ipath_intr.c 41 KB

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