* [PATCH net-next 00/12] net: phy: Introduce MII multiplexers
@ 2026-12-04 11:06 Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 01/12] dt-bindings: net: Add Ethernet " Maxime Chevallier
` (11 more replies)
0 siblings, 12 replies; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
Hi everyone,
3 years after pitching the idea at Netdevconf Vancouver, this is V1 of a
framework to deal with multiplexed MII interfaces.
- What we want to do:
The end-goal is to support multi-port ethernet interfaces. There are
multiple use-cases for that, the most common one is combo-port:
/-- RJ45
MAC ---X
\-- SFP
To achieve this, we can use several HW designs:
1 : Use a physical switch on the MII path:
PHY
xMII /
MAC --- Mux
\
SFP
This is what we find on Turris Omnia for instance. Here, the switch is
driven directly by the onboard electronics, it's connected to the SFP's
mod_def0 signal, and we can't switch it at all from Linux.
2 : Use a multiplexer in the SoC:
/-- xMII -- PHY
MAC -- MUX
\-- xMII -- SFP
This is what we have on Banana Pi R4 I believe.
3 : Use a PHY that contains a Mux:
xMII /---SFP
MAC ---- PHY
\-- RJ45
This is what we have on Machhiatobin for example.
- What we do here:
To make this "digestable" (well, it's already 12 patches, here goes my
netdev budget), this series adds the easiest case: The first one.
This allows adding the core mux infrastructure, the bindings, a small
driver and demonstrating that on upstream supported HW. Because the HW
does the switching, this series does NOT include the logic to drive a
mux from userspace. This will come later.
With this series, we can now use both WAN ports on omnia :)
- What we don't do here, but will do next:
Next step is to add some uAPI path to drive that, this will be done with
the phy_port API. end users don't care about the HW design, they want to
select the port to use, and phy_port represents them already.
The example for that will be mcbin.
Finally, we'll add driveable MII muxes (for bpi r4 and others).
This was tested on Omnia.
Note that patch 12 should likely go through the mvebu tree.
Thanks,
Maxime
Maxime Chevallier (12):
dt-bindings: net: Add Ethernet MII multiplexers
net: phy: Introduce phy_mux, a MII multiplexer representation
net: phy: Don't create the sysfs links for PHYs behind a mux
net: phy: phy_mux: Allow attaching a mux to a net_device
net: phy: phy_mux: Add port selection logic
net: phy: phy_mux: Support SFP cage ports
net: phylink: Factor out phylink_clear_phydev()
net: phy: phy_mux: Add phy_mux_set_mac_managed_pm()
net: phylink: Support PHYs reached through a phy_mux
net: phylink: Support an SFP cage behind a phy_mux
net: phy: mux: Add the mii-mux-auto driver
ARM: dts: turris-omnia: Describe the WAN port multiplexer
.../bindings/net/ethernet-controller.yaml | 6 +
.../devicetree/bindings/net/mii-mux-auto.yaml | 89 +++
.../devicetree/bindings/net/mii-mux.yaml | 74 ++
MAINTAINERS | 9 +
.../dts/marvell/armada-385-turris-omnia.dts | 29 +-
drivers/net/phy/Kconfig | 10 +
drivers/net/phy/Makefile | 2 +
drivers/net/phy/mux/Kconfig | 18 +
drivers/net/phy/mux/Makefile | 3 +
drivers/net/phy/mux/mii_mux_auto.c | 99 +++
drivers/net/phy/phy_device.c | 3 +-
drivers/net/phy/phy_mux.c | 698 ++++++++++++++++++
drivers/net/phy/phylink.c | 264 ++++++-
include/linux/phy.h | 3 +
include/linux/phy_mux.h | 147 ++++
15 files changed, 1423 insertions(+), 31 deletions(-)
create mode 100644 Documentation/devicetree/bindings/net/mii-mux-auto.yaml
create mode 100644 Documentation/devicetree/bindings/net/mii-mux.yaml
create mode 100644 drivers/net/phy/mux/Kconfig
create mode 100644 drivers/net/phy/mux/Makefile
create mode 100644 drivers/net/phy/mux/mii_mux_auto.c
create mode 100644 drivers/net/phy/phy_mux.c
create mode 100644 include/linux/phy_mux.h
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH net-next 01/12] dt-bindings: net: Add Ethernet MII multiplexers
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
@ 2026-12-04 11:06 ` Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 02/12] net: phy: Introduce phy_mux, a MII multiplexer representation Maxime Chevallier
` (10 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
It's not unusual for network equipment to have some flavors of "combo
ports", where multiple physical connectors are available for one single
network interface.
Usually it's for SFP and RJ45 ports and in such a case, only one port
can be used at any point in time.
There are numerous ways to implement this in hardware. It can be a
gpio-driven multiplexer, a small glue in the SoC, inside an ethernet
PHY, etc.
The simplest form of that multiplexer lets the hardware select the
port in use, without any software way to control it. This is the case
on the Turris Omnia, where the mux is controlled by a GPIO directly
connected to the SFP cage's mod_def0 signal. When a module is inserted,
the mux automatically switches to the SFP cage.
Introduce a binding for MII muxes, for now only for the automatic
muxes. The Ethernet controller has a mii-mux-handle property, pointing
to the new mux node.
This node has a compatible, as it may use dedicated drivers to control
it, and lists all the ports of the mux.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
.../bindings/net/ethernet-controller.yaml | 6 ++
.../devicetree/bindings/net/mii-mux-auto.yaml | 89 +++++++++++++++++++
.../devicetree/bindings/net/mii-mux.yaml | 74 +++++++++++++++
MAINTAINERS | 6 ++
4 files changed, 175 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/mii-mux-auto.yaml
create mode 100644 Documentation/devicetree/bindings/net/mii-mux.yaml
diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
index 30b2a335116e..e2836351cd7a 100644
--- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml
+++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml
@@ -100,6 +100,12 @@ properties:
description:
Specifies a reference to a node representing a PHY device.
+ mii-mux-handle:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Specifies a reference to a node representing an Ethernet MII
+ multiplexer.
+
phy:
$ref: "#/properties/phy-handle"
deprecated: true
diff --git a/Documentation/devicetree/bindings/net/mii-mux-auto.yaml b/Documentation/devicetree/bindings/net/mii-mux-auto.yaml
new file mode 100644
index 000000000000..7a965f6e8dcc
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/mii-mux-auto.yaml
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/mii-mux-auto.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Ethernet MII multiplexer switched by the hardware
+
+maintainers:
+ - Maxime Chevallier <maxime.chevallier@bootlin.com>
+
+description:
+ A two-port Ethernet MII multiplexer that the hardware switches by itself,
+ without any software control.
+
+allOf:
+ - $ref: mii-mux.yaml#
+
+properties:
+ compatible:
+ const: mii-mux-auto
+
+patternProperties:
+ "^port@[0-9a-f]+$":
+ $ref: mii-mux.yaml#/$defs/port
+ unevaluatedProperties: false
+
+ properties:
+ takes-precedence:
+ type: boolean
+ description:
+ The multiplexer switches to this port by itself as soon as the
+ port gets active, whatever the state of the other port.
+
+required:
+ - compatible
+ - port@0
+ - port@1
+
+oneOf:
+ - properties:
+ port@0:
+ required:
+ - takes-precedence
+ - properties:
+ port@1:
+ required:
+ - takes-precedence
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ ethernet {
+ phy-mode = "sgmii";
+ mii-mux-handle = <&mii_mux>;
+
+ mdio {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ phy0: ethernet-phy@0 {
+ reg = <0>;
+ };
+ };
+ };
+
+ mii_mux: mii-mux {
+ compatible = "mii-mux-auto";
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@0 {
+ reg = <0>;
+ sfp = <&sfp0>;
+ takes-precedence;
+ };
+
+ port@1 {
+ reg = <1>;
+ phy-handle = <&phy0>;
+ phy-mode = "sgmii";
+ };
+ };
+
+ sfp0: sfp {
+ compatible = "sff,sfp";
+ i2c-bus = <&i2c0>;
+ };
diff --git a/Documentation/devicetree/bindings/net/mii-mux.yaml b/Documentation/devicetree/bindings/net/mii-mux.yaml
new file mode 100644
index 000000000000..cbd99251f460
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/mii-mux.yaml
@@ -0,0 +1,74 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/mii-mux.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Ethernet MII multiplexer
+
+maintainers:
+ - Maxime Chevallier <maxime.chevallier@bootlin.com>
+
+description: |
+ An Ethernet MII multiplexer sits between one Ethernet MAC and several
+ Ethernet PHYs or SFP cages that share the MAC's MII, only one of them
+ being usable at a time.
+
+select: false
+
+properties:
+ "#address-cells":
+ const: 1
+
+ "#size-cells":
+ const: 0
+
+patternProperties:
+ "^port@[0-9a-f]+$":
+ $ref: "#/$defs/port"
+
+required:
+ - "#address-cells"
+ - "#size-cells"
+
+additionalProperties: true
+
+$defs:
+ port:
+ type: object
+
+ properties:
+ reg:
+ maxItems: 1
+ description:
+ The port number.
+
+ phy-handle:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ The Ethernet PHY reached through this port.
+
+ phy-mode:
+ $ref: ethernet-controller.yaml#/properties/phy-connection-type
+ description:
+ The MII mode used between the MAC and this PHY.
+
+ sfp:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ The SFP cage reached through this port.
+
+ required:
+ - reg
+
+ oneOf:
+ - required:
+ - phy-handle
+ - phy-mode
+ properties:
+ sfp: false
+ - required:
+ - sfp
+ properties:
+ phy-handle: false
+ phy-mode: false
diff --git a/MAINTAINERS b/MAINTAINERS
index bfa5a7248973..8685ed44840a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10081,6 +10081,12 @@ S: Maintained
F: rust/kernel/net/phy.rs
F: rust/kernel/net/phy/reg.rs
+ETHERNET PHY MUX
+M: Maxime Chevallier <maxime.chevallier@bootlin.com>
+L: netdev@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/net/mii-mux*.yaml
+
EXEC & BINFMT API, ELF
M: Kees Cook <kees@kernel.org>
L: linux-mm@kvack.org
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 02/12] net: phy: Introduce phy_mux, a MII multiplexer representation
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 ` 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
` (9 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
The implementation of combo-port and multi-PHY interfaces can be done
either by having the MAC's MII interface muxed to 2 different
destinations, or by having a PHY with 2 outputs.
Let's introduce a framework to deal with the first case: muxing the MII
bus. Here again, we can mux it with different techniques:
- A Mux block in the SoC, after the MAC, MMIO-mapped like we have on
banana Pi R4 for example
- A gpio-driven Mux, can be some high speed analog switch for example.
Here again, we have 2 options:
- The switch can be controlled by Linux
- The switch is controlled through another means, that's the case
for Turris Omnia for example, the control pin is tied to the SFP
cage's mod_def0 pin that indicates if a module is present
- No mux at all, the mux is just the MII going to 2 PHYs, one of them
needing to isolate its MII.
The plan is to support all these cases, with the uAPI interface being
phy_port as it'll also allow supporting phy-driven muxes.
Introduce the framework for the muxes, named phy_mux, for now without
users, they'll be added in the next commits.
The mux is represented in DT, and is parsed using the fwnode logic.
A mux has multiple "ports" represented by "struct phy_mux_port", that
correspond to the PHY-side MII busses, only one of these can be active
at any given time.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
MAINTAINERS | 2 +
drivers/net/phy/Kconfig | 8 ++
drivers/net/phy/Makefile | 1 +
drivers/net/phy/phy_mux.c | 189 ++++++++++++++++++++++++++++++++++++++
include/linux/phy_mux.h | 44 +++++++++
5 files changed, 244 insertions(+)
create mode 100644 drivers/net/phy/phy_mux.c
create mode 100644 include/linux/phy_mux.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 8685ed44840a..b2b02a1dbd3a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10086,6 +10086,8 @@ M: Maxime Chevallier <maxime.chevallier@bootlin.com>
L: netdev@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/net/mii-mux*.yaml
+F: drivers/net/phy/phy_mux.c
+F: include/linux/phy_mux.h
EXEC & BINFMT API, ELF
M: Kees Cook <kees@kernel.org>
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 30e9d22c8d1a..d8a0131d2aa2 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -21,6 +21,14 @@ menuconfig PHYLIB
if PHYLIB
+config PHY_MUX
+ bool "PHY multiplexing support"
+ help
+ Some boards route several PHYs or SFP cages to the same MAC
+ through a multiplexer, only one of them being usable at a
+ time. This adds the infrastructure to represent such multiplexers
+ and to select which port carries the link.
+
config SWPHY
bool
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 579066a638f0..b3ec2933fec4 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -5,6 +5,7 @@ libphy-y := phy.o phy-c45.o phy-core.o phy_device.o \
linkmode.o phy_link_topology.o \
phy_caps.o mdio_bus_provider.o phy_port.o \
mdio_device.o
+libphy-$(CONFIG_PHY_MUX) += phy_mux.o
ifdef CONFIG_PHYLIB
# built-in whenever PHYLIB is built-in or module
diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
new file mode 100644
index 000000000000..e259eb4e271a
--- /dev/null
+++ b/drivers/net/phy/phy_mux.c
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/phy.h>
+#include <linux/phy_mux.h>
+#include <linux/property.h>
+#include <linux/slab.h>
+#include <linux/xarray.h>
+
+static LIST_HEAD(phy_muxes);
+static DEFINE_MUTEX(phy_mux_mutex);
+
+struct phy_mux {
+ struct list_head node;
+ struct device *dev;
+
+ struct xarray ports;
+ int n_ports;
+ int max_n_ports;
+
+};
+
+/**
+ * phy_mux_alloc() - Allocate a mux
+ * @dev: The mux device
+ * @max_n_ports: How many ports the mux accepts
+ *
+ * The mux is freed with phy_mux_free().
+ *
+ * Returns: the mux, or an ERR_PTR.
+ */
+struct phy_mux *phy_mux_alloc(struct device *dev, int max_n_ports)
+{
+ struct phy_mux *mux;
+
+ mux = kzalloc_obj(*mux);
+ if (!mux)
+ return ERR_PTR(-ENOMEM);
+
+ xa_init_flags(&mux->ports, XA_FLAGS_ALLOC1);
+
+ mux->dev = dev;
+ mux->max_n_ports = max_n_ports;
+
+ return mux;
+}
+EXPORT_SYMBOL_GPL(phy_mux_alloc);
+
+static void phy_mux_port_destroy(struct phy_mux_port *mux_port)
+{
+ switch (mux_port->type) {
+ case PHY_MUX_PORT_PHY:
+ fwnode_handle_put(mux_port->fwnode);
+ break;
+ }
+
+ kfree(mux_port);
+}
+
+/**
+ * phy_mux_register_port() - Add a port to a mux
+ * @mux: The mux, not registered yet
+ * @port: The port, allocated with kzalloc(). The mux owns it from then on
+ * and frees it in phy_mux_free().
+ *
+ * Returns: 0 on success, -EBUSY if the mux is full, or a negative error.
+ */
+static int phy_mux_register_port(struct phy_mux *mux,
+ struct phy_mux_port *port)
+{
+ int ret;
+
+ if (mux->n_ports >= mux->max_n_ports)
+ return -EBUSY;
+
+ ret = xa_alloc(&mux->ports, &port->id, port, xa_limit_16b, GFP_KERNEL);
+ if (ret)
+ return ret;
+
+ mux->n_ports++;
+
+ return 0;
+}
+
+/**
+ * phy_mux_fwnode_add_ports() - Create the ports described under a fwnode
+ * @mux: The mux
+ * @fwnode: The mux device's fwnode, each child being a port with a
+ * phy-handle and a phy-mode
+ *
+ * The PHYs themselves are only looked up when the mux gets attached.
+ *
+ * Returns: 0 on success or a negative error.
+ */
+int phy_mux_fwnode_add_ports(struct phy_mux *mux,
+ const struct fwnode_handle *fwnode)
+{
+ struct fwnode_handle *child, *phy_fwnode;
+ struct phy_mux_port *port;
+ int ret;
+
+ fwnode_for_each_available_child_node(fwnode, child) {
+ phy_fwnode = fwnode_get_phy_node(child);
+ if (IS_ERR(phy_fwnode)) {
+ ret = PTR_ERR(phy_fwnode);
+ goto err;
+ }
+
+ port = kzalloc_obj(*port);
+ if (!port) {
+ fwnode_handle_put(phy_fwnode);
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ port->type = PHY_MUX_PORT_PHY;
+ port->fwnode = phy_fwnode;
+ port->mux = mux;
+
+ ret = fwnode_get_phy_mode(child);
+ if (ret < 0) {
+ phy_mux_port_destroy(port);
+ goto err;
+ }
+ port->interface = ret;
+
+ ret = phy_mux_register_port(mux, port);
+ if (ret) {
+ phy_mux_port_destroy(port);
+ goto err;
+ }
+ }
+
+ return 0;
+
+err:
+ fwnode_handle_put(child);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(phy_mux_fwnode_add_ports);
+
+/**
+ * phy_mux_register() - Make the mux available to its parent
+ * @mux: The mux, with all its ports added
+ *
+ * Returns: 0 on success or a negative error.
+ */
+int phy_mux_register(struct phy_mux *mux)
+{
+ mutex_lock(&phy_mux_mutex);
+ list_add(&mux->node, &phy_muxes);
+ mutex_unlock(&phy_mux_mutex);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(phy_mux_register);
+
+/**
+ * phy_mux_unregister() - Make the mux unavailable to its parent
+ * @mux: The mux, registered
+ *
+ * The mux still has to be freed with phy_mux_free().
+ */
+void phy_mux_unregister(struct phy_mux *mux)
+{
+ mutex_lock(&phy_mux_mutex);
+ list_del(&mux->node);
+ mutex_unlock(&phy_mux_mutex);
+}
+EXPORT_SYMBOL_GPL(phy_mux_unregister);
+
+/**
+ * phy_mux_free() - Free a mux and its ports
+ * @mux: The mux, not registered
+ */
+void phy_mux_free(struct phy_mux *mux)
+{
+ struct phy_mux_port *port;
+ unsigned long id;
+
+ xa_for_each(&mux->ports, id, port)
+ phy_mux_port_destroy(port);
+
+ xa_destroy(&mux->ports);
+ kfree(mux);
+}
+EXPORT_SYMBOL_GPL(phy_mux_free);
diff --git a/include/linux/phy_mux.h b/include/linux/phy_mux.h
new file mode 100644
index 000000000000..3dde6dd57faf
--- /dev/null
+++ b/include/linux/phy_mux.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __PHY_MUX_H
+#define __PHY_MUX_H
+
+#include <linux/phy.h>
+
+struct device;
+struct fwnode_handle;
+struct phy_mux;
+struct phy_mux_port;
+
+enum phy_mux_port_type {
+ PHY_MUX_PORT_PHY,
+};
+
+/**
+ * struct phy_mux_port - One of the multiplexed channels of a MII multiplexer
+ * @id: Identifier of the port, unique within the mux
+ * @mux: The mux this port belongs to
+ * @type: What sits behind that port
+ * @phydev: For PHY_MUX_PORT_PHY, the PHY device behind the port, while the
+ * mux is attached
+ * @fwnode: For PHY_MUX_PORT_PHY, the firmware node of that PHY
+ * @interface: The MII mode the link runs in when this port is selected
+ */
+struct phy_mux_port {
+ u32 id;
+ struct phy_mux *mux;
+ enum phy_mux_port_type type;
+ struct phy_device *phydev;
+ struct fwnode_handle *fwnode;
+
+ phy_interface_t interface;
+};
+
+struct phy_mux *phy_mux_alloc(struct device *dev, int max_n_ports);
+int phy_mux_fwnode_add_ports(struct phy_mux *mux,
+ const struct fwnode_handle *fwnode);
+int phy_mux_register(struct phy_mux *mux);
+void phy_mux_unregister(struct phy_mux *mux);
+void phy_mux_free(struct phy_mux *mux);
+
+#endif /* __PHY_MUX_H */
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 03/12] net: phy: Don't create the sysfs links for PHYs behind a mux
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 ` Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device Maxime Chevallier
` (8 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
The phy_mux framework allows attaching multiple PHYs to the same netdev,
one of them being actively used at any given time.
Attached phys create sysfs links in the netdev entry, pointing to the
PHY. We can't have two of them (otherwise they'd overwrite one another),
so let's just not create these. PHYs are still visible through the
phy_link_topology API.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
drivers/net/phy/phy_device.c | 3 ++-
include/linux/phy.h | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 60440b62e6c7..9630578a6a5c 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2019,7 +2019,8 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
*/
phydev->sysfs_links = false;
- phy_sysfs_create_links(phydev);
+ if (!phydev->mux_port)
+ phy_sysfs_create_links(phydev);
if (!phydev->attached_dev) {
err = sysfs_create_file(&phydev->mdio.dev.kobj,
diff --git a/include/linux/phy.h b/include/linux/phy.h
index f1b1ad1dd82f..a6cd2fc642ad 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -328,6 +328,7 @@ static inline long rgmii_clock(int speed)
struct device;
struct kernel_hwtstamp_config;
struct phylink;
+struct phy_mux_port;
struct phy_port;
struct sfp_bus;
struct sfp_upstream_ops;
@@ -618,6 +619,7 @@ struct phy_oatc14_sqi_capability {
* @sfp_cage_port: The phy_port connected to the downstream SFP cage
* @mod_port: phy_port representing the SFP module, if it is phy-less
* @upstream_port: phy_port this PHY's MII attaches to, if any
+ * @mux_port: The mux port this PHY sits behind, if any
* @attached_dev: The attached enet driver's device instance ptr
* @adjust_link: Callback for the enet controller to respond to changes: in the
* link state.
@@ -814,6 +816,7 @@ struct phy_device {
struct phy_port *sfp_cage_port;
struct phy_port *mod_port;
struct phy_port *upstream_port;
+ struct phy_mux_port *mux_port;
struct phylink *phylink;
struct net_device *attached_dev;
struct mii_timestamper *mii_ts;
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
` (2 preceding siblings ...)
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 ` Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic Maxime Chevallier
` (7 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
Like any other MII link, muxed MII's need all the involved components
(MAC, PCS, PHY, etc) to be involved for everything to work smoothly.
When switching from one port to another, we need to re-construct the
link and set all parameters, as both ports may be using different kinds
of technologies (think SGMII PHY on one side, 1000BaseX SFP on the
other).
Setting-up a mux therefore requires attaching the mux to its parent
(i.e. the MAC), and let its parent register callbacks to be notified
when switching occurs:
/--- parent_ops
|
v +-----+
+-----+ | |------ PHY
| MAC | ----| MUX |
+-----+ | |------ SFP
+-----+
In practice, these parent_ops will be implemented by phylink.
The mux needs the netdev reference too as it's required when adding the
devlink dependency.
All PHYs in the mux are attached to the netdev, meaning we end-up with
more than one PHY attached to the netdev. We override the link
notification callback from a mux provided one.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
drivers/net/phy/phy_mux.c | 196 +++++++++++++++++++++++++++++++++++++-
include/linux/phy_mux.h | 39 ++++++++
2 files changed, 232 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
index e259eb4e271a..691bca09e0af 100644
--- a/drivers/net/phy/phy_mux.c
+++ b/drivers/net/phy/phy_mux.c
@@ -3,9 +3,11 @@
#include <linux/device.h>
#include <linux/list.h>
#include <linux/mutex.h>
+#include <linux/netdevice.h>
#include <linux/phy.h>
#include <linux/phy_mux.h>
#include <linux/property.h>
+#include <linux/rtnetlink.h>
#include <linux/slab.h>
#include <linux/xarray.h>
@@ -16,12 +18,196 @@ struct phy_mux {
struct list_head node;
struct device *dev;
+ struct net_device *netdev;
+ struct device_link *devlink;
+ const struct phy_mux_parent_ops *pops;
+ void *parent_priv;
+
struct xarray ports;
int n_ports;
int max_n_ports;
-
};
+static void phy_mux_phy_link_change(struct phy_device *phydev, bool up)
+{
+}
+
+static int phy_mux_port_bind_phy(struct phy_mux_port *mux_port)
+{
+ struct phy_device *phydev;
+
+ phydev = fwnode_phy_find_device(mux_port->fwnode);
+ if (!phydev)
+ return -EPROBE_DEFER;
+
+ if (phydev->mux_port) {
+ put_device(&phydev->mdio.dev);
+ return -EBUSY;
+ }
+
+ mux_port->phydev = phydev;
+ phydev->mux_port = mux_port;
+
+ return 0;
+}
+
+static void phy_mux_port_unbind_phy(struct phy_mux_port *mux_port)
+{
+ struct phy_device *phydev = mux_port->phydev;
+
+ if (!phydev)
+ return;
+
+ phydev->mux_port = NULL;
+ mux_port->phydev = NULL;
+
+ put_device(&phydev->mdio.dev);
+}
+
+static void phy_mux_detach_phys(struct phy_mux *mux)
+{
+ struct phy_mux_port *port;
+ unsigned long id;
+
+ xa_for_each(&mux->ports, id, port) {
+ if (!port->attached)
+ continue;
+
+ phy_detach(port->phydev);
+ phy_mux_port_unbind_phy(port);
+ port->attached = false;
+ }
+}
+
+/**
+ * phy_mux_attach() - Attach the mux to its parent
+ * @mux: The mux
+ * @dev: The net_device the mux leads to
+ * @phy_flags: PHY device flags, for the PHYs sitting behind the mux
+ * @pops: The parent's callbacks
+ * @priv: Passed back to @pops
+ *
+ * All the PHYs behind the mux are looked up and attached to @dev, and stay
+ * attached until phy_mux_detach(). The parent only gets to use the one that
+ * is selected.
+ *
+ * Returns: 0 on success, -EBUSY if already attached, -EPROBE_DEFER if a PHY
+ * isn't there yet, or a negative error.
+ */
+static int phy_mux_attach(struct phy_mux *mux, struct net_device *dev,
+ u32 phy_flags,
+ const struct phy_mux_parent_ops *pops, void *priv)
+{
+ struct phy_mux_port *port;
+ bool has_phys = false;
+ unsigned long id;
+ int ret;
+
+ if (mux->netdev)
+ return -EBUSY;
+
+ xa_for_each(&mux->ports, id, port) {
+ if (port->type != PHY_MUX_PORT_PHY)
+ continue;
+
+ ret = phy_mux_port_bind_phy(port);
+ if (ret)
+ goto err_detach;
+
+ ret = phy_attach_direct(dev, port->phydev, phy_flags,
+ port->interface);
+ if (ret) {
+ phy_mux_port_unbind_phy(port);
+ goto err_detach;
+ }
+
+ port->phydev->phy_link_change = phy_mux_phy_link_change;
+ port->attached = true;
+ has_phys = true;
+ }
+
+ if (has_phys)
+ dev->phydev = NULL;
+
+ if (dev->dev.parent)
+ mux->devlink = device_link_add(dev->dev.parent, mux->dev,
+ DL_FLAG_STATELESS);
+
+ mux->pops = pops;
+ mux->parent_priv = priv;
+ mux->netdev = dev;
+
+ if (pops && pops->attach)
+ pops->attach(mux, priv);
+
+ return 0;
+
+err_detach:
+ phy_mux_detach_phys(mux);
+
+ return ret;
+}
+
+/**
+ * fwnode_phy_mux_attach() - Find a mux from its firmware node and attach it
+ * @fwnode: The mux device's fwnode
+ * @dev: The net_device the mux leads to
+ * @phy_flags: PHY device flags, for the PHYs sitting behind the mux
+ * @pops: The parent's callbacks
+ * @priv: Passed back to @pops
+ *
+ * The parent gets the mux through its attach callback, called before the
+ * mux can be unregistered.
+ *
+ * Returns: 0 on success, -EPROBE_DEFER if no mux is registered yet for that
+ * node, or a negative error.
+ */
+int
+fwnode_phy_mux_attach(const struct fwnode_handle *fwnode,
+ struct net_device *dev, u32 phy_flags,
+ const struct phy_mux_parent_ops *pops, void *priv)
+{
+ int ret = -EPROBE_DEFER;
+ struct phy_mux *mux;
+
+ mutex_lock(&phy_mux_mutex);
+ list_for_each_entry(mux, &phy_muxes, node) {
+ if (dev_fwnode(mux->dev) != fwnode)
+ continue;
+
+ ret = phy_mux_attach(mux, dev, phy_flags, pops, priv);
+ break;
+ }
+ mutex_unlock(&phy_mux_mutex);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(fwnode_phy_mux_attach);
+
+/**
+ * phy_mux_detach() - Detach the mux from its parent
+ * @mux: The mux
+ *
+ * The PHYs behind the mux are detached.
+ */
+void phy_mux_detach(struct phy_mux *mux)
+{
+ if (!mux->netdev)
+ return;
+
+ phy_mux_detach_phys(mux);
+
+ if (mux->devlink) {
+ device_link_del(mux->devlink);
+ mux->devlink = NULL;
+ }
+
+ mux->pops = NULL;
+ mux->parent_priv = NULL;
+ mux->netdev = NULL;
+}
+EXPORT_SYMBOL_GPL(phy_mux_detach);
+
/**
* phy_mux_alloc() - Allocate a mux
* @dev: The mux device
@@ -52,6 +238,7 @@ static void phy_mux_port_destroy(struct phy_mux_port *mux_port)
{
switch (mux_port->type) {
case PHY_MUX_PORT_PHY:
+ phy_mux_port_unbind_phy(mux_port);
fwnode_handle_put(mux_port->fwnode);
break;
}
@@ -160,14 +347,17 @@ EXPORT_SYMBOL_GPL(phy_mux_register);
/**
* phy_mux_unregister() - Make the mux unavailable to its parent
* @mux: The mux, registered
- *
- * The mux still has to be freed with phy_mux_free().
*/
void phy_mux_unregister(struct phy_mux *mux)
{
mutex_lock(&phy_mux_mutex);
list_del(&mux->node);
mutex_unlock(&phy_mux_mutex);
+
+ rtnl_lock();
+ if (mux->netdev && mux->pops && mux->pops->detach)
+ mux->pops->detach(mux, mux->parent_priv);
+ rtnl_unlock();
}
EXPORT_SYMBOL_GPL(phy_mux_unregister);
diff --git a/include/linux/phy_mux.h b/include/linux/phy_mux.h
index 3dde6dd57faf..cdc58b56a3b4 100644
--- a/include/linux/phy_mux.h
+++ b/include/linux/phy_mux.h
@@ -7,6 +7,7 @@
struct device;
struct fwnode_handle;
+struct net_device;
struct phy_mux;
struct phy_mux_port;
@@ -23,6 +24,7 @@ enum phy_mux_port_type {
* mux is attached
* @fwnode: For PHY_MUX_PORT_PHY, the firmware node of that PHY
* @interface: The MII mode the link runs in when this port is selected
+ * @attached: For PHY_MUX_PORT_PHY, the PHY is attached to the mux's netdev
*/
struct phy_mux_port {
u32 id;
@@ -32,8 +34,24 @@ struct phy_mux_port {
struct fwnode_handle *fwnode;
phy_interface_t interface;
+
+ bool attached;
+};
+
+/**
+ * struct phy_mux_parent_ops - Ops for the device providing the single MII
+ * that's multiplexed, usually the MAC
+ * @attach: The mux is attached to the parent.
+ * @detach: The mux is going away, the parent must detach from it. Called with
+ * rtnl held.
+ */
+struct phy_mux_parent_ops {
+ void (*attach)(struct phy_mux *mux, void *priv);
+ void (*detach)(struct phy_mux *mux, void *priv);
};
+#if IS_ENABLED(CONFIG_PHY_MUX)
+
struct phy_mux *phy_mux_alloc(struct device *dev, int max_n_ports);
int phy_mux_fwnode_add_ports(struct phy_mux *mux,
const struct fwnode_handle *fwnode);
@@ -41,4 +59,25 @@ int phy_mux_register(struct phy_mux *mux);
void phy_mux_unregister(struct phy_mux *mux);
void phy_mux_free(struct phy_mux *mux);
+int fwnode_phy_mux_attach(const struct fwnode_handle *fwnode,
+ struct net_device *dev, u32 phy_flags,
+ const struct phy_mux_parent_ops *pops, void *priv);
+void phy_mux_detach(struct phy_mux *mux);
+
+#else
+
+static inline int
+fwnode_phy_mux_attach(const struct fwnode_handle *fwnode,
+ struct net_device *dev, u32 phy_flags,
+ const struct phy_mux_parent_ops *pops, void *priv)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline void phy_mux_detach(struct phy_mux *mux)
+{
+}
+
+#endif /* CONFIG_PHY_MUX */
+
#endif /* __PHY_MUX_H */
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
` (3 preceding siblings ...)
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 ` Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports Maxime Chevallier
` (6 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
As Muxes drive multiple MII ports but only one can be used at a time, we
need logic to select which one to use, and notify the parent (i.e. the
netdev).
Selecting a port tells the MAC to start using what's at the end of the
MII line (a PHY, an SFP cage, etc.), so that it can start configuring
its MAC, PCS, Serdes and so on accordingly.
Deselecting it tells the parent to stop using it.
All the ports are deselected when the mux gets attached, and nothing is
selected until the parent starts the mux with phy_mux_start(), which it
is expected to do when the interface is brought up.
The selection policy is as simple as it gets for now, the first port is
selected.
For that, we introduce mux_port_ops:
/--- parent_ops
|
| / phy_mux_port_ops
v +-----+ v
+-----+ | |------ PHY
| MAC | ----| MUX |
+-----+ | |------ SFP
+-----+ ^
\ phy_mux_port_ops
They allow notifying what's at the end of a mux'd MII line (a PHY, an SFP)
that it has been selected or deselected. That way it can act accordingly
to stop trying to reach the MAC.
For now, only deselect is implemented, the rest will come later.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
drivers/net/phy/phy_mux.c | 134 +++++++++++++++++++++++++++++++++++++-
include/linux/phy_mux.h | 29 +++++++++
2 files changed, 162 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
index 691bca09e0af..407269980edc 100644
--- a/drivers/net/phy/phy_mux.c
+++ b/drivers/net/phy/phy_mux.c
@@ -14,6 +14,11 @@
static LIST_HEAD(phy_muxes);
static DEFINE_MUTEX(phy_mux_mutex);
+enum phy_mux_state {
+ PHY_MUX_STOPPED,
+ PHY_MUX_STARTED,
+};
+
struct phy_mux {
struct list_head node;
struct device *dev;
@@ -26,12 +31,97 @@ struct phy_mux {
struct xarray ports;
int n_ports;
int max_n_ports;
+
+ struct phy_mux_port *current_port;
+ enum phy_mux_state state;
};
+static void phy_mux_port_deselect(struct phy_mux_port *port)
+{
+ if (port->ops && port->ops->deselect)
+ port->ops->deselect(port);
+}
+
static void phy_mux_phy_link_change(struct phy_device *phydev, bool up)
{
}
+static void phy_mux_port_set_parent_phy(struct phy_mux *mux,
+ struct phy_mux_port *port, bool used)
+{
+ if (port->type != PHY_MUX_PORT_PHY)
+ return;
+
+ if (!used)
+ port->phydev->phy_link_change = phy_mux_phy_link_change;
+
+ if (mux->netdev)
+ mux->netdev->phydev = used ? port->phydev : NULL;
+}
+
+static void __phy_mux_deselect_port(struct phy_mux *mux,
+ struct phy_mux_port *port)
+{
+ if (mux->pops && mux->pops->deselect) {
+ mux->pops->deselect(mux, port, mux->parent_priv);
+ phy_mux_port_set_parent_phy(mux, port, false);
+ }
+
+ phy_mux_port_deselect(port);
+
+ port->selected = false;
+}
+
+static int __phy_mux_select_port(struct phy_mux *mux,
+ struct phy_mux_port *port)
+{
+ int ret;
+
+ if (mux->pops && mux->pops->select) {
+ ret = mux->pops->select(mux, port, mux->parent_priv);
+ phy_mux_port_set_parent_phy(mux, port, !ret);
+ if (ret)
+ return ret;
+ }
+
+ port->selected = true;
+
+ return 0;
+}
+
+static int phy_mux_select(struct phy_mux *mux, struct phy_mux_port *port)
+{
+ int ret;
+
+ if (mux->current_port == port)
+ return 0;
+
+ if (mux->current_port) {
+ __phy_mux_deselect_port(mux, mux->current_port);
+ mux->current_port = NULL;
+ }
+
+ if (!port)
+ return 0;
+
+ ret = __phy_mux_select_port(mux, port);
+ if (ret)
+ return ret;
+
+ mux->current_port = port;
+
+ return 0;
+}
+
+static void phy_mux_phy_power_down(struct phy_mux_port *port)
+{
+ phy_suspend(port->phydev);
+}
+
+static const struct phy_mux_port_ops phy_mux_phy_power_ops = {
+ .deselect = phy_mux_phy_power_down,
+};
+
static int phy_mux_port_bind_phy(struct phy_mux_port *mux_port)
{
struct phy_device *phydev;
@@ -129,6 +219,9 @@ static int phy_mux_attach(struct phy_mux *mux, struct net_device *dev,
if (has_phys)
dev->phydev = NULL;
+ xa_for_each(&mux->ports, id, port)
+ phy_mux_port_deselect(port);
+
if (dev->dev.parent)
mux->devlink = device_link_add(dev->dev.parent, mux->dev,
DL_FLAG_STATELESS);
@@ -188,13 +281,15 @@ EXPORT_SYMBOL_GPL(fwnode_phy_mux_attach);
* phy_mux_detach() - Detach the mux from its parent
* @mux: The mux
*
- * The PHYs behind the mux are detached.
+ * The mux is stopped and its PHYs are detached. Caller must hold rtnl when
+ * the mux was started.
*/
void phy_mux_detach(struct phy_mux *mux)
{
if (!mux->netdev)
return;
+ phy_mux_stop(mux);
phy_mux_detach_phys(mux);
if (mux->devlink) {
@@ -208,6 +303,41 @@ void phy_mux_detach(struct phy_mux *mux)
}
EXPORT_SYMBOL_GPL(phy_mux_detach);
+/**
+ * phy_mux_start() - Start selecting ports
+ * @mux: The mux, attached
+ *
+ * To be called when the parent is ready to use the PHY of the selected
+ * port, typically when the interface is brought up. Caller must hold rtnl.
+ */
+void phy_mux_start(struct phy_mux *mux)
+{
+ struct phy_mux_port *port;
+ unsigned long id = 0;
+
+ mux->state = PHY_MUX_STARTED;
+
+ port = xa_find(&mux->ports, &id, ULONG_MAX, XA_PRESENT);
+ phy_mux_select(mux, port);
+}
+EXPORT_SYMBOL_GPL(phy_mux_start);
+
+/**
+ * phy_mux_stop() - Deselect the port in use and stop selecting ports
+ * @mux: The mux
+ *
+ * Does nothing when the mux isn't started. Caller must hold rtnl otherwise.
+ */
+void phy_mux_stop(struct phy_mux *mux)
+{
+ if (mux->state < PHY_MUX_STARTED)
+ return;
+
+ mux->state = PHY_MUX_STOPPED;
+ phy_mux_select(mux, NULL);
+}
+EXPORT_SYMBOL_GPL(phy_mux_stop);
+
/**
* phy_mux_alloc() - Allocate a mux
* @dev: The mux device
@@ -305,6 +435,7 @@ int phy_mux_fwnode_add_ports(struct phy_mux *mux,
port->type = PHY_MUX_PORT_PHY;
port->fwnode = phy_fwnode;
port->mux = mux;
+ port->ops = &phy_mux_phy_power_ops;
ret = fwnode_get_phy_mode(child);
if (ret < 0) {
@@ -357,6 +488,7 @@ void phy_mux_unregister(struct phy_mux *mux)
rtnl_lock();
if (mux->netdev && mux->pops && mux->pops->detach)
mux->pops->detach(mux, mux->parent_priv);
+ phy_mux_stop(mux);
rtnl_unlock();
}
EXPORT_SYMBOL_GPL(phy_mux_unregister);
diff --git a/include/linux/phy_mux.h b/include/linux/phy_mux.h
index cdc58b56a3b4..6a42ffff02b7 100644
--- a/include/linux/phy_mux.h
+++ b/include/linux/phy_mux.h
@@ -11,6 +11,14 @@ struct net_device;
struct phy_mux;
struct phy_mux_port;
+/**
+ * struct phy_mux_port_ops - ops for the multiplexed mii ports of the mux
+ * @deselect: Disconnect the port from the MII
+ */
+struct phy_mux_port_ops {
+ void (*deselect)(struct phy_mux_port *port);
+};
+
enum phy_mux_port_type {
PHY_MUX_PORT_PHY,
};
@@ -23,8 +31,10 @@ enum phy_mux_port_type {
* @phydev: For PHY_MUX_PORT_PHY, the PHY device behind the port, while the
* mux is attached
* @fwnode: For PHY_MUX_PORT_PHY, the firmware node of that PHY
+ * @ops: How to drive that port
* @interface: The MII mode the link runs in when this port is selected
* @attached: For PHY_MUX_PORT_PHY, the PHY is attached to the mux's netdev
+ * @selected: The port currently drives the MII
*/
struct phy_mux_port {
u32 id;
@@ -33,20 +43,29 @@ struct phy_mux_port {
struct phy_device *phydev;
struct fwnode_handle *fwnode;
+ const struct phy_mux_port_ops *ops;
phy_interface_t interface;
bool attached;
+ bool selected;
};
/**
* struct phy_mux_parent_ops - Ops for the device providing the single MII
* that's multiplexed, usually the MAC
* @attach: The mux is attached to the parent.
+ * @select: A port was selected, the parent must now use it (e.g. connect
+ * to its PHY)
+ * @deselect: The port is no longer in use
* @detach: The mux is going away, the parent must detach from it. Called with
* rtnl held.
*/
struct phy_mux_parent_ops {
void (*attach)(struct phy_mux *mux, void *priv);
+ int (*select)(struct phy_mux *mux, struct phy_mux_port *port,
+ void *priv);
+ void (*deselect)(struct phy_mux *mux, struct phy_mux_port *port,
+ void *priv);
void (*detach)(struct phy_mux *mux, void *priv);
};
@@ -63,6 +82,8 @@ int fwnode_phy_mux_attach(const struct fwnode_handle *fwnode,
struct net_device *dev, u32 phy_flags,
const struct phy_mux_parent_ops *pops, void *priv);
void phy_mux_detach(struct phy_mux *mux);
+void phy_mux_start(struct phy_mux *mux);
+void phy_mux_stop(struct phy_mux *mux);
#else
@@ -78,6 +99,14 @@ static inline void phy_mux_detach(struct phy_mux *mux)
{
}
+static inline void phy_mux_start(struct phy_mux *mux)
+{
+}
+
+static inline void phy_mux_stop(struct phy_mux *mux)
+{
+}
+
#endif /* CONFIG_PHY_MUX */
#endif /* __PHY_MUX_H */
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
` (4 preceding siblings ...)
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 ` Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 07/12] net: phylink: Factor out phylink_clear_phydev() Maxime Chevallier
` (5 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
It's quite common to have combo ports where one of the ports is an SFP
cage, let's allow adding one on the mux.
To keep things realistic, we only allow one SFP cage per combo port.
When an SFP cage doesn't have any module inserted, it doesn't really
make sense to allow using it as the active port, so we need to keep
track of whether there's a module or not.
There's a simple way to implement a combo port that we find on Turris
Omnia for example, that is to wire the SFP cage's mod_def0 to the
physical multiplexer. In this case, we can't select the port to use from
the host, but we can report that the port is in use and shutdown the
unused port. For that, we however need to indicate that the SFP cage
always takes precedence, as represented in the auto-mux binding.
So, add support for attaching SFP cages to muxes, and implement the
automatic mux.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
drivers/net/phy/phy_mux.c | 190 ++++++++++++++++++++++++++++++++++++--
include/linux/phy_mux.h | 34 ++++++-
2 files changed, 213 insertions(+), 11 deletions(-)
diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
index 407269980edc..de3336970bd9 100644
--- a/drivers/net/phy/phy_mux.c
+++ b/drivers/net/phy/phy_mux.c
@@ -9,6 +9,7 @@
#include <linux/property.h>
#include <linux/rtnetlink.h>
#include <linux/slab.h>
+#include <linux/workqueue.h>
#include <linux/xarray.h>
static LIST_HEAD(phy_muxes);
@@ -33,9 +34,15 @@ struct phy_mux {
int max_n_ports;
struct phy_mux_port *current_port;
+ struct work_struct state_work;
enum phy_mux_state state;
};
+static void phy_mux_trigger(struct phy_mux *mux)
+{
+ queue_work(system_freezable_power_efficient_wq, &mux->state_work);
+}
+
static void phy_mux_port_deselect(struct phy_mux_port *port)
{
if (port->ops && port->ops->deselect)
@@ -122,6 +129,109 @@ static const struct phy_mux_port_ops phy_mux_phy_power_ops = {
.deselect = phy_mux_phy_power_down,
};
+static struct phy_mux_port *phy_mux_choose_port(struct phy_mux *mux)
+{
+ struct phy_mux_port *port;
+ unsigned long id;
+
+ xa_for_each(&mux->ports, id, port)
+ if (port->has_precedence && port->available)
+ return port;
+
+ xa_for_each(&mux->ports, id, port)
+ if (port->available)
+ return port;
+
+ return NULL;
+}
+
+static void phy_mux_state_machine(struct work_struct *work)
+{
+ struct phy_mux *mux = container_of(work, struct phy_mux, state_work);
+
+ rtnl_lock();
+
+ switch (mux->state) {
+ case PHY_MUX_STOPPED:
+ break;
+
+ case PHY_MUX_STARTED:
+ phy_mux_select(mux, phy_mux_choose_port(mux));
+ break;
+ }
+
+ rtnl_unlock();
+}
+
+/**
+ * phy_mux_port_set_available() - Report whether a port has a medium to use
+ * @port: The mux port
+ * @available: true when there is something to link with on that port
+ *
+ * The parent of the mux calls this for the SFP cage port, when a module gets
+ * plugged or removed. Caller must hold rtnl.
+ */
+void phy_mux_port_set_available(struct phy_mux_port *port, bool available)
+{
+ struct phy_mux *mux = port->mux;
+
+ ASSERT_RTNL();
+
+ if (port->available == available)
+ return;
+
+ port->available = available;
+
+ if (available && mux->state == PHY_MUX_STARTED) {
+ phy_mux_select(mux, phy_mux_choose_port(mux));
+ return;
+ }
+
+ phy_mux_trigger(mux);
+}
+EXPORT_SYMBOL_GPL(phy_mux_port_set_available);
+
+/**
+ * phy_mux_get_sfp_port() - Get the SFP cage port of a mux
+ * @mux: The mux
+ *
+ * A mux has at most one SFP cage port.
+ *
+ * Returns: the SFP cage port, or NULL when the mux has none.
+ */
+struct phy_mux_port *phy_mux_get_sfp_port(struct phy_mux *mux)
+{
+ struct phy_mux_port *port;
+ unsigned long id;
+
+ xa_for_each(&mux->ports, id, port)
+ if (port->type == PHY_MUX_PORT_SFP)
+ return port;
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(phy_mux_get_sfp_port);
+
+/**
+ * fwnode_phy_mux_find_sfp_port() - Find the SFP cage port of a mux
+ * @fwnode: The mux device's fwnode
+ *
+ * Returns: the fwnode of the port carrying an sfp property, with a reference
+ * held, or NULL.
+ */
+struct fwnode_handle *
+fwnode_phy_mux_find_sfp_port(const struct fwnode_handle *fwnode)
+{
+ struct fwnode_handle *child;
+
+ fwnode_for_each_available_child_node(fwnode, child)
+ if (fwnode_property_present(child, "sfp"))
+ return child;
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(fwnode_phy_mux_find_sfp_port);
+
static int phy_mux_port_bind_phy(struct phy_mux_port *mux_port)
{
struct phy_device *phydev;
@@ -312,13 +422,8 @@ EXPORT_SYMBOL_GPL(phy_mux_detach);
*/
void phy_mux_start(struct phy_mux *mux)
{
- struct phy_mux_port *port;
- unsigned long id = 0;
-
mux->state = PHY_MUX_STARTED;
-
- port = xa_find(&mux->ports, &id, ULONG_MAX, XA_PRESENT);
- phy_mux_select(mux, port);
+ phy_mux_trigger(mux);
}
EXPORT_SYMBOL_GPL(phy_mux_start);
@@ -335,6 +440,8 @@ void phy_mux_stop(struct phy_mux *mux)
mux->state = PHY_MUX_STOPPED;
phy_mux_select(mux, NULL);
+
+ cancel_work(&mux->state_work);
}
EXPORT_SYMBOL_GPL(phy_mux_stop);
@@ -356,6 +463,7 @@ struct phy_mux *phy_mux_alloc(struct device *dev, int max_n_ports)
return ERR_PTR(-ENOMEM);
xa_init_flags(&mux->ports, XA_FLAGS_ALLOC1);
+ INIT_WORK(&mux->state_work, phy_mux_state_machine);
mux->dev = dev;
mux->max_n_ports = max_n_ports;
@@ -371,6 +479,9 @@ static void phy_mux_port_destroy(struct phy_mux_port *mux_port)
phy_mux_port_unbind_phy(mux_port);
fwnode_handle_put(mux_port->fwnode);
break;
+ case PHY_MUX_PORT_SFP:
+ fwnode_handle_put(mux_port->fwnode);
+ break;
}
kfree(mux_port);
@@ -396,29 +507,80 @@ static int phy_mux_register_port(struct phy_mux *mux,
if (ret)
return ret;
+ port->available = true;
+
mux->n_ports++;
return 0;
}
+static int phy_mux_add_sfp_port(struct phy_mux *mux,
+ struct fwnode_handle *child,
+ int (*init_port)(struct phy_mux_port *port,
+ struct fwnode_handle *child))
+{
+ struct phy_mux_port *port;
+ int ret;
+
+ if (phy_mux_get_sfp_port(mux))
+ return -EBUSY;
+
+ port = kzalloc_obj(*port);
+ if (!port)
+ return -ENOMEM;
+
+ port->type = PHY_MUX_PORT_SFP;
+ port->fwnode = fwnode_handle_get(child);
+ port->mux = mux;
+
+ if (init_port) {
+ ret = init_port(port, child);
+ if (ret) {
+ phy_mux_port_destroy(port);
+ return ret;
+ }
+ }
+
+ ret = phy_mux_register_port(mux, port);
+ if (ret) {
+ phy_mux_port_destroy(port);
+ return ret;
+ }
+
+ port->available = false;
+
+ return 0;
+}
+
/**
* phy_mux_fwnode_add_ports() - Create the ports described under a fwnode
* @mux: The mux
- * @fwnode: The mux device's fwnode, each child being a port with a
- * phy-handle and a phy-mode
+ * @fwnode: The mux device's fwnode, each child being a port with either a
+ * phy-handle and a phy-mode, or an sfp property
+ * @init_port: Optional driver callback to parse the rest of a port's node
*
* The PHYs themselves are only looked up when the mux gets attached.
*
* Returns: 0 on success or a negative error.
*/
int phy_mux_fwnode_add_ports(struct phy_mux *mux,
- const struct fwnode_handle *fwnode)
+ const struct fwnode_handle *fwnode,
+ int (*init_port)(struct phy_mux_port *port,
+ struct fwnode_handle *child))
{
struct fwnode_handle *child, *phy_fwnode;
struct phy_mux_port *port;
int ret;
fwnode_for_each_available_child_node(fwnode, child) {
+ if (fwnode_property_present(child, "sfp")) {
+ ret = phy_mux_add_sfp_port(mux, child, init_port);
+ if (ret)
+ goto err;
+
+ continue;
+ }
+
phy_fwnode = fwnode_get_phy_node(child);
if (IS_ERR(phy_fwnode)) {
ret = PTR_ERR(phy_fwnode);
@@ -444,6 +606,14 @@ int phy_mux_fwnode_add_ports(struct phy_mux *mux,
}
port->interface = ret;
+ if (init_port) {
+ ret = init_port(port, child);
+ if (ret) {
+ phy_mux_port_destroy(port);
+ goto err;
+ }
+ }
+
ret = phy_mux_register_port(mux, port);
if (ret) {
phy_mux_port_destroy(port);
@@ -502,6 +672,8 @@ void phy_mux_free(struct phy_mux *mux)
struct phy_mux_port *port;
unsigned long id;
+ disable_work_sync(&mux->state_work);
+
xa_for_each(&mux->ports, id, port)
phy_mux_port_destroy(port);
diff --git a/include/linux/phy_mux.h b/include/linux/phy_mux.h
index 6a42ffff02b7..77cf389b8c77 100644
--- a/include/linux/phy_mux.h
+++ b/include/linux/phy_mux.h
@@ -21,6 +21,7 @@ struct phy_mux_port_ops {
enum phy_mux_port_type {
PHY_MUX_PORT_PHY,
+ PHY_MUX_PORT_SFP,
};
/**
@@ -30,9 +31,14 @@ enum phy_mux_port_type {
* @type: What sits behind that port
* @phydev: For PHY_MUX_PORT_PHY, the PHY device behind the port, while the
* mux is attached
- * @fwnode: For PHY_MUX_PORT_PHY, the firmware node of that PHY
+ * @fwnode: For PHY_MUX_PORT_PHY, the firmware node of that PHY. For
+ * PHY_MUX_PORT_SFP, the port's own firmware node, carrying the sfp
+ * property.
* @ops: How to drive that port
* @interface: The MII mode the link runs in when this port is selected
+ * @available: The port can be used (e.g. an SFP module is plugged)
+ * @has_precedence: The port is selected as soon as it is available, whatever
+ * the other ports do.
* @attached: For PHY_MUX_PORT_PHY, the PHY is attached to the mux's netdev
* @selected: The port currently drives the MII
*/
@@ -46,6 +52,8 @@ struct phy_mux_port {
const struct phy_mux_port_ops *ops;
phy_interface_t interface;
+ bool available;
+ bool has_precedence;
bool attached;
bool selected;
};
@@ -73,7 +81,9 @@ struct phy_mux_parent_ops {
struct phy_mux *phy_mux_alloc(struct device *dev, int max_n_ports);
int phy_mux_fwnode_add_ports(struct phy_mux *mux,
- const struct fwnode_handle *fwnode);
+ const struct fwnode_handle *fwnode,
+ int (*init_port)(struct phy_mux_port *port,
+ struct fwnode_handle *child));
int phy_mux_register(struct phy_mux *mux);
void phy_mux_unregister(struct phy_mux *mux);
void phy_mux_free(struct phy_mux *mux);
@@ -84,6 +94,10 @@ int fwnode_phy_mux_attach(const struct fwnode_handle *fwnode,
void phy_mux_detach(struct phy_mux *mux);
void phy_mux_start(struct phy_mux *mux);
void phy_mux_stop(struct phy_mux *mux);
+struct fwnode_handle *
+fwnode_phy_mux_find_sfp_port(const struct fwnode_handle *fwnode);
+struct phy_mux_port *phy_mux_get_sfp_port(struct phy_mux *mux);
+void phy_mux_port_set_available(struct phy_mux_port *port, bool available);
#else
@@ -107,6 +121,22 @@ static inline void phy_mux_stop(struct phy_mux *mux)
{
}
+static inline struct fwnode_handle *
+fwnode_phy_mux_find_sfp_port(const struct fwnode_handle *fwnode)
+{
+ return NULL;
+}
+
+static inline struct phy_mux_port *phy_mux_get_sfp_port(struct phy_mux *mux)
+{
+ return NULL;
+}
+
+static inline void phy_mux_port_set_available(struct phy_mux_port *port,
+ bool available)
+{
+}
+
#endif /* CONFIG_PHY_MUX */
#endif /* __PHY_MUX_H */
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 07/12] net: phylink: Factor out phylink_clear_phydev()
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
` (5 preceding siblings ...)
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 ` 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
` (4 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
When disconnecting from a PHY, phylink first clears its internal
references to it, then calls phy_disconnect().
For PHYs that sit behind a mux, we'll only need the first part, as the
mux is the one that attaches and detaches the PHYs from the netdev.
Split that out in phylink_clear_phydev(), in preparation for the phy_mux
support. No functional change intended.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
drivers/net/phy/phylink.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 6f5af388210d..03e255f5ceb1 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -2553,14 +2553,7 @@ int phylink_fwnode_phy_connect(struct phylink *pl,
}
EXPORT_SYMBOL_GPL(phylink_fwnode_phy_connect);
-/**
- * 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.
- */
-void phylink_disconnect_phy(struct phylink *pl)
+static struct phy_device *phylink_clear_phydev(struct phylink *pl)
{
struct phy_device *phy;
@@ -2579,10 +2572,25 @@ void phylink_disconnect_phy(struct phylink *pl)
}
mutex_unlock(&pl->phydev_mutex);
- if (phy) {
+ if (phy)
flush_work(&pl->resolve);
+
+ return 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.
+ */
+void phylink_disconnect_phy(struct phylink *pl)
+{
+ struct phy_device *phy = phylink_clear_phydev(pl);
+
+ if (phy)
phy_disconnect(phy);
- }
}
EXPORT_SYMBOL_GPL(phylink_disconnect_phy);
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 08/12] net: phy: phy_mux: Add phy_mux_set_mac_managed_pm()
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
` (6 preceding siblings ...)
2026-12-04 11:06 ` [PATCH net-next 07/12] net: phylink: Factor out phylink_clear_phydev() Maxime Chevallier
@ 2026-12-04 11:06 ` Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux Maxime Chevallier
` (3 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
MAC drivers that deal with the suspend/resume of their PHY on their own
say so with the mac_managed_pm flag, that ends-up being set on the PHY
when the MAC connects to it.
With a mux, the PHYs are attached by the mux and the parent only gets to
see the PHY of the selected port. The flag is needed on all of them
though, as they are all attached to the netdev.
Add a helper for the mux's parent to set the flag on all the PHYs behind
the mux.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
drivers/net/phy/phy_mux.c | 15 +++++++++++++++
include/linux/phy_mux.h | 5 +++++
2 files changed, 20 insertions(+)
diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
index de3336970bd9..ed0bb8a3f429 100644
--- a/drivers/net/phy/phy_mux.c
+++ b/drivers/net/phy/phy_mux.c
@@ -413,6 +413,21 @@ void phy_mux_detach(struct phy_mux *mux)
}
EXPORT_SYMBOL_GPL(phy_mux_detach);
+/**
+ * phy_mux_set_mac_managed_pm() - Leave the PM of the PHYs to the MAC driver
+ * @mux: The mux, attached
+ */
+void phy_mux_set_mac_managed_pm(struct phy_mux *mux)
+{
+ struct phy_mux_port *port;
+ unsigned long id;
+
+ xa_for_each(&mux->ports, id, port)
+ if (port->attached)
+ port->phydev->mac_managed_pm = true;
+}
+EXPORT_SYMBOL_GPL(phy_mux_set_mac_managed_pm);
+
/**
* phy_mux_start() - Start selecting ports
* @mux: The mux, attached
diff --git a/include/linux/phy_mux.h b/include/linux/phy_mux.h
index 77cf389b8c77..00703371eea8 100644
--- a/include/linux/phy_mux.h
+++ b/include/linux/phy_mux.h
@@ -94,6 +94,7 @@ int fwnode_phy_mux_attach(const struct fwnode_handle *fwnode,
void phy_mux_detach(struct phy_mux *mux);
void phy_mux_start(struct phy_mux *mux);
void phy_mux_stop(struct phy_mux *mux);
+void phy_mux_set_mac_managed_pm(struct phy_mux *mux);
struct fwnode_handle *
fwnode_phy_mux_find_sfp_port(const struct fwnode_handle *fwnode);
struct phy_mux_port *phy_mux_get_sfp_port(struct phy_mux *mux);
@@ -121,6 +122,10 @@ static inline void phy_mux_stop(struct phy_mux *mux)
{
}
+static inline void phy_mux_set_mac_managed_pm(struct phy_mux *mux)
+{
+}
+
static inline struct fwnode_handle *
fwnode_phy_mux_find_sfp_port(const struct fwnode_handle *fwnode)
{
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
` (7 preceding siblings ...)
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
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 10/12] net: phylink: Support an SFP cage behind " Maxime Chevallier
` (2 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
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
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 10/12] net: phylink: Support an SFP cage behind a phy_mux
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
` (8 preceding siblings ...)
2026-12-04 11:06 ` [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux Maxime Chevallier
@ 2026-12-04 11:06 ` Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
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
11 siblings, 1 reply; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
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 <maxime.chevallier@bootlin.com>
---
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
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
` (9 preceding siblings ...)
2026-12-04 11:06 ` [PATCH net-next 10/12] net: phylink: Support an SFP cage behind " Maxime Chevallier
@ 2026-12-04 11:06 ` Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 12/12] ARM: dts: turris-omnia: Describe the WAN port multiplexer Maxime Chevallier
11 siblings, 1 reply; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
Add a driver for the simplest kind of mux, the ones that are switched by
the hardware without any control from software, described with the
mii-mux-auto binding.
That's what we have on the Turris Omnia's WAN port, where the mux's
select line is tied to the SFP cage's mod_def0 signal.
There's not much to do in the driver: it registers the ports, and looks
for the takes-precedence property to tell the core which port the
hardware is going to switch to.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
MAINTAINERS | 1 +
drivers/net/phy/Kconfig | 2 +
drivers/net/phy/Makefile | 1 +
drivers/net/phy/mux/Kconfig | 18 ++++++
drivers/net/phy/mux/Makefile | 3 +
drivers/net/phy/mux/mii_mux_auto.c | 99 ++++++++++++++++++++++++++++++
6 files changed, 124 insertions(+)
create mode 100644 drivers/net/phy/mux/Kconfig
create mode 100644 drivers/net/phy/mux/Makefile
create mode 100644 drivers/net/phy/mux/mii_mux_auto.c
diff --git a/MAINTAINERS b/MAINTAINERS
index b2b02a1dbd3a..59017b0f9f86 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10086,6 +10086,7 @@ M: Maxime Chevallier <maxime.chevallier@bootlin.com>
L: netdev@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/net/mii-mux*.yaml
+F: drivers/net/phy/mux/
F: drivers/net/phy/phy_mux.c
F: include/linux/phy_mux.h
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index d8a0131d2aa2..f6397dab2304 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -29,6 +29,8 @@ config PHY_MUX
time. This adds the infrastructure to represent such multiplexers
and to select which port carries the link.
+source "drivers/net/phy/mux/Kconfig"
+
config SWPHY
bool
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index b3ec2933fec4..b26b34c93dbc 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_PHYLINK) += phylink.o
obj-$(CONFIG_PHYLIB) += libphy.o
obj-$(CONFIG_PHYLIB) += mdio_devres.o
obj-$(CONFIG_PHY_PACKAGE) += phy_package.o
+obj-$(CONFIG_PHY_MUX) += mux/
obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += mii_timestamper.o
diff --git a/drivers/net/phy/mux/Kconfig b/drivers/net/phy/mux/Kconfig
new file mode 100644
index 000000000000..cbfd49fab2ea
--- /dev/null
+++ b/drivers/net/phy/mux/Kconfig
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+if PHY_MUX
+
+config MII_MUX_AUTO
+ tristate "MII multiplexer switched by the hardware"
+ help
+ Support for the two-port MII multiplexers that the hardware
+ switches by itself, without any software control.
+
+ This is typically found on combo ports, where a MAC is wired to
+ either a PHY or an SFP cage depending on whether a module is
+ plugged in the cage.
+
+ To compile this driver as a module, choose M here: the module
+ will be called mii_mux_auto.
+
+endif # PHY_MUX
diff --git a/drivers/net/phy/mux/Makefile b/drivers/net/phy/mux/Makefile
new file mode 100644
index 000000000000..23e8c5029507
--- /dev/null
+++ b/drivers/net/phy/mux/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_MII_MUX_AUTO) += mii_mux_auto.o
diff --git a/drivers/net/phy/mux/mii_mux_auto.c b/drivers/net/phy/mux/mii_mux_auto.c
new file mode 100644
index 000000000000..980cc2c242ba
--- /dev/null
+++ b/drivers/net/phy/mux/mii_mux_auto.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <linux/module.h>
+#include <linux/phy_mux.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+
+static int mii_mux_auto_init_port(struct phy_mux_port *port,
+ struct fwnode_handle *child)
+{
+ port->has_precedence = fwnode_property_read_bool(child,
+ "takes-precedence");
+
+ return 0;
+}
+
+static int mii_mux_auto_check_ports(struct fwnode_handle *fwnode)
+{
+ struct fwnode_handle *child;
+ int n_sfp = 0, n_phy = 0, n_prec = 0, n_sfp_prec = 0;
+
+ fwnode_for_each_available_child_node(fwnode, child) {
+ if (fwnode_property_read_bool(child, "takes-precedence"))
+ n_prec++;
+
+ if (!fwnode_property_present(child, "sfp")) {
+ n_phy++;
+ continue;
+ }
+
+ n_sfp++;
+ if (fwnode_property_read_bool(child, "takes-precedence"))
+ n_sfp_prec++;
+ }
+
+ if (n_sfp != 1 || n_phy != 1 || n_prec != 1 || n_sfp_prec != 1)
+ return -EOPNOTSUPP;
+
+ return 0;
+}
+
+static int mii_mux_auto_probe(struct platform_device *pdev)
+{
+ struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
+ struct phy_mux *mux;
+ int ret;
+
+ ret = mii_mux_auto_check_ports(fwnode);
+ if (ret)
+ return ret;
+
+ mux = phy_mux_alloc(&pdev->dev, 2);
+ if (IS_ERR(mux))
+ return PTR_ERR(mux);
+
+ ret = phy_mux_fwnode_add_ports(mux, fwnode, mii_mux_auto_init_port);
+ if (ret)
+ goto err_free;
+
+ ret = phy_mux_register(mux);
+ if (ret)
+ goto err_free;
+
+ platform_set_drvdata(pdev, mux);
+
+ return 0;
+
+err_free:
+ phy_mux_free(mux);
+ return ret;
+}
+
+static void mii_mux_auto_remove(struct platform_device *pdev)
+{
+ struct phy_mux *mux = platform_get_drvdata(pdev);
+
+ phy_mux_unregister(mux);
+ phy_mux_free(mux);
+}
+
+static const struct of_device_id mii_mux_auto_of_match[] = {
+ { .compatible = "mii-mux-auto" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, mii_mux_auto_of_match);
+
+static struct platform_driver mii_mux_auto_driver = {
+ .probe = mii_mux_auto_probe,
+ .remove = mii_mux_auto_remove,
+ .driver = {
+ .name = "mii-mux-auto",
+ .of_match_table = mii_mux_auto_of_match,
+ },
+};
+module_platform_driver(mii_mux_auto_driver);
+
+MODULE_DESCRIPTION("Ethernet MII multiplexer switched by the hardware");
+MODULE_AUTHOR("Maxime Chevallier <maxime.chevallier@bootlin.com>");
+MODULE_LICENSE("GPL");
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next 12/12] ARM: dts: turris-omnia: Describe the WAN port multiplexer
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
` (10 preceding siblings ...)
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 ` Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
11 siblings, 1 reply; 22+ messages in thread
From: Maxime Chevallier @ 2026-12-04 11:06 UTC (permalink / raw)
To: davem, Andrew Lunn, Jakub Kicinski, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Russell King, Marek Behún,
Sebastian Hesselbarth, Gregory Clement, Heiner Kallweit
Cc: Maxime Chevallier, netdev, linux-kernel, linux-arm-kernel,
thomas.petazzoni, devicetree, Conor Dooley, Krzysztof Kozlowski,
Rob Herring, Christophe Leroy, Herve Codina, Florian Fainelli,
Vladimir Oltean, Köry Maincent, Oleksij Rempel,
Nicolò Veronese, Simon Horman, marcin.s.wojtas, Daniel Golle,
Dimitri Fedrau, Frank Wunderlich, Pietro Ameruoso,
Aleksei Sviridkin
The Turris Omnia's WAN port has a mux between the MAC and both an SFP
cage and a 88E1514 PHY. The mux is a high-speed analog switch (NXP
CBTL02042A), whose select line is driven by the cage's mod_def0 signal:
it switches to the cage as soon as a module is plugged.
We couldn't deal with that so far. The devicetree only describes the
PHY, and relies on the bootloader to enable the sfp node and drop the
phy-handle when a module is found at boot. Modules plugged or removed
later on aren't taken into account.
Now that we have a binding for these muxes, let's describe that one. The
sfp node is always enabled, and we follow the module at runtime.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
.../dts/marvell/armada-385-turris-omnia.dts | 29 ++++++++++++-------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts b/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts
index 83fe00abd652..0501686e2642 100644
--- a/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts
+++ b/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts
@@ -103,13 +103,24 @@ sfp: sfp {
los-gpios = <&pcawan 3 GPIO_ACTIVE_HIGH>;
mod-def0-gpios = <&pcawan 4 GPIO_ACTIVE_LOW>;
maximum-power-milliwatt = <3000>;
+ };
- /*
- * For now this has to be enabled at boot time by U-Boot when
- * a SFP module is present. Read more in the comment in the
- * eth2 node below.
- */
- status = "disabled";
+ wan_mux: mii-mux {
+ compatible = "mii-mux-auto";
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@0 {
+ reg = <0>;
+ sfp = <&sfp>;
+ takes-precedence;
+ };
+
+ port@1 {
+ reg = <1>;
+ phy-handle = <&phy1>;
+ phy-mode = "sgmii";
+ };
};
gpio-keys {
@@ -199,16 +210,12 @@ ð2 {
* eth2 is connected via a multiplexor to both the SFP cage and to
* ethernet-phy@1. The multiplexor switches the signal to SFP cage when
* a SFP module is present, as determined by the mode-def0 GPIO.
- *
- * Until kernel supports this configuration properly, in case SFP module
- * is present, U-Boot has to enable the sfp node above, remove phy
- * handle and add managed = "in-band-status" property.
*/
status = "okay";
phy-mode = "sgmii";
phy-handle = <&phy1>;
+ mii-mux-handle = <&wan_mux>;
phys = <&comphy5 2>;
- sfp = <&sfp>;
buffer-manager = <&bm>;
bm,pool-long = <2>;
bm,pool-short = <3>;
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH net-next 01/12] dt-bindings: net: Add Ethernet MII multiplexers
2026-12-04 11:06 ` [PATCH net-next 01/12] dt-bindings: net: Add Ethernet " Maxime Chevallier
@ 2026-12-05 11:08 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-05 11:08 UTC (permalink / raw)
To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] dt-bindings: net: mii-mux-auto allows >2 ports and extra
takes-precedence
- [Low] dt-bindings: net: mii-mux-auto leaves takes-precedence trigger
unspecified
--
commit 15b0b40dd7397c1fe9390dd7da13fe9a18c062a8
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
dt-bindings: net: Add Ethernet MII multiplexers
This commit adds generic and hardware-switched Ethernet MII multiplexer
devicetree bindings, adds a mii-mux-handle property to
ethernet-controller.yaml, and adds a MAINTAINERS entry.
> diff --git a/Documentation/devicetree/bindings/net/mii-mux-auto.yaml b/Documentation/devicetree/bindings/net/mii-mux-auto.yaml
> new file mode 100644
> index 0000000000000..7a965f6e8dcce
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/mii-mux-auto.yaml
> @@ -0,0 +1,89 @@
[ ... ]
> +allOf:
> + - $ref: mii-mux.yaml#
> +
> +properties:
> + compatible:
> + const: mii-mux-auto
> +
> +patternProperties:
> + "^port@[0-9a-f]+$":
> + $ref: mii-mux.yaml#/$defs/port
> + unevaluatedProperties: false
> +
> + properties:
> + takes-precedence:
> + type: boolean
> + description:
> + The multiplexer switches to this port by itself as soon as the
> + port gets active, whatever the state of the other port.
[Severity: Low]
Should the takes-precedence description specify what physical event counts
as "active"?
Without software control or state readback, drivers must infer when the
hardware switches. "Active" could mean SFP module presence (mod_def0),
optical signal detect (RX_LOS), or link-up, letting incompatible hardware
share the same DT representation.
It also leaves takes-precedence permitted on phy-handle ports even though
no activation trigger is defined for a PHY port.
> +
> +required:
> + - compatible
> + - port@0
> + - port@1
> +
> +oneOf:
> + - properties:
> + port@0:
> + required:
> + - takes-precedence
> + - properties:
> + port@1:
> + required:
> + - takes-precedence
> +
> +unevaluatedProperties: false
[Severity: Medium]
Does this schema still allow a mii-mux-auto node with port@2 or higher?
Both this file and mii-mux.yaml match "^port@[0-9a-f]+$" without bounding
reg, so port@2+ children pass unevaluatedProperties: false. Because oneOf
only checks port@0 and port@1, an extra port can also set takes-precedence
and still pass dtbs_check.
Narrowing the pattern here to "^port@[01]$" alone would not reject port@2+
because mii-mux.yaml still evaluates "^port@[0-9a-f]+$" via allOf;
constraining reg to [0, 1] (or rejecting higher ports explicitly) would
enforce both invariants.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=1
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next 03/12] net: phy: Don't create the sysfs links for PHYs behind a mux
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-05 11:08 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-05 11:08 UTC (permalink / raw)
To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] net: phy: skipping phy_sysfs_create_links() drops per-PHY
attached_dev link
--
commit a16b08e2d216e5687da38893c4bd94d7b180213f
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
net: phy: Don't create the sysfs links for PHYs behind a mux
This commit adds a mux_port pointer to struct phy_device and skips calling
phy_sysfs_create_links() in phy_attach_direct() when phydev->mux_port is set.
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 60440b62e6c79..9630578a6a5c5 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -2019,7 +2019,8 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
> */
> phydev->sysfs_links = false;
>
> - phy_sysfs_create_links(phydev);
> + if (!phydev->mux_port)
> + phy_sysfs_create_links(phydev);
>
> if (!phydev->attached_dev) {
> err = sysfs_create_file(&phydev->mdio.dev.kobj,
[Severity: Low]
Should muxed PHYs still create the per-PHY attached_dev symlink?
phy_sysfs_create_links() creates two symlinks: attached_dev under
phydev->mdio.dev.kobj and phydev under dev->dev.kobj. Only the netdev-side
phydev link collides across multiple PHYs (failing with -EEXIST rather than
overwriting), whereas each PHY has its own kobject for attached_dev.
Skipping phy_sysfs_create_links() entirely while phydev->attached_dev is
still set leaves muxed PHYs with neither attached_dev nor phy_standalone in
sysfs, despite Documentation/ABI/testing/sysfs-class-net-phydev documenting
attached_dev for attached PHYs.
If omitting attached_dev is intentional, the commit message and ABI doc
should note that; otherwise, only the netdev-side phydev link needs to be
skipped (with phy_detach_internal() updated to match).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=3
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device
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-05 11:08 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-05 11:08 UTC (permalink / raw)
To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] net: phy: unsynchronized phy_mux_detach() races with
unregister and attach
- [Medium] net: phy: phy_mux: phy_mux_attach() clobbers dev->sfp_bus
- [Medium] net: phy: phy_mux_detach_phys() omits phy_stop_machine()
before phy_detach()
--
commit 5ec0ab0887a678472a4f565b6b693b7e69aef8df
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
net: phy: phy_mux: Allow attaching a mux to a net_device
This commit adds support for attaching a phy_mux to a net_device and its
parent, binding and attaching the PHYs behind the mux and introducing
parent_ops attach and detach callbacks.
> diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
> index e259eb4e271a0..691bca09e0af1 100644
> --- a/drivers/net/phy/phy_mux.c
> +++ b/drivers/net/phy/phy_mux.c
[ ... ]
> +static void phy_mux_detach_phys(struct phy_mux *mux)
> +{
> + struct phy_mux_port *port;
> + unsigned long id;
> +
> + xa_for_each(&mux->ports, id, port) {
> + if (!port->attached)
> + continue;
> +
> + phy_detach(port->phydev);
> + phy_mux_port_unbind_phy(port);
> + port->attached = false;
> + }
> +}
[Severity: Medium]
Should phy_mux_detach_phys() call phy_stop_machine() before phy_detach()?
phy_mux_attach() sets port->phydev->phy_link_change to
phy_mux_phy_link_change, which causes phy_uses_state_machine() to return
true even for unselected mux PHYs. On MAC drivers without mac_managed_pm
(such as mvneta), mdio_bus_phy_resume() then calls phy_start_machine() and
queues phydev->state_queue. For non-genphy drivers, phy_detach() does not
cancel state_queue.
If a deselected PHY is in PHY_HALTED with phydev->suspended still false
(for example, with WoL enabled), a queued phy_state_machine() work item
can race with detach and netdev teardown:
CPU0 CPU1 (kworker)
phy_state_machine()
_phy_state_machine() /* PHY_HALTED */
mutex_unlock(&phydev->lock)
phy_suspend()
netdev = phydev->attached_dev
phy_mux_detach()
phy_mux_detach_phys()
phy_detach()
phydev->attached_dev = NULL
phy_device_reset(phydev, 1)
free_netdev(netdev)
netdev->ethtool->wol_enabled
<-- use-after-free
Even without WoL, a pending phy_suspend() can run after
phy_device_reset(phydev, 1) or race with a subsequent re-attach and power
down an active PHY.
[ ... ]
> + ret = phy_attach_direct(dev, port->phydev, phy_flags,
> + port->interface);
> + if (ret) {
> + phy_mux_port_unbind_phy(port);
> + goto err_detach;
> + }
> +
> + port->phydev->phy_link_change = phy_mux_phy_link_change;
> + port->attached = true;
> + has_phys = true;
> + }
> +
> + if (has_phys)
> + dev->phydev = NULL;
[Severity: Medium]
Can attaching a muxed PHY here clobber dev->sfp_bus?
Unlike phy_sysfs_create_links(), phy_attach_direct() unconditionally sets
dev->sfp_bus = phydev->sfp_bus when phydev->sfp_bus_attached is true, even
when phydev->mux_port is set. Because deselected mux PHYs keep
phydev->attached_dev set to dev, later phy_sfp_attach() and
phy_sfp_detach() calls also overwrite or clear dev->sfp_bus.
On a mux where a PHY has a downstream SFP cage, this overwrites any
existing dev->sfp_bus (such as an SFP cage on another mux port), causing
ethtool -m to query the wrong cage. In addition, phy_detach_internal()
clears phydev->attached_dev without clearing dev->sfp_bus, leaving a
dangling dev->sfp_bus pointer if the PHY and its SFP socket are later
unbound while dev stays registered.
[ ... ]
> +void phy_mux_detach(struct phy_mux *mux)
> +{
> + if (!mux->netdev)
> + return;
> +
> + phy_mux_detach_phys(mux);
> +
> + if (mux->devlink) {
> + device_link_del(mux->devlink);
> + mux->devlink = NULL;
> + }
> +
> + mux->pops = NULL;
> + mux->parent_priv = NULL;
> + mux->netdev = NULL;
> +}
> +EXPORT_SYMBOL_GPL(phy_mux_detach);
[ ... ]
> void phy_mux_unregister(struct phy_mux *mux)
> {
> mutex_lock(&phy_mux_mutex);
> list_del(&mux->node);
> mutex_unlock(&phy_mux_mutex);
> +
> + rtnl_lock();
> + if (mux->netdev && mux->pops && mux->pops->detach)
> + mux->pops->detach(mux, mux->parent_priv);
> + rtnl_unlock();
> }
[Severity: Medium]
Can phy_mux_detach() race with phy_mux_unregister() and phy_mux_free()?
phy_mux_attach() adds mux->devlink with DL_FLAG_STATELESS, so unbinding
the mux does not unbind the MAC first. phy_mux_unregister() drops
phy_mux_mutex and relies on rtnl_lock() to serialize mux->pops->detach()
before the mux driver calls phy_mux_free(mux), whereas phy_mux_detach()
acquires neither phy_mux_mutex nor rtnl_lock().
When phylink_destroy() calls phy_mux_detach() without RTNL (for instance
in mvpp2_port_remove() or ucc_geth_remove() after an open-time failure
leaves the mux attached), it can run concurrently with mux removal:
CPU0 CPU1
phylink_destroy() /* no RTNL */ phy_mux_unregister()
phy_mux_detach(mux) mutex_lock(&phy_mux_mutex)
if (!mux->netdev) /* false */ list_del(&mux->node)
mutex_unlock(&phy_mux_mutex)
rtnl_lock()
if (mux->netdev && mux->pops->detach)
mux->pops->detach(mux, priv)
phy_mux_detach(mux)
rtnl_unlock()
phy_mux_free(mux)
kfree(mux)
phy_mux_detach_phys(mux)
<-- use-after-free / double detach
If CPU0 finishes phy_mux_detach() and frees phylink while CPU1 is past the
mux->netdev check, CPU1 can likewise dereference NULL mux->pops or call
pops->detach() on freed parent state.
Similarly, fwnode_phy_mux_attach() holds only phy_mux_mutex and is called
without RTNL by drivers such as dsa_user_create() and ocelot_probe_port(),
sharing no common lock with phy_mux_detach(). Calling phy_mux_detach()
without RTNL while dev is still registered (as in ucc_geth_remove()) also
violates the rcu_dereference_protected() check on dev->hwprov in
phy_detach_internal().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=4
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic
2026-12-04 11:06 ` [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic Maxime Chevallier
@ 2026-12-05 11:08 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-05 11:08 UTC (permalink / raw)
To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] net: phy: phy_mux: selected PHY is not resumed before
pops->select()
- [Medium] net: phy: unlocked phy_mux_detach() races with unregister and
ethtool
--
commit dc38119185f1b5ebf431eebfe3a9d57a7ea7cf22
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
net: phy: phy_mux: Add port selection logic
This patch adds port selection and deselection logic to phy_mux, along with
phy_mux_start(), phy_mux_stop(), and phy_mux_port_ops to power down
deselected PHYs.
> diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
> index 691bca09e0af1..407269980edc1 100644
> --- a/drivers/net/phy/phy_mux.c
> +++ b/drivers/net/phy/phy_mux.c
[ ... ]
> +static int __phy_mux_select_port(struct phy_mux *mux,
> + struct phy_mux_port *port)
> +{
> + int ret;
> +
> + if (mux->pops && mux->pops->select) {
> + ret = mux->pops->select(mux, port, mux->parent_priv);
> + phy_mux_port_set_parent_phy(mux, port, !ret);
> + if (ret)
> + return ret;
> + }
> +
> + port->selected = true;
> +
> + return 0;
> +}
[Severity: High]
Should port->phydev be resumed before calling mux->pops->select()?
phy_mux_attach() and __phy_mux_deselect_port() suspend every PHY via
phy_mux_phy_power_down() -> phy_suspend(), so mux->pops->select() runs
against a powered-down PHY. When a parent like phylink runs
phylink_bringup_phy(), EEE clock-stop configuration and
phy_request_interrupt() execute before phy_start() calls __phy_resume().
On PHYs such as Broadcom BCM54xx, non-BMCR register writes are ignored while
BMCR_PDOWN is set and bcm54xx_resume() re-runs bcm54xx_config_init(), leaving
hardware interrupts disabled and EEE settings lost.
If pops->select is NULL or does not call phy_start() or phy_resume(), the
selected PHY also remains suspended while port->selected is true. Adding a
select callback in phy_mux_port_ops to call phy_resume() before
mux->pops->select() would restore symmetry with phy_mux_port_deselect().
[ ... ]
> @@ -188,13 +281,15 @@ EXPORT_SYMBOL_GPL(fwnode_phy_mux_attach);
> * phy_mux_detach() - Detach the mux from its parent
> * @mux: The mux
> *
> - * The PHYs behind the mux are detached.
> + * The mux is stopped and its PHYs are detached. Caller must hold rtnl when
> + * the mux was started.
> */
> void phy_mux_detach(struct phy_mux *mux)
> {
> if (!mux->netdev)
> return;
>
> + phy_mux_stop(mux);
> phy_mux_detach_phys(mux);
[Severity: Medium]
Can calling phy_mux_detach() without rtnl_lock() race with
phy_mux_unregister() and ethtool?
phy_mux_attach() creates mux->devlink with DL_FLAG_STATELESS, which does not
prevent the mux driver from unbinding while the parent MAC driver is bound.
Because phy_mux_unregister() drops phy_mux_mutex before taking rtnl_lock(), a
caller that runs phy_mux_detach() without rtnl_lock() when the mux is stopped
(such as phylink_destroy() in mvpp2_port_remove() after an ndo_open()
failure) has no lock in common with phy_mux_unregister():
CPU0 CPU1
phylink_destroy()
phy_mux_detach(mux)
if (!mux->netdev) // false
phy_mux_unregister()
rtnl_lock()
mux->pops->detach(...)
phy_mux_detach(mux)
phy_mux_detach_phys(mux)
phy_mux_detach_phys(mux)
<-- double phy_detach()
rtnl_unlock()
phy_mux_free(mux)
mux->netdev = NULL
<-- use-after-free
In addition, if the netdev is still NETREG_REGISTERED when phy_mux_detach()
runs without rtnl_lock() (such as ucc_geth_remove() with
devm_register_netdev()), phy_detach_internal() triggers a lockdep splat on
dev->hwprov and phy_link_topo_del_phy() frees struct phy_device_node without
RCU while concurrent ethtool queries in ethnl_req_get_phydev() expect
rtnl_lock().
fwnode_phy_mux_attach() also serializes only on phy_mux_mutex and can be
called without rtnl_lock() (for example from dsa_user_phy_setup()), leaving
mux->netdev, mux->pops, and mux->parent_priv without a common lock between
attach and detach.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=5
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports
2026-12-04 11:06 ` [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports Maxime Chevallier
@ 2026-12-05 11:08 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-05 11:08 UTC (permalink / raw)
To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] net: phy: phy_mux_detach() races with unregister, free, and
attach
- [Medium] net: phy: phy_mux_select() errors silently ignored by callers
- [Medium] net: phy: phy_mux_start() defers port selection past
ndo_open() and RTNL
- [Low] net: phy: phy_mux_port_set_available() queues work when stopped
- [Low] net: phy: commit message overstates auto-mux scope and omits
design
--
commit 7f7c13dd3f5d9a4be97b36f9ec7d719e76abf8ad
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
> net: phy: phy_mux: Support SFP cage ports
>
> It's quite common to have combo ports where one of the ports is an SFP
> cage, let's allow adding one on the mux.
>
> To keep things realistic, we only allow one SFP cage per combo port.
>
> When an SFP cage doesn't have any module inserted, it doesn't really
> make sense to allow using it as the active port, so we need to keep
> track of whether there's a module or not.
>
> There's a simple way to implement a combo port that we find on Turris
> Omnia for example, that is to wire the SFP cage's mod_def0 to the
> physical multiplexer. In this case, we can't select the port to use from
> the host, but we can report that the port is in use and shutdown the
> unused port. For that, we however need to indicate that the SFP cage
> always takes precedence, as represented in the auto-mux binding.
>
> So, add support for attaching SFP cages to muxes, and implement the
> automatic mux.
>
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
[Severity: Low]
This isn't a bug, but the closing sentence states that this patch
implements the automatic mux, whereas it only adds core phy_mux support
for SFP ports and port precedence (not the mii-mux-auto driver or its DT
property parsing).
The commit message also omits explaining the new init_port callback in
phy_mux_fwnode_add_ports(), changing phy_mux_start() to defer selection
to state_work, and why phy_mux_port_set_available() selects synchronously
when available is true but defers to state_work when false.
> diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
> index 407269980edc1..de3336970bd9b 100644
> --- a/drivers/net/phy/phy_mux.c
> +++ b/drivers/net/phy/phy_mux.c
[ ... ]
> @@ -122,6 +129,109 @@ static const struct phy_mux_port_ops phy_mux_phy_power_ops = {
> .deselect = phy_mux_phy_power_down,
> };
>
> +static struct phy_mux_port *phy_mux_choose_port(struct phy_mux *mux)
> +{
> + struct phy_mux_port *port;
> + unsigned long id;
> +
> + xa_for_each(&mux->ports, id, port)
> + if (port->has_precedence && port->available)
> + return port;
> +
> + xa_for_each(&mux->ports, id, port)
> + if (port->available)
> + return port;
> +
> + return NULL;
> +}
> +
> +static void phy_mux_state_machine(struct work_struct *work)
> +{
> + struct phy_mux *mux = container_of(work, struct phy_mux, state_work);
> +
> + rtnl_lock();
> +
> + switch (mux->state) {
> + case PHY_MUX_STOPPED:
> + break;
> +
> + case PHY_MUX_STARTED:
> + phy_mux_select(mux, phy_mux_choose_port(mux));
> + break;
> + }
> +
> + rtnl_unlock();
> +}
[Severity: Medium]
Should phy_mux_state_machine() and phy_mux_port_set_available() check the
return value of phy_mux_select()?
phy_mux_select() deselects any active mux->current_port and sets it to
NULL before calling __phy_mux_select_port(). If mux->pops->select() fails
(for example, phylink_bringup_phy() failing in phy_eee_rx_clock_stop() or
phylink_validate_phy()), ignoring the error leaves mux->current_port NULL
and the interface up with no active port or link, without logging any
error.
> +void phy_mux_port_set_available(struct phy_mux_port *port, bool available)
> +{
> + struct phy_mux *mux = port->mux;
> +
> + ASSERT_RTNL();
> +
> + if (port->available == available)
> + return;
> +
> + port->available = available;
> +
> + if (available && mux->state == PHY_MUX_STARTED) {
> + phy_mux_select(mux, phy_mux_choose_port(mux));
> + return;
> + }
> +
> + phy_mux_trigger(mux);
> +}
[Severity: Low]
Should phy_mux_port_set_available() return early when
mux->state != PHY_MUX_STARTED?
When the mux is stopped, falling through to phy_mux_trigger() wakes a
kworker and acquires rtnl_lock() in phy_mux_state_machine() only to break
out of the switch. phy_mux_stop() also returns early when already
stopped, so work queued while stopped is not cancelled there either.
[ ... ]
> @@ -312,13 +422,8 @@ EXPORT_SYMBOL_GPL(phy_mux_detach);
> */
> void phy_mux_start(struct phy_mux *mux)
> {
> - struct phy_mux_port *port;
> - unsigned long id = 0;
> -
> mux->state = PHY_MUX_STARTED;
> -
> - port = xa_find(&mux->ports, &id, ULONG_MAX, XA_PRESENT);
> - phy_mux_select(mux, port);
> + phy_mux_trigger(mux);
> }
> EXPORT_SYMBOL_GPL(phy_mux_start);
[Severity: Medium]
Does deferring initial port selection to state_work break callers that
expect a PHY to be selected when phy_mux_start() returns?
Because phy_mux_state_machine() blocks on rtnl_lock(), port selection
cannot run until ndo_open() releases RTNL. Drivers such as stmmac_open()
and mvneta_start_dev() call phylink_speed_up() right after phylink_start()
under the same RTNL lock, where pl->phydev is now guaranteed to be NULL;
phy_speed_up() is silently skipped and a PHY downgraded by
phylink_speed_down() remains stuck at its lowest advertised speed.
Userspace ethtool calls issued immediately after ip link set up can also
race ahead of state_work and see pl->phydev == NULL. Calling
phy_mux_select(mux, phy_mux_choose_port(mux)) synchronously in
phy_mux_start() under the caller's held RTNL lock avoids both issues and
the extra kworker wakeup.
[ ... ]
> @@ -502,6 +672,8 @@ void phy_mux_free(struct phy_mux *mux)
> struct phy_mux_port *port;
> unsigned long id;
>
> + disable_work_sync(&mux->state_work);
> +
> xa_for_each(&mux->ports, id, port)
> phy_mux_port_destroy(port);
[Severity: Medium]
Can phy_mux_detach() race with phy_mux_unregister(), phy_mux_free(), and
fwnode_phy_mux_attach()?
fwnode_phy_mux_attach() holds phy_mux_mutex without requiring rtnl_lock(),
phy_mux_unregister() drops phy_mux_mutex and holds only rtnl_lock(), and
phy_mux_detach() acquires neither lock (and is permitted without RTNL when
the mux is stopped, as in phylink_destroy()). Because mux->devlink uses
DL_FLAG_STATELESS and struct phy_mux has no reference count, unbinding the
MAC device and mux device concurrently can interleave:
CPU0 CPU1
phy_mux_detach(mux)
if (!mux->netdev) -> false
...
phy_mux_unregister(mux)
rtnl_lock()
mux->pops->detach(...)
rtnl_unlock()
phy_mux_free(mux)
kfree(mux)
mux->netdev = NULL <-- use-after-free
Depending on timing, CPU1 can also trigger a double detach (double
phy_detach() and device_link_del()), or dereference a NULL mux->pops or
freed parent_priv if CPU0 clears them after CPU1 checks them. Concurrent
fwnode_phy_mux_attach() and phy_mux_detach() are similarly unsynchronized
on mux->netdev and port PHY bindings.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=6
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux
2026-12-04 11:06 ` [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux Maxime Chevallier
@ 2026-12-05 11:08 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-05 11:08 UTC (permalink / raw)
To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] net: phylink: phylink_mux_select() configures suspended PHY
- [High] net: phylink: phylink_resolve() left enabled across phy_mux
port transitions
- [Medium] net: phylink: missing rtnl_lock() in phylink_destroy() mux
detach
- [Medium] net: phylink: phy_mux_stop() in phylink_stop() breaks PM WoL
and RXC resume
- [Medium] net: phylink: unlocked pl->mux read in
phylink_fwnode_phy_connect()
- [Medium] net: phylink: armed PHY IRQ in PHY_HALTED races with mux
select/deselect
--
commit a4afcb522e18328b8fbf2ddefbad3fcd4d9619af
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
net: phylink: Support PHYs reached through a phy_mux
This commit adds phy_mux parent support to phylink so that MACs referencing a
mii-mux-handle attach to the mux in phylink_fwnode_phy_connect() and manage
PHY port selection through phy_mux_parent_ops.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 03e255f5ceb17..702614adcb945 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -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);
[Severity: Medium]
Can calling phylink_detach_mux() here without rtnl_lock() race with
phy_mux_unregister() or phy_mux_state_machine()?
phylink_destroy() is called without rtnl_lock() held, unlike both neighboring
calls (sfp_bus_del_upstream() and phylink_destroy_sfp_cage_port()), which
acquire it internally. In drivers/net/phy/phy_mux.c, phy_mux_unregister() and
phy_mux_state_machine() rely on rtnl_lock() to serialize mux teardown (and
phy_mux_stop() only calls non-synchronous cancel_work(&mux->state_work)).
CPU0 CPU1
phylink_destroy() phy_mux_unregister()
phylink_detach_mux() rtnl_lock()
if (!pl->mux) mux->pops->detach()
phylink_detach_mux()
phy_mux_detach(mux)
pl->mux = NULL
phy_mux_detach(pl->mux) rtnl_unlock()
<-- double detach / UAF phy_mux_free(mux)
If phylink_destroy() runs while pl->mux is still attached, this can double
detach or use-after-free pl or mux, and if the mux is still started,
phy_mux_detach() -> phy_mux_stop() -> phylink_mux_deselect() ->
phylink_clear_phydev() also hits ASSERT_RTNL(). Acquiring rtnl_lock() around
phylink_detach_mux(pl) in phylink_destroy() (and asserting ASSERT_RTNL() in
phylink_detach_mux()) would close this.
[ ... ]
> @@ -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. */
[Severity: Medium]
Can this unlocked read of pl->mux race with a concurrent phy_mux_unregister()?
Callers such as dsa_user_create() invoke phylink_fwnode_phy_connect() without
rtnl_lock(). fwnode_phy_mux_attach() releases phy_mux_mutex before returning:
CPU0 CPU1
phylink_fwnode_phy_connect()
phylink_attach_mux()
fwnode_phy_mux_attach()
mutex_lock(&phy_mux_mutex)
pl->mux = mux
mutex_unlock(&phy_mux_mutex)
phy_mux_unregister()
rtnl_lock()
phylink_mux_detach()
pl->mux = NULL
rtnl_unlock()
if (pl->mux) <-- sees NULL
return 0;
fwnode_get_phy_node()
If phy_mux_unregister() clears pl->mux in that window, this falls through to
fwnode_get_phy_node() as if no mux existed, returning -ENODEV in MLO_AN_PHY
mode or returning 0 with neither mux nor PHY in MLO_AN_INBAND mode.
[ ... ]
> @@ -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);
[Severity: High]
Does leaving phylink_resolve() enabled while no mux port is selected allow
spurious link-up and unlocked reconfiguration in MLO_AN_INBAND mode?
phylink_start() clears PHYLINK_DISABLE_STOPPED and queues pl->resolve before
phy_mux_start() schedules mux->state_work (which blocks on rtnl_lock()).
phylink_mux_deselect() also clears pl->phydev without setting a
PHYLINK_DISABLE_* bit, so the retriggered resolve work runs with pl->phydev
NULL.
CPU0 kworker
phylink_start()
phylink_enable_and_run_resolve()
queue_work(pl->resolve)
phy_mux_start(pl->mux)
schedule_work(mux->state_work)
phylink_resolve()
/* pl->phydev == NULL */
phylink_mac_pcs_get_state()
phylink_link_up() <-- no port selected
In MLO_AN_INBAND mode, phylink_resolve() skips gating on pl->phy_state.link
when pl->phydev is NULL, so a live PCS link triggers phylink_link_up() with
no mux port selected.
When phylink_mux_select() then runs, calling phylink_mac_initial_config() ->
phylink_major_config() while pl->old_link_state is true reconfigures the MAC
and PCS without a preceding phylink_link_down().
Because phylink_resolve() is still enabled, phylink_mux_select() also writes
pl->link_config.interface without pl->state_mutex or phy->lock, and
phylink_mac_initial_config() reads pl->req_link_an_mode, pl->phy_state, and
pl->link_config before taking phy->lock, racing with a concurrent resolve.
> @@ -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)
[Severity: Medium]
Does calling phy_mux_stop() in phylink_stop() break PHY Wake-on-LAN and
mac_requires_rxc resume?
phy_mux_stop() deselects the active port via phylink_mux_deselect(), which
clears pl->phydev to NULL and frees the PHY interrupt. In
phylink_suspend(pl, false), phylink_stop() runs before
phylink_phy_pm_speed_ctrl() checks pl->phydev, so phylink_speed_down() (and
phylink_speed_up() on resume) is always skipped, and freeing the PHY IRQ
breaks IRQ-based PHY Wake-on-LAN wakeups.
Clearing pl->phydev also turns phylink_prepare_resume() into a no-op, so MACs
with mac_requires_rxc (such as stmmac in __stmmac_open()) cannot wake the
suspended PHY to restore RXC before DMA reset.
[ ... ]
> +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;
> +}
[Severity: High]
Isn't port->phydev still suspended when phylink_bringup_phy() and
phylink_mac_initial_config() configure it here?
phy_mux_attach() and port deselection both suspend PHY ports via
phy_mux_phy_power_down() -> phy_suspend(), and phy_mux does not call
phy_resume() on selection. phylink_bringup_phy() performs MDIO accesses for
EEE and enables interrupts via phy_request_interrupt(), and
phylink_major_config() calls phy_config_inband(), all before phy_start(phy)
resumes the PHY.
On PHY drivers that ignore non-BMCR writes in power-down or reset registers on
resume (such as bcm54xx_resume() in drivers/net/phy/broadcom.c or
kszphy_resume() in drivers/net/phy/micrel.c), interrupt and EEE configuration
can be silently discarded or fail, leaving hardware IRQs masked while polling
is disabled so the link never comes up. Resuming the PHY before
phylink_bringup_phy() (and re-suspending on error), or resuming the port in
phy_mux before pops->select(), would avoid this.
> +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;
> +}
[Severity: Medium]
Can a PHY or shared interrupt firing while phy->state is PHY_HALTED re-suspend
the PHY after phy_start() or race with teardown?
Because a muxed PHY stays attached across port switches, phy_stop() leaves it
in PHY_HALTED rather than PHY_READY. In phylink_mux_deselect(), phy_stop()
cancels phy->state_queue before phylink_clear_phydev() flushes pl->resolve and
before phy_free_interrupt() frees the IRQ, without canceling phy->state_queue
afterward. On re-selection in phylink_mux_select(), phylink_bringup_phy()
also calls phy_request_interrupt() while phy->state is still PHY_HALTED.
CPU0 kworker
phylink_mux_select()
phylink_bringup_phy()
phy_request_interrupt(phy)
/* IRQ fires in PHY_HALTED */
phy_state_machine()
mutex_lock(&phy->lock)
_phy_state_machine() -> WORK_SUSPEND
mutex_unlock(&phy->lock)
phy_start(phy)
mutex_lock(&phy->lock)
__phy_resume(phy)
phy->state = PHY_UP
mutex_unlock(&phy->lock)
phy_suspend(phy) <-- re-suspends PHY
Because phy_state_machine() drops phy->lock before
_phy_state_machine_post_work() calls phy_suspend(), a stale PHY_HALTED work
item can re-set BMCR_PDOWN and phy->suspended after phy_start() resumes the
PHY, leaving the link stuck down until another stop/start cycle. During
deselection, the queued work can also race with phy_mux_phy_power_down() or
phy_detach().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=9
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next 10/12] net: phylink: Support an SFP cage behind a phy_mux
2026-12-04 11:06 ` [PATCH net-next 10/12] net: phylink: Support an SFP cage behind " Maxime Chevallier
@ 2026-12-05 11:08 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-05 11:08 UTC (permalink / raw)
To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] net: phylink: stale sfp_link_down after stop/remove/detach
breaks LOS gating
- [Medium] net: phylink: phylink_start() runs resolve before mux selects
SFP port
- [Medium] net: phylink: phylink_mux_select() clears DISABLE_LINK before
reconfiguring
- [Medium] net: phylink: missing sfp_mod_present rollback on
may_have_phy module failures
- [Medium] net: phylink: phylink_mux_deselect() does not bring down
active SFP link
- [Medium] net: phylink: data race on mux_sfp_port in
phylink_mux_attach()
- [Medium] net: phylink: missing rtnl_lock() in phylink_destroy() mux
detach
--
commit 0d6f64bddfb5d3b2e43faf1b89e62b3654b6ad2b
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
net: phylink: Support an SFP cage behind a phy_mux
This commit teaches phylink to discover an SFP cage described on a
phy_mux port, report module availability to the mux, and handle
selecting and deselecting the SFP port.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 702614adcb945..6d62bd37f95a6 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -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;
> }
[Severity: Medium]
Can phylink_destroy() race with phy_mux_state_machine() and cause a
use-after-free of pl when calling phylink_detach_mux(pl) without
rtnl_lock()?
phylink_destroy() runs without rtnl_lock() and calls
sfp_bus_del_upstream(pl->sfp_bus) followed by phylink_detach_mux(pl)
and kfree(pl). With this patch, phylink_sfp_detach() calls
phy_mux_port_set_available(pl->mux_sfp_port, false), which queues
mux->state_work right before sfp_bus_del_upstream() drops rtnl_lock().
Because phy_mux_stop() inside phy_mux_detach() uses cancel_work()
rather than cancel_work_sync(), phylink_destroy() can free pl while
the worker is still running:
CPU0 CPU1 (kworker)
phylink_destroy()
sfp_bus_del_upstream()
rtnl_lock()
phylink_sfp_detach()
phy_mux_port_set_available(..., false)
phy_mux_trigger(mux)
rtnl_unlock()
phy_mux_state_machine()
rtnl_lock()
phylink_detach_mux(pl) phy_mux_select(...)
phy_mux_detach(pl->mux)
phy_mux_stop(mux)
cancel_work(&mux->state_work)
kfree(pl)
mux->pops->select(..., pl)
<-- use-after-free of pl
Drivers such as ucc_geth (ucc_geth_remove()) or lan743x (error path in
lan743x_netdev_open()) can reach phylink_destroy() with pl->mux still
attached. Independently, phy_mux_unregister() can also run
phylink_detach_mux(pl) concurrently under rtnl_lock(), risking double
phy_detach() / device_link_del() or use-after-free. Wrapping
phylink_detach_mux(pl) in rtnl_lock() / rtnl_unlock() inside
phylink_destroy() would serialize both paths before kfree(pl).
[ ... ]
> @@ -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);
> }
[Severity: Medium]
Can phylink_resolve() bring the link up prematurely here before the mux
selects the SFP port?
Earlier in phylink_start(), phylink_enable_and_run_resolve(pl,
PHYLINK_DISABLE_STOPPED) clears PHYLINK_DISABLE_STOPPED and schedules
pl->resolve. Because phylink_sfp_link_down() returns early without
setting PHYLINK_DISABLE_LINK while !pl->sfp_selected,
pl->phylink_disable_state becomes 0.
When an SFP module is already inserted with pl->sfp_link_down true,
phy_mux_port_set_available() runs while mux->state is still
PHY_MUX_STOPPED, so phy_mux_start() defers port selection to
phy_mux_state_machine(). That worker must wait for rtnl_lock(),
whereas phylink_resolve() does not:
CPU0 (under rtnl_lock) CPU1 (kworker)
phylink_start()
phylink_enable_and_run_resolve(
pl, PHYLINK_DISABLE_STOPPED)
phy_mux_port_set_available(...)
phy_mux_start(pl->mux)
phy_mux_trigger(mux)
phylink_resolve()
phylink_disable_state == 0
<-- premature link-up
rtnl_unlock()
phy_mux_state_machine()
rtnl_lock()
phylink_mux_select(SFP)
set PHYLINK_DISABLE_LINK
This allows a spurious carrier-up and flap before SFP startup and LOS
checks complete.
[ ... ]
> @@ -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;
> }
[Severity: Medium]
Does this leave pl->sfp_mod_present and pl->mux_sfp_port->available
stuck true when a may_have_phy module fails deferred setup?
For copper or other may_have_phy modules, validation is deferred to
phylink_sfp_connect_phy() or phylink_sfp_module_start(). Neither
function calls phylink_sfp_set_present(pl, false) on failure (for
example when !phy->drv or phylink_sfp_config_optical() fails), and
sfp_sm_main() transitions straight to SFP_S_FAIL without calling
sfp_module_remove(). That leaves the mux stuck on the rejected SFP
port until the module is physically removed.
Also, calling phylink_sfp_set_present(pl, true) before
phylink_sfp_config_optical() synchronously switches the mux and stops
an active PHY port before discovering that an optical module is
unsupported, causing an unnecessary link bounce when it rolls back.
[ ... ]
> @@ -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);
> }
[Severity: Medium]
Is there a data race on pl->mux_sfp_port between phylink_mux_attach()
and the SFP callbacks?
phylink_create() registers the SFP upstream before
phylink_of_phy_connect() attaches the mux, and probe-time callers such
as dsa_user_create() and ocelot_port_phylink_create() call
phylink_of_phy_connect() without holding rtnl_lock(). In that window,
phylink_mux_attach() writes pl->mux_sfp_port under phy_mux_mutex while
phylink_sfp_set_present() and phylink_sfp_detach() read it under
rtnl_lock():
CPU0 (probe, phy_mux_mutex) CPU1 (SFP work, rtnl_lock)
phylink_of_phy_connect()
phylink_attach_mux()
phylink_mux_attach()
pl->mux_sfp_port = ... phylink_sfp_module_insert()
phylink_sfp_set_present()
if (pl->mux_sfp_port)
<-- data race
> @@ -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;
[Severity: Medium]
Can pl->sfp_link_down stay stale false after phylink_stop(),
phylink_sfp_module_remove(), or phylink_sfp_detach(), bypassing SFP
LOS link gating?
Once an SFP link comes up, phylink_sfp_link_up() clears
pl->sfp_link_down. When phylink_stop() calls sfp_upstream_stop(),
sfp_sm_device() changes sm_dev_state to SFP_DEV_DOWN before
sfp_sm_main() runs, so sfp_sm_main() skips sfp_sm_link_down() (which
is gated on sm_dev_state == SFP_DEV_UP) while resetting sm_state to
SFP_S_DOWN. Neither phylink_stop(), phylink_sfp_module_remove(), nor
phylink_sfp_detach() resets pl->sfp_link_down = true.
If the interface is later reopened with RX_LOS asserted or a new
module inserted, phylink_mux_select() sees stale pl->sfp_link_down ==
false and clears PHYLINK_DISABLE_LINK. Because
sfp_sm_link_check_los() moves straight to SFP_S_WAIT_LOS without
calling sfp_sm_link_down(), PHYLINK_DISABLE_LINK remains cleared and
carrier can come up while LOS is asserted.
> @@ -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);
[Severity: Medium]
Should PHYLINK_DISABLE_LINK be cleared after
phylink_mac_initial_config() rather than before it?
Once PHYLINK_DISABLE_LINK is cleared here, any MAC, PCS, or PHY
interrupt can schedule phylink_resolve() on another CPU without
rtnl_lock(). Because pl->link_config.interface and
pl->req_link_an_mode are updated without pl->state_mutex,
phylink_resolve() can race with those writes and poll the PCS under
stale SFP act_link_an_mode and interface settings before
phylink_mac_initial_config() reconfigures the MAC/PCS. Updating the
config under pl->state_mutex and clearing PHYLINK_DISABLE_LINK after
phylink_mac_initial_config(pl, false) would close this window.
> @@ -4304,7 +4385,10 @@ static void phylink_mux_deselect(struct phy_mux *mux,
> 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;
[Severity: Medium]
Should phylink_mux_deselect() bring the link down when deselecting
PHY_MUX_PORT_SFP?
Unbinding the phy_mux driver while the SFP link is up calls
phy_mux_unregister() -> phylink_mux_detach() -> phy_mux_stop() ->
phylink_mux_deselect() without stopping the netdev. Because
phylink_mux_deselect() only clears pl->sfp_selected without calling
phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_LINK), the link
stays up and later phylink_sfp_link_down() calls return early while
pl->sfp_behind_mux && !pl->sfp_selected, leaving carrier stuck up.
Unbinding the sfp driver while an optical link is up similarly leaves
the link up across the mux switch, so phylink_mux_select() calls
phylink_mac_initial_config() without mac_link_down() first. Also, if
a copper SFP PHY is still attached when deselected, pl->phydev remains
populated and selecting a PHY port fails with -EBUSY.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=10
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver
2026-12-04 11:06 ` [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver Maxime Chevallier
@ 2026-12-05 11:08 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-05 11:08 UTC (permalink / raw)
To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net: phy: mux: unsynchronized mii_mux_auto_remove() vs
phy_mux_detach()
- [Medium] net: phy: unsynchronized pl->mux access and detach vs
phy_mux_unregister()
--
commit 3ddf01a7f8c108024edc40420dc253bccef488c1
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
net: phy: mux: Add the mii-mux-auto driver
This commit adds the mii-mux-auto platform driver for hardware-switched
two-port MII multiplexers, validating the port fwnodes, registering the mux
with the phy_mux core, and unregistering and freeing it on removal.
> diff --git a/drivers/net/phy/mux/mii_mux_auto.c b/drivers/net/phy/mux/mii_mux_auto.c
> new file mode 100644
> index 0000000000000..980cc2c242ba7
> --- /dev/null
> +++ b/drivers/net/phy/mux/mii_mux_auto.c
> @@ -0,0 +1,99 @@
[ ... ]
> +static void mii_mux_auto_remove(struct platform_device *pdev)
> +{
> + struct phy_mux *mux = platform_get_drvdata(pdev);
> +
> + phy_mux_unregister(mux);
> + phy_mux_free(mux);
> +}
[Severity: Medium]
Can mii_mux_auto_remove() race with an unlocked phy_mux_detach() and cause a
use-after-free on struct phy_mux or struct phylink?
phy_mux_attach() adds a DL_FLAG_STATELESS device link, which does not force
consumers to unbind when mii-mux-auto is removed. phy_mux_unregister() only
holds rtnl_lock() around mux->pops->detach(), and phy_mux_free() immediately
destroys the ports and frees mux.
phy_mux_detach() takes neither rtnl_lock() nor phy_mux_mutex.
phylink_destroy() calls phylink_detach_mux() -> phy_mux_detach() unlocked
before freeing pl, which is reachable with pl->mux set if mvpp2_open() fails
in request_irq() and mvpp2_port_remove() later runs:
CPU0 CPU1
mii_mux_auto_remove() mvpp2_port_remove()
phy_mux_unregister(mux) phylink_destroy(pl)
rtnl_lock() phylink_detach_mux(pl)
mux->pops->detach(mux, pl) phy_mux_detach(mux)
phy_mux_stop(mux)
rtnl_unlock()
phy_mux_free(mux)
phy_mux_port_destroy(port)
kfree(mux)
phy_mux_detach_phys(mux)
<-- use-after-free
In the reverse ordering, phylink_destroy() can free pl while
phy_mux_unregister() calls mux->pops->detach(mux, pl), or both paths can
double-detach the PHYs and devlink. Using a managed device link or
serializing teardown with phy_mux_mutex would prevent this.
[Severity: Medium]
Can mii_mux_auto_remove() also race with the unlocked pl->mux check in
phylink_fwnode_phy_connect()?
Callers such as ocelot_port_phylink_create() and dsa_user_phy_setup() invoke
phylink_of_phy_connect() -> phylink_fwnode_phy_connect() without holding
rtnl_lock(). phylink_attach_mux() sets pl->mux under phy_mux_mutex and then
drops it before phylink_fwnode_phy_connect() checks if (pl->mux):
CPU0 CPU1
phylink_fwnode_phy_connect() mii_mux_auto_remove()
phylink_attach_mux() phy_mux_unregister(mux)
mutex_lock(&phy_mux_mutex)
pl->mux = mux
mutex_unlock(&phy_mux_mutex)
mutex_lock(&phy_mux_mutex)
list_del(&mux->node)
mutex_unlock(&phy_mux_mutex)
rtnl_lock()
phylink_mux_detach()
pl->mux = NULL
rtnl_unlock()
if (pl->mux) <-- reads NULL
fwnode_get_phy_node(fwnode)
Because pl->mux is read as NULL, phylink_fwnode_phy_connect() falls through
to fwnode_get_phy_node() and can fail probe with -ENODEV, return 0 without
an attached mux or PHY, or attach a fallback phy-handle while
pl->sfp_behind_mux remains set.
Separately, phylink_destroy() calls phylink_detach_mux() unlocked before
kfree(pl), which can race with mii_mux_auto_remove() -> phy_mux_unregister()
and phy_mux_free() to cause a use-after-free on mux or pl.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=11
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next 12/12] ARM: dts: turris-omnia: Describe the WAN port multiplexer
2026-12-04 11:06 ` [PATCH net-next 12/12] ARM: dts: turris-omnia: Describe the WAN port multiplexer Maxime Chevallier
@ 2026-12-05 11:08 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-05 11:08 UTC (permalink / raw)
To: Maxime Chevallier; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] ARM: dts: turris-omnia: removing eth2 sfp breaks WAN SFP when
PHY_MUX=n
- [Medium] ARM: dts: turris-omnia: mii-mux-handle fails mvneta_open() if
mux absent
- [Medium] ARM: dts: turris-omnia: wan_mux breaks mvneta_mdio_probe()
WoL and speed_up
--
commit 6cfa2117998086601c4b50faf6694fb1b3114fac
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
ARM: dts: turris-omnia: Describe the WAN port multiplexer
This commit describes the Turris Omnia WAN port MII multiplexer in
devicetree, enabling the SFP node unconditionally and wiring eth2 to
the mux instead of referencing the SFP node directly.
> diff --git a/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts b/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts
> index 83fe00abd6523..0501686e26427 100644
> --- a/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts
> +++ b/arch/arm/boot/dts/marvell/armada-385-turris-omnia.dts
> @@ -103,13 +103,24 @@ sfp: sfp {
[ ... ]
> + wan_mux: mii-mux {
> + compatible = "mii-mux-auto";
[Severity: Medium]
Can adding this mii-mux-auto node break eth2 bring-up when
CONFIG_MII_MUX_AUTO is disabled or built as a module?
With CONFIG_PHY_MUX=y, mvneta_open() -> phylink_of_phy_connect() ->
phylink_attach_mux() calls fwnode_phy_mux_attach(). If mii_mux_auto is
not built or not yet probed (such as during IP_PNP DHCP with
CONFIG_MII_MUX_AUTO=m), fwnode_phy_mux_attach() returns -EPROBE_DEFER.
phylink_attach_mux() turns -EPROBE_DEFER into -ENODEV without falling
back to phy-handle, and drivers/of/property.c has no
of_supplier_bindings[] entry for mii-mux-handle to order probing via
fw_devlink. As a result, mvneta_open() fails even on copper RJ45.
[ ... ]
> @@ -199,16 +210,12 @@ ð2 {
[ ... ]
> status = "okay";
> phy-mode = "sgmii";
> phy-handle = <&phy1>;
> + mii-mux-handle = <&wan_mux>;
[Severity: Medium]
Does attaching eth2 through wan_mux break Wake-on-LAN and
phylink_speed_up() in mvneta?
With mii-mux-handle, pl->phydev stays NULL after phylink_of_phy_connect()
until phy_mux_state_machine() asynchronously selects port@1 after
phylink_start(). mvneta_mdio_probe() calls phylink_ethtool_get_wol()
before phylink_start(), so wol.supported is 0 and can_wakeup is cleared.
Because mvneta never re-enables can_wakeup after port selection,
mvneta_ethtool_set_wol() -> device_set_wakeup_enable() silently fails
with -EINVAL. This leaves device_may_wakeup() permanently false and
prevents mvneta_stop_dev() from calling phylink_speed_down().
In addition, mvneta_start_dev() calls phylink_speed_up() right after
phylink_start(), before mux->state_work populates pl->phydev, turning
phylink_speed_up() into a no-op.
> phys = <&comphy5 2>;
> - sfp = <&sfp>;
[Severity: High]
Does removing sfp = <&sfp> from eth2 regress Turris Omnia WAN SFP
networking when CONFIG_PHY_MUX=n or when an older kernel boots this DTB?
Neither CONFIG_PHY_MUX nor CONFIG_MII_MUX_AUTO defaults to y or is
enabled in mvebu_v7_defconfig or multi_v7_defconfig. When
CONFIG_PHY_MUX=n, phylink_register_mux_sfp() gets NULL from the stub
fwnode_phy_mux_find_sfp_port() and falls back to phylink_register_sfp().
With sfp = <&sfp> deleted from eth2, pl->sfp_bus stays NULL while the
enabled sfp node probes unattached with TX_DISABLE asserted, breaking
WAN SFP networking even with U-Boot's boot-time FDT fixup.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=12
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2026-12-05 11:08 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-05 11:08 ` sashiko-bot
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-05 11:08 ` sashiko-bot
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-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
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 ` [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 10/12] net: phylink: Support an SFP cage behind " Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-04 11:06 ` [PATCH net-next 12/12] ARM: dts: turris-omnia: Describe the WAN port multiplexer Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox