From patchwork Tue Mar 24 07:41:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 453747 X-Patchwork-Delegate: joe.hershberger@gmail.com 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 C4F031400F1 for ; Tue, 24 Mar 2015 18:43:54 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0DA584B615; Tue, 24 Mar 2015 08:43:52 +0100 (CET) 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 GLb1EySL5JTI; Tue, 24 Mar 2015 08:43:51 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 79CEF4A047; Tue, 24 Mar 2015 08:43:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8C6EB4A047 for ; Tue, 24 Mar 2015 08:43:47 +0100 (CET) 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 qc9neFAWzgWX for ; Tue, 24 Mar 2015 08:43:47 +0100 (CET) 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 ni.com (skprod3.natinst.com [130.164.80.24]) by theia.denx.de (Postfix) with ESMTPS id 113E34A046 for ; Tue, 24 Mar 2015 08:43:44 +0100 (CET) Received: from us-aus-mgwout1.amer.corp.natinst.com (nb-chan1-1338.natinst.com [130.164.19.134]) by us-aus-skprod3.natinst.com (8.15.0.59/8.15.0.59) with ESMTP id t2O7hfQJ030757; Tue, 24 Mar 2015 02:43:41 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.198]) by us-aus-mgwout1.amer.corp.natinst.com (Lotus Domino Release 8.5.3FP6) with ESMTP id 2015032402434161-347978 ; Tue, 24 Mar 2015 02:43:41 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Tue, 24 Mar 2015 02:41:49 -0500 Message-Id: <1427182909-14529-1-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1427179783-985-1-git-send-email-joe.hershberger@ni.com> References: <1427179783-985-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 03/24/2015 02:43:41 AM, Serialize by Router on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 03/24/2015 02:43:41 AM, Serialize complete at 03/24/2015 02:43:41 AM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2015-03-24_03:, , signatures=0 Cc: Joe Hershberger Subject: [U-Boot] [PATCH v2] net: Update hardware MAC address if it changes in env X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" When the ethaddr changes in the env, the hardware should also be updated so that MAC filtering will work properly without resetting U-Boot. Also remove the manual calls to set the hwaddr that was included in a few drivers as a result of the framework not doing it. Reported-by: Michal Simek Signed-off-by: Joe Hershberger Tested-by: Michal Simek --- Changes in v2: -Implement the check in non-DM eth_initialize also -Use static helper function in DM case drivers/net/bcm-sf2-eth.c | 6 ---- drivers/net/designware.c | 4 --- drivers/net/macb.c | 9 ------ net/eth.c | 76 ++++++++++++++++++++++++++++++----------------- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/drivers/net/bcm-sf2-eth.c b/drivers/net/bcm-sf2-eth.c index 5252d49..9ae88d3 100644 --- a/drivers/net/bcm-sf2-eth.c +++ b/drivers/net/bcm-sf2-eth.c @@ -154,12 +154,6 @@ static int bcm_sf2_eth_open(struct eth_device *dev, bd_t *bt) debug("Enabling BCM SF2 Ethernet.\n"); - /* Set MAC address from env */ - if (bcm_sf2_eth_write_hwaddr(dev) != 0) { - error("%s: MAC set error when opening !\n", __func__); - return -1; - } - eth->enable_mac(); /* enable tx and rx DMA */ diff --git a/drivers/net/designware.c b/drivers/net/designware.c index cc01604..d35236b 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -244,10 +244,6 @@ static int dw_eth_init(struct eth_device *dev, bd_t *bis) mdelay(100); }; - /* Soft reset above clears HW address registers. - * So we have to set it here once again */ - dw_write_hwaddr(dev); - rx_descs_init(dev); tx_descs_init(dev); diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 170ff06..7d5b36b 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -525,7 +525,6 @@ static int macb_phy_init(struct macb_device *macb) return 1; } -static int macb_write_hwaddr(struct eth_device *dev); static int macb_init(struct eth_device *netdev, bd_t *bd) { struct macb_device *macb = to_macb(netdev); @@ -594,14 +593,6 @@ static int macb_init(struct eth_device *netdev, bd_t *bd) #endif /* CONFIG_RMII */ } - /* update the ethaddr */ - if (is_valid_ether_addr(netdev->enetaddr)) { - macb_write_hwaddr(netdev); - } else { - printf("%s: mac address is not valid\n", netdev->name); - return -1; - } - if (!macb_phy_init(macb)) return -1; diff --git a/net/eth.c b/net/eth.c index 13b7723..ed2d52a 100644 --- a/net/eth.c +++ b/net/eth.c @@ -239,6 +239,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_ether_addr(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; @@ -258,13 +283,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) { @@ -356,31 +390,6 @@ 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_ether_addr(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; @@ -820,10 +829,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);