ariadne.c 22 KB

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