ariadne.c 23 KB

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