aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorJoachim Eastwood <manabian@gmail.com>2012-11-07 03:14:53 -0500
committerDavid S. Miller <davem@davemloft.net>2012-11-07 17:44:37 -0500
commit3423247667fc0ffedd7ad682a8751a7dade09e86 (patch)
tree5cea77b2cd2180819e6581a2399785fdfda23579 /drivers/net
parent314bccc4f5b625f9c5a2cf7d74a610cc2612272a (diff)
net/at91_ether: use macb functions for get/set hwaddr
Signed-off-by: Joachim Eastwood <manabian@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/ethernet/cadence/at91_ether.c112
1 files changed, 3 insertions, 109 deletions
diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
index 6eb928ea276d..2f89e645fb01 100644
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ b/drivers/net/ethernet/cadence/at91_ether.c
@@ -46,109 +46,6 @@
46/* max number of receive buffers */ 46/* max number of receive buffers */
47#define MAX_RX_DESCR 9 47#define MAX_RX_DESCR 9
48 48
49/* ......................... ADDRESS MANAGEMENT ........................ */
50
51/*
52 * NOTE: Your bootloader must always set the MAC address correctly before
53 * booting into Linux.
54 *
55 * - It must always set the MAC address after reset, even if it doesn't
56 * happen to access the Ethernet while it's booting. Some versions of
57 * U-Boot on the AT91RM9200-DK do not do this.
58 *
59 * - Likewise it must store the addresses in the correct byte order.
60 * MicroMonitor (uMon) on the CSB337 does this incorrectly (and
61 * continues to do so, for bug-compatibility).
62 */
63
64static short __init unpack_mac_address(struct net_device *dev, unsigned int hi, unsigned int lo)
65{
66 struct macb *lp = netdev_priv(dev);
67 char addr[6];
68
69 if (lp->board_data.rev_eth_addr) {
70 addr[5] = (lo & 0xff); /* The CSB337 bootloader stores the MAC the wrong-way around */
71 addr[4] = (lo & 0xff00) >> 8;
72 addr[3] = (lo & 0xff0000) >> 16;
73 addr[2] = (lo & 0xff000000) >> 24;
74 addr[1] = (hi & 0xff);
75 addr[0] = (hi & 0xff00) >> 8;
76 }
77 else {
78 addr[0] = (lo & 0xff);
79 addr[1] = (lo & 0xff00) >> 8;
80 addr[2] = (lo & 0xff0000) >> 16;
81 addr[3] = (lo & 0xff000000) >> 24;
82 addr[4] = (hi & 0xff);
83 addr[5] = (hi & 0xff00) >> 8;
84 }
85
86 if (is_valid_ether_addr(addr)) {
87 memcpy(dev->dev_addr, &addr, 6);
88 return 1;
89 }
90 return 0;
91}
92
93/*
94 * Set the ethernet MAC address in dev->dev_addr
95 */
96static void __init get_mac_address(struct net_device *dev)
97{
98 struct macb *lp = netdev_priv(dev);
99
100 /* Check Specific-Address 1 */
101 if (unpack_mac_address(dev, macb_readl(lp, SA1T), macb_readl(lp, SA1B)))
102 return;
103 /* Check Specific-Address 2 */
104 if (unpack_mac_address(dev, macb_readl(lp, SA2T), macb_readl(lp, SA2B)))
105 return;
106 /* Check Specific-Address 3 */
107 if (unpack_mac_address(dev, macb_readl(lp, SA3T), macb_readl(lp, SA3B)))
108 return;
109 /* Check Specific-Address 4 */
110 if (unpack_mac_address(dev, macb_readl(lp, SA4T), macb_readl(lp, SA4B)))
111 return;
112
113 printk(KERN_ERR "at91_ether: Your bootloader did not configure a MAC address.\n");
114}
115
116/*
117 * Program the hardware MAC address from dev->dev_addr.
118 */
119static void update_mac_address(struct net_device *dev)
120{
121 struct macb *lp = netdev_priv(dev);
122
123 macb_writel(lp, SA1B, (dev->dev_addr[3] << 24) | (dev->dev_addr[2] << 16)
124 | (dev->dev_addr[1] << 8) | (dev->dev_addr[0]));
125 macb_writel(lp, SA1T, (dev->dev_addr[5] << 8) | (dev->dev_addr[4]));
126
127 macb_writel(lp, SA2B, 0);
128 macb_writel(lp, SA2T, 0);
129}
130
131/*
132 * Store the new hardware address in dev->dev_addr, and update the MAC.
133 */
134static int set_mac_address(struct net_device *dev, void* addr)
135{
136 struct sockaddr *address = addr;
137
138 if (!is_valid_ether_addr(address->sa_data))
139 return -EADDRNOTAVAIL;
140
141 memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
142 update_mac_address(dev);
143
144 printk("%s: Setting MAC address to %pM\n", dev->name,
145 dev->dev_addr);
146
147 return 0;
148}
149
150/* ................................ MAC ................................ */
151
152/* 49/*
153 * Initialize and start the Receiver and Transmit subsystems 50 * Initialize and start the Receiver and Transmit subsystems
154 */ 51 */
@@ -219,8 +116,7 @@ static int at91ether_open(struct net_device *dev)
219 ctl = macb_readl(lp, NCR); 116 ctl = macb_readl(lp, NCR);
220 macb_writel(lp, NCR, ctl | MACB_BIT(CLRSTAT)); 117 macb_writel(lp, NCR, ctl | MACB_BIT(CLRSTAT));
221 118
222 /* Update the MAC address (incase user has changed it) */ 119 macb_set_hwaddr(lp);
223 update_mac_address(dev);
224 120
225 ret = at91ether_start(dev); 121 ret = at91ether_start(dev);
226 if (ret) 122 if (ret)
@@ -438,7 +334,7 @@ static const struct net_device_ops at91ether_netdev_ops = {
438 .ndo_start_xmit = at91ether_start_xmit, 334 .ndo_start_xmit = at91ether_start_xmit,
439 .ndo_get_stats = at91ether_stats, 335 .ndo_get_stats = at91ether_stats,
440 .ndo_set_rx_mode = macb_set_rx_mode, 336 .ndo_set_rx_mode = macb_set_rx_mode,
441 .ndo_set_mac_address = set_mac_address, 337 .ndo_set_mac_address = eth_mac_addr,
442 .ndo_do_ioctl = macb_ioctl, 338 .ndo_do_ioctl = macb_ioctl,
443 .ndo_validate_addr = eth_validate_addr, 339 .ndo_validate_addr = eth_validate_addr,
444 .ndo_change_mtu = eth_change_mtu, 340 .ndo_change_mtu = eth_change_mtu,
@@ -557,9 +453,7 @@ static int __init at91ether_probe(struct platform_device *pdev)
557 453
558 res = at91ether_get_hwaddr_dt(lp); 454 res = at91ether_get_hwaddr_dt(lp);
559 if (res < 0) 455 if (res < 0)
560 get_mac_address(dev); /* Get ethernet address and store it in dev->dev_addr */ 456 macb_get_hwaddr(lp);
561
562 update_mac_address(dev); /* Program ethernet address into MAC */
563 457
564 res = at91ether_get_phy_mode_dt(pdev); 458 res = at91ether_get_phy_mode_dt(pdev);
565 if (res < 0) { 459 if (res < 0) {