ipath_intr.c 39 KB

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