ipath_intr.c 41 KB

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