ipath_intr.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  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. * Since going into a recovery state causes the link state to go
  274. * down and since recovery is transitory, it is better if we "miss"
  275. * ever seeing the link training state go into recovery (i.e.,
  276. * ignore this transition for link state special handling purposes)
  277. * without even updating ipath_lastibcstat.
  278. */
  279. if ((ltstate == INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN) ||
  280. (ltstate == INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT) ||
  281. (ltstate == INFINIPATH_IBCS_LT_STATE_RECOVERIDLE))
  282. goto done;
  283. /*
  284. * if linkstate transitions into INIT from any of the various down
  285. * states, or if it transitions from any of the up (INIT or better)
  286. * states into any of the down states (except link recovery), then
  287. * call the chip-specific code to take appropriate actions.
  288. */
  289. if (lstate >= INFINIPATH_IBCS_L_STATE_INIT &&
  290. lastlstate == INFINIPATH_IBCS_L_STATE_DOWN) {
  291. /* transitioned to UP */
  292. if (dd->ipath_f_ib_updown(dd, 1, ibcs)) {
  293. /* link came up, so we must no longer be disabled */
  294. dd->ipath_flags &= ~IPATH_IB_LINK_DISABLED;
  295. ipath_cdbg(LINKVERB, "LinkUp handled, skipped\n");
  296. goto skip_ibchange; /* chip-code handled */
  297. }
  298. } else if ((lastlstate >= INFINIPATH_IBCS_L_STATE_INIT ||
  299. (dd->ipath_flags & IPATH_IB_FORCE_NOTIFY)) &&
  300. ltstate <= INFINIPATH_IBCS_LT_STATE_CFGWAITRMT &&
  301. ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP) {
  302. int handled;
  303. handled = dd->ipath_f_ib_updown(dd, 0, ibcs);
  304. dd->ipath_flags &= ~IPATH_IB_FORCE_NOTIFY;
  305. if (handled) {
  306. ipath_cdbg(LINKVERB, "LinkDown handled, skipped\n");
  307. goto skip_ibchange; /* chip-code handled */
  308. }
  309. }
  310. /*
  311. * Significant enough to always print and get into logs, if it was
  312. * unexpected. If it was a requested state change, we'll have
  313. * already cleared the flags, so we won't print this warning
  314. */
  315. if ((ibstate != arm && ibstate != active) &&
  316. (dd->ipath_flags & (IPATH_LINKARMED | IPATH_LINKACTIVE))) {
  317. dev_info(&dd->pcidev->dev, "Link state changed from %s "
  318. "to %s\n", (dd->ipath_flags & IPATH_LINKARMED) ?
  319. "ARM" : "ACTIVE", ib_linkstate(dd, ibcs));
  320. }
  321. if (ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE ||
  322. ltstate == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
  323. u32 lastlts;
  324. lastlts = ipath_ib_linktrstate(dd, dd->ipath_lastibcstat);
  325. /*
  326. * Ignore cycling back and forth from Polling.Active to
  327. * Polling.Quiet while waiting for the other end of the link
  328. * to come up, except to try and decide if we are connected
  329. * to a live IB device or not. We will cycle back and
  330. * forth between them if no cable is plugged in, the other
  331. * device is powered off or disabled, etc.
  332. */
  333. if (lastlts == INFINIPATH_IBCS_LT_STATE_POLLACTIVE ||
  334. lastlts == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
  335. if (++dd->ipath_ibpollcnt == 40) {
  336. dd->ipath_flags |= IPATH_NOCABLE;
  337. *dd->ipath_statusp |=
  338. IPATH_STATUS_IB_NOCABLE;
  339. ipath_cdbg(LINKVERB, "Set NOCABLE\n");
  340. }
  341. ipath_cdbg(LINKVERB, "POLL change to %s (%x)\n",
  342. ipath_ibcstatus_str[ltstate], ibstate);
  343. goto skip_ibchange;
  344. }
  345. }
  346. dd->ipath_ibpollcnt = 0; /* not poll*, now */
  347. ipath_stats.sps_iblink++;
  348. if (ibstate != init && dd->ipath_lastlinkrecov && ipath_linkrecovery) {
  349. u64 linkrecov;
  350. linkrecov = ipath_snap_cntr(dd,
  351. dd->ipath_cregs->cr_iblinkerrrecovcnt);
  352. if (linkrecov != dd->ipath_lastlinkrecov) {
  353. ipath_dbg("IB linkrecov up %Lx (%s %s) recov %Lu\n",
  354. ibcs, ib_linkstate(dd, ibcs),
  355. ipath_ibcstatus_str[ltstate],
  356. linkrecov);
  357. /* and no more until active again */
  358. dd->ipath_lastlinkrecov = 0;
  359. ipath_set_linkstate(dd, IPATH_IB_LINKDOWN);
  360. goto skip_ibchange;
  361. }
  362. }
  363. if (ibstate == init || ibstate == arm || ibstate == active) {
  364. *dd->ipath_statusp &= ~IPATH_STATUS_IB_NOCABLE;
  365. if (ibstate == init || ibstate == arm) {
  366. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  367. if (dd->ipath_flags & IPATH_LINKACTIVE)
  368. signal_ib_event(dd, IB_EVENT_PORT_ERR);
  369. }
  370. if (ibstate == arm) {
  371. dd->ipath_flags |= IPATH_LINKARMED;
  372. dd->ipath_flags &= ~(IPATH_LINKUNK |
  373. IPATH_LINKINIT | IPATH_LINKDOWN |
  374. IPATH_LINKACTIVE | IPATH_NOCABLE);
  375. ipath_hol_down(dd);
  376. } else if (ibstate == init) {
  377. /*
  378. * set INIT and DOWN. Down is checked by
  379. * most of the other code, but INIT is
  380. * useful to know in a few places.
  381. */
  382. dd->ipath_flags |= IPATH_LINKINIT |
  383. IPATH_LINKDOWN;
  384. dd->ipath_flags &= ~(IPATH_LINKUNK |
  385. IPATH_LINKARMED | IPATH_LINKACTIVE |
  386. IPATH_NOCABLE);
  387. ipath_hol_down(dd);
  388. } else { /* active */
  389. dd->ipath_lastlinkrecov = ipath_snap_cntr(dd,
  390. dd->ipath_cregs->cr_iblinkerrrecovcnt);
  391. *dd->ipath_statusp |=
  392. IPATH_STATUS_IB_READY | IPATH_STATUS_IB_CONF;
  393. dd->ipath_flags |= IPATH_LINKACTIVE;
  394. dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
  395. | IPATH_LINKDOWN | IPATH_LINKARMED |
  396. IPATH_NOCABLE);
  397. signal_ib_event(dd, IB_EVENT_PORT_ACTIVE);
  398. /* LED active not handled in chip _f_updown */
  399. dd->ipath_f_setextled(dd, lstate, ltstate);
  400. ipath_hol_up(dd);
  401. }
  402. /*
  403. * print after we've already done the work, so as not to
  404. * delay the state changes and notifications, for debugging
  405. */
  406. if (lstate == lastlstate)
  407. ipath_cdbg(LINKVERB, "Unchanged from last: %s "
  408. "(%x)\n", ib_linkstate(dd, ibcs), ibstate);
  409. else
  410. ipath_cdbg(VERBOSE, "Unit %u: link up to %s %s (%x)\n",
  411. dd->ipath_unit, ib_linkstate(dd, ibcs),
  412. ipath_ibcstatus_str[ltstate], ibstate);
  413. } else { /* down */
  414. if (dd->ipath_flags & IPATH_LINKACTIVE)
  415. signal_ib_event(dd, IB_EVENT_PORT_ERR);
  416. dd->ipath_flags |= IPATH_LINKDOWN;
  417. dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
  418. | IPATH_LINKACTIVE |
  419. IPATH_LINKARMED);
  420. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  421. dd->ipath_lli_counter = 0;
  422. if (lastlstate != INFINIPATH_IBCS_L_STATE_DOWN)
  423. ipath_cdbg(VERBOSE, "Unit %u link state down "
  424. "(state 0x%x), from %s\n",
  425. dd->ipath_unit, lstate,
  426. ib_linkstate(dd, dd->ipath_lastibcstat));
  427. else
  428. ipath_cdbg(LINKVERB, "Unit %u link state changed "
  429. "to %s (0x%x) from down (%x)\n",
  430. dd->ipath_unit,
  431. ipath_ibcstatus_str[ltstate],
  432. ibstate, lastlstate);
  433. }
  434. skip_ibchange:
  435. dd->ipath_lastibcstat = ibcs;
  436. done:
  437. return;
  438. }
  439. static void handle_supp_msgs(struct ipath_devdata *dd,
  440. unsigned supp_msgs, char *msg, int msgsz)
  441. {
  442. /*
  443. * Print the message unless it's ibc status change only, which
  444. * happens so often we never want to count it.
  445. */
  446. if (dd->ipath_lasterror & ~INFINIPATH_E_IBSTATUSCHANGED) {
  447. int iserr;
  448. iserr = ipath_decode_err(msg, msgsz,
  449. dd->ipath_lasterror &
  450. ~INFINIPATH_E_IBSTATUSCHANGED);
  451. if (dd->ipath_lasterror &
  452. ~(INFINIPATH_E_RRCVEGRFULL |
  453. INFINIPATH_E_RRCVHDRFULL | INFINIPATH_E_PKTERRS))
  454. ipath_dev_err(dd, "Suppressed %u messages for "
  455. "fast-repeating errors (%s) (%llx)\n",
  456. supp_msgs, msg,
  457. (unsigned long long)
  458. dd->ipath_lasterror);
  459. else {
  460. /*
  461. * rcvegrfull and rcvhdrqfull are "normal", for some
  462. * types of processes (mostly benchmarks) that send
  463. * huge numbers of messages, while not processing
  464. * them. So only complain about these at debug
  465. * level.
  466. */
  467. if (iserr)
  468. ipath_dbg("Suppressed %u messages for %s\n",
  469. supp_msgs, msg);
  470. else
  471. ipath_cdbg(ERRPKT,
  472. "Suppressed %u messages for %s\n",
  473. supp_msgs, msg);
  474. }
  475. }
  476. }
  477. static unsigned handle_frequent_errors(struct ipath_devdata *dd,
  478. ipath_err_t errs, char *msg,
  479. int msgsz, int *noprint)
  480. {
  481. unsigned long nc;
  482. static unsigned long nextmsg_time;
  483. static unsigned nmsgs, supp_msgs;
  484. /*
  485. * Throttle back "fast" messages to no more than 10 per 5 seconds.
  486. * This isn't perfect, but it's a reasonable heuristic. If we get
  487. * more than 10, give a 6x longer delay.
  488. */
  489. nc = jiffies;
  490. if (nmsgs > 10) {
  491. if (time_before(nc, nextmsg_time)) {
  492. *noprint = 1;
  493. if (!supp_msgs++)
  494. nextmsg_time = nc + HZ * 3;
  495. }
  496. else if (supp_msgs) {
  497. handle_supp_msgs(dd, supp_msgs, msg, msgsz);
  498. supp_msgs = 0;
  499. nmsgs = 0;
  500. }
  501. }
  502. else if (!nmsgs++ || time_after(nc, nextmsg_time))
  503. nextmsg_time = nc + HZ / 2;
  504. return supp_msgs;
  505. }
  506. static int handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
  507. {
  508. char msg[128];
  509. u64 ignore_this_time = 0;
  510. int i, iserr = 0;
  511. int chkerrpkts = 0, noprint = 0;
  512. unsigned supp_msgs;
  513. int log_idx;
  514. supp_msgs = handle_frequent_errors(dd, errs, msg, sizeof msg, &noprint);
  515. /* don't report errors that are masked */
  516. errs &= ~dd->ipath_maskederrs;
  517. /* do these first, they are most important */
  518. if (errs & INFINIPATH_E_HARDWARE) {
  519. /* reuse same msg buf */
  520. dd->ipath_f_handle_hwerrors(dd, msg, sizeof msg);
  521. } else {
  522. u64 mask;
  523. for (log_idx = 0; log_idx < IPATH_EEP_LOG_CNT; ++log_idx) {
  524. mask = dd->ipath_eep_st_masks[log_idx].errs_to_log;
  525. if (errs & mask)
  526. ipath_inc_eeprom_err(dd, log_idx, 1);
  527. }
  528. }
  529. if (!noprint && (errs & ~dd->ipath_e_bitsextant))
  530. ipath_dev_err(dd, "error interrupt with unknown errors "
  531. "%llx set\n", (unsigned long long)
  532. (errs & ~dd->ipath_e_bitsextant));
  533. if (errs & E_SUM_ERRS)
  534. ignore_this_time = handle_e_sum_errs(dd, errs);
  535. else if ((errs & E_SUM_LINK_PKTERRS) &&
  536. !(dd->ipath_flags & IPATH_LINKACTIVE)) {
  537. /*
  538. * This can happen when SMA is trying to bring the link
  539. * up, but the IB link changes state at the "wrong" time.
  540. * The IB logic then complains that the packet isn't
  541. * valid. We don't want to confuse people, so we just
  542. * don't print them, except at debug
  543. */
  544. ipath_dbg("Ignoring packet errors %llx, because link not "
  545. "ACTIVE\n", (unsigned long long) errs);
  546. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  547. }
  548. if (supp_msgs == 250000) {
  549. int s_iserr;
  550. /*
  551. * It's not entirely reasonable assuming that the errors set
  552. * in the last clear period are all responsible for the
  553. * problem, but the alternative is to assume it's the only
  554. * ones on this particular interrupt, which also isn't great
  555. */
  556. dd->ipath_maskederrs |= dd->ipath_lasterror | errs;
  557. dd->ipath_errormask &= ~dd->ipath_maskederrs;
  558. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  559. dd->ipath_errormask);
  560. s_iserr = ipath_decode_err(msg, sizeof msg,
  561. dd->ipath_maskederrs);
  562. if (dd->ipath_maskederrs &
  563. ~(INFINIPATH_E_RRCVEGRFULL |
  564. INFINIPATH_E_RRCVHDRFULL | INFINIPATH_E_PKTERRS))
  565. ipath_dev_err(dd, "Temporarily disabling "
  566. "error(s) %llx reporting; too frequent (%s)\n",
  567. (unsigned long long) dd->ipath_maskederrs,
  568. msg);
  569. else {
  570. /*
  571. * rcvegrfull and rcvhdrqfull are "normal",
  572. * for some types of processes (mostly benchmarks)
  573. * that send huge numbers of messages, while not
  574. * processing them. So only complain about
  575. * these at debug level.
  576. */
  577. if (s_iserr)
  578. ipath_dbg("Temporarily disabling reporting "
  579. "too frequent queue full errors (%s)\n",
  580. msg);
  581. else
  582. ipath_cdbg(ERRPKT,
  583. "Temporarily disabling reporting too"
  584. " frequent packet errors (%s)\n",
  585. msg);
  586. }
  587. /*
  588. * Re-enable the masked errors after around 3 minutes. in
  589. * ipath_get_faststats(). If we have a series of fast
  590. * repeating but different errors, the interval will keep
  591. * stretching out, but that's OK, as that's pretty
  592. * catastrophic.
  593. */
  594. dd->ipath_unmasktime = jiffies + HZ * 180;
  595. }
  596. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, errs);
  597. if (ignore_this_time)
  598. errs &= ~ignore_this_time;
  599. if (errs & ~dd->ipath_lasterror) {
  600. errs &= ~dd->ipath_lasterror;
  601. /* never suppress duplicate hwerrors or ibstatuschange */
  602. dd->ipath_lasterror |= errs &
  603. ~(INFINIPATH_E_HARDWARE |
  604. INFINIPATH_E_IBSTATUSCHANGED);
  605. }
  606. /* likely due to cancel, so suppress */
  607. if ((errs & (INFINIPATH_E_SPKTLEN | INFINIPATH_E_SPIOARMLAUNCH)) &&
  608. dd->ipath_lastcancel > jiffies) {
  609. ipath_dbg("Suppressed armlaunch/spktlen after error send cancel\n");
  610. errs &= ~(INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SPKTLEN);
  611. }
  612. if (!errs)
  613. return 0;
  614. if (!noprint)
  615. /*
  616. * the ones we mask off are handled specially below or above
  617. */
  618. ipath_decode_err(msg, sizeof msg,
  619. errs & ~(INFINIPATH_E_IBSTATUSCHANGED |
  620. INFINIPATH_E_RRCVEGRFULL |
  621. INFINIPATH_E_RRCVHDRFULL |
  622. INFINIPATH_E_HARDWARE));
  623. else
  624. /* so we don't need if (!noprint) at strlcat's below */
  625. *msg = 0;
  626. if (errs & E_SUM_PKTERRS) {
  627. ipath_stats.sps_pkterrs++;
  628. chkerrpkts = 1;
  629. }
  630. if (errs & E_SUM_ERRS)
  631. ipath_stats.sps_errs++;
  632. if (errs & (INFINIPATH_E_RICRC | INFINIPATH_E_RVCRC)) {
  633. ipath_stats.sps_crcerrs++;
  634. chkerrpkts = 1;
  635. }
  636. iserr = errs & ~(E_SUM_PKTERRS | INFINIPATH_E_PKTERRS);
  637. /*
  638. * We don't want to print these two as they happen, or we can make
  639. * the situation even worse, because it takes so long to print
  640. * messages to serial consoles. Kernel ports get printed from
  641. * fast_stats, no more than every 5 seconds, user ports get printed
  642. * on close
  643. */
  644. if (errs & INFINIPATH_E_RRCVHDRFULL) {
  645. u32 hd, tl;
  646. ipath_stats.sps_hdrqfull++;
  647. for (i = 0; i < dd->ipath_cfgports; i++) {
  648. struct ipath_portdata *pd = dd->ipath_pd[i];
  649. if (i == 0) {
  650. hd = pd->port_head;
  651. tl = ipath_get_hdrqtail(pd);
  652. } else if (pd && pd->port_cnt &&
  653. pd->port_rcvhdrtail_kvaddr) {
  654. /*
  655. * don't report same point multiple times,
  656. * except kernel
  657. */
  658. tl = *(u64 *) pd->port_rcvhdrtail_kvaddr;
  659. if (tl == pd->port_lastrcvhdrqtail)
  660. continue;
  661. hd = ipath_read_ureg32(dd, ur_rcvhdrhead,
  662. i);
  663. } else
  664. continue;
  665. if (hd == (tl + 1) ||
  666. (!hd && tl == dd->ipath_hdrqlast)) {
  667. if (i == 0)
  668. chkerrpkts = 1;
  669. pd->port_lastrcvhdrqtail = tl;
  670. pd->port_hdrqfull++;
  671. /* flush hdrqfull so that poll() sees it */
  672. wmb();
  673. wake_up_interruptible(&pd->port_wait);
  674. }
  675. }
  676. }
  677. if (errs & INFINIPATH_E_RRCVEGRFULL) {
  678. struct ipath_portdata *pd = dd->ipath_pd[0];
  679. /*
  680. * since this is of less importance and not likely to
  681. * happen without also getting hdrfull, only count
  682. * occurrences; don't check each port (or even the kernel
  683. * vs user)
  684. */
  685. ipath_stats.sps_etidfull++;
  686. if (pd->port_head != ipath_get_hdrqtail(pd))
  687. chkerrpkts = 1;
  688. }
  689. /*
  690. * do this before IBSTATUSCHANGED, in case both bits set in a single
  691. * interrupt; we want the STATUSCHANGE to "win", so we do our
  692. * internal copy of state machine correctly
  693. */
  694. if (errs & INFINIPATH_E_RIBLOSTLINK) {
  695. /*
  696. * force through block below
  697. */
  698. errs |= INFINIPATH_E_IBSTATUSCHANGED;
  699. ipath_stats.sps_iblink++;
  700. dd->ipath_flags |= IPATH_LINKDOWN;
  701. dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
  702. | IPATH_LINKARMED | IPATH_LINKACTIVE);
  703. *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
  704. ipath_dbg("Lost link, link now down (%s)\n",
  705. ipath_ibcstatus_str[ipath_read_kreg64(dd,
  706. dd->ipath_kregs->kr_ibcstatus) & 0xf]);
  707. }
  708. if (errs & INFINIPATH_E_IBSTATUSCHANGED)
  709. handle_e_ibstatuschanged(dd, errs);
  710. if (errs & INFINIPATH_E_RESET) {
  711. if (!noprint)
  712. ipath_dev_err(dd, "Got reset, requires re-init "
  713. "(unload and reload driver)\n");
  714. dd->ipath_flags &= ~IPATH_INITTED; /* needs re-init */
  715. /* mark as having had error */
  716. *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
  717. *dd->ipath_statusp &= ~IPATH_STATUS_IB_CONF;
  718. }
  719. if (!noprint && *msg) {
  720. if (iserr)
  721. ipath_dev_err(dd, "%s error\n", msg);
  722. else
  723. dev_info(&dd->pcidev->dev, "%s packet problems\n",
  724. msg);
  725. }
  726. if (dd->ipath_state_wanted & dd->ipath_flags) {
  727. ipath_cdbg(VERBOSE, "driver wanted state %x, iflags now %x, "
  728. "waking\n", dd->ipath_state_wanted,
  729. dd->ipath_flags);
  730. wake_up_interruptible(&ipath_state_wait);
  731. }
  732. return chkerrpkts;
  733. }
  734. /*
  735. * try to cleanup as much as possible for anything that might have gone
  736. * wrong while in freeze mode, such as pio buffers being written by user
  737. * processes (causing armlaunch), send errors due to going into freeze mode,
  738. * etc., and try to avoid causing extra interrupts while doing so.
  739. * Forcibly update the in-memory pioavail register copies after cleanup
  740. * because the chip won't do it for anything changing while in freeze mode
  741. * (we don't want to wait for the next pio buffer state change).
  742. * Make sure that we don't lose any important interrupts by using the chip
  743. * feature that says that writing 0 to a bit in *clear that is set in
  744. * *status will cause an interrupt to be generated again (if allowed by
  745. * the *mask value).
  746. */
  747. void ipath_clear_freeze(struct ipath_devdata *dd)
  748. {
  749. int i, im;
  750. u64 val;
  751. /* disable error interrupts, to avoid confusion */
  752. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask, 0ULL);
  753. /* also disable interrupts; errormask is sometimes overwriten */
  754. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
  755. /*
  756. * clear all sends, because they have may been
  757. * completed by usercode while in freeze mode, and
  758. * therefore would not be sent, and eventually
  759. * might cause the process to run out of bufs
  760. */
  761. ipath_cancel_sends(dd, 0);
  762. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  763. dd->ipath_control);
  764. /* ensure pio avail updates continue */
  765. ipath_force_pio_avail_update(dd);
  766. /*
  767. * We just enabled pioavailupdate, so dma copy is almost certainly
  768. * not yet right, so read the registers directly. Similar to init
  769. */
  770. for (i = 0; i < dd->ipath_pioavregs; i++) {
  771. /* deal with 6110 chip bug */
  772. im = (i > 3 && (dd->ipath_flags & IPATH_SWAP_PIOBUFS)) ?
  773. i ^ 1 : i;
  774. val = ipath_read_kreg64(dd, (0x1000 / sizeof(u64)) + im);
  775. dd->ipath_pioavailregs_dma[i] = cpu_to_le64(val);
  776. dd->ipath_pioavailshadow[i] = val |
  777. (~dd->ipath_pioavailkernel[i] <<
  778. INFINIPATH_SENDPIOAVAIL_BUSY_SHIFT);
  779. }
  780. /*
  781. * force new interrupt if any hwerr, error or interrupt bits are
  782. * still set, and clear "safe" send packet errors related to freeze
  783. * and cancelling sends. Re-enable error interrupts before possible
  784. * force of re-interrupt on pending interrupts.
  785. */
  786. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear, 0ULL);
  787. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear,
  788. E_SPKT_ERRS_IGNORE);
  789. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  790. dd->ipath_errormask);
  791. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, -1LL);
  792. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);
  793. }
  794. /* this is separate to allow for better optimization of ipath_intr() */
  795. static noinline void ipath_bad_intr(struct ipath_devdata *dd, u32 *unexpectp)
  796. {
  797. /*
  798. * sometimes happen during driver init and unload, don't want
  799. * to process any interrupts at that point
  800. */
  801. /* this is just a bandaid, not a fix, if something goes badly
  802. * wrong */
  803. if (++*unexpectp > 100) {
  804. if (++*unexpectp > 105) {
  805. /*
  806. * ok, we must be taking somebody else's interrupts,
  807. * due to a messed up mptable and/or PIRQ table, so
  808. * unregister the interrupt. We've seen this during
  809. * linuxbios development work, and it may happen in
  810. * the future again.
  811. */
  812. if (dd->pcidev && dd->ipath_irq) {
  813. ipath_dev_err(dd, "Now %u unexpected "
  814. "interrupts, unregistering "
  815. "interrupt handler\n",
  816. *unexpectp);
  817. ipath_dbg("free_irq of irq %d\n",
  818. dd->ipath_irq);
  819. dd->ipath_f_free_irq(dd);
  820. }
  821. }
  822. if (ipath_read_ireg(dd, dd->ipath_kregs->kr_intmask)) {
  823. ipath_dev_err(dd, "%u unexpected interrupts, "
  824. "disabling interrupts completely\n",
  825. *unexpectp);
  826. /*
  827. * disable all interrupts, something is very wrong
  828. */
  829. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
  830. 0ULL);
  831. }
  832. } else if (*unexpectp > 1)
  833. ipath_dbg("Interrupt when not ready, should not happen, "
  834. "ignoring\n");
  835. }
  836. static noinline void ipath_bad_regread(struct ipath_devdata *dd)
  837. {
  838. static int allbits;
  839. /* separate routine, for better optimization of ipath_intr() */
  840. /*
  841. * We print the message and disable interrupts, in hope of
  842. * having a better chance of debugging the problem.
  843. */
  844. ipath_dev_err(dd,
  845. "Read of interrupt status failed (all bits set)\n");
  846. if (allbits++) {
  847. /* disable all interrupts, something is very wrong */
  848. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
  849. if (allbits == 2) {
  850. ipath_dev_err(dd, "Still bad interrupt status, "
  851. "unregistering interrupt\n");
  852. dd->ipath_f_free_irq(dd);
  853. } else if (allbits > 2) {
  854. if ((allbits % 10000) == 0)
  855. printk(".");
  856. } else
  857. ipath_dev_err(dd, "Disabling interrupts, "
  858. "multiple errors\n");
  859. }
  860. }
  861. static void handle_layer_pioavail(struct ipath_devdata *dd)
  862. {
  863. unsigned long flags;
  864. int ret;
  865. ret = ipath_ib_piobufavail(dd->verbs_dev);
  866. if (ret > 0)
  867. goto set;
  868. return;
  869. set:
  870. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  871. dd->ipath_sendctrl |= INFINIPATH_S_PIOINTBUFAVAIL;
  872. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  873. dd->ipath_sendctrl);
  874. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  875. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  876. }
  877. /*
  878. * Handle receive interrupts for user ports; this means a user
  879. * process was waiting for a packet to arrive, and didn't want
  880. * to poll
  881. */
  882. static void handle_urcv(struct ipath_devdata *dd, u64 istat)
  883. {
  884. u64 portr;
  885. int i;
  886. int rcvdint = 0;
  887. /*
  888. * test_and_clear_bit(IPATH_PORT_WAITING_RCV) and
  889. * test_and_clear_bit(IPATH_PORT_WAITING_URG) below
  890. * would both like timely updates of the bits so that
  891. * we don't pass them by unnecessarily. the rmb()
  892. * here ensures that we see them promptly -- the
  893. * corresponding wmb()'s are in ipath_poll_urgent()
  894. * and ipath_poll_next()...
  895. */
  896. rmb();
  897. portr = ((istat >> dd->ipath_i_rcvavail_shift) &
  898. dd->ipath_i_rcvavail_mask) |
  899. ((istat >> dd->ipath_i_rcvurg_shift) &
  900. dd->ipath_i_rcvurg_mask);
  901. for (i = 1; i < dd->ipath_cfgports; i++) {
  902. struct ipath_portdata *pd = dd->ipath_pd[i];
  903. if (portr & (1 << i) && pd && pd->port_cnt) {
  904. if (test_and_clear_bit(IPATH_PORT_WAITING_RCV,
  905. &pd->port_flag)) {
  906. clear_bit(i + dd->ipath_r_intravail_shift,
  907. &dd->ipath_rcvctrl);
  908. wake_up_interruptible(&pd->port_wait);
  909. rcvdint = 1;
  910. } else if (test_and_clear_bit(IPATH_PORT_WAITING_URG,
  911. &pd->port_flag)) {
  912. pd->port_urgent++;
  913. wake_up_interruptible(&pd->port_wait);
  914. }
  915. }
  916. }
  917. if (rcvdint) {
  918. /* only want to take one interrupt, so turn off the rcv
  919. * interrupt for all the ports that we set the rcv_waiting
  920. * (but never for kernel port)
  921. */
  922. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  923. dd->ipath_rcvctrl);
  924. }
  925. }
  926. irqreturn_t ipath_intr(int irq, void *data)
  927. {
  928. struct ipath_devdata *dd = data;
  929. u32 istat, chk0rcv = 0;
  930. ipath_err_t estat = 0;
  931. irqreturn_t ret;
  932. static unsigned unexpected = 0;
  933. u64 kportrbits;
  934. ipath_stats.sps_ints++;
  935. if (dd->ipath_int_counter != (u32) -1)
  936. dd->ipath_int_counter++;
  937. if (!(dd->ipath_flags & IPATH_PRESENT)) {
  938. /*
  939. * This return value is not great, but we do not want the
  940. * interrupt core code to remove our interrupt handler
  941. * because we don't appear to be handling an interrupt
  942. * during a chip reset.
  943. */
  944. return IRQ_HANDLED;
  945. }
  946. /*
  947. * this needs to be flags&initted, not statusp, so we keep
  948. * taking interrupts even after link goes down, etc.
  949. * Also, we *must* clear the interrupt at some point, or we won't
  950. * take it again, which can be real bad for errors, etc...
  951. */
  952. if (!(dd->ipath_flags & IPATH_INITTED)) {
  953. ipath_bad_intr(dd, &unexpected);
  954. ret = IRQ_NONE;
  955. goto bail;
  956. }
  957. istat = ipath_read_ireg(dd, dd->ipath_kregs->kr_intstatus);
  958. if (unlikely(!istat)) {
  959. ipath_stats.sps_nullintr++;
  960. ret = IRQ_NONE; /* not our interrupt, or already handled */
  961. goto bail;
  962. }
  963. if (unlikely(istat == -1)) {
  964. ipath_bad_regread(dd);
  965. /* don't know if it was our interrupt or not */
  966. ret = IRQ_NONE;
  967. goto bail;
  968. }
  969. if (unexpected)
  970. unexpected = 0;
  971. if (unlikely(istat & ~dd->ipath_i_bitsextant))
  972. ipath_dev_err(dd,
  973. "interrupt with unknown interrupts %x set\n",
  974. istat & (u32) ~ dd->ipath_i_bitsextant);
  975. else
  976. ipath_cdbg(VERBOSE, "intr stat=0x%x\n", istat);
  977. if (unlikely(istat & INFINIPATH_I_ERROR)) {
  978. ipath_stats.sps_errints++;
  979. estat = ipath_read_kreg64(dd,
  980. dd->ipath_kregs->kr_errorstatus);
  981. if (!estat)
  982. dev_info(&dd->pcidev->dev, "error interrupt (%x), "
  983. "but no error bits set!\n", istat);
  984. else if (estat == -1LL)
  985. /*
  986. * should we try clearing all, or hope next read
  987. * works?
  988. */
  989. ipath_dev_err(dd, "Read of error status failed "
  990. "(all bits set); ignoring\n");
  991. else
  992. chk0rcv |= handle_errors(dd, estat);
  993. }
  994. if (istat & INFINIPATH_I_GPIO) {
  995. /*
  996. * GPIO interrupts fall in two broad classes:
  997. * GPIO_2 indicates (on some HT4xx boards) that a packet
  998. * has arrived for Port 0. Checking for this
  999. * is controlled by flag IPATH_GPIO_INTR.
  1000. * GPIO_3..5 on IBA6120 Rev2 and IBA6110 Rev4 chips indicate
  1001. * errors that we need to count. Checking for this
  1002. * is controlled by flag IPATH_GPIO_ERRINTRS.
  1003. */
  1004. u32 gpiostatus;
  1005. u32 to_clear = 0;
  1006. gpiostatus = ipath_read_kreg32(
  1007. dd, dd->ipath_kregs->kr_gpio_status);
  1008. /* First the error-counter case. */
  1009. if ((gpiostatus & IPATH_GPIO_ERRINTR_MASK) &&
  1010. (dd->ipath_flags & IPATH_GPIO_ERRINTRS)) {
  1011. /* want to clear the bits we see asserted. */
  1012. to_clear |= (gpiostatus & IPATH_GPIO_ERRINTR_MASK);
  1013. /*
  1014. * Count appropriately, clear bits out of our copy,
  1015. * as they have been "handled".
  1016. */
  1017. if (gpiostatus & (1 << IPATH_GPIO_RXUVL_BIT)) {
  1018. ipath_dbg("FlowCtl on UnsupVL\n");
  1019. dd->ipath_rxfc_unsupvl_errs++;
  1020. }
  1021. if (gpiostatus & (1 << IPATH_GPIO_OVRUN_BIT)) {
  1022. ipath_dbg("Overrun Threshold exceeded\n");
  1023. dd->ipath_overrun_thresh_errs++;
  1024. }
  1025. if (gpiostatus & (1 << IPATH_GPIO_LLI_BIT)) {
  1026. ipath_dbg("Local Link Integrity error\n");
  1027. dd->ipath_lli_errs++;
  1028. }
  1029. gpiostatus &= ~IPATH_GPIO_ERRINTR_MASK;
  1030. }
  1031. /* Now the Port0 Receive case */
  1032. if ((gpiostatus & (1 << IPATH_GPIO_PORT0_BIT)) &&
  1033. (dd->ipath_flags & IPATH_GPIO_INTR)) {
  1034. /*
  1035. * GPIO status bit 2 is set, and we expected it.
  1036. * clear it and indicate in p0bits.
  1037. * This probably only happens if a Port0 pkt
  1038. * arrives at _just_ the wrong time, and we
  1039. * handle that by seting chk0rcv;
  1040. */
  1041. to_clear |= (1 << IPATH_GPIO_PORT0_BIT);
  1042. gpiostatus &= ~(1 << IPATH_GPIO_PORT0_BIT);
  1043. chk0rcv = 1;
  1044. }
  1045. if (gpiostatus) {
  1046. /*
  1047. * Some unexpected bits remain. If they could have
  1048. * caused the interrupt, complain and clear.
  1049. * To avoid repetition of this condition, also clear
  1050. * the mask. It is almost certainly due to error.
  1051. */
  1052. const u32 mask = (u32) dd->ipath_gpio_mask;
  1053. if (mask & gpiostatus) {
  1054. ipath_dbg("Unexpected GPIO IRQ bits %x\n",
  1055. gpiostatus & mask);
  1056. to_clear |= (gpiostatus & mask);
  1057. dd->ipath_gpio_mask &= ~(gpiostatus & mask);
  1058. ipath_write_kreg(dd,
  1059. dd->ipath_kregs->kr_gpio_mask,
  1060. dd->ipath_gpio_mask);
  1061. }
  1062. }
  1063. if (to_clear) {
  1064. ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
  1065. (u64) to_clear);
  1066. }
  1067. }
  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 kernel receive queues before checking for pio buffers
  1079. * available since receives can overflow; piobuf waiters can afford
  1080. * a few extra cycles, since they were waiting anyway, and user's
  1081. * waiting for receive are at the bottom.
  1082. */
  1083. kportrbits = (1ULL << dd->ipath_i_rcvavail_shift) |
  1084. (1ULL << dd->ipath_i_rcvurg_shift);
  1085. if (chk0rcv || (istat & kportrbits)) {
  1086. istat &= ~kportrbits;
  1087. ipath_kreceive(dd->ipath_pd[0]);
  1088. }
  1089. if (istat & ((dd->ipath_i_rcvavail_mask << dd->ipath_i_rcvavail_shift) |
  1090. (dd->ipath_i_rcvurg_mask << dd->ipath_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. }