From nobody Mon Oct 6 11:51:35 2025 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1F6C2EA146; Tue, 22 Jul 2025 12:16:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753186606; cv=none; b=YKmwCNBuAKBCVBsqGH4CWLDnANCY3EUy5/mX/IluBr7ujfmHyuoU4n1Oat8eJdNMLRiARzDw3uEBTlyOSaTdL2oi2rp62Eu5pFCX+C9+Dm9qQ1ZB/54zF0r8tTw5uf4ClsF3OkQBfRZSE+PPfiIs8pgiut28JytG/9RZaiLut7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753186606; c=relaxed/simple; bh=ezcNZPPsulqQ1DwbmXhNh7XZpol9BJzuuCWcBbw88Uc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M9meEDRHrgOeul6u+j80JFO1NthyRvIJzgL9izWBd+hZ592X3+nWB9CIaxHWI+NCpvDK1ZODb5Dxmaw1D9tpmzB4w2hBx+aioOlckimxpfZW9i2WA/KWWhp5ITqYCXubnQNTX89zuWm1dZ17XGdpow/7Y0J0Rhml8YpWsPkMCZw= 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=pRrngC7e; arc=none smtp.client-ip=217.70.183.197 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="pRrngC7e" Received: by mail.gandi.net (Postfix) with ESMTPSA id 20D7243A10; Tue, 22 Jul 2025 12:16:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753186602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lQAZ7stRl5WLTTTFImMuk9n1iZ0cJcfXSt7BRoDfb8c=; b=pRrngC7eS7KkZnAgrcd13MRkvPNRvfI3bzD8UJTvfal+gIrQPicyrCZKVfvYBH7L6jMXmN LmbEiBqmNHVw/9INqMazTeVmiFeGbjl8IdKZCRHAiznqBQ/IHfTYWzeIeuYZ61lcPgsq30 Eci95gmK0AaIkVtqEeAQ+tY6QV2SeqiEyElS3hg8NRA/XSQX9Xe7Da0+4xiNab/gWEnSlK w/uGpRDP70lFo4/4MZ3JX4WSRLzqIUZh6ln8g0KLiydKPNw6L7GHXBxe6tkqVb3qz2ZVtu ziv1m3F1fy1Ip1ZKv7RTJvLgdlJRyuT3spMV4mpmDjYS8u5CZ4QtW5nJ4ft3Yw== 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 v10 06/15] net: phy: Create a phy_port for PHY-driven SFPs Date: Tue, 22 Jul 2025 14:16:11 +0200 Message-ID: <20250722121623.609732-7-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722121623.609732-1-maxime.chevallier@bootlin.com> References: <20250722121623.609732-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-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejgeekkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgvucevhhgvvhgrlhhlihgvrhcuoehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeevgedtffelffelveeuleelgfejfeevvdejhfehgeefgfffvdefteegvedutefftdenucfkphepledtrdejiedriedvrddujedunecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehinhgvthepledtrdejiedriedvrddujedupdhhvghlohepfhgvughorhgrrddrpdhmrghilhhfrhhomhepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepfedupdhrtghpthhtohepuggrvhgvmhesuggrvhgvmhhlohhfthdrnhgvthdprhgtphhtthhopehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmpdhrtghpthhtohepnhgvthguvghvsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhug idqrghrmhdqmhhsmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomhdprhgtphhtthhopegrnhgurhgvfieslhhunhhnrdgthhdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhg X-GND-Sasl: maxime.chevallier@bootlin.com 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 6c6645889352..137d48451959 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1627,6 +1627,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 @@ -1648,6 +1668,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 51870f2378ec..36de8c5c9ad5 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 may 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