genirq: Fixup poll handling
[deliverable/linux.git] / kernel / irq / spurious.c
CommitLineData
1da177e4
LT
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
188fd89d 9#include <linux/jiffies.h>
1da177e4
LT
10#include <linux/irq.h>
11#include <linux/module.h>
12#include <linux/kallsyms.h>
13#include <linux/interrupt.h>
9e094c17 14#include <linux/moduleparam.h>
f84dbb91 15#include <linux/timer.h>
1da177e4 16
bd151412
TG
17#include "internals.h"
18
83d4e6e7 19static int irqfixup __read_mostly;
200803df 20
f84dbb91
EB
21#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
200803df
AC
25/*
26 * Recovery handler for misrouted interrupts.
27 */
f84dbb91 28static int try_one_irq(int irq, struct irq_desc *desc)
200803df 29{
f84dbb91 30 struct irqaction *action;
d3c60047 31 int ok = 0, work = 0;
200803df 32
239007b8 33 raw_spin_lock(&desc->lock);
f84dbb91
EB
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;
239007b8 42 raw_spin_unlock(&desc->lock);
f84dbb91
EB
43 return ok;
44 }
f84dbb91 45 /*
fa27271b
TG
46 * All handlers must agree on IRQF_SHARED, so we test just the
47 * first. Check for action->next as well.
f84dbb91 48 */
fa27271b
TG
49 action = desc->action;
50 if (!action || !(action->flags & IRQF_SHARED) || !action->next)
51 goto out;
52
53 /* Honour the normal IRQ locking */
54 desc->status |= IRQ_INPROGRESS;
55 do {
56 work++;
57 desc->status &= ~IRQ_PENDING;
239007b8 58 raw_spin_unlock(&desc->lock);
fa27271b
TG
59 if (handle_IRQ_event(irq, action) != IRQ_NONE)
60 ok = 1;
239007b8 61 raw_spin_lock(&desc->lock);
fa27271b
TG
62 action = desc->action;
63 } while ((desc->status & IRQ_PENDING) && action);
64
f84dbb91
EB
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 */
fa27271b 70 if (work > 1)
bd151412 71 irq_end(irq, desc);
f84dbb91 72
fa27271b
TG
73out:
74 raw_spin_unlock(&desc->lock);
f84dbb91
EB
75 return ok;
76}
77
78static int misrouted_irq(int irq)
79{
e00585bb 80 struct irq_desc *desc;
d3c60047 81 int i, ok = 0;
f84dbb91 82
e00585bb
YL
83 for_each_irq_desc(i, desc) {
84 if (!i)
85 continue;
f84dbb91
EB
86
87 if (i == irq) /* Already tried */
88 continue;
89
90 if (try_one_irq(i, desc))
91 ok = 1;
200803df
AC
92 }
93 /* So the caller can adjust the irq error counts */
94 return ok;
95}
96
663e6959 97static void poll_spurious_irqs(unsigned long dummy)
f84dbb91 98{
e00585bb 99 struct irq_desc *desc;
d3c60047 100 int i;
e00585bb
YL
101
102 for_each_irq_desc(i, desc) {
f84dbb91
EB
103 unsigned int status;
104
e00585bb
YL
105 if (!i)
106 continue;
107
f84dbb91
EB
108 /* Racy but it doesn't matter */
109 status = desc->status;
110 barrier();
111 if (!(status & IRQ_SPURIOUS_DISABLED))
112 continue;
113
e7e7e0c0 114 local_irq_disable();
f84dbb91 115 try_one_irq(i, desc);
e7e7e0c0 116 local_irq_enable();
f84dbb91
EB
117 }
118
d3c60047
TG
119 mod_timer(&poll_spurious_irq_timer,
120 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
f84dbb91
EB
121}
122
1da177e4
LT
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)
1da177e4 130 */
1da177e4 131static void
34ffdb72
IM
132__report_bad_irq(unsigned int irq, struct irq_desc *desc,
133 irqreturn_t action_ret)
1da177e4
LT
134{
135 struct irqaction *action;
1082687e 136 unsigned long flags;
1da177e4
LT
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 {
200803df
AC
142 printk(KERN_ERR "irq %d: nobody cared (try booting with "
143 "the \"irqpoll\" option)\n", irq);
1da177e4
LT
144 }
145 dump_stack();
146 printk(KERN_ERR "handlers:\n");
06fcb0c6 147
1082687e
TG
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);
1da177e4
LT
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 }
1082687e 163 raw_spin_unlock_irqrestore(&desc->lock, flags);
1da177e4
LT
164}
165
06fcb0c6 166static void
34ffdb72 167report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
1da177e4
LT
168{
169 static int count = 100;
170
171 if (count > 0) {
172 count--;
173 __report_bad_irq(irq, desc, action_ret);
174 }
175}
176
d3c60047
TG
177static inline int
178try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
179 irqreturn_t action_ret)
92ea7727
LT
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
34ffdb72 212void note_interrupt(unsigned int irq, struct irq_desc *desc,
7d12e780 213 irqreturn_t action_ret)
1da177e4 214{
83d4e6e7 215 if (unlikely(action_ret != IRQ_HANDLED)) {
4f27c00b
AC
216 /*
217 * If we are seeing only the odd spurious IRQ caused by
218 * bus asynchronicity then don't eventually trigger an error,
fbfecd37 219 * otherwise the counter becomes a doomsday timer for otherwise
4f27c00b
AC
220 * working systems
221 */
188fd89d 222 if (time_after(jiffies, desc->last_unhandled + HZ/10))
4f27c00b
AC
223 desc->irqs_unhandled = 1;
224 else
225 desc->irqs_unhandled++;
226 desc->last_unhandled = jiffies;
83d4e6e7 227 if (unlikely(action_ret != IRQ_NONE))
1da177e4
LT
228 report_bad_irq(irq, desc, action_ret);
229 }
230
92ea7727
LT
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;
200803df
AC
235 }
236
1da177e4 237 desc->irq_count++;
83d4e6e7 238 if (likely(desc->irq_count < 100000))
1da177e4
LT
239 return;
240
241 desc->irq_count = 0;
83d4e6e7 242 if (unlikely(desc->irqs_unhandled > 99900)) {
1da177e4
LT
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);
1adb0850
TG
251 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
252 desc->depth++;
bc310dda 253 desc->irq_data.chip->irq_disable(&desc->irq_data);
f84dbb91 254
d3c60047
TG
255 mod_timer(&poll_spurious_irq_timer,
256 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
1da177e4
LT
257 }
258 desc->irqs_unhandled = 0;
259}
260
83d4e6e7 261int noirqdebug __read_mostly;
1da177e4 262
343cde51 263int noirqdebug_setup(char *str)
1da177e4
LT
264{
265 noirqdebug = 1;
266 printk(KERN_INFO "IRQ lockup detection disabled\n");
06fcb0c6 267
1da177e4
LT
268 return 1;
269}
270
271__setup("noirqdebug", noirqdebug_setup);
9e094c17
AK
272module_param(noirqdebug, bool, 0644);
273MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
1da177e4 274
200803df
AC
275static 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");
06fcb0c6 280
200803df
AC
281 return 1;
282}
283
284__setup("irqfixup", irqfixup_setup);
9e094c17 285module_param(irqfixup, int, 0644);
200803df
AC
286
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);
This page took 0.501446 seconds and 5 git commands to generate.