bfa_ioc_cb.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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 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. struct bfi_ioc_image_hdr_s fwhdr;
  66. uint32_t fwstate = readl(ioc->ioc_regs.ioc_fwstate);
  67. if (fwstate == BFI_IOC_UNINIT)
  68. return BFA_TRUE;
  69. bfa_ioc_fwver_get(ioc, &fwhdr);
  70. if (swab32(fwhdr.exec) == BFI_BOOT_TYPE_NORMAL)
  71. return BFA_TRUE;
  72. bfa_trc(ioc, fwstate);
  73. bfa_trc(ioc, fwhdr.exec);
  74. writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
  75. return BFA_TRUE;
  76. }
  77. static void
  78. bfa_ioc_cb_firmware_unlock(struct bfa_ioc_s *ioc)
  79. {
  80. }
  81. /*
  82. * Notify other functions on HB failure.
  83. */
  84. static void
  85. bfa_ioc_cb_notify_fail(struct bfa_ioc_s *ioc)
  86. {
  87. writel(__PSS_ERR_STATUS_SET, ioc->ioc_regs.err_set);
  88. readl(ioc->ioc_regs.err_set);
  89. }
  90. /*
  91. * Host to LPU mailbox message addresses
  92. */
  93. static struct { u32 hfn_mbox, lpu_mbox, hfn_pgn; } iocreg_fnreg[] = {
  94. { HOSTFN0_LPU_MBOX0_0, LPU_HOSTFN0_MBOX0_0, HOST_PAGE_NUM_FN0 },
  95. { HOSTFN1_LPU_MBOX0_8, LPU_HOSTFN1_MBOX0_8, HOST_PAGE_NUM_FN1 }
  96. };
  97. /*
  98. * Host <-> LPU mailbox command/status registers
  99. */
  100. static struct { u32 hfn, lpu; } iocreg_mbcmd[] = {
  101. { HOSTFN0_LPU0_CMD_STAT, LPU0_HOSTFN0_CMD_STAT },
  102. { HOSTFN1_LPU1_CMD_STAT, LPU1_HOSTFN1_CMD_STAT }
  103. };
  104. static void
  105. bfa_ioc_cb_reg_init(struct bfa_ioc_s *ioc)
  106. {
  107. void __iomem *rb;
  108. int pcifn = bfa_ioc_pcifn(ioc);
  109. rb = bfa_ioc_bar0(ioc);
  110. ioc->ioc_regs.hfn_mbox = rb + iocreg_fnreg[pcifn].hfn_mbox;
  111. ioc->ioc_regs.lpu_mbox = rb + iocreg_fnreg[pcifn].lpu_mbox;
  112. ioc->ioc_regs.host_page_num_fn = rb + iocreg_fnreg[pcifn].hfn_pgn;
  113. if (ioc->port_id == 0) {
  114. ioc->ioc_regs.heartbeat = rb + BFA_IOC0_HBEAT_REG;
  115. ioc->ioc_regs.ioc_fwstate = rb + BFA_IOC0_STATE_REG;
  116. ioc->ioc_regs.alt_ioc_fwstate = rb + BFA_IOC1_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. ioc->ioc_regs.alt_ioc_fwstate = (rb + BFA_IOC0_STATE_REG);
  121. }
  122. /*
  123. * Host <-> LPU mailbox command/status registers
  124. */
  125. ioc->ioc_regs.hfn_mbox_cmd = rb + iocreg_mbcmd[pcifn].hfn;
  126. ioc->ioc_regs.lpu_mbox_cmd = rb + iocreg_mbcmd[pcifn].lpu;
  127. /*
  128. * PSS control registers
  129. */
  130. ioc->ioc_regs.pss_ctl_reg = (rb + PSS_CTL_REG);
  131. ioc->ioc_regs.pss_err_status_reg = (rb + PSS_ERR_STATUS_REG);
  132. ioc->ioc_regs.app_pll_fast_ctl_reg = (rb + APP_PLL_400_CTL_REG);
  133. ioc->ioc_regs.app_pll_slow_ctl_reg = (rb + APP_PLL_212_CTL_REG);
  134. /*
  135. * IOC semaphore registers and serialization
  136. */
  137. ioc->ioc_regs.ioc_sem_reg = (rb + HOST_SEM0_REG);
  138. ioc->ioc_regs.ioc_init_sem_reg = (rb + HOST_SEM2_REG);
  139. /*
  140. * sram memory access
  141. */
  142. ioc->ioc_regs.smem_page_start = (rb + PSS_SMEM_PAGE_START);
  143. ioc->ioc_regs.smem_pg0 = BFI_IOC_SMEM_PG0_CB;
  144. /*
  145. * err set reg : for notification of hb failure
  146. */
  147. ioc->ioc_regs.err_set = (rb + ERR_SET_REG);
  148. }
  149. /*
  150. * Initialize IOC to port mapping.
  151. */
  152. static void
  153. bfa_ioc_cb_map_port(struct bfa_ioc_s *ioc)
  154. {
  155. /*
  156. * For crossbow, port id is same as pci function.
  157. */
  158. ioc->port_id = bfa_ioc_pcifn(ioc);
  159. bfa_trc(ioc, ioc->port_id);
  160. }
  161. /*
  162. * Set interrupt mode for a function: INTX or MSIX
  163. */
  164. static void
  165. bfa_ioc_cb_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t msix)
  166. {
  167. }
  168. /*
  169. * Synchronized IOC failure processing routines
  170. */
  171. static bfa_boolean_t
  172. bfa_ioc_cb_sync_start(struct bfa_ioc_s *ioc)
  173. {
  174. return bfa_ioc_cb_sync_complete(ioc);
  175. }
  176. /*
  177. * Cleanup hw semaphore and usecnt registers
  178. */
  179. static void
  180. bfa_ioc_cb_ownership_reset(struct bfa_ioc_s *ioc)
  181. {
  182. /*
  183. * Read the hw sem reg to make sure that it is locked
  184. * before we clear it. If it is not locked, writing 1
  185. * will lock it instead of clearing it.
  186. */
  187. readl(ioc->ioc_regs.ioc_sem_reg);
  188. writel(1, ioc->ioc_regs.ioc_sem_reg);
  189. }
  190. /*
  191. * Synchronized IOC failure processing routines
  192. */
  193. static void
  194. bfa_ioc_cb_sync_join(struct bfa_ioc_s *ioc)
  195. {
  196. }
  197. static void
  198. bfa_ioc_cb_sync_leave(struct bfa_ioc_s *ioc)
  199. {
  200. }
  201. static void
  202. bfa_ioc_cb_sync_ack(struct bfa_ioc_s *ioc)
  203. {
  204. writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
  205. }
  206. static bfa_boolean_t
  207. bfa_ioc_cb_sync_complete(struct bfa_ioc_s *ioc)
  208. {
  209. uint32_t fwstate, alt_fwstate;
  210. fwstate = readl(ioc->ioc_regs.ioc_fwstate);
  211. /*
  212. * At this point, this IOC is hoding the hw sem in the
  213. * start path (fwcheck) OR in the disable/enable path
  214. * OR to check if the other IOC has acknowledged failure.
  215. *
  216. * So, this IOC can be in UNINIT, INITING, DISABLED, FAIL
  217. * or in MEMTEST states. In a normal scenario, this IOC
  218. * can not be in OP state when this function is called.
  219. *
  220. * However, this IOC could still be in OP state when
  221. * the OS driver is starting up, if the OptROM code has
  222. * left it in that state.
  223. *
  224. * If we had marked this IOC's fwstate as BFI_IOC_FAIL
  225. * in the failure case and now, if the fwstate is not
  226. * BFI_IOC_FAIL it implies that the other PCI fn have
  227. * reinitialized the ASIC or this IOC got disabled, so
  228. * return TRUE.
  229. */
  230. if (fwstate == BFI_IOC_UNINIT ||
  231. fwstate == BFI_IOC_INITING ||
  232. fwstate == BFI_IOC_DISABLED ||
  233. fwstate == BFI_IOC_MEMTEST ||
  234. fwstate == BFI_IOC_OP)
  235. return BFA_TRUE;
  236. else {
  237. alt_fwstate = readl(ioc->ioc_regs.alt_ioc_fwstate);
  238. if (alt_fwstate == BFI_IOC_FAIL ||
  239. alt_fwstate == BFI_IOC_DISABLED ||
  240. alt_fwstate == BFI_IOC_UNINIT ||
  241. alt_fwstate == BFI_IOC_INITING ||
  242. alt_fwstate == BFI_IOC_MEMTEST)
  243. return BFA_TRUE;
  244. else
  245. return BFA_FALSE;
  246. }
  247. }
  248. bfa_status_t
  249. bfa_ioc_cb_pll_init(void __iomem *rb, bfa_boolean_t fcmode)
  250. {
  251. u32 pll_sclk, pll_fclk;
  252. pll_sclk = __APP_PLL_212_ENABLE | __APP_PLL_212_LRESETN |
  253. __APP_PLL_212_P0_1(3U) |
  254. __APP_PLL_212_JITLMT0_1(3U) |
  255. __APP_PLL_212_CNTLMT0_1(3U);
  256. pll_fclk = __APP_PLL_400_ENABLE | __APP_PLL_400_LRESETN |
  257. __APP_PLL_400_RSEL200500 | __APP_PLL_400_P0_1(3U) |
  258. __APP_PLL_400_JITLMT0_1(3U) |
  259. __APP_PLL_400_CNTLMT0_1(3U);
  260. writel(BFI_IOC_UNINIT, (rb + BFA_IOC0_STATE_REG));
  261. writel(BFI_IOC_UNINIT, (rb + BFA_IOC1_STATE_REG));
  262. writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
  263. writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
  264. writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
  265. writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
  266. writel(0xffffffffU, (rb + HOSTFN0_INT_MSK));
  267. writel(0xffffffffU, (rb + HOSTFN1_INT_MSK));
  268. writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
  269. writel(__APP_PLL_212_BYPASS | __APP_PLL_212_LOGIC_SOFT_RESET,
  270. rb + APP_PLL_212_CTL_REG);
  271. writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
  272. writel(__APP_PLL_400_BYPASS | __APP_PLL_400_LOGIC_SOFT_RESET,
  273. rb + APP_PLL_400_CTL_REG);
  274. udelay(2);
  275. writel(__APP_PLL_212_LOGIC_SOFT_RESET, rb + APP_PLL_212_CTL_REG);
  276. writel(__APP_PLL_400_LOGIC_SOFT_RESET, rb + APP_PLL_400_CTL_REG);
  277. writel(pll_sclk | __APP_PLL_212_LOGIC_SOFT_RESET,
  278. rb + APP_PLL_212_CTL_REG);
  279. writel(pll_fclk | __APP_PLL_400_LOGIC_SOFT_RESET,
  280. rb + APP_PLL_400_CTL_REG);
  281. udelay(2000);
  282. writel(0xffffffffU, (rb + HOSTFN0_INT_STATUS));
  283. writel(0xffffffffU, (rb + HOSTFN1_INT_STATUS));
  284. writel(pll_sclk, (rb + APP_PLL_212_CTL_REG));
  285. writel(pll_fclk, (rb + APP_PLL_400_CTL_REG));
  286. return BFA_STATUS_OK;
  287. }