a2065.c 20 KB

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