[U-Boot] [PATCH] Add eth_get_dev_by_index

Andy Fleming afleming at freescale.com
Wed Feb 11 01:55:35 CET 2009


This allows code to iterate through the ethernet devices

Also does some whitespace cleanup

Signed-off-by: Andy Fleming <afleming at 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;
-- 
1.5.4.GIT



More information about the U-Boot mailing list