interrupt.c 26 KB

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