e1000e: commit speed/duplex changes for m88 PHY
[linux-2.6/mini2440.git] / drivers / net / e1000e / phy.c
blobcb7d71e458e4ea095695e5fd072dac5015f57eb0
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2008 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include <linux/delay.h>
31 #include "e1000.h"
33 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
34 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
35 static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active);
36 static s32 e1000_wait_autoneg(struct e1000_hw *hw);
37 static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg);
38 static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
39 u16 *data, bool read);
41 /* Cable length tables */
42 static const u16 e1000_m88_cable_length_table[] =
43 { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
45 static const u16 e1000_igp_2_cable_length_table[] =
46 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
47 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
48 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
49 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
50 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
51 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
52 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
53 124};
54 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
55 ARRAY_SIZE(e1000_igp_2_cable_length_table)
57 /**
58 * e1000e_check_reset_block_generic - Check if PHY reset is blocked
59 * @hw: pointer to the HW structure
61 * Read the PHY management control register and check whether a PHY reset
62 * is blocked. If a reset is not blocked return 0, otherwise
63 * return E1000_BLK_PHY_RESET (12).
64 **/
65 s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
67 u32 manc;
69 manc = er32(MANC);
71 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
72 E1000_BLK_PHY_RESET : 0;
75 /**
76 * e1000e_get_phy_id - Retrieve the PHY ID and revision
77 * @hw: pointer to the HW structure
79 * Reads the PHY registers and stores the PHY ID and possibly the PHY
80 * revision in the hardware structure.
81 **/
82 s32 e1000e_get_phy_id(struct e1000_hw *hw)
84 struct e1000_phy_info *phy = &hw->phy;
85 s32 ret_val;
86 u16 phy_id;
88 ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
89 if (ret_val)
90 return ret_val;
92 phy->id = (u32)(phy_id << 16);
93 udelay(20);
94 ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
95 if (ret_val)
96 return ret_val;
98 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
99 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
101 return 0;
105 * e1000e_phy_reset_dsp - Reset PHY DSP
106 * @hw: pointer to the HW structure
108 * Reset the digital signal processor.
110 s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
112 s32 ret_val;
114 ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
115 if (ret_val)
116 return ret_val;
118 return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
122 * e1000e_read_phy_reg_mdic - Read MDI control register
123 * @hw: pointer to the HW structure
124 * @offset: register offset to be read
125 * @data: pointer to the read data
127 * Reads the MDI control register in the PHY at offset and stores the
128 * information read to data.
130 s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
132 struct e1000_phy_info *phy = &hw->phy;
133 u32 i, mdic = 0;
135 if (offset > MAX_PHY_REG_ADDRESS) {
136 hw_dbg(hw, "PHY Address %d is out of range\n", offset);
137 return -E1000_ERR_PARAM;
141 * Set up Op-code, Phy Address, and register offset in the MDI
142 * Control register. The MAC will take care of interfacing with the
143 * PHY to retrieve the desired data.
145 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
146 (phy->addr << E1000_MDIC_PHY_SHIFT) |
147 (E1000_MDIC_OP_READ));
149 ew32(MDIC, mdic);
152 * Poll the ready bit to see if the MDI read completed
153 * Increasing the time out as testing showed failures with
154 * the lower time out
156 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
157 udelay(50);
158 mdic = er32(MDIC);
159 if (mdic & E1000_MDIC_READY)
160 break;
162 if (!(mdic & E1000_MDIC_READY)) {
163 hw_dbg(hw, "MDI Read did not complete\n");
164 return -E1000_ERR_PHY;
166 if (mdic & E1000_MDIC_ERROR) {
167 hw_dbg(hw, "MDI Error\n");
168 return -E1000_ERR_PHY;
170 *data = (u16) mdic;
172 return 0;
176 * e1000e_write_phy_reg_mdic - Write MDI control register
177 * @hw: pointer to the HW structure
178 * @offset: register offset to write to
179 * @data: data to write to register at offset
181 * Writes data to MDI control register in the PHY at offset.
183 s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
185 struct e1000_phy_info *phy = &hw->phy;
186 u32 i, mdic = 0;
188 if (offset > MAX_PHY_REG_ADDRESS) {
189 hw_dbg(hw, "PHY Address %d is out of range\n", offset);
190 return -E1000_ERR_PARAM;
194 * Set up Op-code, Phy Address, and register offset in the MDI
195 * Control register. The MAC will take care of interfacing with the
196 * PHY to retrieve the desired data.
198 mdic = (((u32)data) |
199 (offset << E1000_MDIC_REG_SHIFT) |
200 (phy->addr << E1000_MDIC_PHY_SHIFT) |
201 (E1000_MDIC_OP_WRITE));
203 ew32(MDIC, mdic);
206 * Poll the ready bit to see if the MDI read completed
207 * Increasing the time out as testing showed failures with
208 * the lower time out
210 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
211 udelay(50);
212 mdic = er32(MDIC);
213 if (mdic & E1000_MDIC_READY)
214 break;
216 if (!(mdic & E1000_MDIC_READY)) {
217 hw_dbg(hw, "MDI Write did not complete\n");
218 return -E1000_ERR_PHY;
220 if (mdic & E1000_MDIC_ERROR) {
221 hw_dbg(hw, "MDI Error\n");
222 return -E1000_ERR_PHY;
225 return 0;
229 * e1000e_read_phy_reg_m88 - Read m88 PHY register
230 * @hw: pointer to the HW structure
231 * @offset: register offset to be read
232 * @data: pointer to the read data
234 * Acquires semaphore, if necessary, then reads the PHY register at offset
235 * and storing the retrieved information in data. Release any acquired
236 * semaphores before exiting.
238 s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
240 s32 ret_val;
242 ret_val = hw->phy.ops.acquire_phy(hw);
243 if (ret_val)
244 return ret_val;
246 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
247 data);
249 hw->phy.ops.release_phy(hw);
251 return ret_val;
255 * e1000e_write_phy_reg_m88 - Write m88 PHY register
256 * @hw: pointer to the HW structure
257 * @offset: register offset to write to
258 * @data: data to write at register offset
260 * Acquires semaphore, if necessary, then writes the data to PHY register
261 * at the offset. Release any acquired semaphores before exiting.
263 s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
265 s32 ret_val;
267 ret_val = hw->phy.ops.acquire_phy(hw);
268 if (ret_val)
269 return ret_val;
271 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
272 data);
274 hw->phy.ops.release_phy(hw);
276 return ret_val;
280 * e1000e_read_phy_reg_igp - Read igp PHY register
281 * @hw: pointer to the HW structure
282 * @offset: register offset to be read
283 * @data: pointer to the read data
285 * Acquires semaphore, if necessary, then reads the PHY register at offset
286 * and storing the retrieved information in data. Release any acquired
287 * semaphores before exiting.
289 s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
291 s32 ret_val;
293 ret_val = hw->phy.ops.acquire_phy(hw);
294 if (ret_val)
295 return ret_val;
297 if (offset > MAX_PHY_MULTI_PAGE_REG) {
298 ret_val = e1000e_write_phy_reg_mdic(hw,
299 IGP01E1000_PHY_PAGE_SELECT,
300 (u16)offset);
301 if (ret_val) {
302 hw->phy.ops.release_phy(hw);
303 return ret_val;
307 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
308 data);
310 hw->phy.ops.release_phy(hw);
312 return ret_val;
316 * e1000e_write_phy_reg_igp - Write igp PHY register
317 * @hw: pointer to the HW structure
318 * @offset: register offset to write to
319 * @data: data to write at register offset
321 * Acquires semaphore, if necessary, then writes the data to PHY register
322 * at the offset. Release any acquired semaphores before exiting.
324 s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
326 s32 ret_val;
328 ret_val = hw->phy.ops.acquire_phy(hw);
329 if (ret_val)
330 return ret_val;
332 if (offset > MAX_PHY_MULTI_PAGE_REG) {
333 ret_val = e1000e_write_phy_reg_mdic(hw,
334 IGP01E1000_PHY_PAGE_SELECT,
335 (u16)offset);
336 if (ret_val) {
337 hw->phy.ops.release_phy(hw);
338 return ret_val;
342 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
343 data);
345 hw->phy.ops.release_phy(hw);
347 return ret_val;
351 * e1000e_read_kmrn_reg - Read kumeran register
352 * @hw: pointer to the HW structure
353 * @offset: register offset to be read
354 * @data: pointer to the read data
356 * Acquires semaphore, if necessary. Then reads the PHY register at offset
357 * using the kumeran interface. The information retrieved is stored in data.
358 * Release any acquired semaphores before exiting.
360 s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
362 u32 kmrnctrlsta;
363 s32 ret_val;
365 ret_val = hw->phy.ops.acquire_phy(hw);
366 if (ret_val)
367 return ret_val;
369 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
370 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
371 ew32(KMRNCTRLSTA, kmrnctrlsta);
373 udelay(2);
375 kmrnctrlsta = er32(KMRNCTRLSTA);
376 *data = (u16)kmrnctrlsta;
378 hw->phy.ops.release_phy(hw);
380 return ret_val;
384 * e1000e_write_kmrn_reg - Write kumeran register
385 * @hw: pointer to the HW structure
386 * @offset: register offset to write to
387 * @data: data to write at register offset
389 * Acquires semaphore, if necessary. Then write the data to PHY register
390 * at the offset using the kumeran interface. Release any acquired semaphores
391 * before exiting.
393 s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
395 u32 kmrnctrlsta;
396 s32 ret_val;
398 ret_val = hw->phy.ops.acquire_phy(hw);
399 if (ret_val)
400 return ret_val;
402 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
403 E1000_KMRNCTRLSTA_OFFSET) | data;
404 ew32(KMRNCTRLSTA, kmrnctrlsta);
406 udelay(2);
407 hw->phy.ops.release_phy(hw);
409 return ret_val;
413 * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
414 * @hw: pointer to the HW structure
416 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
417 * and downshift values are set also.
419 s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
421 struct e1000_phy_info *phy = &hw->phy;
422 s32 ret_val;
423 u16 phy_data;
425 /* Enable CRS on Tx. This must be set for half-duplex operation. */
426 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
427 if (ret_val)
428 return ret_val;
430 /* For newer PHYs this bit is downshift enable */
431 if (phy->type == e1000_phy_m88)
432 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
435 * Options:
436 * MDI/MDI-X = 0 (default)
437 * 0 - Auto for all speeds
438 * 1 - MDI mode
439 * 2 - MDI-X mode
440 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
442 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
444 switch (phy->mdix) {
445 case 1:
446 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
447 break;
448 case 2:
449 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
450 break;
451 case 3:
452 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
453 break;
454 case 0:
455 default:
456 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
457 break;
461 * Options:
462 * disable_polarity_correction = 0 (default)
463 * Automatic Correction for Reversed Cable Polarity
464 * 0 - Disabled
465 * 1 - Enabled
467 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
468 if (phy->disable_polarity_correction == 1)
469 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
471 /* Enable downshift on BM (disabled by default) */
472 if (phy->type == e1000_phy_bm)
473 phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
475 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
476 if (ret_val)
477 return ret_val;
479 if ((phy->type == e1000_phy_m88) &&
480 (phy->revision < E1000_REVISION_4) &&
481 (phy->id != BME1000_E_PHY_ID_R2)) {
483 * Force TX_CLK in the Extended PHY Specific Control Register
484 * to 25MHz clock.
486 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
487 if (ret_val)
488 return ret_val;
490 phy_data |= M88E1000_EPSCR_TX_CLK_25;
492 if ((phy->revision == 2) &&
493 (phy->id == M88E1111_I_PHY_ID)) {
494 /* 82573L PHY - set the downshift counter to 5x. */
495 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
496 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
497 } else {
498 /* Configure Master and Slave downshift values */
499 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
500 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
501 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
502 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
504 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
505 if (ret_val)
506 return ret_val;
509 if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
510 /* Set PHY page 0, register 29 to 0x0003 */
511 ret_val = e1e_wphy(hw, 29, 0x0003);
512 if (ret_val)
513 return ret_val;
515 /* Set PHY page 0, register 30 to 0x0000 */
516 ret_val = e1e_wphy(hw, 30, 0x0000);
517 if (ret_val)
518 return ret_val;
521 /* Commit the changes. */
522 ret_val = e1000e_commit_phy(hw);
523 if (ret_val)
524 hw_dbg(hw, "Error committing the PHY changes\n");
526 return ret_val;
530 * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
531 * @hw: pointer to the HW structure
533 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
534 * igp PHY's.
536 s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
538 struct e1000_phy_info *phy = &hw->phy;
539 s32 ret_val;
540 u16 data;
542 ret_val = e1000_phy_hw_reset(hw);
543 if (ret_val) {
544 hw_dbg(hw, "Error resetting the PHY.\n");
545 return ret_val;
549 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
550 * timeout issues when LFS is enabled.
552 msleep(100);
554 /* disable lplu d0 during driver init */
555 ret_val = e1000_set_d0_lplu_state(hw, 0);
556 if (ret_val) {
557 hw_dbg(hw, "Error Disabling LPLU D0\n");
558 return ret_val;
560 /* Configure mdi-mdix settings */
561 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
562 if (ret_val)
563 return ret_val;
565 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
567 switch (phy->mdix) {
568 case 1:
569 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
570 break;
571 case 2:
572 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
573 break;
574 case 0:
575 default:
576 data |= IGP01E1000_PSCR_AUTO_MDIX;
577 break;
579 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
580 if (ret_val)
581 return ret_val;
583 /* set auto-master slave resolution settings */
584 if (hw->mac.autoneg) {
586 * when autonegotiation advertisement is only 1000Mbps then we
587 * should disable SmartSpeed and enable Auto MasterSlave
588 * resolution as hardware default.
590 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
591 /* Disable SmartSpeed */
592 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
593 &data);
594 if (ret_val)
595 return ret_val;
597 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
598 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
599 data);
600 if (ret_val)
601 return ret_val;
603 /* Set auto Master/Slave resolution process */
604 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
605 if (ret_val)
606 return ret_val;
608 data &= ~CR_1000T_MS_ENABLE;
609 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
610 if (ret_val)
611 return ret_val;
614 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
615 if (ret_val)
616 return ret_val;
618 /* load defaults for future use */
619 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
620 ((data & CR_1000T_MS_VALUE) ?
621 e1000_ms_force_master :
622 e1000_ms_force_slave) :
623 e1000_ms_auto;
625 switch (phy->ms_type) {
626 case e1000_ms_force_master:
627 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
628 break;
629 case e1000_ms_force_slave:
630 data |= CR_1000T_MS_ENABLE;
631 data &= ~(CR_1000T_MS_VALUE);
632 break;
633 case e1000_ms_auto:
634 data &= ~CR_1000T_MS_ENABLE;
635 default:
636 break;
638 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
641 return ret_val;
645 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
646 * @hw: pointer to the HW structure
648 * Reads the MII auto-neg advertisement register and/or the 1000T control
649 * register and if the PHY is already setup for auto-negotiation, then
650 * return successful. Otherwise, setup advertisement and flow control to
651 * the appropriate values for the wanted auto-negotiation.
653 static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
655 struct e1000_phy_info *phy = &hw->phy;
656 s32 ret_val;
657 u16 mii_autoneg_adv_reg;
658 u16 mii_1000t_ctrl_reg = 0;
660 phy->autoneg_advertised &= phy->autoneg_mask;
662 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
663 ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
664 if (ret_val)
665 return ret_val;
667 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
668 /* Read the MII 1000Base-T Control Register (Address 9). */
669 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
670 if (ret_val)
671 return ret_val;
675 * Need to parse both autoneg_advertised and fc and set up
676 * the appropriate PHY registers. First we will parse for
677 * autoneg_advertised software override. Since we can advertise
678 * a plethora of combinations, we need to check each bit
679 * individually.
683 * First we clear all the 10/100 mb speed bits in the Auto-Neg
684 * Advertisement Register (Address 4) and the 1000 mb speed bits in
685 * the 1000Base-T Control Register (Address 9).
687 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
688 NWAY_AR_100TX_HD_CAPS |
689 NWAY_AR_10T_FD_CAPS |
690 NWAY_AR_10T_HD_CAPS);
691 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
693 hw_dbg(hw, "autoneg_advertised %x\n", phy->autoneg_advertised);
695 /* Do we want to advertise 10 Mb Half Duplex? */
696 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
697 hw_dbg(hw, "Advertise 10mb Half duplex\n");
698 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
701 /* Do we want to advertise 10 Mb Full Duplex? */
702 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
703 hw_dbg(hw, "Advertise 10mb Full duplex\n");
704 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
707 /* Do we want to advertise 100 Mb Half Duplex? */
708 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
709 hw_dbg(hw, "Advertise 100mb Half duplex\n");
710 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
713 /* Do we want to advertise 100 Mb Full Duplex? */
714 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
715 hw_dbg(hw, "Advertise 100mb Full duplex\n");
716 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
719 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
720 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
721 hw_dbg(hw, "Advertise 1000mb Half duplex request denied!\n");
723 /* Do we want to advertise 1000 Mb Full Duplex? */
724 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
725 hw_dbg(hw, "Advertise 1000mb Full duplex\n");
726 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
730 * Check for a software override of the flow control settings, and
731 * setup the PHY advertisement registers accordingly. If
732 * auto-negotiation is enabled, then software will have to set the
733 * "PAUSE" bits to the correct value in the Auto-Negotiation
734 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
735 * negotiation.
737 * The possible values of the "fc" parameter are:
738 * 0: Flow control is completely disabled
739 * 1: Rx flow control is enabled (we can receive pause frames
740 * but not send pause frames).
741 * 2: Tx flow control is enabled (we can send pause frames
742 * but we do not support receiving pause frames).
743 * 3: Both Rx and Tx flow control (symmetric) are enabled.
744 * other: No software override. The flow control configuration
745 * in the EEPROM is used.
747 switch (hw->fc.type) {
748 case e1000_fc_none:
750 * Flow control (Rx & Tx) is completely disabled by a
751 * software over-ride.
753 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
754 break;
755 case e1000_fc_rx_pause:
757 * Rx Flow control is enabled, and Tx Flow control is
758 * disabled, by a software over-ride.
760 * Since there really isn't a way to advertise that we are
761 * capable of Rx Pause ONLY, we will advertise that we
762 * support both symmetric and asymmetric Rx PAUSE. Later
763 * (in e1000e_config_fc_after_link_up) we will disable the
764 * hw's ability to send PAUSE frames.
766 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
767 break;
768 case e1000_fc_tx_pause:
770 * Tx Flow control is enabled, and Rx Flow control is
771 * disabled, by a software over-ride.
773 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
774 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
775 break;
776 case e1000_fc_full:
778 * Flow control (both Rx and Tx) is enabled by a software
779 * over-ride.
781 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
782 break;
783 default:
784 hw_dbg(hw, "Flow control param set incorrectly\n");
785 ret_val = -E1000_ERR_CONFIG;
786 return ret_val;
789 ret_val = e1e_wphy(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
790 if (ret_val)
791 return ret_val;
793 hw_dbg(hw, "Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
795 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
796 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
799 return ret_val;
803 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
804 * @hw: pointer to the HW structure
806 * Performs initial bounds checking on autoneg advertisement parameter, then
807 * configure to advertise the full capability. Setup the PHY to autoneg
808 * and restart the negotiation process between the link partner. If
809 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
811 static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
813 struct e1000_phy_info *phy = &hw->phy;
814 s32 ret_val;
815 u16 phy_ctrl;
818 * Perform some bounds checking on the autoneg advertisement
819 * parameter.
821 phy->autoneg_advertised &= phy->autoneg_mask;
824 * If autoneg_advertised is zero, we assume it was not defaulted
825 * by the calling code so we set to advertise full capability.
827 if (phy->autoneg_advertised == 0)
828 phy->autoneg_advertised = phy->autoneg_mask;
830 hw_dbg(hw, "Reconfiguring auto-neg advertisement params\n");
831 ret_val = e1000_phy_setup_autoneg(hw);
832 if (ret_val) {
833 hw_dbg(hw, "Error Setting up Auto-Negotiation\n");
834 return ret_val;
836 hw_dbg(hw, "Restarting Auto-Neg\n");
839 * Restart auto-negotiation by setting the Auto Neg Enable bit and
840 * the Auto Neg Restart bit in the PHY control register.
842 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
843 if (ret_val)
844 return ret_val;
846 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
847 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
848 if (ret_val)
849 return ret_val;
852 * Does the user want to wait for Auto-Neg to complete here, or
853 * check at a later time (for example, callback routine).
855 if (phy->autoneg_wait_to_complete) {
856 ret_val = e1000_wait_autoneg(hw);
857 if (ret_val) {
858 hw_dbg(hw, "Error while waiting for "
859 "autoneg to complete\n");
860 return ret_val;
864 hw->mac.get_link_status = 1;
866 return ret_val;
870 * e1000e_setup_copper_link - Configure copper link settings
871 * @hw: pointer to the HW structure
873 * Calls the appropriate function to configure the link for auto-neg or forced
874 * speed and duplex. Then we check for link, once link is established calls
875 * to configure collision distance and flow control are called. If link is
876 * not established, we return -E1000_ERR_PHY (-2).
878 s32 e1000e_setup_copper_link(struct e1000_hw *hw)
880 s32 ret_val;
881 bool link;
883 if (hw->mac.autoneg) {
885 * Setup autoneg and flow control advertisement and perform
886 * autonegotiation.
888 ret_val = e1000_copper_link_autoneg(hw);
889 if (ret_val)
890 return ret_val;
891 } else {
893 * PHY will be set to 10H, 10F, 100H or 100F
894 * depending on user settings.
896 hw_dbg(hw, "Forcing Speed and Duplex\n");
897 ret_val = e1000_phy_force_speed_duplex(hw);
898 if (ret_val) {
899 hw_dbg(hw, "Error Forcing Speed and Duplex\n");
900 return ret_val;
905 * Check link status. Wait up to 100 microseconds for link to become
906 * valid.
908 ret_val = e1000e_phy_has_link_generic(hw,
909 COPPER_LINK_UP_LIMIT,
911 &link);
912 if (ret_val)
913 return ret_val;
915 if (link) {
916 hw_dbg(hw, "Valid link established!!!\n");
917 e1000e_config_collision_dist(hw);
918 ret_val = e1000e_config_fc_after_link_up(hw);
919 } else {
920 hw_dbg(hw, "Unable to establish link!!!\n");
923 return ret_val;
927 * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
928 * @hw: pointer to the HW structure
930 * Calls the PHY setup function to force speed and duplex. Clears the
931 * auto-crossover to force MDI manually. Waits for link and returns
932 * successful if link up is successful, else -E1000_ERR_PHY (-2).
934 s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
936 struct e1000_phy_info *phy = &hw->phy;
937 s32 ret_val;
938 u16 phy_data;
939 bool link;
941 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
942 if (ret_val)
943 return ret_val;
945 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
947 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
948 if (ret_val)
949 return ret_val;
952 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
953 * forced whenever speed and duplex are forced.
955 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
956 if (ret_val)
957 return ret_val;
959 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
960 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
962 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
963 if (ret_val)
964 return ret_val;
966 hw_dbg(hw, "IGP PSCR: %X\n", phy_data);
968 udelay(1);
970 if (phy->autoneg_wait_to_complete) {
971 hw_dbg(hw, "Waiting for forced speed/duplex link on IGP phy.\n");
973 ret_val = e1000e_phy_has_link_generic(hw,
974 PHY_FORCE_LIMIT,
975 100000,
976 &link);
977 if (ret_val)
978 return ret_val;
980 if (!link)
981 hw_dbg(hw, "Link taking longer than expected.\n");
983 /* Try once more */
984 ret_val = e1000e_phy_has_link_generic(hw,
985 PHY_FORCE_LIMIT,
986 100000,
987 &link);
988 if (ret_val)
989 return ret_val;
992 return ret_val;
996 * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
997 * @hw: pointer to the HW structure
999 * Calls the PHY setup function to force speed and duplex. Clears the
1000 * auto-crossover to force MDI manually. Resets the PHY to commit the
1001 * changes. If time expires while waiting for link up, we reset the DSP.
1002 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
1003 * successful completion, else return corresponding error code.
1005 s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1007 struct e1000_phy_info *phy = &hw->phy;
1008 s32 ret_val;
1009 u16 phy_data;
1010 bool link;
1013 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1014 * forced whenever speed and duplex are forced.
1016 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1017 if (ret_val)
1018 return ret_val;
1020 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1021 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1022 if (ret_val)
1023 return ret_val;
1025 hw_dbg(hw, "M88E1000 PSCR: %X\n", phy_data);
1027 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
1028 if (ret_val)
1029 return ret_val;
1031 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1033 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
1034 if (ret_val)
1035 return ret_val;
1037 /* Reset the phy to commit changes. */
1038 ret_val = e1000e_commit_phy(hw);
1039 if (ret_val)
1040 return ret_val;
1042 if (phy->autoneg_wait_to_complete) {
1043 hw_dbg(hw, "Waiting for forced speed/duplex link on M88 phy.\n");
1045 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1046 100000, &link);
1047 if (ret_val)
1048 return ret_val;
1050 if (!link) {
1052 * We didn't get link.
1053 * Reset the DSP and cross our fingers.
1055 ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1056 0x001d);
1057 if (ret_val)
1058 return ret_val;
1059 ret_val = e1000e_phy_reset_dsp(hw);
1060 if (ret_val)
1061 return ret_val;
1064 /* Try once more */
1065 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1066 100000, &link);
1067 if (ret_val)
1068 return ret_val;
1071 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1072 if (ret_val)
1073 return ret_val;
1076 * Resetting the phy means we need to re-force TX_CLK in the
1077 * Extended PHY Specific Control Register to 25MHz clock from
1078 * the reset value of 2.5MHz.
1080 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1081 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1082 if (ret_val)
1083 return ret_val;
1086 * In addition, we must re-enable CRS on Tx for both half and full
1087 * duplex.
1089 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1090 if (ret_val)
1091 return ret_val;
1093 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1094 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1096 return ret_val;
1100 * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1101 * @hw: pointer to the HW structure
1102 * @phy_ctrl: pointer to current value of PHY_CONTROL
1104 * Forces speed and duplex on the PHY by doing the following: disable flow
1105 * control, force speed/duplex on the MAC, disable auto speed detection,
1106 * disable auto-negotiation, configure duplex, configure speed, configure
1107 * the collision distance, write configuration to CTRL register. The
1108 * caller must write to the PHY_CONTROL register for these settings to
1109 * take affect.
1111 void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1113 struct e1000_mac_info *mac = &hw->mac;
1114 u32 ctrl;
1116 /* Turn off flow control when forcing speed/duplex */
1117 hw->fc.type = e1000_fc_none;
1119 /* Force speed/duplex on the mac */
1120 ctrl = er32(CTRL);
1121 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1122 ctrl &= ~E1000_CTRL_SPD_SEL;
1124 /* Disable Auto Speed Detection */
1125 ctrl &= ~E1000_CTRL_ASDE;
1127 /* Disable autoneg on the phy */
1128 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1130 /* Forcing Full or Half Duplex? */
1131 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1132 ctrl &= ~E1000_CTRL_FD;
1133 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1134 hw_dbg(hw, "Half Duplex\n");
1135 } else {
1136 ctrl |= E1000_CTRL_FD;
1137 *phy_ctrl |= MII_CR_FULL_DUPLEX;
1138 hw_dbg(hw, "Full Duplex\n");
1141 /* Forcing 10mb or 100mb? */
1142 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1143 ctrl |= E1000_CTRL_SPD_100;
1144 *phy_ctrl |= MII_CR_SPEED_100;
1145 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1146 hw_dbg(hw, "Forcing 100mb\n");
1147 } else {
1148 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1149 *phy_ctrl |= MII_CR_SPEED_10;
1150 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1151 hw_dbg(hw, "Forcing 10mb\n");
1154 e1000e_config_collision_dist(hw);
1156 ew32(CTRL, ctrl);
1160 * e1000e_set_d3_lplu_state - Sets low power link up state for D3
1161 * @hw: pointer to the HW structure
1162 * @active: boolean used to enable/disable lplu
1164 * Success returns 0, Failure returns 1
1166 * The low power link up (lplu) state is set to the power management level D3
1167 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1168 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1169 * is used during Dx states where the power conservation is most important.
1170 * During driver activity, SmartSpeed should be enabled so performance is
1171 * maintained.
1173 s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1175 struct e1000_phy_info *phy = &hw->phy;
1176 s32 ret_val;
1177 u16 data;
1179 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1180 if (ret_val)
1181 return ret_val;
1183 if (!active) {
1184 data &= ~IGP02E1000_PM_D3_LPLU;
1185 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1186 if (ret_val)
1187 return ret_val;
1189 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1190 * during Dx states where the power conservation is most
1191 * important. During driver activity we should enable
1192 * SmartSpeed, so performance is maintained.
1194 if (phy->smart_speed == e1000_smart_speed_on) {
1195 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1196 &data);
1197 if (ret_val)
1198 return ret_val;
1200 data |= IGP01E1000_PSCFR_SMART_SPEED;
1201 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1202 data);
1203 if (ret_val)
1204 return ret_val;
1205 } else if (phy->smart_speed == e1000_smart_speed_off) {
1206 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1207 &data);
1208 if (ret_val)
1209 return ret_val;
1211 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1212 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1213 data);
1214 if (ret_val)
1215 return ret_val;
1217 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1218 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1219 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1220 data |= IGP02E1000_PM_D3_LPLU;
1221 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1222 if (ret_val)
1223 return ret_val;
1225 /* When LPLU is enabled, we should disable SmartSpeed */
1226 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1227 if (ret_val)
1228 return ret_val;
1230 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1231 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1234 return ret_val;
1238 * e1000e_check_downshift - Checks whether a downshift in speed occurred
1239 * @hw: pointer to the HW structure
1241 * Success returns 0, Failure returns 1
1243 * A downshift is detected by querying the PHY link health.
1245 s32 e1000e_check_downshift(struct e1000_hw *hw)
1247 struct e1000_phy_info *phy = &hw->phy;
1248 s32 ret_val;
1249 u16 phy_data, offset, mask;
1251 switch (phy->type) {
1252 case e1000_phy_m88:
1253 case e1000_phy_gg82563:
1254 offset = M88E1000_PHY_SPEC_STATUS;
1255 mask = M88E1000_PSSR_DOWNSHIFT;
1256 break;
1257 case e1000_phy_igp_2:
1258 case e1000_phy_igp_3:
1259 offset = IGP01E1000_PHY_LINK_HEALTH;
1260 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1261 break;
1262 default:
1263 /* speed downshift not supported */
1264 phy->speed_downgraded = 0;
1265 return 0;
1268 ret_val = e1e_rphy(hw, offset, &phy_data);
1270 if (!ret_val)
1271 phy->speed_downgraded = (phy_data & mask);
1273 return ret_val;
1277 * e1000_check_polarity_m88 - Checks the polarity.
1278 * @hw: pointer to the HW structure
1280 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1282 * Polarity is determined based on the PHY specific status register.
1284 static s32 e1000_check_polarity_m88(struct e1000_hw *hw)
1286 struct e1000_phy_info *phy = &hw->phy;
1287 s32 ret_val;
1288 u16 data;
1290 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1292 if (!ret_val)
1293 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1294 ? e1000_rev_polarity_reversed
1295 : e1000_rev_polarity_normal;
1297 return ret_val;
1301 * e1000_check_polarity_igp - Checks the polarity.
1302 * @hw: pointer to the HW structure
1304 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1306 * Polarity is determined based on the PHY port status register, and the
1307 * current speed (since there is no polarity at 100Mbps).
1309 static s32 e1000_check_polarity_igp(struct e1000_hw *hw)
1311 struct e1000_phy_info *phy = &hw->phy;
1312 s32 ret_val;
1313 u16 data, offset, mask;
1316 * Polarity is determined based on the speed of
1317 * our connection.
1319 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1320 if (ret_val)
1321 return ret_val;
1323 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1324 IGP01E1000_PSSR_SPEED_1000MBPS) {
1325 offset = IGP01E1000_PHY_PCS_INIT_REG;
1326 mask = IGP01E1000_PHY_POLARITY_MASK;
1327 } else {
1329 * This really only applies to 10Mbps since
1330 * there is no polarity for 100Mbps (always 0).
1332 offset = IGP01E1000_PHY_PORT_STATUS;
1333 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1336 ret_val = e1e_rphy(hw, offset, &data);
1338 if (!ret_val)
1339 phy->cable_polarity = (data & mask)
1340 ? e1000_rev_polarity_reversed
1341 : e1000_rev_polarity_normal;
1343 return ret_val;
1347 * e1000_wait_autoneg - Wait for auto-neg completion
1348 * @hw: pointer to the HW structure
1350 * Waits for auto-negotiation to complete or for the auto-negotiation time
1351 * limit to expire, which ever happens first.
1353 static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1355 s32 ret_val = 0;
1356 u16 i, phy_status;
1358 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1359 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1360 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1361 if (ret_val)
1362 break;
1363 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1364 if (ret_val)
1365 break;
1366 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1367 break;
1368 msleep(100);
1372 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1373 * has completed.
1375 return ret_val;
1379 * e1000e_phy_has_link_generic - Polls PHY for link
1380 * @hw: pointer to the HW structure
1381 * @iterations: number of times to poll for link
1382 * @usec_interval: delay between polling attempts
1383 * @success: pointer to whether polling was successful or not
1385 * Polls the PHY status register for link, 'iterations' number of times.
1387 s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1388 u32 usec_interval, bool *success)
1390 s32 ret_val = 0;
1391 u16 i, phy_status;
1393 for (i = 0; i < iterations; i++) {
1395 * Some PHYs require the PHY_STATUS register to be read
1396 * twice due to the link bit being sticky. No harm doing
1397 * it across the board.
1399 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1400 if (ret_val)
1401 break;
1402 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1403 if (ret_val)
1404 break;
1405 if (phy_status & MII_SR_LINK_STATUS)
1406 break;
1407 if (usec_interval >= 1000)
1408 mdelay(usec_interval/1000);
1409 else
1410 udelay(usec_interval);
1413 *success = (i < iterations);
1415 return ret_val;
1419 * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1420 * @hw: pointer to the HW structure
1422 * Reads the PHY specific status register to retrieve the cable length
1423 * information. The cable length is determined by averaging the minimum and
1424 * maximum values to get the "average" cable length. The m88 PHY has four
1425 * possible cable length values, which are:
1426 * Register Value Cable Length
1427 * 0 < 50 meters
1428 * 1 50 - 80 meters
1429 * 2 80 - 110 meters
1430 * 3 110 - 140 meters
1431 * 4 > 140 meters
1433 s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1435 struct e1000_phy_info *phy = &hw->phy;
1436 s32 ret_val;
1437 u16 phy_data, index;
1439 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1440 if (ret_val)
1441 return ret_val;
1443 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1444 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1445 phy->min_cable_length = e1000_m88_cable_length_table[index];
1446 phy->max_cable_length = e1000_m88_cable_length_table[index+1];
1448 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1450 return ret_val;
1454 * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1455 * @hw: pointer to the HW structure
1457 * The automatic gain control (agc) normalizes the amplitude of the
1458 * received signal, adjusting for the attenuation produced by the
1459 * cable. By reading the AGC registers, which represent the
1460 * combination of course and fine gain value, the value can be put
1461 * into a lookup table to obtain the approximate cable length
1462 * for each channel.
1464 s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1466 struct e1000_phy_info *phy = &hw->phy;
1467 s32 ret_val;
1468 u16 phy_data, i, agc_value = 0;
1469 u16 cur_agc_index, max_agc_index = 0;
1470 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1471 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1472 {IGP02E1000_PHY_AGC_A,
1473 IGP02E1000_PHY_AGC_B,
1474 IGP02E1000_PHY_AGC_C,
1475 IGP02E1000_PHY_AGC_D};
1477 /* Read the AGC registers for all channels */
1478 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1479 ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1480 if (ret_val)
1481 return ret_val;
1484 * Getting bits 15:9, which represent the combination of
1485 * course and fine gain values. The result is a number
1486 * that can be put into the lookup table to obtain the
1487 * approximate cable length.
1489 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1490 IGP02E1000_AGC_LENGTH_MASK;
1492 /* Array index bound check. */
1493 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1494 (cur_agc_index == 0))
1495 return -E1000_ERR_PHY;
1497 /* Remove min & max AGC values from calculation. */
1498 if (e1000_igp_2_cable_length_table[min_agc_index] >
1499 e1000_igp_2_cable_length_table[cur_agc_index])
1500 min_agc_index = cur_agc_index;
1501 if (e1000_igp_2_cable_length_table[max_agc_index] <
1502 e1000_igp_2_cable_length_table[cur_agc_index])
1503 max_agc_index = cur_agc_index;
1505 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1508 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1509 e1000_igp_2_cable_length_table[max_agc_index]);
1510 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1512 /* Calculate cable length with the error range of +/- 10 meters. */
1513 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1514 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1515 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1517 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1519 return ret_val;
1523 * e1000e_get_phy_info_m88 - Retrieve PHY information
1524 * @hw: pointer to the HW structure
1526 * Valid for only copper links. Read the PHY status register (sticky read)
1527 * to verify that link is up. Read the PHY special control register to
1528 * determine the polarity and 10base-T extended distance. Read the PHY
1529 * special status register to determine MDI/MDIx and current speed. If
1530 * speed is 1000, then determine cable length, local and remote receiver.
1532 s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1534 struct e1000_phy_info *phy = &hw->phy;
1535 s32 ret_val;
1536 u16 phy_data;
1537 bool link;
1539 if (hw->phy.media_type != e1000_media_type_copper) {
1540 hw_dbg(hw, "Phy info is only valid for copper media\n");
1541 return -E1000_ERR_CONFIG;
1544 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1545 if (ret_val)
1546 return ret_val;
1548 if (!link) {
1549 hw_dbg(hw, "Phy info is only valid if link is up\n");
1550 return -E1000_ERR_CONFIG;
1553 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1554 if (ret_val)
1555 return ret_val;
1557 phy->polarity_correction = (phy_data &
1558 M88E1000_PSCR_POLARITY_REVERSAL);
1560 ret_val = e1000_check_polarity_m88(hw);
1561 if (ret_val)
1562 return ret_val;
1564 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1565 if (ret_val)
1566 return ret_val;
1568 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX);
1570 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
1571 ret_val = e1000_get_cable_length(hw);
1572 if (ret_val)
1573 return ret_val;
1575 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
1576 if (ret_val)
1577 return ret_val;
1579 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1580 ? e1000_1000t_rx_status_ok
1581 : e1000_1000t_rx_status_not_ok;
1583 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1584 ? e1000_1000t_rx_status_ok
1585 : e1000_1000t_rx_status_not_ok;
1586 } else {
1587 /* Set values to "undefined" */
1588 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1589 phy->local_rx = e1000_1000t_rx_status_undefined;
1590 phy->remote_rx = e1000_1000t_rx_status_undefined;
1593 return ret_val;
1597 * e1000e_get_phy_info_igp - Retrieve igp PHY information
1598 * @hw: pointer to the HW structure
1600 * Read PHY status to determine if link is up. If link is up, then
1601 * set/determine 10base-T extended distance and polarity correction. Read
1602 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1603 * determine on the cable length, local and remote receiver.
1605 s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
1607 struct e1000_phy_info *phy = &hw->phy;
1608 s32 ret_val;
1609 u16 data;
1610 bool link;
1612 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1613 if (ret_val)
1614 return ret_val;
1616 if (!link) {
1617 hw_dbg(hw, "Phy info is only valid if link is up\n");
1618 return -E1000_ERR_CONFIG;
1621 phy->polarity_correction = 1;
1623 ret_val = e1000_check_polarity_igp(hw);
1624 if (ret_val)
1625 return ret_val;
1627 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1628 if (ret_val)
1629 return ret_val;
1631 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX);
1633 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1634 IGP01E1000_PSSR_SPEED_1000MBPS) {
1635 ret_val = e1000_get_cable_length(hw);
1636 if (ret_val)
1637 return ret_val;
1639 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
1640 if (ret_val)
1641 return ret_val;
1643 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1644 ? e1000_1000t_rx_status_ok
1645 : e1000_1000t_rx_status_not_ok;
1647 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1648 ? e1000_1000t_rx_status_ok
1649 : e1000_1000t_rx_status_not_ok;
1650 } else {
1651 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1652 phy->local_rx = e1000_1000t_rx_status_undefined;
1653 phy->remote_rx = e1000_1000t_rx_status_undefined;
1656 return ret_val;
1660 * e1000e_phy_sw_reset - PHY software reset
1661 * @hw: pointer to the HW structure
1663 * Does a software reset of the PHY by reading the PHY control register and
1664 * setting/write the control register reset bit to the PHY.
1666 s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
1668 s32 ret_val;
1669 u16 phy_ctrl;
1671 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
1672 if (ret_val)
1673 return ret_val;
1675 phy_ctrl |= MII_CR_RESET;
1676 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
1677 if (ret_val)
1678 return ret_val;
1680 udelay(1);
1682 return ret_val;
1686 * e1000e_phy_hw_reset_generic - PHY hardware reset
1687 * @hw: pointer to the HW structure
1689 * Verify the reset block is not blocking us from resetting. Acquire
1690 * semaphore (if necessary) and read/set/write the device control reset
1691 * bit in the PHY. Wait the appropriate delay time for the device to
1692 * reset and release the semaphore (if necessary).
1694 s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
1696 struct e1000_phy_info *phy = &hw->phy;
1697 s32 ret_val;
1698 u32 ctrl;
1700 ret_val = e1000_check_reset_block(hw);
1701 if (ret_val)
1702 return 0;
1704 ret_val = phy->ops.acquire_phy(hw);
1705 if (ret_val)
1706 return ret_val;
1708 ctrl = er32(CTRL);
1709 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
1710 e1e_flush();
1712 udelay(phy->reset_delay_us);
1714 ew32(CTRL, ctrl);
1715 e1e_flush();
1717 udelay(150);
1719 phy->ops.release_phy(hw);
1721 return e1000_get_phy_cfg_done(hw);
1725 * e1000e_get_cfg_done - Generic configuration done
1726 * @hw: pointer to the HW structure
1728 * Generic function to wait 10 milli-seconds for configuration to complete
1729 * and return success.
1731 s32 e1000e_get_cfg_done(struct e1000_hw *hw)
1733 mdelay(10);
1734 return 0;
1738 * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
1739 * @hw: pointer to the HW structure
1741 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
1743 s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
1745 hw_dbg(hw, "Running IGP 3 PHY init script\n");
1747 /* PHY init IGP 3 */
1748 /* Enable rise/fall, 10-mode work in class-A */
1749 e1e_wphy(hw, 0x2F5B, 0x9018);
1750 /* Remove all caps from Replica path filter */
1751 e1e_wphy(hw, 0x2F52, 0x0000);
1752 /* Bias trimming for ADC, AFE and Driver (Default) */
1753 e1e_wphy(hw, 0x2FB1, 0x8B24);
1754 /* Increase Hybrid poly bias */
1755 e1e_wphy(hw, 0x2FB2, 0xF8F0);
1756 /* Add 4% to Tx amplitude in Gig mode */
1757 e1e_wphy(hw, 0x2010, 0x10B0);
1758 /* Disable trimming (TTT) */
1759 e1e_wphy(hw, 0x2011, 0x0000);
1760 /* Poly DC correction to 94.6% + 2% for all channels */
1761 e1e_wphy(hw, 0x20DD, 0x249A);
1762 /* ABS DC correction to 95.9% */
1763 e1e_wphy(hw, 0x20DE, 0x00D3);
1764 /* BG temp curve trim */
1765 e1e_wphy(hw, 0x28B4, 0x04CE);
1766 /* Increasing ADC OPAMP stage 1 currents to max */
1767 e1e_wphy(hw, 0x2F70, 0x29E4);
1768 /* Force 1000 ( required for enabling PHY regs configuration) */
1769 e1e_wphy(hw, 0x0000, 0x0140);
1770 /* Set upd_freq to 6 */
1771 e1e_wphy(hw, 0x1F30, 0x1606);
1772 /* Disable NPDFE */
1773 e1e_wphy(hw, 0x1F31, 0xB814);
1774 /* Disable adaptive fixed FFE (Default) */
1775 e1e_wphy(hw, 0x1F35, 0x002A);
1776 /* Enable FFE hysteresis */
1777 e1e_wphy(hw, 0x1F3E, 0x0067);
1778 /* Fixed FFE for short cable lengths */
1779 e1e_wphy(hw, 0x1F54, 0x0065);
1780 /* Fixed FFE for medium cable lengths */
1781 e1e_wphy(hw, 0x1F55, 0x002A);
1782 /* Fixed FFE for long cable lengths */
1783 e1e_wphy(hw, 0x1F56, 0x002A);
1784 /* Enable Adaptive Clip Threshold */
1785 e1e_wphy(hw, 0x1F72, 0x3FB0);
1786 /* AHT reset limit to 1 */
1787 e1e_wphy(hw, 0x1F76, 0xC0FF);
1788 /* Set AHT master delay to 127 msec */
1789 e1e_wphy(hw, 0x1F77, 0x1DEC);
1790 /* Set scan bits for AHT */
1791 e1e_wphy(hw, 0x1F78, 0xF9EF);
1792 /* Set AHT Preset bits */
1793 e1e_wphy(hw, 0x1F79, 0x0210);
1794 /* Change integ_factor of channel A to 3 */
1795 e1e_wphy(hw, 0x1895, 0x0003);
1796 /* Change prop_factor of channels BCD to 8 */
1797 e1e_wphy(hw, 0x1796, 0x0008);
1798 /* Change cg_icount + enable integbp for channels BCD */
1799 e1e_wphy(hw, 0x1798, 0xD008);
1801 * Change cg_icount + enable integbp + change prop_factor_master
1802 * to 8 for channel A
1804 e1e_wphy(hw, 0x1898, 0xD918);
1805 /* Disable AHT in Slave mode on channel A */
1806 e1e_wphy(hw, 0x187A, 0x0800);
1808 * Enable LPLU and disable AN to 1000 in non-D0a states,
1809 * Enable SPD+B2B
1811 e1e_wphy(hw, 0x0019, 0x008D);
1812 /* Enable restart AN on an1000_dis change */
1813 e1e_wphy(hw, 0x001B, 0x2080);
1814 /* Enable wh_fifo read clock in 10/100 modes */
1815 e1e_wphy(hw, 0x0014, 0x0045);
1816 /* Restart AN, Speed selection is 1000 */
1817 e1e_wphy(hw, 0x0000, 0x1340);
1819 return 0;
1822 /* Internal function pointers */
1825 * e1000_get_phy_cfg_done - Generic PHY configuration done
1826 * @hw: pointer to the HW structure
1828 * Return success if silicon family did not implement a family specific
1829 * get_cfg_done function.
1831 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
1833 if (hw->phy.ops.get_cfg_done)
1834 return hw->phy.ops.get_cfg_done(hw);
1836 return 0;
1840 * e1000_phy_force_speed_duplex - Generic force PHY speed/duplex
1841 * @hw: pointer to the HW structure
1843 * When the silicon family has not implemented a forced speed/duplex
1844 * function for the PHY, simply return 0.
1846 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1848 if (hw->phy.ops.force_speed_duplex)
1849 return hw->phy.ops.force_speed_duplex(hw);
1851 return 0;
1855 * e1000e_get_phy_type_from_id - Get PHY type from id
1856 * @phy_id: phy_id read from the phy
1858 * Returns the phy type from the id.
1860 enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
1862 enum e1000_phy_type phy_type = e1000_phy_unknown;
1864 switch (phy_id) {
1865 case M88E1000_I_PHY_ID:
1866 case M88E1000_E_PHY_ID:
1867 case M88E1111_I_PHY_ID:
1868 case M88E1011_I_PHY_ID:
1869 phy_type = e1000_phy_m88;
1870 break;
1871 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
1872 phy_type = e1000_phy_igp_2;
1873 break;
1874 case GG82563_E_PHY_ID:
1875 phy_type = e1000_phy_gg82563;
1876 break;
1877 case IGP03E1000_E_PHY_ID:
1878 phy_type = e1000_phy_igp_3;
1879 break;
1880 case IFE_E_PHY_ID:
1881 case IFE_PLUS_E_PHY_ID:
1882 case IFE_C_E_PHY_ID:
1883 phy_type = e1000_phy_ife;
1884 break;
1885 case BME1000_E_PHY_ID:
1886 case BME1000_E_PHY_ID_R2:
1887 phy_type = e1000_phy_bm;
1888 break;
1889 default:
1890 phy_type = e1000_phy_unknown;
1891 break;
1893 return phy_type;
1897 * e1000e_determine_phy_address - Determines PHY address.
1898 * @hw: pointer to the HW structure
1900 * This uses a trial and error method to loop through possible PHY
1901 * addresses. It tests each by reading the PHY ID registers and
1902 * checking for a match.
1904 s32 e1000e_determine_phy_address(struct e1000_hw *hw)
1906 s32 ret_val = -E1000_ERR_PHY_TYPE;
1907 u32 phy_addr= 0;
1908 u32 i = 0;
1909 enum e1000_phy_type phy_type = e1000_phy_unknown;
1911 do {
1912 for (phy_addr = 0; phy_addr < 4; phy_addr++) {
1913 hw->phy.addr = phy_addr;
1914 e1000e_get_phy_id(hw);
1915 phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
1918 * If phy_type is valid, break - we found our
1919 * PHY address
1921 if (phy_type != e1000_phy_unknown) {
1922 ret_val = 0;
1923 break;
1926 i++;
1927 } while ((ret_val != 0) && (i < 100));
1929 return ret_val;
1933 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
1934 * @page: page to access
1936 * Returns the phy address for the page requested.
1938 static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
1940 u32 phy_addr = 2;
1942 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
1943 phy_addr = 1;
1945 return phy_addr;
1949 * e1000e_write_phy_reg_bm - Write BM PHY register
1950 * @hw: pointer to the HW structure
1951 * @offset: register offset to write to
1952 * @data: data to write at register offset
1954 * Acquires semaphore, if necessary, then writes the data to PHY register
1955 * at the offset. Release any acquired semaphores before exiting.
1957 s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
1959 s32 ret_val;
1960 u32 page_select = 0;
1961 u32 page = offset >> IGP_PAGE_SHIFT;
1962 u32 page_shift = 0;
1964 /* Page 800 works differently than the rest so it has its own func */
1965 if (page == BM_WUC_PAGE) {
1966 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
1967 false);
1968 goto out;
1971 ret_val = hw->phy.ops.acquire_phy(hw);
1972 if (ret_val)
1973 goto out;
1975 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
1977 if (offset > MAX_PHY_MULTI_PAGE_REG) {
1979 * Page select is register 31 for phy address 1 and 22 for
1980 * phy address 2 and 3. Page select is shifted only for
1981 * phy address 1.
1983 if (hw->phy.addr == 1) {
1984 page_shift = IGP_PAGE_SHIFT;
1985 page_select = IGP01E1000_PHY_PAGE_SELECT;
1986 } else {
1987 page_shift = 0;
1988 page_select = BM_PHY_PAGE_SELECT;
1991 /* Page is shifted left, PHY expects (page x 32) */
1992 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
1993 (page << page_shift));
1994 if (ret_val) {
1995 hw->phy.ops.release_phy(hw);
1996 goto out;
2000 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2001 data);
2003 hw->phy.ops.release_phy(hw);
2005 out:
2006 return ret_val;
2010 * e1000e_read_phy_reg_bm - Read BM PHY register
2011 * @hw: pointer to the HW structure
2012 * @offset: register offset to be read
2013 * @data: pointer to the read data
2015 * Acquires semaphore, if necessary, then reads the PHY register at offset
2016 * and storing the retrieved information in data. Release any acquired
2017 * semaphores before exiting.
2019 s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2021 s32 ret_val;
2022 u32 page_select = 0;
2023 u32 page = offset >> IGP_PAGE_SHIFT;
2024 u32 page_shift = 0;
2026 /* Page 800 works differently than the rest so it has its own func */
2027 if (page == BM_WUC_PAGE) {
2028 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2029 true);
2030 goto out;
2033 ret_val = hw->phy.ops.acquire_phy(hw);
2034 if (ret_val)
2035 goto out;
2037 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2039 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2041 * Page select is register 31 for phy address 1 and 22 for
2042 * phy address 2 and 3. Page select is shifted only for
2043 * phy address 1.
2045 if (hw->phy.addr == 1) {
2046 page_shift = IGP_PAGE_SHIFT;
2047 page_select = IGP01E1000_PHY_PAGE_SELECT;
2048 } else {
2049 page_shift = 0;
2050 page_select = BM_PHY_PAGE_SELECT;
2053 /* Page is shifted left, PHY expects (page x 32) */
2054 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2055 (page << page_shift));
2056 if (ret_val) {
2057 hw->phy.ops.release_phy(hw);
2058 goto out;
2062 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2063 data);
2064 hw->phy.ops.release_phy(hw);
2066 out:
2067 return ret_val;
2071 * e1000e_read_phy_reg_bm2 - Read BM PHY register
2072 * @hw: pointer to the HW structure
2073 * @offset: register offset to be read
2074 * @data: pointer to the read data
2076 * Acquires semaphore, if necessary, then reads the PHY register at offset
2077 * and storing the retrieved information in data. Release any acquired
2078 * semaphores before exiting.
2080 s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2082 s32 ret_val;
2083 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2085 /* Page 800 works differently than the rest so it has its own func */
2086 if (page == BM_WUC_PAGE) {
2087 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2088 true);
2089 return ret_val;
2092 ret_val = hw->phy.ops.acquire_phy(hw);
2093 if (ret_val)
2094 return ret_val;
2096 hw->phy.addr = 1;
2098 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2100 /* Page is shifted left, PHY expects (page x 32) */
2101 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2102 page);
2104 if (ret_val) {
2105 hw->phy.ops.release_phy(hw);
2106 return ret_val;
2110 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2111 data);
2112 hw->phy.ops.release_phy(hw);
2114 return ret_val;
2118 * e1000e_write_phy_reg_bm2 - Write BM PHY register
2119 * @hw: pointer to the HW structure
2120 * @offset: register offset to write to
2121 * @data: data to write at register offset
2123 * Acquires semaphore, if necessary, then writes the data to PHY register
2124 * at the offset. Release any acquired semaphores before exiting.
2126 s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2128 s32 ret_val;
2129 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2131 /* Page 800 works differently than the rest so it has its own func */
2132 if (page == BM_WUC_PAGE) {
2133 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2134 false);
2135 return ret_val;
2138 ret_val = hw->phy.ops.acquire_phy(hw);
2139 if (ret_val)
2140 return ret_val;
2142 hw->phy.addr = 1;
2144 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2145 /* Page is shifted left, PHY expects (page x 32) */
2146 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2147 page);
2149 if (ret_val) {
2150 hw->phy.ops.release_phy(hw);
2151 return ret_val;
2155 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2156 data);
2158 hw->phy.ops.release_phy(hw);
2160 return ret_val;
2164 * e1000_access_phy_wakeup_reg_bm - Read BM PHY wakeup register
2165 * @hw: pointer to the HW structure
2166 * @offset: register offset to be read or written
2167 * @data: pointer to the data to read or write
2168 * @read: determines if operation is read or write
2170 * Acquires semaphore, if necessary, then reads the PHY register at offset
2171 * and storing the retrieved information in data. Release any acquired
2172 * semaphores before exiting. Note that procedure to read the wakeup
2173 * registers are different. It works as such:
2174 * 1) Set page 769, register 17, bit 2 = 1
2175 * 2) Set page to 800 for host (801 if we were manageability)
2176 * 3) Write the address using the address opcode (0x11)
2177 * 4) Read or write the data using the data opcode (0x12)
2178 * 5) Restore 769_17.2 to its original value
2180 static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
2181 u16 *data, bool read)
2183 s32 ret_val;
2184 u16 reg = ((u16)offset) & PHY_REG_MASK;
2185 u16 phy_reg = 0;
2186 u8 phy_acquired = 1;
2189 ret_val = hw->phy.ops.acquire_phy(hw);
2190 if (ret_val) {
2191 phy_acquired = 0;
2192 goto out;
2195 /* All operations in this function are phy address 1 */
2196 hw->phy.addr = 1;
2198 /* Set page 769 */
2199 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2200 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
2202 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
2203 if (ret_val)
2204 goto out;
2206 /* First clear bit 4 to avoid a power state change */
2207 phy_reg &= ~(BM_WUC_HOST_WU_BIT);
2208 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2209 if (ret_val)
2210 goto out;
2212 /* Write bit 2 = 1, and clear bit 4 to 769_17 */
2213 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG,
2214 phy_reg | BM_WUC_ENABLE_BIT);
2215 if (ret_val)
2216 goto out;
2218 /* Select page 800 */
2219 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2220 (BM_WUC_PAGE << IGP_PAGE_SHIFT));
2222 /* Write the page 800 offset value using opcode 0x11 */
2223 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
2224 if (ret_val)
2225 goto out;
2227 if (read) {
2228 /* Read the page 800 value using opcode 0x12 */
2229 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2230 data);
2231 } else {
2232 /* Read the page 800 value using opcode 0x12 */
2233 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2234 *data);
2237 if (ret_val)
2238 goto out;
2241 * Restore 769_17.2 to its original value
2242 * Set page 769
2244 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2245 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
2247 /* Clear 769_17.2 */
2248 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2250 out:
2251 if (phy_acquired == 1)
2252 hw->phy.ops.release_phy(hw);
2253 return ret_val;
2257 * e1000e_commit_phy - Soft PHY reset
2258 * @hw: pointer to the HW structure
2260 * Performs a soft PHY reset on those that apply. This is a function pointer
2261 * entry point called by drivers.
2263 s32 e1000e_commit_phy(struct e1000_hw *hw)
2265 if (hw->phy.ops.commit_phy)
2266 return hw->phy.ops.commit_phy(hw);
2268 return 0;
2272 * e1000_set_d0_lplu_state - Sets low power link up state for D0
2273 * @hw: pointer to the HW structure
2274 * @active: boolean used to enable/disable lplu
2276 * Success returns 0, Failure returns 1
2278 * The low power link up (lplu) state is set to the power management level D0
2279 * and SmartSpeed is disabled when active is true, else clear lplu for D0
2280 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
2281 * is used during Dx states where the power conservation is most important.
2282 * During driver activity, SmartSpeed should be enabled so performance is
2283 * maintained. This is a function pointer entry point called by drivers.
2285 static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2287 if (hw->phy.ops.set_d0_lplu_state)
2288 return hw->phy.ops.set_d0_lplu_state(hw, active);
2290 return 0;