Message ID | 1412667875-18225-4-git-send-email-claudiu.manoil@freescale.com |
---|---|
State | Accepted, archived |
Delegated to: | David Miller |
Headers | show |
From: netdev-owner@vger.kernel. > spin_event_timeout() is PPC dependent, use an arch independent > equivalent instead. I think you should white a local function/#define that expands to spin_event_timeout() on ppc and to the code below you are substituting on other architectures. > /* Wait for the transaction to finish */ > - status = spin_event_timeout(!(ioread32be(®s->miimind) & > - MIIMIND_BUSY), MII_TIMEOUT, 0); > + timeout = MII_TIMEOUT; > + while ((ioread32be(®s->miimind) & MIIMIND_BUSY) && timeout) { > + cpu_relax(); > + timeout--; > + } David -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 10/7/2014 11:12 AM, David Laight wrote: > From: netdev-owner@vger.kernel. >> spin_event_timeout() is PPC dependent, use an arch independent >> equivalent instead. > > I think you should white a local function/#define that expands to spin_event_timeout() > on ppc and to the code below you are substituting on other architectures. > >> /* Wait for the transaction to finish */ >> - status = spin_event_timeout(!(ioread32be(®s->miimind) & >> - MIIMIND_BUSY), MII_TIMEOUT, 0); >> + timeout = MII_TIMEOUT; >> + while ((ioread32be(®s->miimind) & MIIMIND_BUSY) && timeout) { >> + cpu_relax(); >> + timeout--; >> + } > > David > > > Hi David, This point is debatable. Still better than adding a new local function would be to provide an implementation for spin_even_timeout() for ARM. But it is not the place of the ethernet driver to provide an implementation of spin_event_timeout() on ARM. Instead, I opted to simplify the busy wait/ timeout mechanism in the driver using a simple and arch independent implementation replacing the PPC specific spin_event_timeout(). This timeout implementation, open-coded as a while() loop, is commonly used by other drivers too and I think that for this particular driver (fsl_pq_mdio) it is good enough to do the job, while keeping the code simple and portable. It may not be as precise as spin_event_timeout() on PPC, but good enough. Thanks, Claudiu -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/net/ethernet/freescale/fsl_pq_mdio.c b/drivers/net/ethernet/freescale/fsl_pq_mdio.c index a422838..964c6bf 100644 --- a/drivers/net/ethernet/freescale/fsl_pq_mdio.c +++ b/drivers/net/ethernet/freescale/fsl_pq_mdio.c @@ -104,7 +104,7 @@ static int fsl_pq_mdio_write(struct mii_bus *bus, int mii_id, int regnum, { struct fsl_pq_mdio_priv *priv = bus->priv; struct fsl_pq_mii __iomem *regs = priv->regs; - u32 status; + unsigned int timeout; /* Set the PHY address and the register address we want to write */ iowrite32be((mii_id << 8) | regnum, ®s->miimadd); @@ -113,10 +113,13 @@ static int fsl_pq_mdio_write(struct mii_bus *bus, int mii_id, int regnum, iowrite32be(value, ®s->miimcon); /* Wait for the transaction to finish */ - status = spin_event_timeout(!(ioread32be(®s->miimind) & - MIIMIND_BUSY), MII_TIMEOUT, 0); + timeout = MII_TIMEOUT; + while ((ioread32be(®s->miimind) & MIIMIND_BUSY) && timeout) { + cpu_relax(); + timeout--; + } - return status ? 0 : -ETIMEDOUT; + return timeout ? 0 : -ETIMEDOUT; } /* @@ -133,7 +136,7 @@ static int fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum) { struct fsl_pq_mdio_priv *priv = bus->priv; struct fsl_pq_mii __iomem *regs = priv->regs; - u32 status; + unsigned int timeout; u16 value; /* Set the PHY address and the register address we want to read */ @@ -144,10 +147,14 @@ static int fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum) iowrite32be(MII_READ_COMMAND, ®s->miimcom); /* Wait for the transaction to finish, normally less than 100us */ - status = spin_event_timeout(!(ioread32be(®s->miimind) & - (MIIMIND_NOTVALID | MIIMIND_BUSY)), - MII_TIMEOUT, 0); - if (!status) + timeout = MII_TIMEOUT; + while ((ioread32be(®s->miimind) & + (MIIMIND_NOTVALID | MIIMIND_BUSY)) && timeout) { + cpu_relax(); + timeout--; + } + + if (!timeout) return -ETIMEDOUT; /* Grab the value of the register from miimstat */ @@ -162,7 +169,7 @@ static int fsl_pq_mdio_reset(struct mii_bus *bus) { struct fsl_pq_mdio_priv *priv = bus->priv; struct fsl_pq_mii __iomem *regs = priv->regs; - u32 status; + unsigned int timeout; mutex_lock(&bus->mdio_lock); @@ -173,12 +180,15 @@ static int fsl_pq_mdio_reset(struct mii_bus *bus) iowrite32be(MIIMCFG_INIT_VALUE, ®s->miimcfg); /* Wait until the bus is free */ - status = spin_event_timeout(!(ioread32be(®s->miimind) & - MIIMIND_BUSY), MII_TIMEOUT, 0); + timeout = MII_TIMEOUT; + while ((ioread32be(®s->miimind) & MIIMIND_BUSY) && timeout) { + cpu_relax(); + timeout--; + } mutex_unlock(&bus->mdio_lock); - if (!status) { + if (!timeout) { dev_err(&bus->dev, "timeout waiting for MII bus\n"); return -EBUSY; }
spin_event_timeout() is PPC dependent, use an arch independent equivalent instead. Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com> --- v2 - none drivers/net/ethernet/freescale/fsl_pq_mdio.c | 36 ++++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-)