Skip to contentSkip to conversation

net: sfp: probe RollBall bridge with one MDIO read before the PHY probe

PATCH In review Daniel Pawlik 3 participants 3 messages Dec 4 – Dec 5

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 net: sfp: probe RollBall bridge with one MDIO read before the PHY probe

Modules without a RollBall I2C-to-MDIO bridge time out on every RollBall command, but the quirks for such modules force MDIO_I2C_ROLLBALL. The PHY probe then retries 25 times at ~21 seconds per attempt, i.e. for over nine minutes, before the module links up without a PHY. Each attempt runs from sfp_timeout() with rtnl_lock held, so for the whole window every rtnl user on the system stalls in ~21 second chunks, including the state machines of other SFP cages: in one test, pulling a module from another cage was only processed after the current attempt ended, triggering a WARN from phy_error_precise().

mdio-i2c reports a RollBall command timeout as 0xffff, both for a bridge that is still booting and for a module without a bridge. Do one cheap MDIO read of the PHY ID before the full PHY probe and return -ENODEV on 0xffff: the existing 25 x 1 s retry loop still protects slow-booting genuine bridges, but a failed attempt costs one read instead of a full probe timing out on every register.

The ID register is used because phylib ignores a C45 MMD whose ID reads all-ones when matching drivers, so a PHY failing this check could not bind a driver through that MMD anyway. This relies on the PMA/PMD identifier, which Clause 45 makes mandatory, being readable once the bridge is up, as it is on the RollBall PHYs seen so far, such as the AQR113C and RTL8221B.

The trade-off is a shorter window for a bridge that stays completely
silent: the retry loop now gives up after about 45 seconds instead of the ~9 minutes the slow probe accidentally provided. The RollBall fixup allows modules to block PHY access for up to 25 seconds after insertion, so this should be sufficient.

Tested on a Banana Pi BPI-R4 with a bridge-less "OEM SFP-10G-T" rev A module and a genuine rev 02 module with an AQR113C: the rev A module links up at 10G 57 s after boot instead of over nine minutes, and the rev 02 module attaches its PHY as before.

---

Changes in v6:
- Handle a negative return from the MDIO read: log it and return -EIO, as the full PHY probe does, instead of falling through to the full probe (Willem de Bruijn).
- State in the commit message that the check relies on the PMA/PMD identifier being readable once the bridge is up.

Changes in v5:
- Replace the revision-quirk approach of v4 with the generic check suggested by Marek Behún, using the PHY ID register per his and Andrew Lunn's review. This also drops the sfp_strlen() move from v4, making this a single patch.

v5: https://lore.kernel.org/netdev/[email protected]/
v4: https://lore.kernel.org/netdev/[email protected]/
v3: https://lore.kernel.org/netdev/[email protected]/
v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/

---
 drivers/net/phy/sfp.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/phy/sfp.c +16 -0
index 915156743701..1253beba53d7 100644
@@ -2249,6 +2249,7 @@ static int sfp_sm_add_mdio_bus(struct sfp *sfp)
 static int sfp_sm_probe_for_phy(struct sfp *sfp)
 {
 	int err = 0;
+	int ret;
 
 	switch (sfp->mdio_protocol) {
 	case MDIO_I2C_NONE:
@@ -2263,6 +2264,21 @@ static int sfp_sm_probe_for_phy(struct sfp *sfp)
 		break;
 
 	case MDIO_I2C_ROLLBALL:
+		/* mdio-i2c reports a RollBall command timeout as 0xffff, both
+		 * for a bridge that is still booting and for a module without
+		 * a bridge. Retry after one cheap read instead of a full PHY
+		 * probe, which times out on every register under rtnl_lock.
+		 */
+		ret = mdiobus_c45_read(sfp->i2c_mii, SFP_PHY_ADDR_ROLLBALL,
+				       MDIO_MMD_PMAPMD, MII_PHYSID1);
+		if (ret == 0xffff)
+			return -ENODEV;
+		if (ret < 0) {
+			dev_err(sfp->dev, "mdiobus read returned %pe\n",
+				ERR_PTR(ret));
+			return -EIO;
+		}
+
 		err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR_ROLLBALL, true);
 		break;
 	}
