ipath_intr.c 37 KB

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