interrupt.c 26 KB

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