*/
static void probe_valid_drivers(struct usb_device *dev)
{
+ struct eth_device *eth;
int j;
for (j = 0; prob_dev[j].probe && prob_dev[j].get_info; j++) {
/*
* ok, it is a supported eth device. Get info and fill it in
*/
+ eth = &usb_eth[usb_max_eth_dev].eth_dev;
if (prob_dev[j].get_info(dev,
&usb_eth[usb_max_eth_dev],
- &usb_eth[usb_max_eth_dev].eth_dev)) {
+ eth)) {
/* found proper driver */
/* register with networking stack */
usb_max_eth_dev++;
* call since eth_current_changed (internally called)
* relies on it
*/
- eth_register(&usb_eth[usb_max_eth_dev - 1].eth_dev);
+ eth_register(eth);
+ if (eth_write_hwaddr(eth, "usbeth",
+ usb_max_eth_dev - 1))
+ puts("Warning: failed to set MAC address\n");
break;
}
}
extern void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
extern int eth_getenv_enetaddr(char *name, uchar *enetaddr);
extern int eth_setenv_enetaddr(char *name, const uchar *enetaddr);
-extern int eth_getenv_enetaddr_by_index(int index, uchar *enetaddr);
+
+/*
+ * Get the hardware address for an ethernet interface .
+ * Args:
+ * base_name - base name for device (normally "eth")
+ * index - device index number (0 for first)
+ * enetaddr - returns 6 byte hardware address
+ * Returns:
+ * Return true if the address is valid.
+ */
+extern int eth_getenv_enetaddr_by_index(const char *base_name, int index,
+ uchar *enetaddr);
extern int usb_eth_initialize(bd_t *bi);
extern int eth_init(bd_t *bis); /* Initialize the device */
extern void eth_halt(void); /* stop SCC */
extern char *eth_get_name(void); /* get name of current device */
+/*
+ * Set the hardware address for an ethernet interface based on 'eth%daddr'
+ * environment variable (or just 'ethaddr' if eth_number is 0).
+ * Args:
+ * base_name - base name for device (normally "eth")
+ * eth_number - value of %d (0 for first device of this type)
+ * Returns:
+ * 0 is success, non-zero is error status from driver.
+ */
+int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
+ int eth_number);
+
#ifdef CONFIG_MCAST_TFTP
int eth_mcast_join( IPaddr_t mcast_addr, u8 join);
u32 ether_crc (size_t len, unsigned char const *p);
return setenv(name, buf);
}
-int eth_getenv_enetaddr_by_index(int index, uchar *enetaddr)
+int eth_getenv_enetaddr_by_index(const char *base_name, int index,
+ uchar *enetaddr)
{
char enetvar[32];
- sprintf(enetvar, index ? "eth%daddr" : "ethaddr", index);
+ sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
return eth_getenv_enetaddr(enetvar, enetaddr);
}
#endif
}
+int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
+ int eth_number)
+{
+ unsigned char env_enetaddr[6];
+ int ret = 0;
+
+ if (!eth_getenv_enetaddr_by_index(base_name, eth_number, env_enetaddr))
+ return -1;
+
+ if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
+ if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) &&
+ memcmp(dev->enetaddr, env_enetaddr, 6)) {
+ printf("\nWarning: %s MAC addresses don't match:\n",
+ dev->name);
+ printf("Address in SROM is %pM\n",
+ dev->enetaddr);
+ printf("Address in environment is %pM\n",
+ env_enetaddr);
+ }
+
+ memcpy(dev->enetaddr, env_enetaddr, 6);
+ }
+
+ if (dev->write_hwaddr &&
+ !eth_mac_skip(eth_number) &&
+ is_valid_ether_addr(dev->enetaddr)) {
+ ret = dev->write_hwaddr(dev);
+ }
+
+ return ret;
+}
+
int eth_register(struct eth_device *dev)
{
struct eth_device *d;
int eth_initialize(bd_t *bis)
{
- unsigned char env_enetaddr[6];
int eth_number = 0;
eth_devices = NULL;
if (strchr(dev->name, ' '))
puts("\nWarning: eth device name has a space!\n");
- eth_getenv_enetaddr_by_index(eth_number, env_enetaddr);
-
- if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
- if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) &&
- memcmp(dev->enetaddr, env_enetaddr, 6))
- {
- printf ("\nWarning: %s MAC addresses don't match:\n",
- dev->name);
- printf ("Address in SROM is %pM\n",
- dev->enetaddr);
- printf ("Address in environment is %pM\n",
- env_enetaddr);
- }
-
- memcpy(dev->enetaddr, env_enetaddr, 6);
- }
- if (dev->write_hwaddr &&
- !eth_mac_skip(eth_number) &&
- is_valid_ether_addr(dev->enetaddr)) {
- dev->write_hwaddr(dev);
- }
+ if (eth_write_hwaddr(dev, NULL, eth_number))
+ puts("Warning: failed to set MAC address\n");
eth_number++;
dev = dev->next;
do {
uchar env_enetaddr[6];
- if (eth_getenv_enetaddr_by_index(eth_number, env_enetaddr))
+ if (eth_getenv_enetaddr_by_index("eth", eth_number,
+ env_enetaddr))
memcpy(dev->enetaddr, env_enetaddr, 6);
++eth_number;