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