blob: 2fbfda2716e1253c33aeef02037766723f789760 [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);
24
Alan Cox200803d2005-06-28 20:45:18 -070025/*
26 * Recovery handler for misrouted interrupts.
27 */
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070028static int try_one_irq(int irq, struct irq_desc *desc)
29{
30 struct irqaction *action;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020031 int ok = 0, work = 0;
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070032
Thomas Gleixner239007b2009-11-17 16:46:45 +010033 raw_spin_lock(&desc->lock);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070034 /* 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 Gleixner239007b2009-11-17 16:46:45 +010042 raw_spin_unlock(&desc->lock);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070043 return ok;
44 }
45 /* Honour the normal IRQ locking */
46 desc->status |= IRQ_INPROGRESS;
47 action = desc->action;
Thomas Gleixner239007b2009-11-17 16:46:45 +010048 raw_spin_unlock(&desc->lock);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070049
50 while (action) {
51 /* Only shared IRQ handlers are safe to call */
52 if (action->flags & IRQF_SHARED) {
53 if (action->handler(irq, action->dev_id) ==
54 IRQ_HANDLED)
55 ok = 1;
56 }
57 action = action->next;
58 }
59 local_irq_disable();
60 /* Now clean up the flags */
Thomas Gleixner239007b2009-11-17 16:46:45 +010061 raw_spin_lock(&desc->lock);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070062 action = desc->action;
63
64 /*
65 * While we were looking for a fixup someone queued a real
66 * IRQ clashing with our walk:
67 */
68 while ((desc->status & IRQ_PENDING) && action) {
69 /*
70 * Perform real IRQ processing for the IRQ we deferred
71 */
72 work = 1;
Thomas Gleixner239007b2009-11-17 16:46:45 +010073 raw_spin_unlock(&desc->lock);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070074 handle_IRQ_event(irq, action);
Thomas Gleixner239007b2009-11-17 16:46:45 +010075 raw_spin_lock(&desc->lock);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070076 desc->status &= ~IRQ_PENDING;
77 }
78 desc->status &= ~IRQ_INPROGRESS;
79 /*
80 * If we did actual work for the real IRQ line we must let the
81 * IRQ controller clean up too
82 */
Thomas Gleixnerbd151412010-10-01 15:17:14 +020083 if (work)
84 irq_end(irq, desc);
Thomas Gleixner239007b2009-11-17 16:46:45 +010085 raw_spin_unlock(&desc->lock);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070086
87 return ok;
88}
89
David Howells7d12e782006-10-05 14:55:46 +010090static int misrouted_irq(int irq)
Alan Cox200803d2005-06-28 20:45:18 -070091{
Yinghai Lue00585b2008-09-15 01:53:50 -070092 struct irq_desc *desc;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020093 int i, ok = 0;
Alan Cox200803d2005-06-28 20:45:18 -070094
Yinghai Lue00585b2008-09-15 01:53:50 -070095 for_each_irq_desc(i, desc) {
96 if (!i)
97 continue;
Alan Cox200803d2005-06-28 20:45:18 -070098
99 if (i == irq) /* Already tried */
100 continue;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700101
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700102 if (try_one_irq(i, desc))
103 ok = 1;
Alan Cox200803d2005-06-28 20:45:18 -0700104 }
105 /* So the caller can adjust the irq error counts */
106 return ok;
107}
108
Thomas Gleixner663e6952009-11-04 14:22:21 +0100109static void poll_spurious_irqs(unsigned long dummy)
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700110{
Yinghai Lue00585b2008-09-15 01:53:50 -0700111 struct irq_desc *desc;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200112 int i;
Yinghai Lue00585b2008-09-15 01:53:50 -0700113
114 for_each_irq_desc(i, desc) {
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700115 unsigned int status;
116
Yinghai Lue00585b2008-09-15 01:53:50 -0700117 if (!i)
118 continue;
119
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700120 /* Racy but it doesn't matter */
121 status = desc->status;
122 barrier();
123 if (!(status & IRQ_SPURIOUS_DISABLED))
124 continue;
125
Yong Zhange7e7e0c2009-11-07 11:16:13 +0800126 local_irq_disable();
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700127 try_one_irq(i, desc);
Yong Zhange7e7e0c2009-11-07 11:16:13 +0800128 local_irq_enable();
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700129 }
130
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200131 mod_timer(&poll_spurious_irq_timer,
132 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700133}
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/*
136 * If 99,900 of the previous 100,000 interrupts have not been handled
137 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
138 * and try to turn the IRQ off.
139 *
140 * (The other 100-of-100,000 interrupts may have been a correctly
141 * functioning device sharing an IRQ with the failing one)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700144__report_bad_irq(unsigned int irq, struct irq_desc *desc,
145 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 struct irqaction *action;
Thomas Gleixner10826872011-02-07 09:05:05 +0100148 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
151 printk(KERN_ERR "irq event %d: bogus return value %x\n",
152 irq, action_ret);
153 } else {
Alan Cox200803d2005-06-28 20:45:18 -0700154 printk(KERN_ERR "irq %d: nobody cared (try booting with "
155 "the \"irqpoll\" option)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157 dump_stack();
158 printk(KERN_ERR "handlers:\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700159
Thomas Gleixner10826872011-02-07 09:05:05 +0100160 /*
161 * We need to take desc->lock here. note_interrupt() is called
162 * w/o desc->lock held, but IRQ_PROGRESS set. We might race
163 * with something else removing an action. It's ok to take
164 * desc->lock here. See synchronize_irq().
165 */
166 raw_spin_lock_irqsave(&desc->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 action = desc->action;
168 while (action) {
169 printk(KERN_ERR "[<%p>]", action->handler);
170 print_symbol(" (%s)",
171 (unsigned long)action->handler);
172 printk("\n");
173 action = action->next;
174 }
Thomas Gleixner10826872011-02-07 09:05:05 +0100175 raw_spin_unlock_irqrestore(&desc->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700178static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700179report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 static int count = 100;
182
183 if (count > 0) {
184 count--;
185 __report_bad_irq(irq, desc, action_ret);
186 }
187}
188
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200189static inline int
190try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
191 irqreturn_t action_ret)
Linus Torvalds92ea7722007-05-24 08:37:14 -0700192{
193 struct irqaction *action;
194
195 if (!irqfixup)
196 return 0;
197
198 /* We didn't actually handle the IRQ - see if it was misrouted? */
199 if (action_ret == IRQ_NONE)
200 return 1;
201
202 /*
203 * But for 'irqfixup == 2' we also do it for handled interrupts if
204 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
205 * traditional PC timer interrupt.. Legacy)
206 */
207 if (irqfixup < 2)
208 return 0;
209
210 if (!irq)
211 return 1;
212
213 /*
214 * Since we don't get the descriptor lock, "action" can
215 * change under us. We don't really care, but we don't
216 * want to follow a NULL pointer. So tell the compiler to
217 * just load it once by using a barrier.
218 */
219 action = desc->action;
220 barrier();
221 return action && (action->flags & IRQF_IRQPOLL);
222}
223
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700224void note_interrupt(unsigned int irq, struct irq_desc *desc,
David Howells7d12e782006-10-05 14:55:46 +0100225 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700227 if (unlikely(action_ret != IRQ_HANDLED)) {
Alan Cox4f27c002007-07-15 23:40:55 -0700228 /*
229 * If we are seeing only the odd spurious IRQ caused by
230 * bus asynchronicity then don't eventually trigger an error,
Uwe Kleine-Königfbfecd32009-10-28 20:11:04 +0100231 * otherwise the counter becomes a doomsday timer for otherwise
Alan Cox4f27c002007-07-15 23:40:55 -0700232 * working systems
233 */
S.Caglar Onur188fd892008-02-14 17:36:51 +0200234 if (time_after(jiffies, desc->last_unhandled + HZ/10))
Alan Cox4f27c002007-07-15 23:40:55 -0700235 desc->irqs_unhandled = 1;
236 else
237 desc->irqs_unhandled++;
238 desc->last_unhandled = jiffies;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700239 if (unlikely(action_ret != IRQ_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 report_bad_irq(irq, desc, action_ret);
241 }
242
Linus Torvalds92ea7722007-05-24 08:37:14 -0700243 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
244 int ok = misrouted_irq(irq);
245 if (action_ret == IRQ_NONE)
246 desc->irqs_unhandled -= ok;
Alan Cox200803d2005-06-28 20:45:18 -0700247 }
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 desc->irq_count++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700250 if (likely(desc->irq_count < 100000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return;
252
253 desc->irq_count = 0;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700254 if (unlikely(desc->irqs_unhandled > 99900)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 /*
256 * The interrupt is stuck
257 */
258 __report_bad_irq(irq, desc, action_ret);
259 /*
260 * Now kill the IRQ
261 */
262 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
Thomas Gleixner1adb0852008-04-28 17:01:56 +0200263 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
264 desc->depth++;
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000265 desc->irq_data.chip->irq_disable(&desc->irq_data);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700266
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200267 mod_timer(&poll_spurious_irq_timer,
268 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
270 desc->irqs_unhandled = 0;
271}
272
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700273int noirqdebug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Vivek Goyal343cde52007-01-11 01:52:44 +0100275int noirqdebug_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
277 noirqdebug = 1;
278 printk(KERN_INFO "IRQ lockup detection disabled\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 return 1;
281}
282
283__setup("noirqdebug", noirqdebug_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100284module_param(noirqdebug, bool, 0644);
285MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Alan Cox200803d2005-06-28 20:45:18 -0700287static int __init irqfixup_setup(char *str)
288{
289 irqfixup = 1;
290 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
291 printk(KERN_WARNING "This may impact system performance.\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700292
Alan Cox200803d2005-06-28 20:45:18 -0700293 return 1;
294}
295
296__setup("irqfixup", irqfixup_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100297module_param(irqfixup, int, 0644);
Alan Cox200803d2005-06-28 20:45:18 -0700298
299static int __init irqpoll_setup(char *str)
300{
301 irqfixup = 2;
302 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
303 "enabled\n");
304 printk(KERN_WARNING "This may significantly impact system "
305 "performance\n");
306 return 1;
307}
308
309__setup("irqpoll", irqpoll_setup);