a2065.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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_reserve (skb, 2); /* 16 byte align */
  269. skb_put (skb, len); /* make room */
  270. eth_copy_and_sum(skb,
  271. (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
  272. len, 0);
  273. skb->protocol = eth_type_trans (skb, dev);
  274. netif_rx (skb);
  275. dev->last_rx = jiffies;
  276. lp->stats.rx_packets++;
  277. lp->stats.rx_bytes += len;
  278. }
  279. /* Return the packet to the pool */
  280. rd->mblength = 0;
  281. rd->rmd1_bits = LE_R1_OWN;
  282. lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
  283. }
  284. return 0;
  285. }
  286. static int lance_tx (struct net_device *dev)
  287. {
  288. struct lance_private *lp = netdev_priv(dev);
  289. volatile struct lance_init_block *ib = lp->init_block;
  290. volatile struct lance_regs *ll = lp->ll;
  291. volatile struct lance_tx_desc *td;
  292. int i, j;
  293. int status;
  294. /* csr0 is 2f3 */
  295. ll->rdp = LE_C0_TINT | LE_C0_INEA;
  296. /* csr0 is 73 */
  297. j = lp->tx_old;
  298. for (i = j; i != lp->tx_new; i = j) {
  299. td = &ib->btx_ring [i];
  300. /* If we hit a packet not owned by us, stop */
  301. if (td->tmd1_bits & LE_T1_OWN)
  302. break;
  303. if (td->tmd1_bits & LE_T1_ERR) {
  304. status = td->misc;
  305. lp->stats.tx_errors++;
  306. if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
  307. if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
  308. if (status & LE_T3_CLOS) {
  309. lp->stats.tx_carrier_errors++;
  310. if (lp->auto_select) {
  311. lp->tpe = 1 - lp->tpe;
  312. printk(KERN_ERR "%s: Carrier Lost, "
  313. "trying %s\n", dev->name,
  314. lp->tpe?"TPE":"AUI");
  315. /* Stop the lance */
  316. ll->rap = LE_CSR0;
  317. ll->rdp = LE_C0_STOP;
  318. lance_init_ring (dev);
  319. load_csrs (lp);
  320. init_restart_lance (lp);
  321. return 0;
  322. }
  323. }
  324. /* buffer errors and underflows turn off the transmitter */
  325. /* Restart the adapter */
  326. if (status & (LE_T3_BUF|LE_T3_UFL)) {
  327. lp->stats.tx_fifo_errors++;
  328. printk(KERN_ERR "%s: Tx: ERR_BUF|ERR_UFL, "
  329. "restarting\n", dev->name);
  330. /* Stop the lance */
  331. ll->rap = LE_CSR0;
  332. ll->rdp = LE_C0_STOP;
  333. lance_init_ring (dev);
  334. load_csrs (lp);
  335. init_restart_lance (lp);
  336. return 0;
  337. }
  338. } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
  339. /*
  340. * So we don't count the packet more than once.
  341. */
  342. td->tmd1_bits &= ~(LE_T1_POK);
  343. /* One collision before packet was sent. */
  344. if (td->tmd1_bits & LE_T1_EONE)
  345. lp->stats.collisions++;
  346. /* More than one collision, be optimistic. */
  347. if (td->tmd1_bits & LE_T1_EMORE)
  348. lp->stats.collisions += 2;
  349. lp->stats.tx_packets++;
  350. }
  351. j = (j + 1) & lp->tx_ring_mod_mask;
  352. }
  353. lp->tx_old = j;
  354. ll->rdp = LE_C0_TINT | LE_C0_INEA;
  355. return 0;
  356. }
  357. static irqreturn_t lance_interrupt (int irq, void *dev_id)
  358. {
  359. struct net_device *dev;
  360. struct lance_private *lp;
  361. volatile struct lance_regs *ll;
  362. int csr0;
  363. dev = (struct net_device *) dev_id;
  364. lp = netdev_priv(dev);
  365. ll = lp->ll;
  366. ll->rap = LE_CSR0; /* LANCE Controller Status */
  367. csr0 = ll->rdp;
  368. if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
  369. return IRQ_NONE; /* been generated by the Lance. */
  370. /* Acknowledge all the interrupt sources ASAP */
  371. ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
  372. LE_C0_INIT);
  373. if ((csr0 & LE_C0_ERR)) {
  374. /* Clear the error condition */
  375. ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
  376. }
  377. if (csr0 & LE_C0_RINT)
  378. lance_rx (dev);
  379. if (csr0 & LE_C0_TINT)
  380. lance_tx (dev);
  381. /* Log misc errors. */
  382. if (csr0 & LE_C0_BABL)
  383. lp->stats.tx_errors++; /* Tx babble. */
  384. if (csr0 & LE_C0_MISS)
  385. lp->stats.rx_errors++; /* Missed a Rx frame. */
  386. if (csr0 & LE_C0_MERR) {
  387. printk(KERN_ERR "%s: Bus master arbitration failure, status "
  388. "%4.4x.\n", dev->name, csr0);
  389. /* Restart the chip. */
  390. ll->rdp = LE_C0_STRT;
  391. }
  392. if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
  393. netif_wake_queue(dev);
  394. ll->rap = LE_CSR0;
  395. ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
  396. LE_C0_IDON|LE_C0_INEA;
  397. return IRQ_HANDLED;
  398. }
  399. struct net_device *last_dev = 0;
  400. static int lance_open (struct net_device *dev)
  401. {
  402. struct lance_private *lp = netdev_priv(dev);
  403. volatile struct lance_regs *ll = lp->ll;
  404. int ret;
  405. last_dev = dev;
  406. /* Stop the Lance */
  407. ll->rap = LE_CSR0;
  408. ll->rdp = LE_C0_STOP;
  409. /* Install the Interrupt handler */
  410. ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED,
  411. dev->name, dev);
  412. if (ret) return ret;
  413. load_csrs (lp);
  414. lance_init_ring (dev);
  415. netif_start_queue(dev);
  416. return init_restart_lance (lp);
  417. }
  418. static int lance_close (struct net_device *dev)
  419. {
  420. struct lance_private *lp = netdev_priv(dev);
  421. volatile struct lance_regs *ll = lp->ll;
  422. netif_stop_queue(dev);
  423. del_timer_sync(&lp->multicast_timer);
  424. /* Stop the card */
  425. ll->rap = LE_CSR0;
  426. ll->rdp = LE_C0_STOP;
  427. free_irq(IRQ_AMIGA_PORTS, dev);
  428. return 0;
  429. }
  430. static inline int lance_reset (struct net_device *dev)
  431. {
  432. struct lance_private *lp = netdev_priv(dev);
  433. volatile struct lance_regs *ll = lp->ll;
  434. int status;
  435. /* Stop the lance */
  436. ll->rap = LE_CSR0;
  437. ll->rdp = LE_C0_STOP;
  438. load_csrs (lp);
  439. lance_init_ring (dev);
  440. dev->trans_start = jiffies;
  441. netif_start_queue(dev);
  442. status = init_restart_lance (lp);
  443. #ifdef DEBUG_DRIVER
  444. printk(KERN_DEBUG "Lance restart=%d\n", status);
  445. #endif
  446. return status;
  447. }
  448. static void lance_tx_timeout(struct net_device *dev)
  449. {
  450. struct lance_private *lp = netdev_priv(dev);
  451. volatile struct lance_regs *ll = lp->ll;
  452. printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
  453. dev->name, ll->rdp);
  454. lance_reset(dev);
  455. netif_wake_queue(dev);
  456. }
  457. static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
  458. {
  459. struct lance_private *lp = netdev_priv(dev);
  460. volatile struct lance_regs *ll = lp->ll;
  461. volatile struct lance_init_block *ib = lp->init_block;
  462. int entry, skblen, len;
  463. int status = 0;
  464. unsigned long flags;
  465. skblen = skb->len;
  466. len = skblen;
  467. if (len < ETH_ZLEN) {
  468. len = ETH_ZLEN;
  469. if (skb_padto(skb, ETH_ZLEN))
  470. return 0;
  471. }
  472. local_irq_save(flags);
  473. if (!TX_BUFFS_AVAIL){
  474. local_irq_restore(flags);
  475. return -1;
  476. }
  477. #ifdef DEBUG_DRIVER
  478. /* dump the packet */
  479. {
  480. int i;
  481. for (i = 0; i < 64; i++) {
  482. if ((i % 16) == 0)
  483. printk("\n" KERN_DEBUG);
  484. printk ("%2.2x ", skb->data [i]);
  485. }
  486. printk("\n");
  487. }
  488. #endif
  489. entry = lp->tx_new & lp->tx_ring_mod_mask;
  490. ib->btx_ring [entry].length = (-len) | 0xf000;
  491. ib->btx_ring [entry].misc = 0;
  492. skb_copy_from_linear_data(skb, (void *)&ib->tx_buf [entry][0], skblen);
  493. /* Clear the slack of the packet, do I need this? */
  494. if (len != skblen)
  495. memset ((void *) &ib->tx_buf [entry][skblen], 0, len - skblen);
  496. /* Now, give the packet to the lance */
  497. ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
  498. lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
  499. lp->stats.tx_bytes += skblen;
  500. if (TX_BUFFS_AVAIL <= 0)
  501. netif_stop_queue(dev);
  502. /* Kick the lance: transmit now */
  503. ll->rdp = LE_C0_INEA | LE_C0_TDMD;
  504. dev->trans_start = jiffies;
  505. dev_kfree_skb (skb);
  506. local_irq_restore(flags);
  507. return status;
  508. }
  509. static struct net_device_stats *lance_get_stats (struct net_device *dev)
  510. {
  511. struct lance_private *lp = netdev_priv(dev);
  512. return &lp->stats;
  513. }
  514. /* taken from the depca driver */
  515. static void lance_load_multicast (struct net_device *dev)
  516. {
  517. struct lance_private *lp = netdev_priv(dev);
  518. volatile struct lance_init_block *ib = lp->init_block;
  519. volatile u16 *mcast_table = (u16 *)&ib->filter;
  520. struct dev_mc_list *dmi=dev->mc_list;
  521. char *addrs;
  522. int i;
  523. u32 crc;
  524. /* set all multicast bits */
  525. if (dev->flags & IFF_ALLMULTI){
  526. ib->filter [0] = 0xffffffff;
  527. ib->filter [1] = 0xffffffff;
  528. return;
  529. }
  530. /* clear the multicast filter */
  531. ib->filter [0] = 0;
  532. ib->filter [1] = 0;
  533. /* Add addresses */
  534. for (i = 0; i < dev->mc_count; i++){
  535. addrs = dmi->dmi_addr;
  536. dmi = dmi->next;
  537. /* multicast address? */
  538. if (!(*addrs & 1))
  539. continue;
  540. crc = ether_crc_le(6, addrs);
  541. crc = crc >> 26;
  542. mcast_table [crc >> 4] |= 1 << (crc & 0xf);
  543. }
  544. return;
  545. }
  546. static void lance_set_multicast (struct net_device *dev)
  547. {
  548. struct lance_private *lp = netdev_priv(dev);
  549. volatile struct lance_init_block *ib = lp->init_block;
  550. volatile struct lance_regs *ll = lp->ll;
  551. if (!netif_running(dev))
  552. return;
  553. if (lp->tx_old != lp->tx_new) {
  554. mod_timer(&lp->multicast_timer, jiffies + 4);
  555. netif_wake_queue(dev);
  556. return;
  557. }
  558. netif_stop_queue(dev);
  559. ll->rap = LE_CSR0;
  560. ll->rdp = LE_C0_STOP;
  561. lance_init_ring (dev);
  562. if (dev->flags & IFF_PROMISC) {
  563. ib->mode |= LE_MO_PROM;
  564. } else {
  565. ib->mode &= ~LE_MO_PROM;
  566. lance_load_multicast (dev);
  567. }
  568. load_csrs (lp);
  569. init_restart_lance (lp);
  570. netif_wake_queue(dev);
  571. }
  572. static int __devinit a2065_init_one(struct zorro_dev *z,
  573. const struct zorro_device_id *ent);
  574. static void __devexit a2065_remove_one(struct zorro_dev *z);
  575. static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = {
  576. { ZORRO_PROD_CBM_A2065_1 },
  577. { ZORRO_PROD_CBM_A2065_2 },
  578. { ZORRO_PROD_AMERISTAR_A2065 },
  579. { 0 }
  580. };
  581. static struct zorro_driver a2065_driver = {
  582. .name = "a2065",
  583. .id_table = a2065_zorro_tbl,
  584. .probe = a2065_init_one,
  585. .remove = __devexit_p(a2065_remove_one),
  586. };
  587. static int __devinit a2065_init_one(struct zorro_dev *z,
  588. const struct zorro_device_id *ent)
  589. {
  590. struct net_device *dev;
  591. struct lance_private *priv;
  592. unsigned long board, base_addr, mem_start;
  593. struct resource *r1, *r2;
  594. int err;
  595. board = z->resource.start;
  596. base_addr = board+A2065_LANCE;
  597. mem_start = board+A2065_RAM;
  598. r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
  599. "Am7990");
  600. if (!r1)
  601. return -EBUSY;
  602. r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
  603. if (!r2) {
  604. release_resource(r1);
  605. return -EBUSY;
  606. }
  607. dev = alloc_etherdev(sizeof(struct lance_private));
  608. if (dev == NULL) {
  609. release_resource(r1);
  610. release_resource(r2);
  611. return -ENOMEM;
  612. }
  613. SET_MODULE_OWNER(dev);
  614. priv = netdev_priv(dev);
  615. r1->name = dev->name;
  616. r2->name = dev->name;
  617. dev->dev_addr[0] = 0x00;
  618. if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
  619. dev->dev_addr[1] = 0x80;
  620. dev->dev_addr[2] = 0x10;
  621. } else { /* Ameristar */
  622. dev->dev_addr[1] = 0x00;
  623. dev->dev_addr[2] = 0x9f;
  624. }
  625. dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
  626. dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
  627. dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
  628. dev->base_addr = ZTWO_VADDR(base_addr);
  629. dev->mem_start = ZTWO_VADDR(mem_start);
  630. dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
  631. priv->ll = (volatile struct lance_regs *)dev->base_addr;
  632. priv->init_block = (struct lance_init_block *)dev->mem_start;
  633. priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
  634. priv->auto_select = 0;
  635. priv->busmaster_regval = LE_C3_BSWP;
  636. priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  637. priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  638. priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
  639. priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
  640. dev->open = &lance_open;
  641. dev->stop = &lance_close;
  642. dev->hard_start_xmit = &lance_start_xmit;
  643. dev->tx_timeout = &lance_tx_timeout;
  644. dev->watchdog_timeo = 5*HZ;
  645. dev->get_stats = &lance_get_stats;
  646. dev->set_multicast_list = &lance_set_multicast;
  647. dev->dma = 0;
  648. init_timer(&priv->multicast_timer);
  649. priv->multicast_timer.data = (unsigned long) dev;
  650. priv->multicast_timer.function =
  651. (void (*)(unsigned long)) &lance_set_multicast;
  652. err = register_netdev(dev);
  653. if (err) {
  654. release_resource(r1);
  655. release_resource(r2);
  656. free_netdev(dev);
  657. return err;
  658. }
  659. zorro_set_drvdata(z, dev);
  660. printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address "
  661. "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
  662. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  663. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  664. return 0;
  665. }
  666. static void __devexit a2065_remove_one(struct zorro_dev *z)
  667. {
  668. struct net_device *dev = zorro_get_drvdata(z);
  669. unregister_netdev(dev);
  670. release_mem_region(ZTWO_PADDR(dev->base_addr),
  671. sizeof(struct lance_regs));
  672. release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
  673. free_netdev(dev);
  674. }
  675. static int __init a2065_init_module(void)
  676. {
  677. return zorro_register_driver(&a2065_driver);
  678. }
  679. static void __exit a2065_cleanup_module(void)
  680. {
  681. zorro_unregister_driver(&a2065_driver);
  682. }
  683. module_init(a2065_init_module);
  684. module_exit(a2065_cleanup_module);
  685. MODULE_LICENSE("GPL");