Skip to content

Commit e679c9c

Browse files
Russell Kingdavem330
authored andcommitted
sfp/phylink: move module EEPROM ethtool access into netdev core ethtool
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 <[email protected]> Signed-off-by: Russell King <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: Russell King <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c6ab300 commit e679c9c

File tree

6 files changed

+12
-53
lines changed

6 files changed

+12
-53
lines changed

drivers/net/ethernet/marvell/mvneta.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4075,22 +4075,6 @@ static int mvneta_ethtool_set_wol(struct net_device *dev,
40754075
return ret;
40764076
}
40774077

4078-
static int mvneta_ethtool_get_module_info(struct net_device *dev,
4079-
struct ethtool_modinfo *modinfo)
4080-
{
4081-
struct mvneta_port *pp = netdev_priv(dev);
4082-
4083-
return phylink_ethtool_get_module_info(pp->phylink, modinfo);
4084-
}
4085-
4086-
static int mvneta_ethtool_get_module_eeprom(struct net_device *dev,
4087-
struct ethtool_eeprom *ee, u8 *buf)
4088-
{
4089-
struct mvneta_port *pp = netdev_priv(dev);
4090-
4091-
return phylink_ethtool_get_module_eeprom(pp->phylink, ee, buf);
4092-
}
4093-
40944078
static int mvneta_ethtool_get_eee(struct net_device *dev,
40954079
struct ethtool_eee *eee)
40964080
{
@@ -4165,8 +4149,6 @@ static const struct ethtool_ops mvneta_eth_tool_ops = {
41654149
.set_link_ksettings = mvneta_ethtool_set_link_ksettings,
41664150
.get_wol = mvneta_ethtool_get_wol,
41674151
.set_wol = mvneta_ethtool_set_wol,
4168-
.get_module_info = mvneta_ethtool_get_module_info,
4169-
.get_module_eeprom = mvneta_ethtool_get_module_eeprom,
41704152
.get_eee = mvneta_ethtool_get_eee,
41714153
.set_eee = mvneta_ethtool_set_eee,
41724154
};

drivers/net/phy/phylink.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,34 +1250,6 @@ int phylink_ethtool_set_pauseparam(struct phylink *pl,
12501250
}
12511251
EXPORT_SYMBOL_GPL(phylink_ethtool_set_pauseparam);
12521252

1253-
int phylink_ethtool_get_module_info(struct phylink *pl,
1254-
struct ethtool_modinfo *modinfo)
1255-
{
1256-
int ret = -EOPNOTSUPP;
1257-
1258-
WARN_ON(!lockdep_rtnl_is_held());
1259-
1260-
if (pl->sfp_bus)
1261-
ret = sfp_get_module_info(pl->sfp_bus, modinfo);
1262-
1263-
return ret;
1264-
}
1265-
EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_info);
1266-
1267-
int phylink_ethtool_get_module_eeprom(struct phylink *pl,
1268-
struct ethtool_eeprom *ee, u8 *buf)
1269-
{
1270-
int ret = -EOPNOTSUPP;
1271-
1272-
WARN_ON(!lockdep_rtnl_is_held());
1273-
1274-
if (pl->sfp_bus)
1275-
ret = sfp_get_module_eeprom(pl->sfp_bus, ee, buf);
1276-
1277-
return ret;
1278-
}
1279-
EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_eeprom);
1280-
12811253
/**
12821254
* phylink_ethtool_get_eee_err() - read the energy efficient ethernet error
12831255
* counter

drivers/net/phy/sfp-bus.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ static int sfp_register_bus(struct sfp_bus *bus)
342342
}
343343
if (bus->started)
344344
bus->socket_ops->start(bus->sfp);
345+
bus->netdev->sfp_bus = bus;
345346
bus->registered = true;
346347
return 0;
347348
}
@@ -356,6 +357,7 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
356357
if (bus->phydev && ops && ops->disconnect_phy)
357358
ops->disconnect_phy(bus->upstream);
358359
}
360+
bus->netdev->sfp_bus = NULL;
359361
bus->registered = false;
360362
}
361363

@@ -371,8 +373,6 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
371373
*/
372374
int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
373375
{
374-
if (!bus->registered)
375-
return -ENOIOCTLCMD;
376376
return bus->socket_ops->module_info(bus->sfp, modinfo);
377377
}
378378
EXPORT_SYMBOL_GPL(sfp_get_module_info);
@@ -391,8 +391,6 @@ EXPORT_SYMBOL_GPL(sfp_get_module_info);
391391
int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
392392
u8 *data)
393393
{
394-
if (!bus->registered)
395-
return -ENOIOCTLCMD;
396394
return bus->socket_ops->module_eeprom(bus->sfp, ee, data);
397395
}
398396
EXPORT_SYMBOL_GPL(sfp_get_module_eeprom);

