From: Jakub Chylkowski <[email protected]>

Both ixgbe_setup_phy_link_generic() and ixgbe_setup_phy_link_tnx()
end with the same three-line sequence that reads MDIO_CTRL1, sets
the MDIO_AN_CTRL1_RESTART bit, and writes MDIO_CTRL1 back.

Factor it out into a static helper ixgbe_restart_auto_neg() and call
it from both sites.

While at it, also check the return value of phy.ops.read_reg() in the
helper and skip the write on failure.  The original inlined code
ignored the read result and would OR MDIO_AN_CTRL1_RESTART into a
stale autoneg_reg value (left over from the prior MDIO_AN_ADVERTISE
write) and unconditionally write it back to MDIO_CTRL1 if the read
failed.  This is a small behavioral change: on read_reg() failure the
restart write is now skipped instead of being issued with a
potentially garbage value.

Signed-off-by: Jakub Chylkowski <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Signed-off-by: Aleksandr Loktionov <[email protected]>
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c | 36 ++++++++++++--------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
index de8f6c6..c7387a4 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
@@ -1089,6 +1089,26 @@ int ixgbe_mii_bus_init(struct ixgbe_hw *hw)
        return mdiobus_register(bus);
 }
 
+/**
+ * ixgbe_restart_auto_neg - restart PHY autonegotiation
+ * @hw: pointer to hardware structure
+ *
+ * Sets the restart autoneg bit in MDIO_CTRL1 to trigger a new
+ * autonegotiation cycle.
+ **/
+static void ixgbe_restart_auto_neg(struct ixgbe_hw *hw)
+{
+       u16 autoneg_reg;
+       int status;
+
+       status = hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_AN,
+                                     &autoneg_reg);
+       if (status)
+               return;
+       autoneg_reg |= MDIO_AN_CTRL1_RESTART;
+       hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, autoneg_reg);
+}
+
 /**
  *  ixgbe_setup_phy_link_generic - Set and restart autoneg
  *  @hw: pointer to hardware structure
@@ -1156,13 +1176,7 @@ int ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
                return 0;
 
        /* Restart PHY autonegotiation and wait for completion */
-       hw->phy.ops.read_reg(hw, MDIO_CTRL1,
-                            MDIO_MMD_AN, &autoneg_reg);
-
-       autoneg_reg |= MDIO_AN_CTRL1_RESTART;
-
-       hw->phy.ops.write_reg(hw, MDIO_CTRL1,
-                             MDIO_MMD_AN, autoneg_reg);
+       ixgbe_restart_auto_neg(hw);
 
        return status;
 }
@@ -1386,13 +1400,7 @@ int ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
                return 0;
 
        /* Restart PHY autonegotiation and wait for completion */
-       hw->phy.ops.read_reg(hw, MDIO_CTRL1,
-                            MDIO_MMD_AN, &autoneg_reg);
-
-       autoneg_reg |= MDIO_AN_CTRL1_RESTART;
-
-       hw->phy.ops.write_reg(hw, MDIO_CTRL1,
-                             MDIO_MMD_AN, autoneg_reg);
+       ixgbe_restart_auto_neg(hw);
        return 0;
 }
 
-- 
2.52.0

Reply via email to