Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: florian.fainelli@broadcom.com
Cc: netdev@vger.kernel.org, nb@tipi-net.de,
	bcm-kernel-feedback-list@broadcom.com, andrew@lunn.ch,
	hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com
Subject: Re: [PATCH net-next v2 4/4] net: phy: broadcom: Recover BCM54210E from aborted cable tests
Date: Sun, 06 Dec 2026 00:07:36 +0000	[thread overview]
Message-ID: <179651565647.3148.14123507342197810039@kernel.org> (raw)
In-Reply-To: <20261204233633.3790143-5-florian.fainelli@broadcom.com>

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

Critical: 0 · High: 0 · Medium: 3 · 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] bcm54210e_soft_reset() (drivers/net/phy/broadcom.c) adds a
  BMCR_RESET through genphy_soft_reset() to every cable-test abort on…
- [Medium] net: phy: broadcom: bcm54210e_soft_reset() falsely clears
  phydev->suspended
- [Medium] net: phy: broadcom: bcm54210e_soft_reset() drops unpolled PHY
  stats counters
- [Low] Any error inside bcm54210e_soft_reset()
  (drivers/net/phy/broadcom.c) is returned to phy_init_hw().

--

net: phy: broadcom: Recover BCM54210E from aborted cable tests

This patch adds a five second timeout to the BCM54210E cable test. It also
adds a .soft_reset callback that resets the PHY through genphy_soft_reset()
when phy_init_hw() runs while the state is still PHY_CABLETEST. When WoL is
enabled, the WoL filter registers, WoL interrupt mask and TOP_MISC_LED_CTL
are saved before the reset and restored after it.

> diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c
> index 19b97beb8be8d..3b32c15e4dd60 100644
> --- a/drivers/net/phy/broadcom.c
> +++ b/drivers/net/phy/broadcom.c

[ ... ]

