Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp320648rdb; Thu, 21 Dec 2023 10:02:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEs6TMgucShIR317+N2opJhEOWlvbqQZUEM5o7hJir8f32V8xPBPYOYvZWPQwbR3x7I+fsS X-Received: by 2002:a17:906:4c50:b0:a23:453d:95d2 with SMTP id d16-20020a1709064c5000b00a23453d95d2mr49461ejw.309.1703181734146; Thu, 21 Dec 2023 10:02:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703181734; cv=none; d=google.com; s=arc-20160816; b=dGtKefUJQ0sf82+zsJaFez2crW8BKjXPFHX1ItOMpbkqbe48NzI4w62+pU5UHGzKop rq3fvycnp+dNYRIo2cu9EWe19lEB4tqnCd3jwOnhTQPFuLOwofUXTBfNPfzsm+ckt5Ud QBzvTp/Bv8IyAXi8XubjB+pYxUCwL7EiEiYh6tfMtfcXo68vBAANSBDeJpv903hwX4H9 vgFRWrNIIvxk4/IAqhxDrYNw97M5ZLwe3NmXxlAnD/8KMX/EfsPHqirKfkFvbVTdt1Xe D+jW5r8Cql6ohlcb89nUgqMLnswU/WnUB/U33I/ZYJJY2liqXOCGpequrW9PsYYC5DID kKZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=y5N5WzUd2S/X/9BffbusO0YmcdoD10S4ae7/rzIWNrc=; fh=d3Krop4IPE3x6nBOvh3GY5QHg6bS91zVnQiH59I3hyM=; b=norR4ZPFuRlHDAvqOhkGdhtrNQciuA3ZJ4s6zhcZlMoZgxin4FoezRiaWj4oNPXjmy WDY2KGOSJi+X8QMaDWOPYKNMql4A64ONp37O5m8JsXbGuVm5y9sh3IC503O7dHv319wl QTMtXjQtXsskjim8bh06neFdao42oeBTrC4L4TRILa+WurTRIP+e3gq+nUdAUqQ+S/Iv F9UY0eotISB4rFIlNBSkgQ94oN5dSp94nXOdpyTt2ozkF/mRZnUEfXmO0GuQfM3twbpu 8WDilrYQP22IkOypwP0ooFPl2lW2iB3oVPX94IRGR9/PJCZfh7SQyrzbNkM0OegLgP0s auVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Io5ZnaGn; spf=pass (google.com: domain of linux-kernel+bounces-8888-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8888-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g14-20020a1709064e4e00b00a2698c867c3si1034303ejw.749.2023.12.21.10.02.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 10:02:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8888-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Io5ZnaGn; spf=pass (google.com: domain of linux-kernel+bounces-8888-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8888-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B0E821F25C94 for ; Thu, 21 Dec 2023 18:02:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01895651B2; Thu, 21 Dec 2023 18:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Io5ZnaGn" X-Original-To: linux-kernel@vger.kernel.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0080863516; Thu, 21 Dec 2023 18:00:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id E7B421C0008; Thu, 21 Dec 2023 18:00:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1703181656; 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=y5N5WzUd2S/X/9BffbusO0YmcdoD10S4ae7/rzIWNrc=; b=Io5ZnaGnjwvgHpKbhe8/bZMhNRMuVE7+Gw3g+tTjXNHPUkAKKfDWF8R+nZryT0z7scDXNy G7+88jZDQwCmiZxBnFvdWMFFtoDmuYAnv54MIWI/sPA5AQxxP+dDgRJpVE1n6ffLNm1Nbp HUqRP2sI1D8f/mEb2SoArdpvYr+oSUj9bHJambckTmq9bDYjGR0iVwugKEdoLN4HdkrD3V LlvmSZ0FV4cRRWTNxVXtEEyBAD0DQPRim88bkyYmYwpVr9k3kjxy5dyeXSDnWuPG+ThZ1k lVEVW4zgDHdcgPl9aC3AfRPiHY651LFM3oJ5DpCppa0AwAjkq4+yE+c0aSLfzA== 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=20Maincent?= , Jesse Brandeburg , Jonathan Corbet , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Piergiorgio Beruto , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman Subject: [PATCH net-next v5 03/13] net: phy: add helpers to handle sfp phy connect/disconnect Date: Thu, 21 Dec 2023 19:00:36 +0100 Message-ID: <20231221180047.1924733-4-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231221180047.1924733-1-maxime.chevallier@bootlin.com> References: <20231221180047.1924733-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: maxime.chevallier@bootlin.com There are a few PHY drivers that can handle SFP modules through their sfp_upstream_ops. Introduce Phylib helpers to keep track of connected SFP PHYs in a netdevice's namespace, by adding the SFP PHY to the upstream PHY's netdev's namespace. By doing so, these SFP PHYs can be enumerated and exposed to users, which will be able to use their capabilities. Signed-off-by: Maxime Chevallier --- V5: No Changes V4: Rebased the at803x part with the newer version on net-next V3: Renaming V2: Renaming drivers/net/phy/at803x.c | 2 ++ drivers/net/phy/marvell-88x2222.c | 2 ++ drivers/net/phy/marvell.c | 2 ++ drivers/net/phy/marvell10g.c | 2 ++ drivers/net/phy/phy_device.c | 40 +++++++++++++++++++++++++++++++ include/linux/phy.h | 2 ++ 6 files changed, 50 insertions(+) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index d5dc927618ab..1a62f868ec40 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -1452,6 +1452,8 @@ static const struct sfp_upstream_ops at8031_sfp_ops = { .attach = phy_sfp_attach, .detach = phy_sfp_detach, .module_insert = at8031_sfp_insert, + .connect_phy = phy_sfp_connect_phy, + .disconnect_phy = phy_sfp_disconnect_phy, }; static int at8031_parse_dt(struct phy_device *phydev) diff --git a/drivers/net/phy/marvell-88x2222.c b/drivers/net/phy/marvell-88x2222.c index e3aa30dad2e6..3f77bbc7e04f 100644 --- a/drivers/net/phy/marvell-88x2222.c +++ b/drivers/net/phy/marvell-88x2222.c @@ -555,6 +555,8 @@ static const struct sfp_upstream_ops sfp_phy_ops = { .link_down = mv2222_sfp_link_down, .attach = phy_sfp_attach, .detach = phy_sfp_detach, + .connect_phy = phy_sfp_connect_phy, + .disconnect_phy = phy_sfp_disconnect_phy, }; static int mv2222_probe(struct phy_device *phydev) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index eba652a4c1d8..674e29bce2cc 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -3254,6 +3254,8 @@ static const struct sfp_upstream_ops m88e1510_sfp_ops = { .module_remove = m88e1510_sfp_remove, .attach = phy_sfp_attach, .detach = phy_sfp_detach, + .connect_phy = phy_sfp_connect_phy, + .disconnect_phy = phy_sfp_disconnect_phy, }; static int m88e1510_probe(struct phy_device *phydev) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index ad43e280930c..6642eb642d4b 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -503,6 +503,8 @@ static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id) static const struct sfp_upstream_ops mv3310_sfp_ops = { .attach = phy_sfp_attach, .detach = phy_sfp_detach, + .connect_phy = phy_sfp_connect_phy, + .disconnect_phy = phy_sfp_disconnect_phy, .module_insert = mv3310_sfp_insert, }; diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index aad78e3f7894..6a7a05802bc6 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1363,6 +1363,46 @@ phy_standalone_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(phy_standalone); +/** + * phy_sfp_connect_phy - Connect the SFP module's PHY to the upstream PHY + * @upstream: pointer to the upstream phy device + * @phy: pointer to the SFP module's phy device + * + * This helper allows keeping track of PHY devices on the link. It adds the + * SFP module's phy to the phy namespace of the upstream phy + */ +int phy_sfp_connect_phy(void *upstream, struct phy_device *phy) +{ + struct phy_device *phydev = upstream; + struct phy_link_topology *topo = phy_get_link_topology(phydev); + + if (topo) + return phy_link_topo_add_phy(topo, phy, PHY_UPSTREAM_PHY, phydev); + + return 0; +} +EXPORT_SYMBOL(phy_sfp_connect_phy); + +/** + * phy_sfp_disconnect_phy - Disconnect the SFP module's PHY from the upstream PHY + * @upstream: pointer to the upstream phy device + * @phy: pointer to the SFP module's phy device + * + * This helper allows keeping track of PHY devices on the link. It removes the + * SFP module's phy to the phy namespace of the upstream phy. As the module phy + * will be destroyed, re-inserting the same module will add a new phy with a + * new index. + */ +void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy) +{ + struct phy_device *phydev = upstream; + struct phy_link_topology *topo = phy_get_link_topology(phydev); + + if (topo) + phy_link_topo_del_phy(topo, phy); +} +EXPORT_SYMBOL(phy_sfp_disconnect_phy); + /** * phy_sfp_attach - attach the SFP bus to the PHY upstream network device * @upstream: pointer to the phy device diff --git a/include/linux/phy.h b/include/linux/phy.h index 9f21eb380475..6cb9d843aee9 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1726,6 +1726,8 @@ int phy_suspend(struct phy_device *phydev); int phy_resume(struct phy_device *phydev); int __phy_resume(struct phy_device *phydev); int phy_loopback(struct phy_device *phydev, bool enable); +int phy_sfp_connect_phy(void *upstream, struct phy_device *phy); +void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy); void phy_sfp_attach(void *upstream, struct sfp_bus *bus); void phy_sfp_detach(void *upstream, struct sfp_bus *bus); int phy_sfp_probe(struct phy_device *phydev, -- 2.43.0