bfa_core.c 30 KB

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