From patchwork Wed Aug 21 15:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13771762 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6315BC52D7C for ; Wed, 21 Aug 2024 15:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=a4c4LMsYPd0A88DC/zA07JsUCh3J3Fqr2URAkxJM2YA=; b=zEkKEKI4Z29EZCaz6urrfnE5vc WKAL2bJ2R9L2+8mYI8lcgkGr3VDHvAhI7PxNS3kAB+ddXqKduxWm+VEiEWmVJbd3sDlKhMZ435ZK/ NGzUvZ/o2zrIdZHpnwBSAumk6iiDtNPrkPiwRcOY/kLALRPsMxSCf8BA6xSllfcTKSgr3saHJw5v2 MHT+2KXX2iy1SaE3KuJ5Lh8ezJskNY4aP3V7AfEa/0apOGTL/2vEJGYG3dlvHtAMqpVM3dbO2Hk5M edraZFQiUjQpzoL4u9X9SsD0oJcT9ZQ/CsBG7fA3KrhPtPFUAlCaAtVEq5sZjAms+2PGrwAprvVtM GmK6ZfwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgn1P-00000009RyY-1MmI; Wed, 21 Aug 2024 15:13:15 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgmyh-00000009RCK-29ze for linux-arm-kernel@bombadil.infradead.org; Wed, 21 Aug 2024 15:10:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=a4c4LMsYPd0A88DC/zA07JsUCh3J3Fqr2URAkxJM2YA=; b=p5qf9wQsS2TMBOCVGDVlpf1RpF jKGd5gDxEv8NCc4Ja72/KTQwlqvuNFshV5kEdJUAl6yR/9ureRrqVvw9Xx26HaVXWEpwsSlhSXWpJ BK8vf4aecJNwQd4UszraGB7jc0Hl7ss7PGHeSQUcq9Q+mmkfGlV9bZ1oG+re9c8cXvcnNqtjxhHsG TctoRI7qAROOlSKdGBf10A/hPnaSa18G3d/upAlO8TH+Wt6VagMKy5Pln1eY752aq3KT8rDP7T6Ki eB0c8dFrfXIapVaclI7VmLEFvJNx5pZAq3imzvRTxXAe8pH03Y/sx43NAvOdwbvCbgIYF1niuNRtH sYYs3HFQ==; Received: from relay2-d.mail.gandi.net ([217.70.183.194]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgmye-00000009dnL-0TdJ for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 15:10:26 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 7C5F740011; Wed, 21 Aug 2024 15:10:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1724253021; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a4c4LMsYPd0A88DC/zA07JsUCh3J3Fqr2URAkxJM2YA=; b=dE7kbZjy0ldlWHzDG7E4Ktz0wvNgL0rC4913TJXa6lc1N7hTTdzbE+gR+C6/0pE64VJOXK 1N4CxP/dh7zlolYSj4xDb+/OCScoHBy8RmvHyr4GKdbWJbbwNwVLPSVTEg8qEBlKWCHOxj nsHYL4wqqFKYA0018U27XHr5zxmDPTbPRLHF0M9wEIB6QsUCFCQLW0lhkLXsZSpW83tLuF PN4D9R+iKx1GWIUtspCfedVoX0Up5qw4WvjFU21hVKGs4vaUgsXHX6emAP2216ooN3TEnh NjubhmIoxFu4U9wjuSdS4H3/KYya0nz1JNYcBPzPTX3yVCoav5JTzGyOaVAu/A== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?K=C3=B6ry_Maincent?= , Jesse Brandeburg , =?utf-8?q?Marek_Beh=C3=BAn?= , Piergiorgio Beruto , Oleksij Rempel , =?utf-8?q?Nicol=C3=B2_Veronese?= , Simon Horman , mwojtas@chromium.org, Nathan Chancellor , Antoine Tenart , Marc Kleine-Budde , Dan Carpenter , Romain Gantois Subject: [PATCH net-next v18 04/13] net: sfp: Add helper to return the SFP bus name Date: Wed, 21 Aug 2024 17:09:58 +0200 Message-ID: <20240821151009.1681151-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240821151009.1681151-1-maxime.chevallier@bootlin.com> References: <20240821151009.1681151-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_161024_351917_6F83A665 X-CRM114-Status: GOOD ( 13.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Suggested-by: "Russell King (Oracle)" Reviewed-by: Christophe Leroy Tested-by: Christophe Leroy --- 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