bfa_ioc_cb.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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) || bfa_ioc_is_uefi(ioc) ||
  66. bfa_ioc_is_bios_optrom(ioc))
  67. return BFA_TRUE;
  68. bfa_ioc_fwver_get(ioc, &fwhdr);
  69. if (swab32(fwhdr.exec) == BFI_BOOT_TYPE_NORMAL)
  70. return BFA_TRUE;
  71. bfa_trc(ioc, fwstate);
  72. bfa_trc(ioc, fwhdr.exec);
  73. writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
  74. return BFA_TRUE;
  75. }
  76. static void
  77. bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc)
  78. {
  79. }
  80. /*
  81. * Notify other functions on HB failure.
  82. */
  83. static void
  84. bfa_ioc_cb_notify_fail(struct bfa_ioc_s *ioc)
  85. {
  86. writel(__PSS_ERR_STATUS_SET, ioc->ioc_regs.err_set);
  87. readl(ioc->ioc_regs.err_set);
  88. }
  89. /*
  90. * Host to LPU mailbox message addresses
  91. */
  92. static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
  93. { HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 },
  94. { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }
  95. };
  96. /*
  97. * Host <-> LPU mailbox command/status registers
  98. */
  99. static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
  100. { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
  101. { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT }
  102. };
  103. static void
  104. bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
  105. {
  106. void __iomem *rb;
  107. int pcifn = bfa_ioc_pcifn(ioc);
  108. rb = bfa_ioc_bar0(ioc);
  109. ioc->ioc_regs.hfn_mbox = rb + iocreg_fnreg[pcifn].hfn_mbox;
  110. ioc->ioc_regs.lpu_mbox = rb + iocreg_fnreg[pcifn].lpu_mbox;
  111. ioc->ioc_regs.host_page_num_fn = rb + iocreg_fnreg[pcifn].hfn_pgn;
  112. if (ioc->port_id == 0) {
  113. ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
  114. ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
  115. ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_STATE_REG;
  116. } else {
  117. ioc->ioc_regs.heartbeat = (rb + BFA_IOC1_HBEAT_REG);
  118. ioc->ioc_regs.ioc_fwstate = (rb + BFA_IOC1_STATE_REG);
  119. ioc->ioc_regs.alt_ioc_fwstate = (rb + BFA_IOC0_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. /*
  168. * Cleanup hw semaphore and usecnt registers
  169. */
  170. static void
  171. bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc)
  172. {
  173. /*
  174. * Read the hw sem reg to make sure that it is locked
  175. * before we clear it. If it is not locked, writing 1
  176. * will lock it instead of clearing it.
  177. */
  178. readl(ioc->ioc_regs.ioc_sem_reg);
  179. writel(1, ioc->ioc_regs.ioc_sem_reg);
  180. }
  181. /**
  182. * Synchronized IOC failure processing routines
  183. */
  184. static void
  185. bfa_ioc_cb_sync_join(struct bfa_ioc_s *ioc)
  186. {
  187. }
  188. static void
  189. bfa_ioc_cb_sync_leave(struct bfa_ioc_s *ioc)
  190. {
  191. }
  192. static void
  193. bfa_ioc_cb_sync_ack(struct bfa_ioc_s *ioc)
  194. {
  195. writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
  196. }
  197. static bfa_boolean_t
  198. bfa_ioc_cb_sync_complete(struct bfa_ioc_s *ioc)
  199. {
  200. uint32_t fwstate, alt_fwstate;
  201. fwstate = readl(ioc->ioc_regs.ioc_fwstate);
  202. /**
  203. * At this point, this IOC is hoding the hw sem in the
  204. * start path (fwcheck) OR in the disable/enable path
  205. * OR to check if the other IOC has acknowledged failure.
  206. *
  207. * So, this IOC can be in UNINIT, INITING, DISABLED, FAIL
  208. * or in MEMTEST states. In a normal scenario, this IOC
  209. * can not be in OP state when this function is called.
  210. *
  211. * However, this IOC could still be in OP state when
  212. * the OS driver is starting up, if the OptROM code has
  213. * left it in that state.
  214. *
  215. * If we had marked this IOC's fwstate as BFI_IOC_FAIL
  216. * in the failure case and now, if the fwstate is not
  217. * BFI_IOC_FAIL it implies that the other PCI fn have
  218. * reinitialized the ASIC or this IOC got disabled, so
  219. * return TRUE.
  220. */
  221. if (fwstate == BFI_IOC_UNINIT ||
  222. fwstate == BFI_IOC_INITING ||
  223. fwstate == BFI_IOC_DISABLED ||
  224. fwstate == BFI_IOC_MEMTEST ||
  225. fwstate == BFI_IOC_OP)
  226. return BFA_TRUE;
  227. else {
  228. alt_fwstate = readl(ioc->ioc_regs.alt_ioc_fwstate);
  229. if (alt_fwstate == BFI_IOC_FAIL ||
  230. alt_fwstate == BFI_IOC_DISABLED ||
  231. alt_fwstate == BFI_IOC_UNINIT ||
  232. alt_fwstate == BFI_IOC_INITING ||
  233. alt_fwstate == BFI_IOC_MEMTEST)
  234. return BFA_TRUE;
  235. else
  236. return BFA_FALSE;
  237. }
  238. }
  239. bfa_status_t
  240. bfa_ioc_cb_pll_init(void __iomem *rb, bfa_boolean_t fcmode)
  241. {
  242. u32 pll_sclk, pll_fclk;
  243. pll_sclk = __APP_PLL_212_ENABLE | __APP_PLL_212_LRESETN |
  244. __APP_PLL_212_P0_1(3U) |
  245. __APP_PLL_212_JITLMT0_1(3U) |
  246. __APP_PLL_212_CNTLMT0_1(3U);
  247. pll_fclk = __APP_PLL_400_ENABLE | __APP_PLL_400_LRESETN |
  248. __APP_PLL_400_RSEL200500 | __APP_PLL_400_P0_1(3U) |
  249. __APP_PLL_400_JITLMT0_1(3U) |
  250. __APP_PLL_400_CNTLMT0_1(3U);
  251. writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
  252. writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
  253. writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
  254. writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
  255. writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
  256. writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
  257. writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
  258. writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
  259. writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
  260. writel(__APP_PLL_212_BYPASS | __APP_PLL_212_LOGIC_SOFT_RESET,
  261. rb + APP_PLL_212_CTL_REG);
  262. writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
  263. writel(__APP_PLL_400_BYPASS | __APP_PLL_400_LOGIC_SOFT_RESET,
  264. rb + APP_PLL_400_CTL_REG);
  265. udelay(2);
  266. writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
  267. writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
  268. writel(pll_sclk | __APP_PLL_212_LOGIC_SOFT_RESET,
  269. rb + APP_PLL_212_CTL_REG);
  270. writel(pll_fclk | __APP_PLL_400_LOGIC_SOFT_RESET,
  271. rb + APP_PLL_400_CTL_REG);
  272. udelay(2000);
  273. writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
  274. writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
  275. writel(pll_sclk, (rb + APP_PLL_212_CTL_REG));
  276. writel(pll_fclk, (rb + APP_PLL_400_CTL_REG));
  277. return BFA_STATUS_OK;
  278. }