macb.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  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 net_device *dev, int *budget)
  377. {
  378. struct macb *bp = netdev_priv(dev);
  379. int orig_budget, work_done, retval = 0;
  380. u32 status;
  381. status = macb_readl(bp, RSR);
  382. macb_writel(bp, RSR, status);
  383. if (!status) {
  384. /*
  385. * This may happen if an interrupt was pending before
  386. * this function was called last time, and no packets
  387. * have been received since.
  388. */
  389. netif_rx_complete(dev);
  390. goto out;
  391. }
  392. dev_dbg(&bp->pdev->dev, "poll: status = %08lx, budget = %d\n",
  393. (unsigned long)status, *budget);
  394. if (!(status & MACB_BIT(REC))) {
  395. dev_warn(&bp->pdev->dev,
  396. "No RX buffers complete, status = %02lx\n",
  397. (unsigned long)status);
  398. netif_rx_complete(dev);
  399. goto out;
  400. }
  401. orig_budget = *budget;
  402. if (orig_budget > dev->quota)
  403. orig_budget = dev->quota;
  404. work_done = macb_rx(bp, orig_budget);
  405. if (work_done < orig_budget) {
  406. netif_rx_complete(dev);
  407. retval = 0;
  408. } else {
  409. retval = 1;
  410. }
  411. /*
  412. * We've done what we can to clean the buffers. Make sure we
  413. * get notified when new packets arrive.
  414. */
  415. out:
  416. macb_writel(bp, IER, MACB_RX_INT_FLAGS);
  417. /* TODO: Handle errors */
  418. return retval;
  419. }
  420. static irqreturn_t macb_interrupt(int irq, void *dev_id)
  421. {
  422. struct net_device *dev = dev_id;
  423. struct macb *bp = netdev_priv(dev);
  424. u32 status;
  425. status = macb_readl(bp, ISR);
  426. if (unlikely(!status))
  427. return IRQ_NONE;
  428. spin_lock(&bp->lock);
  429. while (status) {
  430. /* close possible race with dev_close */
  431. if (unlikely(!netif_running(dev))) {
  432. macb_writel(bp, IDR, ~0UL);
  433. break;
  434. }
  435. if (status & MACB_RX_INT_FLAGS) {
  436. if (netif_rx_schedule_prep(dev)) {
  437. /*
  438. * There's no point taking any more interrupts
  439. * until we have processed the buffers
  440. */
  441. macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
  442. dev_dbg(&bp->pdev->dev,
  443. "scheduling RX softirq\n");
  444. __netif_rx_schedule(dev);
  445. }
  446. }
  447. if (status & (MACB_BIT(TCOMP) | MACB_BIT(ISR_TUND)))
  448. macb_tx(bp);
  449. /*
  450. * Link change detection isn't possible with RMII, so we'll
  451. * add that if/when we get our hands on a full-blown MII PHY.
  452. */
  453. if (status & MACB_BIT(HRESP)) {
  454. /*
  455. * TODO: Reset the hardware, and maybe move the printk
  456. * to a lower-priority context as well (work queue?)
  457. */
  458. printk(KERN_ERR "%s: DMA bus error: HRESP not OK\n",
  459. dev->name);
  460. }
  461. status = macb_readl(bp, ISR);
  462. }
  463. spin_unlock(&bp->lock);
  464. return IRQ_HANDLED;
  465. }
  466. static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
  467. {
  468. struct macb *bp = netdev_priv(dev);
  469. dma_addr_t mapping;
  470. unsigned int len, entry;
  471. u32 ctrl;
  472. #ifdef DEBUG
  473. int i;
  474. dev_dbg(&bp->pdev->dev,
  475. "start_xmit: len %u head %p data %p tail %p end %p\n",
  476. skb->len, skb->head, skb->data,
  477. skb_tail_pointer(skb), skb_end_pointer(skb));
  478. dev_dbg(&bp->pdev->dev,
  479. "data:");
  480. for (i = 0; i < 16; i++)
  481. printk(" %02x", (unsigned int)skb->data[i]);
  482. printk("\n");
  483. #endif
  484. len = skb->len;
  485. spin_lock_irq(&bp->lock);
  486. /* This is a hard error, log it. */
  487. if (TX_BUFFS_AVAIL(bp) < 1) {
  488. netif_stop_queue(dev);
  489. spin_unlock_irq(&bp->lock);
  490. dev_err(&bp->pdev->dev,
  491. "BUG! Tx Ring full when queue awake!\n");
  492. dev_dbg(&bp->pdev->dev, "tx_head = %u, tx_tail = %u\n",
  493. bp->tx_head, bp->tx_tail);
  494. return 1;
  495. }
  496. entry = bp->tx_head;
  497. dev_dbg(&bp->pdev->dev, "Allocated ring entry %u\n", entry);
  498. mapping = dma_map_single(&bp->pdev->dev, skb->data,
  499. len, DMA_TO_DEVICE);
  500. bp->tx_skb[entry].skb = skb;
  501. bp->tx_skb[entry].mapping = mapping;
  502. dev_dbg(&bp->pdev->dev, "Mapped skb data %p to DMA addr %08lx\n",
  503. skb->data, (unsigned long)mapping);
  504. ctrl = MACB_BF(TX_FRMLEN, len);
  505. ctrl |= MACB_BIT(TX_LAST);
  506. if (entry == (TX_RING_SIZE - 1))
  507. ctrl |= MACB_BIT(TX_WRAP);
  508. bp->tx_ring[entry].addr = mapping;
  509. bp->tx_ring[entry].ctrl = ctrl;
  510. wmb();
  511. entry = NEXT_TX(entry);
  512. bp->tx_head = entry;
  513. macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART));
  514. if (TX_BUFFS_AVAIL(bp) < 1)
  515. netif_stop_queue(dev);
  516. spin_unlock_irq(&bp->lock);
  517. dev->trans_start = jiffies;
  518. return 0;
  519. }
  520. static void macb_free_consistent(struct macb *bp)
  521. {
  522. if (bp->tx_skb) {
  523. kfree(bp->tx_skb);
  524. bp->tx_skb = NULL;
  525. }
  526. if (bp->rx_ring) {
  527. dma_free_coherent(&bp->pdev->dev, RX_RING_BYTES,
  528. bp->rx_ring, bp->rx_ring_dma);
  529. bp->rx_ring = NULL;
  530. }
  531. if (bp->tx_ring) {
  532. dma_free_coherent(&bp->pdev->dev, TX_RING_BYTES,
  533. bp->tx_ring, bp->tx_ring_dma);
  534. bp->tx_ring = NULL;
  535. }
  536. if (bp->rx_buffers) {
  537. dma_free_coherent(&bp->pdev->dev,
  538. RX_RING_SIZE * RX_BUFFER_SIZE,
  539. bp->rx_buffers, bp->rx_buffers_dma);
  540. bp->rx_buffers = NULL;
  541. }
  542. }
  543. static int macb_alloc_consistent(struct macb *bp)
  544. {
  545. int size;
  546. size = TX_RING_SIZE * sizeof(struct ring_info);
  547. bp->tx_skb = kmalloc(size, GFP_KERNEL);
  548. if (!bp->tx_skb)
  549. goto out_err;
  550. size = RX_RING_BYTES;
  551. bp->rx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
  552. &bp->rx_ring_dma, GFP_KERNEL);
  553. if (!bp->rx_ring)
  554. goto out_err;
  555. dev_dbg(&bp->pdev->dev,
  556. "Allocated RX ring of %d bytes at %08lx (mapped %p)\n",
  557. size, (unsigned long)bp->rx_ring_dma, bp->rx_ring);
  558. size = TX_RING_BYTES;
  559. bp->tx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
  560. &bp->tx_ring_dma, GFP_KERNEL);
  561. if (!bp->tx_ring)
  562. goto out_err;
  563. dev_dbg(&bp->pdev->dev,
  564. "Allocated TX ring of %d bytes at %08lx (mapped %p)\n",
  565. size, (unsigned long)bp->tx_ring_dma, bp->tx_ring);
  566. size = RX_RING_SIZE * RX_BUFFER_SIZE;
  567. bp->rx_buffers = dma_alloc_coherent(&bp->pdev->dev, size,
  568. &bp->rx_buffers_dma, GFP_KERNEL);
  569. if (!bp->rx_buffers)
  570. goto out_err;
  571. dev_dbg(&bp->pdev->dev,
  572. "Allocated RX buffers of %d bytes at %08lx (mapped %p)\n",
  573. size, (unsigned long)bp->rx_buffers_dma, bp->rx_buffers);
  574. return 0;
  575. out_err:
  576. macb_free_consistent(bp);
  577. return -ENOMEM;
  578. }
  579. static void macb_init_rings(struct macb *bp)
  580. {
  581. int i;
  582. dma_addr_t addr;
  583. addr = bp->rx_buffers_dma;
  584. for (i = 0; i < RX_RING_SIZE; i++) {
  585. bp->rx_ring[i].addr = addr;
  586. bp->rx_ring[i].ctrl = 0;
  587. addr += RX_BUFFER_SIZE;
  588. }
  589. bp->rx_ring[RX_RING_SIZE - 1].addr |= MACB_BIT(RX_WRAP);
  590. for (i = 0; i < TX_RING_SIZE; i++) {
  591. bp->tx_ring[i].addr = 0;
  592. bp->tx_ring[i].ctrl = MACB_BIT(TX_USED);
  593. }
  594. bp->tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP);
  595. bp->rx_tail = bp->tx_head = bp->tx_tail = 0;
  596. }
  597. static void macb_reset_hw(struct macb *bp)
  598. {
  599. /* Make sure we have the write buffer for ourselves */
  600. wmb();
  601. /*
  602. * Disable RX and TX (XXX: Should we halt the transmission
  603. * more gracefully?)
  604. */
  605. macb_writel(bp, NCR, 0);
  606. /* Clear the stats registers (XXX: Update stats first?) */
  607. macb_writel(bp, NCR, MACB_BIT(CLRSTAT));
  608. /* Clear all status flags */
  609. macb_writel(bp, TSR, ~0UL);
  610. macb_writel(bp, RSR, ~0UL);
  611. /* Disable all interrupts */
  612. macb_writel(bp, IDR, ~0UL);
  613. macb_readl(bp, ISR);
  614. }
  615. static void macb_init_hw(struct macb *bp)
  616. {
  617. u32 config;
  618. macb_reset_hw(bp);
  619. __macb_set_hwaddr(bp);
  620. config = macb_readl(bp, NCFGR) & MACB_BF(CLK, -1L);
  621. config |= MACB_BIT(PAE); /* PAuse Enable */
  622. config |= MACB_BIT(DRFCS); /* Discard Rx FCS */
  623. if (bp->dev->flags & IFF_PROMISC)
  624. config |= MACB_BIT(CAF); /* Copy All Frames */
  625. if (!(bp->dev->flags & IFF_BROADCAST))
  626. config |= MACB_BIT(NBC); /* No BroadCast */
  627. macb_writel(bp, NCFGR, config);
  628. /* Initialize TX and RX buffers */
  629. macb_writel(bp, RBQP, bp->rx_ring_dma);
  630. macb_writel(bp, TBQP, bp->tx_ring_dma);
  631. /* Enable TX and RX */
  632. macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE) | MACB_BIT(MPE));
  633. /* Enable interrupts */
  634. macb_writel(bp, IER, (MACB_BIT(RCOMP)
  635. | MACB_BIT(RXUBR)
  636. | MACB_BIT(ISR_TUND)
  637. | MACB_BIT(ISR_RLE)
  638. | MACB_BIT(TXERR)
  639. | MACB_BIT(TCOMP)
  640. | MACB_BIT(ISR_ROVR)
  641. | MACB_BIT(HRESP)));
  642. }
  643. /*
  644. * The hash address register is 64 bits long and takes up two
  645. * locations in the memory map. The least significant bits are stored
  646. * in EMAC_HSL and the most significant bits in EMAC_HSH.
  647. *
  648. * The unicast hash enable and the multicast hash enable bits in the
  649. * network configuration register enable the reception of hash matched
  650. * frames. The destination address is reduced to a 6 bit index into
  651. * the 64 bit hash register using the following hash function. The
  652. * hash function is an exclusive or of every sixth bit of the
  653. * destination address.
  654. *
  655. * hi[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47]
  656. * hi[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46]
  657. * hi[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45]
  658. * hi[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44]
  659. * hi[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43]
  660. * hi[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42]
  661. *
  662. * da[0] represents the least significant bit of the first byte
  663. * received, that is, the multicast/unicast indicator, and da[47]
  664. * represents the most significant bit of the last byte received. If
  665. * the hash index, hi[n], points to a bit that is set in the hash
  666. * register then the frame will be matched according to whether the
  667. * frame is multicast or unicast. A multicast match will be signalled
  668. * if the multicast hash enable bit is set, da[0] is 1 and the hash
  669. * index points to a bit set in the hash register. A unicast match
  670. * will be signalled if the unicast hash enable bit is set, da[0] is 0
  671. * and the hash index points to a bit set in the hash register. To
  672. * receive all multicast frames, the hash register should be set with
  673. * all ones and the multicast hash enable bit should be set in the
  674. * network configuration register.
  675. */
  676. static inline int hash_bit_value(int bitnr, __u8 *addr)
  677. {
  678. if (addr[bitnr / 8] & (1 << (bitnr % 8)))
  679. return 1;
  680. return 0;
  681. }
  682. /*
  683. * Return the hash index value for the specified address.
  684. */
  685. static int hash_get_index(__u8 *addr)
  686. {
  687. int i, j, bitval;
  688. int hash_index = 0;
  689. for (j = 0; j < 6; j++) {
  690. for (i = 0, bitval = 0; i < 8; i++)
  691. bitval ^= hash_bit_value(i*6 + j, addr);
  692. hash_index |= (bitval << j);
  693. }
  694. return hash_index;
  695. }
  696. /*
  697. * Add multicast addresses to the internal multicast-hash table.
  698. */
  699. static void macb_sethashtable(struct net_device *dev)
  700. {
  701. struct dev_mc_list *curr;
  702. unsigned long mc_filter[2];
  703. unsigned int i, bitnr;
  704. struct macb *bp = netdev_priv(dev);
  705. mc_filter[0] = mc_filter[1] = 0;
  706. curr = dev->mc_list;
  707. for (i = 0; i < dev->mc_count; i++, curr = curr->next) {
  708. if (!curr) break; /* unexpected end of list */
  709. bitnr = hash_get_index(curr->dmi_addr);
  710. mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
  711. }
  712. macb_writel(bp, HRB, mc_filter[0]);
  713. macb_writel(bp, HRT, mc_filter[1]);
  714. }
  715. /*
  716. * Enable/Disable promiscuous and multicast modes.
  717. */
  718. static void macb_set_rx_mode(struct net_device *dev)
  719. {
  720. unsigned long cfg;
  721. struct macb *bp = netdev_priv(dev);
  722. cfg = macb_readl(bp, NCFGR);
  723. if (dev->flags & IFF_PROMISC)
  724. /* Enable promiscuous mode */
  725. cfg |= MACB_BIT(CAF);
  726. else if (dev->flags & (~IFF_PROMISC))
  727. /* Disable promiscuous mode */
  728. cfg &= ~MACB_BIT(CAF);
  729. if (dev->flags & IFF_ALLMULTI) {
  730. /* Enable all multicast mode */
  731. macb_writel(bp, HRB, -1);
  732. macb_writel(bp, HRT, -1);
  733. cfg |= MACB_BIT(NCFGR_MTI);
  734. } else if (dev->mc_count > 0) {
  735. /* Enable specific multicasts */
  736. macb_sethashtable(dev);
  737. cfg |= MACB_BIT(NCFGR_MTI);
  738. } else if (dev->flags & (~IFF_ALLMULTI)) {
  739. /* Disable all multicast mode */
  740. macb_writel(bp, HRB, 0);
  741. macb_writel(bp, HRT, 0);
  742. cfg &= ~MACB_BIT(NCFGR_MTI);
  743. }
  744. macb_writel(bp, NCFGR, cfg);
  745. }
  746. static int macb_open(struct net_device *dev)
  747. {
  748. struct macb *bp = netdev_priv(dev);
  749. int err;
  750. dev_dbg(&bp->pdev->dev, "open\n");
  751. /* if the phy is not yet register, retry later*/
  752. if (!bp->phy_dev)
  753. return -EAGAIN;
  754. if (!is_valid_ether_addr(dev->dev_addr))
  755. return -EADDRNOTAVAIL;
  756. err = macb_alloc_consistent(bp);
  757. if (err) {
  758. printk(KERN_ERR
  759. "%s: Unable to allocate DMA memory (error %d)\n",
  760. dev->name, err);
  761. return err;
  762. }
  763. macb_init_rings(bp);
  764. macb_init_hw(bp);
  765. /* schedule a link state check */
  766. phy_start(bp->phy_dev);
  767. netif_start_queue(dev);
  768. return 0;
  769. }
  770. static int macb_close(struct net_device *dev)
  771. {
  772. struct macb *bp = netdev_priv(dev);
  773. unsigned long flags;
  774. netif_stop_queue(dev);
  775. if (bp->phy_dev)
  776. phy_stop(bp->phy_dev);
  777. spin_lock_irqsave(&bp->lock, flags);
  778. macb_reset_hw(bp);
  779. netif_carrier_off(dev);
  780. spin_unlock_irqrestore(&bp->lock, flags);
  781. macb_free_consistent(bp);
  782. return 0;
  783. }
  784. static struct net_device_stats *macb_get_stats(struct net_device *dev)
  785. {
  786. struct macb *bp = netdev_priv(dev);
  787. struct net_device_stats *nstat = &bp->stats;
  788. struct macb_stats *hwstat = &bp->hw_stats;
  789. /* read stats from hardware */
  790. macb_update_stats(bp);
  791. /* Convert HW stats into netdevice stats */
  792. nstat->rx_errors = (hwstat->rx_fcs_errors +
  793. hwstat->rx_align_errors +
  794. hwstat->rx_resource_errors +
  795. hwstat->rx_overruns +
  796. hwstat->rx_oversize_pkts +
  797. hwstat->rx_jabbers +
  798. hwstat->rx_undersize_pkts +
  799. hwstat->sqe_test_errors +
  800. hwstat->rx_length_mismatch);
  801. nstat->tx_errors = (hwstat->tx_late_cols +
  802. hwstat->tx_excessive_cols +
  803. hwstat->tx_underruns +
  804. hwstat->tx_carrier_errors);
  805. nstat->collisions = (hwstat->tx_single_cols +
  806. hwstat->tx_multiple_cols +
  807. hwstat->tx_excessive_cols);
  808. nstat->rx_length_errors = (hwstat->rx_oversize_pkts +
  809. hwstat->rx_jabbers +
  810. hwstat->rx_undersize_pkts +
  811. hwstat->rx_length_mismatch);
  812. nstat->rx_over_errors = hwstat->rx_resource_errors;
  813. nstat->rx_crc_errors = hwstat->rx_fcs_errors;
  814. nstat->rx_frame_errors = hwstat->rx_align_errors;
  815. nstat->rx_fifo_errors = hwstat->rx_overruns;
  816. /* XXX: What does "missed" mean? */
  817. nstat->tx_aborted_errors = hwstat->tx_excessive_cols;
  818. nstat->tx_carrier_errors = hwstat->tx_carrier_errors;
  819. nstat->tx_fifo_errors = hwstat->tx_underruns;
  820. /* Don't know about heartbeat or window errors... */
  821. return nstat;
  822. }
  823. static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  824. {
  825. struct macb *bp = netdev_priv(dev);
  826. struct phy_device *phydev = bp->phy_dev;
  827. if (!phydev)
  828. return -ENODEV;
  829. return phy_ethtool_gset(phydev, cmd);
  830. }
  831. static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  832. {
  833. struct macb *bp = netdev_priv(dev);
  834. struct phy_device *phydev = bp->phy_dev;
  835. if (!phydev)
  836. return -ENODEV;
  837. return phy_ethtool_sset(phydev, cmd);
  838. }
  839. static void macb_get_drvinfo(struct net_device *dev,
  840. struct ethtool_drvinfo *info)
  841. {
  842. struct macb *bp = netdev_priv(dev);
  843. strcpy(info->driver, bp->pdev->dev.driver->name);
  844. strcpy(info->version, "$Revision: 1.14 $");
  845. strcpy(info->bus_info, bp->pdev->dev.bus_id);
  846. }
  847. static struct ethtool_ops macb_ethtool_ops = {
  848. .get_settings = macb_get_settings,
  849. .set_settings = macb_set_settings,
  850. .get_drvinfo = macb_get_drvinfo,
  851. .get_link = ethtool_op_get_link,
  852. };
  853. static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  854. {
  855. struct macb *bp = netdev_priv(dev);
  856. struct phy_device *phydev = bp->phy_dev;
  857. if (!netif_running(dev))
  858. return -EINVAL;
  859. if (!phydev)
  860. return -ENODEV;
  861. return phy_mii_ioctl(phydev, if_mii(rq), cmd);
  862. }
  863. static int __devinit macb_probe(struct platform_device *pdev)
  864. {
  865. struct eth_platform_data *pdata;
  866. struct resource *regs;
  867. struct net_device *dev;
  868. struct macb *bp;
  869. struct phy_device *phydev;
  870. unsigned long pclk_hz;
  871. u32 config;
  872. int err = -ENXIO;
  873. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  874. if (!regs) {
  875. dev_err(&pdev->dev, "no mmio resource defined\n");
  876. goto err_out;
  877. }
  878. err = -ENOMEM;
  879. dev = alloc_etherdev(sizeof(*bp));
  880. if (!dev) {
  881. dev_err(&pdev->dev, "etherdev alloc failed, aborting.\n");
  882. goto err_out;
  883. }
  884. SET_MODULE_OWNER(dev);
  885. SET_NETDEV_DEV(dev, &pdev->dev);
  886. /* TODO: Actually, we have some interesting features... */
  887. dev->features |= 0;
  888. bp = netdev_priv(dev);
  889. bp->pdev = pdev;
  890. bp->dev = dev;
  891. spin_lock_init(&bp->lock);
  892. #if defined(CONFIG_ARCH_AT91)
  893. bp->pclk = clk_get(&pdev->dev, "macb_clk");
  894. if (IS_ERR(bp->pclk)) {
  895. dev_err(&pdev->dev, "failed to get macb_clk\n");
  896. goto err_out_free_dev;
  897. }
  898. clk_enable(bp->pclk);
  899. #else
  900. bp->pclk = clk_get(&pdev->dev, "pclk");
  901. if (IS_ERR(bp->pclk)) {
  902. dev_err(&pdev->dev, "failed to get pclk\n");
  903. goto err_out_free_dev;
  904. }
  905. bp->hclk = clk_get(&pdev->dev, "hclk");
  906. if (IS_ERR(bp->hclk)) {
  907. dev_err(&pdev->dev, "failed to get hclk\n");
  908. goto err_out_put_pclk;
  909. }
  910. clk_enable(bp->pclk);
  911. clk_enable(bp->hclk);
  912. #endif
  913. bp->regs = ioremap(regs->start, regs->end - regs->start + 1);
  914. if (!bp->regs) {
  915. dev_err(&pdev->dev, "failed to map registers, aborting.\n");
  916. err = -ENOMEM;
  917. goto err_out_disable_clocks;
  918. }
  919. dev->irq = platform_get_irq(pdev, 0);
  920. err = request_irq(dev->irq, macb_interrupt, IRQF_SAMPLE_RANDOM,
  921. dev->name, dev);
  922. if (err) {
  923. printk(KERN_ERR
  924. "%s: Unable to request IRQ %d (error %d)\n",
  925. dev->name, dev->irq, err);
  926. goto err_out_iounmap;
  927. }
  928. dev->open = macb_open;
  929. dev->stop = macb_close;
  930. dev->hard_start_xmit = macb_start_xmit;
  931. dev->get_stats = macb_get_stats;
  932. dev->set_multicast_list = macb_set_rx_mode;
  933. dev->do_ioctl = macb_ioctl;
  934. dev->poll = macb_poll;
  935. dev->weight = 64;
  936. dev->ethtool_ops = &macb_ethtool_ops;
  937. dev->base_addr = regs->start;
  938. /* Set MII management clock divider */
  939. pclk_hz = clk_get_rate(bp->pclk);
  940. if (pclk_hz <= 20000000)
  941. config = MACB_BF(CLK, MACB_CLK_DIV8);
  942. else if (pclk_hz <= 40000000)
  943. config = MACB_BF(CLK, MACB_CLK_DIV16);
  944. else if (pclk_hz <= 80000000)
  945. config = MACB_BF(CLK, MACB_CLK_DIV32);
  946. else
  947. config = MACB_BF(CLK, MACB_CLK_DIV64);
  948. macb_writel(bp, NCFGR, config);
  949. macb_get_hwaddr(bp);
  950. pdata = pdev->dev.platform_data;
  951. if (pdata && pdata->is_rmii)
  952. #if defined(CONFIG_ARCH_AT91)
  953. macb_writel(bp, USRIO, (MACB_BIT(RMII) | MACB_BIT(CLKEN)) );
  954. #else
  955. macb_writel(bp, USRIO, 0);
  956. #endif
  957. else
  958. #if defined(CONFIG_ARCH_AT91)
  959. macb_writel(bp, USRIO, MACB_BIT(CLKEN));
  960. #else
  961. macb_writel(bp, USRIO, MACB_BIT(MII));
  962. #endif
  963. bp->tx_pending = DEF_TX_RING_PENDING;
  964. err = register_netdev(dev);
  965. if (err) {
  966. dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
  967. goto err_out_free_irq;
  968. }
  969. if (macb_mii_init(bp) != 0) {
  970. goto err_out_unregister_netdev;
  971. }
  972. platform_set_drvdata(pdev, dev);
  973. printk(KERN_INFO "%s: Atmel MACB at 0x%08lx irq %d "
  974. "(%02x:%02x:%02x:%02x:%02x:%02x)\n",
  975. dev->name, dev->base_addr, dev->irq,
  976. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  977. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  978. phydev = bp->phy_dev;
  979. printk(KERN_INFO "%s: attached PHY driver [%s] "
  980. "(mii_bus:phy_addr=%s, irq=%d)\n",
  981. dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
  982. return 0;
  983. err_out_unregister_netdev:
  984. unregister_netdev(dev);
  985. err_out_free_irq:
  986. free_irq(dev->irq, dev);
  987. err_out_iounmap:
  988. iounmap(bp->regs);
  989. err_out_disable_clocks:
  990. #ifndef CONFIG_ARCH_AT91
  991. clk_disable(bp->hclk);
  992. clk_put(bp->hclk);
  993. #endif
  994. clk_disable(bp->pclk);
  995. #ifndef CONFIG_ARCH_AT91
  996. err_out_put_pclk:
  997. #endif
  998. clk_put(bp->pclk);
  999. err_out_free_dev:
  1000. free_netdev(dev);
  1001. err_out:
  1002. platform_set_drvdata(pdev, NULL);
  1003. return err;
  1004. }
  1005. static int __devexit macb_remove(struct platform_device *pdev)
  1006. {
  1007. struct net_device *dev;
  1008. struct macb *bp;
  1009. dev = platform_get_drvdata(pdev);
  1010. if (dev) {
  1011. bp = netdev_priv(dev);
  1012. mdiobus_unregister(&bp->mii_bus);
  1013. kfree(bp->mii_bus.irq);
  1014. unregister_netdev(dev);
  1015. free_irq(dev->irq, dev);
  1016. iounmap(bp->regs);
  1017. #ifndef CONFIG_ARCH_AT91
  1018. clk_disable(bp->hclk);
  1019. clk_put(bp->hclk);
  1020. #endif
  1021. clk_disable(bp->pclk);
  1022. clk_put(bp->pclk);
  1023. free_netdev(dev);
  1024. platform_set_drvdata(pdev, NULL);
  1025. }
  1026. return 0;
  1027. }
  1028. static struct platform_driver macb_driver = {
  1029. .probe = macb_probe,
  1030. .remove = __devexit_p(macb_remove),
  1031. .driver = {
  1032. .name = "macb",
  1033. },
  1034. };
  1035. static int __init macb_init(void)
  1036. {
  1037. return platform_driver_register(&macb_driver);
  1038. }
  1039. static void __exit macb_exit(void)
  1040. {
  1041. platform_driver_unregister(&macb_driver);
  1042. }
  1043. module_init(macb_init);
  1044. module_exit(macb_exit);
  1045. MODULE_LICENSE("GPL");
  1046. MODULE_DESCRIPTION("Atmel MACB Ethernet driver");
  1047. MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");