aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/intel
diff options
context:
space:
mode:
authorSasha Neftin <sasha.neftin@intel.com>2018-10-11 03:17:34 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2018-10-17 16:56:55 -0400
commit4eb8080143a9d9fd513bacc65b2466c57983aaae (patch)
tree32923ea729cb92f3afbf68e7ca1698ed7db0b2ef /drivers/net/ethernet/intel
parent5586838fe9ced0980e210b39d635ff3842297448 (diff)
igc: Add setup link functionality
Add link establishment methods Add auto negotiation methods Add read MAC address method Signed-off-by: Sasha Neftin <sasha.neftin@intel.com> Tested-by: Aaron Brown <aaron.f.brown@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/intel')
-rw-r--r--drivers/net/ethernet/intel/igc/igc.h1
-rw-r--r--drivers/net/ethernet/intel/igc/igc_base.c40
-rw-r--r--drivers/net/ethernet/intel/igc/igc_defines.h38
-rw-r--r--drivers/net/ethernet/intel/igc/igc_mac.c271
-rw-r--r--drivers/net/ethernet/intel/igc/igc_mac.h2
-rw-r--r--drivers/net/ethernet/intel/igc/igc_main.c30
-rw-r--r--drivers/net/ethernet/intel/igc/igc_phy.c334
-rw-r--r--drivers/net/ethernet/intel/igc/igc_phy.h1
8 files changed, 717 insertions, 0 deletions
diff --git a/drivers/net/ethernet/intel/igc/igc.h b/drivers/net/ethernet/intel/igc/igc.h
index 7cfbd83d25e4..86fa889b4ab6 100644
--- a/drivers/net/ethernet/intel/igc/igc.h
+++ b/drivers/net/ethernet/intel/igc/igc.h
@@ -314,6 +314,7 @@ struct igc_adapter {
314 struct work_struct reset_task; 314 struct work_struct reset_task;
315 struct work_struct watchdog_task; 315 struct work_struct watchdog_task;
316 struct work_struct dma_err_task; 316 struct work_struct dma_err_task;
317 bool fc_autoneg;
317 318
318 u8 tx_timeout_factor; 319 u8 tx_timeout_factor;
319 320
diff --git a/drivers/net/ethernet/intel/igc/igc_base.c b/drivers/net/ethernet/intel/igc/igc_base.c
index 55faef987479..832da609d9a7 100644
--- a/drivers/net/ethernet/intel/igc/igc_base.c
+++ b/drivers/net/ethernet/intel/igc/igc_base.c
@@ -178,6 +178,29 @@ static s32 igc_init_nvm_params_base(struct igc_hw *hw)
178} 178}
179 179
180/** 180/**
181 * igc_setup_copper_link_base - Configure copper link settings
182 * @hw: pointer to the HW structure
183 *
184 * Configures the link for auto-neg or forced speed and duplex. Then we check
185 * for link, once link is established calls to configure collision distance
186 * and flow control are called.
187 */
188static s32 igc_setup_copper_link_base(struct igc_hw *hw)
189{
190 s32 ret_val = 0;
191 u32 ctrl;
192
193 ctrl = rd32(IGC_CTRL);
194 ctrl |= IGC_CTRL_SLU;
195 ctrl &= ~(IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
196 wr32(IGC_CTRL, ctrl);
197
198 ret_val = igc_setup_copper_link(hw);
199
200 return ret_val;
201}
202
203/**
181 * igc_init_mac_params_base - Init MAC func ptrs. 204 * igc_init_mac_params_base - Init MAC func ptrs.
182 * @hw: pointer to the HW structure 205 * @hw: pointer to the HW structure
183 */ 206 */
@@ -200,6 +223,9 @@ static s32 igc_init_mac_params_base(struct igc_hw *hw)
200 if (mac->type == igc_i225) 223 if (mac->type == igc_i225)
201 dev_spec->clear_semaphore_once = true; 224 dev_spec->clear_semaphore_once = true;
202 225
226 /* physical interface link setup */
227 mac->ops.setup_physical_interface = igc_setup_copper_link_base;
228
203 return 0; 229 return 0;
204} 230}
205 231
@@ -242,6 +268,8 @@ static s32 igc_init_phy_params_base(struct igc_hw *hw)
242 if (ret_val) 268 if (ret_val)
243 return ret_val; 269 return ret_val;
244 270
271 igc_check_for_link_base(hw);
272
245 /* Verify phy id and set remaining function pointers */ 273 /* Verify phy id and set remaining function pointers */
246 switch (phy->id) { 274 switch (phy->id) {
247 case I225_I_PHY_ID: 275 case I225_I_PHY_ID:
@@ -258,10 +286,22 @@ out:
258 286
259static s32 igc_get_invariants_base(struct igc_hw *hw) 287static s32 igc_get_invariants_base(struct igc_hw *hw)
260{ 288{
289 struct igc_mac_info *mac = &hw->mac;
261 u32 link_mode = 0; 290 u32 link_mode = 0;
262 u32 ctrl_ext = 0; 291 u32 ctrl_ext = 0;
263 s32 ret_val = 0; 292 s32 ret_val = 0;
264 293
294 switch (hw->device_id) {
295 case IGC_DEV_ID_I225_LM:
296 case IGC_DEV_ID_I225_V:
297 mac->type = igc_i225;
298 break;
299 default:
300 return -IGC_ERR_MAC_INIT;
301 }
302
303 hw->phy.media_type = igc_media_type_copper;
304
265 ctrl_ext = rd32(IGC_CTRL_EXT); 305 ctrl_ext = rd32(IGC_CTRL_EXT);
266 link_mode = ctrl_ext & IGC_CTRL_EXT_LINK_MODE_MASK; 306 link_mode = ctrl_ext & IGC_CTRL_EXT_LINK_MODE_MASK;
267 307
diff --git a/drivers/net/ethernet/intel/igc/igc_defines.h b/drivers/net/ethernet/intel/igc/igc_defines.h
index d271671e6825..70275a0e85d7 100644
--- a/drivers/net/ethernet/intel/igc/igc_defines.h
+++ b/drivers/net/ethernet/intel/igc/igc_defines.h
@@ -13,6 +13,11 @@
13/* Physical Func Reset Done Indication */ 13/* Physical Func Reset Done Indication */
14#define IGC_CTRL_EXT_LINK_MODE_MASK 0x00C00000 14#define IGC_CTRL_EXT_LINK_MODE_MASK 0x00C00000
15 15
16/* Loop limit on how long we wait for auto-negotiation to complete */
17#define COPPER_LINK_UP_LIMIT 10
18#define PHY_AUTO_NEG_LIMIT 45
19#define PHY_FORCE_LIMIT 20
20
16/* Number of 100 microseconds we wait for PCI Express master disable */ 21/* Number of 100 microseconds we wait for PCI Express master disable */
17#define MASTER_DISABLE_TIMEOUT 800 22#define MASTER_DISABLE_TIMEOUT 800
18/*Blocks new Master requests */ 23/*Blocks new Master requests */
@@ -54,6 +59,12 @@
54#define IGC_CTRL_RST 0x04000000 /* Global reset */ 59#define IGC_CTRL_RST 0x04000000 /* Global reset */
55 60
56#define IGC_CTRL_PHY_RST 0x80000000 /* PHY Reset */ 61#define IGC_CTRL_PHY_RST 0x80000000 /* PHY Reset */
62#define IGC_CTRL_SLU 0x00000040 /* Set link up (Force Link) */
63#define IGC_CTRL_FRCSPD 0x00000800 /* Force Speed */
64#define IGC_CTRL_FRCDPX 0x00001000 /* Force Duplex */
65
66#define IGC_CTRL_RFCE 0x08000000 /* Receive Flow Control enable */
67#define IGC_CTRL_TFCE 0x10000000 /* Transmit flow control enable */
57 68
58/* PBA constants */ 69/* PBA constants */
59#define IGC_PBA_34K 0x0022 70#define IGC_PBA_34K 0x0022
@@ -66,6 +77,29 @@
66#define IGC_SWFW_EEP_SM 0x1 77#define IGC_SWFW_EEP_SM 0x1
67#define IGC_SWFW_PHY0_SM 0x2 78#define IGC_SWFW_PHY0_SM 0x2
68 79
80/* Autoneg Advertisement Register */
81#define NWAY_AR_10T_HD_CAPS 0x0020 /* 10T Half Duplex Capable */
82#define NWAY_AR_10T_FD_CAPS 0x0040 /* 10T Full Duplex Capable */
83#define NWAY_AR_100TX_HD_CAPS 0x0080 /* 100TX Half Duplex Capable */
84#define NWAY_AR_100TX_FD_CAPS 0x0100 /* 100TX Full Duplex Capable */
85#define NWAY_AR_PAUSE 0x0400 /* Pause operation desired */
86#define NWAY_AR_ASM_DIR 0x0800 /* Asymmetric Pause Direction bit */
87
88/* Link Partner Ability Register (Base Page) */
89#define NWAY_LPAR_PAUSE 0x0400 /* LP Pause operation desired */
90#define NWAY_LPAR_ASM_DIR 0x0800 /* LP Asymmetric Pause Direction bit */
91
92/* 1000BASE-T Control Register */
93#define CR_1000T_ASYM_PAUSE 0x0080 /* Advertise asymmetric pause bit */
94#define CR_1000T_HD_CAPS 0x0100 /* Advertise 1000T HD capability */
95#define CR_1000T_FD_CAPS 0x0200 /* Advertise 1000T FD capability */
96
97/* PHY GPY 211 registers */
98#define STANDARD_AN_REG_MASK 0x0007 /* MMD */
99#define ANEG_MULTIGBT_AN_CTRL 0x0020 /* MULTI GBT AN Control Register */
100#define MMD_DEVADDR_SHIFT 16 /* Shift MMD to higher bits */
101#define CR_2500T_FD_CAPS 0x0080 /* Advertise 2500T FD capability */
102
69/* NVM Control */ 103/* NVM Control */
70/* Number of milliseconds for NVM auto read done after MAC reset. */ 104/* Number of milliseconds for NVM auto read done after MAC reset. */
71#define AUTO_READ_DONE_TIMEOUT 10 105#define AUTO_READ_DONE_TIMEOUT 10
@@ -318,6 +352,10 @@
318#define PHY_STATUS 0x01 /* Status Register */ 352#define PHY_STATUS 0x01 /* Status Register */
319#define PHY_ID1 0x02 /* Phy Id Reg (word 1) */ 353#define PHY_ID1 0x02 /* Phy Id Reg (word 1) */
320#define PHY_ID2 0x03 /* Phy Id Reg (word 2) */ 354#define PHY_ID2 0x03 /* Phy Id Reg (word 2) */
355#define PHY_AUTONEG_ADV 0x04 /* Autoneg Advertisement */
356#define PHY_LP_ABILITY 0x05 /* Link Partner Ability (Base Page) */
357#define PHY_1000T_CTRL 0x09 /* 1000Base-T Control Reg */
358#define PHY_1000T_STATUS 0x0A /* 1000Base-T Status Reg */
321 359
322/* Bit definitions for valid PHY IDs. I = Integrated E = External */ 360/* Bit definitions for valid PHY IDs. I = Integrated E = External */
323#define I225_I_PHY_ID 0x67C9DC00 361#define I225_I_PHY_ID 0x67C9DC00
diff --git a/drivers/net/ethernet/intel/igc/igc_mac.c b/drivers/net/ethernet/intel/igc/igc_mac.c
index fce7f7f5aa46..f7683d3ae47c 100644
--- a/drivers/net/ethernet/intel/igc/igc_mac.c
+++ b/drivers/net/ethernet/intel/igc/igc_mac.c
@@ -92,6 +92,8 @@ s32 igc_setup_link(struct igc_hw *hw)
92 /* In the case of the phy reset being blocked, we already have a link. 92 /* In the case of the phy reset being blocked, we already have a link.
93 * We do not need to set it up again. 93 * We do not need to set it up again.
94 */ 94 */
95 if (igc_check_reset_block(hw))
96 goto out;
95 97
96 /* If requested flow control is set to default, set flow control 98 /* If requested flow control is set to default, set flow control
97 * based on the EEPROM flow control settings. 99 * based on the EEPROM flow control settings.
@@ -142,10 +144,74 @@ out:
142 */ 144 */
143static s32 igc_set_default_fc(struct igc_hw *hw) 145static s32 igc_set_default_fc(struct igc_hw *hw)
144{ 146{
147 hw->fc.requested_mode = igc_fc_full;
145 return 0; 148 return 0;
146} 149}
147 150
148/** 151/**
152 * igc_force_mac_fc - Force the MAC's flow control settings
153 * @hw: pointer to the HW structure
154 *
155 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
156 * device control register to reflect the adapter settings. TFCE and RFCE
157 * need to be explicitly set by software when a copper PHY is used because
158 * autonegotiation is managed by the PHY rather than the MAC. Software must
159 * also configure these bits when link is forced on a fiber connection.
160 */
161s32 igc_force_mac_fc(struct igc_hw *hw)
162{
163 s32 ret_val = 0;
164 u32 ctrl;
165
166 ctrl = rd32(IGC_CTRL);
167
168 /* Because we didn't get link via the internal auto-negotiation
169 * mechanism (we either forced link or we got link via PHY
170 * auto-neg), we have to manually enable/disable transmit an
171 * receive flow control.
172 *
173 * The "Case" statement below enables/disable flow control
174 * according to the "hw->fc.current_mode" parameter.
175 *
176 * The possible values of the "fc" parameter are:
177 * 0: Flow control is completely disabled
178 * 1: Rx flow control is enabled (we can receive pause
179 * frames but not send pause frames).
180 * 2: Tx flow control is enabled (we can send pause frames
181 * frames but we do not receive pause frames).
182 * 3: Both Rx and TX flow control (symmetric) is enabled.
183 * other: No other values should be possible at this point.
184 */
185 hw_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
186
187 switch (hw->fc.current_mode) {
188 case igc_fc_none:
189 ctrl &= (~(IGC_CTRL_TFCE | IGC_CTRL_RFCE));
190 break;
191 case igc_fc_rx_pause:
192 ctrl &= (~IGC_CTRL_TFCE);
193 ctrl |= IGC_CTRL_RFCE;
194 break;
195 case igc_fc_tx_pause:
196 ctrl &= (~IGC_CTRL_RFCE);
197 ctrl |= IGC_CTRL_TFCE;
198 break;
199 case igc_fc_full:
200 ctrl |= (IGC_CTRL_TFCE | IGC_CTRL_RFCE);
201 break;
202 default:
203 hw_dbg("Flow control param set incorrectly\n");
204 ret_val = -IGC_ERR_CONFIG;
205 goto out;
206 }
207
208 wr32(IGC_CTRL, ctrl);
209
210out:
211 return ret_val;
212}
213
214/**
149 * igc_set_fc_watermarks - Set flow control high/low watermarks 215 * igc_set_fc_watermarks - Set flow control high/low watermarks
150 * @hw: pointer to the HW structure 216 * @hw: pointer to the HW structure
151 * 217 *
@@ -371,6 +437,7 @@ s32 igc_check_for_copper_link(struct igc_hw *hw)
371 * settings because we may have had to re-autoneg with a 437 * settings because we may have had to re-autoneg with a
372 * different link partner. 438 * different link partner.
373 */ 439 */
440 ret_val = igc_config_fc_after_link_up(hw);
374 if (ret_val) 441 if (ret_val)
375 hw_dbg("Error configuring flow control\n"); 442 hw_dbg("Error configuring flow control\n");
376 443
@@ -400,6 +467,210 @@ void igc_config_collision_dist(struct igc_hw *hw)
400} 467}
401 468
402/** 469/**
470 * igc_config_fc_after_link_up - Configures flow control after link
471 * @hw: pointer to the HW structure
472 *
473 * Checks the status of auto-negotiation after link up to ensure that the
474 * speed and duplex were not forced. If the link needed to be forced, then
475 * flow control needs to be forced also. If auto-negotiation is enabled
476 * and did not fail, then we configure flow control based on our link
477 * partner.
478 */
479s32 igc_config_fc_after_link_up(struct igc_hw *hw)
480{
481 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
482 struct igc_mac_info *mac = &hw->mac;
483 u16 speed, duplex;
484 s32 ret_val = 0;
485
486 /* Check for the case where we have fiber media and auto-neg failed
487 * so we had to force link. In this case, we need to force the
488 * configuration of the MAC to match the "fc" parameter.
489 */
490 if (mac->autoneg_failed) {
491 if (hw->phy.media_type == igc_media_type_copper)
492 ret_val = igc_force_mac_fc(hw);
493 }
494
495 if (ret_val) {
496 hw_dbg("Error forcing flow control settings\n");
497 goto out;
498 }
499
500 /* Check for the case where we have copper media and auto-neg is
501 * enabled. In this case, we need to check and see if Auto-Neg
502 * has completed, and if so, how the PHY and link partner has
503 * flow control configured.
504 */
505 if (hw->phy.media_type == igc_media_type_copper && mac->autoneg) {
506 /* Read the MII Status Register and check to see if AutoNeg
507 * has completed. We read this twice because this reg has
508 * some "sticky" (latched) bits.
509 */
510 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
511 &mii_status_reg);
512 if (ret_val)
513 goto out;
514 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
515 &mii_status_reg);
516 if (ret_val)
517 goto out;
518
519 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
520 hw_dbg("Copper PHY and Auto Neg has not completed.\n");
521 goto out;
522 }
523
524 /* The AutoNeg process has completed, so we now need to
525 * read both the Auto Negotiation Advertisement
526 * Register (Address 4) and the Auto_Negotiation Base
527 * Page Ability Register (Address 5) to determine how
528 * flow control was negotiated.
529 */
530 ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
531 &mii_nway_adv_reg);
532 if (ret_val)
533 goto out;
534 ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
535 &mii_nway_lp_ability_reg);
536 if (ret_val)
537 goto out;
538 /* Two bits in the Auto Negotiation Advertisement Register
539 * (Address 4) and two bits in the Auto Negotiation Base
540 * Page Ability Register (Address 5) determine flow control
541 * for both the PHY and the link partner. The following
542 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
543 * 1999, describes these PAUSE resolution bits and how flow
544 * control is determined based upon these settings.
545 * NOTE: DC = Don't Care
546 *
547 * LOCAL DEVICE | LINK PARTNER
548 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
549 *-------|---------|-------|---------|--------------------
550 * 0 | 0 | DC | DC | igc_fc_none
551 * 0 | 1 | 0 | DC | igc_fc_none
552 * 0 | 1 | 1 | 0 | igc_fc_none
553 * 0 | 1 | 1 | 1 | igc_fc_tx_pause
554 * 1 | 0 | 0 | DC | igc_fc_none
555 * 1 | DC | 1 | DC | igc_fc_full
556 * 1 | 1 | 0 | 0 | igc_fc_none
557 * 1 | 1 | 0 | 1 | igc_fc_rx_pause
558 *
559 * Are both PAUSE bits set to 1? If so, this implies
560 * Symmetric Flow Control is enabled at both ends. The
561 * ASM_DIR bits are irrelevant per the spec.
562 *
563 * For Symmetric Flow Control:
564 *
565 * LOCAL DEVICE | LINK PARTNER
566 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
567 *-------|---------|-------|---------|--------------------
568 * 1 | DC | 1 | DC | IGC_fc_full
569 *
570 */
571 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
572 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
573 /* Now we need to check if the user selected RX ONLY
574 * of pause frames. In this case, we had to advertise
575 * FULL flow control because we could not advertise RX
576 * ONLY. Hence, we must now check to see if we need to
577 * turn OFF the TRANSMISSION of PAUSE frames.
578 */
579 if (hw->fc.requested_mode == igc_fc_full) {
580 hw->fc.current_mode = igc_fc_full;
581 hw_dbg("Flow Control = FULL.\n");
582 } else {
583 hw->fc.current_mode = igc_fc_rx_pause;
584 hw_dbg("Flow Control = RX PAUSE frames only.\n");
585 }
586 }
587
588 /* For receiving PAUSE frames ONLY.
589 *
590 * LOCAL DEVICE | LINK PARTNER
591 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
592 *-------|---------|-------|---------|--------------------
593 * 0 | 1 | 1 | 1 | igc_fc_tx_pause
594 */
595 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
596 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
597 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
598 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
599 hw->fc.current_mode = igc_fc_tx_pause;
600 hw_dbg("Flow Control = TX PAUSE frames only.\n");
601 }
602 /* For transmitting PAUSE frames ONLY.
603 *
604 * LOCAL DEVICE | LINK PARTNER
605 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
606 *-------|---------|-------|---------|--------------------
607 * 1 | 1 | 0 | 1 | igc_fc_rx_pause
608 */
609 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
610 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
611 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
612 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
613 hw->fc.current_mode = igc_fc_rx_pause;
614 hw_dbg("Flow Control = RX PAUSE frames only.\n");
615 }
616 /* Per the IEEE spec, at this point flow control should be
617 * disabled. However, we want to consider that we could
618 * be connected to a legacy switch that doesn't advertise
619 * desired flow control, but can be forced on the link
620 * partner. So if we advertised no flow control, that is
621 * what we will resolve to. If we advertised some kind of
622 * receive capability (Rx Pause Only or Full Flow Control)
623 * and the link partner advertised none, we will configure
624 * ourselves to enable Rx Flow Control only. We can do
625 * this safely for two reasons: If the link partner really
626 * didn't want flow control enabled, and we enable Rx, no
627 * harm done since we won't be receiving any PAUSE frames
628 * anyway. If the intent on the link partner was to have
629 * flow control enabled, then by us enabling RX only, we
630 * can at least receive pause frames and process them.
631 * This is a good idea because in most cases, since we are
632 * predominantly a server NIC, more times than not we will
633 * be asked to delay transmission of packets than asking
634 * our link partner to pause transmission of frames.
635 */
636 else if ((hw->fc.requested_mode == igc_fc_none) ||
637 (hw->fc.requested_mode == igc_fc_tx_pause) ||
638 (hw->fc.strict_ieee)) {
639 hw->fc.current_mode = igc_fc_none;
640 hw_dbg("Flow Control = NONE.\n");
641 } else {
642 hw->fc.current_mode = igc_fc_rx_pause;
643 hw_dbg("Flow Control = RX PAUSE frames only.\n");
644 }
645
646 /* Now we need to do one last check... If we auto-
647 * negotiated to HALF DUPLEX, flow control should not be
648 * enabled per IEEE 802.3 spec.
649 */
650 ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
651 if (ret_val) {
652 hw_dbg("Error getting link speed and duplex\n");
653 goto out;
654 }
655
656 if (duplex == HALF_DUPLEX)
657 hw->fc.current_mode = igc_fc_none;
658
659 /* Now we call a subroutine to actually force the MAC
660 * controller to use the correct flow control settings.
661 */
662 ret_val = igc_force_mac_fc(hw);
663 if (ret_val) {
664 hw_dbg("Error forcing flow control settings\n");
665 goto out;
666 }
667 }
668
669out:
670 return 0;
671}
672
673/**
403 * igc_get_auto_rd_done - Check for auto read completion 674 * igc_get_auto_rd_done - Check for auto read completion
404 * @hw: pointer to the HW structure 675 * @hw: pointer to the HW structure
405 * 676 *
diff --git a/drivers/net/ethernet/intel/igc/igc_mac.h b/drivers/net/ethernet/intel/igc/igc_mac.h
index c842cc561123..782bc995badc 100644
--- a/drivers/net/ethernet/intel/igc/igc_mac.h
+++ b/drivers/net/ethernet/intel/igc/igc_mac.h
@@ -15,6 +15,8 @@
15/* forward declaration */ 15/* forward declaration */
16s32 igc_disable_pcie_master(struct igc_hw *hw); 16s32 igc_disable_pcie_master(struct igc_hw *hw);
17s32 igc_check_for_copper_link(struct igc_hw *hw); 17s32 igc_check_for_copper_link(struct igc_hw *hw);
18s32 igc_config_fc_after_link_up(struct igc_hw *hw);
19s32 igc_force_mac_fc(struct igc_hw *hw);
18void igc_init_rx_addrs(struct igc_hw *hw, u16 rar_count); 20void igc_init_rx_addrs(struct igc_hw *hw, u16 rar_count);
19s32 igc_setup_link(struct igc_hw *hw); 21s32 igc_setup_link(struct igc_hw *hw);
20void igc_clear_hw_cntrs_base(struct igc_hw *hw); 22void igc_clear_hw_cntrs_base(struct igc_hw *hw);
diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c
index 14f324826604..e1a078e084f0 100644
--- a/drivers/net/ethernet/intel/igc/igc_main.c
+++ b/drivers/net/ethernet/intel/igc/igc_main.c
@@ -3403,6 +3403,25 @@ static int igc_probe(struct pci_dev *pdev,
3403 netdev->min_mtu = ETH_MIN_MTU; 3403 netdev->min_mtu = ETH_MIN_MTU;
3404 netdev->max_mtu = MAX_STD_JUMBO_FRAME_SIZE; 3404 netdev->max_mtu = MAX_STD_JUMBO_FRAME_SIZE;
3405 3405
3406 /* before reading the NVM, reset the controller to put the device in a
3407 * known good starting state
3408 */
3409 hw->mac.ops.reset_hw(hw);
3410
3411 if (eth_platform_get_mac_address(&pdev->dev, hw->mac.addr)) {
3412 /* copy the MAC address out of the NVM */
3413 if (hw->mac.ops.read_mac_addr(hw))
3414 dev_err(&pdev->dev, "NVM Read Error\n");
3415 }
3416
3417 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
3418
3419 if (!is_valid_ether_addr(netdev->dev_addr)) {
3420 dev_err(&pdev->dev, "Invalid MAC Address\n");
3421 err = -EIO;
3422 goto err_eeprom;
3423 }
3424
3406 /* configure RXPBSIZE and TXPBSIZE */ 3425 /* configure RXPBSIZE and TXPBSIZE */
3407 wr32(IGC_RXPBS, I225_RXPBSIZE_DEFAULT); 3426 wr32(IGC_RXPBS, I225_RXPBSIZE_DEFAULT);
3408 wr32(IGC_TXPBS, I225_TXPBSIZE_DEFAULT); 3427 wr32(IGC_TXPBS, I225_TXPBSIZE_DEFAULT);
@@ -3411,6 +3430,14 @@ static int igc_probe(struct pci_dev *pdev,
3411 3430
3412 INIT_WORK(&adapter->reset_task, igc_reset_task); 3431 INIT_WORK(&adapter->reset_task, igc_reset_task);
3413 3432
3433 /* Initialize link properties that are user-changeable */
3434 adapter->fc_autoneg = true;
3435 hw->mac.autoneg = true;
3436 hw->phy.autoneg_advertised = 0xaf;
3437
3438 hw->fc.requested_mode = igc_fc_default;
3439 hw->fc.current_mode = igc_fc_default;
3440
3414 /* reset the hardware with the new settings */ 3441 /* reset the hardware with the new settings */
3415 igc_reset(adapter); 3442 igc_reset(adapter);
3416 3443
@@ -3438,6 +3465,9 @@ static int igc_probe(struct pci_dev *pdev,
3438 3465
3439err_register: 3466err_register:
3440 igc_release_hw_control(adapter); 3467 igc_release_hw_control(adapter);
3468err_eeprom:
3469 if (!igc_check_reset_block(hw))
3470 igc_reset_phy(hw);
3441err_sw_init: 3471err_sw_init:
3442 igc_clear_interrupt_scheme(adapter); 3472 igc_clear_interrupt_scheme(adapter);
3443 iounmap(adapter->io_addr); 3473 iounmap(adapter->io_addr);
diff --git a/drivers/net/ethernet/intel/igc/igc_phy.c b/drivers/net/ethernet/intel/igc/igc_phy.c
index 88583c1d4970..38e43e6fc1c7 100644
--- a/drivers/net/ethernet/intel/igc/igc_phy.c
+++ b/drivers/net/ethernet/intel/igc/igc_phy.c
@@ -3,6 +3,10 @@
3 3
4#include "igc_phy.h" 4#include "igc_phy.h"
5 5
6/* forward declaration */
7static s32 igc_phy_setup_autoneg(struct igc_hw *hw);
8static s32 igc_wait_autoneg(struct igc_hw *hw);
9
6/** 10/**
7 * igc_check_reset_block - Check if PHY reset is blocked 11 * igc_check_reset_block - Check if PHY reset is blocked
8 * @hw: pointer to the HW structure 12 * @hw: pointer to the HW structure
@@ -212,6 +216,336 @@ out:
212} 216}
213 217
214/** 218/**
219 * igc_copper_link_autoneg - Setup/Enable autoneg for copper link
220 * @hw: pointer to the HW structure
221 *
222 * Performs initial bounds checking on autoneg advertisement parameter, then
223 * configure to advertise the full capability. Setup the PHY to autoneg
224 * and restart the negotiation process between the link partner. If
225 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
226 */
227static s32 igc_copper_link_autoneg(struct igc_hw *hw)
228{
229 struct igc_phy_info *phy = &hw->phy;
230 u16 phy_ctrl;
231 s32 ret_val;
232
233 /* Perform some bounds checking on the autoneg advertisement
234 * parameter.
235 */
236 phy->autoneg_advertised &= phy->autoneg_mask;
237
238 /* If autoneg_advertised is zero, we assume it was not defaulted
239 * by the calling code so we set to advertise full capability.
240 */
241 if (phy->autoneg_advertised == 0)
242 phy->autoneg_advertised = phy->autoneg_mask;
243
244 hw_dbg("Reconfiguring auto-neg advertisement params\n");
245 ret_val = igc_phy_setup_autoneg(hw);
246 if (ret_val) {
247 hw_dbg("Error Setting up Auto-Negotiation\n");
248 goto out;
249 }
250 hw_dbg("Restarting Auto-Neg\n");
251
252 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
253 * the Auto Neg Restart bit in the PHY control register.
254 */
255 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
256 if (ret_val)
257 goto out;
258
259 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
260 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
261 if (ret_val)
262 goto out;
263
264 /* Does the user want to wait for Auto-Neg to complete here, or
265 * check at a later time (for example, callback routine).
266 */
267 if (phy->autoneg_wait_to_complete) {
268 ret_val = igc_wait_autoneg(hw);
269 if (ret_val) {
270 hw_dbg("Error while waiting for autoneg to complete\n");
271 goto out;
272 }
273 }
274
275 hw->mac.get_link_status = true;
276
277out:
278 return ret_val;
279}
280
281/**
282 * igc_wait_autoneg - Wait for auto-neg completion
283 * @hw: pointer to the HW structure
284 *
285 * Waits for auto-negotiation to complete or for the auto-negotiation time
286 * limit to expire, which ever happens first.
287 */
288static s32 igc_wait_autoneg(struct igc_hw *hw)
289{
290 u16 i, phy_status;
291 s32 ret_val = 0;
292
293 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
294 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
295 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
296 if (ret_val)
297 break;
298 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
299 if (ret_val)
300 break;
301 if (phy_status & MII_SR_AUTONEG_COMPLETE)
302 break;
303 msleep(100);
304 }
305
306 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
307 * has completed.
308 */
309 return ret_val;
310}
311
312/**
313 * igc_phy_setup_autoneg - Configure PHY for auto-negotiation
314 * @hw: pointer to the HW structure
315 *
316 * Reads the MII auto-neg advertisement register and/or the 1000T control
317 * register and if the PHY is already setup for auto-negotiation, then
318 * return successful. Otherwise, setup advertisement and flow control to
319 * the appropriate values for the wanted auto-negotiation.
320 */
321static s32 igc_phy_setup_autoneg(struct igc_hw *hw)
322{
323 struct igc_phy_info *phy = &hw->phy;
324 u16 aneg_multigbt_an_ctrl = 0;
325 u16 mii_1000t_ctrl_reg = 0;
326 u16 mii_autoneg_adv_reg;
327 s32 ret_val;
328
329 phy->autoneg_advertised &= phy->autoneg_mask;
330
331 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
332 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
333 if (ret_val)
334 return ret_val;
335
336 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
337 /* Read the MII 1000Base-T Control Register (Address 9). */
338 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
339 &mii_1000t_ctrl_reg);
340 if (ret_val)
341 return ret_val;
342 }
343
344 if ((phy->autoneg_mask & ADVERTISE_2500_FULL) &&
345 hw->phy.id == I225_I_PHY_ID) {
346 /* Read the MULTI GBT AN Control Register - reg 7.32 */
347 ret_val = phy->ops.read_reg(hw, (STANDARD_AN_REG_MASK <<
348 MMD_DEVADDR_SHIFT) |
349 ANEG_MULTIGBT_AN_CTRL,
350 &aneg_multigbt_an_ctrl);
351
352 if (ret_val)
353 return ret_val;
354 }
355
356 /* Need to parse both autoneg_advertised and fc and set up
357 * the appropriate PHY registers. First we will parse for
358 * autoneg_advertised software override. Since we can advertise
359 * a plethora of combinations, we need to check each bit
360 * individually.
361 */
362
363 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
364 * Advertisement Register (Address 4) and the 1000 mb speed bits in
365 * the 1000Base-T Control Register (Address 9).
366 */
367 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
368 NWAY_AR_100TX_HD_CAPS |
369 NWAY_AR_10T_FD_CAPS |
370 NWAY_AR_10T_HD_CAPS);
371 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
372
373 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
374
375 /* Do we want to advertise 10 Mb Half Duplex? */
376 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
377 hw_dbg("Advertise 10mb Half duplex\n");
378 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
379 }
380
381 /* Do we want to advertise 10 Mb Full Duplex? */
382 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
383 hw_dbg("Advertise 10mb Full duplex\n");
384 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
385 }
386
387 /* Do we want to advertise 100 Mb Half Duplex? */
388 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
389 hw_dbg("Advertise 100mb Half duplex\n");
390 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
391 }
392
393 /* Do we want to advertise 100 Mb Full Duplex? */
394 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
395 hw_dbg("Advertise 100mb Full duplex\n");
396 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
397 }
398
399 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
400 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
401 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
402
403 /* Do we want to advertise 1000 Mb Full Duplex? */
404 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
405 hw_dbg("Advertise 1000mb Full duplex\n");
406 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
407 }
408
409 /* We do not allow the Phy to advertise 2500 Mb Half Duplex */
410 if (phy->autoneg_advertised & ADVERTISE_2500_HALF)
411 hw_dbg("Advertise 2500mb Half duplex request denied!\n");
412
413 /* Do we want to advertise 2500 Mb Full Duplex? */
414 if (phy->autoneg_advertised & ADVERTISE_2500_FULL) {
415 hw_dbg("Advertise 2500mb Full duplex\n");
416 aneg_multigbt_an_ctrl |= CR_2500T_FD_CAPS;
417 } else {
418 aneg_multigbt_an_ctrl &= ~CR_2500T_FD_CAPS;
419 }
420
421 /* Check for a software override of the flow control settings, and
422 * setup the PHY advertisement registers accordingly. If
423 * auto-negotiation is enabled, then software will have to set the
424 * "PAUSE" bits to the correct value in the Auto-Negotiation
425 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
426 * negotiation.
427 *
428 * The possible values of the "fc" parameter are:
429 * 0: Flow control is completely disabled
430 * 1: Rx flow control is enabled (we can receive pause frames
431 * but not send pause frames).
432 * 2: Tx flow control is enabled (we can send pause frames
433 * but we do not support receiving pause frames).
434 * 3: Both Rx and Tx flow control (symmetric) are enabled.
435 * other: No software override. The flow control configuration
436 * in the EEPROM is used.
437 */
438 switch (hw->fc.current_mode) {
439 case igc_fc_none:
440 /* Flow control (Rx & Tx) is completely disabled by a
441 * software over-ride.
442 */
443 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
444 break;
445 case igc_fc_rx_pause:
446 /* Rx Flow control is enabled, and Tx Flow control is
447 * disabled, by a software over-ride.
448 *
449 * Since there really isn't a way to advertise that we are
450 * capable of Rx Pause ONLY, we will advertise that we
451 * support both symmetric and asymmetric Rx PAUSE. Later
452 * (in igc_config_fc_after_link_up) we will disable the
453 * hw's ability to send PAUSE frames.
454 */
455 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
456 break;
457 case igc_fc_tx_pause:
458 /* Tx Flow control is enabled, and Rx Flow control is
459 * disabled, by a software over-ride.
460 */
461 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
462 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
463 break;
464 case igc_fc_full:
465 /* Flow control (both Rx and Tx) is enabled by a software
466 * over-ride.
467 */
468 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
469 break;
470 default:
471 hw_dbg("Flow control param set incorrectly\n");
472 return -IGC_ERR_CONFIG;
473 }
474
475 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
476 if (ret_val)
477 return ret_val;
478
479 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
480
481 if (phy->autoneg_mask & ADVERTISE_1000_FULL)
482 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL,
483 mii_1000t_ctrl_reg);
484
485 if ((phy->autoneg_mask & ADVERTISE_2500_FULL) &&
486 hw->phy.id == I225_I_PHY_ID)
487 ret_val = phy->ops.write_reg(hw,
488 (STANDARD_AN_REG_MASK <<
489 MMD_DEVADDR_SHIFT) |
490 ANEG_MULTIGBT_AN_CTRL,
491 aneg_multigbt_an_ctrl);
492
493 return ret_val;
494}
495
496/**
497 * igc_setup_copper_link - Configure copper link settings
498 * @hw: pointer to the HW structure
499 *
500 * Calls the appropriate function to configure the link for auto-neg or forced
501 * speed and duplex. Then we check for link, once link is established calls
502 * to configure collision distance and flow control are called. If link is
503 * not established, we return -IGC_ERR_PHY (-2).
504 */
505s32 igc_setup_copper_link(struct igc_hw *hw)
506{
507 s32 ret_val = 0;
508 bool link;
509
510 if (hw->mac.autoneg) {
511 /* Setup autoneg and flow control advertisement and perform
512 * autonegotiation.
513 */
514 ret_val = igc_copper_link_autoneg(hw);
515 if (ret_val)
516 goto out;
517 } else {
518 /* PHY will be set to 10H, 10F, 100H or 100F
519 * depending on user settings.
520 */
521 hw_dbg("Forcing Speed and Duplex\n");
522 ret_val = hw->phy.ops.force_speed_duplex(hw);
523 if (ret_val) {
524 hw_dbg("Error Forcing Speed and Duplex\n");
525 goto out;
526 }
527 }
528
529 /* Check link status. Wait up to 100 microseconds for link to become
530 * valid.
531 */
532 ret_val = igc_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link);
533 if (ret_val)
534 goto out;
535
536 if (link) {
537 hw_dbg("Valid link established!!!\n");
538 igc_config_collision_dist(hw);
539 ret_val = igc_config_fc_after_link_up(hw);
540 } else {
541 hw_dbg("Unable to establish link!!!\n");
542 }
543
544out:
545 return ret_val;
546}
547
548/**
215 * igc_read_phy_reg_mdic - Read MDI control register 549 * igc_read_phy_reg_mdic - Read MDI control register
216 * @hw: pointer to the HW structure 550 * @hw: pointer to the HW structure
217 * @offset: register offset to be read 551 * @offset: register offset to be read
diff --git a/drivers/net/ethernet/intel/igc/igc_phy.h b/drivers/net/ethernet/intel/igc/igc_phy.h
index 6a62f381559d..25cba33de7e2 100644
--- a/drivers/net/ethernet/intel/igc/igc_phy.h
+++ b/drivers/net/ethernet/intel/igc/igc_phy.h
@@ -12,6 +12,7 @@ s32 igc_get_phy_id(struct igc_hw *hw);
12s32 igc_phy_has_link(struct igc_hw *hw, u32 iterations, 12s32 igc_phy_has_link(struct igc_hw *hw, u32 iterations,
13 u32 usec_interval, bool *success); 13 u32 usec_interval, bool *success);
14s32 igc_check_downshift(struct igc_hw *hw); 14s32 igc_check_downshift(struct igc_hw *hw);
15s32 igc_setup_copper_link(struct igc_hw *hw);
15void igc_power_up_phy_copper(struct igc_hw *hw); 16void igc_power_up_phy_copper(struct igc_hw *hw);
16void igc_power_down_phy_copper(struct igc_hw *hw); 17void igc_power_down_phy_copper(struct igc_hw *hw);
17s32 igc_write_phy_reg_gpy(struct igc_hw *hw, u32 offset, u16 data); 18s32 igc_write_phy_reg_gpy(struct igc_hw *hw, u32 offset, u16 data);