a2065.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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
  359. lance_interrupt (int irq, void *dev_id, struct pt_regs *regs)
  360. {
  361. struct net_device *dev;
  362. struct lance_private *lp;
  363. volatile struct lance_regs *ll;
  364. int csr0;
  365. dev = (struct net_device *) dev_id;
  366. lp = netdev_priv(dev);
  367. ll = lp->ll;
  368. ll->rap = LE_CSR0; /* LANCE Controller Status */
  369. csr0 = ll->rdp;
  370. if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
  371. return IRQ_NONE; /* been generated by the Lance. */
  372. /* Acknowledge all the interrupt sources ASAP */
  373. ll->rdp = csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|
  374. LE_C0_INIT);
  375. if ((csr0 & LE_C0_ERR)) {
  376. /* Clear the error condition */
  377. ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
  378. }
  379. if (csr0 & LE_C0_RINT)
  380. lance_rx (dev);
  381. if (csr0 & LE_C0_TINT)
  382. lance_tx (dev);
  383. /* Log misc errors. */
  384. if (csr0 & LE_C0_BABL)
  385. lp->stats.tx_errors++; /* Tx babble. */
  386. if (csr0 & LE_C0_MISS)
  387. lp->stats.rx_errors++; /* Missed a Rx frame. */
  388. if (csr0 & LE_C0_MERR) {
  389. printk(KERN_ERR "%s: Bus master arbitration failure, status "
  390. "%4.4x.\n", dev->name, csr0);
  391. /* Restart the chip. */
  392. ll->rdp = LE_C0_STRT;
  393. }
  394. if (netif_queue_stopped(dev) && TX_BUFFS_AVAIL > 0)
  395. netif_wake_queue(dev);
  396. ll->rap = LE_CSR0;
  397. ll->rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|
  398. LE_C0_IDON|LE_C0_INEA;
  399. return IRQ_HANDLED;
  400. }
  401. struct net_device *last_dev = 0;
  402. static int lance_open (struct net_device *dev)
  403. {
  404. struct lance_private *lp = netdev_priv(dev);
  405. volatile struct lance_regs *ll = lp->ll;
  406. int ret;
  407. last_dev = dev;
  408. /* Stop the Lance */
  409. ll->rap = LE_CSR0;
  410. ll->rdp = LE_C0_STOP;
  411. /* Install the Interrupt handler */
  412. ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED,
  413. dev->name, dev);
  414. if (ret) return ret;
  415. load_csrs (lp);
  416. lance_init_ring (dev);
  417. netif_start_queue(dev);
  418. return init_restart_lance (lp);
  419. }
  420. static int lance_close (struct net_device *dev)
  421. {
  422. struct lance_private *lp = netdev_priv(dev);
  423. volatile struct lance_regs *ll = lp->ll;
  424. netif_stop_queue(dev);
  425. del_timer_sync(&lp->multicast_timer);
  426. /* Stop the card */
  427. ll->rap = LE_CSR0;
  428. ll->rdp = LE_C0_STOP;
  429. free_irq(IRQ_AMIGA_PORTS, dev);
  430. return 0;
  431. }
  432. static inline int lance_reset (struct net_device *dev)
  433. {
  434. struct lance_private *lp = netdev_priv(dev);
  435. volatile struct lance_regs *ll = lp->ll;
  436. int status;
  437. /* Stop the lance */
  438. ll->rap = LE_CSR0;
  439. ll->rdp = LE_C0_STOP;
  440. load_csrs (lp);
  441. lance_init_ring (dev);
  442. dev->trans_start = jiffies;
  443. netif_start_queue(dev);
  444. status = init_restart_lance (lp);
  445. #ifdef DEBUG_DRIVER
  446. printk(KERN_DEBUG "Lance restart=%d\n", status);
  447. #endif
  448. return status;
  449. }
  450. static void lance_tx_timeout(struct net_device *dev)
  451. {
  452. struct lance_private *lp = netdev_priv(dev);
  453. volatile struct lance_regs *ll = lp->ll;
  454. printk(KERN_ERR "%s: transmit timed out, status %04x, reset\n",
  455. dev->name, ll->rdp);
  456. lance_reset(dev);
  457. netif_wake_queue(dev);
  458. }
  459. static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
  460. {
  461. struct lance_private *lp = netdev_priv(dev);
  462. volatile struct lance_regs *ll = lp->ll;
  463. volatile struct lance_init_block *ib = lp->init_block;
  464. int entry, skblen, len;
  465. int status = 0;
  466. static int outs;
  467. unsigned long flags;
  468. skblen = skb->len;
  469. len = skblen;
  470. if (len < ETH_ZLEN) {
  471. len = ETH_ZLEN;
  472. if (skb_padto(skb, ETH_ZLEN))
  473. return 0;
  474. }
  475. local_irq_save(flags);
  476. if (!TX_BUFFS_AVAIL){
  477. local_irq_restore(flags);
  478. return -1;
  479. }
  480. #ifdef DEBUG_DRIVER
  481. /* dump the packet */
  482. {
  483. int i;
  484. for (i = 0; i < 64; i++) {
  485. if ((i % 16) == 0)
  486. printk("\n" KERN_DEBUG);
  487. printk ("%2.2x ", skb->data [i]);
  488. }
  489. printk("\n");
  490. }
  491. #endif
  492. entry = lp->tx_new & lp->tx_ring_mod_mask;
  493. ib->btx_ring [entry].length = (-len) | 0xf000;
  494. ib->btx_ring [entry].misc = 0;
  495. memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
  496. /* Clear the slack of the packet, do I need this? */
  497. if (len != skblen)
  498. memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
  499. /* Now, give the packet to the lance */
  500. ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
  501. lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
  502. outs++;
  503. if (TX_BUFFS_AVAIL <= 0)
  504. netif_stop_queue(dev);
  505. /* Kick the lance: transmit now */
  506. ll->rdp = LE_C0_INEA | LE_C0_TDMD;
  507. dev->trans_start = jiffies;
  508. dev_kfree_skb (skb);
  509. local_irq_restore(flags);
  510. return status;
  511. }
  512. static struct net_device_stats *lance_get_stats (struct net_device *dev)
  513. {
  514. struct lance_private *lp = netdev_priv(dev);
  515. return &lp->stats;
  516. }
  517. /* taken from the depca driver */
  518. static void lance_load_multicast (struct net_device *dev)
  519. {
  520. struct lance_private *lp = netdev_priv(dev);
  521. volatile struct lance_init_block *ib = lp->init_block;
  522. volatile u16 *mcast_table = (u16 *)&ib->filter;
  523. struct dev_mc_list *dmi=dev->mc_list;
  524. char *addrs;
  525. int i;
  526. u32 crc;
  527. /* set all multicast bits */
  528. if (dev->flags & IFF_ALLMULTI){
  529. ib->filter [0] = 0xffffffff;
  530. ib->filter [1] = 0xffffffff;
  531. return;
  532. }
  533. /* clear the multicast filter */
  534. ib->filter [0] = 0;
  535. ib->filter [1] = 0;
  536. /* Add addresses */
  537. for (i = 0; i < dev->mc_count; i++){
  538. addrs = dmi->dmi_addr;
  539. dmi = dmi->next;
  540. /* multicast address? */
  541. if (!(*addrs & 1))
  542. continue;
  543. crc = ether_crc_le(6, addrs);
  544. crc = crc >> 26;
  545. mcast_table [crc >> 4] |= 1 << (crc & 0xf);
  546. }
  547. return;
  548. }
  549. static void lance_set_multicast (struct net_device *dev)
  550. {
  551. struct lance_private *lp = netdev_priv(dev);
  552. volatile struct lance_init_block *ib = lp->init_block;
  553. volatile struct lance_regs *ll = lp->ll;
  554. if (!netif_running(dev))
  555. return;
  556. if (lp->tx_old != lp->tx_new) {
  557. mod_timer(&lp->multicast_timer, jiffies + 4);
  558. netif_wake_queue(dev);
  559. return;
  560. }
  561. netif_stop_queue(dev);
  562. ll->rap = LE_CSR0;
  563. ll->rdp = LE_C0_STOP;
  564. lance_init_ring (dev);
  565. if (dev->flags & IFF_PROMISC) {
  566. ib->mode |= LE_MO_PROM;
  567. } else {
  568. ib->mode &= ~LE_MO_PROM;
  569. lance_load_multicast (dev);
  570. }
  571. load_csrs (lp);
  572. init_restart_lance (lp);
  573. netif_wake_queue(dev);
  574. }
  575. static int __devinit a2065_init_one(struct zorro_dev *z,
  576. const struct zorro_device_id *ent);
  577. static void __devexit a2065_remove_one(struct zorro_dev *z);
  578. static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = {
  579. { ZORRO_PROD_CBM_A2065_1 },
  580. { ZORRO_PROD_CBM_A2065_2 },
  581. { ZORRO_PROD_AMERISTAR_A2065 },
  582. { 0 }
  583. };
  584. static struct zorro_driver a2065_driver = {
  585. .name = "a2065",
  586. .id_table = a2065_zorro_tbl,
  587. .probe = a2065_init_one,
  588. .remove = __devexit_p(a2065_remove_one),
  589. };
  590. static int __devinit a2065_init_one(struct zorro_dev *z,
  591. const struct zorro_device_id *ent)
  592. {
  593. struct net_device *dev;
  594. struct lance_private *priv;
  595. unsigned long board, base_addr, mem_start;
  596. struct resource *r1, *r2;
  597. int err;
  598. board = z->resource.start;
  599. base_addr = board+A2065_LANCE;
  600. mem_start = board+A2065_RAM;
  601. r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
  602. "Am7990");
  603. if (!r1)
  604. return -EBUSY;
  605. r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
  606. if (!r2) {
  607. release_resource(r1);
  608. return -EBUSY;
  609. }
  610. dev = alloc_etherdev(sizeof(struct lance_private));
  611. if (dev == NULL) {
  612. release_resource(r1);
  613. release_resource(r2);
  614. return -ENOMEM;
  615. }
  616. SET_MODULE_OWNER(dev);
  617. priv = netdev_priv(dev);
  618. r1->name = dev->name;
  619. r2->name = dev->name;
  620. dev->dev_addr[0] = 0x00;
  621. if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
  622. dev->dev_addr[1] = 0x80;
  623. dev->dev_addr[2] = 0x10;
  624. } else { /* Ameristar */
  625. dev->dev_addr[1] = 0x00;
  626. dev->dev_addr[2] = 0x9f;
  627. }
  628. dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff;
  629. dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff;
  630. dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
  631. dev->base_addr = ZTWO_VADDR(base_addr);
  632. dev->mem_start = ZTWO_VADDR(mem_start);
  633. dev->mem_end = dev->mem_start+A2065_RAM_SIZE;
  634. priv->ll = (volatile struct lance_regs *)dev->base_addr;
  635. priv->init_block = (struct lance_init_block *)dev->mem_start;
  636. priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
  637. priv->auto_select = 0;
  638. priv->busmaster_regval = LE_C3_BSWP;
  639. priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  640. priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  641. priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
  642. priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
  643. dev->open = &lance_open;
  644. dev->stop = &lance_close;
  645. dev->hard_start_xmit = &lance_start_xmit;
  646. dev->tx_timeout = &lance_tx_timeout;
  647. dev->watchdog_timeo = 5*HZ;
  648. dev->get_stats = &lance_get_stats;
  649. dev->set_multicast_list = &lance_set_multicast;
  650. dev->dma = 0;
  651. init_timer(&priv->multicast_timer);
  652. priv->multicast_timer.data = (unsigned long) dev;
  653. priv->multicast_timer.function =
  654. (void (*)(unsigned long)) &lance_set_multicast;
  655. err = register_netdev(dev);
  656. if (err) {
  657. release_resource(r1);
  658. release_resource(r2);
  659. free_netdev(dev);
  660. return err;
  661. }
  662. zorro_set_drvdata(z, dev);
  663. printk(KERN_INFO "%s: A2065 at 0x%08lx, Ethernet Address "
  664. "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
  665. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  666. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  667. return 0;
  668. }
  669. static void __devexit a2065_remove_one(struct zorro_dev *z)
  670. {
  671. struct net_device *dev = zorro_get_drvdata(z);
  672. unregister_netdev(dev);
  673. release_mem_region(ZTWO_PADDR(dev->base_addr),
  674. sizeof(struct lance_regs));
  675. release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
  676. free_netdev(dev);
  677. }
  678. static int __init a2065_init_module(void)
  679. {
  680. return zorro_register_driver(&a2065_driver);
  681. }
  682. static void __exit a2065_cleanup_module(void)
  683. {
  684. zorro_unregister_driver(&a2065_driver);
  685. }
  686. module_init(a2065_init_module);
  687. module_exit(a2065_cleanup_module);
  688. MODULE_LICENSE("GPL");