blob: 801a20d06de680316165f4c74ccbeeb4ec7a5f26 [file] [log] [blame]
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001/*
John Gregor87427da2007-06-11 10:21:14 -07002 * Copyright (c) 2006, 2007 QLogic Corporation. 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'Sullivanb1c1b6a2006-08-25 11:24:31 -070037#include "ipath_verbs.h"
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -070038#include "ipath_common.h"
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -080039
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070040/*
Bryan O'Sullivan9783ab42007-03-15 14:45:07 -070041 * clear (write) a pio buffer, to clear a parity error. This routine
42 * should only be called when in freeze mode, and the buffer should be
43 * canceled afterwards.
44 */
45static void ipath_clrpiobuf(struct ipath_devdata *dd, u32 pnum)
46{
47 u32 __iomem *pbuf;
48 u32 dwcnt; /* dword count to write */
49 if (pnum < dd->ipath_piobcnt2k) {
50 pbuf = (u32 __iomem *) (dd->ipath_pio2kbase + pnum *
51 dd->ipath_palign);
52 dwcnt = dd->ipath_piosize2k >> 2;
53 }
54 else {
55 pbuf = (u32 __iomem *) (dd->ipath_pio4kbase +
56 (pnum - dd->ipath_piobcnt2k) * dd->ipath_4kalign);
57 dwcnt = dd->ipath_piosize4k >> 2;
58 }
59 dev_info(&dd->pcidev->dev,
60 "Rewrite PIO buffer %u, to recover from parity error\n",
61 pnum);
62 *pbuf = dwcnt+1; /* no flush required, since already in freeze */
63 while(--dwcnt)
64 *pbuf++ = 0;
65}
66
67/*
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070068 * Called when we might have an error that is specific to a particular
69 * PIO buffer, and may need to cancel that buffer, so it can be re-used.
Bryan O'Sullivan9783ab42007-03-15 14:45:07 -070070 * If rewrite is true, and bits are set in the sendbufferror registers,
71 * we'll write to the buffer, for error recovery on parity errors.
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070072 */
Roland Dreierda9aec72007-07-17 18:37:43 -070073static void ipath_disarm_senderrbufs(struct ipath_devdata *dd, int rewrite)
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070074{
75 u32 piobcnt;
76 unsigned long sbuf[4];
77 /*
78 * it's possible that sendbuffererror could have bits set; might
79 * have already done this as a result of hardware error handling
80 */
81 piobcnt = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
82 /* read these before writing errorclear */
83 sbuf[0] = ipath_read_kreg64(
84 dd, dd->ipath_kregs->kr_sendbuffererror);
85 sbuf[1] = ipath_read_kreg64(
86 dd, dd->ipath_kregs->kr_sendbuffererror + 1);
87 if (piobcnt > 128) {
88 sbuf[2] = ipath_read_kreg64(
89 dd, dd->ipath_kregs->kr_sendbuffererror + 2);
90 sbuf[3] = ipath_read_kreg64(
91 dd, dd->ipath_kregs->kr_sendbuffererror + 3);
92 }
93
94 if (sbuf[0] || sbuf[1] || (piobcnt > 128 && (sbuf[2] || sbuf[3]))) {
95 int i;
Dave Olson93800682007-06-18 14:24:41 -070096 if (ipath_debug & (__IPATH_PKTDBG|__IPATH_DBG) &&
97 dd->ipath_lastcancel > jiffies) {
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070098 __IPATH_DBG_WHICH(__IPATH_PKTDBG|__IPATH_DBG,
99 "SendbufErrs %lx %lx", sbuf[0],
100 sbuf[1]);
101 if (ipath_debug & __IPATH_PKTDBG && piobcnt > 128)
102 printk(" %lx %lx ", sbuf[2], sbuf[3]);
103 printk("\n");
104 }
105
106 for (i = 0; i < piobcnt; i++)
Bryan O'Sullivan9783ab42007-03-15 14:45:07 -0700107 if (test_bit(i, sbuf)) {
108 if (rewrite)
109 ipath_clrpiobuf(dd, i);
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -0700110 ipath_disarm_piobufs(dd, i, 1);
Bryan O'Sullivan9783ab42007-03-15 14:45:07 -0700111 }
Dave Olson93800682007-06-18 14:24:41 -0700112 /* ignore armlaunch errs for a bit */
113 dd->ipath_lastcancel = jiffies+3;
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -0700114 }
115}
116
117
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700118/* These are all rcv-related errors which we want to count for stats */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800119#define E_SUM_PKTERRS \
120 (INFINIPATH_E_RHDRLEN | INFINIPATH_E_RBADTID | \
121 INFINIPATH_E_RBADVERSION | INFINIPATH_E_RHDR | \
122 INFINIPATH_E_RLONGPKTLEN | INFINIPATH_E_RSHORTPKTLEN | \
123 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RMINPKTLEN | \
124 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RUNSUPVL | \
125 INFINIPATH_E_RUNEXPCHAR | INFINIPATH_E_REBP)
126
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700127/* These are all send-related errors which we want to count for stats */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800128#define E_SUM_ERRS \
129 (INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM | \
130 INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
131 INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SUNSUPVL | \
132 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
133 INFINIPATH_E_INVALIDADDR)
134
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700135/*
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700136 * this is similar to E_SUM_ERRS, but can't ignore armlaunch, don't ignore
137 * errors not related to freeze and cancelling buffers. Can't ignore
138 * armlaunch because could get more while still cleaning up, and need
139 * to cancel those as they happen.
140 */
141#define E_SPKT_ERRS_IGNORE \
142 (INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
143 INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SMINPKTLEN | \
144 INFINIPATH_E_SPKTLEN)
145
146/*
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700147 * these are errors that can occur when the link changes state while
148 * a packet is being sent or received. This doesn't cover things
149 * like EBP or VCRC that can be the result of a sending having the
150 * link change state, so we receive a "known bad" packet.
151 */
152#define E_SUM_LINK_PKTERRS \
153 (INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
154 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
155 INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RMINPKTLEN | \
156 INFINIPATH_E_RUNEXPCHAR)
157
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800158static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs)
159{
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800160 u64 ignore_this_time = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800161
Bryan O'Sullivan9783ab42007-03-15 14:45:07 -0700162 ipath_disarm_senderrbufs(dd, 0);
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700163 if ((errs & E_SUM_LINK_PKTERRS) &&
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800164 !(dd->ipath_flags & IPATH_LINKACTIVE)) {
165 /*
166 * This can happen when SMA is trying to bring the link
167 * up, but the IB link changes state at the "wrong" time.
168 * The IB logic then complains that the packet isn't
169 * valid. We don't want to confuse people, so we just
170 * don't print them, except at debug
171 */
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700172 ipath_dbg("Ignoring packet errors %llx, because link not "
173 "ACTIVE\n", (unsigned long long) errs);
174 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800175 }
176
177 return ignore_this_time;
178}
179
Bryan O'Sullivan8d588f82006-09-28 09:00:08 -0700180/* generic hw error messages... */
181#define INFINIPATH_HWE_TXEMEMPARITYERR_MSG(a) \
182 { \
183 .mask = ( INFINIPATH_HWE_TXEMEMPARITYERR_##a << \
184 INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT ), \
185 .msg = "TXE " #a " Memory Parity" \
186 }
187#define INFINIPATH_HWE_RXEMEMPARITYERR_MSG(a) \
188 { \
189 .mask = ( INFINIPATH_HWE_RXEMEMPARITYERR_##a << \
190 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT ), \
191 .msg = "RXE " #a " Memory Parity" \
192 }
193
194static const struct ipath_hwerror_msgs ipath_generic_hwerror_msgs[] = {
195 INFINIPATH_HWE_MSG(IBCBUSFRSPCPARITYERR, "IPATH2IB Parity"),
196 INFINIPATH_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2IPATH Parity"),
197
198 INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOBUF),
199 INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOPBC),
200 INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOLAUNCHFIFO),
201
202 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(RCVBUF),
203 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(LOOKUPQ),
204 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EAGERTID),
205 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EXPTID),
206 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(FLAGBUF),
207 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(DATAINFO),
208 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(HDRINFO),
209};
210
211/**
212 * ipath_format_hwmsg - format a single hwerror message
213 * @msg message buffer
214 * @msgl length of message buffer
215 * @hwmsg message to add to message buffer
216 */
217static void ipath_format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
218{
219 strlcat(msg, "[", msgl);
220 strlcat(msg, hwmsg, msgl);
221 strlcat(msg, "]", msgl);
222}
223
224/**
225 * ipath_format_hwerrors - format hardware error messages for display
226 * @hwerrs hardware errors bit vector
227 * @hwerrmsgs hardware error descriptions
228 * @nhwerrmsgs number of hwerrmsgs
229 * @msg message buffer
230 * @msgl message buffer length
231 */
232void ipath_format_hwerrors(u64 hwerrs,
233 const struct ipath_hwerror_msgs *hwerrmsgs,
234 size_t nhwerrmsgs,
235 char *msg, size_t msgl)
236{
237 int i;
238 const int glen =
239 sizeof(ipath_generic_hwerror_msgs) /
240 sizeof(ipath_generic_hwerror_msgs[0]);
241
242 for (i=0; i<glen; i++) {
243 if (hwerrs & ipath_generic_hwerror_msgs[i].mask) {
244 ipath_format_hwmsg(msg, msgl,
245 ipath_generic_hwerror_msgs[i].msg);
246 }
247 }
248
249 for (i=0; i<nhwerrmsgs; i++) {
250 if (hwerrs & hwerrmsgs[i].mask) {
251 ipath_format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
252 }
253 }
254}
255
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800256/* return the strings for the most common link states */
257static char *ib_linkstate(u32 linkstate)
258{
259 char *ret;
260
261 switch (linkstate) {
262 case IPATH_IBSTATE_INIT:
263 ret = "Init";
264 break;
265 case IPATH_IBSTATE_ARM:
266 ret = "Arm";
267 break;
268 case IPATH_IBSTATE_ACTIVE:
269 ret = "Active";
270 break;
271 default:
272 ret = "Down";
273 }
274
275 return ret;
276}
277
278static void handle_e_ibstatuschanged(struct ipath_devdata *dd,
279 ipath_err_t errs, int noprint)
280{
281 u64 val;
282 u32 ltstate, lstate;
283
284 /*
285 * even if diags are enabled, we want to notice LINKINIT, etc.
286 * We just don't want to change the LED state, or
287 * dd->ipath_kregs->kr_ibcctrl
288 */
289 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
290 lstate = val & IPATH_IBSTATE_MASK;
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700291
292 /*
293 * this is confusing enough when it happens that I want to always put it
294 * on the console and in the logs. If it was a requested state change,
295 * we'll have already cleared the flags, so we won't print this warning
296 */
297 if ((lstate != IPATH_IBSTATE_ARM && lstate != IPATH_IBSTATE_ACTIVE)
298 && (dd->ipath_flags & (IPATH_LINKARMED | IPATH_LINKACTIVE))) {
299 dev_info(&dd->pcidev->dev, "Link state changed from %s to %s\n",
300 (dd->ipath_flags & IPATH_LINKARMED) ? "ARM" : "ACTIVE",
301 ib_linkstate(lstate));
302 /*
303 * Flush all queued sends when link went to DOWN or INIT,
304 * to be sure that they don't block SMA and other MAD packets
305 */
Dave Olson3810f2a2007-07-20 14:23:37 -0700306 ipath_cancel_sends(dd, 1);
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700307 }
308 else if (lstate == IPATH_IBSTATE_INIT || lstate == IPATH_IBSTATE_ARM ||
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800309 lstate == IPATH_IBSTATE_ACTIVE) {
310 /*
311 * only print at SMA if there is a change, debug if not
312 * (sometimes we want to know that, usually not).
313 */
314 if (lstate == ((unsigned) dd->ipath_lastibcstat
315 & IPATH_IBSTATE_MASK)) {
316 ipath_dbg("Status change intr but no change (%s)\n",
317 ib_linkstate(lstate));
318 }
319 else
Bryan O'Sullivan0fd41362006-08-25 11:24:34 -0700320 ipath_cdbg(VERBOSE, "Unit %u link state %s, last "
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800321 "was %s\n", dd->ipath_unit,
322 ib_linkstate(lstate),
323 ib_linkstate((unsigned)
Roland Dreier5494c222006-04-19 11:40:12 -0700324 dd->ipath_lastibcstat
325 & IPATH_IBSTATE_MASK));
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800326 }
327 else {
328 lstate = dd->ipath_lastibcstat & IPATH_IBSTATE_MASK;
329 if (lstate == IPATH_IBSTATE_INIT ||
330 lstate == IPATH_IBSTATE_ARM ||
331 lstate == IPATH_IBSTATE_ACTIVE)
Bryan O'Sullivan0fd41362006-08-25 11:24:34 -0700332 ipath_cdbg(VERBOSE, "Unit %u link state down"
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800333 " (state 0x%x), from %s\n",
334 dd->ipath_unit,
335 (u32)val & IPATH_IBSTATE_MASK,
336 ib_linkstate(lstate));
337 else
338 ipath_cdbg(VERBOSE, "Unit %u link state changed "
339 "to 0x%x from down (%x)\n",
340 dd->ipath_unit, (u32) val, lstate);
341 }
342 ltstate = (val >> INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
343 INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
344 lstate = (val >> INFINIPATH_IBCS_LINKSTATE_SHIFT) &
345 INFINIPATH_IBCS_LINKSTATE_MASK;
346
347 if (ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE ||
348 ltstate == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
349 u32 last_ltstate;
350
351 /*
352 * Ignore cycling back and forth from Polling.Active
353 * to Polling.Quiet while waiting for the other end of
354 * the link to come up. We will cycle back and forth
355 * between them if no cable is plugged in,
356 * the other device is powered off or disabled, etc.
357 */
358 last_ltstate = (dd->ipath_lastibcstat >>
359 INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT)
360 & INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
361 if (last_ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE
362 || last_ltstate ==
363 INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
364 if (dd->ipath_ibpollcnt > 40) {
365 dd->ipath_flags |= IPATH_NOCABLE;
366 *dd->ipath_statusp |=
367 IPATH_STATUS_IB_NOCABLE;
368 } else
369 dd->ipath_ibpollcnt++;
370 goto skip_ibchange;
371 }
372 }
373 dd->ipath_ibpollcnt = 0; /* some state other than 2 or 3 */
374 ipath_stats.sps_iblink++;
375 if (ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP) {
376 dd->ipath_flags |= IPATH_LINKDOWN;
377 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
378 | IPATH_LINKACTIVE |
379 IPATH_LINKARMED);
380 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
Bryan O'Sullivanfba75202006-07-01 04:36:09 -0700381 dd->ipath_lli_counter = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800382 if (!noprint) {
383 if (((dd->ipath_lastibcstat >>
384 INFINIPATH_IBCS_LINKSTATE_SHIFT) &
385 INFINIPATH_IBCS_LINKSTATE_MASK)
386 == INFINIPATH_IBCS_L_STATE_ACTIVE)
387 /* if from up to down be more vocal */
Bryan O'Sullivan0fd41362006-08-25 11:24:34 -0700388 ipath_cdbg(VERBOSE,
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800389 "Unit %u link now down (%s)\n",
390 dd->ipath_unit,
391 ipath_ibcstatus_str[ltstate]);
392 else
393 ipath_cdbg(VERBOSE, "Unit %u link is "
394 "down (%s)\n", dd->ipath_unit,
395 ipath_ibcstatus_str[ltstate]);
396 }
397
398 dd->ipath_f_setextled(dd, lstate, ltstate);
399 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ACTIVE) {
400 dd->ipath_flags |= IPATH_LINKACTIVE;
401 dd->ipath_flags &=
402 ~(IPATH_LINKUNK | IPATH_LINKINIT | IPATH_LINKDOWN |
403 IPATH_LINKARMED | IPATH_NOCABLE);
404 *dd->ipath_statusp &= ~IPATH_STATUS_IB_NOCABLE;
405 *dd->ipath_statusp |=
406 IPATH_STATUS_IB_READY | IPATH_STATUS_IB_CONF;
407 dd->ipath_f_setextled(dd, lstate, ltstate);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800408 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_INIT) {
409 /*
410 * set INIT and DOWN. Down is checked by most of the other
411 * code, but INIT is useful to know in a few places.
412 */
413 dd->ipath_flags |= IPATH_LINKINIT | IPATH_LINKDOWN;
414 dd->ipath_flags &=
415 ~(IPATH_LINKUNK | IPATH_LINKACTIVE | IPATH_LINKARMED
416 | IPATH_NOCABLE);
417 *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
418 | IPATH_STATUS_IB_READY);
419 dd->ipath_f_setextled(dd, lstate, ltstate);
420 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ARM) {
421 dd->ipath_flags |= IPATH_LINKARMED;
422 dd->ipath_flags &=
423 ~(IPATH_LINKUNK | IPATH_LINKDOWN | IPATH_LINKINIT |
424 IPATH_LINKACTIVE | IPATH_NOCABLE);
425 *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
426 | IPATH_STATUS_IB_READY);
427 dd->ipath_f_setextled(dd, lstate, ltstate);
428 } else {
429 if (!noprint)
430 ipath_dbg("IBstatuschange unit %u: %s (%x)\n",
431 dd->ipath_unit,
432 ipath_ibcstatus_str[ltstate], ltstate);
433 }
434skip_ibchange:
435 dd->ipath_lastibcstat = val;
436}
437
438static void handle_supp_msgs(struct ipath_devdata *dd,
439 unsigned supp_msgs, char msg[512])
440{
441 /*
442 * Print the message unless it's ibc status change only, which
443 * happens so often we never want to count it.
444 */
445 if (dd->ipath_lasterror & ~INFINIPATH_E_IBSTATUSCHANGED) {
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700446 int iserr;
447 iserr = ipath_decode_err(msg, sizeof msg,
448 dd->ipath_lasterror &
449 ~INFINIPATH_E_IBSTATUSCHANGED);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800450 if (dd->ipath_lasterror &
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700451 ~(INFINIPATH_E_RRCVEGRFULL |
452 INFINIPATH_E_RRCVHDRFULL | INFINIPATH_E_PKTERRS))
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800453 ipath_dev_err(dd, "Suppressed %u messages for "
454 "fast-repeating errors (%s) (%llx)\n",
455 supp_msgs, msg,
456 (unsigned long long)
457 dd->ipath_lasterror);
458 else {
459 /*
460 * rcvegrfull and rcvhdrqfull are "normal", for some
461 * types of processes (mostly benchmarks) that send
462 * huge numbers of messages, while not processing
463 * them. So only complain about these at debug
464 * level.
465 */
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700466 if (iserr)
467 ipath_dbg("Suppressed %u messages for %s\n",
468 supp_msgs, msg);
469 else
470 ipath_cdbg(ERRPKT,
471 "Suppressed %u messages for %s\n",
472 supp_msgs, msg);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800473 }
474 }
475}
476
477static unsigned handle_frequent_errors(struct ipath_devdata *dd,
478 ipath_err_t errs, char msg[512],
479 int *noprint)
480{
481 unsigned long nc;
482 static unsigned long nextmsg_time;
483 static unsigned nmsgs, supp_msgs;
484
485 /*
486 * Throttle back "fast" messages to no more than 10 per 5 seconds.
487 * This isn't perfect, but it's a reasonable heuristic. If we get
488 * more than 10, give a 6x longer delay.
489 */
490 nc = jiffies;
491 if (nmsgs > 10) {
492 if (time_before(nc, nextmsg_time)) {
493 *noprint = 1;
494 if (!supp_msgs++)
495 nextmsg_time = nc + HZ * 3;
496 }
497 else if (supp_msgs) {
498 handle_supp_msgs(dd, supp_msgs, msg);
499 supp_msgs = 0;
500 nmsgs = 0;
501 }
502 }
503 else if (!nmsgs++ || time_after(nc, nextmsg_time))
504 nextmsg_time = nc + HZ / 2;
505
506 return supp_msgs;
507}
508
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700509static int handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800510{
511 char msg[512];
512 u64 ignore_this_time = 0;
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700513 int i, iserr = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800514 int chkerrpkts = 0, noprint = 0;
515 unsigned supp_msgs;
Michael Albaughaecd3b52007-05-17 07:26:28 -0700516 int log_idx;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800517
518 supp_msgs = handle_frequent_errors(dd, errs, msg, &noprint);
519
Dave Olson78d1e022007-07-20 14:41:26 -0700520 /* don't report errors that are masked */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800521 errs &= ~dd->ipath_maskederrs;
522
523 /* do these first, they are most important */
524 if (errs & INFINIPATH_E_HARDWARE) {
525 /* reuse same msg buf */
526 dd->ipath_f_handle_hwerrors(dd, msg, sizeof msg);
Michael Albaughaecd3b52007-05-17 07:26:28 -0700527 } else {
528 u64 mask;
529 for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx) {
530 mask = dd->ipath_eep_st_masks[log_idx].errs_to_log;
531 if (errs & mask)
532 ipath_inc_eeprom_err(dd, log_idx, 1);
533 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800534 }
535
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -0700536 if (!noprint && (errs & ~dd->ipath_e_bitsextant))
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800537 ipath_dev_err(dd, "error interrupt with unknown errors "
538 "%llx set\n", (unsigned long long)
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -0700539 (errs & ~dd->ipath_e_bitsextant));
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800540
541 if (errs & E_SUM_ERRS)
542 ignore_this_time = handle_e_sum_errs(dd, errs);
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700543 else if ((errs & E_SUM_LINK_PKTERRS) &&
544 !(dd->ipath_flags & IPATH_LINKACTIVE)) {
545 /*
546 * This can happen when SMA is trying to bring the link
547 * up, but the IB link changes state at the "wrong" time.
548 * The IB logic then complains that the packet isn't
549 * valid. We don't want to confuse people, so we just
550 * don't print them, except at debug
551 */
552 ipath_dbg("Ignoring packet errors %llx, because link not "
553 "ACTIVE\n", (unsigned long long) errs);
554 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
555 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800556
557 if (supp_msgs == 250000) {
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700558 int s_iserr;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800559 /*
560 * It's not entirely reasonable assuming that the errors set
561 * in the last clear period are all responsible for the
562 * problem, but the alternative is to assume it's the only
563 * ones on this particular interrupt, which also isn't great
564 */
565 dd->ipath_maskederrs |= dd->ipath_lasterror | errs;
Dave Olson78d1e022007-07-20 14:41:26 -0700566 dd->ipath_errormask &= ~dd->ipath_maskederrs;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800567 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
Dave Olson78d1e022007-07-20 14:41:26 -0700568 dd->ipath_errormask);
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700569 s_iserr = ipath_decode_err(msg, sizeof msg,
Dave Olson78d1e022007-07-20 14:41:26 -0700570 dd->ipath_maskederrs);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800571
Dave Olson78d1e022007-07-20 14:41:26 -0700572 if (dd->ipath_maskederrs &
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700573 ~(INFINIPATH_E_RRCVEGRFULL |
574 INFINIPATH_E_RRCVHDRFULL | INFINIPATH_E_PKTERRS))
575 ipath_dev_err(dd, "Temporarily disabling "
576 "error(s) %llx reporting; too frequent (%s)\n",
Dave Olson78d1e022007-07-20 14:41:26 -0700577 (unsigned long long)dd->ipath_maskederrs,
578 msg);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800579 else {
580 /*
581 * rcvegrfull and rcvhdrqfull are "normal",
582 * for some types of processes (mostly benchmarks)
583 * that send huge numbers of messages, while not
584 * processing them. So only complain about
585 * these at debug level.
586 */
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700587 if (s_iserr)
588 ipath_dbg("Temporarily disabling reporting "
589 "too frequent queue full errors (%s)\n",
590 msg);
591 else
592 ipath_cdbg(ERRPKT,
593 "Temporarily disabling reporting too"
594 " frequent packet errors (%s)\n",
595 msg);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800596 }
597
598 /*
599 * Re-enable the masked errors after around 3 minutes. in
600 * ipath_get_faststats(). If we have a series of fast
601 * repeating but different errors, the interval will keep
602 * stretching out, but that's OK, as that's pretty
603 * catastrophic.
604 */
605 dd->ipath_unmasktime = jiffies + HZ * 180;
606 }
607
608 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, errs);
609 if (ignore_this_time)
610 errs &= ~ignore_this_time;
611 if (errs & ~dd->ipath_lasterror) {
612 errs &= ~dd->ipath_lasterror;
613 /* never suppress duplicate hwerrors or ibstatuschange */
614 dd->ipath_lasterror |= errs &
615 ~(INFINIPATH_E_HARDWARE |
616 INFINIPATH_E_IBSTATUSCHANGED);
617 }
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -0700618
619 /* likely due to cancel, so suppress */
620 if ((errs & (INFINIPATH_E_SPKTLEN | INFINIPATH_E_SPIOARMLAUNCH)) &&
621 dd->ipath_lastcancel > jiffies) {
622 ipath_dbg("Suppressed armlaunch/spktlen after error send cancel\n");
623 errs &= ~(INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SPKTLEN);
624 }
625
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800626 if (!errs)
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700627 return 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800628
629 if (!noprint)
630 /*
631 * the ones we mask off are handled specially below or above
632 */
633 ipath_decode_err(msg, sizeof msg,
634 errs & ~(INFINIPATH_E_IBSTATUSCHANGED |
635 INFINIPATH_E_RRCVEGRFULL |
636 INFINIPATH_E_RRCVHDRFULL |
637 INFINIPATH_E_HARDWARE));
638 else
639 /* so we don't need if (!noprint) at strlcat's below */
640 *msg = 0;
641
642 if (errs & E_SUM_PKTERRS) {
643 ipath_stats.sps_pkterrs++;
644 chkerrpkts = 1;
645 }
646 if (errs & E_SUM_ERRS)
647 ipath_stats.sps_errs++;
648
649 if (errs & (INFINIPATH_E_RICRC | INFINIPATH_E_RVCRC)) {
650 ipath_stats.sps_crcerrs++;
651 chkerrpkts = 1;
652 }
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700653 iserr = errs & ~(E_SUM_PKTERRS | INFINIPATH_E_PKTERRS);
654
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800655
656 /*
657 * We don't want to print these two as they happen, or we can make
658 * the situation even worse, because it takes so long to print
659 * messages to serial consoles. Kernel ports get printed from
660 * fast_stats, no more than every 5 seconds, user ports get printed
661 * on close
662 */
663 if (errs & INFINIPATH_E_RRCVHDRFULL) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800664 u32 hd, tl;
665 ipath_stats.sps_hdrqfull++;
Roland Dreier44f8e3f2006-12-12 11:50:20 -0800666 for (i = 0; i < dd->ipath_cfgports; i++) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800667 struct ipath_portdata *pd = dd->ipath_pd[i];
668 if (i == 0) {
669 hd = dd->ipath_port0head;
670 tl = (u32) le64_to_cpu(
671 *dd->ipath_hdrqtailptr);
672 } else if (pd && pd->port_cnt &&
673 pd->port_rcvhdrtail_kvaddr) {
674 /*
675 * don't report same point multiple times,
676 * except kernel
677 */
Bryan O'Sullivan1fd3b402006-09-28 09:00:13 -0700678 tl = *(u64 *) pd->port_rcvhdrtail_kvaddr;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800679 if (tl == dd->ipath_lastrcvhdrqtails[i])
680 continue;
681 hd = ipath_read_ureg32(dd, ur_rcvhdrhead,
682 i);
683 } else
684 continue;
685 if (hd == (tl + 1) ||
686 (!hd && tl == dd->ipath_hdrqlast)) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800687 if (i == 0)
688 chkerrpkts = 1;
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700689 dd->ipath_lastrcvhdrqtails[i] = tl;
690 pd->port_hdrqfull++;
Arthur Jones70c51da2007-09-14 12:22:49 -0700691 /* flush hdrqfull so that poll() sees it */
692 wmb();
693 wake_up_interruptible(&pd->port_wait);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800694 }
695 }
696 }
697 if (errs & INFINIPATH_E_RRCVEGRFULL) {
698 /*
699 * since this is of less importance and not likely to
700 * happen without also getting hdrfull, only count
701 * occurrences; don't check each port (or even the kernel
702 * vs user)
703 */
704 ipath_stats.sps_etidfull++;
705 if (dd->ipath_port0head !=
706 (u32) le64_to_cpu(*dd->ipath_hdrqtailptr))
707 chkerrpkts = 1;
708 }
709
710 /*
711 * do this before IBSTATUSCHANGED, in case both bits set in a single
712 * interrupt; we want the STATUSCHANGE to "win", so we do our
713 * internal copy of state machine correctly
714 */
715 if (errs & INFINIPATH_E_RIBLOSTLINK) {
716 /*
717 * force through block below
718 */
719 errs |= INFINIPATH_E_IBSTATUSCHANGED;
720 ipath_stats.sps_iblink++;
721 dd->ipath_flags |= IPATH_LINKDOWN;
722 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
723 | IPATH_LINKARMED | IPATH_LINKACTIVE);
724 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
725 if (!noprint) {
726 u64 st = ipath_read_kreg64(
727 dd, dd->ipath_kregs->kr_ibcstatus);
728
729 ipath_dbg("Lost link, link now down (%s)\n",
730 ipath_ibcstatus_str[st & 0xf]);
731 }
732 }
733 if (errs & INFINIPATH_E_IBSTATUSCHANGED)
734 handle_e_ibstatuschanged(dd, errs, noprint);
735
736 if (errs & INFINIPATH_E_RESET) {
737 if (!noprint)
738 ipath_dev_err(dd, "Got reset, requires re-init "
739 "(unload and reload driver)\n");
740 dd->ipath_flags &= ~IPATH_INITTED; /* needs re-init */
741 /* mark as having had error */
742 *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
743 *dd->ipath_statusp &= ~IPATH_STATUS_IB_CONF;
744 }
745
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700746 if (!noprint && *msg) {
747 if (iserr)
748 ipath_dev_err(dd, "%s error\n", msg);
749 else
750 dev_info(&dd->pcidev->dev, "%s packet problems\n",
751 msg);
752 }
Bryan O'Sullivan0fd41362006-08-25 11:24:34 -0700753 if (dd->ipath_state_wanted & dd->ipath_flags) {
754 ipath_cdbg(VERBOSE, "driver wanted state %x, iflags now %x, "
755 "waking\n", dd->ipath_state_wanted,
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800756 dd->ipath_flags);
Bryan O'Sullivan0fd41362006-08-25 11:24:34 -0700757 wake_up_interruptible(&ipath_state_wait);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800758 }
759
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700760 return chkerrpkts;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800761}
762
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700763
764/*
765 * try to cleanup as much as possible for anything that might have gone
766 * wrong while in freeze mode, such as pio buffers being written by user
767 * processes (causing armlaunch), send errors due to going into freeze mode,
768 * etc., and try to avoid causing extra interrupts while doing so.
769 * Forcibly update the in-memory pioavail register copies after cleanup
770 * because the chip won't do it for anything changing while in freeze mode
771 * (we don't want to wait for the next pio buffer state change).
772 * Make sure that we don't lose any important interrupts by using the chip
773 * feature that says that writing 0 to a bit in *clear that is set in
774 * *status will cause an interrupt to be generated again (if allowed by
775 * the *mask value).
776 */
777void ipath_clear_freeze(struct ipath_devdata *dd)
778{
779 int i, im;
780 __le64 val;
781
782 /* disable error interrupts, to avoid confusion */
783 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask, 0ULL);
784
Dave Olson78d1e022007-07-20 14:41:26 -0700785 /* also disable interrupts; errormask is sometimes overwriten */
786 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
787
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700788 /*
789 * clear all sends, because they have may been
790 * completed by usercode while in freeze mode, and
791 * therefore would not be sent, and eventually
792 * might cause the process to run out of bufs
793 */
Dave Olson3810f2a2007-07-20 14:23:37 -0700794 ipath_cancel_sends(dd, 0);
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700795 ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
796 dd->ipath_control);
797
798 /* ensure pio avail updates continue */
799 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
Dave Olson3810f2a2007-07-20 14:23:37 -0700800 dd->ipath_sendctrl & ~INFINIPATH_S_PIOBUFAVAILUPD);
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700801 ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
802 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
803 dd->ipath_sendctrl);
804
805 /*
806 * We just enabled pioavailupdate, so dma copy is almost certainly
807 * not yet right, so read the registers directly. Similar to init
808 */
809 for (i = 0; i < dd->ipath_pioavregs; i++) {
810 /* deal with 6110 chip bug */
811 im = i > 3 ? ((i&1) ? i-1 : i+1) : i;
Dave Olson78d1e022007-07-20 14:41:26 -0700812 val = ipath_read_kreg64(dd, (0x1000/sizeof(u64))+im);
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700813 dd->ipath_pioavailregs_dma[i] = dd->ipath_pioavailshadow[i]
814 = le64_to_cpu(val);
815 }
816
817 /*
818 * force new interrupt if any hwerr, error or interrupt bits are
819 * still set, and clear "safe" send packet errors related to freeze
820 * and cancelling sends. Re-enable error interrupts before possible
821 * force of re-interrupt on pending interrupts.
822 */
823 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear, 0ULL);
824 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear,
825 E_SPKT_ERRS_IGNORE);
826 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
Dave Olson78d1e022007-07-20 14:41:26 -0700827 dd->ipath_errormask);
828 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, -1LL);
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700829 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);
830}
831
832
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800833/* this is separate to allow for better optimization of ipath_intr() */
834
835static void ipath_bad_intr(struct ipath_devdata *dd, u32 * unexpectp)
836{
837 /*
838 * sometimes happen during driver init and unload, don't want
839 * to process any interrupts at that point
840 */
841
842 /* this is just a bandaid, not a fix, if something goes badly
843 * wrong */
844 if (++*unexpectp > 100) {
845 if (++*unexpectp > 105) {
846 /*
847 * ok, we must be taking somebody else's interrupts,
848 * due to a messed up mptable and/or PIRQ table, so
849 * unregister the interrupt. We've seen this during
850 * linuxbios development work, and it may happen in
851 * the future again.
852 */
Bryan O'Sullivan51f65eb2006-11-08 17:44:58 -0800853 if (dd->pcidev && dd->ipath_irq) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800854 ipath_dev_err(dd, "Now %u unexpected "
855 "interrupts, unregistering "
856 "interrupt handler\n",
857 *unexpectp);
Bryan O'Sullivan51f65eb2006-11-08 17:44:58 -0800858 ipath_dbg("free_irq of irq %d\n",
859 dd->ipath_irq);
860 dd->ipath_f_free_irq(dd);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800861 }
862 }
863 if (ipath_read_kreg32(dd, dd->ipath_kregs->kr_intmask)) {
864 ipath_dev_err(dd, "%u unexpected interrupts, "
865 "disabling interrupts completely\n",
866 *unexpectp);
867 /*
868 * disable all interrupts, something is very wrong
869 */
870 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
871 0ULL);
872 }
873 } else if (*unexpectp > 1)
874 ipath_dbg("Interrupt when not ready, should not happen, "
875 "ignoring\n");
876}
877
878static void ipath_bad_regread(struct ipath_devdata *dd)
879{
880 static int allbits;
881
882 /* separate routine, for better optimization of ipath_intr() */
883
884 /*
885 * We print the message and disable interrupts, in hope of
886 * having a better chance of debugging the problem.
887 */
888 ipath_dev_err(dd,
889 "Read of interrupt status failed (all bits set)\n");
890 if (allbits++) {
891 /* disable all interrupts, something is very wrong */
892 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
893 if (allbits == 2) {
894 ipath_dev_err(dd, "Still bad interrupt status, "
895 "unregistering interrupt\n");
Bryan O'Sullivan51f65eb2006-11-08 17:44:58 -0800896 dd->ipath_f_free_irq(dd);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800897 } else if (allbits > 2) {
898 if ((allbits % 10000) == 0)
899 printk(".");
900 } else
901 ipath_dev_err(dd, "Disabling interrupts, "
902 "multiple errors\n");
903 }
904}
905
906static void handle_port_pioavail(struct ipath_devdata *dd)
907{
908 u32 i;
909 /*
910 * start from port 1, since for now port 0 is never using
911 * wait_event for PIO
912 */
913 for (i = 1; dd->ipath_portpiowait && i < dd->ipath_cfgports; i++) {
914 struct ipath_portdata *pd = dd->ipath_pd[i];
915
916 if (pd && pd->port_cnt &&
917 dd->ipath_portpiowait & (1U << i)) {
918 clear_bit(i, &dd->ipath_portpiowait);
919 if (test_bit(IPATH_PORT_WAITING_PIO,
920 &pd->port_flag)) {
921 clear_bit(IPATH_PORT_WAITING_PIO,
922 &pd->port_flag);
923 wake_up_interruptible(&pd->port_wait);
924 }
925 }
926 }
927}
928
929static void handle_layer_pioavail(struct ipath_devdata *dd)
930{
931 int ret;
932
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -0700933 ret = ipath_ib_piobufavail(dd->verbs_dev);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800934 if (ret > 0)
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -0700935 goto set;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800936
937 return;
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -0700938set:
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800939 set_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
940 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
941 dd->ipath_sendctrl);
942}
943
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700944/*
945 * Handle receive interrupts for user ports; this means a user
946 * process was waiting for a packet to arrive, and didn't want
947 * to poll
948 */
949static void handle_urcv(struct ipath_devdata *dd, u32 istat)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800950{
951 u64 portr;
952 int i;
953 int rcvdint = 0;
954
Arthur Jones70c51da2007-09-14 12:22:49 -0700955 /* test_bit below needs this... */
956 rmb();
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800957 portr = ((istat >> INFINIPATH_I_RCVAVAIL_SHIFT) &
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -0700958 dd->ipath_i_rcvavail_mask)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800959 | ((istat >> INFINIPATH_I_RCVURG_SHIFT) &
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -0700960 dd->ipath_i_rcvurg_mask);
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700961 for (i = 1; i < dd->ipath_cfgports; i++) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800962 struct ipath_portdata *pd = dd->ipath_pd[i];
Robert Walshf2d04232007-06-18 14:24:49 -0700963 if (portr & (1 << i) && pd && pd->port_cnt) {
Arthur Jones70c51da2007-09-14 12:22:49 -0700964 if (test_and_clear_bit(IPATH_PORT_WAITING_RCV,
965 &pd->port_flag)) {
Robert Walshf2d04232007-06-18 14:24:49 -0700966 clear_bit(i + INFINIPATH_R_INTRAVAIL_SHIFT,
967 &dd->ipath_rcvctrl);
968 wake_up_interruptible(&pd->port_wait);
969 rcvdint = 1;
Arthur Jones70c51da2007-09-14 12:22:49 -0700970 } else if (test_and_clear_bit(IPATH_PORT_WAITING_URG,
971 &pd->port_flag)) {
972 pd->port_urgent++;
Robert Walshf2d04232007-06-18 14:24:49 -0700973 wake_up_interruptible(&pd->port_wait);
974 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800975 }
976 }
977 if (rcvdint) {
978 /* only want to take one interrupt, so turn off the rcv
979 * interrupt for all the ports that we did the wakeup on
980 * (but never for kernel port)
981 */
982 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
983 dd->ipath_rcvctrl);
984 }
985}
986
David Howells7d12e782006-10-05 14:55:46 +0100987irqreturn_t ipath_intr(int irq, void *data)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800988{
989 struct ipath_devdata *dd = data;
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700990 u32 istat, chk0rcv = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800991 ipath_err_t estat = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800992 irqreturn_t ret;
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700993 static unsigned unexpected = 0;
994 static const u32 port0rbits = (1U<<INFINIPATH_I_RCVAVAIL_SHIFT) |
995 (1U<<INFINIPATH_I_RCVURG_SHIFT);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800996
Bryan O'Sullivan13aef492006-07-01 04:36:04 -0700997 ipath_stats.sps_ints++;
998
Arthur Jones35884232007-07-06 12:48:53 -0700999 if (dd->ipath_int_counter != (u32) -1)
1000 dd->ipath_int_counter++;
1001
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001002 if (!(dd->ipath_flags & IPATH_PRESENT)) {
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -07001003 /*
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001004 * This return value is not great, but we do not want the
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -07001005 * interrupt core code to remove our interrupt handler
1006 * because we don't appear to be handling an interrupt
1007 * during a chip reset.
1008 */
1009 return IRQ_HANDLED;
1010 }
1011
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001012 /*
1013 * this needs to be flags&initted, not statusp, so we keep
1014 * taking interrupts even after link goes down, etc.
1015 * Also, we *must* clear the interrupt at some point, or we won't
1016 * take it again, which can be real bad for errors, etc...
1017 */
1018
1019 if (!(dd->ipath_flags & IPATH_INITTED)) {
1020 ipath_bad_intr(dd, &unexpected);
1021 ret = IRQ_NONE;
1022 goto bail;
1023 }
1024
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -07001025 istat = ipath_read_kreg32(dd, dd->ipath_kregs->kr_intstatus);
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -07001026
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001027 if (unlikely(!istat)) {
1028 ipath_stats.sps_nullintr++;
1029 ret = IRQ_NONE; /* not our interrupt, or already handled */
1030 goto bail;
1031 }
1032 if (unlikely(istat == -1)) {
1033 ipath_bad_regread(dd);
1034 /* don't know if it was our interrupt or not */
1035 ret = IRQ_NONE;
1036 goto bail;
1037 }
1038
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001039 if (unexpected)
1040 unexpected = 0;
1041
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -07001042 if (unlikely(istat & ~dd->ipath_i_bitsextant))
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001043 ipath_dev_err(dd,
1044 "interrupt with unknown interrupts %x set\n",
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -07001045 istat & (u32) ~ dd->ipath_i_bitsextant);
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001046 else
1047 ipath_cdbg(VERBOSE, "intr stat=0x%x\n", istat);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001048
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001049 if (unlikely(istat & INFINIPATH_I_ERROR)) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001050 ipath_stats.sps_errints++;
1051 estat = ipath_read_kreg64(dd,
1052 dd->ipath_kregs->kr_errorstatus);
1053 if (!estat)
1054 dev_info(&dd->pcidev->dev, "error interrupt (%x), "
1055 "but no error bits set!\n", istat);
1056 else if (estat == -1LL)
1057 /*
1058 * should we try clearing all, or hope next read
1059 * works?
1060 */
1061 ipath_dev_err(dd, "Read of error status failed "
1062 "(all bits set); ignoring\n");
1063 else
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -07001064 if (handle_errors(dd, estat))
1065 /* force calling ipath_kreceive() */
1066 chk0rcv = 1;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001067 }
1068
1069 if (istat & INFINIPATH_I_GPIO) {
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001070 /*
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001071 * GPIO interrupts fall in two broad classes:
1072 * GPIO_2 indicates (on some HT4xx boards) that a packet
1073 * has arrived for Port 0. Checking for this
1074 * is controlled by flag IPATH_GPIO_INTR.
Arthur Jones327a3382007-08-02 14:46:29 -07001075 * GPIO_3..5 on IBA6120 Rev2 and IBA6110 Rev4 chips indicate
1076 * errors that we need to count. Checking for this
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001077 * is controlled by flag IPATH_GPIO_ERRINTRS.
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001078 */
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001079 u32 gpiostatus;
1080 u32 to_clear = 0;
1081
1082 gpiostatus = ipath_read_kreg32(
1083 dd, dd->ipath_kregs->kr_gpio_status);
1084 /* First the error-counter case.
1085 */
1086 if ((gpiostatus & IPATH_GPIO_ERRINTR_MASK) &&
1087 (dd->ipath_flags & IPATH_GPIO_ERRINTRS)) {
1088 /* want to clear the bits we see asserted. */
1089 to_clear |= (gpiostatus & IPATH_GPIO_ERRINTR_MASK);
1090
1091 /*
1092 * Count appropriately, clear bits out of our copy,
1093 * as they have been "handled".
1094 */
1095 if (gpiostatus & (1 << IPATH_GPIO_RXUVL_BIT)) {
1096 ipath_dbg("FlowCtl on UnsupVL\n");
1097 dd->ipath_rxfc_unsupvl_errs++;
1098 }
1099 if (gpiostatus & (1 << IPATH_GPIO_OVRUN_BIT)) {
1100 ipath_dbg("Overrun Threshold exceeded\n");
1101 dd->ipath_overrun_thresh_errs++;
1102 }
1103 if (gpiostatus & (1 << IPATH_GPIO_LLI_BIT)) {
1104 ipath_dbg("Local Link Integrity error\n");
1105 dd->ipath_lli_errs++;
1106 }
1107 gpiostatus &= ~IPATH_GPIO_ERRINTR_MASK;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001108 }
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001109 /* Now the Port0 Receive case */
1110 if ((gpiostatus & (1 << IPATH_GPIO_PORT0_BIT)) &&
1111 (dd->ipath_flags & IPATH_GPIO_INTR)) {
1112 /*
1113 * GPIO status bit 2 is set, and we expected it.
1114 * clear it and indicate in p0bits.
1115 * This probably only happens if a Port0 pkt
1116 * arrives at _just_ the wrong time, and we
1117 * handle that by seting chk0rcv;
1118 */
1119 to_clear |= (1 << IPATH_GPIO_PORT0_BIT);
1120 gpiostatus &= ~(1 << IPATH_GPIO_PORT0_BIT);
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -07001121 chk0rcv = 1;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001122 }
Arthur Jones8f140b42007-05-10 12:10:49 -07001123 if (gpiostatus) {
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001124 /*
1125 * Some unexpected bits remain. If they could have
1126 * caused the interrupt, complain and clear.
Michael Albaugh6a733cd2007-10-03 10:47:38 -07001127 * To avoid repetition of this condition, also clear
1128 * the mask. It is almost certainly due to error.
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001129 */
Arthur Jones8f140b42007-05-10 12:10:49 -07001130 const u32 mask = (u32) dd->ipath_gpio_mask;
1131
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001132 if (mask & gpiostatus) {
1133 ipath_dbg("Unexpected GPIO IRQ bits %x\n",
1134 gpiostatus & mask);
1135 to_clear |= (gpiostatus & mask);
Michael Albaugh6a733cd2007-10-03 10:47:38 -07001136 dd->ipath_gpio_mask &= ~(gpiostatus & mask);
1137 ipath_write_kreg(dd,
1138 dd->ipath_kregs->kr_gpio_mask,
1139 dd->ipath_gpio_mask);
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001140 }
1141 }
1142 if (to_clear) {
1143 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
1144 (u64) to_clear);
1145 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001146 }
Bryan O'Sullivan57abad22006-07-01 04:36:05 -07001147 chk0rcv |= istat & port0rbits;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001148
1149 /*
Bryan O'Sullivan57abad22006-07-01 04:36:05 -07001150 * Clear the interrupt bits we found set, unless they are receive
1151 * related, in which case we already cleared them above, and don't
1152 * want to clear them again, because we might lose an interrupt.
1153 * Clear it early, so we "know" know the chip will have seen this by
1154 * the time we process the queue, and will re-interrupt if necessary.
1155 * The processor itself won't take the interrupt again until we return.
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001156 */
1157 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, istat);
1158
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001159 /*
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -07001160 * handle port0 receive before checking for pio buffers available,
1161 * since receives can overflow; piobuf waiters can afford a few
1162 * extra cycles, since they were waiting anyway, and user's waiting
1163 * for receive are at the bottom.
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001164 */
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -07001165 if (chk0rcv) {
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001166 ipath_kreceive(dd);
1167 istat &= ~port0rbits;
1168 }
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -07001169
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -07001170 if (istat & ((dd->ipath_i_rcvavail_mask <<
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001171 INFINIPATH_I_RCVAVAIL_SHIFT)
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -07001172 | (dd->ipath_i_rcvurg_mask <<
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001173 INFINIPATH_I_RCVURG_SHIFT)))
1174 handle_urcv(dd, istat);
1175
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001176 if (istat & INFINIPATH_I_SPIOBUFAVAIL) {
1177 clear_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
1178 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
1179 dd->ipath_sendctrl);
1180
1181 if (dd->ipath_portpiowait)
1182 handle_port_pioavail(dd);
1183
1184 handle_layer_pioavail(dd);
1185 }
1186
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001187 ret = IRQ_HANDLED;
1188
1189bail:
1190 return ret;
1191}