interrupt.c 26 KB

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