Skip to contentSkip to conversation

net: mdio: handle broken-turn-around for non-PHY MDIO devices

PATCH Superseded Bastian Germann 3 participants 7 messages Nov 19 – Nov 23

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 when registering a non-PHY MDIO device and set the corresponding bit in phy_ignore_ta_mask before registering the device.

---
 drivers/net/mdio/of_mdio.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/mdio/of_mdio.c +3 -0
index b8d298c04d3f..0695ae83b83b 100644
@@ -56,6 +56,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);
maintainer
#1 lore raw
Quoted 9 lines · Bastian Germann

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 when registering a non-PHY MDIO device and set the corresponding bit in phy_ignore_ta_mask before registering the device.

What switch is causing you problems?

I do wounder if the call in fwnode_mdiobus_phy_device_register() should be hoisted up into of_mdiobus_register_device, were it would be common for both PHYs and MDIO devices.

Andrew

#2 lore raw
Quoted 11 lines · Andrew Lunn
Quoted 9 lines · Bastian Germann

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 when registering a non-PHY MDIO device and set the corresponding bit in phy_ignore_ta_mask before registering the device.

What switch is causing you problems?

It is with mv88e6085.

I have just found that Nathan Rossi sent basically the same patch as <[email protected]>.

Quoted 5 lines

I do wounder if the call in fwnode_mdiobus_phy_device_register() should be hoisted up into of_mdiobus_register_device, were it would be common for both PHYs and MDIO devices.

Andrew

maintainer
#3 lore raw
Quoted 9 lines · Bastian Germann
Quoted 8 lines · Andrew Lunn
Quoted 7 lines · Bastian Germann

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.

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Parse the property when registering a non-PHY MDIO device and set the corresponding bit in phy_ignore_ta_mask before registering the device.

What switch is causing you problems?

It is with mv88e6085.

I have just found that Nathan Rossi sent basically the same patch as <[email protected]>.

[Goes and find the thread]

Are you bit banging as well? Or do you have another MDIO bus controller?

The point about the mv88e6085 using multiple addresses is valid. How do you have the mv88e6085 configured?

Andrew

#4 lore raw
Quoted 17 lines · Andrew Lunn
Quoted 9 lines · Bastian Germann
Quoted 8 lines · Andrew Lunn
Quoted 7 lines · Bastian Germann

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.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Parse the property when registering a non-PHY MDIO device and set the corresponding bit in phy_ignore_ta_mask before registering the device.

What switch is causing you problems?

It is with mv88e6085.

I have just found that Nathan Rossi sent basically the same patch as <[email protected]>.

Quoted 7 lines

[Goes and find the thread]

Are you bit banging as well? Or do you have another MDIO bus controller?

The point about the mv88e6085 using multiple addresses is valid. How do you have the mv88e6085 configured?

It is with the TI CPSW3G MDIO controller (ti,davinci_mdio, ti,cpsw-mdio). As this is on a AM64x, errata i2329 applies and davinci_mdio runs with bitbanging.

The mv88e6085 (88E6341) is configured in multi-chip/indirect mode at  reg = <1>. It does not use multiple addresses.

maintainer
#5 lore raw
Quoted 7 lines

It is with the TI CPSW3G MDIO controller (ti,davinci_mdio, ti,cpsw-mdio). As this is on a AM64x, errata i2329 applies and davinci_mdio runs with bitbanging.

The mv88e6085 (88E6341) is configured in multi-chip/indirect mode at  reg = <1>.
It does not use multiple addresses.

O.K, that is good.

So the concept is sounds, it is just a question of if the parsing of the property should be done once at a higher level, since it is supposed to be a common property.

Andrew

#6 lore raw
In reply to Bastian Germann
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 (1) · Low: 1

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] The fix marks only BIT(addr), where addr is the device-tree reg of the non-PHY MDIO device.
- [Low] The kernel-doc for struct mii_bus::phy_ignore_ta_mask (include/linux/phy.h:427) reads 'PHY addresses to ignore the TA/read…

Pre-existing issues:
- [Medium] This patch does not introduce the problem, but the PHY path that the commit message cites as the place where the property already…

--

net: mdio: handle broken-turn-around for non-PHY MDIO devices

This commit parses the "broken-turn-around" property in of_mdiobus_register_device(), so that non-PHY MDIO devices such as DSA switches have their address set in phy_ignore_ta_mask. Before this, only PHY devices registered through fwnode_mdiobus_phy_device_register() honoured the property.

