am79c961a.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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 <asm/hardware.h>
  31. #include <asm/io.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 < 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)
  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_probe(struct platform_device *pdev)
  570. {
  571. struct resource *res;
  572. struct net_device *dev;
  573. struct dev_priv *priv;
  574. int i, ret;
  575. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  576. if (!res)
  577. return -ENODEV;
  578. dev = alloc_etherdev(sizeof(struct dev_priv));
  579. ret = -ENOMEM;
  580. if (!dev)
  581. goto out;
  582. SET_NETDEV_DEV(dev, &pdev->dev);
  583. priv = netdev_priv(dev);
  584. /*
  585. * Fixed address and IRQ lines here.
  586. * The PNP initialisation should have been
  587. * done by the ether bootp loader.
  588. */
  589. dev->base_addr = res->start;
  590. dev->irq = platform_get_irq(pdev, 0);
  591. ret = -ENODEV;
  592. if (dev->irq < 0)
  593. goto nodev;
  594. if (!request_region(dev->base_addr, 0x18, dev->name))
  595. goto nodev;
  596. /*
  597. * Reset the device.
  598. */
  599. inb(dev->base_addr + NET_RESET);
  600. udelay(5);
  601. /*
  602. * Check the manufacturer part of the
  603. * ether address.
  604. */
  605. if (inb(dev->base_addr) != 0x08 ||
  606. inb(dev->base_addr + 2) != 0x00 ||
  607. inb(dev->base_addr + 4) != 0x2b)
  608. goto release;
  609. for (i = 0; i < 6; i++)
  610. dev->dev_addr[i] = inb(dev->base_addr + i * 2) & 0xff;
  611. am79c961_banner();
  612. spin_lock_init(&priv->chip_lock);
  613. init_timer(&priv->timer);
  614. priv->timer.data = (unsigned long)dev;
  615. priv->timer.function = am79c961_timer;
  616. if (am79c961_hw_init(dev))
  617. goto release;
  618. dev->open = am79c961_open;
  619. dev->stop = am79c961_close;
  620. dev->hard_start_xmit = am79c961_sendpacket;
  621. dev->get_stats = am79c961_getstats;
  622. dev->set_multicast_list = am79c961_setmulticastlist;
  623. dev->tx_timeout = am79c961_timeout;
  624. #ifdef CONFIG_NET_POLL_CONTROLLER
  625. dev->poll_controller = am79c961_poll_controller;
  626. #endif
  627. ret = register_netdev(dev);
  628. if (ret == 0) {
  629. printk(KERN_INFO "%s: ether address ", dev->name);
  630. /* Retrive and print the ethernet address. */
  631. for (i = 0; i < 6; i++)
  632. printk (i == 5 ? "%02x\n" : "%02x:", dev->dev_addr[i]);
  633. return 0;
  634. }
  635. release:
  636. release_region(dev->base_addr, 0x18);
  637. nodev:
  638. free_netdev(dev);
  639. out:
  640. return ret;
  641. }
  642. static struct platform_driver am79c961_driver = {
  643. .probe = am79c961_probe,
  644. .driver = {
  645. .name = "am79c961",
  646. },
  647. };
  648. static int __init am79c961_init(void)
  649. {
  650. return platform_driver_register(&am79c961_driver);
  651. }
  652. __initcall(am79c961_init);