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 D3671606A32D 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=pMCbJGTf; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=h+GXZp5y 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=j9fhQ6ybPDBiebKPbEmWU+imhPTG5xq363PN6x/O0nI=; b=pMCbJGTf1GfXgh cCOoSDN1xHNjMYNTBXD65J9P9KVteJbmMRe+PDW4cusfmXk75e++yCJ9Hy5oSGdkgP2Y8JZ1N30Yl jKnVYuObqbnUEfDvL9ejrSwRyodptMpiU5rkekN+Q3P6gKfDkf5XSpsWo4k6yTphKsWYbnhESnIsn quCZzbC/qcz0Urx4P8cZpC2i0P72EKNOv9xXl7XZmRLCE/Zy4L/vlWenYCHwd9QnDCdt5PR1s9xOy r5mIQoITUTrhjBAuylvYvVUBhDdpZ3Rho0bl2+hRgJEq5lIaV+z6Cz5D6ul9vRfto6xqhjtAlLE+N kAKY/TKjkMdPHULi7cbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZR9Z-000000004o9-46I1; Fri, 04 Dec 2026 11:08:37 +0000 Received: from smtpout-02.galae.net ([185.246.84.56]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZR90-000000004WU-1Ck9 for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 11:08:17 +0000 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 9969C1A1947; Fri, 4 Dec 2026 11:08:00 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 68E25603C4; Fri, 4 Dec 2026 11:08:00 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B8C4411EA1940; Fri, 04 Dec 2026 12:07:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796382473; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=j9fhQ6ybPDBiebKPbEmWU+imhPTG5xq363PN6x/O0nI=; b=h+GXZp5yTOS+oR6d64INCa225Y21SoyEXTpTf8mw0RZY0UC5N2LzFc5VJT7NDnvjjLAX5D qZsIDJiEbxz52vgiNw3VEf221jYV+2xyoteom223SrStpYlLQKw/7aXkOwMGi5f9soCRan TRsxpRs3rDjxH0WjXIGAjvyM7akFa1VWRkGHbjzQaPJwlxBU3RSg/7SoH/QploTXelLkGQ PmydxdIPWwMFVgjJABKdah+FZR4o/KVFbEo/TJVwD7Y7r5W5Q6EUWfWiU96cKVP8xtXfPD +hc7pzc+dbmT4nTEDuynbxsyPlgVsNcXmH9ikqCYGNC3DP2d6aWmnY1gaN67Cw== 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 09/12] net: phylink: Support PHYs reached through a phy_mux Date: Fri, 4 Dec 2026 12:06:18 +0100 Message-ID: <20261204110622.1106492-10-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_030811_538601_45E871E8 X-CRM114-Status: GOOD ( 23.22 ) 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 Now that we have phy_mux, we need something to act as its parent, i.e. something that reconfigures the MAC side each time the mux switches. phylink is the right place for that, it already knows how to bring a PHY up and how to configure the MAC and PCS for it. When the MAC's node has a mii-mux-handle property, phylink_fwnode_phy_connect() now attaches to the mux instead of connecting to a PHY. phylink starts and stops the mux along with the interface, and implements the parent_ops: - select: bring up the port's PHY, configure the MAC and start the PHY - deselect: stop the PHY The PHYs are attached to the netdev by the mux, so phylink doesn't attach nor detach them. One side-effect is that phylink has no PHY between the time it attaches to the mux and the first selection, which only happens after phylink_start(). When a mux is used, MAC drivers can't assume there's a PHY right after phylink_fwnode_phy_connect() anymore. Only PHY ports are handled for now, SFP ports come next. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phylink.c | 154 +++++++++++++++++++++++++++++++++++--- 1 file changed, 144 insertions(+), 10 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 03e255f5ceb1..702614adcb94 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -97,6 +98,7 @@ struct phylink { u8 sfp_port; struct phy_port *sfp_cage_port; struct phy_port *mod_port; + struct phy_mux *mux; struct eee_config eee_cfg; @@ -2141,6 +2143,15 @@ struct phylink *phylink_create(struct phylink_config *config, } EXPORT_SYMBOL_GPL(phylink_create); +static void phylink_detach_mux(struct phylink *pl) +{ + if (!pl->mux) + return; + + phy_mux_detach(pl->mux); + pl->mux = NULL; +} + /** * phylink_destroy() - cleanup and destroy the phylink instance * @pl: a pointer to a &struct phylink returned from phylink_create() @@ -2153,6 +2164,7 @@ EXPORT_SYMBOL_GPL(phylink_create); void phylink_destroy(struct phylink *pl) { sfp_bus_del_upstream(pl->sfp_bus); + phylink_detach_mux(pl); phylink_destroy_sfp_cage_port(pl); if (pl->link_gpio) gpiod_put(pl->link_gpio); @@ -2326,9 +2338,13 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, phy->phy_link_change = phylink_phy_change; irq_str = phy_attached_info_irq(phy); - phylink_info(pl, - "PHY [%s] driver [%s] (irq=%s)\n", - dev_name(&phy->mdio.dev), phy->drv->name, irq_str); + if (phy->mux_port) + phylink_dbg(pl, "PHY [%s] driver [%s] (irq=%s)\n", + dev_name(&phy->mdio.dev), phy->drv->name, irq_str); + else + phylink_info(pl, + "PHY [%s] driver [%s] (irq=%s)\n", + dev_name(&phy->mdio.dev), phy->drv->name, irq_str); kfree(irq_str); mutex_lock(&pl->phydev_mutex); @@ -2494,6 +2510,34 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn, } EXPORT_SYMBOL_GPL(phylink_of_phy_connect); +static const struct phy_mux_parent_ops phylink_mux_ops; + +static int phylink_attach_mux(struct phylink *pl, + const struct fwnode_handle *fwnode, u32 flags) +{ + struct fwnode_handle *mux_fwnode; + int ret; + + if (pl->mux || !IS_ENABLED(CONFIG_PHY_MUX)) + return 0; + + if (pl->config->type != PHYLINK_NETDEV) + return 0; + + mux_fwnode = fwnode_find_reference(fwnode, "mii-mux-handle", 0); + if (IS_ERR(mux_fwnode)) + return 0; + + if (pl->config->mac_requires_rxc) + flags |= PHY_F_RXC_ALWAYS_ON; + + ret = fwnode_phy_mux_attach(mux_fwnode, pl->netdev, flags, + &phylink_mux_ops, pl); + fwnode_handle_put(mux_fwnode); + + return ret == -EPROBE_DEFER ? -ENODEV : ret; +} + /** * phylink_fwnode_phy_connect() - connect the PHY specified in the fwnode. * @pl: a pointer to a &struct phylink returned from phylink_create() @@ -2501,7 +2545,7 @@ EXPORT_SYMBOL_GPL(phylink_of_phy_connect); * @flags: PHY-specific flags to communicate to the PHY device driver * * Connect the phy specified @fwnode to the phylink instance specified - * by @pl. + * by @pl, or attach to the PHY multiplexer it refers to. * * Returns 0 on success or a negative errno. */ @@ -2516,6 +2560,13 @@ int phylink_fwnode_phy_connect(struct phylink *pl, if (!phylink_expects_phy(pl)) return 0; + ret = phylink_attach_mux(pl, fwnode, flags); + if (ret) + return ret; + + if (pl->mux) + return 0; + phy_fwnode = fwnode_get_phy_node(fwnode); if (IS_ERR(phy_fwnode)) { /* PHY mode requires a PHY to be specified. */ @@ -2578,19 +2629,26 @@ static struct phy_device *phylink_clear_phydev(struct phylink *pl) return phy; } +static void phylink_disconnect_current_phy(struct phylink *pl) +{ + struct phy_device *phy = phylink_clear_phydev(pl); + + if (phy) + phy_disconnect(phy); +} + /** * phylink_disconnect_phy() - disconnect any PHY attached to the phylink * instance. * @pl: a pointer to a &struct phylink returned from phylink_create() * - * Disconnect any current PHY from the phylink instance described by @pl. + * Disconnect any current PHY from the phylink instance described by @pl, + * and detach from its PHY multiplexer if it has one. */ void phylink_disconnect_phy(struct phylink *pl) { - struct phy_device *phy = phylink_clear_phydev(pl); - - if (phy) - phy_disconnect(phy); + phylink_detach_mux(pl); + phylink_disconnect_current_phy(pl); } EXPORT_SYMBOL_GPL(phylink_disconnect_phy); @@ -2708,6 +2766,8 @@ void phylink_start(struct phylink *pl) phy_start(pl->phydev); if (pl->sfp_bus) sfp_upstream_start(pl->sfp_bus); + if (pl->mux) + phy_mux_start(pl->mux); } EXPORT_SYMBOL_GPL(phylink_start); @@ -2727,6 +2787,8 @@ void phylink_stop(struct phylink *pl) { ASSERT_RTNL(); + if (pl->mux) + phy_mux_stop(pl->mux); if (pl->sfp_bus) sfp_upstream_stop(pl->sfp_bus); if (pl->phydev) @@ -4194,10 +4256,82 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy) static void phylink_sfp_disconnect_phy(void *upstream, struct phy_device *phydev) { - phylink_disconnect_phy(upstream); + phylink_disconnect_current_phy(upstream); phy_set_upstream_port(phydev, NULL); } +static void phylink_mux_attach(struct phy_mux *mux, void *priv) +{ + struct phylink *pl = priv; + + if (pl->config->mac_managed_pm) + phy_mux_set_mac_managed_pm(mux); + + pl->mux = mux; +} + +static int phylink_mux_select(struct phy_mux *mux, struct phy_mux_port *port, + void *priv) +{ + struct phylink *pl = priv; + struct phy_device *phy; + int ret; + + if (port->type != PHY_MUX_PORT_PHY) + return -EOPNOTSUPP; + + if (pl->phydev) + return -EBUSY; + + phy = port->phydev; + + ret = phylink_bringup_phy(pl, phy, port->interface); + if (ret) { + phy->phylink = NULL; + return ret; + } + + pl->link_config.interface = port->interface; + phylink_mac_initial_config(pl, false); + phy_start(phy); + + return 0; +} + +static void phylink_mux_deselect(struct phy_mux *mux, + struct phy_mux_port *port, void *priv) +{ + struct phylink *pl = priv; + struct phy_device *phy; + + if (pl->phydev != port->phydev) + return; + + phy = port->phydev; + + if (phy_is_started(phy) || phy->state == PHY_ERROR) + phy_stop(phy); + + phylink_clear_phydev(pl); + + if (phy_interrupt_is_valid(phy)) + phy_free_interrupt(phy); + + phy->phylink = NULL; +} + +static void phylink_mux_detach(struct phy_mux *mux, void *priv) +{ + phylink_detach_mux(priv); +} + +static const struct phy_mux_parent_ops phylink_mux_ops = { + .attach = phylink_mux_attach, + .select = phylink_mux_select, + .deselect = phylink_mux_deselect, + .detach = phylink_mux_detach, +}; + static const struct sfp_upstream_ops sfp_phylink_ops = { .attach = phylink_sfp_attach, .detach = phylink_sfp_detach, -- 2.56.1