Skip to content

Commit d8ff2df

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 5598cc0 commit d8ff2df

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/ethernet/phy/phy_microchip_vsc8541.c

Lines changed: 9 additions & 1 deletion
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,7 +198,14 @@ 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+
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+
}
201209
} while (reg & MII_BMCR_RESET);
202210

203211
/* configure the RGMII clk delay */

0 commit comments

Comments
 (0)