bfa_core.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  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_fcdiag,
  26. &hal_mod_sgpg,
  27. &hal_mod_fcport,
  28. &hal_mod_fcxp,
  29. &hal_mod_lps,
  30. &hal_mod_uf,
  31. &hal_mod_rport,
  32. &hal_mod_fcp,
  33. &hal_mod_dconf,
  34. NULL
  35. };
  36. /*
  37. * Message handlers for various modules.
  38. */
  39. static bfa_isr_func_t bfa_isrs[BFI_MC_MAX] = {
  40. bfa_isr_unhandled, /* NONE */
  41. bfa_isr_unhandled, /* BFI_MC_IOC */
  42. bfa_fcdiag_intr, /* BFI_MC_DIAG */
  43. bfa_isr_unhandled, /* BFI_MC_FLASH */
  44. bfa_isr_unhandled, /* BFI_MC_CEE */
  45. bfa_fcport_isr, /* BFI_MC_FCPORT */
  46. bfa_isr_unhandled, /* BFI_MC_IOCFC */
  47. bfa_isr_unhandled, /* BFI_MC_LL */
  48. bfa_uf_isr, /* BFI_MC_UF */
  49. bfa_fcxp_isr, /* BFI_MC_FCXP */
  50. bfa_lps_isr, /* BFI_MC_LPS */
  51. bfa_rport_isr, /* BFI_MC_RPORT */
  52. bfa_itn_isr, /* BFI_MC_ITN */
  53. bfa_isr_unhandled, /* BFI_MC_IOIM_READ */
  54. bfa_isr_unhandled, /* BFI_MC_IOIM_WRITE */
  55. bfa_isr_unhandled, /* BFI_MC_IOIM_IO */
  56. bfa_ioim_isr, /* BFI_MC_IOIM */
  57. bfa_ioim_good_comp_isr, /* BFI_MC_IOIM_IOCOM */
  58. bfa_tskim_isr, /* BFI_MC_TSKIM */
  59. bfa_isr_unhandled, /* BFI_MC_SBOOT */
  60. bfa_isr_unhandled, /* BFI_MC_IPFC */
  61. bfa_isr_unhandled, /* BFI_MC_PORT */
  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. bfa_isr_unhandled, /* --------- */
  71. bfa_isr_unhandled, /* --------- */
  72. };
  73. /*
  74. * Message handlers for mailbox command classes
  75. */
  76. static bfa_ioc_mbox_mcfunc_t bfa_mbox_isrs[BFI_MC_MAX] = {
  77. NULL,
  78. NULL, /* BFI_MC_IOC */
  79. NULL, /* BFI_MC_DIAG */
  80. NULL, /* BFI_MC_FLASH */
  81. NULL, /* BFI_MC_CEE */
  82. NULL, /* BFI_MC_PORT */
  83. bfa_iocfc_isr, /* BFI_MC_IOCFC */
  84. NULL,
  85. };
  86. static void
  87. bfa_com_port_attach(struct bfa_s *bfa)
  88. {
  89. struct bfa_port_s *port = &bfa->modules.port;
  90. struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
  91. bfa_port_attach(port, &bfa->ioc, bfa, bfa->trcmod);
  92. bfa_port_mem_claim(port, port_dma->kva_curp, port_dma->dma_curp);
  93. }
  94. /*
  95. * ablk module attach
  96. */
  97. static void
  98. bfa_com_ablk_attach(struct bfa_s *bfa)
  99. {
  100. struct bfa_ablk_s *ablk = &bfa->modules.ablk;
  101. struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
  102. bfa_ablk_attach(ablk, &bfa->ioc);
  103. bfa_ablk_memclaim(ablk, ablk_dma->kva_curp, ablk_dma->dma_curp);
  104. }
  105. static void
  106. bfa_com_cee_attach(struct bfa_s *bfa)
  107. {
  108. struct bfa_cee_s *cee = &bfa->modules.cee;
  109. struct bfa_mem_dma_s *cee_dma = BFA_MEM_CEE_DMA(bfa);
  110. cee->trcmod = bfa->trcmod;
  111. bfa_cee_attach(cee, &bfa->ioc, bfa);
  112. bfa_cee_mem_claim(cee, cee_dma->kva_curp, cee_dma->dma_curp);
  113. }
  114. static void
  115. bfa_com_sfp_attach(struct bfa_s *bfa)
  116. {
  117. struct bfa_sfp_s *sfp = BFA_SFP_MOD(bfa);
  118. struct bfa_mem_dma_s *sfp_dma = BFA_MEM_SFP_DMA(bfa);
  119. bfa_sfp_attach(sfp, &bfa->ioc, bfa, bfa->trcmod);
  120. bfa_sfp_memclaim(sfp, sfp_dma->kva_curp, sfp_dma->dma_curp);
  121. }
  122. static void
  123. bfa_com_flash_attach(struct bfa_s *bfa, bfa_boolean_t mincfg)
  124. {
  125. struct bfa_flash_s *flash = BFA_FLASH(bfa);
  126. struct bfa_mem_dma_s *flash_dma = BFA_MEM_FLASH_DMA(bfa);
  127. bfa_flash_attach(flash, &bfa->ioc, bfa, bfa->trcmod, mincfg);
  128. bfa_flash_memclaim(flash, flash_dma->kva_curp,
  129. flash_dma->dma_curp, mincfg);
  130. }
  131. static void
  132. bfa_com_diag_attach(struct bfa_s *bfa)
  133. {
  134. struct bfa_diag_s *diag = BFA_DIAG_MOD(bfa);
  135. struct bfa_mem_dma_s *diag_dma = BFA_MEM_DIAG_DMA(bfa);
  136. bfa_diag_attach(diag, &bfa->ioc, bfa, bfa_fcport_beacon, bfa->trcmod);
  137. bfa_diag_memclaim(diag, diag_dma->kva_curp, diag_dma->dma_curp);
  138. }
  139. static void
  140. bfa_com_phy_attach(struct bfa_s *bfa, bfa_boolean_t mincfg)
  141. {
  142. struct bfa_phy_s *phy = BFA_PHY(bfa);
  143. struct bfa_mem_dma_s *phy_dma = BFA_MEM_PHY_DMA(bfa);
  144. bfa_phy_attach(phy, &bfa->ioc, bfa, bfa->trcmod, mincfg);
  145. bfa_phy_memclaim(phy, phy_dma->kva_curp, phy_dma->dma_curp, mincfg);
  146. }
  147. /*
  148. * BFA IOC FC related definitions
  149. */
  150. /*
  151. * IOC local definitions
  152. */
  153. #define BFA_IOCFC_TOV 5000 /* msecs */
  154. enum {
  155. BFA_IOCFC_ACT_NONE = 0,
  156. BFA_IOCFC_ACT_INIT = 1,
  157. BFA_IOCFC_ACT_STOP = 2,
  158. BFA_IOCFC_ACT_DISABLE = 3,
  159. BFA_IOCFC_ACT_ENABLE = 4,
  160. };
  161. #define DEF_CFG_NUM_FABRICS 1
  162. #define DEF_CFG_NUM_LPORTS 256
  163. #define DEF_CFG_NUM_CQS 4
  164. #define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
  165. #define DEF_CFG_NUM_TSKIM_REQS 128
  166. #define DEF_CFG_NUM_FCXP_REQS 64
  167. #define DEF_CFG_NUM_UF_BUFS 64
  168. #define DEF_CFG_NUM_RPORTS 1024
  169. #define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
  170. #define DEF_CFG_NUM_TINS 256
  171. #define DEF_CFG_NUM_SGPGS 2048
  172. #define DEF_CFG_NUM_REQQ_ELEMS 256
  173. #define DEF_CFG_NUM_RSPQ_ELEMS 64
  174. #define DEF_CFG_NUM_SBOOT_TGTS 16
  175. #define DEF_CFG_NUM_SBOOT_LUNS 16
  176. /*
  177. * forward declaration for IOC FC functions
  178. */
  179. static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
  180. static void bfa_iocfc_disable_cbfn(void *bfa_arg);
  181. static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
  182. static void bfa_iocfc_reset_cbfn(void *bfa_arg);
  183. static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
  184. /*
  185. * BFA Interrupt handling functions
  186. */
  187. static void
  188. bfa_reqq_resume(struct bfa_s *bfa, int qid)
  189. {
  190. struct list_head *waitq, *qe, *qen;
  191. struct bfa_reqq_wait_s *wqe;
  192. waitq = bfa_reqq(bfa, qid);
  193. list_for_each_safe(qe, qen, waitq) {
  194. /*
  195. * Callback only as long as there is room in request queue
  196. */
  197. if (bfa_reqq_full(bfa, qid))
  198. break;
  199. list_del(qe);
  200. wqe = (struct bfa_reqq_wait_s *) qe;
  201. wqe->qresume(wqe->cbarg);
  202. }
  203. }
  204. bfa_boolean_t
  205. bfa_isr_rspq(struct bfa_s *bfa, int qid)
  206. {
  207. struct bfi_msg_s *m;
  208. u32 pi, ci;
  209. struct list_head *waitq;
  210. bfa_boolean_t ret;
  211. ci = bfa_rspq_ci(bfa, qid);
  212. pi = bfa_rspq_pi(bfa, qid);
  213. ret = (ci != pi);
  214. while (ci != pi) {
  215. m = bfa_rspq_elem(bfa, qid, ci);
  216. WARN_ON(m->mhdr.msg_class >= BFI_MC_MAX);
  217. bfa_isrs[m->mhdr.msg_class] (bfa, m);
  218. CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
  219. }
  220. /*
  221. * acknowledge RME completions and update CI
  222. */
  223. bfa_isr_rspq_ack(bfa, qid, ci);
  224. /*
  225. * Resume any pending requests in the corresponding reqq.
  226. */
  227. waitq = bfa_reqq(bfa, qid);
  228. if (!list_empty(waitq))
  229. bfa_reqq_resume(bfa, qid);
  230. return ret;
  231. }
  232. static inline void
  233. bfa_isr_reqq(struct bfa_s *bfa, int qid)
  234. {
  235. struct list_head *waitq;
  236. bfa_isr_reqq_ack(bfa, qid);
  237. /*
  238. * Resume any pending requests in the corresponding reqq.
  239. */
  240. waitq = bfa_reqq(bfa, qid);
  241. if (!list_empty(waitq))
  242. bfa_reqq_resume(bfa, qid);
  243. }
  244. void
  245. bfa_msix_all(struct bfa_s *bfa, int vec)
  246. {
  247. u32 intr, qintr;
  248. int queue;
  249. intr = readl(bfa->iocfc.bfa_regs.intr_status);
  250. if (!intr)
  251. return;
  252. /*
  253. * RME completion queue interrupt
  254. */
  255. qintr = intr & __HFN_INT_RME_MASK;
  256. if (qintr && bfa->queue_process) {
  257. for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
  258. bfa_isr_rspq(bfa, queue);
  259. }
  260. intr &= ~qintr;
  261. if (!intr)
  262. return;
  263. /*
  264. * CPE completion queue interrupt
  265. */
  266. qintr = intr & __HFN_INT_CPE_MASK;
  267. if (qintr && bfa->queue_process) {
  268. for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
  269. bfa_isr_reqq(bfa, queue);
  270. }
  271. intr &= ~qintr;
  272. if (!intr)
  273. return;
  274. bfa_msix_lpu_err(bfa, intr);
  275. }
  276. bfa_boolean_t
  277. bfa_intx(struct bfa_s *bfa)
  278. {
  279. u32 intr, qintr;
  280. int queue;
  281. bfa_boolean_t rspq_comp = BFA_FALSE;
  282. intr = readl(bfa->iocfc.bfa_regs.intr_status);
  283. qintr = intr & (__HFN_INT_RME_MASK | __HFN_INT_CPE_MASK);
  284. if (qintr)
  285. writel(qintr, bfa->iocfc.bfa_regs.intr_status);
  286. /*
  287. * Unconditional RME completion queue interrupt
  288. */
  289. if (bfa->queue_process) {
  290. for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
  291. if (bfa_isr_rspq(bfa, queue))
  292. rspq_comp = BFA_TRUE;
  293. }
  294. if (!intr)
  295. return (qintr | rspq_comp) ? BFA_TRUE : BFA_FALSE;
  296. /*
  297. * CPE completion queue interrupt
  298. */
  299. qintr = intr & __HFN_INT_CPE_MASK;
  300. if (qintr && bfa->queue_process) {
  301. for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
  302. bfa_isr_reqq(bfa, queue);
  303. }
  304. intr &= ~qintr;
  305. if (!intr)
  306. return BFA_TRUE;
  307. bfa_msix_lpu_err(bfa, intr);
  308. return BFA_TRUE;
  309. }
  310. void
  311. bfa_isr_enable(struct bfa_s *bfa)
  312. {
  313. u32 umsk;
  314. int pci_func = bfa_ioc_pcifn(&bfa->ioc);
  315. bfa_trc(bfa, pci_func);
  316. bfa_msix_ctrl_install(bfa);
  317. if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
  318. umsk = __HFN_INT_ERR_MASK_CT2;
  319. umsk |= pci_func == 0 ?
  320. __HFN_INT_FN0_MASK_CT2 : __HFN_INT_FN1_MASK_CT2;
  321. } else {
  322. umsk = __HFN_INT_ERR_MASK;
  323. umsk |= pci_func == 0 ? __HFN_INT_FN0_MASK : __HFN_INT_FN1_MASK;
  324. }
  325. writel(umsk, bfa->iocfc.bfa_regs.intr_status);
  326. writel(~umsk, bfa->iocfc.bfa_regs.intr_mask);
  327. bfa->iocfc.intr_mask = ~umsk;
  328. bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
  329. }
  330. void
  331. bfa_isr_disable(struct bfa_s *bfa)
  332. {
  333. bfa_isr_mode_set(bfa, BFA_FALSE);
  334. writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
  335. bfa_msix_uninstall(bfa);
  336. }
  337. void
  338. bfa_msix_reqq(struct bfa_s *bfa, int vec)
  339. {
  340. bfa_isr_reqq(bfa, vec - bfa->iocfc.hwif.cpe_vec_q0);
  341. }
  342. void
  343. bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
  344. {
  345. bfa_trc(bfa, m->mhdr.msg_class);
  346. bfa_trc(bfa, m->mhdr.msg_id);
  347. bfa_trc(bfa, m->mhdr.mtag.i2htok);
  348. WARN_ON(1);
  349. bfa_trc_stop(bfa->trcmod);
  350. }
  351. void
  352. bfa_msix_rspq(struct bfa_s *bfa, int vec)
  353. {
  354. bfa_isr_rspq(bfa, vec - bfa->iocfc.hwif.rme_vec_q0);
  355. }
  356. void
  357. bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
  358. {
  359. u32 intr, curr_value;
  360. bfa_boolean_t lpu_isr, halt_isr, pss_isr;
  361. intr = readl(bfa->iocfc.bfa_regs.intr_status);
  362. if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
  363. halt_isr = intr & __HFN_INT_CPQ_HALT_CT2;
  364. pss_isr = intr & __HFN_INT_ERR_PSS_CT2;
  365. lpu_isr = intr & (__HFN_INT_MBOX_LPU0_CT2 |
  366. __HFN_INT_MBOX_LPU1_CT2);
  367. intr &= __HFN_INT_ERR_MASK_CT2;
  368. } else {
  369. halt_isr = bfa_asic_id_ct(bfa->ioc.pcidev.device_id) ?
  370. (intr & __HFN_INT_LL_HALT) : 0;
  371. pss_isr = intr & __HFN_INT_ERR_PSS;
  372. lpu_isr = intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1);
  373. intr &= __HFN_INT_ERR_MASK;
  374. }
  375. if (lpu_isr)
  376. bfa_ioc_mbox_isr(&bfa->ioc);
  377. if (intr) {
  378. if (halt_isr) {
  379. /*
  380. * If LL_HALT bit is set then FW Init Halt LL Port
  381. * Register needs to be cleared as well so Interrupt
  382. * Status Register will be cleared.
  383. */
  384. curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
  385. curr_value &= ~__FW_INIT_HALT_P;
  386. writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
  387. }
  388. if (pss_isr) {
  389. /*
  390. * ERR_PSS bit needs to be cleared as well in case
  391. * interrups are shared so driver's interrupt handler is
  392. * still called even though it is already masked out.
  393. */
  394. curr_value = readl(
  395. bfa->ioc.ioc_regs.pss_err_status_reg);
  396. writel(curr_value,
  397. bfa->ioc.ioc_regs.pss_err_status_reg);
  398. }
  399. writel(intr, bfa->iocfc.bfa_regs.intr_status);
  400. bfa_ioc_error_isr(&bfa->ioc);
  401. }
  402. }
  403. /*
  404. * BFA IOC FC related functions
  405. */
  406. /*
  407. * BFA IOC private functions
  408. */
  409. /*
  410. * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
  411. */
  412. static void
  413. bfa_iocfc_send_cfg(void *bfa_arg)
  414. {
  415. struct bfa_s *bfa = bfa_arg;
  416. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  417. struct bfi_iocfc_cfg_req_s cfg_req;
  418. struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
  419. struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
  420. int i;
  421. WARN_ON(cfg->fwcfg.num_cqs > BFI_IOC_MAX_CQS);
  422. bfa_trc(bfa, cfg->fwcfg.num_cqs);
  423. bfa_iocfc_reset_queues(bfa);
  424. /*
  425. * initialize IOC configuration info
  426. */
  427. cfg_info->single_msix_vec = 0;
  428. if (bfa->msix.nvecs == 1)
  429. cfg_info->single_msix_vec = 1;
  430. cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
  431. cfg_info->num_cqs = cfg->fwcfg.num_cqs;
  432. cfg_info->num_ioim_reqs = cpu_to_be16(cfg->fwcfg.num_ioim_reqs);
  433. cfg_info->num_fwtio_reqs = cpu_to_be16(cfg->fwcfg.num_fwtio_reqs);
  434. bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
  435. /*
  436. * dma map REQ and RSP circular queues and shadow pointers
  437. */
  438. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  439. bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
  440. iocfc->req_cq_ba[i].pa);
  441. bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
  442. iocfc->req_cq_shadow_ci[i].pa);
  443. cfg_info->req_cq_elems[i] =
  444. cpu_to_be16(cfg->drvcfg.num_reqq_elems);
  445. bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
  446. iocfc->rsp_cq_ba[i].pa);
  447. bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
  448. iocfc->rsp_cq_shadow_pi[i].pa);
  449. cfg_info->rsp_cq_elems[i] =
  450. cpu_to_be16(cfg->drvcfg.num_rspq_elems);
  451. }
  452. /*
  453. * Enable interrupt coalescing if it is driver init path
  454. * and not ioc disable/enable path.
  455. */
  456. if (!iocfc->cfgdone)
  457. cfg_info->intr_attr.coalesce = BFA_TRUE;
  458. iocfc->cfgdone = BFA_FALSE;
  459. /*
  460. * dma map IOC configuration itself
  461. */
  462. bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
  463. bfa_fn_lpu(bfa));
  464. bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
  465. bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
  466. sizeof(struct bfi_iocfc_cfg_req_s));
  467. }
  468. static void
  469. bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  470. struct bfa_pcidev_s *pcidev)
  471. {
  472. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  473. bfa->bfad = bfad;
  474. iocfc->bfa = bfa;
  475. iocfc->action = BFA_IOCFC_ACT_NONE;
  476. iocfc->cfg = *cfg;
  477. /*
  478. * Initialize chip specific handlers.
  479. */
  480. if (bfa_asic_id_ctc(bfa_ioc_devid(&bfa->ioc))) {
  481. iocfc->hwif.hw_reginit = bfa_hwct_reginit;
  482. iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
  483. iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
  484. iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
  485. iocfc->hwif.hw_msix_ctrl_install = bfa_hwct_msix_ctrl_install;
  486. iocfc->hwif.hw_msix_queue_install = bfa_hwct_msix_queue_install;
  487. iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
  488. iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
  489. iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
  490. iocfc->hwif.hw_msix_get_rme_range = bfa_hwct_msix_get_rme_range;
  491. iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CT;
  492. iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CT;
  493. } else {
  494. iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
  495. iocfc->hwif.hw_reqq_ack = NULL;
  496. iocfc->hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
  497. iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
  498. iocfc->hwif.hw_msix_ctrl_install = bfa_hwcb_msix_ctrl_install;
  499. iocfc->hwif.hw_msix_queue_install = bfa_hwcb_msix_queue_install;
  500. iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
  501. iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
  502. iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
  503. iocfc->hwif.hw_msix_get_rme_range = bfa_hwcb_msix_get_rme_range;
  504. iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CB +
  505. bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
  506. iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CB +
  507. bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
  508. }
  509. if (bfa_asic_id_ct2(bfa_ioc_devid(&bfa->ioc))) {
  510. iocfc->hwif.hw_reginit = bfa_hwct2_reginit;
  511. iocfc->hwif.hw_isr_mode_set = NULL;
  512. iocfc->hwif.hw_rspq_ack = bfa_hwct2_rspq_ack;
  513. }
  514. iocfc->hwif.hw_reginit(bfa);
  515. bfa->msix.nvecs = 0;
  516. }
  517. static void
  518. bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg)
  519. {
  520. u8 *dm_kva = NULL;
  521. u64 dm_pa = 0;
  522. int i, per_reqq_sz, per_rspq_sz, dbgsz;
  523. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  524. struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
  525. struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
  526. struct bfa_mem_dma_s *reqq_dma, *rspq_dma;
  527. /* First allocate dma memory for IOC */
  528. bfa_ioc_mem_claim(&bfa->ioc, bfa_mem_dma_virt(ioc_dma),
  529. bfa_mem_dma_phys(ioc_dma));
  530. /* Claim DMA-able memory for the request/response queues */
  531. per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
  532. BFA_DMA_ALIGN_SZ);
  533. per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
  534. BFA_DMA_ALIGN_SZ);
  535. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  536. reqq_dma = BFA_MEM_REQQ_DMA(bfa, i);
  537. iocfc->req_cq_ba[i].kva = bfa_mem_dma_virt(reqq_dma);
  538. iocfc->req_cq_ba[i].pa = bfa_mem_dma_phys(reqq_dma);
  539. memset(iocfc->req_cq_ba[i].kva, 0, per_reqq_sz);
  540. rspq_dma = BFA_MEM_RSPQ_DMA(bfa, i);
  541. iocfc->rsp_cq_ba[i].kva = bfa_mem_dma_virt(rspq_dma);
  542. iocfc->rsp_cq_ba[i].pa = bfa_mem_dma_phys(rspq_dma);
  543. memset(iocfc->rsp_cq_ba[i].kva, 0, per_rspq_sz);
  544. }
  545. /* Claim IOCFC dma memory - for shadow CI/PI */
  546. dm_kva = bfa_mem_dma_virt(iocfc_dma);
  547. dm_pa = bfa_mem_dma_phys(iocfc_dma);
  548. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  549. iocfc->req_cq_shadow_ci[i].kva = dm_kva;
  550. iocfc->req_cq_shadow_ci[i].pa = dm_pa;
  551. dm_kva += BFA_CACHELINE_SZ;
  552. dm_pa += BFA_CACHELINE_SZ;
  553. iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
  554. iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
  555. dm_kva += BFA_CACHELINE_SZ;
  556. dm_pa += BFA_CACHELINE_SZ;
  557. }
  558. /* Claim IOCFC dma memory - for the config info page */
  559. bfa->iocfc.cfg_info.kva = dm_kva;
  560. bfa->iocfc.cfg_info.pa = dm_pa;
  561. bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
  562. dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
  563. dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
  564. /* Claim IOCFC dma memory - for the config response */
  565. bfa->iocfc.cfgrsp_dma.kva = dm_kva;
  566. bfa->iocfc.cfgrsp_dma.pa = dm_pa;
  567. bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
  568. dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
  569. BFA_CACHELINE_SZ);
  570. dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
  571. BFA_CACHELINE_SZ);
  572. /* Claim IOCFC kva memory */
  573. dbgsz = (bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
  574. if (dbgsz > 0) {
  575. bfa_ioc_debug_memclaim(&bfa->ioc, bfa_mem_kva_curp(iocfc));
  576. bfa_mem_kva_curp(iocfc) += dbgsz;
  577. }
  578. }
  579. /*
  580. * Start BFA submodules.
  581. */
  582. static void
  583. bfa_iocfc_start_submod(struct bfa_s *bfa)
  584. {
  585. int i;
  586. bfa->queue_process = BFA_TRUE;
  587. for (i = 0; i < BFI_IOC_MAX_CQS; i++)
  588. bfa_isr_rspq_ack(bfa, i, bfa_rspq_ci(bfa, i));
  589. for (i = 0; hal_mods[i]; i++)
  590. hal_mods[i]->start(bfa);
  591. }
  592. /*
  593. * Disable BFA submodules.
  594. */
  595. static void
  596. bfa_iocfc_disable_submod(struct bfa_s *bfa)
  597. {
  598. int i;
  599. for (i = 0; hal_mods[i]; i++)
  600. hal_mods[i]->iocdisable(bfa);
  601. }
  602. static void
  603. bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
  604. {
  605. struct bfa_s *bfa = bfa_arg;
  606. if (complete) {
  607. if (bfa->iocfc.cfgdone && BFA_DCONF_MOD(bfa)->flashdone)
  608. bfa_cb_init(bfa->bfad, BFA_STATUS_OK);
  609. else
  610. bfa_cb_init(bfa->bfad, BFA_STATUS_FAILED);
  611. } else {
  612. if (bfa->iocfc.cfgdone)
  613. bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
  614. }
  615. }
  616. static void
  617. bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
  618. {
  619. struct bfa_s *bfa = bfa_arg;
  620. struct bfad_s *bfad = bfa->bfad;
  621. if (compl)
  622. complete(&bfad->comp);
  623. else
  624. bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
  625. }
  626. static void
  627. bfa_iocfc_enable_cb(void *bfa_arg, bfa_boolean_t compl)
  628. {
  629. struct bfa_s *bfa = bfa_arg;
  630. struct bfad_s *bfad = bfa->bfad;
  631. if (compl)
  632. complete(&bfad->enable_comp);
  633. }
  634. static void
  635. bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
  636. {
  637. struct bfa_s *bfa = bfa_arg;
  638. struct bfad_s *bfad = bfa->bfad;
  639. if (compl)
  640. complete(&bfad->disable_comp);
  641. }
  642. /**
  643. * configure queue registers from firmware response
  644. */
  645. static void
  646. bfa_iocfc_qreg(struct bfa_s *bfa, struct bfi_iocfc_qreg_s *qreg)
  647. {
  648. int i;
  649. struct bfa_iocfc_regs_s *r = &bfa->iocfc.bfa_regs;
  650. void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
  651. for (i = 0; i < BFI_IOC_MAX_CQS; i++) {
  652. bfa->iocfc.hw_qid[i] = qreg->hw_qid[i];
  653. r->cpe_q_ci[i] = kva + be32_to_cpu(qreg->cpe_q_ci_off[i]);
  654. r->cpe_q_pi[i] = kva + be32_to_cpu(qreg->cpe_q_pi_off[i]);
  655. r->cpe_q_ctrl[i] = kva + be32_to_cpu(qreg->cpe_qctl_off[i]);
  656. r->rme_q_ci[i] = kva + be32_to_cpu(qreg->rme_q_ci_off[i]);
  657. r->rme_q_pi[i] = kva + be32_to_cpu(qreg->rme_q_pi_off[i]);
  658. r->rme_q_ctrl[i] = kva + be32_to_cpu(qreg->rme_qctl_off[i]);
  659. }
  660. }
  661. static void
  662. bfa_iocfc_res_recfg(struct bfa_s *bfa, struct bfa_iocfc_fwcfg_s *fwcfg)
  663. {
  664. bfa_fcxp_res_recfg(bfa, fwcfg->num_fcxp_reqs);
  665. bfa_uf_res_recfg(bfa, fwcfg->num_uf_bufs);
  666. bfa_rport_res_recfg(bfa, fwcfg->num_rports);
  667. bfa_fcp_res_recfg(bfa, fwcfg->num_ioim_reqs);
  668. bfa_tskim_res_recfg(bfa, fwcfg->num_tskim_reqs);
  669. }
  670. /*
  671. * Update BFA configuration from firmware configuration.
  672. */
  673. static void
  674. bfa_iocfc_cfgrsp(struct bfa_s *bfa)
  675. {
  676. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  677. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  678. struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
  679. fwcfg->num_cqs = fwcfg->num_cqs;
  680. fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
  681. fwcfg->num_fwtio_reqs = be16_to_cpu(fwcfg->num_fwtio_reqs);
  682. fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
  683. fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
  684. fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
  685. fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
  686. iocfc->cfgdone = BFA_TRUE;
  687. /*
  688. * configure queue register offsets as learnt from firmware
  689. */
  690. bfa_iocfc_qreg(bfa, &cfgrsp->qreg);
  691. /*
  692. * Re-configure resources as learnt from Firmware
  693. */
  694. bfa_iocfc_res_recfg(bfa, fwcfg);
  695. /*
  696. * Install MSIX queue handlers
  697. */
  698. bfa_msix_queue_install(bfa);
  699. /*
  700. * Configuration is complete - initialize/start submodules
  701. */
  702. bfa_fcport_init(bfa);
  703. if (iocfc->action == BFA_IOCFC_ACT_INIT) {
  704. if (BFA_DCONF_MOD(bfa)->flashdone == BFA_TRUE)
  705. bfa_cb_queue(bfa, &iocfc->init_hcb_qe,
  706. bfa_iocfc_init_cb, bfa);
  707. } else {
  708. if (bfa->iocfc.action == BFA_IOCFC_ACT_ENABLE)
  709. bfa_cb_queue(bfa, &bfa->iocfc.en_hcb_qe,
  710. bfa_iocfc_enable_cb, bfa);
  711. bfa_iocfc_start_submod(bfa);
  712. }
  713. }
  714. void
  715. bfa_iocfc_reset_queues(struct bfa_s *bfa)
  716. {
  717. int q;
  718. for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
  719. bfa_reqq_ci(bfa, q) = 0;
  720. bfa_reqq_pi(bfa, q) = 0;
  721. bfa_rspq_ci(bfa, q) = 0;
  722. bfa_rspq_pi(bfa, q) = 0;
  723. }
  724. }
  725. /* Fabric Assigned Address specific functions */
  726. /*
  727. * Check whether IOC is ready before sending command down
  728. */
  729. static bfa_status_t
  730. bfa_faa_validate_request(struct bfa_s *bfa)
  731. {
  732. enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
  733. u32 card_type = bfa->ioc.attr->card_type;
  734. if (bfa_ioc_is_operational(&bfa->ioc)) {
  735. if ((ioc_type != BFA_IOC_TYPE_FC) || bfa_mfg_is_mezz(card_type))
  736. return BFA_STATUS_FEATURE_NOT_SUPPORTED;
  737. } else {
  738. if (!bfa_ioc_is_acq_addr(&bfa->ioc))
  739. return BFA_STATUS_IOC_NON_OP;
  740. }
  741. return BFA_STATUS_OK;
  742. }
  743. bfa_status_t
  744. bfa_faa_enable(struct bfa_s *bfa, bfa_cb_iocfc_t cbfn, void *cbarg)
  745. {
  746. struct bfi_faa_en_dis_s faa_enable_req;
  747. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  748. bfa_status_t status;
  749. iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
  750. iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
  751. status = bfa_faa_validate_request(bfa);
  752. if (status != BFA_STATUS_OK)
  753. return status;
  754. if (iocfc->faa_args.busy == BFA_TRUE)
  755. return BFA_STATUS_DEVBUSY;
  756. if (iocfc->faa_args.faa_state == BFA_FAA_ENABLED)
  757. return BFA_STATUS_FAA_ENABLED;
  758. if (bfa_fcport_is_trunk_enabled(bfa))
  759. return BFA_STATUS_ERROR_TRUNK_ENABLED;
  760. bfa_fcport_cfg_faa(bfa, BFA_FAA_ENABLED);
  761. iocfc->faa_args.busy = BFA_TRUE;
  762. memset(&faa_enable_req, 0, sizeof(struct bfi_faa_en_dis_s));
  763. bfi_h2i_set(faa_enable_req.mh, BFI_MC_IOCFC,
  764. BFI_IOCFC_H2I_FAA_ENABLE_REQ, bfa_fn_lpu(bfa));
  765. bfa_ioc_mbox_send(&bfa->ioc, &faa_enable_req,
  766. sizeof(struct bfi_faa_en_dis_s));
  767. return BFA_STATUS_OK;
  768. }
  769. bfa_status_t
  770. bfa_faa_disable(struct bfa_s *bfa, bfa_cb_iocfc_t cbfn,
  771. void *cbarg)
  772. {
  773. struct bfi_faa_en_dis_s faa_disable_req;
  774. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  775. bfa_status_t status;
  776. iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
  777. iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
  778. status = bfa_faa_validate_request(bfa);
  779. if (status != BFA_STATUS_OK)
  780. return status;
  781. if (iocfc->faa_args.busy == BFA_TRUE)
  782. return BFA_STATUS_DEVBUSY;
  783. if (iocfc->faa_args.faa_state == BFA_FAA_DISABLED)
  784. return BFA_STATUS_FAA_DISABLED;
  785. bfa_fcport_cfg_faa(bfa, BFA_FAA_DISABLED);
  786. iocfc->faa_args.busy = BFA_TRUE;
  787. memset(&faa_disable_req, 0, sizeof(struct bfi_faa_en_dis_s));
  788. bfi_h2i_set(faa_disable_req.mh, BFI_MC_IOCFC,
  789. BFI_IOCFC_H2I_FAA_DISABLE_REQ, bfa_fn_lpu(bfa));
  790. bfa_ioc_mbox_send(&bfa->ioc, &faa_disable_req,
  791. sizeof(struct bfi_faa_en_dis_s));
  792. return BFA_STATUS_OK;
  793. }
  794. bfa_status_t
  795. bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
  796. bfa_cb_iocfc_t cbfn, void *cbarg)
  797. {
  798. struct bfi_faa_query_s faa_attr_req;
  799. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  800. bfa_status_t status;
  801. iocfc->faa_args.faa_attr = attr;
  802. iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
  803. iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
  804. status = bfa_faa_validate_request(bfa);
  805. if (status != BFA_STATUS_OK)
  806. return status;
  807. if (iocfc->faa_args.busy == BFA_TRUE)
  808. return BFA_STATUS_DEVBUSY;
  809. iocfc->faa_args.busy = BFA_TRUE;
  810. memset(&faa_attr_req, 0, sizeof(struct bfi_faa_query_s));
  811. bfi_h2i_set(faa_attr_req.mh, BFI_MC_IOCFC,
  812. BFI_IOCFC_H2I_FAA_QUERY_REQ, bfa_fn_lpu(bfa));
  813. bfa_ioc_mbox_send(&bfa->ioc, &faa_attr_req,
  814. sizeof(struct bfi_faa_query_s));
  815. return BFA_STATUS_OK;
  816. }
  817. /*
  818. * FAA enable response
  819. */
  820. static void
  821. bfa_faa_enable_reply(struct bfa_iocfc_s *iocfc,
  822. struct bfi_faa_en_dis_rsp_s *rsp)
  823. {
  824. void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
  825. bfa_status_t status = rsp->status;
  826. WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
  827. iocfc->faa_args.faa_cb.faa_cbfn(cbarg, status);
  828. iocfc->faa_args.busy = BFA_FALSE;
  829. }
  830. /*
  831. * FAA disable response
  832. */
  833. static void
  834. bfa_faa_disable_reply(struct bfa_iocfc_s *iocfc,
  835. struct bfi_faa_en_dis_rsp_s *rsp)
  836. {
  837. void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
  838. bfa_status_t status = rsp->status;
  839. WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
  840. iocfc->faa_args.faa_cb.faa_cbfn(cbarg, status);
  841. iocfc->faa_args.busy = BFA_FALSE;
  842. }
  843. /*
  844. * FAA query response
  845. */
  846. static void
  847. bfa_faa_query_reply(struct bfa_iocfc_s *iocfc,
  848. bfi_faa_query_rsp_t *rsp)
  849. {
  850. void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
  851. if (iocfc->faa_args.faa_attr) {
  852. iocfc->faa_args.faa_attr->faa = rsp->faa;
  853. iocfc->faa_args.faa_attr->faa_state = rsp->faa_status;
  854. iocfc->faa_args.faa_attr->pwwn_source = rsp->addr_source;
  855. }
  856. WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
  857. iocfc->faa_args.faa_cb.faa_cbfn(cbarg, BFA_STATUS_OK);
  858. iocfc->faa_args.busy = BFA_FALSE;
  859. }
  860. /*
  861. * IOC enable request is complete
  862. */
  863. static void
  864. bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
  865. {
  866. struct bfa_s *bfa = bfa_arg;
  867. if (status == BFA_STATUS_FAA_ACQ_ADDR) {
  868. bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
  869. bfa_iocfc_init_cb, bfa);
  870. return;
  871. }
  872. if (status != BFA_STATUS_OK) {
  873. bfa_isr_disable(bfa);
  874. if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
  875. bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
  876. bfa_iocfc_init_cb, bfa);
  877. else if (bfa->iocfc.action == BFA_IOCFC_ACT_ENABLE)
  878. bfa_cb_queue(bfa, &bfa->iocfc.en_hcb_qe,
  879. bfa_iocfc_enable_cb, bfa);
  880. return;
  881. }
  882. bfa_iocfc_send_cfg(bfa);
  883. bfa_dconf_modinit(bfa);
  884. }
  885. /*
  886. * IOC disable request is complete
  887. */
  888. static void
  889. bfa_iocfc_disable_cbfn(void *bfa_arg)
  890. {
  891. struct bfa_s *bfa = bfa_arg;
  892. bfa_isr_disable(bfa);
  893. bfa_iocfc_disable_submod(bfa);
  894. if (bfa->iocfc.action == BFA_IOCFC_ACT_STOP)
  895. bfa_cb_queue(bfa, &bfa->iocfc.stop_hcb_qe, bfa_iocfc_stop_cb,
  896. bfa);
  897. else {
  898. WARN_ON(bfa->iocfc.action != BFA_IOCFC_ACT_DISABLE);
  899. bfa_cb_queue(bfa, &bfa->iocfc.dis_hcb_qe, bfa_iocfc_disable_cb,
  900. bfa);
  901. }
  902. }
  903. /*
  904. * Notify sub-modules of hardware failure.
  905. */
  906. static void
  907. bfa_iocfc_hbfail_cbfn(void *bfa_arg)
  908. {
  909. struct bfa_s *bfa = bfa_arg;
  910. bfa->queue_process = BFA_FALSE;
  911. bfa_isr_disable(bfa);
  912. bfa_iocfc_disable_submod(bfa);
  913. if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
  914. bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe, bfa_iocfc_init_cb,
  915. bfa);
  916. }
  917. /*
  918. * Actions on chip-reset completion.
  919. */
  920. static void
  921. bfa_iocfc_reset_cbfn(void *bfa_arg)
  922. {
  923. struct bfa_s *bfa = bfa_arg;
  924. bfa_iocfc_reset_queues(bfa);
  925. bfa_isr_enable(bfa);
  926. }
  927. /*
  928. * Query IOC memory requirement information.
  929. */
  930. void
  931. bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
  932. struct bfa_s *bfa)
  933. {
  934. int q, per_reqq_sz, per_rspq_sz;
  935. struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
  936. struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
  937. struct bfa_mem_kva_s *iocfc_kva = BFA_MEM_IOCFC_KVA(bfa);
  938. u32 dm_len = 0;
  939. /* dma memory setup for IOC */
  940. bfa_mem_dma_setup(meminfo, ioc_dma,
  941. BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ));
  942. /* dma memory setup for REQ/RSP queues */
  943. per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
  944. BFA_DMA_ALIGN_SZ);
  945. per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
  946. BFA_DMA_ALIGN_SZ);
  947. for (q = 0; q < cfg->fwcfg.num_cqs; q++) {
  948. bfa_mem_dma_setup(meminfo, BFA_MEM_REQQ_DMA(bfa, q),
  949. per_reqq_sz);
  950. bfa_mem_dma_setup(meminfo, BFA_MEM_RSPQ_DMA(bfa, q),
  951. per_rspq_sz);
  952. }
  953. /* IOCFC dma memory - calculate Shadow CI/PI size */
  954. for (q = 0; q < cfg->fwcfg.num_cqs; q++)
  955. dm_len += (2 * BFA_CACHELINE_SZ);
  956. /* IOCFC dma memory - calculate config info / rsp size */
  957. dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
  958. dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
  959. BFA_CACHELINE_SZ);
  960. /* dma memory setup for IOCFC */
  961. bfa_mem_dma_setup(meminfo, iocfc_dma, dm_len);
  962. /* kva memory setup for IOCFC */
  963. bfa_mem_kva_setup(meminfo, iocfc_kva,
  964. ((bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0));
  965. }
  966. /*
  967. * Query IOC memory requirement information.
  968. */
  969. void
  970. bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  971. struct bfa_pcidev_s *pcidev)
  972. {
  973. int i;
  974. struct bfa_ioc_s *ioc = &bfa->ioc;
  975. bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
  976. bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
  977. bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
  978. bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
  979. ioc->trcmod = bfa->trcmod;
  980. bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
  981. bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_PCIFN_CLASS_FC);
  982. bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
  983. bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
  984. bfa_iocfc_mem_claim(bfa, cfg);
  985. INIT_LIST_HEAD(&bfa->timer_mod.timer_q);
  986. INIT_LIST_HEAD(&bfa->comp_q);
  987. for (i = 0; i < BFI_IOC_MAX_CQS; i++)
  988. INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
  989. }
  990. /*
  991. * Query IOC memory requirement information.
  992. */
  993. void
  994. bfa_iocfc_init(struct bfa_s *bfa)
  995. {
  996. bfa->iocfc.action = BFA_IOCFC_ACT_INIT;
  997. bfa_ioc_enable(&bfa->ioc);
  998. }
  999. /*
  1000. * IOC start called from bfa_start(). Called to start IOC operations
  1001. * at driver instantiation for this instance.
  1002. */
  1003. void
  1004. bfa_iocfc_start(struct bfa_s *bfa)
  1005. {
  1006. if (bfa->iocfc.cfgdone)
  1007. bfa_iocfc_start_submod(bfa);
  1008. }
  1009. /*
  1010. * IOC stop called from bfa_stop(). Called only when driver is unloaded
  1011. * for this instance.
  1012. */
  1013. void
  1014. bfa_iocfc_stop(struct bfa_s *bfa)
  1015. {
  1016. bfa->iocfc.action = BFA_IOCFC_ACT_STOP;
  1017. bfa->queue_process = BFA_FALSE;
  1018. bfa_dconf_modexit(bfa);
  1019. if (BFA_DCONF_MOD(bfa)->flashdone == BFA_TRUE)
  1020. bfa_ioc_disable(&bfa->ioc);
  1021. }
  1022. void
  1023. bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
  1024. {
  1025. struct bfa_s *bfa = bfaarg;
  1026. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1027. union bfi_iocfc_i2h_msg_u *msg;
  1028. msg = (union bfi_iocfc_i2h_msg_u *) m;
  1029. bfa_trc(bfa, msg->mh.msg_id);
  1030. switch (msg->mh.msg_id) {
  1031. case BFI_IOCFC_I2H_CFG_REPLY:
  1032. bfa_iocfc_cfgrsp(bfa);
  1033. break;
  1034. case BFI_IOCFC_I2H_UPDATEQ_RSP:
  1035. iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
  1036. break;
  1037. case BFI_IOCFC_I2H_FAA_ENABLE_RSP:
  1038. bfa_faa_enable_reply(iocfc,
  1039. (struct bfi_faa_en_dis_rsp_s *)msg);
  1040. break;
  1041. case BFI_IOCFC_I2H_FAA_DISABLE_RSP:
  1042. bfa_faa_disable_reply(iocfc,
  1043. (struct bfi_faa_en_dis_rsp_s *)msg);
  1044. break;
  1045. case BFI_IOCFC_I2H_FAA_QUERY_RSP:
  1046. bfa_faa_query_reply(iocfc, (bfi_faa_query_rsp_t *)msg);
  1047. break;
  1048. default:
  1049. WARN_ON(1);
  1050. }
  1051. }
  1052. void
  1053. bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
  1054. {
  1055. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1056. attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
  1057. attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
  1058. be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
  1059. be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
  1060. attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
  1061. be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
  1062. be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
  1063. attr->config = iocfc->cfg;
  1064. }
  1065. bfa_status_t
  1066. bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
  1067. {
  1068. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1069. struct bfi_iocfc_set_intr_req_s *m;
  1070. iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
  1071. iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
  1072. iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
  1073. if (!bfa_iocfc_is_operational(bfa))
  1074. return BFA_STATUS_OK;
  1075. m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
  1076. if (!m)
  1077. return BFA_STATUS_DEVBUSY;
  1078. bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
  1079. bfa_fn_lpu(bfa));
  1080. m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
  1081. m->delay = iocfc->cfginfo->intr_attr.delay;
  1082. m->latency = iocfc->cfginfo->intr_attr.latency;
  1083. bfa_trc(bfa, attr->delay);
  1084. bfa_trc(bfa, attr->latency);
  1085. bfa_reqq_produce(bfa, BFA_REQQ_IOC, m->mh);
  1086. return BFA_STATUS_OK;
  1087. }
  1088. void
  1089. bfa_iocfc_set_snsbase(struct bfa_s *bfa, int seg_no, u64 snsbase_pa)
  1090. {
  1091. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1092. iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
  1093. bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase[seg_no], snsbase_pa);
  1094. }
  1095. /*
  1096. * Enable IOC after it is disabled.
  1097. */
  1098. void
  1099. bfa_iocfc_enable(struct bfa_s *bfa)
  1100. {
  1101. bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
  1102. "IOC Enable");
  1103. bfa->iocfc.action = BFA_IOCFC_ACT_ENABLE;
  1104. bfa_ioc_enable(&bfa->ioc);
  1105. }
  1106. void
  1107. bfa_iocfc_disable(struct bfa_s *bfa)
  1108. {
  1109. bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
  1110. "IOC Disable");
  1111. bfa->iocfc.action = BFA_IOCFC_ACT_DISABLE;
  1112. bfa->queue_process = BFA_FALSE;
  1113. bfa_ioc_disable(&bfa->ioc);
  1114. }
  1115. bfa_boolean_t
  1116. bfa_iocfc_is_operational(struct bfa_s *bfa)
  1117. {
  1118. return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
  1119. }
  1120. /*
  1121. * Return boot target port wwns -- read from boot information in flash.
  1122. */
  1123. void
  1124. bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
  1125. {
  1126. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1127. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  1128. int i;
  1129. if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
  1130. bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
  1131. *nwwns = cfgrsp->pbc_cfg.nbluns;
  1132. for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
  1133. wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
  1134. return;
  1135. }
  1136. *nwwns = cfgrsp->bootwwns.nwwns;
  1137. memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
  1138. }
  1139. int
  1140. bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
  1141. {
  1142. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1143. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  1144. memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
  1145. return cfgrsp->pbc_cfg.nvports;
  1146. }
  1147. /*
  1148. * Use this function query the memory requirement of the BFA library.
  1149. * This function needs to be called before bfa_attach() to get the
  1150. * memory required of the BFA layer for a given driver configuration.
  1151. *
  1152. * This call will fail, if the cap is out of range compared to pre-defined
  1153. * values within the BFA library
  1154. *
  1155. * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
  1156. * its configuration in this structure.
  1157. * The default values for struct bfa_iocfc_cfg_s can be
  1158. * fetched using bfa_cfg_get_default() API.
  1159. *
  1160. * If cap's boundary check fails, the library will use
  1161. * the default bfa_cap_t values (and log a warning msg).
  1162. *
  1163. * @param[out] meminfo - pointer to bfa_meminfo_t. This content
  1164. * indicates the memory type (see bfa_mem_type_t) and
  1165. * amount of memory required.
  1166. *
  1167. * Driver should allocate the memory, populate the
  1168. * starting address for each block and provide the same
  1169. * structure as input parameter to bfa_attach() call.
  1170. *
  1171. * @param[in] bfa - pointer to the bfa structure, used while fetching the
  1172. * dma, kva memory information of the bfa sub-modules.
  1173. *
  1174. * @return void
  1175. *
  1176. * Special Considerations: @note
  1177. */
  1178. void
  1179. bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
  1180. struct bfa_s *bfa)
  1181. {
  1182. int i;
  1183. struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
  1184. struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
  1185. struct bfa_mem_dma_s *cee_dma = BFA_MEM_CEE_DMA(bfa);
  1186. struct bfa_mem_dma_s *sfp_dma = BFA_MEM_SFP_DMA(bfa);
  1187. struct bfa_mem_dma_s *flash_dma = BFA_MEM_FLASH_DMA(bfa);
  1188. struct bfa_mem_dma_s *diag_dma = BFA_MEM_DIAG_DMA(bfa);
  1189. struct bfa_mem_dma_s *phy_dma = BFA_MEM_PHY_DMA(bfa);
  1190. WARN_ON((cfg == NULL) || (meminfo == NULL));
  1191. memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
  1192. /* Initialize the DMA & KVA meminfo queues */
  1193. INIT_LIST_HEAD(&meminfo->dma_info.qe);
  1194. INIT_LIST_HEAD(&meminfo->kva_info.qe);
  1195. bfa_iocfc_meminfo(cfg, meminfo, bfa);
  1196. for (i = 0; hal_mods[i]; i++)
  1197. hal_mods[i]->meminfo(cfg, meminfo, bfa);
  1198. /* dma info setup */
  1199. bfa_mem_dma_setup(meminfo, port_dma, bfa_port_meminfo());
  1200. bfa_mem_dma_setup(meminfo, ablk_dma, bfa_ablk_meminfo());
  1201. bfa_mem_dma_setup(meminfo, cee_dma, bfa_cee_meminfo());
  1202. bfa_mem_dma_setup(meminfo, sfp_dma, bfa_sfp_meminfo());
  1203. bfa_mem_dma_setup(meminfo, flash_dma,
  1204. bfa_flash_meminfo(cfg->drvcfg.min_cfg));
  1205. bfa_mem_dma_setup(meminfo, diag_dma, bfa_diag_meminfo());
  1206. bfa_mem_dma_setup(meminfo, phy_dma,
  1207. bfa_phy_meminfo(cfg->drvcfg.min_cfg));
  1208. }
  1209. /*
  1210. * Use this function to do attach the driver instance with the BFA
  1211. * library. This function will not trigger any HW initialization
  1212. * process (which will be done in bfa_init() call)
  1213. *
  1214. * This call will fail, if the cap is out of range compared to
  1215. * pre-defined values within the BFA library
  1216. *
  1217. * @param[out] bfa Pointer to bfa_t.
  1218. * @param[in] bfad Opaque handle back to the driver's IOC structure
  1219. * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
  1220. * that was used in bfa_cfg_get_meminfo().
  1221. * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
  1222. * use the bfa_cfg_get_meminfo() call to
  1223. * find the memory blocks required, allocate the
  1224. * required memory and provide the starting addresses.
  1225. * @param[in] pcidev pointer to struct bfa_pcidev_s
  1226. *
  1227. * @return
  1228. * void
  1229. *
  1230. * Special Considerations:
  1231. *
  1232. * @note
  1233. *
  1234. */
  1235. void
  1236. bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  1237. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  1238. {
  1239. int i;
  1240. struct bfa_mem_dma_s *dma_info, *dma_elem;
  1241. struct bfa_mem_kva_s *kva_info, *kva_elem;
  1242. struct list_head *dm_qe, *km_qe;
  1243. bfa->fcs = BFA_FALSE;
  1244. WARN_ON((cfg == NULL) || (meminfo == NULL));
  1245. /* Initialize memory pointers for iterative allocation */
  1246. dma_info = &meminfo->dma_info;
  1247. dma_info->kva_curp = dma_info->kva;
  1248. dma_info->dma_curp = dma_info->dma;
  1249. kva_info = &meminfo->kva_info;
  1250. kva_info->kva_curp = kva_info->kva;
  1251. list_for_each(dm_qe, &dma_info->qe) {
  1252. dma_elem = (struct bfa_mem_dma_s *) dm_qe;
  1253. dma_elem->kva_curp = dma_elem->kva;
  1254. dma_elem->dma_curp = dma_elem->dma;
  1255. }
  1256. list_for_each(km_qe, &kva_info->qe) {
  1257. kva_elem = (struct bfa_mem_kva_s *) km_qe;
  1258. kva_elem->kva_curp = kva_elem->kva;
  1259. }
  1260. bfa_iocfc_attach(bfa, bfad, cfg, pcidev);
  1261. for (i = 0; hal_mods[i]; i++)
  1262. hal_mods[i]->attach(bfa, bfad, cfg, pcidev);
  1263. bfa_com_port_attach(bfa);
  1264. bfa_com_ablk_attach(bfa);
  1265. bfa_com_cee_attach(bfa);
  1266. bfa_com_sfp_attach(bfa);
  1267. bfa_com_flash_attach(bfa, cfg->drvcfg.min_cfg);
  1268. bfa_com_diag_attach(bfa);
  1269. bfa_com_phy_attach(bfa, cfg->drvcfg.min_cfg);
  1270. }
  1271. /*
  1272. * Use this function to delete a BFA IOC. IOC should be stopped (by
  1273. * calling bfa_stop()) before this function call.
  1274. *
  1275. * @param[in] bfa - pointer to bfa_t.
  1276. *
  1277. * @return
  1278. * void
  1279. *
  1280. * Special Considerations:
  1281. *
  1282. * @note
  1283. */
  1284. void
  1285. bfa_detach(struct bfa_s *bfa)
  1286. {
  1287. int i;
  1288. for (i = 0; hal_mods[i]; i++)
  1289. hal_mods[i]->detach(bfa);
  1290. bfa_ioc_detach(&bfa->ioc);
  1291. }
  1292. void
  1293. bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
  1294. {
  1295. INIT_LIST_HEAD(comp_q);
  1296. list_splice_tail_init(&bfa->comp_q, comp_q);
  1297. }
  1298. void
  1299. bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
  1300. {
  1301. struct list_head *qe;
  1302. struct list_head *qen;
  1303. struct bfa_cb_qe_s *hcb_qe;
  1304. bfa_cb_cbfn_status_t cbfn;
  1305. list_for_each_safe(qe, qen, comp_q) {
  1306. hcb_qe = (struct bfa_cb_qe_s *) qe;
  1307. if (hcb_qe->pre_rmv) {
  1308. /* qe is invalid after return, dequeue before cbfn() */
  1309. list_del(qe);
  1310. cbfn = (bfa_cb_cbfn_status_t)(hcb_qe->cbfn);
  1311. cbfn(hcb_qe->cbarg, hcb_qe->fw_status);
  1312. } else
  1313. hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
  1314. }
  1315. }
  1316. void
  1317. bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
  1318. {
  1319. struct list_head *qe;
  1320. struct bfa_cb_qe_s *hcb_qe;
  1321. while (!list_empty(comp_q)) {
  1322. bfa_q_deq(comp_q, &qe);
  1323. hcb_qe = (struct bfa_cb_qe_s *) qe;
  1324. WARN_ON(hcb_qe->pre_rmv);
  1325. hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
  1326. }
  1327. }
  1328. void
  1329. bfa_iocfc_cb_dconf_modinit(struct bfa_s *bfa, bfa_status_t status)
  1330. {
  1331. if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT) {
  1332. if (bfa->iocfc.cfgdone == BFA_TRUE)
  1333. bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
  1334. bfa_iocfc_init_cb, bfa);
  1335. }
  1336. }
  1337. /*
  1338. * Return the list of PCI vendor/device id lists supported by this
  1339. * BFA instance.
  1340. */
  1341. void
  1342. bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
  1343. {
  1344. static struct bfa_pciid_s __pciids[] = {
  1345. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
  1346. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
  1347. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
  1348. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
  1349. };
  1350. *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
  1351. *pciids = __pciids;
  1352. }
  1353. /*
  1354. * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
  1355. * into BFA layer). The OS driver can then turn back and overwrite entries that
  1356. * have been configured by the user.
  1357. *
  1358. * @param[in] cfg - pointer to bfa_ioc_cfg_t
  1359. *
  1360. * @return
  1361. * void
  1362. *
  1363. * Special Considerations:
  1364. * note
  1365. */
  1366. void
  1367. bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
  1368. {
  1369. cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
  1370. cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
  1371. cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
  1372. cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
  1373. cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
  1374. cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
  1375. cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
  1376. cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
  1377. cfg->fwcfg.num_fwtio_reqs = 0;
  1378. cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
  1379. cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
  1380. cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
  1381. cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
  1382. cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
  1383. cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
  1384. cfg->drvcfg.ioc_recover = BFA_FALSE;
  1385. cfg->drvcfg.delay_comp = BFA_FALSE;
  1386. }
  1387. void
  1388. bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
  1389. {
  1390. bfa_cfg_get_default(cfg);
  1391. cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
  1392. cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
  1393. cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
  1394. cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
  1395. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  1396. cfg->fwcfg.num_fwtio_reqs = 0;
  1397. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  1398. cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
  1399. cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
  1400. cfg->drvcfg.min_cfg = BFA_TRUE;
  1401. }