a2065.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  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/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. #ifdef CONFIG_SUNLANCE
  101. struct Linux_SBus_DMA *ledma; /* if set this points to ledma and arch=4m */
  102. int burst_sizes; /* ledma SBus burst sizes */
  103. #endif
  104. struct timer_list multicast_timer;
  105. };
  106. #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
  107. /* Load the CSR registers */
  108. static void load_csrs(struct lance_private *lp)
  109. {
  110. volatile struct lance_regs *ll = lp->ll;
  111. volatile struct lance_init_block *aib = lp->lance_init_block;
  112. int leptr = LANCE_ADDR(aib);
  113. ll->rap = LE_CSR1;
  114. ll->rdp = (leptr & 0xFFFF);
  115. ll->rap = LE_CSR2;
  116. ll->rdp = leptr >> 16;
  117. ll->rap = LE_CSR3;
  118. ll->rdp = lp->busmaster_regval;
  119. /* Point back to csr0 */
  120. ll->rap = LE_CSR0;
  121. }
  122. /* Setup the Lance Rx and Tx rings */
  123. static void lance_init_ring(struct net_device *dev)
  124. {
  125. struct lance_private *lp = netdev_priv(dev);
  126. volatile struct lance_init_block *ib = lp->init_block;
  127. volatile struct lance_init_block *aib = lp->lance_init_block;
  128. /* for LANCE_ADDR computations */
  129. int leptr;
  130. int i;
  131. /* Lock out other processes while setting up hardware */
  132. netif_stop_queue(dev);
  133. lp->rx_new = lp->tx_new = 0;
  134. lp->rx_old = lp->tx_old = 0;
  135. ib->mode = 0;
  136. /* Copy the ethernet address to the lance init block
  137. * Note that on the sparc you need to swap the ethernet address.
  138. */
  139. ib->phys_addr[0] = dev->dev_addr[1];
  140. ib->phys_addr[1] = dev->dev_addr[0];
  141. ib->phys_addr[2] = dev->dev_addr[3];
  142. ib->phys_addr[3] = dev->dev_addr[2];
  143. ib->phys_addr[4] = dev->dev_addr[5];
  144. ib->phys_addr[5] = dev->dev_addr[4];
  145. /* Setup the Tx ring entries */
  146. netdev_dbg(dev, "TX rings:\n");
  147. for (i = 0; i <= 1 << lp->lance_log_tx_bufs; i++) {
  148. leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
  149. ib->btx_ring[i].tmd0 = leptr;
  150. ib->btx_ring[i].tmd1_hadr = leptr >> 16;
  151. ib->btx_ring[i].tmd1_bits = 0;
  152. ib->btx_ring[i].length = 0xf000; /* The ones required by tmd2 */
  153. ib->btx_ring[i].misc = 0;
  154. if (i < 3)
  155. netdev_dbg(dev, "%d: 0x%08x\n", i, leptr);
  156. }
  157. /* Setup the Rx ring entries */
  158. netdev_dbg(dev, "RX rings:\n");
  159. for (i = 0; i < 1 << lp->lance_log_rx_bufs; i++) {
  160. leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
  161. ib->brx_ring[i].rmd0 = leptr;
  162. ib->brx_ring[i].rmd1_hadr = leptr >> 16;
  163. ib->brx_ring[i].rmd1_bits = LE_R1_OWN;
  164. ib->brx_ring[i].length = -RX_BUFF_SIZE | 0xf000;
  165. ib->brx_ring[i].mblength = 0;
  166. if (i < 3)
  167. netdev_dbg(dev, "%d: 0x%08x\n", i, leptr);
  168. }
  169. /* Setup the initialization block */
  170. /* Setup rx descriptor pointer */
  171. leptr = LANCE_ADDR(&aib->brx_ring);
  172. ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
  173. ib->rx_ptr = leptr;
  174. netdev_dbg(dev, "RX ptr: %08x\n", leptr);
  175. /* Setup tx descriptor pointer */
  176. leptr = LANCE_ADDR(&aib->btx_ring);
  177. ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
  178. ib->tx_ptr = leptr;
  179. netdev_dbg(dev, "TX ptr: %08x\n", leptr);
  180. /* Clear the multicast filter */
  181. ib->filter[0] = 0;
  182. ib->filter[1] = 0;
  183. }
  184. static int init_restart_lance(struct lance_private *lp)
  185. {
  186. volatile struct lance_regs *ll = lp->ll;
  187. int i;
  188. ll->rap = LE_CSR0;
  189. ll->rdp = LE_C0_INIT;
  190. /* Wait for the lance to complete initialization */
  191. for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
  192. barrier();
  193. if ((i == 100) || (ll->rdp & LE_C0_ERR)) {
  194. pr_err("unopened after %d ticks, csr0=%04x\n", i, ll->rdp);
  195. return -EIO;
  196. }
  197. /* Clear IDON by writing a "1", enable interrupts and start lance */
  198. ll->rdp = LE_C0_IDON;
  199. ll->rdp = LE_C0_INEA | LE_C0_STRT;
  200. return 0;
  201. }
  202. static int lance_rx(struct net_device *dev)
  203. {
  204. struct lance_private *lp = netdev_priv(dev);
  205. volatile struct lance_init_block *ib = lp->init_block;
  206. volatile struct lance_regs *ll = lp->ll;
  207. volatile struct lance_rx_desc *rd;
  208. unsigned char bits;
  209. #ifdef TEST_HITS
  210. int i;
  211. char buf[RX_RING_SIZE + 1];
  212. for (i = 0; i < RX_RING_SIZE; i++) {
  213. char r1_own = ib->brx_ring[i].rmd1_bits & LE_R1_OWN;
  214. if (i == lp->rx_new)
  215. buf[i] = r1_own ? '_' : 'X';
  216. else
  217. buf[i] = r1_own ? '.' : '1';
  218. }
  219. buf[RX_RING_SIZE] = 0;
  220. pr_debug("RxRing TestHits: [%s]\n", buf);
  221. #endif
  222. ll->rdp = LE_C0_RINT | LE_C0_INEA;
  223. for (rd = &ib->brx_ring[lp->rx_new];
  224. !((bits = rd->rmd1_bits) & LE_R1_OWN);
  225. rd = &ib->brx_ring[lp->rx_new]) {
  226. /* We got an incomplete frame? */
  227. if ((bits & LE_R1_POK) != LE_R1_POK) {
  228. dev->stats.rx_over_errors++;
  229. dev->stats.rx_errors++;
  230. continue;
  231. } else if (bits & LE_R1_ERR) {
  232. /* Count only the end frame as a rx error,
  233. * not the beginning
  234. */
  235. if (bits & LE_R1_BUF)
  236. dev->stats.rx_fifo_errors++;
  237. if (bits & LE_R1_CRC)
  238. dev->stats.rx_crc_errors++;
  239. if (bits & LE_R1_OFL)
  240. dev->stats.rx_over_errors++;
  241. if (bits & LE_R1_FRA)
  242. dev->stats.rx_frame_errors++;
  243. if (bits & LE_R1_EOP)
  244. dev->stats.rx_errors++;
  245. } else {
  246. int len = (rd->mblength & 0xfff) - 4;
  247. struct sk_buff *skb = netdev_alloc_skb(dev, len + 2);
  248. if (!skb) {
  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 a2065_init_one(struct zorro_dev *z,
  530. const struct zorro_device_id *ent);
  531. static void a2065_remove_one(struct zorro_dev *z);
  532. static struct zorro_device_id a2065_zorro_tbl[] = {
  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 = 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 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. u32 serial;
  565. int err;
  566. r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
  567. "Am7990");
  568. if (!r1)
  569. return -EBUSY;
  570. r2 = request_mem_region(mem_start, A2065_RAM_SIZE, "RAM");
  571. if (!r2) {
  572. release_mem_region(base_addr, sizeof(struct lance_regs));
  573. return -EBUSY;
  574. }
  575. dev = alloc_etherdev(sizeof(struct lance_private));
  576. if (dev == NULL) {
  577. release_mem_region(base_addr, sizeof(struct lance_regs));
  578. release_mem_region(mem_start, A2065_RAM_SIZE);
  579. return -ENOMEM;
  580. }
  581. priv = netdev_priv(dev);
  582. r1->name = dev->name;
  583. r2->name = dev->name;
  584. serial = be32_to_cpu(z->rom.er_SerialNumber);
  585. dev->dev_addr[0] = 0x00;
  586. if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
  587. dev->dev_addr[1] = 0x80;
  588. dev->dev_addr[2] = 0x10;
  589. } else { /* Ameristar */
  590. dev->dev_addr[1] = 0x00;
  591. dev->dev_addr[2] = 0x9f;
  592. }
  593. dev->dev_addr[3] = (serial >> 16) & 0xff;
  594. dev->dev_addr[4] = (serial >> 8) & 0xff;
  595. dev->dev_addr[5] = serial & 0xff;
  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. dev->netdev_ops = &lance_netdev_ops;
  609. dev->watchdog_timeo = 5*HZ;
  610. dev->dma = 0;
  611. init_timer(&priv->multicast_timer);
  612. priv->multicast_timer.data = (unsigned long) dev;
  613. priv->multicast_timer.function =
  614. (void (*)(unsigned long))lance_set_multicast;
  615. err = register_netdev(dev);
  616. if (err) {
  617. release_mem_region(base_addr, sizeof(struct lance_regs));
  618. release_mem_region(mem_start, A2065_RAM_SIZE);
  619. free_netdev(dev);
  620. return err;
  621. }
  622. zorro_set_drvdata(z, dev);
  623. netdev_info(dev, "A2065 at 0x%08lx, Ethernet Address %pM\n",
  624. board, dev->dev_addr);
  625. return 0;
  626. }
  627. static void a2065_remove_one(struct zorro_dev *z)
  628. {
  629. struct net_device *dev = zorro_get_drvdata(z);
  630. unregister_netdev(dev);
  631. release_mem_region(ZTWO_PADDR(dev->base_addr),
  632. sizeof(struct lance_regs));
  633. release_mem_region(ZTWO_PADDR(dev->mem_start), A2065_RAM_SIZE);
  634. free_netdev(dev);
  635. }
  636. static int __init a2065_init_module(void)
  637. {
  638. return zorro_register_driver(&a2065_driver);
  639. }
  640. static void __exit a2065_cleanup_module(void)
  641. {
  642. zorro_unregister_driver(&a2065_driver);
  643. }
  644. module_init(a2065_init_module);
  645. module_exit(a2065_cleanup_module);
  646. MODULE_LICENSE("GPL");