blob: f749d29bfd81d3f460d90cb9f1f181024d148d39 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Onur188fd892008-02-14 17:36:51 +02009#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/irq.h>
11#include <linux/module.h>
12#include <linux/kallsyms.h>
13#include <linux/interrupt.h>
Andi Kleen9e094c12008-01-30 13:32:48 +010014#include <linux/moduleparam.h>
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070015#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Thomas Gleixnerbd151412010-10-01 15:17:14 +020017#include "internals.h"
18
Andreas Mohr83d4e6e2006-06-23 02:05:32 -070019static int irqfixup __read_mostly;
Alan Cox200803d2005-06-28 20:45:18 -070020
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070021#define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10)
22static void poll_spurious_irqs(unsigned long dummy);
23static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0);
Thomas Gleixnerd05c65f2011-02-07 14:31:37 +010024static int irq_poll_cpu;
25static atomic_t irq_poll_active;
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070026
Alan Cox200803d2005-06-28 20:45:18 -070027/*
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +010028 * We wait here for a poller to finish.
29 *
30 * If the poll runs on this CPU, then we yell loudly and return
31 * false. That will leave the interrupt line disabled in the worst
32 * case, but it should never happen.
33 *
34 * We wait until the poller is done and then recheck disabled and
35 * action (about to be disabled). Only if it's still active, we return
36 * true and let the handler run.
37 */
38bool irq_wait_for_poll(struct irq_desc *desc)
39{
40 if (WARN_ONCE(irq_poll_cpu == smp_processor_id(),
41 "irq poll in progress on cpu %d for irq %d\n",
42 smp_processor_id(), desc->irq_data.irq))
43 return false;
44
45#ifdef CONFIG_SMP
46 do {
47 raw_spin_unlock(&desc->lock);
48 while (desc->status & IRQ_INPROGRESS)
49 cpu_relax();
50 raw_spin_lock(&desc->lock);
51 } while (desc->status & IRQ_INPROGRESS);
52 /* Might have been disabled in meantime */
53 return !(desc->status & IRQ_DISABLED) && desc->action;
54#else
55 return false;
56#endif
57}
58
59/*
Alan Cox200803d2005-06-28 20:45:18 -070060 * Recovery handler for misrouted interrupts.
61 */
Thomas Gleixnerc7259cd2011-02-07 09:52:27 +010062static int try_one_irq(int irq, struct irq_desc *desc, bool force)
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070063{
64 struct irqaction *action;
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +010065 int ok = 0;
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070066
Thomas Gleixner239007b2009-11-17 16:46:45 +010067 raw_spin_lock(&desc->lock);
Thomas Gleixnerc7259cd2011-02-07 09:52:27 +010068
69 /* PER_CPU and nested thread interrupts are never polled */
70 if (desc->status & (IRQ_PER_CPU | IRQ_NESTED_THREAD))
71 goto out;
72
73 /*
74 * Do not poll disabled interrupts unless the spurious
75 * disabled poller asks explicitely.
76 */
77 if ((desc->status & IRQ_DISABLED) && !force)
78 goto out;
79
80 /*
81 * All handlers must agree on IRQF_SHARED, so we test just the
82 * first. Check for action->next as well.
83 */
84 action = desc->action;
85 if (!action || !(action->flags & IRQF_SHARED) ||
86 (action->flags & __IRQF_TIMER) || !action->next)
87 goto out;
88
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070089 /* Already running on another processor */
90 if (desc->status & IRQ_INPROGRESS) {
91 /*
92 * Already running: If it is shared get the other
93 * CPU to go looking for our mystery interrupt too
94 */
Thomas Gleixnerc7259cd2011-02-07 09:52:27 +010095 desc->status |= IRQ_PENDING;
Thomas Gleixnerfa272712011-02-07 09:10:39 +010096 goto out;
Thomas Gleixnerc7259cd2011-02-07 09:52:27 +010097 }
Thomas Gleixnerfa272712011-02-07 09:10:39 +010098
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +010099 /* Honour the normal IRQ locking and mark it poll in progress */
100 desc->status |= IRQ_INPROGRESS | IRQ_POLL_INPROGRESS;
Thomas Gleixnerfa272712011-02-07 09:10:39 +0100101 do {
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700102 desc->status &= ~IRQ_PENDING;
Thomas Gleixnerfa272712011-02-07 09:10:39 +0100103 raw_spin_unlock(&desc->lock);
104 if (handle_IRQ_event(irq, action) != IRQ_NONE)
105 ok = 1;
106 raw_spin_lock(&desc->lock);
107 action = desc->action;
108 } while ((desc->status & IRQ_PENDING) && action);
109
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100110 desc->status &= ~(IRQ_INPROGRESS | IRQ_POLL_INPROGRESS);
Thomas Gleixnerfa272712011-02-07 09:10:39 +0100111out:
112 raw_spin_unlock(&desc->lock);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700113 return ok;
114}
115
David Howells7d12e782006-10-05 14:55:46 +0100116static int misrouted_irq(int irq)
Alan Cox200803d2005-06-28 20:45:18 -0700117{
Yinghai Lue00585b2008-09-15 01:53:50 -0700118 struct irq_desc *desc;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200119 int i, ok = 0;
Alan Cox200803d2005-06-28 20:45:18 -0700120
Thomas Gleixnerd05c65f2011-02-07 14:31:37 +0100121 if (atomic_inc_return(&irq_poll_active) == 1)
122 goto out;
123
124 irq_poll_cpu = smp_processor_id();
125
Yinghai Lue00585b2008-09-15 01:53:50 -0700126 for_each_irq_desc(i, desc) {
127 if (!i)
128 continue;
Alan Cox200803d2005-06-28 20:45:18 -0700129
130 if (i == irq) /* Already tried */
131 continue;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700132
Thomas Gleixnerc7259cd2011-02-07 09:52:27 +0100133 if (try_one_irq(i, desc, false))
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700134 ok = 1;
Alan Cox200803d2005-06-28 20:45:18 -0700135 }
Thomas Gleixnerd05c65f2011-02-07 14:31:37 +0100136out:
137 atomic_dec(&irq_poll_active);
Alan Cox200803d2005-06-28 20:45:18 -0700138 /* So the caller can adjust the irq error counts */
139 return ok;
140}
141
Thomas Gleixner663e6952009-11-04 14:22:21 +0100142static void poll_spurious_irqs(unsigned long dummy)
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700143{
Yinghai Lue00585b2008-09-15 01:53:50 -0700144 struct irq_desc *desc;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200145 int i;
Yinghai Lue00585b2008-09-15 01:53:50 -0700146
Thomas Gleixnerd05c65f2011-02-07 14:31:37 +0100147 if (atomic_inc_return(&irq_poll_active) != 1)
148 goto out;
149 irq_poll_cpu = smp_processor_id();
150
Yinghai Lue00585b2008-09-15 01:53:50 -0700151 for_each_irq_desc(i, desc) {
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700152 unsigned int status;
153
Yinghai Lue00585b2008-09-15 01:53:50 -0700154 if (!i)
155 continue;
156
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700157 /* Racy but it doesn't matter */
158 status = desc->status;
159 barrier();
160 if (!(status & IRQ_SPURIOUS_DISABLED))
161 continue;
162
Yong Zhange7e7e0c2009-11-07 11:16:13 +0800163 local_irq_disable();
Thomas Gleixnerc7259cd2011-02-07 09:52:27 +0100164 try_one_irq(i, desc, true);
Yong Zhange7e7e0c2009-11-07 11:16:13 +0800165 local_irq_enable();
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700166 }
Thomas Gleixnerd05c65f2011-02-07 14:31:37 +0100167out:
168 atomic_dec(&irq_poll_active);
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200169 mod_timer(&poll_spurious_irq_timer,
170 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/*
174 * If 99,900 of the previous 100,000 interrupts have not been handled
175 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
176 * and try to turn the IRQ off.
177 *
178 * (The other 100-of-100,000 interrupts may have been a correctly
179 * functioning device sharing an IRQ with the failing one)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700182__report_bad_irq(unsigned int irq, struct irq_desc *desc,
183 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 struct irqaction *action;
Thomas Gleixner10826872011-02-07 09:05:05 +0100186 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
189 printk(KERN_ERR "irq event %d: bogus return value %x\n",
190 irq, action_ret);
191 } else {
Alan Cox200803d2005-06-28 20:45:18 -0700192 printk(KERN_ERR "irq %d: nobody cared (try booting with "
193 "the \"irqpoll\" option)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
195 dump_stack();
196 printk(KERN_ERR "handlers:\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700197
Thomas Gleixner10826872011-02-07 09:05:05 +0100198 /*
199 * We need to take desc->lock here. note_interrupt() is called
200 * w/o desc->lock held, but IRQ_PROGRESS set. We might race
201 * with something else removing an action. It's ok to take
202 * desc->lock here. See synchronize_irq().
203 */
204 raw_spin_lock_irqsave(&desc->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 action = desc->action;
206 while (action) {
207 printk(KERN_ERR "[<%p>]", action->handler);
208 print_symbol(" (%s)",
209 (unsigned long)action->handler);
210 printk("\n");
211 action = action->next;
212 }
Thomas Gleixner10826872011-02-07 09:05:05 +0100213 raw_spin_unlock_irqrestore(&desc->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700216static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700217report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
219 static int count = 100;
220
221 if (count > 0) {
222 count--;
223 __report_bad_irq(irq, desc, action_ret);
224 }
225}
226
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200227static inline int
228try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
229 irqreturn_t action_ret)
Linus Torvalds92ea7722007-05-24 08:37:14 -0700230{
231 struct irqaction *action;
232
233 if (!irqfixup)
234 return 0;
235
236 /* We didn't actually handle the IRQ - see if it was misrouted? */
237 if (action_ret == IRQ_NONE)
238 return 1;
239
240 /*
241 * But for 'irqfixup == 2' we also do it for handled interrupts if
242 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
243 * traditional PC timer interrupt.. Legacy)
244 */
245 if (irqfixup < 2)
246 return 0;
247
248 if (!irq)
249 return 1;
250
251 /*
252 * Since we don't get the descriptor lock, "action" can
253 * change under us. We don't really care, but we don't
254 * want to follow a NULL pointer. So tell the compiler to
255 * just load it once by using a barrier.
256 */
257 action = desc->action;
258 barrier();
259 return action && (action->flags & IRQF_IRQPOLL);
260}
261
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700262void note_interrupt(unsigned int irq, struct irq_desc *desc,
David Howells7d12e782006-10-05 14:55:46 +0100263 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100265 if (desc->status & IRQ_POLL_INPROGRESS)
266 return;
267
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700268 if (unlikely(action_ret != IRQ_HANDLED)) {
Alan Cox4f27c002007-07-15 23:40:55 -0700269 /*
270 * If we are seeing only the odd spurious IRQ caused by
271 * bus asynchronicity then don't eventually trigger an error,
Uwe Kleine-Königfbfecd32009-10-28 20:11:04 +0100272 * otherwise the counter becomes a doomsday timer for otherwise
Alan Cox4f27c002007-07-15 23:40:55 -0700273 * working systems
274 */
S.Caglar Onur188fd892008-02-14 17:36:51 +0200275 if (time_after(jiffies, desc->last_unhandled + HZ/10))
Alan Cox4f27c002007-07-15 23:40:55 -0700276 desc->irqs_unhandled = 1;
277 else
278 desc->irqs_unhandled++;
279 desc->last_unhandled = jiffies;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700280 if (unlikely(action_ret != IRQ_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 report_bad_irq(irq, desc, action_ret);
282 }
283
Linus Torvalds92ea7722007-05-24 08:37:14 -0700284 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
285 int ok = misrouted_irq(irq);
286 if (action_ret == IRQ_NONE)
287 desc->irqs_unhandled -= ok;
Alan Cox200803d2005-06-28 20:45:18 -0700288 }
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 desc->irq_count++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700291 if (likely(desc->irq_count < 100000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 return;
293
294 desc->irq_count = 0;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700295 if (unlikely(desc->irqs_unhandled > 99900)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 /*
297 * The interrupt is stuck
298 */
299 __report_bad_irq(irq, desc, action_ret);
300 /*
301 * Now kill the IRQ
302 */
303 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
Thomas Gleixner1adb0852008-04-28 17:01:56 +0200304 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
305 desc->depth++;
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000306 desc->irq_data.chip->irq_disable(&desc->irq_data);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700307
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200308 mod_timer(&poll_spurious_irq_timer,
309 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311 desc->irqs_unhandled = 0;
312}
313
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700314int noirqdebug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Vivek Goyal343cde52007-01-11 01:52:44 +0100316int noirqdebug_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 noirqdebug = 1;
319 printk(KERN_INFO "IRQ lockup detection disabled\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 return 1;
322}
323
324__setup("noirqdebug", noirqdebug_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100325module_param(noirqdebug, bool, 0644);
326MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Alan Cox200803d2005-06-28 20:45:18 -0700328static int __init irqfixup_setup(char *str)
329{
330 irqfixup = 1;
331 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
332 printk(KERN_WARNING "This may impact system performance.\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700333
Alan Cox200803d2005-06-28 20:45:18 -0700334 return 1;
335}
336
337__setup("irqfixup", irqfixup_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100338module_param(irqfixup, int, 0644);
Alan Cox200803d2005-06-28 20:45:18 -0700339
340static int __init irqpoll_setup(char *str)
341{
342 irqfixup = 2;
343 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
344 "enabled\n");
345 printk(KERN_WARNING "This may significantly impact system "
346 "performance\n");
347 return 1;
348}
349
350__setup("irqpoll", irqpoll_setup);