X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=net%2Feth.c;h=04a544c872a07c8e17ee003262a9d50f7bf3f8b1;hb=1ab3a40db0c8b4250eabf16b16cf61e18a0322ad;hp=3f5cb7ec991d409b6098e01a768e37a389564dd6;hpb=4bdc27a1dca624fe74b58cd32074a3c2d2fd38a3;p=karo-tx-uboot.git diff --git a/net/eth.c b/net/eth.c index 3f5cb7ec99..04a544c872 100644 --- a/net/eth.c +++ b/net/eth.c @@ -74,12 +74,53 @@ static int eth_mac_skip(int index) { char enetvar[15]; char *skip_state; + sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index); - return ((skip_state = getenv(enetvar)) != NULL); + skip_state = getenv(enetvar); + return skip_state != NULL; } static void eth_current_changed(void); +/* + * CPU and board-specific Ethernet initializations. Aliased function + * signals caller to move on + */ +static int __def_eth_init(bd_t *bis) +{ + return -1; +} +int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init"))); +int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init"))); + +static void eth_common_init(void) +{ + bootstage_mark(BOOTSTAGE_ID_NET_ETH_START); +#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB) + miiphy_init(); +#endif + +#ifdef CONFIG_PHYLIB + phy_init(); +#endif + + eth_env_init(); + + /* + * If board-specific initialization exists, call it. + * If not, call a CPU-specific one + */ + if (board_eth_init != __def_eth_init) { + if (board_eth_init(gd->bd) < 0) + printf("Board Net Initialization Failed\n"); + } else if (cpu_eth_init != __def_eth_init) { + if (cpu_eth_init(gd->bd) < 0) + printf("CPU Net Initialization Failed\n"); + } else { + printf("Net Initialization Skipped\n"); + } +} + #ifdef CONFIG_DM_ETH /** * struct eth_device_priv - private structure for each Ethernet device @@ -240,6 +281,31 @@ int eth_get_dev_index(void) return -1; } +static int eth_write_hwaddr(struct udevice *dev) +{ + struct eth_pdata *pdata = dev->platdata; + int ret = 0; + + if (!dev || !device_active(dev)) + return -EINVAL; + + /* seq is valid since the device is active */ + if (eth_get_ops(dev)->write_hwaddr && !eth_mac_skip(dev->seq)) { + if (!is_valid_ethaddr(pdata->enetaddr)) { + printf("\nError: %s address %pM illegal value\n", + dev->name, pdata->enetaddr); + return -EINVAL; + } + + ret = eth_get_ops(dev)->write_hwaddr(dev); + if (ret) + printf("\nWarning: %s failed to set MAC address\n", + dev->name); + } + + return ret; +} + int eth_init(void) { struct udevice *current; @@ -259,13 +325,22 @@ int eth_init(void) if (device_active(current)) { uchar env_enetaddr[6]; struct eth_pdata *pdata = current->platdata; + int enetaddr_changed = 0; /* Sync environment with network device */ if (eth_getenv_enetaddr_by_index("eth", current->seq, - env_enetaddr)) + env_enetaddr)) { + enetaddr_changed = memcmp(pdata->enetaddr, + env_enetaddr, 6); memcpy(pdata->enetaddr, env_enetaddr, 6); - else + } else { + memset(env_enetaddr, 0, 6); + enetaddr_changed = memcmp(pdata->enetaddr, + env_enetaddr, 6); memset(pdata->enetaddr, 0, 6); + } + if (enetaddr_changed) + eth_write_hwaddr(current); ret = eth_get_ops(current)->start(current); if (ret >= 0) { @@ -275,8 +350,9 @@ int eth_init(void) priv->state = ETH_STATE_ACTIVE; return 0; } - } else + } else { ret = eth_errno; + } debug("FAIL\n"); @@ -359,38 +435,12 @@ int eth_rx(void) return ret; } -static int eth_write_hwaddr(struct udevice *dev) -{ - struct eth_pdata *pdata = dev->platdata; - int ret = 0; - - if (!dev || !device_active(dev)) - return -EINVAL; - - /* seq is valid since the device is active */ - if (eth_get_ops(dev)->write_hwaddr && !eth_mac_skip(dev->seq)) { - if (!is_valid_ethaddr(pdata->enetaddr)) { - printf("\nError: %s address %pM illegal value\n", - dev->name, pdata->enetaddr); - return -EINVAL; - } - - ret = eth_get_ops(dev)->write_hwaddr(dev); - if (ret) - printf("\nWarning: %s failed to set MAC address\n", - dev->name); - } - - return ret; -} - int eth_initialize(void) { int num_devices = 0; struct udevice *dev; - bootstage_mark(BOOTSTAGE_ID_NET_ETH_START); - eth_env_init(); + eth_common_init(); /* * Devices need to write the hwaddr even if not started so that Linux @@ -517,16 +567,6 @@ UCLASS_DRIVER(eth) = { #endif #ifndef CONFIG_DM_ETH -/* - * CPU and board-specific Ethernet initializations. Aliased function - * signals caller to move on - */ -static int __def_eth_init(bd_t *bis) -{ - return -1; -} -int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init"))); -int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init"))); #ifdef CONFIG_API static struct { @@ -612,11 +652,11 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name, if (!is_zero_ethaddr(dev->enetaddr) && memcmp(dev->enetaddr, env_enetaddr, 6)) { printf("\nWarning: %s MAC addresses don't match:\n", - dev->name); + dev->name); printf("Address in SROM is %pM\n", - dev->enetaddr); + dev->enetaddr); printf("Address in environment is %pM\n", - env_enetaddr); + env_enetaddr); } memcpy(dev->enetaddr, env_enetaddr, 6); @@ -624,7 +664,7 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name, eth_setenv_enetaddr_by_index(base_name, eth_number, dev->enetaddr); printf("\nWarning: %s using MAC address from net device\n", - dev->name); + dev->name); } else if (is_zero_ethaddr(dev->enetaddr)) { printf("\nError: %s address not set.\n", dev->name); @@ -634,13 +674,14 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name, if (dev->write_hwaddr && !eth_mac_skip(eth_number)) { if (!is_valid_ethaddr(dev->enetaddr)) { printf("\nError: %s address %pM illegal value\n", - dev->name, dev->enetaddr); + dev->name, dev->enetaddr); return -EINVAL; } ret = dev->write_hwaddr(dev); if (ret) - printf("\nWarning: %s failed to set MAC address\n", dev->name); + printf("\nWarning: %s failed to set MAC address\n", + dev->name); } return ret; @@ -654,7 +695,8 @@ int eth_register(struct eth_device *dev) assert(strlen(dev->name) < sizeof(dev->name)); if (!eth_devices) { - eth_current = eth_devices = dev; + eth_devices = dev; + eth_current = dev; eth_current_changed(); } else { for (d = eth_devices; d->next != eth_devices; d = d->next) @@ -701,32 +743,10 @@ int eth_unregister(struct eth_device *dev) int eth_initialize(void) { int num_devices = 0; + eth_devices = NULL; eth_current = NULL; - - bootstage_mark(BOOTSTAGE_ID_NET_ETH_START); -#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB) - miiphy_init(); -#endif - -#ifdef CONFIG_PHYLIB - phy_init(); -#endif - - eth_env_init(); - - /* - * If board-specific initialization exists, call it. - * If not, call a CPU-specific one - */ - if (board_eth_init != __def_eth_init) { - if (board_eth_init(gd->bd) < 0) - printf("Board Net Initialization Failed\n"); - } else if (cpu_eth_init != __def_eth_init) { - if (cpu_eth_init(gd->bd) < 0) - printf("CPU Net Initialization Failed\n"); - } else - printf("Net Initialization Skipped\n"); + eth_common_init(); if (!eth_devices) { puts("No ethernet found.\n"); @@ -823,10 +843,21 @@ int eth_init(void) dev = eth_devices; do { uchar env_enetaddr[6]; + int enetaddr_changed = 0; if (eth_getenv_enetaddr_by_index("eth", dev->index, - env_enetaddr)) + env_enetaddr)) { + enetaddr_changed = memcmp(dev->enetaddr, + env_enetaddr, 6); memcpy(dev->enetaddr, env_enetaddr, 6); + } else { + memset(env_enetaddr, 0, 6); + enetaddr_changed = memcmp(dev->enetaddr, + env_enetaddr, 6); + memset(dev->enetaddr, 0, 6); + } + if (enetaddr_changed) + eth_write_hwaddr(dev, "eth", dev->index); dev = dev->next; } while (dev != eth_devices); @@ -959,7 +990,7 @@ void eth_try_another(int first_restart) eth_current_changed(); if (first_failed == eth_get_dev()) - NetRestartWrap = 1; + net_restart_wrap = 1; } void eth_set_current(void)