sfp/phylink: move module EEPROM ethtool access into netdev core ethtool
authorRussell King <rmk+kernel@armlinux.org.uk>
Wed, 28 Mar 2018 22:44:16 +0000 (15:44 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 30 Mar 2018 14:11:06 +0000 (10:11 -0400)
Provide a pointer to the SFP bus in struct net_device, so that the
ethtool module EEPROM methods can access the SFP directly, rather
than needing every user to provide a hook for it.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/marvell/mvneta.c
drivers/net/phy/phylink.c
drivers/net/phy/sfp-bus.c
include/linux/netdevice.h
include/linux/phylink.h
net/core/ethtool.c

index cd09bde55596e710a9d8cbfaa591679624aa5cdb..25ced96750bf1f5aa7e9ac94b0bf71f071094d26 100644 (file)
@@ -4075,22 +4075,6 @@ static int mvneta_ethtool_set_wol(struct net_device *dev,
        return ret;
 }
 
-static int mvneta_ethtool_get_module_info(struct net_device *dev,
-                                         struct ethtool_modinfo *modinfo)
-{
-       struct mvneta_port *pp = netdev_priv(dev);
-
-       return phylink_ethtool_get_module_info(pp->phylink, modinfo);
-}
-
-static int mvneta_ethtool_get_module_eeprom(struct net_device *dev,
-                                           struct ethtool_eeprom *ee, u8 *buf)
-{
-       struct mvneta_port *pp = netdev_priv(dev);
-
-       return phylink_ethtool_get_module_eeprom(pp->phylink, ee, buf);
-}
-
 static int mvneta_ethtool_get_eee(struct net_device *dev,
                                  struct ethtool_eee *eee)
 {
@@ -4165,8 +4149,6 @@ static const struct ethtool_ops mvneta_eth_tool_ops = {
        .set_link_ksettings = mvneta_ethtool_set_link_ksettings,
        .get_wol        = mvneta_ethtool_get_wol,
        .set_wol        = mvneta_ethtool_set_wol,
-       .get_module_info = mvneta_ethtool_get_module_info,
-       .get_module_eeprom = mvneta_ethtool_get_module_eeprom,
        .get_eee        = mvneta_ethtool_get_eee,
        .set_eee        = mvneta_ethtool_set_eee,
 };
index 9b1e4721ea3a40e1e98afa0730077e8b31417dd2..c582b2d7546c3359e858e826ddac2dab68b481c7 100644 (file)
@@ -1250,34 +1250,6 @@ int phylink_ethtool_set_pauseparam(struct phylink *pl,
 }
 EXPORT_SYMBOL_GPL(phylink_ethtool_set_pauseparam);
 
-int phylink_ethtool_get_module_info(struct phylink *pl,
-                                   struct ethtool_modinfo *modinfo)
-{
-       int ret = -EOPNOTSUPP;
-
-       WARN_ON(!lockdep_rtnl_is_held());
-
-       if (pl->sfp_bus)
-               ret = sfp_get_module_info(pl->sfp_bus, modinfo);
-
-       return ret;
-}
-EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_info);
-
-int phylink_ethtool_get_module_eeprom(struct phylink *pl,
-                                     struct ethtool_eeprom *ee, u8 *buf)
-{
-       int ret = -EOPNOTSUPP;
-
-       WARN_ON(!lockdep_rtnl_is_held());
-
-       if (pl->sfp_bus)
-               ret = sfp_get_module_eeprom(pl->sfp_bus, ee, buf);
-
-       return ret;
-}
-EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_eeprom);
-
 /**
  * phylink_ethtool_get_eee_err() - read the energy efficient ethernet error
  *   counter
index 3d4ff5d0d2a6db9822ddfbebb26fc43a328fba1d..0381da78d228dc2fe7f87fabb8260cc257a3fc66 100644 (file)
@@ -342,6 +342,7 @@ static int sfp_register_bus(struct sfp_bus *bus)
        }
        if (bus->started)
                bus->socket_ops->start(bus->sfp);
+       bus->netdev->sfp_bus = bus;
        bus->registered = true;
        return 0;
 }
@@ -356,6 +357,7 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
                if (bus->phydev && ops && ops->disconnect_phy)
                        ops->disconnect_phy(bus->upstream);
        }
+       bus->netdev->sfp_bus = NULL;
        bus->registered = false;
 }
 
@@ -371,8 +373,6 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
  */
 int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
 {
-       if (!bus->registered)
-               return -ENOIOCTLCMD;
        return bus->socket_ops->module_info(bus->sfp, modinfo);
 }
 EXPORT_SYMBOL_GPL(sfp_get_module_info);
