From patchwork Wed Nov 7 18:14:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joachim Eastwood X-Patchwork-Id: 197699 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 668682C0156 for ; Thu, 8 Nov 2012 05:15:57 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753972Ab2KGSPm (ORCPT ); Wed, 7 Nov 2012 13:15:42 -0500 Received: from mail-lb0-f174.google.com ([209.85.217.174]:60048 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753374Ab2KGSPQ (ORCPT ); Wed, 7 Nov 2012 13:15:16 -0500 Received: by mail-lb0-f174.google.com with SMTP id n3so1512078lbo.19 for ; Wed, 07 Nov 2012 10:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=6XTzSB997CC2MFPFMUXZlzPfiX5HthMulFIfCOw7hn4=; b=ZqZZRxTPCADmjGyofe4I22x1RJDd7s/A+qHw8TVtEMSYrYdKj0gaZSTQhldnfCmj2g NQfcRK20jcKzWKBxRrMA2ZVIGc7x/r2sI3+SNKEhRu2udM/0BoK3O0TixlYcKhTU99mc yNZlj/fd9l8x0UHs+CEf9owvWxoBOV+eXdJux87ZOWZLHBjrVRfwrlAovSQqmpan4Io4 OQJReJ7nD/2wokmy49mC7HbmrdxdNPdD6CXCGEb7Xu50TLDcbzr8VABKyl9+8/UyCz7q t0aJF1GlChphxI0fuJ58iGB6s+NhMb57pbbLcup43bslv759stWRp+BQigoZXtDlYTgt ZkgQ== Received: by 10.152.102.234 with SMTP id fr10mr5127045lab.28.1352312115977; Wed, 07 Nov 2012 10:15:15 -0800 (PST) Received: from localhost.localdomain (57.90-149-223.nextgentel.com. [90.149.223.57]) by mx.google.com with ESMTPS id b4sm8383536lbi.0.2012.11.07.10.15.15 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 07 Nov 2012 10:15:15 -0800 (PST) From: Joachim Eastwood To: nicolas.ferre@atmel.com, davem@davemloft.net Cc: plagnioj@jcrosoft.com, netdev@vger.kernel.org, Joachim Eastwood Subject: [PATCH 4/8] net/at91_ether: use macb functions for get/set hwaddr Date: Wed, 7 Nov 2012 19:14:53 +0100 Message-Id: <1352312097-31320-5-git-send-email-manabian@gmail.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1352312097-31320-1-git-send-email-manabian@gmail.com> References: <1352312097-31320-1-git-send-email-manabian@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Joachim Eastwood --- drivers/net/ethernet/cadence/at91_ether.c | 112 +----------------------------- 1 file changed, 3 insertions(+), 109 deletions(-) diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c index 6eb928e..2f89e64 100644 --- a/drivers/net/ethernet/cadence/at91_ether.c +++ b/drivers/net/ethernet/cadence/at91_ether.c @@ -46,109 +46,6 @@ /* max number of receive buffers */ #define MAX_RX_DESCR 9 -/* ......................... ADDRESS MANAGEMENT ........................ */ - -/* - * NOTE: Your bootloader must always set the MAC address correctly before - * booting into Linux. - * - * - It must always set the MAC address after reset, even if it doesn't - * happen to access the Ethernet while it's booting. Some versions of - * U-Boot on the AT91RM9200-DK do not do this. - * - * - Likewise it must store the addresses in the correct byte order. - * MicroMonitor (uMon) on the CSB337 does this incorrectly (and - * continues to do so, for bug-compatibility). - */ - -static short __init unpack_mac_address(struct net_device *dev, unsigned int hi, unsigned int lo) -{ - struct macb *lp = netdev_priv(dev); - char addr[6]; - - if (lp->board_data.rev_eth_addr) { - addr[5] = (lo & 0xff); /* The CSB337 bootloader stores the MAC the wrong-way around */ - addr[4] = (lo & 0xff00) >> 8; - addr[3] = (lo & 0xff0000) >> 16; - addr[2] = (lo & 0xff000000) >> 24; - addr[1] = (hi & 0xff); - addr[0] = (hi & 0xff00) >> 8; - } - else { - addr[0] = (lo & 0xff); - addr[1] = (lo & 0xff00) >> 8; - addr[2] = (lo & 0xff0000) >> 16; - addr[3] = (lo & 0xff000000) >> 24; - addr[4] = (hi & 0xff); - addr[5] = (hi & 0xff00) >> 8; - } - - if (is_valid_ether_addr(addr)) { - memcpy(dev->dev_addr, &addr, 6); - return 1; - } - return 0; -} - -/* - * Set the ethernet MAC address in dev->dev_addr - */ -static void __init get_mac_address(struct net_device *dev) -{ - struct macb *lp = netdev_priv(dev); - - /* Check Specific-Address 1 */ - if (unpack_mac_address(dev, macb_readl(lp, SA1T), macb_readl(lp, SA1B))) - return; - /* Check Specific-Address 2 */ - if (unpack_mac_address(dev, macb_readl(lp, SA2T), macb_readl(lp, SA2B))) - return; - /* Check Specific-Address 3 */ - if (unpack_mac_address(dev, macb_readl(lp, SA3T), macb_readl(lp, SA3B))) - return; - /* Check Specific-Address 4 */ - if (unpack_mac_address(dev, macb_readl(lp, SA4T), macb_readl(lp, SA4B))) - return; - - printk(KERN_ERR "at91_ether: Your bootloader did not configure a MAC address.\n"); -} - -/* - * Program the hardware MAC address from dev->dev_addr. - */ -static void update_mac_address(struct net_device *dev) -{ - struct macb *lp = netdev_priv(dev); - - macb_writel(lp, SA1B, (dev->dev_addr[3] << 24) | (dev->dev_addr[2] << 16) - | (dev->dev_addr[1] << 8) | (dev->dev_addr[0])); - macb_writel(lp, SA1T, (dev->dev_addr[5] << 8) | (dev->dev_addr[4])); - - macb_writel(lp, SA2B, 0); - macb_writel(lp, SA2T, 0); -} - -/* - * Store the new hardware address in dev->dev_addr, and update the MAC. - */ -static int set_mac_address(struct net_device *dev, void* addr) -{ - struct sockaddr *address = addr; - - if (!is_valid_ether_addr(address->sa_data)) - return -EADDRNOTAVAIL; - - memcpy(dev->dev_addr, address->sa_data, dev->addr_len); - update_mac_address(dev); - - printk("%s: Setting MAC address to %pM\n", dev->name, - dev->dev_addr); - - return 0; -} - -/* ................................ MAC ................................ */ - /* * Initialize and start the Receiver and Transmit subsystems */ @@ -219,8 +116,7 @@ static int at91ether_open(struct net_device *dev) ctl = macb_readl(lp, NCR); macb_writel(lp, NCR, ctl | MACB_BIT(CLRSTAT)); - /* Update the MAC address (incase user has changed it) */ - update_mac_address(dev); + macb_set_hwaddr(lp); ret = at91ether_start(dev); if (ret) @@ -438,7 +334,7 @@ static const struct net_device_ops at91ether_netdev_ops = { .ndo_start_xmit = at91ether_start_xmit, .ndo_get_stats = at91ether_stats, .ndo_set_rx_mode = macb_set_rx_mode, - .ndo_set_mac_address = set_mac_address, + .ndo_set_mac_address = eth_mac_addr, .ndo_do_ioctl = macb_ioctl, .ndo_validate_addr = eth_validate_addr, .ndo_change_mtu = eth_change_mtu, @@ -557,9 +453,7 @@ static int __init at91ether_probe(struct platform_device *pdev) res = at91ether_get_hwaddr_dt(lp); if (res < 0) - get_mac_address(dev); /* Get ethernet address and store it in dev->dev_addr */ - - update_mac_address(dev); /* Program ethernet address into MAC */ + macb_get_hwaddr(lp); res = at91ether_get_phy_mode_dt(pdev); if (res < 0) {