From nobody Mon Feb 9 14:32:36 2026 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 5CDD63D522A for ; Tue, 3 Feb 2026 17:29:09 +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=1770139750; cv=none; b=Sqo4r98AFSSeN0Iq/B0LRdZeNqooh6WNwgukZ5nj57JzWfUgGB5Uv6f0/ErAtIcaOUqxqFlR7aJv6AO01+dnnKaHxUPCnK1gZk9L9kNdmsZHgni+Tze1N40/L2GdNNqV9jAlPZqWBkW5wBmyC+ZHeALV1YSQQkfef1Vy5Ot5cSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770139750; c=relaxed/simple; bh=kxYprBgxtxpbPjIF2eIjiXbk7fRIQtp2OGCSGG0bxyU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ag/xv4wtVAkk6+F6Dlncv3klfg7kIB0KaNM2CX0et258JiCB5YKjiXHnBBQeELcthWy7wI60yOLbjbaEjtY9AqIRSbYaz3qhrWF0aq6xT+p5qwFkderubf530oSwOO3z/hO9soPoo1yWq3OT9HA2KStT9ocH3Mciibz+4J2B9Fk= 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=xZMgkmep; 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="xZMgkmep" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 20E811A2BC5; Tue, 3 Feb 2026 17:29:08 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id E6DE760728; Tue, 3 Feb 2026 17:29:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 11DDB119A88FF; Tue, 3 Feb 2026 18:29:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1770139746; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=9VMJCSTaZs0qZ6Spe9WxRX/vem2r/rMxnfYcMsORs4w=; b=xZMgkmep7uj1kHyhIDYZ5V1XcTDtVjt0RQms+3rLioJOmz+j2N/UCt4RXR2G62ubSVzvSh Gctz9Iln/fN28oS69I+oKgrMb79S3TB9OX2VOFV3YBhHDMQ68bX+4l9Sddbf5bGBiuVB3w EBLghO7QjOUISnxX+lYyBq8J0MJUJsaS7kVGIlU9Lq7MnQ4BHkztL2BKPf0eF/voVE9MPN UN8qrp0jyCt7qnYrbBm1TzsewzxxM+Gi/6MKagJx6UyGfYmJoLUzcL/qQBzSDAzHHVXvKy 3DTrz6ZS/7/bFstJ+kXAbn0X1/XBk/MlMIyaQBE2zqo5ihU1gnXRhPD6IDCAkA== From: Maxime Chevallier To: davem@davemloft.net, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , Heiner Kallweit Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Christophe Leroy , Herve Codina , Florian Fainelli , 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, Romain Gantois , Daniel Golle , Dimitri Fedrau Subject: [PATCH net-next v4 06/13] net: phylink: Register a phy_port for MAC-driven SFP busses Date: Tue, 3 Feb 2026 18:28:30 +0100 Message-ID: <20260203172839.548524-7-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260203172839.548524-1-maxime.chevallier@bootlin.com> References: <20260203172839.548524-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" phy_port tracks the interfaces that a netdevice feeds into. SFP cages are such ports, but so far we are only tracking the ones that are driven by PHYs acting as media-converters. Let's populate a phy_port for MAC driver SFP cages, handled by phylink. This phy_port represents the SFP cage itself, and not the module that may be plugged into it. It's therefore not an MDI interface, so only the 'interfaces' field is relevant here. The phy_port is only populated for 'NETDEV' phylink instances, as otherwise we don't have any topology to attach the port to. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phylink.c | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index e1f01d7fc4da..7a07de1d42bb 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -93,6 +95,7 @@ struct phylink { DECLARE_PHY_INTERFACE_MASK(sfp_interfaces); __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); u8 sfp_port; + struct phy_port *sfp_bus_port; =20 struct eee_config eee_cfg; =20 @@ -1758,6 +1761,46 @@ static void phylink_fixed_poll(struct timer_list *t) =20 static const struct sfp_upstream_ops sfp_phylink_ops; =20 +static int phylink_create_sfp_port(struct phylink *pl) +{ + struct phy_port *port; + int ret =3D 0; + + if (!pl->netdev || !pl->sfp_bus) + return 0; + + port =3D phy_port_alloc(); + if (!port) + return -ENOMEM; + + port->is_sfp =3D true; + port->is_mii =3D true; + port->active =3D true; + + phy_interface_and(port->interfaces, pl->config->supported_interfaces, + phylink_sfp_interfaces); + phy_port_update_supported(port); + + ret =3D phy_link_topo_add_port(pl->netdev, port); + if (ret) + phy_port_destroy(port); + else + pl->sfp_bus_port =3D port; + + return ret; +} + +static void phylink_destroy_sfp_port(struct phylink *pl) +{ + if (pl->netdev && pl->sfp_bus_port) + phy_link_topo_del_port(pl->netdev, pl->sfp_bus_port); + + if (pl->sfp_bus_port) + phy_port_destroy(pl->sfp_bus_port); + + pl->sfp_bus_port =3D NULL; +} + static int phylink_register_sfp(struct phylink *pl, const struct fwnode_handle *fwnode) { @@ -1775,9 +1818,18 @@ static int phylink_register_sfp(struct phylink *pl, =20 pl->sfp_bus =3D bus; =20 + ret =3D phylink_create_sfp_port(pl); + if (ret) { + sfp_bus_put(bus); + return ret; + } + ret =3D sfp_bus_add_upstream(bus, pl, &sfp_phylink_ops); sfp_bus_put(bus); =20 + if (ret) + phylink_destroy_sfp_port(pl); + return ret; } =20 @@ -1939,6 +1991,7 @@ EXPORT_SYMBOL_GPL(phylink_create); void phylink_destroy(struct phylink *pl) { sfp_bus_del_upstream(pl->sfp_bus); + phylink_destroy_sfp_port(pl); if (pl->link_gpio) gpiod_put(pl->link_gpio); =20 --=20 2.49.0