a2065.c 20 KB

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