[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5dfbc90d-8af7-4f41-aa5e-eb43e6dcc7b4@cs-soprasteria.com>
Date: Wed, 14 Aug 2024 14:29:52 +0000
From: LEROY Christophe <christophe.leroy2@...soprasteria.com>
To: Maxime Chevallier <maxime.chevallier@...tlin.com>, "davem@...emloft.net"
<davem@...emloft.net>
CC: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"thomas.petazzoni@...tlin.com" <thomas.petazzoni@...tlin.com>, Andrew Lunn
<andrew@...n.ch>, Jakub Kicinski <kuba@...nel.org>, Eric Dumazet
<edumazet@...gle.com>, Paolo Abeni <pabeni@...hat.com>, Russell King
<linux@...linux.org.uk>, "linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>, Herve Codina
<herve.codina@...tlin.com>, Florian Fainelli <f.fainelli@...il.com>, Heiner
Kallweit <hkallweit1@...il.com>, Vladimir Oltean <vladimir.oltean@....com>,
Köry Maincent <kory.maincent@...tlin.com>, Jesse
Brandeburg <jesse.brandeburg@...el.com>, Marek Behún
<kabel@...nel.org>, Piergiorgio Beruto <piergiorgio.beruto@...il.com>,
Oleksij Rempel <o.rempel@...gutronix.de>,
Nicolò Veronese <nicveronese@...il.com>, Simon Horman
<horms@...nel.org>, "mwojtas@...omium.org" <mwojtas@...omium.org>, Nathan
Chancellor <nathan@...nel.org>, Antoine Tenart <atenart@...nel.org>, Marc
Kleine-Budde <mkl@...gutronix.de>, Dan Carpenter <dan.carpenter@...aro.org>,
Romain Gantois <romain.gantois@...tlin.com>
Subject: Re: [PATCH net-next v17 04/14] net: sfp: Add helper to return the SFP
bus name
Le 09/07/2024 à 08:30, Maxime Chevallier a écrit :
> 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@...tlin.com>
> Suggested-by: "Russell King (Oracle)" <linux@...linux.org.uk>
Reviewed-by: Christophe Leroy <christophe.leroy@...roup.eu>
Tested-by: Christophe Leroy <christophe.leroy@...roup.eu>
> ---
> drivers/net/phy/sfp-bus.c | 22 ++++++++++++++++++++++
> include/linux/sfp.h | 6 ++++++
> 2 files changed, 28 insertions(+)
>
> diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c
> index 56953e66bb7b..f13c00b5b449 100644
> --- a/drivers/net/phy/sfp-bus.c
> +++ b/drivers/net/phy/sfp-bus.c
> @@ -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)
> {
> 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
Powered by blists - more mailing lists