[PATCH 2/3] net: miidev: Refactor timeout for aneg

Wolfram Sang w.sang at pengutronix.de
Wed Mar 21 07:18:44 EDT 2012


First check the status at least once, then do timeout checks. Minor
cleanups also.

Signed-off-by: Wolfram Sang <w.sang at 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




More information about the barebox mailing list