Skip to contentSkip to conversation

NET: Proper return code handling in eth_init() function in file eth.c

PATCH New Upakul Barkakaty 3 participants 9 messages Nov 29, 2007 – Jan 8, 2008 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NET: Proper return code handling in eth_init() function in file eth.c

NET: Proper return code handling in eth_init() function in file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return codes in the other network stack files. It now returns a 0 on Success and -1 on error.

net/eth.c +5 -5
diff -Naur a/net/eth.c b/net/eth.c
@@ -404,23 +404,23 @@
 	struct eth_device* old_current;
 
 	if (!eth_current)
-		return 0;
+		return -1;
 
 	old_current = eth_current;
 	do {
 		debug ("Trying %s\n", eth_current->name);
 
-		if (eth_current->init(eth_current, bis)) {
+		if (!eth_current->init(eth_current,bis))
+		{
 			eth_current->state = ETH_STATE_ACTIVE;
-
-			return 1;
+			return 0;
 		}
 		debug  ("FAIL\n");
 
 		eth_try_another(0);
 	} while (old_current != eth_current);
 
-	return 0;
+	return -1;
 }
 
 void eth_halt(void)
#1 lore raw

PATCH 1/1 NET: Proper return code handling in eth_init() function in file eth.c

Quoted 16 lines · Upakul Barkakaty

NET: Proper return code handling in eth_init() function in file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return codes in the other network stack files. It now returns a 0 on Success and -1 on error.

diff -Naur a/net/eth.c b/net/eth.c

net/eth.c +0 -0
@@ -404,23 +404,23 @@
 	struct eth_device* old_current;
 
 	if (!eth_current)

net/eth.c line 414

