Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp301054lqr; Wed, 5 Jun 2024 06:38:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXi9NoSNV4edzWXZV1LuhouwpOUsRGialU1/jSqHI5muwJPhNE3Zhb8ZljPQaltvI5k86H/w2uDPPCwfDI+lwKyOW3SmO7me/9HWzLjdg== X-Google-Smtp-Source: AGHT+IGuwQdOJXVV5+A2u2USYwUp/FLVhobIqgnar9j8Eodue6LkxYSQ8ANIgpuHT9iDqqjUiKCF X-Received: by 2002:a05:6a00:b4b:b0:702:8b18:9fc3 with SMTP id d2e1a72fcca58-703e599dbf1mr2890859b3a.15.1717594687879; Wed, 05 Jun 2024 06:38:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717594687; cv=pass; d=google.com; s=arc-20160816; b=i0ZrPUtTZpdDHLOinVGrPSVQgsgrMpKSsaKWK4UN4MoLv91kNqOvk7uOUe09eMnlA6 jtwB2aEmho1wC43kHMhOx4YmIOrdBbMT1A8J43BicYJZ+JFUZBLgnQrIZYIZBLsmiXf5 WYpuymYdnnYh0hYRk2Uh0p/95uq+Rji7mFz9D9aL+VxsV5WVdiBgdBFk8I3yGBfG0a19 sIDxzJhIl9ccNy9o6wyUHJkEEvszOY81axxeywNnXk9FyM8yo1Y3/7sl9jSlmJ9hme66 8/UwfKdMBpTvUg7g/VSn6pDcCMecMvWbQBYZBvENAw4goHEO7k3tp7NHvPWsCiYqLlRM 49tw== ARC-Message-Signature: i=2; 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=qhXdwwFrBOf2sVggxdb3tThwYPj1bqviErEGv82K1dE=; fh=Dinp91LF2KcnzfyOXGg1vCezYXJAYX+8GKPCxLQjq1Q=; b=jWFbZqTkzZXuL5pJi6aujcjmEdQ0gDLSpgVk8g0s2B1T+sPYcJxv6xyAOoV8ok46My JRyKtsyGLsPueK0n3Hhzou9lQqZf2oPJn29yfKajbVaSxRZvAyuYBuZClZNqhBsJb45g kGLZ547LHzGpzuBHArdzMcPEidkpJSRMsbfngR6Jyqtq3254Rcs5iUAGEH8lzAXbcFgL EPmG/xxybyQjzVEIdYSrQwcSDe6QhhBqKWNpemzNAIPnUHkoi/5M97QzHS5Zp7mCzqvj rZ51anrQtPUwKo8Kc4Lj+rS7Opon/wHES0p1gP47eMzVf1S0XkmP6vJDvTgiu+1aT1ti SP/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ayPRaL4r; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-202645-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202645-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-70288b270e6si506446b3a.210.2024.06.05.06.38.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 06:38:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202645-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ayPRaL4r; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-202645-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202645-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 29A2E296A81 for ; Wed, 5 Jun 2024 13:24:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B63E01AB8ED; Wed, 5 Jun 2024 12:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ayPRaL4r" Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 8D3511A3BCB; Wed, 5 Jun 2024 12:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717591774; cv=none; b=LLeNZU1qpzt7PW8AsxaFcAiLILSslTu9MqOXIsmJM6674JD3ShTCHD62wPzNDu/N9grR1soKMXy0Y/4tO0Ck47DyeOTP3E4xruxvG1AGwDI0kwwuVybpgnceAWQSvgQ3nz+YWWUhVXGycBYJPHBOdNNeb9NqGuAH3QCD2c0byMY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717591774; c=relaxed/simple; bh=u1qRU4ASjZ/VuK0avyxtwNgcfu+/iBHDSUUQh5ULDNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rIXUSnDpzssm1YBZ4xt2UG8Ek6kIham3xiA4v/AiYFCiaLiM7EHtflrLOvQl0Ju8TJ26g6Yg/l5uBahc8RLoRZ3e9KV9XyEleB46qxeh4WSWjyruSWT4WyEnHgNiYwhXmhjFOcv8GPr5+KuizIRRv/rreaMAhAf/E+pLgCPhN4Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ayPRaL4r; arc=none smtp.client-ip=217.70.183.200 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 792F620009; Wed, 5 Jun 2024 12:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1717591769; 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=qhXdwwFrBOf2sVggxdb3tThwYPj1bqviErEGv82K1dE=; b=ayPRaL4rUZsQWoHRFPz28L8VNGjjMn5NwLC4vPtToZCvA4t7/6yGMBap0yzvs8kTet9Fc/ gIb2fVBWMAZbRVmrx+f6OFV2X6HvJ8TYQrmO/EhEyN2tRcvGrCq43veYZbYep3zHZ5VZIq FHyMWam4tQICnPLkGXX5R/Oyh7mzJbQNNEtNn0BKG4C7tb8/9e8holkN/OsAfN7rKu/IMt /ockXL9Te66ldVZgEuvc1oPF/ltCKvOYARmQBoncVHBWU1lRlPFtFlUqXYW5zMutgYUE29 dNKu8SK4Y8pQZ6Gm8vxi2ufRk04KKTL2sxl+6e2DBhOJwhe2ykE4YaEXHT8x5g== 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 , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Piergiorgio Beruto , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Nathan Chancellor , Antoine Tenart Subject: [PATCH net-next v12 03/13] net: phy: add helpers to handle sfp phy connect/disconnect Date: Wed, 5 Jun 2024 14:49:08 +0200 Message-ID: <20240605124920.720690-4-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240605124920.720690-1-maxime.chevallier@bootlin.com> References: <20240605124920.720690-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 Reviewed-by: Andrew Lunn --- 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 +++++++++++++++++++++++++++++++ drivers/net/phy/qcom/at803x.c | 2 ++ drivers/net/phy/qcom/qca807x.c | 2 ++ include/linux/phy.h | 2 ++ 7 files changed, 52 insertions(+) diff --git a/drivers/net/phy/marvell-88x2222.c b/drivers/net/phy/marvell-88x2222.c index b88398e6872b..0b777cdd7078 100644 --- a/drivers/net/phy/marvell-88x2222.c +++ b/drivers/net/phy/marvell-88x2222.c @@ -553,6 +553,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 b89fbffa6a93..9964bf3dea2f 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -3613,6 +3613,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 439d03f5774a..111434201545 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1370,6 +1370,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 net_device *dev = phydev->attached_dev; + + if (dev) + return phy_link_topo_add_phy(dev, 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 net_device *dev = phydev->attached_dev; + + if (dev) + phy_link_topo_del_phy(dev, 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/drivers/net/phy/qcom/at803x.c b/drivers/net/phy/qcom/at803x.c index c8f83e5f78ab..105602581a03 100644 --- a/drivers/net/phy/qcom/at803x.c +++ b/drivers/net/phy/qcom/at803x.c @@ -770,6 +770,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/qcom/qca807x.c b/drivers/net/phy/qcom/qca807x.c index 672c6929119a..5eb0ab1cb70e 100644 --- a/drivers/net/phy/qcom/qca807x.c +++ b/drivers/net/phy/qcom/qca807x.c @@ -699,6 +699,8 @@ static const struct sfp_upstream_ops qca807x_sfp_ops = { .detach = phy_sfp_detach, .module_insert = qca807x_sfp_insert, .module_remove = qca807x_sfp_remove, + .connect_phy = phy_sfp_connect_phy, + .disconnect_phy = phy_sfp_disconnect_phy, }; static int qca807x_probe(struct phy_device *phydev) diff --git a/include/linux/phy.h b/include/linux/phy.h index 8c848c79b1fd..3ddfe7fe781a 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1758,6 +1758,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.45.1