bfa_ioc_cb.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 "bfad_drv.h"
  18. #include "bfa_ioc.h"
  19. #include "bfi_reg.h"
  20. #include "bfa_defs.h"
  21. BFA_TRC_FILE(CNA, IOC_CB);
  22. /*
  23. * forward declarations
  24. */
  25. static bfa_boolean_t bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc);
  26. static void bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc);
  27. static void bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc);
  28. static void bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc);
  29. static void bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix);
  30. static void bfa_ioc_cb_notify_fail(struct bfa_ioc_s *ioc);
  31. static void bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc);
  32. static bfa_boolean_t bfa_ioc_cb_sync_start(struct bfa_ioc_s *ioc);
  33. static void bfa_ioc_cb_sync_join(struct bfa_ioc_s *ioc);
  34. static void bfa_ioc_cb_sync_leave(struct bfa_ioc_s *ioc);
  35. static void bfa_ioc_cb_sync_ack(struct bfa_ioc_s *ioc);
  36. static bfa_boolean_t bfa_ioc_cb_sync_complete(struct bfa_ioc_s *ioc);
  37. static struct bfa_ioc_hwif_s hwif_cb;
  38. /*
  39. * Called from bfa_ioc_attach() to map asic specific calls.
  40. */
  41. void
  42. bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc)
  43. {
  44. hwif_cb.ioc_pll_init = bfa_ioc_cb_pll_init;
  45. hwif_cb.ioc_firmware_lock = bfa_ioc_cb_firmware_lock;
  46. hwif_cb.ioc_firmware_unlock = bfa_ioc_cb_firmware_unlock;
  47. hwif_cb.ioc_reg_init = bfa_ioc_cb_reg_init;
  48. hwif_cb.ioc_map_port = bfa_ioc_cb_map_port;
  49. hwif_cb.ioc_isr_mode_set = bfa_ioc_cb_isr_mode_set;
  50. hwif_cb.ioc_notify_fail = bfa_ioc_cb_notify_fail;
  51. hwif_cb.ioc_ownership_reset = bfa_ioc_cb_ownership_reset;
  52. hwif_cb.ioc_sync_start = bfa_ioc_cb_sync_start;
  53. hwif_cb.ioc_sync_join = bfa_ioc_cb_sync_join;
  54. hwif_cb.ioc_sync_leave = bfa_ioc_cb_sync_leave;
  55. hwif_cb.ioc_sync_ack = bfa_ioc_cb_sync_ack;
  56. hwif_cb.ioc_sync_complete = bfa_ioc_cb_sync_complete;
  57. ioc->ioc_hwif = &hwif_cb;
  58. }
  59. /*
  60. * Return true if firmware of current driver matches the running firmware.
  61. */
  62. static bfa_boolean_t
  63. bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc)
  64. {
  65. return BFA_TRUE;
  66. }
  67. static void
  68. bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc)
  69. {
  70. }
  71. /*
  72. * Notify other functions on HB failure.
  73. */
  74. static void
  75. bfa_ioc_cb_notify_fail(struct bfa_ioc_s *ioc)
  76. {
  77. writel(~0U, ioc->ioc_regs.err_set);
  78. readl(ioc->ioc_regs.err_set);
  79. }
  80. /*
  81. * Host to LPU mailbox message addresses
  82. */
  83. static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
  84. { HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 },
  85. { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }
  86. };
  87. /*
  88. * Host <-> LPU mailbox command/status registers
  89. */
  90. static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
  91. { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
  92. { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT }
  93. };
  94. static void
  95. bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
  96. {
  97. void __iomem *rb;
  98. int pcifn = bfa_ioc_pcifn(ioc);
  99. rb = bfa_ioc_bar0(ioc);
  100. ioc->ioc_regs.hfn_mbox = rb + iocreg_fnreg[pcifn].hfn_mbox;
  101. ioc->ioc_regs.lpu_mbox = rb + iocreg_fnreg[pcifn].lpu_mbox;
  102. ioc->ioc_regs.host_page_num_fn = rb + iocreg_fnreg[pcifn].hfn_pgn;
  103. if (ioc->port_id == 0) {
  104. ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
  105. ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
  106. ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG;
  107. } else {
  108. ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG);
  109. ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
  110. ioc->ioc_regs.alt_ioc_fwstate = (rb + BFA_IOC0_STATE_REG);
  111. }
  112. /*
  113. * Host <-> LPU mailbox command/status registers
  114. */
  115. ioc->ioc_regs.hfn_mbox_cmd = rb + iocreg_mbcmd[pcifn].hfn;
  116. ioc->ioc_regs.lpu_mbox_cmd = rb + iocreg_mbcmd[pcifn].lpu;
  117. /*
  118. * PSS control registers
  119. */
  120. ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
  121. ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
  122. ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_LCLK_CTL_REG);
  123. ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_SCLK_CTL_REG);
  124. /*
  125. * IOC semaphore registers and serialization
  126. */
  127. ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
  128. ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
  129. /*
  130. * sram memory access
  131. */
  132. ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
  133. ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CB;
  134. /*
  135. * err set reg : for notification of hb failure
  136. */
  137. ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
  138. }
  139. /*
  140. * Initialize IOC to port mapping.
  141. */
  142. static void
  143. bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc)
  144. {
  145. /*
  146. * For crossbow, port id is same as pci function.
  147. */
  148. ioc->port_id = bfa_ioc_pcifn(ioc);
  149. bfa_trc(ioc, ioc->port_id);
  150. }
  151. /*
  152. * Set interrupt mode for a function: INTX or MSIX
  153. */
  154. static void
  155. bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
  156. {
  157. }
  158. /*
  159. * Synchronized IOC failure processing routines
  160. */
  161. static bfa_boolean_t
  162. bfa_ioc_cb_sync_start(struct bfa_ioc_s *ioc)
  163. {
  164. return bfa_ioc_cb_sync_complete(ioc);
  165. }
  166. /*
  167. * Cleanup hw semaphore and usecnt registers
  168. */
  169. static void
  170. bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc)
  171. {
  172. /*
  173. * Read the hw sem reg to make sure that it is locked
  174. * before we clear it. If it is not locked, writing 1
  175. * will lock it instead of clearing it.
  176. */
  177. readl(ioc->ioc_regs.ioc_sem_reg);
  178. writel(1, ioc->ioc_regs.ioc_sem_reg);
  179. }
  180. /*
  181. * Synchronized IOC failure processing routines
  182. */
  183. static void
  184. bfa_ioc_cb_sync_join(struct bfa_ioc_s *ioc)
  185. {
  186. }
  187. static void
  188. bfa_ioc_cb_sync_leave(struct bfa_ioc_s *ioc)
  189. {
  190. }
  191. static void
  192. bfa_ioc_cb_sync_ack(struct bfa_ioc_s *ioc)
  193. {
  194. writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
  195. }
  196. static bfa_boolean_t
  197. bfa_ioc_cb_sync_complete(struct bfa_ioc_s *ioc)
  198. {
  199. uint32_t fwstate, alt_fwstate;
  200. fwstate = readl(ioc->ioc_regs.ioc_fwstate);
  201. /*
  202. * At this point, this IOC is hoding the hw sem in the
  203. * start path (fwcheck) OR in the disable/enable path
  204. * OR to check if the other IOC has acknowledged failure.
  205. *
  206. * So, this IOC can be in UNINIT, INITING, DISABLED, FAIL
  207. * or in MEMTEST states. In a normal scenario, this IOC
  208. * can not be in OP state when this function is called.
  209. *
  210. * However, this IOC could still be in OP state when
  211. * the OS driver is starting up, if the OptROM code has
  212. * left it in that state.
  213. *
  214. * If we had marked this IOC's fwstate as BFI_IOC_FAIL
  215. * in the failure case and now, if the fwstate is not
  216. * BFI_IOC_FAIL it implies that the other PCI fn have
  217. * reinitialized the ASIC or this IOC got disabled, so
  218. * return TRUE.
  219. */
  220. if (fwstate == BFI_IOC_UNINIT ||
  221. fwstate == BFI_IOC_INITING ||
  222. fwstate == BFI_IOC_DISABLED ||
  223. fwstate == BFI_IOC_MEMTEST ||
  224. fwstate == BFI_IOC_OP)
  225. return BFA_TRUE;
  226. else {
  227. alt_fwstate = readl(ioc->ioc_regs.alt_ioc_fwstate);
  228. if (alt_fwstate == BFI_IOC_FAIL ||
  229. alt_fwstate == BFI_IOC_DISABLED ||
  230. alt_fwstate == BFI_IOC_UNINIT ||
  231. alt_fwstate == BFI_IOC_INITING ||
  232. alt_fwstate == BFI_IOC_MEMTEST)
  233. return BFA_TRUE;
  234. else
  235. return BFA_FALSE;
  236. }
  237. }
  238. bfa_status_t
  239. bfa_ioc_cb_pll_init(void __iomem *rb, enum bfi_asic_mode fcmode)
  240. {
  241. u32 pll_sclk, pll_fclk;
  242. pll_sclk = __APP_PLL_SCLK_ENABLE | __APP_PLL_SCLK_LRESETN |
  243. __APP_PLL_SCLK_P0_1(3U) |
  244. __APP_PLL_SCLK_JITLMT0_1(3U) |
  245. __APP_PLL_SCLK_CNTLMT0_1(3U);
  246. pll_fclk = __APP_PLL_LCLK_ENABLE | __APP_PLL_LCLK_LRESETN |
  247. __APP_PLL_LCLK_RSEL200500 | __APP_PLL_LCLK_P0_1(3U) |
  248. __APP_PLL_LCLK_JITLMT0_1(3U) |
  249. __APP_PLL_LCLK_CNTLMT0_1(3U);
  250. writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
  251. writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
  252. writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
  253. writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
  254. writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
  255. writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
  256. writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
  257. writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
  258. writel(__APP_PLL_SCLK_LOGIC_SOFT_RESET, rb + APP_PLL_SCLK_CTL_REG);
  259. writel(__APP_PLL_SCLK_BYPASS | __APP_PLL_SCLK_LOGIC_SOFT_RESET,
  260. rb + APP_PLL_SCLK_CTL_REG);
  261. writel(__APP_PLL_LCLK_LOGIC_SOFT_RESET, rb + APP_PLL_LCLK_CTL_REG);
  262. writel(__APP_PLL_LCLK_BYPASS | __APP_PLL_LCLK_LOGIC_SOFT_RESET,
  263. rb + APP_PLL_LCLK_CTL_REG);
  264. udelay(2);
  265. writel(__APP_PLL_SCLK_LOGIC_SOFT_RESET, rb + APP_PLL_SCLK_CTL_REG);
  266. writel(__APP_PLL_LCLK_LOGIC_SOFT_RESET, rb + APP_PLL_LCLK_CTL_REG);
  267. writel(pll_sclk | __APP_PLL_SCLK_LOGIC_SOFT_RESET,
  268. rb + APP_PLL_SCLK_CTL_REG);
  269. writel(pll_fclk | __APP_PLL_LCLK_LOGIC_SOFT_RESET,
  270. rb + APP_PLL_LCLK_CTL_REG);
  271. udelay(2000);
  272. writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
  273. writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
  274. writel(pll_sclk, (rb + APP_PLL_SCLK_CTL_REG));
  275. writel(pll_fclk, (rb + APP_PLL_LCLK_CTL_REG));
  276. return BFA_STATUS_OK;
  277. }