> +static int bcm54210e_soft_reset(struct phy_device *phydev)
> +{
> +	static const u16 wol_regs[] = {
> +		BCM54XX_WOL_MPD_DATA1(0), BCM54XX_WOL_MPD_DATA1(1),
> +		BCM54XX_WOL_MPD_DATA1(2), BCM54XX_WOL_MPD_DATA2(0),
> +		BCM54XX_WOL_MPD_DATA2(1), BCM54XX_WOL_MPD_DATA2(2),
> +		BCM54XX_WOL_MASK(0), BCM54XX_WOL_MASK(1), BCM54XX_WOL_MASK(2),
> +		BCM54XX_WOL_INT_MASK, BCM54XX_TOP_MISC_LED_CTL,
> +	};

[Severity: Medium]
What happens to the PTP timestamping configuration across this reset?

The commit message says "A soft reset may clear register settings outside
config_init()", and this list covers the WoL and LED registers. It does
not cover the PTP expansion registers that bcm_ptp_hwtstamp_set() programs
at runtime:

drivers/net/phy/bcm-phy-ptp.c:bcm_ptp_hwtstamp_set() {
    ...
	bcm_phy_write_exp(priv->phydev, TX_EVENT_MODE, mode);
    ...
	bcm_phy_write_exp(priv->phydev, RX_EVENT_MODE, mode);

	bcm_phy_write_exp(priv->phydev, SLICE_CTRL, ctrl);

	if (ctrl & SLICE_TX_EN)
		bcm_phy_write_exp(priv->phydev, TX_TS_CAPTURE, TX_TS_CAP_EN);
    ...
}

PTP is only attached to PHY_ID_BCM54210E, the same device that now gets
the reset. After the reset, config_init() runs
bcm54xx_config_init()->bcm54xx_ptp_config_init()->bcm_ptp_config_init().
That path only writes NSE_CTRL, TIME_SYNC, DPLL_SELECT, TIMECODE_CTRL,
SHADOW_CTRL and SYNC_IN_DIVIDER.

priv->hwts_rx and priv->tx_type in struct bcm_ptp_private survive the
reset. So bcm_ptp_rxtstamp() and bcm_ptp_txtstamp() keep treating
timestamping as enabled.

If BMCR_RESET clears these registers, would TX timestamp requests sit in
tx_queue until they expire? Would RX PTP frames arrive without inserted
timestamps, with no error reported?

Before this patch the BCM54210E entry had no .soft_reset, so phy_init_hw()
on the abort path never reset the chip.

The LED routing has a smaller version of the same gap. TOP_MISC_LED_CTL is
only preserved when BCM54XX_WOL_EN is set. bcm_phy_set_wol() with
wolopts == 0 clears WOL_EN but leaves BCM54XX_LED4_SEL_INTR set in
TOP_MISC_LED_CTL. Is that LED setting expected to be lost in that case?

> +	u16 wol_values[ARRAY_SIZE(wol_regs)];
> +	int wol_ctl, ret;
> +	unsigned int i;

[ ... ]

> +	wol_ctl = bcm_phy_read_exp(phydev, BCM54XX_WOL_MAIN_CTL);
> +	if (wol_ctl < 0)
> +		return wol_ctl;
> +
> +	/* Preserve the programmed wake filters and interrupt routing. */
> +	if (wol_ctl & BCM54XX_WOL_EN) {
> +		for (i = 0; i < ARRAY_SIZE(wol_regs); i++) {
> +			ret = bcm_phy_read_exp(phydev, wol_regs[i]);
> +			if (ret < 0)
> +				return ret;
> +
> +			wol_values[i] = ret;
> +		}
> +	}
> +
> +	ret = genphy_soft_reset(phydev);
> +	if (ret < 0) {
> +		phydev_err(phydev, "Failed to reset PHY after cable test: %d\n",
> +			   ret);
> +		return ret;
> +	}

[Severity: Medium]
Are the PHY error and LPI counters lost across this reset?

The counters behind bcm54xx_get_stats() are clear-on-read in the
PHY. They only reach priv->stats when bcm_phy_update_stats_shadow()
runs, which is why bcm54xx_suspend() flushes them before powering
down:

drivers/net/phy/broadcom.c:bcm54xx_suspend() {
    ...
	mutex_lock(&phydev->lock);
	bcm_phy_update_stats_shadow(phydev, priv->stats);
	mutex_unlock(&phydev->lock);
    ...
}

bcm54210e_soft_reset() calls genphy_soft_reset() without a similar
flush. Anything counted since the last ethtool -S read is then
discarded. That happens on every aborted cable test:

- on the new -ETIMEDOUT path,
- on a status read error,
- on phy_stop() during the test.

In the phy_stop() case, phy_abort_cable_test() runs phy_init_hw()
before phy_suspend() reaches bcm54xx_suspend(). The flush there
runs only after the counters are already gone.

Should the reset path call bcm_phy_update_stats_shadow() on
priv->stats before genphy_soft_reset()? The abort path already runs
with phydev->lock held, so it could not take the lock the way
bcm54xx_suspend() does.

[Severity: Low]
What state is the PHY left in if one of these error returns is taken?

phy_init_hw() returns as soon as soft_reset() fails. That skips
config_init(), config_intr() and the autonomous EEE re-apply:

drivers/net/phy/phy_device.c:phy_init_hw() {
    ...
	if (phydev->drv->soft_reset) {
		ret = phydev->drv->soft_reset(phydev);
		if (ret < 0)
			return ret;
    ...
}

phy_abort_cable_test() only logs the error. _phy_state_machine() then
moves to PHY_UP and starts aneg anyway:

drivers/net/phy/phy.c:phy_abort_cable_test() {
    ...
	err = phy_init_hw(phydev);
	if (err)
		phydev_err(phydev, "Error while aborting cable test");
}

Suppose the bcm_phy_read_exp() of BCM54XX_WOL_MAIN_CTL fails, or a read of
one of the saved WoL registers fails. The function then returns before
genphy_soft_reset() runs.

Would that leave the ECD engine running, with APD still cleared by
bcm54xx_cable_test_start()? The state has already left PHY_CABLETEST, so
the new timeout in bcm54xx_cable_test_get_status() can no longer catch it.
Before this patch the abort path always reached config_init().

Now suppose genphy_soft_reset() fails after BMCR_RESET was written, for
example on a phy_poll_reset() timeout. Or one of the WoL restore writes
fails after a successful reset. Either way the PHY is left at reset
defaults.

Would the RGMII delays, ECR/IMR interrupt masking, LED and PTP setup then
stay unapplied while phylib carries on into autonegotiation?

> +
> +	if (!(wol_ctl & BCM54XX_WOL_EN))
> +		return 0;

[Severity: Medium]
Does adding a .soft_reset that is a no-op outside PHY_CABLETEST
change what phy_init_hw() assumes about the power state?

Before this patch the BCM54210E entry had no .soft_reset, so
phy_init_hw() never touched phydev->suspended. Now every
phy_init_hw() call takes the soft_reset branch. Once the callback
returns >= 0, the flag is cleared unconditionally:

drivers/net/phy/phy_device.c:phy_init_hw() {
    ...
	if (phydev->drv->soft_reset) {
		ret = phydev->drv->soft_reset(phydev);
		if (ret < 0)
			return ret;

		phydev->suspended = 0;
	}
    ...
}

That relies on BMCR_RESET having cleared BMCR_PDOWN. Outside
PHY_CABLETEST, bcm54210e_soft_reset() returns 0 without writing
BMCR. A PHY that bcm54xx_suspend() powered down then stays in
BMCR_PDOWN (and IDDQ if configured) while phydev->suspended reads 0.

Several callers run phy_init_hw() on a suspended PHY without a
guaranteed phy_resume() afterwards:

- bcmgenet_resume() calls phy_init_hw() before bcmgenet_init_dma()
  and only calls phy_resume() conditionally. GENET is the MAC paired
  with this PHY on the Raspberry Pi 4 and CM4.
- ave_resume() skips phy_resume() when the interface is down.
- mdio_bus_phy_resume() and phy_attach_direct() can fail between
  phy_init_hw() and phy_resume().

With the flag out of sync, phylink_prepare_resume() would skip
phy_resume() while RXC is still stopped by BMCR_PDOWN. phy_suspend()
would also run bcm54xx_suspend() again on a PHY that is already
down. That repeats the stats shadow update and the
BCM54XX_WOL_INT_STATUS read while the PHY is powered down.

Could the cable test reset be done somewhere that does not report
a reset to phylib when none happened? One option might be the start
of bcm54xx_config_init() when phydev->state is PHY_CABLETEST.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204233633.3790143-1-florian.fainelli%40broadcom.com

      reply	other threads:[~2026-12-06  0:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 23:36 [PATCH net-next v2 0/4] net: phy: Cable tests for BCM54210E Florian Fainelli
2026-12-04 23:36 ` [PATCH net-next v2 1/4] net: phy: broadcom: Report failed ECD pairs as unspecified Florian Fainelli
2026-12-06  0:07   ` netdev-bot+sashiko
2026-12-04 23:36 ` [PATCH net-next v2 2/4] net: phy: broadcom: Implement cable test initialization for BCM54210E Florian Fainelli
2026-12-06  0:07   ` netdev-bot+sashiko
2026-12-04 23:36 ` [PATCH net-next v2 3/4] net: phy: broadcom: Wire-up cable tests " Florian Fainelli
2026-12-06  0:07   ` netdev-bot+sashiko
2026-12-04 23:36 ` [PATCH net-next v2 4/4] net: phy: broadcom: Recover BCM54210E from aborted cable tests Florian Fainelli
2026-12-06  0:07   ` netdev-bot+sashiko [this message]

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=179651565647.3148.14123507342197810039@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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