From nobody Fri Oct 3 00:03:12 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 9983B35AAC3; Tue, 9 Sep 2025 15:27:41 +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=1757431663; cv=none; b=EHDmdK9BrIxzuO9m2k72VFWI0VrMvG/yribfHyo+T2xB1xFR20WQaCvztmpj8zsg15mx92sl5qoPbVK/l2j3+nEPcpZuOmE2tgIkPq4zuuyfzdyNbfg9ZFilFFRMMo9jibbKOPEcApAjL0giNfPkxr/NrjlM/yL9a1c6ZscEiuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757431663; c=relaxed/simple; bh=oDwT/ytfZ0MIgQePhuGpYEa7Pg+a462k96DQXvNJP9c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cw1VVVBhbkh2FS2Pi9yB/kC0JsEVrfD5dnfFnGfWNAF4734HL9bmfE+QNhD2Ndfk5+pQA5xLndzvkSWHoeCibVz4MOcqeIq79stY4LDdMdwrhvZjj1UGmyNOUOTf0TV+YG0MrWMTR5k1rHvvRv22uc7MR3ZJxFLNAsSsq/fuyPY= 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=CaxyKxzP; 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="CaxyKxzP" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 223571A0A15; Tue, 9 Sep 2025 15:27:40 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id E8A3C60630; Tue, 9 Sep 2025 15:27:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7FB00102F28E8; Tue, 9 Sep 2025 17:27:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1757431658; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=5SortobNjbuyn2TGqqPOApb9i2lqjDnCF5/SjqGdns0=; b=CaxyKxzPINy8o8BW6IMR6S1nQht76NJz2XhyvcrhNj9prZGFyU8ZJWpkNmq0Crg64RVTZx lVMN5oqGsDyGsy5INQGrPtOgx/7+GjZ45Rn6ZeDjTvg6AykNsHF0saFLbnqZWFqqT0B81r 4HQtKgHovL+OXLtqO/3O6x4CEWc0aYI8sPZLO/aFJdtOqoHs8vCh0D8/ZFId26kJa3JiVu lOZLPxcUhHFsLhd9H/fW93cWnmpQd10lZdnM4NHgdFPMOvsT8frUZEvnj7bn/g1BCmUiYm umA0vI852gdkUKsSLkMJXMzT94IejGyRpTr9rx/ugGPRKcA+5VkegDhbTZV8TA== 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 Subject: [PATCH net-next v12 07/18] net: phy: Create a phy_port for PHY-driven SFPs Date: Tue, 9 Sep 2025 17:26:03 +0200 Message-ID: <20250909152617.119554-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250909152617.119554-1-maxime.chevallier@bootlin.com> References: <20250909152617.119554-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" 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 anther entity on the link. The PHY driver needs to specify the various PHY_INTERFACE_MODE_XXX that this port supports. Reviewed-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 8f6bef8ee263..d195e15bde11 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1632,6 +1632,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 @@ -1653,6 +1673,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 cf897ed74c4c..6fecaa68350e 100644 --- a/drivers/net/phy/phy_port.c +++ b/drivers/net/phy/phy_port.c @@ -113,6 +113,21 @@ void phy_port_update_supported(struct phy_port *port) phy_caps_medium_get_supported(supported, i, port->lanes); linkmode_or(port->supported, port->supported, supported); } + + /* 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