From: Nicolai Buchwitz 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 Co-developed-by: Florian Fainelli Signed-off-by: Florian Fainelli --- 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