a2065.c 20 KB

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