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

* Re: [PATCH] net phy: poll for a link
  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  6:37   ` Sascha Hauer
  0 siblings, 2 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-24 18:33 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 20:06 Wed 24 Oct     , Sascha Hauer wrote:
> 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.
5 seconds is too long

and check the link is wrong you need to check the autoneg
the link may be down because no cable

Here we need to check the autoneg is finished
and the phy is up

so use phy_aneg_done and genphy_config_aneg is for this

Best Regards,
J.

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

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

* Re: [PATCH] net phy: poll for a link
  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  6:37   ` Sascha Hauer
  1 sibling, 1 reply; 10+ messages in thread
From: Eric Bénard @ 2012-10-24 19:56 UTC (permalink / raw)
  To: barebox

Hi,

Le Wed, 24 Oct 2012 20:33:59 +0200,
Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :

> On 20:06 Wed 24 Oct     , Sascha Hauer wrote:
> > 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.
> 5 seconds is too long
> 
> and check the link is wrong you need to check the autoneg
> the link may be down because no cable
> 
and the autoneg can have been successful before the cable was
removed : how to you handle this cas ?

Eric

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

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

* Re: [PATCH] net phy: poll for a link
  2012-10-24 18:33 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-10-24 19:56   ` Eric Bénard
@ 2012-10-25  6:37   ` Sascha Hauer
  2012-10-28 11:21     ` Sascha Hauer
  1 sibling, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2012-10-25  6:37 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Wed, Oct 24, 2012 at 08:33:59PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 20:06 Wed 24 Oct     , Sascha Hauer wrote:
> > 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.
> 5 seconds is too long
> 
> and check the link is wrong you need to check the autoneg
> the link may be down because no cable
> 
> Here we need to check the autoneg is finished
> and the phy is up
> 
> so use phy_aneg_done and genphy_config_aneg is for this

phy_aneg_done is not exported and genphy_config_aneg is for phy driver
use only.

Could you prepare a patch for this? You insisted hard on getting this
merged in the first place and seem to know what has to be done.

Sascha

-- 
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] 10+ messages in thread

* Re: [PATCH] net phy: poll for a link
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-25  8:49 UTC (permalink / raw)
  To: Eric Bénard; +Cc: barebox

On 21:56 Wed 24 Oct     , Eric Bénard wrote:
> Hi,
> 
> Le Wed, 24 Oct 2012 20:33:59 +0200,
> Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :
> 
> > On 20:06 Wed 24 Oct     , Sascha Hauer wrote:
> > > 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.
> > 5 seconds is too long
> > 
> > and check the link is wrong you need to check the autoneg
> > the link may be down because no cable
> > 
> and the autoneg can have been successful before the cable was
> removed : how to you handle this cas ?
the advertise tell you something change

so you need to restart the autoneg

Best Regards,
J.

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

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

* Re: [PATCH] net phy: poll for a link
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Bénard @ 2012-10-25  9:05 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Le Thu, 25 Oct 2012 10:49:02 +0200,
Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :

> On 21:56 Wed 24 Oct     , Eric Bénard wrote:
> > Hi,
> > 
> > Le Wed, 24 Oct 2012 20:33:59 +0200,
> > Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :
> > 
> > > On 20:06 Wed 24 Oct     , Sascha Hauer wrote:
> > > > 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.
> > > 5 seconds is too long
> > > 
> > > and check the link is wrong you need to check the autoneg
> > > the link may be down because no cable
> > > 
> > and the autoneg can have been successful before the cable was
> > removed : how to you handle this cas ?
> the advertise tell you something change
> 
> so you need to restart the autoneg
> 
so I don't really understand why you don't want to use the link
information which seems to be the first thing to do before trying to
launch an autoneg but why not, let see the patches when they come.

Eric

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

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

* Re: [PATCH] net phy: poll for a link
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-25  9:11 UTC (permalink / raw)
  To: Eric Bénard; +Cc: barebox

On 11:05 Thu 25 Oct     , Eric Bénard wrote:
> Le Thu, 25 Oct 2012 10:49:02 +0200,
> Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :
> 
> > On 21:56 Wed 24 Oct     , Eric Bénard wrote:
> > > Hi,
> > > 
> > > Le Wed, 24 Oct 2012 20:33:59 +0200,
> > > Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :
> > > 
> > > > On 20:06 Wed 24 Oct     , Sascha Hauer wrote:
> > > > > 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.
> > > > 5 seconds is too long
> > > > 
> > > > and check the link is wrong you need to check the autoneg
> > > > the link may be down because no cable
> > > > 
> > > and the autoneg can have been successful before the cable was
> > > removed : how to you handle this cas ?
> > the advertise tell you something change
> > 
> > so you need to restart the autoneg
> > 
> so I don't really understand why you don't want to use the link
> information which seems to be the first thing to do before trying to
> launch an autoneg but why not, let see the patches when they come.
because if the link is down and the have no advertise meens the phy is really
down and no need to wait

Best Regards,
J.

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

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

* Re: [PATCH] net phy: poll for a link
  2012-10-25  9:11         ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-10-25 12:18           ` Eric Bénard
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Bénard @ 2012-10-25 12:18 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Le Thu, 25 Oct 2012 11:11:06 +0200,
Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :

