From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5578A606A33D for ; Fri, 4 Dec 2026 11:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=h9NOUw2C; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=JbZuqsDY DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=7z04IZ+/FjHnhqx+apRahTycQXBb+FbnziBrOWtrxKk=; b=h9NOUw2CYG7Gaa 0V+D+Gx74dWP5iCoMir4kEr8hm4ZFTmBavVujtfcmAjkU0iw9pPwLK9iLlhjK6gZ1D9ByTiRS1mT/ I+0dDJNpH5jZ7GkD5F9kGf4sQUxtY/fg7B4sFkoMZUjmoCRAIVAtGIunX6wEvlItmaU3BRCVtRFsU 5POYbOa8TEhFVuR5crSqMh1518kb+zjprQT3vGuKgB5OMd+O0nSNG4K7BuF3OzEV1PjOP7yWQRzeJ QY6MG07ui1aFtcqgOvUDdPBLTOQFT8ytuBstg1ddt8QKqndl/eBn4+XhLwT0xJLrJZdpMCHtKoJyK DciHtjC3/O2lA92QMxmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZR9a-000000004oV-0nqw; Fri, 04 Dec 2026 11:08:38 +0000 Received: from smtpout-04.galae.net ([185.171.202.116]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZR9D-000000004Yr-3wUU for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 11:08:18 +0000 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id E36A8C026D7; Fri, 4 Dec 2026 11:08:25 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 19DEF603C4; Fri, 4 Dec 2026 11:08:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D83F411EA196C; Fri, 04 Dec 2026 12:07:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796382486; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=7z04IZ+/FjHnhqx+apRahTycQXBb+FbnziBrOWtrxKk=; b=JbZuqsDYDEaqjKhbiE7ZLKSP62obfmjKzQYEsUqH8JOBEtaBwaPIM3b1YM+gUMRFz96GrC Hk4luJWmBTfg74xOSzxE4l3DYCri7+jkRpXrl8Z6l7MiMUyORXdmaPzCJrgFY2Tn08YXtg I+j9MJ5HA6RzhN5HK/HM62Rbq+tNdWT2uM6UJJ4KINeWZyQx+P9jR0RTSQIo+UTjBSIy6v 9VcTX4CSCN5Ff55d81cc/ryRYlHl808xsfDa2Yh22V9VK0JQZqDrhBB1ajqDx4DCl2md1q 7xgq4x2hznxvU8ZGAD+CgyftPW/R+6v30/MOTBBIkQADaJF+L/a1QNQ415CC3Q== From: Maxime Chevallier To: davem@davemloft.net, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Willem de Bruijn , Paolo Abeni , Russell King , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Sebastian Hesselbarth , Gregory Clement , Heiner Kallweit Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, thomas.petazzoni@bootlin.com, devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Christophe Leroy , Herve Codina , Florian Fainelli , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , marcin.s.wojtas@gmail.com, Daniel Golle , Dimitri Fedrau , Frank Wunderlich , Pietro Ameruoso , Aleksei Sviridkin Subject: [PATCH net-next 10/12] net: phylink: Support an SFP cage behind a phy_mux Date: Fri, 4 Dec 2026 12:06:19 +0100 Message-ID: <20261204110622.1106492-11-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204110622.1106492-1-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-1-maxime.chevallier@bootlin.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_030817_019645_A14D5865 X-CRM114-Status: GOOD ( 21.71 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 With a mux, the SFP cage isn't described in the MAC's node but in one of the mux ports. phylink is still the upstream of that cage, so let's look for it there as well. >From there, modules are handled the same way as with any other MAC-driven cage. What phylink needs to do on top of that is tell the mux when a module is there, with phy_mux_port_set_available(), so that the mux can select the SFP port, and go back to the PHY port when the module is removed. There's one limitation for now, we only report the modules that phylink accepted. On the Turris Omnia the mux switches for any module though, so with an unsupported module we're left with the PHY port selected while the MAC is wired to the cage. Handling that needs a new SFP upstream callback to follow the raw module presence, this is left for later. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phylink.c | 94 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 702614adcb94..6d62bd37f95a 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -93,12 +93,17 @@ struct phylink { struct sfp_bus *sfp_bus; bool sfp_may_have_phy; + bool sfp_mod_present; + bool sfp_behind_mux; + bool sfp_selected; + bool sfp_link_down; DECLARE_PHY_INTERFACE_MASK(sfp_interfaces); __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); u8 sfp_port; struct phy_port *sfp_cage_port; struct phy_port *mod_port; struct phy_mux *mux; + struct phy_mux_port *mux_sfp_port; struct eee_config eee_cfg; @@ -1876,6 +1881,30 @@ static int phylink_register_sfp(struct phylink *pl, return ret; } +static int phylink_register_mux_sfp(struct phylink *pl, + const struct fwnode_handle *fwnode) +{ + struct fwnode_handle *mux_fwnode, *sfp_fwnode; + int ret; + + mux_fwnode = fwnode_find_reference(fwnode, "mii-mux-handle", 0); + if (IS_ERR(mux_fwnode)) + return phylink_register_sfp(pl, fwnode); + + sfp_fwnode = fwnode_phy_mux_find_sfp_port(mux_fwnode); + fwnode_handle_put(mux_fwnode); + if (!sfp_fwnode) + return phylink_register_sfp(pl, fwnode); + + pl->sfp_behind_mux = true; + pl->sfp_link_down = true; + + ret = phylink_register_sfp(pl, sfp_fwnode); + fwnode_handle_put(sfp_fwnode); + + return ret; +} + /** * phylink_set_fixed_link() - set the fixed link * @pl: a pointer to a &struct phylink returned from phylink_create() @@ -2128,7 +2157,7 @@ struct phylink *phylink_create(struct phylink_config *config, pl->req_link_an_mode = pl->cfg_link_an_mode; - ret = phylink_register_sfp(pl, fwnode); + ret = phylink_register_mux_sfp(pl, fwnode); if (ret < 0) goto release_link_gpio; @@ -2150,6 +2179,7 @@ static void phylink_detach_mux(struct phylink *pl) phy_mux_detach(pl->mux); pl->mux = NULL; + pl->mux_sfp_port = NULL; } /** @@ -2766,6 +2796,9 @@ void phylink_start(struct phylink *pl) phy_start(pl->phydev); if (pl->sfp_bus) sfp_upstream_start(pl->sfp_bus); + if (pl->mux_sfp_port) + phy_mux_port_set_available(pl->mux_sfp_port, + pl->sfp_mod_present); if (pl->mux) phy_mux_start(pl->mux); } @@ -3842,7 +3875,8 @@ int phylink_speed_down(struct phylink *pl, bool sync) ASSERT_RTNL(); - if (!pl->sfp_bus && pl->phydev) + if (pl->phydev && + (!pl->sfp_bus || (pl->sfp_behind_mux && !pl->sfp_selected))) ret = phy_speed_down(pl->phydev, sync); return ret; @@ -3865,7 +3899,8 @@ int phylink_speed_up(struct phylink *pl) ASSERT_RTNL(); - if (!pl->sfp_bus && pl->phydev) + if (pl->phydev && + (!pl->sfp_bus || (pl->sfp_behind_mux && !pl->sfp_selected))) ret = phy_speed_up(pl->phydev); return ret; @@ -3884,6 +3919,10 @@ static void phylink_sfp_detach(void *upstream, struct sfp_bus *bus) struct phylink *pl = upstream; pl->netdev->sfp_bus = NULL; + + pl->sfp_mod_present = false; + if (pl->mux_sfp_port) + phy_mux_port_set_available(pl->mux_sfp_port, false); } static phy_interface_t phylink_choose_sfp_interface(struct phylink *pl, @@ -4082,11 +4121,19 @@ static int phylink_sfp_config_optical(struct phylink *pl) return 0; } +static void phylink_sfp_set_present(struct phylink *pl, bool present) +{ + pl->sfp_mod_present = present; + if (pl->mux_sfp_port) + phy_mux_port_set_available(pl->mux_sfp_port, present); +} + static int phylink_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id) { const struct sfp_module_caps *caps; struct phylink *pl = upstream; + int ret; ASSERT_RTNL(); @@ -4096,18 +4143,27 @@ static int phylink_sfp_module_insert(void *upstream, pl->sfp_may_have_phy = caps->may_have_phy; pl->sfp_port = caps->port; + phylink_sfp_set_present(pl, true); + /* If this module may have a PHY connecting later, defer until later */ if (pl->sfp_may_have_phy) return 0; - return phylink_sfp_config_optical(pl); + ret = phylink_sfp_config_optical(pl); + if (ret) + phylink_sfp_set_present(pl, false); + + return ret; } static void phylink_sfp_module_remove(void *upstream) { struct phylink *pl = upstream; + ASSERT_RTNL(); + phy_interface_zero(pl->sfp_interfaces); + phylink_sfp_set_present(pl, false); } static int phylink_add_sfp_mod_port(struct phylink *pl) @@ -4211,6 +4267,10 @@ static void phylink_sfp_link_down(void *upstream) ASSERT_RTNL(); + pl->sfp_link_down = true; + if (pl->sfp_behind_mux && !pl->sfp_selected) + return; + phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_LINK); } @@ -4220,6 +4280,10 @@ static void phylink_sfp_link_up(void *upstream) ASSERT_RTNL(); + pl->sfp_link_down = false; + if (pl->sfp_behind_mux && !pl->sfp_selected) + return; + phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_LINK); } @@ -4268,6 +4332,7 @@ static void phylink_mux_attach(struct phy_mux *mux, void *priv) phy_mux_set_mac_managed_pm(mux); pl->mux = mux; + pl->mux_sfp_port = phy_mux_get_sfp_port(mux); } static int phylink_mux_select(struct phy_mux *mux, struct phy_mux_port *port, @@ -4277,6 +4342,19 @@ static int phylink_mux_select(struct phy_mux *mux, struct phy_mux_port *port, struct phy_device *phy; int ret; + if (port->type == PHY_MUX_PORT_SFP) { + if (!pl->sfp_bus) + return -ENODEV; + + pl->sfp_selected = true; + if (pl->sfp_link_down) + phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_LINK); + else + phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_LINK); + + return 0; + } + if (port->type != PHY_MUX_PORT_PHY) return -EOPNOTSUPP; @@ -4291,7 +4369,10 @@ static int phylink_mux_select(struct phy_mux *mux, struct phy_mux_port *port, return ret; } + clear_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state); + pl->link_config.interface = port->interface; + pl->req_link_an_mode = pl->cfg_link_an_mode; phylink_mac_initial_config(pl, false); phy_start(phy); @@ -4304,7 +4385,10 @@ static void phylink_mux_deselect(struct phy_mux *mux, struct phylink *pl = priv; struct phy_device *phy; - if (pl->phydev != port->phydev) + if (port->type == PHY_MUX_PORT_SFP) + pl->sfp_selected = false; + + if (port->type != PHY_MUX_PORT_PHY || pl->phydev != port->phydev) return; phy = port->phydev; -- 2.56.1