at91_ether.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. /*
  2. * Ethernet driver for the Atmel AT91RM9200 (Thunder)
  3. *
  4. * Copyright (C) 2003 SAN People (Pty) Ltd
  5. *
  6. * Based on an earlier Atmel EMAC macrocell driver by Atmel and Lineo Inc.
  7. * Initial version by Rick Bronson 01/11/2003
  8. *
  9. * Intel LXT971A PHY support by Christopher Bahns & David Knickerbocker
  10. * (Polaroid Corporation)
  11. *
  12. * Realtek RTL8201(B)L PHY support by Roman Avramenko <roman@imsystems.ru>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/config.h>
  22. #include <linux/mii.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/ethtool.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/clk.h>
  30. #include <asm/io.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/arch/at91rm9200_emac.h>
  34. #include <asm/arch/gpio.h>
  35. #include <asm/arch/board.h>
  36. #include "at91_ether.h"
  37. #define DRV_NAME "at91_ether"
  38. #define DRV_VERSION "1.0"
  39. static struct net_device *at91_dev;
  40. static struct clk *ether_clk;
  41. /* ..................................................................... */
  42. /*
  43. * Read from a EMAC register.
  44. */
  45. static inline unsigned long at91_emac_read(unsigned int reg)
  46. {
  47. void __iomem *emac_base = (void __iomem *)AT91_VA_BASE_EMAC;
  48. return __raw_readl(emac_base + reg);
  49. }
  50. /*
  51. * Write to a EMAC register.
  52. */
  53. static inline void at91_emac_write(unsigned int reg, unsigned long value)
  54. {
  55. void __iomem *emac_base = (void __iomem *)AT91_VA_BASE_EMAC;
  56. __raw_writel(value, emac_base + reg);
  57. }
  58. /* ........................... PHY INTERFACE ........................... */
  59. /*
  60. * Enable the MDIO bit in MAC control register
  61. * When not called from an interrupt-handler, access to the PHY must be
  62. * protected by a spinlock.
  63. */
  64. static void enable_mdi(void)
  65. {
  66. unsigned long ctl;
  67. ctl = at91_emac_read(AT91_EMAC_CTL);
  68. at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_MPE); /* enable management port */
  69. }
  70. /*
  71. * Disable the MDIO bit in the MAC control register
  72. */
  73. static void disable_mdi(void)
  74. {
  75. unsigned long ctl;
  76. ctl = at91_emac_read(AT91_EMAC_CTL);
  77. at91_emac_write(AT91_EMAC_CTL, ctl & ~AT91_EMAC_MPE); /* disable management port */
  78. }
  79. /*
  80. * Wait until the PHY operation is complete.
  81. */
  82. static inline void at91_phy_wait(void) {
  83. unsigned long timeout = jiffies + 2;
  84. while (!(at91_emac_read(AT91_EMAC_SR) & AT91_EMAC_SR_IDLE)) {
  85. if (time_after(jiffies, timeout)) {
  86. printk("at91_ether: MIO timeout\n");
  87. break;
  88. }
  89. cpu_relax();
  90. }
  91. }
  92. /*
  93. * Write value to the a PHY register
  94. * Note: MDI interface is assumed to already have been enabled.
  95. */
  96. static void write_phy(unsigned char phy_addr, unsigned char address, unsigned int value)
  97. {
  98. at91_emac_write(AT91_EMAC_MAN, AT91_EMAC_MAN_802_3 | AT91_EMAC_RW_W
  99. | ((phy_addr & 0x1f) << 23) | (address << 18) | (value & AT91_EMAC_DATA));
  100. /* Wait until IDLE bit in Network Status register is cleared */
  101. at91_phy_wait();
  102. }
  103. /*
  104. * Read value stored in a PHY register.
  105. * Note: MDI interface is assumed to already have been enabled.
  106. */
  107. static void read_phy(unsigned char phy_addr, unsigned char address, unsigned int *value)
  108. {
  109. at91_emac_write(AT91_EMAC_MAN, AT91_EMAC_MAN_802_3 | AT91_EMAC_RW_R
  110. | ((phy_addr & 0x1f) << 23) | (address << 18));
  111. /* Wait until IDLE bit in Network Status register is cleared */
  112. at91_phy_wait();
  113. *value = at91_emac_read(AT91_EMAC_MAN) & AT91_EMAC_DATA;
  114. }
  115. /* ........................... PHY MANAGEMENT .......................... */
  116. /*
  117. * Access the PHY to determine the current link speed and mode, and update the
  118. * MAC accordingly.
  119. * If no link or auto-negotiation is busy, then no changes are made.
  120. */
  121. static void update_linkspeed(struct net_device *dev)
  122. {
  123. struct at91_private *lp = (struct at91_private *) dev->priv;
  124. unsigned int bmsr, bmcr, lpa, mac_cfg;
  125. unsigned int speed, duplex;
  126. if (!mii_link_ok(&lp->mii)) { /* no link */
  127. netif_carrier_off(dev);
  128. printk(KERN_INFO "%s: Link down.\n", dev->name);
  129. return;
  130. }
  131. /* Link up, or auto-negotiation still in progress */
  132. read_phy(lp->phy_address, MII_BMSR, &bmsr);
  133. read_phy(lp->phy_address, MII_BMCR, &bmcr);
  134. if (bmcr & BMCR_ANENABLE) { /* AutoNegotiation is enabled */
  135. if (!(bmsr & BMSR_ANEGCOMPLETE))
  136. return; /* Do nothing - another interrupt generated when negotiation complete */
  137. read_phy(lp->phy_address, MII_LPA, &lpa);
  138. if ((lpa & LPA_100FULL) || (lpa & LPA_100HALF)) speed = SPEED_100;
  139. else speed = SPEED_10;
  140. if ((lpa & LPA_100FULL) || (lpa & LPA_10FULL)) duplex = DUPLEX_FULL;
  141. else duplex = DUPLEX_HALF;
  142. } else {
  143. speed = (bmcr & BMCR_SPEED100) ? SPEED_100 : SPEED_10;
  144. duplex = (bmcr & BMCR_FULLDPLX) ? DUPLEX_FULL : DUPLEX_HALF;
  145. }
  146. /* Update the MAC */
  147. mac_cfg = at91_emac_read(AT91_EMAC_CFG) & ~(AT91_EMAC_SPD | AT91_EMAC_FD);
  148. if (speed == SPEED_100) {
  149. if (duplex == DUPLEX_FULL) /* 100 Full Duplex */
  150. mac_cfg |= AT91_EMAC_SPD | AT91_EMAC_FD;
  151. else /* 100 Half Duplex */
  152. mac_cfg |= AT91_EMAC_SPD;
  153. } else {
  154. if (duplex == DUPLEX_FULL) /* 10 Full Duplex */
  155. mac_cfg |= AT91_EMAC_FD;
  156. else {} /* 10 Half Duplex */
  157. }
  158. at91_emac_write(AT91_EMAC_CFG, mac_cfg);
  159. printk(KERN_INFO "%s: Link now %i-%s\n", dev->name, speed, (duplex == DUPLEX_FULL) ? "FullDuplex" : "HalfDuplex");
  160. netif_carrier_on(dev);
  161. }
  162. /*
  163. * Handle interrupts from the PHY
  164. */
  165. static irqreturn_t at91ether_phy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  166. {
  167. struct net_device *dev = (struct net_device *) dev_id;
  168. struct at91_private *lp = (struct at91_private *) dev->priv;
  169. unsigned int phy;
  170. /*
  171. * This hander is triggered on both edges, but the PHY chips expect
  172. * level-triggering. We therefore have to check if the PHY actually has
  173. * an IRQ pending.
  174. */
  175. enable_mdi();
  176. if ((lp->phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) {
  177. read_phy(lp->phy_address, MII_DSINTR_REG, &phy); /* ack interrupt in Davicom PHY */
  178. if (!(phy & (1 << 0)))
  179. goto done;
  180. }
  181. else if (lp->phy_type == MII_LXT971A_ID) {
  182. read_phy(lp->phy_address, MII_ISINTS_REG, &phy); /* ack interrupt in Intel PHY */
  183. if (!(phy & (1 << 2)))
  184. goto done;
  185. }
  186. else if (lp->phy_type == MII_BCM5221_ID) {
  187. read_phy(lp->phy_address, MII_BCMINTR_REG, &phy); /* ack interrupt in Broadcom PHY */
  188. if (!(phy & (1 << 0)))
  189. goto done;
  190. }
  191. else if (lp->phy_type == MII_KS8721_ID) {
  192. read_phy(lp->phy_address, MII_TPISTATUS, &phy); /* ack interrupt in Micrel PHY */
  193. if (!(phy & ((1 << 2) | 1)))
  194. goto done;
  195. }
  196. update_linkspeed(dev);
  197. done:
  198. disable_mdi();
  199. return IRQ_HANDLED;
  200. }
  201. /*
  202. * Initialize and enable the PHY interrupt for link-state changes
  203. */
  204. static void enable_phyirq(struct net_device *dev)
  205. {
  206. struct at91_private *lp = (struct at91_private *) dev->priv;
  207. unsigned int dsintr, irq_number;
  208. int status;
  209. if (lp->phy_type == MII_RTL8201_ID) /* RTL8201 does not have an interrupt */
  210. return;
  211. if (lp->phy_type == MII_DP83847_ID) /* DP83847 does not have an interrupt */
  212. return;
  213. if (lp->phy_type == MII_AC101L_ID) /* AC101L interrupt not supported yet */
  214. return;
  215. irq_number = lp->board_data.phy_irq_pin;
  216. status = request_irq(irq_number, at91ether_phy_interrupt, 0, dev->name, dev);
  217. if (status) {
  218. printk(KERN_ERR "at91_ether: PHY IRQ %d request failed - status %d!\n", irq_number, status);
  219. return;
  220. }
  221. spin_lock_irq(&lp->lock);
  222. enable_mdi();
  223. if ((lp->phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) { /* for Davicom PHY */
  224. read_phy(lp->phy_address, MII_DSINTR_REG, &dsintr);
  225. dsintr = dsintr & ~0xf00; /* clear bits 8..11 */
  226. write_phy(lp->phy_address, MII_DSINTR_REG, dsintr);
  227. }
  228. else if (lp->phy_type == MII_LXT971A_ID) { /* for Intel PHY */
  229. read_phy(lp->phy_address, MII_ISINTE_REG, &dsintr);
  230. dsintr = dsintr | 0xf2; /* set bits 1, 4..7 */
  231. write_phy(lp->phy_address, MII_ISINTE_REG, dsintr);
  232. }
  233. else if (lp->phy_type == MII_BCM5221_ID) { /* for Broadcom PHY */
  234. dsintr = (1 << 15) | ( 1 << 14);
  235. write_phy(lp->phy_address, MII_BCMINTR_REG, dsintr);
  236. }
  237. else if (lp->phy_type == MII_KS8721_ID) { /* for Micrel PHY */
  238. dsintr = (1 << 10) | ( 1 << 8);
  239. write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
  240. }
  241. disable_mdi();
  242. spin_unlock_irq(&lp->lock);
  243. }
  244. /*
  245. * Disable the PHY interrupt
  246. */
  247. static void disable_phyirq(struct net_device *dev)
  248. {
  249. struct at91_private *lp = (struct at91_private *) dev->priv;
  250. unsigned int dsintr;
  251. unsigned int irq_number;
  252. if (lp->phy_type == MII_RTL8201_ID) /* RTL8201 does not have an interrupt */
  253. return;
  254. if (lp->phy_type == MII_DP83847_ID) /* DP83847 does not have an interrupt */
  255. return;
  256. if (lp->phy_type == MII_AC101L_ID) /* AC101L interrupt not supported yet */
  257. return;
  258. spin_lock_irq(&lp->lock);
  259. enable_mdi();
  260. if ((lp->phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) { /* for Davicom PHY */
  261. read_phy(lp->phy_address, MII_DSINTR_REG, &dsintr);
  262. dsintr = dsintr | 0xf00; /* set bits 8..11 */
  263. write_phy(lp->phy_address, MII_DSINTR_REG, dsintr);
  264. }
  265. else if (lp->phy_type == MII_LXT971A_ID) { /* for Intel PHY */
  266. read_phy(lp->phy_address, MII_ISINTE_REG, &dsintr);
  267. dsintr = dsintr & ~0xf2; /* clear bits 1, 4..7 */
  268. write_phy(lp->phy_address, MII_ISINTE_REG, dsintr);
  269. }
  270. else if (lp->phy_type == MII_BCM5221_ID) { /* for Broadcom PHY */
  271. read_phy(lp->phy_address, MII_BCMINTR_REG, &dsintr);
  272. dsintr = ~(1 << 14);
  273. write_phy(lp->phy_address, MII_BCMINTR_REG, dsintr);
  274. }
  275. else if (lp->phy_type == MII_KS8721_ID) { /* for Micrel PHY */
  276. read_phy(lp->phy_address, MII_TPISTATUS, &dsintr);
  277. dsintr = ~((1 << 10) | (1 << 8));
  278. write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
  279. }
  280. disable_mdi();
  281. spin_unlock_irq(&lp->lock);
  282. irq_number = lp->board_data.phy_irq_pin;
  283. free_irq(irq_number, dev); /* Free interrupt handler */
  284. }
  285. /*
  286. * Perform a software reset of the PHY.
  287. */
  288. #if 0
  289. static void reset_phy(struct net_device *dev)
  290. {
  291. struct at91_private *lp = (struct at91_private *) dev->priv;
  292. unsigned int bmcr;
  293. spin_lock_irq(&lp->lock);
  294. enable_mdi();
  295. /* Perform PHY reset */
  296. write_phy(lp->phy_address, MII_BMCR, BMCR_RESET);
  297. /* Wait until PHY reset is complete */
  298. do {
  299. read_phy(lp->phy_address, MII_BMCR, &bmcr);
  300. } while (!(bmcr && BMCR_RESET));
  301. disable_mdi();
  302. spin_unlock_irq(&lp->lock);
  303. }
  304. #endif
  305. /* ......................... ADDRESS MANAGEMENT ........................ */
  306. /*
  307. * NOTE: Your bootloader must always set the MAC address correctly before
  308. * booting into Linux.
  309. *
  310. * - It must always set the MAC address after reset, even if it doesn't
  311. * happen to access the Ethernet while it's booting. Some versions of
  312. * U-Boot on the AT91RM9200-DK do not do this.
  313. *
  314. * - Likewise it must store the addresses in the correct byte order.
  315. * MicroMonitor (uMon) on the CSB337 does this incorrectly (and
  316. * continues to do so, for bug-compatibility).
  317. */
  318. static short __init unpack_mac_address(struct net_device *dev, unsigned int hi, unsigned int lo)
  319. {
  320. char addr[6];
  321. if (machine_is_csb337()) {
  322. addr[5] = (lo & 0xff); /* The CSB337 bootloader stores the MAC the wrong-way around */
  323. addr[4] = (lo & 0xff00) >> 8;
  324. addr[3] = (lo & 0xff0000) >> 16;
  325. addr[2] = (lo & 0xff000000) >> 24;
  326. addr[1] = (hi & 0xff);
  327. addr[0] = (hi & 0xff00) >> 8;
  328. }
  329. else {
  330. addr[0] = (lo & 0xff);
  331. addr[1] = (lo & 0xff00) >> 8;
  332. addr[2] = (lo & 0xff0000) >> 16;
  333. addr[3] = (lo & 0xff000000) >> 24;
  334. addr[4] = (hi & 0xff);
  335. addr[5] = (hi & 0xff00) >> 8;
  336. }
  337. if (is_valid_ether_addr(addr)) {
  338. memcpy(dev->dev_addr, &addr, 6);
  339. return 1;
  340. }
  341. return 0;
  342. }
  343. /*
  344. * Set the ethernet MAC address in dev->dev_addr
  345. */
  346. static void __init get_mac_address(struct net_device *dev)
  347. {
  348. /* Check Specific-Address 1 */
  349. if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA1H), at91_emac_read(AT91_EMAC_SA1L)))
  350. return;
  351. /* Check Specific-Address 2 */
  352. if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA2H), at91_emac_read(AT91_EMAC_SA2L)))
  353. return;
  354. /* Check Specific-Address 3 */
  355. if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA3H), at91_emac_read(AT91_EMAC_SA3L)))
  356. return;
  357. /* Check Specific-Address 4 */
  358. if (unpack_mac_address(dev, at91_emac_read(AT91_EMAC_SA4H), at91_emac_read(AT91_EMAC_SA4L)))
  359. return;
  360. printk(KERN_ERR "at91_ether: Your bootloader did not configure a MAC address.\n");
  361. }
  362. /*
  363. * Program the hardware MAC address from dev->dev_addr.
  364. */
  365. static void update_mac_address(struct net_device *dev)
  366. {
  367. at91_emac_write(AT91_EMAC_SA1L, (dev->dev_addr[3] << 24) | (dev->dev_addr[2] << 16) | (dev->dev_addr[1] << 8) | (dev->dev_addr[0]));
  368. at91_emac_write(AT91_EMAC_SA1H, (dev->dev_addr[5] << 8) | (dev->dev_addr[4]));
  369. at91_emac_write(AT91_EMAC_SA2L, 0);
  370. at91_emac_write(AT91_EMAC_SA2H, 0);
  371. }
  372. /*
  373. * Store the new hardware address in dev->dev_addr, and update the MAC.
  374. */
  375. static int set_mac_address(struct net_device *dev, void* addr)
  376. {
  377. struct sockaddr *address = addr;
  378. if (!is_valid_ether_addr(address->sa_data))
  379. return -EADDRNOTAVAIL;
  380. memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
  381. update_mac_address(dev);
  382. printk("%s: Setting MAC address to %02x:%02x:%02x:%02x:%02x:%02x\n", dev->name,
  383. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  384. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  385. return 0;
  386. }
  387. static int inline hash_bit_value(int bitnr, __u8 *addr)
  388. {
  389. if (addr[bitnr / 8] & (1 << (bitnr % 8)))
  390. return 1;
  391. return 0;
  392. }
  393. /*
  394. * The hash address register is 64 bits long and takes up two locations in the memory map.
  395. * The least significant bits are stored in EMAC_HSL and the most significant
  396. * bits in EMAC_HSH.
  397. *
  398. * The unicast hash enable and the multicast hash enable bits in the network configuration
  399. * register enable the reception of hash matched frames. The destination address is
  400. * reduced to a 6 bit index into the 64 bit hash register using the following hash function.
  401. * The hash function is an exclusive or of every sixth bit of the destination address.
  402. * hash_index[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47]
  403. * hash_index[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46]
  404. * hash_index[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45]
  405. * hash_index[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44]
  406. * hash_index[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43]
  407. * hash_index[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42]
  408. * da[0] represents the least significant bit of the first byte received, that is, the multicast/
  409. * unicast indicator, and da[47] represents the most significant bit of the last byte
  410. * received.
  411. * If the hash index points to a bit that is set in the hash register then the frame will be
  412. * matched according to whether the frame is multicast or unicast.
  413. * A multicast match will be signalled if the multicast hash enable bit is set, da[0] is 1 and
  414. * the hash index points to a bit set in the hash register.
  415. * A unicast match will be signalled if the unicast hash enable bit is set, da[0] is 0 and the
  416. * hash index points to a bit set in the hash register.
  417. * To receive all multicast frames, the hash register should be set with all ones and the
  418. * multicast hash enable bit should be set in the network configuration register.
  419. */
  420. /*
  421. * Return the hash index value for the specified address.
  422. */
  423. static int hash_get_index(__u8 *addr)
  424. {
  425. int i, j, bitval;
  426. int hash_index = 0;
  427. for (j = 0; j < 6; j++) {
  428. for (i = 0, bitval = 0; i < 8; i++)
  429. bitval ^= hash_bit_value(i*6 + j, addr);
  430. hash_index |= (bitval << j);
  431. }
  432. return hash_index;
  433. }
  434. /*
  435. * Add multicast addresses to the internal multicast-hash table.
  436. */
  437. static void at91ether_sethashtable(struct net_device *dev)
  438. {
  439. struct dev_mc_list *curr;
  440. unsigned long mc_filter[2];
  441. unsigned int i, bitnr;
  442. mc_filter[0] = mc_filter[1] = 0;
  443. curr = dev->mc_list;
  444. for (i = 0; i < dev->mc_count; i++, curr = curr->next) {
  445. if (!curr) break; /* unexpected end of list */
  446. bitnr = hash_get_index(curr->dmi_addr);
  447. mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
  448. }
  449. at91_emac_write(AT91_EMAC_HSH, mc_filter[0]);
  450. at91_emac_write(AT91_EMAC_HSL, mc_filter[1]);
  451. }
  452. /*
  453. * Enable/Disable promiscuous and multicast modes.
  454. */
  455. static void at91ether_set_rx_mode(struct net_device *dev)
  456. {
  457. unsigned long cfg;
  458. cfg = at91_emac_read(AT91_EMAC_CFG);
  459. if (dev->flags & IFF_PROMISC) /* Enable promiscuous mode */
  460. cfg |= AT91_EMAC_CAF;
  461. else if (dev->flags & (~IFF_PROMISC)) /* Disable promiscuous mode */
  462. cfg &= ~AT91_EMAC_CAF;
  463. if (dev->flags & IFF_ALLMULTI) { /* Enable all multicast mode */
  464. at91_emac_write(AT91_EMAC_HSH, -1);
  465. at91_emac_write(AT91_EMAC_HSL, -1);
  466. cfg |= AT91_EMAC_MTI;
  467. } else if (dev->mc_count > 0) { /* Enable specific multicasts */
  468. at91ether_sethashtable(dev);
  469. cfg |= AT91_EMAC_MTI;
  470. } else if (dev->flags & (~IFF_ALLMULTI)) { /* Disable all multicast mode */
  471. at91_emac_write(AT91_EMAC_HSH, 0);
  472. at91_emac_write(AT91_EMAC_HSL, 0);
  473. cfg &= ~AT91_EMAC_MTI;
  474. }
  475. at91_emac_write(AT91_EMAC_CFG, cfg);
  476. }
  477. /* ......................... ETHTOOL SUPPORT ........................... */
  478. static int mdio_read(struct net_device *dev, int phy_id, int location)
  479. {
  480. unsigned int value;
  481. read_phy(phy_id, location, &value);
  482. return value;
  483. }
  484. static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
  485. {
  486. write_phy(phy_id, location, value);
  487. }
  488. static int at91ether_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  489. {
  490. struct at91_private *lp = (struct at91_private *) dev->priv;
  491. int ret;
  492. spin_lock_irq(&lp->lock);
  493. enable_mdi();
  494. ret = mii_ethtool_gset(&lp->mii, cmd);
  495. disable_mdi();
  496. spin_unlock_irq(&lp->lock);
  497. if (lp->phy_media == PORT_FIBRE) { /* override media type since mii.c doesn't know */
  498. cmd->supported = SUPPORTED_FIBRE;
  499. cmd->port = PORT_FIBRE;
  500. }
  501. return ret;
  502. }
  503. static int at91ether_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  504. {
  505. struct at91_private *lp = (struct at91_private *) dev->priv;
  506. int ret;
  507. spin_lock_irq(&lp->lock);
  508. enable_mdi();
  509. ret = mii_ethtool_sset(&lp->mii, cmd);
  510. disable_mdi();
  511. spin_unlock_irq(&lp->lock);
  512. return ret;
  513. }
  514. static int at91ether_nwayreset(struct net_device *dev)
  515. {
  516. struct at91_private *lp = (struct at91_private *) dev->priv;
  517. int ret;
  518. spin_lock_irq(&lp->lock);
  519. enable_mdi();
  520. ret = mii_nway_restart(&lp->mii);
  521. disable_mdi();
  522. spin_unlock_irq(&lp->lock);
  523. return ret;
  524. }
  525. static void at91ether_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  526. {
  527. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  528. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  529. strlcpy(info->bus_info, dev->class_dev.dev->bus_id, sizeof(info->bus_info));
  530. }
  531. static struct ethtool_ops at91ether_ethtool_ops = {
  532. .get_settings = at91ether_get_settings,
  533. .set_settings = at91ether_set_settings,
  534. .get_drvinfo = at91ether_get_drvinfo,
  535. .nway_reset = at91ether_nwayreset,
  536. .get_link = ethtool_op_get_link,
  537. };
  538. /* ................................ MAC ................................ */
  539. /*
  540. * Initialize and start the Receiver and Transmit subsystems
  541. */
  542. static void at91ether_start(struct net_device *dev)
  543. {
  544. struct at91_private *lp = (struct at91_private *) dev->priv;
  545. struct recv_desc_bufs *dlist, *dlist_phys;
  546. int i;
  547. unsigned long ctl;
  548. dlist = lp->dlist;
  549. dlist_phys = lp->dlist_phys;
  550. for (i = 0; i < MAX_RX_DESCR; i++) {
  551. dlist->descriptors[i].addr = (unsigned int) &dlist_phys->recv_buf[i][0];
  552. dlist->descriptors[i].size = 0;
  553. }
  554. /* Set the Wrap bit on the last descriptor */
  555. dlist->descriptors[i-1].addr |= EMAC_DESC_WRAP;
  556. /* Reset buffer index */
  557. lp->rxBuffIndex = 0;
  558. /* Program address of descriptor list in Rx Buffer Queue register */
  559. at91_emac_write(AT91_EMAC_RBQP, (unsigned long) dlist_phys);
  560. /* Enable Receive and Transmit */
  561. ctl = at91_emac_read(AT91_EMAC_CTL);
  562. at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_RE | AT91_EMAC_TE);
  563. }
  564. /*
  565. * Open the ethernet interface
  566. */
  567. static int at91ether_open(struct net_device *dev)
  568. {
  569. struct at91_private *lp = (struct at91_private *) dev->priv;
  570. unsigned long ctl;
  571. if (!is_valid_ether_addr(dev->dev_addr))
  572. return -EADDRNOTAVAIL;
  573. clk_enable(ether_clk); /* Re-enable Peripheral clock */
  574. /* Clear internal statistics */
  575. ctl = at91_emac_read(AT91_EMAC_CTL);
  576. at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_CSR);
  577. /* Update the MAC address (incase user has changed it) */
  578. update_mac_address(dev);
  579. /* Enable PHY interrupt */
  580. enable_phyirq(dev);
  581. /* Enable MAC interrupts */
  582. at91_emac_write(AT91_EMAC_IER, AT91_EMAC_RCOM | AT91_EMAC_RBNA
  583. | AT91_EMAC_TUND | AT91_EMAC_RTRY | AT91_EMAC_TCOM
  584. | AT91_EMAC_ROVR | AT91_EMAC_ABT);
  585. /* Determine current link speed */
  586. spin_lock_irq(&lp->lock);
  587. enable_mdi();
  588. update_linkspeed(dev);
  589. disable_mdi();
  590. spin_unlock_irq(&lp->lock);
  591. at91ether_start(dev);
  592. netif_start_queue(dev);
  593. return 0;
  594. }
  595. /*
  596. * Close the interface
  597. */
  598. static int at91ether_close(struct net_device *dev)
  599. {
  600. unsigned long ctl;
  601. /* Disable Receiver and Transmitter */
  602. ctl = at91_emac_read(AT91_EMAC_CTL);
  603. at91_emac_write(AT91_EMAC_CTL, ctl & ~(AT91_EMAC_TE | AT91_EMAC_RE));
  604. /* Disable PHY interrupt */
  605. disable_phyirq(dev);
  606. /* Disable MAC interrupts */
  607. at91_emac_write(AT91_EMAC_IDR, AT91_EMAC_RCOM | AT91_EMAC_RBNA
  608. | AT91_EMAC_TUND | AT91_EMAC_RTRY | AT91_EMAC_TCOM
  609. | AT91_EMAC_ROVR | AT91_EMAC_ABT);
  610. netif_stop_queue(dev);
  611. clk_disable(ether_clk); /* Disable Peripheral clock */
  612. return 0;
  613. }
  614. /*
  615. * Transmit packet.
  616. */
  617. static int at91ether_tx(struct sk_buff *skb, struct net_device *dev)
  618. {
  619. struct at91_private *lp = (struct at91_private *) dev->priv;
  620. if (at91_emac_read(AT91_EMAC_TSR) & AT91_EMAC_TSR_BNQ) {
  621. netif_stop_queue(dev);
  622. /* Store packet information (to free when Tx completed) */
  623. lp->skb = skb;
  624. lp->skb_length = skb->len;
  625. lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE);
  626. lp->stats.tx_bytes += skb->len;
  627. /* Set address of the data in the Transmit Address register */
  628. at91_emac_write(AT91_EMAC_TAR, lp->skb_physaddr);
  629. /* Set length of the packet in the Transmit Control register */
  630. at91_emac_write(AT91_EMAC_TCR, skb->len);
  631. dev->trans_start = jiffies;
  632. } else {
  633. printk(KERN_ERR "at91_ether.c: at91ether_tx() called, but device is busy!\n");
  634. return 1; /* if we return anything but zero, dev.c:1055 calls kfree_skb(skb)
  635. on this skb, he also reports -ENETDOWN and printk's, so either
  636. we free and return(0) or don't free and return 1 */
  637. }
  638. return 0;
  639. }
  640. /*
  641. * Update the current statistics from the internal statistics registers.
  642. */
  643. static struct net_device_stats *at91ether_stats(struct net_device *dev)
  644. {
  645. struct at91_private *lp = (struct at91_private *) dev->priv;
  646. int ale, lenerr, seqe, lcol, ecol;
  647. if (netif_running(dev)) {
  648. lp->stats.rx_packets += at91_emac_read(AT91_EMAC_OK); /* Good frames received */
  649. ale = at91_emac_read(AT91_EMAC_ALE);
  650. lp->stats.rx_frame_errors += ale; /* Alignment errors */
  651. lenerr = at91_emac_read(AT91_EMAC_ELR) + at91_emac_read(AT91_EMAC_USF);
  652. lp->stats.rx_length_errors += lenerr; /* Excessive Length or Undersize Frame error */
  653. seqe = at91_emac_read(AT91_EMAC_SEQE);
  654. lp->stats.rx_crc_errors += seqe; /* CRC error */
  655. lp->stats.rx_fifo_errors += at91_emac_read(AT91_EMAC_DRFC); /* Receive buffer not available */
  656. lp->stats.rx_errors += (ale + lenerr + seqe
  657. + at91_emac_read(AT91_EMAC_CDE) + at91_emac_read(AT91_EMAC_RJB));
  658. lp->stats.tx_packets += at91_emac_read(AT91_EMAC_FRA); /* Frames successfully transmitted */
  659. lp->stats.tx_fifo_errors += at91_emac_read(AT91_EMAC_TUE); /* Transmit FIFO underruns */
  660. lp->stats.tx_carrier_errors += at91_emac_read(AT91_EMAC_CSE); /* Carrier Sense errors */
  661. lp->stats.tx_heartbeat_errors += at91_emac_read(AT91_EMAC_SQEE);/* Heartbeat error */
  662. lcol = at91_emac_read(AT91_EMAC_LCOL);
  663. ecol = at91_emac_read(AT91_EMAC_ECOL);
  664. lp->stats.tx_window_errors += lcol; /* Late collisions */
  665. lp->stats.tx_aborted_errors += ecol; /* 16 collisions */
  666. lp->stats.collisions += (at91_emac_read(AT91_EMAC_SCOL) + at91_emac_read(AT91_EMAC_MCOL) + lcol + ecol);
  667. }
  668. return &lp->stats;
  669. }
  670. /*
  671. * Extract received frame from buffer descriptors and sent to upper layers.
  672. * (Called from interrupt context)
  673. */
  674. static void at91ether_rx(struct net_device *dev)
  675. {
  676. struct at91_private *lp = (struct at91_private *) dev->priv;
  677. struct recv_desc_bufs *dlist;
  678. unsigned char *p_recv;
  679. struct sk_buff *skb;
  680. unsigned int pktlen;
  681. dlist = lp->dlist;
  682. while (dlist->descriptors[lp->rxBuffIndex].addr & EMAC_DESC_DONE) {
  683. p_recv = dlist->recv_buf[lp->rxBuffIndex];
  684. pktlen = dlist->descriptors[lp->rxBuffIndex].size & 0x7ff; /* Length of frame including FCS */
  685. skb = alloc_skb(pktlen + 2, GFP_ATOMIC);
  686. if (skb != NULL) {
  687. skb_reserve(skb, 2);
  688. memcpy(skb_put(skb, pktlen), p_recv, pktlen);
  689. skb->dev = dev;
  690. skb->protocol = eth_type_trans(skb, dev);
  691. skb->len = pktlen;
  692. dev->last_rx = jiffies;
  693. lp->stats.rx_bytes += pktlen;
  694. netif_rx(skb);
  695. }
  696. else {
  697. lp->stats.rx_dropped += 1;
  698. printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
  699. }
  700. if (dlist->descriptors[lp->rxBuffIndex].size & EMAC_MULTICAST)
  701. lp->stats.multicast++;
  702. dlist->descriptors[lp->rxBuffIndex].addr &= ~EMAC_DESC_DONE; /* reset ownership bit */
  703. if (lp->rxBuffIndex == MAX_RX_DESCR-1) /* wrap after last buffer */
  704. lp->rxBuffIndex = 0;
  705. else
  706. lp->rxBuffIndex++;
  707. }
  708. }
  709. /*
  710. * MAC interrupt handler
  711. */
  712. static irqreturn_t at91ether_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  713. {
  714. struct net_device *dev = (struct net_device *) dev_id;
  715. struct at91_private *lp = (struct at91_private *) dev->priv;
  716. unsigned long intstatus, ctl;
  717. /* MAC Interrupt Status register indicates what interrupts are pending.
  718. It is automatically cleared once read. */
  719. intstatus = at91_emac_read(AT91_EMAC_ISR);
  720. if (intstatus & AT91_EMAC_RCOM) /* Receive complete */
  721. at91ether_rx(dev);
  722. if (intstatus & AT91_EMAC_TCOM) { /* Transmit complete */
  723. /* The TCOM bit is set even if the transmission failed. */
  724. if (intstatus & (AT91_EMAC_TUND | AT91_EMAC_RTRY))
  725. lp->stats.tx_errors += 1;
  726. if (lp->skb) {
  727. dev_kfree_skb_irq(lp->skb);
  728. lp->skb = NULL;
  729. dma_unmap_single(NULL, lp->skb_physaddr, lp->skb_length, DMA_TO_DEVICE);
  730. }
  731. netif_wake_queue(dev);
  732. }
  733. /* Work-around for Errata #11 */
  734. if (intstatus & AT91_EMAC_RBNA) {
  735. ctl = at91_emac_read(AT91_EMAC_CTL);
  736. at91_emac_write(AT91_EMAC_CTL, ctl & ~AT91_EMAC_RE);
  737. at91_emac_write(AT91_EMAC_CTL, ctl | AT91_EMAC_RE);
  738. }
  739. if (intstatus & AT91_EMAC_ROVR)
  740. printk("%s: ROVR error\n", dev->name);
  741. return IRQ_HANDLED;
  742. }
  743. /*
  744. * Initialize the ethernet interface
  745. */
  746. static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_address, struct platform_device *pdev)
  747. {
  748. struct at91_eth_data *board_data = pdev->dev.platform_data;
  749. struct net_device *dev;
  750. struct at91_private *lp;
  751. unsigned int val;
  752. int res;
  753. if (at91_dev) /* already initialized */
  754. return 0;
  755. dev = alloc_etherdev(sizeof(struct at91_private));
  756. if (!dev)
  757. return -ENOMEM;
  758. dev->base_addr = AT91_VA_BASE_EMAC;
  759. dev->irq = AT91_ID_EMAC;
  760. SET_MODULE_OWNER(dev);
  761. /* Install the interrupt handler */
  762. if (request_irq(dev->irq, at91ether_interrupt, 0, dev->name, dev)) {
  763. free_netdev(dev);
  764. return -EBUSY;
  765. }
  766. /* Allocate memory for DMA Receive descriptors */
  767. lp = (struct at91_private *)dev->priv;
  768. lp->dlist = (struct recv_desc_bufs *) dma_alloc_coherent(NULL, sizeof(struct recv_desc_bufs), (dma_addr_t *) &lp->dlist_phys, GFP_KERNEL);
  769. if (lp->dlist == NULL) {
  770. free_irq(dev->irq, dev);
  771. free_netdev(dev);
  772. return -ENOMEM;
  773. }
  774. lp->board_data = *board_data;
  775. platform_set_drvdata(pdev, dev);
  776. spin_lock_init(&lp->lock);
  777. ether_setup(dev);
  778. dev->open = at91ether_open;
  779. dev->stop = at91ether_close;
  780. dev->hard_start_xmit = at91ether_tx;
  781. dev->get_stats = at91ether_stats;
  782. dev->set_multicast_list = at91ether_set_rx_mode;
  783. dev->set_mac_address = set_mac_address;
  784. dev->ethtool_ops = &at91ether_ethtool_ops;
  785. SET_NETDEV_DEV(dev, &pdev->dev);
  786. get_mac_address(dev); /* Get ethernet address and store it in dev->dev_addr */
  787. update_mac_address(dev); /* Program ethernet address into MAC */
  788. at91_emac_write(AT91_EMAC_CTL, 0);
  789. if (lp->board_data.is_rmii)
  790. at91_emac_write(AT91_EMAC_CFG, AT91_EMAC_CLK_DIV32 | AT91_EMAC_BIG | AT91_EMAC_RMII);
  791. else
  792. at91_emac_write(AT91_EMAC_CFG, AT91_EMAC_CLK_DIV32 | AT91_EMAC_BIG);
  793. /* Perform PHY-specific initialization */
  794. spin_lock_irq(&lp->lock);
  795. enable_mdi();
  796. if ((phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID)) {
  797. read_phy(phy_address, MII_DSCR_REG, &val);
  798. if ((val & (1 << 10)) == 0) /* DSCR bit 10 is 0 -- fiber mode */
  799. lp->phy_media = PORT_FIBRE;
  800. } else if (machine_is_csb337()) {
  801. /* mix link activity status into LED2 link state */
  802. write_phy(phy_address, MII_LEDCTRL_REG, 0x0d22);
  803. }
  804. disable_mdi();
  805. spin_unlock_irq(&lp->lock);
  806. lp->mii.dev = dev; /* Support for ethtool */
  807. lp->mii.mdio_read = mdio_read;
  808. lp->mii.mdio_write = mdio_write;
  809. lp->phy_type = phy_type; /* Type of PHY connected */
  810. lp->phy_address = phy_address; /* MDI address of PHY */
  811. /* Register the network interface */
  812. res = register_netdev(dev);
  813. if (res) {
  814. free_irq(dev->irq, dev);
  815. free_netdev(dev);
  816. dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys);
  817. return res;
  818. }
  819. at91_dev = dev;
  820. /* Determine current link speed */
  821. spin_lock_irq(&lp->lock);
  822. enable_mdi();
  823. update_linkspeed(dev);
  824. disable_mdi();
  825. spin_unlock_irq(&lp->lock);
  826. netif_carrier_off(dev); /* will be enabled in open() */
  827. /* Display ethernet banner */
  828. printk(KERN_INFO "%s: AT91 ethernet at 0x%08x int=%d %s%s (%02x:%02x:%02x:%02x:%02x:%02x)\n",
  829. dev->name, (uint) dev->base_addr, dev->irq,
  830. at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_SPD ? "100-" : "10-",
  831. at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_FD ? "FullDuplex" : "HalfDuplex",
  832. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  833. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  834. if ((phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID))
  835. printk(KERN_INFO "%s: Davicom 9196 PHY %s\n", dev->name, (lp->phy_media == PORT_FIBRE) ? "(Fiber)" : "(Copper)");
  836. else if (phy_type == MII_LXT971A_ID)
  837. printk(KERN_INFO "%s: Intel LXT971A PHY\n", dev->name);
  838. else if (phy_type == MII_RTL8201_ID)
  839. printk(KERN_INFO "%s: Realtek RTL8201(B)L PHY\n", dev->name);
  840. else if (phy_type == MII_BCM5221_ID)
  841. printk(KERN_INFO "%s: Broadcom BCM5221 PHY\n", dev->name);
  842. else if (phy_type == MII_DP83847_ID)
  843. printk(KERN_INFO "%s: National Semiconductor DP83847 PHY\n", dev->name);
  844. else if (phy_type == MII_AC101L_ID)
  845. printk(KERN_INFO "%s: Altima AC101L PHY\n", dev->name);
  846. else if (phy_type == MII_KS8721_ID)
  847. printk(KERN_INFO "%s: Micrel KS8721 PHY\n", dev->name);
  848. return 0;
  849. }
  850. /*
  851. * Detect MAC and PHY and perform initialization
  852. */
  853. static int __init at91ether_probe(struct platform_device *pdev)
  854. {
  855. unsigned int phyid1, phyid2;
  856. int detected = -1;
  857. unsigned long phy_id;
  858. unsigned short phy_address = 0;
  859. ether_clk = clk_get(&pdev->dev, "ether_clk");
  860. if (!ether_clk) {
  861. printk(KERN_ERR "at91_ether: no clock defined\n");
  862. return -ENODEV;
  863. }
  864. clk_enable(ether_clk); /* Enable Peripheral clock */
  865. while ((detected != 0) && (phy_address < 32)) {
  866. /* Read the PHY ID registers */
  867. enable_mdi();
  868. read_phy(phy_address, MII_PHYSID1, &phyid1);
  869. read_phy(phy_address, MII_PHYSID2, &phyid2);
  870. disable_mdi();
  871. phy_id = (phyid1 << 16) | (phyid2 & 0xfff0);
  872. switch (phy_id) {
  873. case MII_DM9161_ID: /* Davicom 9161: PHY_ID1 = 0x181, PHY_ID2 = B881 */
  874. case MII_DM9161A_ID: /* Davicom 9161A: PHY_ID1 = 0x181, PHY_ID2 = B8A0 */
  875. case MII_LXT971A_ID: /* Intel LXT971A: PHY_ID1 = 0x13, PHY_ID2 = 78E0 */
  876. case MII_RTL8201_ID: /* Realtek RTL8201: PHY_ID1 = 0, PHY_ID2 = 0x8201 */
  877. case MII_BCM5221_ID: /* Broadcom BCM5221: PHY_ID1 = 0x40, PHY_ID2 = 0x61e0 */
  878. case MII_DP83847_ID: /* National Semiconductor DP83847: */
  879. case MII_AC101L_ID: /* Altima AC101L: PHY_ID1 = 0x22, PHY_ID2 = 0x5520 */
  880. case MII_KS8721_ID: /* Micrel KS8721: PHY_ID1 = 0x22, PHY_ID2 = 0x1610 */
  881. detected = at91ether_setup(phy_id, phy_address, pdev);
  882. break;
  883. }
  884. phy_address++;
  885. }
  886. clk_disable(ether_clk); /* Disable Peripheral clock */
  887. return detected;
  888. }
  889. static int __devexit at91ether_remove(struct platform_device *pdev)
  890. {
  891. struct at91_private *lp = (struct at91_private *) at91_dev->priv;
  892. unregister_netdev(at91_dev);
  893. free_irq(at91_dev->irq, at91_dev);
  894. dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys);
  895. clk_put(ether_clk);
  896. free_netdev(at91_dev);
  897. at91_dev = NULL;
  898. return 0;
  899. }
  900. static struct platform_driver at91ether_driver = {
  901. .probe = at91ether_probe,
  902. .remove = __devexit_p(at91ether_remove),
  903. /* FIXME: support suspend and resume */
  904. .driver = {
  905. .name = DRV_NAME,
  906. .owner = THIS_MODULE,
  907. },
  908. };
  909. static int __init at91ether_init(void)
  910. {
  911. return platform_driver_register(&at91ether_driver);
  912. }
  913. static void __exit at91ether_exit(void)
  914. {
  915. platform_driver_unregister(&at91ether_driver);
  916. }
  917. module_init(at91ether_init)
  918. module_exit(at91ether_exit)
  919. MODULE_LICENSE("GPL");
  920. MODULE_DESCRIPTION("AT91RM9200 EMAC Ethernet driver");
  921. MODULE_AUTHOR("Andrew Victor");