macb.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /*
  2. * Atmel MACB Ethernet Controller driver
  3. *
  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. #include <linux/clk.h>
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/slab.h>
  16. #include <linux/init.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/phy.h>
  22. #include <asm/arch/board.h>
  23. #include <asm/arch/cpu.h>
  24. #include "macb.h"
  25. #define RX_BUFFER_SIZE 128
  26. #define RX_RING_SIZE 512
  27. #define RX_RING_BYTES (sizeof(struct dma_desc) * RX_RING_SIZE)
  28. /* Make the IP header word-aligned (the ethernet header is 14 bytes) */
  29. #define RX_OFFSET 2
  30. #define TX_RING_SIZE 128
  31. #define DEF_TX_RING_PENDING (TX_RING_SIZE - 1)
  32. #define TX_RING_BYTES (sizeof(struct dma_desc) * TX_RING_SIZE)
  33. #define TX_RING_GAP(bp) \
  34. (TX_RING_SIZE - (bp)->tx_pending)
  35. #define TX_BUFFS_AVAIL(bp) \
  36. (((bp)->tx_tail <= (bp)->tx_head) ? \
  37. (bp)->tx_tail + (bp)->tx_pending - (bp)->tx_head : \
  38. (bp)->tx_tail - (bp)->tx_head - TX_RING_GAP(bp))
  39. #define NEXT_TX(n) (((n) + 1) & (TX_RING_SIZE - 1))
  40. #define NEXT_RX(n) (((n) + 1) & (RX_RING_SIZE - 1))
  41. /* minimum number of free TX descriptors before waking up TX process */
  42. #define MACB_TX_WAKEUP_THRESH (TX_RING_SIZE / 4)
  43. #define MACB_RX_INT_FLAGS (MACB_BIT(RCOMP) | MACB_BIT(RXUBR) \
  44. | MACB_BIT(ISR_ROVR))
  45. static void __macb_set_hwaddr(struct macb *bp)
  46. {
  47. u32 bottom;
  48. u16 top;
  49. bottom = cpu_to_le32(*((u32 *)bp->dev->dev_addr));
  50. macb_writel(bp, SA1B, bottom);
  51. top = cpu_to_le16(*((u16 *)(bp->dev->dev_addr + 4)));
  52. macb_writel(bp, SA1T, top);
  53. }
  54. static void __init macb_get_hwaddr(struct macb *bp)
  55. {
  56. u32 bottom;
  57. u16 top;
  58. u8 addr[6];
  59. bottom = macb_readl(bp, SA1B);
  60. top = macb_readl(bp, SA1T);
  61. addr[0] = bottom & 0xff;
  62. addr[1] = (bottom >> 8) & 0xff;
  63. addr[2] = (bottom >> 16) & 0xff;
  64. addr[3] = (bottom >> 24) & 0xff;
  65. addr[4] = top & 0xff;
  66. addr[5] = (top >> 8) & 0xff;
  67. if (is_valid_ether_addr(addr))
  68. memcpy(bp->dev->dev_addr, addr, sizeof(addr));
  69. }
  70. static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
  71. {
  72. struct macb *bp = bus->priv;
  73. int value;
  74. macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
  75. | MACB_BF(RW, MACB_MAN_READ)
  76. | MACB_BF(PHYA, mii_id)
  77. | MACB_BF(REGA, regnum)
  78. | MACB_BF(CODE, MACB_MAN_CODE)));
  79. /* wait for end of transfer */
  80. while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
  81. cpu_relax();
  82. value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
  83. return value;
  84. }
  85. static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
  86. u16 value)
  87. {
  88. struct macb *bp = bus->priv;
  89. macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
  90. | MACB_BF(RW, MACB_MAN_WRITE)
  91. | MACB_BF(PHYA, mii_id)
  92. | MACB_BF(REGA, regnum)
  93. | MACB_BF(CODE, MACB_MAN_CODE)
  94. | MACB_BF(DATA, value)));
  95. /* wait for end of transfer */
  96. while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
  97. cpu_relax();
  98. return 0;
  99. }
  100. static int macb_mdio_reset(struct mii_bus *bus)
  101. {
  102. return 0;
  103. }
  104. static void macb_handle_link_change(struct net_device *dev)
  105. {
  106. struct macb *bp = netdev_priv(dev);
  107. struct phy_device *phydev = bp->phy_dev;
  108. unsigned long flags;
  109. int status_change = 0;
  110. spin_lock_irqsave(&bp->lock, flags);
  111. if (phydev->link) {
  112. if ((bp->speed != phydev->speed) ||
  113. (bp->duplex != phydev->duplex)) {
  114. u32 reg;
  115. reg = macb_readl(bp, NCFGR);
  116. reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
  117. if (phydev->duplex)
  118. reg |= MACB_BIT(FD);
  119. if (phydev->speed)
  120. reg |= MACB_BIT(SPD);
  121. macb_writel(bp, NCFGR, reg);
  122. bp->speed = phydev->speed;
  123. bp->duplex = phydev->duplex;
  124. status_change = 1;
  125. }
  126. }
  127. if (phydev->link != bp->link) {
  128. if (phydev->link)
  129. netif_schedule(dev);
  130. else {
  131. bp->speed = 0;
  132. bp->duplex = -1;
  133. }
  134. bp->link = phydev->link;
  135. status_change = 1;
  136. }
  137. spin_unlock_irqrestore(&bp->lock, flags);
  138. if (status_change) {
  139. if (phydev->link)
  140. printk(KERN_INFO "%s: link up (%d/%s)\n",
  141. dev->name, phydev->speed,
  142. DUPLEX_FULL == phydev->duplex ? "Full":"Half");
  143. else
  144. printk(KERN_INFO "%s: link down\n", dev->name);
  145. }
  146. }
  147. /* based on au1000_eth. c*/
  148. static int macb_mii_probe(struct net_device *dev)
  149. {
  150. struct macb *bp = netdev_priv(dev);
  151. struct phy_device *phydev = NULL;
  152. struct eth_platform_data *pdata;
  153. int phy_addr;
  154. /* find the first phy */
  155. for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
  156. if (bp->mii_bus.phy_map[phy_addr]) {
  157. phydev = bp->mii_bus.phy_map[phy_addr];
  158. break;
  159. }
  160. }
  161. if (!phydev) {
  162. printk (KERN_ERR "%s: no PHY found\n", dev->name);
  163. return -1;
  164. }
  165. pdata = bp->pdev->dev.platform_data;
  166. /* TODO : add pin_irq */
  167. /* attach the mac to the phy */
  168. if (pdata && pdata->is_rmii) {
  169. phydev = phy_connect(dev, phydev->dev.bus_id,
  170. &macb_handle_link_change, 0, PHY_INTERFACE_MODE_RMII);
  171. } else {
  172. phydev = phy_connect(dev, phydev->dev.bus_id,
  173. &macb_handle_link_change, 0, PHY_INTERFACE_MODE_MII);
  174. }
  175. if (IS_ERR(phydev)) {
  176. printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
  177. return PTR_ERR(phydev);
  178. }
  179. /* mask with MAC supported features */
  180. phydev->supported &= PHY_BASIC_FEATURES;
  181. phydev->advertising = phydev->supported;
  182. bp->link = 0;
  183. bp->speed = 0;
  184. bp->duplex = -1;
  185. bp->phy_dev = phydev;
  186. return 0;
  187. }
  188. static int macb_mii_init(struct macb *bp)
  189. {
  190. struct eth_platform_data *pdata;
  191. int err = -ENXIO, i;
  192. /* Enable managment port */
  193. macb_writel(bp, NCR, MACB_BIT(MPE));
  194. bp->mii_bus.name = "MACB_mii_bus",
  195. bp->mii_bus.read = &macb_mdio_read,
  196. bp->mii_bus.write = &macb_mdio_write,
  197. bp->mii_bus.reset = &macb_mdio_reset,
  198. bp->mii_bus.id = bp->pdev->id,
  199. bp->mii_bus.priv = bp,
  200. bp->mii_bus.dev = &bp->dev->dev;
  201. pdata = bp->pdev->dev.platform_data;
  202. if (pdata)
  203. bp->mii_bus.phy_mask = pdata->phy_mask;
  204. bp->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
  205. if (!bp->mii_bus.irq) {
  206. err = -ENOMEM;
  207. goto err_out;
  208. }
  209. for (i = 0; i < PHY_MAX_ADDR; i++)
  210. bp->mii_bus.irq[i] = PHY_POLL;
  211. platform_set_drvdata(bp->dev, &bp->mii_bus);
  212. if (mdiobus_register(&bp->mii_bus))
  213. goto err_out_free_mdio_irq;
  214. if (macb_mii_probe(bp->dev) != 0) {
  215. goto err_out_unregister_bus;
  216. }
  217. return 0;
  218. err_out_unregister_bus:
  219. mdiobus_unregister(&bp->mii_bus);
  220. err_out_free_mdio_irq:
  221. kfree(bp->mii_bus.irq);
  222. err_out:
  223. return err;
  224. }
  225. static void macb_update_stats(struct macb *bp)
  226. {
  227. u32 __iomem *reg = bp->regs + MACB_PFR;
  228. u32 *p = &bp->hw_stats.rx_pause_frames;
  229. u32 *end = &bp->hw_stats.tx_pause_frames + 1;
  230. WARN_ON((unsigned long)(end - p - 1) != (MACB_TPF - MACB_PFR) / 4);
  231. for(; p < end; p++, reg++)
  232. *p += __raw_readl(reg);
  233. }
  234. static void macb_tx(struct macb *bp)
  235. {
  236. unsigned int tail;
  237. unsigned int head;
  238. u32 status;
  239. status = macb_readl(bp, TSR);
  240. macb_writel(bp, TSR, status);
  241. dev_dbg(&bp->pdev->dev, "macb_tx status = %02lx\n",
  242. (unsigned long)status);
  243. if (status & MACB_BIT(UND)) {
  244. printk(KERN_ERR "%s: TX underrun, resetting buffers\n",
  245. bp->dev->name);
  246. bp->tx_head = bp->tx_tail = 0;
  247. }
  248. if (!(status & MACB_BIT(COMP)))
  249. /*
  250. * This may happen when a buffer becomes complete
  251. * between reading the ISR and scanning the
  252. * descriptors. Nothing to worry about.
  253. */
  254. return;
  255. head = bp->tx_head;
  256. for (tail = bp->tx_tail; tail != head; tail = NEXT_TX(tail)) {
  257. struct ring_info *rp = &bp->tx_skb[tail];
  258. struct sk_buff *skb = rp->skb;
  259. u32 bufstat;
  260. BUG_ON(skb == NULL);
  261. rmb();
  262. bufstat = bp->tx_ring[tail].ctrl;
  263. if (!(bufstat & MACB_BIT(TX_USED)))
  264. break;
  265. dev_dbg(&bp->pdev->dev, "skb %u (data %p) TX complete\n",
  266. tail, skb->data);
  267. dma_unmap_single(&bp->pdev->dev, rp->mapping, skb->len,
  268. DMA_TO_DEVICE);
  269. bp->stats.tx_packets++;
  270. bp->stats.tx_bytes += skb->len;
  271. rp->skb = NULL;
  272. dev_kfree_skb_irq(skb);
  273. }
  274. bp->tx_tail = tail;
  275. if (netif_queue_stopped(bp->dev) &&
  276. TX_BUFFS_AVAIL(bp) > MACB_TX_WAKEUP_THRESH)
  277. netif_wake_queue(bp->dev);
  278. }
  279. static int macb_rx_frame(struct macb *bp, unsigned int first_frag,
  280. unsigned int last_frag)
  281. {
  282. unsigned int len;
  283. unsigned int frag;
  284. unsigned int offset = 0;
  285. struct sk_buff *skb;
  286. len = MACB_BFEXT(RX_FRMLEN, bp->rx_ring[last_frag].ctrl);
  287. dev_dbg(&bp->pdev->dev, "macb_rx_frame frags %u - %u (len %u)\n",
  288. first_frag, last_frag, len);
  289. skb = dev_alloc_skb(len + RX_OFFSET);
  290. if (!skb) {
  291. bp->stats.rx_dropped++;
  292. for (frag = first_frag; ; frag = NEXT_RX(frag)) {
  293. bp->rx_ring[frag].addr &= ~MACB_BIT(RX_USED);
  294. if (frag == last_frag)
  295. break;
  296. }
  297. wmb();
  298. return 1;
  299. }
  300. skb_reserve(skb, RX_OFFSET);
  301. skb->ip_summed = CHECKSUM_NONE;
  302. skb_put(skb, len);
  303. for (frag = first_frag; ; frag = NEXT_RX(frag)) {
  304. unsigned int frag_len = RX_BUFFER_SIZE;
  305. if (offset + frag_len > len) {
  306. BUG_ON(frag != last_frag);
  307. frag_len = len - offset;
  308. }
  309. skb_copy_to_linear_data_offset(skb, offset,
  310. (bp->rx_buffers +
  311. (RX_BUFFER_SIZE * frag)),
  312. frag_len);
  313. offset += RX_BUFFER_SIZE;
  314. bp->rx_ring[frag].addr &= ~MACB_BIT(RX_USED);
  315. wmb();
  316. if (frag == last_frag)
  317. break;
  318. }
  319. skb->protocol = eth_type_trans(skb, bp->dev);
  320. bp->stats.rx_packets++;
  321. bp->stats.rx_bytes += len;
  322. bp->dev->last_rx = jiffies;
  323. dev_dbg(&bp->pdev->dev, "received skb of length %u, csum: %08x\n",
  324. skb->len, skb->csum);
  325. netif_receive_skb(skb);
  326. return 0;
  327. }
  328. /* Mark DMA descriptors from begin up to and not including end as unused */
  329. static void discard_partial_frame(struct macb *bp, unsigned int begin,
  330. unsigned int end)
  331. {
  332. unsigned int frag;
  333. for (frag = begin; frag != end; frag = NEXT_RX(frag))
  334. bp->rx_ring[frag].addr &= ~MACB_BIT(RX_USED);
  335. wmb();
  336. /*
  337. * When this happens, the hardware stats registers for
  338. * whatever caused this is updated, so we don't have to record
  339. * anything.
  340. */
  341. }
  342. static int macb_rx(struct macb *bp, int budget)
  343. {
  344. int received = 0;
  345. unsigned int tail = bp->rx_tail;
  346. int first_frag = -1;
  347. for (; budget > 0; tail = NEXT_RX(tail)) {
  348. u32 addr, ctrl;
  349. rmb();
  350. addr = bp->rx_ring[tail].addr;
  351. ctrl = bp->rx_ring[tail].ctrl;
  352. if (!(addr & MACB_BIT(RX_USED)))
  353. break;
  354. if (ctrl & MACB_BIT(RX_SOF)) {
  355. if (first_frag != -1)
  356. discard_partial_frame(bp, first_frag, tail);
  357. first_frag = tail;
  358. }
  359. if (ctrl & MACB_BIT(RX_EOF)) {
  360. int dropped;
  361. BUG_ON(first_frag == -1);
  362. dropped = macb_rx_frame(bp, first_frag, tail);
  363. first_frag = -1;
  364. if (!dropped) {
  365. received++;
  366. budget--;
  367. }
  368. }
  369. }
  370. if (first_frag != -1)
  371. bp->rx_tail = first_frag;
  372. else
  373. bp->rx_tail = tail;
  374. return received;
  375. }
  376. static int macb_poll(struct napi_struct *napi, int budget)
  377. {
  378. struct macb *bp = container_of(napi, struct macb, napi);
  379. struct net_device *dev = bp->dev;
  380. int work_done;
  381. u32 status;
  382. status = macb_readl(bp, RSR);
  383. macb_writel(bp, RSR, status);
  384. work_done = 0;
  385. if (!status) {
  386. /*
  387. * This may happen if an interrupt was pending before
  388. * this function was called last time, and no packets
  389. * have been received since.
  390. */
  391. netif_rx_complete(dev, napi);
  392. goto out;
  393. }
  394. dev_dbg(&bp->pdev->dev, "poll: status = %08lx, budget = %d\n",
  395. (unsigned long)status, budget);
  396. if (!(status & MACB_BIT(REC))) {
  397. dev_warn(&bp->pdev->dev,
  398. "No RX buffers complete, status = %02lx\n",
  399. (unsigned long)status);
  400. netif_rx_complete(dev, napi);
  401. goto out;
  402. }
  403. work_done = macb_rx(bp, budget);
  404. if (work_done < budget)
  405. netif_rx_complete(dev, napi);
  406. /*
  407. * We've done what we can to clean the buffers. Make sure we
  408. * get notified when new packets arrive.
  409. */
  410. out:
  411. macb_writel(bp, IER, MACB_RX_INT_FLAGS);
  412. /* TODO: Handle errors */
  413. return work_done;
  414. }
  415. static irqreturn_t macb_interrupt(int irq, void *dev_id)
  416. {
  417. struct net_device *dev = dev_id;
  418. struct macb *bp = netdev_priv(dev);
  419. u32 status;
  420. status = macb_readl(bp, ISR);
  421. if (unlikely(!status))
  422. return IRQ_NONE;
  423. spin_lock(&bp->lock);
  424. while (status) {
  425. /* close possible race with dev_close */
  426. if (unlikely(!netif_running(dev))) {
  427. macb_writel(bp, IDR, ~0UL);
  428. break;
  429. }
  430. if (status & MACB_RX_INT_FLAGS) {
  431. if (netif_rx_schedule_prep(dev, &bp->napi)) {
  432. /*
  433. * There's no point taking any more interrupts
  434. * until we have processed the buffers
  435. */
  436. macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
  437. dev_dbg(&bp->pdev->dev,
  438. "scheduling RX softirq\n");
  439. __netif_rx_schedule(dev, &bp->napi);
  440. }
  441. }
  442. if (status & (MACB_BIT(TCOMP) | MACB_BIT(ISR_TUND)))
  443. macb_tx(bp);
  444. /*
  445. * Link change detection isn't possible with RMII, so we'll
  446. * add that if/when we get our hands on a full-blown MII PHY.
  447. */
  448. if (status & MACB_BIT(HRESP)) {
  449. /*
  450. * TODO: Reset the hardware, and maybe move the printk
  451. * to a lower-priority context as well (work queue?)
  452. */
  453. printk(KERN_ERR "%s: DMA bus error: HRESP not OK\n",
  454. dev->name);
  455. }
  456. status = macb_readl(bp, ISR);
  457. }
  458. spin_unlock(&bp->lock);
  459. return IRQ_HANDLED;
  460. }
  461. static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
  462. {
  463. struct macb *bp = netdev_priv(dev);
  464. dma_addr_t mapping;
  465. unsigned int len, entry;
  466. u32 ctrl;
  467. #ifdef DEBUG
  468. int i;
  469. dev_dbg(&bp->pdev->dev,
  470. "start_xmit: len %u head %p data %p tail %p end %p\n",
  471. skb->len, skb->head, skb->data,
  472. skb_tail_pointer(skb), skb_end_pointer(skb));
  473. dev_dbg(&bp->pdev->dev,
  474. "data:");
  475. for (i = 0; i < 16; i++)
  476. printk(" %02x", (unsigned int)skb->data[i]);
  477. printk("\n");
  478. #endif
  479. len = skb->len;
  480. spin_lock_irq(&bp->lock);
  481. /* This is a hard error, log it. */
  482. if (TX_BUFFS_AVAIL(bp) < 1) {
  483. netif_stop_queue(dev);
  484. spin_unlock_irq(&bp->lock);
  485. dev_err(&bp->pdev->dev,
  486. "BUG! Tx Ring full when queue awake!\n");
  487. dev_dbg(&bp->pdev->dev, "tx_head = %u, tx_tail = %u\n",
  488. bp->tx_head, bp->tx_tail);
  489. return 1;
  490. }
  491. entry = bp->tx_head;
  492. dev_dbg(&bp->pdev->dev, "Allocated ring entry %u\n", entry);
  493. mapping = dma_map_single(&bp->pdev->dev, skb->data,
  494. len, DMA_TO_DEVICE);
  495. bp->tx_skb[entry].skb = skb;
  496. bp->tx_skb[entry].mapping = mapping;
  497. dev_dbg(&bp->pdev->dev, "Mapped skb data %p to DMA addr %08lx\n",
  498. skb->data, (unsigned long)mapping);
  499. ctrl = MACB_BF(TX_FRMLEN, len);
  500. ctrl |= MACB_BIT(TX_LAST);
  501. if (entry == (TX_RING_SIZE - 1))
  502. ctrl |= MACB_BIT(TX_WRAP);
  503. bp->tx_ring[entry].addr = mapping;
  504. bp->tx_ring[entry].ctrl = ctrl;
  505. wmb();
  506. entry = NEXT_TX(entry);
  507. bp->tx_head = entry;
  508. macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART));
  509. if (TX_BUFFS_AVAIL(bp) < 1)
  510. netif_stop_queue(dev);
  511. spin_unlock_irq(&bp->lock);
  512. dev->trans_start = jiffies;
  513. return 0;
  514. }
  515. static void macb_free_consistent(struct macb *bp)
  516. {
  517. if (bp->tx_skb) {
  518. kfree(bp->tx_skb);
  519. bp->tx_skb = NULL;
  520. }
  521. if (bp->rx_ring) {
  522. dma_free_coherent(&bp->pdev->dev, RX_RING_BYTES,
  523. bp->rx_ring, bp->rx_ring_dma);
  524. bp->rx_ring = NULL;
  525. }
  526. if (bp->tx_ring) {
  527. dma_free_coherent(&bp->pdev->dev, TX_RING_BYTES,
  528. bp->tx_ring, bp->tx_ring_dma);
  529. bp->tx_ring = NULL;
  530. }
  531. if (bp->rx_buffers) {
  532. dma_free_coherent(&bp->pdev->dev,
  533. RX_RING_SIZE * RX_BUFFER_SIZE,
  534. bp->rx_buffers, bp->rx_buffers_dma);
  535. bp->rx_buffers = NULL;
  536. }
  537. }
  538. static int macb_alloc_consistent(struct macb *bp)
  539. {
  540. int size;
  541. size = TX_RING_SIZE * sizeof(struct ring_info);
  542. bp->tx_skb = kmalloc(size, GFP_KERNEL);
  543. if (!bp->tx_skb)
  544. goto out_err;
  545. size = RX_RING_BYTES;
  546. bp->rx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
  547. &bp->rx_ring_dma, GFP_KERNEL);
  548. if (!bp->rx_ring)
  549. goto out_err;
  550. dev_dbg(&bp->pdev->dev,
  551. "Allocated RX ring of %d bytes at %08lx (mapped %p)\n",
  552. size, (unsigned long)bp->rx_ring_dma, bp->rx_ring);
  553. size = TX_RING_BYTES;
  554. bp->tx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
  555. &bp->tx_ring_dma, GFP_KERNEL);
  556. if (!bp->tx_ring)
  557. goto out_err;
  558. dev_dbg(&bp->pdev->dev,
  559. "Allocated TX ring of %d bytes at %08lx (mapped %p)\n",
  560. size, (unsigned long)bp->tx_ring_dma, bp->tx_ring);
  561. size = RX_RING_SIZE * RX_BUFFER_SIZE;
  562. bp->rx_buffers = dma_alloc_coherent(&bp->pdev->dev, size,
  563. &bp->rx_buffers_dma, GFP_KERNEL);
  564. if (!bp->rx_buffers)
  565. goto out_err;
  566. dev_dbg(&bp->pdev->dev,
  567. "Allocated RX buffers of %d bytes at %08lx (mapped %p)\n",
  568. size, (unsigned long)bp->rx_buffers_dma, bp->rx_buffers);
  569. return 0;
  570. out_err:
  571. macb_free_consistent(bp);
  572. return -ENOMEM;
  573. }
  574. static void macb_init_rings(struct macb *bp)
  575. {
  576. int i;
  577. dma_addr_t addr;
  578. addr = bp->rx_buffers_dma;
  579. for (i = 0; i < RX_RING_SIZE; i++) {
  580. bp->rx_ring[i].addr = addr;
  581. bp->rx_ring[i].ctrl = 0;
  582. addr += RX_BUFFER_SIZE;
  583. }
  584. bp->rx_ring[RX_RING_SIZE - 1].addr |= MACB_BIT(RX_WRAP);
  585. for (i = 0; i < TX_RING_SIZE; i++) {
  586. bp->tx_ring[i].addr = 0;
  587. bp->tx_ring[i].ctrl = MACB_BIT(TX_USED);
  588. }
  589. bp->tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP);
  590. bp->rx_tail = bp->tx_head = bp->tx_tail = 0;
  591. }
  592. static void macb_reset_hw(struct macb *bp)
  593. {
  594. /* Make sure we have the write buffer for ourselves */
  595. wmb();
  596. /*
  597. * Disable RX and TX (XXX: Should we halt the transmission
  598. * more gracefully?)
  599. */
  600. macb_writel(bp, NCR, 0);
  601. /* Clear the stats registers (XXX: Update stats first?) */
  602. macb_writel(bp, NCR, MACB_BIT(CLRSTAT));
  603. /* Clear all status flags */
  604. macb_writel(bp, TSR, ~0UL);
  605. macb_writel(bp, RSR, ~0UL);
  606. /* Disable all interrupts */
  607. macb_writel(bp, IDR, ~0UL);
  608. macb_readl(bp, ISR);
  609. }
  610. static void macb_init_hw(struct macb *bp)
  611. {
  612. u32 config;
  613. macb_reset_hw(bp);
  614. __macb_set_hwaddr(bp);
  615. config = macb_readl(bp, NCFGR) & MACB_BF(CLK, -1L);
  616. config |= MACB_BIT(PAE); /* PAuse Enable */
  617. config |= MACB_BIT(DRFCS); /* Discard Rx FCS */
  618. if (bp->dev->flags & IFF_PROMISC)
  619. config |= MACB_BIT(CAF); /* Copy All Frames */
  620. if (!(bp->dev->flags & IFF_BROADCAST))
  621. config |= MACB_BIT(NBC); /* No BroadCast */
  622. macb_writel(bp, NCFGR, config);
  623. /* Initialize TX and RX buffers */
  624. macb_writel(bp, RBQP, bp->rx_ring_dma);
  625. macb_writel(bp, TBQP, bp->tx_ring_dma);
  626. /* Enable TX and RX */
  627. macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE) | MACB_BIT(MPE));
  628. /* Enable interrupts */
  629. macb_writel(bp, IER, (MACB_BIT(RCOMP)
  630. | MACB_BIT(RXUBR)
  631. | MACB_BIT(ISR_TUND)
  632. | MACB_BIT(ISR_RLE)
  633. | MACB_BIT(TXERR)
  634. | MACB_BIT(TCOMP)
  635. | MACB_BIT(ISR_ROVR)
  636. | MACB_BIT(HRESP)));
  637. }
  638. /*
  639. * The hash address register is 64 bits long and takes up two
  640. * locations in the memory map. The least significant bits are stored
  641. * in EMAC_HSL and the most significant bits in EMAC_HSH.
  642. *
  643. * The unicast hash enable and the multicast hash enable bits in the
  644. * network configuration register enable the reception of hash matched
  645. * frames. The destination address is reduced to a 6 bit index into
  646. * the 64 bit hash register using the following hash function. The
  647. * hash function is an exclusive or of every sixth bit of the
  648. * destination address.
  649. *
  650. * hi[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47]
  651. * hi[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46]
  652. * hi[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45]
  653. * hi[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44]
  654. * hi[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43]
  655. * hi[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42]
  656. *
  657. * da[0] represents the least significant bit of the first byte
  658. * received, that is, the multicast/unicast indicator, and da[47]
  659. * represents the most significant bit of the last byte received. If
  660. * the hash index, hi[n], points to a bit that is set in the hash
  661. * register then the frame will be matched according to whether the
  662. * frame is multicast or unicast. A multicast match will be signalled
  663. * if the multicast hash enable bit is set, da[0] is 1 and the hash
  664. * index points to a bit set in the hash register. A unicast match
  665. * will be signalled if the unicast hash enable bit is set, da[0] is 0
  666. * and the hash index points to a bit set in the hash register. To
  667. * receive all multicast frames, the hash register should be set with
  668. * all ones and the multicast hash enable bit should be set in the
  669. * network configuration register.
  670. */
  671. static inline int hash_bit_value(int bitnr, __u8 *addr)
  672. {
  673. if (addr[bitnr / 8] & (1 << (bitnr % 8)))
  674. return 1;
  675. return 0;
  676. }
  677. /*
  678. * Return the hash index value for the specified address.
  679. */
  680. static int hash_get_index(__u8 *addr)
  681. {
  682. int i, j, bitval;
  683. int hash_index = 0;
  684. for (j = 0; j < 6; j++) {
  685. for (i = 0, bitval = 0; i < 8; i++)
  686. bitval ^= hash_bit_value(i*6 + j, addr);
  687. hash_index |= (bitval << j);
  688. }
  689. return hash_index;
  690. }
  691. /*
  692. * Add multicast addresses to the internal multicast-hash table.
  693. */
  694. static void macb_sethashtable(struct net_device *dev)
  695. {
  696. struct dev_mc_list *curr;
  697. unsigned long mc_filter[2];
  698. unsigned int i, bitnr;
  699. struct macb *bp = netdev_priv(dev);
  700. mc_filter[0] = mc_filter[1] = 0;
  701. curr = dev->mc_list;
  702. for (i = 0; i < dev->mc_count; i++, curr = curr->next) {
  703. if (!curr) break; /* unexpected end of list */
  704. bitnr = hash_get_index(curr->dmi_addr);
  705. mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
  706. }
  707. macb_writel(bp, HRB, mc_filter[0]);
  708. macb_writel(bp, HRT, mc_filter[1]);
  709. }
  710. /*
  711. * Enable/Disable promiscuous and multicast modes.
  712. */
  713. static void macb_set_rx_mode(struct net_device *dev)
  714. {
  715. unsigned long cfg;
  716. struct macb *bp = netdev_priv(dev);
  717. cfg = macb_readl(bp, NCFGR);
  718. if (dev->flags & IFF_PROMISC)
  719. /* Enable promiscuous mode */
  720. cfg |= MACB_BIT(CAF);
  721. else if (dev->flags & (~IFF_PROMISC))
  722. /* Disable promiscuous mode */
  723. cfg &= ~MACB_BIT(CAF);
  724. if (dev->flags & IFF_ALLMULTI) {
  725. /* Enable all multicast mode */
  726. macb_writel(bp, HRB, -1);
  727. macb_writel(bp, HRT, -1);
  728. cfg |= MACB_BIT(NCFGR_MTI);
  729. } else if (dev->mc_count > 0) {
  730. /* Enable specific multicasts */
  731. macb_sethashtable(dev);
  732. cfg |= MACB_BIT(NCFGR_MTI);
  733. } else if (dev->flags & (~IFF_ALLMULTI)) {
  734. /* Disable all multicast mode */
  735. macb_writel(bp, HRB, 0);
  736. macb_writel(bp, HRT, 0);
  737. cfg &= ~MACB_BIT(NCFGR_MTI);
  738. }
  739. macb_writel(bp, NCFGR, cfg);
  740. }
  741. static int macb_open(struct net_device *dev)
  742. {
  743. struct macb *bp = netdev_priv(dev);
  744. int err;
  745. dev_dbg(&bp->pdev->dev, "open\n");
  746. /* if the phy is not yet register, retry later*/
  747. if (!bp->phy_dev)
  748. return -EAGAIN;
  749. if (!is_valid_ether_addr(dev->dev_addr))
  750. return -EADDRNOTAVAIL;
  751. err = macb_alloc_consistent(bp);
  752. if (err) {
  753. printk(KERN_ERR
  754. "%s: Unable to allocate DMA memory (error %d)\n",
  755. dev->name, err);
  756. return err;
  757. }
  758. napi_enable(&bp->napi);
  759. macb_init_rings(bp);
  760. macb_init_hw(bp);
  761. /* schedule a link state check */
  762. phy_start(bp->phy_dev);
  763. netif_start_queue(dev);
  764. return 0;
  765. }
  766. static int macb_close(struct net_device *dev)
  767. {
  768. struct macb *bp = netdev_priv(dev);
  769. unsigned long flags;
  770. netif_stop_queue(dev);
  771. napi_disable(&bp->napi);
  772. if (bp->phy_dev)
  773. phy_stop(bp->phy_dev);
  774. spin_lock_irqsave(&bp->lock, flags);
  775. macb_reset_hw(bp);
  776. netif_carrier_off(dev);
  777. spin_unlock_irqrestore(&bp->lock, flags);
  778. macb_free_consistent(bp);
  779. return 0;
  780. }
  781. static struct net_device_stats *macb_get_stats(struct net_device *dev)
  782. {
  783. struct macb *bp = netdev_priv(dev);
  784. struct net_device_stats *nstat = &bp->stats;
  785. struct macb_stats *hwstat = &bp->hw_stats;
  786. /* read stats from hardware */
  787. macb_update_stats(bp);
  788. /* Convert HW stats into netdevice stats */
  789. nstat->rx_errors = (hwstat->rx_fcs_errors +
  790. hwstat->rx_align_errors +
  791. hwstat->rx_resource_errors +
  792. hwstat->rx_overruns +
  793. hwstat->rx_oversize_pkts +
  794. hwstat->rx_jabbers +
  795. hwstat->rx_undersize_pkts +
  796. hwstat->sqe_test_errors +
  797. hwstat->rx_length_mismatch);
  798. nstat->tx_errors = (hwstat->tx_late_cols +
  799. hwstat->tx_excessive_cols +
  800. hwstat->tx_underruns +
  801. hwstat->tx_carrier_errors);
  802. nstat->collisions = (hwstat->tx_single_cols +
  803. hwstat->tx_multiple_cols +
  804. hwstat->tx_excessive_cols);
  805. nstat->rx_length_errors = (hwstat->rx_oversize_pkts +
  806. hwstat->rx_jabbers +
  807. hwstat->rx_undersize_pkts +
  808. hwstat->rx_length_mismatch);
  809. nstat->rx_over_errors = hwstat->rx_resource_errors;
  810. nstat->rx_crc_errors = hwstat->rx_fcs_errors;
  811. nstat->rx_frame_errors = hwstat->rx_align_errors;
  812. nstat->rx_fifo_errors = hwstat->rx_overruns;
  813. /* XXX: What does "missed" mean? */
  814. nstat->tx_aborted_errors = hwstat->tx_excessive_cols;
  815. nstat->tx_carrier_errors = hwstat->tx_carrier_errors;
  816. nstat->tx_fifo_errors = hwstat->tx_underruns;
  817. /* Don't know about heartbeat or window errors... */
  818. return nstat;
  819. }
  820. static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  821. {
  822. struct macb *bp = netdev_priv(dev);
  823. struct phy_device *phydev = bp->phy_dev;
  824. if (!phydev)
  825. return -ENODEV;
  826. return phy_ethtool_gset(phydev, cmd);
  827. }
  828. static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  829. {
  830. struct macb *bp = netdev_priv(dev);
  831. struct phy_device *phydev = bp->phy_dev;
  832. if (!phydev)
  833. return -ENODEV;
  834. return phy_ethtool_sset(phydev, cmd);
  835. }
  836. static void macb_get_drvinfo(struct net_device *dev,
  837. struct ethtool_drvinfo *info)
  838. {
  839. struct macb *bp = netdev_priv(dev);
  840. strcpy(info->driver, bp->pdev->dev.driver->name);
  841. strcpy(info->version, "$Revision: 1.14 $");
  842. strcpy(info->bus_info, bp->pdev->dev.bus_id);
  843. }
  844. static struct ethtool_ops macb_ethtool_ops = {
  845. .get_settings = macb_get_settings,
  846. .set_settings = macb_set_settings,
  847. .get_drvinfo = macb_get_drvinfo,
  848. .get_link = ethtool_op_get_link,
  849. };
  850. static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  851. {
  852. struct macb *bp = netdev_priv(dev);
  853. struct phy_device *phydev = bp->phy_dev;
  854. if (!netif_running(dev))
  855. return -EINVAL;
  856. if (!phydev)
  857. return -ENODEV;
  858. return phy_mii_ioctl(phydev, if_mii(rq), cmd);
  859. }
  860. static int __devinit macb_probe(struct platform_device *pdev)
  861. {
  862. struct eth_platform_data *pdata;
  863. struct resource *regs;
  864. struct net_device *dev;
  865. struct macb *bp;
  866. struct phy_device *phydev;
  867. unsigned long pclk_hz;
  868. u32 config;
  869. int err = -ENXIO;
  870. DECLARE_MAC_BUF(mac);
  871. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  872. if (!regs) {
  873. dev_err(&pdev->dev, "no mmio resource defined\n");
  874. goto err_out;
  875. }
  876. err = -ENOMEM;
  877. dev = alloc_etherdev(sizeof(*bp));
  878. if (!dev) {
  879. dev_err(&pdev->dev, "etherdev alloc failed, aborting.\n");
  880. goto err_out;
  881. }
  882. SET_NETDEV_DEV(dev, &pdev->dev);
  883. /* TODO: Actually, we have some interesting features... */
  884. dev->features |= 0;
  885. bp = netdev_priv(dev);
  886. bp->pdev = pdev;
  887. bp->dev = dev;
  888. spin_lock_init(&bp->lock);
  889. #if defined(CONFIG_ARCH_AT91)
  890. bp->pclk = clk_get(&pdev->dev, "macb_clk");
  891. if (IS_ERR(bp->pclk)) {
  892. dev_err(&pdev->dev, "failed to get macb_clk\n");
  893. goto err_out_free_dev;
  894. }
  895. clk_enable(bp->pclk);
  896. #else
  897. bp->pclk = clk_get(&pdev->dev, "pclk");
  898. if (IS_ERR(bp->pclk)) {
  899. dev_err(&pdev->dev, "failed to get pclk\n");
  900. goto err_out_free_dev;
  901. }
  902. bp->hclk = clk_get(&pdev->dev, "hclk");
  903. if (IS_ERR(bp->hclk)) {
  904. dev_err(&pdev->dev, "failed to get hclk\n");
  905. goto err_out_put_pclk;
  906. }
  907. clk_enable(bp->pclk);
  908. clk_enable(bp->hclk);
  909. #endif
  910. bp->regs = ioremap(regs->start, regs->end - regs->start + 1);
  911. if (!bp->regs) {
  912. dev_err(&pdev->dev, "failed to map registers, aborting.\n");
  913. err = -ENOMEM;
  914. goto err_out_disable_clocks;
  915. }
  916. dev->irq = platform_get_irq(pdev, 0);
  917. err = request_irq(dev->irq, macb_interrupt, IRQF_SAMPLE_RANDOM,
  918. dev->name, dev);
  919. if (err) {
  920. printk(KERN_ERR
  921. "%s: Unable to request IRQ %d (error %d)\n",
  922. dev->name, dev->irq, err);
  923. goto err_out_iounmap;
  924. }
  925. dev->open = macb_open;
  926. dev->stop = macb_close;
  927. dev->hard_start_xmit = macb_start_xmit;
  928. dev->get_stats = macb_get_stats;
  929. dev->set_multicast_list = macb_set_rx_mode;
  930. dev->do_ioctl = macb_ioctl;
  931. netif_napi_add(dev, &bp->napi, macb_poll, 64);
  932. dev->ethtool_ops = &macb_ethtool_ops;
  933. dev->base_addr = regs->start;
  934. /* Set MII management clock divider */
  935. pclk_hz = clk_get_rate(bp->pclk);
  936. if (pclk_hz <= 20000000)
  937. config = MACB_BF(CLK, MACB_CLK_DIV8);
  938. else if (pclk_hz <= 40000000)
  939. config = MACB_BF(CLK, MACB_CLK_DIV16);
  940. else if (pclk_hz <= 80000000)
  941. config = MACB_BF(CLK, MACB_CLK_DIV32);
  942. else
  943. config = MACB_BF(CLK, MACB_CLK_DIV64);
  944. macb_writel(bp, NCFGR, config);
  945. macb_get_hwaddr(bp);
  946. pdata = pdev->dev.platform_data;
  947. if (pdata && pdata->is_rmii)
  948. #if defined(CONFIG_ARCH_AT91)
  949. macb_writel(bp, USRIO, (MACB_BIT(RMII) | MACB_BIT(CLKEN)) );
  950. #else
  951. macb_writel(bp, USRIO, 0);
  952. #endif
  953. else
  954. #if defined(CONFIG_ARCH_AT91)
  955. macb_writel(bp, USRIO, MACB_BIT(CLKEN));
  956. #else
  957. macb_writel(bp, USRIO, MACB_BIT(MII));
  958. #endif
  959. bp->tx_pending = DEF_TX_RING_PENDING;
  960. err = register_netdev(dev);
  961. if (err) {
  962. dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
  963. goto err_out_free_irq;
  964. }
  965. if (macb_mii_init(bp) != 0) {
  966. goto err_out_unregister_netdev;
  967. }
  968. platform_set_drvdata(pdev, dev);
  969. printk(KERN_INFO "%s: Atmel MACB at 0x%08lx irq %d "
  970. "(%s)\n",
  971. dev->name, dev->base_addr, dev->irq,
  972. print_mac(mac, dev->dev_addr));
  973. phydev = bp->phy_dev;
  974. printk(KERN_INFO "%s: attached PHY driver [%s] "
  975. "(mii_bus:phy_addr=%s, irq=%d)\n",
  976. dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
  977. return 0;
  978. err_out_unregister_netdev:
  979. unregister_netdev(dev);
  980. err_out_free_irq:
  981. free_irq(dev->irq, dev);
  982. err_out_iounmap:
  983. iounmap(bp->regs);
  984. err_out_disable_clocks:
  985. #ifndef CONFIG_ARCH_AT91
  986. clk_disable(bp->hclk);
  987. clk_put(bp->hclk);
  988. #endif
  989. clk_disable(bp->pclk);
  990. #ifndef CONFIG_ARCH_AT91
  991. err_out_put_pclk:
  992. #endif
  993. clk_put(bp->pclk);
  994. err_out_free_dev:
  995. free_netdev(dev);
  996. err_out:
  997. platform_set_drvdata(pdev, NULL);
  998. return err;
  999. }
  1000. static int __devexit macb_remove(struct platform_device *pdev)
  1001. {
  1002. struct net_device *dev;
  1003. struct macb *bp;
  1004. dev = platform_get_drvdata(pdev);
  1005. if (dev) {
  1006. bp = netdev_priv(dev);
  1007. mdiobus_unregister(&bp->mii_bus);
  1008. kfree(bp->mii_bus.irq);
  1009. unregister_netdev(dev);
  1010. free_irq(dev->irq, dev);
  1011. iounmap(bp->regs);
  1012. #ifndef CONFIG_ARCH_AT91
  1013. clk_disable(bp->hclk);
  1014. clk_put(bp->hclk);
  1015. #endif
  1016. clk_disable(bp->pclk);
  1017. clk_put(bp->pclk);
  1018. free_netdev(dev);
  1019. platform_set_drvdata(pdev, NULL);
  1020. }
  1021. return 0;
  1022. }
  1023. static struct platform_driver macb_driver = {
  1024. .probe = macb_probe,
  1025. .remove = __devexit_p(macb_remove),
  1026. .driver = {
  1027. .name = "macb",
  1028. },
  1029. };
  1030. static int __init macb_init(void)
  1031. {
  1032. return platform_driver_register(&macb_driver);
  1033. }
  1034. static void __exit macb_exit(void)
  1035. {
  1036. platform_driver_unregister(&macb_driver);
  1037. }
  1038. module_init(macb_init);
  1039. module_exit(macb_exit);
  1040. MODULE_LICENSE("GPL");
  1041. MODULE_DESCRIPTION("Atmel MACB Ethernet driver");
  1042. MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");