Netdev List
 help / color / mirror / Atom feed
From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev@vger.kernel.org
Cc: Nicolai Buchwitz <nb@tipi-net.de>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next v2 4/4] net: phy: broadcom: Recover BCM54210E from aborted cable tests
Date: Fri,  4 Dec 2026 15:36:33 -0800	[thread overview]
Message-ID: <20261204233633.3790143-5-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261204233633.3790143-1-florian.fainelli@broadcom.com>

From: Nicolai Buchwitz <nb@tipi-net.de>

A stuck ECD run can leave the PHY in PHY_CABLETEST indefinitely.
Time out after five seconds. phylib reports completion without
pair results, so log the timeout to distinguish it from a
successful test.

Reset the PHY through phy_init_hw() while it is still in
PHY_CABLETEST. This covers timeout, status read errors and an
interface stop during the test. A reset stops the ECD engine
before config_init() can re-enable auto power-down. Propagate
reset errors to phylib.

A soft reset may clear register settings outside config_init().
Preserve the enabled wake filters, interrupt mask and LED routing
across the reset without changing the host IRQ wake state. The
normal initialization sequence reapplies the driver's defaults,
including its LED configuration.

Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
Co-developed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 drivers/net/phy/broadcom.c | 80 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c
index 19b97beb8be8..3b32c15e4dd6 100644
--- a/drivers/net/phy/broadcom.c
+++ b/drivers/net/phy/broadcom.c
@@ -30,12 +30,16 @@ MODULE_DESCRIPTION("Broadcom PHY driver");
 MODULE_AUTHOR("Maciej W. Rozycki");
 MODULE_LICENSE("GPL");
 
+/* An ECD run takes less than a second */
+#define BCM54XX_CABLE_TEST_TIMEOUT_MS	5000
+
 struct bcm54xx_phy_priv {
 	u64	*stats;
 	struct bcm_ptp_private *ptp;
 	int	wake_irq;
 	bool	wake_irq_enabled;
 	bool	brr_mode;
+	unsigned long cable_test_timeout;
 };
 
 /* Link modes for BCM58411 PHY */
@@ -1471,6 +1475,7 @@ static int bcm54xx_disable_autonomous_eee(struct phy_device *phydev)
 
 static int bcm54xx_cable_test_start(struct phy_device *phydev)
 {
+	struct bcm54xx_phy_priv *priv = phydev->priv;
 	int val, ret;
 
 	/* The ECD run never finishes on a line without energy while auto
@@ -1486,21 +1491,89 @@ static int bcm54xx_cable_test_start(struct phy_device *phydev)
 		return ret;
 
 	ret = bcm_phy_cable_test_start(phydev);
-	if (ret < 0)
+	if (ret < 0) {
 		bcm54xx_adjust_rxrefclk(phydev);
+		return ret;
+	}
 
-	return ret;
+	priv->cable_test_timeout = jiffies +
+		msecs_to_jiffies(BCM54XX_CABLE_TEST_TIMEOUT_MS);
+
+	return 0;
+}
+
+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,
+	};
+	u16 wol_values[ARRAY_SIZE(wol_regs)];
+	int wol_ctl, ret;
+	unsigned int i;
+
+	/* phylib reinitializes the PHY before leaving PHY_CABLETEST
+	 * on an abort. Reset the ECD engine before config_init restores APD.
+	 */
+	if (phydev->state != PHY_CABLETEST)
+		return 0;
+
+	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;
+	}
+
+	if (!(wol_ctl & BCM54XX_WOL_EN))
+		return 0;
+
+	for (i = 0; i < ARRAY_SIZE(wol_regs); i++) {
+		ret = bcm_phy_write_exp(phydev, wol_regs[i], wol_values[i]);
+		if (ret < 0)
+			return ret;
+	}
+
+	return bcm_phy_write_exp(phydev, BCM54XX_WOL_MAIN_CTL,
+				 wol_ctl & ~BCM54XX_WOL_RST);
 }
 
 static int bcm54xx_cable_test_get_status(struct phy_device *phydev,
 					 bool *finished)
 {
+	struct bcm54xx_phy_priv *priv = phydev->priv;
 	int ret;
 
 	ret = bcm_phy_cable_test_get_status(phydev, finished);
-	if (ret < 0 || !*finished)
+	if (ret < 0)
 		return ret;
 
+	if (!*finished) {
+		if (time_before(jiffies, priv->cable_test_timeout))
+			return 0;
+
+		phydev_warn(phydev, "Cable test timed out\n");
+		return -ETIMEDOUT;
+	}
+
 	/* Put auto power-down back the way config_init() left it */
 	bcm54xx_adjust_rxrefclk(phydev);
 
@@ -1542,6 +1615,7 @@ static struct phy_driver broadcom_drivers[] = {
 	.get_strings	= bcm_phy_get_strings,
 	.get_stats	= bcm54xx_get_stats,
 	.probe		= bcm54xx_phy_probe,
+	.soft_reset	= bcm54210e_soft_reset,
 	.config_init	= bcm54xx_config_init,
 	.config_intr	= bcm_phy_config_intr,
 	.handle_interrupt = bcm_phy_handle_interrupt,
-- 
2.56.1


      parent reply	other threads:[~2026-12-04 23:36 UTC|newest]

Thread overview: 5+ 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-04 23:36 ` [PATCH net-next v2 2/4] net: phy: broadcom: Implement cable test initialization for BCM54210E Florian Fainelli
2026-12-04 23:36 ` [PATCH net-next v2 3/4] net: phy: broadcom: Wire-up cable tests " Florian Fainelli
2026-12-04 23:36 ` Florian Fainelli [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=20261204233633.3790143-5-florian.fainelli@broadcom.com \
    --to=florian.fainelli@broadcom.com \
    --cc=andrew@lunn.ch \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --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