drivers/net/mdio/of_mdio.c static int of_mdiobus_register_device(struct mii_bus *mdio, · line 60

Quoted 10 lines
drivers/net/mdio/of_mdio.c +2 -0
index b8d298c04d3ff..0695ae83b83be 100644
@@ -56,6 +56,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: Medium]
Does setting only BIT(addr) cover the addresses these switches actually use on the bus?

Bus drivers check phy_ignore_ta_mask against the address of each transfer, not against the registered device. For example, in unimac_mdio_read():

	if (!(bus->phy_ignore_ta_mask & 1 << phy_id) && (cmd & MDIO_READ_FAIL)) {
		ret = -EIO;
		goto out;
	}

The comment above that check names the Broadcom BCM53125 as the broken device. b53_mdio_probe() accepts a reg of either 0 or 30:

	if (mdiodev->addr != BRCM_PSEUDO_PHY_ADDR && mdiodev->addr != 0) {

But b53_mdio_op() sends all switch register traffic to BRCM_PSEUDO_PHY_ADDR (30), whatever reg is:

	for (i = 0; i < 5; ++i) {
		v = mdiobus_read_nested(bus, BRCM_PSEUDO_PHY_ADDR,
					REG_MII_ADDR);
		if (!(v & (REG_MII_ADDR_WRITE | REG_MII_ADDR_READ)))
			break;
		usleep_range(10, 100);
	}

	if (WARN_ON(i == 5))
		return -EIO;

There is an in-tree BCM53125 node with reg = <0> in bcm47094-linksys-panamera.dts. If broken-turn-around were added to a node like that, only bit 0 would be set.

Wouldn't every read at address 30 still return -EIO from unimac_mdio_read()? Once that is truncated into the u16 v, the busy bits look set. b53_mdio_op() would then hit WARN_ON(i == 5), and the switch could not be programmed.

b53_mdio_phy_read16() also reads the internal PHYs at their own addresses on the same bus. The mask does not cover those addresses either.

mv88e6xxx in single-chip mode (reg = <0>, sw_addr == 0) looks similar. There, mv88e6xxx_smi_direct_read() calls:

	ret = mdiobus_read_nested(chip->bus, dev, reg);

for many different dev addresses, so no single reg value would cover the chip.

How much of this matters depends on which of the chip's addresses really have the broken turn-around. Should the commit message say that this change only helps when reg is the only address the device uses? Or should devices like these get a wider set of addresses?

[Severity: Medium]
This is a pre-existing issue, not one introduced by this patch. The commit message cites the PHY path as already handling the property, but that path seems to apply it too late.

In fwnode_mdiobus_register_phy(), a PHY without an explicit ethernet-phy-idXXXX.XXXX compatible goes through:

	if (is_c45 || fwnode_get_phy_id(child, &phy_id))
		phy = get_phy_device(bus, addr, is_c45);

get_phy_device() reads the PHY ID registers over MDIO. The mask is only set later, in fwnode_mdiobus_phy_device_register():

	if (fwnode_property_read_bool(child, "broken-turn-around"))
		mdio->phy_ignore_ta_mask |= 1 << addr;

During that ID read, mdiobb_read_common() would return 0xffff and unimac_mdio_read() would return -EIO. Wouldn't get_phy_device() then fail with -ENODEV before the property takes effect?

The new non-PHY path sets the bit before mdio_device_create(). So after this patch, the PHY and non-PHY paths set the bit in a different order.

[Severity: Low]
This isn't a bug, but the kernel-doc for struct mii_bus in include/linux/phy.h still says:

	/** @phy_ignore_ta_mask: PHY addresses to ignore the TA/read failure */

The comment in mdiobb_read_common() also mentions "this PHY is listed in phy_ignore_ta_mask". After this patch the mask is set for non-PHY MDIO devices too.

"PHY address" is the usual name for the Clause 22 PHYAD field, and phy_mask uses the same wording, so the text is not wrong. Would it still be worth rewording it to say MDIO device addresses?

Quoted 3 lines
drivers/net/mdio/of_mdio.c +0 -0
 	mdiodev = mdio_device_create(mdio, addr);
 	if (IS_ERR(mdiodev))

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119231319.1256419-1-bage%40debian.org