interrupt.c 25 KB

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