1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2012 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 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
,
37 static s32
igb_wait_autoneg(struct e1000_hw
*hw
);
38 static s32
igb_set_master_slave_mode(struct e1000_hw
*hw
);
40 /* Cable length tables */
41 static const u16 e1000_m88_cable_length_table
[] =
42 { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED
};
43 #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
44 (sizeof(e1000_m88_cable_length_table) / \
45 sizeof(e1000_m88_cable_length_table[0]))
47 static const u16 e1000_igp_2_cable_length_table
[] =
48 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
49 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
50 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
51 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
52 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
53 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
54 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
55 104, 109, 114, 118, 121, 124};
56 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
57 (sizeof(e1000_igp_2_cable_length_table) / \
58 sizeof(e1000_igp_2_cable_length_table[0]))
61 * igb_check_reset_block - Check if PHY reset is blocked
62 * @hw: pointer to the HW structure
64 * Read the PHY management control register and check whether a PHY reset
65 * is blocked. If a reset is not blocked return 0, otherwise
66 * return E1000_BLK_PHY_RESET (12).
68 s32
igb_check_reset_block(struct e1000_hw
*hw
)
72 manc
= rd32(E1000_MANC
);
74 return (manc
& E1000_MANC_BLK_PHY_RST_ON_IDE
) ?
75 E1000_BLK_PHY_RESET
: 0;
79 * igb_get_phy_id - Retrieve the PHY ID and revision
80 * @hw: pointer to the HW structure
82 * Reads the PHY registers and stores the PHY ID and possibly the PHY
83 * revision in the hardware structure.
85 s32
igb_get_phy_id(struct e1000_hw
*hw
)
87 struct e1000_phy_info
*phy
= &hw
->phy
;
91 ret_val
= phy
->ops
.read_reg(hw
, PHY_ID1
, &phy_id
);
95 phy
->id
= (u32
)(phy_id
<< 16);
97 ret_val
= phy
->ops
.read_reg(hw
, PHY_ID2
, &phy_id
);
101 phy
->id
|= (u32
)(phy_id
& PHY_REVISION_MASK
);
102 phy
->revision
= (u32
)(phy_id
& ~PHY_REVISION_MASK
);
109 * igb_phy_reset_dsp - Reset PHY DSP
110 * @hw: pointer to the HW structure
112 * Reset the digital signal processor.
114 static s32
igb_phy_reset_dsp(struct e1000_hw
*hw
)
118 if (!(hw
->phy
.ops
.write_reg
))
121 ret_val
= hw
->phy
.ops
.write_reg(hw
, M88E1000_PHY_GEN_CONTROL
, 0xC1);
125 ret_val
= hw
->phy
.ops
.write_reg(hw
, M88E1000_PHY_GEN_CONTROL
, 0);
132 * igb_read_phy_reg_mdic - Read MDI control register
133 * @hw: pointer to the HW structure
134 * @offset: register offset to be read
135 * @data: pointer to the read data
137 * Reads the MDI control regsiter in the PHY at offset and stores the
138 * information read to data.
140 s32
igb_read_phy_reg_mdic(struct e1000_hw
*hw
, u32 offset
, u16
*data
)
142 struct e1000_phy_info
*phy
= &hw
->phy
;
146 if (offset
> MAX_PHY_REG_ADDRESS
) {
147 hw_dbg("PHY Address %d is out of range\n", offset
);
148 ret_val
= -E1000_ERR_PARAM
;
153 * Set up Op-code, Phy Address, and register offset in the MDI
154 * Control register. The MAC will take care of interfacing with the
155 * PHY to retrieve the desired data.
157 mdic
= ((offset
<< E1000_MDIC_REG_SHIFT
) |
158 (phy
->addr
<< E1000_MDIC_PHY_SHIFT
) |
159 (E1000_MDIC_OP_READ
));
161 wr32(E1000_MDIC
, mdic
);
164 * Poll the ready bit to see if the MDI read completed
165 * Increasing the time out as testing showed failures with
168 for (i
= 0; i
< (E1000_GEN_POLL_TIMEOUT
* 3); i
++) {
170 mdic
= rd32(E1000_MDIC
);
171 if (mdic
& E1000_MDIC_READY
)
174 if (!(mdic
& E1000_MDIC_READY
)) {
175 hw_dbg("MDI Read did not complete\n");
176 ret_val
= -E1000_ERR_PHY
;
179 if (mdic
& E1000_MDIC_ERROR
) {
180 hw_dbg("MDI Error\n");
181 ret_val
= -E1000_ERR_PHY
;
191 * igb_write_phy_reg_mdic - Write MDI control register
192 * @hw: pointer to the HW structure
193 * @offset: register offset to write to
194 * @data: data to write to register at offset
196 * Writes data to MDI control register in the PHY at offset.
198 s32
igb_write_phy_reg_mdic(struct e1000_hw
*hw
, u32 offset
, u16 data
)
200 struct e1000_phy_info
*phy
= &hw
->phy
;
204 if (offset
> MAX_PHY_REG_ADDRESS
) {
205 hw_dbg("PHY Address %d is out of range\n", offset
);
206 ret_val
= -E1000_ERR_PARAM
;
211 * Set up Op-code, Phy Address, and register offset in the MDI
212 * Control register. The MAC will take care of interfacing with the
213 * PHY to retrieve the desired data.
215 mdic
= (((u32
)data
) |
216 (offset
<< E1000_MDIC_REG_SHIFT
) |
217 (phy
->addr
<< E1000_MDIC_PHY_SHIFT
) |
218 (E1000_MDIC_OP_WRITE
));
220 wr32(E1000_MDIC
, mdic
);
223 * Poll the ready bit to see if the MDI read completed
224 * Increasing the time out as testing showed failures with
227 for (i
= 0; i
< (E1000_GEN_POLL_TIMEOUT
* 3); i
++) {
229 mdic
= rd32(E1000_MDIC
);
230 if (mdic
& E1000_MDIC_READY
)
233 if (!(mdic
& E1000_MDIC_READY
)) {
234 hw_dbg("MDI Write did not complete\n");
235 ret_val
= -E1000_ERR_PHY
;
238 if (mdic
& E1000_MDIC_ERROR
) {
239 hw_dbg("MDI Error\n");
240 ret_val
= -E1000_ERR_PHY
;
249 * igb_read_phy_reg_i2c - Read PHY register using i2c
250 * @hw: pointer to the HW structure
251 * @offset: register offset to be read
252 * @data: pointer to the read data
254 * Reads the PHY register at offset using the i2c interface and stores the
255 * retrieved information in data.
257 s32
igb_read_phy_reg_i2c(struct e1000_hw
*hw
, u32 offset
, u16
*data
)
259 struct e1000_phy_info
*phy
= &hw
->phy
;
264 * Set up Op-code, Phy Address, and register address in the I2CCMD
265 * register. The MAC will take care of interfacing with the
266 * PHY to retrieve the desired data.
268 i2ccmd
= ((offset
<< E1000_I2CCMD_REG_ADDR_SHIFT
) |
269 (phy
->addr
<< E1000_I2CCMD_PHY_ADDR_SHIFT
) |
270 (E1000_I2CCMD_OPCODE_READ
));
272 wr32(E1000_I2CCMD
, i2ccmd
);
274 /* Poll the ready bit to see if the I2C read completed */
275 for (i
= 0; i
< E1000_I2CCMD_PHY_TIMEOUT
; i
++) {
277 i2ccmd
= rd32(E1000_I2CCMD
);
278 if (i2ccmd
& E1000_I2CCMD_READY
)
281 if (!(i2ccmd
& E1000_I2CCMD_READY
)) {
282 hw_dbg("I2CCMD Read did not complete\n");
283 return -E1000_ERR_PHY
;
285 if (i2ccmd
& E1000_I2CCMD_ERROR
) {
286 hw_dbg("I2CCMD Error bit set\n");
287 return -E1000_ERR_PHY
;
290 /* Need to byte-swap the 16-bit value. */
291 *data
= ((i2ccmd
>> 8) & 0x00FF) | ((i2ccmd
<< 8) & 0xFF00);
297 * igb_write_phy_reg_i2c - Write PHY register using i2c
298 * @hw: pointer to the HW structure
299 * @offset: register offset to write to
300 * @data: data to write at register offset
302 * Writes the data to PHY register at the offset using the i2c interface.
304 s32
igb_write_phy_reg_i2c(struct e1000_hw
*hw
, u32 offset
, u16 data
)
306 struct e1000_phy_info
*phy
= &hw
->phy
;
308 u16 phy_data_swapped
;
310 /* Prevent overwritting SFP I2C EEPROM which is at A0 address.*/
311 if ((hw
->phy
.addr
== 0) || (hw
->phy
.addr
> 7)) {
312 hw_dbg("PHY I2C Address %d is out of range.\n",
314 return -E1000_ERR_CONFIG
;
317 /* Swap the data bytes for the I2C interface */
318 phy_data_swapped
= ((data
>> 8) & 0x00FF) | ((data
<< 8) & 0xFF00);
321 * Set up Op-code, Phy Address, and register address in the I2CCMD
322 * register. The MAC will take care of interfacing with the
323 * PHY to retrieve the desired data.
325 i2ccmd
= ((offset
<< E1000_I2CCMD_REG_ADDR_SHIFT
) |
326 (phy
->addr
<< E1000_I2CCMD_PHY_ADDR_SHIFT
) |
327 E1000_I2CCMD_OPCODE_WRITE
|
330 wr32(E1000_I2CCMD
, i2ccmd
);
332 /* Poll the ready bit to see if the I2C read completed */
333 for (i
= 0; i
< E1000_I2CCMD_PHY_TIMEOUT
; i
++) {
335 i2ccmd
= rd32(E1000_I2CCMD
);
336 if (i2ccmd
& E1000_I2CCMD_READY
)
339 if (!(i2ccmd
& E1000_I2CCMD_READY
)) {
340 hw_dbg("I2CCMD Write did not complete\n");
341 return -E1000_ERR_PHY
;
343 if (i2ccmd
& E1000_I2CCMD_ERROR
) {
344 hw_dbg("I2CCMD Error bit set\n");
345 return -E1000_ERR_PHY
;
352 * igb_read_phy_reg_igp - Read igp PHY register
353 * @hw: pointer to the HW structure
354 * @offset: register offset to be read
355 * @data: pointer to the read data
357 * Acquires semaphore, if necessary, then reads the PHY register at offset
358 * and storing the retrieved information in data. Release any acquired
359 * semaphores before exiting.
361 s32
igb_read_phy_reg_igp(struct e1000_hw
*hw
, u32 offset
, u16
*data
)
365 if (!(hw
->phy
.ops
.acquire
))
368 ret_val
= hw
->phy
.ops
.acquire(hw
);
372 if (offset
> MAX_PHY_MULTI_PAGE_REG
) {
373 ret_val
= igb_write_phy_reg_mdic(hw
,
374 IGP01E1000_PHY_PAGE_SELECT
,
377 hw
->phy
.ops
.release(hw
);
382 ret_val
= igb_read_phy_reg_mdic(hw
, MAX_PHY_REG_ADDRESS
& offset
,
385 hw
->phy
.ops
.release(hw
);
392 * igb_write_phy_reg_igp - Write igp PHY register
393 * @hw: pointer to the HW structure
394 * @offset: register offset to write to
395 * @data: data to write at register offset
397 * Acquires semaphore, if necessary, then writes the data to PHY register
398 * at the offset. Release any acquired semaphores before exiting.
400 s32
igb_write_phy_reg_igp(struct e1000_hw
*hw
, u32 offset
, u16 data
)
404 if (!(hw
->phy
.ops
.acquire
))
407 ret_val
= hw
->phy
.ops
.acquire(hw
);
411 if (offset
> MAX_PHY_MULTI_PAGE_REG
) {
412 ret_val
= igb_write_phy_reg_mdic(hw
,
413 IGP01E1000_PHY_PAGE_SELECT
,
416 hw
->phy
.ops
.release(hw
);
421 ret_val
= igb_write_phy_reg_mdic(hw
, MAX_PHY_REG_ADDRESS
& offset
,
424 hw
->phy
.ops
.release(hw
);
431 * igb_copper_link_setup_82580 - Setup 82580 PHY for copper link
432 * @hw: pointer to the HW structure
434 * Sets up Carrier-sense on Transmit and downshift values.
436 s32
igb_copper_link_setup_82580(struct e1000_hw
*hw
)
438 struct e1000_phy_info
*phy
= &hw
->phy
;
443 if (phy
->reset_disable
) {
448 if (phy
->type
== e1000_phy_82580
) {
449 ret_val
= hw
->phy
.ops
.reset(hw
);
451 hw_dbg("Error resetting the PHY.\n");
456 /* Enable CRS on TX. This must be set for half-duplex operation. */
457 ret_val
= phy
->ops
.read_reg(hw
, I82580_CFG_REG
, &phy_data
);
461 phy_data
|= I82580_CFG_ASSERT_CRS_ON_TX
;
463 /* Enable downshift */
464 phy_data
|= I82580_CFG_ENABLE_DOWNSHIFT
;
466 ret_val
= phy
->ops
.write_reg(hw
, I82580_CFG_REG
, phy_data
);
473 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
474 * @hw: pointer to the HW structure
476 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
477 * and downshift values are set also.
479 s32
igb_copper_link_setup_m88(struct e1000_hw
*hw
)
481 struct e1000_phy_info
*phy
= &hw
->phy
;
485 if (phy
->reset_disable
) {
490 /* Enable CRS on TX. This must be set for half-duplex operation. */
491 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
495 phy_data
|= M88E1000_PSCR_ASSERT_CRS_ON_TX
;
499 * MDI/MDI-X = 0 (default)
500 * 0 - Auto for all speeds
503 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
505 phy_data
&= ~M88E1000_PSCR_AUTO_X_MODE
;
509 phy_data
|= M88E1000_PSCR_MDI_MANUAL_MODE
;
512 phy_data
|= M88E1000_PSCR_MDIX_MANUAL_MODE
;
515 phy_data
|= M88E1000_PSCR_AUTO_X_1000T
;
519 phy_data
|= M88E1000_PSCR_AUTO_X_MODE
;
525 * disable_polarity_correction = 0 (default)
526 * Automatic Correction for Reversed Cable Polarity
530 phy_data
&= ~M88E1000_PSCR_POLARITY_REVERSAL
;
531 if (phy
->disable_polarity_correction
== 1)
532 phy_data
|= M88E1000_PSCR_POLARITY_REVERSAL
;
534 ret_val
= phy
->ops
.write_reg(hw
, M88E1000_PHY_SPEC_CTRL
, phy_data
);
538 if (phy
->revision
< E1000_REVISION_4
) {
540 * Force TX_CLK in the Extended PHY Specific Control Register
543 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
,
548 phy_data
|= M88E1000_EPSCR_TX_CLK_25
;
550 if ((phy
->revision
== E1000_REVISION_2
) &&
551 (phy
->id
== M88E1111_I_PHY_ID
)) {
552 /* 82573L PHY - set the downshift counter to 5x. */
553 phy_data
&= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK
;
554 phy_data
|= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X
;
556 /* Configure Master and Slave downshift values */
557 phy_data
&= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
|
558 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK
);
559 phy_data
|= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
|
560 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X
);
562 ret_val
= phy
->ops
.write_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
,
568 /* Commit the changes. */
569 ret_val
= igb_phy_sw_reset(hw
);
571 hw_dbg("Error committing the PHY changes\n");
574 if (phy
->type
== e1000_phy_i210
) {
575 ret_val
= igb_set_master_slave_mode(hw
);
585 * igb_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
586 * @hw: pointer to the HW structure
588 * Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
589 * Also enables and sets the downshift parameters.
591 s32
igb_copper_link_setup_m88_gen2(struct e1000_hw
*hw
)
593 struct e1000_phy_info
*phy
= &hw
->phy
;
597 if (phy
->reset_disable
) {
602 /* Enable CRS on Tx. This must be set for half-duplex operation. */
603 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
609 * MDI/MDI-X = 0 (default)
610 * 0 - Auto for all speeds
613 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
615 phy_data
&= ~M88E1000_PSCR_AUTO_X_MODE
;
619 phy_data
|= M88E1000_PSCR_MDI_MANUAL_MODE
;
622 phy_data
|= M88E1000_PSCR_MDIX_MANUAL_MODE
;
625 /* M88E1112 does not support this mode) */
626 if (phy
->id
!= M88E1112_E_PHY_ID
) {
627 phy_data
|= M88E1000_PSCR_AUTO_X_1000T
;
632 phy_data
|= M88E1000_PSCR_AUTO_X_MODE
;
638 * disable_polarity_correction = 0 (default)
639 * Automatic Correction for Reversed Cable Polarity
643 phy_data
&= ~M88E1000_PSCR_POLARITY_REVERSAL
;
644 if (phy
->disable_polarity_correction
== 1)
645 phy_data
|= M88E1000_PSCR_POLARITY_REVERSAL
;
647 /* Enable downshift and setting it to X6 */
648 phy_data
&= ~I347AT4_PSCR_DOWNSHIFT_MASK
;
649 phy_data
|= I347AT4_PSCR_DOWNSHIFT_6X
;
650 phy_data
|= I347AT4_PSCR_DOWNSHIFT_ENABLE
;
652 ret_val
= phy
->ops
.write_reg(hw
, M88E1000_PHY_SPEC_CTRL
, phy_data
);
656 /* Commit the changes. */
657 ret_val
= igb_phy_sw_reset(hw
);
659 hw_dbg("Error committing the PHY changes\n");
668 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
669 * @hw: pointer to the HW structure
671 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
674 s32
igb_copper_link_setup_igp(struct e1000_hw
*hw
)
676 struct e1000_phy_info
*phy
= &hw
->phy
;
680 if (phy
->reset_disable
) {
685 ret_val
= phy
->ops
.reset(hw
);
687 hw_dbg("Error resetting the PHY.\n");
692 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
693 * timeout issues when LFS is enabled.
698 * The NVM settings will configure LPLU in D3 for
701 if (phy
->type
== e1000_phy_igp
) {
702 /* disable lplu d3 during driver init */
703 if (phy
->ops
.set_d3_lplu_state
)
704 ret_val
= phy
->ops
.set_d3_lplu_state(hw
, false);
706 hw_dbg("Error Disabling LPLU D3\n");
711 /* disable lplu d0 during driver init */
712 ret_val
= phy
->ops
.set_d0_lplu_state(hw
, false);
714 hw_dbg("Error Disabling LPLU D0\n");
717 /* Configure mdi-mdix settings */
718 ret_val
= phy
->ops
.read_reg(hw
, IGP01E1000_PHY_PORT_CTRL
, &data
);
722 data
&= ~IGP01E1000_PSCR_AUTO_MDIX
;
726 data
&= ~IGP01E1000_PSCR_FORCE_MDI_MDIX
;
729 data
|= IGP01E1000_PSCR_FORCE_MDI_MDIX
;
733 data
|= IGP01E1000_PSCR_AUTO_MDIX
;
736 ret_val
= phy
->ops
.write_reg(hw
, IGP01E1000_PHY_PORT_CTRL
, data
);
740 /* set auto-master slave resolution settings */
741 if (hw
->mac
.autoneg
) {
743 * when autonegotiation advertisement is only 1000Mbps then we
744 * should disable SmartSpeed and enable Auto MasterSlave
745 * resolution as hardware default.
747 if (phy
->autoneg_advertised
== ADVERTISE_1000_FULL
) {
748 /* Disable SmartSpeed */
749 ret_val
= phy
->ops
.read_reg(hw
,
750 IGP01E1000_PHY_PORT_CONFIG
,
755 data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
756 ret_val
= phy
->ops
.write_reg(hw
,
757 IGP01E1000_PHY_PORT_CONFIG
,
762 /* Set auto Master/Slave resolution process */
763 ret_val
= phy
->ops
.read_reg(hw
, PHY_1000T_CTRL
, &data
);
767 data
&= ~CR_1000T_MS_ENABLE
;
768 ret_val
= phy
->ops
.write_reg(hw
, PHY_1000T_CTRL
, data
);
773 ret_val
= phy
->ops
.read_reg(hw
, PHY_1000T_CTRL
, &data
);
777 /* load defaults for future use */
778 phy
->original_ms_type
= (data
& CR_1000T_MS_ENABLE
) ?
779 ((data
& CR_1000T_MS_VALUE
) ?
780 e1000_ms_force_master
:
781 e1000_ms_force_slave
) :
784 switch (phy
->ms_type
) {
785 case e1000_ms_force_master
:
786 data
|= (CR_1000T_MS_ENABLE
| CR_1000T_MS_VALUE
);
788 case e1000_ms_force_slave
:
789 data
|= CR_1000T_MS_ENABLE
;
790 data
&= ~(CR_1000T_MS_VALUE
);
793 data
&= ~CR_1000T_MS_ENABLE
;
797 ret_val
= phy
->ops
.write_reg(hw
, PHY_1000T_CTRL
, data
);
807 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
808 * @hw: pointer to the HW structure
810 * Performs initial bounds checking on autoneg advertisement parameter, then
811 * configure to advertise the full capability. Setup the PHY to autoneg
812 * and restart the negotiation process between the link partner. If
813 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
815 static s32
igb_copper_link_autoneg(struct e1000_hw
*hw
)
817 struct e1000_phy_info
*phy
= &hw
->phy
;
822 * Perform some bounds checking on the autoneg advertisement
825 phy
->autoneg_advertised
&= phy
->autoneg_mask
;
828 * If autoneg_advertised is zero, we assume it was not defaulted
829 * by the calling code so we set to advertise full capability.
831 if (phy
->autoneg_advertised
== 0)
832 phy
->autoneg_advertised
= phy
->autoneg_mask
;
834 hw_dbg("Reconfiguring auto-neg advertisement params\n");
835 ret_val
= igb_phy_setup_autoneg(hw
);
837 hw_dbg("Error Setting up Auto-Negotiation\n");
840 hw_dbg("Restarting Auto-Neg\n");
843 * Restart auto-negotiation by setting the Auto Neg Enable bit and
844 * the Auto Neg Restart bit in the PHY control register.
846 ret_val
= phy
->ops
.read_reg(hw
, PHY_CONTROL
, &phy_ctrl
);
850 phy_ctrl
|= (MII_CR_AUTO_NEG_EN
| MII_CR_RESTART_AUTO_NEG
);
851 ret_val
= phy
->ops
.write_reg(hw
, PHY_CONTROL
, phy_ctrl
);
856 * Does the user want to wait for Auto-Neg to complete here, or
857 * check at a later time (for example, callback routine).
859 if (phy
->autoneg_wait_to_complete
) {
860 ret_val
= igb_wait_autoneg(hw
);
862 hw_dbg("Error while waiting for "
863 "autoneg to complete\n");
868 hw
->mac
.get_link_status
= true;
875 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
876 * @hw: pointer to the HW structure
878 * Reads the MII auto-neg advertisement register and/or the 1000T control
879 * register and if the PHY is already setup for auto-negotiation, then
880 * return successful. Otherwise, setup advertisement and flow control to
881 * the appropriate values for the wanted auto-negotiation.
883 static s32
igb_phy_setup_autoneg(struct e1000_hw
*hw
)
885 struct e1000_phy_info
*phy
= &hw
->phy
;
887 u16 mii_autoneg_adv_reg
;
888 u16 mii_1000t_ctrl_reg
= 0;
890 phy
->autoneg_advertised
&= phy
->autoneg_mask
;
892 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
893 ret_val
= phy
->ops
.read_reg(hw
, PHY_AUTONEG_ADV
, &mii_autoneg_adv_reg
);
897 if (phy
->autoneg_mask
& ADVERTISE_1000_FULL
) {
898 /* Read the MII 1000Base-T Control Register (Address 9). */
899 ret_val
= phy
->ops
.read_reg(hw
, PHY_1000T_CTRL
,
900 &mii_1000t_ctrl_reg
);
906 * Need to parse both autoneg_advertised and fc and set up
907 * the appropriate PHY registers. First we will parse for
908 * autoneg_advertised software override. Since we can advertise
909 * a plethora of combinations, we need to check each bit
914 * First we clear all the 10/100 mb speed bits in the Auto-Neg
915 * Advertisement Register (Address 4) and the 1000 mb speed bits in
916 * the 1000Base-T Control Register (Address 9).
918 mii_autoneg_adv_reg
&= ~(NWAY_AR_100TX_FD_CAPS
|
919 NWAY_AR_100TX_HD_CAPS
|
920 NWAY_AR_10T_FD_CAPS
|
921 NWAY_AR_10T_HD_CAPS
);
922 mii_1000t_ctrl_reg
&= ~(CR_1000T_HD_CAPS
| CR_1000T_FD_CAPS
);
924 hw_dbg("autoneg_advertised %x\n", phy
->autoneg_advertised
);
926 /* Do we want to advertise 10 Mb Half Duplex? */
927 if (phy
->autoneg_advertised
& ADVERTISE_10_HALF
) {
928 hw_dbg("Advertise 10mb Half duplex\n");
929 mii_autoneg_adv_reg
|= NWAY_AR_10T_HD_CAPS
;
932 /* Do we want to advertise 10 Mb Full Duplex? */
933 if (phy
->autoneg_advertised
& ADVERTISE_10_FULL
) {
934 hw_dbg("Advertise 10mb Full duplex\n");
935 mii_autoneg_adv_reg
|= NWAY_AR_10T_FD_CAPS
;
938 /* Do we want to advertise 100 Mb Half Duplex? */
939 if (phy
->autoneg_advertised
& ADVERTISE_100_HALF
) {
940 hw_dbg("Advertise 100mb Half duplex\n");
941 mii_autoneg_adv_reg
|= NWAY_AR_100TX_HD_CAPS
;
944 /* Do we want to advertise 100 Mb Full Duplex? */
945 if (phy
->autoneg_advertised
& ADVERTISE_100_FULL
) {
946 hw_dbg("Advertise 100mb Full duplex\n");
947 mii_autoneg_adv_reg
|= NWAY_AR_100TX_FD_CAPS
;
950 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
951 if (phy
->autoneg_advertised
& ADVERTISE_1000_HALF
)
952 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
954 /* Do we want to advertise 1000 Mb Full Duplex? */
955 if (phy
->autoneg_advertised
& ADVERTISE_1000_FULL
) {
956 hw_dbg("Advertise 1000mb Full duplex\n");
957 mii_1000t_ctrl_reg
|= CR_1000T_FD_CAPS
;
961 * Check for a software override of the flow control settings, and
962 * setup the PHY advertisement registers accordingly. If
963 * auto-negotiation is enabled, then software will have to set the
964 * "PAUSE" bits to the correct value in the Auto-Negotiation
965 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
968 * The possible values of the "fc" parameter are:
969 * 0: Flow control is completely disabled
970 * 1: Rx flow control is enabled (we can receive pause frames
971 * but not send pause frames).
972 * 2: Tx flow control is enabled (we can send pause frames
973 * but we do not support receiving pause frames).
974 * 3: Both Rx and TX flow control (symmetric) are enabled.
975 * other: No software override. The flow control configuration
976 * in the EEPROM is used.
978 switch (hw
->fc
.current_mode
) {
981 * Flow control (RX & TX) is completely disabled by a
982 * software over-ride.
984 mii_autoneg_adv_reg
&= ~(NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
986 case e1000_fc_rx_pause
:
988 * RX Flow control is enabled, and TX Flow control is
989 * disabled, by a software over-ride.
991 * Since there really isn't a way to advertise that we are
992 * capable of RX Pause ONLY, we will advertise that we
993 * support both symmetric and asymmetric RX PAUSE. Later
994 * (in e1000_config_fc_after_link_up) we will disable the
995 * hw's ability to send PAUSE frames.
997 mii_autoneg_adv_reg
|= (NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
999 case e1000_fc_tx_pause
:
1001 * TX Flow control is enabled, and RX Flow control is
1002 * disabled, by a software over-ride.
1004 mii_autoneg_adv_reg
|= NWAY_AR_ASM_DIR
;
1005 mii_autoneg_adv_reg
&= ~NWAY_AR_PAUSE
;
1009 * Flow control (both RX and TX) is enabled by a software
1012 mii_autoneg_adv_reg
|= (NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
1015 hw_dbg("Flow control param set incorrectly\n");
1016 ret_val
= -E1000_ERR_CONFIG
;
1020 ret_val
= phy
->ops
.write_reg(hw
, PHY_AUTONEG_ADV
, mii_autoneg_adv_reg
);
1024 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg
);
1026 if (phy
->autoneg_mask
& ADVERTISE_1000_FULL
) {
1027 ret_val
= phy
->ops
.write_reg(hw
,
1029 mii_1000t_ctrl_reg
);
1039 * igb_setup_copper_link - Configure copper link settings
1040 * @hw: pointer to the HW structure
1042 * Calls the appropriate function to configure the link for auto-neg or forced
1043 * speed and duplex. Then we check for link, once link is established calls
1044 * to configure collision distance and flow control are called. If link is
1045 * not established, we return -E1000_ERR_PHY (-2).
1047 s32
igb_setup_copper_link(struct e1000_hw
*hw
)
1053 if (hw
->mac
.autoneg
) {
1055 * Setup autoneg and flow control advertisement and perform
1058 ret_val
= igb_copper_link_autoneg(hw
);
1063 * PHY will be set to 10H, 10F, 100H or 100F
1064 * depending on user settings.
1066 hw_dbg("Forcing Speed and Duplex\n");
1067 ret_val
= hw
->phy
.ops
.force_speed_duplex(hw
);
1069 hw_dbg("Error Forcing Speed and Duplex\n");
1075 * Check link status. Wait up to 100 microseconds for link to become
1078 ret_val
= igb_phy_has_link(hw
,
1079 COPPER_LINK_UP_LIMIT
,
1086 hw_dbg("Valid link established!!!\n");
1087 igb_config_collision_dist(hw
);
1088 ret_val
= igb_config_fc_after_link_up(hw
);
1090 hw_dbg("Unable to establish link!!!\n");
1098 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1099 * @hw: pointer to the HW structure
1101 * Calls the PHY setup function to force speed and duplex. Clears the
1102 * auto-crossover to force MDI manually. Waits for link and returns
1103 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1105 s32
igb_phy_force_speed_duplex_igp(struct e1000_hw
*hw
)
1107 struct e1000_phy_info
*phy
= &hw
->phy
;
1112 ret_val
= phy
->ops
.read_reg(hw
, PHY_CONTROL
, &phy_data
);
1116 igb_phy_force_speed_duplex_setup(hw
, &phy_data
);
1118 ret_val
= phy
->ops
.write_reg(hw
, PHY_CONTROL
, phy_data
);
1123 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
1124 * forced whenever speed and duplex are forced.
1126 ret_val
= phy
->ops
.read_reg(hw
, IGP01E1000_PHY_PORT_CTRL
, &phy_data
);
1130 phy_data
&= ~IGP01E1000_PSCR_AUTO_MDIX
;
1131 phy_data
&= ~IGP01E1000_PSCR_FORCE_MDI_MDIX
;
1133 ret_val
= phy
->ops
.write_reg(hw
, IGP01E1000_PHY_PORT_CTRL
, phy_data
);
1137 hw_dbg("IGP PSCR: %X\n", phy_data
);
1141 if (phy
->autoneg_wait_to_complete
) {
1142 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
1144 ret_val
= igb_phy_has_link(hw
,
1152 hw_dbg("Link taking longer than expected.\n");
1155 ret_val
= igb_phy_has_link(hw
,
1168 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1169 * @hw: pointer to the HW structure
1171 * Calls the PHY setup function to force speed and duplex. Clears the
1172 * auto-crossover to force MDI manually. Resets the PHY to commit the
1173 * changes. If time expires while waiting for link up, we reset the DSP.
1174 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
1175 * successful completion, else return corresponding error code.
1177 s32
igb_phy_force_speed_duplex_m88(struct e1000_hw
*hw
)
1179 struct e1000_phy_info
*phy
= &hw
->phy
;
1185 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1186 * forced whenever speed and duplex are forced.
1188 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
1192 phy_data
&= ~M88E1000_PSCR_AUTO_X_MODE
;
1193 ret_val
= phy
->ops
.write_reg(hw
, M88E1000_PHY_SPEC_CTRL
, phy_data
);
1197 hw_dbg("M88E1000 PSCR: %X\n", phy_data
);
1199 ret_val
= phy
->ops
.read_reg(hw
, PHY_CONTROL
, &phy_data
);
1203 igb_phy_force_speed_duplex_setup(hw
, &phy_data
);
1205 ret_val
= phy
->ops
.write_reg(hw
, PHY_CONTROL
, phy_data
);
1209 /* Reset the phy to commit changes. */
1210 ret_val
= igb_phy_sw_reset(hw
);
1214 if (phy
->autoneg_wait_to_complete
) {
1215 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
1217 ret_val
= igb_phy_has_link(hw
, PHY_FORCE_LIMIT
, 100000, &link
);
1222 bool reset_dsp
= true;
1224 switch (hw
->phy
.id
) {
1225 case I347AT4_E_PHY_ID
:
1226 case M88E1112_E_PHY_ID
:
1231 if (hw
->phy
.type
!= e1000_phy_m88
)
1236 hw_dbg("Link taking longer than expected.\n");
1239 * We didn't get link.
1240 * Reset the DSP and cross our fingers.
1242 ret_val
= phy
->ops
.write_reg(hw
,
1243 M88E1000_PHY_PAGE_SELECT
,
1247 ret_val
= igb_phy_reset_dsp(hw
);
1254 ret_val
= igb_phy_has_link(hw
, PHY_FORCE_LIMIT
,
1260 if (hw
->phy
.type
!= e1000_phy_m88
||
1261 hw
->phy
.id
== I347AT4_E_PHY_ID
||
1262 hw
->phy
.id
== M88E1112_E_PHY_ID
||
1263 hw
->phy
.id
== I210_I_PHY_ID
)
1266 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
, &phy_data
);
1271 * Resetting the phy means we need to re-force TX_CLK in the
1272 * Extended PHY Specific Control Register to 25MHz clock from
1273 * the reset value of 2.5MHz.
1275 phy_data
|= M88E1000_EPSCR_TX_CLK_25
;
1276 ret_val
= phy
->ops
.write_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
, phy_data
);
1281 * In addition, we must re-enable CRS on Tx for both half and full
1284 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
1288 phy_data
|= M88E1000_PSCR_ASSERT_CRS_ON_TX
;
1289 ret_val
= phy
->ops
.write_reg(hw
, M88E1000_PHY_SPEC_CTRL
, phy_data
);
1296 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1297 * @hw: pointer to the HW structure
1298 * @phy_ctrl: pointer to current value of PHY_CONTROL
1300 * Forces speed and duplex on the PHY by doing the following: disable flow
1301 * control, force speed/duplex on the MAC, disable auto speed detection,
1302 * disable auto-negotiation, configure duplex, configure speed, configure
1303 * the collision distance, write configuration to CTRL register. The
1304 * caller must write to the PHY_CONTROL register for these settings to
1307 static void igb_phy_force_speed_duplex_setup(struct e1000_hw
*hw
,
1310 struct e1000_mac_info
*mac
= &hw
->mac
;
1313 /* Turn off flow control when forcing speed/duplex */
1314 hw
->fc
.current_mode
= e1000_fc_none
;
1316 /* Force speed/duplex on the mac */
1317 ctrl
= rd32(E1000_CTRL
);
1318 ctrl
|= (E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
1319 ctrl
&= ~E1000_CTRL_SPD_SEL
;
1321 /* Disable Auto Speed Detection */
1322 ctrl
&= ~E1000_CTRL_ASDE
;
1324 /* Disable autoneg on the phy */
1325 *phy_ctrl
&= ~MII_CR_AUTO_NEG_EN
;
1327 /* Forcing Full or Half Duplex? */
1328 if (mac
->forced_speed_duplex
& E1000_ALL_HALF_DUPLEX
) {
1329 ctrl
&= ~E1000_CTRL_FD
;
1330 *phy_ctrl
&= ~MII_CR_FULL_DUPLEX
;
1331 hw_dbg("Half Duplex\n");
1333 ctrl
|= E1000_CTRL_FD
;
1334 *phy_ctrl
|= MII_CR_FULL_DUPLEX
;
1335 hw_dbg("Full Duplex\n");
1338 /* Forcing 10mb or 100mb? */
1339 if (mac
->forced_speed_duplex
& E1000_ALL_100_SPEED
) {
1340 ctrl
|= E1000_CTRL_SPD_100
;
1341 *phy_ctrl
|= MII_CR_SPEED_100
;
1342 *phy_ctrl
&= ~(MII_CR_SPEED_1000
| MII_CR_SPEED_10
);
1343 hw_dbg("Forcing 100mb\n");
1345 ctrl
&= ~(E1000_CTRL_SPD_1000
| E1000_CTRL_SPD_100
);
1346 *phy_ctrl
|= MII_CR_SPEED_10
;
1347 *phy_ctrl
&= ~(MII_CR_SPEED_1000
| MII_CR_SPEED_100
);
1348 hw_dbg("Forcing 10mb\n");
1351 igb_config_collision_dist(hw
);
1353 wr32(E1000_CTRL
, ctrl
);
1357 * igb_set_d3_lplu_state - Sets low power link up state for D3
1358 * @hw: pointer to the HW structure
1359 * @active: boolean used to enable/disable lplu
1361 * Success returns 0, Failure returns 1
1363 * The low power link up (lplu) state is set to the power management level D3
1364 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1365 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1366 * is used during Dx states where the power conservation is most important.
1367 * During driver activity, SmartSpeed should be enabled so performance is
1370 s32
igb_set_d3_lplu_state(struct e1000_hw
*hw
, bool active
)
1372 struct e1000_phy_info
*phy
= &hw
->phy
;
1376 if (!(hw
->phy
.ops
.read_reg
))
1379 ret_val
= phy
->ops
.read_reg(hw
, IGP02E1000_PHY_POWER_MGMT
, &data
);
1384 data
&= ~IGP02E1000_PM_D3_LPLU
;
1385 ret_val
= phy
->ops
.write_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
1390 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1391 * during Dx states where the power conservation is most
1392 * important. During driver activity we should enable
1393 * SmartSpeed, so performance is maintained.
1395 if (phy
->smart_speed
== e1000_smart_speed_on
) {
1396 ret_val
= phy
->ops
.read_reg(hw
,
1397 IGP01E1000_PHY_PORT_CONFIG
,
1402 data
|= IGP01E1000_PSCFR_SMART_SPEED
;
1403 ret_val
= phy
->ops
.write_reg(hw
,
1404 IGP01E1000_PHY_PORT_CONFIG
,
1408 } else if (phy
->smart_speed
== e1000_smart_speed_off
) {
1409 ret_val
= phy
->ops
.read_reg(hw
,
1410 IGP01E1000_PHY_PORT_CONFIG
,
1415 data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
1416 ret_val
= phy
->ops
.write_reg(hw
,
1417 IGP01E1000_PHY_PORT_CONFIG
,
1422 } else if ((phy
->autoneg_advertised
== E1000_ALL_SPEED_DUPLEX
) ||
1423 (phy
->autoneg_advertised
== E1000_ALL_NOT_GIG
) ||
1424 (phy
->autoneg_advertised
== E1000_ALL_10_SPEED
)) {
1425 data
|= IGP02E1000_PM_D3_LPLU
;
1426 ret_val
= phy
->ops
.write_reg(hw
, IGP02E1000_PHY_POWER_MGMT
,
1431 /* When LPLU is enabled, we should disable SmartSpeed */
1432 ret_val
= phy
->ops
.read_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
1437 data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
1438 ret_val
= phy
->ops
.write_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
1447 * igb_check_downshift - Checks whether a downshift in speed occurred
1448 * @hw: pointer to the HW structure
1450 * Success returns 0, Failure returns 1
1452 * A downshift is detected by querying the PHY link health.
1454 s32
igb_check_downshift(struct e1000_hw
*hw
)
1456 struct e1000_phy_info
*phy
= &hw
->phy
;
1458 u16 phy_data
, offset
, mask
;
1460 switch (phy
->type
) {
1461 case e1000_phy_i210
:
1463 case e1000_phy_gg82563
:
1464 offset
= M88E1000_PHY_SPEC_STATUS
;
1465 mask
= M88E1000_PSSR_DOWNSHIFT
;
1467 case e1000_phy_igp_2
:
1469 case e1000_phy_igp_3
:
1470 offset
= IGP01E1000_PHY_LINK_HEALTH
;
1471 mask
= IGP01E1000_PLHR_SS_DOWNGRADE
;
1474 /* speed downshift not supported */
1475 phy
->speed_downgraded
= false;
1480 ret_val
= phy
->ops
.read_reg(hw
, offset
, &phy_data
);
1483 phy
->speed_downgraded
= (phy_data
& mask
) ? true : false;
1490 * igb_check_polarity_m88 - Checks the polarity.
1491 * @hw: pointer to the HW structure
1493 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1495 * Polarity is determined based on the PHY specific status register.
1497 s32
igb_check_polarity_m88(struct e1000_hw
*hw
)
1499 struct e1000_phy_info
*phy
= &hw
->phy
;
1503 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_PHY_SPEC_STATUS
, &data
);
1506 phy
->cable_polarity
= (data
& M88E1000_PSSR_REV_POLARITY
)
1507 ? e1000_rev_polarity_reversed
1508 : e1000_rev_polarity_normal
;
1514 * igb_check_polarity_igp - Checks the polarity.
1515 * @hw: pointer to the HW structure
1517 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1519 * Polarity is determined based on the PHY port status register, and the
1520 * current speed (since there is no polarity at 100Mbps).
1522 static s32
igb_check_polarity_igp(struct e1000_hw
*hw
)
1524 struct e1000_phy_info
*phy
= &hw
->phy
;
1526 u16 data
, offset
, mask
;
1529 * Polarity is determined based on the speed of
1532 ret_val
= phy
->ops
.read_reg(hw
, IGP01E1000_PHY_PORT_STATUS
, &data
);
1536 if ((data
& IGP01E1000_PSSR_SPEED_MASK
) ==
1537 IGP01E1000_PSSR_SPEED_1000MBPS
) {
1538 offset
= IGP01E1000_PHY_PCS_INIT_REG
;
1539 mask
= IGP01E1000_PHY_POLARITY_MASK
;
1542 * This really only applies to 10Mbps since
1543 * there is no polarity for 100Mbps (always 0).
1545 offset
= IGP01E1000_PHY_PORT_STATUS
;
1546 mask
= IGP01E1000_PSSR_POLARITY_REVERSED
;
1549 ret_val
= phy
->ops
.read_reg(hw
, offset
, &data
);
1552 phy
->cable_polarity
= (data
& mask
)
1553 ? e1000_rev_polarity_reversed
1554 : e1000_rev_polarity_normal
;
1561 * igb_wait_autoneg - Wait for auto-neg compeletion
1562 * @hw: pointer to the HW structure
1564 * Waits for auto-negotiation to complete or for the auto-negotiation time
1565 * limit to expire, which ever happens first.
1567 static s32
igb_wait_autoneg(struct e1000_hw
*hw
)
1572 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1573 for (i
= PHY_AUTO_NEG_LIMIT
; i
> 0; i
--) {
1574 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_STATUS
, &phy_status
);
1577 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_STATUS
, &phy_status
);
1580 if (phy_status
& MII_SR_AUTONEG_COMPLETE
)
1586 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1593 * igb_phy_has_link - Polls PHY for link
1594 * @hw: pointer to the HW structure
1595 * @iterations: number of times to poll for link
1596 * @usec_interval: delay between polling attempts
1597 * @success: pointer to whether polling was successful or not
1599 * Polls the PHY status register for link, 'iterations' number of times.
1601 s32
igb_phy_has_link(struct e1000_hw
*hw
, u32 iterations
,
1602 u32 usec_interval
, bool *success
)
1607 for (i
= 0; i
< iterations
; i
++) {
1609 * Some PHYs require the PHY_STATUS register to be read
1610 * twice due to the link bit being sticky. No harm doing
1611 * it across the board.
1613 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_STATUS
, &phy_status
);
1616 * If the first read fails, another entity may have
1617 * ownership of the resources, wait and try again to
1618 * see if they have relinquished the resources yet.
1620 udelay(usec_interval
);
1622 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_STATUS
, &phy_status
);
1625 if (phy_status
& MII_SR_LINK_STATUS
)
1627 if (usec_interval
>= 1000)
1628 mdelay(usec_interval
/1000);
1630 udelay(usec_interval
);
1633 *success
= (i
< iterations
) ? true : false;
1639 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
1640 * @hw: pointer to the HW structure
1642 * Reads the PHY specific status register to retrieve the cable length
1643 * information. The cable length is determined by averaging the minimum and
1644 * maximum values to get the "average" cable length. The m88 PHY has four
1645 * possible cable length values, which are:
1646 * Register Value Cable Length
1650 * 3 110 - 140 meters
1653 s32
igb_get_cable_length_m88(struct e1000_hw
*hw
)
1655 struct e1000_phy_info
*phy
= &hw
->phy
;
1657 u16 phy_data
, index
;
1659 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
);
1663 index
= (phy_data
& M88E1000_PSSR_CABLE_LENGTH
) >>
1664 M88E1000_PSSR_CABLE_LENGTH_SHIFT
;
1665 if (index
>= M88E1000_CABLE_LENGTH_TABLE_SIZE
- 1) {
1666 ret_val
= -E1000_ERR_PHY
;
1670 phy
->min_cable_length
= e1000_m88_cable_length_table
[index
];
1671 phy
->max_cable_length
= e1000_m88_cable_length_table
[index
+ 1];
1673 phy
->cable_length
= (phy
->min_cable_length
+ phy
->max_cable_length
) / 2;
1679 s32
igb_get_cable_length_m88_gen2(struct e1000_hw
*hw
)
1681 struct e1000_phy_info
*phy
= &hw
->phy
;
1683 u16 phy_data
, phy_data2
, index
, default_page
, is_cm
;
1685 switch (hw
->phy
.id
) {
1687 case I347AT4_E_PHY_ID
:
1688 /* Remember the original page select and set it to 7 */
1689 ret_val
= phy
->ops
.read_reg(hw
, I347AT4_PAGE_SELECT
,
1694 ret_val
= phy
->ops
.write_reg(hw
, I347AT4_PAGE_SELECT
, 0x07);
1698 /* Get cable length from PHY Cable Diagnostics Control Reg */
1699 ret_val
= phy
->ops
.read_reg(hw
, (I347AT4_PCDL
+ phy
->addr
),
1704 /* Check if the unit of cable length is meters or cm */
1705 ret_val
= phy
->ops
.read_reg(hw
, I347AT4_PCDC
, &phy_data2
);
1709 is_cm
= !(phy_data2
& I347AT4_PCDC_CABLE_LENGTH_UNIT
);
1711 /* Populate the phy structure with cable length in meters */
1712 phy
->min_cable_length
= phy_data
/ (is_cm
? 100 : 1);
1713 phy
->max_cable_length
= phy_data
/ (is_cm
? 100 : 1);
1714 phy
->cable_length
= phy_data
/ (is_cm
? 100 : 1);
1716 /* Reset the page selec to its original value */
1717 ret_val
= phy
->ops
.write_reg(hw
, I347AT4_PAGE_SELECT
,
1722 case M88E1112_E_PHY_ID
:
1723 /* Remember the original page select and set it to 5 */
1724 ret_val
= phy
->ops
.read_reg(hw
, I347AT4_PAGE_SELECT
,
1729 ret_val
= phy
->ops
.write_reg(hw
, I347AT4_PAGE_SELECT
, 0x05);
1733 ret_val
= phy
->ops
.read_reg(hw
, M88E1112_VCT_DSP_DISTANCE
,
1738 index
= (phy_data
& M88E1000_PSSR_CABLE_LENGTH
) >>
1739 M88E1000_PSSR_CABLE_LENGTH_SHIFT
;
1740 if (index
>= M88E1000_CABLE_LENGTH_TABLE_SIZE
- 1) {
1741 ret_val
= -E1000_ERR_PHY
;
1745 phy
->min_cable_length
= e1000_m88_cable_length_table
[index
];
1746 phy
->max_cable_length
= e1000_m88_cable_length_table
[index
+ 1];
1748 phy
->cable_length
= (phy
->min_cable_length
+
1749 phy
->max_cable_length
) / 2;
1751 /* Reset the page select to its original value */
1752 ret_val
= phy
->ops
.write_reg(hw
, I347AT4_PAGE_SELECT
,
1759 ret_val
= -E1000_ERR_PHY
;
1768 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1769 * @hw: pointer to the HW structure
1771 * The automatic gain control (agc) normalizes the amplitude of the
1772 * received signal, adjusting for the attenuation produced by the
1773 * cable. By reading the AGC registers, which represent the
1774 * combination of coarse and fine gain value, the value can be put
1775 * into a lookup table to obtain the approximate cable length
1778 s32
igb_get_cable_length_igp_2(struct e1000_hw
*hw
)
1780 struct e1000_phy_info
*phy
= &hw
->phy
;
1782 u16 phy_data
, i
, agc_value
= 0;
1783 u16 cur_agc_index
, max_agc_index
= 0;
1784 u16 min_agc_index
= IGP02E1000_CABLE_LENGTH_TABLE_SIZE
- 1;
1785 static const u16 agc_reg_array
[IGP02E1000_PHY_CHANNEL_NUM
] = {
1786 IGP02E1000_PHY_AGC_A
,
1787 IGP02E1000_PHY_AGC_B
,
1788 IGP02E1000_PHY_AGC_C
,
1789 IGP02E1000_PHY_AGC_D
1792 /* Read the AGC registers for all channels */
1793 for (i
= 0; i
< IGP02E1000_PHY_CHANNEL_NUM
; i
++) {
1794 ret_val
= phy
->ops
.read_reg(hw
, agc_reg_array
[i
], &phy_data
);
1799 * Getting bits 15:9, which represent the combination of
1800 * coarse and fine gain values. The result is a number
1801 * that can be put into the lookup table to obtain the
1802 * approximate cable length.
1804 cur_agc_index
= (phy_data
>> IGP02E1000_AGC_LENGTH_SHIFT
) &
1805 IGP02E1000_AGC_LENGTH_MASK
;
1807 /* Array index bound check. */
1808 if ((cur_agc_index
>= IGP02E1000_CABLE_LENGTH_TABLE_SIZE
) ||
1809 (cur_agc_index
== 0)) {
1810 ret_val
= -E1000_ERR_PHY
;
1814 /* Remove min & max AGC values from calculation. */
1815 if (e1000_igp_2_cable_length_table
[min_agc_index
] >
1816 e1000_igp_2_cable_length_table
[cur_agc_index
])
1817 min_agc_index
= cur_agc_index
;
1818 if (e1000_igp_2_cable_length_table
[max_agc_index
] <
1819 e1000_igp_2_cable_length_table
[cur_agc_index
])
1820 max_agc_index
= cur_agc_index
;
1822 agc_value
+= e1000_igp_2_cable_length_table
[cur_agc_index
];
1825 agc_value
-= (e1000_igp_2_cable_length_table
[min_agc_index
] +
1826 e1000_igp_2_cable_length_table
[max_agc_index
]);
1827 agc_value
/= (IGP02E1000_PHY_CHANNEL_NUM
- 2);
1829 /* Calculate cable length with the error range of +/- 10 meters. */
1830 phy
->min_cable_length
= ((agc_value
- IGP02E1000_AGC_RANGE
) > 0) ?
1831 (agc_value
- IGP02E1000_AGC_RANGE
) : 0;
1832 phy
->max_cable_length
= agc_value
+ IGP02E1000_AGC_RANGE
;
1834 phy
->cable_length
= (phy
->min_cable_length
+ phy
->max_cable_length
) / 2;
1841 * igb_get_phy_info_m88 - Retrieve PHY information
1842 * @hw: pointer to the HW structure
1844 * Valid for only copper links. Read the PHY status register (sticky read)
1845 * to verify that link is up. Read the PHY special control register to
1846 * determine the polarity and 10base-T extended distance. Read the PHY
1847 * special status register to determine MDI/MDIx and current speed. If
1848 * speed is 1000, then determine cable length, local and remote receiver.
1850 s32
igb_get_phy_info_m88(struct e1000_hw
*hw
)
1852 struct e1000_phy_info
*phy
= &hw
->phy
;
1857 if (phy
->media_type
!= e1000_media_type_copper
) {
1858 hw_dbg("Phy info is only valid for copper media\n");
1859 ret_val
= -E1000_ERR_CONFIG
;
1863 ret_val
= igb_phy_has_link(hw
, 1, 0, &link
);
1868 hw_dbg("Phy info is only valid if link is up\n");
1869 ret_val
= -E1000_ERR_CONFIG
;
1873 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
1877 phy
->polarity_correction
= (phy_data
& M88E1000_PSCR_POLARITY_REVERSAL
)
1880 ret_val
= igb_check_polarity_m88(hw
);
1884 ret_val
= phy
->ops
.read_reg(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
);
1888 phy
->is_mdix
= (phy_data
& M88E1000_PSSR_MDIX
) ? true : false;
1890 if ((phy_data
& M88E1000_PSSR_SPEED
) == M88E1000_PSSR_1000MBS
) {
1891 ret_val
= phy
->ops
.get_cable_length(hw
);
1895 ret_val
= phy
->ops
.read_reg(hw
, PHY_1000T_STATUS
, &phy_data
);
1899 phy
->local_rx
= (phy_data
& SR_1000T_LOCAL_RX_STATUS
)
1900 ? e1000_1000t_rx_status_ok
1901 : e1000_1000t_rx_status_not_ok
;
1903 phy
->remote_rx
= (phy_data
& SR_1000T_REMOTE_RX_STATUS
)
1904 ? e1000_1000t_rx_status_ok
1905 : e1000_1000t_rx_status_not_ok
;
1907 /* Set values to "undefined" */
1908 phy
->cable_length
= E1000_CABLE_LENGTH_UNDEFINED
;
1909 phy
->local_rx
= e1000_1000t_rx_status_undefined
;
1910 phy
->remote_rx
= e1000_1000t_rx_status_undefined
;
1918 * igb_get_phy_info_igp - Retrieve igp PHY information
1919 * @hw: pointer to the HW structure
1921 * Read PHY status to determine if link is up. If link is up, then
1922 * set/determine 10base-T extended distance and polarity correction. Read
1923 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1924 * determine on the cable length, local and remote receiver.
1926 s32
igb_get_phy_info_igp(struct e1000_hw
*hw
)
1928 struct e1000_phy_info
*phy
= &hw
->phy
;
1933 ret_val
= igb_phy_has_link(hw
, 1, 0, &link
);
1938 hw_dbg("Phy info is only valid if link is up\n");
1939 ret_val
= -E1000_ERR_CONFIG
;
1943 phy
->polarity_correction
= true;
1945 ret_val
= igb_check_polarity_igp(hw
);
1949 ret_val
= phy
->ops
.read_reg(hw
, IGP01E1000_PHY_PORT_STATUS
, &data
);
1953 phy
->is_mdix
= (data
& IGP01E1000_PSSR_MDIX
) ? true : false;
1955 if ((data
& IGP01E1000_PSSR_SPEED_MASK
) ==
1956 IGP01E1000_PSSR_SPEED_1000MBPS
) {
1957 ret_val
= phy
->ops
.get_cable_length(hw
);
1961 ret_val
= phy
->ops
.read_reg(hw
, PHY_1000T_STATUS
, &data
);
1965 phy
->local_rx
= (data
& SR_1000T_LOCAL_RX_STATUS
)
1966 ? e1000_1000t_rx_status_ok
1967 : e1000_1000t_rx_status_not_ok
;
1969 phy
->remote_rx
= (data
& SR_1000T_REMOTE_RX_STATUS
)
1970 ? e1000_1000t_rx_status_ok
1971 : e1000_1000t_rx_status_not_ok
;
1973 phy
->cable_length
= E1000_CABLE_LENGTH_UNDEFINED
;
1974 phy
->local_rx
= e1000_1000t_rx_status_undefined
;
1975 phy
->remote_rx
= e1000_1000t_rx_status_undefined
;
1983 * igb_phy_sw_reset - PHY software reset
1984 * @hw: pointer to the HW structure
1986 * Does a software reset of the PHY by reading the PHY control register and
1987 * setting/write the control register reset bit to the PHY.
1989 s32
igb_phy_sw_reset(struct e1000_hw
*hw
)
1994 if (!(hw
->phy
.ops
.read_reg
))
1997 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_CONTROL
, &phy_ctrl
);
2001 phy_ctrl
|= MII_CR_RESET
;
2002 ret_val
= hw
->phy
.ops
.write_reg(hw
, PHY_CONTROL
, phy_ctrl
);
2013 * igb_phy_hw_reset - PHY hardware reset
2014 * @hw: pointer to the HW structure
2016 * Verify the reset block is not blocking us from resetting. Acquire
2017 * semaphore (if necessary) and read/set/write the device control reset
2018 * bit in the PHY. Wait the appropriate delay time for the device to
2019 * reset and relase the semaphore (if necessary).
2021 s32
igb_phy_hw_reset(struct e1000_hw
*hw
)
2023 struct e1000_phy_info
*phy
= &hw
->phy
;
2027 ret_val
= igb_check_reset_block(hw
);
2033 ret_val
= phy
->ops
.acquire(hw
);
2037 ctrl
= rd32(E1000_CTRL
);
2038 wr32(E1000_CTRL
, ctrl
| E1000_CTRL_PHY_RST
);
2041 udelay(phy
->reset_delay_us
);
2043 wr32(E1000_CTRL
, ctrl
);
2048 phy
->ops
.release(hw
);
2050 ret_val
= phy
->ops
.get_cfg_done(hw
);
2057 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
2058 * @hw: pointer to the HW structure
2060 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2062 s32
igb_phy_init_script_igp3(struct e1000_hw
*hw
)
2064 hw_dbg("Running IGP 3 PHY init script\n");
2066 /* PHY init IGP 3 */
2067 /* Enable rise/fall, 10-mode work in class-A */
2068 hw
->phy
.ops
.write_reg(hw
, 0x2F5B, 0x9018);
2069 /* Remove all caps from Replica path filter */
2070 hw
->phy
.ops
.write_reg(hw
, 0x2F52, 0x0000);
2071 /* Bias trimming for ADC, AFE and Driver (Default) */
2072 hw
->phy
.ops
.write_reg(hw
, 0x2FB1, 0x8B24);
2073 /* Increase Hybrid poly bias */
2074 hw
->phy
.ops
.write_reg(hw
, 0x2FB2, 0xF8F0);
2075 /* Add 4% to TX amplitude in Giga mode */
2076 hw
->phy
.ops
.write_reg(hw
, 0x2010, 0x10B0);
2077 /* Disable trimming (TTT) */
2078 hw
->phy
.ops
.write_reg(hw
, 0x2011, 0x0000);
2079 /* Poly DC correction to 94.6% + 2% for all channels */
2080 hw
->phy
.ops
.write_reg(hw
, 0x20DD, 0x249A);
2081 /* ABS DC correction to 95.9% */
2082 hw
->phy
.ops
.write_reg(hw
, 0x20DE, 0x00D3);
2083 /* BG temp curve trim */
2084 hw
->phy
.ops
.write_reg(hw
, 0x28B4, 0x04CE);
2085 /* Increasing ADC OPAMP stage 1 currents to max */
2086 hw
->phy
.ops
.write_reg(hw
, 0x2F70, 0x29E4);
2087 /* Force 1000 ( required for enabling PHY regs configuration) */
2088 hw
->phy
.ops
.write_reg(hw
, 0x0000, 0x0140);
2089 /* Set upd_freq to 6 */
2090 hw
->phy
.ops
.write_reg(hw
, 0x1F30, 0x1606);
2092 hw
->phy
.ops
.write_reg(hw
, 0x1F31, 0xB814);
2093 /* Disable adaptive fixed FFE (Default) */
2094 hw
->phy
.ops
.write_reg(hw
, 0x1F35, 0x002A);
2095 /* Enable FFE hysteresis */
2096 hw
->phy
.ops
.write_reg(hw
, 0x1F3E, 0x0067);
2097 /* Fixed FFE for short cable lengths */
2098 hw
->phy
.ops
.write_reg(hw
, 0x1F54, 0x0065);
2099 /* Fixed FFE for medium cable lengths */
2100 hw
->phy
.ops
.write_reg(hw
, 0x1F55, 0x002A);
2101 /* Fixed FFE for long cable lengths */
2102 hw
->phy
.ops
.write_reg(hw
, 0x1F56, 0x002A);
2103 /* Enable Adaptive Clip Threshold */
2104 hw
->phy
.ops
.write_reg(hw
, 0x1F72, 0x3FB0);
2105 /* AHT reset limit to 1 */
2106 hw
->phy
.ops
.write_reg(hw
, 0x1F76, 0xC0FF);
2107 /* Set AHT master delay to 127 msec */
2108 hw
->phy
.ops
.write_reg(hw
, 0x1F77, 0x1DEC);
2109 /* Set scan bits for AHT */
2110 hw
->phy
.ops
.write_reg(hw
, 0x1F78, 0xF9EF);
2111 /* Set AHT Preset bits */
2112 hw
->phy
.ops
.write_reg(hw
, 0x1F79, 0x0210);
2113 /* Change integ_factor of channel A to 3 */
2114 hw
->phy
.ops
.write_reg(hw
, 0x1895, 0x0003);
2115 /* Change prop_factor of channels BCD to 8 */
2116 hw
->phy
.ops
.write_reg(hw
, 0x1796, 0x0008);
2117 /* Change cg_icount + enable integbp for channels BCD */
2118 hw
->phy
.ops
.write_reg(hw
, 0x1798, 0xD008);
2120 * Change cg_icount + enable integbp + change prop_factor_master
2121 * to 8 for channel A
2123 hw
->phy
.ops
.write_reg(hw
, 0x1898, 0xD918);
2124 /* Disable AHT in Slave mode on channel A */
2125 hw
->phy
.ops
.write_reg(hw
, 0x187A, 0x0800);
2127 * Enable LPLU and disable AN to 1000 in non-D0a states,
2130 hw
->phy
.ops
.write_reg(hw
, 0x0019, 0x008D);
2131 /* Enable restart AN on an1000_dis change */
2132 hw
->phy
.ops
.write_reg(hw
, 0x001B, 0x2080);
2133 /* Enable wh_fifo read clock in 10/100 modes */
2134 hw
->phy
.ops
.write_reg(hw
, 0x0014, 0x0045);
2135 /* Restart AN, Speed selection is 1000 */
2136 hw
->phy
.ops
.write_reg(hw
, 0x0000, 0x1340);
2142 * igb_power_up_phy_copper - Restore copper link in case of PHY power down
2143 * @hw: pointer to the HW structure
2145 * In the case of a PHY power down to save power, or to turn off link during a
2146 * driver unload, restore the link to previous settings.
2148 void igb_power_up_phy_copper(struct e1000_hw
*hw
)
2153 /* The PHY will retain its settings across a power down/up cycle */
2154 hw
->phy
.ops
.read_reg(hw
, PHY_CONTROL
, &mii_reg
);
2155 mii_reg
&= ~MII_CR_POWER_DOWN
;
2156 if (hw
->phy
.type
== e1000_phy_i210
) {
2157 hw
->phy
.ops
.read_reg(hw
, GS40G_COPPER_SPEC
, &power_reg
);
2158 power_reg
&= ~GS40G_CS_POWER_DOWN
;
2159 hw
->phy
.ops
.write_reg(hw
, GS40G_COPPER_SPEC
, power_reg
);
2161 hw
->phy
.ops
.write_reg(hw
, PHY_CONTROL
, mii_reg
);
2165 * igb_power_down_phy_copper - Power down copper PHY
2166 * @hw: pointer to the HW structure
2168 * Power down PHY to save power when interface is down and wake on lan
2171 void igb_power_down_phy_copper(struct e1000_hw
*hw
)
2176 /* The PHY will retain its settings across a power down/up cycle */
2177 hw
->phy
.ops
.read_reg(hw
, PHY_CONTROL
, &mii_reg
);
2178 mii_reg
|= MII_CR_POWER_DOWN
;
2180 /* i210 Phy requires an additional bit for power up/down */
2181 if (hw
->phy
.type
== e1000_phy_i210
) {
2182 hw
->phy
.ops
.read_reg(hw
, GS40G_COPPER_SPEC
, &power_reg
);
2183 power_reg
|= GS40G_CS_POWER_DOWN
;
2184 hw
->phy
.ops
.write_reg(hw
, GS40G_COPPER_SPEC
, power_reg
);
2186 hw
->phy
.ops
.write_reg(hw
, PHY_CONTROL
, mii_reg
);
2191 * igb_check_polarity_82580 - Checks the polarity.
2192 * @hw: pointer to the HW structure
2194 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2196 * Polarity is determined based on the PHY specific status register.
2198 static s32
igb_check_polarity_82580(struct e1000_hw
*hw
)
2200 struct e1000_phy_info
*phy
= &hw
->phy
;
2205 ret_val
= phy
->ops
.read_reg(hw
, I82580_PHY_STATUS_2
, &data
);
2208 phy
->cable_polarity
= (data
& I82580_PHY_STATUS2_REV_POLARITY
)
2209 ? e1000_rev_polarity_reversed
2210 : e1000_rev_polarity_normal
;
2216 * igb_phy_force_speed_duplex_82580 - Force speed/duplex for I82580 PHY
2217 * @hw: pointer to the HW structure
2219 * Calls the PHY setup function to force speed and duplex. Clears the
2220 * auto-crossover to force MDI manually. Waits for link and returns
2221 * successful if link up is successful, else -E1000_ERR_PHY (-2).
2223 s32
igb_phy_force_speed_duplex_82580(struct e1000_hw
*hw
)
2225 struct e1000_phy_info
*phy
= &hw
->phy
;
2231 ret_val
= phy
->ops
.read_reg(hw
, PHY_CONTROL
, &phy_data
);
2235 igb_phy_force_speed_duplex_setup(hw
, &phy_data
);
2237 ret_val
= phy
->ops
.write_reg(hw
, PHY_CONTROL
, phy_data
);
2242 * Clear Auto-Crossover to force MDI manually. 82580 requires MDI
2243 * forced whenever speed and duplex are forced.
2245 ret_val
= phy
->ops
.read_reg(hw
, I82580_PHY_CTRL_2
, &phy_data
);
2249 phy_data
&= ~I82580_PHY_CTRL2_AUTO_MDIX
;
2250 phy_data
&= ~I82580_PHY_CTRL2_FORCE_MDI_MDIX
;
2252 ret_val
= phy
->ops
.write_reg(hw
, I82580_PHY_CTRL_2
, phy_data
);
2256 hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data
);
2260 if (phy
->autoneg_wait_to_complete
) {
2261 hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n");
2263 ret_val
= igb_phy_has_link(hw
,
2271 hw_dbg("Link taking longer than expected.\n");
2274 ret_val
= igb_phy_has_link(hw
,
2287 * igb_get_phy_info_82580 - Retrieve I82580 PHY information
2288 * @hw: pointer to the HW structure
2290 * Read PHY status to determine if link is up. If link is up, then
2291 * set/determine 10base-T extended distance and polarity correction. Read
2292 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
2293 * determine on the cable length, local and remote receiver.
2295 s32
igb_get_phy_info_82580(struct e1000_hw
*hw
)
2297 struct e1000_phy_info
*phy
= &hw
->phy
;
2303 ret_val
= igb_phy_has_link(hw
, 1, 0, &link
);
2308 hw_dbg("Phy info is only valid if link is up\n");
2309 ret_val
= -E1000_ERR_CONFIG
;
2313 phy
->polarity_correction
= true;
2315 ret_val
= igb_check_polarity_82580(hw
);
2319 ret_val
= phy
->ops
.read_reg(hw
, I82580_PHY_STATUS_2
, &data
);
2323 phy
->is_mdix
= (data
& I82580_PHY_STATUS2_MDIX
) ? true : false;
2325 if ((data
& I82580_PHY_STATUS2_SPEED_MASK
) ==
2326 I82580_PHY_STATUS2_SPEED_1000MBPS
) {
2327 ret_val
= hw
->phy
.ops
.get_cable_length(hw
);
2331 ret_val
= phy
->ops
.read_reg(hw
, PHY_1000T_STATUS
, &data
);
2335 phy
->local_rx
= (data
& SR_1000T_LOCAL_RX_STATUS
)
2336 ? e1000_1000t_rx_status_ok
2337 : e1000_1000t_rx_status_not_ok
;
2339 phy
->remote_rx
= (data
& SR_1000T_REMOTE_RX_STATUS
)
2340 ? e1000_1000t_rx_status_ok
2341 : e1000_1000t_rx_status_not_ok
;
2343 phy
->cable_length
= E1000_CABLE_LENGTH_UNDEFINED
;
2344 phy
->local_rx
= e1000_1000t_rx_status_undefined
;
2345 phy
->remote_rx
= e1000_1000t_rx_status_undefined
;
2353 * igb_get_cable_length_82580 - Determine cable length for 82580 PHY
2354 * @hw: pointer to the HW structure
2356 * Reads the diagnostic status register and verifies result is valid before
2357 * placing it in the phy_cable_length field.
2359 s32
igb_get_cable_length_82580(struct e1000_hw
*hw
)
2361 struct e1000_phy_info
*phy
= &hw
->phy
;
2363 u16 phy_data
, length
;
2366 ret_val
= phy
->ops
.read_reg(hw
, I82580_PHY_DIAG_STATUS
, &phy_data
);
2370 length
= (phy_data
& I82580_DSTATUS_CABLE_LENGTH
) >>
2371 I82580_DSTATUS_CABLE_LENGTH_SHIFT
;
2373 if (length
== E1000_CABLE_LENGTH_UNDEFINED
)
2374 ret_val
= -E1000_ERR_PHY
;
2376 phy
->cable_length
= length
;
2383 * igb_write_phy_reg_gs40g - Write GS40G PHY register
2384 * @hw: pointer to the HW structure
2385 * @offset: lower half is register offset to write to
2386 * upper half is page to use.
2387 * @data: data to write at register offset
2389 * Acquires semaphore, if necessary, then writes the data to PHY register
2390 * at the offset. Release any acquired semaphores before exiting.
2392 s32
igb_write_phy_reg_gs40g(struct e1000_hw
*hw
, u32 offset
, u16 data
)
2395 u16 page
= offset
>> GS40G_PAGE_SHIFT
;
2397 offset
= offset
& GS40G_OFFSET_MASK
;
2398 ret_val
= hw
->phy
.ops
.acquire(hw
);
2402 ret_val
= igb_write_phy_reg_mdic(hw
, GS40G_PAGE_SELECT
, page
);
2405 ret_val
= igb_write_phy_reg_mdic(hw
, offset
, data
);
2408 hw
->phy
.ops
.release(hw
);
2413 * igb_read_phy_reg_gs40g - Read GS40G PHY register
2414 * @hw: pointer to the HW structure
2415 * @offset: lower half is register offset to read to
2416 * upper half is page to use.
2417 * @data: data to read at register offset
2419 * Acquires semaphore, if necessary, then reads the data in the PHY register
2420 * at the offset. Release any acquired semaphores before exiting.
2422 s32
igb_read_phy_reg_gs40g(struct e1000_hw
*hw
, u32 offset
, u16
*data
)
2425 u16 page
= offset
>> GS40G_PAGE_SHIFT
;
2427 offset
= offset
& GS40G_OFFSET_MASK
;
2428 ret_val
= hw
->phy
.ops
.acquire(hw
);
2432 ret_val
= igb_write_phy_reg_mdic(hw
, GS40G_PAGE_SELECT
, page
);
2435 ret_val
= igb_read_phy_reg_mdic(hw
, offset
, data
);
2438 hw
->phy
.ops
.release(hw
);
2443 * igb_set_master_slave_mode - Setup PHY for Master/slave mode
2444 * @hw: pointer to the HW structure
2446 * Sets up Master/slave mode
2448 static s32
igb_set_master_slave_mode(struct e1000_hw
*hw
)
2453 /* Resolve Master/Slave mode */
2454 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_1000T_CTRL
, &phy_data
);
2458 /* load defaults for future use */
2459 hw
->phy
.original_ms_type
= (phy_data
& CR_1000T_MS_ENABLE
) ?
2460 ((phy_data
& CR_1000T_MS_VALUE
) ?
2461 e1000_ms_force_master
:
2462 e1000_ms_force_slave
) : e1000_ms_auto
;
2464 switch (hw
->phy
.ms_type
) {
2465 case e1000_ms_force_master
:
2466 phy_data
|= (CR_1000T_MS_ENABLE
| CR_1000T_MS_VALUE
);
2468 case e1000_ms_force_slave
:
2469 phy_data
|= CR_1000T_MS_ENABLE
;
2470 phy_data
&= ~(CR_1000T_MS_VALUE
);
2473 phy_data
&= ~CR_1000T_MS_ENABLE
;
2479 return hw
->phy
.ops
.write_reg(hw
, PHY_1000T_CTRL
, phy_data
);