From: Joachim Eastwood <manabian@gmail.com>
To: nicolas.ferre@atmel.com, davem@davemloft.net
Cc: plagnioj@jcrosoft.com, netdev@vger.kernel.org,
Joachim Eastwood <manabian@gmail.com>
Subject: [PATCH 4/8] net/at91_ether: use macb functions for get/set hwaddr
Date: Wed, 7 Nov 2012 19:14:53 +0100 [thread overview]
Message-ID: <1352312097-31320-5-git-send-email-manabian@gmail.com> (raw)
In-Reply-To: <1352312097-31320-1-git-send-email-manabian@gmail.com>
Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
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) {
--
1.8.0
next prev parent reply other threads:[~2012-11-07 18:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-07 18:14 [PATCH 0/8] at91_ether share stats/address setting with macb Joachim Eastwood
2012-11-07 18:14 ` [PATCH 1/8] net/macb: check all address registers sets Joachim Eastwood
2012-11-07 18:14 ` [PATCH 2/8] net/macb: support reversed hw addr Joachim Eastwood
2012-11-07 18:14 ` [PATCH 3/8] net/macb: export macb_set_hwaddr and macb_get_hwaddr Joachim Eastwood
2012-11-07 18:14 ` Joachim Eastwood [this message]
2012-11-07 18:14 ` [PATCH 5/8] net/at91_ether: use stat function from macb Joachim Eastwood
2012-11-07 18:14 ` [PATCH 6/8] net/at91_ether: drop board_data private struct member Joachim Eastwood
2012-11-07 18:14 ` [PATCH 7/8] net/at91_ether: clean up print outs Joachim Eastwood
2012-11-07 18:14 ` [PATCH 8/8] net/at91_ether: fix comment and style issues Joachim Eastwood
2012-11-07 22:45 ` [PATCH 0/8] at91_ether share stats/address setting with macb David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1352312097-31320-5-git-send-email-manabian@gmail.com \
--to=manabian@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@atmel.com \
--cc=plagnioj@jcrosoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).