spurious.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. /*
  40. * All handlers must agree on IRQF_SHARED, so we test just the
  41. * first. Check for action->next as well.
  42. */
  43. action = desc->action;
  44. if (!action || !(action->flags & IRQF_SHARED) || !action->next)
  45. goto out;
  46. /* Honour the normal IRQ locking */
  47. desc->status |= IRQ_INPROGRESS;
  48. do {
  49. work++;
  50. desc->status &= ~IRQ_PENDING;
  51. raw_spin_unlock(&desc->lock);
  52. if (handle_IRQ_event(irq, action) != IRQ_NONE)
  53. ok = 1;
  54. raw_spin_lock(&desc->lock);
  55. action = desc->action;
  56. } while ((desc->status & IRQ_PENDING) && action);
  57. desc->status &= ~IRQ_INPROGRESS;
  58. /*
  59. * If we did actual work for the real IRQ line we must let the
  60. * IRQ controller clean up too
  61. */
  62. if (work > 1)
  63. irq_end(irq, desc);
  64. out:
  65. raw_spin_unlock(&desc->lock);
  66. return ok;
  67. }
  68. static int misrouted_irq(int irq)
  69. {
  70. struct irq_desc *desc;
  71. int i, ok = 0;
  72. for_each_irq_desc(i, desc) {
  73. if (!i)
  74. continue;
  75. if (i == irq) /* Already tried */
  76. continue;
  77. if (try_one_irq(i, desc))
  78. ok = 1;
  79. }
  80. /* So the caller can adjust the irq error counts */
  81. return ok;
  82. }
  83. static void poll_spurious_irqs(unsigned long dummy)
  84. {
  85. struct irq_desc *desc;
  86. int i;
  87. for_each_irq_desc(i, desc) {
  88. unsigned int status;
  89. if (!i)
  90. continue;
  91. /* Racy but it doesn't matter */
  92. status = desc->status;
  93. barrier();
  94. if (!(status & IRQ_SPURIOUS_DISABLED))
  95. continue;
  96. local_irq_disable();
  97. try_one_irq(i, desc);
  98. local_irq_enable();
  99. }
  100. mod_timer(&poll_spurious_irq_timer,
  101. jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
  102. }
  103. /*
  104. * If 99,900 of the previous 100,000 interrupts have not been handled
  105. * then assume that the IRQ is stuck in some manner. Drop a diagnostic
  106. * and try to turn the IRQ off.
  107. *
  108. * (The other 100-of-100,000 interrupts may have been a correctly
  109. * functioning device sharing an IRQ with the failing one)
  110. */
  111. static void
  112. __report_bad_irq(unsigned int irq, struct irq_desc *desc,
  113. irqreturn_t action_ret)
  114. {
  115. struct irqaction *action;
  116. unsigned long flags;
  117. if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
  118. printk(KERN_ERR "irq event %d: bogus return value %x\n",
  119. irq, action_ret);
  120. } else {
  121. printk(KERN_ERR "irq %d: nobody cared (try booting with "
  122. "the \"irqpoll\" option)\n", irq);
  123. }
  124. dump_stack();
  125. printk(KERN_ERR "handlers:\n");
  126. /*
  127. * We need to take desc->lock here. note_interrupt() is called
  128. * w/o desc->lock held, but IRQ_PROGRESS set. We might race
  129. * with something else removing an action. It's ok to take
  130. * desc->lock here. See synchronize_irq().
  131. */
  132. raw_spin_lock_irqsave(&desc->lock, flags);
  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. raw_spin_unlock_irqrestore(&desc->lock, flags);
  142. }
  143. static void
  144. report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  145. {
  146. static int count = 100;
  147. if (count > 0) {
  148. count--;
  149. __report_bad_irq(irq, desc, action_ret);
  150. }
  151. }
  152. static inline int
  153. try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
  154. irqreturn_t action_ret)
  155. {
  156. struct irqaction *action;
  157. if (!irqfixup)
  158. return 0;
  159. /* We didn't actually handle the IRQ - see if it was misrouted? */
  160. if (action_ret == IRQ_NONE)
  161. return 1;
  162. /*
  163. * But for 'irqfixup == 2' we also do it for handled interrupts if
  164. * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
  165. * traditional PC timer interrupt.. Legacy)
  166. */
  167. if (irqfixup < 2)
  168. return 0;
  169. if (!irq)
  170. return 1;
  171. /*
  172. * Since we don't get the descriptor lock, "action" can
  173. * change under us. We don't really care, but we don't
  174. * want to follow a NULL pointer. So tell the compiler to
  175. * just load it once by using a barrier.
  176. */
  177. action = desc->action;
  178. barrier();
  179. return action && (action->flags & IRQF_IRQPOLL);
  180. }
  181. void note_interrupt(unsigned int irq, struct irq_desc *desc,
  182. irqreturn_t action_ret)
  183. {
  184. if (unlikely(action_ret != IRQ_HANDLED)) {
  185. /*
  186. * If we are seeing only the odd spurious IRQ caused by
  187. * bus asynchronicity then don't eventually trigger an error,
  188. * otherwise the counter becomes a doomsday timer for otherwise
  189. * working systems
  190. */
  191. if (time_after(jiffies, desc->last_unhandled + HZ/10))
  192. desc->irqs_unhandled = 1;
  193. else
  194. desc->irqs_unhandled++;
  195. desc->last_unhandled = jiffies;
  196. if (unlikely(action_ret != IRQ_NONE))
  197. report_bad_irq(irq, desc, action_ret);
  198. }
  199. if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
  200. int ok = misrouted_irq(irq);
  201. if (action_ret == IRQ_NONE)
  202. desc->irqs_unhandled -= ok;
  203. }
  204. desc->irq_count++;
  205. if (likely(desc->irq_count < 100000))
  206. return;
  207. desc->irq_count = 0;
  208. if (unlikely(desc->irqs_unhandled > 99900)) {
  209. /*
  210. * The interrupt is stuck
  211. */
  212. __report_bad_irq(irq, desc, action_ret);
  213. /*
  214. * Now kill the IRQ
  215. */
  216. printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
  217. desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
  218. desc->depth++;
  219. desc->irq_data.chip->irq_disable(&desc->irq_data);
  220. mod_timer(&poll_spurious_irq_timer,
  221. 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. static int __init irqpoll_setup(char *str)
  245. {
  246. irqfixup = 2;
  247. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  248. "enabled\n");
  249. printk(KERN_WARNING "This may significantly impact system "
  250. "performance\n");
  251. return 1;
  252. }
  253. __setup("irqpoll", irqpoll_setup);