Commit 0a2f7de0 authored by Maxime Chevallier's avatar Maxime Chevallier Committed by David S. Miller

net: sfp: Add helper to return the SFP bus name

Knowing the bus name is helpful when we want to expose the link topology
to userspace, add a helper to return the SFP bus name.

This call will always be made while holding the RTNL which ensures
that the SFP driver won't unbind from the device. The returned pointer
to the bus name will only be used while RTNL is held.
Signed-off-by: default avatarMaxime Chevallier <maxime.chevallier@bootlin.com>
Suggested-by: default avatar"Russell King (Oracle)" <linux@armlinux.org.uk>
Reviewed-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Tested-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b2db6f4a
......@@ -722,6 +722,28 @@ void sfp_bus_del_upstream(struct sfp_bus *bus)
}
EXPORT_SYMBOL_GPL(sfp_bus_del_upstream);
/**
* sfp_get_name() - Get the SFP device name
* @bus: a pointer to the &struct sfp_bus structure for the sfp module
*
* Gets the SFP device's name, if @bus has a registered socket. Callers must
* hold RTNL, and the returned name is only valid until RTNL is released.
*
* Returns:
* - The name of the SFP device registered with sfp_register_socket()
* - %NULL if no device was registered on @bus
*/
const char *sfp_get_name(struct sfp_bus *bus)
{
ASSERT_RTNL();
if (bus->sfp_dev)
return dev_name(bus->sfp_dev);
return NULL;
}
EXPORT_SYMBOL_GPL(sfp_get_name);
/* Socket driver entry points */
int sfp_add_phy(struct sfp_bus *bus, struct phy_device *phydev)
{
......
......@@ -576,6 +576,7 @@ struct sfp_bus *sfp_bus_find_fwnode(const struct fwnode_handle *fwnode);
int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
const struct sfp_upstream_ops *ops);
void sfp_bus_del_upstream(struct sfp_bus *bus);
const char *sfp_get_name(struct sfp_bus *bus);
#else
static inline int sfp_parse_port(struct sfp_bus *bus,
const struct sfp_eeprom_id *id,
......@@ -654,6 +655,11 @@ static inline int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
static inline void sfp_bus_del_upstream(struct sfp_bus *bus)
{
}
static inline const char *sfp_get_name(struct sfp_bus *bus)
{
return NULL;
}
#endif
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment