qib_intr.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. * ppd->lflags could be 0 if this is the first time the interrupt
  91. * handlers has been called but the link is already up.
  92. */
  93. if (lstate >= IB_PORT_INIT &&
  94. (!ppd->lflags || (ppd->lflags & QIBL_LINKDOWN)) &&
  95. ltstate == IB_PHYSPORTSTATE_LINKUP) {
  96. /* transitioned to UP */
  97. if (dd->f_ib_updown(ppd, 1, ibcs))
  98. goto skip_ibchange; /* chip-code handled */
  99. } else if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  100. QIBL_LINKACTIVE | QIBL_IB_FORCE_NOTIFY)) {
  101. if (ltstate != IB_PHYSPORTSTATE_LINKUP &&
  102. ltstate <= IB_PHYSPORTSTATE_CFG_TRAIN &&
  103. dd->f_ib_updown(ppd, 0, ibcs))
  104. goto skip_ibchange; /* chip-code handled */
  105. qib_set_uevent_bits(ppd, _QIB_EVENT_LINKDOWN_BIT);
  106. }
  107. if (lstate != IB_PORT_DOWN) {
  108. /* lstate is INIT, ARMED, or ACTIVE */
  109. if (lstate != IB_PORT_ACTIVE) {
  110. *ppd->statusp &= ~QIB_STATUS_IB_READY;
  111. if (ppd->lflags & QIBL_LINKACTIVE)
  112. ev = IB_EVENT_PORT_ERR;
  113. spin_lock_irqsave(&ppd->lflags_lock, flags);
  114. if (lstate == IB_PORT_ARMED) {
  115. ppd->lflags |= QIBL_LINKARMED | QIBL_LINKV;
  116. ppd->lflags &= ~(QIBL_LINKINIT |
  117. QIBL_LINKDOWN | QIBL_LINKACTIVE);
  118. } else {
  119. ppd->lflags |= QIBL_LINKINIT | QIBL_LINKV;
  120. ppd->lflags &= ~(QIBL_LINKARMED |
  121. QIBL_LINKDOWN | QIBL_LINKACTIVE);
  122. }
  123. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  124. /* start a 75msec timer to clear symbol errors */
  125. mod_timer(&ppd->symerr_clear_timer,
  126. msecs_to_jiffies(75));
  127. } else if (ltstate == IB_PHYSPORTSTATE_LINKUP &&
  128. !(ppd->lflags & QIBL_LINKACTIVE)) {
  129. /* active, but not active defered */
  130. qib_hol_up(ppd); /* useful only for 6120 now */
  131. *ppd->statusp |=
  132. QIB_STATUS_IB_READY | QIB_STATUS_IB_CONF;
  133. qib_clear_symerror_on_linkup((unsigned long)ppd);
  134. spin_lock_irqsave(&ppd->lflags_lock, flags);
  135. ppd->lflags |= QIBL_LINKACTIVE | QIBL_LINKV;
  136. ppd->lflags &= ~(QIBL_LINKINIT |
  137. QIBL_LINKDOWN | QIBL_LINKARMED);
  138. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  139. if (dd->flags & QIB_HAS_SEND_DMA)
  140. qib_sdma_process_event(ppd,
  141. qib_sdma_event_e30_go_running);
  142. ev = IB_EVENT_PORT_ACTIVE;
  143. dd->f_setextled(ppd, 1);
  144. }
  145. } else { /* down */
  146. if (ppd->lflags & QIBL_LINKACTIVE)
  147. ev = IB_EVENT_PORT_ERR;
  148. spin_lock_irqsave(&ppd->lflags_lock, flags);
  149. ppd->lflags |= QIBL_LINKDOWN | QIBL_LINKV;
  150. ppd->lflags &= ~(QIBL_LINKINIT |
  151. QIBL_LINKACTIVE | QIBL_LINKARMED);
  152. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  153. *ppd->statusp &= ~QIB_STATUS_IB_READY;
  154. }
  155. skip_ibchange:
  156. ppd->lastibcstat = ibcs;
  157. if (ev)
  158. signal_ib_event(ppd, ev);
  159. }
  160. void qib_clear_symerror_on_linkup(unsigned long opaque)
  161. {
  162. struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
  163. if (ppd->lflags & QIBL_LINKACTIVE)
  164. return;
  165. ppd->ibport_data.z_symbol_error_counter =
  166. ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBSYMBOLERR);
  167. }
  168. /*
  169. * Handle receive interrupts for user ctxts; this means a user
  170. * process was waiting for a packet to arrive, and didn't want
  171. * to poll.
  172. */
  173. void qib_handle_urcv(struct qib_devdata *dd, u64 ctxtr)
  174. {
  175. struct qib_ctxtdata *rcd;
  176. unsigned long flags;
  177. int i;
  178. spin_lock_irqsave(&dd->uctxt_lock, flags);
  179. for (i = dd->first_user_ctxt; dd->rcd && i < dd->cfgctxts; i++) {
  180. if (!(ctxtr & (1ULL << i)))
  181. continue;
  182. rcd = dd->rcd[i];
  183. if (!rcd || !rcd->cnt)
  184. continue;
  185. if (test_and_clear_bit(QIB_CTXT_WAITING_RCV, &rcd->flag)) {
  186. wake_up_interruptible(&rcd->wait);
  187. dd->f_rcvctrl(rcd->ppd, QIB_RCVCTRL_INTRAVAIL_DIS,
  188. rcd->ctxt);
  189. } else if (test_and_clear_bit(QIB_CTXT_WAITING_URG,
  190. &rcd->flag)) {
  191. rcd->urgent++;
  192. wake_up_interruptible(&rcd->wait);
  193. }
  194. }
  195. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  196. }
  197. void qib_bad_intrstatus(struct qib_devdata *dd)
  198. {
  199. static int allbits;
  200. /* separate routine, for better optimization of qib_intr() */
  201. /*
  202. * We print the message and disable interrupts, in hope of
  203. * having a better chance of debugging the problem.
  204. */
  205. qib_dev_err(dd,
  206. "Read of chip interrupt status failed disabling interrupts\n");
  207. if (allbits++) {
  208. /* disable interrupt delivery, something is very wrong */
  209. if (allbits == 2)
  210. dd->f_set_intr_state(dd, 0);
  211. if (allbits == 3) {
  212. qib_dev_err(dd,
  213. "2nd bad interrupt status, unregistering interrupts\n");
  214. dd->flags |= QIB_BADINTR;
  215. dd->flags &= ~QIB_INITTED;
  216. dd->f_free_irq(dd);
  217. }
  218. }
  219. }