Signature · 1 line
2.56.1
maintainer Reviewed-by on v6 1/1
#1 lore raw
Quoted 30 lines · Daniel Pawlik

Modules without a RollBall I2C-to-MDIO bridge time out on every RollBall command, but the quirks for such modules force MDIO_I2C_ROLLBALL. The PHY probe then retries 25 times at ~21 seconds per attempt, i.e. for over nine minutes, before the module links up without a PHY. Each attempt runs from sfp_timeout() with rtnl_lock held, so for the whole window every rtnl user on the system stalls in ~21 second chunks, including the state machines of other SFP cages: in one test, pulling a module from another cage was only processed after the current attempt ended, triggering a WARN from phy_error_precise().

mdio-i2c reports a RollBall command timeout as 0xffff, both for a bridge that is still booting and for a module without a bridge. Do one cheap MDIO read of the PHY ID before the full PHY probe and return -ENODEV on 0xffff: the existing 25 x 1 s retry loop still protects slow-booting genuine bridges, but a failed attempt costs one read instead of a full probe timing out on every register.

The ID register is used because phylib ignores a C45 MMD whose ID reads all-ones when matching drivers, so a PHY failing this check could not bind a driver through that MMD anyway. This relies on the PMA/PMD identifier, which Clause 45 makes mandatory, being readable once the bridge is up, as it is on the RollBall PHYs seen so far, such as the AQR113C and RTL8221B.

The trade-off is a shorter window for a bridge that stays completely
silent: the retry loop now gives up after about 45 seconds instead of the ~9 minutes the slow probe accidentally provided. The RollBall fixup allows modules to block PHY access for up to 25 seconds after insertion, so this should be sufficient.

Quoted 8 lines

Tested on a Banana Pi BPI-R4 with a bridge-less "OEM SFP-10G-T" rev A module and a genuine rev 02 module with an AQR113C: the rev A module links up at 10G 57 s after boot instead of over nine minutes, and the rev 02 module attaches its PHY as before.

Andrew

#2 lore raw
In reply to Daniel Pawlik
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 · 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] In sfp_sm_probe_for_phy() (drivers/net/phy/sfp.c), the new RollBall pre-check turns every negative result from…
- [Low] The commit fixes a user-visible bug but has no Fixes: tag.

--

net: sfp: probe RollBall bridge with one MDIO read before the PHY probe

This patch adds one MDIO read of the PMA/PMD PHY ID register before the full RollBall PHY probe in sfp_sm_probe_for_phy(). A 0xffff result returns -ENODEV so the existing retry loop runs again, and the full probe no longer times out on every register under rtnl_lock. Any other negative result is logged and returned as -EIO.

Quoted 3 lines

[Severity: Low]
This isn't a bug, but should this have a Fixes: tag?

The RollBall probe path in sfp_sm_probe_for_phy() and the quirk that forces MDIO_I2C_ROLLBALL on the bridge-less modules both come from the same commit:

    case MDIO_I2C_ROLLBALL:
        err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR_ROLLBALL, true);

    SFP_QUIRK_F("OEM", "SFP-10G-T", sfp_fixup_rollball_cc),

That commit is:

Fixes 324e88cbe3b7 ("net: sfp: add support for multigig RollBall transceivers")

Without the tag, stable trees may not pick up the fix for the multi-minute rtnl stall.

Quoted 4 lines
drivers/net/phy/sfp.c +0 -0
index 915156743701b..1253beba53d7c 100644

[ ... ]

Quoted 8 lines
drivers/net/phy/sfp.c +4 -0
@@ -2263,6 +2264,21 @@ static int sfp_sm_probe_for_phy(struct sfp *sfp)
 		break;
 
 	case MDIO_I2C_ROLLBALL:
