interrupt.c 26 KB

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