interrupt.c 25 KB

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