Instead of counting the device index everytime a functions needs it, store
it in the eth_device struct. eth_register() keeps track of the indices and
updates the device's index number. This simplifies some functions in
net/eth.c.
Additionally, a network driver can now query its index, eg. to get the
correct environment ethaddr name.
Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
Cc: Mike Frysinger <vapier@gentoo.com>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>
#endif
int (*write_hwaddr) (struct eth_device*);
struct eth_device *next;
#endif
int (*write_hwaddr) (struct eth_device*);
struct eth_device *next;
struct eth_device *eth_get_dev_by_index(int index)
{
struct eth_device *dev, *target_dev;
struct eth_device *eth_get_dev_by_index(int index)
{
struct eth_device *dev, *target_dev;
if (!eth_devices)
return NULL;
if (!eth_devices)
return NULL;
dev = eth_devices;
target_dev = NULL;
do {
dev = eth_devices;
target_dev = NULL;
do {
+ if (dev->index == index) {
target_dev = dev;
break;
}
dev = dev->next;
target_dev = dev;
break;
}
dev = dev->next;
} while (dev != eth_devices);
return target_dev;
} while (dev != eth_devices);
return target_dev;
int eth_get_dev_index (void)
{
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 -1;
+ return eth_current->index;
}
static void eth_current_changed(void)
}
static void eth_current_changed(void)
int eth_register(struct eth_device *dev)
{
struct eth_device *d;
int eth_register(struct eth_device *dev)
{
struct eth_device *d;
assert(strlen(dev->name) < NAMESIZE);
assert(strlen(dev->name) < NAMESIZE);
dev->state = ETH_STATE_INIT;
dev->next = eth_devices;
dev->state = ETH_STATE_INIT;
dev->next = eth_devices;
return 0;
}
int eth_initialize(bd_t *bis)
{
return 0;
}
int eth_initialize(bd_t *bis)
{
eth_devices = NULL;
eth_current = NULL;
eth_devices = NULL;
eth_current = NULL;
show_boot_progress (65);
do {
show_boot_progress (65);
do {
puts (", ");
printf("%s", dev->name);
puts (", ");
printf("%s", dev->name);
if (strchr(dev->name, ' '))
puts("\nWarning: eth device name has a space!\n");
if (strchr(dev->name, ' '))
puts("\nWarning: eth device name has a space!\n");
- if (eth_write_hwaddr(dev, "eth", eth_number))
+ if (eth_write_hwaddr(dev, "eth", dev->index))
puts("\nWarning: failed to set MAC address\n");
puts("\nWarning: failed to set MAC address\n");
} while(dev != eth_devices);
eth_current_changed();
putc ('\n');
}
} while(dev != eth_devices);
eth_current_changed();
putc ('\n');
}
}
#ifdef CONFIG_MCAST_TFTP
}
#ifdef CONFIG_MCAST_TFTP
int eth_init(bd_t *bis)
{
int eth_init(bd_t *bis)
{
struct eth_device *old_current, *dev;
if (!eth_current) {
struct eth_device *old_current, *dev;
if (!eth_current) {
}
/* Sync environment with network devices */
}
/* Sync environment with network devices */
dev = eth_devices;
do {
uchar env_enetaddr[6];
dev = eth_devices;
do {
uchar env_enetaddr[6];
- if (eth_getenv_enetaddr_by_index("eth", eth_number,
+ if (eth_getenv_enetaddr_by_index("eth", dev->index,
env_enetaddr))
memcpy(dev->enetaddr, env_enetaddr, 6);
env_enetaddr))
memcpy(dev->enetaddr, env_enetaddr, 6);
dev = dev->next;
} while (dev != eth_devices);
dev = dev->next;
} while (dev != eth_devices);