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 <f.fainelli@gmail.com>,
	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 3/3] net: phy: broadcom: Time out a stuck cable test
Date: Wed,  2 Dec 2026 16:48:02 -0800	[thread overview]
Message-ID: <20261203004802.85707-4-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261203004802.85707-1-florian.fainelli@broadcom.com>

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

A stuck ECD run leaves the PHY in PHY_CABLETEST for good. Give up after
5 seconds and reset the PHY so the link can come back.

Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/phy/broadcom.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c
index 19b97beb8be8..776a88caae9b 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,40 @@ 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 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;
+
+		/* A stuck ECD run cannot be stopped through ECD_CTRL, only a
+		 * reset gets the PHY back. phylib reruns config_init() when
+		 * it aborts the test.
+		 */
+		genphy_soft_reset(phydev);
+
+		return -ETIMEDOUT;
+	}
+
 	/* Put auto power-down back the way config_init() left it */
 	bcm54xx_adjust_rxrefclk(phydev);
 
-- 
2.53.0


      parent reply	other threads:[~2026-12-03  0:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  0:47 [PATCH net-next 0/3] net: phy: Cable tests for BCM54210E Florian Fainelli
2026-12-03  0:48 ` [PATCH net-next 1/3] net: phy: broadcom: Implement cable test initialization Florian Fainelli
2026-12-03  0:48 ` [PATCH net-next 2/3] net: phy: broadcom: Wire-up cable tests for BCM54210E Florian Fainelli
2026-12-03  0:48 ` 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=20261203004802.85707-4-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=f.fainelli@gmail.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