]> bbs.cooldavid.org Git - net-next-2.6.git/blame - kernel/irq/spurious.c
rtnetlink: Link address family API
[net-next-2.6.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 }
45 /* Honour the normal IRQ locking */
46 desc->status |= IRQ_INPROGRESS;
47 action = desc->action;
239007b8 48 raw_spin_unlock(&desc->lock);
06fcb0c6 49
f84dbb91
EB
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;
200803df 56 }
f84dbb91
EB
57 action = action->next;
58 }
59 local_irq_disable();
60 /* Now clean up the flags */
239007b8 61 raw_spin_lock(&desc->lock);
f84dbb91 62 action = desc->action;
200803df 63
f84dbb91
EB
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) {
200803df 69 /*
f84dbb91 70 * Perform real IRQ processing for the IRQ we deferred
200803df 71 */
f84dbb91 72 work = 1;
239007b8 73 raw_spin_unlock(&desc->lock);
f84dbb91 74 handle_IRQ_event(irq, action);
239007b8 75 raw_spin_lock(&desc->lock);
f84dbb91
EB
76 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 */
bd151412
TG
83 if (work)
84 irq_end(irq, desc);
239007b8 85 raw_spin_unlock(&desc->lock);
f84dbb91
EB
86
87 return ok;
88}
89
90static int misrouted_irq(int irq)
91{
e00585bb 92 struct irq_desc *desc;
d3c60047 93 int i, ok = 0;
f84dbb91 94
e00585bb
YL
95 for_each_irq_desc(i, desc) {
96 if (!i)
97 continue;
f84dbb91
EB
98
99 if (i == irq) /* Already tried */
100 continue;
101
102 if (try_one_irq(i, desc))
103 ok = 1;
200803df
AC
104 }
105 /* So the caller can adjust the irq error counts */
106 return ok;
107}
108
663e6959 109static void poll_spurious_irqs(unsigned long dummy)
f84dbb91 110{
e00585bb 111 struct irq_desc *desc;
d3c60047 112 int i;
e00585bb
YL
113
114 for_each_irq_desc(i, desc) {
f84dbb91
EB
115 unsigned int status;
116
e00585bb
YL
117 if (!i)
118 continue;
119
f84dbb91
EB
120 /* Racy but it doesn't matter */
121 status = desc->status;
122 barrier();
123 if (!(status & IRQ_SPURIOUS_DISABLED))
124 continue;
125
e7e7e0c0 126 local_irq_disable();
f84dbb91 127 try_one_irq(i, desc);
e7e7e0c0 128 local_irq_enable();
f84dbb91
EB
129 }
130
d3c60047
TG
131 mod_timer(&poll_spurious_irq_timer,
132 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
f84dbb91
EB
133}
134
1da177e4
LT
135/*
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)
142 *
143 * Called under desc->lock
144 */
145
146static void
34ffdb72
IM
147__report_bad_irq(unsigned int irq, struct irq_desc *desc,
148 irqreturn_t action_ret)
1da177e4
LT
149{
150 struct irqaction *action;
151
152 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
153 printk(KERN_ERR "irq event %d: bogus return value %x\n",
154 irq, action_ret);
155 } else {
200803df
AC
156 printk(KERN_ERR "irq %d: nobody cared (try booting with "
157 "the \"irqpoll\" option)\n", irq);
1da177e4
LT
158 }
159 dump_stack();
160 printk(KERN_ERR "handlers:\n");
06fcb0c6 161
1da177e4
LT
162 action = desc->action;
163 while (action) {
164 printk(KERN_ERR "[<%p>]", action->handler);
165 print_symbol(" (%s)",
166 (unsigned long)action->handler);
167 printk("\n");
168 action = action->next;
169 }
170}
171
06fcb0c6 172static void
34ffdb72 173report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
1da177e4
LT
174{
175 static int count = 100;
176
177 if (count > 0) {
178 count--;
179 __report_bad_irq(irq, desc, action_ret);
180 }
181}
182
d3c60047
TG
183static inline int
184try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
185 irqreturn_t action_ret)
92ea7727
LT
186{
187 struct irqaction *action;
188
189 if (!irqfixup)
190 return 0;
191
192 /* We didn't actually handle the IRQ - see if it was misrouted? */
193 if (action_ret == IRQ_NONE)
194 return 1;
195
196 /*
197 * But for 'irqfixup == 2' we also do it for handled interrupts if
198 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
199 * traditional PC timer interrupt.. Legacy)
200 */
201 if (irqfixup < 2)
202 return 0;
203
204 if (!irq)
205 return 1;
206
207 /*
208 * Since we don't get the descriptor lock, "action" can
209 * change under us. We don't really care, but we don't
210 * want to follow a NULL pointer. So tell the compiler to
211 * just load it once by using a barrier.
212 */
213 action = desc->action;
214 barrier();
215 return action && (action->flags & IRQF_IRQPOLL);
216}
217
34ffdb72 218void note_interrupt(unsigned int irq, struct irq_desc *desc,
7d12e780 219 irqreturn_t action_ret)
1da177e4 220{
83d4e6e7 221 if (unlikely(action_ret != IRQ_HANDLED)) {
4f27c00b
AC
222 /*
223 * If we are seeing only the odd spurious IRQ caused by
224 * bus asynchronicity then don't eventually trigger an error,
fbfecd37 225 * otherwise the counter becomes a doomsday timer for otherwise
4f27c00b
AC
226 * working systems
227 */
188fd89d 228 if (time_after(jiffies, desc->last_unhandled + HZ/10))
4f27c00b
AC
229 desc->irqs_unhandled = 1;
230 else
231 desc->irqs_unhandled++;
232 desc->last_unhandled = jiffies;
83d4e6e7 233 if (unlikely(action_ret != IRQ_NONE))
1da177e4
LT
234 report_bad_irq(irq, desc, action_ret);
235 }
236
92ea7727
LT
237 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
238 int ok = misrouted_irq(irq);
239 if (action_ret == IRQ_NONE)
240 desc->irqs_unhandled -= ok;
200803df
AC
241 }
242
1da177e4 243 desc->irq_count++;
83d4e6e7 244 if (likely(desc->irq_count < 100000))
1da177e4
LT
245 return;
246
247 desc->irq_count = 0;
83d4e6e7 248 if (unlikely(desc->irqs_unhandled > 99900)) {
1da177e4
LT
249 /*
250 * The interrupt is stuck
251 */
252 __report_bad_irq(irq, desc, action_ret);
253 /*
254 * Now kill the IRQ
255 */
256 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
1adb0850
TG
257 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
258 desc->depth++;
bc310dda 259 desc->irq_data.chip->irq_disable(&desc->irq_data);
f84dbb91 260
d3c60047
TG
261 mod_timer(&poll_spurious_irq_timer,
262 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
1da177e4
LT
263 }
264 desc->irqs_unhandled = 0;
265}
266
83d4e6e7 267int noirqdebug __read_mostly;
1da177e4 268
343cde51 269int noirqdebug_setup(char *str)
1da177e4
LT
270{
271 noirqdebug = 1;
272 printk(KERN_INFO "IRQ lockup detection disabled\n");
06fcb0c6 273
1da177e4
LT
274 return 1;
275}
276
277__setup("noirqdebug", noirqdebug_setup);
9e094c17
AK
278module_param(noirqdebug, bool, 0644);
279MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
1da177e4 280
200803df
AC
281static int __init irqfixup_setup(char *str)
282{
283 irqfixup = 1;
284 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
285 printk(KERN_WARNING "This may impact system performance.\n");
06fcb0c6 286
200803df
AC
287 return 1;
288}
289
290__setup("irqfixup", irqfixup_setup);
9e094c17 291module_param(irqfixup, int, 0644);
200803df
AC
292
293static int __init irqpoll_setup(char *str)
294{
295 irqfixup = 2;
296 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
297 "enabled\n");
298 printk(KERN_WARNING "This may significantly impact system "
299 "performance\n");
300 return 1;
301}
302
303__setup("irqpoll", irqpoll_setup);