ipath_intr.c 37 KB

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