Thread (13 messages) 13 messages, 4 authors, 2026-03-01
STALE105d

[PATCH net-next v2 1/5] net: mdiobus: Scan buses in reverse order (31 -> 0)

From: Jakub Vaněk <hidden>
Date: 2026-02-28 23:23:05
Also in: lkml
Subsystem: ethernet phy library, networking drivers, the rest · Maintainers: Andrew Lunn, Heiner Kallweit, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

Some PHY devices incorrectly treat address 0 as a broadcast address.
As a result, accesses to address 0 may cause multiple PHYs to respond,
making one or both PHYs work unreliably. In other cases, the PHY may be
detected twice by Linux: once at address 0 and once at its actual
address).

On several PHYs (e.g. Motorcomm YT8821 and Realtek RTL8221B), this
behavior can be disabled via a vendor-specific internal register.
However, for that to be useful, that register would have to be
programmed before address 0 is accessed for the first time.

On non-Device Tree systems, MDIO buses are typically scanned in
mdiobus_register(). Change the address scan order from 0->31 to 31->0
so that PHY fixups are applied to addresses 1-31 before address 0
is probed. This way the address collision can be avoided.

The change is implemented separately for Clause 22 and Clause 45 PHYs.
This approach might still leave some collisions at address 0 unhandled,
but it is much easier to implement.

Device Tree-based systems also require a different approach. In that case,
of_mdiobus_register() probes only the addresses explicitly described
in the Device Tree. Handling for DT-based systems is implemented in
a separate commit.

Suggested-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Jakub Vaněk <redacted>
---
 drivers/net/phy/mdio_bus_provider.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/mdio_bus_provider.c b/drivers/net/phy/mdio_bus_provider.c
index 4b0637405740..d3454d229795 100644
--- a/drivers/net/phy/mdio_bus_provider.c
+++ b/drivers/net/phy/mdio_bus_provider.c
@@ -208,7 +208,12 @@ static int mdiobus_scan_bus_c22(struct mii_bus *bus)
 {
 	int i;
 
-	for (i = 0; i < PHY_MAX_ADDR; i++) {
+	/* Scan address 0 last. Some vendors consider it a broadcast address
+	 * and so their PHYs respond at it in addition to the actual PHY address.
+	 * Scanning addresses 1-31 first allows PHY fixups to reconfigure these
+	 * PHYs to not respond at address 0 before we try to scan it.
+	 */
+	for (i = PHY_MAX_ADDR - 1; i >= 0; i--) {
 		if ((bus->phy_mask & BIT(i)) == 0) {
 			struct phy_device *phydev;
 
@@ -224,7 +229,12 @@ static int mdiobus_scan_bus_c45(struct mii_bus *bus)
 {
 	int i;
 
-	for (i = 0; i < PHY_MAX_ADDR; i++) {
+	/* Scan address 0 last. Some vendors consider it a broadcast address
+	 * and so their PHYs respond at it in addition to the actual PHY address.
+	 * Scanning addresses 1-31 first allows PHY fixups to reconfigure these
+	 * PHYs to not respond at address 0 before we try to scan it.
+	 */
+	for (i = PHY_MAX_ADDR - 1; i >= 0; i--) {
 		if ((bus->phy_mask & BIT(i)) == 0) {
 			struct phy_device *phydev;
 
-- 
2.43.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help