ariadne.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /*
  2. * Amiga Linux/m68k Ariadne Ethernet Driver
  3. *
  4. * © Copyright 1995-2003 by Geert Uytterhoeven (geert@linux-m68k.org)
  5. * Peter De Schrijver (p2@mind.be)
  6. *
  7. * ---------------------------------------------------------------------------
  8. *
  9. * This program is based on
  10. *
  11. * lance.c: An AMD LANCE ethernet driver for linux.
  12. * Written 1993-94 by Donald Becker.
  13. *
  14. * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller
  15. * Advanced Micro Devices
  16. * Publication #16907, Rev. B, Amendment/0, May 1994
  17. *
  18. * MC68230: Parallel Interface/Timer (PI/T)
  19. * Motorola Semiconductors, December, 1983
  20. *
  21. * ---------------------------------------------------------------------------
  22. *
  23. * This file is subject to the terms and conditions of the GNU General Public
  24. * License. See the file COPYING in the main directory of the Linux
  25. * distribution for more details.
  26. *
  27. * ---------------------------------------------------------------------------
  28. *
  29. * The Ariadne is a Zorro-II board made by Village Tronic. It contains:
  30. *
  31. * - an Am79C960 PCnet-ISA Single-Chip Ethernet Controller with both
  32. * 10BASE-2 (thin coax) and 10BASE-T (UTP) connectors
  33. *
  34. * - an MC68230 Parallel Interface/Timer configured as 2 parallel ports
  35. */
  36. #include <linux/module.h>
  37. #include <linux/stddef.h>
  38. #include <linux/kernel.h>
  39. #include <linux/string.h>
  40. #include <linux/errno.h>
  41. #include <linux/ioport.h>
  42. #include <linux/slab.h>
  43. #include <linux/netdevice.h>
  44. #include <linux/etherdevice.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/skbuff.h>
  47. #include <linux/init.h>
  48. #include <linux/zorro.h>
  49. #include <linux/bitops.h>
  50. #include <asm/amigaints.h>
  51. #include <asm/amigahw.h>
  52. #include <asm/irq.h>
  53. #include "ariadne.h"
  54. #ifdef ARIADNE_DEBUG
  55. int ariadne_debug = ARIADNE_DEBUG;
  56. #else
  57. int ariadne_debug = 1;
  58. #endif
  59. /*
  60. * Macros to Fix Endianness problems
  61. */
  62. /* Swap the Bytes in a WORD */
  63. #define swapw(x) (((x>>8)&0x00ff)|((x<<8)&0xff00))
  64. /* Get the Low BYTE in a WORD */
  65. #define lowb(x) (x&0xff)
  66. /* Get the Swapped High WORD in a LONG */
  67. #define swhighw(x) ((((x)>>8)&0xff00)|(((x)>>24)&0x00ff))
  68. /* Get the Swapped Low WORD in a LONG */
  69. #define swloww(x) ((((x)<<8)&0xff00)|(((x)>>8)&0x00ff))
  70. /*
  71. * Transmit/Receive Ring Definitions
  72. */
  73. #define TX_RING_SIZE 5
  74. #define RX_RING_SIZE 16
  75. #define PKT_BUF_SIZE 1520
  76. /*
  77. * Private Device Data
  78. */
  79. struct ariadne_private {
  80. volatile struct TDRE *tx_ring[TX_RING_SIZE];
  81. volatile struct RDRE *rx_ring[RX_RING_SIZE];
  82. volatile u_short *tx_buff[TX_RING_SIZE];
  83. volatile u_short *rx_buff[RX_RING_SIZE];
  84. int cur_tx, cur_rx; /* The next free ring entry */
  85. int dirty_tx; /* The ring entries to be free()ed. */
  86. struct net_device_stats stats;
  87. char tx_full;
  88. };
  89. /*
  90. * Structure Created in the Ariadne's RAM Buffer
  91. */
  92. struct lancedata {
  93. struct TDRE tx_ring[TX_RING_SIZE];
  94. struct RDRE rx_ring[RX_RING_SIZE];
  95. u_short tx_buff[TX_RING_SIZE][PKT_BUF_SIZE/sizeof(u_short)];
  96. u_short rx_buff[RX_RING_SIZE][PKT_BUF_SIZE/sizeof(u_short)];
  97. };
  98. static int ariadne_open(struct net_device *dev);
  99. static void ariadne_init_ring(struct net_device *dev);
  100. static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev);
  101. static void ariadne_tx_timeout(struct net_device *dev);
  102. static int ariadne_rx(struct net_device *dev);
  103. static void ariadne_reset(struct net_device *dev);
  104. static irqreturn_t ariadne_interrupt(int irq, void *data);
  105. static int ariadne_close(struct net_device *dev);
  106. static struct net_device_stats *ariadne_get_stats(struct net_device *dev);
  107. #ifdef HAVE_MULTICAST
  108. static void set_multicast_list(struct net_device *dev);
  109. #endif
  110. static void memcpyw(volatile u_short *dest, u_short *src, int len)
  111. {
  112. while (len >= 2) {
  113. *(dest++) = *(src++);
  114. len -= 2;
  115. }
  116. if (len == 1)
  117. *dest = (*(u_char *)src)<<8;
  118. }
  119. static int __devinit ariadne_init_one(struct zorro_dev *z,
  120. const struct zorro_device_id *ent);
  121. static void __devexit ariadne_remove_one(struct zorro_dev *z);
  122. static struct zorro_device_id ariadne_zorro_tbl[] __devinitdata = {
  123. { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE },
  124. { 0 }
  125. };
  126. static struct zorro_driver ariadne_driver = {
  127. .name = "ariadne",
  128. .id_table = ariadne_zorro_tbl,
  129. .probe = ariadne_init_one,
  130. .remove = __devexit_p(ariadne_remove_one),
  131. };
  132. static int __devinit ariadne_init_one(struct zorro_dev *z,
  133. const struct zorro_device_id *ent)
  134. {
  135. unsigned long board = z->resource.start;
  136. unsigned long base_addr = board+ARIADNE_LANCE;
  137. unsigned long mem_start = board+ARIADNE_RAM;
  138. struct resource *r1, *r2;
  139. struct net_device *dev;
  140. struct ariadne_private *priv;
  141. int err;
  142. DECLARE_MAC_BUF(mac);
  143. r1 = request_mem_region(base_addr, sizeof(struct Am79C960), "Am79C960");
  144. if (!r1)
  145. return -EBUSY;
  146. r2 = request_mem_region(mem_start, ARIADNE_RAM_SIZE, "RAM");
  147. if (!r2) {
  148. release_resource(r1);
  149. return -EBUSY;
  150. }
  151. dev = alloc_etherdev(sizeof(struct ariadne_private));
  152. if (dev == NULL) {
  153. release_resource(r1);
  154. release_resource(r2);
  155. return -ENOMEM;
  156. }
  157. priv = netdev_priv(dev);
  158. r1->name = dev->name;
  159. r2->name = dev->name;
  160. dev->dev_addr[0] = 0x00;
  161. dev->dev_addr[1] = 0x60;
  162. dev->dev_addr[2] = 0x30;
  163. dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
  164. dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
  165. dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
  166. dev->base_addr = ZTWO_VADDR(base_addr);
  167. dev->mem_start = ZTWO_VADDR(mem_start);
  168. dev->mem_end = dev->mem_start+ARIADNE_RAM_SIZE;
  169. dev->open = &ariadne_open;
  170. dev->stop = &ariadne_close;
  171. dev->hard_start_xmit = &ariadne_start_xmit;
  172. dev->tx_timeout = &ariadne_tx_timeout;
  173. dev->watchdog_timeo = 5*HZ;
  174. dev->get_stats = &ariadne_get_stats;
  175. dev->set_multicast_list = &set_multicast_list;
  176. err = register_netdev(dev);
  177. if (err) {
  178. release_resource(r1);
  179. release_resource(r2);
  180. free_netdev(dev);
  181. return err;
  182. }
  183. zorro_set_drvdata(z, dev);
  184. printk(KERN_INFO "%s: Ariadne at 0x%08lx, Ethernet Address "
  185. "%s\n", dev->name, board,
  186. print_mac(mac, dev->dev_addr));
  187. return 0;
  188. }
  189. static int ariadne_open(struct net_device *dev)
  190. {
  191. volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
  192. u_short in;
  193. u_long version;
  194. int i;
  195. /* Reset the LANCE */
  196. in = lance->Reset;
  197. /* Stop the LANCE */
  198. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  199. lance->RDP = STOP;
  200. /* Check the LANCE version */
  201. lance->RAP = CSR88; /* Chip ID */
  202. version = swapw(lance->RDP);
  203. lance->RAP = CSR89; /* Chip ID */
  204. version |= swapw(lance->RDP)<<16;
  205. if ((version & 0x00000fff) != 0x00000003) {
  206. printk(KERN_WARNING "ariadne_open: Couldn't find AMD Ethernet Chip\n");
  207. return -EAGAIN;
  208. }
  209. if ((version & 0x0ffff000) != 0x00003000) {
  210. printk(KERN_WARNING "ariadne_open: Couldn't find Am79C960 (Wrong part "
  211. "number = %ld)\n", (version & 0x0ffff000)>>12);
  212. return -EAGAIN;
  213. }
  214. #if 0
  215. printk(KERN_DEBUG "ariadne_open: Am79C960 (PCnet-ISA) Revision %ld\n",
  216. (version & 0xf0000000)>>28);
  217. #endif
  218. ariadne_init_ring(dev);
  219. /* Miscellaneous Stuff */
  220. lance->RAP = CSR3; /* Interrupt Masks and Deferral Control */
  221. lance->RDP = 0x0000;
  222. lance->RAP = CSR4; /* Test and Features Control */
  223. lance->RDP = DPOLL|APAD_XMT|MFCOM|RCVCCOM|TXSTRTM|JABM;
  224. /* Set the Multicast Table */
  225. lance->RAP = CSR8; /* Logical Address Filter, LADRF[15:0] */
  226. lance->RDP = 0x0000;
  227. lance->RAP = CSR9; /* Logical Address Filter, LADRF[31:16] */
  228. lance->RDP = 0x0000;
  229. lance->RAP = CSR10; /* Logical Address Filter, LADRF[47:32] */
  230. lance->RDP = 0x0000;
  231. lance->RAP = CSR11; /* Logical Address Filter, LADRF[63:48] */
  232. lance->RDP = 0x0000;
  233. /* Set the Ethernet Hardware Address */
  234. lance->RAP = CSR12; /* Physical Address Register, PADR[15:0] */
  235. lance->RDP = ((u_short *)&dev->dev_addr[0])[0];
  236. lance->RAP = CSR13; /* Physical Address Register, PADR[31:16] */
  237. lance->RDP = ((u_short *)&dev->dev_addr[0])[1];
  238. lance->RAP = CSR14; /* Physical Address Register, PADR[47:32] */
  239. lance->RDP = ((u_short *)&dev->dev_addr[0])[2];
  240. /* Set the Init Block Mode */
  241. lance->RAP = CSR15; /* Mode Register */
  242. lance->RDP = 0x0000;
  243. /* Set the Transmit Descriptor Ring Pointer */
  244. lance->RAP = CSR30; /* Base Address of Transmit Ring */
  245. lance->RDP = swloww(ARIADNE_RAM+offsetof(struct lancedata, tx_ring));
  246. lance->RAP = CSR31; /* Base Address of transmit Ring */
  247. lance->RDP = swhighw(ARIADNE_RAM+offsetof(struct lancedata, tx_ring));
  248. /* Set the Receive Descriptor Ring Pointer */
  249. lance->RAP = CSR24; /* Base Address of Receive Ring */
  250. lance->RDP = swloww(ARIADNE_RAM+offsetof(struct lancedata, rx_ring));
  251. lance->RAP = CSR25; /* Base Address of Receive Ring */
  252. lance->RDP = swhighw(ARIADNE_RAM+offsetof(struct lancedata, rx_ring));
  253. /* Set the Number of RX and TX Ring Entries */
  254. lance->RAP = CSR76; /* Receive Ring Length */
  255. lance->RDP = swapw(((u_short)-RX_RING_SIZE));
  256. lance->RAP = CSR78; /* Transmit Ring Length */
  257. lance->RDP = swapw(((u_short)-TX_RING_SIZE));
  258. /* Enable Media Interface Port Auto Select (10BASE-2/10BASE-T) */
  259. lance->RAP = ISACSR2; /* Miscellaneous Configuration */
  260. lance->IDP = ASEL;
  261. /* LED Control */
  262. lance->RAP = ISACSR5; /* LED1 Status */
  263. lance->IDP = PSE|XMTE;
  264. lance->RAP = ISACSR6; /* LED2 Status */
  265. lance->IDP = PSE|COLE;
  266. lance->RAP = ISACSR7; /* LED3 Status */
  267. lance->IDP = PSE|RCVE;
  268. netif_start_queue(dev);
  269. i = request_irq(IRQ_AMIGA_PORTS, ariadne_interrupt, IRQF_SHARED,
  270. dev->name, dev);
  271. if (i) return i;
  272. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  273. lance->RDP = INEA|STRT;
  274. return 0;
  275. }
  276. static void ariadne_init_ring(struct net_device *dev)
  277. {
  278. struct ariadne_private *priv = netdev_priv(dev);
  279. volatile struct lancedata *lancedata = (struct lancedata *)dev->mem_start;
  280. int i;
  281. netif_stop_queue(dev);
  282. priv->tx_full = 0;
  283. priv->cur_rx = priv->cur_tx = 0;
  284. priv->dirty_tx = 0;
  285. /* Set up TX Ring */
  286. for (i = 0; i < TX_RING_SIZE; i++) {
  287. volatile struct TDRE *t = &lancedata->tx_ring[i];
  288. t->TMD0 = swloww(ARIADNE_RAM+offsetof(struct lancedata, tx_buff[i]));
  289. t->TMD1 = swhighw(ARIADNE_RAM+offsetof(struct lancedata, tx_buff[i])) |
  290. TF_STP | TF_ENP;
  291. t->TMD2 = swapw((u_short)-PKT_BUF_SIZE);
  292. t->TMD3 = 0;
  293. priv->tx_ring[i] = &lancedata->tx_ring[i];
  294. priv->tx_buff[i] = lancedata->tx_buff[i];
  295. #if 0
  296. printk(KERN_DEBUG "TX Entry %2d at %p, Buf at %p\n", i,
  297. &lancedata->tx_ring[i], lancedata->tx_buff[i]);
  298. #endif
  299. }
  300. /* Set up RX Ring */
  301. for (i = 0; i < RX_RING_SIZE; i++) {
  302. volatile struct RDRE *r = &lancedata->rx_ring[i];
  303. r->RMD0 = swloww(ARIADNE_RAM+offsetof(struct lancedata, rx_buff[i]));
  304. r->RMD1 = swhighw(ARIADNE_RAM+offsetof(struct lancedata, rx_buff[i])) |
  305. RF_OWN;
  306. r->RMD2 = swapw((u_short)-PKT_BUF_SIZE);
  307. r->RMD3 = 0x0000;
  308. priv->rx_ring[i] = &lancedata->rx_ring[i];
  309. priv->rx_buff[i] = lancedata->rx_buff[i];
  310. #if 0
  311. printk(KERN_DEBUG "RX Entry %2d at %p, Buf at %p\n", i,
  312. &lancedata->rx_ring[i], lancedata->rx_buff[i]);
  313. #endif
  314. }
  315. }
  316. static int ariadne_close(struct net_device *dev)
  317. {
  318. struct ariadne_private *priv = netdev_priv(dev);
  319. volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
  320. netif_stop_queue(dev);
  321. lance->RAP = CSR112; /* Missed Frame Count */
  322. priv->stats.rx_missed_errors = swapw(lance->RDP);
  323. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  324. if (ariadne_debug > 1) {
  325. printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
  326. dev->name, lance->RDP);
  327. printk(KERN_DEBUG "%s: %lu packets missed\n", dev->name,
  328. priv->stats.rx_missed_errors);
  329. }
  330. /* We stop the LANCE here -- it occasionally polls memory if we don't. */
  331. lance->RDP = STOP;
  332. free_irq(IRQ_AMIGA_PORTS, dev);
  333. return 0;
  334. }
  335. static inline void ariadne_reset(struct net_device *dev)
  336. {
  337. volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
  338. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  339. lance->RDP = STOP;
  340. ariadne_init_ring(dev);
  341. lance->RDP = INEA|STRT;
  342. netif_start_queue(dev);
  343. }
  344. static irqreturn_t ariadne_interrupt(int irq, void *data)
  345. {
  346. struct net_device *dev = (struct net_device *)data;
  347. volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
  348. struct ariadne_private *priv;
  349. int csr0, boguscnt;
  350. int handled = 0;
  351. if (dev == NULL) {
  352. printk(KERN_WARNING "ariadne_interrupt(): irq for unknown device.\n");
  353. return IRQ_NONE;
  354. }
  355. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  356. if (!(lance->RDP & INTR)) /* Check if any interrupt has been */
  357. return IRQ_NONE; /* generated by the board. */
  358. priv = netdev_priv(dev);
  359. boguscnt = 10;
  360. while ((csr0 = lance->RDP) & (ERR|RINT|TINT) && --boguscnt >= 0) {
  361. /* Acknowledge all of the current interrupt sources ASAP. */
  362. lance->RDP = csr0 & ~(INEA|TDMD|STOP|STRT|INIT);
  363. #if 0
  364. if (ariadne_debug > 5) {
  365. printk(KERN_DEBUG "%s: interrupt csr0=%#2.2x new csr=%#2.2x.",
  366. dev->name, csr0, lance->RDP);
  367. printk("[");
  368. if (csr0 & INTR)
  369. printk(" INTR");
  370. if (csr0 & INEA)
  371. printk(" INEA");
  372. if (csr0 & RXON)
  373. printk(" RXON");
  374. if (csr0 & TXON)
  375. printk(" TXON");
  376. if (csr0 & TDMD)
  377. printk(" TDMD");
  378. if (csr0 & STOP)
  379. printk(" STOP");
  380. if (csr0 & STRT)
  381. printk(" STRT");
  382. if (csr0 & INIT)
  383. printk(" INIT");
  384. if (csr0 & ERR)
  385. printk(" ERR");
  386. if (csr0 & BABL)
  387. printk(" BABL");
  388. if (csr0 & CERR)
  389. printk(" CERR");
  390. if (csr0 & MISS)
  391. printk(" MISS");
  392. if (csr0 & MERR)
  393. printk(" MERR");
  394. if (csr0 & RINT)
  395. printk(" RINT");
  396. if (csr0 & TINT)
  397. printk(" TINT");
  398. if (csr0 & IDON)
  399. printk(" IDON");
  400. printk(" ]\n");
  401. }
  402. #endif
  403. if (csr0 & RINT) { /* Rx interrupt */
  404. handled = 1;
  405. ariadne_rx(dev);
  406. }
  407. if (csr0 & TINT) { /* Tx-done interrupt */
  408. int dirty_tx = priv->dirty_tx;
  409. handled = 1;
  410. while (dirty_tx < priv->cur_tx) {
  411. int entry = dirty_tx % TX_RING_SIZE;
  412. int status = lowb(priv->tx_ring[entry]->TMD1);
  413. if (status & TF_OWN)
  414. break; /* It still hasn't been Txed */
  415. priv->tx_ring[entry]->TMD1 &= 0xff00;
  416. if (status & TF_ERR) {
  417. /* There was an major error, log it. */
  418. int err_status = priv->tx_ring[entry]->TMD3;
  419. priv->stats.tx_errors++;
  420. if (err_status & EF_RTRY)
  421. priv->stats.tx_aborted_errors++;
  422. if (err_status & EF_LCAR)
  423. priv->stats.tx_carrier_errors++;
  424. if (err_status & EF_LCOL)
  425. priv->stats.tx_window_errors++;
  426. if (err_status & EF_UFLO) {
  427. /* Ackk! On FIFO errors the Tx unit is turned off! */
  428. priv->stats.tx_fifo_errors++;
  429. /* Remove this verbosity later! */
  430. printk(KERN_ERR "%s: Tx FIFO error! Status %4.4x.\n",
  431. dev->name, csr0);
  432. /* Restart the chip. */
  433. lance->RDP = STRT;
  434. }
  435. } else {
  436. if (status & (TF_MORE|TF_ONE))
  437. priv->stats.collisions++;
  438. priv->stats.tx_packets++;
  439. }
  440. dirty_tx++;
  441. }
  442. #ifndef final_version
  443. if (priv->cur_tx - dirty_tx >= TX_RING_SIZE) {
  444. printk(KERN_ERR "out-of-sync dirty pointer, %d vs. %d, "
  445. "full=%d.\n", dirty_tx, priv->cur_tx, priv->tx_full);
  446. dirty_tx += TX_RING_SIZE;
  447. }
  448. #endif
  449. if (priv->tx_full && netif_queue_stopped(dev) &&
  450. dirty_tx > priv->cur_tx - TX_RING_SIZE + 2) {
  451. /* The ring is no longer full. */
  452. priv->tx_full = 0;
  453. netif_wake_queue(dev);
  454. }
  455. priv->dirty_tx = dirty_tx;
  456. }
  457. /* Log misc errors. */
  458. if (csr0 & BABL) {
  459. handled = 1;
  460. priv->stats.tx_errors++; /* Tx babble. */
  461. }
  462. if (csr0 & MISS) {
  463. handled = 1;
  464. priv->stats.rx_errors++; /* Missed a Rx frame. */
  465. }
  466. if (csr0 & MERR) {
  467. handled = 1;
  468. printk(KERN_ERR "%s: Bus master arbitration failure, status "
  469. "%4.4x.\n", dev->name, csr0);
  470. /* Restart the chip. */
  471. lance->RDP = STRT;
  472. }
  473. }
  474. /* Clear any other interrupt, and set interrupt enable. */
  475. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  476. lance->RDP = INEA|BABL|CERR|MISS|MERR|IDON;
  477. #if 0
  478. if (ariadne_debug > 4)
  479. printk(KERN_DEBUG "%s: exiting interrupt, csr%d=%#4.4x.\n", dev->name,
  480. lance->RAP, lance->RDP);
  481. #endif
  482. return IRQ_RETVAL(handled);
  483. }
  484. static void ariadne_tx_timeout(struct net_device *dev)
  485. {
  486. volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
  487. printk(KERN_ERR "%s: transmit timed out, status %4.4x, resetting.\n",
  488. dev->name, lance->RDP);
  489. ariadne_reset(dev);
  490. netif_wake_queue(dev);
  491. }
  492. static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev)
  493. {
  494. struct ariadne_private *priv = netdev_priv(dev);
  495. volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
  496. int entry;
  497. unsigned long flags;
  498. int len = skb->len;
  499. #if 0
  500. if (ariadne_debug > 3) {
  501. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  502. printk(KERN_DEBUG "%s: ariadne_start_xmit() called, csr0 %4.4x.\n",
  503. dev->name, lance->RDP);
  504. lance->RDP = 0x0000;
  505. }
  506. #endif
  507. /* FIXME: is the 79C960 new enough to do its own padding right ? */
  508. if (skb->len < ETH_ZLEN)
  509. {
  510. if (skb_padto(skb, ETH_ZLEN))
  511. return 0;
  512. len = ETH_ZLEN;
  513. }
  514. /* Fill in a Tx ring entry */
  515. #if 0
  516. {
  517. DECLARE_MAC_BUF(mac);
  518. DECLARE_MAC_BUF(mac2);
  519. printk(KERN_DEBUG "TX pkt type 0x%04x from %s to %s "
  520. " data 0x%08x len %d\n",
  521. ((u_short *)skb->data)[6],
  522. print_mac(mac, ((const u8 *)skb->data)+6),
  523. print_mac(mac, (const u8 *)skb->data),
  524. (int)skb->data, (int)skb->len);
  525. }
  526. #endif
  527. local_irq_save(flags);
  528. entry = priv->cur_tx % TX_RING_SIZE;
  529. /* Caution: the write order is important here, set the base address with
  530. the "ownership" bits last. */
  531. priv->tx_ring[entry]->TMD2 = swapw((u_short)-skb->len);
  532. priv->tx_ring[entry]->TMD3 = 0x0000;
  533. memcpyw(priv->tx_buff[entry], (u_short *)skb->data, len);
  534. #if 0
  535. {
  536. int i, len;
  537. len = skb->len > 64 ? 64 : skb->len;
  538. len >>= 1;
  539. for (i = 0; i < len; i += 8) {
  540. int j;
  541. printk(KERN_DEBUG "%04x:", i);
  542. for (j = 0; (j < 8) && ((i+j) < len); j++) {
  543. if (!(j & 1))
  544. printk(" ");
  545. printk("%04x", priv->tx_buff[entry][i+j]);
  546. }
  547. printk("\n");
  548. }
  549. }
  550. #endif
  551. priv->tx_ring[entry]->TMD1 = (priv->tx_ring[entry]->TMD1&0xff00)|TF_OWN|TF_STP|TF_ENP;
  552. dev_kfree_skb(skb);
  553. priv->cur_tx++;
  554. if ((priv->cur_tx >= TX_RING_SIZE) && (priv->dirty_tx >= TX_RING_SIZE)) {
  555. #if 0
  556. printk(KERN_DEBUG "*** Subtracting TX_RING_SIZE from cur_tx (%d) and "
  557. "dirty_tx (%d)\n", priv->cur_tx, priv->dirty_tx);
  558. #endif
  559. priv->cur_tx -= TX_RING_SIZE;
  560. priv->dirty_tx -= TX_RING_SIZE;
  561. }
  562. priv->stats.tx_bytes += len;
  563. /* Trigger an immediate send poll. */
  564. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  565. lance->RDP = INEA|TDMD;
  566. dev->trans_start = jiffies;
  567. if (lowb(priv->tx_ring[(entry+1) % TX_RING_SIZE]->TMD1) != 0) {
  568. netif_stop_queue(dev);
  569. priv->tx_full = 1;
  570. }
  571. local_irq_restore(flags);
  572. return 0;
  573. }
  574. static int ariadne_rx(struct net_device *dev)
  575. {
  576. struct ariadne_private *priv = netdev_priv(dev);
  577. int entry = priv->cur_rx % RX_RING_SIZE;
  578. int i;
  579. /* If we own the next entry, it's a new packet. Send it up. */
  580. while (!(lowb(priv->rx_ring[entry]->RMD1) & RF_OWN)) {
  581. int status = lowb(priv->rx_ring[entry]->RMD1);
  582. if (status != (RF_STP|RF_ENP)) { /* There was an error. */
  583. /* There is a tricky error noted by John Murphy,
  584. <murf@perftech.com> to Russ Nelson: Even with full-sized
  585. buffers it's possible for a jabber packet to use two
  586. buffers, with only the last correctly noting the error. */
  587. if (status & RF_ENP)
  588. /* Only count a general error at the end of a packet.*/
  589. priv->stats.rx_errors++;
  590. if (status & RF_FRAM)
  591. priv->stats.rx_frame_errors++;
  592. if (status & RF_OFLO)
  593. priv->stats.rx_over_errors++;
  594. if (status & RF_CRC)
  595. priv->stats.rx_crc_errors++;
  596. if (status & RF_BUFF)
  597. priv->stats.rx_fifo_errors++;
  598. priv->rx_ring[entry]->RMD1 &= 0xff00|RF_STP|RF_ENP;
  599. } else {
  600. /* Malloc up new buffer, compatible with net-3. */
  601. short pkt_len = swapw(priv->rx_ring[entry]->RMD3);
  602. struct sk_buff *skb;
  603. skb = dev_alloc_skb(pkt_len+2);
  604. if (skb == NULL) {
  605. printk(KERN_WARNING "%s: Memory squeeze, deferring packet.\n",
  606. dev->name);
  607. for (i = 0; i < RX_RING_SIZE; i++)
  608. if (lowb(priv->rx_ring[(entry+i) % RX_RING_SIZE]->RMD1) & RF_OWN)
  609. break;
  610. if (i > RX_RING_SIZE-2) {
  611. priv->stats.rx_dropped++;
  612. priv->rx_ring[entry]->RMD1 |= RF_OWN;
  613. priv->cur_rx++;
  614. }
  615. break;
  616. }
  617. skb_reserve(skb,2); /* 16 byte align */
  618. skb_put(skb,pkt_len); /* Make room */
  619. skb_copy_to_linear_data(skb, (char *)priv->rx_buff[entry], pkt_len);
  620. skb->protocol=eth_type_trans(skb,dev);
  621. #if 0
  622. {
  623. DECLARE_MAC_BUF(mac);
  624. printk(KERN_DEBUG "RX pkt type 0x%04x from ",
  625. ((u_short *)skb->data)[6]);
  626. {
  627. u_char *ptr = &((u_char *)skb->data)[6];
  628. printk("%s", print_mac(mac, ptr));
  629. }
  630. printk(" to ");
  631. {
  632. u_char *ptr = (u_char *)skb->data;
  633. printk("%s", print_mac(mac, ptr));
  634. }
  635. printk(" data 0x%08x len %d\n", (int)skb->data, (int)skb->len);
  636. }
  637. #endif
  638. netif_rx(skb);
  639. dev->last_rx = jiffies;
  640. priv->stats.rx_packets++;
  641. priv->stats.rx_bytes += pkt_len;
  642. }
  643. priv->rx_ring[entry]->RMD1 |= RF_OWN;
  644. entry = (++priv->cur_rx) % RX_RING_SIZE;
  645. }
  646. priv->cur_rx = priv->cur_rx % RX_RING_SIZE;
  647. /* We should check that at least two ring entries are free. If not,
  648. we should free one and mark stats->rx_dropped++. */
  649. return 0;
  650. }
  651. static struct net_device_stats *ariadne_get_stats(struct net_device *dev)
  652. {
  653. struct ariadne_private *priv = netdev_priv(dev);
  654. volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
  655. short saved_addr;
  656. unsigned long flags;
  657. local_irq_save(flags);
  658. saved_addr = lance->RAP;
  659. lance->RAP = CSR112; /* Missed Frame Count */
  660. priv->stats.rx_missed_errors = swapw(lance->RDP);
  661. lance->RAP = saved_addr;
  662. local_irq_restore(flags);
  663. return &priv->stats;
  664. }
  665. /* Set or clear the multicast filter for this adaptor.
  666. num_addrs == -1 Promiscuous mode, receive all packets
  667. num_addrs == 0 Normal mode, clear multicast list
  668. num_addrs > 0 Multicast mode, receive normal and MC packets, and do
  669. best-effort filtering.
  670. */
  671. static void set_multicast_list(struct net_device *dev)
  672. {
  673. volatile struct Am79C960 *lance = (struct Am79C960*)dev->base_addr;
  674. if (!netif_running(dev))
  675. return;
  676. netif_stop_queue(dev);
  677. /* We take the simple way out and always enable promiscuous mode. */
  678. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  679. lance->RDP = STOP; /* Temporarily stop the lance. */
  680. ariadne_init_ring(dev);
  681. if (dev->flags & IFF_PROMISC) {
  682. lance->RAP = CSR15; /* Mode Register */
  683. lance->RDP = PROM; /* Set promiscuous mode */
  684. } else {
  685. short multicast_table[4];
  686. int num_addrs = dev->mc_count;
  687. int i;
  688. /* We don't use the multicast table, but rely on upper-layer filtering. */
  689. memset(multicast_table, (num_addrs == 0) ? 0 : -1,
  690. sizeof(multicast_table));
  691. for (i = 0; i < 4; i++) {
  692. lance->RAP = CSR8+(i<<8); /* Logical Address Filter */
  693. lance->RDP = swapw(multicast_table[i]);
  694. }
  695. lance->RAP = CSR15; /* Mode Register */
  696. lance->RDP = 0x0000; /* Unset promiscuous mode */
  697. }
  698. lance->RAP = CSR0; /* PCnet-ISA Controller Status */
  699. lance->RDP = INEA|STRT|IDON; /* Resume normal operation. */
  700. netif_wake_queue(dev);
  701. }
  702. static void __devexit ariadne_remove_one(struct zorro_dev *z)
  703. {
  704. struct net_device *dev = zorro_get_drvdata(z);
  705. unregister_netdev(dev);
  706. release_mem_region(ZTWO_PADDR(dev->base_addr), sizeof(struct Am79C960));
  707. release_mem_region(ZTWO_PADDR(dev->mem_start), ARIADNE_RAM_SIZE);
  708. free_netdev(dev);
  709. }
  710. static int __init ariadne_init_module(void)
  711. {
  712. return zorro_register_driver(&ariadne_driver);
  713. }
  714. static void __exit ariadne_cleanup_module(void)
  715. {
  716. zorro_unregister_driver(&ariadne_driver);
  717. }
  718. module_init(ariadne_init_module);
  719. module_exit(ariadne_cleanup_module);
  720. MODULE_LICENSE("GPL");