ipath_intr.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. /*
  2. * Copyright (c) 2006 QLogic, Inc. All rights reserved.
  3. * 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. #include <linux/pci.h>
  34. #include "ipath_kernel.h"
  35. #include "ipath_verbs.h"
  36. #include "ipath_common.h"
  37. /*
  38. * clear (write) a pio buffer, to clear a parity error. This routine
  39. * should only be called when in freeze mode, and the buffer should be
  40. * canceled afterwards.
  41. */
  42. static void ipath_clrpiobuf(struct ipath_devdata *dd, u32 pnum)
  43. {
  44. u32 __iomem *pbuf;
  45. u32 dwcnt; /* dword count to write */
  46. if (pnum < dd->ipath_piobcnt2k) {
  47. pbuf = (u32 __iomem *) (dd->ipath_pio2kbase + pnum *
  48. dd->ipath_palign);
  49. dwcnt = dd->ipath_piosize2k >> 2;
  50. }
  51. else {
  52. pbuf = (u32 __iomem *) (dd->ipath_pio4kbase +
  53. (pnum - dd->ipath_piobcnt2k) * dd->ipath_4kalign);
  54. dwcnt = dd->ipath_piosize4k >> 2;
  55. }
  56. dev_info(&dd->pcidev->dev,
  57. "Rewrite PIO buffer %u, to recover from parity error\n",
  58. pnum);
  59. *pbuf = dwcnt+1; /* no flush required, since already in freeze */
  60. while(--dwcnt)
  61. *pbuf++ = 0;
  62. }
  63. /*
  64. * Called when we might have an error that is specific to a particular
  65. * PIO buffer, and may need to cancel that buffer, so it can be re-used.
  66. * If rewrite is true, and bits are set in the sendbufferror registers,
  67. * we'll write to the buffer, for error recovery on parity errors.
  68. */
  69. void ipath_disarm_senderrbufs(struct ipath_devdata *dd, int rewrite)
  70. {
  71. u32 piobcnt;
  72. unsigned long sbuf[4];
  73. /*
  74. * it's possible that sendbuffererror could have bits set; might
  75. * have already done this as a result of hardware error handling
  76. */
  77. piobcnt = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
  78. /* read these before writing errorclear */
  79. sbuf[0] = ipath_read_kreg64(
  80. dd, dd->ipath_kregs->kr_sendbuffererror);
  81. sbuf[1] = ipath_read_kreg64(
  82. dd, dd->ipath_kregs->kr_sendbuffererror + 1);
  83. if (piobcnt > 128) {
  84. sbuf[2] = ipath_read_kreg64(
  85. dd, dd->ipath_kregs->kr_sendbuffererror + 2);
  86. sbuf[3] = ipath_read_kreg64(
  87. dd, dd->ipath_kregs->kr_sendbuffererror + 3);
  88. }
  89. if (sbuf[0] || sbuf[1] || (piobcnt > 128 && (sbuf[2] || sbuf[3]))) {
  90. int i;
  91. if (ipath_debug & (__IPATH_PKTDBG|__IPATH_DBG)) {
  92. __IPATH_DBG_WHICH(__IPATH_PKTDBG|__IPATH_DBG,
  93. "SendbufErrs %lx %lx", sbuf[0],
  94. sbuf[1]);
  95. if (ipath_debug & __IPATH_PKTDBG && piobcnt > 128)
  96. printk(" %lx %lx ", sbuf[2], sbuf[3]);
  97. printk("\n");
  98. }
  99. for (i = 0; i < piobcnt; i++)
  100. if (test_bit(i, sbuf)) {
  101. if (rewrite)
  102. ipath_clrpiobuf(dd, i);
  103. ipath_disarm_piobufs(dd, i, 1);
  104. }
  105. dd->ipath_lastcancel = jiffies+3; /* no armlaunch for a bit */
  106. }
  107. }
  108. /* These are all rcv-related errors which we want to count for stats */
  109. #define E_SUM_PKTERRS \
  110. (INFINIPATH_E_RHDRLEN | INFINIPATH_E_RBADTID | \
  111. INFINIPATH_E_RBADVERSION | INFINIPATH_E_RHDR | \
  112. INFINIPATH_E_RLONGPKTLEN | INFINIPATH_E_RSHORTPKTLEN | \
  113. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RMINPKTLEN | \
  114. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RUNSUPVL | \
  115. INFINIPATH_E_RUNEXPCHAR | INFINIPATH_E_REBP)
  116. /* These are all send-related errors which we want to count for stats */
  117. #define E_SUM_ERRS \
  118. (INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM | \
  119. INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
  120. INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SUNSUPVL | \
  121. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
  122. INFINIPATH_E_INVALIDADDR)
  123. /*
  124. * these are errors that can occur when the link changes state while
  125. * a packet is being sent or received. This doesn't cover things
  126. * like EBP or VCRC that can be the result of a sending having the
  127. * link change state, so we receive a "known bad" packet.
  128. */
  129. #define E_SUM_LINK_PKTERRS \
  130. (INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
  131. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
  132. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RMINPKTLEN | \
  133. INFINIPATH_E_RUNEXPCHAR)
  134. static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs)
  135. {
  136. u64 ignore_this_time = 0;
  137. ipath_disarm_senderrbufs(dd, 0);
  138. if ((errs & E_SUM_LINK_PKTERRS) &&
  139. !(dd->ipath_flags & IPATH_LINKACTIVE)) {
  140. /*
  141. * This can happen when SMA is trying to bring the link
  142. * up, but the IB link changes state at the "wrong" time.
  143. * The IB logic then complains that the packet isn't
  144. * valid. We don't want to confuse people, so we just
  145. * don't print them, except at debug
  146. */
  147. ipath_dbg("Ignoring packet errors %llx, because link not "
  148. "ACTIVE\n", (unsigned long long) errs);
  149. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  150. }
  151. return ignore_this_time;
  152. }
  153. /* generic hw error messages... */
  154. #define INFINIPATH_HWE_TXEMEMPARITYERR_MSG(a) \
  155. { \
  156. .mask = ( INFINIPATH_HWE_TXEMEMPARITYERR_##a << \
  157. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT ), \
  158. .msg = "TXE " #a " Memory Parity" \
  159. }
  160. #define INFINIPATH_HWE_RXEMEMPARITYERR_MSG(a) \
  161. { \
  162. .mask = ( INFINIPATH_HWE_RXEMEMPARITYERR_##a << \
  163. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT ), \
  164. .msg = "RXE " #a " Memory Parity" \
  165. }
  166. static const struct ipath_hwerror_msgs ipath_generic_hwerror_msgs[] = {
  167. INFINIPATH_HWE_MSG(IBCBUSFRSPCPARITYERR, "IPATH2IB Parity"),
  168. INFINIPATH_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2IPATH Parity"),
  169. INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOBUF),
  170. INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOPBC),
  171. INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOLAUNCHFIFO),
  172. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(RCVBUF),
  173. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(LOOKUPQ),
  174. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EAGERTID),
  175. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EXPTID),
  176. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(FLAGBUF),
  177. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(DATAINFO),
  178. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(HDRINFO),
  179. };
  180. /**
  181. * ipath_format_hwmsg - format a single hwerror message
  182. * @msg message buffer
  183. * @msgl length of message buffer
  184. * @hwmsg message to add to message buffer
  185. */
  186. static void ipath_format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
  187. {
  188. strlcat(msg, "[", msgl);
  189. strlcat(msg, hwmsg, msgl);
  190. strlcat(msg, "]", msgl);
  191. }
  192. /**
  193. * ipath_format_hwerrors - format hardware error messages for display
  194. * @hwerrs hardware errors bit vector
  195. * @hwerrmsgs hardware error descriptions
  196. * @nhwerrmsgs number of hwerrmsgs
  197. * @msg message buffer
  198. * @msgl message buffer length
  199. */
  200. void ipath_format_hwerrors(u64 hwerrs,
  201. const struct ipath_hwerror_msgs *hwerrmsgs,
  202. size_t nhwerrmsgs,
  203. char *msg, size_t msgl)
  204. {
  205. int i;
  206. const int glen =
  207. sizeof(ipath_generic_hwerror_msgs) /
  208. sizeof(ipath_generic_hwerror_msgs[0]);
  209. for (i=0; i<glen; i++) {
  210. if (hwerrs & ipath_generic_hwerror_msgs[i].mask) {
  211. ipath_format_hwmsg(msg, msgl,
  212. ipath_generic_hwerror_msgs[i].msg);
  213. }
  214. }
  215. for (i=0; i<nhwerrmsgs; i++) {
  216. if (hwerrs & hwerrmsgs[i].mask) {
  217. ipath_format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
  218. }
  219. }
  220. }
  221. /* return the strings for the most common link states */
  222. static char *ib_linkstate(u32 linkstate)
  223. {
  224. char *ret;
  225. switch (linkstate) {
  226. case IPATH_IBSTATE_INIT:
  227. ret = "Init";
  228. break;
  229. case IPATH_IBSTATE_ARM:
  230. ret = "Arm";
  231. break;
  232. case IPATH_IBSTATE_ACTIVE:
  233. ret = "Active";
  234. break;
  235. default:
  236. ret = "Down";
  237. }
  238. return ret;
  239. }
  240. static void handle_e_ibstatuschanged(struct ipath_devdata *dd,
  241. ipath_err_t errs, int noprint)
  242. {
  243. u64 val;
  244. u32 ltstate, lstate;
  245. /*
  246. * even if diags are enabled, we want to notice LINKINIT, etc.
  247. * We just don't want to change the LED state, or
  248. * dd->ipath_kregs->kr_ibcctrl
  249. */
  250. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
  251. lstate = val & IPATH_IBSTATE_MASK;
  252. /*
  253. * this is confusing enough when it happens that I want to always put it
  254. * on the console and in the logs. If it was a requested state change,
  255. * we'll have already cleared the flags, so we won't print this warning
  256. */
  257. if ((lstate != IPATH_IBSTATE_ARM && lstate != IPATH_IBSTATE_ACTIVE)
  258. && (dd->ipath_flags & (IPATH_LINKARMED | IPATH_LINKACTIVE))) {
  259. dev_info(&dd->pcidev->dev, "Link state changed from %s to %s\n",
  260. (dd->ipath_flags & IPATH_LINKARMED) ? "ARM" : "ACTIVE",
  261. ib_linkstate(lstate));
  262. /*
  263. * Flush all queued sends when link went to DOWN or INIT,
  264. * to be sure that they don't block SMA and other MAD packets
  265. */
  266. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  267. INFINIPATH_S_ABORT);
  268. ipath_disarm_piobufs(dd, dd->ipath_lastport_piobuf,
  269. (unsigned)(dd->ipath_piobcnt2k +
  270. dd->ipath_piobcnt4k) -
  271. dd->ipath_lastport_piobuf);
  272. }
  273. else if (lstate == IPATH_IBSTATE_INIT || lstate == IPATH_IBSTATE_ARM ||
  274. lstate == IPATH_IBSTATE_ACTIVE) {
  275. /*
  276. * only print at SMA if there is a change, debug if not
  277. * (sometimes we want to know that, usually not).
  278. */
  279. if (lstate == ((unsigned) dd->ipath_lastibcstat
  280. & IPATH_IBSTATE_MASK)) {
  281. ipath_dbg("Status change intr but no change (%s)\n",
  282. ib_linkstate(lstate));
  283. }
  284. else
  285. ipath_cdbg(VERBOSE, "Unit %u link state %s, last "
  286. "was %s\n", dd->ipath_unit,
  287. ib_linkstate(lstate),
  288. ib_linkstate((unsigned)
  289. dd->ipath_lastibcstat
  290. & IPATH_IBSTATE_MASK));
  291. }
  292. else {
  293. lstate = dd->ipath_lastibcstat & IPATH_IBSTATE_MASK;
  294. if (lstate == IPATH_IBSTATE_INIT ||
  295. lstate == IPATH_IBSTATE_ARM ||
  296. lstate == IPATH_IBSTATE_ACTIVE)
  297. ipath_cdbg(VERBOSE, "Unit %u link state down"
  298. " (state 0x%x), from %s\n",
  299. dd->ipath_unit,
  300. (u32)val & IPATH_IBSTATE_MASK,
  301. ib_linkstate(lstate));
  302. else
  303. ipath_cdbg(VERBOSE, "Unit %u link state changed "
  304. "to 0x%x from down (%x)\n",
  305. dd->ipath_unit, (u32) val, lstate);
  306. }
  307. ltstate = (val >> INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
  308. INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
  309. lstate = (val >> INFINIPATH_IBCS_LINKSTATE_SHIFT) &
  310. INFINIPATH_IBCS_LINKSTATE_MASK;
  311. if (ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE ||
  312. ltstate == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
  313. u32 last_ltstate;
  314. /*
  315. * Ignore cycling back and forth from Polling.Active
  316. * to Polling.Quiet while waiting for the other end of
  317. * the link to come up. We will cycle back and forth
  318. * between them if no cable is plugged in,
  319. * the other device is powered off or disabled, etc.
  320. */
  321. last_ltstate = (dd->ipath_lastibcstat >>
  322. INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT)
  323. & INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
  324. if (last_ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE
  325. || last_ltstate ==
  326. INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
  327. if (dd->ipath_ibpollcnt > 40) {
  328. dd->ipath_flags |= IPATH_NOCABLE;
  329. *dd->ipath_statusp |=
  330. IPATH_STATUS_IB_NOCABLE;
  331. } else
  332. dd->ipath_ibpollcnt++;
  333. goto skip_ibchange;
  334. }
  335. }
  336. dd->ipath_ibpollcnt = 0; /* some state other than 2 or 3 */
  337. ipath_stats.sps_iblink++;
  338. if (ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP) {
  339. dd->ipath_flags |= IPATH_LINKDOWN;
  340. dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
  341. | IPATH_LINKACTIVE |
  342. IPATH_LINKARMED);
  343. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  344. dd->ipath_lli_counter = 0;
  345. if (!noprint) {
  346. if (((dd->ipath_lastibcstat >>
  347. INFINIPATH_IBCS_LINKSTATE_SHIFT) &
  348. INFINIPATH_IBCS_LINKSTATE_MASK)
  349. == INFINIPATH_IBCS_L_STATE_ACTIVE)
  350. /* if from up to down be more vocal */
  351. ipath_cdbg(VERBOSE,
  352. "Unit %u link now down (%s)\n",
  353. dd->ipath_unit,
  354. ipath_ibcstatus_str[ltstate]);
  355. else
  356. ipath_cdbg(VERBOSE, "Unit %u link is "
  357. "down (%s)\n", dd->ipath_unit,
  358. ipath_ibcstatus_str[ltstate]);
  359. }
  360. dd->ipath_f_setextled(dd, lstate, ltstate);
  361. } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ACTIVE) {
  362. dd->ipath_flags |= IPATH_LINKACTIVE;
  363. dd->ipath_flags &=
  364. ~(IPATH_LINKUNK | IPATH_LINKINIT | IPATH_LINKDOWN |
  365. IPATH_LINKARMED | IPATH_NOCABLE);
  366. *dd->ipath_statusp &= ~IPATH_STATUS_IB_NOCABLE;
  367. *dd->ipath_statusp |=
  368. IPATH_STATUS_IB_READY | IPATH_STATUS_IB_CONF;
  369. dd->ipath_f_setextled(dd, lstate, ltstate);
  370. } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_INIT) {
  371. /*
  372. * set INIT and DOWN. Down is checked by most of the other
  373. * code, but INIT is useful to know in a few places.
  374. */
  375. dd->ipath_flags |= IPATH_LINKINIT | IPATH_LINKDOWN;
  376. dd->ipath_flags &=
  377. ~(IPATH_LINKUNK | IPATH_LINKACTIVE | IPATH_LINKARMED
  378. | IPATH_NOCABLE);
  379. *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
  380. | IPATH_STATUS_IB_READY);
  381. dd->ipath_f_setextled(dd, lstate, ltstate);
  382. } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ARM) {
  383. dd->ipath_flags |= IPATH_LINKARMED;
  384. dd->ipath_flags &=
  385. ~(IPATH_LINKUNK | IPATH_LINKDOWN | IPATH_LINKINIT |
  386. IPATH_LINKACTIVE | IPATH_NOCABLE);
  387. *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
  388. | IPATH_STATUS_IB_READY);
  389. dd->ipath_f_setextled(dd, lstate, ltstate);
  390. } else {
  391. if (!noprint)
  392. ipath_dbg("IBstatuschange unit %u: %s (%x)\n",
  393. dd->ipath_unit,
  394. ipath_ibcstatus_str[ltstate], ltstate);
  395. }
  396. skip_ibchange:
  397. dd->ipath_lastibcstat = val;
  398. }
  399. static void handle_supp_msgs(struct ipath_devdata *dd,
  400. unsigned supp_msgs, char msg[512])
  401. {
  402. /*
  403. * Print the message unless it's ibc status change only, which
  404. * happens so often we never want to count it.
  405. */
  406. if (dd->ipath_lasterror & ~INFINIPATH_E_IBSTATUSCHANGED) {
  407. int iserr;
  408. iserr = ipath_decode_err(msg, sizeof msg,
  409. dd->ipath_lasterror &
  410. ~INFINIPATH_E_IBSTATUSCHANGED);
  411. if (dd->ipath_lasterror &
  412. ~(INFINIPATH_E_RRCVEGRFULL |
  413. INFINIPATH_E_RRCVHDRFULL | INFINIPATH_E_PKTERRS))
  414. ipath_dev_err(dd, "Suppressed %u messages for "
  415. "fast-repeating errors (%s) (%llx)\n",
  416. supp_msgs, msg,
  417. (unsigned long long)
  418. dd->ipath_lasterror);
  419. else {
  420. /*
  421. * rcvegrfull and rcvhdrqfull are "normal", for some
  422. * types of processes (mostly benchmarks) that send
  423. * huge numbers of messages, while not processing
  424. * them. So only complain about these at debug
  425. * level.
  426. */
  427. if (iserr)
  428. ipath_dbg("Suppressed %u messages for %s\n",
  429. supp_msgs, msg);
  430. else
  431. ipath_cdbg(ERRPKT,
  432. "Suppressed %u messages for %s\n",
  433. supp_msgs, msg);
  434. }
  435. }
  436. }
  437. static unsigned handle_frequent_errors(struct ipath_devdata *dd,
  438. ipath_err_t errs, char msg[512],
  439. int *noprint)
  440. {
  441. unsigned long nc;
  442. static unsigned long nextmsg_time;
  443. static unsigned nmsgs, supp_msgs;
  444. /*
  445. * Throttle back "fast" messages to no more than 10 per 5 seconds.
  446. * This isn't perfect, but it's a reasonable heuristic. If we get
  447. * more than 10, give a 6x longer delay.
  448. */
  449. nc = jiffies;
  450. if (nmsgs > 10) {
  451. if (time_before(nc, nextmsg_time)) {
  452. *noprint = 1;
  453. if (!supp_msgs++)
  454. nextmsg_time = nc + HZ * 3;
  455. }
  456. else if (supp_msgs) {
  457. handle_supp_msgs(dd, supp_msgs, msg);
  458. supp_msgs = 0;
  459. nmsgs = 0;
  460. }
  461. }
  462. else if (!nmsgs++ || time_after(nc, nextmsg_time))
  463. nextmsg_time = nc + HZ / 2;
  464. return supp_msgs;
  465. }
  466. static int handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
  467. {
  468. char msg[512];
  469. u64 ignore_this_time = 0;
  470. int i, iserr = 0;
  471. int chkerrpkts = 0, noprint = 0;
  472. unsigned supp_msgs;
  473. supp_msgs = handle_frequent_errors(dd, errs, msg, &noprint);
  474. /*
  475. * don't report errors that are masked (includes those always
  476. * ignored)
  477. */
  478. errs &= ~dd->ipath_maskederrs;
  479. /* do these first, they are most important */
  480. if (errs & INFINIPATH_E_HARDWARE) {
  481. /* reuse same msg buf */
  482. dd->ipath_f_handle_hwerrors(dd, msg, sizeof msg);
  483. }
  484. if (!noprint && (errs & ~dd->ipath_e_bitsextant))
  485. ipath_dev_err(dd, "error interrupt with unknown errors "
  486. "%llx set\n", (unsigned long long)
  487. (errs & ~dd->ipath_e_bitsextant));
  488. if (errs & E_SUM_ERRS)
  489. ignore_this_time = handle_e_sum_errs(dd, errs);
  490. else if ((errs & E_SUM_LINK_PKTERRS) &&
  491. !(dd->ipath_flags & IPATH_LINKACTIVE)) {
  492. /*
  493. * This can happen when SMA is trying to bring the link
  494. * up, but the IB link changes state at the "wrong" time.
  495. * The IB logic then complains that the packet isn't
  496. * valid. We don't want to confuse people, so we just
  497. * don't print them, except at debug
  498. */
  499. ipath_dbg("Ignoring packet errors %llx, because link not "
  500. "ACTIVE\n", (unsigned long long) errs);
  501. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  502. }
  503. if (supp_msgs == 250000) {
  504. int s_iserr;
  505. /*
  506. * It's not entirely reasonable assuming that the errors set
  507. * in the last clear period are all responsible for the
  508. * problem, but the alternative is to assume it's the only
  509. * ones on this particular interrupt, which also isn't great
  510. */
  511. dd->ipath_maskederrs |= dd->ipath_lasterror | errs;
  512. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  513. ~dd->ipath_maskederrs);
  514. s_iserr = ipath_decode_err(msg, sizeof msg,
  515. (dd->ipath_maskederrs & ~dd->
  516. ipath_ignorederrs));
  517. if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs) &
  518. ~(INFINIPATH_E_RRCVEGRFULL |
  519. INFINIPATH_E_RRCVHDRFULL | INFINIPATH_E_PKTERRS))
  520. ipath_dev_err(dd, "Temporarily disabling "
  521. "error(s) %llx reporting; too frequent (%s)\n",
  522. (unsigned long long) (dd->ipath_maskederrs &
  523. ~dd->ipath_ignorederrs), msg);
  524. else {
  525. /*
  526. * rcvegrfull and rcvhdrqfull are "normal",
  527. * for some types of processes (mostly benchmarks)
  528. * that send huge numbers of messages, while not
  529. * processing them. So only complain about
  530. * these at debug level.
  531. */
  532. if (s_iserr)
  533. ipath_dbg("Temporarily disabling reporting "
  534. "too frequent queue full errors (%s)\n",
  535. msg);
  536. else
  537. ipath_cdbg(ERRPKT,
  538. "Temporarily disabling reporting too"
  539. " frequent packet errors (%s)\n",
  540. msg);
  541. }
  542. /*
  543. * Re-enable the masked errors after around 3 minutes. in
  544. * ipath_get_faststats(). If we have a series of fast
  545. * repeating but different errors, the interval will keep
  546. * stretching out, but that's OK, as that's pretty
  547. * catastrophic.
  548. */
  549. dd->ipath_unmasktime = jiffies + HZ * 180;
  550. }
  551. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, errs);
  552. if (ignore_this_time)
  553. errs &= ~ignore_this_time;
  554. if (errs & ~dd->ipath_lasterror) {
  555. errs &= ~dd->ipath_lasterror;
  556. /* never suppress duplicate hwerrors or ibstatuschange */
  557. dd->ipath_lasterror |= errs &
  558. ~(INFINIPATH_E_HARDWARE |
  559. INFINIPATH_E_IBSTATUSCHANGED);
  560. }
  561. /* likely due to cancel, so suppress */
  562. if ((errs & (INFINIPATH_E_SPKTLEN | INFINIPATH_E_SPIOARMLAUNCH)) &&
  563. dd->ipath_lastcancel > jiffies) {
  564. ipath_dbg("Suppressed armlaunch/spktlen after error send cancel\n");
  565. errs &= ~(INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SPKTLEN);
  566. }
  567. if (!errs)
  568. return 0;
  569. if (!noprint)
  570. /*
  571. * the ones we mask off are handled specially below or above
  572. */
  573. ipath_decode_err(msg, sizeof msg,
  574. errs & ~(INFINIPATH_E_IBSTATUSCHANGED |
  575. INFINIPATH_E_RRCVEGRFULL |
  576. INFINIPATH_E_RRCVHDRFULL |
  577. INFINIPATH_E_HARDWARE));
  578. else
  579. /* so we don't need if (!noprint) at strlcat's below */
  580. *msg = 0;
  581. if (errs & E_SUM_PKTERRS) {
  582. ipath_stats.sps_pkterrs++;
  583. chkerrpkts = 1;
  584. }
  585. if (errs & E_SUM_ERRS)
  586. ipath_stats.sps_errs++;
  587. if (errs & (INFINIPATH_E_RICRC | INFINIPATH_E_RVCRC)) {
  588. ipath_stats.sps_crcerrs++;
  589. chkerrpkts = 1;
  590. }
  591. iserr = errs & ~(E_SUM_PKTERRS | INFINIPATH_E_PKTERRS);
  592. /*
  593. * We don't want to print these two as they happen, or we can make
  594. * the situation even worse, because it takes so long to print
  595. * messages to serial consoles. Kernel ports get printed from
  596. * fast_stats, no more than every 5 seconds, user ports get printed
  597. * on close
  598. */
  599. if (errs & INFINIPATH_E_RRCVHDRFULL) {
  600. u32 hd, tl;
  601. ipath_stats.sps_hdrqfull++;
  602. for (i = 0; i < dd->ipath_cfgports; i++) {
  603. struct ipath_portdata *pd = dd->ipath_pd[i];
  604. if (i == 0) {
  605. hd = dd->ipath_port0head;
  606. tl = (u32) le64_to_cpu(
  607. *dd->ipath_hdrqtailptr);
  608. } else if (pd && pd->port_cnt &&
  609. pd->port_rcvhdrtail_kvaddr) {
  610. /*
  611. * don't report same point multiple times,
  612. * except kernel
  613. */
  614. tl = *(u64 *) pd->port_rcvhdrtail_kvaddr;
  615. if (tl == dd->ipath_lastrcvhdrqtails[i])
  616. continue;
  617. hd = ipath_read_ureg32(dd, ur_rcvhdrhead,
  618. i);
  619. } else
  620. continue;
  621. if (hd == (tl + 1) ||
  622. (!hd && tl == dd->ipath_hdrqlast)) {
  623. if (i == 0)
  624. chkerrpkts = 1;
  625. dd->ipath_lastrcvhdrqtails[i] = tl;
  626. pd->port_hdrqfull++;
  627. }
  628. }
  629. }
  630. if (errs & INFINIPATH_E_RRCVEGRFULL) {
  631. /*
  632. * since this is of less importance and not likely to
  633. * happen without also getting hdrfull, only count
  634. * occurrences; don't check each port (or even the kernel
  635. * vs user)
  636. */
  637. ipath_stats.sps_etidfull++;
  638. if (dd->ipath_port0head !=
  639. (u32) le64_to_cpu(*dd->ipath_hdrqtailptr))
  640. chkerrpkts = 1;
  641. }
  642. /*
  643. * do this before IBSTATUSCHANGED, in case both bits set in a single
  644. * interrupt; we want the STATUSCHANGE to "win", so we do our
  645. * internal copy of state machine correctly
  646. */
  647. if (errs & INFINIPATH_E_RIBLOSTLINK) {
  648. /*
  649. * force through block below
  650. */
  651. errs |= INFINIPATH_E_IBSTATUSCHANGED;
  652. ipath_stats.sps_iblink++;
  653. dd->ipath_flags |= IPATH_LINKDOWN;
  654. dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
  655. | IPATH_LINKARMED | IPATH_LINKACTIVE);
  656. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  657. if (!noprint) {
  658. u64 st = ipath_read_kreg64(
  659. dd, dd->ipath_kregs->kr_ibcstatus);
  660. ipath_dbg("Lost link, link now down (%s)\n",
  661. ipath_ibcstatus_str[st & 0xf]);
  662. }
  663. }
  664. if (errs & INFINIPATH_E_IBSTATUSCHANGED)
  665. handle_e_ibstatuschanged(dd, errs, noprint);
  666. if (errs & INFINIPATH_E_RESET) {
  667. if (!noprint)
  668. ipath_dev_err(dd, "Got reset, requires re-init "
  669. "(unload and reload driver)\n");
  670. dd->ipath_flags &= ~IPATH_INITTED; /* needs re-init */
  671. /* mark as having had error */
  672. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  673. *dd->ipath_statusp &= ~IPATH_STATUS_IB_CONF;
  674. }
  675. if (!noprint && *msg) {
  676. if (iserr)
  677. ipath_dev_err(dd, "%s error\n", msg);
  678. else
  679. dev_info(&dd->pcidev->dev, "%s packet problems\n",
  680. msg);
  681. }
  682. if (dd->ipath_state_wanted & dd->ipath_flags) {
  683. ipath_cdbg(VERBOSE, "driver wanted state %x, iflags now %x, "
  684. "waking\n", dd->ipath_state_wanted,
  685. dd->ipath_flags);
  686. wake_up_interruptible(&ipath_state_wait);
  687. }
  688. return chkerrpkts;
  689. }
  690. /* this is separate to allow for better optimization of ipath_intr() */
  691. static void ipath_bad_intr(struct ipath_devdata *dd, u32 * unexpectp)
  692. {
  693. /*
  694. * sometimes happen during driver init and unload, don't want
  695. * to process any interrupts at that point
  696. */
  697. /* this is just a bandaid, not a fix, if something goes badly
  698. * wrong */
  699. if (++*unexpectp > 100) {
  700. if (++*unexpectp > 105) {
  701. /*
  702. * ok, we must be taking somebody else's interrupts,
  703. * due to a messed up mptable and/or PIRQ table, so
  704. * unregister the interrupt. We've seen this during
  705. * linuxbios development work, and it may happen in
  706. * the future again.
  707. */
  708. if (dd->pcidev && dd->ipath_irq) {
  709. ipath_dev_err(dd, "Now %u unexpected "
  710. "interrupts, unregistering "
  711. "interrupt handler\n",
  712. *unexpectp);
  713. ipath_dbg("free_irq of irq %d\n",
  714. dd->ipath_irq);
  715. dd->ipath_f_free_irq(dd);
  716. }
  717. }
  718. if (ipath_read_kreg32(dd, dd->ipath_kregs->kr_intmask)) {
  719. ipath_dev_err(dd, "%u unexpected interrupts, "
  720. "disabling interrupts completely\n",
  721. *unexpectp);
  722. /*
  723. * disable all interrupts, something is very wrong
  724. */
  725. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
  726. 0ULL);
  727. }
  728. } else if (*unexpectp > 1)
  729. ipath_dbg("Interrupt when not ready, should not happen, "
  730. "ignoring\n");
  731. }
  732. static void ipath_bad_regread(struct ipath_devdata *dd)
  733. {
  734. static int allbits;
  735. /* separate routine, for better optimization of ipath_intr() */
  736. /*
  737. * We print the message and disable interrupts, in hope of
  738. * having a better chance of debugging the problem.
  739. */
  740. ipath_dev_err(dd,
  741. "Read of interrupt status failed (all bits set)\n");
  742. if (allbits++) {
  743. /* disable all interrupts, something is very wrong */
  744. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
  745. if (allbits == 2) {
  746. ipath_dev_err(dd, "Still bad interrupt status, "
  747. "unregistering interrupt\n");
  748. dd->ipath_f_free_irq(dd);
  749. } else if (allbits > 2) {
  750. if ((allbits % 10000) == 0)
  751. printk(".");
  752. } else
  753. ipath_dev_err(dd, "Disabling interrupts, "
  754. "multiple errors\n");
  755. }
  756. }
  757. static void handle_port_pioavail(struct ipath_devdata *dd)
  758. {
  759. u32 i;
  760. /*
  761. * start from port 1, since for now port 0 is never using
  762. * wait_event for PIO
  763. */
  764. for (i = 1; dd->ipath_portpiowait && i < dd->ipath_cfgports; i++) {
  765. struct ipath_portdata *pd = dd->ipath_pd[i];
  766. if (pd && pd->port_cnt &&
  767. dd->ipath_portpiowait & (1U << i)) {
  768. clear_bit(i, &dd->ipath_portpiowait);
  769. if (test_bit(IPATH_PORT_WAITING_PIO,
  770. &pd->port_flag)) {
  771. clear_bit(IPATH_PORT_WAITING_PIO,
  772. &pd->port_flag);
  773. wake_up_interruptible(&pd->port_wait);
  774. }
  775. }
  776. }
  777. }
  778. static void handle_layer_pioavail(struct ipath_devdata *dd)
  779. {
  780. int ret;
  781. ret = ipath_ib_piobufavail(dd->verbs_dev);
  782. if (ret > 0)
  783. goto set;
  784. return;
  785. set:
  786. set_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
  787. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  788. dd->ipath_sendctrl);
  789. }
  790. /*
  791. * Handle receive interrupts for user ports; this means a user
  792. * process was waiting for a packet to arrive, and didn't want
  793. * to poll
  794. */
  795. static void handle_urcv(struct ipath_devdata *dd, u32 istat)
  796. {
  797. u64 portr;
  798. int i;
  799. int rcvdint = 0;
  800. portr = ((istat >> INFINIPATH_I_RCVAVAIL_SHIFT) &
  801. dd->ipath_i_rcvavail_mask)
  802. | ((istat >> INFINIPATH_I_RCVURG_SHIFT) &
  803. dd->ipath_i_rcvurg_mask);
  804. for (i = 1; i < dd->ipath_cfgports; i++) {
  805. struct ipath_portdata *pd = dd->ipath_pd[i];
  806. if (portr & (1 << i) && pd && pd->port_cnt &&
  807. test_bit(IPATH_PORT_WAITING_RCV, &pd->port_flag)) {
  808. clear_bit(IPATH_PORT_WAITING_RCV,
  809. &pd->port_flag);
  810. clear_bit(i + INFINIPATH_R_INTRAVAIL_SHIFT,
  811. &dd->ipath_rcvctrl);
  812. wake_up_interruptible(&pd->port_wait);
  813. rcvdint = 1;
  814. }
  815. }
  816. if (rcvdint) {
  817. /* only want to take one interrupt, so turn off the rcv
  818. * interrupt for all the ports that we did the wakeup on
  819. * (but never for kernel port)
  820. */
  821. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  822. dd->ipath_rcvctrl);
  823. }
  824. }
  825. irqreturn_t ipath_intr(int irq, void *data)
  826. {
  827. struct ipath_devdata *dd = data;
  828. u32 istat, chk0rcv = 0;
  829. ipath_err_t estat = 0;
  830. irqreturn_t ret;
  831. u32 oldhead, curtail;
  832. static unsigned unexpected = 0;
  833. static const u32 port0rbits = (1U<<INFINIPATH_I_RCVAVAIL_SHIFT) |
  834. (1U<<INFINIPATH_I_RCVURG_SHIFT);
  835. ipath_stats.sps_ints++;
  836. if (!(dd->ipath_flags & IPATH_PRESENT)) {
  837. /*
  838. * This return value is not great, but we do not want the
  839. * interrupt core code to remove our interrupt handler
  840. * because we don't appear to be handling an interrupt
  841. * during a chip reset.
  842. */
  843. return IRQ_HANDLED;
  844. }
  845. /*
  846. * this needs to be flags&initted, not statusp, so we keep
  847. * taking interrupts even after link goes down, etc.
  848. * Also, we *must* clear the interrupt at some point, or we won't
  849. * take it again, which can be real bad for errors, etc...
  850. */
  851. if (!(dd->ipath_flags & IPATH_INITTED)) {
  852. ipath_bad_intr(dd, &unexpected);
  853. ret = IRQ_NONE;
  854. goto bail;
  855. }
  856. /*
  857. * We try to avoid reading the interrupt status register, since
  858. * that's a PIO read, and stalls the processor for up to about
  859. * ~0.25 usec. The idea is that if we processed a port0 packet,
  860. * we blindly clear the port 0 receive interrupt bits, and nothing
  861. * else, then return. If other interrupts are pending, the chip
  862. * will re-interrupt us as soon as we write the intclear register.
  863. * We then won't process any more kernel packets (if not the 2nd
  864. * time, then the 3rd or 4th) and we'll then handle the other
  865. * interrupts. We clear the interrupts first so that we don't
  866. * lose intr for later packets that arrive while we are processing.
  867. */
  868. oldhead = dd->ipath_port0head;
  869. curtail = (u32)le64_to_cpu(*dd->ipath_hdrqtailptr);
  870. if (oldhead != curtail) {
  871. if (dd->ipath_flags & IPATH_GPIO_INTR) {
  872. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
  873. (u64) (1 << IPATH_GPIO_PORT0_BIT));
  874. istat = port0rbits | INFINIPATH_I_GPIO;
  875. }
  876. else
  877. istat = port0rbits;
  878. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, istat);
  879. ipath_kreceive(dd);
  880. if (oldhead != dd->ipath_port0head) {
  881. ipath_stats.sps_fastrcvint++;
  882. goto done;
  883. }
  884. }
  885. istat = ipath_read_kreg32(dd, dd->ipath_kregs->kr_intstatus);
  886. if (unlikely(!istat)) {
  887. ipath_stats.sps_nullintr++;
  888. ret = IRQ_NONE; /* not our interrupt, or already handled */
  889. goto bail;
  890. }
  891. if (unlikely(istat == -1)) {
  892. ipath_bad_regread(dd);
  893. /* don't know if it was our interrupt or not */
  894. ret = IRQ_NONE;
  895. goto bail;
  896. }
  897. if (unexpected)
  898. unexpected = 0;
  899. if (unlikely(istat & ~dd->ipath_i_bitsextant))
  900. ipath_dev_err(dd,
  901. "interrupt with unknown interrupts %x set\n",
  902. istat & (u32) ~ dd->ipath_i_bitsextant);
  903. else
  904. ipath_cdbg(VERBOSE, "intr stat=0x%x\n", istat);
  905. if (unlikely(istat & INFINIPATH_I_ERROR)) {
  906. ipath_stats.sps_errints++;
  907. estat = ipath_read_kreg64(dd,
  908. dd->ipath_kregs->kr_errorstatus);
  909. if (!estat)
  910. dev_info(&dd->pcidev->dev, "error interrupt (%x), "
  911. "but no error bits set!\n", istat);
  912. else if (estat == -1LL)
  913. /*
  914. * should we try clearing all, or hope next read
  915. * works?
  916. */
  917. ipath_dev_err(dd, "Read of error status failed "
  918. "(all bits set); ignoring\n");
  919. else
  920. if (handle_errors(dd, estat))
  921. /* force calling ipath_kreceive() */
  922. chk0rcv = 1;
  923. }
  924. if (istat & INFINIPATH_I_GPIO) {
  925. /*
  926. * GPIO interrupts fall in two broad classes:
  927. * GPIO_2 indicates (on some HT4xx boards) that a packet
  928. * has arrived for Port 0. Checking for this
  929. * is controlled by flag IPATH_GPIO_INTR.
  930. * GPIO_3..5 on IBA6120 Rev2 chips indicate errors
  931. * that we need to count. Checking for this
  932. * is controlled by flag IPATH_GPIO_ERRINTRS.
  933. */
  934. u32 gpiostatus;
  935. u32 to_clear = 0;
  936. gpiostatus = ipath_read_kreg32(
  937. dd, dd->ipath_kregs->kr_gpio_status);
  938. /* First the error-counter case.
  939. */
  940. if ((gpiostatus & IPATH_GPIO_ERRINTR_MASK) &&
  941. (dd->ipath_flags & IPATH_GPIO_ERRINTRS)) {
  942. /* want to clear the bits we see asserted. */
  943. to_clear |= (gpiostatus & IPATH_GPIO_ERRINTR_MASK);
  944. /*
  945. * Count appropriately, clear bits out of our copy,
  946. * as they have been "handled".
  947. */
  948. if (gpiostatus & (1 << IPATH_GPIO_RXUVL_BIT)) {
  949. ipath_dbg("FlowCtl on UnsupVL\n");
  950. dd->ipath_rxfc_unsupvl_errs++;
  951. }
  952. if (gpiostatus & (1 << IPATH_GPIO_OVRUN_BIT)) {
  953. ipath_dbg("Overrun Threshold exceeded\n");
  954. dd->ipath_overrun_thresh_errs++;
  955. }
  956. if (gpiostatus & (1 << IPATH_GPIO_LLI_BIT)) {
  957. ipath_dbg("Local Link Integrity error\n");
  958. dd->ipath_lli_errs++;
  959. }
  960. gpiostatus &= ~IPATH_GPIO_ERRINTR_MASK;
  961. }
  962. /* Now the Port0 Receive case */
  963. if ((gpiostatus & (1 << IPATH_GPIO_PORT0_BIT)) &&
  964. (dd->ipath_flags & IPATH_GPIO_INTR)) {
  965. /*
  966. * GPIO status bit 2 is set, and we expected it.
  967. * clear it and indicate in p0bits.
  968. * This probably only happens if a Port0 pkt
  969. * arrives at _just_ the wrong time, and we
  970. * handle that by seting chk0rcv;
  971. */
  972. to_clear |= (1 << IPATH_GPIO_PORT0_BIT);
  973. gpiostatus &= ~(1 << IPATH_GPIO_PORT0_BIT);
  974. chk0rcv = 1;
  975. }
  976. if (gpiostatus) {
  977. /*
  978. * Some unexpected bits remain. If they could have
  979. * caused the interrupt, complain and clear.
  980. * MEA: this is almost certainly non-ideal.
  981. * we should look into auto-disable of unexpected
  982. * GPIO interrupts, possibly on a "three strikes"
  983. * basis.
  984. */
  985. const u32 mask = (u32) dd->ipath_gpio_mask;
  986. if (mask & gpiostatus) {
  987. ipath_dbg("Unexpected GPIO IRQ bits %x\n",
  988. gpiostatus & mask);
  989. to_clear |= (gpiostatus & mask);
  990. }
  991. }
  992. if (to_clear) {
  993. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
  994. (u64) to_clear);
  995. }
  996. }
  997. chk0rcv |= istat & port0rbits;
  998. /*
  999. * Clear the interrupt bits we found set, unless they are receive
  1000. * related, in which case we already cleared them above, and don't
  1001. * want to clear them again, because we might lose an interrupt.
  1002. * Clear it early, so we "know" know the chip will have seen this by
  1003. * the time we process the queue, and will re-interrupt if necessary.
  1004. * The processor itself won't take the interrupt again until we return.
  1005. */
  1006. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, istat);
  1007. /*
  1008. * handle port0 receive before checking for pio buffers available,
  1009. * since receives can overflow; piobuf waiters can afford a few
  1010. * extra cycles, since they were waiting anyway, and user's waiting
  1011. * for receive are at the bottom.
  1012. */
  1013. if (chk0rcv) {
  1014. ipath_kreceive(dd);
  1015. istat &= ~port0rbits;
  1016. }
  1017. if (istat & ((dd->ipath_i_rcvavail_mask <<
  1018. INFINIPATH_I_RCVAVAIL_SHIFT)
  1019. | (dd->ipath_i_rcvurg_mask <<
  1020. INFINIPATH_I_RCVURG_SHIFT)))
  1021. handle_urcv(dd, istat);
  1022. if (istat & INFINIPATH_I_SPIOBUFAVAIL) {
  1023. clear_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
  1024. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  1025. dd->ipath_sendctrl);
  1026. if (dd->ipath_portpiowait)
  1027. handle_port_pioavail(dd);
  1028. handle_layer_pioavail(dd);
  1029. }
  1030. done:
  1031. ret = IRQ_HANDLED;
  1032. bail:
  1033. return ret;
  1034. }