a2065.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /*
  2. * Amiga Linux/68k A2065 Ethernet Driver
  3. *
  4. * (C) Copyright 1995-2003 by Geert Uytterhoeven <geert@linux-m68k.org>
  5. *
  6. * Fixes and tips by:
  7. * - Janos Farkas (CHEXUM@sparta.banki.hu)
  8. * - Jes Degn Soerensen (jds@kom.auc.dk)
  9. * - Matt Domsch (Matt_Domsch@dell.com)
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * This program is based on
  14. *
  15. * ariadne.?: Amiga Linux/68k Ariadne Ethernet Driver
  16. * (C) Copyright 1995 by Geert Uytterhoeven,
  17. * Peter De Schrijver
  18. *
  19. * lance.c: An AMD LANCE ethernet driver for linux.
  20. * Written 1993-94 by Donald Becker.
  21. *
  22. * Am79C960: PCnet(tm)-ISA Single-Chip Ethernet Controller
  23. * Advanced Micro Devices
  24. * Publication #16907, Rev. B, Amendment/0, May 1994
  25. *
  26. * ----------------------------------------------------------------------------
  27. *
  28. * This file is subject to the terms and conditions of the GNU General Public
  29. * License. See the file COPYING in the main directory of the Linux
  30. * distribution for more details.
  31. *
  32. * ----------------------------------------------------------------------------
  33. *
  34. * The A2065 is a Zorro-II board made by Commodore/Ameristar. It contains:
  35. *
  36. * - an Am7990 Local Area Network Controller for Ethernet (LANCE) with
  37. * both 10BASE-2 (thin coax) and AUI (DB-15) connectors
  38. */
  39. #include <linux/errno.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/etherdevice.h>
  42. #include <linux/module.h>
  43. #include <linux/stddef.h>
  44. #include <linux/kernel.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/ioport.h>
  47. #include <linux/skbuff.h>
  48. #include <linux/slab.h>
  49. #include <linux/string.h>
  50. #include <linux/init.h>
  51. #include <linux/crc32.h>
  52. #include <linux/zorro.h>
  53. #include <linux/bitops.h>
  54. #include <asm/irq.h>
  55. #include <asm/amigaints.h>
  56. #include <asm/amigahw.h>
  57. #include "a2065.h"
  58. /*
  59. * Transmit/Receive Ring Definitions
  60. */
  61. #define LANCE_LOG_TX_BUFFERS (2)
  62. #define LANCE_LOG_RX_BUFFERS (4)
  63. #define TX_RING_SIZE (1<<LANCE_LOG_TX_BUFFERS)
  64. #define RX_RING_SIZE (1<<LANCE_LOG_RX_BUFFERS)
  65. #define TX_RING_MOD_MASK (TX_RING_SIZE-1)
  66. #define RX_RING_MOD_MASK (RX_RING_SIZE-1)
  67. #define PKT_BUF_SIZE (1544)
  68. #define RX_BUFF_SIZE PKT_BUF_SIZE
  69. #define TX_BUFF_SIZE PKT_BUF_SIZE
  70. /*
  71. * Layout of the Lance's RAM Buffer
  72. */
  73. struct lance_init_block {
  74. unsigned short mode; /* Pre-set mode (reg. 15) */
  75. unsigned char phys_addr[6]; /* Physical ethernet address */
  76. unsigned filter[2]; /* Multicast filter. */
  77. /* Receive and transmit ring base, along with extra bits. */
  78. unsigned short rx_ptr; /* receive descriptor addr */
  79. unsigned short rx_len; /* receive len and high addr */
  80. unsigned short tx_ptr; /* transmit descriptor addr */
  81. unsigned short tx_len; /* transmit len and high addr */
  82. /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
  83. struct lance_rx_desc brx_ring[RX_RING_SIZE];
  84. struct lance_tx_desc btx_ring[TX_RING_SIZE];
  85. char rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
  86. char tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
  87. };
  88. /*
  89. * Private Device Data
  90. */
  91. struct lance_private {
  92. char *name;
  93. volatile struct lance_regs *ll;
  94. volatile struct lance_init_block *init_block; /* Hosts view */
  95. volatile struct lance_init_block *lance_init_block; /* Lance view */
  96. int rx_new, tx_new;
  97. int rx_old, tx_old;
  98. int lance_log_rx_bufs, lance_log_tx_bufs;
  99. int rx_ring_mod_mask, tx_ring_mod_mask;
  100. struct net_device_stats stats;
  101. int tpe; /* cable-selection is TPE */
  102. int auto_select; /* cable-selection by carrier */
  103. unsigned short busmaster_regval;
  104. #ifdef CONFIG_SUNLANCE
  105. struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */
  106. int burst_sizes; /* ledma SBus burst sizes */
  107. #endif
  108. struct timer_list multicast_timer;
  109. };
  110. #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
  111. lp->tx_old+lp->tx_ring_mod_mask-lp->tx_new:\
  112. lp->tx_old - lp->tx_new-1)
  113. #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
  114. /* Load the CSR registers */
  115. static void load_csrs (struct lance_private *lp)
  116. {
  117. volatile struct lance_regs *ll = lp->ll;
  118. volatile struct lance_init_block *aib = lp->lance_init_block;
  119. int leptr;
  120. leptr = LANCE_ADDR (aib);
  121. ll->rap = LE_CSR1;
  122. ll->rdp = (leptr & 0xFFFF);
  123. ll->rap = LE_CSR2;
  124. ll->rdp = leptr >> 16;
  125. ll->rap = LE_CSR3;
  126. ll->rdp = lp->busmaster_regval;
  127. /* Point back to csr0 */
  128. ll->rap = LE_CSR0;
  129. }
  130. #define ZERO 0
  131. /* Setup the Lance Rx and Tx rings */
  132. static void lance_init_ring (struct net_device *dev)
  133. {
  134. struct lance_private *lp = netdev_priv(dev);
  135. volatile struct lance_init_block *ib = lp->init_block;
  136. volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
  137. int leptr;
  138. int i;
  139. aib = lp->lance_init_block;
  140. /* Lock out other processes while setting up hardware */
  141. netif_stop_queue(dev);
  142. lp->rx_new = lp->tx_new = 0;
  143. lp->rx_old = lp->tx_old = 0;
  144. ib->mode = 0;
  145. /* Copy the ethernet address to the lance init block
  146. * Note that on the sparc you need to swap the ethernet address.
  147. */
  148. ib->phys_addr [0] = dev->dev_addr [1];
  149. ib->phys_addr [1] = dev->dev_addr [0];
  150. ib->phys_addr [2] = dev->dev_addr [3];
  151. ib->phys_addr [3] = dev->dev_addr [2];
  152. ib->phys_addr [4] = dev->dev_addr [5];
  153. ib->phys_addr [5] = dev->dev_addr [4];
  154. if (ZERO)
  155. printk(KERN_DEBUG "TX rings:\n");
  156. /* Setup the Tx ring entries */
  157. for (i = 0; i <= (1<<lp->lance_log_tx_bufs); i++) {
  158. leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
  159. ib->btx_ring [i].tmd0 = leptr;
  160. ib->btx_ring [i].tmd1_hadr = leptr >> 16;
  161. ib->btx_ring [i].tmd1_bits = 0;
  162. ib->btx_ring [i].length = 0xf000; /* The ones required by tmd2 */
  163. ib->btx_ring [i].misc = 0;
  164. if (i < 3 && ZERO)
  165. printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
  166. }
  167. /* Setup the Rx ring entries */
  168. if (ZERO)
  169. printk(KERN_DEBUG "RX rings:\n");
  170. for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
  171. leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
  172. ib->brx_ring [i].rmd0 = leptr;
  173. ib->brx_ring [i].rmd1_hadr = leptr >> 16;
  174. ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
  175. ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000;
  176. ib->brx_ring [i].mblength = 0;
  177. if (i < 3 && ZERO)
  178. printk(KERN_DEBUG "%d: 0x%8.8x\n", i, leptr);
  179. }
  180. /* Setup the initialization block */
  181. /* Setup rx descriptor pointer */
  182. leptr = LANCE_ADDR(&aib->brx_ring);
  183. ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
  184. ib->rx_ptr = leptr;
  185. if (ZERO)
  186. printk(KERN_DEBUG "RX ptr: %8.8x\n", leptr);
  187. /* Setup tx descriptor pointer */
  188. leptr = LANCE_ADDR(&aib->btx_ring);
  189. ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
  190. ib->tx_ptr = leptr;
  191. if (ZERO)
  192. printk(KERN_DEBUG "TX ptr: %8.8x\n", leptr);
  193. /* Clear the multicast filter */
  194. ib->filter [0] = 0;
  195. ib->filter [1] = 0;
  196. }
  197. static int init_restart_lance (struct lance_private *lp)
  198. {
  199. volatile struct lance_regs *ll = lp->ll;
  200. int i;
  201. ll->rap = LE_CSR0;
  202. ll->rdp = LE_C0_INIT;
  203. /* Wait for the lance to complete initialization */
  204. for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
  205. barrier();
  206. if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
  207. printk(KERN_ERR "LANCE unopened after %d ticks, csr0=%4.4x.\n",
  208. i, ll->rdp);
  209. return -EIO;
  210. }
  211. /* Clear IDON by writing a "1", enable interrupts and start lance */
  212. ll->rdp = LE_C0_IDON;
  213. ll->rdp = LE_C0_INEA | LE_C0_STRT;
  214. return 0;
  215. }
  216. static int lance_rx (struct net_device *dev)
  217. {
  218. struct lance_private *lp = netdev_priv(dev);
  219. volatile struct lance_init_block *ib = lp->init_block;
  220. volatile struct lance_regs *ll = lp->ll;
  221. volatile struct lance_rx_desc *rd;
  222. unsigned char bits;
  223. int len = 0; /* XXX shut up gcc warnings */
  224. struct sk_buff *skb = 0; /* XXX shut up gcc warnings */
  225. #ifdef TEST_HITS
  226. int i;
  227. printk(KERN_DEBUG "[");
  228. for (i = 0; i < RX_RING_SIZE; i++) {
  229. if (i == lp->rx_new)
  230. printk ("%s",
  231. ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
  232. else
  233. printk ("%s",
  234. ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
  235. }
  236. printk ("]\n");
  237. #endif
  238. ll->rdp = LE_C0_RINT|LE_C0_INEA;
  239. for (rd = &ib->brx_ring [lp->rx_new];
  240. !((bits = rd->rmd1_bits) & LE_R1_OWN);
  241. rd = &ib->brx_ring [lp->rx_new]) {
  242. /* We got an incomplete frame? */
  243. if ((bits & LE_R1_POK) != LE_R1_POK) {
  244. lp->stats.rx_over_errors++;
  245. lp->stats.rx_errors++;
  246. continue;
  247. } else if (bits & LE_R1_ERR) {
  248. /* Count only the end frame as a rx error,
  249. * not the beginning
  250. */
  251. if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
  252. if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
  253. if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
  254. if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
  255. if (bits & LE_R1_EOP) lp->stats.rx_errors++;
  256. } else {
  257. len = (rd->mblength & 0xfff) - 4;
  258. skb = dev_alloc_skb (len+2);
  259. if (skb == 0) {
  260. printk(KERN_WARNING "%s: Memory squeeze, "
  261. "deferring packet.\n", dev->name);
  262. lp->stats.rx_dropped++;
  263. rd->mblength = 0;
  264. rd->rmd1_bits = LE_R1_OWN;
  265. lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
  266. return 0;
  267. }
  268. skb->dev = dev;
  269. skb_reserve (skb, 2); /* 16 byte align */
  270. skb_put (skb, len); /* make room */
  271. eth_copy_and_sum(skb,
  272. (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
  273. len, 0);
  274. skb->protocol = eth_type_trans (skb, dev);
  275. netif_rx (skb);
  276. dev->last_rx = jiffies;
  277. lp->stats.rx_packets++;
  278. lp->stats.rx_bytes += len;
  279. }
  280. /* Return the packet to the pool */
  281. rd->mblength = 0;
  282. rd->rmd1_bits = LE_R1_OWN;
  283. lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
  284. }
  285. return 0;
  286. }
  287. static int lance_tx (struct net_device *dev)
  288. {
  289. struct lance_private *lp = netdev_priv(dev);
  290. volatile struct lance_init_block *ib = lp->init_block;
  291. volatile struct lance_regs *ll = lp->ll;
  292. volatile struct lance_tx_desc *td;
  293. int i, j;
  294. int status;
  295. /* csr0 is 2f3 */
  296. ll->rdp = LE_C0_TINT | LE_C0_INEA;
  297. /* csr0 is 73 */
  298. j = lp->tx_old;
  299. for (i = j; i != lp->tx_new; i = j) {
  300. td = &ib->btx_ring [i];
  301. /* If we hit a packet not owned by us, stop */
  302. if (td->tmd1_bits & LE_T1_OWN)
  303. break;
  304. if (td->tmd1_bits & LE_T1_ERR) {
  305. status = td->misc;
  306. lp->stats.tx_errors++;
  307. if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
  308. if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
  309. if (status & LE_T3_CLOS) {
  310. lp->stats.tx_carrier_errors++;
  311. if (lp->auto_select) {
  312. lp->tpe = 1 - lp->tpe;
  313. printk(KERN_ERR "%s: Carrier Lost, "
  314. "trying %s\n", dev->name,
  315. lp->tpe?"TPE":"AUI");
  316. /* Stop the lance */
  317. ll->rap = LE_CSR0;
  318. ll->rdp = LE_C0_STOP;
  319. lance_init_ring (dev);
  320. load_csrs (lp);
  321. init_restart_lance (lp);
  322. return 0;
  323. }
  324. }
  325. /* buffer errors and underflows turn off the transmitter */
  326. /* Restart the adapter */
  327. if (status & (LE_T3_BUF|LE_T3_UFL)) {
  328. lp->stats.tx_fifo_errors++;
  329. printk(KERN_ERR "%s: Tx: ERR_BUF|ERR_UFL, "
  330. "restarting\n", dev->name);
  331. /* Stop the lance */
  332. ll->rap = LE_CSR0;
  333. ll->rdp = LE_C0_STOP;
  334. lance_init_ring (dev);
  335. load_csrs (lp);
  336. init_restart_lance (lp);
  337. return 0;
  338. }
  339. } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
  340. /*
  341. * So we don't count the packet more than once.
  342. */
  343. td->tmd1_bits &= ~(LE_T1_POK);
  344. /* One collision before packet was sent. */
  345. if (td->tmd1_bits & LE_T1_EONE)
  346. lp->stats.collisions++;
  347. /* More than one collision, be optimistic. */
  348. if (td->tmd1_bits & LE_T1_EMORE)
  349. lp->stats.collisions += 2;
  350. lp->stats.tx_packets++;
  351. }
  352. j = (j + 1) & lp->tx_ring_mod_mask;
  353. }
  354. lp->tx_old = j;
  355. ll->rdp = LE_C0_TINT | LE_C0_INEA;
  356. return 0;
  357. }
  358. static irqreturn_t lance_interrupt (int irq, void *dev_id)
  359. {
  360. struct net_device *dev;
  361. struct lance_private *lp;
  362. volatile struct lance_regs *ll;
  363. int csr0;
  364. dev = (struct net_device *) dev_id;
  365. lp = netdev_priv(dev);
  366. ll = lp->ll;
  367. ll->rap = LE_CSR0; /* LANCE Controller Status */
  368. csr0 = ll->rdp;
  369. if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
  370. return IRQ_NONE; /* been generated by the Lance. */
  371. /* Acknowledge all the interrupt sources ASAP */
  372. ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
  373. LE_C0_INIT);
  374. if ((csr0 & LE_C0_ERR)) {
  375. /* Clear the error condition */
  376. ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
  377. }
  378. if (csr0 & LE_C0_RINT)
  379. lance_rx (dev);
  380. if (csr0 & LE_C0_TINT)
  381. lance_tx (dev);
  382. /* Log misc errors. */
  383. if (csr0 & LE_C0_BABL)
  384. lp->stats.tx_errors++; /* Tx babble. */
  385. if (csr0 & LE_C0_MISS)
  386. lp->stats.rx_errors++; /* Missed a Rx frame. */
  387. if (csr0 & LE_C0_MERR) {
  388. printk(KERN_ERR "%s: Bus master arbitration failure, status "
  389. "%4.4x.\n", dev->name, csr0);
  390. /* Restart the chip. */
  391. ll->rdp = LE_C0_STRT;
  392. }
  393. if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
  394. netif_wake_queue(dev);
  395. ll->rap = LE_CSR0;
  396. ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
  397. LE_C0_IDON|LE_C0_INEA;
  398. return IRQ_HANDLED;
  399. }
  400. struct net_device *last_dev = 0;
  401. static int lance_open (struct net_device *dev)
  402. {
  403. struct lance_private *lp = netdev_priv(dev);
  404. volatile struct lance_regs *ll = lp->ll;
  405. int ret;
  406. last_dev = dev;
  407. /* Stop the Lance */
  408. ll->rap = LE_CSR0;
  409. ll->rdp = LE_C0_STOP;
  410. /* Install the Interrupt handler */
  411. ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED,
  412. dev->name, dev);
  413. if (ret) return ret;
  414. load_csrs (lp);
  415. lance_init_ring (dev);
  416. netif_start_queue(dev);
  417. return init_restart_lance (lp);
  418. }
  419. static int lance_close (struct net_device *dev)
  420. {
  421. struct lance_private *lp = netdev_priv(dev);
  422. volatile struct lance_regs *ll = lp->ll;
  423. netif_stop_queue(dev);
  424. del_timer_sync(&lp->multicast_timer);
  425. /* Stop the card */
  426. ll->rap = LE_CSR0;
  427. ll->rdp = LE_C0_STOP;
  428. free_irq(IRQ_AMIGA_PORTS, dev);
  429. return 0;
  430. }
  431. static inline int lance_reset (struct net_device *dev)
  432. {
  433. struct lance_private *lp = netdev_priv(dev);
  434. volatile struct lance_regs *ll = lp->ll;
  435. int status;
  436. /* Stop the lance */
  437. ll->rap = LE_CSR0;
  438. ll->rdp = LE_C0_STOP;
  439. load_csrs (lp);
  440. lance_init_ring (dev);
  441. dev->trans_start = jiffies;
  442. netif_start_queue(dev);
  443. status = init_restart_lance (lp);
  444. #ifdef DEBUG_DRIVER
  445. printk(KERN_DEBUG "Lance restart=%d\n", status);
  446. #endif
  447. return status;
  448. }
  449. static void lance_tx_timeout(struct net_device *dev)
  450. {
  451. struct lance_private *lp = netdev_priv(dev);
  452. volatile struct lance_regs *ll = lp->ll;
  453. printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
  454. dev->name, ll->rdp);
  455. lance_reset(dev);
  456. netif_wake_queue(dev);
  457. }
  458. static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
  459. {
  460. struct lance_private *lp = netdev_priv(dev);
  461. volatile struct lance_regs *ll = lp->ll;
  462. volatile struct lance_init_block *ib = lp->init_block;
  463. int entry, skblen, len;
  464. int status = 0;
  465. static int outs;
  466. unsigned long flags;
  467. skblen = skb->len;
  468. len = skblen;
  469. if (len < ETH_ZLEN) {
  470. len = ETH_ZLEN;
  471. if (skb_padto(skb, ETH_ZLEN))
  472. return 0;
  473. }
  474. local_irq_save(flags);
  475. if (!TX_BUFFS_AVAIL){
  476. local_irq_restore(flags);
  477. return -1;
  478. }
  479. #ifdef DEBUG_DRIVER
  480. /* dump the packet */
  481. {
  482. int i;
  483. for (i = 0; i < 64; i++) {
  484. if ((i % 16) == 0)
  485. printk("\n" KERN_DEBUG);
  486. printk ("%2.2x ", skb->data [i]);
  487. }
  488. printk("\n");
  489. }
  490. #endif
  491. entry = lp->tx_new & lp->tx_ring_mod_mask;
  492. ib->btx_ring [entry].length = (-len) | 0xf000;
  493. ib->btx_ring [entry].misc = 0;
  494. memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
  495. /* Clear the slack of the packet, do I need this? */
  496. if (len != skblen)
  497. memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
  498. /* Now, give the packet to the lance */
  499. ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
  500. lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
  501. outs++;
  502. if (TX_BUFFS_AVAIL <= 0)
  503. netif_stop_queue(dev);
  504. /* Kick the lance: transmit now */
  505. ll->rdp = LE_C0_INEA | LE_C0_TDMD;
  506. dev->trans_start = jiffies;
  507. dev_kfree_skb (skb);
  508. local_irq_restore(flags);
  509. return status;
  510. }
  511. static struct net_device_stats *lance_get_stats (struct net_device *dev)
  512. {
  513. struct lance_private *lp = netdev_priv(dev);
  514. return &lp->stats;
  515. }
  516. /* taken from the depca driver */
  517. static void lance_load_multicast (struct net_device *dev)
  518. {
  519. struct lance_private *lp = netdev_priv(dev);
  520. volatile struct lance_init_block *ib = lp->init_block;
  521. volatile u16 *mcast_table = (u16 *)&ib->filter;
  522. struct dev_mc_list *dmi=dev->mc_list;
  523. char *addrs;
  524. int i;
  525. u32 crc;
  526. /* set all multicast bits */
  527. if (dev->flags & IFF_ALLMULTI){
  528. ib->filter [0] = 0xffffffff;
  529. ib->filter [1] = 0xffffffff;
  530. return;
  531. }
  532. /* clear the multicast filter */
  533. ib->filter [0] = 0;
  534. ib->filter [1] = 0;
  535. /* Add addresses */
  536. for (i = 0; i < dev->mc_count; i++){
  537. addrs = dmi->dmi_addr;
  538. dmi = dmi->next;
  539. /* multicast address? */
  540. if (!(*addrs & 1))
  541. continue;
  542. crc = ether_crc_le(6, addrs);
  543. crc = crc >> 26;
  544. mcast_table [crc >> 4] |= 1 << (crc & 0xf);
  545. }
  546. return;
  547. }
  548. static void lance_set_multicast (struct net_device *dev)
  549. {
  550. struct lance_private *lp = netdev_priv(dev);
  551. volatile struct lance_init_block *ib = lp->init_block;
  552. volatile struct lance_regs *ll = lp->ll;
  553. if (!netif_running(dev))
  554. return;
  555. if (lp->tx_old != lp->tx_new) {
  556. mod_timer(&lp->multicast_timer, jiffies + 4);
  557. netif_wake_queue(dev);
  558. return;
  559. }
  560. netif_stop_queue(dev);
  561. ll->rap = LE_CSR0;
  562. ll->rdp = LE_C0_STOP;
  563. lance_init_ring (dev);
  564. if (dev->flags & IFF_PROMISC) {
  565. ib->mode |= LE_MO_PROM;
  566. } else {
  567. ib->mode &= ~LE_MO_PROM;
  568. lance_load_multicast (dev);
  569. }
  570. load_csrs (lp);
  571. init_restart_lance (lp);
  572. netif_wake_queue(dev);
  573. }
  574. static int __devinit a2065_init_one(struct zorro_dev *z,
  575. const struct zorro_device_id *ent);
  576. static void __devexit a2065_remove_one(struct zorro_dev *z);
  577. static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = {
  578. { ZORRO_PROD_CBM_A2065_1 },
  579. { ZORRO_PROD_CBM_A2065_2 },
  580. { ZORRO_PROD_AMERISTAR_A2065 },
  581. { 0 }
  582. };
  583. static struct zorro_driver a2065_driver = {
  584. .name = "a2065",
  585. .id_table = a2065_zorro_tbl,
  586. .probe = a2065_init_one,
  587. .remove = __devexit_p(a2065_remove_one),
  588. };
  589. static int __devinit a2065_init_one(struct zorro_dev *z,
  590. const struct zorro_device_id *ent)
  591. {
  592. struct net_device *dev;
  593. struct lance_private *priv;
  594. unsigned long board, base_addr, mem_start;
  595. struct resource *r1, *r2;
  596. int err;
  597. board = z->resource.start;
  598. base_addr = board+A2065_LANCE;
  599. mem_start = board+A2065_RAM;
  600. r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
  601. "Am7990");
  602. if (!r1)
  603. return -EBUSY;
  604. r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
  605. if (!r2) {
  606. release_resource(r1);
  607. return -EBUSY;
  608. }
  609. dev = alloc_etherdev(sizeof(struct lance_private));
  610. if (dev == NULL) {
  611. release_resource(r1);
  612. release_resource(r2);
  613. return -ENOMEM;
  614. }
  615. SET_MODULE_OWNER(dev);
  616. priv = netdev_priv(dev);
  617. r1->name = dev->name;
  618. r2->name = dev->name;
  619. dev->dev_addr[0] = 0x00;
  620. if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
  621. dev->dev_addr[1] = 0x80;
  622. dev->dev_addr[2] = 0x10;
  623. } else { /* Ameristar */
  624. dev->dev_addr[1] = 0x00;
  625. dev->dev_addr[2] = 0x9f;
  626. }
  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+A2065_RAM_SIZE;
  633. priv->ll = (volatile struct lance_regs *)dev->base_addr;
  634. priv->init_block = (struct lance_init_block *)dev->mem_start;
  635. priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
  636. priv->auto_select = 0;
  637. priv->busmaster_regval = LE_C3_BSWP;
  638. priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  639. priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  640. priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
  641. priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
  642. dev->open = &lance_open;
  643. dev->stop = &lance_close;
  644. dev->hard_start_xmit = &lance_start_xmit;
  645. dev->tx_timeout = &lance_tx_timeout;
  646. dev->watchdog_timeo = 5*HZ;
  647. dev->get_stats = &lance_get_stats;
  648. dev->set_multicast_list = &lance_set_multicast;
  649. dev->dma = 0;
  650. init_timer(&priv->multicast_timer);
  651. priv->multicast_timer.data = (unsigned long) dev;
  652. priv->multicast_timer.function =
  653. (void (*)(unsigned long)) &lance_set_multicast;
  654. err = register_netdev(dev);
  655. if (err) {
  656. release_resource(r1);
  657. release_resource(r2);
  658. free_netdev(dev);
  659. return err;
  660. }
  661. zorro_set_drvdata(z, dev);
  662. printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address "
  663. "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
  664. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  665. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  666. return 0;
  667. }
  668. static void __devexit a2065_remove_one(struct zorro_dev *z)
  669. {
  670. struct net_device *dev = zorro_get_drvdata(z);
  671. unregister_netdev(dev);
  672. release_mem_region(ZTWO_PADDR(dev->base_addr),
  673. sizeof(struct lance_regs));
  674. release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
  675. free_netdev(dev);
  676. }
  677. static int __init a2065_init_module(void)
  678. {
  679. return zorro_register_driver(&a2065_driver);
  680. }
  681. static void __exit a2065_cleanup_module(void)
  682. {
  683. zorro_unregister_driver(&a2065_driver);
  684. }
  685. module_init(a2065_init_module);
  686. module_exit(a2065_cleanup_module);
  687. MODULE_LICENSE("GPL");