interrupt.c 26 KB

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