diff options
author | Jan Hoffmann <jan@3e8.eu> | 2022-07-23 22:53:16 +0200 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2022-07-28 14:08:51 +0200 |
commit | 81e3017609be0ffa85c7ba430734e47519186481 (patch) | |
tree | 22f1f771160d94aa5a23dfd82c5fddc79b3bad8c /target | |
parent | b6a0d50b7fd1ed8d62cc017d9fc5b83f436d3156 (diff) | |
download | upstream-81e3017609be0ffa85c7ba430734e47519186481.tar.gz upstream-81e3017609be0ffa85c7ba430734e47519186481.tar.bz2 upstream-81e3017609be0ffa85c7ba430734e47519186481.zip |
realtek: clean up rtl838x MDIO busy wait loop
Don't use udelay to allow other kernel tasks to execute if the kernel
has been built without preemption. Also determine the timeout based on
jiffies instead of loop iterations.
This is especially important on devices containing a watchdog with a
short timeout. Without this change, the watchdog is not serviced during
PHY patching which can take multiple seconds.
Tested-by: Birger Koblitz <mail@birger-koblitz.de>
Signed-off-by: Jan Hoffmann <jan@3e8.eu>
Diffstat (limited to 'target')
-rw-r--r-- | target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c index cdf1766778..524594d725 100644 --- a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c +++ b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c @@ -1805,13 +1805,20 @@ irqreturn_t rtl838x_switch_irq(int irq, void *dev_id) int rtl838x_smi_wait_op(int timeout) { - do { - timeout--; - udelay(10); - } while ((sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_1) & 0x1) && (timeout >= 0)); - if (timeout <= 0) - return -1; - return 0; + unsigned long end = jiffies + usecs_to_jiffies(timeout); + + while (1) { + if (!(sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_1) & 0x1)) + return 0; + + if (time_after(jiffies, end)) + break; + + usleep_range(10, 20); + } + + pr_err("rtl838x_smi_wait_op: timeout\n"); + return -1; } /* @@ -1832,7 +1839,7 @@ int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val) mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32_mask(0xffff0000, port << 16, RTL838X_SMI_ACCESS_PHY_CTRL_2); @@ -1842,7 +1849,7 @@ int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val) sw_w32(v | park_page, RTL838X_SMI_ACCESS_PHY_CTRL_1); sw_w32_mask(0, 1, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; *val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff; @@ -1868,7 +1875,7 @@ int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val) return -ENOTSUPP; mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32(BIT(port), RTL838X_SMI_ACCESS_PHY_CTRL_0); @@ -1881,7 +1888,7 @@ int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val) sw_w32(v | park_page, RTL838X_SMI_ACCESS_PHY_CTRL_1); sw_w32_mask(0, 1, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; mutex_unlock(&smi_lock); @@ -1901,7 +1908,7 @@ int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val) mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0); @@ -1916,7 +1923,7 @@ int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val) v = 1 << 1 | 0 << 2 | 1; sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; *val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff; @@ -1940,7 +1947,7 @@ int rtl838x_write_mmd_phy(u32 port, u32 addr, u32 reg, u32 val) val &= 0xffff; mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0); @@ -1954,7 +1961,7 @@ int rtl838x_write_mmd_phy(u32 port, u32 addr, u32 reg, u32 val) v = 1 << 1 | 1 << 2 | 1; sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; mutex_unlock(&smi_lock); |