[U-Boot] [PATCH] Add eth_get_dev_by_index

This allows code to iterate through the ethernet devices
Also does some whitespace cleanup
Signed-off-by: Andy Fleming afleming@freescale.com --- Sorry this is so late. This has been sitting in my tree, and is required for a patch for 85xx. It's included in my upcoming pull request, as long as Ben approves...
include/net.h | 19 ++++++++++--------- net/eth.c | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/include/net.h b/include/net.h index bbe0d4b..fc14615 100644 --- a/include/net.h +++ b/include/net.h @@ -116,18 +116,19 @@ extern void eth_try_another(int first_restart); /* Change the device */ extern void eth_set_current(void); /* set nterface to ethcur var. */ #endif extern struct eth_device *eth_get_dev(void); /* get the current device MAC */ -extern struct eth_device *eth_get_dev_by_name(char *devname); /* get device */ -extern int eth_get_dev_index (void); /* get the device index */ -extern void eth_set_enetaddr(int num, char* a); /* Set new MAC address */ +extern struct eth_device *eth_get_dev_by_name(char *devname); /* get device */ +extern struct eth_device *eth_get_dev_by_index(int index); /* get dev @ index */ +extern int eth_get_dev_index (void); /* get the device index */ +extern void eth_set_enetaddr(int num, char* a); /* Set new MAC address */
-extern int eth_init(bd_t *bis); /* Initialize the device */ -extern int eth_send(volatile void *packet, int length); /* Send a packet */ +extern int eth_init(bd_t *bis); /* Initialize the device */ +extern int eth_send(volatile void *packet, int length); /* Send a packet */ #ifdef CONFIG_API -extern int eth_receive(volatile void *packet, int length); /* Receive a packet */ +extern int eth_receive(volatile void *packet, int length); /* Receive a packet*/ #endif -extern int eth_rx(void); /* Check for received packets */ -extern void eth_halt(void); /* stop SCC */ -extern char *eth_get_name(void); /* get name of current device */ +extern int eth_rx(void); /* Check for received packets */ +extern void eth_halt(void); /* stop SCC */ +extern char *eth_get_name(void); /* get name of current device */
#ifdef CONFIG_MCAST_TFTP int eth_mcast_join( IPaddr_t mcast_addr, u8 join); diff --git a/net/eth.c b/net/eth.c index b7ef09f..ec2ef1a 100644 --- a/net/eth.c +++ b/net/eth.c @@ -80,6 +80,28 @@ struct eth_device *eth_get_dev_by_name(char *devname) return target_dev; }
+struct eth_device *eth_get_dev_by_index(int index) +{ + struct eth_device *dev, *target_dev; + int idx = 0; + + if (!eth_devices) + return NULL; + + dev = eth_devices; + target_dev = NULL; + do { + if (idx == index) { + target_dev = dev; + break; + } + dev = dev->next; + idx++; + } while (dev != eth_devices); + + return target_dev; +} + int eth_get_dev_index (void) { struct eth_device *dev;

On Tuesday 10 February 2009 19:55:35 Andy Fleming wrote:
diff --git a/include/net.h b/include/net.h index bbe0d4b..fc14615 100644 --- a/include/net.h +++ b/include/net.h @@ -116,18 +116,19 @@
looks like a lot of pointless whitespace changes when there should just be 1 new line: the prototype -mike

On Tue, Feb 10, 2009 at 7:01 PM, Mike Frysinger vapier@gentoo.org wrote:
On Tuesday 10 February 2009 19:55:35 Andy Fleming wrote:
diff --git a/include/net.h b/include/net.h index bbe0d4b..fc14615 100644 --- a/include/net.h +++ b/include/net.h @@ -116,18 +116,19 @@
looks like a lot of pointless whitespace changes when there should just be 1 new line: the prototype
They're not pointless, they fix it so that the lines are <= 80 characters wide. The comments had extra spaces which made every line look like:
foo blah /* this is a comment */ foo2 blah3 /* another one */
If people think the whitespace changes are too much, I'll move them into a separate patch.
Andy

On Tuesday 10 February 2009 20:43:54 Andy Fleming wrote:
On Tue, Feb 10, 2009 at 7:01 PM, Mike Frysinger vapier@gentoo.org wrote:
On Tuesday 10 February 2009 19:55:35 Andy Fleming wrote:
diff --git a/include/net.h b/include/net.h index bbe0d4b..fc14615 100644 --- a/include/net.h +++ b/include/net.h @@ -116,18 +116,19 @@
looks like a lot of pointless whitespace changes when there should just be 1 new line: the prototype
They're not pointless, they fix it so that the lines are <= 80 characters wide. The comments had extra spaces which made every line look like:
foo blah /* this is a comment */ foo2 blah3 /* another one */
If people think the whitespace changes are too much, I'll move them into a separate patch.
throwing it in an unrelated patch looks wrong -mike

Dear Andy Fleming,
In message 2acbd3e40902101743w5d9dc788lb05170769790103f@mail.gmail.com you wrote:
looks like a lot of pointless whitespace changes when there should just be 1 new line: the prototype
They're not pointless, they fix it so that the lines are <= 80 characters wide. The comments had extra spaces which made every line look like:
...
If people think the whitespace changes are too much, I'll move them into a separate patch.
Yes, please split this into two patches. Thanks.
Best regards,
Wolfgang Denk

Andy Fleming wrote:
This allows code to iterate through the ethernet devices
Also does some whitespace cleanup
Signed-off-by: Andy Fleming afleming@freescale.com
Acked-by: Ben Warren biggerbadderben@gmail.com
Sorry this is so late. This has been sitting in my tree, and is required for a patch for 85xx. It's included in my upcoming pull request, as long as Ben approves...
Not supposed to mix functional fixes and coding style cleanup, but I don't care so much. thanks, Ben
participants (5)
-
Andy Fleming
-
Andy Fleming
-
Ben Warren
-
Mike Frysinger
-
Wolfgang Denk