Skip to content

Commit aa25c6b

Browse files
committed
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>
1 parent ad67407 commit aa25c6b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/ethernet/phy/phy_microchip_vsc8541.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ static int phy_mc_vsc8541_reset(const struct device *dev)
134134
const struct mc_vsc8541_config *cfg = dev->config;
135135
int ret;
136136
uint16_t reg = 0U;
137+
int count = 0;
137138

138139
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
139140

@@ -197,8 +198,15 @@ static int phy_mc_vsc8541_reset(const struct device *dev)
197198

198199
/* wait for phy finished software reset */
199200
do {
200-
phy_mc_vsc8541_read(dev, MII_BMCR, &reg);
201-
} while (reg & MII_BMCR_RESET);
201+
ret = phy_mc_vsc8541_read(dev, MII_BMCR, &reg);
202+
if (ret < 0) {
203+
return ret;
204+
}
205+
if (count++ > 1000) {
206+
LOG_ERR("phy reset timed out");
207+
return -ETIMEDOUT;
208+
}
209+
} while ((reg & MII_BMCR_RESET) != 0U);
202210

203211
/* configure the RGMII clk delay */
204212
reg = 0x0;

0 commit comments

Comments
 (0)