From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: davem@davemloft.net, "Andrew Lunn" <andrew+netdev@lunn.ch>,
"Jakub Kicinski" <kuba@kernel.org>,
"Eric Dumazet" <edumazet@kernel.org>,
"Willem de Bruijn" <willemb@google.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Russell King" <linux@armlinux.org.uk>,
"Marek Behún" <kabel@kernel.org>,
"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
"Gregory Clement" <gregory.clement@bootlin.com>,
"Heiner Kallweit" <hkallweit1@gmail.com>
Cc: "Maxime Chevallier" <maxime.chevallier@bootlin.com>,
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" <conor+dt@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Herve Codina" <herve.codina@bootlin.com>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Vladimir Oltean" <vladimir.oltean@nxp.com>,
"Köry Maincent" <kory.maincent@bootlin.com>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Nicolò Veronese" <nicveronese@gmail.com>,
"Simon Horman" <horms@kernel.org>,
marcin.s.wojtas@gmail.com, "Daniel Golle" <daniel@makrotopia.org>,
"Dimitri Fedrau" <dimitri.fedrau@liebherr.com>,
"Frank Wunderlich" <frank.wunderlich@linux.dev>,
"Pietro Ameruoso" <p.ameruoso@live.it>,
"Aleksei Sviridkin" <f@lex.la>
Subject: [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux
Date: Fri, 4 Dec 2026 12:06:18 +0100 [thread overview]
Message-ID: <20261204110622.1106492-10-maxime.chevallier@bootlin.com> (raw)
In-Reply-To: <20261204110622.1106492-1-maxime.chevallier@bootlin.com>
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 <maxime.chevallier@bootlin.com>
---
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 <linux/phy.h>
#include <linux/phy_fixed.h>
#include <linux/phy_link_topology.h>
+#include <linux/phy_mux.h>
#include <linux/phy_port.h>
#include <linux/phylink.h>
#include <linux/rtnetlink.h>
@@ -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
next prev parent reply other threads:[~2026-12-04 11:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 01/12] dt-bindings: net: Add Ethernet " Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 02/12] net: phy: Introduce phy_mux, a MII multiplexer representation Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 03/12] net: phy: Don't create the sysfs links for PHYs behind a mux Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 07/12] net: phylink: Factor out phylink_clear_phydev() Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 08/12] net: phy: phy_mux: Add phy_mux_set_mac_managed_pm() Maxime Chevallier
2026-12-04 11:06 ` Maxime Chevallier [this message]
2026-12-04 11:06 ` [PATCH net-next 10/12] net: phylink: Support an SFP cage behind a phy_mux Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 12/12] ARM: dts: turris-omnia: Describe the WAN port multiplexer Maxime Chevallier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204110622.1106492-10-maxime.chevallier@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=christophe.leroy@csgroup.eu \
--cc=conor+dt@kernel.org \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=dimitri.fedrau@liebherr.com \
--cc=edumazet@kernel.org \
--cc=f.fainelli@gmail.com \
--cc=f@lex.la \
--cc=frank.wunderlich@linux.dev \
--cc=gregory.clement@bootlin.com \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kabel@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=marcin.s.wojtas@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=nicveronese@gmail.com \
--cc=o.rempel@pengutronix.de \
--cc=p.ameruoso@live.it \
--cc=pabeni@redhat.com \
--cc=robh@kernel.org \
--cc=sebastian.hesselbarth@gmail.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.oltean@nxp.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox