arch/arm/stm32h7: wait for the PHY link in milliseconds.

The PHY was polled with nxsched_usleep(100) in a loop of 0x1998
iterations, so the time the link had to come up depended on the period
of the system tick. With the usual 10 ms tick that is about 65 s, but
with CONFIG_SCHED_TICKLESS and a 100 us tick it is about 0.65 s, shorter
than the auto-negotiation of the PHY (about 1.7 s on the board tested),
and the interface could not be brought up.

Poll every 10 ms and give the PHY up to 5 s, both for the link and for
the auto-negotiation to complete, whatever the tick.

Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
Assisted-by: Claude:claude-sonnet-5
This commit is contained in:
Daniel P. Carvalho 2026-09-20 15:47:52 -03:00 • committed by Xiang Xiao
parent 5beb781f9b
commit 9d861ca27e

View file

@ -366,7 +366,15 @@
#define PHY_READ_TIMEOUT (0x0004ffff)
#define PHY_WRITE_TIMEOUT (0x0004ffff)
#define PHY_RETRY_TIMEOUT (0x0001998)
/* The PHY is polled every PHY_POLL_MS milliseconds and given up to
* PHY_LINK_TIMEOUT_MS milliseconds to bring the link up or to complete
* auto-negotiation. The time is in milliseconds so that it does not depend
* on the period of the system tick.
*/
#define PHY_POLL_MS (10)
#define PHY_LINK_TIMEOUT_MS (5000)
#define PHY_RETRY_TIMEOUT (PHY_LINK_TIMEOUT_MS / PHY_POLL_MS)
/* MAC reset ready delays in loop counts */
@ -3413,7 +3421,7 @@ static int stm32_phyinit(struct stm32_ethmac_s *priv)
break;
}
nxsched_usleep(100);
nxsched_msleep(PHY_POLL_MS);
}
if (timeout >= PHY_RETRY_TIMEOUT)
@ -3464,7 +3472,7 @@ static int stm32_phyinit(struct stm32_ethmac_s *priv)
break;
}
nxsched_usleep(100);
nxsched_msleep(PHY_POLL_MS);
}
if (timeout >= PHY_RETRY_TIMEOUT)