net/eth: set status to active before calling init
Subsystems (2)
PATCH 1/3 net/eth: set status to active before calling init
If we set the status after successful init call then we get in trouble if stdout (or setderr) is set to netconsole. If we are going to use one of those (lets say printf) during ->init() the following happens:
- network is of (state passive)
- we switch on netconsole
- nc_getc() gets called
- in NetLoop() we switch on ethernet via eth_init()
- we end up in tsec_init() (inc case we use the tsec driver). Here we call a printf()
- That printf() ends up in nc_puts() because netconsole is our default output.
- The state is not active yet, so we call eth_init() once again.
- and we are again in tsec_init(). Another printf() is waiting. However, due to the recursion check nc_puts() returns early before doing anything.
- we return from each function. Sine nc_puts() thinks that it was in charge of enabling the ethernet, it disables it before leaving.
- We return now to the top-most eth_init() function. Since everything went fine, it sets the status to active. In reality the network is switched off.
- nc_getc() gets called over and over to receive new packets. Sadly the nic is disabled and new network packets won't be noticed.
This patch sets the network status early so nc_puts() does not get confused and disables the network interface in case of a printf() on its way.
--- net/eth.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
net/eth.c +7 -4
@@ -380,14 +380,17 @@ int eth_init(bd_t *bis) old_current = eth_current;do { +int old_state; +debug ("Trying %s\n" , eth_current->name); -if (eth_current->init (eth_current,bis) >=0 ) { - eth_current->state =ETH_STATE_ACTIVE ; - + old_state = eth_current->state; + eth_current->state =ETH_STATE_ACTIVE ; +if (eth_current->init (eth_current,bis) >=0 )return 0 ; - } +debug ("FAIL\n" ); + eth_current->state = old_state;eth_try_another (0 ); }while (old_current != eth_current);
Signature · 1 line
1.7.9.1
PATCH 2/3 net/tsec: convert the printf() to serial_printf()
In case we use netconsole for stdout and something goes wrong here and we run into one of this printf() then there is no point of sending this over network again since it is likely that will fail again.
--- drivers/net/tsec.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/tsec.c +6 -6
@@ -199,7 +199,7 @@ static void adjust_link(struct tsec_private *priv, struct phy_device *phydev)u32 ecntrl, maccfg2;if (!phydev->link) { -printf ("%s: No link.\n" , phydev->dev->name); +serial_printf ("%s: No link.\n" , phydev->dev->name);return ; }
@@ -228,14 +228,14 @@ static void adjust_link(struct tsec_private *priv, struct phy_device *phydev) ecntrl |=ECNTRL_R100 ;break ;default : -printf ("%s: Speed was bad\n" , phydev->dev->name); +serial_printf ("%s: Speed was bad\n" , phydev->dev->name);break ; }out_be32 (®s->ecntrl, ecntrl);out_be32 (®s->maccfg2, maccfg2); -printf ("Speed: %d, %s duplex%s\n" , phydev->speed, +serial_printf ("Speed: %d, %s duplex%s\n" , phydev->speed, (phydev->duplex) ?"full" :"half" , (phydev->port ==PORT_FIBRE ) ?", fiber mode" :"" ); }
@@ -287,7 +287,7 @@ void redundant_init(struct eth_device *dev)/* Wait for buffer to be received */ for (t =0 ; rtx.rxbd[rxIdx].status &RXBD_EMPTY ; t++) {if (t >=10 *TOUT_LOOP ) { -printf ("%s: tsec: rx error\n" , dev->name); +serial_printf ("%s: tsec: rx error\n" , dev->name);break ; } }
@@ -305,7 +305,7 @@ void redundant_init(struct eth_device *dev)out_be32 (®s->rstat,RSTAT_CLEAR_RHALT ); }if (fail) { -printf ("loopback recv packet error!\n" ); +serial_printf ("loopback recv packet error!\n" );clrbits_be32 (®s->maccfg1,MACCFG1_RX_EN );udelay (1000 );setbits_be32 (®s->maccfg1,MACCFG1_RX_EN );
@@ -428,7 +428,7 @@ static int tsec_recv(struct eth_device *dev)if (!(rtx.rxbd[rxIdx].status &RXBD_STATS )) {NetReceive (NetRxPackets[rxIdx], length -4 ); }else { -printf ("Got error %x\n" , +serial_printf ("Got error %x\n" , (rtx.rxbd[rxIdx].status &RXBD_STATS )); }
Signature · 1 line
1.7.9.1
PATCH 3/3 net/tsec: Don't tell the link status if used with netconsole
In reply to Sebastian Andrzej SiewiorSince we start/stop the network after each character we see that line printed a lot.
--- drivers/net/tsec.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/tsec.c +5 -3
@@ -235,9 +235,11 @@ static void adjust_link(struct tsec_private *priv, struct phy_device *phydev)out_be32 (®s->ecntrl, ecntrl);out_be32 (®s->maccfg2, maccfg2); -serial_printf ("Speed: %d, %s duplex%s\n" , phydev->speed, - (phydev->duplex) ?"full" :"half" , - (phydev->port ==PORT_FIBRE ) ?", fiber mode" :"" ); +if (strcmp (getenv ("stdout" ),"nc" )) +serial_printf ("Speed: %d, %s duplex%s\n" , phydev->speed, + (phydev->duplex) ?"full" :"half" , + (phydev->port ==PORT_FIBRE ) ?", fiber mode" + :"" ); }#ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129
Signature · 1 line
1.7.9.1
PATCH 3/3 net/tsec: Don't tell the link status if used with netconsole
drivers/net/tsec.c static void adjust_link(struct tsec_private *priv, struct phy_device *phydev) · line 238
Quoted 4 lines · On Friday 23 March 2012 16:11:19 Sebastian Andrzej Siewior wrote:
drivers/net/tsec.c +1
-0+if (strcmp (getenv ("stdout" ),"nc" ))
i really don't like special casing devices like this
drivers/net/tsec.c static void adjust_link(struct tsec_private *priv, struct phy_device *phydev) · line 242
Quoted 7 lines
drivers/net/tsec.c +4
-3-serial_printf ("Speed: %d, %s duplex%s\n" , phydev->speed, - (phydev->duplex) ?"full" :"half" , - (phydev->port ==PORT_FIBRE ) ?", fiber mode" :"" ); +serial_printf ("Speed: %d, %s duplex%s\n" , phydev->speed, + (phydev->duplex) ?"full" :"half" , + (phydev->port ==PORT_FIBRE ) ?", fiber mode" + :"" );
why not just delete this line completely ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120403/6e0ba6f0/attachment.pgp>
PATCH 3/3 net/tsec: Don't tell the link status if used with netconsole
Quoted 8 lines · Mike Frysinger
drivers/net/tsec.c static void adjust_link(struct tsec_private *priv, struct phy_device *phydev) · line 238
Quoted 4 lines · On Friday 23 March 2012 16:11:19 Sebastian Andrzej Siewior wrote:
drivers/net/tsec.c +1
-0+if (strcmp (getenv ("stdout" ),"nc" ))i really don't like special casing devices like this
Quoted 9 lines
drivers/net/tsec.c static void adjust_link(struct tsec_private *priv, struct phy_device *phydev) · line 242
Quoted 7 lines
drivers/net/tsec.c +4
-3-serial_printf ("Speed: %d, %s duplex%s\n" , phydev->speed, - (phydev->duplex) ?"full" :"half" , - (phydev->port ==PORT_FIBRE ) ?", fiber mode" :"" ); +serial_printf ("Speed: %d, %s duplex%s\n" , phydev->speed, + (phydev->duplex) ?"full" :"half" , + (phydev->port ==PORT_FIBRE ) ?", fiber mode" + :"" );why not just delete this line completely ?
*I* don't mind but others might complain about missing important information. So in my re-do of the series I remove it instead and see what happens.
Quoted 1 line
-mike
Sebastian
PATCH 3/3 net/tsec: Don't tell the link status if used with netconsole
Hi Sebastian,
Quoted 11 lines · Sebastian Andrzej Siewior
Quoted 10 lines · Mike Frysinger
drivers/net/tsec.c
Quoted 5 lines · On Friday 23 March 2012 16:11:19 Sebastian Andrzej Siewior wrote:
drivers/net/tsec.c +1
-0+ ? ? ? if (strcmp(getenv("stdout"), "nc"))i really don't like special casing devices like this
In this case I think it is better to check if stdout is nc, but not to explicitly write to serial_printf(). The nc device is the reason to avoid printing this since it uses the network. The serial_printf seems like the special case to avoid. Consider the case of using a SPI UART. There is no reason these traces should not go to it via the normal printf routing.
Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
- ? ? ? serial_printf("Speed: %d, %s duplex%s\n",
phydev->speed,
- ? ? ? ? ? ? ? ? ? ? ? (phydev->duplex) ? "full" : "half",
- ? ? ? ? ? ? ? ? ? ? ? (phydev->port==PORT_FIBRE) ? ", fiber mode" :
"");
+ ? ? ? ? ? ? ? serial_printf("Speed: %d, %s duplex%s\n",phydev->speed,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (phydev->duplex) ? "full" : "half",
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (phydev->port==PORT_FIBRE) ? ", fiber mode"
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : "");
Quoted 6 lines
Quoted 1 line
why not just delete this line completely ?
*I* don't mind but others might complain about missing important information. So in my re-do of the series I remove it instead and see what happens.
It is pretty typical to print the result of the auto-negotiation.
Are you working on an updated series?
Thanks,
-Joe
PATCH 3/3 net/tsec: Don't tell the link status if used with netconsole
Quoted 10 lines · On Wednesday 04 April 2012 11:27:44 Joe Hershberger wrote:
Quoted 8 lines · Sebastian Andrzej Siewior
Quoted 7 lines · Mike Frysinger
drivers/net/tsec.c static void adjust_link(struct tsec_private *priv, struct phy_device *phydev) · line 238
Quoted 4 lines · On Friday 23 March 2012 16:11:19 Sebastian Andrzej Siewior wrote:
drivers/net/tsec.c +1
-0+if (strcmp (getenv ("stdout" ),"nc" ))i really don't like special casing devices like this
Quoted 6 lines
In this case I think it is better to check if stdout is nc, but not to explicitly write to
serial_printf(). The nc device is the reason to avoid printing this since it uses the network. Theserial_printfseems like the special case to avoid. Consider the case of using a SPI UART. There is no reason these traces should not go to it via the normal printf routing.
my point is that this doesn't scale ... not even close. either drop the printf calls in the core net case (when it'd be a problem with the netconsole), or figure out a solution that does actually scale. maybe a net_printf().
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120408/d8e26af1/attachment.pgp>
PATCH 3/3 net/tsec: Don't tell the link status if used with netconsole
Quoted 18 lines · Mike Frysinger
Quoted 10 lines · On Wednesday 04 April 2012 11:27:44 Joe Hershberger wrote:
Quoted 8 lines · Sebastian Andrzej Siewior
Quoted 7 lines · Mike Frysinger
drivers/net/tsec.c
Quoted 4 lines · On Friday 23 March 2012 16:11:19 Sebastian Andrzej Siewior wrote:
drivers/net/tsec.c +1
-0+ ? ? ? if (strcmp(getenv("stdout"), "nc"))i really don't like special casing devices like this
Quoted 6 lines
In this case I think it is better to check if stdout is nc, but not to explicitly write to
serial_printf(). ?The nc device is the reason to avoid printing this since it uses the network. ?Theserial_printfseems like the special case to avoid. ?Consider the case of using a SPI UART. ?There is no reason these traces should not go to it via the normal printf routing.
Quoted 4 lines
my point is that this doesn't scale ... not even close. ?either drop the printf calls in the core net case (when it'd be a problem with the netconsole), or figure out a solution that does actually scale. ?maybe a
net_printf().
I agree. A net_printf sounds like a good solution.
-Joe
PATCH 1/3 net/eth: set status to active before calling init
In reply to Sebastian Andrzej SiewiorQuoted 9 lines · On Friday 23 March 2012 16:11:17 Sebastian Andrzej Siewior wrote:
If we set the status after successful init call then we get in trouble if stdout (or setderr) is set to netconsole. If we are going to use one of those (lets say printf) during ->init() the following happens:
- network is of (state passive)
- we switch on netconsole
-nc_getc()gets called
- inNetLoop()we switch on ethernet viaeth_init()
- we end up intsec_init()(inc case we use the tsec driver). Here we call aprintf()
considering your followup patches convert printf() to serial_printf(), is this patch still needed ?
Quoted 14 lines
net/eth.c +3
-3@@ -380,14 +380,17 @@ int eth_init(bd_t *bis) old_current = eth_current; do { + int old_state; + debug("Trying %s\n", eth_current->name); - if (eth_current->init(eth_current,bis) >= 0) { - eth_current->state = ETH_STATE_ACTIVE; - + old_state = eth_current->state;
net/eth.c int eth_init(bd_t *bis) · line 396
Quoted 10 lines
net/eth.c +4
-1+ eth_current->state =ETH_STATE_ACTIVE ; +if (eth_current->init (eth_current,bis) >=0 )return 0 ; - } +debug ("FAIL\n" ); + eth_current->state = old_state;eth_try_another (0 ); }while (old_current != eth_current);
this needs a comment in the code explaining why you're setting things active early and then turning it off
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120403/3550492a/attachment.pgp>
PATCH 1/3 net/eth: set status to active before calling init
Quoted 11 lines · Mike Frysinger
Quoted 9 lines · On Friday 23 March 2012 16:11:17 Sebastian Andrzej Siewior wrote:
If we set the status after successful init call then we get in trouble if stdout (or setderr) is set to netconsole. If we are going to use one of those (lets say printf) during ->init() the following happens:
- network is of (state passive)
- we switch on netconsole
-nc_getc()gets called
- inNetLoop()we switch on ethernet viaeth_init()
- we end up intsec_init()(inc case we use the tsec driver). Here we call aprintf()
Quoted 2 lines
considering your followup patches convert
printf()toserial_printf(), is this patch still needed ?
Not for the tsec driver but it is possible that other driver do have the same problem. I haven't also checked all the phy devices which might do some prints. Therefore I would prefer to have this in.
Quoted 22 lines
Quoted 22 lines
net/eth.c +7
-4@@ -380,14 +380,17 @@ int eth_init(bd_t *bis) old_current = eth_current; do { + int old_state; + debug("Trying %s\n", eth_current->name); - if (eth_current->init(eth_current,bis)>= 0) { - eth_current->state = ETH_STATE_ACTIVE; - + old_state = eth_current->state; + eth_current->state = ETH_STATE_ACTIVE; + if (eth_current->init(eth_current,bis)>= 0) return 0; - } + debug("FAIL\n"); + eth_current->state = old_state;
Quoted 5 lines
net/eth.c int eth_init(bd_t *bis) · line 396
Quoted 2 lines
net/eth.c +0
-0eth_try_another (0 ); }while (old_current != eth_current);this needs a comment in the code explaining why you're setting things active early and then turning it off
Okay.
Quoted 1 line
-mike
Sebastian