From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 515F431AF3C for ; Thu, 20 Nov 2025 20:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672132; cv=none; b=JCROhQAntrwCf75YXoHZiLoULLp8ldSDnZ1EFbSx2PdIokn/CKEHMx0t3P+g+/zkMw/C6QMDsegT2G0bmBq3zZLw/ymZ2ozc50MnRD9nc097pDKuivPGtbB8jId57sbWPvnXdQ3GpZv0uNQBBwUqkhBkGday5PVE5073aaHHAwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672132; c=relaxed/simple; bh=xlVwY/jvea8mhfmXnt+y3NKWE9PqF8k8tql6frayO/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D9OR+yf0o9A4OquUBGWFnbjHZ0ckkE7rGEjayyCtnKt4hWlMSf7qc75+/CBHnnaBADaDsTq1f3h3LOu5AoQTVXlnJI/wPD5LOIayrF9g5jKVAkBwko6vvNjJmrrwuWeQYoR//XVZDmpqajiJ5deSlPTvZgwqsmw0ktEZQNmq7Ug= 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=I2HKjw3K; arc=none smtp.client-ip=185.246.85.4 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="I2HKjw3K" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 8FB124E41812; Thu, 20 Nov 2025 20:55:28 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5DDD8606F6; Thu, 20 Nov 2025 20:55:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BF4F710371BC9; Thu, 20 Nov 2025 21:55:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672126; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Ufp3kAXMSgKW2930xyBy2R83bPWmF3ZuHUfc35hNYPk=; b=I2HKjw3KQEoqpZqOeDnrlVnh7yylCTcMpRHU/SIScJBuf3OnHp2x9XHiqmV/nsEO06k30n wnNNeN2jxdWaUzVGp0FxWzCA3OhHrpS+xStQ2nH+MDdc3D+Az/LYkypFm4PMzTH6JiW9ma 8lHhWMmm2S3198D3KxvG45468HSvmOfWzzxaQ/Sv/x3cf5RLWzmJIubVpg1SQTxEQrN0Mf FEIpUyJR6xeETV/QrAfTF3eXTv09hojGPEcmEG8mu99DUJwwxCfVRwk9JK3HrIYFHLrErg DlfibSvusghTO70oFh195lh+rTi1BRfarWJ9o43lpun+I5Vh9+qoJzrkk3EgCA== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 01/15] dt-bindings: net: Introduce the ethernet-connector description Date: Thu, 20 Nov 2025 21:54:51 +0100 Message-ID: <20251120205508.553909-2-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The ability to describe the physical ports of Ethernet devices is useful to describe multi-port devices, as well as to remove any ambiguity with regard to the nature of the port. Moreover, describing ports allows for a better description of features that are tied to connectors, such as PoE through the PSE-PD devices. Introduce a binding to allow describing the ports, for now with 2 attributes : - The number of pairs, which is a quite generic property that allows differentating between multiple similar technologies such as BaseT1 and "regular" BaseT (which usually means BaseT4). - The media that can be used on that port, such as BaseT for Twisted Copper, BaseC for coax copper, BaseS/L for Fiber, BaseK for backplane ethernet, etc. This allows defining the nature of the port, and therefore avoids the need for vendor-specific properties such as "micrel,fiber-mode" or "ti,fiber-mode". The port description lives in its own file, as it is intended in the future to allow describing the ports for phy-less devices. Reviewed-by: Andrew Lunn Reviewed-by: Christophe Leroy Reviewed-by: Rob Herring (Arm) Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- .../bindings/net/ethernet-connector.yaml | 57 +++++++++++++++++++ .../devicetree/bindings/net/ethernet-phy.yaml | 18 ++++++ MAINTAINERS | 1 + 3 files changed, 76 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/ethernet-connecto= r.yaml diff --git a/Documentation/devicetree/bindings/net/ethernet-connector.yaml = b/Documentation/devicetree/bindings/net/ethernet-connector.yaml new file mode 100644 index 000000000000..2ccac24bd8d6 --- /dev/null +++ b/Documentation/devicetree/bindings/net/ethernet-connector.yaml @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/ethernet-connector.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Generic Ethernet Connector + +maintainers: + - Maxime Chevallier + +description: + An Ethernet Connector represents the output of a network component such = as + a PHY, an Ethernet controller with no PHY, or an SFP module. + +properties: + + pairs: + description: + Defines the number of BaseT pairs that are used on the connector. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [1, 2, 4] + + media: + description: + The mediums, as defined in 802.3, that can be used on the port. + enum: + - BaseT + - BaseK + - BaseS + - BaseC + - BaseL + - BaseD + - BaseE + - BaseF + - BaseV + - BaseMLD + +required: + - media + +allOf: + - if: + properties: + media: + contains: + const: BaseT + then: + required: + - pairs + else: + properties: + pairs: false + +additionalProperties: true + +... diff --git a/Documentation/devicetree/bindings/net/ethernet-phy.yaml b/Docu= mentation/devicetree/bindings/net/ethernet-phy.yaml index bb4c49fc5fd8..58634fee9fc4 100644 --- a/Documentation/devicetree/bindings/net/ethernet-phy.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-phy.yaml @@ -281,6 +281,17 @@ properties: =20 additionalProperties: false =20 + mdi: + type: object + + patternProperties: + '^connector-[0-9]+$': + $ref: /schemas/net/ethernet-connector.yaml# + + unevaluatedProperties: false + + additionalProperties: false + required: - reg =20 @@ -317,5 +328,12 @@ examples: default-state =3D "keep"; }; }; + /* Fast Ethernet port, with only 2 pairs wired */ + mdi { + connector-0 { + pairs =3D <2>; + media =3D "BaseT"; + }; + }; }; }; diff --git a/MAINTAINERS b/MAINTAINERS index b0223cfb2583..0f4fb37e77b1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9279,6 +9279,7 @@ R: Russell King L: netdev@vger.kernel.org S: Maintained F: Documentation/ABI/testing/sysfs-class-net-phydev +F: Documentation/devicetree/bindings/net/ethernet-connector.yaml F: Documentation/devicetree/bindings/net/ethernet-phy.yaml F: Documentation/devicetree/bindings/net/mdio* F: Documentation/devicetree/bindings/net/qca,ar803x.yaml --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 25E32361DBE for ; Thu, 20 Nov 2025 20:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672135; cv=none; b=S3FxWLwUgw+wrH3UworYnspXkjQbYhe8BMrs9YyKH58r/7BqW+SF+1VOVBexnQQruNj00S6DdLh03o2L/fjryeHU/xDfuLnxp2gc53lnALC5sIFSVBTlRirOu1tjSIhsxQTsOtrUEA5Vt/VM1a/Fg0UUhI1pgMaqxrlwcZSk1YI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672135; c=relaxed/simple; bh=aKmuwBKq8Ua7yX7SOJlzqXLg8NO2LG6p6dBvfYnfKeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i84o1z/ahQ4Jj+QTuEN5G/49WlYw7vKYvT5Sv4dRIel0LtLSpyl8LggjEet3jLMF8oawO8d+7/jI1HxBh6Z0BM7xIIlvGqbnyWCD24C4Bru7u6FcRJ2j5ljKZLI0zlMoufcXNQZSPEu2SGn8d7PvZhimGJJBAFL1Z0U3sBmXuT8= 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=aRDTpCxW; arc=none smtp.client-ip=185.246.84.56 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="aRDTpCxW" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id A4B261A1C0F; Thu, 20 Nov 2025 20:55:31 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 78401606F6; Thu, 20 Nov 2025 20:55:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 3FD6410371BC1; Thu, 20 Nov 2025 21:55:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672130; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=3tDfFtO2Ig/g5OR4TfHBhi9z6xQgS+5SdupKJ8c0yyA=; b=aRDTpCxWmF45qN8vc4gCbfqdnFE9+gPD4DwfTH429JUF9wtqosi4EdY8wDFx2sD64p6OaY 0RXU+rYI19VxV01cQX1WVIelqzCPrkvAmjIevL7K0nCbF37+j1uyITjTIfOvX/uh5uZ0KH CtVz3kgCIaEf0Jst6LxEHMtRpikmxuOtljOEONQR6G4aZSM4qgtOfkiUJCo0Dm1ZelJDhP LfdWr8+Umi34qNw3lo7w5UD9td+ukg0mSkRFix318UjZuEbeas5hWRRSvHjSFshaGWOVYB ix5mv8EmQudJFd+ewGI3EoOvg0+pkYoVdi+w8YcZAp/4Z1hswCykMSkvkiRG0g== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 02/15] net: ethtool: Introduce ETHTOOL_LINK_MEDIUM_* values Date: Thu, 20 Nov 2025 21:54:52 +0100 Message-ID: <20251120205508.553909-3-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" In an effort to have a better representation of Ethernet ports, introduce enumeration values representing the various ethernet Mediums. This is part of the 802.3 naming convention, for example : 1000 Base T 4 | | | | | | | \_ pairs (4) | | \___ Medium (T =3D=3D Twisted Copper Pairs) | \_______ Baseband transmission \____________ Speed Other example : 10000 Base K X 4 | | \_ lanes (4) | \___ encoding (BaseX is 8b/10b while BaseR is 66b/64b) \_____ Medium (K is backplane ethernet) In the case of representing a physical port, only the medium and number of pairs should be relevant. One exception would be 1000BaseX, which is currently also used as a medium in what appears to be any of 1000BaseSX, 1000BaseCX and 1000BaseLX. This was reflected in the mediums associated with the 1000BaseX linkmode. These mediums are set in the net/ethtool/common.c lookup table that maintains a list of all linkmodes with their number of pairs, medium, encoding, speed and duplex. One notable exception to this is 100M BaseT Ethernet. 100BaseTX is a 2-pairs protocol but it will also work on 4-pairs cables, so the lookup table contains 2 sets of pair numbers, indicating the min number of pairs for a protocol to work and the "nominal" number of pairs as well. Another set of exceptions are linkmodes such 100000baseLR4_ER4, where the same link mode seems to represent 100GBaseLR4 and 100GBaseER4. The macro __DEFINE_LINK_MODE_PARAMS_MEDIUMS is here used to populate the .mediums bitfield with all appropriate mediums. Reviewed-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_caps.c | 8 ++ include/linux/ethtool.h | 25 +++- net/ethtool/common.c | 252 +++++++++++++++++++++---------------- 3 files changed, 173 insertions(+), 112 deletions(-) diff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c index 23c808b59b6f..9a5e293c5104 100644 --- a/drivers/net/phy/phy_caps.c +++ b/drivers/net/phy/phy_caps.c @@ -78,6 +78,14 @@ int __init phy_caps_init(void) /* Fill the caps array from net/ethtool/common.c */ for (i =3D 0; i < __ETHTOOL_LINK_MODE_MASK_NBITS; i++) { linkmode =3D &link_mode_params[i]; + + /* Sanity check the linkmodes array for number of pairs */ + if (linkmode->pairs < linkmode->min_pairs) { + pr_err("Pairs count must not be under min_pairs for linkmode %d\n", + i); + return -EINVAL; + } + capa =3D speed_duplex_to_capa(linkmode->speed, linkmode->duplex); =20 if (capa < 0) { diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 5c9162193d26..37aede6af96f 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -216,13 +216,32 @@ static inline u8 *ethtool_rxfh_context_key(struct eth= tool_rxfh_context *ctx) void ethtool_rxfh_context_lost(struct net_device *dev, u32 context_id); =20 struct link_mode_info { - int speed; - u8 lanes; - u8 duplex; + int speed; + u8 lanes; + u8 min_pairs; + u8 pairs; + u8 duplex; + u16 mediums; }; =20 extern const struct link_mode_info link_mode_params[]; =20 +enum ethtool_link_medium { + ETHTOOL_LINK_MEDIUM_BASET =3D 0, + ETHTOOL_LINK_MEDIUM_BASEK, + ETHTOOL_LINK_MEDIUM_BASES, + ETHTOOL_LINK_MEDIUM_BASEC, + ETHTOOL_LINK_MEDIUM_BASEL, + ETHTOOL_LINK_MEDIUM_BASED, + ETHTOOL_LINK_MEDIUM_BASEE, + ETHTOOL_LINK_MEDIUM_BASEF, + ETHTOOL_LINK_MEDIUM_BASEV, + ETHTOOL_LINK_MEDIUM_BASEMLD, + ETHTOOL_LINK_MEDIUM_NONE, + + __ETHTOOL_LINK_MEDIUM_LAST, +}; + /* declare a link mode bitmap */ #define __ETHTOOL_DECLARE_LINK_MODE_MASK(name) \ DECLARE_BITMAP(name, __ETHTOOL_LINK_MODE_MASK_NBITS) diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 55223ebc2a7e..2f4b70f104e8 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -281,12 +281,35 @@ static_assert(ARRAY_SIZE(link_mode_names) =3D=3D __ET= HTOOL_LINK_MODE_MASK_NBITS); #define __LINK_MODE_LANES_DR8_2 8 #define __LINK_MODE_LANES_T1BRR 1 =20 -#define __DEFINE_LINK_MODE_PARAMS(_speed, _type, _duplex) \ +#define __DEFINE_LINK_MODE_PARAMS_PAIRS(_speed, _type, _min_pairs, _pairs,= _duplex, _medium) \ [ETHTOOL_LINK_MODE(_speed, _type, _duplex)] =3D { \ .speed =3D SPEED_ ## _speed, \ .lanes =3D __LINK_MODE_LANES_ ## _type, \ - .duplex =3D __DUPLEX_ ## _duplex \ + .min_pairs =3D _min_pairs, \ + .pairs =3D _pairs, \ + .duplex =3D __DUPLEX_ ## _duplex, \ + .mediums =3D BIT(ETHTOOL_LINK_MEDIUM_BASE ## _medium) \ } + +#define __DEFINE_LINK_MODE_PARAMS(_speed, _type, _duplex, _medium) \ + [ETHTOOL_LINK_MODE(_speed, _type, _duplex)] =3D { \ + .speed =3D SPEED_ ## _speed, \ + .lanes =3D __LINK_MODE_LANES_ ## _type, \ + .min_pairs =3D 0, \ + .pairs =3D 0, \ + .duplex =3D __DUPLEX_ ## _duplex, \ + .mediums =3D BIT(ETHTOOL_LINK_MEDIUM_BASE ## _medium) \ + } +#define __DEFINE_LINK_MODE_PARAMS_MEDIUMS(_speed, _type, _duplex, _mediums= ) \ + [ETHTOOL_LINK_MODE(_speed, _type, _duplex)] =3D { \ + .speed =3D SPEED_ ## _speed, \ + .lanes =3D __LINK_MODE_LANES_ ## _type, \ + .min_pairs =3D 0, \ + .pairs =3D 0, \ + .duplex =3D __DUPLEX_ ## _duplex, \ + .mediums =3D (_mediums) \ + } +#define __MED(_medium) (BIT(ETHTOOL_LINK_MEDIUM_BASE ## _medium)) #define __DUPLEX_Half DUPLEX_HALF #define __DUPLEX_Full DUPLEX_FULL #define __DEFINE_SPECIAL_MODE_PARAMS(_mode) \ @@ -294,134 +317,145 @@ static_assert(ARRAY_SIZE(link_mode_names) =3D=3D __= ETHTOOL_LINK_MODE_MASK_NBITS); .speed =3D SPEED_UNKNOWN, \ .lanes =3D 0, \ .duplex =3D DUPLEX_UNKNOWN, \ + .mediums =3D BIT(ETHTOOL_LINK_MEDIUM_NONE), \ } =20 const struct link_mode_info link_mode_params[] =3D { - __DEFINE_LINK_MODE_PARAMS(10, T, Half), - __DEFINE_LINK_MODE_PARAMS(10, T, Full), - __DEFINE_LINK_MODE_PARAMS(100, T, Half), - __DEFINE_LINK_MODE_PARAMS(100, T, Full), - __DEFINE_LINK_MODE_PARAMS(1000, T, Half), - __DEFINE_LINK_MODE_PARAMS(1000, T, Full), + __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T, 2, 4, Half, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T, 2, 4, Full, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(100, T, 2, 4, Half, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(100, T, 2, 4, Full, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(1000, T, 4, 4, Half, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(1000, T, 4, 4, Full, T), __DEFINE_SPECIAL_MODE_PARAMS(Autoneg), __DEFINE_SPECIAL_MODE_PARAMS(TP), __DEFINE_SPECIAL_MODE_PARAMS(AUI), __DEFINE_SPECIAL_MODE_PARAMS(MII), __DEFINE_SPECIAL_MODE_PARAMS(FIBRE), __DEFINE_SPECIAL_MODE_PARAMS(BNC), - __DEFINE_LINK_MODE_PARAMS(10000, T, Full), + __DEFINE_LINK_MODE_PARAMS_PAIRS(10000, T, 4, 4, Full, T), __DEFINE_SPECIAL_MODE_PARAMS(Pause), __DEFINE_SPECIAL_MODE_PARAMS(Asym_Pause), - __DEFINE_LINK_MODE_PARAMS(2500, X, Full), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(2500, X, Full, + __MED(C) | __MED(S) | __MED(L)), __DEFINE_SPECIAL_MODE_PARAMS(Backplane), - __DEFINE_LINK_MODE_PARAMS(1000, KX, Full), - __DEFINE_LINK_MODE_PARAMS(10000, KX4, Full), - __DEFINE_LINK_MODE_PARAMS(10000, KR, Full), + __DEFINE_LINK_MODE_PARAMS(1000, KX, Full, K), + __DEFINE_LINK_MODE_PARAMS(10000, KX4, Full, K), + __DEFINE_LINK_MODE_PARAMS(10000, KR, Full, K), [ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] =3D { .speed =3D SPEED_10000, .lanes =3D 1, .duplex =3D DUPLEX_FULL, }, - __DEFINE_LINK_MODE_PARAMS(20000, MLD2, Full), - __DEFINE_LINK_MODE_PARAMS(20000, KR2, Full), - __DEFINE_LINK_MODE_PARAMS(40000, KR4, Full), - __DEFINE_LINK_MODE_PARAMS(40000, CR4, Full), - __DEFINE_LINK_MODE_PARAMS(40000, SR4, Full), - __DEFINE_LINK_MODE_PARAMS(40000, LR4, Full), - __DEFINE_LINK_MODE_PARAMS(56000, KR4, Full), - __DEFINE_LINK_MODE_PARAMS(56000, CR4, Full), - __DEFINE_LINK_MODE_PARAMS(56000, SR4, Full), - __DEFINE_LINK_MODE_PARAMS(56000, LR4, Full), - __DEFINE_LINK_MODE_PARAMS(25000, CR, Full), - __DEFINE_LINK_MODE_PARAMS(25000, KR, Full), - __DEFINE_LINK_MODE_PARAMS(25000, SR, Full), - __DEFINE_LINK_MODE_PARAMS(50000, CR2, Full), - __DEFINE_LINK_MODE_PARAMS(50000, KR2, Full), - __DEFINE_LINK_MODE_PARAMS(100000, KR4, Full), - __DEFINE_LINK_MODE_PARAMS(100000, SR4, Full), - __DEFINE_LINK_MODE_PARAMS(100000, CR4, Full), - __DEFINE_LINK_MODE_PARAMS(100000, LR4_ER4, Full), - __DEFINE_LINK_MODE_PARAMS(50000, SR2, Full), - __DEFINE_LINK_MODE_PARAMS(1000, X, Full), - __DEFINE_LINK_MODE_PARAMS(10000, CR, Full), - __DEFINE_LINK_MODE_PARAMS(10000, SR, Full), - __DEFINE_LINK_MODE_PARAMS(10000, LR, Full), - __DEFINE_LINK_MODE_PARAMS(10000, LRM, Full), - __DEFINE_LINK_MODE_PARAMS(10000, ER, Full), - __DEFINE_LINK_MODE_PARAMS(2500, T, Full), - __DEFINE_LINK_MODE_PARAMS(5000, T, Full), + __DEFINE_LINK_MODE_PARAMS(20000, MLD2, Full, MLD), + __DEFINE_LINK_MODE_PARAMS(20000, KR2, Full, K), + __DEFINE_LINK_MODE_PARAMS(40000, KR4, Full, K), + __DEFINE_LINK_MODE_PARAMS(40000, CR4, Full, C), + __DEFINE_LINK_MODE_PARAMS(40000, SR4, Full, S), + __DEFINE_LINK_MODE_PARAMS(40000, LR4, Full, L), + __DEFINE_LINK_MODE_PARAMS(56000, KR4, Full, K), + __DEFINE_LINK_MODE_PARAMS(56000, CR4, Full, C), + __DEFINE_LINK_MODE_PARAMS(56000, SR4, Full, S), + __DEFINE_LINK_MODE_PARAMS(56000, LR4, Full, L), + __DEFINE_LINK_MODE_PARAMS(25000, CR, Full, C), + __DEFINE_LINK_MODE_PARAMS(25000, KR, Full, K), + __DEFINE_LINK_MODE_PARAMS(25000, SR, Full, S), + __DEFINE_LINK_MODE_PARAMS(50000, CR2, Full, C), + __DEFINE_LINK_MODE_PARAMS(50000, KR2, Full, K), + __DEFINE_LINK_MODE_PARAMS(100000, KR4, Full, K), + __DEFINE_LINK_MODE_PARAMS(100000, SR4, Full, S), + __DEFINE_LINK_MODE_PARAMS(100000, CR4, Full, C), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(100000, LR4_ER4, Full, + __MED(L) | __MED(E)), + __DEFINE_LINK_MODE_PARAMS(50000, SR2, Full, S), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(1000, X, Full, + __MED(C) | __MED(S) | __MED(L)), + __DEFINE_LINK_MODE_PARAMS(10000, CR, Full, C), + __DEFINE_LINK_MODE_PARAMS(10000, SR, Full, S), + __DEFINE_LINK_MODE_PARAMS(10000, LR, Full, L), + __DEFINE_LINK_MODE_PARAMS(10000, LRM, Full, L), + __DEFINE_LINK_MODE_PARAMS(10000, ER, Full, E), + __DEFINE_LINK_MODE_PARAMS_PAIRS(2500, T, 4, 4, Full, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(5000, T, 4, 4, Full, T), __DEFINE_SPECIAL_MODE_PARAMS(FEC_NONE), __DEFINE_SPECIAL_MODE_PARAMS(FEC_RS), __DEFINE_SPECIAL_MODE_PARAMS(FEC_BASER), - __DEFINE_LINK_MODE_PARAMS(50000, KR, Full), - __DEFINE_LINK_MODE_PARAMS(50000, SR, Full), - __DEFINE_LINK_MODE_PARAMS(50000, CR, Full), - __DEFINE_LINK_MODE_PARAMS(50000, LR_ER_FR, Full), - __DEFINE_LINK_MODE_PARAMS(50000, DR, Full), - __DEFINE_LINK_MODE_PARAMS(100000, KR2, Full), - __DEFINE_LINK_MODE_PARAMS(100000, SR2, Full), - __DEFINE_LINK_MODE_PARAMS(100000, CR2, Full), - __DEFINE_LINK_MODE_PARAMS(100000, LR2_ER2_FR2, Full), - __DEFINE_LINK_MODE_PARAMS(100000, DR2, Full), - __DEFINE_LINK_MODE_PARAMS(200000, KR4, Full), - __DEFINE_LINK_MODE_PARAMS(200000, SR4, Full), - __DEFINE_LINK_MODE_PARAMS(200000, LR4_ER4_FR4, Full), - __DEFINE_LINK_MODE_PARAMS(200000, DR4, Full), - __DEFINE_LINK_MODE_PARAMS(200000, CR4, Full), - __DEFINE_LINK_MODE_PARAMS(100, T1, Full), - __DEFINE_LINK_MODE_PARAMS(1000, T1, Full), - __DEFINE_LINK_MODE_PARAMS(400000, KR8, Full), - __DEFINE_LINK_MODE_PARAMS(400000, SR8, Full), - __DEFINE_LINK_MODE_PARAMS(400000, LR8_ER8_FR8, Full), - __DEFINE_LINK_MODE_PARAMS(400000, DR8, Full), - __DEFINE_LINK_MODE_PARAMS(400000, CR8, Full), + __DEFINE_LINK_MODE_PARAMS(50000, KR, Full, K), + __DEFINE_LINK_MODE_PARAMS(50000, SR, Full, S), + __DEFINE_LINK_MODE_PARAMS(50000, CR, Full, C), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(50000, LR_ER_FR, Full, + __MED(L) | __MED(E) | __MED(F)), + __DEFINE_LINK_MODE_PARAMS(50000, DR, Full, D), + __DEFINE_LINK_MODE_PARAMS(100000, KR2, Full, K), + __DEFINE_LINK_MODE_PARAMS(100000, SR2, Full, S), + __DEFINE_LINK_MODE_PARAMS(100000, CR2, Full, C), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(100000, LR2_ER2_FR2, Full, + __MED(L) | __MED(E) | __MED(F)), + __DEFINE_LINK_MODE_PARAMS(100000, DR2, Full, D), + __DEFINE_LINK_MODE_PARAMS(200000, KR4, Full, K), + __DEFINE_LINK_MODE_PARAMS(200000, SR4, Full, S), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(200000, LR4_ER4_FR4, Full, + __MED(L) | __MED(E) | __MED(F)), + __DEFINE_LINK_MODE_PARAMS(200000, DR4, Full, D), + __DEFINE_LINK_MODE_PARAMS(200000, CR4, Full, C), + __DEFINE_LINK_MODE_PARAMS_PAIRS(100, T1, 1, 1, Full, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(1000, T1, 1, 1, Full, T), + __DEFINE_LINK_MODE_PARAMS(400000, KR8, Full, K), + __DEFINE_LINK_MODE_PARAMS(400000, SR8, Full, S), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(400000, LR8_ER8_FR8, Full, + __MED(L) | __MED(E) | __MED(F)), + __DEFINE_LINK_MODE_PARAMS(400000, DR8, Full, D), + __DEFINE_LINK_MODE_PARAMS(400000, CR8, Full, C), __DEFINE_SPECIAL_MODE_PARAMS(FEC_LLRS), - __DEFINE_LINK_MODE_PARAMS(100000, KR, Full), - __DEFINE_LINK_MODE_PARAMS(100000, SR, Full), - __DEFINE_LINK_MODE_PARAMS(100000, LR_ER_FR, Full), - __DEFINE_LINK_MODE_PARAMS(100000, DR, Full), - __DEFINE_LINK_MODE_PARAMS(100000, CR, Full), - __DEFINE_LINK_MODE_PARAMS(200000, KR2, Full), - __DEFINE_LINK_MODE_PARAMS(200000, SR2, Full), - __DEFINE_LINK_MODE_PARAMS(200000, LR2_ER2_FR2, Full), - __DEFINE_LINK_MODE_PARAMS(200000, DR2, Full), - __DEFINE_LINK_MODE_PARAMS(200000, CR2, Full), - __DEFINE_LINK_MODE_PARAMS(400000, KR4, Full), - __DEFINE_LINK_MODE_PARAMS(400000, SR4, Full), - __DEFINE_LINK_MODE_PARAMS(400000, LR4_ER4_FR4, Full), - __DEFINE_LINK_MODE_PARAMS(400000, DR4, Full), - __DEFINE_LINK_MODE_PARAMS(400000, CR4, Full), - __DEFINE_LINK_MODE_PARAMS(100, FX, Half), - __DEFINE_LINK_MODE_PARAMS(100, FX, Full), - __DEFINE_LINK_MODE_PARAMS(10, T1L, Full), - __DEFINE_LINK_MODE_PARAMS(800000, CR8, Full), - __DEFINE_LINK_MODE_PARAMS(800000, KR8, Full), - __DEFINE_LINK_MODE_PARAMS(800000, DR8, Full), - __DEFINE_LINK_MODE_PARAMS(800000, DR8_2, Full), - __DEFINE_LINK_MODE_PARAMS(800000, SR8, Full), - __DEFINE_LINK_MODE_PARAMS(800000, VR8, Full), - __DEFINE_LINK_MODE_PARAMS(10, T1S, Full), - __DEFINE_LINK_MODE_PARAMS(10, T1S, Half), - __DEFINE_LINK_MODE_PARAMS(10, T1S_P2MP, Half), - __DEFINE_LINK_MODE_PARAMS(10, T1BRR, Full), - __DEFINE_LINK_MODE_PARAMS(200000, CR, Full), - __DEFINE_LINK_MODE_PARAMS(200000, KR, Full), - __DEFINE_LINK_MODE_PARAMS(200000, DR, Full), - __DEFINE_LINK_MODE_PARAMS(200000, DR_2, Full), - __DEFINE_LINK_MODE_PARAMS(200000, SR, Full), - __DEFINE_LINK_MODE_PARAMS(200000, VR, Full), - __DEFINE_LINK_MODE_PARAMS(400000, CR2, Full), - __DEFINE_LINK_MODE_PARAMS(400000, KR2, Full), - __DEFINE_LINK_MODE_PARAMS(400000, DR2, Full), - __DEFINE_LINK_MODE_PARAMS(400000, DR2_2, Full), - __DEFINE_LINK_MODE_PARAMS(400000, SR2, Full), - __DEFINE_LINK_MODE_PARAMS(400000, VR2, Full), - __DEFINE_LINK_MODE_PARAMS(800000, CR4, Full), - __DEFINE_LINK_MODE_PARAMS(800000, KR4, Full), - __DEFINE_LINK_MODE_PARAMS(800000, DR4, Full), - __DEFINE_LINK_MODE_PARAMS(800000, DR4_2, Full), - __DEFINE_LINK_MODE_PARAMS(800000, SR4, Full), - __DEFINE_LINK_MODE_PARAMS(800000, VR4, Full), + __DEFINE_LINK_MODE_PARAMS(100000, KR, Full, K), + __DEFINE_LINK_MODE_PARAMS(100000, SR, Full, S), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(100000, LR_ER_FR, Full, + __MED(L) | __MED(E) | __MED(F)), + __DEFINE_LINK_MODE_PARAMS(100000, DR, Full, D), + __DEFINE_LINK_MODE_PARAMS(100000, CR, Full, C), + __DEFINE_LINK_MODE_PARAMS(200000, KR2, Full, K), + __DEFINE_LINK_MODE_PARAMS(200000, SR2, Full, S), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(200000, LR2_ER2_FR2, Full, + __MED(L) | __MED(E) | __MED(F)), + __DEFINE_LINK_MODE_PARAMS(200000, DR2, Full, D), + __DEFINE_LINK_MODE_PARAMS(200000, CR2, Full, C), + __DEFINE_LINK_MODE_PARAMS(400000, KR4, Full, K), + __DEFINE_LINK_MODE_PARAMS(400000, SR4, Full, S), + __DEFINE_LINK_MODE_PARAMS_MEDIUMS(400000, LR4_ER4_FR4, Full, + __MED(L) | __MED(E) | __MED(F)), + __DEFINE_LINK_MODE_PARAMS(400000, DR4, Full, D), + __DEFINE_LINK_MODE_PARAMS(400000, CR4, Full, C), + __DEFINE_LINK_MODE_PARAMS(100, FX, Half, F), + __DEFINE_LINK_MODE_PARAMS(100, FX, Full, F), + __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1L, 1, 1, Full, T), + __DEFINE_LINK_MODE_PARAMS(800000, CR8, Full, C), + __DEFINE_LINK_MODE_PARAMS(800000, KR8, Full, K), + __DEFINE_LINK_MODE_PARAMS(800000, DR8, Full, D), + __DEFINE_LINK_MODE_PARAMS(800000, DR8_2, Full, D), + __DEFINE_LINK_MODE_PARAMS(800000, SR8, Full, S), + __DEFINE_LINK_MODE_PARAMS(800000, VR8, Full, V), + __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1S, 1, 1, Full, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1S, 1, 1, Half, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1S_P2MP, 1, 1, Half, T), + __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1BRR, 1, 1, Full, T), + __DEFINE_LINK_MODE_PARAMS(200000, CR, Full, C), + __DEFINE_LINK_MODE_PARAMS(200000, KR, Full, K), + __DEFINE_LINK_MODE_PARAMS(200000, DR, Full, D), + __DEFINE_LINK_MODE_PARAMS(200000, DR_2, Full, D), + __DEFINE_LINK_MODE_PARAMS(200000, SR, Full, S), + __DEFINE_LINK_MODE_PARAMS(200000, VR, Full, V), + __DEFINE_LINK_MODE_PARAMS(400000, CR2, Full, C), + __DEFINE_LINK_MODE_PARAMS(400000, KR2, Full, K), + __DEFINE_LINK_MODE_PARAMS(400000, DR2, Full, D), + __DEFINE_LINK_MODE_PARAMS(400000, DR2_2, Full, D), + __DEFINE_LINK_MODE_PARAMS(400000, SR2, Full, S), + __DEFINE_LINK_MODE_PARAMS(400000, VR2, Full, V), + __DEFINE_LINK_MODE_PARAMS(800000, CR4, Full, C), + __DEFINE_LINK_MODE_PARAMS(800000, KR4, Full, K), + __DEFINE_LINK_MODE_PARAMS(800000, DR4, Full, D), + __DEFINE_LINK_MODE_PARAMS(800000, DR4_2, Full, D), + __DEFINE_LINK_MODE_PARAMS(800000, SR4, Full, S), + __DEFINE_LINK_MODE_PARAMS(800000, VR4, Full, V), }; static_assert(ARRAY_SIZE(link_mode_params) =3D=3D __ETHTOOL_LINK_MODE_MASK= _NBITS); EXPORT_SYMBOL_GPL(link_mode_params); --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 54F9D368E11; Thu, 20 Nov 2025 20:55:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672139; cv=none; b=d3MQ8jXn6XpJIqibYEX+14Y+HcrZByIMWjZzv7QCsCWZvPUVf/Ki4+IfMkbMCb1cWoDh24FEF5TLCqFit5w6YrfzLXdudm0TE+UlkiTUk933dpLmtkgnVjQePDYoYVcOEQFYNUhZY62yORm1Rlow1U9dIXVWIpfNgRqSwhvNdM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672139; c=relaxed/simple; bh=1Qzewlejoa39+teK8rlGsTUztkfvPm/M1lH4AGzYpXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W2+8IytfO6D6sUpdUTeWnVZC5ucXdnUMWN/84CUC9PEVm7T+jtyXgcHsq23rlqFw0maJXCh6w69QBK4BlW2YM2qp3pdLbTOryC0CEu+xO3Zs7h0aqk/uChb7Xp9QLEn46RScrORnv/PPohEmczDrkrG5xQxCjz3H/SUquRG97HM= 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=sP/OT9hs; arc=none smtp.client-ip=185.171.202.116 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="sP/OT9hs" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id AA788C111B0; Thu, 20 Nov 2025 20:55:12 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 0610A606F6; Thu, 20 Nov 2025 20:55:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 644E210371BCA; Thu, 20 Nov 2025 21:55:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672133; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=zRGNlmy1hXmaS4gyh3nAaOOsK3X7Ev1m7aFpN+6rDno=; b=sP/OT9hs2kYAmlRd9QgYkoxaQy3FbDMJj10sf8JHZ3mayY6MLxjIWcm1ZHfjclBE8Kk9p9 W476RngcSWjNRmaXwX4oTn6Xphhx8TzdfY77NfpTXMQV5poTDcTc1elP6WPyOJ2XSl4b8h kdiPXWIzWmnD53e+sFLTESQ+GbS8zjS8TUYL6w6ypiTiHnJxH+x0u90fmIP2lULTEA2v74 vSHogOTCRGfdKJyRdNHtjqUqyBxyyIEbSWxzHD/WsC6ljoUPKAjiQ4UBpHB1UusNqmwKeK iVwPZb7z6FY/4Uj1KJ+gioKpH76agoUfu2lApy92+5//uUpgUN5mjVixFyzZ+A== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 03/15] net: phy: Introduce PHY ports representation Date: Thu, 20 Nov 2025 21:54:53 +0100 Message-ID: <20251120205508.553909-4-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Ethernet provides a wide variety of layer 1 protocols and standards for data transmission. The front-facing ports of an interface have their own complexity and configurability. Introduce a representation of these front-facing ports. The current code is minimalistic and only support ports controlled by PHY devices, but the plan is to extend that to SFP as well as raw Ethernet MACs that don't use PHY devices. This minimal port representation allows describing the media and number of pairs of a BaseT port. From that information, we can derive the linkmodes usable on the port, which can be used to limit the capabilities of an interface. For now, the port pairs and medium is derived from devicetree, defined by the PHY driver, or populated with default values (as we assume that all PHYs expose at least one port). The typical example is 100M ethernet. 100BaseT can work using only 2 pairs on a Cat 5 cables. However, in the situation where a 10/100/1000 capable PHY is wired to its RJ45 port through 2 pairs only, we have no way of detecting that. The "max-speed" DT property can be used, but a more accurate representation can be used : mdi { connector-0 { media =3D "BaseT"; pairs =3D <2>; }; }; From that information, we can derive the max speed reachable on the port. Another benefit of having that is to avoid vendor-specific DT properties (micrel,fiber-mode or ti,fiber-mode). This basic representation is meant to be expanded, by the introduction of port ops, userspace listing of ports, and support for multi-port devices. Reviewed-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- MAINTAINERS | 7 ++ drivers/net/phy/Makefile | 2 +- drivers/net/phy/phy-caps.h | 5 + drivers/net/phy/phy-core.c | 6 ++ drivers/net/phy/phy_caps.c | 57 +++++++++++ drivers/net/phy/phy_device.c | 190 +++++++++++++++++++++++++++++++++++ drivers/net/phy/phy_port.c | 153 ++++++++++++++++++++++++++++ include/linux/ethtool.h | 11 ++ include/linux/phy.h | 55 ++++++++++ include/linux/phy_port.h | 96 ++++++++++++++++++ net/ethtool/common.c | 27 +++++ 11 files changed, 608 insertions(+), 1 deletion(-) create mode 100644 drivers/net/phy/phy_port.c create mode 100644 include/linux/phy_port.h diff --git a/MAINTAINERS b/MAINTAINERS index 0f4fb37e77b1..e0dc230df90e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17978,6 +17978,13 @@ F: drivers/net/phy/phy_link_topology.c F: include/linux/phy_link_topology.h F: net/ethtool/phy.c =20 +NETWORKING [ETHTOOL PHY PORT] +M: Maxime Chevallier +F: Documentation/devicetree/bindings/net/ethernet-connector.yaml +F: drivers/net/phy/phy_port.c +F: include/linux/phy_port.h +K: struct\s+phy_port|phy_port_ + NETWORKING [GENERAL] M: "David S. Miller" M: Eric Dumazet diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 76e0db40f879..3a34917adea7 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -3,7 +3,7 @@ =20 libphy-y :=3D phy.o phy-c45.o phy-core.o phy_device.o \ linkmode.o phy_link_topology.o \ - phy_caps.o mdio_bus_provider.o + phy_caps.o mdio_bus_provider.o phy_port.o mdio-bus-y +=3D mdio_bus.o mdio_device.o =20 ifdef CONFIG_PHYLIB diff --git a/drivers/net/phy/phy-caps.h b/drivers/net/phy/phy-caps.h index b7f0c6a3037a..c94b9c852563 100644 --- a/drivers/net/phy/phy-caps.h +++ b/drivers/net/phy/phy-caps.h @@ -60,4 +60,9 @@ const struct link_capabilities * phy_caps_lookup(int speed, unsigned int duplex, const unsigned long *suppo= rted, bool exact); =20 +void phy_caps_medium_get_supported(unsigned long *supported, + enum ethtool_link_medium medium, + int lanes); +u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes); + #endif /* __PHY_CAPS_H */ diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 0c63e6ba2cb0..4dfdb902b2e7 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -4,6 +4,7 @@ */ #include #include +#include #include =20 #include "phylib.h" @@ -206,7 +207,12 @@ EXPORT_SYMBOL_GPL(phy_interface_num_ports); =20 static void __set_phy_supported(struct phy_device *phydev, u32 max_speed) { + struct phy_port *port; + phy_caps_linkmode_max_speed(max_speed, phydev->supported); + + phy_for_each_port(phydev, port) + phy_caps_linkmode_max_speed(max_speed, port->supported); } =20 /** diff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c index 9a5e293c5104..080a09f29311 100644 --- a/drivers/net/phy/phy_caps.c +++ b/drivers/net/phy/phy_caps.c @@ -384,3 +384,60 @@ unsigned long phy_caps_from_interface(phy_interface_t = interface) return link_caps; } EXPORT_SYMBOL_GPL(phy_caps_from_interface); + +/** + * phy_caps_medium_get_supported() - Returns linkmodes supported on a give= n medium + * @supported: After this call, contains all possible linkmodes on a given= medium, + * and with the given number of pairs, or less. + * @medium: The medium to get the support from + * @pairs: The number of pairs used on the given medium. Only relevant for= modes + * that support this notion, such as BaseT. Pass 0 if not applicable. + * + * If no match exists, the supported field is left untouched. + */ +void phy_caps_medium_get_supported(unsigned long *supported, + enum ethtool_link_medium medium, + int pairs) +{ + int i; + + for (i =3D 0; i < __ETHTOOL_LINK_MODE_MASK_NBITS; i++) { + /* Special bits such as Autoneg, Pause, Asym_pause, etc. are + * set and will be masked away by the port parent. + */ + if (link_mode_params[i].mediums =3D=3D BIT(ETHTOOL_LINK_MEDIUM_NONE)) { + linkmode_set_bit(i, supported); + continue; + } + + /* If this medium matches, and had a non-zero min-pairs */ + if (link_mode_params[i].mediums & BIT(medium) && + (!link_mode_params[i].min_pairs || + (link_mode_params[i].min_pairs <=3D pairs && + link_mode_params[i].pairs >=3D pairs))) + linkmode_set_bit(i, supported); + } +} +EXPORT_SYMBOL_GPL(phy_caps_medium_get_supported); + +/** + * phy_caps_mediums_from_linkmodes() - Get all mediums from a linkmodes li= st + * @linkmodes: A bitset of linkmodes to get the mediums from + * + * Returns: A bitset of ETHTOOL_MEDIUM_XXX values corresponding to all med= ium + * types in the linkmodes list + */ +u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes) +{ + const struct link_mode_info *linkmode; + u32 mediums =3D 0; + int i; + + for_each_set_bit(i, linkmodes, __ETHTOOL_LINK_MODE_MASK_NBITS) { + linkmode =3D &link_mode_params[i]; + mediums |=3D linkmode->mediums; + } + + return mediums; +} +EXPORT_SYMBOL_GPL(phy_caps_mediums_from_linkmodes); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 81984d4ebb7c..f48565c3a9b8 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -845,6 +846,13 @@ struct phy_device *phy_device_create(struct mii_bus *b= us, int addr, u32 phy_id, =20 dev->state =3D PHY_DOWN; INIT_LIST_HEAD(&dev->leds); + INIT_LIST_HEAD(&dev->ports); + + /* The driver's probe function must change that to the real number + * of ports possible on the PHY. We assume by default we are dealing + * with a single-port PHY + */ + dev->max_n_ports =3D 1; =20 mutex_init(&dev->lock); INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); @@ -1590,6 +1598,51 @@ void phy_sfp_detach(void *upstream, struct sfp_bus *= bus) } EXPORT_SYMBOL(phy_sfp_detach); =20 +static int phy_add_port(struct phy_device *phydev, struct phy_port *port) +{ + int ret =3D 0; + + if (phydev->n_ports =3D=3D phydev->max_n_ports) + return -EBUSY; + + /* We set all ports as active by default, PHY drivers may deactivate + * them (when unused) + */ + port->active =3D true; + + if (port->is_mii) { + if (phydev->drv && phydev->drv->attach_mii_port) + ret =3D phydev->drv->attach_mii_port(phydev, port); + } else { + if (phydev->drv && phydev->drv->attach_mdi_port) + ret =3D phydev->drv->attach_mdi_port(phydev, port); + } + + if (ret) + return ret; + + /* The PHY driver might have added, removed or set medium/pairs info, + * so update the port supported accordingly. + */ + phy_port_update_supported(port); + + list_add(&port->head, &phydev->ports); + + phydev->n_ports++; + + return 0; +} + +static void phy_del_port(struct phy_device *phydev, struct phy_port *port) +{ + if (!phydev->n_ports) + return; + + list_del(&port->head); + + phydev->n_ports--; +} + /** * phy_sfp_probe - probe for a SFP cage attached to this PHY device * @phydev: Pointer to phy_device @@ -3325,6 +3378,136 @@ static int of_phy_leds(struct phy_device *phydev) return 0; } =20 +static void phy_cleanup_ports(struct phy_device *phydev) +{ + struct phy_port *tmp, *port; + + list_for_each_entry_safe(port, tmp, &phydev->ports, head) { + phy_del_port(phydev, port); + phy_port_destroy(port); + } +} + +static int phy_default_setup_single_port(struct phy_device *phydev) +{ + struct phy_port *port =3D phy_port_alloc(); + unsigned long mode; + + if (!port) + return -ENOMEM; + + port->parent_type =3D PHY_PORT_PHY; + port->phy =3D phydev; + + /* Let the PHY driver know that this port was never described anywhere. + * This is the usual case, where we assume single-port PHY devices with + * no SFP. In that case, the port supports exactly the same thing as + * the PHY itself. + * + * However, this can also be because we have a combo-port PHY, with + * only one port described in DT, through SFP for example. + * + * In that case, the PHY driver will be in charge of saying what we can + * do on that non-represented port. + */ + port->not_described =3D true; + linkmode_copy(port->supported, phydev->supported); + port->mediums =3D phy_caps_mediums_from_linkmodes(port->supported); + + for_each_set_bit(mode, port->supported, __ETHTOOL_LINK_MODE_MASK_NBITS) + port->pairs =3D max_t(int, port->pairs, + ethtool_linkmode_n_pairs(mode)); + + phy_add_port(phydev, port); + + return 0; +} + +static int of_phy_ports(struct phy_device *phydev) +{ + struct device_node *node =3D phydev->mdio.dev.of_node; + struct device_node *mdi; + struct phy_port *port; + int err; + + if (!IS_ENABLED(CONFIG_OF_MDIO)) + return 0; + + if (!node) + return 0; + + mdi =3D of_get_child_by_name(node, "mdi"); + if (!mdi) + return 0; + + for_each_available_child_of_node_scoped(mdi, port_node) { + port =3D phy_of_parse_port(port_node); + if (IS_ERR(port)) { + err =3D PTR_ERR(port); + goto out_err; + } + + port->parent_type =3D PHY_PORT_PHY; + port->phy =3D phydev; + err =3D phy_add_port(phydev, port); + if (err) + goto out_err; + } + of_node_put(mdi); + + return 0; + +out_err: + phy_cleanup_ports(phydev); + of_node_put(mdi); + return err; +} + +static int phy_setup_ports(struct phy_device *phydev) +{ + __ETHTOOL_DECLARE_LINK_MODE_MASK(ports_supported); + struct phy_port *port; + int ret; + + ret =3D of_phy_ports(phydev); + if (ret) + return ret; + + if (phydev->n_ports < phydev->max_n_ports) { + ret =3D phy_default_setup_single_port(phydev); + if (ret) + goto out; + } + + linkmode_zero(ports_supported); + + /* Aggregate the supported modes, which are made-up of : + * - What the PHY itself supports + * - What the sum of all ports support + */ + list_for_each_entry(port, &phydev->ports, head) + if (port->active) + linkmode_or(ports_supported, ports_supported, + port->supported); + + if (!linkmode_empty(ports_supported)) + linkmode_and(phydev->supported, phydev->supported, + ports_supported); + + /* For now, the phy->port field is set as the first active port's type */ + list_for_each_entry(port, &phydev->ports, head) + if (port->active) { + phydev->port =3D phy_port_get_type(port); + break; + } + + return 0; + +out: + phy_cleanup_ports(phydev); + return ret; +} + /** * fwnode_mdio_find_device - Given a fwnode, find the mdio_device * @fwnode: pointer to the mdio_device's fwnode @@ -3462,6 +3645,11 @@ static int phy_probe(struct device *dev) phydev->is_gigabit_capable =3D 1; =20 of_set_phy_supported(phydev); + + err =3D phy_setup_ports(phydev); + if (err) + goto out; + phy_advertise_supported(phydev); =20 /* Get PHY default EEE advertising modes and handle them as potentially @@ -3537,6 +3725,8 @@ static int phy_remove(struct device *dev) =20 phydev->state =3D PHY_DOWN; =20 + phy_cleanup_ports(phydev); + sfp_bus_del_upstream(phydev->sfp_bus); phydev->sfp_bus =3D NULL; =20 diff --git a/drivers/net/phy/phy_port.c b/drivers/net/phy/phy_port.c new file mode 100644 index 000000000000..0502fe60da3e --- /dev/null +++ b/drivers/net/phy/phy_port.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Framework to drive Ethernet ports + * + * Copyright (c) 2024 Maxime Chevallier + */ + +#include +#include +#include + +#include "phy-caps.h" + +/** + * phy_port_alloc() - Allocate a new phy_port + * + * Returns: a newly allocated struct phy_port, or NULL. + */ +struct phy_port *phy_port_alloc(void) +{ + struct phy_port *port; + + port =3D kzalloc(sizeof(*port), GFP_KERNEL); + if (!port) + return NULL; + + linkmode_zero(port->supported); + INIT_LIST_HEAD(&port->head); + + return port; +} +EXPORT_SYMBOL_GPL(phy_port_alloc); + +/** + * phy_port_destroy() - Free a struct phy_port + * @port: The port to destroy + */ +void phy_port_destroy(struct phy_port *port) +{ + kfree(port); +} +EXPORT_SYMBOL_GPL(phy_port_destroy); + +/** + * phy_of_parse_port() - Create a phy_port from a firmware representation + * @dn: device_node representation of the port, following the + * ethernet-connector.yaml binding + * + * Returns: a newly allocated and initialized phy_port pointer, or an ERR_= PTR. + */ +struct phy_port *phy_of_parse_port(struct device_node *dn) +{ + struct fwnode_handle *fwnode =3D of_fwnode_handle(dn); + enum ethtool_link_medium medium; + struct phy_port *port; + const char *med_str; + u32 pairs =3D 0, mediums =3D 0; + int ret; + + ret =3D fwnode_property_read_string(fwnode, "media", &med_str); + if (ret) + return ERR_PTR(ret); + + medium =3D ethtool_str_to_medium(med_str); + if (medium =3D=3D ETHTOOL_LINK_MEDIUM_NONE) + return ERR_PTR(-EINVAL); + + if (pairs && medium !=3D ETHTOOL_LINK_MEDIUM_BASET) { + pr_err("pairs property is only compatible with BaseT medium\n"); + return ERR_PTR(-EINVAL); + } + + if (medium =3D=3D ETHTOOL_LINK_MEDIUM_BASET) { + ret =3D fwnode_property_read_u32(fwnode, "pairs", &pairs); + if (ret) + return ERR_PTR(ret); + + switch (pairs) { + case 1: /* BaseT1 */ + case 2: /* 100BaseTX */ + case 4: + break; + default: + pr_err("%u is not a valid number of pairs\n", pairs); + return ERR_PTR(-EINVAL); + } + } + + mediums |=3D BIT(medium); + + if (!mediums) + return ERR_PTR(-EINVAL); + + port =3D phy_port_alloc(); + if (!port) + return ERR_PTR(-ENOMEM); + + port->pairs =3D pairs; + port->mediums =3D mediums; + + return port; +} +EXPORT_SYMBOL_GPL(phy_of_parse_port); + +/** + * phy_port_update_supported() - Setup the port->supported field + * @port: the port to update + * + * Once the port's medium list and number of pairs has been configured bas= ed + * on firmware, straps and vendor-specific properties, this function may be + * called to update the port's supported linkmodes list. + * + * Any mode that was manually set in the port's supported list remains set. + */ +void phy_port_update_supported(struct phy_port *port) +{ + __ETHTOOL_DECLARE_LINK_MODE_MASK(supported) =3D { 0 }; + unsigned long mode; + int i; + + for_each_set_bit(i, &port->mediums, __ETHTOOL_LINK_MEDIUM_LAST) { + linkmode_zero(supported); + phy_caps_medium_get_supported(supported, i, port->pairs); + linkmode_or(port->supported, port->supported, supported); + } + + /* If there's no pairs specified, we grab the default number of + * pairs as the max of the default pairs for each linkmode + */ + if (!port->pairs) + for_each_set_bit(mode, port->supported, + __ETHTOOL_LINK_MODE_MASK_NBITS) + port->pairs =3D max_t(int, port->pairs, + ethtool_linkmode_n_pairs(mode)); +} +EXPORT_SYMBOL_GPL(phy_port_update_supported); + +/** + * phy_port_get_type() - get the PORT_* attribute for that port. + * @port: The port we want the information from + * + * Returns: A PORT_XXX value. + */ +int phy_port_get_type(struct phy_port *port) +{ + if (port->mediums & BIT(ETHTOOL_LINK_MEDIUM_BASET)) + return PORT_TP; + + if (phy_port_is_fiber(port)) + return PORT_FIBRE; + + return PORT_OTHER; +} +EXPORT_SYMBOL_GPL(phy_port_get_type); diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 37aede6af96f..798abec67a1b 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -242,6 +242,17 @@ enum ethtool_link_medium { __ETHTOOL_LINK_MEDIUM_LAST, }; =20 +#define ETHTOOL_MEDIUM_FIBER_BITS (BIT(ETHTOOL_LINK_MEDIUM_BASES) | \ + BIT(ETHTOOL_LINK_MEDIUM_BASEL) | \ + BIT(ETHTOOL_LINK_MEDIUM_BASEF)) + +enum ethtool_link_medium ethtool_str_to_medium(const char *str); + +static inline int ethtool_linkmode_n_pairs(unsigned int mode) +{ + return link_mode_params[mode].pairs; +} + /* declare a link mode bitmap */ #define __ETHTOOL_DECLARE_LINK_MODE_MASK(name) \ DECLARE_BITMAP(name, __ETHTOOL_LINK_MODE_MASK_NBITS) diff --git a/include/linux/phy.h b/include/linux/phy.h index 65b0c3ca6a2b..36f55ad09907 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -327,6 +327,7 @@ static inline long rgmii_clock(int speed) struct device; struct kernel_hwtstamp_config; struct phylink; +struct phy_port; struct sfp_bus; struct sfp_upstream_ops; struct sk_buff; @@ -621,6 +622,9 @@ struct macsec_ops; * @master_slave_state: Current master/slave configuration * @mii_ts: Pointer to time stamper callbacks * @psec: Pointer to Power Sourcing Equipment control struct + * @ports: List of PHY ports structures + * @n_ports: Number of ports currently attached to the PHY + * @max_n_ports: Max number of ports this PHY can expose * @lock: Mutex for serialization access to PHY * @state_queue: Work queue for state machine * @link_down_events: Number of times link was lost @@ -758,6 +762,10 @@ struct phy_device { struct mii_timestamper *mii_ts; struct pse_control *psec; =20 + struct list_head ports; + int n_ports; + int max_n_ports; + u8 mdix; u8 mdix_ctrl; =20 @@ -780,6 +788,9 @@ struct phy_device { =20 #define to_phy_device(__dev) container_of_const(to_mdio_device(__dev), str= uct phy_device, mdio) =20 +#define phy_for_each_port(phydev, port) \ + list_for_each_entry(port, &(phydev)->ports, head) + /** * struct phy_tdr_config - Configuration of a TDR raw test * @@ -1480,6 +1491,49 @@ struct phy_driver { * Returns the time in jiffies until the next update event. */ unsigned int (*get_next_update_time)(struct phy_device *dev); + + /** + * @attach_mii_port: Attach the given MII port to the PHY device + * @dev: PHY device to notify + * @port: The port being added + * + * Called when an MII port that needs to be driven by the PHY is found. + * + * The port that is being passed may or may not be initialized. If it is + * already initialized, it is by the generic port representation from + * devicetree, which superseeds any strapping or vendor-specific + * properties. + * + * If the port isn't initialized, the port->mediums and port->lanes + * fields must be set, possibly according to strapping information. + * + * The PHY driver must set the port->interfaces field to indicate the + * possible MII modes that this PHY can output on the port. + * + * Returns 0, or an error code. + */ + int (*attach_mii_port)(struct phy_device *dev, struct phy_port *port); + + /** + * @attach_mdi_port: Attach the given MII port to the PHY device + * @dev: PHY device to notify + * @port: The port being added + * + * Called when a port that needs to be driven by the PHY is found. The + * number of time this will be called depends on phydev->max_n_ports, + * which the driver can change in .probe(). + * + * The port that is being passed may or may not be initialized. If it is + * already initialized, it is by the generic port representation from + * devicetree, which superseeds any strapping or vendor-specific + * properties. + * + * If the port isn't initialized, the port->mediums and port->lanes + * fields must be set, possibly according to strapping information. + * + * Returns 0, or an error code. + */ + int (*attach_mdi_port)(struct phy_device *dev, struct phy_port *port); }; #define to_phy_driver(d) container_of_const(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv) @@ -2281,6 +2335,7 @@ void phy_trigger_machine(struct phy_device *phydev); void phy_mac_interrupt(struct phy_device *phydev); void phy_start_machine(struct phy_device *phydev); void phy_stop_machine(struct phy_device *phydev); + void phy_ethtool_ksettings_get(struct phy_device *phydev, struct ethtool_link_ksettings *cmd); int phy_ethtool_ksettings_set(struct phy_device *phydev, diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h new file mode 100644 index 000000000000..ce0208fbccf7 --- /dev/null +++ b/include/linux/phy_port.h @@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __PHY_PORT_H +#define __PHY_PORT_H + +#include +#include +#include + +struct phy_port; + +/** + * enum phy_port_parent - The device this port is attached to + * + * @PHY_PORT_PHY: Indicates that the port is driven by a PHY device + */ +enum phy_port_parent { + PHY_PORT_PHY, +}; + +struct phy_port_ops { + /* Sometimes, the link state can be retrieved from physical, + * out-of-band channels such as the LOS signal on SFP. These + * callbacks allows notifying the port about state changes + */ + void (*link_up)(struct phy_port *port); + void (*link_down)(struct phy_port *port); + + /* If the port acts as a Media Independent Interface (Serdes port), + * configures the port with the relevant state and mode. When enable is + * not set, interface should be ignored + */ + int (*configure_mii)(struct phy_port *port, bool enable, phy_interface_t = interface); +}; + +/** + * struct phy_port - A representation of a network device physical interfa= ce + * + * @head: Used by the port's parent to list ports + * @parent_type: The type of device this port is directly connected to + * @phy: If the parent is PHY_PORT_PHYDEV, the PHY controlling that port + * @ops: Callback ops implemented by the port controller + * @pairs: The number of pairs this port has, 0 if not applicable + * @mediums: Bitmask of the physical mediums this port provides access to + * @supported: The link modes this port can expose, if this port is MDI (n= ot MII) + * @interfaces: The MII interfaces this port supports, if this port is MII + * @not_described: Indicates to the parent driver if this port isn't descr= ibed, + * so it's up to the parent to filter its capabilities. + * @active: Indicates if the port is currently part of the active link. + * @is_mii: Indicates if this port is MII (Media Independent Interface), + * or MDI (Media Dependent Interface). + */ +struct phy_port { + struct list_head head; + enum phy_port_parent parent_type; + union { + struct phy_device *phy; + }; + + const struct phy_port_ops *ops; + + int pairs; + unsigned long mediums; + __ETHTOOL_DECLARE_LINK_MODE_MASK(supported); + DECLARE_PHY_INTERFACE_MASK(interfaces); + + unsigned int not_described:1; + unsigned int active:1; + unsigned int is_mii:1; +}; + +struct phy_port *phy_port_alloc(void); +void phy_port_destroy(struct phy_port *port); + +static inline struct phy_device *port_phydev(struct phy_port *port) +{ + return port->phy; +} + +struct phy_port *phy_of_parse_port(struct device_node *dn); + +static inline bool phy_port_is_copper(struct phy_port *port) +{ + return port->mediums =3D=3D BIT(ETHTOOL_LINK_MEDIUM_BASET); +} + +static inline bool phy_port_is_fiber(struct phy_port *port) +{ + return !!(port->mediums & ETHTOOL_MEDIUM_FIBER_BITS); +} + +void phy_port_update_supported(struct phy_port *port); + +int phy_port_get_type(struct phy_port *port); + +#endif diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 2f4b70f104e8..42d524902d5b 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -460,6 +460,21 @@ const struct link_mode_info link_mode_params[] =3D { static_assert(ARRAY_SIZE(link_mode_params) =3D=3D __ETHTOOL_LINK_MODE_MASK= _NBITS); EXPORT_SYMBOL_GPL(link_mode_params); =20 +static const char ethtool_link_medium_names[][ETH_GSTRING_LEN] =3D { + [ETHTOOL_LINK_MEDIUM_BASET] =3D "BaseT", + [ETHTOOL_LINK_MEDIUM_BASEK] =3D "BaseK", + [ETHTOOL_LINK_MEDIUM_BASES] =3D "BaseS", + [ETHTOOL_LINK_MEDIUM_BASEC] =3D "BaseC", + [ETHTOOL_LINK_MEDIUM_BASEL] =3D "BaseL", + [ETHTOOL_LINK_MEDIUM_BASED] =3D "BaseD", + [ETHTOOL_LINK_MEDIUM_BASEE] =3D "BaseE", + [ETHTOOL_LINK_MEDIUM_BASEF] =3D "BaseF", + [ETHTOOL_LINK_MEDIUM_BASEV] =3D "BaseV", + [ETHTOOL_LINK_MEDIUM_BASEMLD] =3D "BaseMLD", + [ETHTOOL_LINK_MEDIUM_NONE] =3D "None", +}; +static_assert(ARRAY_SIZE(ethtool_link_medium_names) =3D=3D __ETHTOOL_LINK_= MEDIUM_LAST); + const char netif_msg_class_names[][ETH_GSTRING_LEN] =3D { [NETIF_MSG_DRV_BIT] =3D "drv", [NETIF_MSG_PROBE_BIT] =3D "probe", @@ -1193,3 +1208,15 @@ void ethtool_rxfh_context_lost(struct net_device *de= v, u32 context_id) ethtool_rss_notify(dev, ETHTOOL_MSG_RSS_DELETE_NTF, context_id); } EXPORT_SYMBOL(ethtool_rxfh_context_lost); + +enum ethtool_link_medium ethtool_str_to_medium(const char *str) +{ + int i; + + for (i =3D 0; i < __ETHTOOL_LINK_MEDIUM_LAST; i++) + if (!strcmp(ethtool_link_medium_names[i], str)) + return i; + + return ETHTOOL_LINK_MEDIUM_NONE; +} +EXPORT_SYMBOL_GPL(ethtool_str_to_medium); --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 3FD5136B05B; Thu, 20 Nov 2025 20:55:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672142; cv=none; b=FKZHs9s+VMN8/vFcBlYx6tW1BMEn6jMySmVljYIq2p/ZH29ZLOH3TwtdLsPR8zi9i8GiWW+zzt+5qS1brQ0p/xRhv1LwwwcweJofjCwcy/cnbMeLkvpsNkiYDggmz8QP/SDQjPA8BjoUtVPUxwZPz0aYpWDOD1fdJHEvD1swHvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672142; c=relaxed/simple; bh=pi/yUiE0GLIh3NoCUC5adF6wKjp71KSefaDgIXV/uPc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iGnnRDqV9iUDej/v5+2QSVCIGH9TdujG25VG3vFzK+M+oNYOHuSizEaEG2DRki+SZTMAD1WsrLvaEEBk4fKo2BfuKvDvnRzHkLcMcLGDcAaDLT1LOW3sIqZkjh8JldWAAnJ6waFG71sR6QgUAkywjrTE+s9RZmSUS1sCAMC3HAQ= 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=u63LDw+z; arc=none smtp.client-ip=185.246.85.4 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="u63LDw+z" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 91D154E41811; Thu, 20 Nov 2025 20:55:38 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 66A1B606F6; Thu, 20 Nov 2025 20:55:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id C5D1E10371BCD; Thu, 20 Nov 2025 21:55:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672136; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=KSlMJCkHN3qoiesq+GZbeTPd6cykEBxG8JM7oiO9bAg=; b=u63LDw+zxl227n8atSyeD9uuhfKhW6FZiz/XIR1bW69ICQvlWTfyirupMzK4u11d1RV51n StvJayfd7W4iEEbuCOGYyRXsGmacF4PT4A8rhVwLXMHVBMlpdlP1IM28CPG6uVXhdkkx01 CkzY85j6plp0AlxO27GmSy/7u4zUgKsi4AvilUIYtPrHNDM5YEDfzkBRGbgfd7dbLIHwTu nLmRB+gdssUSvxoJygV/8Z0/ksijan44uocs6zfHlYwr559PR40WADWvNAwVxuLwFNP2Qf cCWKb1uef0RPMbN4C5MRSARASuLw6Y5w/J+IlTziqrO62hjL1fsyGHTin5Q4tw== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 04/15] net: phy: dp83822: Add support for phy_port representation Date: Thu, 20 Nov 2025 21:54:54 +0100 Message-ID: <20251120205508.553909-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" With the phy_port representation introduced, we can use .attach_port to populate the port information based on either the straps or the ti,fiber-mode property. This allows simplifying the probe function and allow users to override the strapping configuration. Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/dp83822.c | 71 +++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/drivers/net/phy/dp83822.c b/drivers/net/phy/dp83822.c index 33db21251f2e..c012dfab3171 100644 --- a/drivers/net/phy/dp83822.c +++ b/drivers/net/phy/dp83822.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include =20 @@ -811,17 +812,6 @@ static int dp83822_of_init(struct phy_device *phydev) int i, ret; u32 val; =20 - /* Signal detection for the PHY is only enabled if the FX_EN and the - * SD_EN pins are strapped. Signal detection can only enabled if FX_EN - * is strapped otherwise signal detection is disabled for the PHY. - */ - if (dp83822->fx_enabled && dp83822->fx_sd_enable) - dp83822->fx_signal_det_low =3D device_property_present(dev, - "ti,link-loss-low"); - if (!dp83822->fx_enabled) - dp83822->fx_enabled =3D device_property_present(dev, - "ti,fiber-mode"); - if (!device_property_read_string(dev, "ti,gpio2-clk-out", &of_val)) { if (strcmp(of_val, "mac-if") =3D=3D 0) { dp83822->gpio2_clk_out =3D DP83822_CLK_SRC_MAC_IF; @@ -950,6 +940,48 @@ static int dp83822_read_straps(struct phy_device *phyd= ev) return 0; } =20 +static int dp83822_attach_mdi_port(struct phy_device *phydev, + struct phy_port *port) +{ + struct dp83822_private *dp83822 =3D phydev->priv; + int ret; + + if (port->mediums) { + if (phy_port_is_fiber(port)) + dp83822->fx_enabled =3D true; + } else { + ret =3D dp83822_read_straps(phydev); + if (ret) + return ret; + +#if IS_ENABLED(CONFIG_OF_MDIO) + if (dp83822->fx_enabled && dp83822->fx_sd_enable) + dp83822->fx_signal_det_low =3D + device_property_present(&phydev->mdio.dev, + "ti,link-loss-low"); + + /* ti,fiber-mode is still used for backwards compatibility, but + * has been replaced with the mdi node definition, see + * ethernet-port.yaml + */ + if (!dp83822->fx_enabled) + dp83822->fx_enabled =3D + device_property_present(&phydev->mdio.dev, + "ti,fiber-mode"); +#endif /* CONFIG_OF_MDIO */ + + if (dp83822->fx_enabled) { + port->mediums =3D BIT(ETHTOOL_LINK_MEDIUM_BASEF); + } else { + /* This PHY can only to 100BaseTX max, so on 2 pairs */ + port->pairs =3D 2; + port->mediums =3D BIT(ETHTOOL_LINK_MEDIUM_BASET); + } + } + + return 0; +} + static int dp8382x_probe(struct phy_device *phydev) { struct dp83822_private *dp83822; @@ -968,27 +1000,13 @@ static int dp8382x_probe(struct phy_device *phydev) =20 static int dp83822_probe(struct phy_device *phydev) { - struct dp83822_private *dp83822; int ret; =20 ret =3D dp8382x_probe(phydev); if (ret) return ret; =20 - dp83822 =3D phydev->priv; - - ret =3D dp83822_read_straps(phydev); - if (ret) - return ret; - - ret =3D dp83822_of_init(phydev); - if (ret) - return ret; - - if (dp83822->fx_enabled) - phydev->port =3D PORT_FIBRE; - - return 0; + return dp83822_of_init(phydev); } =20 static int dp83826_probe(struct phy_device *phydev) @@ -1172,6 +1190,7 @@ static int dp83822_led_hw_control_get(struct phy_devi= ce *phydev, u8 index, .led_hw_is_supported =3D dp83822_led_hw_is_supported, \ .led_hw_control_set =3D dp83822_led_hw_control_set, \ .led_hw_control_get =3D dp83822_led_hw_control_get, \ + .attach_mdi_port =3D dp83822_attach_mdi_port \ } =20 #define DP83825_PHY_DRIVER(_id, _name) \ --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 469B236C5A1; Thu, 20 Nov 2025 20:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672145; cv=none; b=KdLDSkPXf9Q5LLS/KRpT2ZAvNIDeXWrkusj/n84028cy/mEjJvgt8qoLZkDNvjM/Uhg7yyLCA/K3slH4lgRWQaz1dTWD2W6vA+c6U94I/pvpSx2BNe000FdTQMwaLf+EQPkbz2NMr6Mb4zJXaVSo99iH7+sXH0cuLRRdYQe7B/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672145; c=relaxed/simple; bh=AWU+PLSApT8kjesX7dOkFXgGY2hpp0B4x81yGGBbha0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JzvUKtoo8pqPyZqpgYfcNPtFqHXkzbuSzlJChrB9Jv6DH+cxUdiAtuaofhlu2DUivI9jf2CtT7ZLNJ/2dJvuMOmei5d46wuSx66jRXcHsbX0jHjpSHAd2qZfmHTz12ZPU03qhonMcrEwdmiQvYGaP8tPSsNGcxzI2V4+HfvAHXo= 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=tb3fv+uj; arc=none smtp.client-ip=185.246.84.56 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="tb3fv+uj" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id C71911A1C19; Thu, 20 Nov 2025 20:55:41 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9B9AB606F6; Thu, 20 Nov 2025 20:55:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2CD2310371BD6; Thu, 20 Nov 2025 21:55:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672140; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=EguoN5UoBIxCjveRFklA6CdlXXdagmARsUp7EB8KNWQ=; b=tb3fv+ujNricuSdRrmIBAgCXlsvSDAQbfllIshkIzhhhFt83u2diALm9E03r4TLcpZttRl x42zlcfr0LA3AtR2MlBHZaIMEIqPk0/nyt4d5WhFZ85L7A6TdVZA+9Y3Elo+lAqflqkg0E zHLvWGdXSJuBIXiGfgUolE+PtHYbozNJRpS0si3MDDdz3uMEgKB3T/fE778gZoqpxfRpWJ /5gSLYfsUe/sTKaRuMB+4FPteP3FDaB7ppwLcx8NoGIYy/aBP4DlikEbsoQMXlmZBEzyby eSNQyvERPiTQfI6ZkXgMMtCOr98d4ujZuNLuQKi+2ZZCegZVvNsjSra650IF+g== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 05/15] dt-bindings: net: dp83822: Deprecate ti,fiber-mode Date: Thu, 20 Nov 2025 21:54:55 +0100 Message-ID: <20251120205508.553909-6-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The newly added ethernet-connector binding allows describing an Ethernet connector with greater precision, and in a more generic manner, than ti,fiber-mode. Deprecate this property. Reviewed-by: Rob Herring (Arm) Reviewed-by: Christophe Leroy Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- Documentation/devicetree/bindings/net/ti,dp83822.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/net/ti,dp83822.yaml b/Docume= ntation/devicetree/bindings/net/ti,dp83822.yaml index 28a0bddb9af9..23c70d863c39 100644 --- a/Documentation/devicetree/bindings/net/ti,dp83822.yaml +++ b/Documentation/devicetree/bindings/net/ti,dp83822.yaml @@ -47,6 +47,9 @@ properties: is disabled. In fiber mode, auto-negotiation is disabled and the PHY can only wo= rk in 100base-fx (full and half duplex) modes. + This property is deprecated, for details please refer to + Documentation/devicetree/bindings/net/ethernet-connector.yaml + deprecated: true =20 rx-internal-delay-ps: description: | @@ -141,7 +144,11 @@ examples: tx-internal-delay-ps =3D <1>; ti,gpio2-clk-out =3D "xi"; mac-termination-ohms =3D <43>; + mdi { + connector-0 { + media =3D "BaseF"; + }; + }; }; }; - ... --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 F1D8236B05B for ; Thu, 20 Nov 2025 20:55:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672149; cv=none; b=E385OzJmZvyiJZ+1bvNJ73A68Ul7gJoc6PBlU9GZsUEe1GEeaF64t9LKe6g/OJiZJJZwa+RPaAaP+7X7sV7xa8CPDB/NjeaovCPoZn9AxsJYamipt8AVCWmhlBAsI1nv8P+F96kq8i7laOPof0H92L6ifM3rpLLf7QnzQNmPKio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672149; c=relaxed/simple; bh=IcGYyGYeJra0a/n0iJzuDoZje8jd+zE7LoYkmi7TlSI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KmmRpvAzS0djwDm3lAo3qP6nOa+WcnoH2ePUdSlgdqOtsyQKdNCcLwVdPt4vjq9Fkm/Il1NVkAwTqfsnZxgQ4YHixhrpxb6eVHgc3iIdI8Zylup9Kifa2XimKEuKDm+0/CkV/agrW8j16k/4NmvXAhdBOfVfntGdo4NauF9AD+A= 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=oVU1rQZj; arc=none smtp.client-ip=185.246.85.4 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="oVU1rQZj" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 2D3AD4E41811; Thu, 20 Nov 2025 20:55:45 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 0022F606F6; Thu, 20 Nov 2025 20:55:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 85BAC10371BD8; Thu, 20 Nov 2025 21:55:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672143; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=VCtqMiTZqbHQ/q1ZrgDpE3C+9DphXwTOYBU9gv86OWM=; b=oVU1rQZjgThTvICPp5KCK6sAXYy65UkxBQfG8SeB2YoOvNQqjJhS5BjXlKXiR9zB0ulPBQ TAJp4bOaGrOxI/JauDoimFtXZ82ZUP6RnLAShCYvp5su+AiCt/ySI9bVhy4711f12ijIAx IxMXAyD2ibMuoe8hcAyhd1aNDp/kRjGL9CIbTyak1982DKjcjpFZwzlVPFWnkVxSGtXzN/ Hfzz4hHP1jKqmBN1caN5PvG0dVXmhcwrCBFPxcvBBwVDkxbS8gcBuESjg9SvWuCeRtMb59 y3kkJWvZo85xhUTLJI/5keS4ljOcrIXxwVvfeJueBrDauFqCBSrQe8fGuRF+7w== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 06/15] net: phy: Create a phy_port for PHY-driven SFPs Date: Thu, 20 Nov 2025 21:54:56 +0100 Message-ID: <20251120205508.553909-7-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 X-Rspamd-Fuzzy: f0a28691f7ec4acdd6a2650b9611bd90b8db1865e04a7f31d08e08ed4978660bd74e6f9d7b79f45cf671da8c3c71ec37e6f3c48ea0acdb78a09d500b02d2c7fd Content-Type: text/plain; charset="utf-8" Some PHY devices may be used as media-converters to drive SFP ports (for example, to allow using SFP when the SoC can only output RGMII). This is already supported to some extend by allowing PHY drivers to registers themselves as being SFP upstream. However, the logic to drive the SFP can actually be split to a per-port control logic, allowing support for multi-port PHYs, or PHYs that can either drive SFPs or Copper. To that extent, create a phy_port when registering an SFP bus onto a PHY. This port is considered a "serdes" port, in that it can feed data to another entity on the link. The PHY driver needs to specify the various PHY_INTERFACE_MODE_XXX that this port supports. Reviewed-by: Andrew Lunn Reviewed-by: Christophe Leroy Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_device.c | 24 ++++++++++++++++++++++++ drivers/net/phy/phy_port.c | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index f48565c3a9b8..3772c68b1dbc 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1643,6 +1643,26 @@ static void phy_del_port(struct phy_device *phydev, = struct phy_port *port) phydev->n_ports--; } =20 +static int phy_setup_sfp_port(struct phy_device *phydev) +{ + struct phy_port *port =3D phy_port_alloc(); + + if (!port) + return -ENOMEM; + + port->parent_type =3D PHY_PORT_PHY; + port->phy =3D phydev; + + /* The PHY is a media converter, the port connected to the SFP cage + * is a MII port. + */ + port->is_mii =3D true; + + phy_add_port(phydev, port); + + return 0; +} + /** * phy_sfp_probe - probe for a SFP cage attached to this PHY device * @phydev: Pointer to phy_device @@ -1664,6 +1684,10 @@ int phy_sfp_probe(struct phy_device *phydev, ret =3D sfp_bus_add_upstream(bus, phydev, ops); sfp_bus_put(bus); } + + if (phydev->sfp_bus) + ret =3D phy_setup_sfp_port(phydev); + return ret; } EXPORT_SYMBOL(phy_sfp_probe); diff --git a/drivers/net/phy/phy_port.c b/drivers/net/phy/phy_port.c index 0502fe60da3e..f89f70f83593 100644 --- a/drivers/net/phy/phy_port.c +++ b/drivers/net/phy/phy_port.c @@ -131,6 +131,21 @@ void phy_port_update_supported(struct phy_port *port) __ETHTOOL_LINK_MODE_MASK_NBITS) port->pairs =3D max_t(int, port->pairs, ethtool_linkmode_n_pairs(mode)); + + /* Serdes ports supported through SFP may not have any medium set, + * as they will output PHY_INTERFACE_MODE_XXX modes. In that case, derive + * the supported list based on these interfaces + */ + if (port->is_mii && linkmode_empty(supported)) { + unsigned long interface, link_caps =3D 0; + + /* Get each interface's caps */ + for_each_set_bit(interface, port->interfaces, + PHY_INTERFACE_MODE_MAX) + link_caps |=3D phy_caps_from_interface(interface); + + phy_caps_linkmodes(link_caps, port->supported); + } } EXPORT_SYMBOL_GPL(phy_port_update_supported); =20 --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 C16C136E9D8; Thu, 20 Nov 2025 20:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672152; cv=none; b=nhBVZoEVfs2GocmUsAIqEs54EcJFaTxdiqCuNILKfiGkqavNcvpOpALqDFyosb2wbiYoE9KC7YMox62kBx8Z7w3laSIqFSaZIEoMVHtLMTzcC8XjFsNaG49ABJWlDUXqiIPzncf0nAaGqnwubjpVethOCDqV0/kEe/DRW3Evm18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672152; c=relaxed/simple; bh=aRtUZtB/2IhSyS0iYSqarp5WdnsB0Gj3JMudc89jka4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YlI1mT8zpjk2+C0fQqDZrTJJwDH02waDxUhoPYClLBZzsNtJoPNZ0Z9Qe69k4naQQagq6lZ1/++xOqurKwsgZ/8pFSqmOfsz3nzgj2hAYvDCoumNzNLyhmpNB97MZAF9SA/GVmIxsuEDSIx/qG8cWNj9G7QNVo/Uy/UxZ+SJRXw= 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=E/FuIU8l; arc=none smtp.client-ip=185.171.202.116 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="E/FuIU8l" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 0E310C111AC; Thu, 20 Nov 2025 20:55:26 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 542A4606F6; Thu, 20 Nov 2025 20:55:48 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E90AE10371BEE; Thu, 20 Nov 2025 21:55:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672146; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=nbkAZIEf8Tu2wjsn82ZilWe0FCnGQR/YkMMymJ/j6Rs=; b=E/FuIU8lXPvIcTKWa+oPgsWICtOkFSc5pJGIsoTRWGRhEOAH0+PokcRLclOpuxWKN0VYX6 qLsGv9TPV2K636M3pIB+lpZ8enS0LRV7691TZF5pa/501lvQ2e//DmUvwyA31e3p1mg4M5 rCzcw5+xvZl/yUlG+QfPFeY1Fys2rjLuPMRJ7pHGi/YEtjGZQOWtMRwsRAazhEEWsEAD89 ARJ5hJne4YgTwteVpe2fR/uYoVzX952AAlb0pxyeyoDZgPi4LvM3wO9L9LjeFc2R2pkvC4 ZWE7Xcv3z147/e9Jv1pht6P0RcKrfw9c+M/OwP/mo4uA6caKo/zuKz/SvgDxfA== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 07/15] net: phy: Introduce generic SFP handling for PHY drivers Date: Thu, 20 Nov 2025 21:54:57 +0100 Message-ID: <20251120205508.553909-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" There are currently 4 PHY drivers that can drive downstream SFPs: marvell.c, marvell10g.c, at803x.c and marvell-88x2222.c. Most of the logic is boilerplate, either calling into generic phylib helpers (for SFP PHY attach, bus attach, etc.) or performing the same tasks with a bit of validation : - Getting the module's expected interface mode - Making sure the PHY supports it - Optionaly perform some configuration to make sure the PHY outputs the right mode This can be made more generic by leveraging the phy_port, and its configure_mii() callback which allows setting a port's interfaces when the port is a serdes. Introduce a generic PHY SFP support. If a driver doesn't probe the SFP bus itself, but an SFP phandle is found in devicetree/firmware, then the generic PHY SFP support will be used, relying on port ops. PHY driver need to : - Register a .attach_port() callback - When a serdes port is registered to the PHY, drivers must set port->interfaces to the set of PHY_INTERFACE_MODE the port can output - If the port has limitations regarding speed, duplex and aneg, the port can also fine-tune the final linkmodes that can be supported - The port may register a set of ops, including .configure_mii(), that will be called at module_insert time to adjust the interface based on the module detected. Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_device.c | 107 +++++++++++++++++++++++++++++++++++ include/linux/phy.h | 2 + include/linux/phy_port.h | 2 + 3 files changed, 111 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 3772c68b1dbc..8bc3c668696d 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1598,6 +1598,86 @@ void phy_sfp_detach(void *upstream, struct sfp_bus *= bus) } EXPORT_SYMBOL(phy_sfp_detach); =20 +static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_i= d *id) +{ + __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); + struct phy_device *phydev =3D upstream; + const struct sfp_module_caps *caps; + struct phy_port *port; + + phy_interface_t iface; + + linkmode_zero(sfp_support); + + port =3D phy_get_sfp_port(phydev); + if (!port) + return -EINVAL; + + caps =3D sfp_get_module_caps(phydev->sfp_bus); + + linkmode_and(sfp_support, port->supported, caps->link_modes); + if (linkmode_empty(sfp_support)) { + dev_err(&phydev->mdio.dev, "incompatible SFP module inserted, no common = linkmode\n"); + return -EINVAL; + } + + iface =3D sfp_select_interface(phydev->sfp_bus, sfp_support); + if (iface =3D=3D PHY_INTERFACE_MODE_NA) { + dev_err(&phydev->mdio.dev, "PHY %s does not support the SFP module's req= uested MII interfaces\n", + phydev_name(phydev)); + return -EINVAL; + } + + if (phydev->n_ports =3D=3D 1) + phydev->port =3D caps->port; + + if (port->ops && port->ops->configure_mii) + return port->ops->configure_mii(port, true, iface); + + return 0; +} + +static void phy_sfp_module_remove(void *upstream) +{ + struct phy_device *phydev =3D upstream; + struct phy_port *port =3D phy_get_sfp_port(phydev); + + if (port && port->ops && port->ops->configure_mii) + port->ops->configure_mii(port, false, PHY_INTERFACE_MODE_NA); + + if (phydev->n_ports =3D=3D 1) + phydev->port =3D PORT_NONE; +} + +static void phy_sfp_link_up(void *upstream) +{ + struct phy_device *phydev =3D upstream; + struct phy_port *port =3D phy_get_sfp_port(phydev); + + if (port && port->ops && port->ops->link_up) + port->ops->link_up(port); +} + +static void phy_sfp_link_down(void *upstream) +{ + struct phy_device *phydev =3D upstream; + struct phy_port *port =3D phy_get_sfp_port(phydev); + + if (port && port->ops && port->ops->link_down) + port->ops->link_down(port); +} + +static const struct sfp_upstream_ops sfp_phydev_ops =3D { + .attach =3D phy_sfp_attach, + .detach =3D phy_sfp_detach, + .module_insert =3D phy_sfp_module_insert, + .module_remove =3D phy_sfp_module_remove, + .link_up =3D phy_sfp_link_up, + .link_down =3D phy_sfp_link_down, + .connect_phy =3D phy_sfp_connect_phy, + .disconnect_phy =3D phy_sfp_disconnect_phy, +}; + static int phy_add_port(struct phy_device *phydev, struct phy_port *port) { int ret =3D 0; @@ -1657,6 +1737,7 @@ static int phy_setup_sfp_port(struct phy_device *phyd= ev) * is a MII port. */ port->is_mii =3D true; + port->is_sfp =3D true; =20 phy_add_port(phydev, port); =20 @@ -3497,6 +3578,13 @@ static int phy_setup_ports(struct phy_device *phydev) if (ret) return ret; =20 + /* Use generic SFP probing only if the driver didn't do so already */ + if (!phydev->sfp_bus) { + ret =3D phy_sfp_probe(phydev, &sfp_phydev_ops); + if (ret) + goto out; + } + if (phydev->n_ports < phydev->max_n_ports) { ret =3D phy_default_setup_single_port(phydev); if (ret) @@ -3532,6 +3620,25 @@ static int phy_setup_ports(struct phy_device *phydev) return ret; } =20 +/** + * phy_get_sfp_port() - Returns the first valid SFP port of a PHY + * @phydev: pointer to the PHY device to get the SFP port from + * + * Returns: The first active SFP (serdes) port of a PHY device, NULL if no= ne + * exist. + */ +struct phy_port *phy_get_sfp_port(struct phy_device *phydev) +{ + struct phy_port *port; + + list_for_each_entry(port, &phydev->ports, head) + if (port->active && port->is_sfp) + return port; + + return NULL; +} +EXPORT_SYMBOL_GPL(phy_get_sfp_port); + /** * fwnode_mdio_find_device - Given a fwnode, find the mdio_device * @fwnode: pointer to the mdio_device's fwnode diff --git a/include/linux/phy.h b/include/linux/phy.h index 36f55ad09907..aada0b604987 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2426,6 +2426,8 @@ int __phy_hwtstamp_set(struct phy_device *phydev, struct kernel_hwtstamp_config *config, struct netlink_ext_ack *extack); =20 +struct phy_port *phy_get_sfp_port(struct phy_device *phydev); + extern const struct bus_type mdio_bus_type; extern const struct class mdio_bus_class; =20 diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h index ce0208fbccf7..550c3f4ab19f 100644 --- a/include/linux/phy_port.h +++ b/include/linux/phy_port.h @@ -49,6 +49,7 @@ struct phy_port_ops { * @active: Indicates if the port is currently part of the active link. * @is_mii: Indicates if this port is MII (Media Independent Interface), * or MDI (Media Dependent Interface). + * @is_sfp: Indicates if this port drives an SFP cage. */ struct phy_port { struct list_head head; @@ -67,6 +68,7 @@ struct phy_port { unsigned int not_described:1; unsigned int active:1; unsigned int is_mii:1; + unsigned int is_sfp:1; }; =20 struct phy_port *phy_port_alloc(void); --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 6FAE1371A16 for ; Thu, 20 Nov 2025 20:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672155; cv=none; b=Ib/hXJMXhbqHm2Syg/9bQJ6mnuRRud40IooTlSexfp7ZRfBC9vPIpkgJCXzhv0pnFXf6v21xDB2LW/nf9MLctAUsHSIs4Ps5+igNbXLY7M4SnW0uHyMOzLOyLwX0Pr49s4sB+6GwUE2CfWKLTohMzLgY3pk2+OX9oQXgFWZhjP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672155; c=relaxed/simple; bh=7SbdU+tcUgAxQ/T7dZ9ZoX49c89mZ2EajY+VEunSIIg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=og5aHw8aQesaBpr5E9T5u19i+YkzUNcXzDKliF7HkY340DkmG8+6Ma2UsFhxQyUgaNMuAEfhAsJfU0aXOx6Z7N11nDkBaXwav6w6IUv1Xc7Xni8d4o7j+FsKnEMVUJSTyDeFAkVKmD8hEM9Gt7P2ye05SHke/g6Nb3gFo6PTLVQ= 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=0CZKBjBs; arc=none smtp.client-ip=185.171.202.116 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="0CZKBjBs" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id C51C8C111B0; Thu, 20 Nov 2025 20:55:29 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2077E606F6; Thu, 20 Nov 2025 20:55:52 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 33CC610371BC1; Thu, 20 Nov 2025 21:55:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672150; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=cvalqWQNdUHmlVQiWYTBVow57GCTnO3jvYApxg1ymio=; b=0CZKBjBsdFc/vhqunaiaVNfeXWbQfyZXxtq79NK6sznevsenvrf7xcWBjuIe3V6sxo+OUk 0hIQD8koNGwyUcdZH1l4xS9UmltavdpvNKpTPU2hg/MxFgVc9jDoA3Mv9983J65f7pfmdD rSLy34y8XjVmS0DKOnfc3tfsWaZvg2bm6NdE9S+oADoPsCWkPRwUEp+nlO3cQLSOHD3QWU mJYUHfRiK91pOeCidQHKpvRy6X4+SPUAm56V8D30zjEJzALY/8IHS3m9A7iwWrrhWpS6Z+ ftlaEgNeUgOUaGGaaDS/8uiZylMwKlGedOyoY9S6R1y4z6ppUXwdfiiA4fkmbA== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 08/15] net: phy: marvell-88x2222: Support SFP through phy_port interface Date: Thu, 20 Nov 2025 21:54:58 +0100 Message-ID: <20251120205508.553909-9-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The 88x2222 PHY from Marvell only supports serialised modes as its line-facing interfaces. Convert that driver to the generic phylib SFP handling. Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/marvell-88x2222.c | 94 +++++++++++++------------------ 1 file changed, 38 insertions(+), 56 deletions(-) diff --git a/drivers/net/phy/marvell-88x2222.c b/drivers/net/phy/marvell-88= x2222.c index 894bcee61e65..ba1bbb6c63d6 100644 --- a/drivers/net/phy/marvell-88x2222.c +++ b/drivers/net/phy/marvell-88x2222.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include =20 /* Port PCS Configuration */ @@ -473,89 +473,70 @@ static int mv2222_config_init(struct phy_device *phyd= ev) return 0; } =20 -static int mv2222_sfp_insert(void *upstream, const struct sfp_eeprom_id *i= d) +static int mv2222_configure_serdes(struct phy_port *port, bool enable, + phy_interface_t interface) { - struct phy_device *phydev =3D upstream; - const struct sfp_module_caps *caps; - phy_interface_t sfp_interface; + struct phy_device *phydev =3D port_phydev(port); struct mv2222_data *priv; - struct device *dev; - int ret; + int ret =3D 0; =20 priv =3D phydev->priv; - dev =3D &phydev->mdio.dev; - - caps =3D sfp_get_module_caps(phydev->sfp_bus); - - phydev->port =3D caps->port; - sfp_interface =3D sfp_select_interface(phydev->sfp_bus, caps->link_modes); - - dev_info(dev, "%s SFP module inserted\n", phy_modes(sfp_interface)); + priv->line_interface =3D interface; =20 - if (sfp_interface !=3D PHY_INTERFACE_MODE_10GBASER && - sfp_interface !=3D PHY_INTERFACE_MODE_1000BASEX && - sfp_interface !=3D PHY_INTERFACE_MODE_SGMII) { - dev_err(dev, "Incompatible SFP module inserted\n"); + if (enable) { + linkmode_and(priv->supported, phydev->supported, port->supported); =20 - return -EINVAL; - } - - priv->line_interface =3D sfp_interface; - linkmode_and(priv->supported, phydev->supported, caps->link_modes); + ret =3D mv2222_config_line(phydev); + if (ret < 0) + return ret; =20 - ret =3D mv2222_config_line(phydev); - if (ret < 0) - return ret; + if (mutex_trylock(&phydev->lock)) { + ret =3D mv2222_config_aneg(phydev); + mutex_unlock(&phydev->lock); + } =20 - if (mutex_trylock(&phydev->lock)) { - ret =3D mv2222_config_aneg(phydev); - mutex_unlock(&phydev->lock); + } else { + linkmode_zero(priv->supported); } =20 return ret; } =20 -static void mv2222_sfp_remove(void *upstream) +static void mv2222_port_link_up(struct phy_port *port) { - struct phy_device *phydev =3D upstream; - struct mv2222_data *priv; - - priv =3D phydev->priv; - - priv->line_interface =3D PHY_INTERFACE_MODE_NA; - linkmode_zero(priv->supported); - phydev->port =3D PORT_NONE; -} - -static void mv2222_sfp_link_up(void *upstream) -{ - struct phy_device *phydev =3D upstream; + struct phy_device *phydev =3D port_phydev(port); struct mv2222_data *priv; =20 priv =3D phydev->priv; priv->sfp_link =3D true; } =20 -static void mv2222_sfp_link_down(void *upstream) +static void mv2222_port_link_down(struct phy_port *port) { - struct phy_device *phydev =3D upstream; + struct phy_device *phydev =3D port_phydev(port); struct mv2222_data *priv; =20 priv =3D phydev->priv; priv->sfp_link =3D false; } =20 -static const struct sfp_upstream_ops sfp_phy_ops =3D { - .module_insert =3D mv2222_sfp_insert, - .module_remove =3D mv2222_sfp_remove, - .link_up =3D mv2222_sfp_link_up, - .link_down =3D mv2222_sfp_link_down, - .attach =3D phy_sfp_attach, - .detach =3D phy_sfp_detach, - .connect_phy =3D phy_sfp_connect_phy, - .disconnect_phy =3D phy_sfp_disconnect_phy, +static const struct phy_port_ops mv2222_port_ops =3D { + .link_up =3D mv2222_port_link_up, + .link_down =3D mv2222_port_link_down, + .configure_mii =3D mv2222_configure_serdes, }; =20 +static int mv2222_attach_mii_port(struct phy_device *phydev, struct phy_po= rt *port) +{ + port->ops =3D &mv2222_port_ops; + + __set_bit(PHY_INTERFACE_MODE_10GBASER, port->interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, port->interfaces); + __set_bit(PHY_INTERFACE_MODE_SGMII, port->interfaces); + + return 0; +} + static int mv2222_probe(struct phy_device *phydev) { struct device *dev =3D &phydev->mdio.dev; @@ -591,7 +572,7 @@ static int mv2222_probe(struct phy_device *phydev) priv->line_interface =3D PHY_INTERFACE_MODE_NA; phydev->priv =3D priv; =20 - return phy_sfp_probe(phydev, &sfp_phy_ops); + return 0; } =20 static struct phy_driver mv2222_drivers[] =3D { @@ -608,6 +589,7 @@ static struct phy_driver mv2222_drivers[] =3D { .suspend =3D mv2222_suspend, .resume =3D mv2222_resume, .read_status =3D mv2222_read_status, + .attach_mii_port =3D mv2222_attach_mii_port, }, }; module_phy_driver(mv2222_drivers); --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 452CE371A1A; Thu, 20 Nov 2025 20:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672163; cv=none; b=Y/uao/1ObZ8H5fg2/vdBru/LZMWP5KiI6QCGh+TkixF6xpgbz1NDIcz42et87kfmOxa7AasSNYilOe/zQBr8GFCH6aujkgfPmA08jppcWuKDMx7NC4VqLm/zzwPP382Rhc94ONGi7WpO5Nz4lz35RshOGVWBAwY9xgilWgh9GiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672163; c=relaxed/simple; bh=MQurAbVAKyKsLw2Mye1uGTxhsgFGOYYFNL3jQh/5tjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AaPJImIhCIExnadGXtzNhHu4epL35dDm+pqXAV7Bu3lw0ls08OzwnHdGrMReBUBKnFlzl+1pWCKAqbGEtWU+iWQbQ+dRA0vCf4xRs0XDFNvQjAz5qERIgm6Ybu2TLL2oEAnDVi38s+eXyOYQgHxLEYUfymS1i+bniBodNPLnZgg= 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=WHyH9w+t; arc=none smtp.client-ip=185.246.84.56 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="WHyH9w+t" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 9EA661A1C19; Thu, 20 Nov 2025 20:55:56 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 73778606F6; Thu, 20 Nov 2025 20:55:56 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1DF2A10371BD5; Thu, 20 Nov 2025 21:55:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672154; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=tJEx6X7jTirj87wA7LztjO6u7T36oh+3CaAe0KvSpGE=; b=WHyH9w+tLF2OFYIjCdr8i8sXTQOfhmrIb27wzXjXr3iF0x4pBFRQO6ltWAczZ3XaeP8ubv eE+oAkVDtrbRm1BVWq8jTQOyoWuMjx96oh2klmccxeMfVh8B2TaCoS0y53KhWESuGMwstL P5x46eI8ftwEm8+T8yFT/nhcqcXlRXf6SdfnuWkWXYHE22cLWEM09SRpqGHePIhjaDX1cY rRGP8TA2xlVL+wi14TLg9xrnYPb2aeV0Wsmc2K1YiVdhROl41RG9DzeGr9Ph6V7G8LXIG4 xl7RZo/7yOO7O4lT3C/tGwl/bVfFapcO2YTa0NstxqHHc659/w2sA5v4dbsExw== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 09/15] net: phy: marvell: Support SFP through phy_port interface Date: Thu, 20 Nov 2025 21:54:59 +0100 Message-ID: <20251120205508.553909-10-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Convert the Marvell driver (especially the 88e1512 driver) to use the phy_port interface to handle SFPs. This means registering a .attach_port() handler to detect when a serdes line interface is used (most likely, and SFP module). Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/marvell.c | 92 ++++++++++++++------------------------- 1 file changed, 33 insertions(+), 59 deletions(-) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index c248c90510ae..542166cfcb23 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -29,10 +29,10 @@ #include #include #include +#include #include #include #include -#include =20 #include #include @@ -3598,11 +3598,10 @@ static int marvell_probe(struct phy_device *phydev) return marvell_hwmon_probe(phydev); } =20 -static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id = *id) +static int m88e1510_port_configure_serdes(struct phy_port *port, bool enab= le, + phy_interface_t interface) { - struct phy_device *phydev =3D upstream; - const struct sfp_module_caps *caps; - phy_interface_t interface; + struct phy_device *phydev =3D port_phydev(port); struct device *dev; int oldpage; int ret =3D 0; @@ -3610,28 +3609,27 @@ static int m88e1510_sfp_insert(void *upstream, cons= t struct sfp_eeprom_id *id) =20 dev =3D &phydev->mdio.dev; =20 - caps =3D sfp_get_module_caps(phydev->sfp_bus); - interface =3D sfp_select_interface(phydev->sfp_bus, caps->link_modes); + if (enable) { + switch (interface) { + case PHY_INTERFACE_MODE_1000BASEX: + mode =3D MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X; =20 - dev_info(dev, "%s SFP module inserted\n", phy_modes(interface)); + break; + case PHY_INTERFACE_MODE_100BASEX: + mode =3D MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX; =20 - switch (interface) { - case PHY_INTERFACE_MODE_1000BASEX: - mode =3D MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X; + break; + case PHY_INTERFACE_MODE_SGMII: + mode =3D MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII; =20 - break; - case PHY_INTERFACE_MODE_100BASEX: - mode =3D MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX; - - break; - case PHY_INTERFACE_MODE_SGMII: - mode =3D MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII; + break; + default: + dev_err(dev, "Incompatible SFP module inserted\n"); =20 - break; - default: - dev_err(dev, "Incompatible SFP module inserted\n"); - - return -EINVAL; + return -EINVAL; + } + } else { + mode =3D MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII; } =20 oldpage =3D phy_select_page(phydev, MII_MARVELL_MODE_PAGE); @@ -3648,49 +3646,24 @@ static int m88e1510_sfp_insert(void *upstream, cons= t struct sfp_eeprom_id *id) =20 error: return phy_restore_page(phydev, oldpage, ret); -} - -static void m88e1510_sfp_remove(void *upstream) -{ - struct phy_device *phydev =3D upstream; - int oldpage; - int ret =3D 0; =20 - oldpage =3D phy_select_page(phydev, MII_MARVELL_MODE_PAGE); - if (oldpage < 0) - goto error; - - ret =3D __phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1, - MII_88E1510_GEN_CTRL_REG_1_MODE_MASK, - MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII); - if (ret < 0) - goto error; - - ret =3D __phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1, - MII_88E1510_GEN_CTRL_REG_1_RESET); - -error: - phy_restore_page(phydev, oldpage, ret); + return 0; } =20 -static const struct sfp_upstream_ops m88e1510_sfp_ops =3D { - .module_insert =3D m88e1510_sfp_insert, - .module_remove =3D m88e1510_sfp_remove, - .attach =3D phy_sfp_attach, - .detach =3D phy_sfp_detach, - .connect_phy =3D phy_sfp_connect_phy, - .disconnect_phy =3D phy_sfp_disconnect_phy, +static const struct phy_port_ops m88e1510_serdes_port_ops =3D { + .configure_mii =3D m88e1510_port_configure_serdes, }; =20 -static int m88e1510_probe(struct phy_device *phydev) +static int m88e1510_attach_mii_port(struct phy_device *phy_device, + struct phy_port *port) { - int err; + port->ops =3D &m88e1510_serdes_port_ops; =20 - err =3D marvell_probe(phydev); - if (err) - return err; + __set_bit(PHY_INTERFACE_MODE_SGMII, port->interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, port->interfaces); + __set_bit(PHY_INTERFACE_MODE_100BASEX, port->interfaces); =20 - return phy_sfp_probe(phydev, &m88e1510_sfp_ops); + return 0; } =20 static struct phy_driver marvell_drivers[] =3D { @@ -3950,7 +3923,7 @@ static struct phy_driver marvell_drivers[] =3D { .driver_data =3D DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), .features =3D PHY_GBIT_FIBRE_FEATURES, .flags =3D PHY_POLL_CABLE_TEST, - .probe =3D m88e1510_probe, + .probe =3D marvell_probe, .config_init =3D m88e1510_config_init, .config_aneg =3D m88e1510_config_aneg, .read_status =3D marvell_read_status, @@ -3976,6 +3949,7 @@ static struct phy_driver marvell_drivers[] =3D { .led_hw_is_supported =3D m88e1318_led_hw_is_supported, .led_hw_control_set =3D m88e1318_led_hw_control_set, .led_hw_control_get =3D m88e1318_led_hw_control_get, + .attach_mii_port =3D m88e1510_attach_mii_port, }, { .phy_id =3D MARVELL_PHY_ID_88E1540, --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 CAD37342C8E; Thu, 20 Nov 2025 20:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672165; cv=none; b=C/UJj5yYuKftjjIQosSC4KNE8Pv2Lgo/QHBg4katW03DSAj5MqHc1gNc5B83z2RqlNlZonhzOHm38Fufikxzh3+JnGZ5e+/c+r06PsVIUqyx1ooQvRptFBO8eYamYUW5HjUSXc6MnsvCW6y7TbRWSw0YdI0Hg9V1uLeGSyR+Upk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672165; c=relaxed/simple; bh=kt970PIrRbKVbKWCO7Ijcr1y2Psk1Vk4rbXY/51Trjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=POqRD1h3ZoZcs8UU2Y8zTV/fkbq9dqFhugQeMVcvyPMNh0HC+E3LRkRQLwMFTuRWzH19BegHe8WIzg1Q/eZJ4L2bFfsS0UIG5nNMpT0ckVb8lcW6bk2ODoh/+25HAaN087a5Bq83wnQq9ZzVDKICZsY7c0kFIIO0W9pPy6/sqZo= 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=Ngl3j0i2; arc=none smtp.client-ip=185.246.85.4 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Ngl3j0i2" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 41ADA4E41811; Thu, 20 Nov 2025 20:56:00 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 15AE2606F6; Thu, 20 Nov 2025 20:56:00 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id CDDCF10371BCA; Thu, 20 Nov 2025 21:55:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672158; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=mXISH1m2FWOa1re4lRf2E8WpcS+3R+/gMgNN8FHfuxc=; b=Ngl3j0i2NzOphVUazxIOQsAG0K9GOFvLXlKJQ3z/Rf1IVldCKEqLSUFGv4lTlz2UsdhlDy /gHu4o6txa4pRd4v6gb73J5JxsMujRgyYgT44eAoRxcUdQIaEArfux/VXYxv1kpVoNin8R nnvieWCoro33ruPQd01Fba4wGDyo5NI1jwaV9HCNw5MSZPAePNkJ2yrUjsu/T3oAWlAY5Q SYmeRxuryWNnLixUb2XifH0RxsNZKumMJSzLscdR2iS8fRpLgi7nMKBmmv/omIhUoh1Tsz j6+jW8UcTfnl4eiPP1AMUp6B8Jhd7ZBxUkYvQhqPcjZkzljkSw3KSHMEKfDNmg== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 10/15] net: phy: marvell10g: Support SFP through phy_port Date: Thu, 20 Nov 2025 21:55:00 +0100 Message-ID: <20251120205508.553909-11-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 X-Rspamd-Fuzzy: 3cb21b558de28fb2da6f0bd9e82e7e0b10c8d141dc54d9d6fbfd2e91509e71453fa3284c1bc137d8881b8fab86d8e63a2159b0df6846de9d71fb1087f1828b62 Content-Type: text/plain; charset="utf-8" Convert the Marvell10G driver to use the generic SFP handling, through a dedicated .attach_port() handler to populate the port's supported interfaces. As the 88x3310 supports multiple MDI, the .attach_port() logic handles both SFP attach with 10GBaseR support, and support for the "regular" port that usually is a BaseT port. Reviewed-by: Andrew Lunn Reviewed-by: Christophe Leroy Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/marvell10g.c | 52 ++++++++++++++++++++++-------------- drivers/net/phy/phy_port.c | 44 ++++++++++++++++++++++++++++++ include/linux/phy_port.h | 1 + 3 files changed, 77 insertions(+), 20 deletions(-) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index 8fd42131cdbf..d4cace758fe8 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include =20 #define MV_PHY_ALASKA_NBT_QUIRK_MASK 0xfffffffe @@ -463,35 +463,35 @@ static int mv3310_set_edpd(struct phy_device *phydev,= u16 edpd) return err; } =20 -static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *i= d) +static int mv3310_attach_mii_port(struct phy_device *phydev, + struct phy_port *port) { - struct phy_device *phydev =3D upstream; - const struct sfp_module_caps *caps; - phy_interface_t iface; + __set_bit(PHY_INTERFACE_MODE_10GBASER, port->interfaces); + return 0; +} =20 - caps =3D sfp_get_module_caps(phydev->sfp_bus); - iface =3D sfp_select_interface(phydev->sfp_bus, caps->link_modes); +static int mv3310_attach_mdi_port(struct phy_device *phydev, + struct phy_port *port) +{ + /* This PHY can do combo-ports, i.e. 2 MDI outputs, usually one + * of them going to an SFP and the other one to a RJ45 + * connector. If we don't have any representation for the port + * in DT, and we are dealing with a non-SFP port, then we + * mask the port's capabilities to report BaseT-only modes + */ + if (port->not_described) + return phy_port_restrict_mediums(port, + BIT(ETHTOOL_LINK_MEDIUM_BASET)); =20 - if (iface !=3D PHY_INTERFACE_MODE_10GBASER) { - dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n"); - return -EINVAL; - } return 0; } =20 -static const struct sfp_upstream_ops mv3310_sfp_ops =3D { - .attach =3D phy_sfp_attach, - .detach =3D phy_sfp_detach, - .connect_phy =3D phy_sfp_connect_phy, - .disconnect_phy =3D phy_sfp_disconnect_phy, - .module_insert =3D mv3310_sfp_insert, -}; - static int mv3310_probe(struct phy_device *phydev) { const struct mv3310_chip *chip =3D to_mv3310_chip(phydev); struct mv3310_priv *priv; u32 mmd_mask =3D MDIO_DEVS_PMAPMD | MDIO_DEVS_AN; + DECLARE_PHY_INTERFACE_MASK(interfaces); int ret; =20 if (!phydev->is_c45 || @@ -542,9 +542,13 @@ static int mv3310_probe(struct phy_device *phydev) if (ret) return ret; =20 + __set_bit(PHY_INTERFACE_MODE_10GBASER, interfaces); + chip->init_supported_interfaces(priv->supported_interfaces); =20 - return phy_sfp_probe(phydev, &mv3310_sfp_ops); + phydev->max_n_ports =3D 2; + + return 0; } =20 static void mv3310_remove(struct phy_device *phydev) @@ -1405,6 +1409,8 @@ static struct phy_driver mv3310_drivers[] =3D { .set_loopback =3D genphy_c45_loopback, .get_wol =3D mv3110_get_wol, .set_wol =3D mv3110_set_wol, + .attach_mii_port =3D mv3310_attach_mii_port, + .attach_mdi_port =3D mv3310_attach_mdi_port, }, { .phy_id =3D MARVELL_PHY_ID_88X3310, @@ -1424,6 +1430,8 @@ static struct phy_driver mv3310_drivers[] =3D { .set_tunable =3D mv3310_set_tunable, .remove =3D mv3310_remove, .set_loopback =3D genphy_c45_loopback, + .attach_mii_port =3D mv3310_attach_mii_port, + .attach_mdi_port =3D mv3310_attach_mdi_port, }, { .phy_id =3D MARVELL_PHY_ID_88E2110, @@ -1444,6 +1452,8 @@ static struct phy_driver mv3310_drivers[] =3D { .set_loopback =3D genphy_c45_loopback, .get_wol =3D mv3110_get_wol, .set_wol =3D mv3110_set_wol, + .attach_mii_port =3D mv3310_attach_mii_port, + .attach_mdi_port =3D mv3310_attach_mdi_port, }, { .phy_id =3D MARVELL_PHY_ID_88E2110, @@ -1462,6 +1472,8 @@ static struct phy_driver mv3310_drivers[] =3D { .set_tunable =3D mv3310_set_tunable, .remove =3D mv3310_remove, .set_loopback =3D genphy_c45_loopback, + .attach_mii_port =3D mv3310_attach_mii_port, + .attach_mdi_port =3D mv3310_attach_mdi_port, }, }; =20 diff --git a/drivers/net/phy/phy_port.c b/drivers/net/phy/phy_port.c index f89f70f83593..d9099196f870 100644 --- a/drivers/net/phy/phy_port.c +++ b/drivers/net/phy/phy_port.c @@ -149,6 +149,50 @@ void phy_port_update_supported(struct phy_port *port) } EXPORT_SYMBOL_GPL(phy_port_update_supported); =20 +/** + * phy_port_filter_supported() - Make sure that port->supported match port= ->mediums + * @port: The port to filter + * + * After updating a port's mediums to a more restricted subset, this helpe= r will + * make sure that port->supported only contains linkmodes that are compati= ble + * with port->mediums. + */ +static void phy_port_filter_supported(struct phy_port *port) +{ + __ETHTOOL_DECLARE_LINK_MODE_MASK(supported) =3D { 0 }; + int i; + + for_each_set_bit(i, &port->mediums, __ETHTOOL_LINK_MEDIUM_LAST) + phy_caps_medium_get_supported(supported, i, port->pairs); + + linkmode_and(port->supported, port->supported, supported); +} + +/** + * phy_port_restrict_mediums - Mask away some of the port's supported medi= ums + * @port: The port to act upon + * @mediums: A mask of mediums to support on the port + * + * This helper allows removing some mediums from a port's list of supported + * mediums, which occurs once we have enough information about the port to + * know its nature. + * + * Returns: 0 if the change was donne correctly, a negative value otherwis= e. + */ +int phy_port_restrict_mediums(struct phy_port *port, unsigned long mediums) +{ + /* We forbid ending-up with a port with empty mediums */ + if (!(port->mediums & mediums)) + return -EINVAL; + + port->mediums &=3D mediums; + + phy_port_filter_supported(port); + + return 0; +} +EXPORT_SYMBOL_GPL(phy_port_restrict_mediums); + /** * phy_port_get_type() - get the PORT_* attribute for that port. * @port: The port we want the information from diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h index 550c3f4ab19f..0ef0f5ce4709 100644 --- a/include/linux/phy_port.h +++ b/include/linux/phy_port.h @@ -92,6 +92,7 @@ static inline bool phy_port_is_fiber(struct phy_port *por= t) } =20 void phy_port_update_supported(struct phy_port *port); +int phy_port_restrict_mediums(struct phy_port *port, unsigned long mediums= ); =20 int phy_port_get_type(struct phy_port *port); =20 --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 D991436215F; Thu, 20 Nov 2025 20:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672166; cv=none; b=A8dFMxG9LVeLr7mb2FaqzHNGvrnEtmmLGeq9airXbymw3XJ75AekKFvnLF7f/P+9lVowWCVfLppAYIAiWa+LpiHt6jzEjmCX/Vx7ySxTVxyy/ib5UEbhIDDHN6tT/1GmETvKM3whiNAARMnojIP2M8h57DLIuGV2S325lH4eiGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672166; c=relaxed/simple; bh=FPOPOiaHiMS1DGiB15UET9ZTvHI8/dOj06ra13vuyiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uWoUQdmkdfDT3KDKPDqLQOwZglxcKjzK2cCQ30dhCJpm+uTwlbtBc8HnpAL2nehKlGnq+YQNbZ117qBwiW7biVtbX9pEGYUxjGFOoc9rJPKjmmH5cwA3oUcfjuCdXSAVTXPoGafn1F3FhsLo9OF5Rpgwmc3E+LdG1kGyjeT5aAE= 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=ZGf4K8OH; arc=none smtp.client-ip=185.171.202.116 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ZGf4K8OH" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 42A78C111B7; Thu, 20 Nov 2025 20:55:41 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 91A8C606F6; Thu, 20 Nov 2025 20:56:03 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DA51710371BD8; Thu, 20 Nov 2025 21:55:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672162; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=246FoifQioiJlJKgK0l+PteqgHVK9qea+qwvqnjBY1s=; b=ZGf4K8OHHJAaPPsUIYhfkU2r3sXDIeJQHEsMnHAUMKfV4mEKpmpVmYaq9j4SEOn9r+YnPj W1b1wWweSzVNQOFEx9lJMTjb3RXw6t2La4EiPJZlp//70MRu90NqsTDIDW+lckkAMKUPwj Uzz+P/kInrLJh5ABTnFomNp0vXPI7eAtUnoLGvnzKNtBNdYtSP9Hfald4OElDoSOGF1t+F 2O7lYjV780Mz5jOMEmmsyU2PwfAug6n0RARxxAMsLASEAtJm3dSsWTRL8FnRMotPvDw/oE H+oUX2n95M+FcHlJBBwBV3MHuX3Jxq3UVw99AwGDsxG6s5b/fL1kFZLjBqhkWQ== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 11/15] net: phy: at803x: Support SFP through phy_port interface Date: Thu, 20 Nov 2025 21:55:01 +0100 Message-ID: <20251120205508.553909-12-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Convert the at803x driver to use the generic phylib SFP handling, via a dedicated .attach_port() callback, populating the supported interfaces. As these devices are limited to 1000BaseX, a workaround is used to also support, in a very limited way, copper modules. This is done by supporting SGMII but limiting it to 1G full duplex (in which case it's somewhat compatible with 1000BaseX). Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/qcom/at803x.c | 77 +++++++++++++++-------------------- 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/drivers/net/phy/qcom/at803x.c b/drivers/net/phy/qcom/at803x.c index 338acd11a9b6..2995b08bac96 100644 --- a/drivers/net/phy/qcom/at803x.c +++ b/drivers/net/phy/qcom/at803x.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include =20 #include "qcom.h" @@ -769,57 +769,44 @@ static int at8031_register_regulators(struct phy_devi= ce *phydev) return 0; } =20 -static int at8031_sfp_insert(void *upstream, const struct sfp_eeprom_id *i= d) +static int at803x_configure_mii(struct phy_port *port, bool enable, + phy_interface_t interface) { - __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support); - __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); - struct phy_device *phydev =3D upstream; - const struct sfp_module_caps *caps; - phy_interface_t iface; - - linkmode_zero(phy_support); - phylink_set(phy_support, 1000baseX_Full); - phylink_set(phy_support, 1000baseT_Full); - phylink_set(phy_support, Autoneg); - phylink_set(phy_support, Pause); - phylink_set(phy_support, Asym_Pause); - - caps =3D sfp_get_module_caps(phydev->sfp_bus); - /* Some modules support 10G modes as well as others we support. - * Mask out non-supported modes so the correct interface is picked. - */ - linkmode_and(sfp_support, phy_support, caps->link_modes); + struct phy_device *phydev =3D port_phydev(port); =20 - if (linkmode_empty(sfp_support)) { - dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n"); - return -EINVAL; - } + if (interface =3D=3D PHY_INTERFACE_MODE_SGMII) + dev_warn(&phydev->mdio.dev, + "module may not function if 1000Base-X not supported\n"); + + return 0; +} =20 - iface =3D sfp_select_interface(phydev->sfp_bus, sfp_support); +static const struct phy_port_ops at803x_port_ops =3D { + .configure_mii =3D at803x_configure_mii, +}; =20 - /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes - * interface for use with SFP modules. - * However, some copper modules detected as having a preferred SGMII - * interface do default to and function in 1000Base-X mode, so just - * print a warning and allow such modules, as they may have some chance - * of working. +static int at8031_attach_mii_port(struct phy_device *phydev, + struct phy_port *port) +{ + linkmode_zero(port->supported); + phylink_set(port->supported, 1000baseX_Full); + phylink_set(port->supported, 1000baseT_Full); + phylink_set(port->supported, Autoneg); + phylink_set(port->supported, Pause); + phylink_set(port->supported, Asym_Pause); + + /* This device doesn't really support SGMII. However, do our best + * to be compatible with copper modules (that usually require SGMII), + * in a degraded mode as we only allow 1000BaseT Full */ - if (iface =3D=3D PHY_INTERFACE_MODE_SGMII) - dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not s= upported\n"); - else if (iface !=3D PHY_INTERFACE_MODE_1000BASEX) - return -EINVAL; + __set_bit(PHY_INTERFACE_MODE_SGMII, port->interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, port->interfaces); + + port->ops =3D &at803x_port_ops; =20 return 0; } =20 -static const struct sfp_upstream_ops at8031_sfp_ops =3D { - .attach =3D phy_sfp_attach, - .detach =3D phy_sfp_detach, - .module_insert =3D at8031_sfp_insert, - .connect_phy =3D phy_sfp_connect_phy, - .disconnect_phy =3D phy_sfp_disconnect_phy, -}; - static int at8031_parse_dt(struct phy_device *phydev) { struct device_node *node =3D phydev->mdio.dev.of_node; @@ -840,8 +827,7 @@ static int at8031_parse_dt(struct phy_device *phydev) return ret; } =20 - /* Only AR8031/8033 support 1000Base-X for SFP modules */ - return phy_sfp_probe(phydev, &at8031_sfp_ops); + return 0; } =20 static int at8031_probe(struct phy_device *phydev) @@ -1172,6 +1158,7 @@ static struct phy_driver at803x_driver[] =3D { .set_tunable =3D at803x_set_tunable, .cable_test_start =3D at8031_cable_test_start, .cable_test_get_status =3D at8031_cable_test_get_status, + .attach_mii_port =3D at8031_attach_mii_port, }, { /* Qualcomm Atheros AR8032 */ PHY_ID_MATCH_EXACT(ATH8032_PHY_ID), --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 03360376BDC; Thu, 20 Nov 2025 20:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672172; cv=none; b=hmdTwhjyjBvbkIN/EoYDwUsjg4mVE+MXG0TkMi0zQ5vfyzz6D3S3iIfwE7v1GBgY4UYZUUrAFPc8kRx85BbwMzUAzSvX1O+aJTA6Uml4LRI1hCQhrlYpFnZ1IsCUDgps4kGMr2WtcTa6jjoe4dE20REvZ+F1FF1S/+ds6lK5FNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672172; c=relaxed/simple; bh=4N8v2KuuWJiFFdDvLQAu3AxJQTp2J6eEXtQhiOrOwUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TNNL12+XYBQ+F0YLggx8dy0P/hi/EuOn3uTdHlR7pOI10hWBtXMiFy8aU0IQRXpEdFPXa+LirX1flQLCmxn21QT1nzmYYwpgseAshuXLDfpsKNu2z80+0wEZa76vSo2QYfMuO9nXPqgAk1Kkb9E+efvLWdyYRonYS/PFZS4fbGg= 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=MfEKrfBq; arc=none smtp.client-ip=185.246.85.4 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MfEKrfBq" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 6BB054E41811; Thu, 20 Nov 2025 20:56:07 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 3ACD2606F6; Thu, 20 Nov 2025 20:56:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7AF7C10371BCD; Thu, 20 Nov 2025 21:56:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672165; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=RwnFhKTWvcMiLm1Et/DfqdWvufrCtHepMfYsjNpJGhU=; b=MfEKrfBqlHxLP4eIKUH8ftXzMuenbII82HzABiDZ93Vqm1ebqTRmo0HsQv+IxuDVKPoBtF 5hSA6SM1lb5loGF8cexuxUpMlw1NaHUr8iiiC8bcUH16Gih4p2R/ns13oNQyincoG/A5bx xsnJXkp0BuCU/e9aK1TUhpcHfJarVIodVepWd+w4IxYwavRZ1wyRXwpXEuuEALIrb+z+hr uOnBYZ07dso0porGtFmOn1UJqnKFoDmqwZ9JZCwXnJIBKPfxghL59bsfbBrjvzWE+OnACk Y5ghvkLR2eWf/u3DHon6kKht/fmKV24+mjkruOwLU8xcKyXsJtd9mEi8Re79vQ== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 12/15] net: phy: qca807x: Support SFP through phy_port interface Date: Thu, 20 Nov 2025 21:55:02 +0100 Message-ID: <20251120205508.553909-13-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" QCA8072/8075 may be used as combo-port PHYs, with Serdes (100/1000BaseX) and Copper interfaces. The PHY has the ability to read the configuration it's in. If the configuration indicates the PHY is in combo mode, allow registering up to 2 ports. Register a dedicated set of port ops to handle the serdes port, and rely on generic phylib SFP support for the SFP handling. Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/qcom/qca807x.c | 72 ++++++++++++++-------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/drivers/net/phy/qcom/qca807x.c b/drivers/net/phy/qcom/qca807x.c index 1be8295a95cb..d8f1ce5a7128 100644 --- a/drivers/net/phy/qcom/qca807x.c +++ b/drivers/net/phy/qcom/qca807x.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include =20 #include "../phylib.h" #include "qcom.h" @@ -643,67 +643,54 @@ static int qca807x_phy_package_config_init_once(struc= t phy_device *phydev) return ret; } =20 -static int qca807x_sfp_insert(void *upstream, const struct sfp_eeprom_id *= id) +static int qca807x_configure_serdes(struct phy_port *port, bool enable, + phy_interface_t interface) { - struct phy_device *phydev =3D upstream; - const struct sfp_module_caps *caps; - phy_interface_t iface; + struct phy_device *phydev =3D port_phydev(port); int ret; =20 - caps =3D sfp_get_module_caps(phydev->sfp_bus); - iface =3D sfp_select_interface(phydev->sfp_bus, caps->link_modes); + if (!phydev) + return -ENODEV; =20 - dev_info(&phydev->mdio.dev, "%s SFP module inserted\n", phy_modes(iface)); - - switch (iface) { - case PHY_INTERFACE_MODE_1000BASEX: - case PHY_INTERFACE_MODE_100BASEX: + if (enable) { /* Set PHY mode to PSGMII combo (1/4 copper + combo ports) mode */ ret =3D phy_modify(phydev, QCA807X_CHIP_CONFIGURATION, QCA807X_CHIP_CONFIGURATION_MODE_CFG_MASK, QCA807X_CHIP_CONFIGURATION_MODE_PSGMII_FIBER); + if (ret) + return ret; /* Enable fiber mode autodection (1000Base-X or 100Base-FX) */ ret =3D phy_set_bits_mmd(phydev, MDIO_MMD_AN, QCA807X_MMD7_FIBER_MODE_AUTO_DETECTION, QCA807X_MMD7_FIBER_MODE_AUTO_DETECTION_EN); - /* Select fiber page */ - ret =3D phy_clear_bits(phydev, - QCA807X_CHIP_CONFIGURATION, - QCA807X_BT_BX_REG_SEL); - - phydev->port =3D PORT_FIBRE; - break; - default: - dev_err(&phydev->mdio.dev, "Incompatible SFP module inserted\n"); - return -EINVAL; + if (ret) + return ret; } =20 - return ret; + phydev->port =3D enable ? PORT_FIBRE : PORT_TP; + + return phy_modify(phydev, QCA807X_CHIP_CONFIGURATION, + QCA807X_BT_BX_REG_SEL, + enable ? 0 : QCA807X_BT_BX_REG_SEL); } =20 -static void qca807x_sfp_remove(void *upstream) +static const struct phy_port_ops qca807x_serdes_port_ops =3D { + .configure_mii =3D qca807x_configure_serdes, +}; + +static int qca807x_attach_mii_port(struct phy_device *phydev, + struct phy_port *port) { - struct phy_device *phydev =3D upstream; + __set_bit(PHY_INTERFACE_MODE_1000BASEX, port->interfaces); + __set_bit(PHY_INTERFACE_MODE_100BASEX, port->interfaces); =20 - /* Select copper page */ - phy_set_bits(phydev, - QCA807X_CHIP_CONFIGURATION, - QCA807X_BT_BX_REG_SEL); + port->ops =3D &qca807x_serdes_port_ops; =20 - phydev->port =3D PORT_TP; + return 0; } =20 -static const struct sfp_upstream_ops qca807x_sfp_ops =3D { - .attach =3D phy_sfp_attach, - .detach =3D phy_sfp_detach, - .module_insert =3D qca807x_sfp_insert, - .module_remove =3D qca807x_sfp_remove, - .connect_phy =3D phy_sfp_connect_phy, - .disconnect_phy =3D phy_sfp_disconnect_phy, -}; - static int qca807x_probe(struct phy_device *phydev) { struct device_node *node =3D phydev->mdio.dev.of_node; @@ -744,9 +731,8 @@ static int qca807x_probe(struct phy_device *phydev) =20 /* Attach SFP bus on combo port*/ if (phy_read(phydev, QCA807X_CHIP_CONFIGURATION)) { - ret =3D phy_sfp_probe(phydev, &qca807x_sfp_ops); - if (ret) - return ret; + phydev->max_n_ports =3D 2; + linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->supported); linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->advertising); } @@ -824,6 +810,7 @@ static struct phy_driver qca807x_drivers[] =3D { .get_phy_stats =3D qca807x_get_phy_stats, .set_wol =3D at8031_set_wol, .get_wol =3D at803x_get_wol, + .attach_mii_port =3D qca807x_attach_mii_port, }, { PHY_ID_MATCH_EXACT(PHY_ID_QCA8075), @@ -851,6 +838,7 @@ static struct phy_driver qca807x_drivers[] =3D { .get_phy_stats =3D qca807x_get_phy_stats, .set_wol =3D at8031_set_wol, .get_wol =3D at803x_get_wol, + .attach_mii_port =3D qca807x_attach_mii_port, }, }; module_phy_driver(qca807x_drivers); --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 5B79D3751A4; Thu, 20 Nov 2025 20:56:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672176; cv=none; b=JYYrUWcIqb7saBOqkb8qm7w3q9TnJIc3wIbevW+NkBqDxG63mWlCPyrUIq5FQgRA2dMTW2m8wt/0hU6EVC2zjN9JlP+CNVKJNMJYZJPKklehT0CbpwIxopIFcgk4tw9FesSxCNV8ifov/tey3w0RtKGG6KROYA+4dAPkWOocHUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672176; c=relaxed/simple; bh=cCo0IgQqXEMn9ztDHkyUaWDdqC/uO9R1GOS12araZyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R5D92qfPcpKgT5TzlgskVIAR355GPOijTAaoyCfDJ7ONimC26pGYw1cblY4EttYX43ufNNGEWUgt4E3XOjX/R3wscLHYIr78xbzYCQb5nLTt2eXzqpww/BUqI+y7vB6xd6OYV89hmVWmva4zfMHtMls+2/+8EReIaDUs+Syyvlo= 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=dT8e0+Ze; arc=none smtp.client-ip=185.246.85.4 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="dT8e0+Ze" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id B98C24E41812; Thu, 20 Nov 2025 20:56:10 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8ECF1606F6; Thu, 20 Nov 2025 20:56:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 214EF10371BD6; Thu, 20 Nov 2025 21:56:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672169; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=KpRsXnyW8tO+FN1PKb7espJ1L0Z1Ujud4FWNRD5M24Y=; b=dT8e0+ZedZM7b41/7DZR4a8as9u/Ale4MblBTg/Tyu6JSi7sE9CZx07nNeu1KlWLwgLz8c 1tBqHi9XWSUuaWAE9seJQCE/9sjBBPJXuCPxwFs1nNPMntWeriitxafoctEFtB2sTO5Tgn y4hqbP+iZBLtUBRk8Te0F5jUHro997iKf75KDjlLfUT6BHncWdQuzmpakq300OjqpL8Th0 TSnKzxQhbnGJP2pbHFKAM75ssh4oh4HPyxaYC8tC69KbDZv643y3li8HcFfQIBAW0Fa0Hb wXy6flHbB0ZL+HpMsvQ1NqfYq1Ra3l53I/pkZQZtryQrnF10zPtrIWrkEpxeEw== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 13/15] net: phy: Only rely on phy_port for PHY-driven SFP Date: Thu, 20 Nov 2025 21:55:03 +0100 Message-ID: <20251120205508.553909-14-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Now that all PHY drivers that support downstream SFP have been converted to phy_port serdes handling, we can make the generic PHY SFP handling mandatory, thus making all phylib sfp helpers static. Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_device.c | 28 +++++++++------------------- include/linux/phy.h | 6 ------ 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 8bc3c668696d..523a79631f63 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1532,7 +1532,7 @@ static DEVICE_ATTR_RO(phy_standalone); * * Return: 0 on success, otherwise a negative error code. */ -int phy_sfp_connect_phy(void *upstream, struct phy_device *phy) +static int phy_sfp_connect_phy(void *upstream, struct phy_device *phy) { struct phy_device *phydev =3D upstream; struct net_device *dev =3D phydev->attached_dev; @@ -1542,7 +1542,6 @@ int phy_sfp_connect_phy(void *upstream, struct phy_de= vice *phy) =20 return 0; } -EXPORT_SYMBOL(phy_sfp_connect_phy); =20 /** * phy_sfp_disconnect_phy - Disconnect the SFP module's PHY from the upstr= eam PHY @@ -1554,7 +1553,7 @@ EXPORT_SYMBOL(phy_sfp_connect_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) +static void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy) { struct phy_device *phydev =3D upstream; struct net_device *dev =3D phydev->attached_dev; @@ -1562,7 +1561,6 @@ void phy_sfp_disconnect_phy(void *upstream, struct ph= y_device *phy) if (dev) phy_link_topo_del_phy(dev, phy); } -EXPORT_SYMBOL(phy_sfp_disconnect_phy); =20 /** * phy_sfp_attach - attach the SFP bus to the PHY upstream network device @@ -1571,7 +1569,7 @@ EXPORT_SYMBOL(phy_sfp_disconnect_phy); * * This is used to fill in the sfp_upstream_ops .attach member. */ -void phy_sfp_attach(void *upstream, struct sfp_bus *bus) +static void phy_sfp_attach(void *upstream, struct sfp_bus *bus) { struct phy_device *phydev =3D upstream; =20 @@ -1579,7 +1577,6 @@ void phy_sfp_attach(void *upstream, struct sfp_bus *b= us) phydev->attached_dev->sfp_bus =3D bus; phydev->sfp_bus_attached =3D true; } -EXPORT_SYMBOL(phy_sfp_attach); =20 /** * phy_sfp_detach - detach the SFP bus from the PHY upstream network device @@ -1588,7 +1585,7 @@ EXPORT_SYMBOL(phy_sfp_attach); * * This is used to fill in the sfp_upstream_ops .detach member. */ -void phy_sfp_detach(void *upstream, struct sfp_bus *bus) +static void phy_sfp_detach(void *upstream, struct sfp_bus *bus) { struct phy_device *phydev =3D upstream; =20 @@ -1596,7 +1593,6 @@ void phy_sfp_detach(void *upstream, struct sfp_bus *b= us) phydev->attached_dev->sfp_bus =3D NULL; phydev->sfp_bus_attached =3D false; } -EXPORT_SYMBOL(phy_sfp_detach); =20 static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_i= d *id) { @@ -1747,10 +1743,8 @@ static int phy_setup_sfp_port(struct phy_device *phy= dev) /** * phy_sfp_probe - probe for a SFP cage attached to this PHY device * @phydev: Pointer to phy_device - * @ops: SFP's upstream operations */ -int phy_sfp_probe(struct phy_device *phydev, - const struct sfp_upstream_ops *ops) +static int phy_sfp_probe(struct phy_device *phydev) { struct sfp_bus *bus; int ret =3D 0; @@ -1762,7 +1756,7 @@ int phy_sfp_probe(struct phy_device *phydev, =20 phydev->sfp_bus =3D bus; =20 - ret =3D sfp_bus_add_upstream(bus, phydev, ops); + ret =3D sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops); sfp_bus_put(bus); } =20 @@ -1771,7 +1765,6 @@ int phy_sfp_probe(struct phy_device *phydev, =20 return ret; } -EXPORT_SYMBOL(phy_sfp_probe); =20 static bool phy_drv_supports_irq(const struct phy_driver *phydrv) { @@ -3578,12 +3571,9 @@ static int phy_setup_ports(struct phy_device *phydev) if (ret) return ret; =20 - /* Use generic SFP probing only if the driver didn't do so already */ - if (!phydev->sfp_bus) { - ret =3D phy_sfp_probe(phydev, &sfp_phydev_ops); - if (ret) - goto out; - } + ret =3D phy_sfp_probe(phydev); + if (ret) + goto out; =20 if (phydev->n_ports < phydev->max_n_ports) { ret =3D phy_default_setup_single_port(phydev); diff --git a/include/linux/phy.h b/include/linux/phy.h index aada0b604987..8c8f25c7a1ac 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2124,12 +2124,6 @@ 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 speed); -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, - const struct sfp_upstream_ops *ops); struct phy_device *phy_attach(struct net_device *dev, const char *bus_id, phy_interface_t interface); struct phy_device *phy_find_next(struct mii_bus *bus, struct phy_device *p= os); --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 588AB3064A3; Thu, 20 Nov 2025 20:56:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672177; cv=none; b=F+4Xl3XJxgfQrZdkPyMWLn3jkmegfCXXC9VTmTyFxsovrarYC/DK/Tcd+riK6AVaCL2Ht1l3eStJbG/tuFZ+B+/Z6nroCn7QkmNoVIKnAgl459NJ7bwTd0uXiaaROO2l0mrk3+n8dCHtMbGs10k1mMP3C1awiXvDXLrY2nrOm5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672177; c=relaxed/simple; bh=jxA5jlW4L1kXG64MdapWoWEFhI8/sWrRMrBcoL9gL2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hSOFCWmStDWGyox5CZ0j+b2Qtuzbudw2zkBT4fnPz2iV12L+P5OWsl29FzAzbSypk1znrj9bdp54+8H6XzYk7PBNvWphJlFpPASEJncegtIop00BCPWZVoY4AoBW6205pVJ4QafVBqJ/qdAIJC5TBEcW/dD50G/hoXVYEE1gFBE= 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=F7orXe+w; arc=none smtp.client-ip=185.171.202.116 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="F7orXe+w" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id AB10DC111AC; Thu, 20 Nov 2025 20:55:51 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 07232606F6; Thu, 20 Nov 2025 20:56:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 86AB710371BC1; Thu, 20 Nov 2025 21:56:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672172; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=uIAXwEdg0d4MmgTZP1ulCjwLYFQ+33UFGD9u1cTHZGc=; b=F7orXe+wufXZZNtLCYeFPm1ecjfzChVYYLKxF90LWDA0q5V+CSILqLZer2mRFvDM/c1Ywc SU7M32tDQm1NBf0nClzmQIh4rFS58R7Rn1iLVSTmvO1JXt185bTSIrerhdJie5ni5fAQbt rsw1tp0zX1udVMEV6w34mQPSPiLafWWVzBgIfR/kdXx/uGYNxLH6tr+X7C1T/d9bOmdJn6 PBmo2B7Axc6YAeYxw3YLdz9kfVAS3ZIttTQotjfmyzI7T00CuUC96Biq0K1p7LPE0qUO69 6+qBlr66HxzBBVbbGVGWZ24p/KzUi7uo3+CDONhFT8khsbt9PDk11ACCGq4nUA== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 14/15] net: phy: dp83822: Add SFP support through the phy_port interface Date: Thu, 20 Nov 2025 21:55:04 +0100 Message-ID: <20251120205508.553909-15-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The DP83822 can support 100BaseFX. This mode was only accessible through custom DT properties, but there also exist SFP modules that support these modes. As this only requires setting the relevant supported interface in the driver, expose the port capability with the new phy_port API, allowing SFP support. Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/dp83822.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/phy/dp83822.c b/drivers/net/phy/dp83822.c index c012dfab3171..f31b6d974d22 100644 --- a/drivers/net/phy/dp83822.c +++ b/drivers/net/phy/dp83822.c @@ -979,6 +979,13 @@ static int dp83822_attach_mdi_port(struct phy_device *= phydev, } } =20 + /* If attached from SFP, is_mii is set, but not the mediums. */ + if (port->is_mii) + dp83822->fx_enabled =3D true; + + if (dp83822->fx_enabled) + __set_bit(PHY_INTERFACE_MODE_100BASEX, port->interfaces); + return 0; } =20 --=20 2.49.0 From nobody Tue Dec 2 01:50:46 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 67BC4393DDF; Thu, 20 Nov 2025 20:56:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672181; cv=none; b=bFqXYm1NLvOwLZKMossDDewbP7TSVOuUmfHOKk1RjTPWgvOa3/GWQpRxzrgV4tn4zpzyJBIDLdd1nI2Yb/+Gw0qYKg5mYzhF0IfddDL0VBKyvXwu7C+IC2TCf0k2bd+yjnOi617Sen3uLRqvGwjs/rxQrfF3VyxCMCrzgW1nrpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763672181; c=relaxed/simple; bh=ygnMB0zO5n7LNWTLaftTf7mOpO0kT3kaJ+Cqfp3KG9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AZUKZ6hQYVHktObhfaZjzRgFqphDI8/hg6ZmqNg0ojWd4j6n3KR++JPJ0oX8LzbvcT7rHTuAuLjs9cB8bTcK3/7lP1W3q9WabXtHtlQoVD0+y01qHcDw8n5X9zvl96oVNjL1l7r+dz0kV2iaAFRr3bIN+UfWP/l/reQt11FCrRc= 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=PyGvrDcT; arc=none smtp.client-ip=185.171.202.116 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="PyGvrDcT" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id A6833C111B0; Thu, 20 Nov 2025 20:55:54 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 021AD606F6; Thu, 20 Nov 2025 20:56:17 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DAEF710371BCD; Thu, 20 Nov 2025 21:56:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763672175; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=q5cHSdBiFQndzU4nTFiD7tW7FCwQQjMLgxuIBfRu/1k=; b=PyGvrDcT7ypsyJNjzh+XF97vqWLiE8UgFZwD7LM7RTXeyL/4Df4ybgKbJIgSfHMiszYoBL RfnisJjNgq3dKPJCUn7XNHa3V1ufBk7zvdiGLs4jfrCS6TfteYrpdnbZqXIldeMej/LavL T7NtNIm7wrzUnuluFWffTovgBZQrO5kdnQ+W05WXlw52dR909gOg58d8+g+zu5kBwtVHEH OwWlRLHVmeD40/q91gRspHwa+bDPPrQaf/OZLfPru6WG84weJYyQafqnPhtfzR1ZKsbla6 8cVAo7zOrWuBoUomfUFq/LGqUJyXQ/KiNqnCl5WgLjV9gJTkXCUkN4jgCFT+Yw== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@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?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v18 15/15] Documentation: networking: Document the phy_port infrastructure Date: Thu, 20 Nov 2025 21:55:05 +0100 Message-ID: <20251120205508.553909-16-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251120205508.553909-1-maxime.chevallier@bootlin.com> References: <20251120205508.553909-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: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" This documentation aims at describing the main goal of the phy_port infrastructure. Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- Documentation/networking/index.rst | 1 + Documentation/networking/phy-port.rst | 111 ++++++++++++++++++++++++++ MAINTAINERS | 2 + 3 files changed, 114 insertions(+) create mode 100644 Documentation/networking/phy-port.rst diff --git a/Documentation/networking/index.rst b/Documentation/networking/= index.rst index 75db2251649b..49fcfa577711 100644 --- a/Documentation/networking/index.rst +++ b/Documentation/networking/index.rst @@ -96,6 +96,7 @@ Contents: packet_mmap phonet phy-link-topology + phy-port pktgen plip ppp_generic diff --git a/Documentation/networking/phy-port.rst b/Documentation/networki= ng/phy-port.rst new file mode 100644 index 000000000000..6e28d9094bce --- /dev/null +++ b/Documentation/networking/phy-port.rst @@ -0,0 +1,111 @@ +.. SPDX-License-Identifier: GPL-2.0 +.. _phy_port: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Ethernet ports +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This document is a basic description of the phy_port infrastructure, +introduced to represent physical interfaces of Ethernet devices. + +Without phy_port, we already have quite a lot of information about what the +media-facing interface of a NIC can do and looks like, through the +:c:type:`struct ethtool_link_ksettings ` attribute= s, +which includes : + + - What the NIC can do through the :c:member:`supported` field + - What the Link Partner advertises through :c:member:`lp_advertising` + - Which features we're advertising through :c:member:`advertising` + +We also have info about the number of pairs and the PORT type. These setti= ngs +are built by aggregating together information reported by various devices = that +are sitting on the link : + + - The NIC itself, through the :c:member:`get_link_ksettings` callback + - Precise information from the MAC and PCS by using phylink in the MAC d= river + - Information reported by the PHY device + - Information reported by an SFP module (which can itself include a PHY) + +This model however starts showing its limitations when we consider devices= that +have more than one media interface. In such a case, only information about= the +actively used interface is reported, and it's not possible to know what the +other interfaces can do. In fact, we have very little information about wh= ether +or not there are any other media interfaces. + +The goal of the phy_port representation is to provide a way of representin= g a +physical interface of a NIC, regardless of what is driving the port (NIC t= hrough +a firmware, SFP module, Ethernet PHY). + +Multi-port interfaces examples +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D + +Several cases of multi-interface NICs have been observed so far : + +Internal MII Mux:: + + +------------------+ + | SoC | + | +-----+ | +-----+ + | +-----+ | |-------------| PHY | + | | MAC |--| Mux | | +-----+ +-----+ + | +-----+ | |-----| SFP | + | +-----+ | +-----+ + +------------------+ + +Internal Mux with internal PHY:: + + +------------------------+ + | SoC | + | +-----+ +-----+ + | +-----+ | |-| PHY | + | | MAC |--| Mux | +-----+ +-----+ + | +-----+ | |-----------| SFP | + | +-----+ | +-----+ + +------------------------+ + +External Mux:: + + +---------+ + | SoC | +-----+ +-----+ + | | | |--| PHY | + | +-----+ | | | +-----+ + | | MAC |----| Mux | +-----+ + | +-----+ | | |--| PHY | + | | +-----+ +-----+ + | | | + | GPIO-------+ + +---------+ + +Double-port PHY:: + + +---------+ + | SoC | +-----+ + | | | |--- RJ45 + | +-----+ | | | + | | MAC |---| PHY | +-----+ + | +-----+ | | |---| SFP | + +---------+ +-----+ +-----+ + +phy_port aims at providing a path to support all the above topologies, by +representing the media interfaces in a way that's agnostic to what's drivi= ng +the interface. the struct phy_port object has its own set of callback ops,= and +will eventually be able to report its own ksettings:: + + _____ +------+ + ( )-----| Port | + +-----+ ( ) +------+ + | MAC |--( ??? ) + +-----+ ( ) +------+ + (_____)-----| Port | + +------+ + +Next steps +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +As of writing this documentation, only ports controlled by PHY devices are +supported. The next steps will be to add the Netlink API to expose these +to userspace and add support for raw ports (controlled by some firmware, a= nd directly +managed by the NIC driver). + +Another parallel task is the introduction of a MII muxing framework to all= ow the +control of non-PHY driver multi-port setups. diff --git a/MAINTAINERS b/MAINTAINERS index e0dc230df90e..219c04aab4a6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9283,6 +9283,7 @@ F: Documentation/devicetree/bindings/net/ethernet-con= nector.yaml F: Documentation/devicetree/bindings/net/ethernet-phy.yaml F: Documentation/devicetree/bindings/net/mdio* F: Documentation/devicetree/bindings/net/qca,ar803x.yaml +F: Documentation/networking/phy-port.rst F: Documentation/networking/phy.rst F: drivers/net/mdio/ F: drivers/net/mdio/acpi_mdio.c @@ -17981,6 +17982,7 @@ F: net/ethtool/phy.c NETWORKING [ETHTOOL PHY PORT] M: Maxime Chevallier F: Documentation/devicetree/bindings/net/ethernet-connector.yaml +F: Documentation/networking/phy-port.rst F: drivers/net/phy/phy_port.c F: include/linux/phy_port.h K: struct\s+phy_port|phy_port_ --=20 2.49.0