bfa_ioc_cb.c 7.4 KB

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