]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: phy: Add helper to convert MII ADV register to a linkmode
authorAndrew Lunn <andrew@lunn.ch>
Sat, 29 Sep 2018 21:04:12 +0000 (23:04 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 2 Oct 2018 05:55:36 +0000 (22:55 -0700)
The phy_mii_ioctl can be used to write a value into the MII_ADVERTISE
register in the PHY. Since this changes the state of the PHY, we need
to make the same change to phydev->advertising. Add a helper which can
convert the register value to a linkmode.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/mii.h

index 567047ef0309f45e279f07a26ae48897ae90ff17..8c7da9473ad98f462144b9f353acc24247bf5257 100644 (file)
@@ -303,6 +303,37 @@ static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa)
        return result | mii_adv_to_ethtool_adv_x(lpa);
 }
 
+/**
+ * mii_adv_to_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.
+ */
+static inline void mii_adv_to_linkmode_adv_t(unsigned long *advertising,
+                                            u32 adv)
+{
+       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_advertise_flowctrl - get flow control advertisement flags
  * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both)