net: mdio: handle broken-turn-around for non-PHY MDIO devices
Subsystems (3)
PATCH v2 1/1 net: mdio: handle broken-turn-around for non-PHY MDIO devices
The "broken-turn-around" property is documented in mdio.yaml for any MDIO device, but the MDIO core currently parses it only for PHY devices in fwnode_mdiobus_phy_device_register(). Non-PHY devices, such as DSA switches, are registered through of_mdiobus_register_device(), where the property is ignored, so MDIO bus drivers that rely on phy_ignore_ta_mask still treat the turn-around/read failure as an error.
Parse the property in of_mdiobus_register_phy() and of_mdiobus_register_device() instead, so it is handled in one place for both PHYs and other MDIO devices, and drop it from fwnode_mdiobus_phy_device_register().
--- drivers/net/mdio/fwnode_mdio.c | 3 --- drivers/net/mdio/of_mdio.c | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/mdio/fwnode_mdio.c +0 -3
@@ -89,9 +89,6 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, phy->irq = mdio->irq[addr]; } -if (fwnode_property_read_bool (child,"broken-turn-around" )) - mdio->phy_ignore_ta_mask |=1 << addr; -/* Associate the fwnode with the device structure so it * can be looked up later */
drivers/net/mdio/of_mdio.c +6 -0
@@ -46,6 +46,9 @@ EXPORT_SYMBOL(of_mdiobus_phy_device_register);static int of_mdiobus_register_phy (struct mii_bus *mdio,struct device_node *child,u32 addr) { +if (of_property_read_bool (child,"broken-turn-around" )) + mdio->phy_ignore_ta_mask |=BIT (addr); +return fwnode_mdiobus_register_phy (mdio,of_fwnode_handle (child), addr); }
@@ -56,6 +59,9 @@ static int of_mdiobus_register_device(struct mii_bus *mdio,struct mdio_device *mdiodev;int rc; +if (fwnode_property_read_bool (fwnode,"broken-turn-around" )) + mdio->phy_ignore_ta_mask |=BIT (addr); + mdiodev =mdio_device_create (mdio, addr);if (IS_ERR (mdiodev))return PTR_ERR (mdiodev);
Andrew Lunn
maintainerQuoted 4 lines
Parse the property in
of_mdiobus_register_phy()andof_mdiobus_register_device()instead, so it is handled in one place for both PHYs and other MDIO devices, and drop it fromfwnode_mdiobus_phy_device_register().
This seems odd. "handled in one place", yet you do it in two?
Is there a reason not to do it in __of_mdiobus_parse_phys() ?
Andrew
Hi Andrew,
Quoted 7 lines · Andrew Lunn
Quoted 4 lines
Parse the property in
of_mdiobus_register_phy()andof_mdiobus_register_device()instead, so it is handled in one place for both PHYs and other MDIO devices, and drop it fromfwnode_mdiobus_phy_device_register().This seems odd. "handled in one place", yet you do it in two?
Is there a reason not to do it in
__of_mdiobus_parse_phys()?
Yes. My v2 draft was exactly that (which is the reason for the commit message oddity) but I noticed that children with empty reg that are handled in the auto-scan loop would then not get the bit mask set, which is an unnecessary behavior change for PHYs. I will send a v3 with your proposal. I am happy with either of them.
Thanks,
Bastian
Andrew Lunn
maintainerQuoted 7 lines · Bastian Germann
Hi Andrew,
Quoted 4 lines · Andrew Lunn
Quoted 4 lines
Parse the property in
of_mdiobus_register_phy()andof_mdiobus_register_device()instead, so it is handled in one place for both PHYs and other MDIO devices, and drop it fromfwnode_mdiobus_phy_device_register().
Quoted 8 lines
Quoted 3 lines
This seems odd. "handled in one place", yet you do it in two?
Is there a reason not to do it in
__of_mdiobus_parse_phys()?Yes. My v2 draft was exactly that (which is the reason for the commit message oddity) but I noticed that children with empty reg that are handled in the auto-scan loop would then not get the bit mask set, which is an unnecessary behavior change for PHYs.
Ah, O.K. I never liked that scan code filling in missing devices. It has a warning not to do that. So i don't know if it is actually used.
Also, i could not find any in kernel dt blobs using broken-turn-around. So we are not going to break anything.
Andrew
---
pw-bot: cr
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Regression in an exported API: PHYs registered through of_mdiobus_phy_device_register() no longer honour "broken-turn-around".
- [Medium] of_mdiobus_register_phy() now sets BIT(addr) in mdio->phy_ignore_ta_mask unconditionally, before…
- [Medium] The fix only partly covers DSA switches, which the commit message names as the motivating case.
- [Low] The commit message frames the change as a bug fix: mdio.yaml documents broken-turn-around for any '@[0-9a-f]+$' MDIO child, but…
- [Low] net: mdio: duplicated broken-turn-around parsing in of_mdio.c
--
net: mdio: handle broken-turn-around for non-PHY MDIO devices
The commit moves parsing of the "broken-turn-around" DT property out of fwnode_mdiobus_phy_device_register() and into the static helpers of_mdiobus_register_phy() and of_mdiobus_register_device(). The aim is to also honour the property for non-PHY MDIO devices such as DSA switches.
Quoted 4 lines
Non-PHY devices, such as DSA
switches, are registered throughof_mdiobus_register_device(), where the property is ignored, so MDIO bus drivers that rely onphy_ignore_ta_maskstill treat the turn-around/read failure as an error.
[Severity: Low]
This describes broken behaviour that users can see, but there is no Fixes:
tag and nothing says whether this is meant for net or net-next.
Should a Fixes: tag be added for the commit that introduced non-PHY registration through of_mdiobus_register_device() (or the binding change)? If not, should the commit message say this is new functionality for net-next?
drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, · line 94
Quoted 11 lines
drivers/net/mdio/fwnode_mdio.c +0
-3@@ -89,9 +89,6 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, phy->irq = mdio->irq[addr]; } -if (fwnode_property_read_bool (child,"broken-turn-around" )) - mdio->phy_ignore_ta_mask |=1 << addr; -
[Severity: Medium]
With the parse removed here, what happens to PHYs registered through the exported of_mdiobus_phy_device_register()?
drivers/net/mdio/of_mdio.c:of_mdiobus_phy_device_register() {
return fwnode_mdiobus_phy_device_register(mdio, phy,
of_fwnode_handle(child),
addr);
}This wrapper never goes through of_mdiobus_register_phy(), so it never reaches the new parse.
Its in-tree caller, tja1102_p1_register() in drivers/net/phy/nxp-tja11xx.c, registers the port 1 PHY from a DT child node:
ret = of_mdiobus_phy_device_register(bus, phy, child, addr);
and does not set phy_ignore_ta_mask itself.
ethernet-phy.yaml documents broken-turn-around for every PHY node. Would the property on a port 1 node now be ignored without any warning? On a bus that checks the mask (mdio-bcm-unimac, mdio-pic64hpsc, mdio-bitbang), reads from that PHY would then return -EIO or 0xffff.
This also means the two exported OF PHY registration paths now disagree on whether the property is honoured.
Quoted 8 lines
drivers/net/mdio/fwnode_mdio.c +0
-0/* Associate the fwnode with the device structure so it * can be looked up later */ drivers/net/mdio/of_mdio.c +0
-0
drivers/net/mdio/of_mdio.c EXPORT_SYMBOL(of_mdiobus_phy_device_register); · line 53
Quoted 8 lines
drivers/net/mdio/of_mdio.c +3
-0@@ -46,6 +46,9 @@ EXPORT_SYMBOL(of_mdiobus_phy_device_register);static int of_mdiobus_register_phy (struct mii_bus *mdio,struct device_node *child,u32 addr) { +if (of_property_read_bool (child,"broken-turn-around" )) + mdio->phy_ignore_ta_mask |=BIT (addr); +return fwnode_mdiobus_register_phy (mdio,of_fwnode_handle (child), addr); }
[Severity: Medium]
The bit is now set before fwnode_mdiobus_register_phy()->get_phy_device() checks whether anything answers at addr. Is it intended that nothing clears it when registration fails?
For PHY nodes without a reg property, the auto-scan loop in __of_mdiobus_register() calls this helper for every unregistered address and expects -ENODEV for most of them:
if (of_mdiobus_child_is_phy(child)) {
...
rc = of_mdiobus_register_phy(mdio, child, addr);
if (!rc)
break;
if (rc != -ENODEV)
goto put_unregister;
}If such a node has broken-turn-around, every empty address scanned before the real PHY keeps the ignore-TA bit for good. If no PHY is found, every unregistered address keeps it.
Before this patch, the bit was set in fwnode_mdiobus_phy_device_register(). That only runs after get_phy_device() or phy_device_create() has succeeded.
With those stale bits, unimac_mdio_read() returns the latched data instead of -EIO:
if (!(bus->phy_ignore_ta_mask & 1 << phy_id) && (cmd & MDIO_READ_FAIL)) {
ret = -EIO;pic64hpsc_mdio_c22_read() behaves the same way. get_phy_c22_id() used to map -EIO to -ENODEV and skip the address. Now any latched value that does not match the (*phy_id & 0x1fffffff) == 0x1fffffff check counts as a valid ID.
Could this register a phantom PHY at the lowest empty address? The loop breaks on the first success, so the real PHY would never be found.
It would also hide real read errors at those addresses from later users of the bus. That conflicts with the phy.h description of phy_ignore_ta_mask:
"PHY addresses to ignore the TA/read failure".
The same applies, more narrowly, to the reg-based paths. When of_mdiobus_register_phy() fails, the bit stays set. The same is true when of_mdiobus_register_device() fails, either on the IS_ERR() return after mdio_device_create() or on the mdio_device_free() error path. In both cases no device was registered.
drivers/net/mdio/of_mdio.c static int of_mdiobus_register_device(struct mii_bus *mdio, · line 64
Quoted 8 lines
drivers/net/mdio/of_mdio.c +3
-0@@ -56,6 +59,9 @@ static int of_mdiobus_register_device(struct mii_bus *mdio,struct mdio_device *mdiodev;int rc; +if (fwnode_property_read_bool (fwnode,"broken-turn-around" )) + mdio->phy_ignore_ta_mask |=BIT (addr); +
[Severity: Low]
The commit message says the property is now parsed "in one place for both PHYs and other MDIO devices". The patch actually adds two copies of the same check in of_mdio.c. One is in of_mdiobus_register_phy() and the other is in of_mdiobus_register_device().
The two copies also read the same DT node with different accessors. The PHY helper uses of_property_read_bool(child, ...). The device helper uses fwnode_property_read_bool(fwnode, ...). For an OF node they should give the same answer today. A reader cannot tell why the two paths differ, though, and the copies can drift apart later.
Could this be handled once in a shared place instead? One option is a small static helper in of_mdio.c that both functions call. Another is to handle it where the MDIO core already deals with per-device firmware properties, for example in mdiobus_register_device() once the fwnode is attached to mdiodev->dev. If the ordering works out, that would also cover callers of the exported of_mdiobus_phy_device_register(). It would also set the bit only after a device really exists at the address. Would that work for the cases you have in mind?
If you prefer to keep the two call sites, please reword the commit message so it no longer says the property is handled in one place.
[Severity: Medium]
The commit message gives DSA switches as the motivating case. Is the DT reg address alone enough to cover the bus addresses such a switch actually uses?
Broadcom b53 switches include the BCM53125, which mdio-bcm-unimac names as not releasing the line during turn-around. For these, b53_mdio_probe() accepts either address 0 or 30:
if (mdiodev->addr != BRCM_PSEUDO_PHY_ADDR && mdiodev->addr != 0) {However, all switch register traffic in b53_mdio_op() and the b53_mdio_read*/write* helpers goes to BRCM_PSEUDO_PHY_ADDR (30), whatever mdiodev->addr is. b53_mdio_probe() also reads the ID from address 0:
phy_id = mdiobus_read(mdiodev->bus, 0, 2) << 16;
bcm47094-linksys-panamera.dts describes a BCM53125 as switch@0. If that node had broken-turn-around, only BIT(0) would be set. Reads at address 30 would still fail the TA check (-EIO on unimac/pic64hpsc, 0xffff on bitbang), and b53 would store those values as register contents.
The reverse is also true. With reg = <30>, the ID read at address 0 during probe is not covered.
Does this leave the b53 case that the commit message describes still broken?
Quoted 3 lines
drivers/net/mdio/of_mdio.c +0
-0mdiodev =mdio_device_create (mdio, addr);if (IS_ERR (mdiodev))return PTR_ERR (mdiodev);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121092933.186731-1-bage%40debian.org
Andrew Lunn
maintainerQuoted 13 lines
[Severity: Medium]
With the parse removed here, what happens to PHYs registered through the exportedof_mdiobus_phy_device_register()?drivers/net/mdio/of_mdio.c:of_mdiobus_phy_device_register() { return fwnode_mdiobus_phy_device_register(mdio, phy, of_fwnode_handle(child), addr); }This wrapper never goes through
of_mdiobus_register_phy(), so it never reaches the new parse.
Quoted 6 lines
Its in-tree caller,
tja1102_p1_register()indrivers/net/phy/nxp-tja11xx.c, registers the port 1 PHY from a DT child node:ret = of_mdiobus_phy_device_register(bus, phy, child, addr);and does not set
phy_ignore_ta_maskitself.
It feels like we are putting in too much effort for a feature which has no in kernel users.
You solution is not 100% correct, it has some corner cases, but i'm happy with the basic architecture of doing it once at a higher level. If a new user comes along and lands in one of those corners, let leave it to them to fix.
Quoted 4 lines
[Severity: Medium]
The bit is now set before fwnode_mdiobus_register_phy()->get_phy_device() checks whether anything answers at addr. Is it intended that nothing clears it when registration fails?
If the device comes to life later, it still has broken turn around, so this is not a problem.
Andrew