ipath_intr.c 39 KB

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