bfa_core.c 32 KB

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