bfa_core.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. dm_len += bfa_port_meminfo();
  79. meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_len = km_len;
  80. meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_len = dm_len;
  81. }
  82. static void
  83. bfa_com_port_attach(struct bfa_s *bfa, struct bfa_meminfo_s *mi)
  84. {
  85. struct bfa_port_s *port = &bfa->modules.port;
  86. uint32_t dm_len;
  87. uint8_t *dm_kva;
  88. uint64_t dm_pa;
  89. dm_len = bfa_port_meminfo();
  90. dm_kva = bfa_meminfo_dma_virt(mi);
  91. dm_pa = bfa_meminfo_dma_phys(mi);
  92. memset(port, 0, sizeof(struct bfa_port_s));
  93. bfa_port_attach(port, &bfa->ioc, bfa, bfa->trcmod, bfa->logm);
  94. bfa_port_mem_claim(port, dm_kva, dm_pa);
  95. bfa_meminfo_dma_virt(mi) = dm_kva + dm_len;
  96. bfa_meminfo_dma_phys(mi) = dm_pa + dm_len;
  97. }
  98. /**
  99. * Use this function to do attach the driver instance with the BFA
  100. * library. This function will not trigger any HW initialization
  101. * process (which will be done in bfa_init() call)
  102. *
  103. * This call will fail, if the cap is out of range compared to
  104. * pre-defined values within the BFA library
  105. *
  106. * @param[out] bfa Pointer to bfa_t.
  107. * @param[in] bfad Opaque handle back to the driver's IOC structure
  108. * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
  109. * that was used in bfa_cfg_get_meminfo().
  110. * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
  111. * use the bfa_cfg_get_meminfo() call to
  112. * find the memory blocks required, allocate the
  113. * required memory and provide the starting addresses.
  114. * @param[in] pcidev pointer to struct bfa_pcidev_s
  115. *
  116. * @return
  117. * void
  118. *
  119. * Special Considerations:
  120. *
  121. * @note
  122. *
  123. */
  124. void
  125. bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  126. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  127. {
  128. int i;
  129. struct bfa_mem_elem_s *melem;
  130. bfa->fcs = BFA_FALSE;
  131. bfa_assert((cfg != NULL) && (meminfo != NULL));
  132. /**
  133. * initialize all memory pointers for iterative allocation
  134. */
  135. for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
  136. melem = meminfo->meminfo + i;
  137. melem->kva_curp = melem->kva;
  138. melem->dma_curp = melem->dma;
  139. }
  140. bfa_iocfc_attach(bfa, bfad, cfg, meminfo, pcidev);
  141. for (i = 0; hal_mods[i]; i++)
  142. hal_mods[i]->attach(bfa, bfad, cfg, meminfo, pcidev);
  143. bfa_com_port_attach(bfa, meminfo);
  144. }
  145. /**
  146. * Use this function to delete a BFA IOC. IOC should be stopped (by
  147. * calling bfa_stop()) before this function call.
  148. *
  149. * @param[in] bfa - pointer to bfa_t.
  150. *
  151. * @return
  152. * void
  153. *
  154. * Special Considerations:
  155. *
  156. * @note
  157. */
  158. void
  159. bfa_detach(struct bfa_s *bfa)
  160. {
  161. int i;
  162. for (i = 0; hal_mods[i]; i++)
  163. hal_mods[i]->detach(bfa);
  164. bfa_iocfc_detach(bfa);
  165. }
  166. void
  167. bfa_init_trc(struct bfa_s *bfa, struct bfa_trc_mod_s *trcmod)
  168. {
  169. bfa->trcmod = trcmod;
  170. }
  171. void
  172. bfa_init_log(struct bfa_s *bfa, struct bfa_log_mod_s *logmod)
  173. {
  174. bfa->logm = logmod;
  175. }
  176. void
  177. bfa_init_aen(struct bfa_s *bfa, struct bfa_aen_s *aen)
  178. {
  179. bfa->aen = aen;
  180. }
  181. void
  182. bfa_init_plog(struct bfa_s *bfa, struct bfa_plog_s *plog)
  183. {
  184. bfa->plog = plog;
  185. }
  186. /**
  187. * Initialize IOC.
  188. *
  189. * This function will return immediately, when the IOC initialization is
  190. * completed, the bfa_cb_init() will be called.
  191. *
  192. * @param[in] bfa instance
  193. *
  194. * @return void
  195. *
  196. * Special Considerations:
  197. *
  198. * @note
  199. * When this function returns, the driver should register the interrupt service
  200. * routine(s) and enable the device interrupts. If this is not done,
  201. * bfa_cb_init() will never get called
  202. */
  203. void
  204. bfa_init(struct bfa_s *bfa)
  205. {
  206. bfa_iocfc_init(bfa);
  207. }
  208. /**
  209. * Use this function initiate the IOC configuration setup. This function
  210. * will return immediately.
  211. *
  212. * @param[in] bfa instance
  213. *
  214. * @return None
  215. */
  216. void
  217. bfa_start(struct bfa_s *bfa)
  218. {
  219. bfa_iocfc_start(bfa);
  220. }
  221. /**
  222. * Use this function quiese the IOC. This function will return immediately,
  223. * when the IOC is actually stopped, the bfa_cb_stop() will be called.
  224. *
  225. * @param[in] bfa - pointer to bfa_t.
  226. *
  227. * @return None
  228. *
  229. * Special Considerations:
  230. * bfa_cb_stop() could be called before or after bfa_stop() returns.
  231. *
  232. * @note
  233. * In case of any failure, we could handle it automatically by doing a
  234. * reset and then succeed the bfa_stop() call.
  235. */
  236. void
  237. bfa_stop(struct bfa_s *bfa)
  238. {
  239. bfa_iocfc_stop(bfa);
  240. }
  241. void
  242. bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
  243. {
  244. INIT_LIST_HEAD(comp_q);
  245. list_splice_tail_init(&bfa->comp_q, comp_q);
  246. }
  247. void
  248. bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
  249. {
  250. struct list_head *qe;
  251. struct list_head *qen;
  252. struct bfa_cb_qe_s *hcb_qe;
  253. list_for_each_safe(qe, qen, comp_q) {
  254. hcb_qe = (struct bfa_cb_qe_s *) qe;
  255. hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
  256. }
  257. }
  258. void
  259. bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
  260. {
  261. struct list_head *qe;
  262. struct bfa_cb_qe_s *hcb_qe;
  263. while (!list_empty(comp_q)) {
  264. bfa_q_deq(comp_q, &qe);
  265. hcb_qe = (struct bfa_cb_qe_s *) qe;
  266. hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
  267. }
  268. }
  269. void
  270. bfa_attach_fcs(struct bfa_s *bfa)
  271. {
  272. bfa->fcs = BFA_TRUE;
  273. }
  274. /**
  275. * Periodic timer heart beat from driver
  276. */
  277. void
  278. bfa_timer_tick(struct bfa_s *bfa)
  279. {
  280. bfa_timer_beat(&bfa->timer_mod);
  281. }
  282. #ifndef BFA_BIOS_BUILD
  283. /**
  284. * Return the list of PCI vendor/device id lists supported by this
  285. * BFA instance.
  286. */
  287. void
  288. bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
  289. {
  290. static struct bfa_pciid_s __pciids[] = {
  291. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
  292. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
  293. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
  294. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
  295. };
  296. *npciids = ARRAY_SIZE(__pciids);
  297. *pciids = __pciids;
  298. }
  299. /**
  300. * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
  301. * into BFA layer). The OS driver can then turn back and overwrite entries that
  302. * have been configured by the user.
  303. *
  304. * @param[in] cfg - pointer to bfa_ioc_cfg_t
  305. *
  306. * @return
  307. * void
  308. *
  309. * Special Considerations:
  310. * note
  311. */
  312. void
  313. bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
  314. {
  315. cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
  316. cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
  317. cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
  318. cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
  319. cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
  320. cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
  321. cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
  322. cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
  323. cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
  324. cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
  325. cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
  326. cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
  327. cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
  328. cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
  329. cfg->drvcfg.ioc_recover = BFA_FALSE;
  330. cfg->drvcfg.delay_comp = BFA_FALSE;
  331. }
  332. void
  333. bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
  334. {
  335. bfa_cfg_get_default(cfg);
  336. cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
  337. cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
  338. cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
  339. cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
  340. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  341. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  342. cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
  343. cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
  344. cfg->drvcfg.min_cfg = BFA_TRUE;
  345. }
  346. void
  347. bfa_get_attr(struct bfa_s *bfa, struct bfa_ioc_attr_s *ioc_attr)
  348. {
  349. bfa_ioc_get_attr(&bfa->ioc, ioc_attr);
  350. }
  351. /**
  352. * Retrieve firmware trace information on IOC failure.
  353. */
  354. bfa_status_t
  355. bfa_debug_fwsave(struct bfa_s *bfa, void *trcdata, int *trclen)
  356. {
  357. return bfa_ioc_debug_fwsave(&bfa->ioc, trcdata, trclen);
  358. }
  359. /**
  360. * Clear the saved firmware trace information of an IOC.
  361. */
  362. void
  363. bfa_debug_fwsave_clear(struct bfa_s *bfa)
  364. {
  365. bfa_ioc_debug_fwsave_clear(&bfa->ioc);
  366. }
  367. /**
  368. * Fetch firmware trace data.
  369. *
  370. * @param[in] bfa BFA instance
  371. * @param[out] trcdata Firmware trace buffer
  372. * @param[in,out] trclen Firmware trace buffer len
  373. *
  374. * @retval BFA_STATUS_OK Firmware trace is fetched.
  375. * @retval BFA_STATUS_INPROGRESS Firmware trace fetch is in progress.
  376. */
  377. bfa_status_t
  378. bfa_debug_fwtrc(struct bfa_s *bfa, void *trcdata, int *trclen)
  379. {
  380. return bfa_ioc_debug_fwtrc(&bfa->ioc, trcdata, trclen);
  381. }
  382. /**
  383. * Reset hw semaphore & usage cnt regs and initialize.
  384. */
  385. void
  386. bfa_chip_reset(struct bfa_s *bfa)
  387. {
  388. bfa_ioc_ownership_reset(&bfa->ioc);
  389. bfa_ioc_pll_init(&bfa->ioc);
  390. }
  391. #endif