bfa_core.c 33 KB

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