bfa_ioc_cb.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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_cbreg.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 void bfa_ioc_cb_sync_join(struct bfa_ioc_s *ioc);
  33. static void bfa_ioc_cb_sync_leave(struct bfa_ioc_s *ioc);
  34. static void bfa_ioc_cb_sync_ack(struct bfa_ioc_s *ioc);
  35. static bfa_boolean_t bfa_ioc_cb_sync_complete(struct bfa_ioc_s *ioc);
  36. static struct bfa_ioc_hwif_s hwif_cb;
  37. /*
  38. * Called from bfa_ioc_attach() to map asic specific calls.
  39. */
  40. void
  41. bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc)
  42. {
  43. hwif_cb.ioc_pll_init = bfa_ioc_cb_pll_init;
  44. hwif_cb.ioc_firmware_lock = bfa_ioc_cb_firmware_lock;
  45. hwif_cb.ioc_firmware_unlock = bfa_ioc_cb_firmware_unlock;
  46. hwif_cb.ioc_reg_init = bfa_ioc_cb_reg_init;
  47. hwif_cb.ioc_map_port = bfa_ioc_cb_map_port;
  48. hwif_cb.ioc_isr_mode_set = bfa_ioc_cb_isr_mode_set;
  49. hwif_cb.ioc_notify_fail = bfa_ioc_cb_notify_fail;
  50. hwif_cb.ioc_ownership_reset = bfa_ioc_cb_ownership_reset;
  51. hwif_cb.ioc_sync_join = bfa_ioc_cb_sync_join;
  52. hwif_cb.ioc_sync_leave = bfa_ioc_cb_sync_leave;
  53. hwif_cb.ioc_sync_ack = bfa_ioc_cb_sync_ack;
  54. hwif_cb.ioc_sync_complete = bfa_ioc_cb_sync_complete;
  55. ioc->ioc_hwif = &hwif_cb;
  56. }
  57. /*
  58. * Return true if firmware of current driver matches the running firmware.
  59. */
  60. static bfa_boolean_t
  61. bfa_ioc_cb_firmware_lock(struct bfa_ioc_s *ioc)
  62. {
  63. struct bfi_ioc_image_hdr_s fwhdr;
  64. uint32_t fwstate = readl(ioc->ioc_regs.ioc_fwstate);
  65. if (fwstate == BFI_IOC_UNINIT)
  66. return BFA_TRUE;
  67. bfa_ioc_fwver_get(ioc, &fwhdr);
  68. if (swab32(fwhdr.exec) == BFI_BOOT_TYPE_NORMAL)
  69. return BFA_TRUE;
  70. bfa_trc(ioc, fwstate);
  71. bfa_trc(ioc, fwhdr.exec);
  72. writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
  73. return BFA_TRUE;
  74. }
  75. static void
  76. bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc)
  77. {
  78. }
  79. /*
  80. * Notify other functions on HB failure.
  81. */
  82. static void
  83. bfa_ioc_cb_notify_fail(struct bfa_ioc_s *ioc)
  84. {
  85. writel(__PSS_ERR_STATUS_SET, ioc->ioc_regs.err_set);
  86. readl(ioc->ioc_regs.err_set);
  87. }
  88. /*
  89. * Host to LPU mailbox message addresses
  90. */
  91. static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
  92. { HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 },
  93. { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }
  94. };
  95. /*
  96. * Host <-> LPU mailbox command/status registers
  97. */
  98. static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
  99. { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
  100. { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT }
  101. };
  102. static void
  103. bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
  104. {
  105. void __iomem *rb;
  106. int pcifn = bfa_ioc_pcifn(ioc);
  107. rb = bfa_ioc_bar0(ioc);
  108. ioc->ioc_regs.hfn_mbox = rb + iocreg_fnreg[pcifn].hfn_mbox;
  109. ioc->ioc_regs.lpu_mbox = rb + iocreg_fnreg[pcifn].lpu_mbox;
  110. ioc->ioc_regs.host_page_num_fn = rb + iocreg_fnreg[pcifn].hfn_pgn;
  111. if (ioc->port_id == 0) {
  112. ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
  113. ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
  114. ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG;
  115. } else {
  116. ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG);
  117. ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
  118. ioc->ioc_regs.alt_ioc_fwstate = (rb + BFA_IOC0_STATE_REG);
  119. }
  120. /*
  121. * Host <-> LPU mailbox command/status registers
  122. */
  123. ioc->ioc_regs.hfn_mbox_cmd = rb + iocreg_mbcmd[pcifn].hfn;
  124. ioc->ioc_regs.lpu_mbox_cmd = rb + iocreg_mbcmd[pcifn].lpu;
  125. /*
  126. * PSS control registers
  127. */
  128. ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
  129. ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_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. /*
  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, bfa_boolean_t fcmode)
  240. {
  241. u32 pll_sclk, pll_fclk;
  242. pll_sclk = __APP_PLL_212_ENABLE | __APP_PLL_212_LRESETN |
  243. __APP_PLL_212_P0_1(3U) |
  244. __APP_PLL_212_JITLMT0_1(3U) |
  245. __APP_PLL_212_CNTLMT0_1(3U);
  246. pll_fclk = __APP_PLL_400_ENABLE | __APP_PLL_400_LRESETN |
  247. __APP_PLL_400_RSEL200500 | __APP_PLL_400_P0_1(3U) |
  248. __APP_PLL_400_JITLMT0_1(3U) |
  249. __APP_PLL_400_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_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
  259. writel(__APP_PLL_212_BYPASS | __APP_PLL_212_LOGIC_SOFT_RESET,
  260. rb + APP_PLL_212_CTL_REG);
  261. writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
  262. writel(__APP_PLL_400_BYPASS | __APP_PLL_400_LOGIC_SOFT_RESET,
  263. rb + APP_PLL_400_CTL_REG);
  264. udelay(2);
  265. writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
  266. writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
  267. writel(pll_sclk | __APP_PLL_212_LOGIC_SOFT_RESET,
  268. rb + APP_PLL_212_CTL_REG);
  269. writel(pll_fclk | __APP_PLL_400_LOGIC_SOFT_RESET,
  270. rb + APP_PLL_400_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_212_CTL_REG));
  275. writel(pll_fclk, (rb + APP_PLL_400_CTL_REG));
  276. return BFA_STATUS_OK;
  277. }