interrupt.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /*
  2. drivers/net/ethernet/dec/tulip/interrupt.c
  3. Copyright 2000,2001 The Linux Kernel Team
  4. Written/copyright 1994-2001 by Donald Becker.
  5. This software may be used and distributed according to the terms
  6. of the GNU General Public License, incorporated herein by reference.
  7. Please submit bugs to http://bugzilla.kernel.org/ .
  8. */
  9. #include <linux/pci.h>
  10. #include "tulip.h"
  11. #include <linux/etherdevice.h>
  12. int tulip_rx_copybreak;
  13. unsigned int tulip_max_interrupt_work;
  14. #ifdef CONFIG_TULIP_NAPI_HW_MITIGATION
  15. #define MIT_SIZE 15
  16. #define MIT_TABLE 15 /* We use 0 or max */
  17. static unsigned int mit_table[MIT_SIZE+1] =
  18. {
  19. /* CRS11 21143 hardware Mitigation Control Interrupt
  20. We use only RX mitigation we other techniques for
  21. TX intr. mitigation.
  22. 31 Cycle Size (timer control)
  23. 30:27 TX timer in 16 * Cycle size
  24. 26:24 TX No pkts before Int.
  25. 23:20 RX timer in Cycle size
  26. 19:17 RX No pkts before Int.
  27. 16 Continues Mode (CM)
  28. */
  29. 0x0, /* IM disabled */
  30. 0x80150000, /* RX time = 1, RX pkts = 2, CM = 1 */
  31. 0x80150000,
  32. 0x80270000,
  33. 0x80370000,
  34. 0x80490000,
  35. 0x80590000,
  36. 0x80690000,
  37. 0x807B0000,
  38. 0x808B0000,
  39. 0x809D0000,
  40. 0x80AD0000,
  41. 0x80BD0000,
  42. 0x80CF0000,
  43. 0x80DF0000,
  44. // 0x80FF0000 /* RX time = 16, RX pkts = 7, CM = 1 */
  45. 0x80F10000 /* RX time = 16, RX pkts = 0, CM = 1 */
  46. };
  47. #endif
  48. int tulip_refill_rx(struct net_device *dev)
  49. {
  50. struct tulip_private *tp = netdev_priv(dev);
  51. int entry;
  52. int refilled = 0;
  53. /* Refill the Rx ring buffers. */
  54. for (; tp->cur_rx - tp->dirty_rx > 0; tp->dirty_rx++) {
  55. entry = tp->dirty_rx % RX_RING_SIZE;
  56. if (tp->rx_buffers[entry].skb == NULL) {
  57. struct sk_buff *skb;
  58. dma_addr_t mapping;
  59. skb = tp->rx_buffers[entry].skb =
  60. netdev_alloc_skb(dev, PKT_BUF_SZ);
  61. if (skb == NULL)
  62. break;
  63. mapping = dma_map_single(&tp->pdev->dev, skb->data,
  64. PKT_BUF_SZ, DMA_FROM_DEVICE);
  65. if (dma_mapping_error(&tp->pdev->dev, mapping)) {
  66. dev_kfree_skb(skb);
  67. tp->rx_buffers[entry].skb = NULL;
  68. break;
  69. }
  70. tp->rx_buffers[entry].mapping = mapping;
  71. tp->rx_ring[entry].buffer1 = cpu_to_le32(mapping);
  72. refilled++;
  73. }
  74. tp->rx_ring[entry].status = cpu_to_le32(DescOwned);
  75. }
  76. if(tp->chip_id == LC82C168) {
  77. if(((ioread32(tp->base_addr + CSR5)>>17)&0x07) == 4) {
  78. /* Rx stopped due to out of buffers,
  79. * restart it
  80. */
  81. iowrite32(0x01, tp->base_addr + CSR2);
  82. }
  83. }
  84. return refilled;
  85. }
  86. #ifdef CONFIG_TULIP_NAPI
  87. void oom_timer(struct timer_list *t)
  88. {
  89. struct tulip_private *tp = from_timer(tp, t, oom_timer);
  90. napi_schedule(&tp->napi);
  91. }
  92. int tulip_poll(struct napi_struct *napi, int budget)
  93. {
  94. struct tulip_private *tp = container_of(napi, struct tulip_private, napi);
  95. struct net_device *dev = tp->dev;
  96. int entry = tp->cur_rx % RX_RING_SIZE;
  97. int work_done = 0;
  98. #ifdef CONFIG_TULIP_NAPI_HW_MITIGATION
  99. int received = 0;
  100. #endif
  101. #ifdef CONFIG_TULIP_NAPI_HW_MITIGATION
  102. /* that one buffer is needed for mit activation; or might be a
  103. bug in the ring buffer code; check later -- JHS*/
  104. if (budget >=RX_RING_SIZE) budget--;
  105. #endif
  106. if (tulip_debug > 4)
  107. netdev_dbg(dev, " In tulip_rx(), entry %d %08x\n",
  108. entry, tp->rx_ring[entry].status);
  109. do {
  110. if (ioread32(tp->base_addr + CSR5) == 0xffffffff) {
  111. netdev_dbg(dev, " In tulip_poll(), hardware disappeared\n");
  112. break;
  113. }
  114. /* Acknowledge current RX interrupt sources. */
  115. iowrite32((RxIntr | RxNoBuf), tp->base_addr + CSR5);
  116. /* If we own the next entry, it is a new packet. Send it up. */
  117. while ( ! (tp->rx_ring[entry].status & cpu_to_le32(DescOwned))) {
  118. s32 status = le32_to_cpu(tp->rx_ring[entry].status);
  119. short pkt_len;
  120. if (tp->dirty_rx + RX_RING_SIZE == tp->cur_rx)
  121. break;
  122. if (tulip_debug > 5)
  123. netdev_dbg(dev, "In tulip_rx(), entry %d %08x\n",
  124. entry, status);
  125. if (++work_done >= budget)
  126. goto not_done;
  127. /*
  128. * Omit the four octet CRC from the length.
  129. * (May not be considered valid until we have
  130. * checked status for RxLengthOver2047 bits)
  131. */
  132. pkt_len = ((status >> 16) & 0x7ff) - 4;
  133. /*
  134. * Maximum pkt_len is 1518 (1514 + vlan header)
  135. * Anything higher than this is always invalid
  136. * regardless of RxLengthOver2047 bits
  137. */
  138. if ((status & (RxLengthOver2047 |
  139. RxDescCRCError |
  140. RxDescCollisionSeen |
  141. RxDescRunt |
  142. RxDescDescErr |
  143. RxWholePkt)) != RxWholePkt ||
  144. pkt_len > 1518) {
  145. if ((status & (RxLengthOver2047 |
  146. RxWholePkt)) != RxWholePkt) {
  147. /* Ingore earlier buffers. */
  148. if ((status & 0xffff) != 0x7fff) {
  149. if (tulip_debug > 1)
  150. dev_warn(&dev->dev,
  151. "Oversized Ethernet frame spanned multiple buffers, status %08x!\n",
  152. status);
  153. dev->stats.rx_length_errors++;
  154. }
  155. } else {
  156. /* There was a fatal error. */
  157. if (tulip_debug > 2)
  158. netdev_dbg(dev, "Receive error, Rx status %08x\n",
  159. status);
  160. dev->stats.rx_errors++; /* end of a packet.*/
  161. if (pkt_len > 1518 ||
  162. (status & RxDescRunt))
  163. dev->stats.rx_length_errors++;
  164. if (status & 0x0004)
  165. dev->stats.rx_frame_errors++;
  166. if (status & 0x0002)
  167. dev->stats.rx_crc_errors++;
  168. if (status & 0x0001)
  169. dev->stats.rx_fifo_errors++;
  170. }
  171. } else {
  172. struct sk_buff *skb;
  173. /* Check if the packet is long enough to accept without copying
  174. to a minimally-sized skbuff. */
  175. if (pkt_len < tulip_rx_copybreak &&
  176. (skb = netdev_alloc_skb(dev, pkt_len + 2)) != NULL) {
  177. skb_reserve(skb, 2); /* 16 byte align the IP header */
  178. dma_sync_single_for_cpu(&tp->pdev->dev,
  179. tp->rx_buffers[entry].mapping,
  180. pkt_len,
  181. DMA_FROM_DEVICE);
  182. #if ! defined(__alpha__)
  183. skb_copy_to_linear_data(skb, tp->rx_buffers[entry].skb->data,
  184. pkt_len);
  185. skb_put(skb, pkt_len);
  186. #else
  187. skb_put_data(skb,
  188. tp->rx_buffers[entry].skb->data,
  189. pkt_len);
  190. #endif
  191. dma_sync_single_for_device(&tp->pdev->dev,
  192. tp->rx_buffers[entry].mapping,
  193. pkt_len,
  194. DMA_FROM_DEVICE);
  195. } else { /* Pass up the skb already on the Rx ring. */
  196. char *temp = skb_put(skb = tp->rx_buffers[entry].skb,
  197. pkt_len);
  198. #ifndef final_version
  199. if (tp->rx_buffers[entry].mapping !=
  200. le32_to_cpu(tp->rx_ring[entry].buffer1)) {
  201. dev_err(&dev->dev,
  202. "Internal fault: The skbuff addresses do not match in tulip_rx: %08x vs. %08llx %p / %p\n",
  203. le32_to_cpu(tp->rx_ring[entry].buffer1),
  204. (unsigned long long)tp->rx_buffers[entry].mapping,
  205. skb->head, temp);
  206. }
  207. #endif
  208. dma_unmap_single(&tp->pdev->dev,
  209. tp->rx_buffers[entry].mapping,
  210. PKT_BUF_SZ,
  211. DMA_FROM_DEVICE);
  212. tp->rx_buffers[entry].skb = NULL;
  213. tp->rx_buffers[entry].mapping = 0;
  214. }
  215. skb->protocol = eth_type_trans(skb, dev);
  216. netif_receive_skb(skb);
  217. dev->stats.rx_packets++;
  218. dev->stats.rx_bytes += pkt_len;
  219. }
  220. #ifdef CONFIG_TULIP_NAPI_HW_MITIGATION
  221. received++;
  222. #endif
  223. entry = (++tp->cur_rx) % RX_RING_SIZE;
  224. if (tp->cur_rx - tp->dirty_rx > RX_RING_SIZE/4)
  225. tulip_refill_rx(dev);
  226. }
  227. /* New ack strategy... irq does not ack Rx any longer
  228. hopefully this helps */
  229. /* Really bad things can happen here... If new packet arrives
  230. * and an irq arrives (tx or just due to occasionally unset
  231. * mask), it will be acked by irq handler, but new thread
  232. * is not scheduled. It is major hole in design.
  233. * No idea how to fix this if "playing with fire" will fail
  234. * tomorrow (night 011029). If it will not fail, we won
  235. * finally: amount of IO did not increase at all. */
  236. } while ((ioread32(tp->base_addr + CSR5) & RxIntr));
  237. #ifdef CONFIG_TULIP_NAPI_HW_MITIGATION
  238. /* We use this simplistic scheme for IM. It's proven by
  239. real life installations. We can have IM enabled
  240. continuesly but this would cause unnecessary latency.
  241. Unfortunely we can't use all the NET_RX_* feedback here.
  242. This would turn on IM for devices that is not contributing
  243. to backlog congestion with unnecessary latency.
  244. We monitor the device RX-ring and have:
  245. HW Interrupt Mitigation either ON or OFF.
  246. ON: More then 1 pkt received (per intr.) OR we are dropping
  247. OFF: Only 1 pkt received
  248. Note. We only use min and max (0, 15) settings from mit_table */
  249. if( tp->flags & HAS_INTR_MITIGATION) {
  250. if( received > 1 ) {
  251. if( ! tp->mit_on ) {
  252. tp->mit_on = 1;
  253. iowrite32(mit_table[MIT_TABLE], tp->base_addr + CSR11);
  254. }
  255. }
  256. else {
  257. if( tp->mit_on ) {
  258. tp->mit_on = 0;
  259. iowrite32(0, tp->base_addr + CSR11);
  260. }
  261. }
  262. }
  263. #endif /* CONFIG_TULIP_NAPI_HW_MITIGATION */
  264. tulip_refill_rx(dev);
  265. /* If RX ring is not full we are out of memory. */
  266. if (tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
  267. goto oom;
  268. /* Remove us from polling list and enable RX intr. */
  269. napi_complete_done(napi, work_done);
  270. iowrite32(tulip_tbl[tp->chip_id].valid_intrs, tp->base_addr+CSR7);
  271. /* The last op happens after poll completion. Which means the following:
  272. * 1. it can race with disabling irqs in irq handler
  273. * 2. it can race with dise/enabling irqs in other poll threads
  274. * 3. if an irq raised after beginning loop, it will be immediately
  275. * triggered here.
  276. *
  277. * Summarizing: the logic results in some redundant irqs both
  278. * due to races in masking and due to too late acking of already
  279. * processed irqs. But it must not result in losing events.
  280. */
  281. return work_done;
  282. not_done:
  283. if (tp->cur_rx - tp->dirty_rx > RX_RING_SIZE/2 ||
  284. tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
  285. tulip_refill_rx(dev);
  286. if (tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
  287. goto oom;
  288. return work_done;
  289. oom: /* Executed with RX ints disabled */
  290. /* Start timer, stop polling, but do not enable rx interrupts. */
  291. mod_timer(&tp->oom_timer, jiffies+1);
  292. /* Think: timer_pending() was an explicit signature of bug.
  293. * Timer can be pending now but fired and completed
  294. * before we did napi_complete(). See? We would lose it. */
  295. /* remove ourselves from the polling list */
  296. napi_complete_done(napi, work_done);
  297. return work_done;
  298. }
  299. #else /* CONFIG_TULIP_NAPI */
  300. static int tulip_rx(struct net_device *dev)
  301. {
  302. struct tulip_private *tp = netdev_priv(dev);
  303. int entry = tp->cur_rx % RX_RING_SIZE;
  304. int rx_work_limit = tp->dirty_rx + RX_RING_SIZE - tp->cur_rx;
  305. int received = 0;
  306. if (tulip_debug > 4)
  307. netdev_dbg(dev, "In tulip_rx(), entry %d %08x\n",
  308. entry, tp->rx_ring[entry].status);
  309. /* If we own the next entry, it is a new packet. Send it up. */
  310. while ( ! (tp->rx_ring[entry].status & cpu_to_le32(DescOwned))) {
  311. s32 status = le32_to_cpu(tp->rx_ring[entry].status);
  312. short pkt_len;
  313. if (tulip_debug > 5)
  314. netdev_dbg(dev, "In tulip_rx(), entry %d %08x\n",
  315. entry, status);
  316. if (--rx_work_limit < 0)
  317. break;
  318. /*
  319. Omit the four octet CRC from the length.
  320. (May not be considered valid until we have
  321. checked status for RxLengthOver2047 bits)
  322. */
  323. pkt_len = ((status >> 16) & 0x7ff) - 4;
  324. /*
  325. Maximum pkt_len is 1518 (1514 + vlan header)
  326. Anything higher than this is always invalid
  327. regardless of RxLengthOver2047 bits
  328. */
  329. if ((status & (RxLengthOver2047 |
  330. RxDescCRCError |
  331. RxDescCollisionSeen |
  332. RxDescRunt |
  333. RxDescDescErr |
  334. RxWholePkt)) != RxWholePkt ||
  335. pkt_len > 1518) {
  336. if ((status & (RxLengthOver2047 |
  337. RxWholePkt)) != RxWholePkt) {
  338. /* Ingore earlier buffers. */
  339. if ((status & 0xffff) != 0x7fff) {
  340. if (tulip_debug > 1)
  341. netdev_warn(dev,
  342. "Oversized Ethernet frame spanned multiple buffers, status %08x!\n",
  343. status);
  344. dev->stats.rx_length_errors++;
  345. }
  346. } else {
  347. /* There was a fatal error. */
  348. if (tulip_debug > 2)
  349. netdev_dbg(dev, "Receive error, Rx status %08x\n",
  350. status);
  351. dev->stats.rx_errors++; /* end of a packet.*/
  352. if (pkt_len > 1518 ||
  353. (status & RxDescRunt))
  354. dev->stats.rx_length_errors++;
  355. if (status & 0x0004)
  356. dev->stats.rx_frame_errors++;
  357. if (status & 0x0002)
  358. dev->stats.rx_crc_errors++;
  359. if (status & 0x0001)
  360. dev->stats.rx_fifo_errors++;
  361. }
  362. } else {
  363. struct sk_buff *skb;
  364. /* Check if the packet is long enough to accept without copying
  365. to a minimally-sized skbuff. */
  366. if (pkt_len < tulip_rx_copybreak &&
  367. (skb = netdev_alloc_skb(dev, pkt_len + 2)) != NULL) {
  368. skb_reserve(skb, 2); /* 16 byte align the IP header */
  369. dma_sync_single_for_cpu(&tp->pdev->dev,
  370. tp->rx_buffers[entry].mapping,
  371. pkt_len,
  372. DMA_FROM_DEVICE);
  373. #if ! defined(__alpha__)
  374. skb_copy_to_linear_data(skb, tp->rx_buffers[entry].skb->data,
  375. pkt_len);
  376. skb_put(skb, pkt_len);
  377. #else
  378. skb_put_data(skb,
  379. tp->rx_buffers[entry].skb->data,
  380. pkt_len);
  381. #endif
  382. dma_sync_single_for_device(&tp->pdev->dev,
  383. tp->rx_buffers[entry].mapping,
  384. pkt_len,
  385. DMA_FROM_DEVICE);
  386. } else { /* Pass up the skb already on the Rx ring. */
  387. char *temp = skb_put(skb = tp->rx_buffers[entry].skb,
  388. pkt_len);
  389. #ifndef final_version
  390. if (tp->rx_buffers[entry].mapping !=
  391. le32_to_cpu(tp->rx_ring[entry].buffer1)) {
  392. dev_err(&dev->dev,
  393. "Internal fault: The skbuff addresses do not match in tulip_rx: %08x vs. %Lx %p / %p\n",
  394. le32_to_cpu(tp->rx_ring[entry].buffer1),
  395. (long long)tp->rx_buffers[entry].mapping,
  396. skb->head, temp);
  397. }
  398. #endif
  399. dma_unmap_single(&tp->pdev->dev,
  400. tp->rx_buffers[entry].mapping,
  401. PKT_BUF_SZ, DMA_FROM_DEVICE);
  402. tp->rx_buffers[entry].skb = NULL;
  403. tp->rx_buffers[entry].mapping = 0;
  404. }
  405. skb->protocol = eth_type_trans(skb, dev);
  406. netif_rx(skb);
  407. dev->stats.rx_packets++;
  408. dev->stats.rx_bytes += pkt_len;
  409. }
  410. received++;
  411. entry = (++tp->cur_rx) % RX_RING_SIZE;
  412. }
  413. return received;
  414. }
  415. #endif /* CONFIG_TULIP_NAPI */
  416. static inline unsigned int phy_interrupt (struct net_device *dev)
  417. {
  418. #ifdef __hppa__
  419. struct tulip_private *tp = netdev_priv(dev);
  420. int csr12 = ioread32(tp->base_addr + CSR12) & 0xff;
  421. if (csr12 != tp->csr12_shadow) {
  422. /* ack interrupt */
  423. iowrite32(csr12 | 0x02, tp->base_addr + CSR12);
  424. tp->csr12_shadow = csr12;
  425. /* do link change stuff */
  426. spin_lock(&tp->lock);
  427. tulip_check_duplex(dev);
  428. spin_unlock(&tp->lock);
  429. /* clear irq ack bit */
  430. iowrite32(csr12 & ~0x02, tp->base_addr + CSR12);
  431. return 1;
  432. }
  433. #endif
  434. return 0;
  435. }
  436. /* The interrupt handler does all of the Rx thread work and cleans up
  437. after the Tx thread. */
  438. irqreturn_t tulip_interrupt(int irq, void *dev_instance)
  439. {
  440. struct net_device *dev = (struct net_device *)dev_instance;
  441. struct tulip_private *tp = netdev_priv(dev);
  442. void __iomem *ioaddr = tp->base_addr;
  443. int csr5;
  444. int missed;
  445. int rx = 0;
  446. int tx = 0;
  447. int oi = 0;
  448. int maxrx = RX_RING_SIZE;
  449. int maxtx = TX_RING_SIZE;
  450. int maxoi = TX_RING_SIZE;
  451. #ifdef CONFIG_TULIP_NAPI
  452. int rxd = 0;
  453. #else
  454. int entry;
  455. #endif
  456. unsigned int work_count = tulip_max_interrupt_work;
  457. unsigned int handled = 0;
  458. /* Let's see whether the interrupt really is for us */
  459. csr5 = ioread32(ioaddr + CSR5);
  460. if (tp->flags & HAS_PHY_IRQ)
  461. handled = phy_interrupt (dev);
  462. if ((csr5 & (NormalIntr|AbnormalIntr)) == 0)
  463. return IRQ_RETVAL(handled);
  464. tp->nir++;
  465. do {
  466. #ifdef CONFIG_TULIP_NAPI
  467. if (!rxd && (csr5 & (RxIntr | RxNoBuf))) {
  468. rxd++;
  469. /* Mask RX intrs and add the device to poll list. */
  470. iowrite32(tulip_tbl[tp->chip_id].valid_intrs&~RxPollInt, ioaddr + CSR7);
  471. napi_schedule(&tp->napi);
  472. if (!(csr5&~(AbnormalIntr|NormalIntr|RxPollInt|TPLnkPass)))
  473. break;
  474. }
  475. /* Acknowledge the interrupt sources we handle here ASAP
  476. the poll function does Rx and RxNoBuf acking */
  477. iowrite32(csr5 & 0x0001ff3f, ioaddr + CSR5);
  478. #else
  479. /* Acknowledge all of the current interrupt sources ASAP. */
  480. iowrite32(csr5 & 0x0001ffff, ioaddr + CSR5);
  481. if (csr5 & (RxIntr | RxNoBuf)) {
  482. rx += tulip_rx(dev);
  483. tulip_refill_rx(dev);
  484. }
  485. #endif /* CONFIG_TULIP_NAPI */
  486. if (tulip_debug > 4)
  487. netdev_dbg(dev, "interrupt csr5=%#8.8x new csr5=%#8.8x\n",
  488. csr5, ioread32(ioaddr + CSR5));
  489. if (csr5 & (TxNoBuf | TxDied | TxIntr | TimerInt)) {
  490. unsigned int dirty_tx;
  491. spin_lock(&tp->lock);
  492. for (dirty_tx = tp->dirty_tx; tp->cur_tx - dirty_tx > 0;
  493. dirty_tx++) {
  494. int entry = dirty_tx % TX_RING_SIZE;
  495. int status = le32_to_cpu(tp->tx_ring[entry].status);
  496. if (status < 0)
  497. break; /* It still has not been Txed */
  498. /* Check for Rx filter setup frames. */
  499. if (tp->tx_buffers[entry].skb == NULL) {
  500. /* test because dummy frames not mapped */
  501. if (tp->tx_buffers[entry].mapping)
  502. dma_unmap_single(&tp->pdev->dev,
  503. tp->tx_buffers[entry].mapping,
  504. sizeof(tp->setup_frame),
  505. DMA_TO_DEVICE);
  506. continue;
  507. }
  508. if (status & 0x8000) {
  509. /* There was an major error, log it. */
  510. #ifndef final_version
  511. if (tulip_debug > 1)
  512. netdev_dbg(dev, "Transmit error, Tx status %08x\n",
  513. status);
  514. #endif
  515. dev->stats.tx_errors++;
  516. if (status & 0x4104)
  517. dev->stats.tx_aborted_errors++;
  518. if (status & 0x0C00)
  519. dev->stats.tx_carrier_errors++;
  520. if (status & 0x0200)
  521. dev->stats.tx_window_errors++;
  522. if (status & 0x0002)
  523. dev->stats.tx_fifo_errors++;
  524. if ((status & 0x0080) && tp->full_duplex == 0)
  525. dev->stats.tx_heartbeat_errors++;
  526. } else {
  527. dev->stats.tx_bytes +=
  528. tp->tx_buffers[entry].skb->len;
  529. dev->stats.collisions += (status >> 3) & 15;
  530. dev->stats.tx_packets++;
  531. }
  532. dma_unmap_single(&tp->pdev->dev,
  533. tp->tx_buffers[entry].mapping,
  534. tp->tx_buffers[entry].skb->len,
  535. DMA_TO_DEVICE);
  536. /* Free the original skb. */
  537. dev_kfree_skb_irq(tp->tx_buffers[entry].skb);
  538. tp->tx_buffers[entry].skb = NULL;
  539. tp->tx_buffers[entry].mapping = 0;
  540. tx++;
  541. }
  542. #ifndef final_version
  543. if (tp->cur_tx - dirty_tx > TX_RING_SIZE) {
  544. dev_err(&dev->dev,
  545. "Out-of-sync dirty pointer, %d vs. %d\n",
  546. dirty_tx, tp->cur_tx);
  547. dirty_tx += TX_RING_SIZE;
  548. }
  549. #endif
  550. if (tp->cur_tx - dirty_tx < TX_RING_SIZE - 2)
  551. netif_wake_queue(dev);
  552. tp->dirty_tx = dirty_tx;
  553. if (csr5 & TxDied) {
  554. if (tulip_debug > 2)
  555. dev_warn(&dev->dev,
  556. "The transmitter stopped. CSR5 is %x, CSR6 %x, new CSR6 %x\n",
  557. csr5, ioread32(ioaddr + CSR6),
  558. tp->csr6);
  559. tulip_restart_rxtx(tp);
  560. }
  561. spin_unlock(&tp->lock);
  562. }
  563. /* Log errors. */
  564. if (csr5 & AbnormalIntr) { /* Abnormal error summary bit. */
  565. if (csr5 == 0xffffffff)
  566. break;
  567. if (csr5 & TxJabber)
  568. dev->stats.tx_errors++;
  569. if (csr5 & TxFIFOUnderflow) {
  570. if ((tp->csr6 & 0xC000) != 0xC000)
  571. tp->csr6 += 0x4000; /* Bump up the Tx threshold */
  572. else
  573. tp->csr6 |= 0x00200000; /* Store-n-forward. */
  574. /* Restart the transmit process. */
  575. tulip_restart_rxtx(tp);
  576. iowrite32(0, ioaddr + CSR1);
  577. }
  578. if (csr5 & (RxDied | RxNoBuf)) {
  579. if (tp->flags & COMET_MAC_ADDR) {
  580. iowrite32(tp->mc_filter[0], ioaddr + 0xAC);
  581. iowrite32(tp->mc_filter[1], ioaddr + 0xB0);
  582. }
  583. }
  584. if (csr5 & RxDied) { /* Missed a Rx frame. */
  585. dev->stats.rx_missed_errors += ioread32(ioaddr + CSR8) & 0xffff;
  586. dev->stats.rx_errors++;
  587. tulip_start_rxtx(tp);
  588. }
  589. /*
  590. * NB: t21142_lnk_change() does a del_timer_sync(), so be careful if this
  591. * call is ever done under the spinlock
  592. */
  593. if (csr5 & (TPLnkPass | TPLnkFail | 0x08000000)) {
  594. if (tp->link_change)
  595. (tp->link_change)(dev, csr5);
  596. }
  597. if (csr5 & SystemError) {
  598. int error = (csr5 >> 23) & 7;
  599. /* oops, we hit a PCI error. The code produced corresponds
  600. * to the reason:
  601. * 0 - parity error
  602. * 1 - master abort
  603. * 2 - target abort
  604. * Note that on parity error, we should do a software reset
  605. * of the chip to get it back into a sane state (according
  606. * to the 21142/3 docs that is).
  607. * -- rmk
  608. */
  609. dev_err(&dev->dev,
  610. "(%lu) System Error occurred (%d)\n",
  611. tp->nir, error);
  612. }
  613. /* Clear all error sources, included undocumented ones! */
  614. iowrite32(0x0800f7ba, ioaddr + CSR5);
  615. oi++;
  616. }
  617. if (csr5 & TimerInt) {
  618. if (tulip_debug > 2)
  619. dev_err(&dev->dev,
  620. "Re-enabling interrupts, %08x\n",
  621. csr5);
  622. iowrite32(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
  623. tp->ttimer = 0;
  624. oi++;
  625. }
  626. if (tx > maxtx || rx > maxrx || oi > maxoi) {
  627. if (tulip_debug > 1)
  628. dev_warn(&dev->dev, "Too much work during an interrupt, csr5=0x%08x. (%lu) (%d,%d,%d)\n",
  629. csr5, tp->nir, tx, rx, oi);
  630. /* Acknowledge all interrupt sources. */
  631. iowrite32(0x8001ffff, ioaddr + CSR5);
  632. if (tp->flags & HAS_INTR_MITIGATION) {
  633. /* Josip Loncaric at ICASE did extensive experimentation
  634. to develop a good interrupt mitigation setting.*/
  635. iowrite32(0x8b240000, ioaddr + CSR11);
  636. } else if (tp->chip_id == LC82C168) {
  637. /* the LC82C168 doesn't have a hw timer.*/
  638. iowrite32(0x00, ioaddr + CSR7);
  639. mod_timer(&tp->timer, RUN_AT(HZ/50));
  640. } else {
  641. /* Mask all interrupting sources, set timer to
  642. re-enable. */
  643. iowrite32(((~csr5) & 0x0001ebef) | AbnormalIntr | TimerInt, ioaddr + CSR7);
  644. iowrite32(0x0012, ioaddr + CSR11);
  645. }
  646. break;
  647. }
  648. work_count--;
  649. if (work_count == 0)
  650. break;
  651. csr5 = ioread32(ioaddr + CSR5);
  652. #ifdef CONFIG_TULIP_NAPI
  653. if (rxd)
  654. csr5 &= ~RxPollInt;
  655. } while ((csr5 & (TxNoBuf |
  656. TxDied |
  657. TxIntr |
  658. TimerInt |
  659. /* Abnormal intr. */
  660. RxDied |
  661. TxFIFOUnderflow |
  662. TxJabber |
  663. TPLnkFail |
  664. SystemError )) != 0);
  665. #else
  666. } while ((csr5 & (NormalIntr|AbnormalIntr)) != 0);
  667. tulip_refill_rx(dev);
  668. /* check if the card is in suspend mode */
  669. entry = tp->dirty_rx % RX_RING_SIZE;
  670. if (tp->rx_buffers[entry].skb == NULL) {
  671. if (tulip_debug > 1)
  672. dev_warn(&dev->dev,
  673. "in rx suspend mode: (%lu) (tp->cur_rx = %u, ttimer = %d, rx = %d) go/stay in suspend mode\n",
  674. tp->nir, tp->cur_rx, tp->ttimer, rx);
  675. if (tp->chip_id == LC82C168) {
  676. iowrite32(0x00, ioaddr + CSR7);
  677. mod_timer(&tp->timer, RUN_AT(HZ/50));
  678. } else {
  679. if (tp->ttimer == 0 || (ioread32(ioaddr + CSR11) & 0xffff) == 0) {
  680. if (tulip_debug > 1)
  681. dev_warn(&dev->dev,
  682. "in rx suspend mode: (%lu) set timer\n",
  683. tp->nir);
  684. iowrite32(tulip_tbl[tp->chip_id].valid_intrs | TimerInt,
  685. ioaddr + CSR7);
  686. iowrite32(TimerInt, ioaddr + CSR5);
  687. iowrite32(12, ioaddr + CSR11);
  688. tp->ttimer = 1;
  689. }
  690. }
  691. }
  692. #endif /* CONFIG_TULIP_NAPI */
  693. if ((missed = ioread32(ioaddr + CSR8) & 0x1ffff)) {
  694. dev->stats.rx_dropped += missed & 0x10000 ? 0x10000 : missed;
  695. }
  696. if (tulip_debug > 4)
  697. netdev_dbg(dev, "exiting interrupt, csr5=%#04x\n",
  698. ioread32(ioaddr + CSR5));
  699. return IRQ_HANDLED;
  700. }