blob: edb2aba9045c0e182d7d8188731fb61646e88766 [file] [log] [blame]
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001/*
Jamie Ilesf75ba502011-11-08 10:12:32 +00002 * Cadence MACB/GEM Ethernet Controller driver
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01003 *
4 * Copyright (C) 2004-2006 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
Jamie Ilesc220f8c2011-03-08 20:27:08 +000011#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010012#include <linux/clk.h>
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/slab.h>
18#include <linux/init.h>
Joachim Eastwood2dbfdbb92012-11-11 13:56:27 +000019#include <linux/gpio.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000020#include <linux/interrupt.h>
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010021#include <linux/netdevice.h>
22#include <linux/etherdevice.h>
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010023#include <linux/dma-mapping.h>
Jamie Iles84e0cdb2011-03-08 20:17:06 +000024#include <linux/platform_data/macb.h>
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010025#include <linux/platform_device.h>
frederic RODO6c36a702007-07-12 19:07:24 +020026#include <linux/phy.h>
Olof Johanssonb17471f2011-12-20 13:13:07 -080027#include <linux/of.h>
Jean-Christophe PLAGNIOL-VILLARDfb97a842011-11-18 15:29:25 +010028#include <linux/of_device.h>
29#include <linux/of_net.h>
Jean-Christophe PLAGNIOL-VILLARD8ef29f8a2012-10-31 06:04:59 +000030#include <linux/pinctrl/consumer.h>
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010031
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010032#include "macb.h"
33
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010034#define RX_BUFFER_SIZE 128
Havard Skinnemoen55054a12012-10-31 06:04:55 +000035#define RX_RING_SIZE 512 /* must be power of 2 */
36#define RX_RING_BYTES (sizeof(struct macb_dma_desc) * RX_RING_SIZE)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010037
Havard Skinnemoen55054a12012-10-31 06:04:55 +000038#define TX_RING_SIZE 128 /* must be power of 2 */
39#define TX_RING_BYTES (sizeof(struct macb_dma_desc) * TX_RING_SIZE)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010040
41/* minimum number of free TX descriptors before waking up TX process */
42#define MACB_TX_WAKEUP_THRESH (TX_RING_SIZE / 4)
43
44#define MACB_RX_INT_FLAGS (MACB_BIT(RCOMP) | MACB_BIT(RXUBR) \
45 | MACB_BIT(ISR_ROVR))
Nicolas Ferree86cd532012-10-31 06:04:57 +000046#define MACB_TX_ERR_FLAGS (MACB_BIT(ISR_TUND) \
47 | MACB_BIT(ISR_RLE) \
48 | MACB_BIT(TXERR))
49#define MACB_TX_INT_FLAGS (MACB_TX_ERR_FLAGS | MACB_BIT(TCOMP))
50
51/*
52 * Graceful stop timeouts in us. We should allow up to
53 * 1 frame time (10 Mbits/s, full-duplex, ignoring collisions)
54 */
55#define MACB_HALT_TIMEOUT 1230
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010056
Havard Skinnemoen55054a12012-10-31 06:04:55 +000057/* Ring buffer accessors */
58static unsigned int macb_tx_ring_wrap(unsigned int index)
59{
60 return index & (TX_RING_SIZE - 1);
61}
62
63static unsigned int macb_tx_ring_avail(struct macb *bp)
64{
65 return (bp->tx_tail - bp->tx_head) & (TX_RING_SIZE - 1);
66}
67
68static struct macb_dma_desc *macb_tx_desc(struct macb *bp, unsigned int index)
69{
70 return &bp->tx_ring[macb_tx_ring_wrap(index)];
71}
72
73static struct macb_tx_skb *macb_tx_skb(struct macb *bp, unsigned int index)
74{
75 return &bp->tx_skb[macb_tx_ring_wrap(index)];
76}
77
78static dma_addr_t macb_tx_dma(struct macb *bp, unsigned int index)
79{
80 dma_addr_t offset;
81
82 offset = macb_tx_ring_wrap(index) * sizeof(struct macb_dma_desc);
83
84 return bp->tx_ring_dma + offset;
85}
86
87static unsigned int macb_rx_ring_wrap(unsigned int index)
88{
89 return index & (RX_RING_SIZE - 1);
90}
91
92static struct macb_dma_desc *macb_rx_desc(struct macb *bp, unsigned int index)
93{
94 return &bp->rx_ring[macb_rx_ring_wrap(index)];
95}
96
97static void *macb_rx_buffer(struct macb *bp, unsigned int index)
98{
99 return bp->rx_buffers + RX_BUFFER_SIZE * macb_rx_ring_wrap(index);
100}
101
Joachim Eastwood314bccc2012-11-07 08:14:52 +0000102void macb_set_hwaddr(struct macb *bp)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100103{
104 u32 bottom;
105 u16 top;
106
107 bottom = cpu_to_le32(*((u32 *)bp->dev->dev_addr));
Jamie Ilesf75ba502011-11-08 10:12:32 +0000108 macb_or_gem_writel(bp, SA1B, bottom);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100109 top = cpu_to_le16(*((u16 *)(bp->dev->dev_addr + 4)));
Jamie Ilesf75ba502011-11-08 10:12:32 +0000110 macb_or_gem_writel(bp, SA1T, top);
Joachim Eastwood3629a6c2012-11-11 13:56:28 +0000111
112 /* Clear unused address register sets */
113 macb_or_gem_writel(bp, SA2B, 0);
114 macb_or_gem_writel(bp, SA2T, 0);
115 macb_or_gem_writel(bp, SA3B, 0);
116 macb_or_gem_writel(bp, SA3T, 0);
117 macb_or_gem_writel(bp, SA4B, 0);
118 macb_or_gem_writel(bp, SA4T, 0);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100119}
Joachim Eastwood314bccc2012-11-07 08:14:52 +0000120EXPORT_SYMBOL_GPL(macb_set_hwaddr);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100121
Joachim Eastwood314bccc2012-11-07 08:14:52 +0000122void macb_get_hwaddr(struct macb *bp)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100123{
Joachim Eastwoodd25e78a2012-11-07 08:14:51 +0000124 struct macb_platform_data *pdata;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100125 u32 bottom;
126 u16 top;
127 u8 addr[6];
Joachim Eastwood17b8bb32012-11-07 08:14:50 +0000128 int i;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100129
Joachim Eastwoodd25e78a2012-11-07 08:14:51 +0000130 pdata = bp->pdev->dev.platform_data;
131
Joachim Eastwood17b8bb32012-11-07 08:14:50 +0000132 /* Check all 4 address register for vaild address */
133 for (i = 0; i < 4; i++) {
134 bottom = macb_or_gem_readl(bp, SA1B + i * 8);
135 top = macb_or_gem_readl(bp, SA1T + i * 8);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100136
Joachim Eastwoodd25e78a2012-11-07 08:14:51 +0000137 if (pdata && pdata->rev_eth_addr) {
138 addr[5] = bottom & 0xff;
139 addr[4] = (bottom >> 8) & 0xff;
140 addr[3] = (bottom >> 16) & 0xff;
141 addr[2] = (bottom >> 24) & 0xff;
142 addr[1] = top & 0xff;
143 addr[0] = (top & 0xff00) >> 8;
144 } else {
145 addr[0] = bottom & 0xff;
146 addr[1] = (bottom >> 8) & 0xff;
147 addr[2] = (bottom >> 16) & 0xff;
148 addr[3] = (bottom >> 24) & 0xff;
149 addr[4] = top & 0xff;
150 addr[5] = (top >> 8) & 0xff;
151 }
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100152
Joachim Eastwood17b8bb32012-11-07 08:14:50 +0000153 if (is_valid_ether_addr(addr)) {
154 memcpy(bp->dev->dev_addr, addr, sizeof(addr));
155 return;
156 }
Sven Schnelled1d57412008-06-09 16:33:57 -0700157 }
Joachim Eastwood17b8bb32012-11-07 08:14:50 +0000158
159 netdev_info(bp->dev, "invalid hw address, using random\n");
160 eth_hw_addr_random(bp->dev);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100161}
Joachim Eastwood314bccc2012-11-07 08:14:52 +0000162EXPORT_SYMBOL_GPL(macb_get_hwaddr);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100163
frederic RODO6c36a702007-07-12 19:07:24 +0200164static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100165{
frederic RODO6c36a702007-07-12 19:07:24 +0200166 struct macb *bp = bus->priv;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100167 int value;
168
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100169 macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
170 | MACB_BF(RW, MACB_MAN_READ)
frederic RODO6c36a702007-07-12 19:07:24 +0200171 | MACB_BF(PHYA, mii_id)
172 | MACB_BF(REGA, regnum)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100173 | MACB_BF(CODE, MACB_MAN_CODE)));
174
frederic RODO6c36a702007-07-12 19:07:24 +0200175 /* wait for end of transfer */
176 while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
177 cpu_relax();
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100178
179 value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100180
181 return value;
182}
183
frederic RODO6c36a702007-07-12 19:07:24 +0200184static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
185 u16 value)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100186{
frederic RODO6c36a702007-07-12 19:07:24 +0200187 struct macb *bp = bus->priv;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100188
189 macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
190 | MACB_BF(RW, MACB_MAN_WRITE)
frederic RODO6c36a702007-07-12 19:07:24 +0200191 | MACB_BF(PHYA, mii_id)
192 | MACB_BF(REGA, regnum)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100193 | MACB_BF(CODE, MACB_MAN_CODE)
frederic RODO6c36a702007-07-12 19:07:24 +0200194 | MACB_BF(DATA, value)));
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100195
frederic RODO6c36a702007-07-12 19:07:24 +0200196 /* wait for end of transfer */
197 while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
198 cpu_relax();
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100199
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100200 return 0;
201}
202
frederic RODO6c36a702007-07-12 19:07:24 +0200203static int macb_mdio_reset(struct mii_bus *bus)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100204{
frederic RODO6c36a702007-07-12 19:07:24 +0200205 return 0;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100206}
207
frederic RODO6c36a702007-07-12 19:07:24 +0200208static void macb_handle_link_change(struct net_device *dev)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100209{
frederic RODO6c36a702007-07-12 19:07:24 +0200210 struct macb *bp = netdev_priv(dev);
211 struct phy_device *phydev = bp->phy_dev;
212 unsigned long flags;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100213
frederic RODO6c36a702007-07-12 19:07:24 +0200214 int status_change = 0;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100215
frederic RODO6c36a702007-07-12 19:07:24 +0200216 spin_lock_irqsave(&bp->lock, flags);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100217
frederic RODO6c36a702007-07-12 19:07:24 +0200218 if (phydev->link) {
219 if ((bp->speed != phydev->speed) ||
220 (bp->duplex != phydev->duplex)) {
221 u32 reg;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100222
frederic RODO6c36a702007-07-12 19:07:24 +0200223 reg = macb_readl(bp, NCFGR);
224 reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
Patrice Vilchez140b7552012-10-31 06:04:50 +0000225 if (macb_is_gem(bp))
226 reg &= ~GEM_BIT(GBE);
frederic RODO6c36a702007-07-12 19:07:24 +0200227
228 if (phydev->duplex)
229 reg |= MACB_BIT(FD);
Atsushi Nemoto179956f2008-02-21 22:50:54 +0900230 if (phydev->speed == SPEED_100)
frederic RODO6c36a702007-07-12 19:07:24 +0200231 reg |= MACB_BIT(SPD);
Patrice Vilchez140b7552012-10-31 06:04:50 +0000232 if (phydev->speed == SPEED_1000)
233 reg |= GEM_BIT(GBE);
frederic RODO6c36a702007-07-12 19:07:24 +0200234
Patrice Vilchez140b7552012-10-31 06:04:50 +0000235 macb_or_gem_writel(bp, NCFGR, reg);
frederic RODO6c36a702007-07-12 19:07:24 +0200236
237 bp->speed = phydev->speed;
238 bp->duplex = phydev->duplex;
239 status_change = 1;
240 }
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100241 }
242
frederic RODO6c36a702007-07-12 19:07:24 +0200243 if (phydev->link != bp->link) {
Anton Vorontsovc8f15682008-07-22 15:41:24 -0700244 if (!phydev->link) {
frederic RODO6c36a702007-07-12 19:07:24 +0200245 bp->speed = 0;
246 bp->duplex = -1;
247 }
248 bp->link = phydev->link;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100249
frederic RODO6c36a702007-07-12 19:07:24 +0200250 status_change = 1;
251 }
252
253 spin_unlock_irqrestore(&bp->lock, flags);
254
255 if (status_change) {
Nicolas Ferre03fc4722012-07-03 23:14:13 +0000256 if (phydev->link) {
257 netif_carrier_on(dev);
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000258 netdev_info(dev, "link up (%d/%s)\n",
259 phydev->speed,
260 phydev->duplex == DUPLEX_FULL ?
261 "Full" : "Half");
Nicolas Ferre03fc4722012-07-03 23:14:13 +0000262 } else {
263 netif_carrier_off(dev);
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000264 netdev_info(dev, "link down\n");
Nicolas Ferre03fc4722012-07-03 23:14:13 +0000265 }
frederic RODO6c36a702007-07-12 19:07:24 +0200266 }
267}
268
269/* based on au1000_eth. c*/
270static int macb_mii_probe(struct net_device *dev)
271{
272 struct macb *bp = netdev_priv(dev);
Joachim Eastwood2dbfdbb92012-11-11 13:56:27 +0000273 struct macb_platform_data *pdata;
Jiri Pirko7455a762010-02-08 05:12:08 +0000274 struct phy_device *phydev;
Joachim Eastwood2dbfdbb92012-11-11 13:56:27 +0000275 int phy_irq;
Jiri Pirko7455a762010-02-08 05:12:08 +0000276 int ret;
frederic RODO6c36a702007-07-12 19:07:24 +0200277
Jiri Pirko7455a762010-02-08 05:12:08 +0000278 phydev = phy_find_first(bp->mii_bus);
frederic RODO6c36a702007-07-12 19:07:24 +0200279 if (!phydev) {
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000280 netdev_err(dev, "no PHY found\n");
frederic RODO6c36a702007-07-12 19:07:24 +0200281 return -1;
282 }
283
Joachim Eastwood2dbfdbb92012-11-11 13:56:27 +0000284 pdata = dev_get_platdata(&bp->pdev->dev);
285 if (pdata && gpio_is_valid(pdata->phy_irq_pin)) {
286 ret = devm_gpio_request(&bp->pdev->dev, pdata->phy_irq_pin, "phy int");
287 if (!ret) {
288 phy_irq = gpio_to_irq(pdata->phy_irq_pin);
289 phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq;
290 }
291 }
frederic RODO6c36a702007-07-12 19:07:24 +0200292
293 /* attach the mac to the phy */
Jiri Pirko7455a762010-02-08 05:12:08 +0000294 ret = phy_connect_direct(dev, phydev, &macb_handle_link_change, 0,
Jean-Christophe PLAGNIOL-VILLARDfb97a842011-11-18 15:29:25 +0100295 bp->phy_interface);
Jiri Pirko7455a762010-02-08 05:12:08 +0000296 if (ret) {
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000297 netdev_err(dev, "Could not attach to PHY\n");
Jiri Pirko7455a762010-02-08 05:12:08 +0000298 return ret;
frederic RODO6c36a702007-07-12 19:07:24 +0200299 }
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100300
frederic RODO6c36a702007-07-12 19:07:24 +0200301 /* mask with MAC supported features */
Patrice Vilchez140b7552012-10-31 06:04:50 +0000302 if (macb_is_gem(bp))
303 phydev->supported &= PHY_GBIT_FEATURES;
304 else
305 phydev->supported &= PHY_BASIC_FEATURES;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100306
frederic RODO6c36a702007-07-12 19:07:24 +0200307 phydev->advertising = phydev->supported;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100308
frederic RODO6c36a702007-07-12 19:07:24 +0200309 bp->link = 0;
310 bp->speed = 0;
311 bp->duplex = -1;
312 bp->phy_dev = phydev;
313
314 return 0;
315}
316
Joachim Eastwood0005f542012-10-18 11:01:12 +0000317int macb_mii_init(struct macb *bp)
frederic RODO6c36a702007-07-12 19:07:24 +0200318{
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000319 struct macb_platform_data *pdata;
frederic RODO6c36a702007-07-12 19:07:24 +0200320 int err = -ENXIO, i;
321
Uwe Kleine-Koenig3dbda772009-07-23 08:31:31 +0200322 /* Enable management port */
frederic RODO6c36a702007-07-12 19:07:24 +0200323 macb_writel(bp, NCR, MACB_BIT(MPE));
324
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700325 bp->mii_bus = mdiobus_alloc();
326 if (bp->mii_bus == NULL) {
frederic RODO6c36a702007-07-12 19:07:24 +0200327 err = -ENOMEM;
328 goto err_out;
329 }
330
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700331 bp->mii_bus->name = "MACB_mii_bus";
332 bp->mii_bus->read = &macb_mdio_read;
333 bp->mii_bus->write = &macb_mdio_write;
334 bp->mii_bus->reset = &macb_mdio_reset;
Florian Fainelli98d5e572012-01-09 23:59:11 +0000335 snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
336 bp->pdev->name, bp->pdev->id);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700337 bp->mii_bus->priv = bp;
338 bp->mii_bus->parent = &bp->dev->dev;
339 pdata = bp->pdev->dev.platform_data;
340
341 if (pdata)
342 bp->mii_bus->phy_mask = pdata->phy_mask;
343
344 bp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
345 if (!bp->mii_bus->irq) {
346 err = -ENOMEM;
347 goto err_out_free_mdiobus;
348 }
349
frederic RODO6c36a702007-07-12 19:07:24 +0200350 for (i = 0; i < PHY_MAX_ADDR; i++)
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700351 bp->mii_bus->irq[i] = PHY_POLL;
frederic RODO6c36a702007-07-12 19:07:24 +0200352
Jamie Iles91523942011-02-28 04:05:25 +0000353 dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
frederic RODO6c36a702007-07-12 19:07:24 +0200354
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700355 if (mdiobus_register(bp->mii_bus))
frederic RODO6c36a702007-07-12 19:07:24 +0200356 goto err_out_free_mdio_irq;
357
358 if (macb_mii_probe(bp->dev) != 0) {
359 goto err_out_unregister_bus;
360 }
361
362 return 0;
363
364err_out_unregister_bus:
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700365 mdiobus_unregister(bp->mii_bus);
frederic RODO6c36a702007-07-12 19:07:24 +0200366err_out_free_mdio_irq:
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700367 kfree(bp->mii_bus->irq);
368err_out_free_mdiobus:
369 mdiobus_free(bp->mii_bus);
frederic RODO6c36a702007-07-12 19:07:24 +0200370err_out:
371 return err;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100372}
Joachim Eastwood0005f542012-10-18 11:01:12 +0000373EXPORT_SYMBOL_GPL(macb_mii_init);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100374
375static void macb_update_stats(struct macb *bp)
376{
377 u32 __iomem *reg = bp->regs + MACB_PFR;
Jamie Ilesa494ed82011-03-09 16:26:35 +0000378 u32 *p = &bp->hw_stats.macb.rx_pause_frames;
379 u32 *end = &bp->hw_stats.macb.tx_pause_frames + 1;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100380
381 WARN_ON((unsigned long)(end - p - 1) != (MACB_TPF - MACB_PFR) / 4);
382
383 for(; p < end; p++, reg++)
Haavard Skinnemoen0f0d84e2006-12-08 14:38:30 +0100384 *p += __raw_readl(reg);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100385}
386
Nicolas Ferree86cd532012-10-31 06:04:57 +0000387static int macb_halt_tx(struct macb *bp)
388{
389 unsigned long halt_time, timeout;
390 u32 status;
391
392 macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(THALT));
393
394 timeout = jiffies + usecs_to_jiffies(MACB_HALT_TIMEOUT);
395 do {
396 halt_time = jiffies;
397 status = macb_readl(bp, TSR);
398 if (!(status & MACB_BIT(TGO)))
399 return 0;
400
401 usleep_range(10, 250);
402 } while (time_before(halt_time, timeout));
403
404 return -ETIMEDOUT;
405}
406
407static void macb_tx_error_task(struct work_struct *work)
408{
409 struct macb *bp = container_of(work, struct macb, tx_error_task);
410 struct macb_tx_skb *tx_skb;
411 struct sk_buff *skb;
412 unsigned int tail;
413
414 netdev_vdbg(bp->dev, "macb_tx_error_task: t = %u, h = %u\n",
415 bp->tx_tail, bp->tx_head);
416
417 /* Make sure nobody is trying to queue up new packets */
418 netif_stop_queue(bp->dev);
419
420 /*
421 * Stop transmission now
422 * (in case we have just queued new packets)
423 */
424 if (macb_halt_tx(bp))
425 /* Just complain for now, reinitializing TX path can be good */
426 netdev_err(bp->dev, "BUG: halt tx timed out\n");
427
428 /* No need for the lock here as nobody will interrupt us anymore */
429
430 /*
431 * Treat frames in TX queue including the ones that caused the error.
432 * Free transmit buffers in upper layer.
433 */
434 for (tail = bp->tx_tail; tail != bp->tx_head; tail++) {
435 struct macb_dma_desc *desc;
436 u32 ctrl;
437
438 desc = macb_tx_desc(bp, tail);
439 ctrl = desc->ctrl;
440 tx_skb = macb_tx_skb(bp, tail);
441 skb = tx_skb->skb;
442
443 if (ctrl & MACB_BIT(TX_USED)) {
444 netdev_vdbg(bp->dev, "txerr skb %u (data %p) TX complete\n",
445 macb_tx_ring_wrap(tail), skb->data);
446 bp->stats.tx_packets++;
447 bp->stats.tx_bytes += skb->len;
448 } else {
449 /*
450 * "Buffers exhausted mid-frame" errors may only happen
451 * if the driver is buggy, so complain loudly about those.
452 * Statistics are updated by hardware.
453 */
454 if (ctrl & MACB_BIT(TX_BUF_EXHAUSTED))
455 netdev_err(bp->dev,
456 "BUG: TX buffers exhausted mid-frame\n");
457
458 desc->ctrl = ctrl | MACB_BIT(TX_USED);
459 }
460
461 dma_unmap_single(&bp->pdev->dev, tx_skb->mapping, skb->len,
462 DMA_TO_DEVICE);
463 tx_skb->skb = NULL;
464 dev_kfree_skb(skb);
465 }
466
467 /* Make descriptor updates visible to hardware */
468 wmb();
469
470 /* Reinitialize the TX desc queue */
471 macb_writel(bp, TBQP, bp->tx_ring_dma);
472 /* Make TX ring reflect state of hardware */
473 bp->tx_head = bp->tx_tail = 0;
474
475 /* Now we are ready to start transmission again */
476 netif_wake_queue(bp->dev);
477
478 /* Housework before enabling TX IRQ */
479 macb_writel(bp, TSR, macb_readl(bp, TSR));
480 macb_writel(bp, IER, MACB_TX_INT_FLAGS);
481}
482
483static void macb_tx_interrupt(struct macb *bp)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100484{
485 unsigned int tail;
486 unsigned int head;
487 u32 status;
488
489 status = macb_readl(bp, TSR);
490 macb_writel(bp, TSR, status);
491
Nicolas Ferree86cd532012-10-31 06:04:57 +0000492 netdev_vdbg(bp->dev, "macb_tx_interrupt status = 0x%03lx\n",
493 (unsigned long)status);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100494
495 head = bp->tx_head;
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000496 for (tail = bp->tx_tail; tail != head; tail++) {
497 struct macb_tx_skb *tx_skb;
498 struct sk_buff *skb;
499 struct macb_dma_desc *desc;
500 u32 ctrl;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100501
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000502 desc = macb_tx_desc(bp, tail);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100503
Havard Skinnemoen03dbe052012-10-31 06:04:51 +0000504 /* Make hw descriptor updates visible to CPU */
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100505 rmb();
Havard Skinnemoen03dbe052012-10-31 06:04:51 +0000506
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000507 ctrl = desc->ctrl;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100508
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000509 if (!(ctrl & MACB_BIT(TX_USED)))
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100510 break;
511
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000512 tx_skb = macb_tx_skb(bp, tail);
513 skb = tx_skb->skb;
514
Havard Skinnemoena268adb2012-10-31 06:04:52 +0000515 netdev_vdbg(bp->dev, "skb %u (data %p) TX complete\n",
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000516 macb_tx_ring_wrap(tail), skb->data);
517 dma_unmap_single(&bp->pdev->dev, tx_skb->mapping, skb->len,
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100518 DMA_TO_DEVICE);
519 bp->stats.tx_packets++;
520 bp->stats.tx_bytes += skb->len;
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000521 tx_skb->skb = NULL;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100522 dev_kfree_skb_irq(skb);
523 }
524
525 bp->tx_tail = tail;
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000526 if (netif_queue_stopped(bp->dev)
527 && macb_tx_ring_avail(bp) > MACB_TX_WAKEUP_THRESH)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100528 netif_wake_queue(bp->dev);
529}
530
531static int macb_rx_frame(struct macb *bp, unsigned int first_frag,
532 unsigned int last_frag)
533{
534 unsigned int len;
535 unsigned int frag;
Havard Skinnemoen29bc2e12012-10-31 06:04:58 +0000536 unsigned int offset;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100537 struct sk_buff *skb;
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000538 struct macb_dma_desc *desc;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100539
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000540 desc = macb_rx_desc(bp, last_frag);
541 len = MACB_BFEXT(RX_FRMLEN, desc->ctrl);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100542
Havard Skinnemoena268adb2012-10-31 06:04:52 +0000543 netdev_vdbg(bp->dev, "macb_rx_frame frags %u - %u (len %u)\n",
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000544 macb_rx_ring_wrap(first_frag),
545 macb_rx_ring_wrap(last_frag), len);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100546
Havard Skinnemoen29bc2e12012-10-31 06:04:58 +0000547 /*
548 * The ethernet header starts NET_IP_ALIGN bytes into the
549 * first buffer. Since the header is 14 bytes, this makes the
550 * payload word-aligned.
551 *
552 * Instead of calling skb_reserve(NET_IP_ALIGN), we just copy
553 * the two padding bytes into the skb so that we avoid hitting
554 * the slowpath in memcpy(), and pull them off afterwards.
555 */
556 skb = netdev_alloc_skb(bp->dev, len + NET_IP_ALIGN);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100557 if (!skb) {
558 bp->stats.rx_dropped++;
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000559 for (frag = first_frag; ; frag++) {
560 desc = macb_rx_desc(bp, frag);
561 desc->addr &= ~MACB_BIT(RX_USED);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100562 if (frag == last_frag)
563 break;
564 }
Havard Skinnemoen03dbe052012-10-31 06:04:51 +0000565
566 /* Make descriptor updates visible to hardware */
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100567 wmb();
Havard Skinnemoen03dbe052012-10-31 06:04:51 +0000568
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100569 return 1;
570 }
571
Havard Skinnemoen29bc2e12012-10-31 06:04:58 +0000572 offset = 0;
573 len += NET_IP_ALIGN;
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700574 skb_checksum_none_assert(skb);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100575 skb_put(skb, len);
576
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000577 for (frag = first_frag; ; frag++) {
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100578 unsigned int frag_len = RX_BUFFER_SIZE;
579
580 if (offset + frag_len > len) {
581 BUG_ON(frag != last_frag);
582 frag_len = len - offset;
583 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300584 skb_copy_to_linear_data_offset(skb, offset,
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000585 macb_rx_buffer(bp, frag), frag_len);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100586 offset += RX_BUFFER_SIZE;
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000587 desc = macb_rx_desc(bp, frag);
588 desc->addr &= ~MACB_BIT(RX_USED);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100589
590 if (frag == last_frag)
591 break;
592 }
593
Havard Skinnemoen03dbe052012-10-31 06:04:51 +0000594 /* Make descriptor updates visible to hardware */
595 wmb();
596
Havard Skinnemoen29bc2e12012-10-31 06:04:58 +0000597 __skb_pull(skb, NET_IP_ALIGN);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100598 skb->protocol = eth_type_trans(skb, bp->dev);
599
600 bp->stats.rx_packets++;
Havard Skinnemoen29bc2e12012-10-31 06:04:58 +0000601 bp->stats.rx_bytes += skb->len;
Havard Skinnemoena268adb2012-10-31 06:04:52 +0000602 netdev_vdbg(bp->dev, "received skb of length %u, csum: %08x\n",
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000603 skb->len, skb->csum);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100604 netif_receive_skb(skb);
605
606 return 0;
607}
608
609/* Mark DMA descriptors from begin up to and not including end as unused */
610static void discard_partial_frame(struct macb *bp, unsigned int begin,
611 unsigned int end)
612{
613 unsigned int frag;
614
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000615 for (frag = begin; frag != end; frag++) {
616 struct macb_dma_desc *desc = macb_rx_desc(bp, frag);
617 desc->addr &= ~MACB_BIT(RX_USED);
618 }
Havard Skinnemoen03dbe052012-10-31 06:04:51 +0000619
620 /* Make descriptor updates visible to hardware */
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100621 wmb();
622
623 /*
624 * When this happens, the hardware stats registers for
625 * whatever caused this is updated, so we don't have to record
626 * anything.
627 */
628}
629
630static int macb_rx(struct macb *bp, int budget)
631{
632 int received = 0;
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000633 unsigned int tail;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100634 int first_frag = -1;
635
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000636 for (tail = bp->rx_tail; budget > 0; tail++) {
637 struct macb_dma_desc *desc = macb_rx_desc(bp, tail);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100638 u32 addr, ctrl;
639
Havard Skinnemoen03dbe052012-10-31 06:04:51 +0000640 /* Make hw descriptor updates visible to CPU */
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100641 rmb();
Havard Skinnemoen03dbe052012-10-31 06:04:51 +0000642
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000643 addr = desc->addr;
644 ctrl = desc->ctrl;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100645
646 if (!(addr & MACB_BIT(RX_USED)))
647 break;
648
649 if (ctrl & MACB_BIT(RX_SOF)) {
650 if (first_frag != -1)
651 discard_partial_frame(bp, first_frag, tail);
652 first_frag = tail;
653 }
654
655 if (ctrl & MACB_BIT(RX_EOF)) {
656 int dropped;
657 BUG_ON(first_frag == -1);
658
659 dropped = macb_rx_frame(bp, first_frag, tail);
660 first_frag = -1;
661 if (!dropped) {
662 received++;
663 budget--;
664 }
665 }
666 }
667
668 if (first_frag != -1)
669 bp->rx_tail = first_frag;
670 else
671 bp->rx_tail = tail;
672
673 return received;
674}
675
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700676static int macb_poll(struct napi_struct *napi, int budget)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100677{
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700678 struct macb *bp = container_of(napi, struct macb, napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700679 int work_done;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100680 u32 status;
681
682 status = macb_readl(bp, RSR);
683 macb_writel(bp, RSR, status);
684
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700685 work_done = 0;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100686
Havard Skinnemoena268adb2012-10-31 06:04:52 +0000687 netdev_vdbg(bp->dev, "poll: status = %08lx, budget = %d\n",
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000688 (unsigned long)status, budget);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100689
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700690 work_done = macb_rx(bp, budget);
Joshua Hokeb3363692010-10-25 01:44:22 +0000691 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800692 napi_complete(napi);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100693
Joshua Hokeb3363692010-10-25 01:44:22 +0000694 /*
695 * We've done what we can to clean the buffers. Make sure we
696 * get notified when new packets arrive.
697 */
698 macb_writel(bp, IER, MACB_RX_INT_FLAGS);
699 }
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100700
701 /* TODO: Handle errors */
702
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700703 return work_done;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100704}
705
706static irqreturn_t macb_interrupt(int irq, void *dev_id)
707{
708 struct net_device *dev = dev_id;
709 struct macb *bp = netdev_priv(dev);
710 u32 status;
711
712 status = macb_readl(bp, ISR);
713
714 if (unlikely(!status))
715 return IRQ_NONE;
716
717 spin_lock(&bp->lock);
718
719 while (status) {
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100720 /* close possible race with dev_close */
721 if (unlikely(!netif_running(dev))) {
Joachim Eastwood95ebcea2012-10-22 08:45:31 +0000722 macb_writel(bp, IDR, -1);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100723 break;
724 }
725
Havard Skinnemoena268adb2012-10-31 06:04:52 +0000726 netdev_vdbg(bp->dev, "isr = 0x%08lx\n", (unsigned long)status);
727
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100728 if (status & MACB_RX_INT_FLAGS) {
Joshua Hokeb3363692010-10-25 01:44:22 +0000729 /*
730 * There's no point taking any more interrupts
731 * until we have processed the buffers. The
732 * scheduling call may fail if the poll routine
733 * is already scheduled, so disable interrupts
734 * now.
735 */
736 macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
737
Ben Hutchings288379f2009-01-19 16:43:59 -0800738 if (napi_schedule_prep(&bp->napi)) {
Havard Skinnemoena268adb2012-10-31 06:04:52 +0000739 netdev_vdbg(bp->dev, "scheduling RX softirq\n");
Ben Hutchings288379f2009-01-19 16:43:59 -0800740 __napi_schedule(&bp->napi);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100741 }
742 }
743
Nicolas Ferree86cd532012-10-31 06:04:57 +0000744 if (unlikely(status & (MACB_TX_ERR_FLAGS))) {
745 macb_writel(bp, IDR, MACB_TX_INT_FLAGS);
746 schedule_work(&bp->tx_error_task);
747 break;
748 }
749
750 if (status & MACB_BIT(TCOMP))
751 macb_tx_interrupt(bp);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100752
753 /*
754 * Link change detection isn't possible with RMII, so we'll
755 * add that if/when we get our hands on a full-blown MII PHY.
756 */
757
Alexander Steinb19f7f72011-04-13 05:03:24 +0000758 if (status & MACB_BIT(ISR_ROVR)) {
759 /* We missed at least one packet */
Jamie Ilesf75ba502011-11-08 10:12:32 +0000760 if (macb_is_gem(bp))
761 bp->hw_stats.gem.rx_overruns++;
762 else
763 bp->hw_stats.macb.rx_overruns++;
Alexander Steinb19f7f72011-04-13 05:03:24 +0000764 }
765
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100766 if (status & MACB_BIT(HRESP)) {
767 /*
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000768 * TODO: Reset the hardware, and maybe move the
769 * netdev_err to a lower-priority context as well
770 * (work queue?)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100771 */
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000772 netdev_err(dev, "DMA bus error: HRESP not OK\n");
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100773 }
774
775 status = macb_readl(bp, ISR);
776 }
777
778 spin_unlock(&bp->lock);
779
780 return IRQ_HANDLED;
781}
782
Thomas Petazzoni6e8cf5c2009-05-04 11:08:41 -0700783#ifdef CONFIG_NET_POLL_CONTROLLER
784/*
785 * Polling receive - used by netconsole and other diagnostic tools
786 * to allow network i/o with interrupts disabled.
787 */
788static void macb_poll_controller(struct net_device *dev)
789{
790 unsigned long flags;
791
792 local_irq_save(flags);
793 macb_interrupt(dev->irq, dev);
794 local_irq_restore(flags);
795}
796#endif
797
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100798static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
799{
800 struct macb *bp = netdev_priv(dev);
801 dma_addr_t mapping;
802 unsigned int len, entry;
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000803 struct macb_dma_desc *desc;
804 struct macb_tx_skb *tx_skb;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100805 u32 ctrl;
Dongdong Deng48719532009-08-23 19:49:07 -0700806 unsigned long flags;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100807
Havard Skinnemoena268adb2012-10-31 06:04:52 +0000808#if defined(DEBUG) && defined(VERBOSE_DEBUG)
809 netdev_vdbg(bp->dev,
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000810 "start_xmit: len %u head %p data %p tail %p end %p\n",
811 skb->len, skb->head, skb->data,
812 skb_tail_pointer(skb), skb_end_pointer(skb));
813 print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_OFFSET, 16, 1,
814 skb->data, 16, true);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100815#endif
816
817 len = skb->len;
Dongdong Deng48719532009-08-23 19:49:07 -0700818 spin_lock_irqsave(&bp->lock, flags);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100819
820 /* This is a hard error, log it. */
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000821 if (macb_tx_ring_avail(bp) < 1) {
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100822 netif_stop_queue(dev);
Dongdong Deng48719532009-08-23 19:49:07 -0700823 spin_unlock_irqrestore(&bp->lock, flags);
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000824 netdev_err(bp->dev, "BUG! Tx Ring full when queue awake!\n");
825 netdev_dbg(bp->dev, "tx_head = %u, tx_tail = %u\n",
826 bp->tx_head, bp->tx_tail);
Patrick McHardy5b548142009-06-12 06:22:29 +0000827 return NETDEV_TX_BUSY;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100828 }
829
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000830 entry = macb_tx_ring_wrap(bp->tx_head);
831 bp->tx_head++;
Havard Skinnemoena268adb2012-10-31 06:04:52 +0000832 netdev_vdbg(bp->dev, "Allocated ring entry %u\n", entry);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100833 mapping = dma_map_single(&bp->pdev->dev, skb->data,
834 len, DMA_TO_DEVICE);
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000835
836 tx_skb = &bp->tx_skb[entry];
837 tx_skb->skb = skb;
838 tx_skb->mapping = mapping;
Havard Skinnemoena268adb2012-10-31 06:04:52 +0000839 netdev_vdbg(bp->dev, "Mapped skb data %p to DMA addr %08lx\n",
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000840 skb->data, (unsigned long)mapping);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100841
842 ctrl = MACB_BF(TX_FRMLEN, len);
843 ctrl |= MACB_BIT(TX_LAST);
844 if (entry == (TX_RING_SIZE - 1))
845 ctrl |= MACB_BIT(TX_WRAP);
846
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000847 desc = &bp->tx_ring[entry];
848 desc->addr = mapping;
849 desc->ctrl = ctrl;
Havard Skinnemoen03dbe052012-10-31 06:04:51 +0000850
851 /* Make newly initialized descriptor visible to hardware */
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100852 wmb();
853
Richard Cochrane0720922011-06-19 21:51:28 +0000854 skb_tx_timestamp(skb);
855
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100856 macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART));
857
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000858 if (macb_tx_ring_avail(bp) < 1)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100859 netif_stop_queue(dev);
860
Dongdong Deng48719532009-08-23 19:49:07 -0700861 spin_unlock_irqrestore(&bp->lock, flags);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100862
Patrick McHardy6ed10652009-06-23 06:03:08 +0000863 return NETDEV_TX_OK;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100864}
865
866static void macb_free_consistent(struct macb *bp)
867{
868 if (bp->tx_skb) {
869 kfree(bp->tx_skb);
870 bp->tx_skb = NULL;
871 }
872 if (bp->rx_ring) {
873 dma_free_coherent(&bp->pdev->dev, RX_RING_BYTES,
874 bp->rx_ring, bp->rx_ring_dma);
875 bp->rx_ring = NULL;
876 }
877 if (bp->tx_ring) {
878 dma_free_coherent(&bp->pdev->dev, TX_RING_BYTES,
879 bp->tx_ring, bp->tx_ring_dma);
880 bp->tx_ring = NULL;
881 }
882 if (bp->rx_buffers) {
883 dma_free_coherent(&bp->pdev->dev,
884 RX_RING_SIZE * RX_BUFFER_SIZE,
885 bp->rx_buffers, bp->rx_buffers_dma);
886 bp->rx_buffers = NULL;
887 }
888}
889
890static int macb_alloc_consistent(struct macb *bp)
891{
892 int size;
893
Havard Skinnemoen55054a12012-10-31 06:04:55 +0000894 size = TX_RING_SIZE * sizeof(struct macb_tx_skb);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100895 bp->tx_skb = kmalloc(size, GFP_KERNEL);
896 if (!bp->tx_skb)
897 goto out_err;
898
899 size = RX_RING_BYTES;
900 bp->rx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
901 &bp->rx_ring_dma, GFP_KERNEL);
902 if (!bp->rx_ring)
903 goto out_err;
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000904 netdev_dbg(bp->dev,
905 "Allocated RX ring of %d bytes at %08lx (mapped %p)\n",
906 size, (unsigned long)bp->rx_ring_dma, bp->rx_ring);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100907
908 size = TX_RING_BYTES;
909 bp->tx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
910 &bp->tx_ring_dma, GFP_KERNEL);
911 if (!bp->tx_ring)
912 goto out_err;
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000913 netdev_dbg(bp->dev,
914 "Allocated TX ring of %d bytes at %08lx (mapped %p)\n",
915 size, (unsigned long)bp->tx_ring_dma, bp->tx_ring);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100916
917 size = RX_RING_SIZE * RX_BUFFER_SIZE;
918 bp->rx_buffers = dma_alloc_coherent(&bp->pdev->dev, size,
919 &bp->rx_buffers_dma, GFP_KERNEL);
920 if (!bp->rx_buffers)
921 goto out_err;
Jamie Ilesc220f8c2011-03-08 20:27:08 +0000922 netdev_dbg(bp->dev,
923 "Allocated RX buffers of %d bytes at %08lx (mapped %p)\n",
924 size, (unsigned long)bp->rx_buffers_dma, bp->rx_buffers);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100925
926 return 0;
927
928out_err:
929 macb_free_consistent(bp);
930 return -ENOMEM;
931}
932
933static void macb_init_rings(struct macb *bp)
934{
935 int i;
936 dma_addr_t addr;
937
938 addr = bp->rx_buffers_dma;
939 for (i = 0; i < RX_RING_SIZE; i++) {
940 bp->rx_ring[i].addr = addr;
941 bp->rx_ring[i].ctrl = 0;
942 addr += RX_BUFFER_SIZE;
943 }
944 bp->rx_ring[RX_RING_SIZE - 1].addr |= MACB_BIT(RX_WRAP);
945
946 for (i = 0; i < TX_RING_SIZE; i++) {
947 bp->tx_ring[i].addr = 0;
948 bp->tx_ring[i].ctrl = MACB_BIT(TX_USED);
949 }
950 bp->tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP);
951
952 bp->rx_tail = bp->tx_head = bp->tx_tail = 0;
953}
954
955static void macb_reset_hw(struct macb *bp)
956{
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100957 /*
958 * Disable RX and TX (XXX: Should we halt the transmission
959 * more gracefully?)
960 */
961 macb_writel(bp, NCR, 0);
962
963 /* Clear the stats registers (XXX: Update stats first?) */
964 macb_writel(bp, NCR, MACB_BIT(CLRSTAT));
965
966 /* Clear all status flags */
Joachim Eastwood95ebcea2012-10-22 08:45:31 +0000967 macb_writel(bp, TSR, -1);
968 macb_writel(bp, RSR, -1);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100969
970 /* Disable all interrupts */
Joachim Eastwood95ebcea2012-10-22 08:45:31 +0000971 macb_writel(bp, IDR, -1);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100972 macb_readl(bp, ISR);
973}
974
Jamie Iles70c9f3d2011-03-09 16:22:54 +0000975static u32 gem_mdc_clk_div(struct macb *bp)
976{
977 u32 config;
978 unsigned long pclk_hz = clk_get_rate(bp->pclk);
979
980 if (pclk_hz <= 20000000)
981 config = GEM_BF(CLK, GEM_CLK_DIV8);
982 else if (pclk_hz <= 40000000)
983 config = GEM_BF(CLK, GEM_CLK_DIV16);
984 else if (pclk_hz <= 80000000)
985 config = GEM_BF(CLK, GEM_CLK_DIV32);
986 else if (pclk_hz <= 120000000)
987 config = GEM_BF(CLK, GEM_CLK_DIV48);
988 else if (pclk_hz <= 160000000)
989 config = GEM_BF(CLK, GEM_CLK_DIV64);
990 else
991 config = GEM_BF(CLK, GEM_CLK_DIV96);
992
993 return config;
994}
995
996static u32 macb_mdc_clk_div(struct macb *bp)
997{
998 u32 config;
999 unsigned long pclk_hz;
1000
1001 if (macb_is_gem(bp))
1002 return gem_mdc_clk_div(bp);
1003
1004 pclk_hz = clk_get_rate(bp->pclk);
1005 if (pclk_hz <= 20000000)
1006 config = MACB_BF(CLK, MACB_CLK_DIV8);
1007 else if (pclk_hz <= 40000000)
1008 config = MACB_BF(CLK, MACB_CLK_DIV16);
1009 else if (pclk_hz <= 80000000)
1010 config = MACB_BF(CLK, MACB_CLK_DIV32);
1011 else
1012 config = MACB_BF(CLK, MACB_CLK_DIV64);
1013
1014 return config;
1015}
1016
Jamie Iles757a03c2011-03-09 16:29:59 +00001017/*
1018 * Get the DMA bus width field of the network configuration register that we
1019 * should program. We find the width from decoding the design configuration
1020 * register to find the maximum supported data bus width.
1021 */
1022static u32 macb_dbw(struct macb *bp)
1023{
1024 if (!macb_is_gem(bp))
1025 return 0;
1026
1027 switch (GEM_BFEXT(DBWDEF, gem_readl(bp, DCFG1))) {
1028 case 4:
1029 return GEM_BF(DBW, GEM_DBW128);
1030 case 2:
1031 return GEM_BF(DBW, GEM_DBW64);
1032 case 1:
1033 default:
1034 return GEM_BF(DBW, GEM_DBW32);
1035 }
1036}
1037
Jamie Iles0116da42011-03-14 17:38:30 +00001038/*
1039 * Configure the receive DMA engine to use the correct receive buffer size.
1040 * This is a configurable parameter for GEM.
1041 */
1042static void macb_configure_dma(struct macb *bp)
1043{
1044 u32 dmacfg;
1045
1046 if (macb_is_gem(bp)) {
1047 dmacfg = gem_readl(bp, DMACFG) & ~GEM_BF(RXBS, -1L);
1048 dmacfg |= GEM_BF(RXBS, RX_BUFFER_SIZE / 64);
1049 gem_writel(bp, DMACFG, dmacfg);
1050 }
1051}
1052
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001053static void macb_init_hw(struct macb *bp)
1054{
1055 u32 config;
1056
1057 macb_reset_hw(bp);
Joachim Eastwood314bccc2012-11-07 08:14:52 +00001058 macb_set_hwaddr(bp);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001059
Jamie Iles70c9f3d2011-03-09 16:22:54 +00001060 config = macb_mdc_clk_div(bp);
Havard Skinnemoen29bc2e12012-10-31 06:04:58 +00001061 config |= MACB_BF(RBOF, NET_IP_ALIGN); /* Make eth data aligned */
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001062 config |= MACB_BIT(PAE); /* PAuse Enable */
1063 config |= MACB_BIT(DRFCS); /* Discard Rx FCS */
Peter Korsgaard8dd4bd02010-04-07 21:53:41 -07001064 config |= MACB_BIT(BIG); /* Receive oversized frames */
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001065 if (bp->dev->flags & IFF_PROMISC)
1066 config |= MACB_BIT(CAF); /* Copy All Frames */
1067 if (!(bp->dev->flags & IFF_BROADCAST))
1068 config |= MACB_BIT(NBC); /* No BroadCast */
Jamie Iles757a03c2011-03-09 16:29:59 +00001069 config |= macb_dbw(bp);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001070 macb_writel(bp, NCFGR, config);
Vitalii Demianets26cdfb42012-11-02 07:09:24 +00001071 bp->speed = SPEED_10;
1072 bp->duplex = DUPLEX_HALF;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001073
Jamie Iles0116da42011-03-14 17:38:30 +00001074 macb_configure_dma(bp);
1075
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001076 /* Initialize TX and RX buffers */
1077 macb_writel(bp, RBQP, bp->rx_ring_dma);
1078 macb_writel(bp, TBQP, bp->tx_ring_dma);
1079
1080 /* Enable TX and RX */
frederic RODO6c36a702007-07-12 19:07:24 +02001081 macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE) | MACB_BIT(MPE));
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001082
1083 /* Enable interrupts */
Nicolas Ferree86cd532012-10-31 06:04:57 +00001084 macb_writel(bp, IER, (MACB_RX_INT_FLAGS
1085 | MACB_TX_INT_FLAGS
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001086 | MACB_BIT(HRESP)));
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001087
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001088}
1089
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001090/*
1091 * The hash address register is 64 bits long and takes up two
1092 * locations in the memory map. The least significant bits are stored
1093 * in EMAC_HSL and the most significant bits in EMAC_HSH.
1094 *
1095 * The unicast hash enable and the multicast hash enable bits in the
1096 * network configuration register enable the reception of hash matched
1097 * frames. The destination address is reduced to a 6 bit index into
1098 * the 64 bit hash register using the following hash function. The
1099 * hash function is an exclusive or of every sixth bit of the
1100 * destination address.
1101 *
1102 * hi[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47]
1103 * hi[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46]
1104 * hi[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45]
1105 * hi[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44]
1106 * hi[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43]
1107 * hi[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42]
1108 *
1109 * da[0] represents the least significant bit of the first byte
1110 * received, that is, the multicast/unicast indicator, and da[47]
1111 * represents the most significant bit of the last byte received. If
1112 * the hash index, hi[n], points to a bit that is set in the hash
1113 * register then the frame will be matched according to whether the
1114 * frame is multicast or unicast. A multicast match will be signalled
1115 * if the multicast hash enable bit is set, da[0] is 1 and the hash
1116 * index points to a bit set in the hash register. A unicast match
1117 * will be signalled if the unicast hash enable bit is set, da[0] is 0
1118 * and the hash index points to a bit set in the hash register. To
1119 * receive all multicast frames, the hash register should be set with
1120 * all ones and the multicast hash enable bit should be set in the
1121 * network configuration register.
1122 */
1123
1124static inline int hash_bit_value(int bitnr, __u8 *addr)
1125{
1126 if (addr[bitnr / 8] & (1 << (bitnr % 8)))
1127 return 1;
1128 return 0;
1129}
1130
1131/*
1132 * Return the hash index value for the specified address.
1133 */
1134static int hash_get_index(__u8 *addr)
1135{
1136 int i, j, bitval;
1137 int hash_index = 0;
1138
1139 for (j = 0; j < 6; j++) {
1140 for (i = 0, bitval = 0; i < 8; i++)
1141 bitval ^= hash_bit_value(i*6 + j, addr);
1142
1143 hash_index |= (bitval << j);
1144 }
1145
1146 return hash_index;
1147}
1148
1149/*
1150 * Add multicast addresses to the internal multicast-hash table.
1151 */
1152static void macb_sethashtable(struct net_device *dev)
1153{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001154 struct netdev_hw_addr *ha;
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001155 unsigned long mc_filter[2];
Jiri Pirkof9dcbcc2010-02-23 09:19:49 +00001156 unsigned int bitnr;
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001157 struct macb *bp = netdev_priv(dev);
1158
1159 mc_filter[0] = mc_filter[1] = 0;
1160
Jiri Pirko22bedad32010-04-01 21:22:57 +00001161 netdev_for_each_mc_addr(ha, dev) {
1162 bitnr = hash_get_index(ha->addr);
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001163 mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
1164 }
1165
Jamie Ilesf75ba502011-11-08 10:12:32 +00001166 macb_or_gem_writel(bp, HRB, mc_filter[0]);
1167 macb_or_gem_writel(bp, HRT, mc_filter[1]);
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001168}
1169
1170/*
1171 * Enable/Disable promiscuous and multicast modes.
1172 */
Joachim Eastwoode0da1f12012-10-18 11:01:15 +00001173void macb_set_rx_mode(struct net_device *dev)
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001174{
1175 unsigned long cfg;
1176 struct macb *bp = netdev_priv(dev);
1177
1178 cfg = macb_readl(bp, NCFGR);
1179
1180 if (dev->flags & IFF_PROMISC)
1181 /* Enable promiscuous mode */
1182 cfg |= MACB_BIT(CAF);
1183 else if (dev->flags & (~IFF_PROMISC))
1184 /* Disable promiscuous mode */
1185 cfg &= ~MACB_BIT(CAF);
1186
1187 if (dev->flags & IFF_ALLMULTI) {
1188 /* Enable all multicast mode */
Jamie Ilesf75ba502011-11-08 10:12:32 +00001189 macb_or_gem_writel(bp, HRB, -1);
1190 macb_or_gem_writel(bp, HRT, -1);
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001191 cfg |= MACB_BIT(NCFGR_MTI);
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001192 } else if (!netdev_mc_empty(dev)) {
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001193 /* Enable specific multicasts */
1194 macb_sethashtable(dev);
1195 cfg |= MACB_BIT(NCFGR_MTI);
1196 } else if (dev->flags & (~IFF_ALLMULTI)) {
1197 /* Disable all multicast mode */
Jamie Ilesf75ba502011-11-08 10:12:32 +00001198 macb_or_gem_writel(bp, HRB, 0);
1199 macb_or_gem_writel(bp, HRT, 0);
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001200 cfg &= ~MACB_BIT(NCFGR_MTI);
1201 }
1202
1203 macb_writel(bp, NCFGR, cfg);
1204}
Joachim Eastwoode0da1f12012-10-18 11:01:15 +00001205EXPORT_SYMBOL_GPL(macb_set_rx_mode);
Patrice Vilchez446ebd02007-07-12 19:07:25 +02001206
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001207static int macb_open(struct net_device *dev)
1208{
1209 struct macb *bp = netdev_priv(dev);
1210 int err;
1211
Jamie Ilesc220f8c2011-03-08 20:27:08 +00001212 netdev_dbg(bp->dev, "open\n");
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001213
Nicolas Ferre03fc4722012-07-03 23:14:13 +00001214 /* carrier starts down */
1215 netif_carrier_off(dev);
1216
frederic RODO6c36a702007-07-12 19:07:24 +02001217 /* if the phy is not yet register, retry later*/
1218 if (!bp->phy_dev)
1219 return -EAGAIN;
1220
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001221 if (!is_valid_ether_addr(dev->dev_addr))
1222 return -EADDRNOTAVAIL;
1223
1224 err = macb_alloc_consistent(bp);
1225 if (err) {
Jamie Ilesc220f8c2011-03-08 20:27:08 +00001226 netdev_err(dev, "Unable to allocate DMA memory (error %d)\n",
1227 err);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001228 return err;
1229 }
1230
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001231 napi_enable(&bp->napi);
1232
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001233 macb_init_rings(bp);
1234 macb_init_hw(bp);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001235
frederic RODO6c36a702007-07-12 19:07:24 +02001236 /* schedule a link state check */
1237 phy_start(bp->phy_dev);
1238
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001239 netif_start_queue(dev);
1240
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001241 return 0;
1242}
1243
1244static int macb_close(struct net_device *dev)
1245{
1246 struct macb *bp = netdev_priv(dev);
1247 unsigned long flags;
1248
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001249 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001250 napi_disable(&bp->napi);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001251
frederic RODO6c36a702007-07-12 19:07:24 +02001252 if (bp->phy_dev)
1253 phy_stop(bp->phy_dev);
1254
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001255 spin_lock_irqsave(&bp->lock, flags);
1256 macb_reset_hw(bp);
1257 netif_carrier_off(dev);
1258 spin_unlock_irqrestore(&bp->lock, flags);
1259
1260 macb_free_consistent(bp);
1261
1262 return 0;
1263}
1264
Jamie Ilesa494ed82011-03-09 16:26:35 +00001265static void gem_update_stats(struct macb *bp)
1266{
1267 u32 __iomem *reg = bp->regs + GEM_OTX;
1268 u32 *p = &bp->hw_stats.gem.tx_octets_31_0;
1269 u32 *end = &bp->hw_stats.gem.rx_udp_checksum_errors + 1;
1270
1271 for (; p < end; p++, reg++)
1272 *p += __raw_readl(reg);
1273}
1274
1275static struct net_device_stats *gem_get_stats(struct macb *bp)
1276{
1277 struct gem_stats *hwstat = &bp->hw_stats.gem;
1278 struct net_device_stats *nstat = &bp->stats;
1279
1280 gem_update_stats(bp);
1281
1282 nstat->rx_errors = (hwstat->rx_frame_check_sequence_errors +
1283 hwstat->rx_alignment_errors +
1284 hwstat->rx_resource_errors +
1285 hwstat->rx_overruns +
1286 hwstat->rx_oversize_frames +
1287 hwstat->rx_jabbers +
1288 hwstat->rx_undersized_frames +
1289 hwstat->rx_length_field_frame_errors);
1290 nstat->tx_errors = (hwstat->tx_late_collisions +
1291 hwstat->tx_excessive_collisions +
1292 hwstat->tx_underrun +
1293 hwstat->tx_carrier_sense_errors);
1294 nstat->multicast = hwstat->rx_multicast_frames;
1295 nstat->collisions = (hwstat->tx_single_collision_frames +
1296 hwstat->tx_multiple_collision_frames +
1297 hwstat->tx_excessive_collisions);
1298 nstat->rx_length_errors = (hwstat->rx_oversize_frames +
1299 hwstat->rx_jabbers +
1300 hwstat->rx_undersized_frames +
1301 hwstat->rx_length_field_frame_errors);
1302 nstat->rx_over_errors = hwstat->rx_resource_errors;
1303 nstat->rx_crc_errors = hwstat->rx_frame_check_sequence_errors;
1304 nstat->rx_frame_errors = hwstat->rx_alignment_errors;
1305 nstat->rx_fifo_errors = hwstat->rx_overruns;
1306 nstat->tx_aborted_errors = hwstat->tx_excessive_collisions;
1307 nstat->tx_carrier_errors = hwstat->tx_carrier_sense_errors;
1308 nstat->tx_fifo_errors = hwstat->tx_underrun;
1309
1310 return nstat;
1311}
1312
Joachim Eastwood2ea32ee2012-11-07 08:14:54 +00001313struct net_device_stats *macb_get_stats(struct net_device *dev)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001314{
1315 struct macb *bp = netdev_priv(dev);
1316 struct net_device_stats *nstat = &bp->stats;
Jamie Ilesa494ed82011-03-09 16:26:35 +00001317 struct macb_stats *hwstat = &bp->hw_stats.macb;
1318
1319 if (macb_is_gem(bp))
1320 return gem_get_stats(bp);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001321
frederic RODO6c36a702007-07-12 19:07:24 +02001322 /* read stats from hardware */
1323 macb_update_stats(bp);
1324
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001325 /* Convert HW stats into netdevice stats */
1326 nstat->rx_errors = (hwstat->rx_fcs_errors +
1327 hwstat->rx_align_errors +
1328 hwstat->rx_resource_errors +
1329 hwstat->rx_overruns +
1330 hwstat->rx_oversize_pkts +
1331 hwstat->rx_jabbers +
1332 hwstat->rx_undersize_pkts +
1333 hwstat->sqe_test_errors +
1334 hwstat->rx_length_mismatch);
1335 nstat->tx_errors = (hwstat->tx_late_cols +
1336 hwstat->tx_excessive_cols +
1337 hwstat->tx_underruns +
1338 hwstat->tx_carrier_errors);
1339 nstat->collisions = (hwstat->tx_single_cols +
1340 hwstat->tx_multiple_cols +
1341 hwstat->tx_excessive_cols);
1342 nstat->rx_length_errors = (hwstat->rx_oversize_pkts +
1343 hwstat->rx_jabbers +
1344 hwstat->rx_undersize_pkts +
1345 hwstat->rx_length_mismatch);
Alexander Steinb19f7f72011-04-13 05:03:24 +00001346 nstat->rx_over_errors = hwstat->rx_resource_errors +
1347 hwstat->rx_overruns;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001348 nstat->rx_crc_errors = hwstat->rx_fcs_errors;
1349 nstat->rx_frame_errors = hwstat->rx_align_errors;
1350 nstat->rx_fifo_errors = hwstat->rx_overruns;
1351 /* XXX: What does "missed" mean? */
1352 nstat->tx_aborted_errors = hwstat->tx_excessive_cols;
1353 nstat->tx_carrier_errors = hwstat->tx_carrier_errors;
1354 nstat->tx_fifo_errors = hwstat->tx_underruns;
1355 /* Don't know about heartbeat or window errors... */
1356
1357 return nstat;
1358}
Joachim Eastwood2ea32ee2012-11-07 08:14:54 +00001359EXPORT_SYMBOL_GPL(macb_get_stats);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001360
1361static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1362{
1363 struct macb *bp = netdev_priv(dev);
frederic RODO6c36a702007-07-12 19:07:24 +02001364 struct phy_device *phydev = bp->phy_dev;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001365
frederic RODO6c36a702007-07-12 19:07:24 +02001366 if (!phydev)
1367 return -ENODEV;
1368
1369 return phy_ethtool_gset(phydev, cmd);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001370}
1371
1372static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1373{
1374 struct macb *bp = netdev_priv(dev);
frederic RODO6c36a702007-07-12 19:07:24 +02001375 struct phy_device *phydev = bp->phy_dev;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001376
frederic RODO6c36a702007-07-12 19:07:24 +02001377 if (!phydev)
1378 return -ENODEV;
1379
1380 return phy_ethtool_sset(phydev, cmd);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001381}
1382
Nicolas Ferred1d1b532012-10-31 06:04:56 +00001383static int macb_get_regs_len(struct net_device *netdev)
1384{
1385 return MACB_GREGS_NBR * sizeof(u32);
1386}
1387
1388static void macb_get_regs(struct net_device *dev, struct ethtool_regs *regs,
1389 void *p)
1390{
1391 struct macb *bp = netdev_priv(dev);
1392 unsigned int tail, head;
1393 u32 *regs_buff = p;
1394
1395 regs->version = (macb_readl(bp, MID) & ((1 << MACB_REV_SIZE) - 1))
1396 | MACB_GREGS_VERSION;
1397
1398 tail = macb_tx_ring_wrap(bp->tx_tail);
1399 head = macb_tx_ring_wrap(bp->tx_head);
1400
1401 regs_buff[0] = macb_readl(bp, NCR);
1402 regs_buff[1] = macb_or_gem_readl(bp, NCFGR);
1403 regs_buff[2] = macb_readl(bp, NSR);
1404 regs_buff[3] = macb_readl(bp, TSR);
1405 regs_buff[4] = macb_readl(bp, RBQP);
1406 regs_buff[5] = macb_readl(bp, TBQP);
1407 regs_buff[6] = macb_readl(bp, RSR);
1408 regs_buff[7] = macb_readl(bp, IMR);
1409
1410 regs_buff[8] = tail;
1411 regs_buff[9] = head;
1412 regs_buff[10] = macb_tx_dma(bp, tail);
1413 regs_buff[11] = macb_tx_dma(bp, head);
1414
1415 if (macb_is_gem(bp)) {
1416 regs_buff[12] = gem_readl(bp, USRIO);
1417 regs_buff[13] = gem_readl(bp, DMACFG);
1418 }
1419}
1420
Joachim Eastwood0005f542012-10-18 11:01:12 +00001421const struct ethtool_ops macb_ethtool_ops = {
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001422 .get_settings = macb_get_settings,
1423 .set_settings = macb_set_settings,
Nicolas Ferred1d1b532012-10-31 06:04:56 +00001424 .get_regs_len = macb_get_regs_len,
1425 .get_regs = macb_get_regs,
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001426 .get_link = ethtool_op_get_link,
Richard Cochran17f393e2012-04-03 22:59:31 +00001427 .get_ts_info = ethtool_op_get_ts_info,
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001428};
Joachim Eastwood0005f542012-10-18 11:01:12 +00001429EXPORT_SYMBOL_GPL(macb_ethtool_ops);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001430
Joachim Eastwood0005f542012-10-18 11:01:12 +00001431int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001432{
1433 struct macb *bp = netdev_priv(dev);
frederic RODO6c36a702007-07-12 19:07:24 +02001434 struct phy_device *phydev = bp->phy_dev;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001435
1436 if (!netif_running(dev))
1437 return -EINVAL;
1438
frederic RODO6c36a702007-07-12 19:07:24 +02001439 if (!phydev)
1440 return -ENODEV;
1441
Richard Cochran28b04112010-07-17 08:48:55 +00001442 return phy_mii_ioctl(phydev, rq, cmd);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001443}
Joachim Eastwood0005f542012-10-18 11:01:12 +00001444EXPORT_SYMBOL_GPL(macb_ioctl);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001445
Alexander Beregalov5f1fa992009-04-11 07:42:26 +00001446static const struct net_device_ops macb_netdev_ops = {
1447 .ndo_open = macb_open,
1448 .ndo_stop = macb_close,
1449 .ndo_start_xmit = macb_start_xmit,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001450 .ndo_set_rx_mode = macb_set_rx_mode,
Alexander Beregalov5f1fa992009-04-11 07:42:26 +00001451 .ndo_get_stats = macb_get_stats,
1452 .ndo_do_ioctl = macb_ioctl,
1453 .ndo_validate_addr = eth_validate_addr,
1454 .ndo_change_mtu = eth_change_mtu,
1455 .ndo_set_mac_address = eth_mac_addr,
Thomas Petazzoni6e8cf5c2009-05-04 11:08:41 -07001456#ifdef CONFIG_NET_POLL_CONTROLLER
1457 .ndo_poll_controller = macb_poll_controller,
1458#endif
Alexander Beregalov5f1fa992009-04-11 07:42:26 +00001459};
1460
Jean-Christophe PLAGNIOL-VILLARDfb97a842011-11-18 15:29:25 +01001461#if defined(CONFIG_OF)
1462static const struct of_device_id macb_dt_ids[] = {
1463 { .compatible = "cdns,at32ap7000-macb" },
1464 { .compatible = "cdns,at91sam9260-macb" },
1465 { .compatible = "cdns,macb" },
1466 { .compatible = "cdns,pc302-gem" },
1467 { .compatible = "cdns,gem" },
1468 { /* sentinel */ }
1469};
1470
1471MODULE_DEVICE_TABLE(of, macb_dt_ids);
1472
1473static int __devinit macb_get_phy_mode_dt(struct platform_device *pdev)
1474{
1475 struct device_node *np = pdev->dev.of_node;
1476
1477 if (np)
1478 return of_get_phy_mode(np);
1479
1480 return -ENODEV;
1481}
1482
1483static int __devinit macb_get_hwaddr_dt(struct macb *bp)
1484{
1485 struct device_node *np = bp->pdev->dev.of_node;
1486 if (np) {
1487 const char *mac = of_get_mac_address(np);
1488 if (mac) {
1489 memcpy(bp->dev->dev_addr, mac, ETH_ALEN);
1490 return 0;
1491 }
1492 }
1493
1494 return -ENODEV;
1495}
1496#else
1497static int __devinit macb_get_phy_mode_dt(struct platform_device *pdev)
1498{
1499 return -ENODEV;
1500}
1501static int __devinit macb_get_hwaddr_dt(struct macb *bp)
1502{
1503 return -ENODEV;
1504}
1505#endif
1506
Haavard Skinnemoen06c3fd62008-01-31 13:10:22 +01001507static int __init macb_probe(struct platform_device *pdev)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001508{
Jamie Iles84e0cdb2011-03-08 20:17:06 +00001509 struct macb_platform_data *pdata;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001510 struct resource *regs;
1511 struct net_device *dev;
1512 struct macb *bp;
frederic RODO6c36a702007-07-12 19:07:24 +02001513 struct phy_device *phydev;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001514 u32 config;
1515 int err = -ENXIO;
Jean-Christophe PLAGNIOL-VILLARD8ef29f8a2012-10-31 06:04:59 +00001516 struct pinctrl *pinctrl;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001517
1518 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1519 if (!regs) {
1520 dev_err(&pdev->dev, "no mmio resource defined\n");
1521 goto err_out;
1522 }
1523
Jean-Christophe PLAGNIOL-VILLARD8ef29f8a2012-10-31 06:04:59 +00001524 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
1525 if (IS_ERR(pinctrl)) {
1526 err = PTR_ERR(pinctrl);
1527 if (err == -EPROBE_DEFER)
1528 goto err_out;
1529
1530 dev_warn(&pdev->dev, "No pinctrl provided\n");
1531 }
1532
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001533 err = -ENOMEM;
1534 dev = alloc_etherdev(sizeof(*bp));
Joe Perches41de8d42012-01-29 13:47:52 +00001535 if (!dev)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001536 goto err_out;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001537
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001538 SET_NETDEV_DEV(dev, &pdev->dev);
1539
1540 /* TODO: Actually, we have some interesting features... */
1541 dev->features |= 0;
1542
1543 bp = netdev_priv(dev);
1544 bp->pdev = pdev;
1545 bp->dev = dev;
1546
1547 spin_lock_init(&bp->lock);
Nicolas Ferree86cd532012-10-31 06:04:57 +00001548 INIT_WORK(&bp->tx_error_task, macb_tx_error_task);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001549
Jamie Iles461845d2011-03-08 20:19:23 +00001550 bp->pclk = clk_get(&pdev->dev, "pclk");
Andrew Victor0cc86742007-02-07 16:40:44 +01001551 if (IS_ERR(bp->pclk)) {
1552 dev_err(&pdev->dev, "failed to get macb_clk\n");
1553 goto err_out_free_dev;
1554 }
1555 clk_enable(bp->pclk);
Jamie Iles461845d2011-03-08 20:19:23 +00001556
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001557 bp->hclk = clk_get(&pdev->dev, "hclk");
1558 if (IS_ERR(bp->hclk)) {
1559 dev_err(&pdev->dev, "failed to get hclk\n");
1560 goto err_out_put_pclk;
1561 }
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001562 clk_enable(bp->hclk);
1563
Joe Perches28f65c112011-06-09 09:13:32 -07001564 bp->regs = ioremap(regs->start, resource_size(regs));
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001565 if (!bp->regs) {
1566 dev_err(&pdev->dev, "failed to map registers, aborting.\n");
1567 err = -ENOMEM;
1568 goto err_out_disable_clocks;
1569 }
1570
1571 dev->irq = platform_get_irq(pdev, 0);
Javier Martinez Canillasab392d22011-03-28 16:27:31 +00001572 err = request_irq(dev->irq, macb_interrupt, 0, dev->name, dev);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001573 if (err) {
Jamie Ilesc220f8c2011-03-08 20:27:08 +00001574 dev_err(&pdev->dev, "Unable to request IRQ %d (error %d)\n",
1575 dev->irq, err);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001576 goto err_out_iounmap;
1577 }
1578
Alexander Beregalov5f1fa992009-04-11 07:42:26 +00001579 dev->netdev_ops = &macb_netdev_ops;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001580 netif_napi_add(dev, &bp->napi, macb_poll, 64);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001581 dev->ethtool_ops = &macb_ethtool_ops;
1582
1583 dev->base_addr = regs->start;
1584
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001585 /* Set MII management clock divider */
Jamie Iles70c9f3d2011-03-09 16:22:54 +00001586 config = macb_mdc_clk_div(bp);
Jamie Iles757a03c2011-03-09 16:29:59 +00001587 config |= macb_dbw(bp);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001588 macb_writel(bp, NCFGR, config);
1589
Jean-Christophe PLAGNIOL-VILLARDfb97a842011-11-18 15:29:25 +01001590 err = macb_get_hwaddr_dt(bp);
1591 if (err < 0)
1592 macb_get_hwaddr(bp);
frederic RODO6c36a702007-07-12 19:07:24 +02001593
Jean-Christophe PLAGNIOL-VILLARDfb97a842011-11-18 15:29:25 +01001594 err = macb_get_phy_mode_dt(pdev);
1595 if (err < 0) {
1596 pdata = pdev->dev.platform_data;
1597 if (pdata && pdata->is_rmii)
1598 bp->phy_interface = PHY_INTERFACE_MODE_RMII;
1599 else
1600 bp->phy_interface = PHY_INTERFACE_MODE_MII;
1601 } else {
1602 bp->phy_interface = err;
1603 }
1604
Patrice Vilchez140b7552012-10-31 06:04:50 +00001605 if (bp->phy_interface == PHY_INTERFACE_MODE_RGMII)
1606 macb_or_gem_writel(bp, USRIO, GEM_BIT(RGMII));
1607 else if (bp->phy_interface == PHY_INTERFACE_MODE_RMII)
Andrew Victor0cc86742007-02-07 16:40:44 +01001608#if defined(CONFIG_ARCH_AT91)
Jamie Ilesf75ba502011-11-08 10:12:32 +00001609 macb_or_gem_writel(bp, USRIO, (MACB_BIT(RMII) |
1610 MACB_BIT(CLKEN)));
Andrew Victor0cc86742007-02-07 16:40:44 +01001611#else
Jamie Ilesf75ba502011-11-08 10:12:32 +00001612 macb_or_gem_writel(bp, USRIO, 0);
Andrew Victor0cc86742007-02-07 16:40:44 +01001613#endif
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001614 else
Andrew Victor0cc86742007-02-07 16:40:44 +01001615#if defined(CONFIG_ARCH_AT91)
Jamie Ilesf75ba502011-11-08 10:12:32 +00001616 macb_or_gem_writel(bp, USRIO, MACB_BIT(CLKEN));
Andrew Victor0cc86742007-02-07 16:40:44 +01001617#else
Jamie Ilesf75ba502011-11-08 10:12:32 +00001618 macb_or_gem_writel(bp, USRIO, MACB_BIT(MII));
Andrew Victor0cc86742007-02-07 16:40:44 +01001619#endif
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001620
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001621 err = register_netdev(dev);
1622 if (err) {
1623 dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
1624 goto err_out_free_irq;
1625 }
1626
frederic RODO6c36a702007-07-12 19:07:24 +02001627 if (macb_mii_init(bp) != 0) {
1628 goto err_out_unregister_netdev;
1629 }
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001630
frederic RODO6c36a702007-07-12 19:07:24 +02001631 platform_set_drvdata(pdev, dev);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001632
Nicolas Ferre03fc4722012-07-03 23:14:13 +00001633 netif_carrier_off(dev);
1634
Jamie Ilesf75ba502011-11-08 10:12:32 +00001635 netdev_info(dev, "Cadence %s at 0x%08lx irq %d (%pM)\n",
1636 macb_is_gem(bp) ? "GEM" : "MACB", dev->base_addr,
1637 dev->irq, dev->dev_addr);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001638
frederic RODO6c36a702007-07-12 19:07:24 +02001639 phydev = bp->phy_dev;
Jamie Ilesc220f8c2011-03-08 20:27:08 +00001640 netdev_info(dev, "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
1641 phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
frederic RODO6c36a702007-07-12 19:07:24 +02001642
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001643 return 0;
1644
frederic RODO6c36a702007-07-12 19:07:24 +02001645err_out_unregister_netdev:
1646 unregister_netdev(dev);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001647err_out_free_irq:
1648 free_irq(dev->irq, dev);
1649err_out_iounmap:
1650 iounmap(bp->regs);
1651err_out_disable_clocks:
1652 clk_disable(bp->hclk);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001653 clk_put(bp->hclk);
Andrew Victor0cc86742007-02-07 16:40:44 +01001654 clk_disable(bp->pclk);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001655err_out_put_pclk:
1656 clk_put(bp->pclk);
1657err_out_free_dev:
1658 free_netdev(dev);
1659err_out:
1660 platform_set_drvdata(pdev, NULL);
1661 return err;
1662}
1663
Haavard Skinnemoen06c3fd62008-01-31 13:10:22 +01001664static int __exit macb_remove(struct platform_device *pdev)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001665{
1666 struct net_device *dev;
1667 struct macb *bp;
1668
1669 dev = platform_get_drvdata(pdev);
1670
1671 if (dev) {
1672 bp = netdev_priv(dev);
Atsushi Nemoto84b79012008-04-10 23:30:07 +09001673 if (bp->phy_dev)
1674 phy_disconnect(bp->phy_dev);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -07001675 mdiobus_unregister(bp->mii_bus);
1676 kfree(bp->mii_bus->irq);
1677 mdiobus_free(bp->mii_bus);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001678 unregister_netdev(dev);
1679 free_irq(dev->irq, dev);
1680 iounmap(bp->regs);
1681 clk_disable(bp->hclk);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001682 clk_put(bp->hclk);
Andrew Victor0cc86742007-02-07 16:40:44 +01001683 clk_disable(bp->pclk);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001684 clk_put(bp->pclk);
1685 free_netdev(dev);
1686 platform_set_drvdata(pdev, NULL);
1687 }
1688
1689 return 0;
1690}
1691
Haavard Skinnemoenc1f598f2008-03-04 13:39:29 +01001692#ifdef CONFIG_PM
1693static int macb_suspend(struct platform_device *pdev, pm_message_t state)
1694{
1695 struct net_device *netdev = platform_get_drvdata(pdev);
1696 struct macb *bp = netdev_priv(netdev);
1697
Nicolas Ferre03fc4722012-07-03 23:14:13 +00001698 netif_carrier_off(netdev);
Haavard Skinnemoenc1f598f2008-03-04 13:39:29 +01001699 netif_device_detach(netdev);
1700
Haavard Skinnemoenc1f598f2008-03-04 13:39:29 +01001701 clk_disable(bp->hclk);
Haavard Skinnemoenc1f598f2008-03-04 13:39:29 +01001702 clk_disable(bp->pclk);
1703
1704 return 0;
1705}
1706
1707static int macb_resume(struct platform_device *pdev)
1708{
1709 struct net_device *netdev = platform_get_drvdata(pdev);
1710 struct macb *bp = netdev_priv(netdev);
1711
1712 clk_enable(bp->pclk);
Haavard Skinnemoenc1f598f2008-03-04 13:39:29 +01001713 clk_enable(bp->hclk);
Haavard Skinnemoenc1f598f2008-03-04 13:39:29 +01001714
1715 netif_device_attach(netdev);
1716
1717 return 0;
1718}
1719#else
1720#define macb_suspend NULL
1721#define macb_resume NULL
1722#endif
1723
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001724static struct platform_driver macb_driver = {
Haavard Skinnemoen06c3fd62008-01-31 13:10:22 +01001725 .remove = __exit_p(macb_remove),
Haavard Skinnemoenc1f598f2008-03-04 13:39:29 +01001726 .suspend = macb_suspend,
1727 .resume = macb_resume,
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001728 .driver = {
1729 .name = "macb",
Kay Sievers72abb462008-04-18 13:50:44 -07001730 .owner = THIS_MODULE,
Jean-Christophe PLAGNIOL-VILLARDfb97a842011-11-18 15:29:25 +01001731 .of_match_table = of_match_ptr(macb_dt_ids),
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001732 },
1733};
1734
1735static int __init macb_init(void)
1736{
Haavard Skinnemoen06c3fd62008-01-31 13:10:22 +01001737 return platform_driver_probe(&macb_driver, macb_probe);
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001738}
1739
1740static void __exit macb_exit(void)
1741{
1742 platform_driver_unregister(&macb_driver);
1743}
1744
1745module_init(macb_init);
1746module_exit(macb_exit);
1747
1748MODULE_LICENSE("GPL");
Jamie Ilesf75ba502011-11-08 10:12:32 +00001749MODULE_DESCRIPTION("Cadence MACB/GEM Ethernet driver");
Jean Delvaree05503e2011-05-18 16:49:24 +02001750MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
Kay Sievers72abb462008-04-18 13:50:44 -07001751MODULE_ALIAS("platform:macb");