Skip to contentSkip to conversation

tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5()

PATCH New Ian Rogers 2 participants 2 messages Nov 22 – Nov 23

Subsystems (3)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH v2 1/1 tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5()

In tg3_phy_reset_5703_4_5(), the 10-iteration retry loop discards the return value of both tg3_readphy() calls on continue and never checks err after the loop terminates. If MDIO reads fail across all 10 retries, phy9_orig is never initialized before being written back to MII_CTRL1000; if tg3_phy_write_and_check_testpat() fails across all 10 retries, the function silently continues as if the PHY test pattern succeeded.

Record err on both tg3_readphy() calls and return err if the retry loop finishes with an error so dead MDIO hardware fails probe cleanly via tg3_phy_probe(), and zero-initialize phy9_orig since Clang's value-insensitive -Wconditional-uninitialized check does not correlate the earlier continue on err != 0 with the post-loop 'if (err)' check.

Found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig build with AI coding assistant help. Verified by building drivers/net/ethernet/broadcom/tg3.o with LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized; not runtime-tested on BCM5703/5704/5705 hardware.

---

Notes:
v2:
- Target net-next and drop the Fixes tag (Andrew Lunn).
- Also zero-initialize phy9_orig so Clang's value-insensitive -Wconditional-uninitialized check sees no uninitialized CFG path across the earlier 'continue'.

v1: https://lore.kernel.org/r/[email protected]

 drivers/net/ethernet/broadcom/tg3.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +8 -3
index 95827df4cf6a..4d375328621c 100644
@@ -2544,7 +2544,7 @@ static int tg3_phy_reset_chanpat(struct tg3 *tp)
 
 static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
 {
-	u32 reg32, phy9_orig;
+	u32 reg32, phy9_orig = 0;
 	int retries, do_phy_reset, err;
 
 	retries = 10;
@@ -2558,7 +2558,8 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
 		}
 
 		/* Disable transmitter and interrupt.  */
-		if (tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32))
+		err = tg3_readphy(tp, MII_TG3_EXT_CTRL, &reg32);
+		if (err)
 			continue;
 
 		reg32 |= 0x3000;
@@ -2569,7 +2570,8 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
 			     BMCR_FULLDPLX | BMCR_SPEED1000);
 
 		/* Set to master mode.  */
-		if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig))
+		err = tg3_readphy(tp, MII_CTRL1000, &phy9_orig);
+		if (err)
 			continue;
 
 		tg3_writephy(tp, MII_CTRL1000,
@@ -2587,6 +2589,9 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
 			break;
 	} while (--retries);
 
+	if (err)
+		return err;
+
 	err = tg3_phy_reset_chanpat(tp);
 	if (err)
 		return err;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
#1 lore raw
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: 1 · Medium: 1 · Low: 0

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).

- [High] The new post-loop if (err) return err; in tg3_phy_reset_5703_4_5()…
- [Medium] The commit message says the new post-loop if (err) return err; makes "dead MDIO hardware fail probe cleanly via…

--

tg3: Propagate PHY reset retry failures in tg3_phy_reset_5703_4_5()

This patch stores the return value of both tg3_readphy() calls in the retry loop of tg3_phy_reset_5703_4_5(). If the loop ends without success, the function now returns that error. It also zero-initializes phy9_orig to silence a Clang -Wconditional-uninitialized warning.

Quoted 3 lines

Record err on both tg3_readphy() calls and return err if the retry loop finishes with an error so dead MDIO hardware fails probe cleanly via tg3_phy_probe(), and zero-initialize phy9_orig since Clang's

[Severity: Medium]
Is this description accurate? In tg3_get_invariants(), an error from tg3_phy_probe() is logged and probe keeps going:

drivers/net/ethernet/broadcom/tg3.c:tg3_get_invariants() {
    ...
	err = tg3_phy_probe(tp);
	if (err) {
		dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err);
		/* ... but do not return immediately ... */
		tg3_mdio_fini(tp);
	}
    ...
}

