a2065.c 20 KB

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