Skip to content

Commit

Permalink
Merge branch 'mv88e6xxx-fix-wait'
Browse files Browse the repository at this point in the history
Andrew Lunn says:

====================
Fix mv88e6xxx wait function

The mv88e6xxx wait function can be upset of the system has nots of
other things to do and a sleep takes a lot longer than expected. Fix
this be using a fixed number of iterations, rather than a fixed
walkclock time.

Witht that change made, it is possible to consoliate another
wait function.

A wait actually timing out should not happen and when it does, it
means something serious is wrong. Make sure an error is logged,
since not all callers will log an error.
====================

Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Aug 20, 2016
2 parents 7a7e780 + 3085355 commit 0ae940c
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 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 All @@ -325,6 +325,7 @@ static int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg,
usleep_range(1000, 2000);
}

dev_err(chip->dev, "Timeout while waiting for switch\n");
return -ETIMEDOUT;
}

Expand All @@ -333,20 +334,12 @@ static int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
u16 update)
{
u16 val;
int i, err;
int err;

/* Wait until the previous operation is completed */
for (i = 0; i < 16; ++i) {
err = mv88e6xxx_read(chip, addr, reg, &val);
if (err)
return err;

if (!(val & BIT(15)))
break;
}

if (i == 16)
return -ETIMEDOUT;
err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
if (err)
return err;

/* Set the Update bit to trigger a write operation */
val = BIT(15) | update;
Expand Down Expand Up @@ -375,7 +368,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 +379,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 +395,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 +406,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 0ae940c

Please sign in to comment.