Commit 59399c59 authored by Timur Tabi's avatar Timur Tabi Committed by David S. Miller

net/fsl_pq_mdio: use spin_event_timeout() to poll the indicator register

Macro spin_event_timeout() was designed for simple polling of hardware
registers with a timeout, so use it when we poll the MIIMIND register.
This allows us to return an error code instead of polling indefinitely.

Note that PHY_INIT_TIMEOUT is a count of loop iterations, so we can't use
it for spin_event_timeout(), which asks for microseconds.
Signed-off-by: default avatarTimur Tabi <timur@freescale.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9fa32e94
...@@ -47,6 +47,9 @@ ...@@ -47,6 +47,9 @@
#include "gianfar.h" #include "gianfar.h"
#include "fsl_pq_mdio.h" #include "fsl_pq_mdio.h"
/* Number of microseconds to wait for an MII register to respond */
#define MII_TIMEOUT 1000
struct fsl_pq_mdio_priv { struct fsl_pq_mdio_priv {
void __iomem *map; void __iomem *map;
struct fsl_pq_mdio __iomem *regs; struct fsl_pq_mdio __iomem *regs;
...@@ -64,6 +67,8 @@ struct fsl_pq_mdio_priv { ...@@ -64,6 +67,8 @@ struct fsl_pq_mdio_priv {
int fsl_pq_local_mdio_write(struct fsl_pq_mdio __iomem *regs, int mii_id, int fsl_pq_local_mdio_write(struct fsl_pq_mdio __iomem *regs, int mii_id,
int regnum, u16 value) int regnum, u16 value)
{ {
u32 status;
/* Set the PHY address and the register address we want to write */ /* Set the PHY address and the register address we want to write */
out_be32(&regs->miimadd, (mii_id << 8) | regnum); out_be32(&regs->miimadd, (mii_id << 8) | regnum);
...@@ -71,10 +76,10 @@ int fsl_pq_local_mdio_write(struct fsl_pq_mdio __iomem *regs, int mii_id, ...@@ -71,10 +76,10 @@ int fsl_pq_local_mdio_write(struct fsl_pq_mdio __iomem *regs, int mii_id,
out_be32(&regs->miimcon, value); out_be32(&regs->miimcon, value);
/* Wait for the transaction to finish */ /* Wait for the transaction to finish */
while (in_be32(&regs->miimind) & MIIMIND_BUSY) status = spin_event_timeout(!(in_be32(&regs->miimind) & MIIMIND_BUSY),
cpu_relax(); MII_TIMEOUT, 0);
return 0; return status ? 0 : -ETIMEDOUT;
} }
/* /*
...@@ -91,6 +96,7 @@ int fsl_pq_local_mdio_read(struct fsl_pq_mdio __iomem *regs, ...@@ -91,6 +96,7 @@ int fsl_pq_local_mdio_read(struct fsl_pq_mdio __iomem *regs,
int mii_id, int regnum) int mii_id, int regnum)
{ {
u16 value; u16 value;
u32 status;
/* Set the PHY address and the register address we want to read */ /* Set the PHY address and the register address we want to read */
out_be32(&regs->miimadd, (mii_id << 8) | regnum); out_be32(&regs->miimadd, (mii_id << 8) | regnum);
...@@ -99,9 +105,12 @@ int fsl_pq_local_mdio_read(struct fsl_pq_mdio __iomem *regs, ...@@ -99,9 +105,12 @@ int fsl_pq_local_mdio_read(struct fsl_pq_mdio __iomem *regs,
out_be32(&regs->miimcom, 0); out_be32(&regs->miimcom, 0);
out_be32(&regs->miimcom, MII_READ_COMMAND); out_be32(&regs->miimcom, MII_READ_COMMAND);
/* Wait for the transaction to finish */ /* Wait for the transaction to finish, normally less than 100us */
while (in_be32(&regs->miimind) & (MIIMIND_NOTVALID | MIIMIND_BUSY)) status = spin_event_timeout(!(in_be32(&regs->miimind) &
cpu_relax(); (MIIMIND_NOTVALID | MIIMIND_BUSY)),
MII_TIMEOUT, 0);
if (!status)
return -ETIMEDOUT;
/* Grab the value of the register from miimstat */ /* Grab the value of the register from miimstat */
value = in_be32(&regs->miimstat); value = in_be32(&regs->miimstat);
...@@ -144,7 +153,7 @@ int fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum) ...@@ -144,7 +153,7 @@ int fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
static int fsl_pq_mdio_reset(struct mii_bus *bus) static int fsl_pq_mdio_reset(struct mii_bus *bus)
{ {
struct fsl_pq_mdio __iomem *regs = fsl_pq_mdio_get_regs(bus); struct fsl_pq_mdio __iomem *regs = fsl_pq_mdio_get_regs(bus);
int timeout = PHY_INIT_TIMEOUT; u32 status;
mutex_lock(&bus->mdio_lock); mutex_lock(&bus->mdio_lock);
...@@ -155,12 +164,12 @@ static int fsl_pq_mdio_reset(struct mii_bus *bus) ...@@ -155,12 +164,12 @@ static int fsl_pq_mdio_reset(struct mii_bus *bus)
out_be32(&regs->miimcfg, MIIMCFG_INIT_VALUE); out_be32(&regs->miimcfg, MIIMCFG_INIT_VALUE);
/* Wait until the bus is free */ /* Wait until the bus is free */
while ((in_be32(&regs->miimind) & MIIMIND_BUSY) && timeout--) status = spin_event_timeout(!(in_be32(&regs->miimind) & MIIMIND_BUSY),
cpu_relax(); MII_TIMEOUT, 0);
mutex_unlock(&bus->mdio_lock); mutex_unlock(&bus->mdio_lock);
if (timeout < 0) { if (!status) {
printk(KERN_ERR "%s: The MII Bus is stuck!\n", printk(KERN_ERR "%s: The MII Bus is stuck!\n",
bus->name); bus->name);
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