spurious.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * linux/kernel/irq/spurious.c
  3. *
  4. * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
  5. *
  6. * This file contains spurious interrupt handling.
  7. */
  8. #include <linux/jiffies.h>
  9. #include <linux/irq.h>
  10. #include <linux/module.h>
  11. #include <linux/kallsyms.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/timer.h>
  15. static int irqfixup __read_mostly;
  16. #define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10)
  17. static void poll_spurious_irqs(unsigned long dummy);
  18. static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0);
  19. /*
  20. * Recovery handler for misrouted interrupts.
  21. */
  22. static int try_one_irq(int irq, struct irq_desc *desc)
  23. {
  24. struct irqaction *action;
  25. int ok = 0;
  26. int work = 0; /* Did we do work for a real IRQ */
  27. spin_lock(&desc->lock);
  28. /* Already running on another processor */
  29. if (desc->status & IRQ_INPROGRESS) {
  30. /*
  31. * Already running: If it is shared get the other
  32. * CPU to go looking for our mystery interrupt too
  33. */
  34. if (desc->action && (desc->action->flags & IRQF_SHARED))
  35. desc->status |= IRQ_PENDING;
  36. spin_unlock(&desc->lock);
  37. return ok;
  38. }
  39. /* Honour the normal IRQ locking */
  40. desc->status |= IRQ_INPROGRESS;
  41. action = desc->action;
  42. spin_unlock(&desc->lock);
  43. while (action) {
  44. /* Only shared IRQ handlers are safe to call */
  45. if (action->flags & IRQF_SHARED) {
  46. if (action->handler(irq, action->dev_id) ==
  47. IRQ_HANDLED)
  48. ok = 1;
  49. }
  50. action = action->next;
  51. }
  52. local_irq_disable();
  53. /* Now clean up the flags */
  54. spin_lock(&desc->lock);
  55. action = desc->action;
  56. /*
  57. * While we were looking for a fixup someone queued a real
  58. * IRQ clashing with our walk:
  59. */
  60. while ((desc->status & IRQ_PENDING) && action) {
  61. /*
  62. * Perform real IRQ processing for the IRQ we deferred
  63. */
  64. work = 1;
  65. spin_unlock(&desc->lock);
  66. handle_IRQ_event(irq, action);
  67. spin_lock(&desc->lock);
  68. desc->status &= ~IRQ_PENDING;
  69. }
  70. desc->status &= ~IRQ_INPROGRESS;
  71. /*
  72. * If we did actual work for the real IRQ line we must let the
  73. * IRQ controller clean up too
  74. */
  75. if (work && desc->chip && desc->chip->end)
  76. desc->chip->end(irq);
  77. spin_unlock(&desc->lock);
  78. return ok;
  79. }
  80. static int misrouted_irq(int irq)
  81. {
  82. int i;
  83. int ok = 0;
  84. for (i = 1; i < nr_irqs; i++) {
  85. struct irq_desc *desc = irq_desc + i;
  86. if (i == irq) /* Already tried */
  87. continue;
  88. if (try_one_irq(i, desc))
  89. ok = 1;
  90. }
  91. /* So the caller can adjust the irq error counts */
  92. return ok;
  93. }
  94. static void poll_spurious_irqs(unsigned long dummy)
  95. {
  96. int i;
  97. for (i = 1; i < nr_irqs; i++) {
  98. struct irq_desc *desc = irq_desc + i;
  99. unsigned int status;
  100. /* Racy but it doesn't matter */
  101. status = desc->status;
  102. barrier();
  103. if (!(status & IRQ_SPURIOUS_DISABLED))
  104. continue;
  105. try_one_irq(i, desc);
  106. }
  107. mod_timer(&poll_spurious_irq_timer, jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
  108. }
  109. /*
  110. * If 99,900 of the previous 100,000 interrupts have not been handled
  111. * then assume that the IRQ is stuck in some manner. Drop a diagnostic
  112. * and try to turn the IRQ off.
  113. *
  114. * (The other 100-of-100,000 interrupts may have been a correctly
  115. * functioning device sharing an IRQ with the failing one)
  116. *
  117. * Called under desc->lock
  118. */
  119. static void
  120. __report_bad_irq(unsigned int irq, struct irq_desc *desc,
  121. irqreturn_t action_ret)
  122. {
  123. struct irqaction *action;
  124. if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
  125. printk(KERN_ERR "irq event %d: bogus return value %x\n",
  126. irq, action_ret);
  127. } else {
  128. printk(KERN_ERR "irq %d: nobody cared (try booting with "
  129. "the \"irqpoll\" option)\n", irq);
  130. }
  131. dump_stack();
  132. printk(KERN_ERR "handlers:\n");
  133. action = desc->action;
  134. while (action) {
  135. printk(KERN_ERR "[<%p>]", action->handler);
  136. print_symbol(" (%s)",
  137. (unsigned long)action->handler);
  138. printk("\n");
  139. action = action->next;
  140. }
  141. }
  142. static void
  143. report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  144. {
  145. static int count = 100;
  146. if (count > 0) {
  147. count--;
  148. __report_bad_irq(irq, desc, action_ret);
  149. }
  150. }
  151. static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  152. {
  153. struct irqaction *action;
  154. if (!irqfixup)
  155. return 0;
  156. /* We didn't actually handle the IRQ - see if it was misrouted? */
  157. if (action_ret == IRQ_NONE)
  158. return 1;
  159. /*
  160. * But for 'irqfixup == 2' we also do it for handled interrupts if
  161. * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
  162. * traditional PC timer interrupt.. Legacy)
  163. */
  164. if (irqfixup < 2)
  165. return 0;
  166. if (!irq)
  167. return 1;
  168. /*
  169. * Since we don't get the descriptor lock, "action" can
  170. * change under us. We don't really care, but we don't
  171. * want to follow a NULL pointer. So tell the compiler to
  172. * just load it once by using a barrier.
  173. */
  174. action = desc->action;
  175. barrier();
  176. return action && (action->flags & IRQF_IRQPOLL);
  177. }
  178. void note_interrupt(unsigned int irq, struct irq_desc *desc,
  179. irqreturn_t action_ret)
  180. {
  181. if (unlikely(action_ret != IRQ_HANDLED)) {
  182. /*
  183. * If we are seeing only the odd spurious IRQ caused by
  184. * bus asynchronicity then don't eventually trigger an error,
  185. * otherwise the couter becomes a doomsday timer for otherwise
  186. * working systems
  187. */
  188. if (time_after(jiffies, desc->last_unhandled + HZ/10))
  189. desc->irqs_unhandled = 1;
  190. else
  191. desc->irqs_unhandled++;
  192. desc->last_unhandled = jiffies;
  193. if (unlikely(action_ret != IRQ_NONE))
  194. report_bad_irq(irq, desc, action_ret);
  195. }
  196. if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
  197. int ok = misrouted_irq(irq);
  198. if (action_ret == IRQ_NONE)
  199. desc->irqs_unhandled -= ok;
  200. }
  201. desc->irq_count++;
  202. if (likely(desc->irq_count < 100000))
  203. return;
  204. desc->irq_count = 0;
  205. if (unlikely(desc->irqs_unhandled > 99900)) {
  206. /*
  207. * The interrupt is stuck
  208. */
  209. __report_bad_irq(irq, desc, action_ret);
  210. /*
  211. * Now kill the IRQ
  212. */
  213. printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
  214. desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
  215. desc->depth++;
  216. desc->chip->disable(irq);
  217. mod_timer(&poll_spurious_irq_timer, jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
  218. }
  219. desc->irqs_unhandled = 0;
  220. }
  221. int noirqdebug __read_mostly;
  222. int noirqdebug_setup(char *str)
  223. {
  224. noirqdebug = 1;
  225. printk(KERN_INFO "IRQ lockup detection disabled\n");
  226. return 1;
  227. }
  228. __setup("noirqdebug", noirqdebug_setup);
  229. module_param(noirqdebug, bool, 0644);
  230. MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
  231. static int __init irqfixup_setup(char *str)
  232. {
  233. irqfixup = 1;
  234. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  235. printk(KERN_WARNING "This may impact system performance.\n");
  236. return 1;
  237. }
  238. __setup("irqfixup", irqfixup_setup);
  239. module_param(irqfixup, int, 0644);
  240. MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
  241. static int __init irqpoll_setup(char *str)
  242. {
  243. irqfixup = 2;
  244. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  245. "enabled\n");
  246. printk(KERN_WARNING "This may significantly impact system "
  247. "performance\n");
  248. return 1;
  249. }
  250. __setup("irqpoll", irqpoll_setup);