bfa_core.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /*
  2. * Copyright (c) 2005-2009 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.h>
  18. #include <defs/bfa_defs_pci.h>
  19. #include <cs/bfa_debug.h>
  20. #include <bfa_iocfc.h>
  21. #define DEF_CFG_NUM_FABRICS 1
  22. #define DEF_CFG_NUM_LPORTS 256
  23. #define DEF_CFG_NUM_CQS 4
  24. #define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
  25. #define DEF_CFG_NUM_TSKIM_REQS 128
  26. #define DEF_CFG_NUM_FCXP_REQS 64
  27. #define DEF_CFG_NUM_UF_BUFS 64
  28. #define DEF_CFG_NUM_RPORTS 1024
  29. #define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
  30. #define DEF_CFG_NUM_TINS 256
  31. #define DEF_CFG_NUM_SGPGS 2048
  32. #define DEF_CFG_NUM_REQQ_ELEMS 256
  33. #define DEF_CFG_NUM_RSPQ_ELEMS 64
  34. #define DEF_CFG_NUM_SBOOT_TGTS 16
  35. #define DEF_CFG_NUM_SBOOT_LUNS 16
  36. /**
  37. * Use this function query the memory requirement of the BFA library.
  38. * This function needs to be called before bfa_attach() to get the
  39. * memory required of the BFA layer for a given driver configuration.
  40. *
  41. * This call will fail, if the cap is out of range compared to pre-defined
  42. * values within the BFA library
  43. *
  44. * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
  45. * its configuration in this structure.
  46. * The default values for struct bfa_iocfc_cfg_s can be
  47. * fetched using bfa_cfg_get_default() API.
  48. *
  49. * If cap's boundary check fails, the library will use
  50. * the default bfa_cap_t values (and log a warning msg).
  51. *
  52. * @param[out] meminfo - pointer to bfa_meminfo_t. This content
  53. * indicates the memory type (see bfa_mem_type_t) and
  54. * amount of memory required.
  55. *
  56. * Driver should allocate the memory, populate the
  57. * starting address for each block and provide the same
  58. * structure as input parameter to bfa_attach() call.
  59. *
  60. * @return void
  61. *
  62. * Special Considerations: @note
  63. */
  64. void
  65. bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo)
  66. {
  67. int i;
  68. u32 km_len = 0, dm_len = 0;
  69. bfa_assert((cfg != NULL) && (meminfo != NULL));
  70. bfa_os_memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
  71. meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_type =
  72. BFA_MEM_TYPE_KVA;
  73. meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_type =
  74. BFA_MEM_TYPE_DMA;
  75. bfa_iocfc_meminfo(cfg, &km_len, &dm_len);
  76. for (i = 0; hal_mods[i]; i++)
  77. hal_mods[i]->meminfo(cfg, &km_len, &dm_len);
  78. meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_len = km_len;
  79. meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_len = dm_len;
  80. }
  81. /**
  82. * Use this function to do attach the driver instance with the BFA
  83. * library. This function will not trigger any HW initialization
  84. * process (which will be done in bfa_init() call)
  85. *
  86. * This call will fail, if the cap is out of range compared to
  87. * pre-defined values within the BFA library
  88. *
  89. * @param[out] bfa Pointer to bfa_t.
  90. * @param[in] bfad Opaque handle back to the driver's IOC structure
  91. * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
  92. * that was used in bfa_cfg_get_meminfo().
  93. * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
  94. * use the bfa_cfg_get_meminfo() call to
  95. * find the memory blocks required, allocate the
  96. * required memory and provide the starting addresses.
  97. * @param[in] pcidev pointer to struct bfa_pcidev_s
  98. *
  99. * @return
  100. * void
  101. *
  102. * Special Considerations:
  103. *
  104. * @note
  105. *
  106. */
  107. void
  108. bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  109. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  110. {
  111. int i;
  112. struct bfa_mem_elem_s *melem;
  113. bfa->fcs = BFA_FALSE;
  114. bfa_assert((cfg != NULL) && (meminfo != NULL));
  115. /**
  116. * initialize all memory pointers for iterative allocation
  117. */
  118. for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
  119. melem = meminfo->meminfo + i;
  120. melem->kva_curp = melem->kva;
  121. melem->dma_curp = melem->dma;
  122. }
  123. bfa_iocfc_attach(bfa, bfad, cfg, meminfo, pcidev);
  124. for (i = 0; hal_mods[i]; i++)
  125. hal_mods[i]->attach(bfa, bfad, cfg, meminfo, pcidev);
  126. }
  127. /**
  128. * Use this function to delete a BFA IOC. IOC should be stopped (by
  129. * calling bfa_stop()) before this function call.
  130. *
  131. * @param[in] bfa - pointer to bfa_t.
  132. *
  133. * @return
  134. * void
  135. *
  136. * Special Considerations:
  137. *
  138. * @note
  139. */
  140. void
  141. bfa_detach(struct bfa_s *bfa)
  142. {
  143. int i;
  144. for (i = 0; hal_mods[i]; i++)
  145. hal_mods[i]->detach(bfa);
  146. bfa_iocfc_detach(bfa);
  147. }
  148. void
  149. bfa_init_trc(struct bfa_s *bfa, struct bfa_trc_mod_s *trcmod)
  150. {
  151. bfa->trcmod = trcmod;
  152. }
  153. void
  154. bfa_init_log(struct bfa_s *bfa, struct bfa_log_mod_s *logmod)
  155. {
  156. bfa->logm = logmod;
  157. }
  158. void
  159. bfa_init_aen(struct bfa_s *bfa, struct bfa_aen_s *aen)
  160. {
  161. bfa->aen = aen;
  162. }
  163. void
  164. bfa_init_plog(struct bfa_s *bfa, struct bfa_plog_s *plog)
  165. {
  166. bfa->plog = plog;
  167. }
  168. /**
  169. * Initialize IOC.
  170. *
  171. * This function will return immediately, when the IOC initialization is
  172. * completed, the bfa_cb_init() will be called.
  173. *
  174. * @param[in] bfa instance
  175. *
  176. * @return void
  177. *
  178. * Special Considerations:
  179. *
  180. * @note
  181. * When this function returns, the driver should register the interrupt service
  182. * routine(s) and enable the device interrupts. If this is not done,
  183. * bfa_cb_init() will never get called
  184. */
  185. void
  186. bfa_init(struct bfa_s *bfa)
  187. {
  188. bfa_iocfc_init(bfa);
  189. }
  190. /**
  191. * Use this function initiate the IOC configuration setup. This function
  192. * will return immediately.
  193. *
  194. * @param[in] bfa instance
  195. *
  196. * @return None
  197. */
  198. void
  199. bfa_start(struct bfa_s *bfa)
  200. {
  201. bfa_iocfc_start(bfa);
  202. }
  203. /**
  204. * Use this function quiese the IOC. This function will return immediately,
  205. * when the IOC is actually stopped, the bfa_cb_stop() will be called.
  206. *
  207. * @param[in] bfa - pointer to bfa_t.
  208. *
  209. * @return None
  210. *
  211. * Special Considerations:
  212. * bfa_cb_stop() could be called before or after bfa_stop() returns.
  213. *
  214. * @note
  215. * In case of any failure, we could handle it automatically by doing a
  216. * reset and then succeed the bfa_stop() call.
  217. */
  218. void
  219. bfa_stop(struct bfa_s *bfa)
  220. {
  221. bfa_iocfc_stop(bfa);
  222. }
  223. void
  224. bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
  225. {
  226. INIT_LIST_HEAD(comp_q);
  227. list_splice_tail_init(&bfa->comp_q, comp_q);
  228. }
  229. void
  230. bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
  231. {
  232. struct list_head *qe;
  233. struct list_head *qen;
  234. struct bfa_cb_qe_s *hcb_qe;
  235. list_for_each_safe(qe, qen, comp_q) {
  236. hcb_qe = (struct bfa_cb_qe_s *) qe;
  237. hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
  238. }
  239. }
  240. void
  241. bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
  242. {
  243. struct list_head *qe;
  244. struct bfa_cb_qe_s *hcb_qe;
  245. while (!list_empty(comp_q)) {
  246. bfa_q_deq(comp_q, &qe);
  247. hcb_qe = (struct bfa_cb_qe_s *) qe;
  248. hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
  249. }
  250. }
  251. void
  252. bfa_attach_fcs(struct bfa_s *bfa)
  253. {
  254. bfa->fcs = BFA_TRUE;
  255. }
  256. /**
  257. * Periodic timer heart beat from driver
  258. */
  259. void
  260. bfa_timer_tick(struct bfa_s *bfa)
  261. {
  262. bfa_timer_beat(&bfa->timer_mod);
  263. }
  264. #ifndef BFA_BIOS_BUILD
  265. /**
  266. * Return the list of PCI vendor/device id lists supported by this
  267. * BFA instance.
  268. */
  269. void
  270. bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
  271. {
  272. static struct bfa_pciid_s __pciids[] = {
  273. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
  274. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
  275. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
  276. };
  277. *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
  278. *pciids = __pciids;
  279. }
  280. /**
  281. * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
  282. * into BFA layer). The OS driver can then turn back and overwrite entries that
  283. * have been configured by the user.
  284. *
  285. * @param[in] cfg - pointer to bfa_ioc_cfg_t
  286. *
  287. * @return
  288. * void
  289. *
  290. * Special Considerations:
  291. * note
  292. */
  293. void
  294. bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
  295. {
  296. cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
  297. cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
  298. cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
  299. cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
  300. cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
  301. cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
  302. cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
  303. cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
  304. cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
  305. cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
  306. cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
  307. cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
  308. cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
  309. cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
  310. cfg->drvcfg.ioc_recover = BFA_FALSE;
  311. cfg->drvcfg.delay_comp = BFA_FALSE;
  312. }
  313. void
  314. bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
  315. {
  316. bfa_cfg_get_default(cfg);
  317. cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
  318. cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
  319. cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
  320. cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
  321. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  322. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  323. cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
  324. cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
  325. cfg->drvcfg.min_cfg = BFA_TRUE;
  326. }
  327. void
  328. bfa_get_attr(struct bfa_s *bfa, struct bfa_ioc_attr_s *ioc_attr)
  329. {
  330. bfa_ioc_get_attr(&bfa->ioc, ioc_attr);
  331. }
  332. /**
  333. * Retrieve firmware trace information on IOC failure.
  334. */
  335. bfa_status_t
  336. bfa_debug_fwsave(struct bfa_s *bfa, void *trcdata, int *trclen)
  337. {
  338. return bfa_ioc_debug_fwsave(&bfa->ioc, trcdata, trclen);
  339. }
  340. /**
  341. * Fetch firmware trace data.
  342. *
  343. * @param[in] bfa BFA instance
  344. * @param[out] trcdata Firmware trace buffer
  345. * @param[in,out] trclen Firmware trace buffer len
  346. *
  347. * @retval BFA_STATUS_OK Firmware trace is fetched.
  348. * @retval BFA_STATUS_INPROGRESS Firmware trace fetch is in progress.
  349. */
  350. bfa_status_t
  351. bfa_debug_fwtrc(struct bfa_s *bfa, void *trcdata, int *trclen)
  352. {
  353. return bfa_ioc_debug_fwtrc(&bfa->ioc, trcdata, trclen);
  354. }
  355. #endif