qib_intr.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.
  3. * All rights reserved.
  4. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/pci.h>
  35. #include <linux/delay.h>
  36. #include "qib.h"
  37. #include "qib_common.h"
  38. /**
  39. * qib_format_hwmsg - format a single hwerror message
  40. * @msg message buffer
  41. * @msgl length of message buffer
  42. * @hwmsg message to add to message buffer
  43. */
  44. static void qib_format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
  45. {
  46. strlcat(msg, "[", msgl);
  47. strlcat(msg, hwmsg, msgl);
  48. strlcat(msg, "]", msgl);
  49. }
  50. /**
  51. * qib_format_hwerrors - format hardware error messages for display
  52. * @hwerrs hardware errors bit vector
  53. * @hwerrmsgs hardware error descriptions
  54. * @nhwerrmsgs number of hwerrmsgs
  55. * @msg message buffer
  56. * @msgl message buffer length
  57. */
  58. void qib_format_hwerrors(u64 hwerrs, const struct qib_hwerror_msgs *hwerrmsgs,
  59. size_t nhwerrmsgs, char *msg, size_t msgl)
  60. {
  61. int i;
  62. for (i = 0; i < nhwerrmsgs; i++)
  63. if (hwerrs & hwerrmsgs[i].mask)
  64. qib_format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
  65. }
  66. static void signal_ib_event(struct qib_pportdata *ppd, enum ib_event_type ev)
  67. {
  68. struct ib_event event;
  69. struct qib_devdata *dd = ppd->dd;
  70. event.device = &dd->verbs_dev.ibdev;
  71. event.element.port_num = ppd->port;
  72. event.event = ev;
  73. ib_dispatch_event(&event);
  74. }
  75. void qib_handle_e_ibstatuschanged(struct qib_pportdata *ppd, u64 ibcs)
  76. {
  77. struct qib_devdata *dd = ppd->dd;
  78. unsigned long flags;
  79. u32 lstate;
  80. u8 ltstate;
  81. enum ib_event_type ev = 0;
  82. lstate = dd->f_iblink_state(ibcs); /* linkstate */
  83. ltstate = dd->f_ibphys_portstate(ibcs);
  84. /*
  85. * If linkstate transitions into INIT from any of the various down
  86. * states, or if it transitions from any of the up (INIT or better)
  87. * states into any of the down states (except link recovery), then
  88. * call the chip-specific code to take appropriate actions.
  89. */
  90. if (lstate >= IB_PORT_INIT && (ppd->lflags & QIBL_LINKDOWN) &&
  91. ltstate == IB_PHYSPORTSTATE_LINKUP) {
  92. /* transitioned to UP */
  93. if (dd->f_ib_updown(ppd, 1, ibcs))
  94. goto skip_ibchange; /* chip-code handled */
  95. } else if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  96. QIBL_LINKACTIVE | QIBL_IB_FORCE_NOTIFY)) {
  97. if (ltstate != IB_PHYSPORTSTATE_LINKUP &&
  98. ltstate <= IB_PHYSPORTSTATE_CFG_TRAIN &&
  99. dd->f_ib_updown(ppd, 0, ibcs))
  100. goto skip_ibchange; /* chip-code handled */
  101. qib_set_uevent_bits(ppd, _QIB_EVENT_LINKDOWN_BIT);
  102. }
  103. if (lstate != IB_PORT_DOWN) {
  104. /* lstate is INIT, ARMED, or ACTIVE */
  105. if (lstate != IB_PORT_ACTIVE) {
  106. *ppd->statusp &= ~QIB_STATUS_IB_READY;
  107. if (ppd->lflags & QIBL_LINKACTIVE)
  108. ev = IB_EVENT_PORT_ERR;
  109. spin_lock_irqsave(&ppd->lflags_lock, flags);
  110. if (lstate == IB_PORT_ARMED) {
  111. ppd->lflags |= QIBL_LINKARMED | QIBL_LINKV;
  112. ppd->lflags &= ~(QIBL_LINKINIT |
  113. QIBL_LINKDOWN | QIBL_LINKACTIVE);
  114. } else {
  115. ppd->lflags |= QIBL_LINKINIT | QIBL_LINKV;
  116. ppd->lflags &= ~(QIBL_LINKARMED |
  117. QIBL_LINKDOWN | QIBL_LINKACTIVE);
  118. }
  119. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  120. /* start a 75msec timer to clear symbol errors */
  121. mod_timer(&ppd->symerr_clear_timer,
  122. msecs_to_jiffies(75));
  123. } else if (ltstate == IB_PHYSPORTSTATE_LINKUP &&
  124. !(ppd->lflags & QIBL_LINKACTIVE)) {
  125. /* active, but not active defered */
  126. qib_hol_up(ppd); /* useful only for 6120 now */
  127. *ppd->statusp |=
  128. QIB_STATUS_IB_READY | QIB_STATUS_IB_CONF;
  129. qib_clear_symerror_on_linkup((unsigned long)ppd);
  130. spin_lock_irqsave(&ppd->lflags_lock, flags);
  131. ppd->lflags |= QIBL_LINKACTIVE | QIBL_LINKV;
  132. ppd->lflags &= ~(QIBL_LINKINIT |
  133. QIBL_LINKDOWN | QIBL_LINKARMED);
  134. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  135. if (dd->flags & QIB_HAS_SEND_DMA)
  136. qib_sdma_process_event(ppd,
  137. qib_sdma_event_e30_go_running);
  138. ev = IB_EVENT_PORT_ACTIVE;
  139. dd->f_setextled(ppd, 1);
  140. }
  141. } else { /* down */
  142. if (ppd->lflags & QIBL_LINKACTIVE)
  143. ev = IB_EVENT_PORT_ERR;
  144. spin_lock_irqsave(&ppd->lflags_lock, flags);
  145. ppd->lflags |= QIBL_LINKDOWN | QIBL_LINKV;
  146. ppd->lflags &= ~(QIBL_LINKINIT |
  147. QIBL_LINKACTIVE | QIBL_LINKARMED);
  148. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  149. *ppd->statusp &= ~QIB_STATUS_IB_READY;
  150. }
  151. skip_ibchange:
  152. ppd->lastibcstat = ibcs;
  153. if (ev)
  154. signal_ib_event(ppd, ev);
  155. return;
  156. }
  157. void qib_clear_symerror_on_linkup(unsigned long opaque)
  158. {
  159. struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
  160. if (ppd->lflags & QIBL_LINKACTIVE)
  161. return;
  162. ppd->ibport_data.z_symbol_error_counter =
  163. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBSYMBOLERR);
  164. }
  165. /*
  166. * Handle receive interrupts for user ctxts; this means a user
  167. * process was waiting for a packet to arrive, and didn't want
  168. * to poll.
  169. */
  170. void qib_handle_urcv(struct qib_devdata *dd, u64 ctxtr)
  171. {
  172. struct qib_ctxtdata *rcd;
  173. unsigned long flags;
  174. int i;
  175. spin_lock_irqsave(&dd->uctxt_lock, flags);
  176. for (i = dd->first_user_ctxt; dd->rcd && i < dd->cfgctxts; i++) {
  177. if (!(ctxtr & (1ULL << i)))
  178. continue;
  179. rcd = dd->rcd[i];
  180. if (!rcd || !rcd->cnt)
  181. continue;
  182. if (test_and_clear_bit(QIB_CTXT_WAITING_RCV, &rcd->flag)) {
  183. wake_up_interruptible(&rcd->wait);
  184. dd->f_rcvctrl(rcd->ppd, QIB_RCVCTRL_INTRAVAIL_DIS,
  185. rcd->ctxt);
  186. } else if (test_and_clear_bit(QIB_CTXT_WAITING_URG,
  187. &rcd->flag)) {
  188. rcd->urgent++;
  189. wake_up_interruptible(&rcd->wait);
  190. }
  191. }
  192. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  193. }
  194. void qib_bad_intrstatus(struct qib_devdata *dd)
  195. {
  196. static int allbits;
  197. /* separate routine, for better optimization of qib_intr() */
  198. /*
  199. * We print the message and disable interrupts, in hope of
  200. * having a better chance of debugging the problem.
  201. */
  202. qib_dev_err(dd, "Read of chip interrupt status failed"
  203. " disabling interrupts\n");
  204. if (allbits++) {
  205. /* disable interrupt delivery, something is very wrong */
  206. if (allbits == 2)
  207. dd->f_set_intr_state(dd, 0);
  208. if (allbits == 3) {
  209. qib_dev_err(dd, "2nd bad interrupt status, "
  210. "unregistering interrupts\n");
  211. dd->flags |= QIB_BADINTR;
  212. dd->flags &= ~QIB_INITTED;
  213. dd->f_free_irq(dd);
  214. }
  215. }
  216. }