drivers: ethernet: phy: vsc8541: Add timeout on SW reset

The driver previously could enter an infinite loop if the PHY software
reset failed to complete, which could happen due to hardware reset
issues or MDIO bus problems. Add a timeout of 1000 iterations so we
report an error in this scenario rather than causing a lockup.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
This commit is contained in:
Robert Hancock 2025-06-13 15:09:18 -06:00 committed by Benjamin Cabé
parent aa85d76777
commit aab1f68d08

View File

@ -134,6 +134,7 @@ static int phy_mc_vsc8541_reset(const struct device *dev)
const struct mc_vsc8541_config *cfg = dev->config;
int ret;
uint16_t reg = 0U;
int count = 0;
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
@ -197,8 +198,15 @@ static int phy_mc_vsc8541_reset(const struct device *dev)
/* wait for phy finished software reset */
do {
phy_mc_vsc8541_read(dev, MII_BMCR, &reg);
} while (reg & MII_BMCR_RESET);
ret = phy_mc_vsc8541_read(dev, MII_BMCR, &reg);
if (ret < 0) {
return ret;
}
if (count++ > 1000) {
LOG_ERR("phy reset timed out");
return -ETIMEDOUT;
}
} while ((reg & MII_BMCR_RESET) != 0U);
/* configure the RGMII clk delay */
reg = 0x0;