ipath_intr.c 39 KB

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