From: "Jakub Vaněk" <linuxtardis@gmail.com>
To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: "Andrew Lunn" <andrew@lunn.ch>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Russell King" <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
Frank <Frank.Sae@motor-comm.com>,
"Sai Krishna" <saikrishnag@marvell.com>,
"Daniel Golle" <daniel@makrotopia.org>,
"Jakub Vaněk" <linuxtardis@gmail.com>
Subject: [PATCH net-next v2 1/5] net: mdiobus: Scan buses in reverse order (31 -> 0)
Date: Sun, 1 Mar 2026 00:22:37 +0100 [thread overview]
Message-ID: <20260228232241.1274236-2-linuxtardis@gmail.com> (raw)
In-Reply-To: <20260228232241.1274236-1-linuxtardis@gmail.com>
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 <linuxtardis@gmail.com>
---
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
next prev parent reply other threads:[~2026-02-28 23:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-28 23:22 [PATCH net-next v2 0/5] net: phy: Disable MDIO broadcast address on YT8821 Jakub Vaněk
2026-02-28 23:22 ` Jakub Vaněk [this message]
2026-03-01 15:11 ` [PATCH net-next v2 1/5] net: mdiobus: Scan buses in reverse order (31 -> 0) Andrew Lunn
2026-03-01 17:03 ` Russell King (Oracle)
2026-03-01 17:24 ` Jakub Vaněk
2026-02-28 23:22 ` [PATCH net-next v2 2/5] of: mdio: Scan PHY address 0 last Jakub Vaněk
2026-02-28 23:22 ` [PATCH net-next v2 3/5] net: phy: Support PHY fixups on Clause 45 PHYs Jakub Vaněk
2026-02-28 23:22 ` [PATCH net-next v2 4/5] net: phy: Add infrastructure for PHY address 0 fixups Jakub Vaněk
2026-02-28 23:22 ` [PATCH net-next v2 5/5] net: phy: motorcomm: yt8821: Disable MDIO broadcast Jakub Vaněk
2026-03-01 2:43 ` kernel test robot
2026-03-01 16:06 ` [PATCH net-next v2 0/5] net: phy: Disable MDIO broadcast address on YT8821 Andrew Lunn
2026-03-01 17:07 ` Russell King (Oracle)
2026-03-01 17:15 ` Jakub Vaněk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260228232241.1274236-2-linuxtardis@gmail.com \
--to=linuxtardis@gmail.com \
--cc=Frank.Sae@motor-comm.com \
--cc=andrew@lunn.ch \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saikrishnag@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox