MDIO bus timeout issues on Dreamplug
Subsystems (2)
cover MDIO bus timeout issues on Dreamplug
Hello,
I just upgraded my Dreamplug to kernel 3.12-rc4 and began encountering timeout errors in the log, like the following :-
orion-mdio f1072004.mdio-bus: Timeout when reading PHY
I discovered that the mv643xx_eth driver had been converted to use the mvmdio driver to talk to the PHY rather than the old code that was embedded in the driver. The new code had some inconsistent timeouts and always polled for a response rather than using the interrupt, where available. The timeout was 1ms when polling but the Dreamplug can take up to 4.9ms to respond.
So, making reference to the old 3.9 driver I changed the mvmdio driver to have more consistent timeouts and use interrupts to poll, where available. I set the timeout to 10ms. Patches 1 and 2 do this.
I got carried away checking the size of the code and patch 3 is a simple optimisation to reduce the code size. The final patch updates the documentation in mvmdio to make it reflect the current situation.
I have tested the patches on my Dreamplug and Mirabox and have not encountered any issues.
One final thing I noticed when testing: you can unload the mvmdio driver and the machine will crash shortly after. I tried to understand how the module reference counting would apply to these kinds of drivers and got a bit stuck. I think these modules should not be unloadable while there is an ethernet driver that uses them.
Regards,
Leigh.
Leigh Brown (4):
net: mvmdio: make orion_mdio_wait_ready consistent
net: mvmdio: orion_mdio_ready: remove manual poll
net: mvmdio: slight optimisation of orion_mdio_write
net: mvmdio: doc: mvmdio now used by mv643xx_eth
drivers/net/ethernet/marvell/mvmdio.c | 93 +++++++++++++++------------------ 1 file changed, 42 insertions(+), 51 deletions(-)
Signature · 1 line
1.7.10.4
RFC PATCH 1/4 net: mvmdio: make orion_mdio_wait_ready consistent
Amend orion_mdio_wait_ready so that the same timeout is used when polling or using wait_event_timeout. Set the timeout to 10ms.
Generate the same log message at timeout when polling or using wait_event_timeout.
--- drivers/net/ethernet/marvell/mvmdio.c | 41 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 19 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +22 -19
@@ -44,6 +44,13 @@#define MVMDIO_ERR_INT_SMI_DONE 0x00000010#define MVMDIO_ERR_INT_MASK 0x0080 +/* +* Testing on a Dreamplug showed that the SMI interface took an average of +* 3.2ms to respond, with a maximum time of 4.9ms. +*/ +#define MVMDIO_SMI_TIMEOUT 10000/* 10000us = 10ms */ +#define MVMDIO_SMI_POLL_INTERVAL 10 +struct orion_mdio_dev {struct mutex lock;void __iomem *regs;
@@ -70,32 +77,28 @@ static int orion_mdio_wait_ready(struct mii_bus *bus)struct orion_mdio_dev *dev = bus->priv;int count; -if (dev->err_interrupt <=0 ) { - count =0 ; -while (1 ) { +if (dev->err_interrupt <=0 ) +for (count =MVMDIO_SMI_TIMEOUT /MVMDIO_SMI_POLL_INTERVAL ; + count >0 ; + --count) {if (orion_mdio_smi_is_done (dev)) -break ; - -if (count >100 ) { -dev_err (bus->parent, -"Timeout: SMI busy for too long\n" ); -return -ETIMEDOUT ; - } +return 0 ; -udelay (10 ); - count++; +udelay (MVMDIO_SMI_POLL_INTERVAL ); } - }else { -if (!orion_mdio_smi_is_done (dev)) { +else { +if (!orion_mdio_smi_is_done (dev))wait_event_timeout (dev->smi_busy_wait,orion_mdio_smi_is_done (dev), -msecs_to_jiffies (100 )); -if (!orion_mdio_smi_is_done (dev)) -return -ETIMEDOUT ; - } +usecs_to_jiffies (MVMDIO_SMI_TIMEOUT )); + +if (orion_mdio_smi_is_done (dev)) +return 0 ; } -return 0 ; +dev_err (bus->parent, +"Timeout: SMI busy for too long\n" ); +return -ETIMEDOUT ; } static int orion_mdio_read(struct mii_bus *bus, int mii_id,
Signature · 1 line
1.7.10.4
RFC PATCH 2/4 net: mvmdio: orion_mdio_ready: remove manual poll
In reply to Leigh BrownReplace manual poll of MVMDIO_SMI_READ_VALID with a call to orion_mdio_wait_ready. This ensures a consistent timeout and avoids a busy loop where the hardware supports it.
--- drivers/net/ethernet/marvell/mvmdio.c | 34 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 21 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +13 -21
@@ -105,43 +105,35 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id, int regnum) {struct orion_mdio_dev *dev = bus->priv; -int count;u32 val;int ret;mutex_lock (&dev->lock); ret =orion_mdio_wait_ready (bus); -if (ret <0 ) { -mutex_unlock (&dev->lock); -return ret; - } +if (ret <0 ) + goto out;writel (((mii_id <<MVMDIO_SMI_PHY_ADDR_SHIFT ) | (regnum <<MVMDIO_SMI_PHY_REG_SHIFT ) |MVMDIO_SMI_READ_OPERATION ), dev->regs); -/* Wait for the value to become available */ - count =0 ; -while (1 ) { - val =readl (dev->regs); -if (val &MVMDIO_SMI_READ_VALID ) -break ; - -if (count >100 ) { -dev_err (bus->parent,"Timeout when reading PHY\n" ); -mutex_unlock (&dev->lock); -return -ETIMEDOUT ; - } + ret =orion_mdio_wait_ready (bus); +if (ret <0 ) + goto out; -udelay (10 ); - count++; + val =readl (dev->regs); +if (!(val &MVMDIO_SMI_READ_VALID )) { +dev_err (bus->parent,"SMI bus read not valid\n" ); + ret = -ENODEV ; + goto out; } + ret = val &0xFFFF ; +out:mutex_unlock (&dev->lock); - -return val &0xFFFF ; +return ret; } static int orion_mdio_write(struct mii_bus *bus, int mii_id,
Signature · 1 line
1.7.10.4
RFC PATCH 3/4 net: mvmdio: slight optimisation of orion_mdio_write
In reply to Leigh BrownMake only a single call to mutex_unlock in orion_mdio_write.
--- drivers/net/ethernet/marvell/mvmdio.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +4 -6
@@ -145,10 +145,8 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id,mutex_lock (&dev->lock); ret =orion_mdio_wait_ready (bus); -if (ret <0 ) { -mutex_unlock (&dev->lock); -return ret; - } +if (ret !=0 ) + goto out; writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | (regnum << MVMDIO_SMI_PHY_REG_SHIFT) |
@@ -156,9 +154,9 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id, (value << MVMDIO_SMI_DATA_SHIFT)), dev->regs); +out:mutex_unlock (&dev->lock); - -return 0 ; +return ret; }static int orion_mdio_reset (struct mii_bus *bus)
Signature · 1 line
1.7.10.4
RFC PATCH 4/4 net: mvmdio: doc: mvmdio now used by mv643xx_eth
In reply to Leigh BrownAmend the documentation in the mvmdio driver to note the fact that it is now used by both the mvneta and mv643xx_eth drivers.
--- drivers/net/ethernet/marvell/mvmdio.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +3 -5
@@ -4,11 +4,9 @@* Since the MDIO interface of Marvell network interfaces is shared * between all network interfaces, having a single driver allows to * handle concurrent accesses properly (you may have four Ethernet -* ports, but they in fact share the same SMI interface to access the -* MDIO bus). Moreover, this MDIO interface code is similar between -* the mv643xx_eth driver and the mvneta driver. For now, it is only -* used by the mvneta driver, but it could later be used by the -* mv643xx_eth driver as well. +* ports, but they in fact share the same SMI interface to access +* the MDIO bus). This driver is currently used by the mvneta and +* mv643xx_eth drivers. * * Copyright (C) 2012 Marvell *
Signature · 1 line
1.7.10.4
Re: [PATCH RFC 1/4] net: mvmdio: make orion_mdio_wait_ready consistent
In reply to Leigh BrownQuoted 43 lines · Leigh Brown
Amend
orion_mdio_wait_readyso that the same timeout is used when polling or usingwait_event_timeout. Set the timeout to 10ms.Generate the same log message at timeout when polling or using
wait_event_timeout.Signed-off-by Leigh Brown <[email protected]>--- drivers/net/ethernet/marvell/mvmdio.c | 41 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 19 deletions(-)drivers/net/ethernet/marvell/mvmdio.c +11
-5@@ -44,6 +44,13 @@#define MVMDIO_ERR_INT_SMI_DONE 0x00000010#define MVMDIO_ERR_INT_MASK 0x0080 +/* +* Testing on a Dreamplug showed that the SMI interface took an average of +* 3.2ms to respond, with a maximum time of 4.9ms. +*/ +#define MVMDIO_SMI_TIMEOUT 10000/* 10000us = 10ms */ +#define MVMDIO_SMI_POLL_INTERVAL 10 +struct orion_mdio_dev {struct mutex lock;void __iomem *regs;@@ -70,32 +77,28 @@ static int orion_mdio_wait_ready(struct mii_bus *bus)struct orion_mdio_dev *dev = bus->priv;int count; -if (dev->err_interrupt <=0 ) { - count =0 ; -while (1 ) { +if (dev->err_interrupt <=0 ) +for (count =MVMDIO_SMI_TIMEOUT /MVMDIO_SMI_POLL_INTERVAL ; + count >0 ; + --count) {if (orion_mdio_smi_is_done (dev)) -break ; -
drivers/net/ethernet/marvell/mvmdio.c static int orion_mdio_wait_ready(struct mii_bus *bus) · line 87
Quoted 10 lines
drivers/net/ethernet/marvell/mvmdio.c +2
-7-if (count >100 ) { -dev_err (bus->parent, -"Timeout: SMI busy for too long\n" ); -return -ETIMEDOUT ; - } +return 0 ; -udelay (10 ); - count++; +udelay (MVMDIO_SMI_POLL_INTERVAL );
Leigh,
this isn't happening in interrupt context, is it? According to Documentation/timers/timers-howto.txt starting from 10us you should use usleep_range instead. I guess it isn't really critical but IMHO sleeping is always better than delay.
Sebastian
Quoted 25 lines
drivers/net/ethernet/marvell/mvmdio.c +9
-7} - }else { -if (!orion_mdio_smi_is_done (dev)) { +else { +if (!orion_mdio_smi_is_done (dev))wait_event_timeout (dev->smi_busy_wait,orion_mdio_smi_is_done (dev), -msecs_to_jiffies (100 )); -if (!orion_mdio_smi_is_done (dev)) -return -ETIMEDOUT ; - } +usecs_to_jiffies (MVMDIO_SMI_TIMEOUT )); + +if (orion_mdio_smi_is_done (dev)) +return 0 ; } -return 0 ; +dev_err (bus->parent, +"Timeout: SMI busy for too long\n" ); +return -ETIMEDOUT ; } static int orion_mdio_read(struct mii_bus *bus, int mii_id,
v2 cover MDIO bus timeout issues on Dreamplug
In reply to Leigh BrownThanks to the comment from Sebastian I did some more investigation and discovered that almost everything about my analysis was wrong (woops). The patch itself wasn't too bad though.
In terms of timings, I don't believe the timeout was due to the SMI bus taking too long to respond because when I have repeated my testing (this time disabling interrupts whilst waiting), I have found that the maximum time that my Dreamplug takes to respond was about 95us (and 43us on the Mirabox, which polls). So I think the root cause of the problem was that interrupt handler was interfering with the polling in some way.
I have therefore amended the first patch to use usleep_range to sleep instead of busy wait as suggested by Sebastian, and set the timeout to 1ms. I've tested this on both the Dreamplug and Mirabox and have seen no timeouts at all.
The second, third and fourth patches are pretty much the same as before.
If I receive no comments who do I submit this to for inclusion?
Regards,
Leigh.
Leigh Brown (4):
net: mvmdio: make orion_mdio_wait_ready consistent
net: mvmdio: orion_mdio_ready: remove manual poll
net: mvmdio: slight optimisation of orion_mdio_write
net: mvmdio: doc: mvmdio now used by mv643xx_eth
drivers/net/ethernet/marvell/mvmdio.c | 107 ++++++++++++++++----------------- 1 file changed, 52 insertions(+), 55 deletions(-)
Signature · 1 line
1.7.10.4
RFC PATCH v2 1/4 net: mvmdio: make orion_mdio_wait_ready consistent
Amend orion_mdio_wait_ready so that the same timeout is used when polling or using wait_event_timeout. Set the timeout to 1ms.
Replace udelay with usleep_range to avoid a busy loop, and set the polling interval range as 45us to 55us, so that the first sleep will be enough in almost all cases.
Generate the same log message at timeout when polling or using wait_event_timeout.
--- drivers/net/ethernet/marvell/mvmdio.c | 51 +++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 21 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +30 -21
@@ -44,6 +44,15 @@#define MVMDIO_ERR_INT_SMI_DONE 0x00000010#define MVMDIO_ERR_INT_MASK 0x0080 +/* +* SMI Timeout measurements: +* - Kirkwood 88F6281 (Globalscale Dreamplug): 45us to 95us (Interrupt) +* - Armada 370 (Globalscale Mirabox): 41us to 43us (Polled) +*/ +#define MVMDIO_SMI_TIMEOUT 1000/* 1000us = 1ms */ +#define MVMDIO_SMI_POLL_INTERVAL_MIN 45 +#define MVMDIO_SMI_POLL_INTERVAL_MAX 55 +struct orion_mdio_dev {struct mutex lock;void __iomem *regs;
@@ -68,34 +77,34 @@ static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev)static int orion_mdio_wait_ready (struct mii_bus *bus) {struct orion_mdio_dev *dev = bus->priv; -int count; +unsigned long timeout =usecs_to_jiffies (MVMDIO_SMI_TIMEOUT ); +unsigned long end = jiffies + timeout; +int timedout =0 ; -if (dev->err_interrupt <=0 ) { - count =0 ; -while (1 ) { -if (orion_mdio_smi_is_done (dev)) +while (1 ) { +if (orion_mdio_smi_is_done (dev)) +return 0 ; +else +if (timedout)break ; -if (count >100 ) { -dev_err (bus->parent, -"Timeout: SMI busy for too long\n" ); -return -ETIMEDOUT ; - } +if (dev->err_interrupt <=0 ) { +usleep_range (MVMDIO_SMI_POLL_INTERVAL_MIN , +MVMDIO_SMI_POLL_INTERVAL_MAX ); -udelay (10 ); - count++; - } - }else { -if (!orion_mdio_smi_is_done (dev)) { +if (time_is_before_jiffies (end)) + ++timedout; + }else {wait_event_timeout (dev->smi_busy_wait, -orion_mdio_smi_is_done (dev), -msecs_to_jiffies (100 )); -if (!orion_mdio_smi_is_done (dev)) -return -ETIMEDOUT ; - } +orion_mdio_smi_is_done (dev), + timeout); + + ++timedout; + } } -return 0 ; +dev_err (bus->parent,"Timeout: SMI busy for too long\n" ); +return -ETIMEDOUT ; } static int orion_mdio_read(struct mii_bus *bus, int mii_id,
Signature · 1 line
1.7.10.4
RFC PATCH v2 2/4 net: mvmdio: orion_mdio_ready: remove manual poll
In reply to Leigh BrownReplace manual poll of MVMDIO_SMI_READ_VALID with a call to orion_mdio_wait_ready. This ensures a consistent timeout, eliminates a busy loop, and allows for use of interrupts on systems that support them.
--- drivers/net/ethernet/marvell/mvmdio.c | 36 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 22 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +14 -22
@@ -111,43 +111,35 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id, int regnum) {struct orion_mdio_dev *dev = bus->priv; -int count;u32 val;int ret;mutex_lock (&dev->lock); ret =orion_mdio_wait_ready (bus); -if (ret <0 ) { -mutex_unlock (&dev->lock); -return ret; - } +if (ret <0 ) + goto out;writel (((mii_id <<MVMDIO_SMI_PHY_ADDR_SHIFT ) | (regnum <<MVMDIO_SMI_PHY_REG_SHIFT ) |MVMDIO_SMI_READ_OPERATION ), dev->regs); -/* Wait for the value to become available */ - count =0 ; -while (1 ) { - val =readl (dev->regs); -if (val &MVMDIO_SMI_READ_VALID ) -break ; - -if (count >100 ) { -dev_err (bus->parent,"Timeout when reading PHY\n" ); -mutex_unlock (&dev->lock); -return -ETIMEDOUT ; - } - -udelay (10 ); - count++; + ret =orion_mdio_wait_ready (bus); +if (ret <0 ) + goto out; + + val =readl (dev->regs); +if (!(val &MVMDIO_SMI_READ_VALID )) { +dev_err (bus->parent,"SMI bus read not valid\n" ); + ret = -ENODEV ; + goto out; } + ret = val &0xFFFF ; +out:mutex_unlock (&dev->lock); - -return val &0xFFFF ; +return ret; } static int orion_mdio_write(struct mii_bus *bus, int mii_id,
Signature · 1 line
1.7.10.4
RFC PATCH v2 3/4 net: mvmdio: slight optimisation of orion_mdio_write
In reply to Leigh BrownMake only a single call to mutex_unlock in orion_mdio_write.
--- drivers/net/ethernet/marvell/mvmdio.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +4 -6
@@ -151,10 +151,8 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id,mutex_lock (&dev->lock); ret =orion_mdio_wait_ready (bus); -if (ret <0 ) { -mutex_unlock (&dev->lock); -return ret; - } +if (ret !=0 ) + goto out; writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | (regnum << MVMDIO_SMI_PHY_REG_SHIFT) |
@@ -162,9 +160,9 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id, (value << MVMDIO_SMI_DATA_SHIFT)), dev->regs); +out:mutex_unlock (&dev->lock); - -return 0 ; +return ret; }static int orion_mdio_reset (struct mii_bus *bus)
Signature · 1 line
1.7.10.4
RFC PATCH v2 4/4 net: mvmdio: doc: mvmdio now used by mv643xx_eth
In reply to Leigh BrownAmend the documentation in the mvmdio driver to note the fact that it is now used by both the mvneta and mv643xx_eth drivers.
--- drivers/net/ethernet/marvell/mvmdio.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +3 -5
@@ -4,11 +4,9 @@* Since the MDIO interface of Marvell network interfaces is shared * between all network interfaces, having a single driver allows to * handle concurrent accesses properly (you may have four Ethernet -* ports, but they in fact share the same SMI interface to access the -* MDIO bus). Moreover, this MDIO interface code is similar between -* the mv643xx_eth driver and the mvneta driver. For now, it is only -* used by the mvneta driver, but it could later be used by the -* mv643xx_eth driver as well. +* ports, but they in fact share the same SMI interface to access +* the MDIO bus). This driver is currently used by the mvneta and +* mv643xx_eth drivers. * * Copyright (C) 2012 Marvell *
Signature · 1 line
1.7.10.4
Leigh,
Thanks for getting the bottom of this!
Quoted 17 lines · Leigh Brown
Thanks to the comment from Sebastian I did some more investigation and discovered that almost everything about my analysis was wrong (woops). The patch itself wasn't too bad though.
In terms of timings, I don't believe the timeout was due to the SMI bus taking too long to respond because when I have repeated my testing (this time disabling interrupts whilst waiting), I have found that the maximum time that my Dreamplug takes to respond was about 95us (and 43us on the Mirabox, which polls). So I think the root cause of the problem was that interrupt handler was interfering with the polling in some way.
I have therefore amended the first patch to use
usleep_rangeto sleep instead of busy wait as suggested by Sebastian, and set the timeout to 1ms. I've tested this on both the Dreamplug and Mirabox and have seen no timeouts at all.
Quoted 5 lines
The second, third and fourth patches are pretty much the same as before.
If I receive no comments who do I submit this to for inclusion?
You can can use scripts/get_maintainer.pl for this. In this case, it spits out:
"David S. Miller" <[email protected]> (commit_signer:63/70=90%) Thomas Petazzoni <[email protected]> (commit_signer:15/70=21%) Sebastian Hesselbarth <[email protected]> (commit_signer:10/70=14%) Florian Fainelli <[email protected]> (commit_signer:8/70=11%) Stephen Hemminger <[email protected]> (commit_signer:6/70=9%) netdev at vger.kernel.org (open list:NETWORKING DRIVERS) linux-kernel at vger.kernel.org (open list)
thx,
Jason.
David Miller
maintainerRe: [PATCH RFC v2 1/4] net: mvmdio: make orion_mdio_wait_ready consistent
In reply to Leigh BrownFrom: Leigh Brown <[email protected]>
Date: Thu, 24 Oct 2013 19:09:31 +0100
drivers/net/ethernet/marvell/mvmdio.c static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev) · line 89
Quoted 4 lines
drivers/net/ethernet/marvell/mvmdio.c +2
-0+else +if (timedout)break ;
Please make this:
else if (timedout) break;
David Miller
maintainerRe: [PATCH RFC v2 3/4] net: mvmdio: slight optimisation of orion_mdio_write
In reply to Leigh BrownFrom: Leigh Brown <[email protected]>
Date: Thu, 24 Oct 2013 19:09:33 +0100
Quoted 3 lines
Make only a single call to
mutex_unlockinorion_mdio_write.Signed-off-by Leigh Brown <[email protected]>
You patch does more than what you're talking about here in your commit message. In particular you're also changing the interpretation of the orion_mdio_wait_ready() return value by changing the test from < 0 to != 0.
Even if that is a legitimate change:
1) You're not describing it in the commit message@all.
2) It's a logically separate change, so should go into a completely separate patch.
v3 cover Fix MDIO bus timeout issues on Dreamplug
In reply to Leigh BrownI think I have addressed all comments.
Changes since v2:
- Fix coding style in ordio_mdio_wait_ready, as identified by David
- Remove un-needed operator change in orion_mdio_write, as identified by David
This patchset fixes an issue with the Dreamplug MDIO bus timeout since the mv643xx_eth driver was converted to use the mvmdio driver to access the bus.
Leigh Brown (4):
net: mvmdio: make orion_mdio_wait_ready consistent
net: mvmdio: orion_mdio_ready: remove manual poll
net: mvmdio: slight optimisation of orion_mdio_write
net: mvmdio: doc: mvmdio now used by mv643xx_eth
drivers/net/ethernet/marvell/mvmdio.c | 110 ++++++++++++++++------------------ 1 file changed, 53 insertions(+), 57 deletions(-)
Signature · 1 line
1.8.4.rc3
PATCH v3 1/4 net: mvmdio: make orion_mdio_wait_ready consistent
Amend orion_mdio_wait_ready so that the same timeout is used when polling or using wait_event_timeout. Set the timeout to 1ms.
Replace udelay with usleep_range to avoid a busy loop, and set the polling interval range as 45us to 55us, so that the first sleep will be enough in almost all cases.
Generate the same log message at timeout when polling or using wait_event_timeout.
--- drivers/net/ethernet/marvell/mvmdio.c | 52 ++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 22 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +30 -22
@@ -44,6 +44,15 @@#define MVMDIO_ERR_INT_SMI_DONE 0x00000010#define MVMDIO_ERR_INT_MASK 0x0080 +/* +* SMI Timeout measurements: +* - Kirkwood 88F6281 (Globalscale Dreamplug): 45us to 95us (Interrupt) +* - Armada 370 (Globalscale Mirabox): 41us to 43us (Polled) +*/ +#define MVMDIO_SMI_TIMEOUT 1000/* 1000us = 1ms */ +#define MVMDIO_SMI_POLL_INTERVAL_MIN 45 +#define MVMDIO_SMI_POLL_INTERVAL_MAX 55 +struct orion_mdio_dev {struct mutex lock;void __iomem *regs;
@@ -68,34 +77,33 @@ static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev)static int orion_mdio_wait_ready (struct mii_bus *bus) {struct orion_mdio_dev *dev = bus->priv; -int count; +unsigned long timeout =usecs_to_jiffies (MVMDIO_SMI_TIMEOUT ); +unsigned long end = jiffies + timeout; +int timedout =0 ; -if (dev->err_interrupt <=0 ) { - count =0 ; -while (1 ) { -if (orion_mdio_smi_is_done (dev)) -break ; +while (1 ) { +if (orion_mdio_smi_is_done (dev)) +return 0 ; +else if (timedout) +break ; -if (count >100 ) { -dev_err (bus->parent, -"Timeout: SMI busy for too long\n" ); -return -ETIMEDOUT ; - } +if (dev->err_interrupt <=0 ) { +usleep_range (MVMDIO_SMI_POLL_INTERVAL_MIN , +MVMDIO_SMI_POLL_INTERVAL_MAX ); -udelay (10 ); - count++; - } - }else { -if (!orion_mdio_smi_is_done (dev)) { +if (time_is_before_jiffies (end)) + ++timedout; + }else {wait_event_timeout (dev->smi_busy_wait, -orion_mdio_smi_is_done (dev), -msecs_to_jiffies (100 )); -if (!orion_mdio_smi_is_done (dev)) -return -ETIMEDOUT ; - } +orion_mdio_smi_is_done (dev), + timeout); + + ++timedout; + } } -return 0 ; +dev_err (bus->parent,"Timeout: SMI busy for too long\n" ); +return -ETIMEDOUT ; } static int orion_mdio_read(struct mii_bus *bus, int mii_id,
Signature · 1 line
1.8.4.rc3
PATCH v3 2/4 net: mvmdio: orion_mdio_ready: remove manual poll
In reply to Leigh BrownReplace manual poll of MVMDIO_SMI_READ_VALID with a call to orion_mdio_wait_ready. This ensures a consistent timeout, eliminates a busy loop, and allows for use of interrupts on systems that support them.
--- drivers/net/ethernet/marvell/mvmdio.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +13 -21
@@ -110,43 +110,35 @@ static int orion_mdio_read(struct mii_bus *bus, int mii_id, int regnum) {struct orion_mdio_dev *dev = bus->priv; -int count;u32 val;int ret;mutex_lock (&dev->lock); ret =orion_mdio_wait_ready (bus); -if (ret <0 ) { -mutex_unlock (&dev->lock); -return ret; - } +if (ret <0 ) + goto out;writel (((mii_id <<MVMDIO_SMI_PHY_ADDR_SHIFT ) | (regnum <<MVMDIO_SMI_PHY_REG_SHIFT ) |MVMDIO_SMI_READ_OPERATION ), dev->regs); -/* Wait for the value to become available */ - count =0 ; -while (1 ) { - val =readl (dev->regs); -if (val &MVMDIO_SMI_READ_VALID ) -break ; - -if (count >100 ) { -dev_err (bus->parent,"Timeout when reading PHY\n" ); -mutex_unlock (&dev->lock); -return -ETIMEDOUT ; - } + ret =orion_mdio_wait_ready (bus); +if (ret <0 ) + goto out; -udelay (10 ); - count++; + val =readl (dev->regs); +if (!(val &MVMDIO_SMI_READ_VALID )) { +dev_err (bus->parent,"SMI bus read not valid\n" ); + ret = -ENODEV ; + goto out; } + ret = val &0xFFFF ; +out:mutex_unlock (&dev->lock); - -return val &0xFFFF ; +return ret; } static int orion_mdio_write(struct mii_bus *bus, int mii_id,
Signature · 1 line
1.8.4.rc3
PATCH v3 3/4 net: mvmdio: slight optimisation of orion_mdio_write
In reply to Leigh BrownMake only a single call to mutex_unlock in orion_mdio_write.
--- drivers/net/ethernet/marvell/mvmdio.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +4 -6
@@ -150,10 +150,8 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id,mutex_lock (&dev->lock); ret =orion_mdio_wait_ready (bus); -if (ret <0 ) { -mutex_unlock (&dev->lock); -return ret; - } +if (ret <0 ) + goto out; writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) | (regnum << MVMDIO_SMI_PHY_REG_SHIFT) |
@@ -161,9 +159,9 @@ static int orion_mdio_write(struct mii_bus *bus, int mii_id, (value << MVMDIO_SMI_DATA_SHIFT)), dev->regs); +out:mutex_unlock (&dev->lock); - -return 0 ; +return ret; }static int orion_mdio_reset (struct mii_bus *bus)
Signature · 1 line
1.8.4.rc3
PATCH v3 4/4 net: mvmdio: doc: mvmdio now used by mv643xx_eth
In reply to Leigh BrownAmend the documentation in the mvmdio driver to note the fact that it is now used by both the mvneta and mv643xx_eth drivers.
--- drivers/net/ethernet/marvell/mvmdio.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/marvell/mvmdio.c +3 -5
@@ -4,11 +4,9 @@* Since the MDIO interface of Marvell network interfaces is shared * between all network interfaces, having a single driver allows to * handle concurrent accesses properly (you may have four Ethernet -* ports, but they in fact share the same SMI interface to access the -* MDIO bus). Moreover, this MDIO interface code is similar between -* the mv643xx_eth driver and the mvneta driver. For now, it is only -* used by the mvneta driver, but it could later be used by the -* mv643xx_eth driver as well. +* ports, but they in fact share the same SMI interface to access +* the MDIO bus). This driver is currently used by the mvneta and +* mv643xx_eth drivers. * * Copyright (C) 2012 Marvell *
Signature · 1 line
1.8.4.rc3
David Miller
maintainerRe: [PATCH v3 0/4] Fix MDIO bus timeout issues on Dreamplug
In reply to Leigh BrownFrom: Leigh Brown <[email protected]>
Date: Tue, 29 Oct 2013 09:33:30 +0000
Quoted 8 lines
I think I have addressed all comments.
Changes since v2:
- Fix coding style inordio_mdio_wait_ready, as identified by David
- Remove un-needed operator change inorion_mdio_write, as identified by DavidThis patchset fixes an issue with the Dreamplug MDIO bus timeout since the
mv643xx_ethdriver was converted to use the mvmdio driver to access the bus.
Series applied to net-next, thanks.