blob: 26900b3b7a4ee1bcef2fe064a1a8148900128fae [file] [log] [blame]
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001/*
Ralph Campbelle7eacd32008-04-16 21:09:32 -07002 * Copyright (c) 2006, 2007, 2008 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>
John Gregor58411d12008-04-16 21:09:24 -070035#include <linux/delay.h>
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -080036
37#include "ipath_kernel.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'Sullivan9783ab42007-03-15 14:45:07 -070041
42/*
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070043 * Called when we might have an error that is specific to a particular
44 * PIO buffer, and may need to cancel that buffer, so it can be re-used.
45 */
Dave Olsone2ab41c2008-05-07 11:00:15 -070046void ipath_disarm_senderrbufs(struct ipath_devdata *dd)
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070047{
48 u32 piobcnt;
49 unsigned long sbuf[4];
50 /*
51 * it's possible that sendbuffererror could have bits set; might
52 * have already done this as a result of hardware error handling
53 */
54 piobcnt = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
55 /* read these before writing errorclear */
56 sbuf[0] = ipath_read_kreg64(
57 dd, dd->ipath_kregs->kr_sendbuffererror);
58 sbuf[1] = ipath_read_kreg64(
59 dd, dd->ipath_kregs->kr_sendbuffererror + 1);
Arthur Jonesbb917142008-04-16 21:09:31 -070060 if (piobcnt > 128)
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070061 sbuf[2] = ipath_read_kreg64(
62 dd, dd->ipath_kregs->kr_sendbuffererror + 2);
Arthur Jonesbb917142008-04-16 21:09:31 -070063 if (piobcnt > 192)
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070064 sbuf[3] = ipath_read_kreg64(
65 dd, dd->ipath_kregs->kr_sendbuffererror + 3);
Arthur Jonesbb917142008-04-16 21:09:31 -070066 else
67 sbuf[3] = 0;
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070068
69 if (sbuf[0] || sbuf[1] || (piobcnt > 128 && (sbuf[2] || sbuf[3]))) {
70 int i;
Dave Olson93800682007-06-18 14:24:41 -070071 if (ipath_debug & (__IPATH_PKTDBG|__IPATH_DBG) &&
72 dd->ipath_lastcancel > jiffies) {
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070073 __IPATH_DBG_WHICH(__IPATH_PKTDBG|__IPATH_DBG,
74 "SendbufErrs %lx %lx", sbuf[0],
75 sbuf[1]);
76 if (ipath_debug & __IPATH_PKTDBG && piobcnt > 128)
77 printk(" %lx %lx ", sbuf[2], sbuf[3]);
78 printk("\n");
79 }
80
81 for (i = 0; i < piobcnt; i++)
Dave Olsone2ab41c2008-05-07 11:00:15 -070082 if (test_bit(i, sbuf))
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070083 ipath_disarm_piobufs(dd, i, 1);
Dave Olson93800682007-06-18 14:24:41 -070084 /* ignore armlaunch errs for a bit */
85 dd->ipath_lastcancel = jiffies+3;
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -070086 }
87}
88
89
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -070090/* These are all rcv-related errors which we want to count for stats */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -080091#define E_SUM_PKTERRS \
92 (INFINIPATH_E_RHDRLEN | INFINIPATH_E_RBADTID | \
93 INFINIPATH_E_RBADVERSION | INFINIPATH_E_RHDR | \
94 INFINIPATH_E_RLONGPKTLEN | INFINIPATH_E_RSHORTPKTLEN | \
95 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RMINPKTLEN | \
96 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RUNSUPVL | \
97 INFINIPATH_E_RUNEXPCHAR | INFINIPATH_E_REBP)
98
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -070099/* These are all send-related errors which we want to count for stats */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800100#define E_SUM_ERRS \
101 (INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM | \
102 INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
103 INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SUNSUPVL | \
104 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
105 INFINIPATH_E_INVALIDADDR)
106
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700107/*
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700108 * this is similar to E_SUM_ERRS, but can't ignore armlaunch, don't ignore
109 * errors not related to freeze and cancelling buffers. Can't ignore
110 * armlaunch because could get more while still cleaning up, and need
111 * to cancel those as they happen.
112 */
113#define E_SPKT_ERRS_IGNORE \
114 (INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
115 INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SMINPKTLEN | \
116 INFINIPATH_E_SPKTLEN)
117
118/*
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700119 * these are errors that can occur when the link changes state while
120 * a packet is being sent or received. This doesn't cover things
121 * like EBP or VCRC that can be the result of a sending having the
122 * link change state, so we receive a "known bad" packet.
123 */
124#define E_SUM_LINK_PKTERRS \
125 (INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
126 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
127 INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RMINPKTLEN | \
128 INFINIPATH_E_RUNEXPCHAR)
129
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800130static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs)
131{
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800132 u64 ignore_this_time = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800133
Dave Olsone2ab41c2008-05-07 11:00:15 -0700134 ipath_disarm_senderrbufs(dd);
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700135 if ((errs & E_SUM_LINK_PKTERRS) &&
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800136 !(dd->ipath_flags & IPATH_LINKACTIVE)) {
137 /*
138 * This can happen when SMA is trying to bring the link
139 * up, but the IB link changes state at the "wrong" time.
140 * The IB logic then complains that the packet isn't
141 * valid. We don't want to confuse people, so we just
142 * don't print them, except at debug
143 */
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700144 ipath_dbg("Ignoring packet errors %llx, because link not "
145 "ACTIVE\n", (unsigned long long) errs);
146 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800147 }
148
149 return ignore_this_time;
150}
151
Bryan O'Sullivan8d588f82006-09-28 09:00:08 -0700152/* generic hw error messages... */
153#define INFINIPATH_HWE_TXEMEMPARITYERR_MSG(a) \
154 { \
155 .mask = ( INFINIPATH_HWE_TXEMEMPARITYERR_##a << \
156 INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT ), \
157 .msg = "TXE " #a " Memory Parity" \
158 }
159#define INFINIPATH_HWE_RXEMEMPARITYERR_MSG(a) \
160 { \
161 .mask = ( INFINIPATH_HWE_RXEMEMPARITYERR_##a << \
162 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT ), \
163 .msg = "RXE " #a " Memory Parity" \
164 }
165
166static const struct ipath_hwerror_msgs ipath_generic_hwerror_msgs[] = {
167 INFINIPATH_HWE_MSG(IBCBUSFRSPCPARITYERR, "IPATH2IB Parity"),
168 INFINIPATH_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2IPATH Parity"),
169
170 INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOBUF),
171 INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOPBC),
172 INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOLAUNCHFIFO),
173
174 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(RCVBUF),
175 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(LOOKUPQ),
176 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EAGERTID),
177 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EXPTID),
178 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(FLAGBUF),
179 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(DATAINFO),
180 INFINIPATH_HWE_RXEMEMPARITYERR_MSG(HDRINFO),
181};
182
183/**
184 * ipath_format_hwmsg - format a single hwerror message
185 * @msg message buffer
186 * @msgl length of message buffer
187 * @hwmsg message to add to message buffer
188 */
189static void ipath_format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
190{
191 strlcat(msg, "[", msgl);
192 strlcat(msg, hwmsg, msgl);
193 strlcat(msg, "]", msgl);
194}
195
196/**
197 * ipath_format_hwerrors - format hardware error messages for display
198 * @hwerrs hardware errors bit vector
199 * @hwerrmsgs hardware error descriptions
200 * @nhwerrmsgs number of hwerrmsgs
201 * @msg message buffer
202 * @msgl message buffer length
203 */
204void ipath_format_hwerrors(u64 hwerrs,
205 const struct ipath_hwerror_msgs *hwerrmsgs,
206 size_t nhwerrmsgs,
207 char *msg, size_t msgl)
208{
209 int i;
210 const int glen =
211 sizeof(ipath_generic_hwerror_msgs) /
212 sizeof(ipath_generic_hwerror_msgs[0]);
213
214 for (i=0; i<glen; i++) {
215 if (hwerrs & ipath_generic_hwerror_msgs[i].mask) {
216 ipath_format_hwmsg(msg, msgl,
217 ipath_generic_hwerror_msgs[i].msg);
218 }
219 }
220
221 for (i=0; i<nhwerrmsgs; i++) {
222 if (hwerrs & hwerrmsgs[i].mask) {
223 ipath_format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
224 }
225 }
226}
227
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800228/* return the strings for the most common link states */
John Gregor58411d12008-04-16 21:09:24 -0700229static char *ib_linkstate(struct ipath_devdata *dd, u64 ibcs)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800230{
231 char *ret;
John Gregor58411d12008-04-16 21:09:24 -0700232 u32 state;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800233
John Gregor58411d12008-04-16 21:09:24 -0700234 state = ipath_ib_state(dd, ibcs);
235 if (state == dd->ib_init)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800236 ret = "Init";
John Gregor58411d12008-04-16 21:09:24 -0700237 else if (state == dd->ib_arm)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800238 ret = "Arm";
John Gregor58411d12008-04-16 21:09:24 -0700239 else if (state == dd->ib_active)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800240 ret = "Active";
John Gregor58411d12008-04-16 21:09:24 -0700241 else
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800242 ret = "Down";
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800243 return ret;
244}
245
Ralph Campbell49739b32007-09-19 16:47:31 -0700246void signal_ib_event(struct ipath_devdata *dd, enum ib_event_type ev)
247{
248 struct ib_event event;
249
250 event.device = &dd->verbs_dev->ibdev;
251 event.element.port_num = 1;
252 event.event = ev;
253 ib_dispatch_event(&event);
254}
255
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800256static void handle_e_ibstatuschanged(struct ipath_devdata *dd,
John Gregor58411d12008-04-16 21:09:24 -0700257 ipath_err_t errs)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800258{
John Gregor58411d12008-04-16 21:09:24 -0700259 u32 ltstate, lstate, ibstate, lastlstate;
260 u32 init = dd->ib_init;
261 u32 arm = dd->ib_arm;
262 u32 active = dd->ib_active;
263 const u64 ibcs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
264
265 lstate = ipath_ib_linkstate(dd, ibcs); /* linkstate */
266 ibstate = ipath_ib_state(dd, ibcs);
267 /* linkstate at last interrupt */
268 lastlstate = ipath_ib_linkstate(dd, dd->ipath_lastibcstat);
269 ltstate = ipath_ib_linktrstate(dd, ibcs); /* linktrainingtate */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800270
271 /*
Dave Olson555b2032008-04-16 21:09:29 -0700272 * Since going into a recovery state causes the link state to go
273 * down and since recovery is transitory, it is better if we "miss"
274 * ever seeing the link training state go into recovery (i.e.,
275 * ignore this transition for link state special handling purposes)
276 * without even updating ipath_lastibcstat.
277 */
278 if ((ltstate == INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN) ||
279 (ltstate == INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT) ||
280 (ltstate == INFINIPATH_IBCS_LT_STATE_RECOVERIDLE))
281 goto done;
282
283 /*
John Gregor58411d12008-04-16 21:09:24 -0700284 * if linkstate transitions into INIT from any of the various down
285 * states, or if it transitions from any of the up (INIT or better)
286 * states into any of the down states (except link recovery), then
287 * call the chip-specific code to take appropriate actions.
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800288 */
John Gregor58411d12008-04-16 21:09:24 -0700289 if (lstate >= INFINIPATH_IBCS_L_STATE_INIT &&
290 lastlstate == INFINIPATH_IBCS_L_STATE_DOWN) {
291 /* transitioned to UP */
292 if (dd->ipath_f_ib_updown(dd, 1, ibcs)) {
Michael Albaugh4330e4d2008-04-16 21:09:26 -0700293 /* link came up, so we must no longer be disabled */
294 dd->ipath_flags &= ~IPATH_IB_LINK_DISABLED;
John Gregor58411d12008-04-16 21:09:24 -0700295 ipath_cdbg(LINKVERB, "LinkUp handled, skipped\n");
296 goto skip_ibchange; /* chip-code handled */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800297 }
John Gregor58411d12008-04-16 21:09:24 -0700298 } else if ((lastlstate >= INFINIPATH_IBCS_L_STATE_INIT ||
299 (dd->ipath_flags & IPATH_IB_FORCE_NOTIFY)) &&
Dave Olson555b2032008-04-16 21:09:29 -0700300 ltstate <= INFINIPATH_IBCS_LT_STATE_CFGWAITRMT &&
John Gregor58411d12008-04-16 21:09:24 -0700301 ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP) {
302 int handled;
303 handled = dd->ipath_f_ib_updown(dd, 0, ibcs);
304 dd->ipath_flags &= ~IPATH_IB_FORCE_NOTIFY;
305 if (handled) {
306 ipath_cdbg(LINKVERB, "LinkDown handled, skipped\n");
307 goto skip_ibchange; /* chip-code handled */
308 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800309 }
John Gregor58411d12008-04-16 21:09:24 -0700310
311 /*
312 * Significant enough to always print and get into logs, if it was
313 * unexpected. If it was a requested state change, we'll have
314 * already cleared the flags, so we won't print this warning
315 */
316 if ((ibstate != arm && ibstate != active) &&
317 (dd->ipath_flags & (IPATH_LINKARMED | IPATH_LINKACTIVE))) {
318 dev_info(&dd->pcidev->dev, "Link state changed from %s "
319 "to %s\n", (dd->ipath_flags & IPATH_LINKARMED) ?
320 "ARM" : "ACTIVE", ib_linkstate(dd, ibcs));
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800321 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800322
323 if (ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE ||
324 ltstate == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
John Gregor58411d12008-04-16 21:09:24 -0700325 u32 lastlts;
326 lastlts = ipath_ib_linktrstate(dd, dd->ipath_lastibcstat);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800327 /*
John Gregor58411d12008-04-16 21:09:24 -0700328 * Ignore cycling back and forth from Polling.Active to
329 * Polling.Quiet while waiting for the other end of the link
330 * to come up, except to try and decide if we are connected
331 * to a live IB device or not. We will cycle back and
332 * forth between them if no cable is plugged in, the other
333 * device is powered off or disabled, etc.
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800334 */
John Gregor58411d12008-04-16 21:09:24 -0700335 if (lastlts == INFINIPATH_IBCS_LT_STATE_POLLACTIVE ||
336 lastlts == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
Arthur Jonesbb917142008-04-16 21:09:31 -0700337 if (!(dd->ipath_flags & IPATH_IB_AUTONEG_INPROG) &&
338 (++dd->ipath_ibpollcnt == 40)) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800339 dd->ipath_flags |= IPATH_NOCABLE;
340 *dd->ipath_statusp |=
341 IPATH_STATUS_IB_NOCABLE;
John Gregor58411d12008-04-16 21:09:24 -0700342 ipath_cdbg(LINKVERB, "Set NOCABLE\n");
343 }
344 ipath_cdbg(LINKVERB, "POLL change to %s (%x)\n",
345 ipath_ibcstatus_str[ltstate], ibstate);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800346 goto skip_ibchange;
347 }
348 }
John Gregor58411d12008-04-16 21:09:24 -0700349
350 dd->ipath_ibpollcnt = 0; /* not poll*, now */
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800351 ipath_stats.sps_iblink++;
John Gregor58411d12008-04-16 21:09:24 -0700352
Dave Olson72708a02008-04-16 21:09:25 -0700353 if (ibstate != init && dd->ipath_lastlinkrecov && ipath_linkrecovery) {
354 u64 linkrecov;
355 linkrecov = ipath_snap_cntr(dd,
356 dd->ipath_cregs->cr_iblinkerrrecovcnt);
357 if (linkrecov != dd->ipath_lastlinkrecov) {
358 ipath_dbg("IB linkrecov up %Lx (%s %s) recov %Lu\n",
359 ibcs, ib_linkstate(dd, ibcs),
360 ipath_ibcstatus_str[ltstate],
361 linkrecov);
362 /* and no more until active again */
363 dd->ipath_lastlinkrecov = 0;
364 ipath_set_linkstate(dd, IPATH_IB_LINKDOWN);
365 goto skip_ibchange;
366 }
367 }
368
John Gregor58411d12008-04-16 21:09:24 -0700369 if (ibstate == init || ibstate == arm || ibstate == active) {
370 *dd->ipath_statusp &= ~IPATH_STATUS_IB_NOCABLE;
371 if (ibstate == init || ibstate == arm) {
372 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
373 if (dd->ipath_flags & IPATH_LINKACTIVE)
374 signal_ib_event(dd, IB_EVENT_PORT_ERR);
375 }
376 if (ibstate == arm) {
377 dd->ipath_flags |= IPATH_LINKARMED;
378 dd->ipath_flags &= ~(IPATH_LINKUNK |
379 IPATH_LINKINIT | IPATH_LINKDOWN |
380 IPATH_LINKACTIVE | IPATH_NOCABLE);
381 ipath_hol_down(dd);
382 } else if (ibstate == init) {
383 /*
384 * set INIT and DOWN. Down is checked by
385 * most of the other code, but INIT is
386 * useful to know in a few places.
387 */
388 dd->ipath_flags |= IPATH_LINKINIT |
389 IPATH_LINKDOWN;
390 dd->ipath_flags &= ~(IPATH_LINKUNK |
391 IPATH_LINKARMED | IPATH_LINKACTIVE |
392 IPATH_NOCABLE);
393 ipath_hol_down(dd);
394 } else { /* active */
Dave Olson72708a02008-04-16 21:09:25 -0700395 dd->ipath_lastlinkrecov = ipath_snap_cntr(dd,
396 dd->ipath_cregs->cr_iblinkerrrecovcnt);
John Gregor58411d12008-04-16 21:09:24 -0700397 *dd->ipath_statusp |=
398 IPATH_STATUS_IB_READY | IPATH_STATUS_IB_CONF;
399 dd->ipath_flags |= IPATH_LINKACTIVE;
400 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
401 | IPATH_LINKDOWN | IPATH_LINKARMED |
402 IPATH_NOCABLE);
Dave Olson124b4dc2008-04-16 21:09:32 -0700403 if (dd->ipath_flags & IPATH_HAS_SEND_DMA)
404 ipath_restart_sdma(dd);
John Gregor58411d12008-04-16 21:09:24 -0700405 signal_ib_event(dd, IB_EVENT_PORT_ACTIVE);
406 /* LED active not handled in chip _f_updown */
407 dd->ipath_f_setextled(dd, lstate, ltstate);
408 ipath_hol_up(dd);
409 }
410
411 /*
412 * print after we've already done the work, so as not to
413 * delay the state changes and notifications, for debugging
414 */
415 if (lstate == lastlstate)
416 ipath_cdbg(LINKVERB, "Unchanged from last: %s "
417 "(%x)\n", ib_linkstate(dd, ibcs), ibstate);
418 else
419 ipath_cdbg(VERBOSE, "Unit %u: link up to %s %s (%x)\n",
420 dd->ipath_unit, ib_linkstate(dd, ibcs),
421 ipath_ibcstatus_str[ltstate], ibstate);
422 } else { /* down */
Ralph Campbell49739b32007-09-19 16:47:31 -0700423 if (dd->ipath_flags & IPATH_LINKACTIVE)
424 signal_ib_event(dd, IB_EVENT_PORT_ERR);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800425 dd->ipath_flags |= IPATH_LINKDOWN;
426 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
427 | IPATH_LINKACTIVE |
428 IPATH_LINKARMED);
429 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
Bryan O'Sullivanfba75202006-07-01 04:36:09 -0700430 dd->ipath_lli_counter = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800431
John Gregor58411d12008-04-16 21:09:24 -0700432 if (lastlstate != INFINIPATH_IBCS_L_STATE_DOWN)
433 ipath_cdbg(VERBOSE, "Unit %u link state down "
434 "(state 0x%x), from %s\n",
435 dd->ipath_unit, lstate,
436 ib_linkstate(dd, dd->ipath_lastibcstat));
437 else
438 ipath_cdbg(LINKVERB, "Unit %u link state changed "
439 "to %s (0x%x) from down (%x)\n",
440 dd->ipath_unit,
441 ipath_ibcstatus_str[ltstate],
442 ibstate, lastlstate);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800443 }
John Gregor58411d12008-04-16 21:09:24 -0700444
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800445skip_ibchange:
John Gregor58411d12008-04-16 21:09:24 -0700446 dd->ipath_lastibcstat = ibcs;
Dave Olson555b2032008-04-16 21:09:29 -0700447done:
448 return;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800449}
450
451static void handle_supp_msgs(struct ipath_devdata *dd,
Dave Olson124b4dc2008-04-16 21:09:32 -0700452 unsigned supp_msgs, char *msg, u32 msgsz)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800453{
454 /*
455 * Print the message unless it's ibc status change only, which
456 * happens so often we never want to count it.
457 */
458 if (dd->ipath_lasterror & ~INFINIPATH_E_IBSTATUSCHANGED) {
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700459 int iserr;
Dave Olson124b4dc2008-04-16 21:09:32 -0700460 ipath_err_t mask;
461 iserr = ipath_decode_err(dd, msg, msgsz,
Dave Olson164ef7a2007-10-09 22:24:36 -0700462 dd->ipath_lasterror &
463 ~INFINIPATH_E_IBSTATUSCHANGED);
Dave Olson124b4dc2008-04-16 21:09:32 -0700464
465 mask = INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
466 INFINIPATH_E_PKTERRS | INFINIPATH_E_SDMADISABLED;
467
468 /* if we're in debug, then don't mask SDMADISABLED msgs */
469 if (ipath_debug & __IPATH_DBG)
470 mask &= ~INFINIPATH_E_SDMADISABLED;
471
472 if (dd->ipath_lasterror & ~mask)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800473 ipath_dev_err(dd, "Suppressed %u messages for "
474 "fast-repeating errors (%s) (%llx)\n",
475 supp_msgs, msg,
476 (unsigned long long)
477 dd->ipath_lasterror);
478 else {
479 /*
480 * rcvegrfull and rcvhdrqfull are "normal", for some
481 * types of processes (mostly benchmarks) that send
482 * huge numbers of messages, while not processing
483 * them. So only complain about these at debug
484 * level.
485 */
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700486 if (iserr)
487 ipath_dbg("Suppressed %u messages for %s\n",
488 supp_msgs, msg);
489 else
490 ipath_cdbg(ERRPKT,
491 "Suppressed %u messages for %s\n",
492 supp_msgs, msg);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800493 }
494 }
495}
496
497static unsigned handle_frequent_errors(struct ipath_devdata *dd,
Dave Olson164ef7a2007-10-09 22:24:36 -0700498 ipath_err_t errs, char *msg,
Dave Olson124b4dc2008-04-16 21:09:32 -0700499 u32 msgsz, int *noprint)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800500{
501 unsigned long nc;
502 static unsigned long nextmsg_time;
503 static unsigned nmsgs, supp_msgs;
504
505 /*
506 * Throttle back "fast" messages to no more than 10 per 5 seconds.
507 * This isn't perfect, but it's a reasonable heuristic. If we get
508 * more than 10, give a 6x longer delay.
509 */
510 nc = jiffies;
511 if (nmsgs > 10) {
512 if (time_before(nc, nextmsg_time)) {
513 *noprint = 1;
514 if (!supp_msgs++)
515 nextmsg_time = nc + HZ * 3;
516 }
517 else if (supp_msgs) {
Dave Olson164ef7a2007-10-09 22:24:36 -0700518 handle_supp_msgs(dd, supp_msgs, msg, msgsz);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800519 supp_msgs = 0;
520 nmsgs = 0;
521 }
522 }
523 else if (!nmsgs++ || time_after(nc, nextmsg_time))
524 nextmsg_time = nc + HZ / 2;
525
526 return supp_msgs;
527}
528
Dave Olson124b4dc2008-04-16 21:09:32 -0700529static void handle_sdma_errors(struct ipath_devdata *dd, ipath_err_t errs)
530{
531 unsigned long flags;
532 int expected;
533
534 if (ipath_debug & __IPATH_DBG) {
535 char msg[128];
536 ipath_decode_err(dd, msg, sizeof msg, errs &
537 INFINIPATH_E_SDMAERRS);
538 ipath_dbg("errors %lx (%s)\n", (unsigned long)errs, msg);
539 }
540 if (ipath_debug & __IPATH_VERBDBG) {
541 unsigned long tl, hd, status, lengen;
542 tl = ipath_read_kreg64(dd, dd->ipath_kregs->kr_senddmatail);
543 hd = ipath_read_kreg64(dd, dd->ipath_kregs->kr_senddmahead);
544 status = ipath_read_kreg64(dd
545 , dd->ipath_kregs->kr_senddmastatus);
546 lengen = ipath_read_kreg64(dd,
547 dd->ipath_kregs->kr_senddmalengen);
548 ipath_cdbg(VERBOSE, "sdma tl 0x%lx hd 0x%lx status 0x%lx "
549 "lengen 0x%lx\n", tl, hd, status, lengen);
550 }
551
552 spin_lock_irqsave(&dd->ipath_sdma_lock, flags);
553 __set_bit(IPATH_SDMA_DISABLED, &dd->ipath_sdma_status);
554 expected = test_bit(IPATH_SDMA_ABORTING, &dd->ipath_sdma_status);
555 spin_unlock_irqrestore(&dd->ipath_sdma_lock, flags);
556 if (!expected)
557 ipath_cancel_sends(dd, 1);
558}
559
560static void handle_sdma_intr(struct ipath_devdata *dd, u64 istat)
561{
562 unsigned long flags;
563 int expected;
564
565 if ((istat & INFINIPATH_I_SDMAINT) &&
566 !test_bit(IPATH_SDMA_SHUTDOWN, &dd->ipath_sdma_status))
567 ipath_sdma_intr(dd);
568
569 if (istat & INFINIPATH_I_SDMADISABLED) {
570 expected = test_bit(IPATH_SDMA_ABORTING,
571 &dd->ipath_sdma_status);
572 ipath_dbg("%s SDmaDisabled intr\n",
573 expected ? "expected" : "unexpected");
574 spin_lock_irqsave(&dd->ipath_sdma_lock, flags);
575 __set_bit(IPATH_SDMA_DISABLED, &dd->ipath_sdma_status);
576 spin_unlock_irqrestore(&dd->ipath_sdma_lock, flags);
577 if (!expected)
578 ipath_cancel_sends(dd, 1);
579 if (!test_bit(IPATH_SDMA_SHUTDOWN, &dd->ipath_sdma_status))
580 tasklet_hi_schedule(&dd->ipath_sdma_abort_task);
581 }
582}
583
584static int handle_hdrq_full(struct ipath_devdata *dd)
585{
586 int chkerrpkts = 0;
587 u32 hd, tl;
588 u32 i;
589
590 ipath_stats.sps_hdrqfull++;
591 for (i = 0; i < dd->ipath_cfgports; i++) {
592 struct ipath_portdata *pd = dd->ipath_pd[i];
593
594 if (i == 0) {
595 /*
596 * For kernel receive queues, we just want to know
597 * if there are packets in the queue that we can
598 * process.
599 */
600 if (pd->port_head != ipath_get_hdrqtail(pd))
601 chkerrpkts |= 1 << i;
602 continue;
603 }
604
605 /* Skip if user context is not open */
606 if (!pd || !pd->port_cnt)
607 continue;
608
609 /* Don't report the same point multiple times. */
610 if (dd->ipath_flags & IPATH_NODMA_RTAIL)
611 tl = ipath_read_ureg32(dd, ur_rcvhdrtail, i);
612 else
613 tl = ipath_get_rcvhdrtail(pd);
614 if (tl == pd->port_lastrcvhdrqtail)
615 continue;
616
617 hd = ipath_read_ureg32(dd, ur_rcvhdrhead, i);
618 if (hd == (tl + 1) || (!hd && tl == dd->ipath_hdrqlast)) {
619 pd->port_lastrcvhdrqtail = tl;
620 pd->port_hdrqfull++;
621 /* flush hdrqfull so that poll() sees it */
622 wmb();
623 wake_up_interruptible(&pd->port_wait);
624 }
625 }
626
627 return chkerrpkts;
628}
629
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700630static int handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800631{
Dave Olson164ef7a2007-10-09 22:24:36 -0700632 char msg[128];
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800633 u64 ignore_this_time = 0;
Dave Olson124b4dc2008-04-16 21:09:32 -0700634 u64 iserr = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800635 int chkerrpkts = 0, noprint = 0;
636 unsigned supp_msgs;
Michael Albaughaecd3b52007-05-17 07:26:28 -0700637 int log_idx;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800638
Dave Olson124b4dc2008-04-16 21:09:32 -0700639 /*
640 * don't report errors that are masked, either at init
641 * (not set in ipath_errormask), or temporarily (set in
642 * ipath_maskederrs)
643 */
644 errs &= dd->ipath_errormask & ~dd->ipath_maskederrs;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800645
Dave Olson124b4dc2008-04-16 21:09:32 -0700646 supp_msgs = handle_frequent_errors(dd, errs, msg, (u32)sizeof msg,
647 &noprint);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800648
649 /* do these first, they are most important */
650 if (errs & INFINIPATH_E_HARDWARE) {
651 /* reuse same msg buf */
652 dd->ipath_f_handle_hwerrors(dd, msg, sizeof msg);
Michael Albaughaecd3b52007-05-17 07:26:28 -0700653 } else {
654 u64 mask;
655 for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx) {
656 mask = dd->ipath_eep_st_masks[log_idx].errs_to_log;
657 if (errs & mask)
658 ipath_inc_eeprom_err(dd, log_idx, 1);
659 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800660 }
661
Dave Olson124b4dc2008-04-16 21:09:32 -0700662 if (errs & INFINIPATH_E_SDMAERRS)
663 handle_sdma_errors(dd, errs);
664
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -0700665 if (!noprint && (errs & ~dd->ipath_e_bitsextant))
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800666 ipath_dev_err(dd, "error interrupt with unknown errors "
667 "%llx set\n", (unsigned long long)
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -0700668 (errs & ~dd->ipath_e_bitsextant));
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800669
670 if (errs & E_SUM_ERRS)
671 ignore_this_time = handle_e_sum_errs(dd, errs);
Bryan O'Sullivanf37bda92006-07-01 04:36:03 -0700672 else if ((errs & E_SUM_LINK_PKTERRS) &&
673 !(dd->ipath_flags & IPATH_LINKACTIVE)) {
674 /*
675 * This can happen when SMA is trying to bring the link
676 * up, but the IB link changes state at the "wrong" time.
677 * The IB logic then complains that the packet isn't
678 * valid. We don't want to confuse people, so we just
679 * don't print them, except at debug
680 */
681 ipath_dbg("Ignoring packet errors %llx, because link not "
682 "ACTIVE\n", (unsigned long long) errs);
683 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
684 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800685
686 if (supp_msgs == 250000) {
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700687 int s_iserr;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800688 /*
689 * It's not entirely reasonable assuming that the errors set
690 * in the last clear period are all responsible for the
691 * problem, but the alternative is to assume it's the only
692 * ones on this particular interrupt, which also isn't great
693 */
694 dd->ipath_maskederrs |= dd->ipath_lasterror | errs;
Ralph Campbell2ba3f562008-04-16 21:09:29 -0700695
Dave Olson78d1e022007-07-20 14:41:26 -0700696 dd->ipath_errormask &= ~dd->ipath_maskederrs;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800697 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
Ralph Campbell2ba3f562008-04-16 21:09:29 -0700698 dd->ipath_errormask);
Dave Olson124b4dc2008-04-16 21:09:32 -0700699 s_iserr = ipath_decode_err(dd, msg, sizeof msg,
Ralph Campbell2ba3f562008-04-16 21:09:29 -0700700 dd->ipath_maskederrs);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800701
Dave Olson78d1e022007-07-20 14:41:26 -0700702 if (dd->ipath_maskederrs &
Ralph Campbell2ba3f562008-04-16 21:09:29 -0700703 ~(INFINIPATH_E_RRCVEGRFULL |
704 INFINIPATH_E_RRCVHDRFULL | INFINIPATH_E_PKTERRS))
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700705 ipath_dev_err(dd, "Temporarily disabling "
706 "error(s) %llx reporting; too frequent (%s)\n",
Ralph Campbell2ba3f562008-04-16 21:09:29 -0700707 (unsigned long long) dd->ipath_maskederrs,
Dave Olson78d1e022007-07-20 14:41:26 -0700708 msg);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800709 else {
710 /*
711 * rcvegrfull and rcvhdrqfull are "normal",
712 * for some types of processes (mostly benchmarks)
713 * that send huge numbers of messages, while not
714 * processing them. So only complain about
715 * these at debug level.
716 */
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700717 if (s_iserr)
718 ipath_dbg("Temporarily disabling reporting "
719 "too frequent queue full errors (%s)\n",
720 msg);
721 else
722 ipath_cdbg(ERRPKT,
723 "Temporarily disabling reporting too"
724 " frequent packet errors (%s)\n",
725 msg);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800726 }
727
728 /*
729 * Re-enable the masked errors after around 3 minutes. in
730 * ipath_get_faststats(). If we have a series of fast
731 * repeating but different errors, the interval will keep
732 * stretching out, but that's OK, as that's pretty
733 * catastrophic.
734 */
735 dd->ipath_unmasktime = jiffies + HZ * 180;
736 }
737
738 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, errs);
739 if (ignore_this_time)
740 errs &= ~ignore_this_time;
741 if (errs & ~dd->ipath_lasterror) {
742 errs &= ~dd->ipath_lasterror;
743 /* never suppress duplicate hwerrors or ibstatuschange */
744 dd->ipath_lasterror |= errs &
745 ~(INFINIPATH_E_HARDWARE |
746 INFINIPATH_E_IBSTATUSCHANGED);
747 }
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -0700748
Dave Olson124b4dc2008-04-16 21:09:32 -0700749 if (errs & INFINIPATH_E_SENDSPECIALTRIGGER) {
750 dd->ipath_spectriggerhit++;
751 ipath_dbg("%lu special trigger hits\n",
752 dd->ipath_spectriggerhit);
753 }
754
755 /* likely due to cancel; so suppress message unless verbose */
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -0700756 if ((errs & (INFINIPATH_E_SPKTLEN | INFINIPATH_E_SPIOARMLAUNCH)) &&
757 dd->ipath_lastcancel > jiffies) {
Dave Olson124b4dc2008-04-16 21:09:32 -0700758 /* armlaunch takes precedence; it often causes both. */
759 ipath_cdbg(VERBOSE,
760 "Suppressed %s error (%llx) after sendbuf cancel\n",
761 (errs & INFINIPATH_E_SPIOARMLAUNCH) ?
762 "armlaunch" : "sendpktlen", (unsigned long long)errs);
Bryan O'Sullivan89d1e092006-09-28 09:00:18 -0700763 errs &= ~(INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SPKTLEN);
764 }
765
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800766 if (!errs)
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700767 return 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800768
Dave Olson124b4dc2008-04-16 21:09:32 -0700769 if (!noprint) {
770 ipath_err_t mask;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800771 /*
Dave Olson124b4dc2008-04-16 21:09:32 -0700772 * The ones we mask off are handled specially below
773 * or above. Also mask SDMADISABLED by default as it
774 * is too chatty.
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800775 */
Dave Olson124b4dc2008-04-16 21:09:32 -0700776 mask = INFINIPATH_E_IBSTATUSCHANGED |
777 INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
778 INFINIPATH_E_HARDWARE | INFINIPATH_E_SDMADISABLED;
779
780 /* if we're in debug, then don't mask SDMADISABLED msgs */
781 if (ipath_debug & __IPATH_DBG)
782 mask &= ~INFINIPATH_E_SDMADISABLED;
783
784 ipath_decode_err(dd, msg, sizeof msg, errs & ~mask);
785 } else
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800786 /* so we don't need if (!noprint) at strlcat's below */
787 *msg = 0;
788
789 if (errs & E_SUM_PKTERRS) {
790 ipath_stats.sps_pkterrs++;
791 chkerrpkts = 1;
792 }
793 if (errs & E_SUM_ERRS)
794 ipath_stats.sps_errs++;
795
796 if (errs & (INFINIPATH_E_RICRC | INFINIPATH_E_RVCRC)) {
797 ipath_stats.sps_crcerrs++;
798 chkerrpkts = 1;
799 }
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700800 iserr = errs & ~(E_SUM_PKTERRS | INFINIPATH_E_PKTERRS);
801
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800802
803 /*
804 * We don't want to print these two as they happen, or we can make
805 * the situation even worse, because it takes so long to print
806 * messages to serial consoles. Kernel ports get printed from
807 * fast_stats, no more than every 5 seconds, user ports get printed
808 * on close
809 */
Dave Olson124b4dc2008-04-16 21:09:32 -0700810 if (errs & INFINIPATH_E_RRCVHDRFULL)
811 chkerrpkts |= handle_hdrq_full(dd);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800812 if (errs & INFINIPATH_E_RRCVEGRFULL) {
Ralph Campbellc59a80a2007-12-20 02:43:23 -0800813 struct ipath_portdata *pd = dd->ipath_pd[0];
814
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800815 /*
816 * since this is of less importance and not likely to
817 * happen without also getting hdrfull, only count
818 * occurrences; don't check each port (or even the kernel
819 * vs user)
820 */
821 ipath_stats.sps_etidfull++;
Ralph Campbell9355fb62008-04-16 21:09:29 -0700822 if (pd->port_head != ipath_get_hdrqtail(pd))
Dave Olson124b4dc2008-04-16 21:09:32 -0700823 chkerrpkts |= 1;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800824 }
825
826 /*
827 * do this before IBSTATUSCHANGED, in case both bits set in a single
828 * interrupt; we want the STATUSCHANGE to "win", so we do our
829 * internal copy of state machine correctly
830 */
831 if (errs & INFINIPATH_E_RIBLOSTLINK) {
832 /*
833 * force through block below
834 */
835 errs |= INFINIPATH_E_IBSTATUSCHANGED;
836 ipath_stats.sps_iblink++;
837 dd->ipath_flags |= IPATH_LINKDOWN;
838 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
839 | IPATH_LINKARMED | IPATH_LINKACTIVE);
840 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800841
John Gregor58411d12008-04-16 21:09:24 -0700842 ipath_dbg("Lost link, link now down (%s)\n",
843 ipath_ibcstatus_str[ipath_read_kreg64(dd,
844 dd->ipath_kregs->kr_ibcstatus) & 0xf]);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800845 }
846 if (errs & INFINIPATH_E_IBSTATUSCHANGED)
John Gregor58411d12008-04-16 21:09:24 -0700847 handle_e_ibstatuschanged(dd, errs);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800848
849 if (errs & INFINIPATH_E_RESET) {
850 if (!noprint)
851 ipath_dev_err(dd, "Got reset, requires re-init "
852 "(unload and reload driver)\n");
853 dd->ipath_flags &= ~IPATH_INITTED; /* needs re-init */
854 /* mark as having had error */
855 *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
856 *dd->ipath_statusp &= ~IPATH_STATUS_IB_CONF;
857 }
858
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700859 if (!noprint && *msg) {
860 if (iserr)
861 ipath_dev_err(dd, "%s error\n", msg);
Bryan O'Sullivan8ec10772007-03-15 14:44:55 -0700862 }
Bryan O'Sullivan0fd41362006-08-25 11:24:34 -0700863 if (dd->ipath_state_wanted & dd->ipath_flags) {
864 ipath_cdbg(VERBOSE, "driver wanted state %x, iflags now %x, "
865 "waking\n", dd->ipath_state_wanted,
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800866 dd->ipath_flags);
Bryan O'Sullivan0fd41362006-08-25 11:24:34 -0700867 wake_up_interruptible(&ipath_state_wait);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800868 }
869
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -0700870 return chkerrpkts;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800871}
872
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700873/*
874 * try to cleanup as much as possible for anything that might have gone
875 * wrong while in freeze mode, such as pio buffers being written by user
876 * processes (causing armlaunch), send errors due to going into freeze mode,
877 * etc., and try to avoid causing extra interrupts while doing so.
878 * Forcibly update the in-memory pioavail register copies after cleanup
Dave Olsone2ab41c2008-05-07 11:00:15 -0700879 * because the chip won't do it while in freeze mode (the register values
880 * themselves are kept correct).
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700881 * Make sure that we don't lose any important interrupts by using the chip
882 * feature that says that writing 0 to a bit in *clear that is set in
883 * *status will cause an interrupt to be generated again (if allowed by
884 * the *mask value).
885 */
886void ipath_clear_freeze(struct ipath_devdata *dd)
887{
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700888 /* disable error interrupts, to avoid confusion */
889 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask, 0ULL);
890
Dave Olson78d1e022007-07-20 14:41:26 -0700891 /* also disable interrupts; errormask is sometimes overwriten */
892 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
893
Dave Olsonb4d390d2008-05-07 10:57:48 -0700894 ipath_cancel_sends(dd, 1);
Dave Olsone2ab41c2008-05-07 11:00:15 -0700895
896 /* clear the freeze, and be sure chip saw it */
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700897 ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
898 dd->ipath_control);
Dave Olsone2ab41c2008-05-07 11:00:15 -0700899 ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700900
Dave Olsone2ab41c2008-05-07 11:00:15 -0700901 /* force in-memory update now we are out of freeze */
Ralph Campbellc4b4d162008-04-16 21:09:26 -0700902 ipath_force_pio_avail_update(dd);
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700903
904 /*
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700905 * force new interrupt if any hwerr, error or interrupt bits are
906 * still set, and clear "safe" send packet errors related to freeze
907 * and cancelling sends. Re-enable error interrupts before possible
908 * force of re-interrupt on pending interrupts.
909 */
910 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear, 0ULL);
911 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear,
912 E_SPKT_ERRS_IGNORE);
913 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
Dave Olson78d1e022007-07-20 14:41:26 -0700914 dd->ipath_errormask);
915 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, -1LL);
Dave Olson0f4fc5e2007-07-06 12:48:33 -0700916 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);
917}
918
919
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800920/* this is separate to allow for better optimization of ipath_intr() */
921
Dave Olsone193e332007-10-10 05:10:35 -0700922static noinline void ipath_bad_intr(struct ipath_devdata *dd, u32 *unexpectp)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800923{
924 /*
925 * sometimes happen during driver init and unload, don't want
926 * to process any interrupts at that point
927 */
928
929 /* this is just a bandaid, not a fix, if something goes badly
930 * wrong */
931 if (++*unexpectp > 100) {
932 if (++*unexpectp > 105) {
933 /*
934 * ok, we must be taking somebody else's interrupts,
935 * due to a messed up mptable and/or PIRQ table, so
936 * unregister the interrupt. We've seen this during
937 * linuxbios development work, and it may happen in
938 * the future again.
939 */
Bryan O'Sullivan51f65eb2006-11-08 17:44:58 -0800940 if (dd->pcidev && dd->ipath_irq) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800941 ipath_dev_err(dd, "Now %u unexpected "
942 "interrupts, unregistering "
943 "interrupt handler\n",
944 *unexpectp);
Bryan O'Sullivan51f65eb2006-11-08 17:44:58 -0800945 ipath_dbg("free_irq of irq %d\n",
946 dd->ipath_irq);
947 dd->ipath_f_free_irq(dd);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800948 }
949 }
Arthur Jones7da04982008-01-06 21:12:38 -0800950 if (ipath_read_ireg(dd, dd->ipath_kregs->kr_intmask)) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800951 ipath_dev_err(dd, "%u unexpected interrupts, "
952 "disabling interrupts completely\n",
953 *unexpectp);
954 /*
955 * disable all interrupts, something is very wrong
956 */
957 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
958 0ULL);
959 }
960 } else if (*unexpectp > 1)
961 ipath_dbg("Interrupt when not ready, should not happen, "
962 "ignoring\n");
963}
964
Dave Olsone193e332007-10-10 05:10:35 -0700965static noinline void ipath_bad_regread(struct ipath_devdata *dd)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800966{
967 static int allbits;
968
969 /* separate routine, for better optimization of ipath_intr() */
970
971 /*
972 * We print the message and disable interrupts, in hope of
973 * having a better chance of debugging the problem.
974 */
975 ipath_dev_err(dd,
976 "Read of interrupt status failed (all bits set)\n");
977 if (allbits++) {
978 /* disable all interrupts, something is very wrong */
979 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
980 if (allbits == 2) {
981 ipath_dev_err(dd, "Still bad interrupt status, "
982 "unregistering interrupt\n");
Bryan O'Sullivan51f65eb2006-11-08 17:44:58 -0800983 dd->ipath_f_free_irq(dd);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800984 } else if (allbits > 2) {
985 if ((allbits % 10000) == 0)
986 printk(".");
987 } else
988 ipath_dev_err(dd, "Disabling interrupts, "
989 "multiple errors\n");
990 }
991}
992
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800993static void handle_layer_pioavail(struct ipath_devdata *dd)
994{
John Gregore342c112007-09-05 01:57:14 -0700995 unsigned long flags;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800996 int ret;
997
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -0700998 ret = ipath_ib_piobufavail(dd->verbs_dev);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -0800999 if (ret > 0)
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -07001000 goto set;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001001
1002 return;
Bryan O'Sullivand562a5a2006-04-24 14:23:08 -07001003set:
John Gregore342c112007-09-05 01:57:14 -07001004 spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
1005 dd->ipath_sendctrl |= INFINIPATH_S_PIOINTBUFAVAIL;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001006 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
1007 dd->ipath_sendctrl);
John Gregore342c112007-09-05 01:57:14 -07001008 ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
1009 spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001010}
1011
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001012/*
1013 * Handle receive interrupts for user ports; this means a user
1014 * process was waiting for a packet to arrive, and didn't want
1015 * to poll
1016 */
Ralph Campbell9355fb62008-04-16 21:09:29 -07001017static void handle_urcv(struct ipath_devdata *dd, u64 istat)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001018{
1019 u64 portr;
1020 int i;
1021 int rcvdint = 0;
1022
Arthur Jones2f01a702007-10-17 18:18:29 -07001023 /*
1024 * test_and_clear_bit(IPATH_PORT_WAITING_RCV) and
1025 * test_and_clear_bit(IPATH_PORT_WAITING_URG) below
1026 * would both like timely updates of the bits so that
1027 * we don't pass them by unnecessarily. the rmb()
1028 * here ensures that we see them promptly -- the
1029 * corresponding wmb()'s are in ipath_poll_urgent()
1030 * and ipath_poll_next()...
1031 */
Arthur Jones70c51da2007-09-14 12:22:49 -07001032 rmb();
Ralph Campbell9355fb62008-04-16 21:09:29 -07001033 portr = ((istat >> dd->ipath_i_rcvavail_shift) &
1034 dd->ipath_i_rcvavail_mask) |
1035 ((istat >> dd->ipath_i_rcvurg_shift) &
1036 dd->ipath_i_rcvurg_mask);
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001037 for (i = 1; i < dd->ipath_cfgports; i++) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001038 struct ipath_portdata *pd = dd->ipath_pd[i];
Ralph Campbell2ba3f562008-04-16 21:09:29 -07001039
Robert Walshf2d04232007-06-18 14:24:49 -07001040 if (portr & (1 << i) && pd && pd->port_cnt) {
Arthur Jones70c51da2007-09-14 12:22:49 -07001041 if (test_and_clear_bit(IPATH_PORT_WAITING_RCV,
1042 &pd->port_flag)) {
Dave Olsond8274862007-12-21 01:50:59 -08001043 clear_bit(i + dd->ipath_r_intravail_shift,
Robert Walshf2d04232007-06-18 14:24:49 -07001044 &dd->ipath_rcvctrl);
1045 wake_up_interruptible(&pd->port_wait);
1046 rcvdint = 1;
Arthur Jones70c51da2007-09-14 12:22:49 -07001047 } else if (test_and_clear_bit(IPATH_PORT_WAITING_URG,
1048 &pd->port_flag)) {
1049 pd->port_urgent++;
Robert Walshf2d04232007-06-18 14:24:49 -07001050 wake_up_interruptible(&pd->port_wait);
1051 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001052 }
1053 }
1054 if (rcvdint) {
1055 /* only want to take one interrupt, so turn off the rcv
Ralph Campbell9355fb62008-04-16 21:09:29 -07001056 * interrupt for all the ports that we set the rcv_waiting
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001057 * (but never for kernel port)
1058 */
1059 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
1060 dd->ipath_rcvctrl);
1061 }
1062}
1063
David Howells7d12e782006-10-05 14:55:46 +01001064irqreturn_t ipath_intr(int irq, void *data)
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001065{
1066 struct ipath_devdata *dd = data;
Dave Olson124b4dc2008-04-16 21:09:32 -07001067 u64 istat, chk0rcv = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001068 ipath_err_t estat = 0;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001069 irqreturn_t ret;
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001070 static unsigned unexpected = 0;
Ralph Campbell9355fb62008-04-16 21:09:29 -07001071 u64 kportrbits;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001072
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001073 ipath_stats.sps_ints++;
1074
Arthur Jones35884232007-07-06 12:48:53 -07001075 if (dd->ipath_int_counter != (u32) -1)
1076 dd->ipath_int_counter++;
1077
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001078 if (!(dd->ipath_flags & IPATH_PRESENT)) {
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -07001079 /*
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001080 * This return value is not great, but we do not want the
Bryan O'Sullivanc71c30d2006-04-24 14:23:03 -07001081 * interrupt core code to remove our interrupt handler
1082 * because we don't appear to be handling an interrupt
1083 * during a chip reset.
1084 */
1085 return IRQ_HANDLED;
1086 }
1087
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001088 /*
1089 * this needs to be flags&initted, not statusp, so we keep
1090 * taking interrupts even after link goes down, etc.
1091 * Also, we *must* clear the interrupt at some point, or we won't
1092 * take it again, which can be real bad for errors, etc...
1093 */
1094
1095 if (!(dd->ipath_flags & IPATH_INITTED)) {
1096 ipath_bad_intr(dd, &unexpected);
1097 ret = IRQ_NONE;
1098 goto bail;
1099 }
1100
Arthur Jones7da04982008-01-06 21:12:38 -08001101 istat = ipath_read_ireg(dd, dd->ipath_kregs->kr_intstatus);
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -07001102
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001103 if (unlikely(!istat)) {
1104 ipath_stats.sps_nullintr++;
1105 ret = IRQ_NONE; /* not our interrupt, or already handled */
1106 goto bail;
1107 }
1108 if (unlikely(istat == -1)) {
1109 ipath_bad_regread(dd);
1110 /* don't know if it was our interrupt or not */
1111 ret = IRQ_NONE;
1112 goto bail;
1113 }
1114
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001115 if (unexpected)
1116 unexpected = 0;
1117
Bryan O'Sullivanf62fe772006-09-28 09:00:11 -07001118 if (unlikely(istat & ~dd->ipath_i_bitsextant))
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001119 ipath_dev_err(dd,
Dave Olson124b4dc2008-04-16 21:09:32 -07001120 "interrupt with unknown interrupts %Lx set\n",
1121 istat & ~dd->ipath_i_bitsextant);
1122 else if (istat & ~INFINIPATH_I_ERROR) /* errors do own printing */
1123 ipath_cdbg(VERBOSE, "intr stat=0x%Lx\n", istat);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001124
Dave Olson124b4dc2008-04-16 21:09:32 -07001125 if (istat & INFINIPATH_I_ERROR) {
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001126 ipath_stats.sps_errints++;
1127 estat = ipath_read_kreg64(dd,
1128 dd->ipath_kregs->kr_errorstatus);
1129 if (!estat)
Dave Olson124b4dc2008-04-16 21:09:32 -07001130 dev_info(&dd->pcidev->dev, "error interrupt (%Lx), "
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001131 "but no error bits set!\n", istat);
1132 else if (estat == -1LL)
1133 /*
1134 * should we try clearing all, or hope next read
1135 * works?
1136 */
1137 ipath_dev_err(dd, "Read of error status failed "
1138 "(all bits set); ignoring\n");
1139 else
Ralph Campbell9355fb62008-04-16 21:09:29 -07001140 chk0rcv |= handle_errors(dd, estat);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001141 }
1142
1143 if (istat & INFINIPATH_I_GPIO) {
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001144 /*
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001145 * GPIO interrupts fall in two broad classes:
1146 * GPIO_2 indicates (on some HT4xx boards) that a packet
1147 * has arrived for Port 0. Checking for this
1148 * is controlled by flag IPATH_GPIO_INTR.
Arthur Jones327a3382007-08-02 14:46:29 -07001149 * GPIO_3..5 on IBA6120 Rev2 and IBA6110 Rev4 chips indicate
1150 * errors that we need to count. Checking for this
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001151 * is controlled by flag IPATH_GPIO_ERRINTRS.
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001152 */
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001153 u32 gpiostatus;
1154 u32 to_clear = 0;
1155
1156 gpiostatus = ipath_read_kreg32(
1157 dd, dd->ipath_kregs->kr_gpio_status);
Ralph Campbell2ba3f562008-04-16 21:09:29 -07001158 /* First the error-counter case. */
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001159 if ((gpiostatus & IPATH_GPIO_ERRINTR_MASK) &&
1160 (dd->ipath_flags & IPATH_GPIO_ERRINTRS)) {
1161 /* want to clear the bits we see asserted. */
1162 to_clear |= (gpiostatus & IPATH_GPIO_ERRINTR_MASK);
1163
1164 /*
1165 * Count appropriately, clear bits out of our copy,
1166 * as they have been "handled".
1167 */
1168 if (gpiostatus & (1 << IPATH_GPIO_RXUVL_BIT)) {
1169 ipath_dbg("FlowCtl on UnsupVL\n");
1170 dd->ipath_rxfc_unsupvl_errs++;
1171 }
1172 if (gpiostatus & (1 << IPATH_GPIO_OVRUN_BIT)) {
1173 ipath_dbg("Overrun Threshold exceeded\n");
1174 dd->ipath_overrun_thresh_errs++;
1175 }
1176 if (gpiostatus & (1 << IPATH_GPIO_LLI_BIT)) {
1177 ipath_dbg("Local Link Integrity error\n");
1178 dd->ipath_lli_errs++;
1179 }
1180 gpiostatus &= ~IPATH_GPIO_ERRINTR_MASK;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001181 }
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001182 /* Now the Port0 Receive case */
1183 if ((gpiostatus & (1 << IPATH_GPIO_PORT0_BIT)) &&
1184 (dd->ipath_flags & IPATH_GPIO_INTR)) {
1185 /*
1186 * GPIO status bit 2 is set, and we expected it.
1187 * clear it and indicate in p0bits.
1188 * This probably only happens if a Port0 pkt
1189 * arrives at _just_ the wrong time, and we
1190 * handle that by seting chk0rcv;
1191 */
1192 to_clear |= (1 << IPATH_GPIO_PORT0_BIT);
1193 gpiostatus &= ~(1 << IPATH_GPIO_PORT0_BIT);
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -07001194 chk0rcv = 1;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001195 }
Arthur Jones8f140b42007-05-10 12:10:49 -07001196 if (gpiostatus) {
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001197 /*
1198 * Some unexpected bits remain. If they could have
1199 * caused the interrupt, complain and clear.
Michael Albaugh6a733cd2007-10-03 10:47:38 -07001200 * To avoid repetition of this condition, also clear
1201 * the mask. It is almost certainly due to error.
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001202 */
Arthur Jones8f140b42007-05-10 12:10:49 -07001203 const u32 mask = (u32) dd->ipath_gpio_mask;
1204
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001205 if (mask & gpiostatus) {
1206 ipath_dbg("Unexpected GPIO IRQ bits %x\n",
1207 gpiostatus & mask);
1208 to_clear |= (gpiostatus & mask);
Michael Albaugh6a733cd2007-10-03 10:47:38 -07001209 dd->ipath_gpio_mask &= ~(gpiostatus & mask);
1210 ipath_write_kreg(dd,
1211 dd->ipath_kregs->kr_gpio_mask,
1212 dd->ipath_gpio_mask);
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001213 }
1214 }
1215 if (to_clear) {
1216 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
1217 (u64) to_clear);
1218 }
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001219 }
1220
1221 /*
Bryan O'Sullivan57abad22006-07-01 04:36:05 -07001222 * Clear the interrupt bits we found set, unless they are receive
1223 * related, in which case we already cleared them above, and don't
1224 * want to clear them again, because we might lose an interrupt.
1225 * Clear it early, so we "know" know the chip will have seen this by
1226 * the time we process the queue, and will re-interrupt if necessary.
1227 * The processor itself won't take the interrupt again until we return.
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001228 */
1229 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, istat);
1230
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001231 /*
Ralph Campbell9355fb62008-04-16 21:09:29 -07001232 * Handle kernel receive queues before checking for pio buffers
1233 * available since receives can overflow; piobuf waiters can afford
1234 * a few extra cycles, since they were waiting anyway, and user's
1235 * waiting for receive are at the bottom.
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001236 */
Ralph Campbell9355fb62008-04-16 21:09:29 -07001237 kportrbits = (1ULL << dd->ipath_i_rcvavail_shift) |
1238 (1ULL << dd->ipath_i_rcvurg_shift);
1239 if (chk0rcv || (istat & kportrbits)) {
1240 istat &= ~kportrbits;
Ralph Campbellc59a80a2007-12-20 02:43:23 -08001241 ipath_kreceive(dd->ipath_pd[0]);
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001242 }
Bryan O'Sullivanf5f99922006-07-01 04:36:05 -07001243
Ralph Campbell9355fb62008-04-16 21:09:29 -07001244 if (istat & ((dd->ipath_i_rcvavail_mask << dd->ipath_i_rcvavail_shift) |
1245 (dd->ipath_i_rcvurg_mask << dd->ipath_i_rcvurg_shift)))
Bryan O'Sullivan13aef492006-07-01 04:36:04 -07001246 handle_urcv(dd, istat);
1247
Dave Olson124b4dc2008-04-16 21:09:32 -07001248 if (istat & (INFINIPATH_I_SDMAINT | INFINIPATH_I_SDMADISABLED))
1249 handle_sdma_intr(dd, istat);
1250
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001251 if (istat & INFINIPATH_I_SPIOBUFAVAIL) {
John Gregore342c112007-09-05 01:57:14 -07001252 unsigned long flags;
1253
1254 spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
1255 dd->ipath_sendctrl &= ~INFINIPATH_S_PIOINTBUFAVAIL;
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001256 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
1257 dd->ipath_sendctrl);
John Gregore342c112007-09-05 01:57:14 -07001258 ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
1259 spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001260
Dave Olsone2ab41c2008-05-07 11:00:15 -07001261 /* always process; sdma verbs uses PIO for acks and VL15 */
1262 handle_layer_pioavail(dd);
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001263 }
1264
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001265 ret = IRQ_HANDLED;
1266
1267bail:
1268 return ret;
1269}