Quoted 10 lines
net/eth.c +3 -2
-		return 0;
+		return -1;
 
 	old_current = eth_current;
 	do {
 		debug ("Trying %s\n", eth_current->name);
 
-		if (eth_current->init(eth_current, bis)) {
+		if (!eth_current->init(eth_current,bis))
+		{

Don't move the "{" into the next line.

Please change this and resend the patch. Thanks.

Best regards,
Stefan

=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================

#2 lore raw

PATCH 1/1 NET: Proper return code handling in eth_init() function in file eth.c

NET: Proper return code handling in eth_init() function in file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return codes in the other network stack files. It now returns a 0 on Success and -1 on error.

net/eth.c +4 -4
diff -Naur a/net/eth.c b/net/eth.c
@@ -404,23 +404,23 @@
 	struct eth_device* old_current;
 
 	if (!eth_current)
-		return 0;
+		return -1;
 
 	old_current = eth_current;
 	do {
 		debug ("Trying %s\n", eth_current->name);
 
-		if (eth_current->init(eth_current, bis)) {
+		if (!eth_current->init(eth_current,bis)) {
 			eth_current->state = ETH_STATE_ACTIVE;
 
-			return 1;
+			return 0;
 		}
 		debug  ("FAIL\n");
 
 		eth_try_another(0);
 	} while (old_current != eth_current);
 
-	return 0;
+	return -1;
 }
 
 void eth_halt(void)
#3 lore raw

PATCH 1/1 NET: Proper return code handling in eth_init() function in file eth.c

Quoted 6 lines · Upakul Barkakaty

NET: Proper return code handling in eth_init() function in file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return codes in the other network stack files. It now returns a 0 on Success and -1 on error.

I just noticed that this patch breaks TFTP on 4xx platforms:

commit 505be87a65e4f87ad7d8da1d57ea4dcd487d7e32

Author: Upakul Barkakaty <[email protected]>
Date:   Thu Nov 29 12:16:13 2007 +0530

NET: Proper return code handling in eth_init() function in file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return codes in the other network stack files. It now returns a 0 on Success and -1 on error.

I just see link auto-negotiation going on, and after that no real transaction is happening! :-(

=> tftp 100000 u-image.bin
Waiting for PHY auto negotiation to complete.... done ENET Speed is 1000 Mbps - FULL duplex connection (EMAC0)

Would be great if someone could look into this ASAP. Unfortunately I have no time left today.

Thanks.

Best regards,
Stefan

=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================

#4 lore raw

PATCH 1/1 NET: Proper return code handling in eth_init() function in file eth.c

Quoted 39 lines · Stefan Roese
Quoted 6 lines · Upakul Barkakaty

NET: Proper return code handling in eth_init() function in file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return codes in the other network stack files. It now returns a 0 on Success and -1 on error.

I just noticed that this patch breaks TFTP on 4xx platforms:

commit 505be87a65e4f87ad7d8da1d57ea4dcd487d7e32

Author: Upakul Barkakaty <[email protected]>
Date:   Thu Nov 29 12:16:13 2007 +0530

NET: Proper return code handling in eth_init() function in file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return codes in the other network stack files. It now returns a 0 on Success and -1 on error.

I just see link auto-negotiation going on, and after that no real transaction
is happening! :-(

=> tftp 100000 u-image.bin
Waiting for PHY auto negotiation to complete.... done ENET Speed is 1000 Mbps - FULL duplex connection (EMAC0)

Would be great if someone could look into this ASAP. Unfortunately I have no
time left today.

Thanks.

Quoted 8 lines

Best regards,
Stefan

=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================

Hi Stefan,

Could you please tell which ethernet driver is being used? Please mention the filename.

Thanks.

Signature · 5 lines
Regards,
Upakul Barkakaty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.denx.de/pipermail/u-boot/attachments/20080108/c2a5e301/attachment.htm 
#5 lore raw

PATCH 1/1 NET: Proper return code handling in eth_init() function in file eth.c

In reply to Stefan Roese
Quoted 39 lines · Stefan Roese
Quoted 6 lines · Upakul Barkakaty

NET: Proper return code handling in eth_init() function in file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return codes in the other network stack files. It now returns a 0 on Success and -1 on error.

I just noticed that this patch breaks TFTP on 4xx platforms:

commit 505be87a65e4f87ad7d8da1d57ea4dcd487d7e32

Author: Upakul Barkakaty <[email protected]>
Date:   Thu Nov 29 12:16:13 2007 +0530

NET: Proper return code handling in eth_init() function in file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return codes in the other network stack files. It now returns a 0 on Success and -1 on error.

I just see link auto-negotiation going on, and after that no real transaction
is happening! :-(

=> tftp 100000 u-image.bin
Waiting for PHY auto negotiation to complete.... done ENET Speed is 1000 Mbps - FULL duplex connection (EMAC0)

Would be great if someone could look into this ASAP. Unfortunately I have no
time left today.

Thanks.

Quoted 9 lines

Best regards,
Stefan

=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================

Hi Stefan,

Probably i got the reason why this is happening. As a convention that is usually followed, the code in eth_init() function in the file eth.c was reworked to handle 0 in case of Success and any non zero value in case of an error.

Most of the Ethernet driver's init routines adhere to the same convention of returning a 0 on Success and a non zero value in case of error. However, the driver you might be using, may be returning a non zero value on Successful initialization, that is why the problem is arising. The solution could be to return 0 in case of Success, from the Ethernet driver's init() routine.

Thanks!!

Signature · 5 lines
Regards,
Upakul Barkakaty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.denx.de/pipermail/u-boot/attachments/20080108/247a5965/attachment.htm 
#6 lore raw

PATCH 1/1 NET: Proper return code handling in eth_init() function in file eth.c

Quoted 66 lines · Upakul Barkakaty

On 1/8/08, *Stefan Roese* <sr at denx.de <mailto:[email protected]>> wrote:

On Thursday 29 November 2007, Upakul Barkakaty wrote:
> NET: Proper return code handling in eth_init() function in file eth.c
>
> This patch modifies the return code handling in the eth_init() > function, to be compatible with the handling of the return codes in > the other network stack files. It now returns a 0 on Success and -1 on
> error.

I just noticed that this patch breaks TFTP on 4xx platforms:

commit 505be87a65e4f87ad7d8da1d57ea4dcd487d7e32
Author: Upakul Barkakaty <upakul at gmail.com <mailto:[email protected]>>
Date: Thu Nov 29 12:16:13 2007 +0530

NET: Proper return code handling in eth_init() function in
file eth.c

This patch modifies the return code handling in the eth_init() function, to be compatible with the handling of the return
codes in
the other network stack files. It now returns a 0 on Success
and -1 on
error.

Signed-off-by: Upakul Barkakaty <
upakul.barkakaty at conexant.com <mailto:[email protected]>>

<mailto:[email protected]>>

I just see link auto-negotiation going on, and after that no real transaction
is happening! :-(

=> tftp 100000 u-image.bin
Waiting for PHY auto negotiation to complete.... done ENET Speed is 1000 Mbps - FULL duplex connection (EMAC0)

Would be great if someone could look into this ASAP. Unfortunately I have no
time left today.

Thanks.

Best regards,
Stefan

=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email:
office at denx.de <mailto:[email protected]>
=====================================================================

Hi Stefan,

Probably i got the reason why this is happening. As a convention that is usually followed, the code in eth_init() function in the file eth.c was reworked to handle 0 in case of Success and any non zero value in case of an error.

Quoted 12 lines

Most of the Ethernet driver's init routines adhere to the same convention of returning a 0 on Success and a non zero value in case of error. However, the driver you might be using, may be returning a non zero value on Successful initialization, that is why the problem is arising. The solution could be to return 0 in case of Success, from the Ethernet driver's init() routine.

Thanks!!

Signature · 2 lines
Regards,
Upakul Barkakaty

Yeah, looks like ppc_4xx_eth_init() (cpu/ppc4xx/4xx_enet.c) returns 1 on success and -1 on failure. I don't have hardware to test this. Can you check it out Stefan? Let's look through the other drivers to see if this is an isolated case.

regards,
Ben

#7 lore raw

PATCH 1/1 NET: Proper return code handling in eth_init() function in file eth.c

Quoted 14 lines · Ben Warren
Quoted 14 lines

Probably i got the reason why this is happening. As a convention that is usually followed, the code in eth_init() function in the file eth.c was reworked to handle 0 in case of Success and any non zero value in case of an error.

Most of the Ethernet driver's init routines adhere to the same convention of returning a 0 on Success and a non zero value in case of error. However, the driver you might be using, may be returning a non zero value on Successful initialization, that is why the problem is arising. The solution could be to return 0 in case of Success, from the Ethernet driver's init() routine.

Thanks!!

Quoted 8 lines
Quoted 3 lines

--
Regards,
Upakul Barkakaty

Yeah, looks like ppc_4xx_eth_init() (cpu/ppc4xx/4xx_enet.c) returns 1 on success and -1 on failure. I don't have hardware to test this. Can you check it out Stefan? Let's look through the other drivers to see if this is an isolated case.

I'm back now and will give it a try this evening. Thanks for pointing this out.

Note: This patch may trigger other platform ethernet driver problems as well. So I strongly encourage all platform maintainers/custodians to check if a change in the return code of the ethernet driver is needed.

Best regards,
Stefan

=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================

#8 lore raw

PATCH 1/1 NET: Proper return code handling in eth_init() function in file eth.c

Quoted 29 lines · Stefan Roese
Quoted 14 lines · Ben Warren
Quoted 14 lines

Probably i got the reason why this is happening. As a convention that is usually followed, the code in eth_init() function in the file eth.c was reworked to handle 0 in case of Success and any non zero value in case of an error.

Most of the Ethernet driver's init routines adhere to the same convention of returning a 0 on Success and a non zero value in case of error. However, the driver you might be using, may be returning a non zero value on Successful initialization, that is why the problem is arising. The solution could be to return 0 in case of Success, from the Ethernet driver's init() routine.

Thanks!!

Quoted 9 lines
Quoted 4 lines

--
Regards,
Upakul Barkakaty

Yeah, looks like ppc_4xx_eth_init() (cpu/ppc4xx/4xx_enet.c) returns 1 on success and -1 on failure. I don't have hardware to test this. Can you check it out Stefan? Let's look through the other drivers to see if this is an isolated case.

I'm back now and will give it a try this evening. Thanks for pointing this out.

Quoted 7 lines

Note: This patch may trigger other platform ethernet driver problems as well. So I strongly encourage all platform maintainers/custodians to check if a change in the return code of the ethernet driver is needed.

Best regards,
Stefan

Don't waste too much time on this - every driver returns 1 on success. I'm putting together a patch to clean things up and should have it within an hour or so.

regards,
Ben