include/linux/netdevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct device;
5858
struct phy_device;
5959
struct dsa_port;
6060

61+
struct sfp_bus;
6162
/* 802.11 specific */
6263
struct wireless_dev;
6364
/* 802.15.4 specific */
@@ -1662,6 +1663,7 @@ enum netdev_priv_flags {
16621663
* @priomap: XXX: need comments on this one
16631664
* @phydev: Physical device may attach itself
16641665
* for hardware timestamping
1666+
* @sfp_bus: attached &struct sfp_bus structure.
16651667
*
16661668
* @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock
16671669
* @qdisc_running_key: lockdep class annotating Qdisc->running seqcount
@@ -1945,6 +1947,7 @@ struct net_device {
19451947
struct netprio_map __rcu *priomap;
19461948
#endif
19471949
struct phy_device *phydev;
1950+
struct sfp_bus *sfp_bus;
19481951
struct lock_class_key *qdisc_tx_busylock;
19491952
struct lock_class_key *qdisc_running_key;
19501953
bool proto_down;

include/linux/phylink.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,6 @@ void phylink_ethtool_get_pauseparam(struct phylink *,
219219
struct ethtool_pauseparam *);
220220
int phylink_ethtool_set_pauseparam(struct phylink *,
221221
struct ethtool_pauseparam *);
222-
int phylink_ethtool_get_module_info(struct phylink *, struct ethtool_modinfo *);
223-
int phylink_ethtool_get_module_eeprom(struct phylink *,
224-
struct ethtool_eeprom *, u8 *);
225222
int phylink_get_eee_err(struct phylink *);
226223
int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
227224
int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);

net/core/ethtool.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/bitops.h>
2323
#include <linux/uaccess.h>
2424
#include <linux/vmalloc.h>
25+
#include <linux/sfp.h>
2526
#include <linux/slab.h>
2627
#include <linux/rtnetlink.h>
2728
#include <linux/sched/signal.h>
@@ -2245,6 +2246,9 @@ static int __ethtool_get_module_info(struct net_device *dev,
22452246
const struct ethtool_ops *ops = dev->ethtool_ops;
22462247
struct phy_device *phydev = dev->phydev;
22472248

2249+
if (dev->sfp_bus)
2250+
return sfp_get_module_info(dev->sfp_bus, modinfo);
2251+
22482252
if (phydev && phydev->drv && phydev->drv->module_info)
22492253
return phydev->drv->module_info(phydev, modinfo);
22502254

@@ -2279,6 +2283,9 @@ static int __ethtool_get_module_eeprom(struct net_device *dev,
22792283
const struct ethtool_ops *ops = dev->ethtool_ops;
22802284
struct phy_device *phydev = dev->phydev;
22812285

2286+
if (dev->sfp_bus)
2287+
return sfp_get_module_eeprom(dev->sfp_bus, ee, data);
2288+
22822289
if (phydev && phydev->drv && phydev->drv->module_eeprom)
22832290
return phydev->drv->module_eeprom(phydev, ee, data);
22842291

0 commit comments

Comments
 (0)