Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: stmmac: Convert open-coded register polling to helper macro

Drop the open-coded register polling routines.
Use readl_poll_timeout_atomic() in atomic state.

Also adjust the delay time to 10us which seems more reasonable.

Tested on NXP i.MX8MP and ROCKCHIP RK3588 boards,
the break condition was met right after the first polling,
no delay involved at all.
So the 10us delay should be long enough for most cases.

Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Furong Xu <0x1207@gmail.com>
Link: https://patch.msgid.link/20250927081036.10611-1-0x1207@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Furong Xu and committed by
Jakub Kicinski
9dd4e022 74f7c523

+6 -22
+6 -22
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
··· 135 135 static int config_addend(void __iomem *ioaddr, u32 addend) 136 136 { 137 137 u32 value; 138 - int limit; 139 138 140 139 writel(addend, ioaddr + PTP_TAR); 141 140 /* issue command to update the addend value */ ··· 143 144 writel(value, ioaddr + PTP_TCR); 144 145 145 146 /* wait for present addend update to complete */ 146 - limit = 10; 147 - while (limit--) { 148 - if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSADDREG)) 149 - break; 150 - mdelay(10); 151 - } 152 - if (limit < 0) 153 - return -EBUSY; 154 - 155 - return 0; 147 + return readl_poll_timeout_atomic(ioaddr + PTP_TCR, value, 148 + !(value & PTP_TCR_TSADDREG), 149 + 10, 100000); 156 150 } 157 151 158 152 static int adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec, 159 153 int add_sub, int gmac4) 160 154 { 161 155 u32 value; 162 - int limit; 163 156 164 157 if (add_sub) { 165 158 /* If the new sec value needs to be subtracted with ··· 178 187 writel(value, ioaddr + PTP_TCR); 179 188 180 189 /* wait for present system time adjust/update to complete */ 181 - limit = 10; 182 - while (limit--) { 183 - if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSUPDT)) 184 - break; 185 - mdelay(10); 186 - } 187 - if (limit < 0) 188 - return -EBUSY; 189 - 190 - return 0; 190 + return readl_poll_timeout_atomic(ioaddr + PTP_TCR, value, 191 + !(value & PTP_TCR_TSUPDT), 192 + 10, 100000); 191 193 } 192 194 193 195 static void get_systime(void __iomem *ioaddr, u64 *systime)