bfa_core.c 33 KB

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