bfa_intr.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include <bfa.h>
  18. #include <bfi/bfi_ctreg.h>
  19. #include <bfa_port_priv.h>
  20. #include <bfa_intr_priv.h>
  21. #include <cs/bfa_debug.h>
  22. BFA_TRC_FILE(HAL, INTR);
  23. static void
  24. bfa_msix_errint(struct bfa_s *bfa, u32 intr)
  25. {
  26. bfa_ioc_error_isr(&bfa->ioc);
  27. }
  28. static void
  29. bfa_msix_lpu(struct bfa_s *bfa)
  30. {
  31. bfa_ioc_mbox_isr(&bfa->ioc);
  32. }
  33. void
  34. bfa_msix_all(struct bfa_s *bfa, int vec)
  35. {
  36. bfa_intx(bfa);
  37. }
  38. /**
  39. * hal_intr_api
  40. */
  41. bfa_boolean_t
  42. bfa_intx(struct bfa_s *bfa)
  43. {
  44. u32 intr, qintr;
  45. int queue;
  46. intr = bfa_reg_read(bfa->iocfc.bfa_regs.intr_status);
  47. if (!intr)
  48. return BFA_FALSE;
  49. /**
  50. * RME completion queue interrupt
  51. */
  52. qintr = intr & __HFN_INT_RME_MASK;
  53. bfa_reg_write(bfa->iocfc.bfa_regs.intr_status, qintr);
  54. for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
  55. if (intr & (__HFN_INT_RME_Q0 << queue))
  56. bfa_msix_rspq(bfa, queue & (BFI_IOC_MAX_CQS - 1));
  57. }
  58. intr &= ~qintr;
  59. if (!intr)
  60. return BFA_TRUE;
  61. /**
  62. * CPE completion queue interrupt
  63. */
  64. qintr = intr & __HFN_INT_CPE_MASK;
  65. bfa_reg_write(bfa->iocfc.bfa_regs.intr_status, qintr);
  66. for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
  67. if (intr & (__HFN_INT_CPE_Q0 << queue))
  68. bfa_msix_reqq(bfa, queue & (BFI_IOC_MAX_CQS - 1));
  69. }
  70. intr &= ~qintr;
  71. if (!intr)
  72. return BFA_TRUE;
  73. bfa_msix_lpu_err(bfa, intr);
  74. return BFA_TRUE;
  75. }
  76. void
  77. bfa_isr_enable(struct bfa_s *bfa)
  78. {
  79. u32 intr_unmask;
  80. int pci_func = bfa_ioc_pcifn(&bfa->ioc);
  81. bfa_trc(bfa, pci_func);
  82. bfa_msix_install(bfa);
  83. intr_unmask = (__HFN_INT_ERR_EMC | __HFN_INT_ERR_LPU0 |
  84. __HFN_INT_ERR_LPU1 | __HFN_INT_ERR_PSS |
  85. __HFN_INT_LL_HALT);
  86. if (pci_func == 0)
  87. intr_unmask |= (__HFN_INT_CPE_Q0 | __HFN_INT_CPE_Q1 |
  88. __HFN_INT_CPE_Q2 | __HFN_INT_CPE_Q3 |
  89. __HFN_INT_RME_Q0 | __HFN_INT_RME_Q1 |
  90. __HFN_INT_RME_Q2 | __HFN_INT_RME_Q3 |
  91. __HFN_INT_MBOX_LPU0);
  92. else
  93. intr_unmask |= (__HFN_INT_CPE_Q4 | __HFN_INT_CPE_Q5 |
  94. __HFN_INT_CPE_Q6 | __HFN_INT_CPE_Q7 |
  95. __HFN_INT_RME_Q4 | __HFN_INT_RME_Q5 |
  96. __HFN_INT_RME_Q6 | __HFN_INT_RME_Q7 |
  97. __HFN_INT_MBOX_LPU1);
  98. bfa_reg_write(bfa->iocfc.bfa_regs.intr_status, intr_unmask);
  99. bfa_reg_write(bfa->iocfc.bfa_regs.intr_mask, ~intr_unmask);
  100. bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
  101. }
  102. void
  103. bfa_isr_disable(struct bfa_s *bfa)
  104. {
  105. bfa_isr_mode_set(bfa, BFA_FALSE);
  106. bfa_reg_write(bfa->iocfc.bfa_regs.intr_mask, -1L);
  107. bfa_msix_uninstall(bfa);
  108. }
  109. void
  110. bfa_msix_reqq(struct bfa_s *bfa, int qid)
  111. {
  112. struct list_head *waitq, *qe, *qen;
  113. struct bfa_reqq_wait_s *wqe;
  114. qid &= (BFI_IOC_MAX_CQS - 1);
  115. waitq = bfa_reqq(bfa, qid);
  116. list_for_each_safe(qe, qen, waitq) {
  117. /**
  118. * Callback only as long as there is room in request queue
  119. */
  120. if (bfa_reqq_full(bfa, qid))
  121. break;
  122. list_del(qe);
  123. wqe = (struct bfa_reqq_wait_s *) qe;
  124. wqe->qresume(wqe->cbarg);
  125. }
  126. }
  127. void
  128. bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
  129. {
  130. bfa_trc(bfa, m->mhdr.msg_class);
  131. bfa_trc(bfa, m->mhdr.msg_id);
  132. bfa_trc(bfa, m->mhdr.mtag.i2htok);
  133. bfa_assert(0);
  134. bfa_trc_stop(bfa->trcmod);
  135. }
  136. void
  137. bfa_msix_rspq(struct bfa_s *bfa, int rsp_qid)
  138. {
  139. struct bfi_msg_s *m;
  140. u32 pi, ci;
  141. bfa_trc_fp(bfa, rsp_qid);
  142. rsp_qid &= (BFI_IOC_MAX_CQS - 1);
  143. bfa->iocfc.hwif.hw_rspq_ack(bfa, rsp_qid);
  144. ci = bfa_rspq_ci(bfa, rsp_qid);
  145. pi = bfa_rspq_pi(bfa, rsp_qid);
  146. bfa_trc_fp(bfa, ci);
  147. bfa_trc_fp(bfa, pi);
  148. if (bfa->rme_process) {
  149. while (ci != pi) {
  150. m = bfa_rspq_elem(bfa, rsp_qid, ci);
  151. bfa_assert_fp(m->mhdr.msg_class < BFI_MC_MAX);
  152. bfa_isrs[m->mhdr.msg_class] (bfa, m);
  153. CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
  154. }
  155. }
  156. /**
  157. * update CI
  158. */
  159. bfa_rspq_ci(bfa, rsp_qid) = pi;
  160. bfa_reg_write(bfa->iocfc.bfa_regs.rme_q_ci[rsp_qid], pi);
  161. bfa_os_mmiowb();
  162. }
  163. void
  164. bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
  165. {
  166. u32 intr;
  167. intr = bfa_reg_read(bfa->iocfc.bfa_regs.intr_status);
  168. if (intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1))
  169. bfa_msix_lpu(bfa);
  170. if (intr & (__HFN_INT_ERR_EMC |
  171. __HFN_INT_ERR_LPU0 | __HFN_INT_ERR_LPU1 |
  172. __HFN_INT_ERR_PSS | __HFN_INT_LL_HALT))
  173. bfa_msix_errint(bfa, intr);
  174. }
  175. void
  176. bfa_isr_bind(enum bfi_mclass mc, bfa_isr_func_t isr_func)
  177. {
  178. bfa_isrs[mc] = isr_func;
  179. }