ipath_intr.c 37 KB

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