2 * Copyright 2021 Intel Corp
3 * Copyright 2021 Rubicon Communications, LLC (Netgate)
4 * SPDX-License-Identifier: BSD-3-Clause
12 static s32 igc_wait_autoneg(struct igc_hw *hw);
15 * igc_init_phy_ops_generic - Initialize PHY function pointers
16 * @hw: pointer to the HW structure
18 * Setups up the function pointers to no-op functions
20 void igc_init_phy_ops_generic(struct igc_hw *hw)
22 struct igc_phy_info *phy = &hw->phy;
23 DEBUGFUNC("igc_init_phy_ops_generic");
25 /* Initialize function pointers */
26 phy->ops.init_params = igc_null_ops_generic;
27 phy->ops.acquire = igc_null_ops_generic;
28 phy->ops.check_reset_block = igc_null_ops_generic;
29 phy->ops.force_speed_duplex = igc_null_ops_generic;
30 phy->ops.get_info = igc_null_ops_generic;
31 phy->ops.set_page = igc_null_set_page;
32 phy->ops.read_reg = igc_null_read_reg;
33 phy->ops.read_reg_locked = igc_null_read_reg;
34 phy->ops.read_reg_page = igc_null_read_reg;
35 phy->ops.release = igc_null_phy_generic;
36 phy->ops.reset = igc_null_ops_generic;
37 phy->ops.set_d0_lplu_state = igc_null_lplu_state;
38 phy->ops.set_d3_lplu_state = igc_null_lplu_state;
39 phy->ops.write_reg = igc_null_write_reg;
40 phy->ops.write_reg_locked = igc_null_write_reg;
41 phy->ops.write_reg_page = igc_null_write_reg;
42 phy->ops.power_up = igc_null_phy_generic;
43 phy->ops.power_down = igc_null_phy_generic;
47 * igc_null_set_page - No-op function, return 0
48 * @hw: pointer to the HW structure
49 * @data: dummy variable
51 s32 igc_null_set_page(struct igc_hw IGC_UNUSEDARG *hw,
52 u16 IGC_UNUSEDARG data)
54 DEBUGFUNC("igc_null_set_page");
59 * igc_null_read_reg - No-op function, return 0
60 * @hw: pointer to the HW structure
61 * @offset: dummy variable
62 * @data: dummy variable
64 s32 igc_null_read_reg(struct igc_hw IGC_UNUSEDARG *hw,
65 u32 IGC_UNUSEDARG offset, u16 IGC_UNUSEDARG *data)
67 DEBUGFUNC("igc_null_read_reg");
72 * igc_null_phy_generic - No-op function, return void
73 * @hw: pointer to the HW structure
75 void igc_null_phy_generic(struct igc_hw IGC_UNUSEDARG *hw)
77 DEBUGFUNC("igc_null_phy_generic");
82 * igc_null_lplu_state - No-op function, return 0
83 * @hw: pointer to the HW structure
84 * @active: dummy variable
86 s32 igc_null_lplu_state(struct igc_hw IGC_UNUSEDARG *hw,
87 bool IGC_UNUSEDARG active)
89 DEBUGFUNC("igc_null_lplu_state");
94 * igc_null_write_reg - No-op function, return 0
95 * @hw: pointer to the HW structure
96 * @offset: dummy variable
97 * @data: dummy variable
99 s32 igc_null_write_reg(struct igc_hw IGC_UNUSEDARG *hw,
100 u32 IGC_UNUSEDARG offset, u16 IGC_UNUSEDARG data)
102 DEBUGFUNC("igc_null_write_reg");
107 * igc_check_reset_block_generic - Check if PHY reset is blocked
108 * @hw: pointer to the HW structure
110 * Read the PHY management control register and check whether a PHY reset
111 * is blocked. If a reset is not blocked return IGC_SUCCESS, otherwise
112 * return IGC_BLK_PHY_RESET (12).
114 s32 igc_check_reset_block_generic(struct igc_hw *hw)
118 DEBUGFUNC("igc_check_reset_block");
120 manc = IGC_READ_REG(hw, IGC_MANC);
122 return (manc & IGC_MANC_BLK_PHY_RST_ON_IDE) ?
123 IGC_BLK_PHY_RESET : IGC_SUCCESS;
127 * igc_get_phy_id - Retrieve the PHY ID and revision
128 * @hw: pointer to the HW structure
130 * Reads the PHY registers and stores the PHY ID and possibly the PHY
131 * revision in the hardware structure.
133 s32 igc_get_phy_id(struct igc_hw *hw)
135 struct igc_phy_info *phy = &hw->phy;
136 s32 ret_val = IGC_SUCCESS;
139 DEBUGFUNC("igc_get_phy_id");
141 if (!phy->ops.read_reg)
144 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
148 phy->id = (u32)(phy_id << 16);
150 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
154 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
155 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
161 * igc_read_phy_reg_mdic - Read MDI control register
162 * @hw: pointer to the HW structure
163 * @offset: register offset to be read
164 * @data: pointer to the read data
166 * Reads the MDI control register in the PHY at offset and stores the
167 * information read to data.
169 s32 igc_read_phy_reg_mdic(struct igc_hw *hw, u32 offset, u16 *data)
171 struct igc_phy_info *phy = &hw->phy;
174 DEBUGFUNC("igc_read_phy_reg_mdic");
176 if (offset > MAX_PHY_REG_ADDRESS) {
177 DEBUGOUT1("PHY Address %d is out of range\n", offset);
178 return -IGC_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 = ((offset << IGC_MDIC_REG_SHIFT) |
186 (phy->addr << IGC_MDIC_PHY_SHIFT) |
189 IGC_WRITE_REG(hw, IGC_MDIC, mdic);
191 /* Poll the ready bit to see if the MDI read completed
192 * Increasing the time out as testing showed failures with
195 for (i = 0; i < (IGC_GEN_POLL_TIMEOUT * 3); i++) {
197 mdic = IGC_READ_REG(hw, IGC_MDIC);
198 if (mdic & IGC_MDIC_READY)
201 if (!(mdic & IGC_MDIC_READY)) {
202 DEBUGOUT("MDI Read did not complete\n");
205 if (mdic & IGC_MDIC_ERROR) {
206 DEBUGOUT("MDI Error\n");
209 if (((mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT) != offset) {
210 DEBUGOUT2("MDI Read offset error - requested %d, returned %d\n",
212 (mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT);
221 * igc_write_phy_reg_mdic - Write MDI control register
222 * @hw: pointer to the HW structure
223 * @offset: register offset to write to
224 * @data: data to write to register at offset
226 * Writes data to MDI control register in the PHY at offset.
228 s32 igc_write_phy_reg_mdic(struct igc_hw *hw, u32 offset, u16 data)
230 struct igc_phy_info *phy = &hw->phy;
233 DEBUGFUNC("igc_write_phy_reg_mdic");
235 if (offset > MAX_PHY_REG_ADDRESS) {
236 DEBUGOUT1("PHY Address %d is out of range\n", offset);
237 return -IGC_ERR_PARAM;
240 /* Set up Op-code, Phy Address, and register offset in the MDI
241 * Control register. The MAC will take care of interfacing with the
242 * PHY to retrieve the desired data.
244 mdic = (((u32)data) |
245 (offset << IGC_MDIC_REG_SHIFT) |
246 (phy->addr << IGC_MDIC_PHY_SHIFT) |
247 (IGC_MDIC_OP_WRITE));
249 IGC_WRITE_REG(hw, IGC_MDIC, mdic);
251 /* Poll the ready bit to see if the MDI read completed
252 * Increasing the time out as testing showed failures with
255 for (i = 0; i < (IGC_GEN_POLL_TIMEOUT * 3); i++) {
257 mdic = IGC_READ_REG(hw, IGC_MDIC);
258 if (mdic & IGC_MDIC_READY)
261 if (!(mdic & IGC_MDIC_READY)) {
262 DEBUGOUT("MDI Write did not complete\n");
265 if (mdic & IGC_MDIC_ERROR) {
266 DEBUGOUT("MDI Error\n");
269 if (((mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT) != offset) {
270 DEBUGOUT2("MDI Write offset error - requested %d, returned %d\n",
272 (mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT);
280 * igc_phy_setup_autoneg - Configure PHY for auto-negotiation
281 * @hw: pointer to the HW structure
283 * Reads the MII auto-neg advertisement register and/or the 1000T control
284 * register and if the PHY is already setup for auto-negotiation, then
285 * return successful. Otherwise, setup advertisement and flow control to
286 * the appropriate values for the wanted auto-negotiation.
288 static s32 igc_phy_setup_autoneg(struct igc_hw *hw)
290 struct igc_phy_info *phy = &hw->phy;
292 u16 mii_autoneg_adv_reg;
293 u16 mii_1000t_ctrl_reg = 0;
294 u16 aneg_multigbt_an_ctrl = 0;
296 DEBUGFUNC("igc_phy_setup_autoneg");
298 phy->autoneg_advertised &= phy->autoneg_mask;
300 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
301 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
305 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
306 /* Read the MII 1000Base-T Control Register (Address 9). */
307 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
308 &mii_1000t_ctrl_reg);
313 if ((phy->autoneg_mask & ADVERTISE_2500_FULL) &&
314 hw->phy.id == I225_I_PHY_ID) {
315 /* Read the MULTI GBT AN Control Register - reg 7.32 */
316 ret_val = phy->ops.read_reg(hw, (STANDARD_AN_REG_MASK <<
318 ANEG_MULTIGBT_AN_CTRL,
319 &aneg_multigbt_an_ctrl);
325 /* Need to parse both autoneg_advertised and fc and set up
326 * the appropriate PHY registers. First we will parse for
327 * autoneg_advertised software override. Since we can advertise
328 * a plethora of combinations, we need to check each bit
332 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
333 * Advertisement Register (Address 4) and the 1000 mb speed bits in
334 * the 1000Base-T Control Register (Address 9).
336 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
337 NWAY_AR_100TX_HD_CAPS |
338 NWAY_AR_10T_FD_CAPS |
339 NWAY_AR_10T_HD_CAPS);
340 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
342 DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
344 /* Do we want to advertise 10 Mb Half Duplex? */
345 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
346 DEBUGOUT("Advertise 10mb Half duplex\n");
347 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
350 /* Do we want to advertise 10 Mb Full Duplex? */
351 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
352 DEBUGOUT("Advertise 10mb Full duplex\n");
353 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
356 /* Do we want to advertise 100 Mb Half Duplex? */
357 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
358 DEBUGOUT("Advertise 100mb Half duplex\n");
359 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
362 /* Do we want to advertise 100 Mb Full Duplex? */
363 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
364 DEBUGOUT("Advertise 100mb Full duplex\n");
365 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
368 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
369 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
370 DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
372 /* Do we want to advertise 1000 Mb Full Duplex? */
373 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
374 DEBUGOUT("Advertise 1000mb Full duplex\n");
375 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
378 /* We do not allow the Phy to advertise 2500 Mb Half Duplex */
379 if (phy->autoneg_advertised & ADVERTISE_2500_HALF)
380 DEBUGOUT("Advertise 2500mb Half duplex request denied!\n");
382 /* Do we want to advertise 2500 Mb Full Duplex? */
383 if (phy->autoneg_advertised & ADVERTISE_2500_FULL) {
384 DEBUGOUT("Advertise 2500mb Full duplex\n");
385 aneg_multigbt_an_ctrl |= CR_2500T_FD_CAPS;
387 aneg_multigbt_an_ctrl &= ~CR_2500T_FD_CAPS;
390 /* Check for a software override of the flow control settings, and
391 * setup the PHY advertisement registers accordingly. If
392 * auto-negotiation is enabled, then software will have to set the
393 * "PAUSE" bits to the correct value in the Auto-Negotiation
394 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
397 * The possible values of the "fc" parameter are:
398 * 0: Flow control is completely disabled
399 * 1: Rx flow control is enabled (we can receive pause frames
400 * but not send pause frames).
401 * 2: Tx flow control is enabled (we can send pause frames
402 * but we do not support receiving pause frames).
403 * 3: Both Rx and Tx flow control (symmetric) are enabled.
404 * other: No software override. The flow control configuration
405 * in the EEPROM is used.
407 switch (hw->fc.current_mode) {
409 /* Flow control (Rx & Tx) is completely disabled by a
410 * software over-ride.
412 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
414 case igc_fc_rx_pause:
415 /* Rx Flow control is enabled, and Tx Flow control is
416 * disabled, by a software over-ride.
418 * Since there really isn't a way to advertise that we are
419 * capable of Rx Pause ONLY, we will advertise that we
420 * support both symmetric and asymmetric Rx PAUSE. Later
421 * (in igc_config_fc_after_link_up) we will disable the
422 * hw's ability to send PAUSE frames.
424 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
426 case igc_fc_tx_pause:
427 /* Tx Flow control is enabled, and Rx Flow control is
428 * disabled, by a software over-ride.
430 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
431 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
434 /* Flow control (both Rx and Tx) is enabled by a software
437 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
440 DEBUGOUT("Flow control param set incorrectly\n");
441 return -IGC_ERR_CONFIG;
444 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
448 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
450 if (phy->autoneg_mask & ADVERTISE_1000_FULL)
451 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL,
454 if ((phy->autoneg_mask & ADVERTISE_2500_FULL) &&
455 hw->phy.id == I225_I_PHY_ID)
456 ret_val = phy->ops.write_reg(hw,
457 (STANDARD_AN_REG_MASK <<
459 ANEG_MULTIGBT_AN_CTRL,
460 aneg_multigbt_an_ctrl);
466 * igc_copper_link_autoneg - Setup/Enable autoneg for copper link
467 * @hw: pointer to the HW structure
469 * Performs initial bounds checking on autoneg advertisement parameter, then
470 * configure to advertise the full capability. Setup the PHY to autoneg
471 * and restart the negotiation process between the link partner. If
472 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
474 static s32 igc_copper_link_autoneg(struct igc_hw *hw)
476 struct igc_phy_info *phy = &hw->phy;
480 DEBUGFUNC("igc_copper_link_autoneg");
482 /* Perform some bounds checking on the autoneg advertisement
485 phy->autoneg_advertised &= phy->autoneg_mask;
487 /* If autoneg_advertised is zero, we assume it was not defaulted
488 * by the calling code so we set to advertise full capability.
490 if (!phy->autoneg_advertised)
491 phy->autoneg_advertised = phy->autoneg_mask;
493 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
494 ret_val = igc_phy_setup_autoneg(hw);
496 DEBUGOUT("Error Setting up Auto-Negotiation\n");
499 DEBUGOUT("Restarting Auto-Neg\n");
501 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
502 * the Auto Neg Restart bit in the PHY control register.
504 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
508 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
509 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
513 /* Does the user want to wait for Auto-Neg to complete here, or
514 * check at a later time (for example, callback routine).
516 if (phy->autoneg_wait_to_complete) {
517 ret_val = igc_wait_autoneg(hw);
519 DEBUGOUT("Error while waiting for autoneg to complete\n");
524 hw->mac.get_link_status = true;
530 * igc_setup_copper_link_generic - Configure copper link settings
531 * @hw: pointer to the HW structure
533 * Calls the appropriate function to configure the link for auto-neg or forced
534 * speed and duplex. Then we check for link, once link is established calls
535 * to configure collision distance and flow control are called. If link is
536 * not established, we return -IGC_ERR_PHY (-2).
538 s32 igc_setup_copper_link_generic(struct igc_hw *hw)
543 DEBUGFUNC("igc_setup_copper_link_generic");
545 if (hw->mac.autoneg) {
546 /* Setup autoneg and flow control advertisement and perform
549 ret_val = igc_copper_link_autoneg(hw);
553 /* PHY will be set to 10H, 10F, 100H or 100F
554 * depending on user settings.
556 DEBUGOUT("Forcing Speed and Duplex\n");
557 ret_val = hw->phy.ops.force_speed_duplex(hw);
559 DEBUGOUT("Error Forcing Speed and Duplex\n");
564 /* Check link status. Wait up to 100 microseconds for link to become
567 ret_val = igc_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
573 DEBUGOUT("Valid link established!!!\n");
574 hw->mac.ops.config_collision_dist(hw);
575 ret_val = igc_config_fc_after_link_up_generic(hw);
577 DEBUGOUT("Unable to establish link!!!\n");
584 * igc_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
585 * @hw: pointer to the HW structure
586 * @phy_ctrl: pointer to current value of PHY_CONTROL
588 * Forces speed and duplex on the PHY by doing the following: disable flow
589 * control, force speed/duplex on the MAC, disable auto speed detection,
590 * disable auto-negotiation, configure duplex, configure speed, configure
591 * the collision distance, write configuration to CTRL register. The
592 * caller must write to the PHY_CONTROL register for these settings to
595 void igc_phy_force_speed_duplex_setup(struct igc_hw *hw, u16 *phy_ctrl)
597 struct igc_mac_info *mac = &hw->mac;
600 DEBUGFUNC("igc_phy_force_speed_duplex_setup");
602 /* Turn off flow control when forcing speed/duplex */
603 hw->fc.current_mode = igc_fc_none;
605 /* Force speed/duplex on the mac */
606 ctrl = IGC_READ_REG(hw, IGC_CTRL);
607 ctrl |= (IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
608 ctrl &= ~IGC_CTRL_SPD_SEL;
610 /* Disable Auto Speed Detection */
611 ctrl &= ~IGC_CTRL_ASDE;
613 /* Disable autoneg on the phy */
614 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
616 /* Forcing Full or Half Duplex? */
617 if (mac->forced_speed_duplex & IGC_ALL_HALF_DUPLEX) {
618 ctrl &= ~IGC_CTRL_FD;
619 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
620 DEBUGOUT("Half Duplex\n");
623 *phy_ctrl |= MII_CR_FULL_DUPLEX;
624 DEBUGOUT("Full Duplex\n");
627 /* Forcing 10mb or 100mb? */
628 if (mac->forced_speed_duplex & IGC_ALL_100_SPEED) {
629 ctrl |= IGC_CTRL_SPD_100;
630 *phy_ctrl |= MII_CR_SPEED_100;
631 *phy_ctrl &= ~MII_CR_SPEED_1000;
632 DEBUGOUT("Forcing 100mb\n");
634 ctrl &= ~(IGC_CTRL_SPD_1000 | IGC_CTRL_SPD_100);
635 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
636 DEBUGOUT("Forcing 10mb\n");
639 hw->mac.ops.config_collision_dist(hw);
641 IGC_WRITE_REG(hw, IGC_CTRL, ctrl);
645 * igc_set_d3_lplu_state_generic - Sets low power link up state for D3
646 * @hw: pointer to the HW structure
647 * @active: boolean used to enable/disable lplu
649 * Success returns 0, Failure returns 1
651 * The low power link up (lplu) state is set to the power management level D3
652 * and SmartSpeed is disabled when active is true, else clear lplu for D3
653 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
654 * is used during Dx states where the power conservation is most important.
655 * During driver activity, SmartSpeed should be enabled so performance is
658 s32 igc_set_d3_lplu_state_generic(struct igc_hw *hw, bool active)
660 struct igc_phy_info *phy = &hw->phy;
664 DEBUGFUNC("igc_set_d3_lplu_state_generic");
666 if (!hw->phy.ops.read_reg)
669 ret_val = phy->ops.read_reg(hw, IGP02IGC_PHY_POWER_MGMT, &data);
674 data &= ~IGP02IGC_PM_D3_LPLU;
675 ret_val = phy->ops.write_reg(hw, IGP02IGC_PHY_POWER_MGMT,
679 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
680 * during Dx states where the power conservation is most
681 * important. During driver activity we should enable
682 * SmartSpeed, so performance is maintained.
684 if (phy->smart_speed == igc_smart_speed_on) {
685 ret_val = phy->ops.read_reg(hw,
686 IGP01IGC_PHY_PORT_CONFIG,
691 data |= IGP01IGC_PSCFR_SMART_SPEED;
692 ret_val = phy->ops.write_reg(hw,
693 IGP01IGC_PHY_PORT_CONFIG,
697 } else if (phy->smart_speed == igc_smart_speed_off) {
698 ret_val = phy->ops.read_reg(hw,
699 IGP01IGC_PHY_PORT_CONFIG,
704 data &= ~IGP01IGC_PSCFR_SMART_SPEED;
705 ret_val = phy->ops.write_reg(hw,
706 IGP01IGC_PHY_PORT_CONFIG,
711 } else if ((phy->autoneg_advertised == IGC_ALL_SPEED_DUPLEX) ||
712 (phy->autoneg_advertised == IGC_ALL_NOT_GIG) ||
713 (phy->autoneg_advertised == IGC_ALL_10_SPEED)) {
714 data |= IGP02IGC_PM_D3_LPLU;
715 ret_val = phy->ops.write_reg(hw, IGP02IGC_PHY_POWER_MGMT,
720 /* When LPLU is enabled, we should disable SmartSpeed */
721 ret_val = phy->ops.read_reg(hw, IGP01IGC_PHY_PORT_CONFIG,
726 data &= ~IGP01IGC_PSCFR_SMART_SPEED;
727 ret_val = phy->ops.write_reg(hw, IGP01IGC_PHY_PORT_CONFIG,
735 * igc_check_downshift_generic - Checks whether a downshift in speed occurred
736 * @hw: pointer to the HW structure
738 * Success returns 0, Failure returns 1
740 * A downshift is detected by querying the PHY link health.
742 s32 igc_check_downshift_generic(struct igc_hw *hw)
744 struct igc_phy_info *phy = &hw->phy;
747 DEBUGFUNC("igc_check_downshift_generic");
752 /* speed downshift not supported */
753 phy->speed_downgraded = false;
761 * igc_wait_autoneg - Wait for auto-neg completion
762 * @hw: pointer to the HW structure
764 * Waits for auto-negotiation to complete or for the auto-negotiation time
765 * limit to expire, which ever happens first.
767 static s32 igc_wait_autoneg(struct igc_hw *hw)
769 s32 ret_val = IGC_SUCCESS;
772 DEBUGFUNC("igc_wait_autoneg");
774 if (!hw->phy.ops.read_reg)
777 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
778 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
779 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
782 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
785 if (phy_status & MII_SR_AUTONEG_COMPLETE)
790 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
797 * igc_phy_has_link_generic - Polls PHY for link
798 * @hw: pointer to the HW structure
799 * @iterations: number of times to poll for link
800 * @usec_interval: delay between polling attempts
801 * @success: pointer to whether polling was successful or not
803 * Polls the PHY status register for link, 'iterations' number of times.
805 s32 igc_phy_has_link_generic(struct igc_hw *hw, u32 iterations,
806 u32 usec_interval, bool *success)
808 s32 ret_val = IGC_SUCCESS;
811 DEBUGFUNC("igc_phy_has_link_generic");
813 if (!hw->phy.ops.read_reg)
816 for (i = 0; i < iterations; i++) {
817 /* Some PHYs require the PHY_STATUS register to be read
818 * twice due to the link bit being sticky. No harm doing
819 * it across the board.
821 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
823 /* If the first read fails, another entity may have
824 * ownership of the resources, wait and try again to
825 * see if they have relinquished the resources yet.
827 if (usec_interval >= 1000)
828 msec_delay(usec_interval/1000);
830 usec_delay(usec_interval);
832 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
835 if (phy_status & MII_SR_LINK_STATUS)
837 if (usec_interval >= 1000)
838 msec_delay(usec_interval/1000);
840 usec_delay(usec_interval);
843 *success = (i < iterations);
849 * igc_phy_hw_reset_generic - PHY hardware reset
850 * @hw: pointer to the HW structure
852 * Verify the reset block is not blocking us from resetting. Acquire
853 * semaphore (if necessary) and read/set/write the device control reset
854 * bit in the PHY. Wait the appropriate delay time for the device to
855 * reset and release the semaphore (if necessary).
857 s32 igc_phy_hw_reset_generic(struct igc_hw *hw)
859 struct igc_phy_info *phy = &hw->phy;
861 u32 ctrl, timeout = 10000, phpm = 0;
863 DEBUGFUNC("igc_phy_hw_reset_generic");
865 if (phy->ops.check_reset_block) {
866 ret_val = phy->ops.check_reset_block(hw);
871 ret_val = phy->ops.acquire(hw);
875 phpm = IGC_READ_REG(hw, IGC_I225_PHPM);
877 ctrl = IGC_READ_REG(hw, IGC_CTRL);
878 IGC_WRITE_REG(hw, IGC_CTRL, ctrl | IGC_CTRL_PHY_RST);
881 usec_delay(phy->reset_delay_us);
883 IGC_WRITE_REG(hw, IGC_CTRL, ctrl);
889 phpm = IGC_READ_REG(hw, IGC_I225_PHPM);
892 } while (!(phpm & IGC_I225_PHPM_RST_COMPL) && timeout);
895 DEBUGOUT("Timeout expired after a phy reset\n");
897 phy->ops.release(hw);
903 * igc_power_up_phy_copper - Restore copper link in case of PHY power down
904 * @hw: pointer to the HW structure
906 * In the case of a PHY power down to save power, or to turn off link during a
907 * driver unload, or wake on lan is not enabled, restore the link to previous
910 void igc_power_up_phy_copper(struct igc_hw *hw)
914 /* The PHY will retain its settings across a power down/up cycle */
915 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
916 mii_reg &= ~MII_CR_POWER_DOWN;
917 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
922 * igc_power_down_phy_copper - Restore copper link in case of PHY power down
923 * @hw: pointer to the HW structure
925 * In the case of a PHY power down to save power, or to turn off link during a
926 * driver unload, or wake on lan is not enabled, restore the link to previous
929 void igc_power_down_phy_copper(struct igc_hw *hw)
933 /* The PHY will retain its settings across a power down/up cycle */
934 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
935 mii_reg |= MII_CR_POWER_DOWN;
936 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
940 * igc_write_phy_reg_gpy - Write GPY PHY register
941 * @hw: pointer to the HW structure
942 * @offset: register offset to write to
943 * @data: data to write at register offset
945 * Acquires semaphore, if necessary, then writes the data to PHY register
946 * at the offset. Release any acquired semaphores before exiting.
948 s32 igc_write_phy_reg_gpy(struct igc_hw *hw, u32 offset, u16 data)
951 u8 dev_addr = (offset & GPY_MMD_MASK) >> GPY_MMD_SHIFT;
953 DEBUGFUNC("igc_write_phy_reg_gpy");
955 offset = offset & GPY_REG_MASK;
958 ret_val = hw->phy.ops.acquire(hw);
961 ret_val = igc_write_phy_reg_mdic(hw, offset, data);
964 hw->phy.ops.release(hw);
966 ret_val = igc_write_xmdio_reg(hw, (u16)offset, dev_addr,
973 * igc_read_phy_reg_gpy - Read GPY PHY register
974 * @hw: pointer to the HW structure
975 * @offset: lower half is register offset to read to
976 * upper half is MMD to use.
977 * @data: data to read at register offset
979 * Acquires semaphore, if necessary, then reads the data in the PHY register
980 * at the offset. Release any acquired semaphores before exiting.
982 s32 igc_read_phy_reg_gpy(struct igc_hw *hw, u32 offset, u16 *data)
985 u8 dev_addr = (offset & GPY_MMD_MASK) >> GPY_MMD_SHIFT;
987 DEBUGFUNC("igc_read_phy_reg_gpy");
989 offset = offset & GPY_REG_MASK;
992 ret_val = hw->phy.ops.acquire(hw);
995 ret_val = igc_read_phy_reg_mdic(hw, offset, data);
998 hw->phy.ops.release(hw);
1000 ret_val = igc_read_xmdio_reg(hw, (u16)offset, dev_addr,
1008 * __igc_access_xmdio_reg - Read/write XMDIO register
1009 * @hw: pointer to the HW structure
1010 * @address: XMDIO address to program
1011 * @dev_addr: device address to program
1012 * @data: pointer to value to read/write from/to the XMDIO address
1013 * @read: boolean flag to indicate read or write
1015 static s32 __igc_access_xmdio_reg(struct igc_hw *hw, u16 address,
1016 u8 dev_addr, u16 *data, bool read)
1020 DEBUGFUNC("__igc_access_xmdio_reg");
1022 ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAC, dev_addr);
1026 ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAAD, address);
1030 ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAC, IGC_MMDAC_FUNC_DATA |
1036 ret_val = hw->phy.ops.read_reg(hw, IGC_MMDAAD, data);
1038 ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAAD, *data);
1042 /* Recalibrate the device back to 0 */
1043 ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAC, 0);
1051 * igc_read_xmdio_reg - Read XMDIO register
1052 * @hw: pointer to the HW structure
1053 * @addr: XMDIO address to program
1054 * @dev_addr: device address to program
1055 * @data: value to be read from the EMI address
1057 s32 igc_read_xmdio_reg(struct igc_hw *hw, u16 addr, u8 dev_addr, u16 *data)
1059 DEBUGFUNC("igc_read_xmdio_reg");
1061 return __igc_access_xmdio_reg(hw, addr, dev_addr, data, true);
1065 * igc_write_xmdio_reg - Write XMDIO register
1066 * @hw: pointer to the HW structure
1067 * @addr: XMDIO address to program
1068 * @dev_addr: device address to program
1069 * @data: value to be written to the XMDIO address
1071 s32 igc_write_xmdio_reg(struct igc_hw *hw, u16 addr, u8 dev_addr, u16 data)
1073 DEBUGFUNC("igc_write_xmdio_reg");
1075 return __igc_access_xmdio_reg(hw, addr, dev_addr, &data, false);