bfa_core.c 42 KB

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