blob: ed54f8f2945eb47f0f03d2b6d24db471585949e3 [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"
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -080037#include "ipath_layer.h"
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -070038#include "ipath_verbs.h"
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -070039#include "ipath_common.h"
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -080040
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -070041/* These are all rcv-related errors which we want to count for stats */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -080042#define E_SUM_PKTERRS \
43 (INFINIPATH_E_RHDRLEN | INFINIPATH_E_RBADTID | \
44 INFINIPATH_E_RBADVERSION | INFINIPATH_E_RHDR | \
45 INFINIPATH_E_RLONGPKTLEN | INFINIPATH_E_RSHORTPKTLEN | \
46 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RMINPKTLEN | \
47 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RUNSUPVL | \
48 INFINIPATH_E_RUNEXPCHAR | INFINIPATH_E_REBP)
49
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -070050/* These are all send-related errors which we want to count for stats */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -080051#define E_SUM_ERRS \
52 (INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM | \
53 INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
54 INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SUNSUPVL | \
55 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
56 INFINIPATH_E_INVALIDADDR)
57
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -070058/*
59 * these are errors that can occur when the link changes state while
60 * a packet is being sent or received. This doesn't cover things
61 * like EBP or VCRC that can be the result of a sending having the
62 * link change state, so we receive a "known bad" packet.
63 */
64#define E_SUM_LINK_PKTERRS \
65 (INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
66 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
67 INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RMINPKTLEN | \
68 INFINIPATH_E_RUNEXPCHAR)
69
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -080070static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs)
71{
72 unsigned long sbuf[4];
73 u64 ignore_this_time = 0;
74 u32 piobcnt;
75
76 /* if possible that sendbuffererror could be valid */
77 piobcnt = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
78 /* read these before writing errorclear */
79 sbuf[0] = ipath_read_kreg64(
80 dd, dd->ipath_kregs->kr_sendbuffererror);
81 sbuf[1] = ipath_read_kreg64(
82 dd, dd->ipath_kregs->kr_sendbuffererror + 1);
83 if (piobcnt > 128) {
84 sbuf[2] = ipath_read_kreg64(
85 dd, dd->ipath_kregs->kr_sendbuffererror + 2);
86 sbuf[3] = ipath_read_kreg64(
87 dd, dd->ipath_kregs->kr_sendbuffererror + 3);
88 }
89
90 if (sbuf[0] || sbuf[1] || (piobcnt > 128 && (sbuf[2] || sbuf[3]))) {
91 int i;
92
93 ipath_cdbg(PKT, "SendbufErrs %lx %lx ", sbuf[0], sbuf[1]);
94 if (ipath_debug & __IPATH_PKTDBG && piobcnt > 128)
95 printk("%lx %lx ", sbuf[2], sbuf[3]);
96 for (i = 0; i < piobcnt; i++) {
97 if (test_bit(i, sbuf)) {
98 u32 __iomem *piobuf;
99 if (i < dd->ipath_piobcnt2k)
100 piobuf = (u32 __iomem *)
101 (dd->ipath_pio2kbase +
102 i * dd->ipath_palign);
103 else
104 piobuf = (u32 __iomem *)
105 (dd->ipath_pio4kbase +
106 (i - dd->ipath_piobcnt2k) *
107 dd->ipath_4kalign);
108
109 ipath_cdbg(PKT,
110 "PIObuf[%u] @%p pbc is %x; ",
111 i, piobuf, readl(piobuf));
112
113 ipath_disarm_piobufs(dd, i, 1);
114 }
115 }
116 if (ipath_debug & __IPATH_PKTDBG)
117 printk("\n");
118 }
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700119 if ((errs & E_SUM_LINK_PKTERRS) &&
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800120 !(dd->ipath_flags & IPATH_LINKACTIVE)) {
121 /*
122 * This can happen when SMA is trying to bring the link
123 * up, but the IB link changes state at the "wrong" time.
124 * The IB logic then complains that the packet isn't
125 * valid. We don't want to confuse people, so we just
126 * don't print them, except at debug
127 */
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700128 ipath_dbg("Ignoring packet errors %llx, because link not "
129 "ACTIVE\n", (unsigned long long) errs);
130 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800131 }
132
133 return ignore_this_time;
134}
135
136/* return the strings for the most common link states */
137static char *ib_linkstate(u32 linkstate)
138{
139 char *ret;
140
141 switch (linkstate) {
142 case IPATH_IBSTATE_INIT:
143 ret = "Init";
144 break;
145 case IPATH_IBSTATE_ARM:
146 ret = "Arm";
147 break;
148 case IPATH_IBSTATE_ACTIVE:
149 ret = "Active";
150 break;
151 default:
152 ret = "Down";
153 }
154
155 return ret;
156}
157
158static void handle_e_ibstatuschanged(struct ipath_devdata *dd,
159 ipath_err_t errs, int noprint)
160{
161 u64 val;
162 u32 ltstate, lstate;
163
164 /*
165 * even if diags are enabled, we want to notice LINKINIT, etc.
166 * We just don't want to change the LED state, or
167 * dd->ipath_kregs->kr_ibcctrl
168 */
169 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
170 lstate = val & IPATH_IBSTATE_MASK;
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700171
172 /*
173 * this is confusing enough when it happens that I want to always put it
174 * on the console and in the logs. If it was a requested state change,
175 * we'll have already cleared the flags, so we won't print this warning
176 */
177 if ((lstate != IPATH_IBSTATE_ARM && lstate != IPATH_IBSTATE_ACTIVE)
178 && (dd->ipath_flags & (IPATH_LINKARMED | IPATH_LINKACTIVE))) {
179 dev_info(&dd->pcidev->dev, "Link state changed from %s to %s\n",
180 (dd->ipath_flags & IPATH_LINKARMED) ? "ARM" : "ACTIVE",
181 ib_linkstate(lstate));
182 /*
183 * Flush all queued sends when link went to DOWN or INIT,
184 * to be sure that they don't block SMA and other MAD packets
185 */
186 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
187 INFINIPATH_S_ABORT);
188 ipath_disarm_piobufs(dd, dd->ipath_lastport_piobuf,
189 (unsigned)(dd->ipath_piobcnt2k +
190 dd->ipath_piobcnt4k) -
191 dd->ipath_lastport_piobuf);
192 }
193 else if (lstate == IPATH_IBSTATE_INIT || lstate == IPATH_IBSTATE_ARM ||
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800194 lstate == IPATH_IBSTATE_ACTIVE) {
195 /*
196 * only print at SMA if there is a change, debug if not
197 * (sometimes we want to know that, usually not).
198 */
199 if (lstate == ((unsigned) dd->ipath_lastibcstat
200 & IPATH_IBSTATE_MASK)) {
201 ipath_dbg("Status change intr but no change (%s)\n",
202 ib_linkstate(lstate));
203 }
204 else
205 ipath_cdbg(SMA, "Unit %u link state %s, last "
206 "was %s\n", dd->ipath_unit,
207 ib_linkstate(lstate),
208 ib_linkstate((unsigned)
Roland Dreier5494c222006-04-19 11:40:12 -0700209 dd->ipath_lastibcstat
210 & IPATH_IBSTATE_MASK));
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800211 }
212 else {
213 lstate = dd->ipath_lastibcstat & IPATH_IBSTATE_MASK;
214 if (lstate == IPATH_IBSTATE_INIT ||
215 lstate == IPATH_IBSTATE_ARM ||
216 lstate == IPATH_IBSTATE_ACTIVE)
217 ipath_cdbg(SMA, "Unit %u link state down"
218 " (state 0x%x), from %s\n",
219 dd->ipath_unit,
220 (u32)val & IPATH_IBSTATE_MASK,
221 ib_linkstate(lstate));
222 else
223 ipath_cdbg(VERBOSE, "Unit %u link state changed "
224 "to 0x%x from down (%x)\n",
225 dd->ipath_unit, (u32) val, lstate);
226 }
227 ltstate = (val >> INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
228 INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
229 lstate = (val >> INFINIPATH_IBCS_LINKSTATE_SHIFT) &
230 INFINIPATH_IBCS_LINKSTATE_MASK;
231
232 if (ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE ||
233 ltstate == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
234 u32 last_ltstate;
235
236 /*
237 * Ignore cycling back and forth from Polling.Active
238 * to Polling.Quiet while waiting for the other end of
239 * the link to come up. We will cycle back and forth
240 * between them if no cable is plugged in,
241 * the other device is powered off or disabled, etc.
242 */
243 last_ltstate = (dd->ipath_lastibcstat >>
244 INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT)
245 & INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
246 if (last_ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE
247 || last_ltstate ==
248 INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
249 if (dd->ipath_ibpollcnt > 40) {
250 dd->ipath_flags |= IPATH_NOCABLE;
251 *dd->ipath_statusp |=
252 IPATH_STATUS_IB_NOCABLE;
253 } else
254 dd->ipath_ibpollcnt++;
255 goto skip_ibchange;
256 }
257 }
258 dd->ipath_ibpollcnt = 0; /* some state other than 2 or 3 */
259 ipath_stats.sps_iblink++;
260 if (ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP) {
261 dd->ipath_flags |= IPATH_LINKDOWN;
262 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
263 | IPATH_LINKACTIVE |
264 IPATH_LINKARMED);
265 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
Bryan O'Sullivanfba75202006-07-01 04:36:09 -0700266 dd->ipath_lli_counter = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800267 if (!noprint) {
268 if (((dd->ipath_lastibcstat >>
269 INFINIPATH_IBCS_LINKSTATE_SHIFT) &
270 INFINIPATH_IBCS_LINKSTATE_MASK)
271 == INFINIPATH_IBCS_L_STATE_ACTIVE)
272 /* if from up to down be more vocal */
273 ipath_cdbg(SMA,
274 "Unit %u link now down (%s)\n",
275 dd->ipath_unit,
276 ipath_ibcstatus_str[ltstate]);
277 else
278 ipath_cdbg(VERBOSE, "Unit %u link is "
279 "down (%s)\n", dd->ipath_unit,
280 ipath_ibcstatus_str[ltstate]);
281 }
282
283 dd->ipath_f_setextled(dd, lstate, ltstate);
284 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ACTIVE) {
285 dd->ipath_flags |= IPATH_LINKACTIVE;
286 dd->ipath_flags &=
287 ~(IPATH_LINKUNK | IPATH_LINKINIT | IPATH_LINKDOWN |
288 IPATH_LINKARMED | IPATH_NOCABLE);
289 *dd->ipath_statusp &= ~IPATH_STATUS_IB_NOCABLE;
290 *dd->ipath_statusp |=
291 IPATH_STATUS_IB_READY | IPATH_STATUS_IB_CONF;
292 dd->ipath_f_setextled(dd, lstate, ltstate);
293
294 __ipath_layer_intr(dd, IPATH_LAYER_INT_IF_UP);
295 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_INIT) {
296 /*
297 * set INIT and DOWN. Down is checked by most of the other
298 * code, but INIT is useful to know in a few places.
299 */
300 dd->ipath_flags |= IPATH_LINKINIT | IPATH_LINKDOWN;
301 dd->ipath_flags &=
302 ~(IPATH_LINKUNK | IPATH_LINKACTIVE | IPATH_LINKARMED
303 | IPATH_NOCABLE);
304 *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
305 | IPATH_STATUS_IB_READY);
306 dd->ipath_f_setextled(dd, lstate, ltstate);
307 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ARM) {
308 dd->ipath_flags |= IPATH_LINKARMED;
309 dd->ipath_flags &=
310 ~(IPATH_LINKUNK | IPATH_LINKDOWN | IPATH_LINKINIT |
311 IPATH_LINKACTIVE | IPATH_NOCABLE);
312 *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
313 | IPATH_STATUS_IB_READY);
314 dd->ipath_f_setextled(dd, lstate, ltstate);
315 } else {
316 if (!noprint)
317 ipath_dbg("IBstatuschange unit %u: %s (%x)\n",
318 dd->ipath_unit,
319 ipath_ibcstatus_str[ltstate], ltstate);
320 }
321skip_ibchange:
322 dd->ipath_lastibcstat = val;
323}
324
325static void handle_supp_msgs(struct ipath_devdata *dd,
326 unsigned supp_msgs, char msg[512])
327{
328 /*
329 * Print the message unless it's ibc status change only, which
330 * happens so often we never want to count it.
331 */
332 if (dd->ipath_lasterror & ~INFINIPATH_E_IBSTATUSCHANGED) {
333 ipath_decode_err(msg, sizeof msg, dd->ipath_lasterror &
334 ~INFINIPATH_E_IBSTATUSCHANGED);
335 if (dd->ipath_lasterror &
336 ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL))
337 ipath_dev_err(dd, "Suppressed %u messages for "
338 "fast-repeating errors (%s) (%llx)\n",
339 supp_msgs, msg,
340 (unsigned long long)
341 dd->ipath_lasterror);
342 else {
343 /*
344 * rcvegrfull and rcvhdrqfull are "normal", for some
345 * types of processes (mostly benchmarks) that send
346 * huge numbers of messages, while not processing
347 * them. So only complain about these at debug
348 * level.
349 */
350 ipath_dbg("Suppressed %u messages for %s\n",
351 supp_msgs, msg);
352 }
353 }
354}
355
356static unsigned handle_frequent_errors(struct ipath_devdata *dd,
357 ipath_err_t errs, char msg[512],
358 int *noprint)
359{
360 unsigned long nc;
361 static unsigned long nextmsg_time;
362 static unsigned nmsgs, supp_msgs;
363
364 /*
365 * Throttle back "fast" messages to no more than 10 per 5 seconds.
366 * This isn't perfect, but it's a reasonable heuristic. If we get
367 * more than 10, give a 6x longer delay.
368 */
369 nc = jiffies;
370 if (nmsgs > 10) {
371 if (time_before(nc, nextmsg_time)) {
372 *noprint = 1;
373 if (!supp_msgs++)
374 nextmsg_time = nc + HZ * 3;
375 }
376 else if (supp_msgs) {
377 handle_supp_msgs(dd, supp_msgs, msg);
378 supp_msgs = 0;
379 nmsgs = 0;
380 }
381 }
382 else if (!nmsgs++ || time_after(nc, nextmsg_time))
383 nextmsg_time = nc + HZ / 2;
384
385 return supp_msgs;
386}
387
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700388static int handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800389{
390 char msg[512];
391 u64 ignore_this_time = 0;
392 int i;
393 int chkerrpkts = 0, noprint = 0;
394 unsigned supp_msgs;
395
396 supp_msgs = handle_frequent_errors(dd, errs, msg, &noprint);
397
398 /*
399 * don't report errors that are masked (includes those always
400 * ignored)
401 */
402 errs &= ~dd->ipath_maskederrs;
403
404 /* do these first, they are most important */
405 if (errs & INFINIPATH_E_HARDWARE) {
406 /* reuse same msg buf */
407 dd->ipath_f_handle_hwerrors(dd, msg, sizeof msg);
408 }
409
410 if (!noprint && (errs & ~infinipath_e_bitsextant))
411 ipath_dev_err(dd, "error interrupt with unknown errors "
412 "%llx set\n", (unsigned long long)
413 (errs & ~infinipath_e_bitsextant));
414
415 if (errs & E_SUM_ERRS)
416 ignore_this_time = handle_e_sum_errs(dd, errs);
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700417 else if ((errs & E_SUM_LINK_PKTERRS) &&
418 !(dd->ipath_flags & IPATH_LINKACTIVE)) {
419 /*
420 * This can happen when SMA is trying to bring the link
421 * up, but the IB link changes state at the "wrong" time.
422 * The IB logic then complains that the packet isn't
423 * valid. We don't want to confuse people, so we just
424 * don't print them, except at debug
425 */
426 ipath_dbg("Ignoring packet errors %llx, because link not "
427 "ACTIVE\n", (unsigned long long) errs);
428 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
429 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800430
431 if (supp_msgs == 250000) {
432 /*
433 * It's not entirely reasonable assuming that the errors set
434 * in the last clear period are all responsible for the
435 * problem, but the alternative is to assume it's the only
436 * ones on this particular interrupt, which also isn't great
437 */
438 dd->ipath_maskederrs |= dd->ipath_lasterror | errs;
439 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
440 ~dd->ipath_maskederrs);
441 ipath_decode_err(msg, sizeof msg,
442 (dd->ipath_maskederrs & ~dd->
443 ipath_ignorederrs));
444
445 if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs) &
446 ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL))
447 ipath_dev_err(dd, "Disabling error(s) %llx because "
Adrian Bunk80f72282006-06-30 18:27:16 +0200448 "occurring too frequently (%s)\n",
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800449 (unsigned long long)
450 (dd->ipath_maskederrs &
451 ~dd->ipath_ignorederrs), msg);
452 else {
453 /*
454 * rcvegrfull and rcvhdrqfull are "normal",
455 * for some types of processes (mostly benchmarks)
456 * that send huge numbers of messages, while not
457 * processing them. So only complain about
458 * these at debug level.
459 */
460 ipath_dbg("Disabling frequent queue full errors "
461 "(%s)\n", msg);
462 }
463
464 /*
465 * Re-enable the masked errors after around 3 minutes. in
466 * ipath_get_faststats(). If we have a series of fast
467 * repeating but different errors, the interval will keep
468 * stretching out, but that's OK, as that's pretty
469 * catastrophic.
470 */
471 dd->ipath_unmasktime = jiffies + HZ * 180;
472 }
473
474 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, errs);
475 if (ignore_this_time)
476 errs &= ~ignore_this_time;
477 if (errs & ~dd->ipath_lasterror) {
478 errs &= ~dd->ipath_lasterror;
479 /* never suppress duplicate hwerrors or ibstatuschange */
480 dd->ipath_lasterror |= errs &
481 ~(INFINIPATH_E_HARDWARE |
482 INFINIPATH_E_IBSTATUSCHANGED);
483 }
484 if (!errs)
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700485 return 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800486
487 if (!noprint)
488 /*
489 * the ones we mask off are handled specially below or above
490 */
491 ipath_decode_err(msg, sizeof msg,
492 errs & ~(INFINIPATH_E_IBSTATUSCHANGED |
493 INFINIPATH_E_RRCVEGRFULL |
494 INFINIPATH_E_RRCVHDRFULL |
495 INFINIPATH_E_HARDWARE));
496 else
497 /* so we don't need if (!noprint) at strlcat's below */
498 *msg = 0;
499
500 if (errs & E_SUM_PKTERRS) {
501 ipath_stats.sps_pkterrs++;
502 chkerrpkts = 1;
503 }
504 if (errs & E_SUM_ERRS)
505 ipath_stats.sps_errs++;
506
507 if (errs & (INFINIPATH_E_RICRC | INFINIPATH_E_RVCRC)) {
508 ipath_stats.sps_crcerrs++;
509 chkerrpkts = 1;
510 }
511
512 /*
513 * We don't want to print these two as they happen, or we can make
514 * the situation even worse, because it takes so long to print
515 * messages to serial consoles. Kernel ports get printed from
516 * fast_stats, no more than every 5 seconds, user ports get printed
517 * on close
518 */
519 if (errs & INFINIPATH_E_RRCVHDRFULL) {
520 int any;
521 u32 hd, tl;
522 ipath_stats.sps_hdrqfull++;
523 for (any = i = 0; i < dd->ipath_cfgports; i++) {
524 struct ipath_portdata *pd = dd->ipath_pd[i];
525 if (i == 0) {
526 hd = dd->ipath_port0head;
527 tl = (u32) le64_to_cpu(
528 *dd->ipath_hdrqtailptr);
529 } else if (pd && pd->port_cnt &&
530 pd->port_rcvhdrtail_kvaddr) {
531 /*
532 * don't report same point multiple times,
533 * except kernel
534 */
535 tl = (u32) * pd->port_rcvhdrtail_kvaddr;
536 if (tl == dd->ipath_lastrcvhdrqtails[i])
537 continue;
538 hd = ipath_read_ureg32(dd, ur_rcvhdrhead,
539 i);
540 } else
541 continue;
542 if (hd == (tl + 1) ||
543 (!hd && tl == dd->ipath_hdrqlast)) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800544 if (i == 0)
545 chkerrpkts = 1;
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700546 dd->ipath_lastrcvhdrqtails[i] = tl;
547 pd->port_hdrqfull++;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800548 }
549 }
550 }
551 if (errs & INFINIPATH_E_RRCVEGRFULL) {
552 /*
553 * since this is of less importance and not likely to
554 * happen without also getting hdrfull, only count
555 * occurrences; don't check each port (or even the kernel
556 * vs user)
557 */
558 ipath_stats.sps_etidfull++;
559 if (dd->ipath_port0head !=
560 (u32) le64_to_cpu(*dd->ipath_hdrqtailptr))
561 chkerrpkts = 1;
562 }
563
564 /*
565 * do this before IBSTATUSCHANGED, in case both bits set in a single
566 * interrupt; we want the STATUSCHANGE to "win", so we do our
567 * internal copy of state machine correctly
568 */
569 if (errs & INFINIPATH_E_RIBLOSTLINK) {
570 /*
571 * force through block below
572 */
573 errs |= INFINIPATH_E_IBSTATUSCHANGED;
574 ipath_stats.sps_iblink++;
575 dd->ipath_flags |= IPATH_LINKDOWN;
576 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
577 | IPATH_LINKARMED | IPATH_LINKACTIVE);
578 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
579 if (!noprint) {
580 u64 st = ipath_read_kreg64(
581 dd, dd->ipath_kregs->kr_ibcstatus);
582
583 ipath_dbg("Lost link, link now down (%s)\n",
584 ipath_ibcstatus_str[st & 0xf]);
585 }
586 }
587 if (errs & INFINIPATH_E_IBSTATUSCHANGED)
588 handle_e_ibstatuschanged(dd, errs, noprint);
589
590 if (errs & INFINIPATH_E_RESET) {
591 if (!noprint)
592 ipath_dev_err(dd, "Got reset, requires re-init "
593 "(unload and reload driver)\n");
594 dd->ipath_flags &= ~IPATH_INITTED; /* needs re-init */
595 /* mark as having had error */
596 *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
597 *dd->ipath_statusp &= ~IPATH_STATUS_IB_CONF;
598 }
599
600 if (!noprint && *msg)
601 ipath_dev_err(dd, "%s error\n", msg);
602 if (dd->ipath_sma_state_wanted & dd->ipath_flags) {
603 ipath_cdbg(VERBOSE, "sma wanted state %x, iflags now %x, "
604 "waking\n", dd->ipath_sma_state_wanted,
605 dd->ipath_flags);
606 wake_up_interruptible(&ipath_sma_state_wait);
607 }
608
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700609 return chkerrpkts;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800610}
611
612/* this is separate to allow for better optimization of ipath_intr() */
613
614static void ipath_bad_intr(struct ipath_devdata *dd, u32 * unexpectp)
615{
616 /*
617 * sometimes happen during driver init and unload, don't want
618 * to process any interrupts at that point
619 */
620
621 /* this is just a bandaid, not a fix, if something goes badly
622 * wrong */
623 if (++*unexpectp > 100) {
624 if (++*unexpectp > 105) {
625 /*
626 * ok, we must be taking somebody else's interrupts,
627 * due to a messed up mptable and/or PIRQ table, so
628 * unregister the interrupt. We've seen this during
629 * linuxbios development work, and it may happen in
630 * the future again.
631 */
632 if (dd->pcidev && dd->pcidev->irq) {
633 ipath_dev_err(dd, "Now %u unexpected "
634 "interrupts, unregistering "
635 "interrupt handler\n",
636 *unexpectp);
637 ipath_dbg("free_irq of irq %x\n",
638 dd->pcidev->irq);
639 free_irq(dd->pcidev->irq, dd);
640 }
641 }
642 if (ipath_read_kreg32(dd, dd->ipath_kregs->kr_intmask)) {
643 ipath_dev_err(dd, "%u unexpected interrupts, "
644 "disabling interrupts completely\n",
645 *unexpectp);
646 /*
647 * disable all interrupts, something is very wrong
648 */
649 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
650 0ULL);
651 }
652 } else if (*unexpectp > 1)
653 ipath_dbg("Interrupt when not ready, should not happen, "
654 "ignoring\n");
655}
656
657static void ipath_bad_regread(struct ipath_devdata *dd)
658{
659 static int allbits;
660
661 /* separate routine, for better optimization of ipath_intr() */
662
663 /*
664 * We print the message and disable interrupts, in hope of
665 * having a better chance of debugging the problem.
666 */
667 ipath_dev_err(dd,
668 "Read of interrupt status failed (all bits set)\n");
669 if (allbits++) {
670 /* disable all interrupts, something is very wrong */
671 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
672 if (allbits == 2) {
673 ipath_dev_err(dd, "Still bad interrupt status, "
674 "unregistering interrupt\n");
675 free_irq(dd->pcidev->irq, dd);
676 } else if (allbits > 2) {
677 if ((allbits % 10000) == 0)
678 printk(".");
679 } else
680 ipath_dev_err(dd, "Disabling interrupts, "
681 "multiple errors\n");
682 }
683}
684
685static void handle_port_pioavail(struct ipath_devdata *dd)
686{
687 u32 i;
688 /*
689 * start from port 1, since for now port 0 is never using
690 * wait_event for PIO
691 */
692 for (i = 1; dd->ipath_portpiowait && i < dd->ipath_cfgports; i++) {
693 struct ipath_portdata *pd = dd->ipath_pd[i];
694
695 if (pd && pd->port_cnt &&
696 dd->ipath_portpiowait & (1U << i)) {
697 clear_bit(i, &dd->ipath_portpiowait);
698 if (test_bit(IPATH_PORT_WAITING_PIO,
699 &pd->port_flag)) {
700 clear_bit(IPATH_PORT_WAITING_PIO,
701 &pd->port_flag);
702 wake_up_interruptible(&pd->port_wait);
703 }
704 }
705 }
706}
707
708static void handle_layer_pioavail(struct ipath_devdata *dd)
709{
710 int ret;
711
712 ret = __ipath_layer_intr(dd, IPATH_LAYER_INT_SEND_CONTINUE);
713 if (ret > 0)
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -0700714 goto set;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800715
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -0700716 ret = ipath_ib_piobufavail(dd->verbs_dev);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800717 if (ret > 0)
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -0700718 goto set;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800719
720 return;
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -0700721set:
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800722 set_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
723 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
724 dd->ipath_sendctrl);
725}
726
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700727/*
728 * Handle receive interrupts for user ports; this means a user
729 * process was waiting for a packet to arrive, and didn't want
730 * to poll
731 */
732static void handle_urcv(struct ipath_devdata *dd, u32 istat)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800733{
734 u64 portr;
735 int i;
736 int rcvdint = 0;
737
738 portr = ((istat >> INFINIPATH_I_RCVAVAIL_SHIFT) &
739 infinipath_i_rcvavail_mask)
740 | ((istat >> INFINIPATH_I_RCVURG_SHIFT) &
741 infinipath_i_rcvurg_mask);
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700742 for (i = 1; i < dd->ipath_cfgports; i++) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800743 struct ipath_portdata *pd = dd->ipath_pd[i];
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700744 if (portr & (1 << i) && pd && pd->port_cnt &&
745 test_bit(IPATH_PORT_WAITING_RCV, &pd->port_flag)) {
746 int rcbit;
747 clear_bit(IPATH_PORT_WAITING_RCV,
748 &pd->port_flag);
749 rcbit = i + INFINIPATH_R_INTRAVAIL_SHIFT;
750 clear_bit(1UL << rcbit, &dd->ipath_rcvctrl);
751 wake_up_interruptible(&pd->port_wait);
752 rcvdint = 1;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800753 }
754 }
755 if (rcvdint) {
756 /* only want to take one interrupt, so turn off the rcv
757 * interrupt for all the ports that we did the wakeup on
758 * (but never for kernel port)
759 */
760 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
761 dd->ipath_rcvctrl);
762 }
763}
764
765irqreturn_t ipath_intr(int irq, void *data, struct pt_regs *regs)
766{
767 struct ipath_devdata *dd = data;
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700768 u32 istat, chk0rcv = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800769 ipath_err_t estat = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800770 irqreturn_t ret;
Bryan O'Sullivan57abad22006-07-01 04:36:05 -0700771 u32 oldhead, curtail;
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700772 static unsigned unexpected = 0;
773 static const u32 port0rbits = (1U<<INFINIPATH_I_RCVAVAIL_SHIFT) |
774 (1U<<INFINIPATH_I_RCVURG_SHIFT);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800775
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700776 ipath_stats.sps_ints++;
777
778 if (!(dd->ipath_flags & IPATH_PRESENT)) {
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -0700779 /*
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700780 * This return value is not great, but we do not want the
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -0700781 * interrupt core code to remove our interrupt handler
782 * because we don't appear to be handling an interrupt
783 * during a chip reset.
784 */
785 return IRQ_HANDLED;
786 }
787
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700788 /*
789 * this needs to be flags&initted, not statusp, so we keep
790 * taking interrupts even after link goes down, etc.
791 * Also, we *must* clear the interrupt at some point, or we won't
792 * take it again, which can be real bad for errors, etc...
793 */
794
795 if (!(dd->ipath_flags & IPATH_INITTED)) {
796 ipath_bad_intr(dd, &unexpected);
797 ret = IRQ_NONE;
798 goto bail;
799 }
800
801 /*
802 * We try to avoid reading the interrupt status register, since
803 * that's a PIO read, and stalls the processor for up to about
804 * ~0.25 usec. The idea is that if we processed a port0 packet,
805 * we blindly clear the port 0 receive interrupt bits, and nothing
806 * else, then return. If other interrupts are pending, the chip
807 * will re-interrupt us as soon as we write the intclear register.
808 * We then won't process any more kernel packets (if not the 2nd
809 * time, then the 3rd or 4th) and we'll then handle the other
810 * interrupts. We clear the interrupts first so that we don't
811 * lose intr for later packets that arrive while we are processing.
812 */
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700813 oldhead = dd->ipath_port0head;
Bryan O'Sullivan57abad22006-07-01 04:36:05 -0700814 curtail = (u32)le64_to_cpu(*dd->ipath_hdrqtailptr);
815 if (oldhead != curtail) {
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700816 if (dd->ipath_flags & IPATH_GPIO_INTR) {
817 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
818 (u64) (1 << 2));
Bryan O'Sullivan57abad22006-07-01 04:36:05 -0700819 istat = port0rbits | INFINIPATH_I_GPIO;
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700820 }
821 else
Bryan O'Sullivan57abad22006-07-01 04:36:05 -0700822 istat = port0rbits;
823 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, istat);
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700824 ipath_kreceive(dd);
825 if (oldhead != dd->ipath_port0head) {
826 ipath_stats.sps_fastrcvint++;
827 goto done;
828 }
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700829 }
830
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -0700831 istat = ipath_read_kreg32(dd, dd->ipath_kregs->kr_intstatus);
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700832
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800833 if (unlikely(!istat)) {
834 ipath_stats.sps_nullintr++;
835 ret = IRQ_NONE; /* not our interrupt, or already handled */
836 goto bail;
837 }
838 if (unlikely(istat == -1)) {
839 ipath_bad_regread(dd);
840 /* don't know if it was our interrupt or not */
841 ret = IRQ_NONE;
842 goto bail;
843 }
844
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800845 if (unexpected)
846 unexpected = 0;
847
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700848 if (unlikely(istat & ~infinipath_i_bitsextant))
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800849 ipath_dev_err(dd,
850 "interrupt with unknown interrupts %x set\n",
851 istat & (u32) ~ infinipath_i_bitsextant);
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700852 else
853 ipath_cdbg(VERBOSE, "intr stat=0x%x\n", istat);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800854
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700855 if (unlikely(istat & INFINIPATH_I_ERROR)) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800856 ipath_stats.sps_errints++;
857 estat = ipath_read_kreg64(dd,
858 dd->ipath_kregs->kr_errorstatus);
859 if (!estat)
860 dev_info(&dd->pcidev->dev, "error interrupt (%x), "
861 "but no error bits set!\n", istat);
862 else if (estat == -1LL)
863 /*
864 * should we try clearing all, or hope next read
865 * works?
866 */
867 ipath_dev_err(dd, "Read of error status failed "
868 "(all bits set); ignoring\n");
869 else
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700870 if (handle_errors(dd, estat))
871 /* force calling ipath_kreceive() */
872 chk0rcv = 1;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800873 }
874
875 if (istat & INFINIPATH_I_GPIO) {
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700876 /*
877 * Packets are available in the port 0 rcv queue.
878 * Eventually this needs to be generalized to check
879 * IPATH_GPIO_INTR, and the specific GPIO bit, if
880 * GPIO interrupts are used for anything else.
881 */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800882 if (unlikely(!(dd->ipath_flags & IPATH_GPIO_INTR))) {
883 u32 gpiostatus;
884 gpiostatus = ipath_read_kreg32(
885 dd, dd->ipath_kregs->kr_gpio_status);
886 ipath_dbg("Unexpected GPIO interrupt bits %x\n",
887 gpiostatus);
888 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
889 gpiostatus);
890 }
891 else {
892 /* Clear GPIO status bit 2 */
893 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
Bryan O'Sullivan57abad22006-07-01 04:36:05 -0700894 (u64) (1 << 2));
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700895 chk0rcv = 1;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800896 }
897 }
Bryan O'Sullivan57abad22006-07-01 04:36:05 -0700898 chk0rcv |= istat & port0rbits;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800899
900 /*
Bryan O'Sullivan57abad22006-07-01 04:36:05 -0700901 * Clear the interrupt bits we found set, unless they are receive
902 * related, in which case we already cleared them above, and don't
903 * want to clear them again, because we might lose an interrupt.
904 * Clear it early, so we "know" know the chip will have seen this by
905 * the time we process the queue, and will re-interrupt if necessary.
906 * The processor itself won't take the interrupt again until we return.
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800907 */
908 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, istat);
909
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700910 /*
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700911 * handle port0 receive before checking for pio buffers available,
912 * since receives can overflow; piobuf waiters can afford a few
913 * extra cycles, since they were waiting anyway, and user's waiting
914 * for receive are at the bottom.
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700915 */
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700916 if (chk0rcv) {
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700917 ipath_kreceive(dd);
918 istat &= ~port0rbits;
919 }
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700920
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700921 if (istat & ((infinipath_i_rcvavail_mask <<
922 INFINIPATH_I_RCVAVAIL_SHIFT)
923 | (infinipath_i_rcvurg_mask <<
924 INFINIPATH_I_RCVURG_SHIFT)))
925 handle_urcv(dd, istat);
926
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800927 if (istat & INFINIPATH_I_SPIOBUFAVAIL) {
928 clear_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
929 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
930 dd->ipath_sendctrl);
931
932 if (dd->ipath_portpiowait)
933 handle_port_pioavail(dd);
934
935 handle_layer_pioavail(dd);
936 }
937
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700938done:
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800939 ret = IRQ_HANDLED;
940
941bail:
942 return ret;
943}