From patchwork Thu Oct 6 22:23:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 118180 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 9112BB6FA1 for ; Fri, 7 Oct 2011 09:32:37 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CD2D4294E5; Fri, 7 Oct 2011 00:32:28 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AcFjYpsqr3YU; Fri, 7 Oct 2011 00:32:28 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 61C8C294BB; Fri, 7 Oct 2011 00:32:11 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BB0D329476 for ; Fri, 7 Oct 2011 00:32:03 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 87Bkxl-sSAZN for ; Fri, 7 Oct 2011 00:32:01 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.serverraum.org (mail.serverraum.org [78.47.150.89]) by theia.denx.de (Postfix) with ESMTP id 3E7E829479 for ; Fri, 7 Oct 2011 00:32:00 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.serverraum.org (Postfix) with ESMTP id BC48C3EF4D; Fri, 7 Oct 2011 00:23:42 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.serverraum.org Received: from mail.serverraum.org ([127.0.0.1]) by localhost (web.serverraum.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2-AQECUW4aWS; Fri, 7 Oct 2011 00:23:42 +0200 (CEST) Received: from thanatos.fritz.box (95-89-251-205-dynip.superkabel.de [95.89.251.205]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.serverraum.org (Postfix) with ESMTPSA id 82A253EF4C; Fri, 7 Oct 2011 00:23:42 +0200 (CEST) From: Michael Walle To: u-boot@lists.denx.de Date: Fri, 7 Oct 2011 00:23:22 +0200 Message-Id: <1317939802-19695-1-git-send-email-michael@walle.cc> X-Mailer: git-send-email 1.7.2.5 Subject: [U-Boot] [PATCH] mvgbe: fix network device indices X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Don't assume that the MAC address of egiga0 rsp. egiga1 is ethaddr rsp. eth1addr. If there is only a egiga1 device, u-boot will enumerate it as device 0 and therefore the MAC address is set with the environmen varibale ethaddr. Signed-off-by: Michael Walle --- drivers/net/mvgbe.c | 13 +++++++------ include/net.h | 12 ++++++++++++ net/eth.c | 8 ++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/net/mvgbe.c b/drivers/net/mvgbe.c index c701f43..738e8d3 100644 --- a/drivers/net/mvgbe.c +++ b/drivers/net/mvgbe.c @@ -645,7 +645,7 @@ int mvgbe_initialize(bd_t *bis) struct mvgbe_device *dmvgbe; struct eth_device *dev; int devnum; - char *s; + int eth_idx = 0; u8 used_ports[MAX_MVGBE_DEVS] = CONFIG_MVGBE_PORTS; for (devnum = 0; devnum < MAX_MVGBE_DEVS; devnum++) { @@ -700,16 +700,13 @@ error1: /* must be less than NAMESIZE (16) */ sprintf(dev->name, "egiga%d", devnum); - /* Extract the MAC address from the environment */ switch (devnum) { case 0: dmvgbe->regs = (void *)MVGBE0_BASE; - s = "ethaddr"; break; #if defined(MVGBE1_BASE) case 1: dmvgbe->regs = (void *)MVGBE1_BASE; - s = "eth1addr"; break; #endif default: /* this should never happen */ @@ -718,7 +715,9 @@ error1: return -1; } - while (!eth_getenv_enetaddr(s, dev->enetaddr)) { + /* Extract the MAC address from the environment */ + while (!eth_getenv_enetaddr_by_index("eth", eth_idx, + dev->enetaddr)) { /* Generate Private MAC addr if not set */ dev->enetaddr[0] = 0x02; dev->enetaddr[1] = 0x50; @@ -734,7 +733,7 @@ error1: dev->enetaddr[4] = get_random_hex(); dev->enetaddr[5] = get_random_hex(); #endif - eth_setenv_enetaddr(s, dev->enetaddr); + eth_setenv_enetaddr_by_index("eth", eth_idx, dev->enetaddr); } dev->init = (void *)mvgbe_init; @@ -745,6 +744,8 @@ error1: eth_register(dev); + eth_idx++; + #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) miiphy_register(dev->name, smi_reg_read, smi_reg_write); /* Set phy address of the port */ diff --git a/include/net.h b/include/net.h index d5d37b6..d378cd2 100644 --- a/include/net.h +++ b/include/net.h @@ -103,6 +103,18 @@ extern int eth_setenv_enetaddr(char *name, const uchar *enetaddr); extern int eth_getenv_enetaddr_by_index(const char *base_name, int index, uchar *enetaddr); +/* + * Set 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 environment varibable was set successfully. + */ +extern int eth_setenv_enetaddr_by_index(const char *base_name, int index, + const uchar *enetaddr); + extern int usb_eth_initialize(bd_t *bi); extern int eth_init(bd_t *bis); /* Initialize the device */ extern int eth_send(volatile void *packet, int length); /* Send a packet */ diff --git a/net/eth.c b/net/eth.c index 4280d6d..a8f68fc 100644 --- a/net/eth.c +++ b/net/eth.c @@ -62,6 +62,14 @@ int eth_getenv_enetaddr_by_index(const char *base_name, int index, return eth_getenv_enetaddr(enetvar, enetaddr); } +int eth_setenv_enetaddr_by_index(const char *base_name, int index, + const uchar *enetaddr) +{ + char enetvar[32]; + sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index); + return eth_setenv_enetaddr(enetvar, enetaddr); +} + static int eth_mac_skip(int index) { char enetvar[15];