From nobody Mon Feb 9 01:29:57 2026 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 E676837474C; Wed, 28 Jan 2026 20:45:59 +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=1769633165; cv=none; b=CEiqHRTpzFrFtYEOyVe4oP8jMsQF6meTUm1ZyOzBN6axzfSkHkIMuvl8HeSh9QKZ0pdwQapkLqX0s/Ce2aD4N5gb9xYG0awoM2IqJvBYz7txDMBvTHKwIEiAc+GRJjJDykzV0PCUfjZrMLJiBqXBnBn3sa9HG2CK+2e6gVb8vN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769633165; c=relaxed/simple; bh=07iRNpUNsbBPH6Szj7tXNtrkE9omvubg/HSfMgsnHeE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HbolO32qVZBW03EAHC9byY19cJIWHc5C+IcQ8JqFN+8OrFiorT/2JW3bAakftdwLvhonzl6INQk/P/HMhlWHKWobrhG8NhjxvnPWSidL3hNVYwiqZkOURMGWNM7359IfkNjedlzDecwZPGcUaU3aaTg+gW+9f5XF1JK9B6P9Vmc= 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=Q1s+mY2T; 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="Q1s+mY2T" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 26A77C211F2; Wed, 28 Jan 2026 20:46:01 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 7B2C56071F; Wed, 28 Jan 2026 20:45:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 730D3119A8839; Wed, 28 Jan 2026 21:45:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1769633157; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=aSlo6fpytFPeRO/3rcUa8O6Tp4iGzNbOtCMyHVTaty0=; b=Q1s+mY2Ton5mlNsrOlHjSulUZrAlhlKD5obe7wcJU9FHm+FF2Gx0KfT40BW+gK146k/Nvk YxLITH/mpbifJbLiExWSboq85psYkq7XNTuDBS+GZGBJ7rB3E9pOYcIwK/DVNuKJaOBVHk fMIZ8nzAg7jwYFckHaH4lkVH1YMirG+Keq/NYfD69t8A06AJUJEkIbFyKR6BBOIpHfle+k 7u5NRTOurPNoZWpStm9SQcgHTeMyAGZCasKgEQ/7f6g+Q4FzATyrfQPBXeUYwevz+Zc2iv vmyi7+v9ZInaZ954LX6xrmnaPIvWCKsf38QXiET3RZ+mZ02UZRl9S0esWns1/w== 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 v2 08/12] net: phylink: Represent PHY-less SFP modules with phy_port Date: Wed, 28 Jan 2026 21:45:21 +0100 Message-ID: <20260128204526.170927-9-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260128204526.170927-1-maxime.chevallier@bootlin.com> References: <20260128204526.170927-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" Let phylink handle the phy_port for PHY-less modules, and register it to the topology. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phylink.c | 71 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 310af33d49a0..21af1dffa837 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -96,6 +96,7 @@ struct phylink { __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); u8 sfp_port; struct phy_port *sfp_bus_port; + struct phy_port *mod_port; =20 struct eee_config eee_cfg; =20 @@ -1786,13 +1787,31 @@ static int phylink_create_sfp_port(struct phylink *= pl) else pl->sfp_bus_port =3D port; =20 + if (pl->mod_port) { + ret =3D phy_link_topo_add_port(pl->netdev, pl->mod_port); + if (ret) + goto out_bus_port; + } + + return 0; +out_bus_port: + phy_link_topo_del_port(pl->netdev, port); + phy_port_destroy(port); return ret; } =20 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->netdev) { + if (pl->sfp_bus_port) + phy_link_topo_del_port(pl->netdev, pl->sfp_bus_port); + + /* Only remove it from the topology, it will be destroyed at + * module removal. + */ + if (pl->mod_port) + phy_link_topo_del_port(pl->netdev, pl->mod_port); + } =20 if (pl->sfp_bus_port) phy_port_destroy(pl->sfp_bus_port); @@ -3998,6 +4017,52 @@ static void phylink_sfp_disconnect_phy(void *upstrea= m, phylink_disconnect_phy(upstream); } =20 +static int phylink_sfp_connect_nophy(void *upstream) +{ + const struct sfp_module_caps *caps; + struct phylink *pl =3D upstream; + struct phy_port *port; + int ret =3D 0; + + if (!pl->sfp_bus_port) + return 0; + + /* Create mod port */ + port =3D phy_port_alloc(); + if (!port) + return -ENOMEM; + + port->active =3D true; + + caps =3D sfp_get_module_caps(pl->sfp_bus); + + phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes, + pl->sfp_bus_port->interfaces); + + if (pl->netdev) { + ret =3D phy_link_topo_add_port(pl->netdev, port); + if (ret) { + phy_port_destroy(port); + return ret; + } + } + + pl->mod_port =3D port; + + return 0; +} + +static void phylink_sfp_disconnect_nophy(void *upstream) +{ + struct phylink *pl =3D upstream; + + if (pl->netdev) + phy_link_topo_del_port(pl->netdev, pl->mod_port); + + phy_port_destroy(pl->mod_port); + pl->mod_port =3D NULL; +} + static const struct sfp_upstream_ops sfp_phylink_ops =3D { .attach =3D phylink_sfp_attach, .detach =3D phylink_sfp_detach, @@ -4009,6 +4074,8 @@ static const struct sfp_upstream_ops sfp_phylink_ops = =3D { .link_down =3D phylink_sfp_link_down, .connect_phy =3D phylink_sfp_connect_phy, .disconnect_phy =3D phylink_sfp_disconnect_phy, + .connect_nophy =3D phylink_sfp_connect_nophy, + .disconnect_nophy =3D phylink_sfp_disconnect_nophy, }; =20 /* Helpers for MAC drivers */ --=20 2.49.0