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
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".
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>
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,
54 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
55 ARRAY_SIZE(e1000_igp_2_cable_length_table)
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).
65 s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
71 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
72 E1000_BLK_PHY_RESET : 0;
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.
82 s32 e1000e_get_phy_id(struct e1000_hw *hw)
84 struct e1000_phy_info *phy = &hw->phy;
88 ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
92 phy->id = (u32)(phy_id << 16);
94 ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
98 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
99 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
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)
114 ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
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;
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));
152 * Poll the ready bit to see if the MDI read completed
153 * Increasing the time out as testing showed failures with
156 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
159 if (mdic & E1000_MDIC_READY)
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;
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;
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));
206 * Poll the ready bit to see if the MDI read completed
207 * Increasing the time out as testing showed failures with
210 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
213 if (mdic & E1000_MDIC_READY)
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;
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)
242 ret_val = hw->phy.ops.acquire_phy(hw);
246 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
249 hw->phy.ops.release_phy(hw);
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)
267 ret_val = hw->phy.ops.acquire_phy(hw);
271 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
274 hw->phy.ops.release_phy(hw);
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)
293 ret_val = hw->phy.ops.acquire_phy(hw);
297 if (offset > MAX_PHY_MULTI_PAGE_REG) {
298 ret_val = e1000e_write_phy_reg_mdic(hw,
299 IGP01E1000_PHY_PAGE_SELECT,
302 hw->phy.ops.release_phy(hw);
307 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
310 hw->phy.ops.release_phy(hw);
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)
328 ret_val = hw->phy.ops.acquire_phy(hw);
332 if (offset > MAX_PHY_MULTI_PAGE_REG) {
333 ret_val = e1000e_write_phy_reg_mdic(hw,
334 IGP01E1000_PHY_PAGE_SELECT,
337 hw->phy.ops.release_phy(hw);
342 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
345 hw->phy.ops.release_phy(hw);
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)
365 ret_val = hw->phy.ops.acquire_phy(hw);
369 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
370 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
371 ew32(KMRNCTRLSTA, kmrnctrlsta);
375 kmrnctrlsta = er32(KMRNCTRLSTA);
376 *data = (u16)kmrnctrlsta;
378 hw->phy.ops.release_phy(hw);
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
393 s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
398 ret_val = hw->phy.ops.acquire_phy(hw);
402 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
403 E1000_KMRNCTRLSTA_OFFSET) | data;
404 ew32(KMRNCTRLSTA, kmrnctrlsta);
407 hw->phy.ops.release_phy(hw);
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;
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);
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;
436 * MDI/MDI-X = 0 (default)
437 * 0 - Auto for all speeds
440 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
442 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
446 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
449 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
452 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
456 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
462 * disable_polarity_correction = 0 (default)
463 * Automatic Correction for Reversed Cable Polarity
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);
479 if ((phy->type == e1000_phy_m88) && (phy->revision < 4)) {
481 * Force TX_CLK in the Extended PHY Specific Control Register
484 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
488 phy_data |= M88E1000_EPSCR_TX_CLK_25;
490 if ((phy->revision == 2) &&
491 (phy->id == M88E1111_I_PHY_ID)) {
492 /* 82573L PHY - set the downshift counter to 5x. */
493 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
494 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
496 /* Configure Master and Slave downshift values */
497 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
498 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
499 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
500 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
502 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
507 /* Commit the changes. */
508 ret_val = e1000e_commit_phy(hw);
510 hw_dbg(hw, "Error committing the PHY changes\n");
516 * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
517 * @hw: pointer to the HW structure
519 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
522 s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
524 struct e1000_phy_info *phy = &hw->phy;
528 ret_val = e1000_phy_hw_reset(hw);
530 hw_dbg(hw, "Error resetting the PHY.\n");
535 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
536 * timeout issues when LFS is enabled.
540 /* disable lplu d0 during driver init */
541 ret_val = e1000_set_d0_lplu_state(hw, 0);
543 hw_dbg(hw, "Error Disabling LPLU D0\n");
546 /* Configure mdi-mdix settings */
547 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
551 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
555 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
558 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
562 data |= IGP01E1000_PSCR_AUTO_MDIX;
565 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
569 /* set auto-master slave resolution settings */
570 if (hw->mac.autoneg) {
572 * when autonegotiation advertisement is only 1000Mbps then we
573 * should disable SmartSpeed and enable Auto MasterSlave
574 * resolution as hardware default.
576 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
577 /* Disable SmartSpeed */
578 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
583 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
584 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
589 /* Set auto Master/Slave resolution process */
590 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
594 data &= ~CR_1000T_MS_ENABLE;
595 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
600 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &data);
604 /* load defaults for future use */
605 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
606 ((data & CR_1000T_MS_VALUE) ?
607 e1000_ms_force_master :
608 e1000_ms_force_slave) :
611 switch (phy->ms_type) {
612 case e1000_ms_force_master:
613 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
615 case e1000_ms_force_slave:
616 data |= CR_1000T_MS_ENABLE;
617 data &= ~(CR_1000T_MS_VALUE);
620 data &= ~CR_1000T_MS_ENABLE;
624 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, data);
631 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
632 * @hw: pointer to the HW structure
634 * Reads the MII auto-neg advertisement register and/or the 1000T control
635 * register and if the PHY is already setup for auto-negotiation, then
636 * return successful. Otherwise, setup advertisement and flow control to
637 * the appropriate values for the wanted auto-negotiation.
639 static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
641 struct e1000_phy_info *phy = &hw->phy;
643 u16 mii_autoneg_adv_reg;
644 u16 mii_1000t_ctrl_reg = 0;
646 phy->autoneg_advertised &= phy->autoneg_mask;
648 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
649 ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
653 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
654 /* Read the MII 1000Base-T Control Register (Address 9). */
655 ret_val = e1e_rphy(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
661 * Need to parse both autoneg_advertised and fc and set up
662 * the appropriate PHY registers. First we will parse for
663 * autoneg_advertised software override. Since we can advertise
664 * a plethora of combinations, we need to check each bit
669 * First we clear all the 10/100 mb speed bits in the Auto-Neg
670 * Advertisement Register (Address 4) and the 1000 mb speed bits in
671 * the 1000Base-T Control Register (Address 9).
673 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
674 NWAY_AR_100TX_HD_CAPS |
675 NWAY_AR_10T_FD_CAPS |
676 NWAY_AR_10T_HD_CAPS);
677 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
679 hw_dbg(hw, "autoneg_advertised %x\n", phy->autoneg_advertised);
681 /* Do we want to advertise 10 Mb Half Duplex? */
682 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
683 hw_dbg(hw, "Advertise 10mb Half duplex\n");
684 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
687 /* Do we want to advertise 10 Mb Full Duplex? */
688 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
689 hw_dbg(hw, "Advertise 10mb Full duplex\n");
690 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
693 /* Do we want to advertise 100 Mb Half Duplex? */
694 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
695 hw_dbg(hw, "Advertise 100mb Half duplex\n");
696 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
699 /* Do we want to advertise 100 Mb Full Duplex? */
700 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
701 hw_dbg(hw, "Advertise 100mb Full duplex\n");
702 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
705 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
706 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
707 hw_dbg(hw, "Advertise 1000mb Half duplex request denied!\n");
709 /* Do we want to advertise 1000 Mb Full Duplex? */
710 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
711 hw_dbg(hw, "Advertise 1000mb Full duplex\n");
712 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
716 * Check for a software override of the flow control settings, and
717 * setup the PHY advertisement registers accordingly. If
718 * auto-negotiation is enabled, then software will have to set the
719 * "PAUSE" bits to the correct value in the Auto-Negotiation
720 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
723 * The possible values of the "fc" parameter are:
724 * 0: Flow control is completely disabled
725 * 1: Rx flow control is enabled (we can receive pause frames
726 * but not send pause frames).
727 * 2: Tx flow control is enabled (we can send pause frames
728 * but we do not support receiving pause frames).
729 * 3: Both Rx and Tx flow control (symmetric) are enabled.
730 * other: No software override. The flow control configuration
731 * in the EEPROM is used.
733 switch (hw->fc.type) {
736 * Flow control (Rx & Tx) is completely disabled by a
737 * software over-ride.
739 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
741 case e1000_fc_rx_pause:
743 * Rx Flow control is enabled, and Tx Flow control is
744 * disabled, by a software over-ride.
746 * Since there really isn't a way to advertise that we are
747 * capable of Rx Pause ONLY, we will advertise that we
748 * support both symmetric and asymmetric Rx PAUSE. Later
749 * (in e1000e_config_fc_after_link_up) we will disable the
750 * hw's ability to send PAUSE frames.
752 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
754 case e1000_fc_tx_pause:
756 * Tx Flow control is enabled, and Rx Flow control is
757 * disabled, by a software over-ride.
759 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
760 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
764 * Flow control (both Rx and Tx) is enabled by a software
767 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
770 hw_dbg(hw, "Flow control param set incorrectly\n");
771 ret_val = -E1000_ERR_CONFIG;
775 ret_val = e1e_wphy(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
779 hw_dbg(hw, "Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
781 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
782 ret_val = e1e_wphy(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
789 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
790 * @hw: pointer to the HW structure
792 * Performs initial bounds checking on autoneg advertisement parameter, then
793 * configure to advertise the full capability. Setup the PHY to autoneg
794 * and restart the negotiation process between the link partner. If
795 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
797 static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
799 struct e1000_phy_info *phy = &hw->phy;
804 * Perform some bounds checking on the autoneg advertisement
807 phy->autoneg_advertised &= phy->autoneg_mask;
810 * If autoneg_advertised is zero, we assume it was not defaulted
811 * by the calling code so we set to advertise full capability.
813 if (phy->autoneg_advertised == 0)
814 phy->autoneg_advertised = phy->autoneg_mask;
816 hw_dbg(hw, "Reconfiguring auto-neg advertisement params\n");
817 ret_val = e1000_phy_setup_autoneg(hw);
819 hw_dbg(hw, "Error Setting up Auto-Negotiation\n");
822 hw_dbg(hw, "Restarting Auto-Neg\n");
825 * Restart auto-negotiation by setting the Auto Neg Enable bit and
826 * the Auto Neg Restart bit in the PHY control register.
828 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
832 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
833 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
838 * Does the user want to wait for Auto-Neg to complete here, or
839 * check at a later time (for example, callback routine).
841 if (phy->autoneg_wait_to_complete) {
842 ret_val = e1000_wait_autoneg(hw);
844 hw_dbg(hw, "Error while waiting for "
845 "autoneg to complete\n");
850 hw->mac.get_link_status = 1;
856 * e1000e_setup_copper_link - Configure copper link settings
857 * @hw: pointer to the HW structure
859 * Calls the appropriate function to configure the link for auto-neg or forced
860 * speed and duplex. Then we check for link, once link is established calls
861 * to configure collision distance and flow control are called. If link is
862 * not established, we return -E1000_ERR_PHY (-2).
864 s32 e1000e_setup_copper_link(struct e1000_hw *hw)
869 if (hw->mac.autoneg) {
871 * Setup autoneg and flow control advertisement and perform
874 ret_val = e1000_copper_link_autoneg(hw);
879 * PHY will be set to 10H, 10F, 100H or 100F
880 * depending on user settings.
882 hw_dbg(hw, "Forcing Speed and Duplex\n");
883 ret_val = e1000_phy_force_speed_duplex(hw);
885 hw_dbg(hw, "Error Forcing Speed and Duplex\n");
891 * Check link status. Wait up to 100 microseconds for link to become
894 ret_val = e1000e_phy_has_link_generic(hw,
895 COPPER_LINK_UP_LIMIT,
902 hw_dbg(hw, "Valid link established!!!\n");
903 e1000e_config_collision_dist(hw);
904 ret_val = e1000e_config_fc_after_link_up(hw);
906 hw_dbg(hw, "Unable to establish link!!!\n");
913 * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
914 * @hw: pointer to the HW structure
916 * Calls the PHY setup function to force speed and duplex. Clears the
917 * auto-crossover to force MDI manually. Waits for link and returns
918 * successful if link up is successful, else -E1000_ERR_PHY (-2).
920 s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
922 struct e1000_phy_info *phy = &hw->phy;
927 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
931 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
933 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
938 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
939 * forced whenever speed and duplex are forced.
941 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
945 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
946 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
948 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
952 hw_dbg(hw, "IGP PSCR: %X\n", phy_data);
956 if (phy->autoneg_wait_to_complete) {
957 hw_dbg(hw, "Waiting for forced speed/duplex link on IGP phy.\n");
959 ret_val = e1000e_phy_has_link_generic(hw,
967 hw_dbg(hw, "Link taking longer than expected.\n");
970 ret_val = e1000e_phy_has_link_generic(hw,
982 * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
983 * @hw: pointer to the HW structure
985 * Calls the PHY setup function to force speed and duplex. Clears the
986 * auto-crossover to force MDI manually. Resets the PHY to commit the
987 * changes. If time expires while waiting for link up, we reset the DSP.
988 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
989 * successful completion, else return corresponding error code.
991 s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
993 struct e1000_phy_info *phy = &hw->phy;
999 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1000 * forced whenever speed and duplex are forced.
1002 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1006 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1007 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1011 hw_dbg(hw, "M88E1000 PSCR: %X\n", phy_data);
1013 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_data);
1017 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1019 /* Reset the phy to commit changes. */
1020 phy_data |= MII_CR_RESET;
1022 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_data);
1028 if (phy->autoneg_wait_to_complete) {
1029 hw_dbg(hw, "Waiting for forced speed/duplex link on M88 phy.\n");
1031 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1038 * We didn't get link.
1039 * Reset the DSP and cross our fingers.
1041 ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1045 ret_val = e1000e_phy_reset_dsp(hw);
1051 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1057 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1062 * Resetting the phy means we need to re-force TX_CLK in the
1063 * Extended PHY Specific Control Register to 25MHz clock from
1064 * the reset value of 2.5MHz.
1066 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1067 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1072 * In addition, we must re-enable CRS on Tx for both half and full
1075 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1079 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1080 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1086 * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1087 * @hw: pointer to the HW structure
1088 * @phy_ctrl: pointer to current value of PHY_CONTROL
1090 * Forces speed and duplex on the PHY by doing the following: disable flow
1091 * control, force speed/duplex on the MAC, disable auto speed detection,
1092 * disable auto-negotiation, configure duplex, configure speed, configure
1093 * the collision distance, write configuration to CTRL register. The
1094 * caller must write to the PHY_CONTROL register for these settings to
1097 void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1099 struct e1000_mac_info *mac = &hw->mac;
1102 /* Turn off flow control when forcing speed/duplex */
1103 hw->fc.type = e1000_fc_none;
1105 /* Force speed/duplex on the mac */
1107 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1108 ctrl &= ~E1000_CTRL_SPD_SEL;
1110 /* Disable Auto Speed Detection */
1111 ctrl &= ~E1000_CTRL_ASDE;
1113 /* Disable autoneg on the phy */
1114 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1116 /* Forcing Full or Half Duplex? */
1117 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1118 ctrl &= ~E1000_CTRL_FD;
1119 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1120 hw_dbg(hw, "Half Duplex\n");
1122 ctrl |= E1000_CTRL_FD;
1123 *phy_ctrl |= MII_CR_FULL_DUPLEX;
1124 hw_dbg(hw, "Full Duplex\n");
1127 /* Forcing 10mb or 100mb? */
1128 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1129 ctrl |= E1000_CTRL_SPD_100;
1130 *phy_ctrl |= MII_CR_SPEED_100;
1131 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1132 hw_dbg(hw, "Forcing 100mb\n");
1134 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1135 *phy_ctrl |= MII_CR_SPEED_10;
1136 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1137 hw_dbg(hw, "Forcing 10mb\n");
1140 e1000e_config_collision_dist(hw);
1146 * e1000e_set_d3_lplu_state - Sets low power link up state for D3
1147 * @hw: pointer to the HW structure
1148 * @active: boolean used to enable/disable lplu
1150 * Success returns 0, Failure returns 1
1152 * The low power link up (lplu) state is set to the power management level D3
1153 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1154 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1155 * is used during Dx states where the power conservation is most important.
1156 * During driver activity, SmartSpeed should be enabled so performance is
1159 s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1161 struct e1000_phy_info *phy = &hw->phy;
1165 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1170 data &= ~IGP02E1000_PM_D3_LPLU;
1171 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1175 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1176 * during Dx states where the power conservation is most
1177 * important. During driver activity we should enable
1178 * SmartSpeed, so performance is maintained.
1180 if (phy->smart_speed == e1000_smart_speed_on) {
1181 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1186 data |= IGP01E1000_PSCFR_SMART_SPEED;
1187 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1191 } else if (phy->smart_speed == e1000_smart_speed_off) {
1192 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1197 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1198 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1203 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1204 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1205 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1206 data |= IGP02E1000_PM_D3_LPLU;
1207 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1211 /* When LPLU is enabled, we should disable SmartSpeed */
1212 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1216 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1217 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1224 * e1000e_check_downshift - Checks whether a downshift in speed occurred
1225 * @hw: pointer to the HW structure
1227 * Success returns 0, Failure returns 1
1229 * A downshift is detected by querying the PHY link health.
1231 s32 e1000e_check_downshift(struct e1000_hw *hw)
1233 struct e1000_phy_info *phy = &hw->phy;
1235 u16 phy_data, offset, mask;
1237 switch (phy->type) {
1239 case e1000_phy_gg82563:
1240 offset = M88E1000_PHY_SPEC_STATUS;
1241 mask = M88E1000_PSSR_DOWNSHIFT;
1243 case e1000_phy_igp_2:
1244 case e1000_phy_igp_3:
1245 offset = IGP01E1000_PHY_LINK_HEALTH;
1246 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1249 /* speed downshift not supported */
1250 phy->speed_downgraded = 0;
1254 ret_val = e1e_rphy(hw, offset, &phy_data);
1257 phy->speed_downgraded = (phy_data & mask);
1263 * e1000_check_polarity_m88 - Checks the polarity.
1264 * @hw: pointer to the HW structure
1266 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1268 * Polarity is determined based on the PHY specific status register.
1270 static s32 e1000_check_polarity_m88(struct e1000_hw *hw)
1272 struct e1000_phy_info *phy = &hw->phy;
1276 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1279 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1280 ? e1000_rev_polarity_reversed
1281 : e1000_rev_polarity_normal;
1287 * e1000_check_polarity_igp - Checks the polarity.
1288 * @hw: pointer to the HW structure
1290 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1292 * Polarity is determined based on the PHY port status register, and the
1293 * current speed (since there is no polarity at 100Mbps).
1295 static s32 e1000_check_polarity_igp(struct e1000_hw *hw)
1297 struct e1000_phy_info *phy = &hw->phy;
1299 u16 data, offset, mask;
1302 * Polarity is determined based on the speed of
1305 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1309 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1310 IGP01E1000_PSSR_SPEED_1000MBPS) {
1311 offset = IGP01E1000_PHY_PCS_INIT_REG;
1312 mask = IGP01E1000_PHY_POLARITY_MASK;
1315 * This really only applies to 10Mbps since
1316 * there is no polarity for 100Mbps (always 0).
1318 offset = IGP01E1000_PHY_PORT_STATUS;
1319 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1322 ret_val = e1e_rphy(hw, offset, &data);
1325 phy->cable_polarity = (data & mask)
1326 ? e1000_rev_polarity_reversed
1327 : e1000_rev_polarity_normal;
1333 * e1000_wait_autoneg - Wait for auto-neg completion
1334 * @hw: pointer to the HW structure
1336 * Waits for auto-negotiation to complete or for the auto-negotiation time
1337 * limit to expire, which ever happens first.
1339 static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1344 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1345 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1346 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1349 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1352 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1358 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1365 * e1000e_phy_has_link_generic - Polls PHY for link
1366 * @hw: pointer to the HW structure
1367 * @iterations: number of times to poll for link
1368 * @usec_interval: delay between polling attempts
1369 * @success: pointer to whether polling was successful or not
1371 * Polls the PHY status register for link, 'iterations' number of times.
1373 s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1374 u32 usec_interval, bool *success)
1379 for (i = 0; i < iterations; i++) {
1381 * Some PHYs require the PHY_STATUS register to be read
1382 * twice due to the link bit being sticky. No harm doing
1383 * it across the board.
1385 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1388 ret_val = e1e_rphy(hw, PHY_STATUS, &phy_status);
1391 if (phy_status & MII_SR_LINK_STATUS)
1393 if (usec_interval >= 1000)
1394 mdelay(usec_interval/1000);
1396 udelay(usec_interval);
1399 *success = (i < iterations);
1405 * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1406 * @hw: pointer to the HW structure
1408 * Reads the PHY specific status register to retrieve the cable length
1409 * information. The cable length is determined by averaging the minimum and
1410 * maximum values to get the "average" cable length. The m88 PHY has four
1411 * possible cable length values, which are:
1412 * Register Value Cable Length
1416 * 3 110 - 140 meters
1419 s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1421 struct e1000_phy_info *phy = &hw->phy;
1423 u16 phy_data, index;
1425 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1429 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1430 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1431 phy->min_cable_length = e1000_m88_cable_length_table[index];
1432 phy->max_cable_length = e1000_m88_cable_length_table[index+1];
1434 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1440 * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1441 * @hw: pointer to the HW structure
1443 * The automatic gain control (agc) normalizes the amplitude of the
1444 * received signal, adjusting for the attenuation produced by the
1445 * cable. By reading the AGC registers, which represent the
1446 * combination of course and fine gain value, the value can be put
1447 * into a lookup table to obtain the approximate cable length
1450 s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1452 struct e1000_phy_info *phy = &hw->phy;
1454 u16 phy_data, i, agc_value = 0;
1455 u16 cur_agc_index, max_agc_index = 0;
1456 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1457 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1458 {IGP02E1000_PHY_AGC_A,
1459 IGP02E1000_PHY_AGC_B,
1460 IGP02E1000_PHY_AGC_C,
1461 IGP02E1000_PHY_AGC_D};
1463 /* Read the AGC registers for all channels */
1464 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1465 ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1470 * Getting bits 15:9, which represent the combination of
1471 * course and fine gain values. The result is a number
1472 * that can be put into the lookup table to obtain the
1473 * approximate cable length.
1475 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1476 IGP02E1000_AGC_LENGTH_MASK;
1478 /* Array index bound check. */
1479 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1480 (cur_agc_index == 0))
1481 return -E1000_ERR_PHY;
1483 /* Remove min & max AGC values from calculation. */
1484 if (e1000_igp_2_cable_length_table[min_agc_index] >
1485 e1000_igp_2_cable_length_table[cur_agc_index])
1486 min_agc_index = cur_agc_index;
1487 if (e1000_igp_2_cable_length_table[max_agc_index] <
1488 e1000_igp_2_cable_length_table[cur_agc_index])
1489 max_agc_index = cur_agc_index;
1491 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1494 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1495 e1000_igp_2_cable_length_table[max_agc_index]);
1496 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1498 /* Calculate cable length with the error range of +/- 10 meters. */
1499 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1500 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1501 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1503 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1509 * e1000e_get_phy_info_m88 - Retrieve PHY information
1510 * @hw: pointer to the HW structure
1512 * Valid for only copper links. Read the PHY status register (sticky read)
1513 * to verify that link is up. Read the PHY special control register to
1514 * determine the polarity and 10base-T extended distance. Read the PHY
1515 * special status register to determine MDI/MDIx and current speed. If
1516 * speed is 1000, then determine cable length, local and remote receiver.
1518 s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1520 struct e1000_phy_info *phy = &hw->phy;
1525 if (hw->phy.media_type != e1000_media_type_copper) {
1526 hw_dbg(hw, "Phy info is only valid for copper media\n");
1527 return -E1000_ERR_CONFIG;
1530 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1535 hw_dbg(hw, "Phy info is only valid if link is up\n");
1536 return -E1000_ERR_CONFIG;
1539 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1543 phy->polarity_correction = (phy_data &
1544 M88E1000_PSCR_POLARITY_REVERSAL);
1546 ret_val = e1000_check_polarity_m88(hw);
1550 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1554 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX);
1556 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
1557 ret_val = e1000_get_cable_length(hw);
1561 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
1565 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1566 ? e1000_1000t_rx_status_ok
1567 : e1000_1000t_rx_status_not_ok;
1569 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1570 ? e1000_1000t_rx_status_ok
1571 : e1000_1000t_rx_status_not_ok;
1573 /* Set values to "undefined" */
1574 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1575 phy->local_rx = e1000_1000t_rx_status_undefined;
1576 phy->remote_rx = e1000_1000t_rx_status_undefined;
1583 * e1000e_get_phy_info_igp - Retrieve igp PHY information
1584 * @hw: pointer to the HW structure
1586 * Read PHY status to determine if link is up. If link is up, then
1587 * set/determine 10base-T extended distance and polarity correction. Read
1588 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1589 * determine on the cable length, local and remote receiver.
1591 s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
1593 struct e1000_phy_info *phy = &hw->phy;
1598 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1603 hw_dbg(hw, "Phy info is only valid if link is up\n");
1604 return -E1000_ERR_CONFIG;
1607 phy->polarity_correction = 1;
1609 ret_val = e1000_check_polarity_igp(hw);
1613 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1617 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX);
1619 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1620 IGP01E1000_PSSR_SPEED_1000MBPS) {
1621 ret_val = e1000_get_cable_length(hw);
1625 ret_val = e1e_rphy(hw, PHY_1000T_STATUS, &data);
1629 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1630 ? e1000_1000t_rx_status_ok
1631 : e1000_1000t_rx_status_not_ok;
1633 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1634 ? e1000_1000t_rx_status_ok
1635 : e1000_1000t_rx_status_not_ok;
1637 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1638 phy->local_rx = e1000_1000t_rx_status_undefined;
1639 phy->remote_rx = e1000_1000t_rx_status_undefined;
1646 * e1000e_phy_sw_reset - PHY software reset
1647 * @hw: pointer to the HW structure
1649 * Does a software reset of the PHY by reading the PHY control register and
1650 * setting/write the control register reset bit to the PHY.
1652 s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
1657 ret_val = e1e_rphy(hw, PHY_CONTROL, &phy_ctrl);
1661 phy_ctrl |= MII_CR_RESET;
1662 ret_val = e1e_wphy(hw, PHY_CONTROL, phy_ctrl);
1672 * e1000e_phy_hw_reset_generic - PHY hardware reset
1673 * @hw: pointer to the HW structure
1675 * Verify the reset block is not blocking us from resetting. Acquire
1676 * semaphore (if necessary) and read/set/write the device control reset
1677 * bit in the PHY. Wait the appropriate delay time for the device to
1678 * reset and release the semaphore (if necessary).
1680 s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
1682 struct e1000_phy_info *phy = &hw->phy;
1686 ret_val = e1000_check_reset_block(hw);
1690 ret_val = phy->ops.acquire_phy(hw);
1695 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
1698 udelay(phy->reset_delay_us);
1705 phy->ops.release_phy(hw);
1707 return e1000_get_phy_cfg_done(hw);
1711 * e1000e_get_cfg_done - Generic configuration done
1712 * @hw: pointer to the HW structure
1714 * Generic function to wait 10 milli-seconds for configuration to complete
1715 * and return success.
1717 s32 e1000e_get_cfg_done(struct e1000_hw *hw)
1723 /* Internal function pointers */
1726 * e1000_get_phy_cfg_done - Generic PHY configuration done
1727 * @hw: pointer to the HW structure
1729 * Return success if silicon family did not implement a family specific
1730 * get_cfg_done function.
1732 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
1734 if (hw->phy.ops.get_cfg_done)
1735 return hw->phy.ops.get_cfg_done(hw);
1741 * e1000_phy_force_speed_duplex - Generic force PHY speed/duplex
1742 * @hw: pointer to the HW structure
1744 * When the silicon family has not implemented a forced speed/duplex
1745 * function for the PHY, simply return 0.
1747 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1749 if (hw->phy.ops.force_speed_duplex)
1750 return hw->phy.ops.force_speed_duplex(hw);
1756 * e1000e_get_phy_type_from_id - Get PHY type from id
1757 * @phy_id: phy_id read from the phy
1759 * Returns the phy type from the id.
1761 enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
1763 enum e1000_phy_type phy_type = e1000_phy_unknown;
1766 case M88E1000_I_PHY_ID:
1767 case M88E1000_E_PHY_ID:
1768 case M88E1111_I_PHY_ID:
1769 case M88E1011_I_PHY_ID:
1770 phy_type = e1000_phy_m88;
1772 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
1773 phy_type = e1000_phy_igp_2;
1775 case GG82563_E_PHY_ID:
1776 phy_type = e1000_phy_gg82563;
1778 case IGP03E1000_E_PHY_ID:
1779 phy_type = e1000_phy_igp_3;
1782 case IFE_PLUS_E_PHY_ID:
1783 case IFE_C_E_PHY_ID:
1784 phy_type = e1000_phy_ife;
1786 case BME1000_E_PHY_ID:
1787 case BME1000_E_PHY_ID_R2:
1788 phy_type = e1000_phy_bm;
1791 phy_type = e1000_phy_unknown;
1798 * e1000e_determine_phy_address - Determines PHY address.
1799 * @hw: pointer to the HW structure
1801 * This uses a trial and error method to loop through possible PHY
1802 * addresses. It tests each by reading the PHY ID registers and
1803 * checking for a match.
1805 s32 e1000e_determine_phy_address(struct e1000_hw *hw)
1807 s32 ret_val = -E1000_ERR_PHY_TYPE;
1810 enum e1000_phy_type phy_type = e1000_phy_unknown;
1813 for (phy_addr = 0; phy_addr < 4; phy_addr++) {
1814 hw->phy.addr = phy_addr;
1815 e1000e_get_phy_id(hw);
1816 phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
1819 * If phy_type is valid, break - we found our
1822 if (phy_type != e1000_phy_unknown) {
1828 } while ((ret_val != 0) && (i < 100));
1834 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
1835 * @page: page to access
1837 * Returns the phy address for the page requested.
1839 static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
1843 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
1850 * e1000e_write_phy_reg_bm - Write BM PHY register
1851 * @hw: pointer to the HW structure
1852 * @offset: register offset to write to
1853 * @data: data to write at register offset
1855 * Acquires semaphore, if necessary, then writes the data to PHY register
1856 * at the offset. Release any acquired semaphores before exiting.
1858 s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
1861 u32 page_select = 0;
1862 u32 page = offset >> IGP_PAGE_SHIFT;
1865 /* Page 800 works differently than the rest so it has its own func */
1866 if (page == BM_WUC_PAGE) {
1867 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
1872 ret_val = hw->phy.ops.acquire_phy(hw);
1876 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
1878 if (offset > MAX_PHY_MULTI_PAGE_REG) {
1880 * Page select is register 31 for phy address 1 and 22 for
1881 * phy address 2 and 3. Page select is shifted only for
1884 if (hw->phy.addr == 1) {
1885 page_shift = IGP_PAGE_SHIFT;
1886 page_select = IGP01E1000_PHY_PAGE_SELECT;
1889 page_select = BM_PHY_PAGE_SELECT;
1892 /* Page is shifted left, PHY expects (page x 32) */
1893 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
1894 (page << page_shift));
1896 hw->phy.ops.release_phy(hw);
1901 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
1904 hw->phy.ops.release_phy(hw);
1911 * e1000e_read_phy_reg_bm - Read BM PHY register
1912 * @hw: pointer to the HW structure
1913 * @offset: register offset to be read
1914 * @data: pointer to the read data
1916 * Acquires semaphore, if necessary, then reads the PHY register at offset
1917 * and storing the retrieved information in data. Release any acquired
1918 * semaphores before exiting.
1920 s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
1923 u32 page_select = 0;
1924 u32 page = offset >> IGP_PAGE_SHIFT;
1927 /* Page 800 works differently than the rest so it has its own func */
1928 if (page == BM_WUC_PAGE) {
1929 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
1934 ret_val = hw->phy.ops.acquire_phy(hw);
1938 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
1940 if (offset > MAX_PHY_MULTI_PAGE_REG) {
1942 * Page select is register 31 for phy address 1 and 22 for
1943 * phy address 2 and 3. Page select is shifted only for
1946 if (hw->phy.addr == 1) {
1947 page_shift = IGP_PAGE_SHIFT;
1948 page_select = IGP01E1000_PHY_PAGE_SELECT;
1951 page_select = BM_PHY_PAGE_SELECT;
1954 /* Page is shifted left, PHY expects (page x 32) */
1955 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
1956 (page << page_shift));
1958 hw->phy.ops.release_phy(hw);
1963 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
1965 hw->phy.ops.release_phy(hw);
1972 * e1000_access_phy_wakeup_reg_bm - Read BM PHY wakeup register
1973 * @hw: pointer to the HW structure
1974 * @offset: register offset to be read or written
1975 * @data: pointer to the data to read or write
1976 * @read: determines if operation is read or write
1978 * Acquires semaphore, if necessary, then reads the PHY register at offset
1979 * and storing the retrieved information in data. Release any acquired
1980 * semaphores before exiting. Note that procedure to read the wakeup
1981 * registers are different. It works as such:
1982 * 1) Set page 769, register 17, bit 2 = 1
1983 * 2) Set page to 800 for host (801 if we were manageability)
1984 * 3) Write the address using the address opcode (0x11)
1985 * 4) Read or write the data using the data opcode (0x12)
1986 * 5) Restore 769_17.2 to its original value
1988 static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
1989 u16 *data, bool read)
1992 u16 reg = ((u16)offset) & PHY_REG_MASK;
1994 u8 phy_acquired = 1;
1997 ret_val = hw->phy.ops.acquire_phy(hw);
2003 /* All operations in this function are phy address 1 */
2007 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2008 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
2010 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &phy_reg);
2014 /* First clear bit 4 to avoid a power state change */
2015 phy_reg &= ~(BM_WUC_HOST_WU_BIT);
2016 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2020 /* Write bit 2 = 1, and clear bit 4 to 769_17 */
2021 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG,
2022 phy_reg | BM_WUC_ENABLE_BIT);
2026 /* Select page 800 */
2027 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2028 (BM_WUC_PAGE << IGP_PAGE_SHIFT));
2030 /* Write the page 800 offset value using opcode 0x11 */
2031 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
2036 /* Read the page 800 value using opcode 0x12 */
2037 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2040 /* Read the page 800 value using opcode 0x12 */
2041 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2049 * Restore 769_17.2 to its original value
2052 e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2053 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
2055 /* Clear 769_17.2 */
2056 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2059 if (phy_acquired == 1)
2060 hw->phy.ops.release_phy(hw);
2065 * e1000e_commit_phy - Soft PHY reset
2066 * @hw: pointer to the HW structure
2068 * Performs a soft PHY reset on those that apply. This is a function pointer
2069 * entry point called by drivers.
2071 s32 e1000e_commit_phy(struct e1000_hw *hw)
2073 if (hw->phy.ops.commit_phy)
2074 return hw->phy.ops.commit_phy(hw);
2080 * e1000_set_d0_lplu_state - Sets low power link up state for D0
2081 * @hw: pointer to the HW structure
2082 * @active: boolean used to enable/disable lplu
2084 * Success returns 0, Failure returns 1
2086 * The low power link up (lplu) state is set to the power management level D0
2087 * and SmartSpeed is disabled when active is true, else clear lplu for D0
2088 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
2089 * is used during Dx states where the power conservation is most important.
2090 * During driver activity, SmartSpeed should be enabled so performance is
2091 * maintained. This is a function pointer entry point called by drivers.
2093 static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2095 if (hw->phy.ops.set_d0_lplu_state)
2096 return hw->phy.ops.set_d0_lplu_state(hw, active);