public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/3] net/eth_device: keep index inside each device
@ 2009-08-11 20:49 Jean-Christophe PLAGNIOL-VILLARD
  2009-08-11 20:49 ` [U-Boot] [PATCH 2/3] net: add getenv/setenv enetaddr function to use ethernet device num Jean-Christophe PLAGNIOL-VILLARD
  2009-08-12 18:50 ` [U-Boot] [PATCH 1/3] net/eth_device: keep index inside each device Wolfgang Denk
  0 siblings, 2 replies; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2009-08-11 20:49 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/net.h |    1 +
 net/eth.c     |   17 +++++------------
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/include/net.h b/include/net.h
index 4a03717..2a8a12d 100644
--- a/include/net.h
+++ b/include/net.h
@@ -93,6 +93,7 @@ enum eth_state_t {
 };
 
 struct eth_device {
+	int index;
 	char name[NAMESIZE];
 	unsigned char enetaddr[6];
 	int iobase;
diff --git a/net/eth.c b/net/eth.c
index 42f74da..2316a22 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -83,6 +83,7 @@ static unsigned int eth_rcv_current = 0, eth_rcv_last = 0;
 #endif
 
 static struct eth_device *eth_devices, *eth_current;
+static int nb_eth_devices = 0;
 
 struct eth_device *eth_get_dev(void)
 {
@@ -133,22 +134,12 @@ struct eth_device *eth_get_dev_by_index(int index)
 
 int eth_get_dev_index (void)
 {
-	struct eth_device *dev;
-	int num = 0;
-
 	if (!eth_devices) {
 		return (-1);
 	}
 
-	for (dev = eth_devices; dev; dev = dev->next) {
-		if (dev == eth_current)
-			break;
-		++num;
-	}
-
-	if (dev) {
-		return (num);
-	}
+	if (eth_current)
+		return eth_current->index;
 
 	return (0);
 }
@@ -172,6 +163,8 @@ int eth_register(struct eth_device* dev)
 		d->next = dev;
 	}
 
+	dev->index = nb_eth_devices;
+	nb_eth_devices++;
 	dev->state = ETH_STATE_INIT;
 	dev->next  = eth_devices;
 
-- 
1.6.4

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

end of thread, other threads:[~2009-08-12 23:16 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-11 20:49 [U-Boot] [PATCH 1/3] net/eth_device: keep index inside each device Jean-Christophe PLAGNIOL-VILLARD
2009-08-11 20:49 ` [U-Boot] [PATCH 2/3] net: add getenv/setenv enetaddr function to use ethernet device num Jean-Christophe PLAGNIOL-VILLARD
2009-08-11 20:49   ` [U-Boot] [PATCH 3/3] smc91111: switch to MULTI_NET api Jean-Christophe PLAGNIOL-VILLARD
2009-08-12 15:54     ` Ben Warren
2009-08-12 20:38       ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-12 20:46         ` Ben Warren
2009-08-12 19:12     ` Wolfgang Denk
2009-08-12 20:36       ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-12 21:26         ` Wolfgang Denk
2009-08-12 18:58   ` [U-Boot] [PATCH 2/3] net: add getenv/setenv enetaddr function to use ethernet device num Wolfgang Denk
2009-08-12 20:58     ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-12 21:32       ` Wolfgang Denk
2009-08-12 18:50 ` [U-Boot] [PATCH 1/3] net/eth_device: keep index inside each device Wolfgang Denk
2009-08-12 21:03   ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-12 21:15     ` Ben Warren
2009-08-12 21:26       ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-12 21:46         ` Wolfgang Denk
2009-08-12 23:16         ` Ben Warren
2009-08-12 21:35     ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox