spurious.c 6.8 KB

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