blob: 0af9e59c82ebf8008af6d75778c9d64c9d9a8802 [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 }
Thomas Gleixnerfa272712011-02-07 09:10:39 +010045 /*
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. Biedermanf84dbb92008-07-10 14:48:54 -070053 /* Honour the normal IRQ locking */
54 desc->status |= IRQ_INPROGRESS;
Thomas Gleixnerfa272712011-02-07 09:10:39 +010055 do {
56 work++;
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070057 desc->status &= ~IRQ_PENDING;
Thomas Gleixnerfa272712011-02-07 09:10:39 +010058 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. Biedermanf84dbb92008-07-10 14:48:54 -070065 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 Gleixnerfa272712011-02-07 09:10:39 +010070 if (work > 1)
Thomas Gleixnerbd151412010-10-01 15:17:14 +020071 irq_end(irq, desc);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070072
Thomas Gleixnerfa272712011-02-07 09:10:39 +010073out:
74 raw_spin_unlock(&desc->lock);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070075 return ok;
76}
77
David Howells7d12e782006-10-05 14:55:46 +010078static int misrouted_irq(int irq)
Alan Cox200803d2005-06-28 20:45:18 -070079{
Yinghai Lue00585b2008-09-15 01:53:50 -070080 struct irq_desc *desc;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020081 int i, ok = 0;
Alan Cox200803d2005-06-28 20:45:18 -070082
Yinghai Lue00585b2008-09-15 01:53:50 -070083 for_each_irq_desc(i, desc) {
84 if (!i)
85 continue;
Alan Cox200803d2005-06-28 20:45:18 -070086
87 if (i == irq) /* Already tried */
88 continue;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070089
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070090 if (try_one_irq(i, desc))
91 ok = 1;
Alan Cox200803d2005-06-28 20:45:18 -070092 }
93 /* So the caller can adjust the irq error counts */
94 return ok;
95}
96
Thomas Gleixner663e6952009-11-04 14:22:21 +010097static void poll_spurious_irqs(unsigned long dummy)
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070098{
Yinghai Lue00585b2008-09-15 01:53:50 -070099 struct irq_desc *desc;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200100 int i;
Yinghai Lue00585b2008-09-15 01:53:50 -0700101
102 for_each_irq_desc(i, desc) {
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700103 unsigned int status;
104
Yinghai Lue00585b2008-09-15 01:53:50 -0700105 if (!i)
106 continue;
107
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700108 /* Racy but it doesn't matter */
109 status = desc->status;
110 barrier();
111 if (!(status & IRQ_SPURIOUS_DISABLED))
112 continue;
113
Yong Zhange7e7e0c2009-11-07 11:16:13 +0800114 local_irq_disable();
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700115 try_one_irq(i, desc);
Yong Zhange7e7e0c2009-11-07 11:16:13 +0800116 local_irq_enable();
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700117 }
118
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200119 mod_timer(&poll_spurious_irq_timer,
120 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700121}
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123/*
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 Torvalds1da177e2005-04-16 15:20:36 -0700130 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700132__report_bad_irq(unsigned int irq, struct irq_desc *desc,
133 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 struct irqaction *action;
Thomas Gleixner10826872011-02-07 09:05:05 +0100136 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
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 Cox200803d2005-06-28 20:45:18 -0700142 printk(KERN_ERR "irq %d: nobody cared (try booting with "
143 "the \"irqpoll\" option)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
145 dump_stack();
146 printk(KERN_ERR "handlers:\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700147
Thomas Gleixner10826872011-02-07 09:05:05 +0100148 /*
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 Torvalds1da177e2005-04-16 15:20:36 -0700155 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 Gleixner10826872011-02-07 09:05:05 +0100163 raw_spin_unlock_irqrestore(&desc->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700166static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700167report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
169 static int count = 100;
170
171 if (count > 0) {
172 count--;
173 __report_bad_irq(irq, desc, action_ret);
174 }
175}
176
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200177static inline int
178try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
179 irqreturn_t action_ret)
Linus Torvalds92ea7722007-05-24 08:37:14 -0700180{
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 Molnar34ffdb72006-06-29 02:24:40 -0700212void note_interrupt(unsigned int irq, struct irq_desc *desc,
David Howells7d12e782006-10-05 14:55:46 +0100213 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700215 if (unlikely(action_ret != IRQ_HANDLED)) {
Alan Cox4f27c002007-07-15 23:40:55 -0700216 /*
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önigfbfecd32009-10-28 20:11:04 +0100219 * otherwise the counter becomes a doomsday timer for otherwise
Alan Cox4f27c002007-07-15 23:40:55 -0700220 * working systems
221 */
S.Caglar Onur188fd892008-02-14 17:36:51 +0200222 if (time_after(jiffies, desc->last_unhandled + HZ/10))
Alan Cox4f27c002007-07-15 23:40:55 -0700223 desc->irqs_unhandled = 1;
224 else
225 desc->irqs_unhandled++;
226 desc->last_unhandled = jiffies;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700227 if (unlikely(action_ret != IRQ_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 report_bad_irq(irq, desc, action_ret);
229 }
230
Linus Torvalds92ea7722007-05-24 08:37:14 -0700231 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 Cox200803d2005-06-28 20:45:18 -0700235 }
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 desc->irq_count++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700238 if (likely(desc->irq_count < 100000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 return;
240
241 desc->irq_count = 0;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700242 if (unlikely(desc->irqs_unhandled > 99900)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 /*
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 Gleixner1adb0852008-04-28 17:01:56 +0200251 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
252 desc->depth++;
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000253 desc->irq_data.chip->irq_disable(&desc->irq_data);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700254
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200255 mod_timer(&poll_spurious_irq_timer,
256 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258 desc->irqs_unhandled = 0;
259}
260
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700261int noirqdebug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Vivek Goyal343cde52007-01-11 01:52:44 +0100263int noirqdebug_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
265 noirqdebug = 1;
266 printk(KERN_INFO "IRQ lockup detection disabled\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return 1;
269}
270
271__setup("noirqdebug", noirqdebug_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100272module_param(noirqdebug, bool, 0644);
273MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Alan Cox200803d2005-06-28 20:45:18 -0700275static 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 Molnar06fcb0c2006-06-29 02:24:40 -0700280
Alan Cox200803d2005-06-28 20:45:18 -0700281 return 1;
282}
283
284__setup("irqfixup", irqfixup_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100285module_param(irqfixup, int, 0644);
Alan Cox200803d2005-06-28 20:45:18 -0700286
287static 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);