am79c961a.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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 <asm/system.h>
  30. #include <asm/irq.h>
  31. #include <asm/hardware.h>
  32. #include <asm/io.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, struct pt_regs *regs);
  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. else if (!lnkstat && carrier)
  256. netif_carrier_off(dev);
  257. mod_timer(&priv->timer, jiffies + msecs_to_jiffies(500));
  258. }
  259. /*
  260. * Open/initialize the board.
  261. */
  262. static int
  263. am79c961_open(struct net_device *dev)
  264. {
  265. struct dev_priv *priv = netdev_priv(dev);
  266. int ret;
  267. memset (&priv->stats, 0, sizeof (priv->stats));
  268. ret = request_irq(dev->irq, am79c961_interrupt, 0, dev->name, dev);
  269. if (ret)
  270. return ret;
  271. am79c961_init_for_open(dev);
  272. netif_carrier_off(dev);
  273. priv->timer.expires = jiffies;
  274. add_timer(&priv->timer);
  275. netif_start_queue(dev);
  276. return 0;
  277. }
  278. /*
  279. * The inverse routine to am79c961_open().
  280. */
  281. static int
  282. am79c961_close(struct net_device *dev)
  283. {
  284. struct dev_priv *priv = netdev_priv(dev);
  285. unsigned long flags;
  286. del_timer_sync(&priv->timer);
  287. netif_stop_queue(dev);
  288. netif_carrier_off(dev);
  289. spin_lock_irqsave(priv->chip_lock, flags);
  290. write_rreg (dev->base_addr, CSR0, CSR0_STOP);
  291. write_rreg (dev->base_addr, CSR3, CSR3_MASKALL);
  292. spin_unlock_irqrestore(priv->chip_lock, flags);
  293. free_irq (dev->irq, dev);
  294. return 0;
  295. }
  296. /*
  297. * Get the current statistics.
  298. */
  299. static struct net_device_stats *am79c961_getstats (struct net_device *dev)
  300. {
  301. struct dev_priv *priv = netdev_priv(dev);
  302. return &priv->stats;
  303. }
  304. static void am79c961_mc_hash(struct dev_mc_list *dmi, unsigned short *hash)
  305. {
  306. if (dmi->dmi_addrlen == ETH_ALEN && dmi->dmi_addr[0] & 0x01) {
  307. int idx, bit;
  308. u32 crc;
  309. crc = ether_crc_le(ETH_ALEN, dmi->dmi_addr);
  310. idx = crc >> 30;
  311. bit = (crc >> 26) & 15;
  312. hash[idx] |= 1 << bit;
  313. }
  314. }
  315. /*
  316. * Set or clear promiscuous/multicast mode filter for this adapter.
  317. */
  318. static void am79c961_setmulticastlist (struct net_device *dev)
  319. {
  320. struct dev_priv *priv = netdev_priv(dev);
  321. unsigned long flags;
  322. unsigned short multi_hash[4], mode;
  323. int i, stopped;
  324. mode = MODE_PORT_10BT;
  325. if (dev->flags & IFF_PROMISC) {
  326. mode |= MODE_PROMISC;
  327. } else if (dev->flags & IFF_ALLMULTI) {
  328. memset(multi_hash, 0xff, sizeof(multi_hash));
  329. } else {
  330. struct dev_mc_list *dmi;
  331. memset(multi_hash, 0x00, sizeof(multi_hash));
  332. for (dmi = dev->mc_list; dmi; dmi = dmi->next)
  333. am79c961_mc_hash(dmi, multi_hash);
  334. }
  335. spin_lock_irqsave(priv->chip_lock, flags);
  336. stopped = read_rreg(dev->base_addr, CSR0) & CSR0_STOP;
  337. if (!stopped) {
  338. /*
  339. * Put the chip into suspend mode
  340. */
  341. write_rreg(dev->base_addr, CTRL1, CTRL1_SPND);
  342. /*
  343. * Spin waiting for chip to report suspend mode
  344. */
  345. while ((read_rreg(dev->base_addr, CTRL1) & CTRL1_SPND) == 0) {
  346. spin_unlock_irqrestore(priv->chip_lock, flags);
  347. nop();
  348. spin_lock_irqsave(priv->chip_lock, flags);
  349. }
  350. }
  351. /*
  352. * Update the multicast hash table
  353. */
  354. for (i = 0; i < sizeof(multi_hash) / sizeof(multi_hash[0]); i++)
  355. write_rreg(dev->base_addr, i + LADRL, multi_hash[i]);
  356. /*
  357. * Write the mode register
  358. */
  359. write_rreg(dev->base_addr, MODE, mode);
  360. if (!stopped) {
  361. /*
  362. * Put the chip back into running mode
  363. */
  364. write_rreg(dev->base_addr, CTRL1, 0);
  365. }
  366. spin_unlock_irqrestore(priv->chip_lock, flags);
  367. }
  368. static void am79c961_timeout(struct net_device *dev)
  369. {
  370. printk(KERN_WARNING "%s: transmit timed out, network cable problem?\n",
  371. dev->name);
  372. /*
  373. * ought to do some setup of the tx side here
  374. */
  375. netif_wake_queue(dev);
  376. }
  377. /*
  378. * Transmit a packet
  379. */
  380. static int
  381. am79c961_sendpacket(struct sk_buff *skb, struct net_device *dev)
  382. {
  383. struct dev_priv *priv = netdev_priv(dev);
  384. unsigned int hdraddr, bufaddr;
  385. unsigned int head;
  386. unsigned long flags;
  387. head = priv->txhead;
  388. hdraddr = priv->txhdr + (head << 3);
  389. bufaddr = priv->txbuffer[head];
  390. head += 1;
  391. if (head >= TX_BUFFERS)
  392. head = 0;
  393. am_writebuffer (dev, bufaddr, skb->data, skb->len);
  394. am_writeword (dev, hdraddr + 4, -skb->len);
  395. am_writeword (dev, hdraddr + 2, TMD_OWN|TMD_STP|TMD_ENP);
  396. priv->txhead = head;
  397. spin_lock_irqsave(priv->chip_lock, flags);
  398. write_rreg (dev->base_addr, CSR0, CSR0_TDMD|CSR0_IENA);
  399. dev->trans_start = jiffies;
  400. spin_unlock_irqrestore(priv->chip_lock, flags);
  401. /*
  402. * If the next packet is owned by the ethernet device,
  403. * then the tx ring is full and we can't add another
  404. * packet.
  405. */
  406. if (am_readword(dev, priv->txhdr + (priv->txhead << 3) + 2) & TMD_OWN)
  407. netif_stop_queue(dev);
  408. dev_kfree_skb(skb);
  409. return 0;
  410. }
  411. /*
  412. * If we have a good packet(s), get it/them out of the buffers.
  413. */
  414. static void
  415. am79c961_rx(struct net_device *dev, struct dev_priv *priv)
  416. {
  417. do {
  418. struct sk_buff *skb;
  419. u_int hdraddr;
  420. u_int pktaddr;
  421. u_int status;
  422. int len;
  423. hdraddr = priv->rxhdr + (priv->rxtail << 3);
  424. pktaddr = priv->rxbuffer[priv->rxtail];
  425. status = am_readword (dev, hdraddr + 2);
  426. if (status & RMD_OWN) /* do we own it? */
  427. break;
  428. priv->rxtail ++;
  429. if (priv->rxtail >= RX_BUFFERS)
  430. priv->rxtail = 0;
  431. if ((status & (RMD_ERR|RMD_STP|RMD_ENP)) != (RMD_STP|RMD_ENP)) {
  432. am_writeword (dev, hdraddr + 2, RMD_OWN);
  433. priv->stats.rx_errors ++;
  434. if (status & RMD_ERR) {
  435. if (status & RMD_FRAM)
  436. priv->stats.rx_frame_errors ++;
  437. if (status & RMD_CRC)
  438. priv->stats.rx_crc_errors ++;
  439. } else if (status & RMD_STP)
  440. priv->stats.rx_length_errors ++;
  441. continue;
  442. }
  443. len = am_readword(dev, hdraddr + 6);
  444. skb = dev_alloc_skb(len + 2);
  445. if (skb) {
  446. skb->dev = dev;
  447. skb_reserve(skb, 2);
  448. am_readbuffer(dev, pktaddr, skb_put(skb, len), len);
  449. am_writeword(dev, hdraddr + 2, RMD_OWN);
  450. skb->protocol = eth_type_trans(skb, dev);
  451. netif_rx(skb);
  452. dev->last_rx = jiffies;
  453. priv->stats.rx_bytes += len;
  454. priv->stats.rx_packets ++;
  455. } else {
  456. am_writeword (dev, hdraddr + 2, RMD_OWN);
  457. printk (KERN_WARNING "%s: memory squeeze, dropping packet.\n", dev->name);
  458. priv->stats.rx_dropped ++;
  459. break;
  460. }
  461. } while (1);
  462. }
  463. /*
  464. * Update stats for the transmitted packet
  465. */
  466. static void
  467. am79c961_tx(struct net_device *dev, struct dev_priv *priv)
  468. {
  469. do {
  470. short len;
  471. u_int hdraddr;
  472. u_int status;
  473. hdraddr = priv->txhdr + (priv->txtail << 3);
  474. status = am_readword (dev, hdraddr + 2);
  475. if (status & TMD_OWN)
  476. break;
  477. priv->txtail ++;
  478. if (priv->txtail >= TX_BUFFERS)
  479. priv->txtail = 0;
  480. if (status & TMD_ERR) {
  481. u_int status2;
  482. priv->stats.tx_errors ++;
  483. status2 = am_readword (dev, hdraddr + 6);
  484. /*
  485. * Clear the error byte
  486. */
  487. am_writeword (dev, hdraddr + 6, 0);
  488. if (status2 & TST_RTRY)
  489. priv->stats.collisions += 16;
  490. if (status2 & TST_LCOL)
  491. priv->stats.tx_window_errors ++;
  492. if (status2 & TST_LCAR)
  493. priv->stats.tx_carrier_errors ++;
  494. if (status2 & TST_UFLO)
  495. priv->stats.tx_fifo_errors ++;
  496. continue;
  497. }
  498. priv->stats.tx_packets ++;
  499. len = am_readword (dev, hdraddr + 4);
  500. priv->stats.tx_bytes += -len;
  501. } while (priv->txtail != priv->txhead);
  502. netif_wake_queue(dev);
  503. }
  504. static irqreturn_t
  505. am79c961_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  506. {
  507. struct net_device *dev = (struct net_device *)dev_id;
  508. struct dev_priv *priv = netdev_priv(dev);
  509. u_int status, n = 100;
  510. int handled = 0;
  511. do {
  512. status = read_rreg(dev->base_addr, CSR0);
  513. write_rreg(dev->base_addr, CSR0, status &
  514. (CSR0_IENA|CSR0_TINT|CSR0_RINT|
  515. CSR0_MERR|CSR0_MISS|CSR0_CERR|CSR0_BABL));
  516. if (status & CSR0_RINT) {
  517. handled = 1;
  518. am79c961_rx(dev, priv);
  519. }
  520. if (status & CSR0_TINT) {
  521. handled = 1;
  522. am79c961_tx(dev, priv);
  523. }
  524. if (status & CSR0_MISS) {
  525. handled = 1;
  526. priv->stats.rx_dropped ++;
  527. }
  528. if (status & CSR0_CERR) {
  529. handled = 1;
  530. mod_timer(&priv->timer, jiffies);
  531. }
  532. } while (--n && status & (CSR0_RINT | CSR0_TINT));
  533. return IRQ_RETVAL(handled);
  534. }
  535. #ifdef CONFIG_NET_POLL_CONTROLLER
  536. static void am79c961_poll_controller(struct net_device *dev)
  537. {
  538. unsigned long flags;
  539. local_irq_save(flags);
  540. am79c961_interrupt(dev->irq, dev, NULL);
  541. local_irq_restore(flags);
  542. }
  543. #endif
  544. /*
  545. * Initialise the chip. Note that we always expect
  546. * to be entered with interrupts enabled.
  547. */
  548. static int
  549. am79c961_hw_init(struct net_device *dev)
  550. {
  551. struct dev_priv *priv = netdev_priv(dev);
  552. spin_lock_irq(&priv->chip_lock);
  553. write_rreg (dev->base_addr, CSR0, CSR0_STOP);
  554. write_rreg (dev->base_addr, CSR3, CSR3_MASKALL);
  555. spin_unlock_irq(&priv->chip_lock);
  556. am79c961_ramtest(dev, 0x66);
  557. am79c961_ramtest(dev, 0x99);
  558. return 0;
  559. }
  560. static void __init am79c961_banner(void)
  561. {
  562. static unsigned version_printed;
  563. if (net_debug && version_printed++ == 0)
  564. printk(KERN_INFO "%s", version);
  565. }
  566. static int __init am79c961_init(void)
  567. {
  568. struct net_device *dev;
  569. struct dev_priv *priv;
  570. int i, ret;
  571. dev = alloc_etherdev(sizeof(struct dev_priv));
  572. ret = -ENOMEM;
  573. if (!dev)
  574. goto out;
  575. priv = netdev_priv(dev);
  576. /*
  577. * Fixed address and IRQ lines here.
  578. * The PNP initialisation should have been
  579. * done by the ether bootp loader.
  580. */
  581. dev->base_addr = 0x220;
  582. dev->irq = IRQ_EBSA110_ETHERNET;
  583. ret = -ENODEV;
  584. if (!request_region(dev->base_addr, 0x18, dev->name))
  585. goto nodev;
  586. /*
  587. * Reset the device.
  588. */
  589. inb(dev->base_addr + NET_RESET);
  590. udelay(5);
  591. /*
  592. * Check the manufacturer part of the
  593. * ether address.
  594. */
  595. if (inb(dev->base_addr) != 0x08 ||
  596. inb(dev->base_addr + 2) != 0x00 ||
  597. inb(dev->base_addr + 4) != 0x2b)
  598. goto release;
  599. am79c961_banner();
  600. for (i = 0; i < 6; i++)
  601. dev->dev_addr[i] = inb(dev->base_addr + i * 2) & 0xff;
  602. spin_lock_init(&priv->chip_lock);
  603. init_timer(&priv->timer);
  604. priv->timer.data = (unsigned long)dev;
  605. priv->timer.function = am79c961_timer;
  606. if (am79c961_hw_init(dev))
  607. goto release;
  608. dev->open = am79c961_open;
  609. dev->stop = am79c961_close;
  610. dev->hard_start_xmit = am79c961_sendpacket;
  611. dev->get_stats = am79c961_getstats;
  612. dev->set_multicast_list = am79c961_setmulticastlist;
  613. dev->tx_timeout = am79c961_timeout;
  614. #ifdef CONFIG_NET_POLL_CONTROLLER
  615. dev->poll_controller = am79c961_poll_controller;
  616. #endif
  617. ret = register_netdev(dev);
  618. if (ret == 0) {
  619. printk(KERN_INFO "%s: ether address ", dev->name);
  620. for (i = 0; i < 6; i++)
  621. printk (i == 5 ? "%02x\n" : "%02x:", dev->dev_addr[i]);
  622. return 0;
  623. }
  624. release:
  625. release_region(dev->base_addr, 0x18);
  626. nodev:
  627. free_netdev(dev);
  628. out:
  629. return ret;
  630. }
  631. __initcall(am79c961_init);