bfa_ioc_cb.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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_ioc.h"
  18. #include "bfi_cbreg.h"
  19. #include "bfa_defs.h"
  20. BFA_TRC_FILE(CNA, IOC_CB);
  21. /*
  22. * forward declarations
  23. */
  24. static bfa_boolean_t bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc);
  25. static void bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc);
  26. static void bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc);
  27. static void bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc);
  28. static void bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix);
  29. static void bfa_ioc_cb_notify_hbfail(struct bfa_ioc_s *ioc);
  30. static void bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc);
  31. struct bfa_ioc_hwif_s hwif_cb;
  32. /*
  33. * Called from bfa_ioc_attach() to map asic specific calls.
  34. */
  35. void
  36. bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc)
  37. {
  38. hwif_cb.ioc_pll_init = bfa_ioc_cb_pll_init;
  39. hwif_cb.ioc_firmware_lock = bfa_ioc_cb_firmware_lock;
  40. hwif_cb.ioc_firmware_unlock = bfa_ioc_cb_firmware_unlock;
  41. hwif_cb.ioc_reg_init = bfa_ioc_cb_reg_init;
  42. hwif_cb.ioc_map_port = bfa_ioc_cb_map_port;
  43. hwif_cb.ioc_isr_mode_set = bfa_ioc_cb_isr_mode_set;
  44. hwif_cb.ioc_notify_hbfail = bfa_ioc_cb_notify_hbfail;
  45. hwif_cb.ioc_ownership_reset = bfa_ioc_cb_ownership_reset;
  46. ioc->ioc_hwif = &hwif_cb;
  47. }
  48. /*
  49. * Return true if firmware of current driver matches the running firmware.
  50. */
  51. static bfa_boolean_t
  52. bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc)
  53. {
  54. return BFA_TRUE;
  55. }
  56. static void
  57. bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc)
  58. {
  59. }
  60. /*
  61. * Notify other functions on HB failure.
  62. */
  63. static void
  64. bfa_ioc_cb_notify_hbfail(struct bfa_ioc_s *ioc)
  65. {
  66. writel(__PSS_ERR_STATUS_SET, ioc->ioc_regs.err_set);
  67. readl(ioc->ioc_regs.err_set);
  68. }
  69. /*
  70. * Host to LPU mailbox message addresses
  71. */
  72. static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
  73. { HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 },
  74. { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }
  75. };
  76. /*
  77. * Host <-> LPU mailbox command/status registers
  78. */
  79. static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
  80. { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
  81. { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT }
  82. };
  83. static void
  84. bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
  85. {
  86. void __iomem *rb;
  87. int pcifn = bfa_ioc_pcifn(ioc);
  88. rb = bfa_ioc_bar0(ioc);
  89. ioc->ioc_regs.hfn_mbox = rb + iocreg_fnreg[pcifn].hfn_mbox;
  90. ioc->ioc_regs.lpu_mbox = rb + iocreg_fnreg[pcifn].lpu_mbox;
  91. ioc->ioc_regs.host_page_num_fn = rb + iocreg_fnreg[pcifn].hfn_pgn;
  92. if (ioc->port_id == 0) {
  93. ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
  94. ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
  95. } else {
  96. ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG);
  97. ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
  98. }
  99. /*
  100. * Host <-> LPU mailbox command/status registers
  101. */
  102. ioc->ioc_regs.hfn_mbox_cmd = rb + iocreg_mbcmd[pcifn].hfn;
  103. ioc->ioc_regs.lpu_mbox_cmd = rb + iocreg_mbcmd[pcifn].lpu;
  104. /*
  105. * PSS control registers
  106. */
  107. ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
  108. ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
  109. ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_400_CTL_REG);
  110. ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_212_CTL_REG);
  111. /*
  112. * IOC semaphore registers and serialization
  113. */
  114. ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
  115. ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
  116. /*
  117. * sram memory access
  118. */
  119. ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
  120. ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CB;
  121. /*
  122. * err set reg : for notification of hb failure
  123. */
  124. ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
  125. }
  126. /*
  127. * Initialize IOC to port mapping.
  128. */
  129. static void
  130. bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc)
  131. {
  132. /*
  133. * For crossbow, port id is same as pci function.
  134. */
  135. ioc->port_id = bfa_ioc_pcifn(ioc);
  136. bfa_trc(ioc, ioc->port_id);
  137. }
  138. /*
  139. * Set interrupt mode for a function: INTX or MSIX
  140. */
  141. static void
  142. bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
  143. {
  144. }
  145. /*
  146. * Cleanup hw semaphore and usecnt registers
  147. */
  148. static void
  149. bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc)
  150. {
  151. /*
  152. * Read the hw sem reg to make sure that it is locked
  153. * before we clear it. If it is not locked, writing 1
  154. * will lock it instead of clearing it.
  155. */
  156. readl(ioc->ioc_regs.ioc_sem_reg);
  157. bfa_ioc_hw_sem_release(ioc);
  158. }
  159. bfa_status_t
  160. bfa_ioc_cb_pll_init(void __iomem *rb, bfa_boolean_t fcmode)
  161. {
  162. u32 pll_sclk, pll_fclk;
  163. pll_sclk = __APP_PLL_212_ENABLE | __APP_PLL_212_LRESETN |
  164. __APP_PLL_212_P0_1(3U) |
  165. __APP_PLL_212_JITLMT0_1(3U) |
  166. __APP_PLL_212_CNTLMT0_1(3U);
  167. pll_fclk = __APP_PLL_400_ENABLE | __APP_PLL_400_LRESETN |
  168. __APP_PLL_400_RSEL200500 | __APP_PLL_400_P0_1(3U) |
  169. __APP_PLL_400_JITLMT0_1(3U) |
  170. __APP_PLL_400_CNTLMT0_1(3U);
  171. writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
  172. writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
  173. writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
  174. writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
  175. writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
  176. writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
  177. writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
  178. writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
  179. writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
  180. writel(__APP_PLL_212_BYPASS | __APP_PLL_212_LOGIC_SOFT_RESET,
  181. rb + APP_PLL_212_CTL_REG);
  182. writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
  183. writel(__APP_PLL_400_BYPASS | __APP_PLL_400_LOGIC_SOFT_RESET,
  184. rb + APP_PLL_400_CTL_REG);
  185. udelay(2);
  186. writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
  187. writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
  188. writel(pll_sclk | __APP_PLL_212_LOGIC_SOFT_RESET,
  189. rb + APP_PLL_212_CTL_REG);
  190. writel(pll_fclk | __APP_PLL_400_LOGIC_SOFT_RESET,
  191. rb + APP_PLL_400_CTL_REG);
  192. udelay(2000);
  193. writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
  194. writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
  195. writel(pll_sclk, (rb + APP_PLL_212_CTL_REG));
  196. writel(pll_fclk, (rb + APP_PLL_400_CTL_REG));
  197. return BFA_STATUS_OK;
  198. }