Commit 8dac428a authored by Jonas Bonn's avatar Jonas Bonn Committed by David S. Miller

ethoc: rework mdio read/write

MDIO read and write were checking whether a timeout had expired to determine
whether to recheck the result of the MDIO operation.  Under heavy CPU usage,
however, it was possible for the timeout to expire before the routine got
around to be able to check a second time even, thus erroneousy returning an
-EBUSY.

This patch changes the the MDIO IO routines to try up to five times to complete
the operation before giving up, thus lessening the dependency on CPU load.

This resolves a problem whereby a ping flood would keep the CPU so busy that
the above problem would manifest itself; the MDIO command to check link status
would fail and the interface would erroneously be shut down.
Signed-off-by: default avatarJonas Bonn <jonas@southpole.se>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fa98eb0e
...@@ -611,13 +611,13 @@ static int ethoc_poll(struct napi_struct *napi, int budget) ...@@ -611,13 +611,13 @@ static int ethoc_poll(struct napi_struct *napi, int budget)
static int ethoc_mdio_read(struct mii_bus *bus, int phy, int reg) static int ethoc_mdio_read(struct mii_bus *bus, int phy, int reg)
{ {
unsigned long timeout = jiffies + ETHOC_MII_TIMEOUT;
struct ethoc *priv = bus->priv; struct ethoc *priv = bus->priv;
int i;
ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg)); ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg));
ethoc_write(priv, MIICOMMAND, MIICOMMAND_READ); ethoc_write(priv, MIICOMMAND, MIICOMMAND_READ);
while (time_before(jiffies, timeout)) { for (i=0; i < 5; i++) {
u32 status = ethoc_read(priv, MIISTATUS); u32 status = ethoc_read(priv, MIISTATUS);
if (!(status & MIISTATUS_BUSY)) { if (!(status & MIISTATUS_BUSY)) {
u32 data = ethoc_read(priv, MIIRX_DATA); u32 data = ethoc_read(priv, MIIRX_DATA);
...@@ -625,8 +625,7 @@ static int ethoc_mdio_read(struct mii_bus *bus, int phy, int reg) ...@@ -625,8 +625,7 @@ static int ethoc_mdio_read(struct mii_bus *bus, int phy, int reg)
ethoc_write(priv, MIICOMMAND, 0); ethoc_write(priv, MIICOMMAND, 0);
return data; return data;
} }
usleep_range(100,200);
schedule();
} }
return -EBUSY; return -EBUSY;
...@@ -634,22 +633,21 @@ static int ethoc_mdio_read(struct mii_bus *bus, int phy, int reg) ...@@ -634,22 +633,21 @@ static int ethoc_mdio_read(struct mii_bus *bus, int phy, int reg)
static int ethoc_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val) static int ethoc_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
{ {
unsigned long timeout = jiffies + ETHOC_MII_TIMEOUT;
struct ethoc *priv = bus->priv; struct ethoc *priv = bus->priv;
int i;
ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg)); ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg));
ethoc_write(priv, MIITX_DATA, val); ethoc_write(priv, MIITX_DATA, val);
ethoc_write(priv, MIICOMMAND, MIICOMMAND_WRITE); ethoc_write(priv, MIICOMMAND, MIICOMMAND_WRITE);
while (time_before(jiffies, timeout)) { for (i=0; i < 5; i++) {
u32 stat = ethoc_read(priv, MIISTATUS); u32 stat = ethoc_read(priv, MIISTATUS);
if (!(stat & MIISTATUS_BUSY)) { if (!(stat & MIISTATUS_BUSY)) {
/* reset MII command register */ /* reset MII command register */
ethoc_write(priv, MIICOMMAND, 0); ethoc_write(priv, MIICOMMAND, 0);
return 0; return 0;
} }
usleep_range(100,200);
schedule();
} }
return -EBUSY; return -EBUSY;
......
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