Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
S.Caglar Onur | 188fd89 | 2008-02-14 17:36:51 +0200 | [diff] [blame] | 9 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/irq.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/kallsyms.h> |
| 13 | #include <linux/interrupt.h> |
Andi Kleen | 9e094c1 | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 14 | #include <linux/moduleparam.h> |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 15 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Thomas Gleixner | bd15141 | 2010-10-01 15:17:14 +0200 | [diff] [blame] | 17 | #include "internals.h" |
| 18 | |
Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 19 | static int irqfixup __read_mostly; |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 20 | |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 21 | #define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10) |
| 22 | static void poll_spurious_irqs(unsigned long dummy); |
| 23 | static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0); |
| 24 | |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 25 | /* |
| 26 | * Recovery handler for misrouted interrupts. |
| 27 | */ |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 28 | static int try_one_irq(int irq, struct irq_desc *desc) |
| 29 | { |
| 30 | struct irqaction *action; |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 31 | int ok = 0, work = 0; |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 32 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 33 | raw_spin_lock(&desc->lock); |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 34 | /* Already running on another processor */ |
| 35 | if (desc->status & IRQ_INPROGRESS) { |
| 36 | /* |
| 37 | * Already running: If it is shared get the other |
| 38 | * CPU to go looking for our mystery interrupt too |
| 39 | */ |
| 40 | if (desc->action && (desc->action->flags & IRQF_SHARED)) |
| 41 | desc->status |= IRQ_PENDING; |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 42 | raw_spin_unlock(&desc->lock); |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 43 | return ok; |
| 44 | } |
Thomas Gleixner | fa27271 | 2011-02-07 09:10:39 +0100 | [diff] [blame^] | 45 | /* |
| 46 | * All handlers must agree on IRQF_SHARED, so we test just the |
| 47 | * first. Check for action->next as well. |
| 48 | */ |
| 49 | action = desc->action; |
| 50 | if (!action || !(action->flags & IRQF_SHARED) || !action->next) |
| 51 | goto out; |
| 52 | |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 53 | /* Honour the normal IRQ locking */ |
| 54 | desc->status |= IRQ_INPROGRESS; |
Thomas Gleixner | fa27271 | 2011-02-07 09:10:39 +0100 | [diff] [blame^] | 55 | do { |
| 56 | work++; |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 57 | desc->status &= ~IRQ_PENDING; |
Thomas Gleixner | fa27271 | 2011-02-07 09:10:39 +0100 | [diff] [blame^] | 58 | raw_spin_unlock(&desc->lock); |
| 59 | if (handle_IRQ_event(irq, action) != IRQ_NONE) |
| 60 | ok = 1; |
| 61 | raw_spin_lock(&desc->lock); |
| 62 | action = desc->action; |
| 63 | } while ((desc->status & IRQ_PENDING) && action); |
| 64 | |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 65 | desc->status &= ~IRQ_INPROGRESS; |
| 66 | /* |
| 67 | * If we did actual work for the real IRQ line we must let the |
| 68 | * IRQ controller clean up too |
| 69 | */ |
Thomas Gleixner | fa27271 | 2011-02-07 09:10:39 +0100 | [diff] [blame^] | 70 | if (work > 1) |
Thomas Gleixner | bd15141 | 2010-10-01 15:17:14 +0200 | [diff] [blame] | 71 | irq_end(irq, desc); |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 72 | |
Thomas Gleixner | fa27271 | 2011-02-07 09:10:39 +0100 | [diff] [blame^] | 73 | out: |
| 74 | raw_spin_unlock(&desc->lock); |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 75 | return ok; |
| 76 | } |
| 77 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 78 | static int misrouted_irq(int irq) |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 79 | { |
Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 80 | struct irq_desc *desc; |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 81 | int i, ok = 0; |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 82 | |
Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 83 | for_each_irq_desc(i, desc) { |
| 84 | if (!i) |
| 85 | continue; |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 86 | |
| 87 | if (i == irq) /* Already tried */ |
| 88 | continue; |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 89 | |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 90 | if (try_one_irq(i, desc)) |
| 91 | ok = 1; |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 92 | } |
| 93 | /* So the caller can adjust the irq error counts */ |
| 94 | return ok; |
| 95 | } |
| 96 | |
Thomas Gleixner | 663e695 | 2009-11-04 14:22:21 +0100 | [diff] [blame] | 97 | static void poll_spurious_irqs(unsigned long dummy) |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 98 | { |
Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 99 | struct irq_desc *desc; |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 100 | int i; |
Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 101 | |
| 102 | for_each_irq_desc(i, desc) { |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 103 | unsigned int status; |
| 104 | |
Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 105 | if (!i) |
| 106 | continue; |
| 107 | |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 108 | /* Racy but it doesn't matter */ |
| 109 | status = desc->status; |
| 110 | barrier(); |
| 111 | if (!(status & IRQ_SPURIOUS_DISABLED)) |
| 112 | continue; |
| 113 | |
Yong Zhang | e7e7e0c | 2009-11-07 11:16:13 +0800 | [diff] [blame] | 114 | local_irq_disable(); |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 115 | try_one_irq(i, desc); |
Yong Zhang | e7e7e0c | 2009-11-07 11:16:13 +0800 | [diff] [blame] | 116 | local_irq_enable(); |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 119 | mod_timer(&poll_spurious_irq_timer, |
| 120 | jiffies + POLL_SPURIOUS_IRQ_INTERVAL); |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | /* |
| 124 | * If 99,900 of the previous 100,000 interrupts have not been handled |
| 125 | * then assume that the IRQ is stuck in some manner. Drop a diagnostic |
| 126 | * and try to turn the IRQ off. |
| 127 | * |
| 128 | * (The other 100-of-100,000 interrupts may have been a correctly |
| 129 | * functioning device sharing an IRQ with the failing one) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | static void |
Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 132 | __report_bad_irq(unsigned int irq, struct irq_desc *desc, |
| 133 | irqreturn_t action_ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
| 135 | struct irqaction *action; |
Thomas Gleixner | 1082687 | 2011-02-07 09:05:05 +0100 | [diff] [blame] | 136 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) { |
| 139 | printk(KERN_ERR "irq event %d: bogus return value %x\n", |
| 140 | irq, action_ret); |
| 141 | } else { |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 142 | printk(KERN_ERR "irq %d: nobody cared (try booting with " |
| 143 | "the \"irqpoll\" option)\n", irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | dump_stack(); |
| 146 | printk(KERN_ERR "handlers:\n"); |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 147 | |
Thomas Gleixner | 1082687 | 2011-02-07 09:05:05 +0100 | [diff] [blame] | 148 | /* |
| 149 | * We need to take desc->lock here. note_interrupt() is called |
| 150 | * w/o desc->lock held, but IRQ_PROGRESS set. We might race |
| 151 | * with something else removing an action. It's ok to take |
| 152 | * desc->lock here. See synchronize_irq(). |
| 153 | */ |
| 154 | raw_spin_lock_irqsave(&desc->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | action = desc->action; |
| 156 | while (action) { |
| 157 | printk(KERN_ERR "[<%p>]", action->handler); |
| 158 | print_symbol(" (%s)", |
| 159 | (unsigned long)action->handler); |
| 160 | printk("\n"); |
| 161 | action = action->next; |
| 162 | } |
Thomas Gleixner | 1082687 | 2011-02-07 09:05:05 +0100 | [diff] [blame] | 163 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 166 | static void |
Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 167 | report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
| 169 | static int count = 100; |
| 170 | |
| 171 | if (count > 0) { |
| 172 | count--; |
| 173 | __report_bad_irq(irq, desc, action_ret); |
| 174 | } |
| 175 | } |
| 176 | |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 177 | static inline int |
| 178 | try_misrouted_irq(unsigned int irq, struct irq_desc *desc, |
| 179 | irqreturn_t action_ret) |
Linus Torvalds | 92ea772 | 2007-05-24 08:37:14 -0700 | [diff] [blame] | 180 | { |
| 181 | struct irqaction *action; |
| 182 | |
| 183 | if (!irqfixup) |
| 184 | return 0; |
| 185 | |
| 186 | /* We didn't actually handle the IRQ - see if it was misrouted? */ |
| 187 | if (action_ret == IRQ_NONE) |
| 188 | return 1; |
| 189 | |
| 190 | /* |
| 191 | * But for 'irqfixup == 2' we also do it for handled interrupts if |
| 192 | * they are marked as IRQF_IRQPOLL (or for irq zero, which is the |
| 193 | * traditional PC timer interrupt.. Legacy) |
| 194 | */ |
| 195 | if (irqfixup < 2) |
| 196 | return 0; |
| 197 | |
| 198 | if (!irq) |
| 199 | return 1; |
| 200 | |
| 201 | /* |
| 202 | * Since we don't get the descriptor lock, "action" can |
| 203 | * change under us. We don't really care, but we don't |
| 204 | * want to follow a NULL pointer. So tell the compiler to |
| 205 | * just load it once by using a barrier. |
| 206 | */ |
| 207 | action = desc->action; |
| 208 | barrier(); |
| 209 | return action && (action->flags & IRQF_IRQPOLL); |
| 210 | } |
| 211 | |
Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 212 | void note_interrupt(unsigned int irq, struct irq_desc *desc, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 213 | irqreturn_t action_ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 215 | if (unlikely(action_ret != IRQ_HANDLED)) { |
Alan Cox | 4f27c00 | 2007-07-15 23:40:55 -0700 | [diff] [blame] | 216 | /* |
| 217 | * If we are seeing only the odd spurious IRQ caused by |
| 218 | * bus asynchronicity then don't eventually trigger an error, |
Uwe Kleine-König | fbfecd3 | 2009-10-28 20:11:04 +0100 | [diff] [blame] | 219 | * otherwise the counter becomes a doomsday timer for otherwise |
Alan Cox | 4f27c00 | 2007-07-15 23:40:55 -0700 | [diff] [blame] | 220 | * working systems |
| 221 | */ |
S.Caglar Onur | 188fd89 | 2008-02-14 17:36:51 +0200 | [diff] [blame] | 222 | if (time_after(jiffies, desc->last_unhandled + HZ/10)) |
Alan Cox | 4f27c00 | 2007-07-15 23:40:55 -0700 | [diff] [blame] | 223 | desc->irqs_unhandled = 1; |
| 224 | else |
| 225 | desc->irqs_unhandled++; |
| 226 | desc->last_unhandled = jiffies; |
Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 227 | if (unlikely(action_ret != IRQ_NONE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | report_bad_irq(irq, desc, action_ret); |
| 229 | } |
| 230 | |
Linus Torvalds | 92ea772 | 2007-05-24 08:37:14 -0700 | [diff] [blame] | 231 | if (unlikely(try_misrouted_irq(irq, desc, action_ret))) { |
| 232 | int ok = misrouted_irq(irq); |
| 233 | if (action_ret == IRQ_NONE) |
| 234 | desc->irqs_unhandled -= ok; |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | desc->irq_count++; |
Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 238 | if (likely(desc->irq_count < 100000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return; |
| 240 | |
| 241 | desc->irq_count = 0; |
Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 242 | if (unlikely(desc->irqs_unhandled > 99900)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | /* |
| 244 | * The interrupt is stuck |
| 245 | */ |
| 246 | __report_bad_irq(irq, desc, action_ret); |
| 247 | /* |
| 248 | * Now kill the IRQ |
| 249 | */ |
| 250 | printk(KERN_EMERG "Disabling IRQ #%d\n", irq); |
Thomas Gleixner | 1adb085 | 2008-04-28 17:01:56 +0200 | [diff] [blame] | 251 | desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED; |
| 252 | desc->depth++; |
Thomas Gleixner | bc310dd | 2010-09-27 12:45:02 +0000 | [diff] [blame] | 253 | desc->irq_data.chip->irq_disable(&desc->irq_data); |
Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 254 | |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 255 | mod_timer(&poll_spurious_irq_timer, |
| 256 | jiffies + POLL_SPURIOUS_IRQ_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | desc->irqs_unhandled = 0; |
| 259 | } |
| 260 | |
Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 261 | int noirqdebug __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Vivek Goyal | 343cde5 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 263 | int noirqdebug_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
| 265 | noirqdebug = 1; |
| 266 | printk(KERN_INFO "IRQ lockup detection disabled\n"); |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | return 1; |
| 269 | } |
| 270 | |
| 271 | __setup("noirqdebug", noirqdebug_setup); |
Andi Kleen | 9e094c1 | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 272 | module_param(noirqdebug, bool, 0644); |
| 273 | MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 275 | static int __init irqfixup_setup(char *str) |
| 276 | { |
| 277 | irqfixup = 1; |
| 278 | printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n"); |
| 279 | printk(KERN_WARNING "This may impact system performance.\n"); |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 280 | |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 281 | return 1; |
| 282 | } |
| 283 | |
| 284 | __setup("irqfixup", irqfixup_setup); |
Andi Kleen | 9e094c1 | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 285 | module_param(irqfixup, int, 0644); |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 286 | |
| 287 | static int __init irqpoll_setup(char *str) |
| 288 | { |
| 289 | irqfixup = 2; |
| 290 | printk(KERN_WARNING "Misrouted IRQ fixup and polling support " |
| 291 | "enabled\n"); |
| 292 | printk(KERN_WARNING "This may significantly impact system " |
| 293 | "performance\n"); |
| 294 | return 1; |
| 295 | } |
| 296 | |
| 297 | __setup("irqpoll", irqpoll_setup); |