net: phylink: add phylink_speed_(up|down) interface
authorRussell King <rmk+kernel@armlinux.org.uk>
Wed, 24 Jun 2020 10:06:54 +0000 (11:06 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 25 Jun 2020 20:01:39 +0000 (13:01 -0700)
Add an interface for the phy_speed_(up|down) functions when a driver
makes use of phylink. These pass the call through to phylib when we
have a normal PHY attached (i.o.w., not a PHY on a SFP module.)

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/phylink.c
include/linux/phylink.h

index 7ce787c227b30040aca52c5cda83176b1991f8d7..7cda1646bbf7d30b14ff3230480848607f044ebe 100644 (file)
@@ -1826,6 +1826,54 @@ int phylink_mii_ioctl(struct phylink *pl, struct ifreq *ifr, int cmd)
 }
 EXPORT_SYMBOL_GPL(phylink_mii_ioctl);
 
+/**
+ * phylink_speed_down() - set the non-SFP PHY to lowest speed supported by both
+ *   link partners
+ * @pl: a pointer to a &struct phylink returned from phylink_create()
+ * @sync: perform action synchronously
+ *
+ * If we have a PHY that is not part of a SFP module, then set the speed
+ * as described in the phy_speed_down() function. Please see this function
+ * for a description of the @sync parameter.
+ *
+ * Returns zero if there is no PHY, otherwise as per phy_speed_down().
+ */
+int phylink_speed_down(struct phylink *pl, bool sync)
+{
+       int ret = 0;
+
+       ASSERT_RTNL();
+
+       if (!pl->sfp_bus && pl->phydev)
+               ret = phy_speed_down(pl->phydev, sync);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(phylink_speed_down);
+
+/**
+ * phylink_speed_up() - restore the advertised speeds prior to the call to
+ *   phylink_speed_down()
+ * @pl: a pointer to a &struct phylink returned from phylink_create()
+ *
+ * If we have a PHY that is not part of a SFP module, then restore the
+ * PHY speeds as per phy_speed_up().
+ *
+ * Returns zero if there is no PHY, otherwise as per phy_speed_up().
+ */
+int phylink_speed_up(struct phylink *pl)
+{
+       int ret = 0;
+
+       ASSERT_RTNL();
+
+       if (!pl->sfp_bus && pl->phydev)
+               ret = phy_speed_up(pl->phydev);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(phylink_speed_up);
+
 static void phylink_sfp_attach(void *upstream, struct sfp_bus *bus)
 {
        struct phylink *pl = upstream;
index cc5b452a184e530847422761289f082fce50cdc6..b32b8b45421b24312236fc77d30c8fd8455eece8 100644 (file)
@@ -392,6 +392,8 @@ int phylink_init_eee(struct phylink *, bool);
 int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
 int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
+int phylink_speed_down(struct phylink *pl, bool sync);
+int phylink_speed_up(struct phylink *pl);
 
 #define phylink_zero(bm) \
        bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)