interrupt.c 25 KB

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