bfa_core.c 31 KB

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