blob: 9004be32f3e6061cbcd4e9d67a88ff91a2b0641d [file] [log] [blame]
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001/*
Bryan O'Sullivan759d5762006-07-01 04:35:49 -07002 * Copyright (c) 2006 QLogic, Inc. All rights reserved.
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08003 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <linux/pci.h>
35
36#include "ipath_kernel.h"
37#include "ips_common.h"
38#include "ipath_layer.h"
39
40#define E_SUM_PKTERRS \
41 (INFINIPATH_E_RHDRLEN | INFINIPATH_E_RBADTID | \
42 INFINIPATH_E_RBADVERSION | INFINIPATH_E_RHDR | \
43 INFINIPATH_E_RLONGPKTLEN | INFINIPATH_E_RSHORTPKTLEN | \
44 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RMINPKTLEN | \
45 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RUNSUPVL | \
46 INFINIPATH_E_RUNEXPCHAR | INFINIPATH_E_REBP)
47
48#define E_SUM_ERRS \
49 (INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM | \
50 INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
51 INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SUNSUPVL | \
52 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
53 INFINIPATH_E_INVALIDADDR)
54
55static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs)
56{
57 unsigned long sbuf[4];
58 u64 ignore_this_time = 0;
59 u32 piobcnt;
60
61 /* if possible that sendbuffererror could be valid */
62 piobcnt = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
63 /* read these before writing errorclear */
64 sbuf[0] = ipath_read_kreg64(
65 dd, dd->ipath_kregs->kr_sendbuffererror);
66 sbuf[1] = ipath_read_kreg64(
67 dd, dd->ipath_kregs->kr_sendbuffererror + 1);
68 if (piobcnt > 128) {
69 sbuf[2] = ipath_read_kreg64(
70 dd, dd->ipath_kregs->kr_sendbuffererror + 2);
71 sbuf[3] = ipath_read_kreg64(
72 dd, dd->ipath_kregs->kr_sendbuffererror + 3);
73 }
74
75 if (sbuf[0] || sbuf[1] || (piobcnt > 128 && (sbuf[2] || sbuf[3]))) {
76 int i;
77
78 ipath_cdbg(PKT, "SendbufErrs %lx %lx ", sbuf[0], sbuf[1]);
79 if (ipath_debug & __IPATH_PKTDBG && piobcnt > 128)
80 printk("%lx %lx ", sbuf[2], sbuf[3]);
81 for (i = 0; i < piobcnt; i++) {
82 if (test_bit(i, sbuf)) {
83 u32 __iomem *piobuf;
84 if (i < dd->ipath_piobcnt2k)
85 piobuf = (u32 __iomem *)
86 (dd->ipath_pio2kbase +
87 i * dd->ipath_palign);
88 else
89 piobuf = (u32 __iomem *)
90 (dd->ipath_pio4kbase +
91 (i - dd->ipath_piobcnt2k) *
92 dd->ipath_4kalign);
93
94 ipath_cdbg(PKT,
95 "PIObuf[%u] @%p pbc is %x; ",
96 i, piobuf, readl(piobuf));
97
98 ipath_disarm_piobufs(dd, i, 1);
99 }
100 }
101 if (ipath_debug & __IPATH_PKTDBG)
102 printk("\n");
103 }
104 if ((errs & (INFINIPATH_E_SDROPPEDDATAPKT |
105 INFINIPATH_E_SDROPPEDSMPPKT |
106 INFINIPATH_E_SMINPKTLEN)) &&
107 !(dd->ipath_flags & IPATH_LINKACTIVE)) {
108 /*
109 * This can happen when SMA is trying to bring the link
110 * up, but the IB link changes state at the "wrong" time.
111 * The IB logic then complains that the packet isn't
112 * valid. We don't want to confuse people, so we just
113 * don't print them, except at debug
114 */
115 ipath_dbg("Ignoring pktsend errors %llx, because not "
116 "yet active\n", (unsigned long long) errs);
117 ignore_this_time = INFINIPATH_E_SDROPPEDDATAPKT |
118 INFINIPATH_E_SDROPPEDSMPPKT |
119 INFINIPATH_E_SMINPKTLEN;
120 }
121
122 return ignore_this_time;
123}
124
125/* return the strings for the most common link states */
126static char *ib_linkstate(u32 linkstate)
127{
128 char *ret;
129
130 switch (linkstate) {
131 case IPATH_IBSTATE_INIT:
132 ret = "Init";
133 break;
134 case IPATH_IBSTATE_ARM:
135 ret = "Arm";
136 break;
137 case IPATH_IBSTATE_ACTIVE:
138 ret = "Active";
139 break;
140 default:
141 ret = "Down";
142 }
143
144 return ret;
145}
146
147static void handle_e_ibstatuschanged(struct ipath_devdata *dd,
148 ipath_err_t errs, int noprint)
149{
150 u64 val;
151 u32 ltstate, lstate;
152
153 /*
154 * even if diags are enabled, we want to notice LINKINIT, etc.
155 * We just don't want to change the LED state, or
156 * dd->ipath_kregs->kr_ibcctrl
157 */
158 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
159 lstate = val & IPATH_IBSTATE_MASK;
160 if (lstate == IPATH_IBSTATE_INIT || lstate == IPATH_IBSTATE_ARM ||
161 lstate == IPATH_IBSTATE_ACTIVE) {
162 /*
163 * only print at SMA if there is a change, debug if not
164 * (sometimes we want to know that, usually not).
165 */
166 if (lstate == ((unsigned) dd->ipath_lastibcstat
167 & IPATH_IBSTATE_MASK)) {
168 ipath_dbg("Status change intr but no change (%s)\n",
169 ib_linkstate(lstate));
170 }
171 else
172 ipath_cdbg(SMA, "Unit %u link state %s, last "
173 "was %s\n", dd->ipath_unit,
174 ib_linkstate(lstate),
175 ib_linkstate((unsigned)
Roland Dreier5494c222006-04-19 11:40:12 -0700176 dd->ipath_lastibcstat
177 & IPATH_IBSTATE_MASK));
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800178 }
179 else {
180 lstate = dd->ipath_lastibcstat & IPATH_IBSTATE_MASK;
181 if (lstate == IPATH_IBSTATE_INIT ||
182 lstate == IPATH_IBSTATE_ARM ||
183 lstate == IPATH_IBSTATE_ACTIVE)
184 ipath_cdbg(SMA, "Unit %u link state down"
185 " (state 0x%x), from %s\n",
186 dd->ipath_unit,
187 (u32)val & IPATH_IBSTATE_MASK,
188 ib_linkstate(lstate));
189 else
190 ipath_cdbg(VERBOSE, "Unit %u link state changed "
191 "to 0x%x from down (%x)\n",
192 dd->ipath_unit, (u32) val, lstate);
193 }
194 ltstate = (val >> INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
195 INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
196 lstate = (val >> INFINIPATH_IBCS_LINKSTATE_SHIFT) &
197 INFINIPATH_IBCS_LINKSTATE_MASK;
198
199 if (ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE ||
200 ltstate == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
201 u32 last_ltstate;
202
203 /*
204 * Ignore cycling back and forth from Polling.Active
205 * to Polling.Quiet while waiting for the other end of
206 * the link to come up. We will cycle back and forth
207 * between them if no cable is plugged in,
208 * the other device is powered off or disabled, etc.
209 */
210 last_ltstate = (dd->ipath_lastibcstat >>
211 INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT)
212 & INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
213 if (last_ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE
214 || last_ltstate ==
215 INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
216 if (dd->ipath_ibpollcnt > 40) {
217 dd->ipath_flags |= IPATH_NOCABLE;
218 *dd->ipath_statusp |=
219 IPATH_STATUS_IB_NOCABLE;
220 } else
221 dd->ipath_ibpollcnt++;
222 goto skip_ibchange;
223 }
224 }
225 dd->ipath_ibpollcnt = 0; /* some state other than 2 or 3 */
226 ipath_stats.sps_iblink++;
227 if (ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP) {
228 dd->ipath_flags |= IPATH_LINKDOWN;
229 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
230 | IPATH_LINKACTIVE |
231 IPATH_LINKARMED);
232 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
233 if (!noprint) {
234 if (((dd->ipath_lastibcstat >>
235 INFINIPATH_IBCS_LINKSTATE_SHIFT) &
236 INFINIPATH_IBCS_LINKSTATE_MASK)
237 == INFINIPATH_IBCS_L_STATE_ACTIVE)
238 /* if from up to down be more vocal */
239 ipath_cdbg(SMA,
240 "Unit %u link now down (%s)\n",
241 dd->ipath_unit,
242 ipath_ibcstatus_str[ltstate]);
243 else
244 ipath_cdbg(VERBOSE, "Unit %u link is "
245 "down (%s)\n", dd->ipath_unit,
246 ipath_ibcstatus_str[ltstate]);
247 }
248
249 dd->ipath_f_setextled(dd, lstate, ltstate);
250 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ACTIVE) {
251 dd->ipath_flags |= IPATH_LINKACTIVE;
252 dd->ipath_flags &=
253 ~(IPATH_LINKUNK | IPATH_LINKINIT | IPATH_LINKDOWN |
254 IPATH_LINKARMED | IPATH_NOCABLE);
255 *dd->ipath_statusp &= ~IPATH_STATUS_IB_NOCABLE;
256 *dd->ipath_statusp |=
257 IPATH_STATUS_IB_READY | IPATH_STATUS_IB_CONF;
258 dd->ipath_f_setextled(dd, lstate, ltstate);
259
260 __ipath_layer_intr(dd, IPATH_LAYER_INT_IF_UP);
261 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_INIT) {
262 /*
263 * set INIT and DOWN. Down is checked by most of the other
264 * code, but INIT is useful to know in a few places.
265 */
266 dd->ipath_flags |= IPATH_LINKINIT | IPATH_LINKDOWN;
267 dd->ipath_flags &=
268 ~(IPATH_LINKUNK | IPATH_LINKACTIVE | IPATH_LINKARMED
269 | IPATH_NOCABLE);
270 *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
271 | IPATH_STATUS_IB_READY);
272 dd->ipath_f_setextled(dd, lstate, ltstate);
273 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ARM) {
274 dd->ipath_flags |= IPATH_LINKARMED;
275 dd->ipath_flags &=
276 ~(IPATH_LINKUNK | IPATH_LINKDOWN | IPATH_LINKINIT |
277 IPATH_LINKACTIVE | IPATH_NOCABLE);
278 *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
279 | IPATH_STATUS_IB_READY);
280 dd->ipath_f_setextled(dd, lstate, ltstate);
281 } else {
282 if (!noprint)
283 ipath_dbg("IBstatuschange unit %u: %s (%x)\n",
284 dd->ipath_unit,
285 ipath_ibcstatus_str[ltstate], ltstate);
286 }
287skip_ibchange:
288 dd->ipath_lastibcstat = val;
289}
290
291static void handle_supp_msgs(struct ipath_devdata *dd,
292 unsigned supp_msgs, char msg[512])
293{
294 /*
295 * Print the message unless it's ibc status change only, which
296 * happens so often we never want to count it.
297 */
298 if (dd->ipath_lasterror & ~INFINIPATH_E_IBSTATUSCHANGED) {
299 ipath_decode_err(msg, sizeof msg, dd->ipath_lasterror &
300 ~INFINIPATH_E_IBSTATUSCHANGED);
301 if (dd->ipath_lasterror &
302 ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL))
303 ipath_dev_err(dd, "Suppressed %u messages for "
304 "fast-repeating errors (%s) (%llx)\n",
305 supp_msgs, msg,
306 (unsigned long long)
307 dd->ipath_lasterror);
308 else {
309 /*
310 * rcvegrfull and rcvhdrqfull are "normal", for some
311 * types of processes (mostly benchmarks) that send
312 * huge numbers of messages, while not processing
313 * them. So only complain about these at debug
314 * level.
315 */
316 ipath_dbg("Suppressed %u messages for %s\n",
317 supp_msgs, msg);
318 }
319 }
320}
321
322static unsigned handle_frequent_errors(struct ipath_devdata *dd,
323 ipath_err_t errs, char msg[512],
324 int *noprint)
325{
326 unsigned long nc;
327 static unsigned long nextmsg_time;
328 static unsigned nmsgs, supp_msgs;
329
330 /*
331 * Throttle back "fast" messages to no more than 10 per 5 seconds.
332 * This isn't perfect, but it's a reasonable heuristic. If we get
333 * more than 10, give a 6x longer delay.
334 */
335 nc = jiffies;
336 if (nmsgs > 10) {
337 if (time_before(nc, nextmsg_time)) {
338 *noprint = 1;
339 if (!supp_msgs++)
340 nextmsg_time = nc + HZ * 3;
341 }
342 else if (supp_msgs) {
343 handle_supp_msgs(dd, supp_msgs, msg);
344 supp_msgs = 0;
345 nmsgs = 0;
346 }
347 }
348 else if (!nmsgs++ || time_after(nc, nextmsg_time))
349 nextmsg_time = nc + HZ / 2;
350
351 return supp_msgs;
352}
353
354static void handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
355{
356 char msg[512];
357 u64 ignore_this_time = 0;
358 int i;
359 int chkerrpkts = 0, noprint = 0;
360 unsigned supp_msgs;
361
362 supp_msgs = handle_frequent_errors(dd, errs, msg, &noprint);
363
364 /*
365 * don't report errors that are masked (includes those always
366 * ignored)
367 */
368 errs &= ~dd->ipath_maskederrs;
369
370 /* do these first, they are most important */
371 if (errs & INFINIPATH_E_HARDWARE) {
372 /* reuse same msg buf */
373 dd->ipath_f_handle_hwerrors(dd, msg, sizeof msg);
374 }
375
376 if (!noprint && (errs & ~infinipath_e_bitsextant))
377 ipath_dev_err(dd, "error interrupt with unknown errors "
378 "%llx set\n", (unsigned long long)
379 (errs & ~infinipath_e_bitsextant));
380
381 if (errs & E_SUM_ERRS)
382 ignore_this_time = handle_e_sum_errs(dd, errs);
383
384 if (supp_msgs == 250000) {
385 /*
386 * It's not entirely reasonable assuming that the errors set
387 * in the last clear period are all responsible for the
388 * problem, but the alternative is to assume it's the only
389 * ones on this particular interrupt, which also isn't great
390 */
391 dd->ipath_maskederrs |= dd->ipath_lasterror | errs;
392 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
393 ~dd->ipath_maskederrs);
394 ipath_decode_err(msg, sizeof msg,
395 (dd->ipath_maskederrs & ~dd->
396 ipath_ignorederrs));
397
398 if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs) &
399 ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL))
400 ipath_dev_err(dd, "Disabling error(s) %llx because "
Adrian Bunk80f72282006-06-30 18:27:16 +0200401 "occurring too frequently (%s)\n",
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800402 (unsigned long long)
403 (dd->ipath_maskederrs &
404 ~dd->ipath_ignorederrs), msg);
405 else {
406 /*
407 * rcvegrfull and rcvhdrqfull are "normal",
408 * for some types of processes (mostly benchmarks)
409 * that send huge numbers of messages, while not
410 * processing them. So only complain about
411 * these at debug level.
412 */
413 ipath_dbg("Disabling frequent queue full errors "
414 "(%s)\n", msg);
415 }
416
417 /*
418 * Re-enable the masked errors after around 3 minutes. in
419 * ipath_get_faststats(). If we have a series of fast
420 * repeating but different errors, the interval will keep
421 * stretching out, but that's OK, as that's pretty
422 * catastrophic.
423 */
424 dd->ipath_unmasktime = jiffies + HZ * 180;
425 }
426
427 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, errs);
428 if (ignore_this_time)
429 errs &= ~ignore_this_time;
430 if (errs & ~dd->ipath_lasterror) {
431 errs &= ~dd->ipath_lasterror;
432 /* never suppress duplicate hwerrors or ibstatuschange */
433 dd->ipath_lasterror |= errs &
434 ~(INFINIPATH_E_HARDWARE |
435 INFINIPATH_E_IBSTATUSCHANGED);
436 }
437 if (!errs)
438 return;
439
440 if (!noprint)
441 /*
442 * the ones we mask off are handled specially below or above
443 */
444 ipath_decode_err(msg, sizeof msg,
445 errs & ~(INFINIPATH_E_IBSTATUSCHANGED |
446 INFINIPATH_E_RRCVEGRFULL |
447 INFINIPATH_E_RRCVHDRFULL |
448 INFINIPATH_E_HARDWARE));
449 else
450 /* so we don't need if (!noprint) at strlcat's below */
451 *msg = 0;
452
453 if (errs & E_SUM_PKTERRS) {
454 ipath_stats.sps_pkterrs++;
455 chkerrpkts = 1;
456 }
457 if (errs & E_SUM_ERRS)
458 ipath_stats.sps_errs++;
459
460 if (errs & (INFINIPATH_E_RICRC | INFINIPATH_E_RVCRC)) {
461 ipath_stats.sps_crcerrs++;
462 chkerrpkts = 1;
463 }
464
465 /*
466 * We don't want to print these two as they happen, or we can make
467 * the situation even worse, because it takes so long to print
468 * messages to serial consoles. Kernel ports get printed from
469 * fast_stats, no more than every 5 seconds, user ports get printed
470 * on close
471 */
472 if (errs & INFINIPATH_E_RRCVHDRFULL) {
473 int any;
474 u32 hd, tl;
475 ipath_stats.sps_hdrqfull++;
476 for (any = i = 0; i < dd->ipath_cfgports; i++) {
477 struct ipath_portdata *pd = dd->ipath_pd[i];
478 if (i == 0) {
479 hd = dd->ipath_port0head;
480 tl = (u32) le64_to_cpu(
481 *dd->ipath_hdrqtailptr);
482 } else if (pd && pd->port_cnt &&
483 pd->port_rcvhdrtail_kvaddr) {
484 /*
485 * don't report same point multiple times,
486 * except kernel
487 */
488 tl = (u32) * pd->port_rcvhdrtail_kvaddr;
489 if (tl == dd->ipath_lastrcvhdrqtails[i])
490 continue;
491 hd = ipath_read_ureg32(dd, ur_rcvhdrhead,
492 i);
493 } else
494 continue;
495 if (hd == (tl + 1) ||
496 (!hd && tl == dd->ipath_hdrqlast)) {
497 dd->ipath_lastrcvhdrqtails[i] = tl;
498 pd->port_hdrqfull++;
499 if (i == 0)
500 chkerrpkts = 1;
501 }
502 }
503 }
504 if (errs & INFINIPATH_E_RRCVEGRFULL) {
505 /*
506 * since this is of less importance and not likely to
507 * happen without also getting hdrfull, only count
508 * occurrences; don't check each port (or even the kernel
509 * vs user)
510 */
511 ipath_stats.sps_etidfull++;
512 if (dd->ipath_port0head !=
513 (u32) le64_to_cpu(*dd->ipath_hdrqtailptr))
514 chkerrpkts = 1;
515 }
516
517 /*
518 * do this before IBSTATUSCHANGED, in case both bits set in a single
519 * interrupt; we want the STATUSCHANGE to "win", so we do our
520 * internal copy of state machine correctly
521 */
522 if (errs & INFINIPATH_E_RIBLOSTLINK) {
523 /*
524 * force through block below
525 */
526 errs |= INFINIPATH_E_IBSTATUSCHANGED;
527 ipath_stats.sps_iblink++;
528 dd->ipath_flags |= IPATH_LINKDOWN;
529 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
530 | IPATH_LINKARMED | IPATH_LINKACTIVE);
531 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
532 if (!noprint) {
533 u64 st = ipath_read_kreg64(
534 dd, dd->ipath_kregs->kr_ibcstatus);
535
536 ipath_dbg("Lost link, link now down (%s)\n",
537 ipath_ibcstatus_str[st & 0xf]);
538 }
539 }
540 if (errs & INFINIPATH_E_IBSTATUSCHANGED)
541 handle_e_ibstatuschanged(dd, errs, noprint);
542
543 if (errs & INFINIPATH_E_RESET) {
544 if (!noprint)
545 ipath_dev_err(dd, "Got reset, requires re-init "
546 "(unload and reload driver)\n");
547 dd->ipath_flags &= ~IPATH_INITTED; /* needs re-init */
548 /* mark as having had error */
549 *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
550 *dd->ipath_statusp &= ~IPATH_STATUS_IB_CONF;
551 }
552
553 if (!noprint && *msg)
554 ipath_dev_err(dd, "%s error\n", msg);
555 if (dd->ipath_sma_state_wanted & dd->ipath_flags) {
556 ipath_cdbg(VERBOSE, "sma wanted state %x, iflags now %x, "
557 "waking\n", dd->ipath_sma_state_wanted,
558 dd->ipath_flags);
559 wake_up_interruptible(&ipath_sma_state_wait);
560 }
561
562 if (chkerrpkts)
563 /* process possible error packets in hdrq */
564 ipath_kreceive(dd);
565}
566
567/* this is separate to allow for better optimization of ipath_intr() */
568
569static void ipath_bad_intr(struct ipath_devdata *dd, u32 * unexpectp)
570{
571 /*
572 * sometimes happen during driver init and unload, don't want
573 * to process any interrupts at that point
574 */
575
576 /* this is just a bandaid, not a fix, if something goes badly
577 * wrong */
578 if (++*unexpectp > 100) {
579 if (++*unexpectp > 105) {
580 /*
581 * ok, we must be taking somebody else's interrupts,
582 * due to a messed up mptable and/or PIRQ table, so
583 * unregister the interrupt. We've seen this during
584 * linuxbios development work, and it may happen in
585 * the future again.
586 */
587 if (dd->pcidev && dd->pcidev->irq) {
588 ipath_dev_err(dd, "Now %u unexpected "
589 "interrupts, unregistering "
590 "interrupt handler\n",
591 *unexpectp);
592 ipath_dbg("free_irq of irq %x\n",
593 dd->pcidev->irq);
594 free_irq(dd->pcidev->irq, dd);
595 }
596 }
597 if (ipath_read_kreg32(dd, dd->ipath_kregs->kr_intmask)) {
598 ipath_dev_err(dd, "%u unexpected interrupts, "
599 "disabling interrupts completely\n",
600 *unexpectp);
601 /*
602 * disable all interrupts, something is very wrong
603 */
604 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
605 0ULL);
606 }
607 } else if (*unexpectp > 1)
608 ipath_dbg("Interrupt when not ready, should not happen, "
609 "ignoring\n");
610}
611
612static void ipath_bad_regread(struct ipath_devdata *dd)
613{
614 static int allbits;
615
616 /* separate routine, for better optimization of ipath_intr() */
617
618 /*
619 * We print the message and disable interrupts, in hope of
620 * having a better chance of debugging the problem.
621 */
622 ipath_dev_err(dd,
623 "Read of interrupt status failed (all bits set)\n");
624 if (allbits++) {
625 /* disable all interrupts, something is very wrong */
626 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
627 if (allbits == 2) {
628 ipath_dev_err(dd, "Still bad interrupt status, "
629 "unregistering interrupt\n");
630 free_irq(dd->pcidev->irq, dd);
631 } else if (allbits > 2) {
632 if ((allbits % 10000) == 0)
633 printk(".");
634 } else
635 ipath_dev_err(dd, "Disabling interrupts, "
636 "multiple errors\n");
637 }
638}
639
640static void handle_port_pioavail(struct ipath_devdata *dd)
641{
642 u32 i;
643 /*
644 * start from port 1, since for now port 0 is never using
645 * wait_event for PIO
646 */
647 for (i = 1; dd->ipath_portpiowait && i < dd->ipath_cfgports; i++) {
648 struct ipath_portdata *pd = dd->ipath_pd[i];
649
650 if (pd && pd->port_cnt &&
651 dd->ipath_portpiowait & (1U << i)) {
652 clear_bit(i, &dd->ipath_portpiowait);
653 if (test_bit(IPATH_PORT_WAITING_PIO,
654 &pd->port_flag)) {
655 clear_bit(IPATH_PORT_WAITING_PIO,
656 &pd->port_flag);
657 wake_up_interruptible(&pd->port_wait);
658 }
659 }
660 }
661}
662
663static void handle_layer_pioavail(struct ipath_devdata *dd)
664{
665 int ret;
666
667 ret = __ipath_layer_intr(dd, IPATH_LAYER_INT_SEND_CONTINUE);
668 if (ret > 0)
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -0700669 goto set;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800670
671 ret = __ipath_verbs_piobufavail(dd);
672 if (ret > 0)
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -0700673 goto set;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800674
675 return;
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -0700676set:
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800677 set_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
678 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
679 dd->ipath_sendctrl);
680}
681
682static void handle_rcv(struct ipath_devdata *dd, u32 istat)
683{
684 u64 portr;
685 int i;
686 int rcvdint = 0;
687
688 portr = ((istat >> INFINIPATH_I_RCVAVAIL_SHIFT) &
689 infinipath_i_rcvavail_mask)
690 | ((istat >> INFINIPATH_I_RCVURG_SHIFT) &
691 infinipath_i_rcvurg_mask);
692 for (i = 0; i < dd->ipath_cfgports; i++) {
693 struct ipath_portdata *pd = dd->ipath_pd[i];
694 if (portr & (1 << i) && pd &&
695 pd->port_cnt) {
696 if (i == 0)
697 ipath_kreceive(dd);
698 else if (test_bit(IPATH_PORT_WAITING_RCV,
699 &pd->port_flag)) {
700 int rcbit;
701 clear_bit(IPATH_PORT_WAITING_RCV,
702 &pd->port_flag);
703 rcbit = i + INFINIPATH_R_INTRAVAIL_SHIFT;
704 clear_bit(1UL << rcbit, &dd->ipath_rcvctrl);
705 wake_up_interruptible(&pd->port_wait);
706 rcvdint = 1;
707 }
708 }
709 }
710 if (rcvdint) {
711 /* only want to take one interrupt, so turn off the rcv
712 * interrupt for all the ports that we did the wakeup on
713 * (but never for kernel port)
714 */
715 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
716 dd->ipath_rcvctrl);
717 }
718}
719
720irqreturn_t ipath_intr(int irq, void *data, struct pt_regs *regs)
721{
722 struct ipath_devdata *dd = data;
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -0700723 u32 istat;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800724 ipath_err_t estat = 0;
725 static unsigned unexpected = 0;
726 irqreturn_t ret;
727
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -0700728 if(!(dd->ipath_flags & IPATH_PRESENT)) {
729 /* this is mostly so we don't try to touch the chip while
730 * it is being reset */
731 /*
732 * This return value is perhaps odd, but we do not want the
733 * interrupt core code to remove our interrupt handler
734 * because we don't appear to be handling an interrupt
735 * during a chip reset.
736 */
737 return IRQ_HANDLED;
738 }
739
740 istat = ipath_read_kreg32(dd, dd->ipath_kregs->kr_intstatus);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800741 if (unlikely(!istat)) {
742 ipath_stats.sps_nullintr++;
743 ret = IRQ_NONE; /* not our interrupt, or already handled */
744 goto bail;
745 }
746 if (unlikely(istat == -1)) {
747 ipath_bad_regread(dd);
748 /* don't know if it was our interrupt or not */
749 ret = IRQ_NONE;
750 goto bail;
751 }
752
753 ipath_stats.sps_ints++;
754
755 /*
756 * this needs to be flags&initted, not statusp, so we keep
757 * taking interrupts even after link goes down, etc.
758 * Also, we *must* clear the interrupt at some point, or we won't
759 * take it again, which can be real bad for errors, etc...
760 */
761
762 if (!(dd->ipath_flags & IPATH_INITTED)) {
763 ipath_bad_intr(dd, &unexpected);
764 ret = IRQ_NONE;
765 goto bail;
766 }
767 if (unexpected)
768 unexpected = 0;
769
770 ipath_cdbg(VERBOSE, "intr stat=0x%x\n", istat);
771
772 if (istat & ~infinipath_i_bitsextant)
773 ipath_dev_err(dd,
774 "interrupt with unknown interrupts %x set\n",
775 istat & (u32) ~ infinipath_i_bitsextant);
776
777 if (istat & INFINIPATH_I_ERROR) {
778 ipath_stats.sps_errints++;
779 estat = ipath_read_kreg64(dd,
780 dd->ipath_kregs->kr_errorstatus);
781 if (!estat)
782 dev_info(&dd->pcidev->dev, "error interrupt (%x), "
783 "but no error bits set!\n", istat);
784 else if (estat == -1LL)
785 /*
786 * should we try clearing all, or hope next read
787 * works?
788 */
789 ipath_dev_err(dd, "Read of error status failed "
790 "(all bits set); ignoring\n");
791 else
792 handle_errors(dd, estat);
793 }
794
795 if (istat & INFINIPATH_I_GPIO) {
796 if (unlikely(!(dd->ipath_flags & IPATH_GPIO_INTR))) {
797 u32 gpiostatus;
798 gpiostatus = ipath_read_kreg32(
799 dd, dd->ipath_kregs->kr_gpio_status);
800 ipath_dbg("Unexpected GPIO interrupt bits %x\n",
801 gpiostatus);
802 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
803 gpiostatus);
804 }
805 else {
806 /* Clear GPIO status bit 2 */
807 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
808 (u64) (1 << 2));
809
810 /*
811 * Packets are available in the port 0 rcv queue.
812 * Eventually this needs to be generalized to check
813 * IPATH_GPIO_INTR, and the specific GPIO bit, if
814 * GPIO interrupts are used for anything else.
815 */
816 ipath_kreceive(dd);
817 }
818 }
819
820 /*
821 * clear the ones we will deal with on this round
822 * We clear it early, mostly for receive interrupts, so we
823 * know the chip will have seen this by the time we process
824 * the queue, and will re-interrupt if necessary. The processor
825 * itself won't take the interrupt again until we return.
826 */
827 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, istat);
828
829 if (istat & INFINIPATH_I_SPIOBUFAVAIL) {
830 clear_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
831 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
832 dd->ipath_sendctrl);
833
834 if (dd->ipath_portpiowait)
835 handle_port_pioavail(dd);
836
837 handle_layer_pioavail(dd);
838 }
839
840 /*
841 * we check for both transition from empty to non-empty, and urgent
842 * packets (those with the interrupt bit set in the header)
843 */
844
845 if (istat & ((infinipath_i_rcvavail_mask <<
846 INFINIPATH_I_RCVAVAIL_SHIFT)
847 | (infinipath_i_rcvurg_mask <<
848 INFINIPATH_I_RCVURG_SHIFT)))
849 handle_rcv(dd, istat);
850
851 ret = IRQ_HANDLED;
852
853bail:
854 return ret;
855}