bfa_ioc_cb.c 7.2 KB

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