bfa_core.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  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_modules.h"
  19. #include "bfi_reg.h"
  20. BFA_TRC_FILE(HAL, CORE);
  21. /*
  22. * BFA module list terminated by NULL
  23. */
  24. static struct bfa_module_s *hal_mods[] = {
  25. &hal_mod_sgpg,
  26. &hal_mod_fcport,
  27. &hal_mod_fcxp,
  28. &hal_mod_lps,
  29. &hal_mod_uf,
  30. &hal_mod_rport,
  31. &hal_mod_fcp,
  32. NULL
  33. };
  34. /*
  35. * Message handlers for various modules.
  36. */
  37. static bfa_isr_func_t bfa_isrs[BFI_MC_MAX] = {
  38. bfa_isr_unhandled, /* NONE */
  39. bfa_isr_unhandled, /* BFI_MC_IOC */
  40. bfa_isr_unhandled, /* BFI_MC_DIAG */
  41. bfa_isr_unhandled, /* BFI_MC_FLASH */
  42. bfa_isr_unhandled, /* BFI_MC_CEE */
  43. bfa_fcport_isr, /* BFI_MC_FCPORT */
  44. bfa_isr_unhandled, /* BFI_MC_IOCFC */
  45. bfa_isr_unhandled, /* BFI_MC_LL */
  46. bfa_uf_isr, /* BFI_MC_UF */
  47. bfa_fcxp_isr, /* BFI_MC_FCXP */
  48. bfa_lps_isr, /* BFI_MC_LPS */
  49. bfa_rport_isr, /* BFI_MC_RPORT */
  50. bfa_itn_isr, /* BFI_MC_ITN */
  51. bfa_isr_unhandled, /* BFI_MC_IOIM_READ */
  52. bfa_isr_unhandled, /* BFI_MC_IOIM_WRITE */
  53. bfa_isr_unhandled, /* BFI_MC_IOIM_IO */
  54. bfa_ioim_isr, /* BFI_MC_IOIM */
  55. bfa_ioim_good_comp_isr, /* BFI_MC_IOIM_IOCOM */
  56. bfa_tskim_isr, /* BFI_MC_TSKIM */
  57. bfa_isr_unhandled, /* BFI_MC_SBOOT */
  58. bfa_isr_unhandled, /* BFI_MC_IPFC */
  59. bfa_isr_unhandled, /* BFI_MC_PORT */
  60. bfa_isr_unhandled, /* --------- */
  61. bfa_isr_unhandled, /* --------- */
  62. bfa_isr_unhandled, /* --------- */
  63. bfa_isr_unhandled, /* --------- */
  64. bfa_isr_unhandled, /* --------- */
  65. bfa_isr_unhandled, /* --------- */
  66. bfa_isr_unhandled, /* --------- */
  67. bfa_isr_unhandled, /* --------- */
  68. bfa_isr_unhandled, /* --------- */
  69. bfa_isr_unhandled, /* --------- */
  70. };
  71. /*
  72. * Message handlers for mailbox command classes
  73. */
  74. static bfa_ioc_mbox_mcfunc_t bfa_mbox_isrs[BFI_MC_MAX] = {
  75. NULL,
  76. NULL, /* BFI_MC_IOC */
  77. NULL, /* BFI_MC_DIAG */
  78. NULL, /* BFI_MC_FLASH */
  79. NULL, /* BFI_MC_CEE */
  80. NULL, /* BFI_MC_PORT */
  81. bfa_iocfc_isr, /* BFI_MC_IOCFC */
  82. NULL,
  83. };
  84. static void
  85. bfa_com_port_attach(struct bfa_s *bfa, struct bfa_meminfo_s *mi)
  86. {
  87. struct bfa_port_s *port = &bfa->modules.port;
  88. u32 dm_len;
  89. u8 *dm_kva;
  90. u64 dm_pa;
  91. dm_len = bfa_port_meminfo();
  92. dm_kva = bfa_meminfo_dma_virt(mi);
  93. dm_pa = bfa_meminfo_dma_phys(mi);
  94. memset(port, 0, sizeof(struct bfa_port_s));
  95. bfa_port_attach(port, &bfa->ioc, bfa, bfa->trcmod);
  96. bfa_port_mem_claim(port, dm_kva, dm_pa);
  97. bfa_meminfo_dma_virt(mi) = dm_kva + dm_len;
  98. bfa_meminfo_dma_phys(mi) = dm_pa + dm_len;
  99. }
  100. /*
  101. * BFA IOC FC related definitions
  102. */
  103. /*
  104. * IOC local definitions
  105. */
  106. #define BFA_IOCFC_TOV 5000 /* msecs */
  107. enum {
  108. BFA_IOCFC_ACT_NONE = 0,
  109. BFA_IOCFC_ACT_INIT = 1,
  110. BFA_IOCFC_ACT_STOP = 2,
  111. BFA_IOCFC_ACT_DISABLE = 3,
  112. };
  113. #define DEF_CFG_NUM_FABRICS 1
  114. #define DEF_CFG_NUM_LPORTS 256
  115. #define DEF_CFG_NUM_CQS 4
  116. #define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
  117. #define DEF_CFG_NUM_TSKIM_REQS 128
  118. #define DEF_CFG_NUM_FCXP_REQS 64
  119. #define DEF_CFG_NUM_UF_BUFS 64
  120. #define DEF_CFG_NUM_RPORTS 1024
  121. #define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
  122. #define DEF_CFG_NUM_TINS 256
  123. #define DEF_CFG_NUM_SGPGS 2048
  124. #define DEF_CFG_NUM_REQQ_ELEMS 256
  125. #define DEF_CFG_NUM_RSPQ_ELEMS 64
  126. #define DEF_CFG_NUM_SBOOT_TGTS 16
  127. #define DEF_CFG_NUM_SBOOT_LUNS 16
  128. /*
  129. * forward declaration for IOC FC functions
  130. */
  131. static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
  132. static void bfa_iocfc_disable_cbfn(void *bfa_arg);
  133. static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
  134. static void bfa_iocfc_reset_cbfn(void *bfa_arg);
  135. static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
  136. /*
  137. * BFA Interrupt handling functions
  138. */
  139. static void
  140. bfa_reqq_resume(struct bfa_s *bfa, int qid)
  141. {
  142. struct list_head *waitq, *qe, *qen;
  143. struct bfa_reqq_wait_s *wqe;
  144. waitq = bfa_reqq(bfa, qid);
  145. list_for_each_safe(qe, qen, waitq) {
  146. /*
  147. * Callback only as long as there is room in request queue
  148. */
  149. if (bfa_reqq_full(bfa, qid))
  150. break;
  151. list_del(qe);
  152. wqe = (struct bfa_reqq_wait_s *) qe;
  153. wqe->qresume(wqe->cbarg);
  154. }
  155. }
  156. static inline void
  157. bfa_isr_rspq(struct bfa_s *bfa, int qid)
  158. {
  159. struct bfi_msg_s *m;
  160. u32 pi, ci;
  161. struct list_head *waitq;
  162. bfa->iocfc.hwif.hw_rspq_ack(bfa, qid);
  163. ci = bfa_rspq_ci(bfa, qid);
  164. pi = bfa_rspq_pi(bfa, qid);
  165. while (ci != pi) {
  166. m = bfa_rspq_elem(bfa, qid, ci);
  167. WARN_ON(m->mhdr.msg_class >= BFI_MC_MAX);
  168. bfa_isrs[m->mhdr.msg_class] (bfa, m);
  169. CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
  170. }
  171. /*
  172. * update CI
  173. */
  174. bfa_rspq_ci(bfa, qid) = pi;
  175. writel(pi, bfa->iocfc.bfa_regs.rme_q_ci[qid]);
  176. mmiowb();
  177. /*
  178. * Resume any pending requests in the corresponding reqq.
  179. */
  180. waitq = bfa_reqq(bfa, qid);
  181. if (!list_empty(waitq))
  182. bfa_reqq_resume(bfa, qid);
  183. }
  184. static inline void
  185. bfa_isr_reqq(struct bfa_s *bfa, int qid)
  186. {
  187. struct list_head *waitq;
  188. qid &= (BFI_IOC_MAX_CQS - 1);
  189. bfa->iocfc.hwif.hw_reqq_ack(bfa, qid);
  190. /*
  191. * Resume any pending requests in the corresponding reqq.
  192. */
  193. waitq = bfa_reqq(bfa, qid);
  194. if (!list_empty(waitq))
  195. bfa_reqq_resume(bfa, qid);
  196. }
  197. void
  198. bfa_msix_all(struct bfa_s *bfa, int vec)
  199. {
  200. bfa_intx(bfa);
  201. }
  202. bfa_boolean_t
  203. bfa_intx(struct bfa_s *bfa)
  204. {
  205. u32 intr, qintr;
  206. int queue;
  207. intr = readl(bfa->iocfc.bfa_regs.intr_status);
  208. if (!intr)
  209. return BFA_FALSE;
  210. /*
  211. * RME completion queue interrupt
  212. */
  213. qintr = intr & __HFN_INT_RME_MASK;
  214. writel(qintr, bfa->iocfc.bfa_regs.intr_status);
  215. for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
  216. if ((intr & (__HFN_INT_RME_Q0 << queue)) && bfa->queue_process)
  217. bfa_isr_rspq(bfa, queue & (BFI_IOC_MAX_CQS - 1));
  218. }
  219. intr &= ~qintr;
  220. if (!intr)
  221. return BFA_TRUE;
  222. /*
  223. * CPE completion queue interrupt
  224. */
  225. qintr = intr & __HFN_INT_CPE_MASK;
  226. writel(qintr, bfa->iocfc.bfa_regs.intr_status);
  227. for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
  228. if ((intr & (__HFN_INT_CPE_Q0 << queue)) && bfa->queue_process)
  229. bfa_isr_reqq(bfa, queue & (BFI_IOC_MAX_CQS - 1));
  230. }
  231. intr &= ~qintr;
  232. if (!intr)
  233. return BFA_TRUE;
  234. bfa_msix_lpu_err(bfa, intr);
  235. return BFA_TRUE;
  236. }
  237. void
  238. bfa_isr_enable(struct bfa_s *bfa)
  239. {
  240. u32 umsk;
  241. int pci_func = bfa_ioc_pcifn(&bfa->ioc);
  242. bfa_trc(bfa, pci_func);
  243. bfa_msix_ctrl_install(bfa);
  244. if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
  245. umsk = __HFN_INT_ERR_MASK_CT2;
  246. umsk |= pci_func == 0 ?
  247. __HFN_INT_FN0_MASK_CT2 : __HFN_INT_FN1_MASK_CT2;
  248. } else {
  249. umsk = __HFN_INT_ERR_MASK;
  250. umsk |= pci_func == 0 ? __HFN_INT_FN0_MASK : __HFN_INT_FN1_MASK;
  251. }
  252. writel(umsk, bfa->iocfc.bfa_regs.intr_status);
  253. writel(~umsk, bfa->iocfc.bfa_regs.intr_mask);
  254. bfa->iocfc.intr_mask = ~umsk;
  255. bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
  256. }
  257. void
  258. bfa_isr_disable(struct bfa_s *bfa)
  259. {
  260. bfa_isr_mode_set(bfa, BFA_FALSE);
  261. writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
  262. bfa_msix_uninstall(bfa);
  263. }
  264. void
  265. bfa_msix_reqq(struct bfa_s *bfa, int vec)
  266. {
  267. bfa_isr_reqq(bfa, vec - bfa->iocfc.hwif.cpe_vec_q0);
  268. }
  269. void
  270. bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
  271. {
  272. bfa_trc(bfa, m->mhdr.msg_class);
  273. bfa_trc(bfa, m->mhdr.msg_id);
  274. bfa_trc(bfa, m->mhdr.mtag.i2htok);
  275. WARN_ON(1);
  276. bfa_trc_stop(bfa->trcmod);
  277. }
  278. void
  279. bfa_msix_rspq(struct bfa_s *bfa, int vec)
  280. {
  281. bfa_isr_rspq(bfa, vec - bfa->iocfc.hwif.rme_vec_q0);
  282. }
  283. void
  284. bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
  285. {
  286. u32 intr, curr_value;
  287. bfa_boolean_t lpu_isr, halt_isr, pss_isr;
  288. intr = readl(bfa->iocfc.bfa_regs.intr_status);
  289. if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
  290. halt_isr = intr & __HFN_INT_CPQ_HALT_CT2;
  291. pss_isr = intr & __HFN_INT_ERR_PSS_CT2;
  292. lpu_isr = intr & (__HFN_INT_MBOX_LPU0_CT2 |
  293. __HFN_INT_MBOX_LPU1_CT2);
  294. intr &= __HFN_INT_ERR_MASK_CT2;
  295. } else {
  296. halt_isr = intr & __HFN_INT_LL_HALT;
  297. pss_isr = intr & __HFN_INT_ERR_PSS;
  298. lpu_isr = intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1);
  299. intr &= __HFN_INT_ERR_MASK;
  300. }
  301. if (lpu_isr)
  302. bfa_ioc_mbox_isr(&bfa->ioc);
  303. if (intr) {
  304. if (halt_isr) {
  305. /*
  306. * If LL_HALT bit is set then FW Init Halt LL Port
  307. * Register needs to be cleared as well so Interrupt
  308. * Status Register will be cleared.
  309. */
  310. curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
  311. curr_value &= ~__FW_INIT_HALT_P;
  312. writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
  313. }
  314. if (pss_isr) {
  315. /*
  316. * ERR_PSS bit needs to be cleared as well in case
  317. * interrups are shared so driver's interrupt handler is
  318. * still called even though it is already masked out.
  319. */
  320. curr_value = readl(
  321. bfa->ioc.ioc_regs.pss_err_status_reg);
  322. writel(curr_value,
  323. bfa->ioc.ioc_regs.pss_err_status_reg);
  324. }
  325. writel(intr, bfa->iocfc.bfa_regs.intr_status);
  326. bfa_ioc_error_isr(&bfa->ioc);
  327. }
  328. }
  329. /*
  330. * BFA IOC FC related functions
  331. */
  332. /*
  333. * BFA IOC private functions
  334. */
  335. static void
  336. bfa_iocfc_cqs_sz(struct bfa_iocfc_cfg_s *cfg, u32 *dm_len)
  337. {
  338. int i, per_reqq_sz, per_rspq_sz;
  339. per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
  340. BFA_DMA_ALIGN_SZ);
  341. per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
  342. BFA_DMA_ALIGN_SZ);
  343. /*
  344. * Calculate CQ size
  345. */
  346. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  347. *dm_len = *dm_len + per_reqq_sz;
  348. *dm_len = *dm_len + per_rspq_sz;
  349. }
  350. /*
  351. * Calculate Shadow CI/PI size
  352. */
  353. for (i = 0; i < cfg->fwcfg.num_cqs; i++)
  354. *dm_len += (2 * BFA_CACHELINE_SZ);
  355. }
  356. static void
  357. bfa_iocfc_fw_cfg_sz(struct bfa_iocfc_cfg_s *cfg, u32 *dm_len)
  358. {
  359. *dm_len +=
  360. BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
  361. *dm_len +=
  362. BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
  363. BFA_CACHELINE_SZ);
  364. }
  365. /*
  366. * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
  367. */
  368. static void
  369. bfa_iocfc_send_cfg(void *bfa_arg)
  370. {
  371. struct bfa_s *bfa = bfa_arg;
  372. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  373. struct bfi_iocfc_cfg_req_s cfg_req;
  374. struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
  375. struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
  376. int i;
  377. WARN_ON(cfg->fwcfg.num_cqs > BFI_IOC_MAX_CQS);
  378. bfa_trc(bfa, cfg->fwcfg.num_cqs);
  379. bfa_iocfc_reset_queues(bfa);
  380. /*
  381. * initialize IOC configuration info
  382. */
  383. cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
  384. cfg_info->num_cqs = cfg->fwcfg.num_cqs;
  385. cfg_info->num_ioim_reqs = cpu_to_be16(cfg->fwcfg.num_ioim_reqs);
  386. cfg_info->num_fwtio_reqs = cpu_to_be16(cfg->fwcfg.num_fwtio_reqs);
  387. bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
  388. /*
  389. * dma map REQ and RSP circular queues and shadow pointers
  390. */
  391. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  392. bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
  393. iocfc->req_cq_ba[i].pa);
  394. bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
  395. iocfc->req_cq_shadow_ci[i].pa);
  396. cfg_info->req_cq_elems[i] =
  397. cpu_to_be16(cfg->drvcfg.num_reqq_elems);
  398. bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
  399. iocfc->rsp_cq_ba[i].pa);
  400. bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
  401. iocfc->rsp_cq_shadow_pi[i].pa);
  402. cfg_info->rsp_cq_elems[i] =
  403. cpu_to_be16(cfg->drvcfg.num_rspq_elems);
  404. }
  405. /*
  406. * Enable interrupt coalescing if it is driver init path
  407. * and not ioc disable/enable path.
  408. */
  409. if (!iocfc->cfgdone)
  410. cfg_info->intr_attr.coalesce = BFA_TRUE;
  411. iocfc->cfgdone = BFA_FALSE;
  412. /*
  413. * dma map IOC configuration itself
  414. */
  415. bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
  416. bfa_lpuid(bfa));
  417. bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
  418. bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
  419. sizeof(struct bfi_iocfc_cfg_req_s));
  420. }
  421. static void
  422. bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  423. struct bfa_pcidev_s *pcidev)
  424. {
  425. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  426. bfa->bfad = bfad;
  427. iocfc->bfa = bfa;
  428. iocfc->action = BFA_IOCFC_ACT_NONE;
  429. iocfc->cfg = *cfg;
  430. /*
  431. * Initialize chip specific handlers.
  432. */
  433. if (bfa_asic_id_ctc(bfa_ioc_devid(&bfa->ioc))) {
  434. iocfc->hwif.hw_reginit = bfa_hwct_reginit;
  435. iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
  436. iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
  437. iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
  438. iocfc->hwif.hw_msix_ctrl_install = bfa_hwct_msix_ctrl_install;
  439. iocfc->hwif.hw_msix_queue_install = bfa_hwct_msix_queue_install;
  440. iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
  441. iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
  442. iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
  443. iocfc->hwif.hw_msix_get_rme_range = bfa_hwct_msix_get_rme_range;
  444. iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CT;
  445. iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CT;
  446. } else {
  447. iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
  448. iocfc->hwif.hw_reqq_ack = bfa_hwcb_reqq_ack;
  449. iocfc->hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
  450. iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
  451. iocfc->hwif.hw_msix_ctrl_install = bfa_hwcb_msix_ctrl_install;
  452. iocfc->hwif.hw_msix_queue_install = bfa_hwcb_msix_queue_install;
  453. iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
  454. iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
  455. iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
  456. iocfc->hwif.hw_msix_get_rme_range = bfa_hwcb_msix_get_rme_range;
  457. iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CB +
  458. bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
  459. iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CB +
  460. bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
  461. }
  462. if (bfa_asic_id_ct2(bfa_ioc_devid(&bfa->ioc))) {
  463. iocfc->hwif.hw_reginit = bfa_hwct2_reginit;
  464. iocfc->hwif.hw_isr_mode_set = NULL;
  465. }
  466. iocfc->hwif.hw_reginit(bfa);
  467. bfa->msix.nvecs = 0;
  468. }
  469. static void
  470. bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg,
  471. struct bfa_meminfo_s *meminfo)
  472. {
  473. u8 *dm_kva;
  474. u64 dm_pa;
  475. int i, per_reqq_sz, per_rspq_sz;
  476. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  477. int dbgsz;
  478. dm_kva = bfa_meminfo_dma_virt(meminfo);
  479. dm_pa = bfa_meminfo_dma_phys(meminfo);
  480. /*
  481. * First allocate dma memory for IOC.
  482. */
  483. bfa_ioc_mem_claim(&bfa->ioc, dm_kva, dm_pa);
  484. dm_kva += BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
  485. dm_pa += BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
  486. /*
  487. * Claim DMA-able memory for the request/response queues and for shadow
  488. * ci/pi registers
  489. */
  490. per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
  491. BFA_DMA_ALIGN_SZ);
  492. per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
  493. BFA_DMA_ALIGN_SZ);
  494. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  495. iocfc->req_cq_ba[i].kva = dm_kva;
  496. iocfc->req_cq_ba[i].pa = dm_pa;
  497. memset(dm_kva, 0, per_reqq_sz);
  498. dm_kva += per_reqq_sz;
  499. dm_pa += per_reqq_sz;
  500. iocfc->rsp_cq_ba[i].kva = dm_kva;
  501. iocfc->rsp_cq_ba[i].pa = dm_pa;
  502. memset(dm_kva, 0, per_rspq_sz);
  503. dm_kva += per_rspq_sz;
  504. dm_pa += per_rspq_sz;
  505. }
  506. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  507. iocfc->req_cq_shadow_ci[i].kva = dm_kva;
  508. iocfc->req_cq_shadow_ci[i].pa = dm_pa;
  509. dm_kva += BFA_CACHELINE_SZ;
  510. dm_pa += BFA_CACHELINE_SZ;
  511. iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
  512. iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
  513. dm_kva += BFA_CACHELINE_SZ;
  514. dm_pa += BFA_CACHELINE_SZ;
  515. }
  516. /*
  517. * Claim DMA-able memory for the config info page
  518. */
  519. bfa->iocfc.cfg_info.kva = dm_kva;
  520. bfa->iocfc.cfg_info.pa = dm_pa;
  521. bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
  522. dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
  523. dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
  524. /*
  525. * Claim DMA-able memory for the config response
  526. */
  527. bfa->iocfc.cfgrsp_dma.kva = dm_kva;
  528. bfa->iocfc.cfgrsp_dma.pa = dm_pa;
  529. bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
  530. dm_kva +=
  531. BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
  532. BFA_CACHELINE_SZ);
  533. dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
  534. BFA_CACHELINE_SZ);
  535. bfa_meminfo_dma_virt(meminfo) = dm_kva;
  536. bfa_meminfo_dma_phys(meminfo) = dm_pa;
  537. dbgsz = (bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
  538. if (dbgsz > 0) {
  539. bfa_ioc_debug_memclaim(&bfa->ioc, bfa_meminfo_kva(meminfo));
  540. bfa_meminfo_kva(meminfo) += dbgsz;
  541. }
  542. }
  543. /*
  544. * Start BFA submodules.
  545. */
  546. static void
  547. bfa_iocfc_start_submod(struct bfa_s *bfa)
  548. {
  549. int i;
  550. bfa->queue_process = BFA_TRUE;
  551. for (i = 0; i < BFI_IOC_MAX_CQS; i++)
  552. bfa->iocfc.hwif.hw_rspq_ack(bfa, i);
  553. for (i = 0; hal_mods[i]; i++)
  554. hal_mods[i]->start(bfa);
  555. }
  556. /*
  557. * Disable BFA submodules.
  558. */
  559. static void
  560. bfa_iocfc_disable_submod(struct bfa_s *bfa)
  561. {
  562. int i;
  563. for (i = 0; hal_mods[i]; i++)
  564. hal_mods[i]->iocdisable(bfa);
  565. }
  566. static void
  567. bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
  568. {
  569. struct bfa_s *bfa = bfa_arg;
  570. if (complete) {
  571. if (bfa->iocfc.cfgdone)
  572. bfa_cb_init(bfa->bfad, BFA_STATUS_OK);
  573. else
  574. bfa_cb_init(bfa->bfad, BFA_STATUS_FAILED);
  575. } else {
  576. if (bfa->iocfc.cfgdone)
  577. bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
  578. }
  579. }
  580. static void
  581. bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
  582. {
  583. struct bfa_s *bfa = bfa_arg;
  584. struct bfad_s *bfad = bfa->bfad;
  585. if (compl)
  586. complete(&bfad->comp);
  587. else
  588. bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
  589. }
  590. static void
  591. bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
  592. {
  593. struct bfa_s *bfa = bfa_arg;
  594. struct bfad_s *bfad = bfa->bfad;
  595. if (compl)
  596. complete(&bfad->disable_comp);
  597. }
  598. /**
  599. * configure queue registers from firmware response
  600. */
  601. static void
  602. bfa_iocfc_qreg(struct bfa_s *bfa, struct bfi_iocfc_qreg_s *qreg)
  603. {
  604. int i;
  605. struct bfa_iocfc_regs_s *r = &bfa->iocfc.bfa_regs;
  606. void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
  607. for (i = 0; i < BFI_IOC_MAX_CQS; i++) {
  608. r->cpe_q_ci[i] = kva + be32_to_cpu(qreg->cpe_q_ci_off[i]);
  609. r->cpe_q_pi[i] = kva + be32_to_cpu(qreg->cpe_q_pi_off[i]);
  610. r->cpe_q_ctrl[i] = kva + be32_to_cpu(qreg->cpe_qctl_off[i]);
  611. r->rme_q_ci[i] = kva + be32_to_cpu(qreg->rme_q_ci_off[i]);
  612. r->rme_q_pi[i] = kva + be32_to_cpu(qreg->rme_q_pi_off[i]);
  613. r->rme_q_ctrl[i] = kva + be32_to_cpu(qreg->rme_qctl_off[i]);
  614. }
  615. }
  616. /*
  617. * Update BFA configuration from firmware configuration.
  618. */
  619. static void
  620. bfa_iocfc_cfgrsp(struct bfa_s *bfa)
  621. {
  622. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  623. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  624. struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
  625. fwcfg->num_cqs = fwcfg->num_cqs;
  626. fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
  627. fwcfg->num_fwtio_reqs = be16_to_cpu(fwcfg->num_fwtio_reqs);
  628. fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
  629. fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
  630. fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
  631. fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
  632. iocfc->cfgdone = BFA_TRUE;
  633. /*
  634. * configure queue register offsets as learnt from firmware
  635. */
  636. bfa_iocfc_qreg(bfa, &cfgrsp->qreg);
  637. /*
  638. * Install MSIX queue handlers
  639. */
  640. bfa_msix_queue_install(bfa);
  641. /*
  642. * Configuration is complete - initialize/start submodules
  643. */
  644. bfa_fcport_init(bfa);
  645. if (iocfc->action == BFA_IOCFC_ACT_INIT)
  646. bfa_cb_queue(bfa, &iocfc->init_hcb_qe, bfa_iocfc_init_cb, bfa);
  647. else
  648. bfa_iocfc_start_submod(bfa);
  649. }
  650. void
  651. bfa_iocfc_reset_queues(struct bfa_s *bfa)
  652. {
  653. int q;
  654. for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
  655. bfa_reqq_ci(bfa, q) = 0;
  656. bfa_reqq_pi(bfa, q) = 0;
  657. bfa_rspq_ci(bfa, q) = 0;
  658. bfa_rspq_pi(bfa, q) = 0;
  659. }
  660. }
  661. /*
  662. * IOC enable request is complete
  663. */
  664. static void
  665. bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
  666. {
  667. struct bfa_s *bfa = bfa_arg;
  668. if (status != BFA_STATUS_OK) {
  669. bfa_isr_disable(bfa);
  670. if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
  671. bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
  672. bfa_iocfc_init_cb, bfa);
  673. return;
  674. }
  675. bfa_iocfc_send_cfg(bfa);
  676. }
  677. /*
  678. * IOC disable request is complete
  679. */
  680. static void
  681. bfa_iocfc_disable_cbfn(void *bfa_arg)
  682. {
  683. struct bfa_s *bfa = bfa_arg;
  684. bfa_isr_disable(bfa);
  685. bfa_iocfc_disable_submod(bfa);
  686. if (bfa->iocfc.action == BFA_IOCFC_ACT_STOP)
  687. bfa_cb_queue(bfa, &bfa->iocfc.stop_hcb_qe, bfa_iocfc_stop_cb,
  688. bfa);
  689. else {
  690. WARN_ON(bfa->iocfc.action != BFA_IOCFC_ACT_DISABLE);
  691. bfa_cb_queue(bfa, &bfa->iocfc.dis_hcb_qe, bfa_iocfc_disable_cb,
  692. bfa);
  693. }
  694. }
  695. /*
  696. * Notify sub-modules of hardware failure.
  697. */
  698. static void
  699. bfa_iocfc_hbfail_cbfn(void *bfa_arg)
  700. {
  701. struct bfa_s *bfa = bfa_arg;
  702. bfa->queue_process = BFA_FALSE;
  703. bfa_isr_disable(bfa);
  704. bfa_iocfc_disable_submod(bfa);
  705. if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
  706. bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe, bfa_iocfc_init_cb,
  707. bfa);
  708. }
  709. /*
  710. * Actions on chip-reset completion.
  711. */
  712. static void
  713. bfa_iocfc_reset_cbfn(void *bfa_arg)
  714. {
  715. struct bfa_s *bfa = bfa_arg;
  716. bfa_iocfc_reset_queues(bfa);
  717. bfa_isr_enable(bfa);
  718. }
  719. /*
  720. * Query IOC memory requirement information.
  721. */
  722. void
  723. bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
  724. u32 *dm_len)
  725. {
  726. /* dma memory for IOC */
  727. *dm_len += BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
  728. bfa_iocfc_fw_cfg_sz(cfg, dm_len);
  729. bfa_iocfc_cqs_sz(cfg, dm_len);
  730. *km_len += (bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
  731. }
  732. /*
  733. * Query IOC memory requirement information.
  734. */
  735. void
  736. bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  737. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  738. {
  739. int i;
  740. struct bfa_ioc_s *ioc = &bfa->ioc;
  741. bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
  742. bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
  743. bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
  744. bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
  745. ioc->trcmod = bfa->trcmod;
  746. bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
  747. /*
  748. * Set FC mode for BFA_PCI_DEVICE_ID_CT_FC.
  749. */
  750. if (pcidev->device_id == BFA_PCI_DEVICE_ID_CT_FC)
  751. bfa_ioc_set_fcmode(&bfa->ioc);
  752. bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_PCIFN_CLASS_FC);
  753. bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
  754. bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
  755. bfa_iocfc_mem_claim(bfa, cfg, meminfo);
  756. INIT_LIST_HEAD(&bfa->timer_mod.timer_q);
  757. INIT_LIST_HEAD(&bfa->comp_q);
  758. for (i = 0; i < BFI_IOC_MAX_CQS; i++)
  759. INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
  760. }
  761. /*
  762. * Query IOC memory requirement information.
  763. */
  764. void
  765. bfa_iocfc_init(struct bfa_s *bfa)
  766. {
  767. bfa->iocfc.action = BFA_IOCFC_ACT_INIT;
  768. bfa_ioc_enable(&bfa->ioc);
  769. }
  770. /*
  771. * IOC start called from bfa_start(). Called to start IOC operations
  772. * at driver instantiation for this instance.
  773. */
  774. void
  775. bfa_iocfc_start(struct bfa_s *bfa)
  776. {
  777. if (bfa->iocfc.cfgdone)
  778. bfa_iocfc_start_submod(bfa);
  779. }
  780. /*
  781. * IOC stop called from bfa_stop(). Called only when driver is unloaded
  782. * for this instance.
  783. */
  784. void
  785. bfa_iocfc_stop(struct bfa_s *bfa)
  786. {
  787. bfa->iocfc.action = BFA_IOCFC_ACT_STOP;
  788. bfa->queue_process = BFA_FALSE;
  789. bfa_ioc_disable(&bfa->ioc);
  790. }
  791. void
  792. bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
  793. {
  794. struct bfa_s *bfa = bfaarg;
  795. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  796. union bfi_iocfc_i2h_msg_u *msg;
  797. msg = (union bfi_iocfc_i2h_msg_u *) m;
  798. bfa_trc(bfa, msg->mh.msg_id);
  799. switch (msg->mh.msg_id) {
  800. case BFI_IOCFC_I2H_CFG_REPLY:
  801. bfa_iocfc_cfgrsp(bfa);
  802. break;
  803. case BFI_IOCFC_I2H_UPDATEQ_RSP:
  804. iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
  805. break;
  806. default:
  807. WARN_ON(1);
  808. }
  809. }
  810. void
  811. bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
  812. {
  813. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  814. attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
  815. attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
  816. be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
  817. be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
  818. attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
  819. be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
  820. be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
  821. attr->config = iocfc->cfg;
  822. }
  823. bfa_status_t
  824. bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
  825. {
  826. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  827. struct bfi_iocfc_set_intr_req_s *m;
  828. iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
  829. iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
  830. iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
  831. if (!bfa_iocfc_is_operational(bfa))
  832. return BFA_STATUS_OK;
  833. m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
  834. if (!m)
  835. return BFA_STATUS_DEVBUSY;
  836. bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
  837. bfa_lpuid(bfa));
  838. m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
  839. m->delay = iocfc->cfginfo->intr_attr.delay;
  840. m->latency = iocfc->cfginfo->intr_attr.latency;
  841. bfa_trc(bfa, attr->delay);
  842. bfa_trc(bfa, attr->latency);
  843. bfa_reqq_produce(bfa, BFA_REQQ_IOC);
  844. return BFA_STATUS_OK;
  845. }
  846. void
  847. bfa_iocfc_set_snsbase(struct bfa_s *bfa, u64 snsbase_pa)
  848. {
  849. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  850. iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
  851. bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase, snsbase_pa);
  852. }
  853. /*
  854. * Enable IOC after it is disabled.
  855. */
  856. void
  857. bfa_iocfc_enable(struct bfa_s *bfa)
  858. {
  859. bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
  860. "IOC Enable");
  861. bfa_ioc_enable(&bfa->ioc);
  862. }
  863. void
  864. bfa_iocfc_disable(struct bfa_s *bfa)
  865. {
  866. bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
  867. "IOC Disable");
  868. bfa->iocfc.action = BFA_IOCFC_ACT_DISABLE;
  869. bfa->queue_process = BFA_FALSE;
  870. bfa_ioc_disable(&bfa->ioc);
  871. }
  872. bfa_boolean_t
  873. bfa_iocfc_is_operational(struct bfa_s *bfa)
  874. {
  875. return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
  876. }
  877. /*
  878. * Return boot target port wwns -- read from boot information in flash.
  879. */
  880. void
  881. bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
  882. {
  883. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  884. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  885. int i;
  886. if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
  887. bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
  888. *nwwns = cfgrsp->pbc_cfg.nbluns;
  889. for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
  890. wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
  891. return;
  892. }
  893. *nwwns = cfgrsp->bootwwns.nwwns;
  894. memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
  895. }
  896. int
  897. bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
  898. {
  899. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  900. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  901. memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
  902. return cfgrsp->pbc_cfg.nvports;
  903. }
  904. /*
  905. * Use this function query the memory requirement of the BFA library.
  906. * This function needs to be called before bfa_attach() to get the
  907. * memory required of the BFA layer for a given driver configuration.
  908. *
  909. * This call will fail, if the cap is out of range compared to pre-defined
  910. * values within the BFA library
  911. *
  912. * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
  913. * its configuration in this structure.
  914. * The default values for struct bfa_iocfc_cfg_s can be
  915. * fetched using bfa_cfg_get_default() API.
  916. *
  917. * If cap's boundary check fails, the library will use
  918. * the default bfa_cap_t values (and log a warning msg).
  919. *
  920. * @param[out] meminfo - pointer to bfa_meminfo_t. This content
  921. * indicates the memory type (see bfa_mem_type_t) and
  922. * amount of memory required.
  923. *
  924. * Driver should allocate the memory, populate the
  925. * starting address for each block and provide the same
  926. * structure as input parameter to bfa_attach() call.
  927. *
  928. * @return void
  929. *
  930. * Special Considerations: @note
  931. */
  932. void
  933. bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo)
  934. {
  935. int i;
  936. u32 km_len = 0, dm_len = 0;
  937. WARN_ON((cfg == NULL) || (meminfo == NULL));
  938. memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
  939. meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_type =
  940. BFA_MEM_TYPE_KVA;
  941. meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_type =
  942. BFA_MEM_TYPE_DMA;
  943. bfa_iocfc_meminfo(cfg, &km_len, &dm_len);
  944. for (i = 0; hal_mods[i]; i++)
  945. hal_mods[i]->meminfo(cfg, &km_len, &dm_len);
  946. dm_len += bfa_port_meminfo();
  947. meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_len = km_len;
  948. meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_len = dm_len;
  949. }
  950. /*
  951. * Use this function to do attach the driver instance with the BFA
  952. * library. This function will not trigger any HW initialization
  953. * process (which will be done in bfa_init() call)
  954. *
  955. * This call will fail, if the cap is out of range compared to
  956. * pre-defined values within the BFA library
  957. *
  958. * @param[out] bfa Pointer to bfa_t.
  959. * @param[in] bfad Opaque handle back to the driver's IOC structure
  960. * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
  961. * that was used in bfa_cfg_get_meminfo().
  962. * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
  963. * use the bfa_cfg_get_meminfo() call to
  964. * find the memory blocks required, allocate the
  965. * required memory and provide the starting addresses.
  966. * @param[in] pcidev pointer to struct bfa_pcidev_s
  967. *
  968. * @return
  969. * void
  970. *
  971. * Special Considerations:
  972. *
  973. * @note
  974. *
  975. */
  976. void
  977. bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  978. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  979. {
  980. int i;
  981. struct bfa_mem_elem_s *melem;
  982. bfa->fcs = BFA_FALSE;
  983. WARN_ON((cfg == NULL) || (meminfo == NULL));
  984. /*
  985. * initialize all memory pointers for iterative allocation
  986. */
  987. for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
  988. melem = meminfo->meminfo + i;
  989. melem->kva_curp = melem->kva;
  990. melem->dma_curp = melem->dma;
  991. }
  992. bfa_iocfc_attach(bfa, bfad, cfg, meminfo, pcidev);
  993. for (i = 0; hal_mods[i]; i++)
  994. hal_mods[i]->attach(bfa, bfad, cfg, meminfo, pcidev);
  995. bfa_com_port_attach(bfa, meminfo);
  996. }
  997. /*
  998. * Use this function to delete a BFA IOC. IOC should be stopped (by
  999. * calling bfa_stop()) before this function call.
  1000. *
  1001. * @param[in] bfa - pointer to bfa_t.
  1002. *
  1003. * @return
  1004. * void
  1005. *
  1006. * Special Considerations:
  1007. *
  1008. * @note
  1009. */
  1010. void
  1011. bfa_detach(struct bfa_s *bfa)
  1012. {
  1013. int i;
  1014. for (i = 0; hal_mods[i]; i++)
  1015. hal_mods[i]->detach(bfa);
  1016. bfa_ioc_detach(&bfa->ioc);
  1017. }
  1018. void
  1019. bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
  1020. {
  1021. INIT_LIST_HEAD(comp_q);
  1022. list_splice_tail_init(&bfa->comp_q, comp_q);
  1023. }
  1024. void
  1025. bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
  1026. {
  1027. struct list_head *qe;
  1028. struct list_head *qen;
  1029. struct bfa_cb_qe_s *hcb_qe;
  1030. list_for_each_safe(qe, qen, comp_q) {
  1031. hcb_qe = (struct bfa_cb_qe_s *) qe;
  1032. hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
  1033. }
  1034. }
  1035. void
  1036. bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
  1037. {
  1038. struct list_head *qe;
  1039. struct bfa_cb_qe_s *hcb_qe;
  1040. while (!list_empty(comp_q)) {
  1041. bfa_q_deq(comp_q, &qe);
  1042. hcb_qe = (struct bfa_cb_qe_s *) qe;
  1043. hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
  1044. }
  1045. }
  1046. /*
  1047. * Return the list of PCI vendor/device id lists supported by this
  1048. * BFA instance.
  1049. */
  1050. void
  1051. bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
  1052. {
  1053. static struct bfa_pciid_s __pciids[] = {
  1054. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
  1055. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
  1056. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
  1057. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
  1058. };
  1059. *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
  1060. *pciids = __pciids;
  1061. }
  1062. /*
  1063. * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
  1064. * into BFA layer). The OS driver can then turn back and overwrite entries that
  1065. * have been configured by the user.
  1066. *
  1067. * @param[in] cfg - pointer to bfa_ioc_cfg_t
  1068. *
  1069. * @return
  1070. * void
  1071. *
  1072. * Special Considerations:
  1073. * note
  1074. */
  1075. void
  1076. bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
  1077. {
  1078. cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
  1079. cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
  1080. cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
  1081. cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
  1082. cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
  1083. cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
  1084. cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
  1085. cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
  1086. cfg->fwcfg.num_fwtio_reqs = 0;
  1087. cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
  1088. cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
  1089. cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
  1090. cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
  1091. cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
  1092. cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
  1093. cfg->drvcfg.ioc_recover = BFA_FALSE;
  1094. cfg->drvcfg.delay_comp = BFA_FALSE;
  1095. }
  1096. void
  1097. bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
  1098. {
  1099. bfa_cfg_get_default(cfg);
  1100. cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
  1101. cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
  1102. cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
  1103. cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
  1104. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  1105. cfg->fwcfg.num_fwtio_reqs = 0;
  1106. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  1107. cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
  1108. cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
  1109. cfg->drvcfg.min_cfg = BFA_TRUE;
  1110. }