bfa_ioc_cb.c 11 KB

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