Commit aab1f68d authored by Robert Hancock's avatar Robert Hancock Committed by Benjamin Cabé
Browse files

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: default avatarRobert Hancock <robert.hancock@calian.com>
parent aa85d767
Loading
Loading
Loading
Loading
+10 −2
Changes for drivers/ethernet/phy/phy_microchip_vsc8541.c: 10 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -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;