bfa_ioc_cb.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 uint32_t *
  61. bfa_ioc_cb_fwimg_get_chunk(struct bfa_ioc_s *ioc, uint32_t off)
  62. {
  63. return bfi_image_cb_get_chunk(off);
  64. }
  65. static uint32_t
  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 { uint32_t 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 { uint32_t 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.app_pll_fast_ctl_reg = (rb + APP_PLL_400_CTL_REG);
  131. ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_212_CTL_REG);
  132. /*
  133. * IOC semaphore registers and serialization
  134. */
  135. ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
  136. ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
  137. /**
  138. * sram memory access
  139. */
  140. ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
  141. ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CB;
  142. /*
  143. * err set reg : for notification of hb failure
  144. */
  145. ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
  146. }
  147. /**
  148. * Initialize IOC to port mapping.
  149. */
  150. static void
  151. bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc)
  152. {
  153. /**
  154. * For crossbow, port id is same as pci function.
  155. */
  156. ioc->port_id = bfa_ioc_pcifn(ioc);
  157. bfa_trc(ioc, ioc->port_id);
  158. }
  159. /**
  160. * Set interrupt mode for a function: INTX or MSIX
  161. */
  162. static void
  163. bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
  164. {
  165. }
  166. static bfa_status_t
  167. bfa_ioc_cb_pll_init(struct bfa_ioc_s *ioc)
  168. {
  169. bfa_os_addr_t rb = ioc->pcidev.pci_bar_kva;
  170. uint32_t pll_sclk, pll_fclk;
  171. /*
  172. * Hold semaphore so that nobody can access the chip during init.
  173. */
  174. bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
  175. pll_sclk = __APP_PLL_212_ENABLE | __APP_PLL_212_LRESETN |
  176. __APP_PLL_212_P0_1(3U) |
  177. __APP_PLL_212_JITLMT0_1(3U) |
  178. __APP_PLL_212_CNTLMT0_1(3U);
  179. pll_fclk = __APP_PLL_400_ENABLE | __APP_PLL_400_LRESETN |
  180. __APP_PLL_400_RSEL200500 | __APP_PLL_400_P0_1(3U) |
  181. __APP_PLL_400_JITLMT0_1(3U) |
  182. __APP_PLL_400_CNTLMT0_1(3U);
  183. bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_UNINIT);
  184. bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_UNINIT);
  185. bfa_reg_write((rb + HOSTFN0_INT_MSK), 0xffffffffU);
  186. bfa_reg_write((rb + HOSTFN1_INT_MSK), 0xffffffffU);
  187. bfa_reg_write((rb + HOSTFN0_INT_STATUS), 0xffffffffU);
  188. bfa_reg_write((rb + HOSTFN1_INT_STATUS), 0xffffffffU);
  189. bfa_reg_write((rb + HOSTFN0_INT_MSK), 0xffffffffU);
  190. bfa_reg_write((rb + HOSTFN1_INT_MSK), 0xffffffffU);
  191. bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg,
  192. __APP_PLL_212_LOGIC_SOFT_RESET);
  193. bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg,
  194. __APP_PLL_212_BYPASS |
  195. __APP_PLL_212_LOGIC_SOFT_RESET);
  196. bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg,
  197. __APP_PLL_400_LOGIC_SOFT_RESET);
  198. bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg,
  199. __APP_PLL_400_BYPASS |
  200. __APP_PLL_400_LOGIC_SOFT_RESET);
  201. bfa_os_udelay(2);
  202. bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg,
  203. __APP_PLL_212_LOGIC_SOFT_RESET);
  204. bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg,
  205. __APP_PLL_400_LOGIC_SOFT_RESET);
  206. bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg,
  207. pll_sclk | __APP_PLL_212_LOGIC_SOFT_RESET);
  208. bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg,
  209. pll_fclk | __APP_PLL_400_LOGIC_SOFT_RESET);
  210. /**
  211. * Wait for PLLs to lock.
  212. */
  213. bfa_os_udelay(2000);
  214. bfa_reg_write((rb + HOSTFN0_INT_STATUS), 0xffffffffU);
  215. bfa_reg_write((rb + HOSTFN1_INT_STATUS), 0xffffffffU);
  216. bfa_reg_write(ioc->ioc_regs.app_pll_slow_ctl_reg, pll_sclk);
  217. bfa_reg_write(ioc->ioc_regs.app_pll_fast_ctl_reg, pll_fclk);
  218. /*
  219. * release semaphore.
  220. */
  221. bfa_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
  222. return BFA_STATUS_OK;
  223. }
  224. /**
  225. * Cleanup hw semaphore and usecnt registers
  226. */
  227. static void
  228. bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc)
  229. {
  230. /*
  231. * Read the hw sem reg to make sure that it is locked
  232. * before we clear it. If it is not locked, writing 1
  233. * will lock it instead of clearing it.
  234. */
  235. bfa_reg_read(ioc->ioc_regs.ioc_sem_reg);
  236. bfa_ioc_hw_sem_release(ioc);
  237. }