+		/* mdio-i2c reports a RollBall command timeout as 0xffff, both
+		 * for a bridge that is still booting and for a module without
+		 * a bridge. Retry after one cheap read instead of a full PHY
+		 * probe, which times out on every register under rtnl_lock.

drivers/net/phy/sfp.c static int sfp_sm_probe_for_phy(struct sfp *sfp) · line 2280

Quoted 10 lines
drivers/net/phy/sfp.c +10 -0
+		 */
+		ret = mdiobus_c45_read(sfp->i2c_mii, SFP_PHY_ADDR_ROLLBALL,
+				       MDIO_MMD_PMAPMD, MII_PHYSID1);
+		if (ret == 0xffff)
+			return -ENODEV;
+		if (ret < 0) {
+			dev_err(sfp->dev, "mdiobus read returned %pe\n",
+				ERR_PTR(ret));
+			return -EIO;
+		}

[Severity: Medium]
Can this turn a retryable probe failure into a permanent one? In sfp_sm_main(), only -ENODEV is retried:

    ret = sfp_sm_probe_for_phy(sfp);
    if (ret == -ENODEV) {
        if (--sfp->sm_phy_retries) {
            sfp_sm_next(sfp, SFP_S_INIT_PHY,
                        sfp->phy_t_retry);
    ...
    } else if (ret) {
        sfp_sm_next(sfp, SFP_S_FAIL, 0);
        break;
    }

So any negative value from this read other than 0xffff, including -EIO and -ENODEV, now moves the module straight to SFP_S_FAIL.

Before this patch, the same failure on the first RollBall read went through sfp_sm_probe_phy()->get_phy_device()->get_phy_c45_ids()-> get_phy_c45_devs_in_pkg(), which maps -EIO and -ENODEV to -ENODEV:

drivers/net/phy/phy_device.c:get_phy_c45_devs_in_pkg() {
    ...
	phy_reg = mdiobus_c45_read(bus, addr, dev_addr, MDIO_DEVS2);
	if (phy_reg < 0)
		/* Like get_phy_c22_id(): returning -ENODEV doesn't stop bus
		 * scanning
		 */
		return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO;
    ...
}

On -ENODEV, get_phy_c45_ids() then tries MMD 0, and it returns -ENODEV if that read fails the same way. sfp_sm_probe_phy() then hands it back as a retryable -ENODEV.

-EIO looks reachable on this path. i2c_mii_read_rollball() maps only a poll -ETIMEDOUT to 0xffff and passes other errors through. __i2c_transfer_err() returns -EIO on a short transfer:

drivers/net/mdio/mdio-i2c.c:__i2c_transfer_err() {
    ...
	else if (ret != num)
		return -EIO;
    ...
}
drivers/net/mdio/mdio-i2c.c:i2c_mii_read_rollball() {
    ...
	ret = i2c_rollball_mii_poll(bus, bus_addr, res, sizeof(res));
	if (ret == -ETIMEDOUT)
		return 0xffff;
	else if (ret < 0)
		return ret;
    ...
}

Adapters such as i2c-algo-bit also return -EIO on a data NAK.

A single transient -EIO on the first RollBall transaction could happen while the module MCU is still busy or coming up, even after the password write in i2c_mii_init_rollball() has succeeded. Would that leave the module in SFP_S_FAIL with no PHY and no link until it is reinserted or the netdev is brought down and up?

The v6 changelog says the -EIO return matches "as the full PHY probe does", but for -EIO and -ENODEV the full probe returns -ENODEV and is retried.

To match phylib, could this return -ENODEV for 0xffff, -EIO and -ENODEV, and keep the -EIO/SFP_S_FAIL path for other errors only?

Quoted 4 lines
drivers/net/phy/sfp.c +1 -0
+
 		err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR_ROLLBALL, true);
 		break;
 	}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204093408.1391147-1-pawlik.dan%40gmail.com