> On 11:05 Thu 25 Oct     , Eric Bénard wrote:
> > Le Thu, 25 Oct 2012 10:49:02 +0200,
> > Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :
> > 
> > > On 21:56 Wed 24 Oct     , Eric Bénard wrote:
> > > > Hi,
> > > > 
> > > > Le Wed, 24 Oct 2012 20:33:59 +0200,
> > > > Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> a écrit :
> > > > 
> > > > > On 20:06 Wed 24 Oct     , Sascha Hauer wrote:
> > > > > > 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.
> > > > > 5 seconds is too long
> > > > > 
> > > > > and check the link is wrong you need to check the autoneg
> > > > > the link may be down because no cable
> > > > > 
> > > > and the autoneg can have been successful before the cable was
> > > > removed : how to you handle this cas ?
> > > the advertise tell you something change
> > > 
> > > so you need to restart the autoneg
> > > 
> > so I don't really understand why you don't want to use the link
> > information which seems to be the first thing to do before trying to
> > launch an autoneg but why not, let see the patches when they come.
> because if the link is down and the have no advertise meens the phy is really
> down and no need to wait
> 
under which conditions can you have link down and advertise at the same
time ?

Eric

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

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

* Re: [PATCH] net phy: poll for a link
  2012-10-25  6:37   ` Sascha Hauer
@ 2012-10-28 11:21     ` Sascha Hauer
  2012-10-28 12:31       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2012-10-28 11:21 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Jean-Christophe,

On Thu, Oct 25, 2012 at 08:37:11AM +0200, Sascha Hauer wrote:
> On Wed, Oct 24, 2012 at 08:33:59PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 20:06 Wed 24 Oct     , Sascha Hauer wrote:
> > > 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.
> > 5 seconds is too long
> > 
> > and check the link is wrong you need to check the autoneg
> > the link may be down because no cable
> > 
> > Here we need to check the autoneg is finished
> > and the phy is up
> > 
> > so use phy_aneg_done and genphy_config_aneg is for this
> 
> phy_aneg_done is not exported and genphy_config_aneg is for phy driver
> use only.
> 
> Could you prepare a patch for this? You insisted hard on getting this
> merged in the first place and seem to know what has to be done.

Will you prepare a patch for this? This is really something I want to
have solved before the next release and right now I do not understand
your proposed solution to this.

Sascha


-- 
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] 10+ messages in thread

* Re: [PATCH] net phy: poll for a link
  2012-10-28 11:21     ` Sascha Hauer
@ 2012-10-28 12:31       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-10-28 12:31 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 12:21 Sun 28 Oct     , Sascha Hauer wrote:
> Jean-Christophe,
> 
> On Thu, Oct 25, 2012 at 08:37:11AM +0200, Sascha Hauer wrote:
> > On Wed, Oct 24, 2012 at 08:33:59PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > On 20:06 Wed 24 Oct     , Sascha Hauer wrote:
> > > > 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.
> > > 5 seconds is too long
> > > 
> > > and check the link is wrong you need to check the autoneg
> > > the link may be down because no cable
> > > 
> > > Here we need to check the autoneg is finished
> > > and the phy is up
> > > 
> > > so use phy_aneg_done and genphy_config_aneg is for this
> > 
> > phy_aneg_done is not exported and genphy_config_aneg is for phy driver
> > use only.
> > 
> > Could you prepare a patch for this? You insisted hard on getting this
> > merged in the first place and seem to know what has to be done.
> 
> Will you prepare a patch for this? This is really something I want to
> have solved before the next release and right now I do not understand
> your proposed solution to this.
next week maybe tuesday or wednesday
I need to finish some work on at91 for the Atmel kernel release
to fix some hw issue

The 1-wire support is needed for this

Best Regards,
J.

_______________________________________________
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