@@ -391,8 +391,6 @@ EXPORT_SYMBOL_GPL(sfp_get_module_info);
 int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
                          u8 *data)
 {
-       if (!bus->registered)
-               return -ENOIOCTLCMD;
        return bus->socket_ops->module_eeprom(bus->sfp, ee, data);
 }
 EXPORT_SYMBOL_GPL(sfp_get_module_eeprom);
index da44dab492e36ff322db0c1f96d7e4eeec9e27e8..cf44503ea81ab925496e45dbf123a9da813fca0e 100644 (file)
@@ -58,6 +58,7 @@ struct device;
 struct phy_device;
 struct dsa_port;
 
+struct sfp_bus;
 /* 802.11 specific */
 struct wireless_dev;
 /* 802.15.4 specific */
@@ -1662,6 +1663,7 @@ enum netdev_priv_flags {
  *     @priomap:       XXX: need comments on this one
  *     @phydev:        Physical device may attach itself
  *                     for hardware timestamping
+ *     @sfp_bus:       attached &struct sfp_bus structure.
  *
  *     @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock
  *     @qdisc_running_key: lockdep class annotating Qdisc->running seqcount
@@ -1945,6 +1947,7 @@ struct net_device {
        struct netprio_map __rcu *priomap;
 #endif
        struct phy_device       *phydev;
+       struct sfp_bus          *sfp_bus;
        struct lock_class_key   *qdisc_tx_busylock;
        struct lock_class_key   *qdisc_running_key;
        bool                    proto_down;
index e95cc12030fa1b92caa1fb9687855e2c2cb346ba..50eeae025f1e1c0b56f9296d5cd8ffca9851cf74 100644 (file)
@@ -219,9 +219,6 @@ void phylink_ethtool_get_pauseparam(struct phylink *,
                                    struct ethtool_pauseparam *);
 int phylink_ethtool_set_pauseparam(struct phylink *,
                                   struct ethtool_pauseparam *);
-int phylink_ethtool_get_module_info(struct phylink *, struct ethtool_modinfo *);
-int phylink_ethtool_get_module_eeprom(struct phylink *,
-                                     struct ethtool_eeprom *, u8 *);
 int phylink_get_eee_err(struct phylink *);
 int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
 int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
index bb6e498c6e3d55493fb74700eae429050b4c54f8..eb55252ca1fbbf873b974575b33708078ae26230 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/bitops.h>
 #include <linux/uaccess.h>
 #include <linux/vmalloc.h>
+#include <linux/sfp.h>
 #include <linux/slab.h>
 #include <linux/rtnetlink.h>
 #include <linux/sched/signal.h>
@@ -2245,6 +2246,9 @@ static int __ethtool_get_module_info(struct net_device *dev,
        const struct ethtool_ops *ops = dev->ethtool_ops;
        struct phy_device *phydev = dev->phydev;
 
+       if (dev->sfp_bus)
+               return sfp_get_module_info(dev->sfp_bus, modinfo);
+
        if (phydev && phydev->drv && phydev->drv->module_info)
                return phydev->drv->module_info(phydev, modinfo);
 
@@ -2279,6 +2283,9 @@ static int __ethtool_get_module_eeprom(struct net_device *dev,
        const struct ethtool_ops *ops = dev->ethtool_ops;
        struct phy_device *phydev = dev->phydev;
 
+       if (dev->sfp_bus)
+               return sfp_get_module_eeprom(dev->sfp_bus, ee, data);
+
        if (phydev && phydev->drv && phydev->drv->module_eeprom)
                return phydev->drv->module_eeprom(phydev, ee, data);