* [PATCH 0/3] miidev: improve phy initialization
@ 2012-03-21 11:18 Wolfram Sang
2012-03-21 11:18 ` [PATCH 1/3] net: miidev: check for errors when accessing bus in restart_aneg Wolfram Sang
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Wolfram Sang @ 2012-03-21 11:18 UTC (permalink / raw)
To: barebox
I had problems with link detection, because the PHY was put into an energy
saving mode by the kernel which made it react pretty slow. barebox failed on
that, so make the initialization more robust by adding more checks and proper
timeout mechanisms.
Wolfram Sang (3):
net: miidev: check for errors when accessing bus
net: miidev: Refactor timeout for aneg
net: miidev: properly check for MII reset
drivers/net/miidev.c | 63 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 41 insertions(+), 22 deletions(-)
--
1.7.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] net: miidev: check for errors when accessing bus in restart_aneg
2012-03-21 11:18 [PATCH 0/3] miidev: improve phy initialization Wolfram Sang
@ 2012-03-21 11:18 ` Wolfram Sang
2012-03-21 11:18 ` [PATCH 2/3] net: miidev: Refactor timeout for aneg Wolfram Sang
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2012-03-21 11:18 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
drivers/net/miidev.c | 29 +++++++++++++++++++++++------
1 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/net/miidev.c b/drivers/net/miidev.c
index d721aac..83b6fe9 100644
--- a/drivers/net/miidev.c
+++ b/drivers/net/miidev.c
@@ -30,13 +30,14 @@
int miidev_restart_aneg(struct mii_device *mdev)
{
- uint16_t status;
- int timeout;
+ int status, timeout;
/*
* Reset PHY, then delay 300ns
*/
- mii_write(mdev, mdev->address, MII_BMCR, BMCR_RESET);
+ status = mii_write(mdev, mdev->address, MII_BMCR, BMCR_RESET);
+ if (status)
+ return status;
if (mdev->flags & MIIDEV_FORCE_LINK)
return 0;
@@ -45,8 +46,14 @@ int miidev_restart_aneg(struct mii_device *mdev)
if (mdev->flags & MIIDEV_FORCE_10) {
printf("Forcing 10 Mbps ethernet link... ");
+
status = mii_read(mdev, mdev->address, MII_BMSR);
- mii_write(mdev, mdev->address, MII_BMCR, BMCR_FULLDPLX | BMCR_CTST);
+ if (status < 0)
+ return status;
+
+ status = mii_write(mdev, mdev->address, MII_BMCR, BMCR_FULLDPLX | BMCR_CTST);
+ if (status)
+ return status;
timeout = 20;
do { /* wait for link status to go down */
@@ -56,6 +63,8 @@ int miidev_restart_aneg(struct mii_device *mdev)
break;
}
status = mii_read(mdev, mdev->address, MII_BMSR);
+ if (status < 0)
+ return status;
} while (status & BMSR_LSTATUS);
} else { /* MII100 */
@@ -63,10 +72,18 @@ int miidev_restart_aneg(struct mii_device *mdev)
* Set the auto-negotiation advertisement register bits
*/
status = mii_read(mdev, mdev->address, MII_ADVERTISE);
+ if (status < 0)
+ return status;
+
status |= ADVERTISE_ALL;
- mii_write(mdev, mdev->address, MII_ADVERTISE, status);
- mii_write(mdev, mdev->address, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
+ status = mii_write(mdev, mdev->address, MII_ADVERTISE, status);
+ if (status)
+ return status;
+
+ status = mii_write(mdev, mdev->address, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
+ if (status)
+ return status;
}
return 0;
--
1.7.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] net: miidev: Refactor timeout for aneg
2012-03-21 11:18 [PATCH 0/3] miidev: improve phy initialization Wolfram Sang
2012-03-21 11:18 ` [PATCH 1/3] net: miidev: check for errors when accessing bus in restart_aneg Wolfram Sang
@ 2012-03-21 11:18 ` Wolfram Sang
2012-03-21 11:18 ` [PATCH 3/3] net: miidev: properly check for MII reset Wolfram Sang
2012-03-23 7:23 ` [PATCH 0/3] miidev: improve phy initialization Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2012-03-21 11:18 UTC (permalink / raw)
To: barebox
First check the status at least once, then do timeout checks. Minor
cleanups also.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
drivers/net/miidev.c | 17 ++++++-----------
1 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/net/miidev.c b/drivers/net/miidev.c
index 83b6fe9..16a3461 100644
--- a/drivers/net/miidev.c
+++ b/drivers/net/miidev.c
@@ -91,27 +91,22 @@ int miidev_restart_aneg(struct mii_device *mdev)
int miidev_wait_aneg(struct mii_device *mdev)
{
- uint64_t start;
int status;
+ uint64_t start = get_time_ns();
if (mdev->flags & MIIDEV_FORCE_LINK)
return 0;
- /*
- * Wait for AN completion
- */
- start = get_time_ns();
do {
+ status = mii_read(mdev, mdev->address, MII_BMSR);
+ if (status < 0)
+ return status;
+
if (is_timeout(start, 5 * SECOND)) {
printf("%s: Autonegotiation timeout\n", mdev->cdev.name);
- return -1;
+ return -ETIMEDOUT;
}
- status = mii_read(mdev, mdev->address, MII_BMSR);
- if (status < 0) {
- printf("%s: Autonegotiation failed. status: 0x%04x\n", mdev->cdev.name, status);
- return -1;
- }
} while (!(status & BMSR_LSTATUS));
return 0;
--
1.7.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] net: miidev: properly check for MII reset
2012-03-21 11:18 [PATCH 0/3] miidev: improve phy initialization Wolfram Sang
2012-03-21 11:18 ` [PATCH 1/3] net: miidev: check for errors when accessing bus in restart_aneg Wolfram Sang
2012-03-21 11:18 ` [PATCH 2/3] net: miidev: Refactor timeout for aneg Wolfram Sang
@ 2012-03-21 11:18 ` Wolfram Sang
2012-03-23 7:23 ` [PATCH 0/3] miidev: improve phy initialization Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2012-03-21 11:18 UTC (permalink / raw)
To: barebox
Wait until the reset bit is actually cleared instead of some
arbitrary delay (which caused problems with a PHY which was in some
energy saving mode).
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
drivers/net/miidev.c | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/net/miidev.c b/drivers/net/miidev.c
index 16a3461..3b73133 100644
--- a/drivers/net/miidev.c
+++ b/drivers/net/miidev.c
@@ -31,19 +31,26 @@
int miidev_restart_aneg(struct mii_device *mdev)
{
int status, timeout;
+ uint64_t start;
- /*
- * Reset PHY, then delay 300ns
- */
status = mii_write(mdev, mdev->address, MII_BMCR, BMCR_RESET);
if (status)
return status;
+ start = get_time_ns();
+ do {
+ status = mii_read(mdev, mdev->address, MII_BMCR);
+ if (status < 0)
+ return status;
+
+ if (is_timeout(start, SECOND))
+ return -ETIMEDOUT;
+
+ } while (status & BMCR_RESET);
+
if (mdev->flags & MIIDEV_FORCE_LINK)
return 0;
- udelay(1000);
-
if (mdev->flags & MIIDEV_FORCE_10) {
printf("Forcing 10 Mbps ethernet link... ");
--
1.7.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] miidev: improve phy initialization
2012-03-21 11:18 [PATCH 0/3] miidev: improve phy initialization Wolfram Sang
` (2 preceding siblings ...)
2012-03-21 11:18 ` [PATCH 3/3] net: miidev: properly check for MII reset Wolfram Sang
@ 2012-03-23 7:23 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-03-23 7:23 UTC (permalink / raw)
To: Wolfram Sang; +Cc: barebox
On Wed, Mar 21, 2012 at 12:18:42PM +0100, Wolfram Sang wrote:
> I had problems with link detection, because the PHY was put into an energy
> saving mode by the kernel which made it react pretty slow. barebox failed on
> that, so make the initialization more robust by adding more checks and proper
> timeout mechanisms.
>
> Wolfram Sang (3):
> net: miidev: check for errors when accessing bus
> net: miidev: Refactor timeout for aneg
> net: miidev: properly check for MII reset
Applied, thanks
Sascha
>
> drivers/net/miidev.c | 63 ++++++++++++++++++++++++++++++++-----------------
> 1 files changed, 41 insertions(+), 22 deletions(-)
>
> --
> 1.7.9.1
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-03-23 7:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-21 11:18 [PATCH 0/3] miidev: improve phy initialization Wolfram Sang
2012-03-21 11:18 ` [PATCH 1/3] net: miidev: check for errors when accessing bus in restart_aneg Wolfram Sang
2012-03-21 11:18 ` [PATCH 2/3] net: miidev: Refactor timeout for aneg Wolfram Sang
2012-03-21 11:18 ` [PATCH 3/3] net: miidev: properly check for MII reset Wolfram Sang
2012-03-23 7:23 ` [PATCH 0/3] miidev: improve phy initialization Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox