spurious.c 7.0 KB

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