mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] net phy: poll for a link
@ 2012-10-24 18:06 Sascha Hauer
  2012-10-24 18:33 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2012-10-24 18:06 UTC (permalink / raw)
  To: barebox

Since we have phylib we have no instance which polls for a link. This
means that network boot often bails out after a powercycle or phy reset.
This changes the link status behaviour to:

- Always check for a link if the last link test was unsuccesful
- If the last check was succesful, check for a link when the last
  check is longer than 5 seconds ago
- Try to get a link for 5 seconds.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/eth.c |   32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/net/eth.c b/net/eth.c
index f3d7bfe..5af2d09 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -128,9 +128,10 @@ int eth_complete(struct string_list *sl, char *instr)
 /*
  * Check for link if we haven't done so for longer.
  */
-static int eth_carrier_check(int force)
+static int eth_carrier_check(void)
 {
 	int ret;
+	uint64_t s;
 
 	if (!IS_ENABLED(CONFIG_PHYLIB))
 		return 0;
@@ -138,14 +139,31 @@ static int eth_carrier_check(int force)
 	if (!eth_current->phydev)
 		return 0;
 
-	if (force || is_timeout(last_link_check, 5 * SECOND)) {
+	/*
+	 * If we recently succesfully checked for a link just bail
+	 * out.
+	 */
+	if (!is_timeout(last_link_check, 5 * SECOND) &&
+			eth_current->phydev->link)
+		return 0;
+
+	s = get_time_ns();
+
+	/*
+	 * Poll for a link until we get one or we have a timeout.
+	 */
+	while (!is_timeout(s, 5 * SECOND)) {
 		ret = phy_update_status(eth_current->phydev);
 		if (ret)
 			return ret;
-		last_link_check = get_time_ns();
+
+		if (eth_current->phydev->link) {
+			last_link_check = get_time_ns();
+			return 0;
+		}
 	}
 
-	return eth_current->phydev->link ? 0 : -ENETDOWN;
+	return -ENETDOWN;
 }
 
 /*
@@ -168,7 +186,7 @@ static int eth_check_open(void)
 
 	eth_current->active = 1;
 
-	return eth_carrier_check(1);
+	return eth_carrier_check();
 }
 
 int eth_send(void *packet, int length)
@@ -179,7 +197,7 @@ int eth_send(void *packet, int length)
 	if (ret)
 		return ret;
 
-	ret = eth_carrier_check(0);
+	ret = eth_carrier_check();
 	if (ret)
 		return ret;
 
@@ -196,7 +214,7 @@ int eth_rx(void)
 	if (ret)
 		return ret;
 
-	ret = eth_carrier_check(0);
+	ret = eth_carrier_check();
 	if (ret)
 		return ret;
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-10-28 12:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-24 18:06 [PATCH] net phy: poll for a link Sascha Hauer
2012-10-24 18:33 ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-24 19:56   ` Eric Bénard
2012-10-25  8:49     ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-25  9:05       ` Eric Bénard
2012-10-25  9:11         ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-25 12:18           ` Eric Bénard
2012-10-25  6:37   ` Sascha Hauer
2012-10-28 11:21     ` Sascha Hauer
2012-10-28 12:31       ` Jean-Christophe PLAGNIOL-VILLARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox