net: phy: improve genphy_read_status
authorHeiner Kallweit <hkallweit1@gmail.com>
Sat, 30 Mar 2019 09:22:45 +0000 (10:22 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 2 Apr 2019 01:06:43 +0000 (18:06 -0700)
This patch improves few aspects of genphy_read_status():

- Don't initialize lpagb, it's not needed.

- Move initializing phydev->speed et al before the if clause.

- In auto-neg case, skip populating lp_advertising if we
  don't have a link. This avoids quite some unnecessary
  MDIO reads in case of phylib polling mode.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/phy_device.c

index 77068c545de0d33607981e7a94a32bf7ed1ff34c..de2b6333e7ea548f54330031bbe776164668d1f8 100644 (file)
@@ -1743,19 +1743,21 @@ EXPORT_SYMBOL(genphy_update_link);
  */
 int genphy_read_status(struct phy_device *phydev)
 {
-       int adv;
-       int err;
-       int lpa;
-       int lpagb = 0;
+       int adv, lpa, lpagb, err;
 
        /* Update the link, but return if there was an error */
        err = genphy_update_link(phydev);
        if (err)
                return err;
 
+       phydev->speed = SPEED_UNKNOWN;
+       phydev->duplex = DUPLEX_UNKNOWN;
+       phydev->pause = 0;
+       phydev->asym_pause = 0;
+
        linkmode_zero(phydev->lp_advertising);
 
-       if (AUTONEG_ENABLE == phydev->autoneg) {
+       if (phydev->autoneg == AUTONEG_ENABLE && phydev->link) {
                if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
                                      phydev->supported) ||
                    linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
@@ -1785,14 +1787,8 @@ int genphy_read_status(struct phy_device *phydev)
                        return lpa;
 
                mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa);
-
-               phydev->speed = SPEED_UNKNOWN;
-               phydev->duplex = DUPLEX_UNKNOWN;
-               phydev->pause = 0;
-               phydev->asym_pause = 0;
-
                phy_resolve_aneg_linkmode(phydev);
-       } else {
+       } else if (phydev->autoneg == AUTONEG_DISABLE) {
                int bmcr = phy_read(phydev, MII_BMCR);
 
                if (bmcr < 0)
@@ -1809,9 +1805,6 @@ int genphy_read_status(struct phy_device *phydev)
                        phydev->speed = SPEED_100;
                else
                        phydev->speed = SPEED_10;
-
-               phydev->pause = 0;
-               phydev->asym_pause = 0;
        }
 
        return 0;