am79c961a.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. * linux/drivers/net/am79c961.c
  3. *
  4. * by Russell King <rmk@arm.linux.org.uk> 1995-2001.
  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. * Derived from various things including skeleton.c
  11. *
  12. * This is a special driver for the am79c961A Lance chip used in the
  13. * Intel (formally Digital Equipment Corp) EBSA110 platform. Please
  14. * note that this can not be built as a module (it doesn't make sense).
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/ioport.h>
  20. #include <linux/slab.h>
  21. #include <linux/string.h>
  22. #include <linux/errno.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/delay.h>
  26. #include <linux/init.h>
  27. #include <linux/crc32.h>
  28. #include <linux/bitops.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/io.h>
  31. #include <mach/hardware.h>
  32. #include <asm/system.h>
  33. #define TX_BUFFERS 15
  34. #define RX_BUFFERS 25
  35. #include "am79c961a.h"
  36. static irqreturn_t
  37. am79c961_interrupt (int irq, void *dev_id);
  38. static unsigned int net_debug = NET_DEBUG;
  39. static const char version[] =
  40. "am79c961 ethernet driver (C) 1995-2001 Russell King v0.04\n";
  41. /* --------------------------------------------------------------------------- */
  42. #ifdef __arm__
  43. static void write_rreg(u_long base, u_int reg, u_int val)
  44. {
  45. __asm__(
  46. "str%?h %1, [%2] @ NET_RAP\n\t"
  47. "str%?h %0, [%2, #-4] @ NET_RDP"
  48. :
  49. : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464));
  50. }
  51. static inline unsigned short read_rreg(u_long base_addr, u_int reg)
  52. {
  53. unsigned short v;
  54. __asm__(
  55. "str%?h %1, [%2] @ NET_RAP\n\t"
  56. "ldr%?h %0, [%2, #-4] @ NET_RDP"
  57. : "=r" (v)
  58. : "r" (reg), "r" (ISAIO_BASE + 0x0464));
  59. return v;
  60. }
  61. static inline void write_ireg(u_long base, u_int reg, u_int val)
  62. {
  63. __asm__(
  64. "str%?h %1, [%2] @ NET_RAP\n\t"
  65. "str%?h %0, [%2, #8] @ NET_IDP"
  66. :
  67. : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464));
  68. }
  69. static inline unsigned short read_ireg(u_long base_addr, u_int reg)
  70. {
  71. u_short v;
  72. __asm__(
  73. "str%?h %1, [%2] @ NAT_RAP\n\t"
  74. "ldr%?h %0, [%2, #8] @ NET_IDP\n\t"
  75. : "=r" (v)
  76. : "r" (reg), "r" (ISAIO_BASE + 0x0464));
  77. return v;
  78. }
  79. #define am_writeword(dev,off,val) __raw_writew(val, ISAMEM_BASE + ((off) << 1))
  80. #define am_readword(dev,off) __raw_readw(ISAMEM_BASE + ((off) << 1))
  81. static inline void
  82. am_writebuffer(struct net_device *dev, u_int offset, unsigned char *buf, unsigned int length)
  83. {
  84. offset = ISAMEM_BASE + (offset << 1);
  85. length = (length + 1) & ~1;
  86. if ((int)buf & 2) {
  87. __asm__ __volatile__("str%?h %2, [%0], #4"
  88. : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8)));
  89. buf += 2;
  90. length -= 2;
  91. }
  92. while (length > 8) {
  93. unsigned int tmp, tmp2;
  94. __asm__ __volatile__(
  95. "ldm%?ia %1!, {%2, %3}\n\t"
  96. "str%?h %2, [%0], #4\n\t"
  97. "mov%? %2, %2, lsr #16\n\t"
  98. "str%?h %2, [%0], #4\n\t"
  99. "str%?h %3, [%0], #4\n\t"
  100. "mov%? %3, %3, lsr #16\n\t"
  101. "str%?h %3, [%0], #4"
  102. : "=&r" (offset), "=&r" (buf), "=r" (tmp), "=r" (tmp2)
  103. : "0" (offset), "1" (buf));
  104. length -= 8;
  105. }
  106. while (length > 0) {
  107. __asm__ __volatile__("str%?h %2, [%0], #4"
  108. : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8)));
  109. buf += 2;
  110. length -= 2;
  111. }
  112. }
  113. static inline void
  114. am_readbuffer(struct net_device *dev, u_int offset, unsigned char *buf, unsigned int length)
  115. {
  116. offset = ISAMEM_BASE + (offset << 1);
  117. length = (length + 1) & ~1;
  118. if ((int)buf & 2) {
  119. unsigned int tmp;
  120. __asm__ __volatile__(
  121. "ldr%?h %2, [%0], #4\n\t"
  122. "str%?b %2, [%1], #1\n\t"
  123. "mov%? %2, %2, lsr #8\n\t"
  124. "str%?b %2, [%1], #1"
  125. : "=&r" (offset), "=&r" (buf), "=r" (tmp): "0" (offset), "1" (buf));
  126. length -= 2;
  127. }
  128. while (length > 8) {
  129. unsigned int tmp, tmp2, tmp3;
  130. __asm__ __volatile__(
  131. "ldr%?h %2, [%0], #4\n\t"
  132. "ldr%?h %3, [%0], #4\n\t"
  133. "orr%? %2, %2, %3, lsl #16\n\t"
  134. "ldr%?h %3, [%0], #4\n\t"
  135. "ldr%?h %4, [%0], #4\n\t"
  136. "orr%? %3, %3, %4, lsl #16\n\t"
  137. "stm%?ia %1!, {%2, %3}"
  138. : "=&r" (offset), "=&r" (buf), "=r" (tmp), "=r" (tmp2), "=r" (tmp3)
  139. : "0" (offset), "1" (buf));
  140. length -= 8;
  141. }
  142. while (length > 0) {
  143. unsigned int tmp;
  144. __asm__ __volatile__(
  145. "ldr%?h %2, [%0], #4\n\t"
  146. "str%?b %2, [%1], #1\n\t"
  147. "mov%? %2, %2, lsr #8\n\t"
  148. "str%?b %2, [%1], #1"
  149. : "=&r" (offset), "=&r" (buf), "=r" (tmp) : "0" (offset), "1" (buf));
  150. length -= 2;
  151. }
  152. }
  153. #else
  154. #error Not compatible
  155. #endif
  156. static int
  157. am79c961_ramtest(struct net_device *dev, unsigned int val)
  158. {
  159. unsigned char *buffer = kmalloc (65536, GFP_KERNEL);
  160. int i, error = 0, errorcount = 0;
  161. if (!buffer)
  162. return 0;
  163. memset (buffer, val, 65536);
  164. am_writebuffer(dev, 0, buffer, 65536);
  165. memset (buffer, val ^ 255, 65536);
  166. am_readbuffer(dev, 0, buffer, 65536);
  167. for (i = 0; i < 65536; i++) {
  168. if (buffer[i] != val && !error) {
  169. printk ("%s: buffer error (%02X %02X) %05X - ", dev->name, val, buffer[i], i);
  170. error = 1;
  171. errorcount ++;
  172. } else if (error && buffer[i] == val) {
  173. printk ("%05X\n", i);
  174. error = 0;
  175. }
  176. }
  177. if (error)
  178. printk ("10000\n");
  179. kfree (buffer);
  180. return errorcount;
  181. }
  182. static void
  183. am79c961_init_for_open(struct net_device *dev)
  184. {
  185. struct dev_priv *priv = netdev_priv(dev);
  186. unsigned long flags;
  187. unsigned char *p;
  188. u_int hdr_addr, first_free_addr;
  189. int i;
  190. /*
  191. * Stop the chip.
  192. */
  193. spin_lock_irqsave(&priv->chip_lock, flags);
  194. write_rreg (dev->base_addr, CSR0, CSR0_BABL|CSR0_CERR|CSR0_MISS|CSR0_MERR|CSR0_TINT|CSR0_RINT|CSR0_STOP);
  195. spin_unlock_irqrestore(&priv->chip_lock, flags);
  196. write_ireg (dev->base_addr, 5, 0x00a0); /* Receive address LED */
  197. write_ireg (dev->base_addr, 6, 0x0081); /* Collision LED */
  198. write_ireg (dev->base_addr, 7, 0x0090); /* XMIT LED */
  199. write_ireg (dev->base_addr, 2, 0x0000); /* MODE register selects media */
  200. for (i = LADRL; i <= LADRH; i++)
  201. write_rreg (dev->base_addr, i, 0);
  202. for (i = PADRL, p = dev->dev_addr; i <= PADRH; i++, p += 2)
  203. write_rreg (dev->base_addr, i, p[0] | (p[1] << 8));
  204. i = MODE_PORT_10BT;
  205. if (dev->flags & IFF_PROMISC)
  206. i |= MODE_PROMISC;
  207. write_rreg (dev->base_addr, MODE, i);
  208. write_rreg (dev->base_addr, POLLINT, 0);
  209. write_rreg (dev->base_addr, SIZERXR, -RX_BUFFERS);
  210. write_rreg (dev->base_addr, SIZETXR, -TX_BUFFERS);
  211. first_free_addr = RX_BUFFERS * 8 + TX_BUFFERS * 8 + 16;
  212. hdr_addr = 0;
  213. priv->rxhead = 0;
  214. priv->rxtail = 0;
  215. priv->rxhdr = hdr_addr;
  216. for (i = 0; i < RX_BUFFERS; i++) {
  217. priv->rxbuffer[i] = first_free_addr;
  218. am_writeword (dev, hdr_addr, first_free_addr);
  219. am_writeword (dev, hdr_addr + 2, RMD_OWN);
  220. am_writeword (dev, hdr_addr + 4, (-1600));
  221. am_writeword (dev, hdr_addr + 6, 0);
  222. first_free_addr += 1600;
  223. hdr_addr += 8;
  224. }
  225. priv->txhead = 0;
  226. priv->txtail = 0;
  227. priv->txhdr = hdr_addr;
  228. for (i = 0; i < TX_BUFFERS; i++) {
  229. priv->txbuffer[i] = first_free_addr;
  230. am_writeword (dev, hdr_addr, first_free_addr);
  231. am_writeword (dev, hdr_addr + 2, TMD_STP|TMD_ENP);
  232. am_writeword (dev, hdr_addr + 4, 0xf000);
  233. am_writeword (dev, hdr_addr + 6, 0);
  234. first_free_addr += 1600;
  235. hdr_addr += 8;
  236. }
  237. write_rreg (dev->base_addr, BASERXL, priv->rxhdr);
  238. write_rreg (dev->base_addr, BASERXH, 0);
  239. write_rreg (dev->base_addr, BASETXL, priv->txhdr);
  240. write_rreg (dev->base_addr, BASERXH, 0);
  241. write_rreg (dev->base_addr, CSR0, CSR0_STOP);
  242. write_rreg (dev->base_addr, CSR3, CSR3_IDONM|CSR3_BABLM|CSR3_DXSUFLO);
  243. write_rreg (dev->base_addr, CSR4, CSR4_APAD_XMIT|CSR4_MFCOM|CSR4_RCVCCOM|CSR4_TXSTRTM|CSR4_JABM);
  244. write_rreg (dev->base_addr, CSR0, CSR0_IENA|CSR0_STRT);
  245. }
  246. static void am79c961_timer(unsigned long data)
  247. {
  248. struct net_device *dev = (struct net_device *)data;
  249. struct dev_priv *priv = netdev_priv(dev);
  250. unsigned int lnkstat, carrier;
  251. lnkstat = read_ireg(dev->base_addr, ISALED0) & ISALED0_LNKST;
  252. carrier = netif_carrier_ok(dev);
  253. if (lnkstat && !carrier) {
  254. netif_carrier_on(dev);
  255. printk("%s: link up\n", dev->name);
  256. } else if (!lnkstat && carrier) {
  257. netif_carrier_off(dev);
  258. printk("%s: link down\n", dev->name);
  259. }
  260. mod_timer(&priv->timer, jiffies + msecs_to_jiffies(500));
  261. }
  262. /*
  263. * Open/initialize the board.
  264. */
  265. static int
  266. am79c961_open(struct net_device *dev)
  267. {
  268. struct dev_priv *priv = netdev_priv(dev);
  269. int ret;
  270. memset (&priv->stats, 0, sizeof (priv->stats));
  271. ret = request_irq(dev->irq, am79c961_interrupt, 0, dev->name, dev);
  272. if (ret)
  273. return ret;
  274. am79c961_init_for_open(dev);
  275. netif_carrier_off(dev);
  276. priv->timer.expires = jiffies;
  277. add_timer(&priv->timer);
  278. netif_start_queue(dev);
  279. return 0;
  280. }
  281. /*
  282. * The inverse routine to am79c961_open().
  283. */
  284. static int
  285. am79c961_close(struct net_device *dev)
  286. {
  287. struct dev_priv *priv = netdev_priv(dev);
  288. unsigned long flags;
  289. del_timer_sync(&priv->timer);
  290. netif_stop_queue(dev);
  291. netif_carrier_off(dev);
  292. spin_lock_irqsave(&priv->chip_lock, flags);
  293. write_rreg (dev->base_addr, CSR0, CSR0_STOP);
  294. write_rreg (dev->base_addr, CSR3, CSR3_MASKALL);
  295. spin_unlock_irqrestore(&priv->chip_lock, flags);
  296. free_irq (dev->irq, dev);
  297. return 0;
  298. }
  299. /*
  300. * Get the current statistics.
  301. */
  302. static struct net_device_stats *am79c961_getstats (struct net_device *dev)
  303. {
  304. struct dev_priv *priv = netdev_priv(dev);
  305. return &priv->stats;
  306. }
  307. static void am79c961_mc_hash(struct dev_mc_list *dmi, unsigned short *hash)
  308. {
  309. if (dmi->dmi_addrlen == ETH_ALEN && dmi->dmi_addr[0] & 0x01) {
  310. int idx, bit;
  311. u32 crc;
  312. crc = ether_crc_le(ETH_ALEN, dmi->dmi_addr);
  313. idx = crc >> 30;
  314. bit = (crc >> 26) & 15;
  315. hash[idx] |= 1 << bit;
  316. }
  317. }
  318. /*
  319. * Set or clear promiscuous/multicast mode filter for this adapter.
  320. */
  321. static void am79c961_setmulticastlist (struct net_device *dev)
  322. {
  323. struct dev_priv *priv = netdev_priv(dev);
  324. unsigned long flags;
  325. unsigned short multi_hash[4], mode;
  326. int i, stopped;
  327. mode = MODE_PORT_10BT;
  328. if (dev->flags & IFF_PROMISC) {
  329. mode |= MODE_PROMISC;
  330. } else if (dev->flags & IFF_ALLMULTI) {
  331. memset(multi_hash, 0xff, sizeof(multi_hash));
  332. } else {
  333. struct dev_mc_list *dmi;
  334. memset(multi_hash, 0x00, sizeof(multi_hash));
  335. for (dmi = dev->mc_list; dmi; dmi = dmi->next)
  336. am79c961_mc_hash(dmi, multi_hash);
  337. }
  338. spin_lock_irqsave(&priv->chip_lock, flags);
  339. stopped = read_rreg(dev->base_addr, CSR0) & CSR0_STOP;
  340. if (!stopped) {
  341. /*
  342. * Put the chip into suspend mode
  343. */
  344. write_rreg(dev->base_addr, CTRL1, CTRL1_SPND);
  345. /*
  346. * Spin waiting for chip to report suspend mode
  347. */
  348. while ((read_rreg(dev->base_addr, CTRL1) & CTRL1_SPND) == 0) {
  349. spin_unlock_irqrestore(&priv->chip_lock, flags);
  350. nop();
  351. spin_lock_irqsave(&priv->chip_lock, flags);
  352. }
  353. }
  354. /*
  355. * Update the multicast hash table
  356. */
  357. for (i = 0; i < ARRAY_SIZE(multi_hash); i++)
  358. write_rreg(dev->base_addr, i + LADRL, multi_hash[i]);
  359. /*
  360. * Write the mode register
  361. */
  362. write_rreg(dev->base_addr, MODE, mode);
  363. if (!stopped) {
  364. /*
  365. * Put the chip back into running mode
  366. */
  367. write_rreg(dev->base_addr, CTRL1, 0);
  368. }
  369. spin_unlock_irqrestore(&priv->chip_lock, flags);
  370. }
  371. static void am79c961_timeout(struct net_device *dev)
  372. {
  373. printk(KERN_WARNING "%s: transmit timed out, network cable problem?\n",
  374. dev->name);
  375. /*
  376. * ought to do some setup of the tx side here
  377. */
  378. netif_wake_queue(dev);
  379. }
  380. /*
  381. * Transmit a packet
  382. */
  383. static int
  384. am79c961_sendpacket(struct sk_buff *skb, struct net_device *dev)
  385. {
  386. struct dev_priv *priv = netdev_priv(dev);
  387. unsigned int hdraddr, bufaddr;
  388. unsigned int head;
  389. unsigned long flags;
  390. head = priv->txhead;
  391. hdraddr = priv->txhdr + (head << 3);
  392. bufaddr = priv->txbuffer[head];
  393. head += 1;
  394. if (head >= TX_BUFFERS)
  395. head = 0;
  396. am_writebuffer (dev, bufaddr, skb->data, skb->len);
  397. am_writeword (dev, hdraddr + 4, -skb->len);
  398. am_writeword (dev, hdraddr + 2, TMD_OWN|TMD_STP|TMD_ENP);
  399. priv->txhead = head;
  400. spin_lock_irqsave(&priv->chip_lock, flags);
  401. write_rreg (dev->base_addr, CSR0, CSR0_TDMD|CSR0_IENA);
  402. dev->trans_start = jiffies;
  403. spin_unlock_irqrestore(&priv->chip_lock, flags);
  404. /*
  405. * If the next packet is owned by the ethernet device,
  406. * then the tx ring is full and we can't add another
  407. * packet.
  408. */
  409. if (am_readword(dev, priv->txhdr + (priv->txhead << 3) + 2) & TMD_OWN)
  410. netif_stop_queue(dev);
  411. dev_kfree_skb(skb);
  412. return 0;
  413. }
  414. /*
  415. * If we have a good packet(s), get it/them out of the buffers.
  416. */
  417. static void
  418. am79c961_rx(struct net_device *dev, struct dev_priv *priv)
  419. {
  420. do {
  421. struct sk_buff *skb;
  422. u_int hdraddr;
  423. u_int pktaddr;
  424. u_int status;
  425. int len;
  426. hdraddr = priv->rxhdr + (priv->rxtail << 3);
  427. pktaddr = priv->rxbuffer[priv->rxtail];
  428. status = am_readword (dev, hdraddr + 2);
  429. if (status & RMD_OWN) /* do we own it? */
  430. break;
  431. priv->rxtail ++;
  432. if (priv->rxtail >= RX_BUFFERS)
  433. priv->rxtail = 0;
  434. if ((status & (RMD_ERR|RMD_STP|RMD_ENP)) != (RMD_STP|RMD_ENP)) {
  435. am_writeword (dev, hdraddr + 2, RMD_OWN);
  436. priv->stats.rx_errors ++;
  437. if (status & RMD_ERR) {
  438. if (status & RMD_FRAM)
  439. priv->stats.rx_frame_errors ++;
  440. if (status & RMD_CRC)
  441. priv->stats.rx_crc_errors ++;
  442. } else if (status & RMD_STP)
  443. priv->stats.rx_length_errors ++;
  444. continue;
  445. }
  446. len = am_readword(dev, hdraddr + 6);
  447. skb = dev_alloc_skb(len + 2);
  448. if (skb) {
  449. skb_reserve(skb, 2);
  450. am_readbuffer(dev, pktaddr, skb_put(skb, len), len);
  451. am_writeword(dev, hdraddr + 2, RMD_OWN);
  452. skb->protocol = eth_type_trans(skb, dev);
  453. netif_rx(skb);
  454. priv->stats.rx_bytes += len;
  455. priv->stats.rx_packets ++;
  456. } else {
  457. am_writeword (dev, hdraddr + 2, RMD_OWN);
  458. printk (KERN_WARNING "%s: memory squeeze, dropping packet.\n", dev->name);
  459. priv->stats.rx_dropped ++;
  460. break;
  461. }
  462. } while (1);
  463. }
  464. /*
  465. * Update stats for the transmitted packet
  466. */
  467. static void
  468. am79c961_tx(struct net_device *dev, struct dev_priv *priv)
  469. {
  470. do {
  471. short len;
  472. u_int hdraddr;
  473. u_int status;
  474. hdraddr = priv->txhdr + (priv->txtail << 3);
  475. status = am_readword (dev, hdraddr + 2);
  476. if (status & TMD_OWN)
  477. break;
  478. priv->txtail ++;
  479. if (priv->txtail >= TX_BUFFERS)
  480. priv->txtail = 0;
  481. if (status & TMD_ERR) {
  482. u_int status2;
  483. priv->stats.tx_errors ++;
  484. status2 = am_readword (dev, hdraddr + 6);
  485. /*
  486. * Clear the error byte
  487. */
  488. am_writeword (dev, hdraddr + 6, 0);
  489. if (status2 & TST_RTRY)
  490. priv->stats.collisions += 16;
  491. if (status2 & TST_LCOL)
  492. priv->stats.tx_window_errors ++;
  493. if (status2 & TST_LCAR)
  494. priv->stats.tx_carrier_errors ++;
  495. if (status2 & TST_UFLO)
  496. priv->stats.tx_fifo_errors ++;
  497. continue;
  498. }
  499. priv->stats.tx_packets ++;
  500. len = am_readword (dev, hdraddr + 4);
  501. priv->stats.tx_bytes += -len;
  502. } while (priv->txtail != priv->txhead);
  503. netif_wake_queue(dev);
  504. }
  505. static irqreturn_t
  506. am79c961_interrupt(int irq, void *dev_id)
  507. {
  508. struct net_device *dev = (struct net_device *)dev_id;
  509. struct dev_priv *priv = netdev_priv(dev);
  510. u_int status, n = 100;
  511. int handled = 0;
  512. do {
  513. status = read_rreg(dev->base_addr, CSR0);
  514. write_rreg(dev->base_addr, CSR0, status &
  515. (CSR0_IENA|CSR0_TINT|CSR0_RINT|
  516. CSR0_MERR|CSR0_MISS|CSR0_CERR|CSR0_BABL));
  517. if (status & CSR0_RINT) {
  518. handled = 1;
  519. am79c961_rx(dev, priv);
  520. }
  521. if (status & CSR0_TINT) {
  522. handled = 1;
  523. am79c961_tx(dev, priv);
  524. }
  525. if (status & CSR0_MISS) {
  526. handled = 1;
  527. priv->stats.rx_dropped ++;
  528. }
  529. if (status & CSR0_CERR) {
  530. handled = 1;
  531. mod_timer(&priv->timer, jiffies);
  532. }
  533. } while (--n && status & (CSR0_RINT | CSR0_TINT));
  534. return IRQ_RETVAL(handled);
  535. }
  536. #ifdef CONFIG_NET_POLL_CONTROLLER
  537. static void am79c961_poll_controller(struct net_device *dev)
  538. {
  539. unsigned long flags;
  540. local_irq_save(flags);
  541. am79c961_interrupt(dev->irq, dev);
  542. local_irq_restore(flags);
  543. }
  544. #endif
  545. /*
  546. * Initialise the chip. Note that we always expect
  547. * to be entered with interrupts enabled.
  548. */
  549. static int
  550. am79c961_hw_init(struct net_device *dev)
  551. {
  552. struct dev_priv *priv = netdev_priv(dev);
  553. spin_lock_irq(&priv->chip_lock);
  554. write_rreg (dev->base_addr, CSR0, CSR0_STOP);
  555. write_rreg (dev->base_addr, CSR3, CSR3_MASKALL);
  556. spin_unlock_irq(&priv->chip_lock);
  557. am79c961_ramtest(dev, 0x66);
  558. am79c961_ramtest(dev, 0x99);
  559. return 0;
  560. }
  561. static void __init am79c961_banner(void)
  562. {
  563. static unsigned version_printed;
  564. if (net_debug && version_printed++ == 0)
  565. printk(KERN_INFO "%s", version);
  566. }
  567. static const struct net_device_ops am79c961_netdev_ops = {
  568. .ndo_open = am79c961_open,
  569. .ndo_stop = am79c961_close,
  570. .ndo_start_xmit = am79c961_sendpacket,
  571. .ndo_get_stats = am79c961_getstats,
  572. .ndo_set_multicast_list = am79c961_setmulticastlist,
  573. .ndo_tx_timeout = am79c961_timeout,
  574. .ndo_validate_addr = eth_validate_addr,
  575. .ndo_change_mtu = eth_change_mtu,
  576. .ndo_set_mac_address = eth_mac_addr,
  577. #ifdef CONFIG_NET_POLL_CONTROLLER
  578. .ndo_poll_controller = am79c961_poll_controller,
  579. #endif
  580. };
  581. static int __init am79c961_probe(struct platform_device *pdev)
  582. {
  583. struct resource *res;
  584. struct net_device *dev;
  585. struct dev_priv *priv;
  586. int i, ret;
  587. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  588. if (!res)
  589. return -ENODEV;
  590. dev = alloc_etherdev(sizeof(struct dev_priv));
  591. ret = -ENOMEM;
  592. if (!dev)
  593. goto out;
  594. SET_NETDEV_DEV(dev, &pdev->dev);
  595. priv = netdev_priv(dev);
  596. /*
  597. * Fixed address and IRQ lines here.
  598. * The PNP initialisation should have been
  599. * done by the ether bootp loader.
  600. */
  601. dev->base_addr = res->start;
  602. ret = platform_get_irq(pdev, 0);
  603. if (ret < 0) {
  604. ret = -ENODEV;
  605. goto nodev;
  606. }
  607. dev->irq = ret;
  608. ret = -ENODEV;
  609. if (!request_region(dev->base_addr, 0x18, dev->name))
  610. goto nodev;
  611. /*
  612. * Reset the device.
  613. */
  614. inb(dev->base_addr + NET_RESET);
  615. udelay(5);
  616. /*
  617. * Check the manufacturer part of the
  618. * ether address.
  619. */
  620. if (inb(dev->base_addr) != 0x08 ||
  621. inb(dev->base_addr + 2) != 0x00 ||
  622. inb(dev->base_addr + 4) != 0x2b)
  623. goto release;
  624. for (i = 0; i < 6; i++)
  625. dev->dev_addr[i] = inb(dev->base_addr + i * 2) & 0xff;
  626. am79c961_banner();
  627. spin_lock_init(&priv->chip_lock);
  628. init_timer(&priv->timer);
  629. priv->timer.data = (unsigned long)dev;
  630. priv->timer.function = am79c961_timer;
  631. if (am79c961_hw_init(dev))
  632. goto release;
  633. dev->netdev_ops = &am79c961_netdev_ops;
  634. ret = register_netdev(dev);
  635. if (ret == 0) {
  636. printk(KERN_INFO "%s: ether address %pM\n",
  637. dev->name, dev->dev_addr);
  638. return 0;
  639. }
  640. release:
  641. release_region(dev->base_addr, 0x18);
  642. nodev:
  643. free_netdev(dev);
  644. out:
  645. return ret;
  646. }
  647. static struct platform_driver am79c961_driver = {
  648. .probe = am79c961_probe,
  649. .driver = {
  650. .name = "am79c961",
  651. },
  652. };
  653. static int __init am79c961_init(void)
  654. {
  655. return platform_driver_register(&am79c961_driver);
  656. }
  657. __initcall(am79c961_init);