a2065.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  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. dev->stats.rx_dropped++;
  249. rd->mblength = 0;
  250. rd->rmd1_bits = LE_R1_OWN;
  251. lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
  252. return 0;
  253. }
  254. skb_reserve(skb, 2); /* 16 byte align */
  255. skb_put(skb, len); /* make room */
  256. skb_copy_to_linear_data(skb,
  257. (unsigned char *)&ib->rx_buf[lp->rx_new][0],
  258. len);
  259. skb->protocol = eth_type_trans(skb, dev);
  260. netif_rx(skb);
  261. dev->stats.rx_packets++;
  262. dev->stats.rx_bytes += len;
  263. }
  264. /* Return the packet to the pool */
  265. rd->mblength = 0;
  266. rd->rmd1_bits = LE_R1_OWN;
  267. lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
  268. }
  269. return 0;
  270. }
  271. static int lance_tx(struct net_device *dev)
  272. {
  273. struct lance_private *lp = netdev_priv(dev);
  274. volatile struct lance_init_block *ib = lp->init_block;
  275. volatile struct lance_regs *ll = lp->ll;
  276. volatile struct lance_tx_desc *td;
  277. int i, j;
  278. int status;
  279. /* csr0 is 2f3 */
  280. ll->rdp = LE_C0_TINT | LE_C0_INEA;
  281. /* csr0 is 73 */
  282. j = lp->tx_old;
  283. for (i = j; i != lp->tx_new; i = j) {
  284. td = &ib->btx_ring[i];
  285. /* If we hit a packet not owned by us, stop */
  286. if (td->tmd1_bits & LE_T1_OWN)
  287. break;
  288. if (td->tmd1_bits & LE_T1_ERR) {
  289. status = td->misc;
  290. dev->stats.tx_errors++;
  291. if (status & LE_T3_RTY)
  292. dev->stats.tx_aborted_errors++;
  293. if (status & LE_T3_LCOL)
  294. dev->stats.tx_window_errors++;
  295. if (status & LE_T3_CLOS) {
  296. dev->stats.tx_carrier_errors++;
  297. if (lp->auto_select) {
  298. lp->tpe = 1 - lp->tpe;
  299. netdev_err(dev, "Carrier Lost, trying %s\n",
  300. lp->tpe ? "TPE" : "AUI");
  301. /* Stop the lance */
  302. ll->rap = LE_CSR0;
  303. ll->rdp = LE_C0_STOP;
  304. lance_init_ring(dev);
  305. load_csrs(lp);
  306. init_restart_lance(lp);
  307. return 0;
  308. }
  309. }
  310. /* buffer errors and underflows turn off
  311. * the transmitter, so restart the adapter
  312. */
  313. if (status & (LE_T3_BUF | LE_T3_UFL)) {
  314. dev->stats.tx_fifo_errors++;
  315. netdev_err(dev, "Tx: ERR_BUF|ERR_UFL, restarting\n");
  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. } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
  325. /* So we don't count the packet more than once. */
  326. td->tmd1_bits &= ~(LE_T1_POK);
  327. /* One collision before packet was sent. */
  328. if (td->tmd1_bits & LE_T1_EONE)
  329. dev->stats.collisions++;
  330. /* More than one collision, be optimistic. */
  331. if (td->tmd1_bits & LE_T1_EMORE)
  332. dev->stats.collisions += 2;
  333. dev->stats.tx_packets++;
  334. }
  335. j = (j + 1) & lp->tx_ring_mod_mask;
  336. }
  337. lp->tx_old = j;
  338. ll->rdp = LE_C0_TINT | LE_C0_INEA;
  339. return 0;
  340. }
  341. static int lance_tx_buffs_avail(struct lance_private *lp)
  342. {
  343. if (lp->tx_old <= lp->tx_new)
  344. return lp->tx_old + lp->tx_ring_mod_mask - lp->tx_new;
  345. return lp->tx_old - lp->tx_new - 1;
  346. }
  347. static irqreturn_t lance_interrupt(int irq, void *dev_id)
  348. {
  349. struct net_device *dev = dev_id;
  350. struct lance_private *lp = netdev_priv(dev);
  351. volatile struct lance_regs *ll = lp->ll;
  352. int csr0;
  353. ll->rap = LE_CSR0; /* LANCE Controller Status */
  354. csr0 = ll->rdp;
  355. if (!(csr0 & LE_C0_INTR)) /* Check if any interrupt has */
  356. return IRQ_NONE; /* been generated by the Lance. */
  357. /* Acknowledge all the interrupt sources ASAP */
  358. ll->rdp = csr0 & ~(LE_C0_INEA | LE_C0_TDMD | LE_C0_STOP | LE_C0_STRT |
  359. LE_C0_INIT);
  360. if (csr0 & LE_C0_ERR) {
  361. /* Clear the error condition */
  362. ll->rdp = LE_C0_BABL | LE_C0_ERR | LE_C0_MISS | LE_C0_INEA;
  363. }
  364. if (csr0 & LE_C0_RINT)
  365. lance_rx(dev);
  366. if (csr0 & LE_C0_TINT)
  367. lance_tx(dev);
  368. /* Log misc errors. */
  369. if (csr0 & LE_C0_BABL)
  370. dev->stats.tx_errors++; /* Tx babble. */
  371. if (csr0 & LE_C0_MISS)
  372. dev->stats.rx_errors++; /* Missed a Rx frame. */
  373. if (csr0 & LE_C0_MERR) {
  374. netdev_err(dev, "Bus master arbitration failure, status %04x\n",
  375. csr0);
  376. /* Restart the chip. */
  377. ll->rdp = LE_C0_STRT;
  378. }
  379. if (netif_queue_stopped(dev) && lance_tx_buffs_avail(lp) > 0)
  380. netif_wake_queue(dev);
  381. ll->rap = LE_CSR0;
  382. ll->rdp = (LE_C0_BABL | LE_C0_CERR | LE_C0_MISS | LE_C0_MERR |
  383. LE_C0_IDON | LE_C0_INEA);
  384. return IRQ_HANDLED;
  385. }
  386. static int lance_open(struct net_device *dev)
  387. {
  388. struct lance_private *lp = netdev_priv(dev);
  389. volatile struct lance_regs *ll = lp->ll;
  390. int ret;
  391. /* Stop the Lance */
  392. ll->rap = LE_CSR0;
  393. ll->rdp = LE_C0_STOP;
  394. /* Install the Interrupt handler */
  395. ret = request_irq(IRQ_AMIGA_PORTS, lance_interrupt, IRQF_SHARED,
  396. dev->name, dev);
  397. if (ret)
  398. return ret;
  399. load_csrs(lp);
  400. lance_init_ring(dev);
  401. netif_start_queue(dev);
  402. return init_restart_lance(lp);
  403. }
  404. static int lance_close(struct net_device *dev)
  405. {
  406. struct lance_private *lp = netdev_priv(dev);
  407. volatile struct lance_regs *ll = lp->ll;
  408. netif_stop_queue(dev);
  409. del_timer_sync(&lp->multicast_timer);
  410. /* Stop the card */
  411. ll->rap = LE_CSR0;
  412. ll->rdp = LE_C0_STOP;
  413. free_irq(IRQ_AMIGA_PORTS, dev);
  414. return 0;
  415. }
  416. static inline int lance_reset(struct net_device *dev)
  417. {
  418. struct lance_private *lp = netdev_priv(dev);
  419. volatile struct lance_regs *ll = lp->ll;
  420. int status;
  421. /* Stop the lance */
  422. ll->rap = LE_CSR0;
  423. ll->rdp = LE_C0_STOP;
  424. load_csrs(lp);
  425. lance_init_ring(dev);
  426. dev->trans_start = jiffies; /* prevent tx timeout */
  427. netif_start_queue(dev);
  428. status = init_restart_lance(lp);
  429. netdev_dbg(dev, "Lance restart=%d\n", status);
  430. return status;
  431. }
  432. static void lance_tx_timeout(struct net_device *dev)
  433. {
  434. struct lance_private *lp = netdev_priv(dev);
  435. volatile struct lance_regs *ll = lp->ll;
  436. netdev_err(dev, "transmit timed out, status %04x, reset\n", ll->rdp);
  437. lance_reset(dev);
  438. netif_wake_queue(dev);
  439. }
  440. static netdev_tx_t lance_start_xmit(struct sk_buff *skb,
  441. struct net_device *dev)
  442. {
  443. struct lance_private *lp = netdev_priv(dev);
  444. volatile struct lance_regs *ll = lp->ll;
  445. volatile struct lance_init_block *ib = lp->init_block;
  446. int entry, skblen;
  447. int status = NETDEV_TX_OK;
  448. unsigned long flags;
  449. if (skb_padto(skb, ETH_ZLEN))
  450. return NETDEV_TX_OK;
  451. skblen = max_t(unsigned, skb->len, ETH_ZLEN);
  452. local_irq_save(flags);
  453. if (!lance_tx_buffs_avail(lp)) {
  454. local_irq_restore(flags);
  455. return NETDEV_TX_LOCKED;
  456. }
  457. #ifdef DEBUG
  458. /* dump the packet */
  459. print_hex_dump(KERN_DEBUG, "skb->data: ", DUMP_PREFIX_NONE,
  460. 16, 1, skb->data, 64, true);
  461. #endif
  462. entry = lp->tx_new & lp->tx_ring_mod_mask;
  463. ib->btx_ring[entry].length = (-skblen) | 0xf000;
  464. ib->btx_ring[entry].misc = 0;
  465. skb_copy_from_linear_data(skb, (void *)&ib->tx_buf[entry][0], skblen);
  466. /* Now, give the packet to the lance */
  467. ib->btx_ring[entry].tmd1_bits = (LE_T1_POK | LE_T1_OWN);
  468. lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
  469. dev->stats.tx_bytes += skblen;
  470. if (lance_tx_buffs_avail(lp) <= 0)
  471. netif_stop_queue(dev);
  472. /* Kick the lance: transmit now */
  473. ll->rdp = LE_C0_INEA | LE_C0_TDMD;
  474. dev_kfree_skb(skb);
  475. local_irq_restore(flags);
  476. return status;
  477. }
  478. /* taken from the depca driver */
  479. static void lance_load_multicast(struct net_device *dev)
  480. {
  481. struct lance_private *lp = netdev_priv(dev);
  482. volatile struct lance_init_block *ib = lp->init_block;
  483. volatile u16 *mcast_table = (u16 *)&ib->filter;
  484. struct netdev_hw_addr *ha;
  485. u32 crc;
  486. /* set all multicast bits */
  487. if (dev->flags & IFF_ALLMULTI) {
  488. ib->filter[0] = 0xffffffff;
  489. ib->filter[1] = 0xffffffff;
  490. return;
  491. }
  492. /* clear the multicast filter */
  493. ib->filter[0] = 0;
  494. ib->filter[1] = 0;
  495. /* Add addresses */
  496. netdev_for_each_mc_addr(ha, dev) {
  497. crc = ether_crc_le(6, ha->addr);
  498. crc = crc >> 26;
  499. mcast_table[crc >> 4] |= 1 << (crc & 0xf);
  500. }
  501. }
  502. static void lance_set_multicast(struct net_device *dev)
  503. {
  504. struct lance_private *lp = netdev_priv(dev);
  505. volatile struct lance_init_block *ib = lp->init_block;
  506. volatile struct lance_regs *ll = lp->ll;
  507. if (!netif_running(dev))
  508. return;
  509. if (lp->tx_old != lp->tx_new) {
  510. mod_timer(&lp->multicast_timer, jiffies + 4);
  511. netif_wake_queue(dev);
  512. return;
  513. }
  514. netif_stop_queue(dev);
  515. ll->rap = LE_CSR0;
  516. ll->rdp = LE_C0_STOP;
  517. lance_init_ring(dev);
  518. if (dev->flags & IFF_PROMISC) {
  519. ib->mode |= LE_MO_PROM;
  520. } else {
  521. ib->mode &= ~LE_MO_PROM;
  522. lance_load_multicast(dev);
  523. }
  524. load_csrs(lp);
  525. init_restart_lance(lp);
  526. netif_wake_queue(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 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_change_mtu = eth_change_mtu,
  552. .ndo_set_mac_address = eth_mac_addr,
  553. };
  554. static int a2065_init_one(struct zorro_dev *z,
  555. const struct zorro_device_id *ent)
  556. {
  557. struct net_device *dev;
  558. struct lance_private *priv;
  559. unsigned long board = z->resource.start;
  560. unsigned long base_addr = board + A2065_LANCE;
  561. unsigned long mem_start = board + A2065_RAM;
  562. struct resource *r1, *r2;
  563. int err;
  564. r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
  565. "Am7990");
  566. if (!r1)
  567. return -EBUSY;
  568. r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
  569. if (!r2) {
  570. release_mem_region(base_addr, sizeof(struct lance_regs));
  571. return -EBUSY;
  572. }
  573. dev = alloc_etherdev(sizeof(struct lance_private));
  574. if (dev == NULL) {
  575. release_mem_region(base_addr, sizeof(struct lance_regs));
  576. release_mem_region(mem_start, A2065_RAM_SIZE);
  577. return -ENOMEM;
  578. }
  579. priv = netdev_priv(dev);
  580. r1->name = dev->name;
  581. r2->name = dev->name;
  582. dev->dev_addr[0] = 0x00;
  583. if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
  584. dev->dev_addr[1] = 0x80;
  585. dev->dev_addr[2] = 0x10;
  586. } else { /* Ameristar */
  587. dev->dev_addr[1] = 0x00;
  588. dev->dev_addr[2] = 0x9f;
  589. }
  590. dev->dev_addr[3] = (z->rom.er_SerialNumber >> 16) & 0xff;
  591. dev->dev_addr[4] = (z->rom.er_SerialNumber >> 8) & 0xff;
  592. dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
  593. dev->base_addr = ZTWO_VADDR(base_addr);
  594. dev->mem_start = ZTWO_VADDR(mem_start);
  595. dev->mem_end = dev->mem_start + A2065_RAM_SIZE;
  596. priv->ll = (volatile struct lance_regs *)dev->base_addr;
  597. priv->init_block = (struct lance_init_block *)dev->mem_start;
  598. priv->lance_init_block = (struct lance_init_block *)A2065_RAM;
  599. priv->auto_select = 0;
  600. priv->busmaster_regval = LE_C3_BSWP;
  601. priv->lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
  602. priv->lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
  603. priv->rx_ring_mod_mask = RX_RING_MOD_MASK;
  604. priv->tx_ring_mod_mask = TX_RING_MOD_MASK;
  605. dev->netdev_ops = &lance_netdev_ops;
  606. dev->watchdog_timeo = 5*HZ;
  607. dev->dma = 0;
  608. init_timer(&priv->multicast_timer);
  609. priv->multicast_timer.data = (unsigned long) dev;
  610. priv->multicast_timer.function =
  611. (void (*)(unsigned long))lance_set_multicast;
  612. err = register_netdev(dev);
  613. if (err) {
  614. release_mem_region(base_addr, sizeof(struct lance_regs));
  615. release_mem_region(mem_start, A2065_RAM_SIZE);
  616. free_netdev(dev);
  617. return err;
  618. }
  619. zorro_set_drvdata(z, dev);
  620. netdev_info(dev, "A2065 at 0x%08lx, Ethernet Address %pM\n",
  621. board, dev->dev_addr);
  622. return 0;
  623. }
  624. static void a2065_remove_one(struct zorro_dev *z)
  625. {
  626. struct net_device *dev = zorro_get_drvdata(z);
  627. unregister_netdev(dev);
  628. release_mem_region(ZTWO_PADDR(dev->base_addr),
  629. sizeof(struct lance_regs));
  630. release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
  631. free_netdev(dev);
  632. }
  633. static int __init a2065_init_module(void)
  634. {
  635. return zorro_register_driver(&a2065_driver);
  636. }
  637. static void __exit a2065_cleanup_module(void)
  638. {
  639. zorro_unregister_driver(&a2065_driver);
  640. }
  641. module_init(a2065_init_module);
  642. module_exit(a2065_cleanup_module);
  643. MODULE_LICENSE("GPL");