bfa_core.c 38 KB

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