Skip to content

Commit 0a2f7de

Browse files
minimaxwelldavem330
authored andcommitted
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: Maxime Chevallier <maxime.chevallier@bootlin.com> Suggested-by: "Russell King (Oracle)" <linux@armlinux.org.uk> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b2db6f4 commit 0a2f7de

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

drivers/net/phy/sfp-bus.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,28 @@ void sfp_bus_del_upstream(struct sfp_bus *bus)
722722
}
723723
EXPORT_SYMBOL_GPL(sfp_bus_del_upstream);
724724

725+
/**
726+
* sfp_get_name() - Get the SFP device name
727+
* @bus: a pointer to the &struct sfp_bus structure for the sfp module
728+
*
729+
* Gets the SFP device's name, if @bus has a registered socket. Callers must
730+
* hold RTNL, and the returned name is only valid until RTNL is released.
731+
*
732+
* Returns:
733+
* - The name of the SFP device registered with sfp_register_socket()
734+
* - %NULL if no device was registered on @bus
735+
*/
736+
const char *sfp_get_name(struct sfp_bus *bus)
737+
{
738+
ASSERT_RTNL();
739+
740+
if (bus->sfp_dev)
741+
return dev_name(bus->sfp_dev);
742+
743+
return NULL;
744+
}
745+
EXPORT_SYMBOL_GPL(sfp_get_name);
746+
725747
/* Socket driver entry points */
726748
int sfp_add_phy(struct sfp_bus *bus, struct phy_device *phydev)
727749
{

include/linux/sfp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ struct sfp_bus *sfp_bus_find_fwnode(const struct fwnode_handle *fwnode);
576576
int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
577577
const struct sfp_upstream_ops *ops);
578578
void sfp_bus_del_upstream(struct sfp_bus *bus);
579+
const char *sfp_get_name(struct sfp_bus *bus);
579580
#else
580581
static inline int sfp_parse_port(struct sfp_bus *bus,
581582
const struct sfp_eeprom_id *id,
@@ -654,6 +655,11 @@ static inline int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
654655
static inline void sfp_bus_del_upstream(struct sfp_bus *bus)
655656
{
656657
}
658+
659+
static inline const char *sfp_get_name(struct sfp_bus *bus)
660+
{
661+
return NULL;
662+
}
657663
#endif
658664

659665
#endif

0 commit comments

Comments
 (0)