net: mii: Add mii_lpa_mod_linkmode_lpa_t
authorAndrew Lunn <andrew@lunn.ch>
Wed, 5 Dec 2018 20:49:43 +0000 (21:49 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 6 Dec 2018 00:26:16 +0000 (16:26 -0800)
Add a _mod_ variant of mii_lpa_to_linkmode_lpa_t. Use this to fix the
genphy_read_status() where the 1G link partner features are getting
lost.

Fixes: c0ec3c273677 ("net: phy: Convert u32 phydev->lp_advertising to linkmode")
Reported-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/phy_device.c
include/linux/mii.h

index c20b5ec..7d5d698 100644 (file)
@@ -1748,7 +1748,7 @@ int genphy_read_status(struct phy_device *phydev)
                if (lpa < 0)
                        return lpa;
 
-               mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, lpa);
+               mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa);
 
                adv = phy_read(phydev, MII_ADVERTISE);
                if (adv < 0)
index b915ef6..e724477 100644 (file)
@@ -373,6 +373,36 @@ static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa)
 }
 
 /**
+ * mii_adv_mod_linkmode_adv_t
+ * @advertising:pointer to destination link mode.
+ * @adv: value of the MII_ADVERTISE register
+ *
+ * A small helper function that translates MII_ADVERTISE bits to
+ * linkmode advertisement settings. Leaves other bits unchanged.
+ */
+static inline void mii_adv_mod_linkmode_adv_t(unsigned long *advertising,
+                                             u32 adv)
+{
+       linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT,
+                        advertising, adv & ADVERTISE_10HALF);
+
+       linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT,
+                        advertising, adv & ADVERTISE_10FULL);
+
+       linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT,
+                        advertising, adv & ADVERTISE_100HALF);
+
+       linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
+                        advertising, adv & ADVERTISE_100FULL);
+
+       linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising,
+                        adv & ADVERTISE_PAUSE_CAP);
+
+       linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+                        advertising, adv & ADVERTISE_PAUSE_ASYM);
+}
+
+/**
  * mii_adv_to_linkmode_adv_t
  * @advertising:pointer to destination link mode.
  * @adv: value of the MII_ADVERTISE register
@@ -386,22 +416,7 @@ static inline void mii_adv_to_linkmode_adv_t(unsigned long *advertising,
 {
        linkmode_zero(advertising);
 
-       if (adv & ADVERTISE_10HALF)
-               linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT,
-                                advertising);
-       if (adv & ADVERTISE_10FULL)
-               linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT,
-                                advertising);
-       if (adv & ADVERTISE_100HALF)
-               linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT,
-                                advertising);
-       if (adv & ADVERTISE_100FULL)
-               linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
-                                advertising);
-       if (adv & ADVERTISE_PAUSE_CAP)
-               linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising);
-       if (adv & ADVERTISE_PAUSE_ASYM)
-               linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising);
+       mii_adv_mod_linkmode_adv_t(advertising, adv);
 }
 
 /**
@@ -424,6 +439,27 @@ static inline void mii_lpa_to_linkmode_lpa_t(unsigned long *lp_advertising,
 }
 
 /**
+ * mii_lpa_mod_linkmode_lpa_t
+ * @adv: value of the MII_LPA register
+ *
+ * A small helper function that translates MII_LPA bits, when in
+ * 1000Base-T mode, to linkmode LP advertisement settings. Leaves
+ * other bits unchanged.
+ */
+static inline void mii_lpa_mod_linkmode_lpa_t(unsigned long *lp_advertising,
+                                             u32 lpa)
+{
+       mii_adv_mod_linkmode_adv_t(lp_advertising, lpa);
+
+       if (lpa & LPA_LPACK)
+               linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+                                lp_advertising);
+       else
+               linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+                                  lp_advertising);
+}
+
+/**
  * linkmode_adv_to_lcl_adv_t
  * @advertising:pointer to linkmode advertising
  *