bfa_hw_ct.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (c) 2005-2010 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_modules.h"
  18. #include "bfi_ctreg.h"
  19. BFA_TRC_FILE(HAL, IOCFC_CT);
  20. static u32 __ct_msix_err_vec_reg[] = {
  21. HOST_MSIX_ERR_INDEX_FN0,
  22. HOST_MSIX_ERR_INDEX_FN1,
  23. HOST_MSIX_ERR_INDEX_FN2,
  24. HOST_MSIX_ERR_INDEX_FN3,
  25. };
  26. static void
  27. bfa_hwct_msix_lpu_err_set(struct bfa_s *bfa, bfa_boolean_t msix, int vec)
  28. {
  29. int fn = bfa_ioc_pcifn(&bfa->ioc);
  30. bfa_os_addr_t kva = bfa_ioc_bar0(&bfa->ioc);
  31. if (msix)
  32. bfa_reg_write(kva + __ct_msix_err_vec_reg[fn], vec);
  33. else
  34. bfa_reg_write(kva + __ct_msix_err_vec_reg[fn], 0);
  35. }
  36. /**
  37. * Dummy interrupt handler for handling spurious interrupt during chip-reinit.
  38. */
  39. static void
  40. bfa_hwct_msix_dummy(struct bfa_s *bfa, int vec)
  41. {
  42. }
  43. void
  44. bfa_hwct_reginit(struct bfa_s *bfa)
  45. {
  46. struct bfa_iocfc_regs_s *bfa_regs = &bfa->iocfc.bfa_regs;
  47. bfa_os_addr_t kva = bfa_ioc_bar0(&bfa->ioc);
  48. int i, q, fn = bfa_ioc_pcifn(&bfa->ioc);
  49. if (fn == 0) {
  50. bfa_regs->intr_status = (kva + HOSTFN0_INT_STATUS);
  51. bfa_regs->intr_mask = (kva + HOSTFN0_INT_MSK);
  52. } else {
  53. bfa_regs->intr_status = (kva + HOSTFN1_INT_STATUS);
  54. bfa_regs->intr_mask = (kva + HOSTFN1_INT_MSK);
  55. }
  56. for (i = 0; i < BFI_IOC_MAX_CQS; i++) {
  57. /*
  58. * CPE registers
  59. */
  60. q = CPE_Q_NUM(fn, i);
  61. bfa_regs->cpe_q_pi[i] = (kva + CPE_PI_PTR_Q(q << 5));
  62. bfa_regs->cpe_q_ci[i] = (kva + CPE_CI_PTR_Q(q << 5));
  63. bfa_regs->cpe_q_depth[i] = (kva + CPE_DEPTH_Q(q << 5));
  64. bfa_regs->cpe_q_ctrl[i] = (kva + CPE_QCTRL_Q(q << 5));
  65. /*
  66. * RME registers
  67. */
  68. q = CPE_Q_NUM(fn, i);
  69. bfa_regs->rme_q_pi[i] = (kva + RME_PI_PTR_Q(q << 5));
  70. bfa_regs->rme_q_ci[i] = (kva + RME_CI_PTR_Q(q << 5));
  71. bfa_regs->rme_q_depth[i] = (kva + RME_DEPTH_Q(q << 5));
  72. bfa_regs->rme_q_ctrl[i] = (kva + RME_QCTRL_Q(q << 5));
  73. }
  74. }
  75. void
  76. bfa_hwct_reqq_ack(struct bfa_s *bfa, int reqq)
  77. {
  78. u32 r32;
  79. r32 = bfa_reg_read(bfa->iocfc.bfa_regs.cpe_q_ctrl[reqq]);
  80. bfa_reg_write(bfa->iocfc.bfa_regs.cpe_q_ctrl[reqq], r32);
  81. }
  82. void
  83. bfa_hwct_rspq_ack(struct bfa_s *bfa, int rspq)
  84. {
  85. u32 r32;
  86. r32 = bfa_reg_read(bfa->iocfc.bfa_regs.rme_q_ctrl[rspq]);
  87. bfa_reg_write(bfa->iocfc.bfa_regs.rme_q_ctrl[rspq], r32);
  88. }
  89. void
  90. bfa_hwct_msix_getvecs(struct bfa_s *bfa, u32 *msix_vecs_bmap,
  91. u32 *num_vecs, u32 *max_vec_bit)
  92. {
  93. *msix_vecs_bmap = (1 << BFA_MSIX_CT_MAX) - 1;
  94. *max_vec_bit = (1 << (BFA_MSIX_CT_MAX - 1));
  95. *num_vecs = BFA_MSIX_CT_MAX;
  96. }
  97. /**
  98. * Setup MSI-X vector for catapult
  99. */
  100. void
  101. bfa_hwct_msix_init(struct bfa_s *bfa, int nvecs)
  102. {
  103. bfa_assert((nvecs == 1) || (nvecs == BFA_MSIX_CT_MAX));
  104. bfa_trc(bfa, nvecs);
  105. bfa->msix.nvecs = nvecs;
  106. bfa_hwct_msix_uninstall(bfa);
  107. }
  108. void
  109. bfa_hwct_msix_install(struct bfa_s *bfa)
  110. {
  111. int i;
  112. if (bfa->msix.nvecs == 0)
  113. return;
  114. if (bfa->msix.nvecs == 1) {
  115. for (i = 0; i < BFA_MSIX_CT_MAX; i++)
  116. bfa->msix.handler[i] = bfa_msix_all;
  117. return;
  118. }
  119. for (i = BFA_MSIX_CPE_Q0; i <= BFA_MSIX_CPE_Q3; i++)
  120. bfa->msix.handler[i] = bfa_msix_reqq;
  121. for (; i <= BFA_MSIX_RME_Q3; i++)
  122. bfa->msix.handler[i] = bfa_msix_rspq;
  123. bfa_assert(i == BFA_MSIX_LPU_ERR);
  124. bfa->msix.handler[BFA_MSIX_LPU_ERR] = bfa_msix_lpu_err;
  125. }
  126. void
  127. bfa_hwct_msix_uninstall(struct bfa_s *bfa)
  128. {
  129. int i;
  130. for (i = 0; i < BFA_MSIX_CT_MAX; i++)
  131. bfa->msix.handler[i] = bfa_hwct_msix_dummy;
  132. }
  133. /**
  134. * Enable MSI-X vectors
  135. */
  136. void
  137. bfa_hwct_isr_mode_set(struct bfa_s *bfa, bfa_boolean_t msix)
  138. {
  139. bfa_trc(bfa, 0);
  140. bfa_hwct_msix_lpu_err_set(bfa, msix, BFA_MSIX_LPU_ERR);
  141. bfa_ioc_isr_mode_set(&bfa->ioc, msix);
  142. }
  143. void
  144. bfa_hwct_msix_get_rme_range(struct bfa_s *bfa, u32 *start, u32 *end)
  145. {
  146. *start = BFA_MSIX_RME_Q0;
  147. *end = BFA_MSIX_RME_Q3;
  148. }