diff mbox series

[net-next,v15,04/14] net: sfp: Add helper to return the SFP bus name

Message ID 20240703140806.271938-5-maxime.chevallier@bootlin.com (mailing list archive)
State New
Headers show
Series Introduce PHY listing and link_topology tracking | expand

Commit Message

Maxime Chevallier July 3, 2024, 2:07 p.m. UTC
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>
---
 drivers/net/phy/sfp-bus.c | 11 +++++++++++
 include/linux/sfp.h       |  6 ++++++
 2 files changed, 17 insertions(+)

Comments

Russell King (Oracle) July 3, 2024, 3:36 p.m. UTC | #1
On Wed, Jul 03, 2024 at 04:07:54PM +0200, Maxime Chevallier wrote:
> 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.

I think it's worth mentioning about the use case in this patch as well,
something like:

"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>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  drivers/net/phy/sfp-bus.c | 11 +++++++++++
>  include/linux/sfp.h       |  6 ++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c
> index 56953e66bb7b..37c85f1e6534 100644
> --- a/drivers/net/phy/sfp-bus.c
> +++ b/drivers/net/phy/sfp-bus.c
> @@ -860,3 +860,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);

Please move this to just below sfp_bus_del_upstream() since the
functions in this file are organised as:

- internal functions
- upstream callable functions
- downstream (sfp driver) callable functions.

Note also that the upstream callable functions are all documented with
kerneldoc, and sfp_get_name() is clearly a function called from the
upstream side.

Thanks.
Maxime Chevallier July 4, 2024, 8:04 a.m. UTC | #2
Hello Russell,

On Wed, 3 Jul 2024 16:36:20 +0100
"Russell King (Oracle)" <linux@armlinux.org.uk> wrote:

> On Wed, Jul 03, 2024 at 04:07:54PM +0200, Maxime Chevallier wrote:
> > 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.  
> 
> I think it's worth mentioning about the use case in this patch as well,
> something like:
> 
> "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."

I'll add that in both the commit log and the documentation for the
function.

[...]

> > +EXPORT_SYMBOL_GPL(sfp_get_name);  
> 
> Please move this to just below sfp_bus_del_upstream() since the
> functions in this file are organised as:
> 
> - internal functions
> - upstream callable functions
> - downstream (sfp driver) callable functions.
> 
> Note also that the upstream callable functions are all documented with
> kerneldoc, and sfp_get_name() is clearly a function called from the
> upstream side.

No problem, I'll move it and a some proper documentation. Thanks for
the review,

Maxime
diff mbox series

Patch

diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c
index 56953e66bb7b..37c85f1e6534 100644
--- a/drivers/net/phy/sfp-bus.c
+++ b/drivers/net/phy/sfp-bus.c
@@ -860,3 +860,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);
diff --git a/include/linux/sfp.h b/include/linux/sfp.h
index 54abb4d22b2e..60c65cea74f6 100644
--- a/include/linux/sfp.h
+++ b/include/linux/sfp.h
@@ -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