Skip to content

Commit

Permalink
dsa: mv88e6xxx: Timeout based on iterations, not time
Browse files Browse the repository at this point in the history
The mv88e6xxx driver times out operations on the switch based on
looping until an elapsed wall clock time is reached. However, if
usleep_range() sleeps much longer than expected, it could timeout with
an error without actually checking to see if the devices has completed
the operation. So replace the elapsed time with a fixed upper bound on
the number of loops.

Testing on various switches has shown that switches takes either 0 or
1 iteration, so a maximum of 16 iterations is a safe limit.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Andrew Lunn authored and David S. Miller committed Aug 20, 2016
1 parent 7a7e780 commit 6441e66
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions drivers/net/dsa/mv88e6xxx/chip.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
static int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg,
u16 mask)
{
unsigned long timeout = jiffies + HZ / 10;
int i;

while (time_before(jiffies, timeout)) {
for (i = 0; i < 16; i++) {
u16 val;
int err;

Expand Down Expand Up @@ -375,7 +375,7 @@ static int _mv88e6xxx_reg_write(struct mv88e6xxx_chip *chip, int addr,
static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
{
int ret;
unsigned long timeout;
int i;

ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_CONTROL);
if (ret < 0)
Expand All @@ -386,8 +386,7 @@ static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
if (ret)
return ret;

timeout = jiffies + 1 * HZ;
while (time_before(jiffies, timeout)) {
for (i = 0; i < 16; i++) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_STATUS);
if (ret < 0)
return ret;
Expand All @@ -403,8 +402,7 @@ static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)

static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
{
int ret, err;
unsigned long timeout;
int ret, err, i;

ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_CONTROL);
if (ret < 0)
Expand All @@ -415,8 +413,7 @@ static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
if (err)
return err;

timeout = jiffies + 1 * HZ;
while (time_before(jiffies, timeout)) {
for (i = 0; i < 16; i++) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_STATUS);
if (ret < 0)
return ret;
Expand Down

0 comments on commit 6441e66

Please sign in to comment.