am79c961a.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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/fcntl.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/ioport.h>
  21. #include <linux/in.h>
  22. #include <linux/slab.h>
  23. #include <linux/string.h>
  24. #include <linux/errno.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/skbuff.h>
  28. #include <linux/delay.h>
  29. #include <linux/init.h>
  30. #include <linux/crc32.h>
  31. #include <linux/bitops.h>
  32. #include <asm/system.h>
  33. #include <asm/irq.h>
  34. #include <asm/io.h>
  35. #include <asm/dma.h>
  36. #define TX_BUFFERS 15
  37. #define RX_BUFFERS 25
  38. #include "am79c961a.h"
  39. static irqreturn_t
  40. am79c961_interrupt (int irq, void *dev_id, struct pt_regs *regs);
  41. static unsigned int net_debug = NET_DEBUG;
  42. static const char version[] =
  43. "am79c961 ethernet driver (C) 1995-2001 Russell King v0.04\n";
  44. /* --------------------------------------------------------------------------- */
  45. #ifdef __arm__
  46. static void write_rreg(u_long base, u_int reg, u_int val)
  47. {
  48. __asm__(
  49. "str%?h %1, [%2] @ NET_RAP\n\t"
  50. "str%?h %0, [%2, #-4] @ NET_RDP"
  51. :
  52. : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464));
  53. }
  54. static inline unsigned short read_rreg(u_long base_addr, u_int reg)
  55. {
  56. unsigned short v;
  57. __asm__(
  58. "str%?h %1, [%2] @ NET_RAP\n\t"
  59. "ldr%?h %0, [%2, #-4] @ NET_RDP"
  60. : "=r" (v)
  61. : "r" (reg), "r" (ISAIO_BASE + 0x0464));
  62. return v;
  63. }
  64. static inline void write_ireg(u_long base, u_int reg, u_int val)
  65. {
  66. __asm__(
  67. "str%?h %1, [%2] @ NET_RAP\n\t"
  68. "str%?h %0, [%2, #8] @ NET_IDP"
  69. :
  70. : "r" (val), "r" (reg), "r" (ISAIO_BASE + 0x0464));
  71. }
  72. static inline unsigned short read_ireg(u_long base_addr, u_int reg)
  73. {
  74. u_short v;
  75. __asm__(
  76. "str%?h %1, [%2] @ NAT_RAP\n\t"
  77. "str%?h %0, [%2, #8] @ NET_IDP\n\t"
  78. : "=r" (v)
  79. : "r" (reg), "r" (ISAIO_BASE + 0x0464));
  80. return v;
  81. }
  82. #define am_writeword(dev,off,val) __raw_writew(val, ISAMEM_BASE + ((off) << 1))
  83. #define am_readword(dev,off) __raw_readw(ISAMEM_BASE + ((off) << 1))
  84. static inline void
  85. am_writebuffer(struct net_device *dev, u_int offset, unsigned char *buf, unsigned int length)
  86. {
  87. offset = ISAMEM_BASE + (offset << 1);
  88. length = (length + 1) & ~1;
  89. if ((int)buf & 2) {
  90. __asm__ __volatile__("str%?h %2, [%0], #4"
  91. : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8)));
  92. buf += 2;
  93. length -= 2;
  94. }
  95. while (length > 8) {
  96. unsigned int tmp, tmp2;
  97. __asm__ __volatile__(
  98. "ldm%?ia %1!, {%2, %3}\n\t"
  99. "str%?h %2, [%0], #4\n\t"
  100. "mov%? %2, %2, lsr #16\n\t"
  101. "str%?h %2, [%0], #4\n\t"
  102. "str%?h %3, [%0], #4\n\t"
  103. "mov%? %3, %3, lsr #16\n\t"
  104. "str%?h %3, [%0], #4"
  105. : "=&r" (offset), "=&r" (buf), "=r" (tmp), "=r" (tmp2)
  106. : "0" (offset), "1" (buf));
  107. length -= 8;
  108. }
  109. while (length > 0) {
  110. __asm__ __volatile__("str%?h %2, [%0], #4"
  111. : "=&r" (offset) : "0" (offset), "r" (buf[0] | (buf[1] << 8)));
  112. buf += 2;
  113. length -= 2;
  114. }
  115. }
  116. static inline void
  117. am_readbuffer(struct net_device *dev, u_int offset, unsigned char *buf, unsigned int length)
  118. {
  119. offset = ISAMEM_BASE + (offset << 1);
  120. length = (length + 1) & ~1;
  121. if ((int)buf & 2) {
  122. unsigned int tmp;
  123. __asm__ __volatile__(
  124. "ldr%?h %2, [%0], #4\n\t"
  125. "str%?b %2, [%1], #1\n\t"
  126. "mov%? %2, %2, lsr #8\n\t"
  127. "str%?b %2, [%1], #1"
  128. : "=&r" (offset), "=&r" (buf), "=r" (tmp): "0" (offset), "1" (buf));
  129. length -= 2;
  130. }
  131. while (length > 8) {
  132. unsigned int tmp, tmp2, tmp3;
  133. __asm__ __volatile__(
  134. "ldr%?h %2, [%0], #4\n\t"
  135. "ldr%?h %3, [%0], #4\n\t"
  136. "orr%? %2, %2, %3, lsl #16\n\t"
  137. "ldr%?h %3, [%0], #4\n\t"
  138. "ldr%?h %4, [%0], #4\n\t"
  139. "orr%? %3, %3, %4, lsl #16\n\t"
  140. "stm%?ia %1!, {%2, %3}"
  141. : "=&r" (offset), "=&r" (buf), "=r" (tmp), "=r" (tmp2), "=r" (tmp3)
  142. : "0" (offset), "1" (buf));
  143. length -= 8;
  144. }
  145. while (length > 0) {
  146. unsigned int tmp;
  147. __asm__ __volatile__(
  148. "ldr%?h %2, [%0], #4\n\t"
  149. "str%?b %2, [%1], #1\n\t"
  150. "mov%? %2, %2, lsr #8\n\t"
  151. "str%?b %2, [%1], #1"
  152. : "=&r" (offset), "=&r" (buf), "=r" (tmp) : "0" (offset), "1" (buf));
  153. length -= 2;
  154. }
  155. }
  156. #else
  157. #error Not compatible
  158. #endif
  159. static int
  160. am79c961_ramtest(struct net_device *dev, unsigned int val)
  161. {
  162. unsigned char *buffer = kmalloc (65536, GFP_KERNEL);
  163. int i, error = 0, errorcount = 0;
  164. if (!buffer)
  165. return 0;
  166. memset (buffer, val, 65536);
  167. am_writebuffer(dev, 0, buffer, 65536);
  168. memset (buffer, val ^ 255, 65536);
  169. am_readbuffer(dev, 0, buffer, 65536);
  170. for (i = 0; i < 65536; i++) {
  171. if (buffer[i] != val && !error) {
  172. printk ("%s: buffer error (%02X %02X) %05X - ", dev->name, val, buffer[i], i);
  173. error = 1;
  174. errorcount ++;
  175. } else if (error && buffer[i] == val) {
  176. printk ("%05X\n", i);
  177. error = 0;
  178. }
  179. }
  180. if (error)
  181. printk ("10000\n");
  182. kfree (buffer);
  183. return errorcount;
  184. }
  185. static void
  186. am79c961_init_for_open(struct net_device *dev)
  187. {
  188. struct dev_priv *priv = netdev_priv(dev);
  189. unsigned long flags;
  190. unsigned char *p;
  191. u_int hdr_addr, first_free_addr;
  192. int i;
  193. /*
  194. * Stop the chip.
  195. */
  196. spin_lock_irqsave(priv->chip_lock, flags);
  197. write_rreg (dev->base_addr, CSR0, CSR0_BABL|CSR0_CERR|CSR0_MISS|CSR0_MERR|CSR0_TINT|CSR0_RINT|CSR0_STOP);
  198. spin_unlock_irqrestore(priv->chip_lock, flags);
  199. write_ireg (dev->base_addr, 5, 0x00a0); /* Receive address LED */
  200. write_ireg (dev->base_addr, 6, 0x0081); /* Collision LED */
  201. write_ireg (dev->base_addr, 7, 0x0090); /* XMIT LED */
  202. write_ireg (dev->base_addr, 2, 0x0000); /* MODE register selects media */
  203. for (i = LADRL; i <= LADRH; i++)
  204. write_rreg (dev->base_addr, i, 0);
  205. for (i = PADRL, p = dev->dev_addr; i <= PADRH; i++, p += 2)
  206. write_rreg (dev->base_addr, i, p[0] | (p[1] << 8));
  207. i = MODE_PORT_10BT;
  208. if (dev->flags & IFF_PROMISC)
  209. i |= MODE_PROMISC;
  210. write_rreg (dev->base_addr, MODE, i);
  211. write_rreg (dev->base_addr, POLLINT, 0);
  212. write_rreg (dev->base_addr, SIZERXR, -RX_BUFFERS);
  213. write_rreg (dev->base_addr, SIZETXR, -TX_BUFFERS);
  214. first_free_addr = RX_BUFFERS * 8 + TX_BUFFERS * 8 + 16;
  215. hdr_addr = 0;
  216. priv->rxhead = 0;
  217. priv->rxtail = 0;
  218. priv->rxhdr = hdr_addr;
  219. for (i = 0; i < RX_BUFFERS; i++) {
  220. priv->rxbuffer[i] = first_free_addr;
  221. am_writeword (dev, hdr_addr, first_free_addr);
  222. am_writeword (dev, hdr_addr + 2, RMD_OWN);
  223. am_writeword (dev, hdr_addr + 4, (-1600));
  224. am_writeword (dev, hdr_addr + 6, 0);
  225. first_free_addr += 1600;
  226. hdr_addr += 8;
  227. }
  228. priv->txhead = 0;
  229. priv->txtail = 0;
  230. priv->txhdr = hdr_addr;
  231. for (i = 0; i < TX_BUFFERS; i++) {
  232. priv->txbuffer[i] = first_free_addr;
  233. am_writeword (dev, hdr_addr, first_free_addr);
  234. am_writeword (dev, hdr_addr + 2, TMD_STP|TMD_ENP);
  235. am_writeword (dev, hdr_addr + 4, 0xf000);
  236. am_writeword (dev, hdr_addr + 6, 0);
  237. first_free_addr += 1600;
  238. hdr_addr += 8;
  239. }
  240. write_rreg (dev->base_addr, BASERXL, priv->rxhdr);
  241. write_rreg (dev->base_addr, BASERXH, 0);
  242. write_rreg (dev->base_addr, BASETXL, priv->txhdr);
  243. write_rreg (dev->base_addr, BASERXH, 0);
  244. write_rreg (dev->base_addr, CSR0, CSR0_STOP);
  245. write_rreg (dev->base_addr, CSR3, CSR3_IDONM|CSR3_BABLM|CSR3_DXSUFLO);
  246. write_rreg (dev->base_addr, CSR4, CSR4_APAD_XMIT|CSR4_MFCOM|CSR4_RCVCCOM|CSR4_TXSTRTM|CSR4_JABM);
  247. write_rreg (dev->base_addr, CSR0, CSR0_IENA|CSR0_STRT);
  248. }
  249. static void am79c961_timer(unsigned long data)
  250. {
  251. struct net_device *dev = (struct net_device *)data;
  252. struct dev_priv *priv = netdev_priv(dev);
  253. unsigned int lnkstat, carrier;
  254. lnkstat = read_ireg(dev->base_addr, ISALED0) & ISALED0_LNKST;
  255. carrier = netif_carrier_ok(dev);
  256. if (lnkstat && !carrier)
  257. netif_carrier_on(dev);
  258. else if (!lnkstat && carrier)
  259. netif_carrier_off(dev);
  260. mod_timer(&priv->timer, jiffies + 5*HZ);
  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 < sizeof(multi_hash) / sizeof(multi_hash[0]); 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->dev = dev;
  450. skb_reserve(skb, 2);
  451. am_readbuffer(dev, pktaddr, skb_put(skb, len), len);
  452. am_writeword(dev, hdraddr + 2, RMD_OWN);
  453. skb->protocol = eth_type_trans(skb, dev);
  454. netif_rx(skb);
  455. dev->last_rx = jiffies;
  456. priv->stats.rx_bytes += len;
  457. priv->stats.rx_packets ++;
  458. } else {
  459. am_writeword (dev, hdraddr + 2, RMD_OWN);
  460. printk (KERN_WARNING "%s: memory squeeze, dropping packet.\n", dev->name);
  461. priv->stats.rx_dropped ++;
  462. break;
  463. }
  464. } while (1);
  465. }
  466. /*
  467. * Update stats for the transmitted packet
  468. */
  469. static void
  470. am79c961_tx(struct net_device *dev, struct dev_priv *priv)
  471. {
  472. do {
  473. short len;
  474. u_int hdraddr;
  475. u_int status;
  476. hdraddr = priv->txhdr + (priv->txtail << 3);
  477. status = am_readword (dev, hdraddr + 2);
  478. if (status & TMD_OWN)
  479. break;
  480. priv->txtail ++;
  481. if (priv->txtail >= TX_BUFFERS)
  482. priv->txtail = 0;
  483. if (status & TMD_ERR) {
  484. u_int status2;
  485. priv->stats.tx_errors ++;
  486. status2 = am_readword (dev, hdraddr + 6);
  487. /*
  488. * Clear the error byte
  489. */
  490. am_writeword (dev, hdraddr + 6, 0);
  491. if (status2 & TST_RTRY)
  492. priv->stats.collisions += 16;
  493. if (status2 & TST_LCOL)
  494. priv->stats.tx_window_errors ++;
  495. if (status2 & TST_LCAR)
  496. priv->stats.tx_carrier_errors ++;
  497. if (status2 & TST_UFLO)
  498. priv->stats.tx_fifo_errors ++;
  499. continue;
  500. }
  501. priv->stats.tx_packets ++;
  502. len = am_readword (dev, hdraddr + 4);
  503. priv->stats.tx_bytes += -len;
  504. } while (priv->txtail != priv->txhead);
  505. netif_wake_queue(dev);
  506. }
  507. static irqreturn_t
  508. am79c961_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  509. {
  510. struct net_device *dev = (struct net_device *)dev_id;
  511. struct dev_priv *priv = netdev_priv(dev);
  512. u_int status, n = 100;
  513. int handled = 0;
  514. do {
  515. status = read_rreg(dev->base_addr, CSR0);
  516. write_rreg(dev->base_addr, CSR0, status &
  517. (CSR0_IENA|CSR0_TINT|CSR0_RINT|
  518. CSR0_MERR|CSR0_MISS|CSR0_CERR|CSR0_BABL));
  519. if (status & CSR0_RINT) {
  520. handled = 1;
  521. am79c961_rx(dev, priv);
  522. }
  523. if (status & CSR0_TINT) {
  524. handled = 1;
  525. am79c961_tx(dev, priv);
  526. }
  527. if (status & CSR0_MISS) {
  528. handled = 1;
  529. priv->stats.rx_dropped ++;
  530. }
  531. if (status & CSR0_CERR) {
  532. handled = 1;
  533. mod_timer(&priv->timer, jiffies);
  534. }
  535. } while (--n && status & (CSR0_RINT | CSR0_TINT));
  536. return IRQ_RETVAL(handled);
  537. }
  538. #ifdef CONFIG_NET_POLL_CONTROLLER
  539. static void am79c961_poll_controller(struct net_device *dev)
  540. {
  541. unsigned long flags;
  542. local_irq_save(flags);
  543. am79c961_interrupt(dev->irq, dev, NULL);
  544. local_irq_restore(flags);
  545. }
  546. #endif
  547. /*
  548. * Initialise the chip. Note that we always expect
  549. * to be entered with interrupts enabled.
  550. */
  551. static int
  552. am79c961_hw_init(struct net_device *dev)
  553. {
  554. struct dev_priv *priv = netdev_priv(dev);
  555. spin_lock_irq(&priv->chip_lock);
  556. write_rreg (dev->base_addr, CSR0, CSR0_STOP);
  557. write_rreg (dev->base_addr, CSR3, CSR3_MASKALL);
  558. spin_unlock_irq(&priv->chip_lock);
  559. am79c961_ramtest(dev, 0x66);
  560. am79c961_ramtest(dev, 0x99);
  561. return 0;
  562. }
  563. static void __init am79c961_banner(void)
  564. {
  565. static unsigned version_printed;
  566. if (net_debug && version_printed++ == 0)
  567. printk(KERN_INFO "%s", version);
  568. }
  569. static int __init am79c961_init(void)
  570. {
  571. struct net_device *dev;
  572. struct dev_priv *priv;
  573. int i, ret;
  574. dev = alloc_etherdev(sizeof(struct dev_priv));
  575. ret = -ENOMEM;
  576. if (!dev)
  577. goto out;
  578. priv = netdev_priv(dev);
  579. /*
  580. * Fixed address and IRQ lines here.
  581. * The PNP initialisation should have been
  582. * done by the ether bootp loader.
  583. */
  584. dev->base_addr = 0x220;
  585. dev->irq = IRQ_EBSA110_ETHERNET;
  586. ret = -ENODEV;
  587. if (!request_region(dev->base_addr, 0x18, dev->name))
  588. goto nodev;
  589. /*
  590. * Reset the device.
  591. */
  592. inb(dev->base_addr + NET_RESET);
  593. udelay(5);
  594. /*
  595. * Check the manufacturer part of the
  596. * ether address.
  597. */
  598. if (inb(dev->base_addr) != 0x08 ||
  599. inb(dev->base_addr + 2) != 0x00 ||
  600. inb(dev->base_addr + 4) != 0x2b)
  601. goto release;
  602. am79c961_banner();
  603. printk(KERN_INFO "%s: ether address ", dev->name);
  604. /* Retrive and print the ethernet address. */
  605. for (i = 0; i < 6; i++) {
  606. dev->dev_addr[i] = inb(dev->base_addr + i * 2) & 0xff;
  607. printk (i == 5 ? "%02x\n" : "%02x:", dev->dev_addr[i]);
  608. }
  609. spin_lock_init(&priv->chip_lock);
  610. init_timer(&priv->timer);
  611. priv->timer.data = (unsigned long)dev;
  612. priv->timer.function = am79c961_timer;
  613. if (am79c961_hw_init(dev))
  614. goto release;
  615. dev->open = am79c961_open;
  616. dev->stop = am79c961_close;
  617. dev->hard_start_xmit = am79c961_sendpacket;
  618. dev->get_stats = am79c961_getstats;
  619. dev->set_multicast_list = am79c961_setmulticastlist;
  620. dev->tx_timeout = am79c961_timeout;
  621. #ifdef CONFIG_NET_POLL_CONTROLLER
  622. dev->poll_controller = am79c961_poll_controller;
  623. #endif
  624. ret = register_netdev(dev);
  625. if (ret == 0)
  626. return 0;
  627. release:
  628. release_region(dev->base_addr, 0x18);
  629. nodev:
  630. free_netdev(dev);
  631. out:
  632. return ret;
  633. }
  634. __initcall(am79c961_init);