spurious.c 6.8 KB

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