ariadne.c 24 KB

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