ipath_intr.c 37 KB

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