spurious.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. struct irq_desc *desc;
  85. for_each_irq_desc(i, desc) {
  86. if (!i)
  87. continue;
  88. if (i == irq) /* Already tried */
  89. continue;
  90. if (try_one_irq(i, desc))
  91. ok = 1;
  92. }
  93. /* So the caller can adjust the irq error counts */
  94. return ok;
  95. }
  96. static void poll_spurious_irqs(unsigned long dummy)
  97. {
  98. int i;
  99. struct irq_desc *desc;
  100. for_each_irq_desc(i, desc) {
  101. unsigned int status;
  102. if (!i)
  103. continue;
  104. /* Racy but it doesn't matter */
  105. status = desc->status;
  106. barrier();
  107. if (!(status & IRQ_SPURIOUS_DISABLED))
  108. continue;
  109. try_one_irq(i, desc);
  110. }
  111. mod_timer(&poll_spurious_irq_timer, jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
  112. }
  113. /*
  114. * If 99,900 of the previous 100,000 interrupts have not been handled
  115. * then assume that the IRQ is stuck in some manner. Drop a diagnostic
  116. * and try to turn the IRQ off.
  117. *
  118. * (The other 100-of-100,000 interrupts may have been a correctly
  119. * functioning device sharing an IRQ with the failing one)
  120. *
  121. * Called under desc->lock
  122. */
  123. static void
  124. __report_bad_irq(unsigned int irq, struct irq_desc *desc,
  125. irqreturn_t action_ret)
  126. {
  127. struct irqaction *action;
  128. if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
  129. printk(KERN_ERR "irq event %d: bogus return value %x\n",
  130. irq, action_ret);
  131. } else {
  132. printk(KERN_ERR "irq %d: nobody cared (try booting with "
  133. "the \"irqpoll\" option)\n", irq);
  134. }
  135. dump_stack();
  136. printk(KERN_ERR "handlers:\n");
  137. action = desc->action;
  138. while (action) {
  139. printk(KERN_ERR "[<%p>]", action->handler);
  140. print_symbol(" (%s)",
  141. (unsigned long)action->handler);
  142. printk("\n");
  143. action = action->next;
  144. }
  145. }
  146. static void
  147. report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  148. {
  149. static int count = 100;
  150. if (count > 0) {
  151. count--;
  152. __report_bad_irq(irq, desc, action_ret);
  153. }
  154. }
  155. static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  156. {
  157. struct irqaction *action;
  158. if (!irqfixup)
  159. return 0;
  160. /* We didn't actually handle the IRQ - see if it was misrouted? */
  161. if (action_ret == IRQ_NONE)
  162. return 1;
  163. /*
  164. * But for 'irqfixup == 2' we also do it for handled interrupts if
  165. * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
  166. * traditional PC timer interrupt.. Legacy)
  167. */
  168. if (irqfixup < 2)
  169. return 0;
  170. if (!irq)
  171. return 1;
  172. /*
  173. * Since we don't get the descriptor lock, "action" can
  174. * change under us. We don't really care, but we don't
  175. * want to follow a NULL pointer. So tell the compiler to
  176. * just load it once by using a barrier.
  177. */
  178. action = desc->action;
  179. barrier();
  180. return action && (action->flags & IRQF_IRQPOLL);
  181. }
  182. void note_interrupt(unsigned int irq, struct irq_desc *desc,
  183. irqreturn_t action_ret)
  184. {
  185. if (unlikely(action_ret != IRQ_HANDLED)) {
  186. /*
  187. * If we are seeing only the odd spurious IRQ caused by
  188. * bus asynchronicity then don't eventually trigger an error,
  189. * otherwise the couter becomes a doomsday timer for otherwise
  190. * working systems
  191. */
  192. if (time_after(jiffies, desc->last_unhandled + HZ/10))
  193. desc->irqs_unhandled = 1;
  194. else
  195. desc->irqs_unhandled++;
  196. desc->last_unhandled = jiffies;
  197. if (unlikely(action_ret != IRQ_NONE))
  198. report_bad_irq(irq, desc, action_ret);
  199. }
  200. if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
  201. int ok = misrouted_irq(irq);
  202. if (action_ret == IRQ_NONE)
  203. desc->irqs_unhandled -= ok;
  204. }
  205. desc->irq_count++;
  206. if (likely(desc->irq_count < 100000))
  207. return;
  208. desc->irq_count = 0;
  209. if (unlikely(desc->irqs_unhandled > 99900)) {
  210. /*
  211. * The interrupt is stuck
  212. */
  213. __report_bad_irq(irq, desc, action_ret);
  214. /*
  215. * Now kill the IRQ
  216. */
  217. printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
  218. desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
  219. desc->depth++;
  220. desc->chip->disable(irq);
  221. mod_timer(&poll_spurious_irq_timer, jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
  222. }
  223. desc->irqs_unhandled = 0;
  224. }
  225. int noirqdebug __read_mostly;
  226. int noirqdebug_setup(char *str)
  227. {
  228. noirqdebug = 1;
  229. printk(KERN_INFO "IRQ lockup detection disabled\n");
  230. return 1;
  231. }
  232. __setup("noirqdebug", noirqdebug_setup);
  233. module_param(noirqdebug, bool, 0644);
  234. MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
  235. static int __init irqfixup_setup(char *str)
  236. {
  237. irqfixup = 1;
  238. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  239. printk(KERN_WARNING "This may impact system performance.\n");
  240. return 1;
  241. }
  242. __setup("irqfixup", irqfixup_setup);
  243. module_param(irqfixup, int, 0644);
  244. MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode, 2: irqpoll mode");
  245. static int __init irqpoll_setup(char *str)
  246. {
  247. irqfixup = 2;
  248. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  249. "enabled\n");
  250. printk(KERN_WARNING "This may significantly impact system "
  251. "performance\n");
  252. return 1;
  253. }
  254. __setup("irqpoll", irqpoll_setup);