Commit eb7e33d0 authored by Pawel Dembicki's avatar Pawel Dembicki Committed by Jakub Kicinski

net: dsa: vsc73xx: use read_poll_timeout instead delay loop

Switch the delay loop during the Arbiter empty check from
vsc73xx_adjust_link() to use read_poll_timeout(). Functionally,
one msleep() call is eliminated at the end of the loop in the timeout
case.

As Russell King suggested:

"This [change] avoids the issue that on the last iteration, the code reads
the register, tests it, finds the condition that's being waiting for is
false, _then_ waits and end up printing the error message - that last
wait is rather useless, and as the arbiter state isn't checked after
waiting, it could be that we had success during the last wait."
Suggested-by: default avatarRussell King <linux@armlinux.org.uk>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Reviewed-by: default avatarFlorian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: default avatarPawel Dembicki <paweldembicki@gmail.com>
Link: https://lore.kernel.org/r/20240417205048.3542839-2-paweldembicki@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c51db4ac
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/iopoll.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_mdio.h> #include <linux/of_mdio.h>
#include <linux/bitops.h> #include <linux/bitops.h>
...@@ -268,6 +269,9 @@ ...@@ -268,6 +269,9 @@
#define IS_7398(a) ((a)->chipid == VSC73XX_CHIPID_ID_7398) #define IS_7398(a) ((a)->chipid == VSC73XX_CHIPID_ID_7398)
#define IS_739X(a) (IS_7395(a) || IS_7398(a)) #define IS_739X(a) (IS_7395(a) || IS_7398(a))
#define VSC73XX_POLL_SLEEP_US 1000
#define VSC73XX_POLL_TIMEOUT_US 10000
struct vsc73xx_counter { struct vsc73xx_counter {
u8 counter; u8 counter;
const char *name; const char *name;
...@@ -779,7 +783,7 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, ...@@ -779,7 +783,7 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port,
* after a PHY or the CPU port comes up or down. * after a PHY or the CPU port comes up or down.
*/ */
if (!phydev->link) { if (!phydev->link) {
int maxloop = 10; int ret, err;
dev_dbg(vsc->dev, "port %d: went down\n", dev_dbg(vsc->dev, "port %d: went down\n",
port); port);
...@@ -794,19 +798,17 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port, ...@@ -794,19 +798,17 @@ static void vsc73xx_adjust_link(struct dsa_switch *ds, int port,
VSC73XX_ARBDISC, BIT(port), BIT(port)); VSC73XX_ARBDISC, BIT(port), BIT(port));
/* Wait until queue is empty */ /* Wait until queue is empty */
vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, ret = read_poll_timeout(vsc73xx_read, err,
VSC73XX_ARBEMPTY, &val); err < 0 || (val & BIT(port)),
while (!(val & BIT(port))) { VSC73XX_POLL_SLEEP_US,
msleep(1); VSC73XX_POLL_TIMEOUT_US, false,
vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, vsc, VSC73XX_BLOCK_ARBITER, 0,
VSC73XX_ARBEMPTY, &val); VSC73XX_ARBEMPTY, &val);
if (--maxloop == 0) { if (ret)
dev_err(vsc->dev, dev_err(vsc->dev,
"timeout waiting for block arbiter\n"); "timeout waiting for block arbiter\n");
/* Continue anyway */ else if (err < 0)
break; dev_err(vsc->dev, "error reading arbiter\n");
}
}
/* Put this port into reset */ /* Put this port into reset */
vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG, vsc73xx_write(vsc, VSC73XX_BLOCK_MAC, port, VSC73XX_MAC_CFG,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment