ipath_intr.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. /*
  2. * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.
  3. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/pci.h>
  34. #include <linux/delay.h>
  35. #include <linux/sched.h>
  36. #include "ipath_kernel.h"
  37. #include "ipath_verbs.h"
  38. #include "ipath_common.h"
  39. /*
  40. * Called when we might have an error that is specific to a particular
  41. * PIO buffer, and may need to cancel that buffer, so it can be re-used.
  42. */
  43. void ipath_disarm_senderrbufs(struct ipath_devdata *dd)
  44. {
  45. u32 piobcnt;
  46. unsigned long sbuf[4];
  47. /*
  48. * it's possible that sendbuffererror could have bits set; might
  49. * have already done this as a result of hardware error handling
  50. */
  51. piobcnt = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
  52. /* read these before writing errorclear */
  53. sbuf[0] = ipath_read_kreg64(
  54. dd, dd->ipath_kregs->kr_sendbuffererror);
  55. sbuf[1] = ipath_read_kreg64(
  56. dd, dd->ipath_kregs->kr_sendbuffererror + 1);
  57. if (piobcnt > 128)
  58. sbuf[2] = ipath_read_kreg64(
  59. dd, dd->ipath_kregs->kr_sendbuffererror + 2);
  60. if (piobcnt > 192)
  61. sbuf[3] = ipath_read_kreg64(
  62. dd, dd->ipath_kregs->kr_sendbuffererror + 3);
  63. else
  64. sbuf[3] = 0;
  65. if (sbuf[0] || sbuf[1] || (piobcnt > 128 && (sbuf[2] || sbuf[3]))) {
  66. int i;
  67. if (ipath_debug & (__IPATH_PKTDBG|__IPATH_DBG) &&
  68. time_after(dd->ipath_lastcancel, jiffies)) {
  69. __IPATH_DBG_WHICH(__IPATH_PKTDBG|__IPATH_DBG,
  70. "SendbufErrs %lx %lx", sbuf[0],
  71. sbuf[1]);
  72. if (ipath_debug & __IPATH_PKTDBG && piobcnt > 128)
  73. printk(" %lx %lx ", sbuf[2], sbuf[3]);
  74. printk("\n");
  75. }
  76. for (i = 0; i < piobcnt; i++)
  77. if (test_bit(i, sbuf))
  78. ipath_disarm_piobufs(dd, i, 1);
  79. /* ignore armlaunch errs for a bit */
  80. dd->ipath_lastcancel = jiffies+3;
  81. }
  82. }
  83. /* These are all rcv-related errors which we want to count for stats */
  84. #define E_SUM_PKTERRS \
  85. (INFINIPATH_E_RHDRLEN | INFINIPATH_E_RBADTID | \
  86. INFINIPATH_E_RBADVERSION | INFINIPATH_E_RHDR | \
  87. INFINIPATH_E_RLONGPKTLEN | INFINIPATH_E_RSHORTPKTLEN | \
  88. INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RMINPKTLEN | \
  89. INFINIPATH_E_RFORMATERR | INFINIPATH_E_RUNSUPVL | \
  90. INFINIPATH_E_RUNEXPCHAR | INFINIPATH_E_REBP)
  91. /* These are all send-related errors which we want to count for stats */
  92. #define E_SUM_ERRS \
  93. (INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM | \
  94. INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
  95. INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SUNSUPVL | \
  96. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
  97. INFINIPATH_E_INVALIDADDR)
  98. /*
  99. * this is similar to E_SUM_ERRS, but can't ignore armlaunch, don't ignore
  100. * errors not related to freeze and cancelling buffers. Can't ignore
  101. * armlaunch because could get more while still cleaning up, and need
  102. * to cancel those as they happen.
  103. */
  104. #define E_SPKT_ERRS_IGNORE \
  105. (INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
  106. INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SMINPKTLEN | \
  107. INFINIPATH_E_SPKTLEN)
  108. /*
  109. * these are errors that can occur when the link changes state while
  110. * a packet is being sent or received. This doesn't cover things
  111. * like EBP or VCRC that can be the result of a sending having the
  112. * link change state, so we receive a "known bad" packet.
  113. */
  114. #define E_SUM_LINK_PKTERRS \
  115. (INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
  116. INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
  117. INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RMINPKTLEN | \
  118. INFINIPATH_E_RUNEXPCHAR)
  119. static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs)
  120. {
  121. u64 ignore_this_time = 0;
  122. ipath_disarm_senderrbufs(dd);
  123. if ((errs & E_SUM_LINK_PKTERRS) &&
  124. !(dd->ipath_flags & IPATH_LINKACTIVE)) {
  125. /*
  126. * This can happen when SMA is trying to bring the link
  127. * up, but the IB link changes state at the "wrong" time.
  128. * The IB logic then complains that the packet isn't
  129. * valid. We don't want to confuse people, so we just
  130. * don't print them, except at debug
  131. */
  132. ipath_dbg("Ignoring packet errors %llx, because link not "
  133. "ACTIVE\n", (unsigned long long) errs);
  134. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  135. }
  136. return ignore_this_time;
  137. }
  138. /* generic hw error messages... */
  139. #define INFINIPATH_HWE_TXEMEMPARITYERR_MSG(a) \
  140. { \
  141. .mask = ( INFINIPATH_HWE_TXEMEMPARITYERR_##a << \
  142. INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT ), \
  143. .msg = "TXE " #a " Memory Parity" \
  144. }
  145. #define INFINIPATH_HWE_RXEMEMPARITYERR_MSG(a) \
  146. { \
  147. .mask = ( INFINIPATH_HWE_RXEMEMPARITYERR_##a << \
  148. INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT ), \
  149. .msg = "RXE " #a " Memory Parity" \
  150. }
  151. static const struct ipath_hwerror_msgs ipath_generic_hwerror_msgs[] = {
  152. INFINIPATH_HWE_MSG(IBCBUSFRSPCPARITYERR, "IPATH2IB Parity"),
  153. INFINIPATH_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2IPATH Parity"),
  154. INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOBUF),
  155. INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOPBC),
  156. INFINIPATH_HWE_TXEMEMPARITYERR_MSG(PIOLAUNCHFIFO),
  157. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(RCVBUF),
  158. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(LOOKUPQ),
  159. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EAGERTID),
  160. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(EXPTID),
  161. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(FLAGBUF),
  162. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(DATAINFO),
  163. INFINIPATH_HWE_RXEMEMPARITYERR_MSG(HDRINFO),
  164. };
  165. /**
  166. * ipath_format_hwmsg - format a single hwerror message
  167. * @msg message buffer
  168. * @msgl length of message buffer
  169. * @hwmsg message to add to message buffer
  170. */
  171. static void ipath_format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
  172. {
  173. strlcat(msg, "[", msgl);
  174. strlcat(msg, hwmsg, msgl);
  175. strlcat(msg, "]", msgl);
  176. }
  177. /**
  178. * ipath_format_hwerrors - format hardware error messages for display
  179. * @hwerrs hardware errors bit vector
  180. * @hwerrmsgs hardware error descriptions
  181. * @nhwerrmsgs number of hwerrmsgs
  182. * @msg message buffer
  183. * @msgl message buffer length
  184. */
  185. void ipath_format_hwerrors(u64 hwerrs,
  186. const struct ipath_hwerror_msgs *hwerrmsgs,
  187. size_t nhwerrmsgs,
  188. char *msg, size_t msgl)
  189. {
  190. int i;
  191. const int glen =
  192. ARRAY_SIZE(ipath_generic_hwerror_msgs);
  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. time_after(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. }