mm-only debug patch...
[mmotm.git] / drivers / net / igb / e1000_phy.c
blob83b706c460b3e639ba188268da438bb6cf473843
1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2009 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 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include <linux/if_ether.h>
29 #include <linux/delay.h>
31 #include "e1000_mac.h"
32 #include "e1000_phy.h"
34 static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
35 static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
36 u16 *phy_ctrl);
37 static s32 igb_wait_autoneg(struct e1000_hw *hw);
39 /* Cable length tables */
40 static const u16 e1000_m88_cable_length_table[] =
41 { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
42 #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
43 (sizeof(e1000_m88_cable_length_table) / \
44 sizeof(e1000_m88_cable_length_table[0]))
46 static const u16 e1000_igp_2_cable_length_table[] =
47 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
48 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
49 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
50 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
51 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
52 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
53 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
54 104, 109, 114, 118, 121, 124};
55 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
56 (sizeof(e1000_igp_2_cable_length_table) / \
57 sizeof(e1000_igp_2_cable_length_table[0]))
59 /**
60 * igb_check_reset_block - Check if PHY reset is blocked
61 * @hw: pointer to the HW structure
63 * Read the PHY management control register and check whether a PHY reset
64 * is blocked. If a reset is not blocked return 0, otherwise
65 * return E1000_BLK_PHY_RESET (12).
66 **/
67 s32 igb_check_reset_block(struct e1000_hw *hw)
69 u32 manc;
71 manc = rd32(E1000_MANC);
73 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
74 E1000_BLK_PHY_RESET : 0;
77 /**
78 * igb_get_phy_id - Retrieve the PHY ID and revision
79 * @hw: pointer to the HW structure
81 * Reads the PHY registers and stores the PHY ID and possibly the PHY
82 * revision in the hardware structure.
83 **/
84 s32 igb_get_phy_id(struct e1000_hw *hw)
86 struct e1000_phy_info *phy = &hw->phy;
87 s32 ret_val = 0;
88 u16 phy_id;
90 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
91 if (ret_val)
92 goto out;
94 phy->id = (u32)(phy_id << 16);
95 udelay(20);
96 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
97 if (ret_val)
98 goto out;
100 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
101 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
103 out:
104 return ret_val;
108 * igb_phy_reset_dsp - Reset PHY DSP
109 * @hw: pointer to the HW structure
111 * Reset the digital signal processor.
113 static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
115 s32 ret_val = 0;
117 if (!(hw->phy.ops.write_reg))
118 goto out;
120 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
121 if (ret_val)
122 goto out;
124 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
126 out:
127 return ret_val;
131 * igb_read_phy_reg_mdic - Read MDI control register
132 * @hw: pointer to the HW structure
133 * @offset: register offset to be read
134 * @data: pointer to the read data
136 * Reads the MDI control regsiter in the PHY at offset and stores the
137 * information read to data.
139 static s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
141 struct e1000_phy_info *phy = &hw->phy;
142 u32 i, mdic = 0;
143 s32 ret_val = 0;
145 if (offset > MAX_PHY_REG_ADDRESS) {
146 hw_dbg("PHY Address %d is out of range\n", offset);
147 ret_val = -E1000_ERR_PARAM;
148 goto out;
152 * Set up Op-code, Phy Address, and register offset in the MDI
153 * Control register. The MAC will take care of interfacing with the
154 * PHY to retrieve the desired data.
156 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
157 (phy->addr << E1000_MDIC_PHY_SHIFT) |
158 (E1000_MDIC_OP_READ));
160 wr32(E1000_MDIC, mdic);
163 * Poll the ready bit to see if the MDI read completed
164 * Increasing the time out as testing showed failures with
165 * the lower time out
167 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
168 udelay(50);
169 mdic = rd32(E1000_MDIC);
170 if (mdic & E1000_MDIC_READY)
171 break;
173 if (!(mdic & E1000_MDIC_READY)) {
174 hw_dbg("MDI Read did not complete\n");
175 ret_val = -E1000_ERR_PHY;
176 goto out;
178 if (mdic & E1000_MDIC_ERROR) {
179 hw_dbg("MDI Error\n");
180 ret_val = -E1000_ERR_PHY;
181 goto out;
183 *data = (u16) mdic;
185 out:
186 return ret_val;
190 * igb_write_phy_reg_mdic - Write MDI control register
191 * @hw: pointer to the HW structure
192 * @offset: register offset to write to
193 * @data: data to write to register at offset
195 * Writes data to MDI control register in the PHY at offset.
197 static s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
199 struct e1000_phy_info *phy = &hw->phy;
200 u32 i, mdic = 0;
201 s32 ret_val = 0;
203 if (offset > MAX_PHY_REG_ADDRESS) {
204 hw_dbg("PHY Address %d is out of range\n", offset);
205 ret_val = -E1000_ERR_PARAM;
206 goto out;
210 * Set up Op-code, Phy Address, and register offset in the MDI
211 * Control register. The MAC will take care of interfacing with the
212 * PHY to retrieve the desired data.
214 mdic = (((u32)data) |
215 (offset << E1000_MDIC_REG_SHIFT) |
216 (phy->addr << E1000_MDIC_PHY_SHIFT) |
217 (E1000_MDIC_OP_WRITE));
219 wr32(E1000_MDIC, mdic);
222 * Poll the ready bit to see if the MDI read completed
223 * Increasing the time out as testing showed failures with
224 * the lower time out
226 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
227 udelay(50);
228 mdic = rd32(E1000_MDIC);
229 if (mdic & E1000_MDIC_READY)
230 break;
232 if (!(mdic & E1000_MDIC_READY)) {
233 hw_dbg("MDI Write did not complete\n");
234 ret_val = -E1000_ERR_PHY;
235 goto out;
237 if (mdic & E1000_MDIC_ERROR) {
238 hw_dbg("MDI Error\n");
239 ret_val = -E1000_ERR_PHY;
240 goto out;
243 out:
244 return ret_val;
248 * igb_read_phy_reg_i2c - Read PHY register using i2c
249 * @hw: pointer to the HW structure
250 * @offset: register offset to be read
251 * @data: pointer to the read data
253 * Reads the PHY register at offset using the i2c interface and stores the
254 * retrieved information in data.
256 s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
258 struct e1000_phy_info *phy = &hw->phy;
259 u32 i, i2ccmd = 0;
263 * Set up Op-code, Phy Address, and register address in the I2CCMD
264 * register. The MAC will take care of interfacing with the
265 * PHY to retrieve the desired data.
267 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
268 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
269 (E1000_I2CCMD_OPCODE_READ));
271 wr32(E1000_I2CCMD, i2ccmd);
273 /* Poll the ready bit to see if the I2C read completed */
274 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
275 udelay(50);
276 i2ccmd = rd32(E1000_I2CCMD);
277 if (i2ccmd & E1000_I2CCMD_READY)
278 break;
280 if (!(i2ccmd & E1000_I2CCMD_READY)) {
281 hw_dbg("I2CCMD Read did not complete\n");
282 return -E1000_ERR_PHY;
284 if (i2ccmd & E1000_I2CCMD_ERROR) {
285 hw_dbg("I2CCMD Error bit set\n");
286 return -E1000_ERR_PHY;
289 /* Need to byte-swap the 16-bit value. */
290 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
292 return 0;
296 * igb_write_phy_reg_i2c - Write PHY register using i2c
297 * @hw: pointer to the HW structure
298 * @offset: register offset to write to
299 * @data: data to write at register offset
301 * Writes the data to PHY register at the offset using the i2c interface.
303 s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
305 struct e1000_phy_info *phy = &hw->phy;
306 u32 i, i2ccmd = 0;
307 u16 phy_data_swapped;
310 /* Swap the data bytes for the I2C interface */
311 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
314 * Set up Op-code, Phy Address, and register address in the I2CCMD
315 * register. The MAC will take care of interfacing with the
316 * PHY to retrieve the desired data.
318 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
319 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
320 E1000_I2CCMD_OPCODE_WRITE |
321 phy_data_swapped);
323 wr32(E1000_I2CCMD, i2ccmd);
325 /* Poll the ready bit to see if the I2C read completed */
326 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
327 udelay(50);
328 i2ccmd = rd32(E1000_I2CCMD);
329 if (i2ccmd & E1000_I2CCMD_READY)
330 break;
332 if (!(i2ccmd & E1000_I2CCMD_READY)) {
333 hw_dbg("I2CCMD Write did not complete\n");
334 return -E1000_ERR_PHY;
336 if (i2ccmd & E1000_I2CCMD_ERROR) {
337 hw_dbg("I2CCMD Error bit set\n");
338 return -E1000_ERR_PHY;
341 return 0;
345 * igb_read_phy_reg_igp - Read igp PHY register
346 * @hw: pointer to the HW structure
347 * @offset: register offset to be read
348 * @data: pointer to the read data
350 * Acquires semaphore, if necessary, then reads the PHY register at offset
351 * and storing the retrieved information in data. Release any acquired
352 * semaphores before exiting.
354 s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
356 s32 ret_val = 0;
358 if (!(hw->phy.ops.acquire))
359 goto out;
361 ret_val = hw->phy.ops.acquire(hw);
362 if (ret_val)
363 goto out;
365 if (offset > MAX_PHY_MULTI_PAGE_REG) {
366 ret_val = igb_write_phy_reg_mdic(hw,
367 IGP01E1000_PHY_PAGE_SELECT,
368 (u16)offset);
369 if (ret_val) {
370 hw->phy.ops.release(hw);
371 goto out;
375 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
376 data);
378 hw->phy.ops.release(hw);
380 out:
381 return ret_val;
385 * igb_write_phy_reg_igp - Write igp PHY register
386 * @hw: pointer to the HW structure
387 * @offset: register offset to write to
388 * @data: data to write at register offset
390 * Acquires semaphore, if necessary, then writes the data to PHY register
391 * at the offset. Release any acquired semaphores before exiting.
393 s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
395 s32 ret_val = 0;
397 if (!(hw->phy.ops.acquire))
398 goto out;
400 ret_val = hw->phy.ops.acquire(hw);
401 if (ret_val)
402 goto out;
404 if (offset > MAX_PHY_MULTI_PAGE_REG) {
405 ret_val = igb_write_phy_reg_mdic(hw,
406 IGP01E1000_PHY_PAGE_SELECT,
407 (u16)offset);
408 if (ret_val) {
409 hw->phy.ops.release(hw);
410 goto out;
414 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
415 data);
417 hw->phy.ops.release(hw);
419 out:
420 return ret_val;
424 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
425 * @hw: pointer to the HW structure
427 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
428 * and downshift values are set also.
430 s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
432 struct e1000_phy_info *phy = &hw->phy;
433 s32 ret_val;
434 u16 phy_data;
436 if (phy->reset_disable) {
437 ret_val = 0;
438 goto out;
441 /* Enable CRS on TX. This must be set for half-duplex operation. */
442 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
443 if (ret_val)
444 goto out;
446 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
449 * Options:
450 * MDI/MDI-X = 0 (default)
451 * 0 - Auto for all speeds
452 * 1 - MDI mode
453 * 2 - MDI-X mode
454 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
456 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
458 switch (phy->mdix) {
459 case 1:
460 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
461 break;
462 case 2:
463 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
464 break;
465 case 3:
466 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
467 break;
468 case 0:
469 default:
470 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
471 break;
475 * Options:
476 * disable_polarity_correction = 0 (default)
477 * Automatic Correction for Reversed Cable Polarity
478 * 0 - Disabled
479 * 1 - Enabled
481 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
482 if (phy->disable_polarity_correction == 1)
483 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
485 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
486 if (ret_val)
487 goto out;
489 if (phy->revision < E1000_REVISION_4) {
491 * Force TX_CLK in the Extended PHY Specific Control Register
492 * to 25MHz clock.
494 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
495 &phy_data);
496 if (ret_val)
497 goto out;
499 phy_data |= M88E1000_EPSCR_TX_CLK_25;
501 if ((phy->revision == E1000_REVISION_2) &&
502 (phy->id == M88E1111_I_PHY_ID)) {
503 /* 82573L PHY - set the downshift counter to 5x. */
504 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
505 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
506 } else {
507 /* Configure Master and Slave downshift values */
508 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
509 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
510 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
511 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
513 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
514 phy_data);
515 if (ret_val)
516 goto out;
519 /* Commit the changes. */
520 ret_val = igb_phy_sw_reset(hw);
521 if (ret_val) {
522 hw_dbg("Error committing the PHY changes\n");
523 goto out;
526 out:
527 return ret_val;
531 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
532 * @hw: pointer to the HW structure
534 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
535 * igp PHY's.
537 s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
539 struct e1000_phy_info *phy = &hw->phy;
540 s32 ret_val;
541 u16 data;
543 if (phy->reset_disable) {
544 ret_val = 0;
545 goto out;
548 ret_val = phy->ops.reset(hw);
549 if (ret_val) {
550 hw_dbg("Error resetting the PHY.\n");
551 goto out;
555 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
556 * timeout issues when LFS is enabled.
558 msleep(100);
561 * The NVM settings will configure LPLU in D3 for
562 * non-IGP1 PHYs.
564 if (phy->type == e1000_phy_igp) {
565 /* disable lplu d3 during driver init */
566 if (phy->ops.set_d3_lplu_state)
567 ret_val = phy->ops.set_d3_lplu_state(hw, false);
568 if (ret_val) {
569 hw_dbg("Error Disabling LPLU D3\n");
570 goto out;
574 /* disable lplu d0 during driver init */
575 ret_val = phy->ops.set_d0_lplu_state(hw, false);
576 if (ret_val) {
577 hw_dbg("Error Disabling LPLU D0\n");
578 goto out;
580 /* Configure mdi-mdix settings */
581 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
582 if (ret_val)
583 goto out;
585 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
587 switch (phy->mdix) {
588 case 1:
589 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
590 break;
591 case 2:
592 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
593 break;
594 case 0:
595 default:
596 data |= IGP01E1000_PSCR_AUTO_MDIX;
597 break;
599 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
600 if (ret_val)
601 goto out;
603 /* set auto-master slave resolution settings */
604 if (hw->mac.autoneg) {
606 * when autonegotiation advertisement is only 1000Mbps then we
607 * should disable SmartSpeed and enable Auto MasterSlave
608 * resolution as hardware default.
610 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
611 /* Disable SmartSpeed */
612 ret_val = phy->ops.read_reg(hw,
613 IGP01E1000_PHY_PORT_CONFIG,
614 &data);
615 if (ret_val)
616 goto out;
618 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
619 ret_val = phy->ops.write_reg(hw,
620 IGP01E1000_PHY_PORT_CONFIG,
621 data);
622 if (ret_val)
623 goto out;
625 /* Set auto Master/Slave resolution process */
626 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
627 if (ret_val)
628 goto out;
630 data &= ~CR_1000T_MS_ENABLE;
631 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
632 if (ret_val)
633 goto out;
636 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
637 if (ret_val)
638 goto out;
640 /* load defaults for future use */
641 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
642 ((data & CR_1000T_MS_VALUE) ?
643 e1000_ms_force_master :
644 e1000_ms_force_slave) :
645 e1000_ms_auto;
647 switch (phy->ms_type) {
648 case e1000_ms_force_master:
649 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
650 break;
651 case e1000_ms_force_slave:
652 data |= CR_1000T_MS_ENABLE;
653 data &= ~(CR_1000T_MS_VALUE);
654 break;
655 case e1000_ms_auto:
656 data &= ~CR_1000T_MS_ENABLE;
657 default:
658 break;
660 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
661 if (ret_val)
662 goto out;
665 out:
666 return ret_val;
670 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
671 * @hw: pointer to the HW structure
673 * Performs initial bounds checking on autoneg advertisement parameter, then
674 * configure to advertise the full capability. Setup the PHY to autoneg
675 * and restart the negotiation process between the link partner. If
676 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
678 static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
680 struct e1000_phy_info *phy = &hw->phy;
681 s32 ret_val;
682 u16 phy_ctrl;
685 * Perform some bounds checking on the autoneg advertisement
686 * parameter.
688 phy->autoneg_advertised &= phy->autoneg_mask;
691 * If autoneg_advertised is zero, we assume it was not defaulted
692 * by the calling code so we set to advertise full capability.
694 if (phy->autoneg_advertised == 0)
695 phy->autoneg_advertised = phy->autoneg_mask;
697 hw_dbg("Reconfiguring auto-neg advertisement params\n");
698 ret_val = igb_phy_setup_autoneg(hw);
699 if (ret_val) {
700 hw_dbg("Error Setting up Auto-Negotiation\n");
701 goto out;
703 hw_dbg("Restarting Auto-Neg\n");
706 * Restart auto-negotiation by setting the Auto Neg Enable bit and
707 * the Auto Neg Restart bit in the PHY control register.
709 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
710 if (ret_val)
711 goto out;
713 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
714 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
715 if (ret_val)
716 goto out;
719 * Does the user want to wait for Auto-Neg to complete here, or
720 * check at a later time (for example, callback routine).
722 if (phy->autoneg_wait_to_complete) {
723 ret_val = igb_wait_autoneg(hw);
724 if (ret_val) {
725 hw_dbg("Error while waiting for "
726 "autoneg to complete\n");
727 goto out;
731 hw->mac.get_link_status = true;
733 out:
734 return ret_val;
738 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
739 * @hw: pointer to the HW structure
741 * Reads the MII auto-neg advertisement register and/or the 1000T control
742 * register and if the PHY is already setup for auto-negotiation, then
743 * return successful. Otherwise, setup advertisement and flow control to
744 * the appropriate values for the wanted auto-negotiation.
746 static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
748 struct e1000_phy_info *phy = &hw->phy;
749 s32 ret_val;
750 u16 mii_autoneg_adv_reg;
751 u16 mii_1000t_ctrl_reg = 0;
753 phy->autoneg_advertised &= phy->autoneg_mask;
755 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
756 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
757 if (ret_val)
758 goto out;
760 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
761 /* Read the MII 1000Base-T Control Register (Address 9). */
762 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
763 &mii_1000t_ctrl_reg);
764 if (ret_val)
765 goto out;
769 * Need to parse both autoneg_advertised and fc and set up
770 * the appropriate PHY registers. First we will parse for
771 * autoneg_advertised software override. Since we can advertise
772 * a plethora of combinations, we need to check each bit
773 * individually.
777 * First we clear all the 10/100 mb speed bits in the Auto-Neg
778 * Advertisement Register (Address 4) and the 1000 mb speed bits in
779 * the 1000Base-T Control Register (Address 9).
781 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
782 NWAY_AR_100TX_HD_CAPS |
783 NWAY_AR_10T_FD_CAPS |
784 NWAY_AR_10T_HD_CAPS);
785 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
787 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
789 /* Do we want to advertise 10 Mb Half Duplex? */
790 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
791 hw_dbg("Advertise 10mb Half duplex\n");
792 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
795 /* Do we want to advertise 10 Mb Full Duplex? */
796 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
797 hw_dbg("Advertise 10mb Full duplex\n");
798 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
801 /* Do we want to advertise 100 Mb Half Duplex? */
802 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
803 hw_dbg("Advertise 100mb Half duplex\n");
804 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
807 /* Do we want to advertise 100 Mb Full Duplex? */
808 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
809 hw_dbg("Advertise 100mb Full duplex\n");
810 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
813 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
814 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
815 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
817 /* Do we want to advertise 1000 Mb Full Duplex? */
818 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
819 hw_dbg("Advertise 1000mb Full duplex\n");
820 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
824 * Check for a software override of the flow control settings, and
825 * setup the PHY advertisement registers accordingly. If
826 * auto-negotiation is enabled, then software will have to set the
827 * "PAUSE" bits to the correct value in the Auto-Negotiation
828 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
829 * negotiation.
831 * The possible values of the "fc" parameter are:
832 * 0: Flow control is completely disabled
833 * 1: Rx flow control is enabled (we can receive pause frames
834 * but not send pause frames).
835 * 2: Tx flow control is enabled (we can send pause frames
836 * but we do not support receiving pause frames).
837 * 3: Both Rx and TX flow control (symmetric) are enabled.
838 * other: No software override. The flow control configuration
839 * in the EEPROM is used.
841 switch (hw->fc.current_mode) {
842 case e1000_fc_none:
844 * Flow control (RX & TX) is completely disabled by a
845 * software over-ride.
847 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
848 break;
849 case e1000_fc_rx_pause:
851 * RX Flow control is enabled, and TX Flow control is
852 * disabled, by a software over-ride.
854 * Since there really isn't a way to advertise that we are
855 * capable of RX Pause ONLY, we will advertise that we
856 * support both symmetric and asymmetric RX PAUSE. Later
857 * (in e1000_config_fc_after_link_up) we will disable the
858 * hw's ability to send PAUSE frames.
860 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
861 break;
862 case e1000_fc_tx_pause:
864 * TX Flow control is enabled, and RX Flow control is
865 * disabled, by a software over-ride.
867 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
868 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
869 break;
870 case e1000_fc_full:
872 * Flow control (both RX and TX) is enabled by a software
873 * over-ride.
875 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
876 break;
877 default:
878 hw_dbg("Flow control param set incorrectly\n");
879 ret_val = -E1000_ERR_CONFIG;
880 goto out;
883 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
884 if (ret_val)
885 goto out;
887 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
889 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
890 ret_val = phy->ops.write_reg(hw,
891 PHY_1000T_CTRL,
892 mii_1000t_ctrl_reg);
893 if (ret_val)
894 goto out;
897 out:
898 return ret_val;
902 * igb_setup_copper_link - Configure copper link settings
903 * @hw: pointer to the HW structure
905 * Calls the appropriate function to configure the link for auto-neg or forced
906 * speed and duplex. Then we check for link, once link is established calls
907 * to configure collision distance and flow control are called. If link is
908 * not established, we return -E1000_ERR_PHY (-2).
910 s32 igb_setup_copper_link(struct e1000_hw *hw)
912 s32 ret_val;
913 bool link;
916 if (hw->mac.autoneg) {
918 * Setup autoneg and flow control advertisement and perform
919 * autonegotiation.
921 ret_val = igb_copper_link_autoneg(hw);
922 if (ret_val)
923 goto out;
924 } else {
926 * PHY will be set to 10H, 10F, 100H or 100F
927 * depending on user settings.
929 hw_dbg("Forcing Speed and Duplex\n");
930 ret_val = hw->phy.ops.force_speed_duplex(hw);
931 if (ret_val) {
932 hw_dbg("Error Forcing Speed and Duplex\n");
933 goto out;
938 * Check link status. Wait up to 100 microseconds for link to become
939 * valid.
941 ret_val = igb_phy_has_link(hw,
942 COPPER_LINK_UP_LIMIT,
944 &link);
945 if (ret_val)
946 goto out;
948 if (link) {
949 hw_dbg("Valid link established!!!\n");
950 igb_config_collision_dist(hw);
951 ret_val = igb_config_fc_after_link_up(hw);
952 } else {
953 hw_dbg("Unable to establish link!!!\n");
956 out:
957 return ret_val;
961 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
962 * @hw: pointer to the HW structure
964 * Calls the PHY setup function to force speed and duplex. Clears the
965 * auto-crossover to force MDI manually. Waits for link and returns
966 * successful if link up is successful, else -E1000_ERR_PHY (-2).
968 s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
970 struct e1000_phy_info *phy = &hw->phy;
971 s32 ret_val;
972 u16 phy_data;
973 bool link;
975 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
976 if (ret_val)
977 goto out;
979 igb_phy_force_speed_duplex_setup(hw, &phy_data);
981 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
982 if (ret_val)
983 goto out;
986 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
987 * forced whenever speed and duplex are forced.
989 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
990 if (ret_val)
991 goto out;
993 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
994 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
996 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
997 if (ret_val)
998 goto out;
1000 hw_dbg("IGP PSCR: %X\n", phy_data);
1002 udelay(1);
1004 if (phy->autoneg_wait_to_complete) {
1005 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
1007 ret_val = igb_phy_has_link(hw,
1008 PHY_FORCE_LIMIT,
1009 100000,
1010 &link);
1011 if (ret_val)
1012 goto out;
1014 if (!link)
1015 hw_dbg("Link taking longer than expected.\n");
1017 /* Try once more */
1018 ret_val = igb_phy_has_link(hw,
1019 PHY_FORCE_LIMIT,
1020 100000,
1021 &link);
1022 if (ret_val)
1023 goto out;
1026 out:
1027 return ret_val;
1031 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1032 * @hw: pointer to the HW structure
1034 * Calls the PHY setup function to force speed and duplex. Clears the
1035 * auto-crossover to force MDI manually. Resets the PHY to commit the
1036 * changes. If time expires while waiting for link up, we reset the DSP.
1037 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
1038 * successful completion, else return corresponding error code.
1040 s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1042 struct e1000_phy_info *phy = &hw->phy;
1043 s32 ret_val;
1044 u16 phy_data;
1045 bool link;
1048 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1049 * forced whenever speed and duplex are forced.
1051 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1052 if (ret_val)
1053 goto out;
1055 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1056 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1057 if (ret_val)
1058 goto out;
1060 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
1062 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1063 if (ret_val)
1064 goto out;
1066 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1068 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1069 if (ret_val)
1070 goto out;
1072 /* Reset the phy to commit changes. */
1073 ret_val = igb_phy_sw_reset(hw);
1074 if (ret_val)
1075 goto out;
1077 if (phy->autoneg_wait_to_complete) {
1078 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
1080 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
1081 if (ret_val)
1082 goto out;
1084 if (!link) {
1086 * We didn't get link.
1087 * Reset the DSP and cross our fingers.
1089 ret_val = phy->ops.write_reg(hw,
1090 M88E1000_PHY_PAGE_SELECT,
1091 0x001d);
1092 if (ret_val)
1093 goto out;
1094 ret_val = igb_phy_reset_dsp(hw);
1095 if (ret_val)
1096 goto out;
1099 /* Try once more */
1100 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
1101 100000, &link);
1102 if (ret_val)
1103 goto out;
1106 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1107 if (ret_val)
1108 goto out;
1111 * Resetting the phy means we need to re-force TX_CLK in the
1112 * Extended PHY Specific Control Register to 25MHz clock from
1113 * the reset value of 2.5MHz.
1115 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1116 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1117 if (ret_val)
1118 goto out;
1121 * In addition, we must re-enable CRS on Tx for both half and full
1122 * duplex.
1124 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1125 if (ret_val)
1126 goto out;
1128 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1129 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1131 out:
1132 return ret_val;
1136 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1137 * @hw: pointer to the HW structure
1138 * @phy_ctrl: pointer to current value of PHY_CONTROL
1140 * Forces speed and duplex on the PHY by doing the following: disable flow
1141 * control, force speed/duplex on the MAC, disable auto speed detection,
1142 * disable auto-negotiation, configure duplex, configure speed, configure
1143 * the collision distance, write configuration to CTRL register. The
1144 * caller must write to the PHY_CONTROL register for these settings to
1145 * take affect.
1147 static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
1148 u16 *phy_ctrl)
1150 struct e1000_mac_info *mac = &hw->mac;
1151 u32 ctrl;
1153 /* Turn off flow control when forcing speed/duplex */
1154 hw->fc.current_mode = e1000_fc_none;
1156 /* Force speed/duplex on the mac */
1157 ctrl = rd32(E1000_CTRL);
1158 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1159 ctrl &= ~E1000_CTRL_SPD_SEL;
1161 /* Disable Auto Speed Detection */
1162 ctrl &= ~E1000_CTRL_ASDE;
1164 /* Disable autoneg on the phy */
1165 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1167 /* Forcing Full or Half Duplex? */
1168 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1169 ctrl &= ~E1000_CTRL_FD;
1170 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1171 hw_dbg("Half Duplex\n");
1172 } else {
1173 ctrl |= E1000_CTRL_FD;
1174 *phy_ctrl |= MII_CR_FULL_DUPLEX;
1175 hw_dbg("Full Duplex\n");
1178 /* Forcing 10mb or 100mb? */
1179 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1180 ctrl |= E1000_CTRL_SPD_100;
1181 *phy_ctrl |= MII_CR_SPEED_100;
1182 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1183 hw_dbg("Forcing 100mb\n");
1184 } else {
1185 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1186 *phy_ctrl |= MII_CR_SPEED_10;
1187 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1188 hw_dbg("Forcing 10mb\n");
1191 igb_config_collision_dist(hw);
1193 wr32(E1000_CTRL, ctrl);
1197 * igb_set_d3_lplu_state - Sets low power link up state for D3
1198 * @hw: pointer to the HW structure
1199 * @active: boolean used to enable/disable lplu
1201 * Success returns 0, Failure returns 1
1203 * The low power link up (lplu) state is set to the power management level D3
1204 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1205 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1206 * is used during Dx states where the power conservation is most important.
1207 * During driver activity, SmartSpeed should be enabled so performance is
1208 * maintained.
1210 s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1212 struct e1000_phy_info *phy = &hw->phy;
1213 s32 ret_val = 0;
1214 u16 data;
1216 if (!(hw->phy.ops.read_reg))
1217 goto out;
1219 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1220 if (ret_val)
1221 goto out;
1223 if (!active) {
1224 data &= ~IGP02E1000_PM_D3_LPLU;
1225 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1226 data);
1227 if (ret_val)
1228 goto out;
1230 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1231 * during Dx states where the power conservation is most
1232 * important. During driver activity we should enable
1233 * SmartSpeed, so performance is maintained.
1235 if (phy->smart_speed == e1000_smart_speed_on) {
1236 ret_val = phy->ops.read_reg(hw,
1237 IGP01E1000_PHY_PORT_CONFIG,
1238 &data);
1239 if (ret_val)
1240 goto out;
1242 data |= IGP01E1000_PSCFR_SMART_SPEED;
1243 ret_val = phy->ops.write_reg(hw,
1244 IGP01E1000_PHY_PORT_CONFIG,
1245 data);
1246 if (ret_val)
1247 goto out;
1248 } else if (phy->smart_speed == e1000_smart_speed_off) {
1249 ret_val = phy->ops.read_reg(hw,
1250 IGP01E1000_PHY_PORT_CONFIG,
1251 &data);
1252 if (ret_val)
1253 goto out;
1255 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1256 ret_val = phy->ops.write_reg(hw,
1257 IGP01E1000_PHY_PORT_CONFIG,
1258 data);
1259 if (ret_val)
1260 goto out;
1262 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1263 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1264 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1265 data |= IGP02E1000_PM_D3_LPLU;
1266 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1267 data);
1268 if (ret_val)
1269 goto out;
1271 /* When LPLU is enabled, we should disable SmartSpeed */
1272 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1273 &data);
1274 if (ret_val)
1275 goto out;
1277 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1278 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1279 data);
1282 out:
1283 return ret_val;
1287 * igb_check_downshift - Checks whether a downshift in speed occured
1288 * @hw: pointer to the HW structure
1290 * Success returns 0, Failure returns 1
1292 * A downshift is detected by querying the PHY link health.
1294 s32 igb_check_downshift(struct e1000_hw *hw)
1296 struct e1000_phy_info *phy = &hw->phy;
1297 s32 ret_val;
1298 u16 phy_data, offset, mask;
1300 switch (phy->type) {
1301 case e1000_phy_m88:
1302 case e1000_phy_gg82563:
1303 offset = M88E1000_PHY_SPEC_STATUS;
1304 mask = M88E1000_PSSR_DOWNSHIFT;
1305 break;
1306 case e1000_phy_igp_2:
1307 case e1000_phy_igp:
1308 case e1000_phy_igp_3:
1309 offset = IGP01E1000_PHY_LINK_HEALTH;
1310 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1311 break;
1312 default:
1313 /* speed downshift not supported */
1314 phy->speed_downgraded = false;
1315 ret_val = 0;
1316 goto out;
1319 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
1321 if (!ret_val)
1322 phy->speed_downgraded = (phy_data & mask) ? true : false;
1324 out:
1325 return ret_val;
1329 * igb_check_polarity_m88 - Checks the polarity.
1330 * @hw: pointer to the HW structure
1332 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1334 * Polarity is determined based on the PHY specific status register.
1336 static s32 igb_check_polarity_m88(struct e1000_hw *hw)
1338 struct e1000_phy_info *phy = &hw->phy;
1339 s32 ret_val;
1340 u16 data;
1342 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
1344 if (!ret_val)
1345 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1346 ? e1000_rev_polarity_reversed
1347 : e1000_rev_polarity_normal;
1349 return ret_val;
1353 * igb_check_polarity_igp - Checks the polarity.
1354 * @hw: pointer to the HW structure
1356 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1358 * Polarity is determined based on the PHY port status register, and the
1359 * current speed (since there is no polarity at 100Mbps).
1361 static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1363 struct e1000_phy_info *phy = &hw->phy;
1364 s32 ret_val;
1365 u16 data, offset, mask;
1368 * Polarity is determined based on the speed of
1369 * our connection.
1371 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1372 if (ret_val)
1373 goto out;
1375 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1376 IGP01E1000_PSSR_SPEED_1000MBPS) {
1377 offset = IGP01E1000_PHY_PCS_INIT_REG;
1378 mask = IGP01E1000_PHY_POLARITY_MASK;
1379 } else {
1381 * This really only applies to 10Mbps since
1382 * there is no polarity for 100Mbps (always 0).
1384 offset = IGP01E1000_PHY_PORT_STATUS;
1385 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1388 ret_val = phy->ops.read_reg(hw, offset, &data);
1390 if (!ret_val)
1391 phy->cable_polarity = (data & mask)
1392 ? e1000_rev_polarity_reversed
1393 : e1000_rev_polarity_normal;
1395 out:
1396 return ret_val;
1400 * igb_wait_autoneg - Wait for auto-neg compeletion
1401 * @hw: pointer to the HW structure
1403 * Waits for auto-negotiation to complete or for the auto-negotiation time
1404 * limit to expire, which ever happens first.
1406 static s32 igb_wait_autoneg(struct e1000_hw *hw)
1408 s32 ret_val = 0;
1409 u16 i, phy_status;
1411 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1412 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1413 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1414 if (ret_val)
1415 break;
1416 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1417 if (ret_val)
1418 break;
1419 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1420 break;
1421 msleep(100);
1425 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1426 * has completed.
1428 return ret_val;
1432 * igb_phy_has_link - Polls PHY for link
1433 * @hw: pointer to the HW structure
1434 * @iterations: number of times to poll for link
1435 * @usec_interval: delay between polling attempts
1436 * @success: pointer to whether polling was successful or not
1438 * Polls the PHY status register for link, 'iterations' number of times.
1440 s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
1441 u32 usec_interval, bool *success)
1443 s32 ret_val = 0;
1444 u16 i, phy_status;
1446 for (i = 0; i < iterations; i++) {
1448 * Some PHYs require the PHY_STATUS register to be read
1449 * twice due to the link bit being sticky. No harm doing
1450 * it across the board.
1452 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1453 if (ret_val) {
1455 * If the first read fails, another entity may have
1456 * ownership of the resources, wait and try again to
1457 * see if they have relinquished the resources yet.
1459 udelay(usec_interval);
1461 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1462 if (ret_val)
1463 break;
1464 if (phy_status & MII_SR_LINK_STATUS)
1465 break;
1466 if (usec_interval >= 1000)
1467 mdelay(usec_interval/1000);
1468 else
1469 udelay(usec_interval);
1472 *success = (i < iterations) ? true : false;
1474 return ret_val;
1478 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
1479 * @hw: pointer to the HW structure
1481 * Reads the PHY specific status register to retrieve the cable length
1482 * information. The cable length is determined by averaging the minimum and
1483 * maximum values to get the "average" cable length. The m88 PHY has four
1484 * possible cable length values, which are:
1485 * Register Value Cable Length
1486 * 0 < 50 meters
1487 * 1 50 - 80 meters
1488 * 2 80 - 110 meters
1489 * 3 110 - 140 meters
1490 * 4 > 140 meters
1492 s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1494 struct e1000_phy_info *phy = &hw->phy;
1495 s32 ret_val;
1496 u16 phy_data, index;
1498 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1499 if (ret_val)
1500 goto out;
1502 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1503 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1504 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1505 ret_val = -E1000_ERR_PHY;
1506 goto out;
1509 phy->min_cable_length = e1000_m88_cable_length_table[index];
1510 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1512 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1514 out:
1515 return ret_val;
1519 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1520 * @hw: pointer to the HW structure
1522 * The automatic gain control (agc) normalizes the amplitude of the
1523 * received signal, adjusting for the attenuation produced by the
1524 * cable. By reading the AGC registers, which represent the
1525 * combination of coarse and fine gain value, the value can be put
1526 * into a lookup table to obtain the approximate cable length
1527 * for each channel.
1529 s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1531 struct e1000_phy_info *phy = &hw->phy;
1532 s32 ret_val = 0;
1533 u16 phy_data, i, agc_value = 0;
1534 u16 cur_agc_index, max_agc_index = 0;
1535 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1536 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1537 {IGP02E1000_PHY_AGC_A,
1538 IGP02E1000_PHY_AGC_B,
1539 IGP02E1000_PHY_AGC_C,
1540 IGP02E1000_PHY_AGC_D};
1542 /* Read the AGC registers for all channels */
1543 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1544 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
1545 if (ret_val)
1546 goto out;
1549 * Getting bits 15:9, which represent the combination of
1550 * coarse and fine gain values. The result is a number
1551 * that can be put into the lookup table to obtain the
1552 * approximate cable length.
1554 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1555 IGP02E1000_AGC_LENGTH_MASK;
1557 /* Array index bound check. */
1558 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1559 (cur_agc_index == 0)) {
1560 ret_val = -E1000_ERR_PHY;
1561 goto out;
1564 /* Remove min & max AGC values from calculation. */
1565 if (e1000_igp_2_cable_length_table[min_agc_index] >
1566 e1000_igp_2_cable_length_table[cur_agc_index])
1567 min_agc_index = cur_agc_index;
1568 if (e1000_igp_2_cable_length_table[max_agc_index] <
1569 e1000_igp_2_cable_length_table[cur_agc_index])
1570 max_agc_index = cur_agc_index;
1572 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1575 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1576 e1000_igp_2_cable_length_table[max_agc_index]);
1577 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1579 /* Calculate cable length with the error range of +/- 10 meters. */
1580 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1581 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1582 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1584 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1586 out:
1587 return ret_val;
1591 * igb_get_phy_info_m88 - Retrieve PHY information
1592 * @hw: pointer to the HW structure
1594 * Valid for only copper links. Read the PHY status register (sticky read)
1595 * to verify that link is up. Read the PHY special control register to
1596 * determine the polarity and 10base-T extended distance. Read the PHY
1597 * special status register to determine MDI/MDIx and current speed. If
1598 * speed is 1000, then determine cable length, local and remote receiver.
1600 s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1602 struct e1000_phy_info *phy = &hw->phy;
1603 s32 ret_val;
1604 u16 phy_data;
1605 bool link;
1607 if (phy->media_type != e1000_media_type_copper) {
1608 hw_dbg("Phy info is only valid for copper media\n");
1609 ret_val = -E1000_ERR_CONFIG;
1610 goto out;
1613 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1614 if (ret_val)
1615 goto out;
1617 if (!link) {
1618 hw_dbg("Phy info is only valid if link is up\n");
1619 ret_val = -E1000_ERR_CONFIG;
1620 goto out;
1623 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1624 if (ret_val)
1625 goto out;
1627 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
1628 ? true : false;
1630 ret_val = igb_check_polarity_m88(hw);
1631 if (ret_val)
1632 goto out;
1634 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1635 if (ret_val)
1636 goto out;
1638 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1640 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
1641 ret_val = phy->ops.get_cable_length(hw);
1642 if (ret_val)
1643 goto out;
1645 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
1646 if (ret_val)
1647 goto out;
1649 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1650 ? e1000_1000t_rx_status_ok
1651 : e1000_1000t_rx_status_not_ok;
1653 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1654 ? e1000_1000t_rx_status_ok
1655 : e1000_1000t_rx_status_not_ok;
1656 } else {
1657 /* Set values to "undefined" */
1658 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1659 phy->local_rx = e1000_1000t_rx_status_undefined;
1660 phy->remote_rx = e1000_1000t_rx_status_undefined;
1663 out:
1664 return ret_val;
1668 * igb_get_phy_info_igp - Retrieve igp PHY information
1669 * @hw: pointer to the HW structure
1671 * Read PHY status to determine if link is up. If link is up, then
1672 * set/determine 10base-T extended distance and polarity correction. Read
1673 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1674 * determine on the cable length, local and remote receiver.
1676 s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1678 struct e1000_phy_info *phy = &hw->phy;
1679 s32 ret_val;
1680 u16 data;
1681 bool link;
1683 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1684 if (ret_val)
1685 goto out;
1687 if (!link) {
1688 hw_dbg("Phy info is only valid if link is up\n");
1689 ret_val = -E1000_ERR_CONFIG;
1690 goto out;
1693 phy->polarity_correction = true;
1695 ret_val = igb_check_polarity_igp(hw);
1696 if (ret_val)
1697 goto out;
1699 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1700 if (ret_val)
1701 goto out;
1703 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
1705 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1706 IGP01E1000_PSSR_SPEED_1000MBPS) {
1707 ret_val = phy->ops.get_cable_length(hw);
1708 if (ret_val)
1709 goto out;
1711 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
1712 if (ret_val)
1713 goto out;
1715 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1716 ? e1000_1000t_rx_status_ok
1717 : e1000_1000t_rx_status_not_ok;
1719 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1720 ? e1000_1000t_rx_status_ok
1721 : e1000_1000t_rx_status_not_ok;
1722 } else {
1723 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1724 phy->local_rx = e1000_1000t_rx_status_undefined;
1725 phy->remote_rx = e1000_1000t_rx_status_undefined;
1728 out:
1729 return ret_val;
1733 * igb_phy_sw_reset - PHY software reset
1734 * @hw: pointer to the HW structure
1736 * Does a software reset of the PHY by reading the PHY control register and
1737 * setting/write the control register reset bit to the PHY.
1739 s32 igb_phy_sw_reset(struct e1000_hw *hw)
1741 s32 ret_val = 0;
1742 u16 phy_ctrl;
1744 if (!(hw->phy.ops.read_reg))
1745 goto out;
1747 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
1748 if (ret_val)
1749 goto out;
1751 phy_ctrl |= MII_CR_RESET;
1752 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
1753 if (ret_val)
1754 goto out;
1756 udelay(1);
1758 out:
1759 return ret_val;
1763 * igb_phy_hw_reset - PHY hardware reset
1764 * @hw: pointer to the HW structure
1766 * Verify the reset block is not blocking us from resetting. Acquire
1767 * semaphore (if necessary) and read/set/write the device control reset
1768 * bit in the PHY. Wait the appropriate delay time for the device to
1769 * reset and relase the semaphore (if necessary).
1771 s32 igb_phy_hw_reset(struct e1000_hw *hw)
1773 struct e1000_phy_info *phy = &hw->phy;
1774 s32 ret_val;
1775 u32 ctrl;
1777 ret_val = igb_check_reset_block(hw);
1778 if (ret_val) {
1779 ret_val = 0;
1780 goto out;
1783 ret_val = phy->ops.acquire(hw);
1784 if (ret_val)
1785 goto out;
1787 ctrl = rd32(E1000_CTRL);
1788 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
1789 wrfl();
1791 udelay(phy->reset_delay_us);
1793 wr32(E1000_CTRL, ctrl);
1794 wrfl();
1796 udelay(150);
1798 phy->ops.release(hw);
1800 ret_val = phy->ops.get_cfg_done(hw);
1802 out:
1803 return ret_val;
1807 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
1808 * @hw: pointer to the HW structure
1810 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
1812 s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
1814 hw_dbg("Running IGP 3 PHY init script\n");
1816 /* PHY init IGP 3 */
1817 /* Enable rise/fall, 10-mode work in class-A */
1818 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
1819 /* Remove all caps from Replica path filter */
1820 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
1821 /* Bias trimming for ADC, AFE and Driver (Default) */
1822 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
1823 /* Increase Hybrid poly bias */
1824 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
1825 /* Add 4% to TX amplitude in Giga mode */
1826 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
1827 /* Disable trimming (TTT) */
1828 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
1829 /* Poly DC correction to 94.6% + 2% for all channels */
1830 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
1831 /* ABS DC correction to 95.9% */
1832 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
1833 /* BG temp curve trim */
1834 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
1835 /* Increasing ADC OPAMP stage 1 currents to max */
1836 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
1837 /* Force 1000 ( required for enabling PHY regs configuration) */
1838 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
1839 /* Set upd_freq to 6 */
1840 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
1841 /* Disable NPDFE */
1842 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
1843 /* Disable adaptive fixed FFE (Default) */
1844 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
1845 /* Enable FFE hysteresis */
1846 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
1847 /* Fixed FFE for short cable lengths */
1848 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
1849 /* Fixed FFE for medium cable lengths */
1850 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
1851 /* Fixed FFE for long cable lengths */
1852 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
1853 /* Enable Adaptive Clip Threshold */
1854 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
1855 /* AHT reset limit to 1 */
1856 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
1857 /* Set AHT master delay to 127 msec */
1858 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
1859 /* Set scan bits for AHT */
1860 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
1861 /* Set AHT Preset bits */
1862 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
1863 /* Change integ_factor of channel A to 3 */
1864 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
1865 /* Change prop_factor of channels BCD to 8 */
1866 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
1867 /* Change cg_icount + enable integbp for channels BCD */
1868 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
1870 * Change cg_icount + enable integbp + change prop_factor_master
1871 * to 8 for channel A
1873 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
1874 /* Disable AHT in Slave mode on channel A */
1875 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
1877 * Enable LPLU and disable AN to 1000 in non-D0a states,
1878 * Enable SPD+B2B
1880 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
1881 /* Enable restart AN on an1000_dis change */
1882 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
1883 /* Enable wh_fifo read clock in 10/100 modes */
1884 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
1885 /* Restart AN, Speed selection is 1000 */
1886 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
1888 return 0;