From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.85.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382482; b=kdAXJz3hkuHFhzSNq5uqOEZI2tHLzml2vRu3gJ4kvuTCKKAaNzC7LPCFUVfR/RgTWttT vjfi2y65jnKPNiBE28OCOmgReOp9yXq8jC8PrgEf5FBiKqkIgKRiMo7NWaJ8ypxi0Gwmw N/maZFhw+921xskQariPMpo/IuIATbYa0S+ogFEpaCes9HuGBhL10cmUoU/+A82/yaSMl 4kjZwWRQWu69KV8mLbzJw5QQ3iGKvOO+ZN4cUUWXaklkJkugHGtsjwMFsdBVrh33jHNGN jwmL/HcSosQMNhJzgeGOyffLWx1OBOaNznaoqCSKNFeX7fY4FZy6ASl7KBQ16JudCrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382482; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=j9fhQ6ybPDBiebKPbEmWU+imhPTG5xq363PN6x/O0nI=; b=qJjIeM8A7HG+47sALlBSu4mSjnWYyq5UzGXUxWl8dsaETvlCd7f9YyZiGioE6b0gweqZ XwmulYLz2UIBosq4/TFbBmm7t5xQHvhVyLbmze5BrJlLghkeY3ovQNQphbD2UqmVec5rl dBD3SZN00p2SWqigcRvKEuu6izakEsdUnYGryqXYS3gb3QdrqT0InDv61ST8JoxmXJH1F ViZ6elfUfPlNsA5pGvyxdRiKib860PRVmr+xNbOWOnW35waR1wxp6jviiduw2BdItw4nS oW1B62znxmq4L4VwCOKEiRDZ19PsOcRl+KCSHobp2llwCOhFDQBzzk+4h22hVhF7wkQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=h+GXZp5y; arc=none smtp.remote-ip=185.246.85.4 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 13837606A332 for ; Fri, 4 Dec 2026 11:08:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 13837606A332 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.a=rsa-sha256 header.s=dkim header.b=h+GXZp5y Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id A04404E4185D; 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-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 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