So the netdev is still registered.

Dead MDIO also looks like it is caught before the retry loop runs. tg3_phy_reset() already returns -EBUSY when the MII_BMSR reads fail:

	err  = tg3_readphy(tp, MII_BMSR, &val);
	err |= tg3_readphy(tp, MII_BMSR, &val);
	if (err != 0)
		return -EBUSY;

tg3_bmcr_reset() at the top of the loop also returns -EBUSY on any BMCR write or read failure.

That leaves tg3_phy_write_and_check_testpat() failing ten times as the main case that now gets propagated. This includes the readback mismatch branch, which is only reached after the MDIO reads succeeded:

			if (low != test_pat[chan][i] ||
			    high != test_pat[chan][i+1]) {
				tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b);
				tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001);
				tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005);

				return -EBUSY;
			}

Before this patch, that error was overwritten by
err = tg3_phy_reset_chanpat(tp) and so was effectively tolerated.

At probe time, the new error makes tg3_phy_probe() return straight after tg3_phy_reset(). That skips tg3_phy_set_wirespeed() and the tg3_phy_autoneg_cfg() / BMCR_ANENABLE | BMCR_ANRESTART setup, but the device still registers.

Could the commit message describe this behavior change instead?

Quoted 4 lines
drivers/net/ethernet/broadcom/tg3.c +0 -0
index 95827df4cf6a1..4d375328621cc 100644

[ ... ]

drivers/net/ethernet/broadcom/tg3.c static int tg3_phy_reset_5703_4_5(struct tg3 *tp) · line 2597

Quoted 10 lines
drivers/net/ethernet/broadcom/tg3.c +3 -0
@@ -2587,6 +2589,9 @@ static int tg3_phy_reset_5703_4_5(struct tg3 *tp)
 			break;
 	} while (--retries);
 
+	if (err)
+		return err;
+
 	err = tg3_phy_reset_chanpat(tp);
 	if (err)
 		return err;

[Severity: High]
Can this early return leave the BCM5703/5704/5705 PHY in its DSP test configuration?

Before the test pattern check, the loop sets the PHY up like this:

		reg32 |= 0x3000;
		tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);
		...
		tg3_writephy(tp, MII_BMCR,
			     BMCR_FULLDPLX | BMCR_SPEED1000);
		...
		tg3_writephy(tp, MII_CTRL1000,
			     CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER);

		err = tg3_phy_toggle_auxctl_smdsp(tp, true);
		...
		/* Block the PHY control access.  */
		tg3_phydsp_write(tp, 0x8005, 0x0800);

Before this patch, the code after the loop always ran and undid this setup:

	tg3_phydsp_write(tp, 0x8005, 0x0000);
	...
	tg3_phy_toggle_auxctl_smdsp(tp, false);

	tg3_writephy(tp, MII_CTRL1000, phy9_orig);
	...
	reg32 &= ~0x3000;
	tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32);

The new return skips all of this in two cases. tg3_phy_write_and_check_testpat() may fail on all ten iterations, or the MII_TG3_EXT_CTRL or MII_CTRL1000 read may fail on the last iteration. tg3_phy_reset() then passes the error up and skips its out: errata fixups.

Most callers ignore the return value of tg3_phy_reset(). For example, tg3_reset_hw() does:

	if (reset_phy)
		tg3_phy_reset(tp);

tg3_setup_copper_phy() and tg3_set_eee() do the same. On those paths the driver carries on as if the reset worked.

Later autoneg setup rewrites BMCR, ADVERTISE and CTRL1000. However, nothing else on the 5703/4/5 path appears to clear the 0x3000 bits in MII_TG3_EXT_CTRL or unblock DSP 0x8005.

Would the interface then come up with the PHY transmitter disabled and unable to get a link?

In the test pattern mismatch case the MDIO bus is working, so the skipped restore writes would have reached the PHY. Could the restore sequence run first and the function return err afterwards? Another option is to keep the old fall-through for the mismatch case.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122045326.19641-1-irogers%40google.com