1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2018 Intel Corporation. */
4 #include <linux/bitfield.h>
5 #include <linux/delay.h>
6 #include <linux/if_ether.h>
10 static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
11 static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
13 static s32 igb_wait_autoneg(struct e1000_hw *hw);
14 static s32 igb_set_master_slave_mode(struct e1000_hw *hw);
16 /* Cable length tables */
17 static const u16 e1000_m88_cable_length_table[] = {
18 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
20 static const u16 e1000_igp_2_cable_length_table[] = {
21 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
22 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
23 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
24 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
25 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
26 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
27 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
28 104, 109, 114, 118, 121, 124};
31 * igb_check_reset_block - Check if PHY reset is blocked
32 * @hw: pointer to the HW structure
34 * Read the PHY management control register and check whether a PHY reset
35 * is blocked. If a reset is not blocked return 0, otherwise
36 * return E1000_BLK_PHY_RESET (12).
38 s32 igb_check_reset_block(struct e1000_hw *hw)
42 manc = rd32(E1000_MANC);
44 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? E1000_BLK_PHY_RESET : 0;
48 * igb_get_phy_id - Retrieve the PHY ID and revision
49 * @hw: pointer to the HW structure
51 * Reads the PHY registers and stores the PHY ID and possibly the PHY
52 * revision in the hardware structure.
54 s32 igb_get_phy_id(struct e1000_hw *hw)
56 struct e1000_phy_info *phy = &hw->phy;
60 /* ensure PHY page selection to fix misconfigured i210 */
61 if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211))
62 phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0);
64 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
68 phy->id = (u32)(phy_id << 16);
70 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
74 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
75 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
82 * igb_phy_reset_dsp - Reset PHY DSP
83 * @hw: pointer to the HW structure
85 * Reset the digital signal processor.
87 static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
91 if (!(hw->phy.ops.write_reg))
94 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
98 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
105 * igb_read_phy_reg_mdic - Read MDI control register
106 * @hw: pointer to the HW structure
107 * @offset: register offset to be read
108 * @data: pointer to the read data
110 * Reads the MDI control register in the PHY at offset and stores the
111 * information read to data.
113 s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
115 struct e1000_phy_info *phy = &hw->phy;
119 if (offset > MAX_PHY_REG_ADDRESS) {
120 hw_dbg("PHY Address %d is out of range\n", offset);
121 ret_val = -E1000_ERR_PARAM;
125 /* Set up Op-code, Phy Address, and register offset in the MDI
126 * Control register. The MAC will take care of interfacing with the
127 * PHY to retrieve the desired data.
129 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
130 (phy->addr << E1000_MDIC_PHY_SHIFT) |
131 (E1000_MDIC_OP_READ));
133 wr32(E1000_MDIC, mdic);
135 /* Poll the ready bit to see if the MDI read completed
136 * Increasing the time out as testing showed failures with
139 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
141 mdic = rd32(E1000_MDIC);
142 if (mdic & E1000_MDIC_READY)
145 if (!(mdic & E1000_MDIC_READY)) {
146 hw_dbg("MDI Read did not complete\n");
147 ret_val = -E1000_ERR_PHY;
150 if (mdic & E1000_MDIC_ERROR) {
151 hw_dbg("MDI Error\n");
152 ret_val = -E1000_ERR_PHY;
162 * igb_write_phy_reg_mdic - Write MDI control register
163 * @hw: pointer to the HW structure
164 * @offset: register offset to write to
165 * @data: data to write to register at offset
167 * Writes data to MDI control register in the PHY at offset.
169 s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
171 struct e1000_phy_info *phy = &hw->phy;
175 if (offset > MAX_PHY_REG_ADDRESS) {
176 hw_dbg("PHY Address %d is out of range\n", offset);
177 ret_val = -E1000_ERR_PARAM;
181 /* Set up Op-code, Phy Address, and register offset in the MDI
182 * Control register. The MAC will take care of interfacing with the
183 * PHY to retrieve the desired data.
185 mdic = (((u32)data) |
186 (offset << E1000_MDIC_REG_SHIFT) |
187 (phy->addr << E1000_MDIC_PHY_SHIFT) |
188 (E1000_MDIC_OP_WRITE));
190 wr32(E1000_MDIC, mdic);
192 /* Poll the ready bit to see if the MDI read completed
193 * Increasing the time out as testing showed failures with
196 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
198 mdic = rd32(E1000_MDIC);
199 if (mdic & E1000_MDIC_READY)
202 if (!(mdic & E1000_MDIC_READY)) {
203 hw_dbg("MDI Write did not complete\n");
204 ret_val = -E1000_ERR_PHY;
207 if (mdic & E1000_MDIC_ERROR) {
208 hw_dbg("MDI Error\n");
209 ret_val = -E1000_ERR_PHY;
218 * igb_read_phy_reg_i2c - Read PHY register using i2c
219 * @hw: pointer to the HW structure
220 * @offset: register offset to be read
221 * @data: pointer to the read data
223 * Reads the PHY register at offset using the i2c interface and stores the
224 * retrieved information in data.
226 s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
228 struct e1000_phy_info *phy = &hw->phy;
231 /* Set up Op-code, Phy Address, and register address in the I2CCMD
232 * register. The MAC will take care of interfacing with the
233 * PHY to retrieve the desired data.
235 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
236 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
237 (E1000_I2CCMD_OPCODE_READ));
239 wr32(E1000_I2CCMD, i2ccmd);
241 /* Poll the ready bit to see if the I2C read completed */
242 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
244 i2ccmd = rd32(E1000_I2CCMD);
245 if (i2ccmd & E1000_I2CCMD_READY)
248 if (!(i2ccmd & E1000_I2CCMD_READY)) {
249 hw_dbg("I2CCMD Read did not complete\n");
250 return -E1000_ERR_PHY;
252 if (i2ccmd & E1000_I2CCMD_ERROR) {
253 hw_dbg("I2CCMD Error bit set\n");
254 return -E1000_ERR_PHY;
257 /* Need to byte-swap the 16-bit value. */
258 *data = ((i2ccmd >> 8) & 0x00FF) | FIELD_PREP(0xFF00, i2ccmd);
264 * igb_write_phy_reg_i2c - Write PHY register using i2c
265 * @hw: pointer to the HW structure
266 * @offset: register offset to write to
267 * @data: data to write at register offset
269 * Writes the data to PHY register at the offset using the i2c interface.
271 s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
273 struct e1000_phy_info *phy = &hw->phy;
275 u16 phy_data_swapped;
277 /* Prevent overwriting SFP I2C EEPROM which is at A0 address.*/
278 if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) {
279 hw_dbg("PHY I2C Address %d is out of range.\n",
281 return -E1000_ERR_CONFIG;
284 /* Swap the data bytes for the I2C interface */
285 phy_data_swapped = ((data >> 8) & 0x00FF) | FIELD_PREP(0xFF00, data);
287 /* Set up Op-code, Phy Address, and register address in the I2CCMD
288 * register. The MAC will take care of interfacing with the
289 * PHY to retrieve the desired data.
291 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
292 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
293 E1000_I2CCMD_OPCODE_WRITE |
296 wr32(E1000_I2CCMD, i2ccmd);
298 /* Poll the ready bit to see if the I2C read completed */
299 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
301 i2ccmd = rd32(E1000_I2CCMD);
302 if (i2ccmd & E1000_I2CCMD_READY)
305 if (!(i2ccmd & E1000_I2CCMD_READY)) {
306 hw_dbg("I2CCMD Write did not complete\n");
307 return -E1000_ERR_PHY;
309 if (i2ccmd & E1000_I2CCMD_ERROR) {
310 hw_dbg("I2CCMD Error bit set\n");
311 return -E1000_ERR_PHY;
318 * igb_read_sfp_data_byte - Reads SFP module data.
319 * @hw: pointer to the HW structure
320 * @offset: byte location offset to be read
321 * @data: read data buffer pointer
323 * Reads one byte from SFP module data stored
324 * in SFP resided EEPROM memory or SFP diagnostic area.
325 * Function should be called with
326 * E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
327 * E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
330 s32 igb_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data)
336 if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
337 hw_dbg("I2CCMD command address exceeds upper limit\n");
338 return -E1000_ERR_PHY;
341 /* Set up Op-code, EEPROM Address,in the I2CCMD
342 * register. The MAC will take care of interfacing with the
343 * EEPROM to retrieve the desired data.
345 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
346 E1000_I2CCMD_OPCODE_READ);
348 wr32(E1000_I2CCMD, i2ccmd);
350 /* Poll the ready bit to see if the I2C read completed */
351 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
353 data_local = rd32(E1000_I2CCMD);
354 if (data_local & E1000_I2CCMD_READY)
357 if (!(data_local & E1000_I2CCMD_READY)) {
358 hw_dbg("I2CCMD Read did not complete\n");
359 return -E1000_ERR_PHY;
361 if (data_local & E1000_I2CCMD_ERROR) {
362 hw_dbg("I2CCMD Error bit set\n");
363 return -E1000_ERR_PHY;
365 *data = (u8) data_local & 0xFF;
371 * igb_read_phy_reg_igp - Read igp PHY register
372 * @hw: pointer to the HW structure
373 * @offset: register offset to be read
374 * @data: pointer to the read data
376 * Acquires semaphore, if necessary, then reads the PHY register at offset
377 * and storing the retrieved information in data. Release any acquired
378 * semaphores before exiting.
380 s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
384 if (!(hw->phy.ops.acquire))
387 ret_val = hw->phy.ops.acquire(hw);
391 if (offset > MAX_PHY_MULTI_PAGE_REG) {
392 ret_val = igb_write_phy_reg_mdic(hw,
393 IGP01E1000_PHY_PAGE_SELECT,
396 hw->phy.ops.release(hw);
401 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
404 hw->phy.ops.release(hw);
411 * igb_write_phy_reg_igp - Write igp PHY register
412 * @hw: pointer to the HW structure
413 * @offset: register offset to write to
414 * @data: data to write at register offset
416 * Acquires semaphore, if necessary, then writes the data to PHY register
417 * at the offset. Release any acquired semaphores before exiting.
419 s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
423 if (!(hw->phy.ops.acquire))
426 ret_val = hw->phy.ops.acquire(hw);
430 if (offset > MAX_PHY_MULTI_PAGE_REG) {
431 ret_val = igb_write_phy_reg_mdic(hw,
432 IGP01E1000_PHY_PAGE_SELECT,
435 hw->phy.ops.release(hw);
440 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
443 hw->phy.ops.release(hw);
450 * igb_copper_link_setup_82580 - Setup 82580 PHY for copper link
451 * @hw: pointer to the HW structure
453 * Sets up Carrier-sense on Transmit and downshift values.
455 s32 igb_copper_link_setup_82580(struct e1000_hw *hw)
457 struct e1000_phy_info *phy = &hw->phy;
461 if (phy->reset_disable) {
466 if (phy->type == e1000_phy_82580) {
467 ret_val = hw->phy.ops.reset(hw);
469 hw_dbg("Error resetting the PHY.\n");
474 /* Enable CRS on TX. This must be set for half-duplex operation. */
475 ret_val = phy->ops.read_reg(hw, I82580_CFG_REG, &phy_data);
479 phy_data |= I82580_CFG_ASSERT_CRS_ON_TX;
481 /* Enable downshift */
482 phy_data |= I82580_CFG_ENABLE_DOWNSHIFT;
484 ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data);
488 /* Set MDI/MDIX mode */
489 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
492 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
498 switch (hw->phy.mdix) {
502 phy_data |= I82580_PHY_CTRL2_MANUAL_MDIX;
506 phy_data |= I82580_PHY_CTRL2_AUTO_MDI_MDIX;
509 ret_val = hw->phy.ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
516 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
517 * @hw: pointer to the HW structure
519 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
520 * and downshift values are set also.
522 s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
524 struct e1000_phy_info *phy = &hw->phy;
528 if (phy->reset_disable) {
533 /* Enable CRS on TX. This must be set for half-duplex operation. */
534 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
538 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
541 * MDI/MDI-X = 0 (default)
542 * 0 - Auto for all speeds
545 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
547 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
551 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
554 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
557 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
561 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
566 * disable_polarity_correction = 0 (default)
567 * Automatic Correction for Reversed Cable Polarity
571 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
572 if (phy->disable_polarity_correction == 1)
573 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
575 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
579 if (phy->revision < E1000_REVISION_4) {
580 /* Force TX_CLK in the Extended PHY Specific Control Register
583 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
588 phy_data |= M88E1000_EPSCR_TX_CLK_25;
590 if ((phy->revision == E1000_REVISION_2) &&
591 (phy->id == M88E1111_I_PHY_ID)) {
592 /* 82573L PHY - set the downshift counter to 5x. */
593 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
594 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
596 /* Configure Master and Slave downshift values */
597 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
598 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
599 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
600 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
602 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
608 /* Commit the changes. */
609 ret_val = igb_phy_sw_reset(hw);
611 hw_dbg("Error committing the PHY changes\n");
620 * igb_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
621 * @hw: pointer to the HW structure
623 * Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
624 * Also enables and sets the downshift parameters.
626 s32 igb_copper_link_setup_m88_gen2(struct e1000_hw *hw)
628 struct e1000_phy_info *phy = &hw->phy;
632 if (phy->reset_disable)
635 /* Enable CRS on Tx. This must be set for half-duplex operation. */
636 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
641 * MDI/MDI-X = 0 (default)
642 * 0 - Auto for all speeds
645 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
647 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
651 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
654 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
657 /* M88E1112 does not support this mode) */
658 if (phy->id != M88E1112_E_PHY_ID) {
659 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
665 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
670 * disable_polarity_correction = 0 (default)
671 * Automatic Correction for Reversed Cable Polarity
675 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
676 if (phy->disable_polarity_correction == 1)
677 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
679 /* Enable downshift and setting it to X6 */
680 if (phy->id == M88E1543_E_PHY_ID) {
681 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE;
683 phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
687 ret_val = igb_phy_sw_reset(hw);
689 hw_dbg("Error committing the PHY changes\n");
694 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
695 phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
696 phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
698 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
702 /* Commit the changes. */
703 ret_val = igb_phy_sw_reset(hw);
705 hw_dbg("Error committing the PHY changes\n");
708 ret_val = igb_set_master_slave_mode(hw);
716 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
717 * @hw: pointer to the HW structure
719 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
722 s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
724 struct e1000_phy_info *phy = &hw->phy;
728 if (phy->reset_disable) {
733 ret_val = phy->ops.reset(hw);
735 hw_dbg("Error resetting the PHY.\n");
739 /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
740 * timeout issues when LFS is enabled.
744 /* The NVM settings will configure LPLU in D3 for
747 if (phy->type == e1000_phy_igp) {
748 /* disable lplu d3 during driver init */
749 if (phy->ops.set_d3_lplu_state)
750 ret_val = phy->ops.set_d3_lplu_state(hw, false);
752 hw_dbg("Error Disabling LPLU D3\n");
757 /* disable lplu d0 during driver init */
758 ret_val = phy->ops.set_d0_lplu_state(hw, false);
760 hw_dbg("Error Disabling LPLU D0\n");
763 /* Configure mdi-mdix settings */
764 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
768 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
772 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
775 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
779 data |= IGP01E1000_PSCR_AUTO_MDIX;
782 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
786 /* set auto-master slave resolution settings */
787 if (hw->mac.autoneg) {
788 /* when autonegotiation advertisement is only 1000Mbps then we
789 * should disable SmartSpeed and enable Auto MasterSlave
790 * resolution as hardware default.
792 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
793 /* Disable SmartSpeed */
794 ret_val = phy->ops.read_reg(hw,
795 IGP01E1000_PHY_PORT_CONFIG,
800 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
801 ret_val = phy->ops.write_reg(hw,
802 IGP01E1000_PHY_PORT_CONFIG,
807 /* Set auto Master/Slave resolution process */
808 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
812 data &= ~CR_1000T_MS_ENABLE;
813 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
818 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
822 /* load defaults for future use */
823 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
824 ((data & CR_1000T_MS_VALUE) ?
825 e1000_ms_force_master :
826 e1000_ms_force_slave) :
829 switch (phy->ms_type) {
830 case e1000_ms_force_master:
831 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
833 case e1000_ms_force_slave:
834 data |= CR_1000T_MS_ENABLE;
835 data &= ~(CR_1000T_MS_VALUE);
838 data &= ~CR_1000T_MS_ENABLE;
843 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
853 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
854 * @hw: pointer to the HW structure
856 * Performs initial bounds checking on autoneg advertisement parameter, then
857 * configure to advertise the full capability. Setup the PHY to autoneg
858 * and restart the negotiation process between the link partner. If
859 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
861 static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
863 struct e1000_phy_info *phy = &hw->phy;
867 /* Perform some bounds checking on the autoneg advertisement
870 phy->autoneg_advertised &= phy->autoneg_mask;
872 /* If autoneg_advertised is zero, we assume it was not defaulted
873 * by the calling code so we set to advertise full capability.
875 if (phy->autoneg_advertised == 0)
876 phy->autoneg_advertised = phy->autoneg_mask;
878 hw_dbg("Reconfiguring auto-neg advertisement params\n");
879 ret_val = igb_phy_setup_autoneg(hw);
881 hw_dbg("Error Setting up Auto-Negotiation\n");
884 hw_dbg("Restarting Auto-Neg\n");
886 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
887 * the Auto Neg Restart bit in the PHY control register.
889 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
893 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
894 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
898 /* Does the user want to wait for Auto-Neg to complete here, or
899 * check at a later time (for example, callback routine).
901 if (phy->autoneg_wait_to_complete) {
902 ret_val = igb_wait_autoneg(hw);
904 hw_dbg("Error while waiting for autoneg to complete\n");
909 hw->mac.get_link_status = true;
916 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
917 * @hw: pointer to the HW structure
919 * Reads the MII auto-neg advertisement register and/or the 1000T control
920 * register and if the PHY is already setup for auto-negotiation, then
921 * return successful. Otherwise, setup advertisement and flow control to
922 * the appropriate values for the wanted auto-negotiation.
924 static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
926 struct e1000_phy_info *phy = &hw->phy;
928 u16 mii_autoneg_adv_reg;
929 u16 mii_1000t_ctrl_reg = 0;
931 phy->autoneg_advertised &= phy->autoneg_mask;
933 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
934 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
938 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
939 /* Read the MII 1000Base-T Control Register (Address 9). */
940 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
941 &mii_1000t_ctrl_reg);
946 /* Need to parse both autoneg_advertised and fc and set up
947 * the appropriate PHY registers. First we will parse for
948 * autoneg_advertised software override. Since we can advertise
949 * a plethora of combinations, we need to check each bit
953 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
954 * Advertisement Register (Address 4) and the 1000 mb speed bits in
955 * the 1000Base-T Control Register (Address 9).
957 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
958 NWAY_AR_100TX_HD_CAPS |
959 NWAY_AR_10T_FD_CAPS |
960 NWAY_AR_10T_HD_CAPS);
961 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
963 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
965 /* Do we want to advertise 10 Mb Half Duplex? */
966 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
967 hw_dbg("Advertise 10mb Half duplex\n");
968 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
971 /* Do we want to advertise 10 Mb Full Duplex? */
972 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
973 hw_dbg("Advertise 10mb Full duplex\n");
974 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
977 /* Do we want to advertise 100 Mb Half Duplex? */
978 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
979 hw_dbg("Advertise 100mb Half duplex\n");
980 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
983 /* Do we want to advertise 100 Mb Full Duplex? */
984 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
985 hw_dbg("Advertise 100mb Full duplex\n");
986 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
989 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
990 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
991 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
993 /* Do we want to advertise 1000 Mb Full Duplex? */
994 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
995 hw_dbg("Advertise 1000mb Full duplex\n");
996 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
999 /* Check for a software override of the flow control settings, and
1000 * setup the PHY advertisement registers accordingly. If
1001 * auto-negotiation is enabled, then software will have to set the
1002 * "PAUSE" bits to the correct value in the Auto-Negotiation
1003 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1006 * The possible values of the "fc" parameter are:
1007 * 0: Flow control is completely disabled
1008 * 1: Rx flow control is enabled (we can receive pause frames
1009 * but not send pause frames).
1010 * 2: Tx flow control is enabled (we can send pause frames
1011 * but we do not support receiving pause frames).
1012 * 3: Both Rx and TX flow control (symmetric) are enabled.
1013 * other: No software override. The flow control configuration
1014 * in the EEPROM is used.
1016 switch (hw->fc.current_mode) {
1018 /* Flow control (RX & TX) is completely disabled by a
1019 * software over-ride.
1021 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1023 case e1000_fc_rx_pause:
1024 /* RX Flow control is enabled, and TX Flow control is
1025 * disabled, by a software over-ride.
1027 * Since there really isn't a way to advertise that we are
1028 * capable of RX Pause ONLY, we will advertise that we
1029 * support both symmetric and asymmetric RX PAUSE. Later
1030 * (in e1000_config_fc_after_link_up) we will disable the
1031 * hw's ability to send PAUSE frames.
1033 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1035 case e1000_fc_tx_pause:
1036 /* TX Flow control is enabled, and RX Flow control is
1037 * disabled, by a software over-ride.
1039 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1040 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1043 /* Flow control (both RX and TX) is enabled by a software
1046 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1049 hw_dbg("Flow control param set incorrectly\n");
1050 ret_val = -E1000_ERR_CONFIG;
1054 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1058 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1060 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1061 ret_val = phy->ops.write_reg(hw,
1063 mii_1000t_ctrl_reg);
1073 * igb_setup_copper_link - Configure copper link settings
1074 * @hw: pointer to the HW structure
1076 * Calls the appropriate function to configure the link for auto-neg or forced
1077 * speed and duplex. Then we check for link, once link is established calls
1078 * to configure collision distance and flow control are called. If link is
1079 * not established, we return -E1000_ERR_PHY (-2).
1081 s32 igb_setup_copper_link(struct e1000_hw *hw)
1086 if (hw->mac.autoneg) {
1087 /* Setup autoneg and flow control advertisement and perform
1090 ret_val = igb_copper_link_autoneg(hw);
1094 /* PHY will be set to 10H, 10F, 100H or 100F
1095 * depending on user settings.
1097 hw_dbg("Forcing Speed and Duplex\n");
1098 ret_val = hw->phy.ops.force_speed_duplex(hw);
1100 hw_dbg("Error Forcing Speed and Duplex\n");
1105 /* Check link status. Wait up to 100 microseconds for link to become
1108 ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
1113 hw_dbg("Valid link established!!!\n");
1114 igb_config_collision_dist(hw);
1115 ret_val = igb_config_fc_after_link_up(hw);
1117 hw_dbg("Unable to establish link!!!\n");
1125 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1126 * @hw: pointer to the HW structure
1128 * Calls the PHY setup function to force speed and duplex. Clears the
1129 * auto-crossover to force MDI manually. Waits for link and returns
1130 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1132 s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1134 struct e1000_phy_info *phy = &hw->phy;
1139 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1143 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1145 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1149 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1150 * forced whenever speed and duplex are forced.
1152 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1156 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1157 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1159 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1163 hw_dbg("IGP PSCR: %X\n", phy_data);
1167 if (phy->autoneg_wait_to_complete) {
1168 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
1170 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
1175 hw_dbg("Link taking longer than expected.\n");
1178 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link);
1188 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1189 * @hw: pointer to the HW structure
1191 * Calls the PHY setup function to force speed and duplex. Clears the
1192 * auto-crossover to force MDI manually. Resets the PHY to commit the
1193 * changes. If time expires while waiting for link up, we reset the DSP.
1194 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
1195 * successful completion, else return corresponding error code.
1197 s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1199 struct e1000_phy_info *phy = &hw->phy;
1204 /* I210 and I211 devices support Auto-Crossover in forced operation. */
1205 if (phy->type != e1000_phy_i210) {
1206 /* Clear Auto-Crossover to force MDI manually. M88E1000
1207 * requires MDI forced whenever speed and duplex are forced.
1209 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL,
1214 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1215 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
1220 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
1223 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1227 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1229 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1233 /* Reset the phy to commit changes. */
1234 ret_val = igb_phy_sw_reset(hw);
1238 if (phy->autoneg_wait_to_complete) {
1239 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
1241 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
1246 bool reset_dsp = true;
1248 switch (hw->phy.id) {
1249 case I347AT4_E_PHY_ID:
1250 case M88E1112_E_PHY_ID:
1251 case M88E1543_E_PHY_ID:
1252 case M88E1512_E_PHY_ID:
1257 if (hw->phy.type != e1000_phy_m88)
1262 hw_dbg("Link taking longer than expected.\n");
1264 /* We didn't get link.
1265 * Reset the DSP and cross our fingers.
1267 ret_val = phy->ops.write_reg(hw,
1268 M88E1000_PHY_PAGE_SELECT,
1272 ret_val = igb_phy_reset_dsp(hw);
1279 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
1285 if (hw->phy.type != e1000_phy_m88 ||
1286 hw->phy.id == I347AT4_E_PHY_ID ||
1287 hw->phy.id == M88E1112_E_PHY_ID ||
1288 hw->phy.id == M88E1543_E_PHY_ID ||
1289 hw->phy.id == M88E1512_E_PHY_ID ||
1290 hw->phy.id == I210_I_PHY_ID)
1293 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1297 /* Resetting the phy means we need to re-force TX_CLK in the
1298 * Extended PHY Specific Control Register to 25MHz clock from
1299 * the reset value of 2.5MHz.
1301 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1302 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1306 /* In addition, we must re-enable CRS on Tx for both half and full
1309 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1313 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1314 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1321 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1322 * @hw: pointer to the HW structure
1323 * @phy_ctrl: pointer to current value of PHY_CONTROL
1325 * Forces speed and duplex on the PHY by doing the following: disable flow
1326 * control, force speed/duplex on the MAC, disable auto speed detection,
1327 * disable auto-negotiation, configure duplex, configure speed, configure
1328 * the collision distance, write configuration to CTRL register. The
1329 * caller must write to the PHY_CONTROL register for these settings to
1332 static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
1335 struct e1000_mac_info *mac = &hw->mac;
1338 /* Turn off flow control when forcing speed/duplex */
1339 hw->fc.current_mode = e1000_fc_none;
1341 /* Force speed/duplex on the mac */
1342 ctrl = rd32(E1000_CTRL);
1343 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1344 ctrl &= ~E1000_CTRL_SPD_SEL;
1346 /* Disable Auto Speed Detection */
1347 ctrl &= ~E1000_CTRL_ASDE;
1349 /* Disable autoneg on the phy */
1350 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1352 /* Forcing Full or Half Duplex? */
1353 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1354 ctrl &= ~E1000_CTRL_FD;
1355 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1356 hw_dbg("Half Duplex\n");
1358 ctrl |= E1000_CTRL_FD;
1359 *phy_ctrl |= MII_CR_FULL_DUPLEX;
1360 hw_dbg("Full Duplex\n");
1363 /* Forcing 10mb or 100mb? */
1364 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1365 ctrl |= E1000_CTRL_SPD_100;
1366 *phy_ctrl |= MII_CR_SPEED_100;
1367 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1368 hw_dbg("Forcing 100mb\n");
1370 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1371 *phy_ctrl |= MII_CR_SPEED_10;
1372 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1373 hw_dbg("Forcing 10mb\n");
1376 igb_config_collision_dist(hw);
1378 wr32(E1000_CTRL, ctrl);
1382 * igb_set_d3_lplu_state - Sets low power link up state for D3
1383 * @hw: pointer to the HW structure
1384 * @active: boolean used to enable/disable lplu
1386 * Success returns 0, Failure returns 1
1388 * The low power link up (lplu) state is set to the power management level D3
1389 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1390 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1391 * is used during Dx states where the power conservation is most important.
1392 * During driver activity, SmartSpeed should be enabled so performance is
1395 s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1397 struct e1000_phy_info *phy = &hw->phy;
1401 if (!(hw->phy.ops.read_reg))
1404 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1409 data &= ~IGP02E1000_PM_D3_LPLU;
1410 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1414 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
1415 * during Dx states where the power conservation is most
1416 * important. During driver activity we should enable
1417 * SmartSpeed, so performance is maintained.
1419 if (phy->smart_speed == e1000_smart_speed_on) {
1420 ret_val = phy->ops.read_reg(hw,
1421 IGP01E1000_PHY_PORT_CONFIG,
1426 data |= IGP01E1000_PSCFR_SMART_SPEED;
1427 ret_val = phy->ops.write_reg(hw,
1428 IGP01E1000_PHY_PORT_CONFIG,
1432 } else if (phy->smart_speed == e1000_smart_speed_off) {
1433 ret_val = phy->ops.read_reg(hw,
1434 IGP01E1000_PHY_PORT_CONFIG,
1439 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1440 ret_val = phy->ops.write_reg(hw,
1441 IGP01E1000_PHY_PORT_CONFIG,
1446 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1447 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1448 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1449 data |= IGP02E1000_PM_D3_LPLU;
1450 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1455 /* When LPLU is enabled, we should disable SmartSpeed */
1456 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1461 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1462 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1471 * igb_check_downshift - Checks whether a downshift in speed occurred
1472 * @hw: pointer to the HW structure
1474 * Success returns 0, Failure returns 1
1476 * A downshift is detected by querying the PHY link health.
1478 s32 igb_check_downshift(struct e1000_hw *hw)
1480 struct e1000_phy_info *phy = &hw->phy;
1482 u16 phy_data, offset, mask;
1484 switch (phy->type) {
1485 case e1000_phy_i210:
1487 case e1000_phy_gg82563:
1488 offset = M88E1000_PHY_SPEC_STATUS;
1489 mask = M88E1000_PSSR_DOWNSHIFT;
1491 case e1000_phy_igp_2:
1493 case e1000_phy_igp_3:
1494 offset = IGP01E1000_PHY_LINK_HEALTH;
1495 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1498 /* speed downshift not supported */
1499 phy->speed_downgraded = false;
1504 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
1507 phy->speed_downgraded = (phy_data & mask) ? true : false;
1514 * igb_check_polarity_m88 - 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 specific status register.
1521 s32 igb_check_polarity_m88(struct e1000_hw *hw)
1523 struct e1000_phy_info *phy = &hw->phy;
1527 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
1530 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1531 ? e1000_rev_polarity_reversed
1532 : e1000_rev_polarity_normal;
1538 * igb_check_polarity_igp - Checks the polarity.
1539 * @hw: pointer to the HW structure
1541 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1543 * Polarity is determined based on the PHY port status register, and the
1544 * current speed (since there is no polarity at 100Mbps).
1546 static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1548 struct e1000_phy_info *phy = &hw->phy;
1550 u16 data, offset, mask;
1552 /* Polarity is determined based on the speed of
1555 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1559 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1560 IGP01E1000_PSSR_SPEED_1000MBPS) {
1561 offset = IGP01E1000_PHY_PCS_INIT_REG;
1562 mask = IGP01E1000_PHY_POLARITY_MASK;
1564 /* This really only applies to 10Mbps since
1565 * there is no polarity for 100Mbps (always 0).
1567 offset = IGP01E1000_PHY_PORT_STATUS;
1568 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1571 ret_val = phy->ops.read_reg(hw, offset, &data);
1574 phy->cable_polarity = (data & mask)
1575 ? e1000_rev_polarity_reversed
1576 : e1000_rev_polarity_normal;
1583 * igb_wait_autoneg - Wait for auto-neg completion
1584 * @hw: pointer to the HW structure
1586 * Waits for auto-negotiation to complete or for the auto-negotiation time
1587 * limit to expire, which ever happens first.
1589 static s32 igb_wait_autoneg(struct e1000_hw *hw)
1594 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1595 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1596 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1599 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1602 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1607 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1614 * igb_phy_has_link - Polls PHY for link
1615 * @hw: pointer to the HW structure
1616 * @iterations: number of times to poll for link
1617 * @usec_interval: delay between polling attempts
1618 * @success: pointer to whether polling was successful or not
1620 * Polls the PHY status register for link, 'iterations' number of times.
1622 s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
1623 u32 usec_interval, bool *success)
1628 for (i = 0; i < iterations; i++) {
1629 /* Some PHYs require the PHY_STATUS register to be read
1630 * twice due to the link bit being sticky. No harm doing
1631 * it across the board.
1633 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1634 if (ret_val && usec_interval > 0) {
1635 /* If the first read fails, another entity may have
1636 * ownership of the resources, wait and try again to
1637 * see if they have relinquished the resources yet.
1639 if (usec_interval >= 1000)
1640 mdelay(usec_interval/1000);
1642 udelay(usec_interval);
1644 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1647 if (phy_status & MII_SR_LINK_STATUS)
1649 if (usec_interval >= 1000)
1650 mdelay(usec_interval/1000);
1652 udelay(usec_interval);
1655 *success = (i < iterations) ? true : false;
1661 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
1662 * @hw: pointer to the HW structure
1664 * Reads the PHY specific status register to retrieve the cable length
1665 * information. The cable length is determined by averaging the minimum and
1666 * maximum values to get the "average" cable length. The m88 PHY has four
1667 * possible cable length values, which are:
1668 * Register Value Cable Length
1672 * 3 110 - 140 meters
1675 s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1677 struct e1000_phy_info *phy = &hw->phy;
1679 u16 phy_data, index;
1681 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1685 index = FIELD_GET(M88E1000_PSSR_CABLE_LENGTH, phy_data);
1686 if (index >= ARRAY_SIZE(e1000_m88_cable_length_table) - 1) {
1687 ret_val = -E1000_ERR_PHY;
1691 phy->min_cable_length = e1000_m88_cable_length_table[index];
1692 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1694 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1700 s32 igb_get_cable_length_m88_gen2(struct e1000_hw *hw)
1702 struct e1000_phy_info *phy = &hw->phy;
1704 u16 phy_data, phy_data2, index, default_page, is_cm;
1709 switch (hw->phy.id) {
1710 case M88E1543_E_PHY_ID:
1711 case M88E1512_E_PHY_ID:
1712 case I347AT4_E_PHY_ID:
1714 /* Remember the original page select and set it to 7 */
1715 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1720 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
1724 /* Check if the unit of cable length is meters or cm */
1725 ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
1729 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
1731 /* Get cable length from Pair 0 length Regs */
1732 ret_val = phy->ops.read_reg(hw, I347AT4_PCDL0, &phy_data);
1736 phy->pair_length[0] = phy_data / (is_cm ? 100 : 1);
1737 len_tot = phy->pair_length[0];
1738 len_min = phy->pair_length[0];
1739 len_max = phy->pair_length[0];
1741 /* Get cable length from Pair 1 length Regs */
1742 ret_val = phy->ops.read_reg(hw, I347AT4_PCDL1, &phy_data);
1746 phy->pair_length[1] = phy_data / (is_cm ? 100 : 1);
1747 len_tot += phy->pair_length[1];
1748 len_min = min(len_min, phy->pair_length[1]);
1749 len_max = max(len_max, phy->pair_length[1]);
1751 /* Get cable length from Pair 2 length Regs */
1752 ret_val = phy->ops.read_reg(hw, I347AT4_PCDL2, &phy_data);
1756 phy->pair_length[2] = phy_data / (is_cm ? 100 : 1);
1757 len_tot += phy->pair_length[2];
1758 len_min = min(len_min, phy->pair_length[2]);
1759 len_max = max(len_max, phy->pair_length[2]);
1761 /* Get cable length from Pair 3 length Regs */
1762 ret_val = phy->ops.read_reg(hw, I347AT4_PCDL3, &phy_data);
1766 phy->pair_length[3] = phy_data / (is_cm ? 100 : 1);
1767 len_tot += phy->pair_length[3];
1768 len_min = min(len_min, phy->pair_length[3]);
1769 len_max = max(len_max, phy->pair_length[3]);
1771 /* Populate the phy structure with cable length in meters */
1772 phy->min_cable_length = len_min;
1773 phy->max_cable_length = len_max;
1774 phy->cable_length = len_tot / 4;
1776 /* Reset the page selec to its original value */
1777 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1782 case M88E1112_E_PHY_ID:
1783 /* Remember the original page select and set it to 5 */
1784 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
1789 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
1793 ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
1798 index = FIELD_GET(M88E1000_PSSR_CABLE_LENGTH, phy_data);
1799 if (index >= ARRAY_SIZE(e1000_m88_cable_length_table) - 1) {
1800 ret_val = -E1000_ERR_PHY;
1804 phy->min_cable_length = e1000_m88_cable_length_table[index];
1805 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1807 phy->cable_length = (phy->min_cable_length +
1808 phy->max_cable_length) / 2;
1810 /* Reset the page select to its original value */
1811 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
1818 ret_val = -E1000_ERR_PHY;
1827 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1828 * @hw: pointer to the HW structure
1830 * The automatic gain control (agc) normalizes the amplitude of the
1831 * received signal, adjusting for the attenuation produced by the
1832 * cable. By reading the AGC registers, which represent the
1833 * combination of coarse and fine gain value, the value can be put
1834 * into a lookup table to obtain the approximate cable length
1837 s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1839 struct e1000_phy_info *phy = &hw->phy;
1841 u16 phy_data, i, agc_value = 0;
1842 u16 cur_agc_index, max_agc_index = 0;
1843 u16 min_agc_index = ARRAY_SIZE(e1000_igp_2_cable_length_table) - 1;
1844 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
1845 IGP02E1000_PHY_AGC_A,
1846 IGP02E1000_PHY_AGC_B,
1847 IGP02E1000_PHY_AGC_C,
1848 IGP02E1000_PHY_AGC_D
1851 /* Read the AGC registers for all channels */
1852 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1853 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
1857 /* Getting bits 15:9, which represent the combination of
1858 * coarse and fine gain values. The result is a number
1859 * that can be put into the lookup table to obtain the
1860 * approximate cable length.
1862 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1863 IGP02E1000_AGC_LENGTH_MASK;
1865 /* Array index bound check. */
1866 if ((cur_agc_index >= ARRAY_SIZE(e1000_igp_2_cable_length_table)) ||
1867 (cur_agc_index == 0)) {
1868 ret_val = -E1000_ERR_PHY;
1872 /* Remove min & max AGC values from calculation. */
1873 if (e1000_igp_2_cable_length_table[min_agc_index] >
1874 e1000_igp_2_cable_length_table[cur_agc_index])
1875 min_agc_index = cur_agc_index;
1876 if (e1000_igp_2_cable_length_table[max_agc_index] <
1877 e1000_igp_2_cable_length_table[cur_agc_index])
1878 max_agc_index = cur_agc_index;
1880 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1883 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1884 e1000_igp_2_cable_length_table[max_agc_index]);
1885 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1887 /* Calculate cable length with the error range of +/- 10 meters. */
1888 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1889 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1890 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1892 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1899 * igb_get_phy_info_m88 - Retrieve PHY information
1900 * @hw: pointer to the HW structure
1902 * Valid for only copper links. Read the PHY status register (sticky read)
1903 * to verify that link is up. Read the PHY special control register to
1904 * determine the polarity and 10base-T extended distance. Read the PHY
1905 * special status register to determine MDI/MDIx and current speed. If
1906 * speed is 1000, then determine cable length, local and remote receiver.
1908 s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1910 struct e1000_phy_info *phy = &hw->phy;
1915 if (phy->media_type != e1000_media_type_copper) {
1916 hw_dbg("Phy info is only valid for copper media\n");
1917 ret_val = -E1000_ERR_CONFIG;
1921 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1926 hw_dbg("Phy info is only valid if link is up\n");
1927 ret_val = -E1000_ERR_CONFIG;
1931 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1935 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
1938 ret_val = igb_check_polarity_m88(hw);
1942 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1946 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1948 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
1949 ret_val = phy->ops.get_cable_length(hw);
1953 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
1957 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1958 ? e1000_1000t_rx_status_ok
1959 : e1000_1000t_rx_status_not_ok;
1961 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1962 ? e1000_1000t_rx_status_ok
1963 : e1000_1000t_rx_status_not_ok;
1965 /* Set values to "undefined" */
1966 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1967 phy->local_rx = e1000_1000t_rx_status_undefined;
1968 phy->remote_rx = e1000_1000t_rx_status_undefined;
1976 * igb_get_phy_info_igp - Retrieve igp PHY information
1977 * @hw: pointer to the HW structure
1979 * Read PHY status to determine if link is up. If link is up, then
1980 * set/determine 10base-T extended distance and polarity correction. Read
1981 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1982 * determine on the cable length, local and remote receiver.
1984 s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1986 struct e1000_phy_info *phy = &hw->phy;
1991 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1996 hw_dbg("Phy info is only valid if link is up\n");
1997 ret_val = -E1000_ERR_CONFIG;
2001 phy->polarity_correction = true;
2003 ret_val = igb_check_polarity_igp(hw);
2007 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2011 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
2013 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2014 IGP01E1000_PSSR_SPEED_1000MBPS) {
2015 ret_val = phy->ops.get_cable_length(hw);
2019 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2023 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2024 ? e1000_1000t_rx_status_ok
2025 : e1000_1000t_rx_status_not_ok;
2027 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2028 ? e1000_1000t_rx_status_ok
2029 : e1000_1000t_rx_status_not_ok;
2031 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2032 phy->local_rx = e1000_1000t_rx_status_undefined;
2033 phy->remote_rx = e1000_1000t_rx_status_undefined;
2041 * igb_phy_sw_reset - PHY software reset
2042 * @hw: pointer to the HW structure
2044 * Does a software reset of the PHY by reading the PHY control register and
2045 * setting/write the control register reset bit to the PHY.
2047 s32 igb_phy_sw_reset(struct e1000_hw *hw)
2052 if (!(hw->phy.ops.read_reg))
2055 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
2059 phy_ctrl |= MII_CR_RESET;
2060 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
2071 * igb_phy_hw_reset - PHY hardware reset
2072 * @hw: pointer to the HW structure
2074 * Verify the reset block is not blocking us from resetting. Acquire
2075 * semaphore (if necessary) and read/set/write the device control reset
2076 * bit in the PHY. Wait the appropriate delay time for the device to
2077 * reset and release the semaphore (if necessary).
2079 s32 igb_phy_hw_reset(struct e1000_hw *hw)
2081 struct e1000_phy_info *phy = &hw->phy;
2085 ret_val = igb_check_reset_block(hw);
2091 ret_val = phy->ops.acquire(hw);
2095 ctrl = rd32(E1000_CTRL);
2096 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
2099 udelay(phy->reset_delay_us);
2101 wr32(E1000_CTRL, ctrl);
2106 phy->ops.release(hw);
2108 ret_val = phy->ops.get_cfg_done(hw);
2115 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
2116 * @hw: pointer to the HW structure
2118 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2120 s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
2122 hw_dbg("Running IGP 3 PHY init script\n");
2124 /* PHY init IGP 3 */
2125 /* Enable rise/fall, 10-mode work in class-A */
2126 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
2127 /* Remove all caps from Replica path filter */
2128 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
2129 /* Bias trimming for ADC, AFE and Driver (Default) */
2130 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
2131 /* Increase Hybrid poly bias */
2132 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
2133 /* Add 4% to TX amplitude in Giga mode */
2134 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
2135 /* Disable trimming (TTT) */
2136 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
2137 /* Poly DC correction to 94.6% + 2% for all channels */
2138 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
2139 /* ABS DC correction to 95.9% */
2140 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
2141 /* BG temp curve trim */
2142 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
2143 /* Increasing ADC OPAMP stage 1 currents to max */
2144 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
2145 /* Force 1000 ( required for enabling PHY regs configuration) */
2146 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
2147 /* Set upd_freq to 6 */
2148 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
2150 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
2151 /* Disable adaptive fixed FFE (Default) */
2152 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
2153 /* Enable FFE hysteresis */
2154 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
2155 /* Fixed FFE for short cable lengths */
2156 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
2157 /* Fixed FFE for medium cable lengths */
2158 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
2159 /* Fixed FFE for long cable lengths */
2160 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
2161 /* Enable Adaptive Clip Threshold */
2162 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
2163 /* AHT reset limit to 1 */
2164 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
2165 /* Set AHT master delay to 127 msec */
2166 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
2167 /* Set scan bits for AHT */
2168 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
2169 /* Set AHT Preset bits */
2170 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
2171 /* Change integ_factor of channel A to 3 */
2172 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
2173 /* Change prop_factor of channels BCD to 8 */
2174 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
2175 /* Change cg_icount + enable integbp for channels BCD */
2176 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
2177 /* Change cg_icount + enable integbp + change prop_factor_master
2178 * to 8 for channel A
2180 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
2181 /* Disable AHT in Slave mode on channel A */
2182 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
2183 /* Enable LPLU and disable AN to 1000 in non-D0a states,
2186 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
2187 /* Enable restart AN on an1000_dis change */
2188 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
2189 /* Enable wh_fifo read clock in 10/100 modes */
2190 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
2191 /* Restart AN, Speed selection is 1000 */
2192 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
2198 * igb_initialize_M88E1512_phy - Initialize M88E1512 PHY
2199 * @hw: pointer to the HW structure
2201 * Initialize Marvel 1512 to work correctly with Avoton.
2203 s32 igb_initialize_M88E1512_phy(struct e1000_hw *hw)
2205 struct e1000_phy_info *phy = &hw->phy;
2208 /* Switch to PHY page 0xFF. */
2209 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FF);
2213 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x214B);
2217 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2144);
2221 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x0C28);
2225 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2146);
2229 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xB233);
2233 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x214D);
2237 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xCC0C);
2241 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2159);
2245 /* Switch to PHY page 0xFB. */
2246 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FB);
2250 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_3, 0x000D);
2254 /* Switch to PHY page 0x12. */
2255 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x12);
2259 /* Change mode to SGMII-to-Copper */
2260 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_MODE, 0x8001);
2264 /* Return the PHY to page 0. */
2265 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2269 ret_val = igb_phy_sw_reset(hw);
2271 hw_dbg("Error committing the PHY changes\n");
2275 /* msec_delay(1000); */
2276 usleep_range(1000, 2000);
2282 * igb_initialize_M88E1543_phy - Initialize M88E1512 PHY
2283 * @hw: pointer to the HW structure
2285 * Initialize Marvell 1543 to work correctly with Avoton.
2287 s32 igb_initialize_M88E1543_phy(struct e1000_hw *hw)
2289 struct e1000_phy_info *phy = &hw->phy;
2292 /* Switch to PHY page 0xFF. */
2293 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FF);
2297 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x214B);
2301 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2144);
2305 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0x0C28);
2309 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2146);
2313 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xB233);
2317 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x214D);
2321 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_2, 0xDC0C);
2325 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_1, 0x2159);
2329 /* Switch to PHY page 0xFB. */
2330 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x00FB);
2334 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_CFG_REG_3, 0x0C0D);
2338 /* Switch to PHY page 0x12. */
2339 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x12);
2343 /* Change mode to SGMII-to-Copper */
2344 ret_val = phy->ops.write_reg(hw, E1000_M88E1512_MODE, 0x8001);
2348 /* Switch to PHY page 1. */
2349 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0x1);
2353 /* Change mode to 1000BASE-X/SGMII and autoneg enable */
2354 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_FIBER_CTRL, 0x9140);
2358 /* Return the PHY to page 0. */
2359 ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
2363 ret_val = igb_phy_sw_reset(hw);
2365 hw_dbg("Error committing the PHY changes\n");
2369 /* msec_delay(1000); */
2370 usleep_range(1000, 2000);
2376 * igb_power_up_phy_copper - Restore copper link in case of PHY power down
2377 * @hw: pointer to the HW structure
2379 * In the case of a PHY power down to save power, or to turn off link during a
2380 * driver unload, restore the link to previous settings.
2382 void igb_power_up_phy_copper(struct e1000_hw *hw)
2386 /* The PHY will retain its settings across a power down/up cycle */
2387 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2388 mii_reg &= ~MII_CR_POWER_DOWN;
2389 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2393 * igb_power_down_phy_copper - Power down copper PHY
2394 * @hw: pointer to the HW structure
2396 * Power down PHY to save power when interface is down and wake on lan
2399 void igb_power_down_phy_copper(struct e1000_hw *hw)
2403 /* The PHY will retain its settings across a power down/up cycle */
2404 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2405 mii_reg |= MII_CR_POWER_DOWN;
2406 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2407 usleep_range(1000, 2000);
2411 * igb_check_polarity_82580 - Checks the polarity.
2412 * @hw: pointer to the HW structure
2414 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2416 * Polarity is determined based on the PHY specific status register.
2418 static s32 igb_check_polarity_82580(struct e1000_hw *hw)
2420 struct e1000_phy_info *phy = &hw->phy;
2425 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2428 phy->cable_polarity = (data & I82580_PHY_STATUS2_REV_POLARITY)
2429 ? e1000_rev_polarity_reversed
2430 : e1000_rev_polarity_normal;
2436 * igb_phy_force_speed_duplex_82580 - Force speed/duplex for I82580 PHY
2437 * @hw: pointer to the HW structure
2439 * Calls the PHY setup function to force speed and duplex. Clears the
2440 * auto-crossover to force MDI manually. Waits for link and returns
2441 * successful if link up is successful, else -E1000_ERR_PHY (-2).
2443 s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw)
2445 struct e1000_phy_info *phy = &hw->phy;
2450 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
2454 igb_phy_force_speed_duplex_setup(hw, &phy_data);
2456 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
2460 /* Clear Auto-Crossover to force MDI manually. 82580 requires MDI
2461 * forced whenever speed and duplex are forced.
2463 ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data);
2467 phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;
2469 ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);
2473 hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data);
2477 if (phy->autoneg_wait_to_complete) {
2478 hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n");
2480 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
2485 hw_dbg("Link taking longer than expected.\n");
2488 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
2498 * igb_get_phy_info_82580 - Retrieve I82580 PHY information
2499 * @hw: pointer to the HW structure
2501 * Read PHY status to determine if link is up. If link is up, then
2502 * set/determine 10base-T extended distance and polarity correction. Read
2503 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
2504 * determine on the cable length, local and remote receiver.
2506 s32 igb_get_phy_info_82580(struct e1000_hw *hw)
2508 struct e1000_phy_info *phy = &hw->phy;
2513 ret_val = igb_phy_has_link(hw, 1, 0, &link);
2518 hw_dbg("Phy info is only valid if link is up\n");
2519 ret_val = -E1000_ERR_CONFIG;
2523 phy->polarity_correction = true;
2525 ret_val = igb_check_polarity_82580(hw);
2529 ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data);
2533 phy->is_mdix = (data & I82580_PHY_STATUS2_MDIX) ? true : false;
2535 if ((data & I82580_PHY_STATUS2_SPEED_MASK) ==
2536 I82580_PHY_STATUS2_SPEED_1000MBPS) {
2537 ret_val = hw->phy.ops.get_cable_length(hw);
2541 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2545 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2546 ? e1000_1000t_rx_status_ok
2547 : e1000_1000t_rx_status_not_ok;
2549 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2550 ? e1000_1000t_rx_status_ok
2551 : e1000_1000t_rx_status_not_ok;
2553 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2554 phy->local_rx = e1000_1000t_rx_status_undefined;
2555 phy->remote_rx = e1000_1000t_rx_status_undefined;
2563 * igb_get_cable_length_82580 - Determine cable length for 82580 PHY
2564 * @hw: pointer to the HW structure
2566 * Reads the diagnostic status register and verifies result is valid before
2567 * placing it in the phy_cable_length field.
2569 s32 igb_get_cable_length_82580(struct e1000_hw *hw)
2571 struct e1000_phy_info *phy = &hw->phy;
2573 u16 phy_data, length;
2575 ret_val = phy->ops.read_reg(hw, I82580_PHY_DIAG_STATUS, &phy_data);
2579 length = FIELD_GET(I82580_DSTATUS_CABLE_LENGTH, phy_data);
2581 if (length == E1000_CABLE_LENGTH_UNDEFINED)
2582 ret_val = -E1000_ERR_PHY;
2584 phy->cable_length = length;
2591 * igb_set_master_slave_mode - Setup PHY for Master/slave mode
2592 * @hw: pointer to the HW structure
2594 * Sets up Master/slave mode
2596 static s32 igb_set_master_slave_mode(struct e1000_hw *hw)
2601 /* Resolve Master/Slave mode */
2602 ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data);
2606 /* load defaults for future use */
2607 hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
2608 ((phy_data & CR_1000T_MS_VALUE) ?
2609 e1000_ms_force_master :
2610 e1000_ms_force_slave) : e1000_ms_auto;
2612 switch (hw->phy.ms_type) {
2613 case e1000_ms_force_master:
2614 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2616 case e1000_ms_force_slave:
2617 phy_data |= CR_1000T_MS_ENABLE;
2618 phy_data &= ~(CR_1000T_MS_VALUE);
2621 phy_data &= ~CR_1000T_MS_ENABLE;
2627 return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data);