7990.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * 7990.c -- LANCE ethernet IC generic routines.
  3. * This is an attempt to separate out the bits of various ethernet
  4. * drivers that are common because they all use the AMD 7990 LANCE
  5. * (Local Area Network Controller for Ethernet) chip.
  6. *
  7. * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
  8. *
  9. * Most of this stuff was obtained by looking at other LANCE drivers,
  10. * in particular a2065.[ch]. The AMD C-LANCE datasheet was also helpful.
  11. * NB: this was made easy by the fact that Jes Sorensen had cleaned up
  12. * most of a2025 and sunlance with the aim of merging them, so the
  13. * common code was pretty obvious.
  14. */
  15. #include <linux/crc32.h>
  16. #include <linux/delay.h>
  17. #include <linux/errno.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/fcntl.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/ioport.h>
  26. #include <linux/in.h>
  27. #include <linux/route.h>
  28. #include <linux/string.h>
  29. #include <linux/skbuff.h>
  30. #include <asm/irq.h>
  31. /* Used for the temporal inet entries and routing */
  32. #include <linux/socket.h>
  33. #include <linux/bitops.h>
  34. #include <asm/io.h>
  35. #include <asm/dma.h>
  36. #include <asm/pgtable.h>
  37. #ifdef CONFIG_HP300
  38. #include <asm/blinken.h>
  39. #endif
  40. #include "7990.h"
  41. #define WRITERAP(lp, x) out_be16(lp->base + LANCE_RAP, (x))
  42. #define WRITERDP(lp, x) out_be16(lp->base + LANCE_RDP, (x))
  43. #define READRDP(lp) in_be16(lp->base + LANCE_RDP)
  44. #if IS_ENABLED(CONFIG_HPLANCE)
  45. #include "hplance.h"
  46. #undef WRITERAP
  47. #undef WRITERDP
  48. #undef READRDP
  49. #if IS_ENABLED(CONFIG_MVME147_NET)
  50. /* Lossage Factor Nine, Mr Sulu. */
  51. #define WRITERAP(lp, x) (lp->writerap(lp, x))
  52. #define WRITERDP(lp, x) (lp->writerdp(lp, x))
  53. #define READRDP(lp) (lp->readrdp(lp))
  54. #else
  55. /* These inlines can be used if only CONFIG_HPLANCE is defined */
  56. static inline void WRITERAP(struct lance_private *lp, __u16 value)
  57. {
  58. do {
  59. out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
  60. } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
  61. }
  62. static inline void WRITERDP(struct lance_private *lp, __u16 value)
  63. {
  64. do {
  65. out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
  66. } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
  67. }
  68. static inline __u16 READRDP(struct lance_private *lp)
  69. {
  70. __u16 value;
  71. do {
  72. value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
  73. } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
  74. return value;
  75. }
  76. #endif
  77. #endif /* IS_ENABLED(CONFIG_HPLANCE) */
  78. /* debugging output macros, various flavours */
  79. /* #define TEST_HITS */
  80. #ifdef UNDEF
  81. #define PRINT_RINGS() \
  82. do { \
  83. int t; \
  84. for (t = 0; t < RX_RING_SIZE; t++) { \
  85. printk("R%d: @(%02X %04X) len %04X, mblen %04X, bits %02X\n", \
  86. t, ib->brx_ring[t].rmd1_hadr, ib->brx_ring[t].rmd0, \
  87. ib->brx_ring[t].length, \
  88. ib->brx_ring[t].mblength, ib->brx_ring[t].rmd1_bits); \
  89. } \
  90. for (t = 0; t < TX_RING_SIZE; t++) { \
  91. printk("T%d: @(%02X %04X) len %04X, misc %04X, bits %02X\n", \
  92. t, ib->btx_ring[t].tmd1_hadr, ib->btx_ring[t].tmd0, \
  93. ib->btx_ring[t].length, \
  94. ib->btx_ring[t].misc, ib->btx_ring[t].tmd1_bits); \
  95. } \
  96. } while (0)
  97. #else
  98. #define PRINT_RINGS()
  99. #endif
  100. /* Load the CSR registers. The LANCE has to be STOPped when we do this! */
  101. static void load_csrs(struct lance_private *lp)
  102. {
  103. volatile struct lance_init_block *aib = lp->lance_init_block;
  104. int leptr;
  105. leptr = LANCE_ADDR(aib);
  106. WRITERAP(lp, LE_CSR1); /* load address of init block */
  107. WRITERDP(lp, leptr & 0xFFFF);
  108. WRITERAP(lp, LE_CSR2);
  109. WRITERDP(lp, leptr >> 16);
  110. WRITERAP(lp, LE_CSR3);
  111. WRITERDP(lp, lp->busmaster_regval); /* set byteswap/ALEctrl/byte ctrl */
  112. /* Point back to csr0 */
  113. WRITERAP(lp, LE_CSR0);
  114. }
  115. /* #define to 0 or 1 appropriately */
  116. #define DEBUG_IRING 0
  117. /* Set up the Lance Rx and Tx rings and the init block */
  118. static void lance_init_ring(struct net_device *dev)
  119. {
  120. struct lance_private *lp = netdev_priv(dev);
  121. volatile struct lance_init_block *ib = lp->init_block;
  122. volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
  123. int leptr;
  124. int i;
  125. aib = lp->lance_init_block;
  126. lp->rx_new = lp->tx_new = 0;
  127. lp->rx_old = lp->tx_old = 0;
  128. ib->mode = LE_MO_PROM; /* normal, enable Tx & Rx */
  129. /* Copy the ethernet address to the lance init block
  130. * Notice that we do a byteswap if we're big endian.
  131. * [I think this is the right criterion; at least, sunlance,
  132. * a2065 and atarilance do the byteswap and lance.c (PC) doesn't.
  133. * However, the datasheet says that the BSWAP bit doesn't affect
  134. * the init block, so surely it should be low byte first for
  135. * everybody? Um.]
  136. * We could define the ib->physaddr as three 16bit values and
  137. * use (addr[1] << 8) | addr[0] & co, but this is more efficient.
  138. */
  139. #ifdef __BIG_ENDIAN
  140. ib->phys_addr[0] = dev->dev_addr[1];
  141. ib->phys_addr[1] = dev->dev_addr[0];
  142. ib->phys_addr[2] = dev->dev_addr[3];
  143. ib->phys_addr[3] = dev->dev_addr[2];
  144. ib->phys_addr[4] = dev->dev_addr[5];
  145. ib->phys_addr[5] = dev->dev_addr[4];
  146. #else
  147. for (i = 0; i < 6; i++)
  148. ib->phys_addr[i] = dev->dev_addr[i];
  149. #endif
  150. if (DEBUG_IRING)
  151. printk("TX rings:\n");
  152. lp->tx_full = 0;
  153. /* Setup the Tx ring entries */
  154. for (i = 0; i < (1 << lp->lance_log_tx_bufs); i++) {
  155. leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
  156. ib->btx_ring[i].tmd0 = leptr;
  157. ib->btx_ring[i].tmd1_hadr = leptr >> 16;
  158. ib->btx_ring[i].tmd1_bits = 0;
  159. ib->btx_ring[i].length = 0xf000; /* The ones required by tmd2 */
  160. ib->btx_ring[i].misc = 0;
  161. if (DEBUG_IRING)
  162. printk("%d: 0x%8.8x\n", i, leptr);
  163. }
  164. /* Setup the Rx ring entries */
  165. if (DEBUG_IRING)
  166. printk("RX rings:\n");
  167. for (i = 0; i < (1 << lp->lance_log_rx_bufs); i++) {
  168. leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
  169. ib->brx_ring[i].rmd0 = leptr;
  170. ib->brx_ring[i].rmd1_hadr = leptr >> 16;
  171. ib->brx_ring[i].rmd1_bits = LE_R1_OWN;
  172. /* 0xf000 == bits that must be one (reserved, presumably) */
  173. ib->brx_ring[i].length = -RX_BUFF_SIZE | 0xf000;
  174. ib->brx_ring[i].mblength = 0;
  175. if (DEBUG_IRING)
  176. printk("%d: 0x%8.8x\n", i, leptr);
  177. }
  178. /* Setup the initialization block */
  179. /* Setup rx descriptor pointer */
  180. leptr = LANCE_ADDR(&aib->brx_ring);
  181. ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
  182. ib->rx_ptr = leptr;
  183. if (DEBUG_IRING)
  184. printk("RX ptr: %8.8x\n", leptr);
  185. /* Setup tx descriptor pointer */
  186. leptr = LANCE_ADDR(&aib->btx_ring);
  187. ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
  188. ib->tx_ptr = leptr;
  189. if (DEBUG_IRING)
  190. printk("TX ptr: %8.8x\n", leptr);
  191. /* Clear the multicast filter */
  192. ib->filter[0] = 0;
  193. ib->filter[1] = 0;
  194. PRINT_RINGS();
  195. }
  196. /* LANCE must be STOPped before we do this, too... */
  197. static int init_restart_lance(struct lance_private *lp)
  198. {
  199. int i;
  200. WRITERAP(lp, LE_CSR0);
  201. WRITERDP(lp, LE_C0_INIT);
  202. /* Need a hook here for sunlance ledma stuff */
  203. /* Wait for the lance to complete initialization */
  204. for (i = 0; (i < 100) && !(READRDP(lp) & (LE_C0_ERR | LE_C0_IDON)); i++)
  205. barrier();
  206. if ((i == 100) || (READRDP(lp) & LE_C0_ERR)) {
  207. printk("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, READRDP(lp));
  208. return -1;
  209. }
  210. /* Clear IDON by writing a "1", enable interrupts and start lance */
  211. WRITERDP(lp, LE_C0_IDON);
  212. WRITERDP(lp, LE_C0_INEA | LE_C0_STRT);
  213. return 0;
  214. }
  215. static int lance_reset(struct net_device *dev)
  216. {
  217. struct lance_private *lp = netdev_priv(dev);
  218. int status;
  219. /* Stop the lance */
  220. WRITERAP(lp, LE_CSR0);
  221. WRITERDP(lp, LE_C0_STOP);
  222. load_csrs(lp);
  223. lance_init_ring(dev);
  224. netif_trans_update(dev); /* prevent tx timeout */
  225. status = init_restart_lance(lp);
  226. #ifdef DEBUG_DRIVER
  227. printk("Lance restart=%d\n", status);
  228. #endif
  229. return status;
  230. }
  231. static int lance_rx(struct net_device *dev)
  232. {
  233. struct lance_private *lp = netdev_priv(dev);
  234. volatile struct lance_init_block *ib = lp->init_block;
  235. volatile struct lance_rx_desc *rd;
  236. unsigned char bits;
  237. #ifdef TEST_HITS
  238. int i;
  239. #endif
  240. #ifdef TEST_HITS
  241. printk("[");
  242. for (i = 0; i < RX_RING_SIZE; i++) {
  243. if (i == lp->rx_new)
  244. printk("%s",
  245. ib->brx_ring[i].rmd1_bits & LE_R1_OWN ? "_" : "X");
  246. else
  247. printk("%s",
  248. ib->brx_ring[i].rmd1_bits & LE_R1_OWN ? "." : "1");
  249. }
  250. printk("]");
  251. #endif
  252. #ifdef CONFIG_HP300
  253. blinken_leds(0x40, 0);
  254. #endif
  255. WRITERDP(lp, LE_C0_RINT | LE_C0_INEA); /* ack Rx int, reenable ints */
  256. for (rd = &ib->brx_ring[lp->rx_new]; /* For each Rx ring we own... */
  257. !((bits = rd->rmd1_bits) & LE_R1_OWN);
  258. rd = &ib->brx_ring[lp->rx_new]) {
  259. /* We got an incomplete frame? */
  260. if ((bits & LE_R1_POK) != LE_R1_POK) {
  261. dev->stats.rx_over_errors++;
  262. dev->stats.rx_errors++;
  263. continue;
  264. } else if (bits & LE_R1_ERR) {
  265. /* Count only the end frame as a rx error,
  266. * not the beginning
  267. */
  268. if (bits & LE_R1_BUF)
  269. dev->stats.rx_fifo_errors++;
  270. if (bits & LE_R1_CRC)
  271. dev->stats.rx_crc_errors++;
  272. if (bits & LE_R1_OFL)
  273. dev->stats.rx_over_errors++;
  274. if (bits & LE_R1_FRA)
  275. dev->stats.rx_frame_errors++;
  276. if (bits & LE_R1_EOP)
  277. dev->stats.rx_errors++;
  278. } else {
  279. int len = (rd->mblength & 0xfff) - 4;
  280. struct sk_buff *skb = netdev_alloc_skb(dev, len + 2);
  281. if (!skb) {
  282. dev->stats.rx_dropped++;
  283. rd->mblength = 0;
  284. rd->rmd1_bits = LE_R1_OWN;
  285. lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
  286. return 0;
  287. }
  288. skb_reserve(skb, 2); /* 16 byte align */
  289. skb_put(skb, len); /* make room */
  290. skb_copy_to_linear_data(skb,
  291. (unsigned char *)&(ib->rx_buf[lp->rx_new][0]),
  292. len);
  293. skb->protocol = eth_type_trans(skb, dev);
  294. netif_rx(skb);
  295. dev->stats.rx_packets++;
  296. dev->stats.rx_bytes += len;
  297. }
  298. /* Return the packet to the pool */
  299. rd->mblength = 0;
  300. rd->rmd1_bits = LE_R1_OWN;
  301. lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
  302. }
  303. return 0;
  304. }
  305. static int lance_tx(struct net_device *dev)
  306. {
  307. struct lance_private *lp = netdev_priv(dev);
  308. volatile struct lance_init_block *ib = lp->init_block;
  309. volatile struct lance_tx_desc *td;
  310. int i, j;
  311. int status;
  312. #ifdef CONFIG_HP300
  313. blinken_leds(0x80, 0);
  314. #endif
  315. /* csr0 is 2f3 */
  316. WRITERDP(lp, LE_C0_TINT | LE_C0_INEA);
  317. /* csr0 is 73 */
  318. j = lp->tx_old;
  319. for (i = j; i != lp->tx_new; i = j) {
  320. td = &ib->btx_ring[i];
  321. /* If we hit a packet not owned by us, stop */
  322. if (td->tmd1_bits & LE_T1_OWN)
  323. break;
  324. if (td->tmd1_bits & LE_T1_ERR) {
  325. status = td->misc;
  326. dev->stats.tx_errors++;
  327. if (status & LE_T3_RTY)
  328. dev->stats.tx_aborted_errors++;
  329. if (status & LE_T3_LCOL)
  330. dev->stats.tx_window_errors++;
  331. if (status & LE_T3_CLOS) {
  332. dev->stats.tx_carrier_errors++;
  333. if (lp->auto_select) {
  334. lp->tpe = 1 - lp->tpe;
  335. printk("%s: Carrier Lost, trying %s\n",
  336. dev->name,
  337. lp->tpe ? "TPE" : "AUI");
  338. /* Stop the lance */
  339. WRITERAP(lp, LE_CSR0);
  340. WRITERDP(lp, LE_C0_STOP);
  341. lance_init_ring(dev);
  342. load_csrs(lp);
  343. init_restart_lance(lp);
  344. return 0;
  345. }
  346. }
  347. /* buffer errors and underflows turn off the transmitter */
  348. /* Restart the adapter */
  349. if (status & (LE_T3_BUF|LE_T3_UFL)) {
  350. dev->stats.tx_fifo_errors++;
  351. printk("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
  352. dev->name);
  353. /* Stop the lance */
  354. WRITERAP(lp, LE_CSR0);
  355. WRITERDP(lp, LE_C0_STOP);
  356. lance_init_ring(dev);
  357. load_csrs(lp);
  358. init_restart_lance(lp);
  359. return 0;
  360. }
  361. } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
  362. /*
  363. * So we don't count the packet more than once.
  364. */
  365. td->tmd1_bits &= ~(LE_T1_POK);
  366. /* One collision before packet was sent. */
  367. if (td->tmd1_bits & LE_T1_EONE)
  368. dev->stats.collisions++;
  369. /* More than one collision, be optimistic. */
  370. if (td->tmd1_bits & LE_T1_EMORE)
  371. dev->stats.collisions += 2;
  372. dev->stats.tx_packets++;
  373. }
  374. j = (j + 1) & lp->tx_ring_mod_mask;
  375. }
  376. lp->tx_old = j;
  377. WRITERDP(lp, LE_C0_TINT | LE_C0_INEA);
  378. return 0;
  379. }
  380. static irqreturn_t
  381. lance_interrupt(int irq, void *dev_id)
  382. {
  383. struct net_device *dev = (struct net_device *)dev_id;
  384. struct lance_private *lp = netdev_priv(dev);
  385. int csr0;
  386. spin_lock(&lp->devlock);
  387. WRITERAP(lp, LE_CSR0); /* LANCE Controller Status */
  388. csr0 = READRDP(lp);
  389. PRINT_RINGS();
  390. if (!(csr0 & LE_C0_INTR)) { /* Check if any interrupt has */
  391. spin_unlock(&lp->devlock);
  392. return IRQ_NONE; /* been generated by the Lance. */
  393. }
  394. /* Acknowledge all the interrupt sources ASAP */
  395. WRITERDP(lp, csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|LE_C0_INIT));
  396. if ((csr0 & LE_C0_ERR)) {
  397. /* Clear the error condition */
  398. WRITERDP(lp, LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA);
  399. }
  400. if (csr0 & LE_C0_RINT)
  401. lance_rx(dev);
  402. if (csr0 & LE_C0_TINT)
  403. lance_tx(dev);
  404. /* Log misc errors. */
  405. if (csr0 & LE_C0_BABL)
  406. dev->stats.tx_errors++; /* Tx babble. */
  407. if (csr0 & LE_C0_MISS)
  408. dev->stats.rx_errors++; /* Missed a Rx frame. */
  409. if (csr0 & LE_C0_MERR) {
  410. printk("%s: Bus master arbitration failure, status %4.4x.\n",
  411. dev->name, csr0);
  412. /* Restart the chip. */
  413. WRITERDP(lp, LE_C0_STRT);
  414. }
  415. if (lp->tx_full && netif_queue_stopped(dev) && (TX_BUFFS_AVAIL >= 0)) {
  416. lp->tx_full = 0;
  417. netif_wake_queue(dev);
  418. }
  419. WRITERAP(lp, LE_CSR0);
  420. WRITERDP(lp, LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|LE_C0_IDON|LE_C0_INEA);
  421. spin_unlock(&lp->devlock);
  422. return IRQ_HANDLED;
  423. }
  424. int lance_open(struct net_device *dev)
  425. {
  426. struct lance_private *lp = netdev_priv(dev);
  427. int res;
  428. /* Install the Interrupt handler. Or we could shunt this out to specific drivers? */
  429. if (request_irq(lp->irq, lance_interrupt, IRQF_SHARED, lp->name, dev))
  430. return -EAGAIN;
  431. res = lance_reset(dev);
  432. spin_lock_init(&lp->devlock);
  433. netif_start_queue(dev);
  434. return res;
  435. }
  436. EXPORT_SYMBOL_GPL(lance_open);
  437. int lance_close(struct net_device *dev)
  438. {
  439. struct lance_private *lp = netdev_priv(dev);
  440. netif_stop_queue(dev);
  441. /* Stop the LANCE */
  442. WRITERAP(lp, LE_CSR0);
  443. WRITERDP(lp, LE_C0_STOP);
  444. free_irq(lp->irq, dev);
  445. return 0;
  446. }
  447. EXPORT_SYMBOL_GPL(lance_close);
  448. void lance_tx_timeout(struct net_device *dev)
  449. {
  450. printk("lance_tx_timeout\n");
  451. lance_reset(dev);
  452. netif_trans_update(dev); /* prevent tx timeout */
  453. netif_wake_queue(dev);
  454. }
  455. EXPORT_SYMBOL_GPL(lance_tx_timeout);
  456. int lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
  457. {
  458. struct lance_private *lp = netdev_priv(dev);
  459. volatile struct lance_init_block *ib = lp->init_block;
  460. int entry, skblen, len;
  461. static int outs;
  462. unsigned long flags;
  463. netif_stop_queue(dev);
  464. if (!TX_BUFFS_AVAIL) {
  465. dev_consume_skb_any(skb);
  466. return NETDEV_TX_OK;
  467. }
  468. skblen = skb->len;
  469. #ifdef DEBUG_DRIVER
  470. /* dump the packet */
  471. {
  472. int i;
  473. for (i = 0; i < 64; i++) {
  474. if ((i % 16) == 0)
  475. printk("\n");
  476. printk("%2.2x ", skb->data[i]);
  477. }
  478. }
  479. #endif
  480. len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
  481. entry = lp->tx_new & lp->tx_ring_mod_mask;
  482. ib->btx_ring[entry].length = (-len) | 0xf000;
  483. ib->btx_ring[entry].misc = 0;
  484. if (skb->len < ETH_ZLEN)
  485. memset((void *)&ib->tx_buf[entry][0], 0, ETH_ZLEN);
  486. skb_copy_from_linear_data(skb, (void *)&ib->tx_buf[entry][0], skblen);
  487. /* Now, give the packet to the lance */
  488. ib->btx_ring[entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
  489. lp->tx_new = (lp->tx_new + 1) & lp->tx_ring_mod_mask;
  490. outs++;
  491. /* Kick the lance: transmit now */
  492. WRITERDP(lp, LE_C0_INEA | LE_C0_TDMD);
  493. dev_consume_skb_any(skb);
  494. spin_lock_irqsave(&lp->devlock, flags);
  495. if (TX_BUFFS_AVAIL)
  496. netif_start_queue(dev);
  497. else
  498. lp->tx_full = 1;
  499. spin_unlock_irqrestore(&lp->devlock, flags);
  500. return NETDEV_TX_OK;
  501. }
  502. EXPORT_SYMBOL_GPL(lance_start_xmit);
  503. /* taken from the depca driver via a2065.c */
  504. static void lance_load_multicast(struct net_device *dev)
  505. {
  506. struct lance_private *lp = netdev_priv(dev);
  507. volatile struct lance_init_block *ib = lp->init_block;
  508. volatile u16 *mcast_table = (u16 *)&ib->filter;
  509. struct netdev_hw_addr *ha;
  510. u32 crc;
  511. /* set all multicast bits */
  512. if (dev->flags & IFF_ALLMULTI) {
  513. ib->filter[0] = 0xffffffff;
  514. ib->filter[1] = 0xffffffff;
  515. return;
  516. }
  517. /* clear the multicast filter */
  518. ib->filter[0] = 0;
  519. ib->filter[1] = 0;
  520. /* Add addresses */
  521. netdev_for_each_mc_addr(ha, dev) {
  522. crc = ether_crc_le(6, ha->addr);
  523. crc = crc >> 26;
  524. mcast_table[crc >> 4] |= 1 << (crc & 0xf);
  525. }
  526. }
  527. void lance_set_multicast(struct net_device *dev)
  528. {
  529. struct lance_private *lp = netdev_priv(dev);
  530. volatile struct lance_init_block *ib = lp->init_block;
  531. int stopped;
  532. stopped = netif_queue_stopped(dev);
  533. if (!stopped)
  534. netif_stop_queue(dev);
  535. while (lp->tx_old != lp->tx_new)
  536. schedule();
  537. WRITERAP(lp, LE_CSR0);
  538. WRITERDP(lp, LE_C0_STOP);
  539. lance_init_ring(dev);
  540. if (dev->flags & IFF_PROMISC) {
  541. ib->mode |= LE_MO_PROM;
  542. } else {
  543. ib->mode &= ~LE_MO_PROM;
  544. lance_load_multicast(dev);
  545. }
  546. load_csrs(lp);
  547. init_restart_lance(lp);
  548. if (!stopped)
  549. netif_start_queue(dev);
  550. }
  551. EXPORT_SYMBOL_GPL(lance_set_multicast);
  552. #ifdef CONFIG_NET_POLL_CONTROLLER
  553. void lance_poll(struct net_device *dev)
  554. {
  555. struct lance_private *lp = netdev_priv(dev);
  556. spin_lock(&lp->devlock);
  557. WRITERAP(lp, LE_CSR0);
  558. WRITERDP(lp, LE_C0_STRT);
  559. spin_unlock(&lp->devlock);
  560. lance_interrupt(dev->irq, dev);
  561. }
  562. EXPORT_SYMBOL_GPL(lance_poll);
  563. #endif
  564. MODULE_LICENSE("GPL");