net: sfp: Add helper to return the SFP bus name
authorMaxime Chevallier <maxime.chevallier@bootlin.com>
Thu, 4 Apr 2024 09:29:54 +0000 (11:29 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 6 Apr 2024 17:25:14 +0000 (18:25 +0100)
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 <maxime.chevallier@bootlin.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/sfp-bus.c
include/linux/sfp.h

index e05013aeecc3d503ff12560337fce46b40a0e0ed..413021619afe8de6b84e7b0587140cc344005821 100644 (file)
@@ -859,3 +859,14 @@ void sfp_unregister_socket(struct sfp_bus *bus)
        sfp_bus_put(bus);
 }
 EXPORT_SYMBOL_GPL(sfp_unregister_socket);
+
+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);
index 0573e53b0c11f842060358bb765e2572e3897479..55c0ab17c9e2e5d190f10ddcbfeb9993a098999c 100644 (file)
@@ -570,6 +570,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,
@@ -648,6 +649,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