Skip to content

Commit fdd3539

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. Signed-off-by: Maxime Chevallier <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e75e4e0 commit fdd3539

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

drivers/net/phy/sfp-bus.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,3 +859,14 @@ void sfp_unregister_socket(struct sfp_bus *bus)
859859
sfp_bus_put(bus);
860860
}
861861
EXPORT_SYMBOL_GPL(sfp_unregister_socket);
862+
863+
const char *sfp_get_name(struct sfp_bus *bus)
864+
{
865+
ASSERT_RTNL();
866+
867+
if (bus->sfp_dev)
868+
return dev_name(bus->sfp_dev);
869+
870+
return NULL;
871+
}
872+
EXPORT_SYMBOL_GPL(sfp_get_name);

include/linux/sfp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ struct sfp_bus *sfp_bus_find_fwnode(const struct fwnode_handle *fwnode);
570570
int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
571571
const struct sfp_upstream_ops *ops);
572572
void sfp_bus_del_upstream(struct sfp_bus *bus);
573+
const char *sfp_get_name(struct sfp_bus *bus);
573574
#else
574575
static inline int sfp_parse_port(struct sfp_bus *bus,
575576
const struct sfp_eeprom_id *id,
@@ -648,6 +649,11 @@ static inline int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
648649
static inline void sfp_bus_del_upstream(struct sfp_bus *bus)
649650
{
650651
}
652+
653+
static inline const char *sfp_get_name(struct sfp_bus *bus)
654+
{
655+
return NULL;
656+
}
651657
#endif
652658

653659
#endif

0 commit comments

Comments
 (0)