bfa_ioc.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. #ifndef __BFA_IOC_H__
  18. #define __BFA_IOC_H__
  19. #include "bfa_os_inc.h"
  20. #include "bfa_cs.h"
  21. #include "bfi.h"
  22. /*
  23. * BFA timer declarations
  24. */
  25. typedef void (*bfa_timer_cbfn_t)(void *);
  26. /*
  27. * BFA timer data structure
  28. */
  29. struct bfa_timer_s {
  30. struct list_head qe;
  31. bfa_timer_cbfn_t timercb;
  32. void *arg;
  33. int timeout; /* in millisecs */
  34. };
  35. /*
  36. * Timer module structure
  37. */
  38. struct bfa_timer_mod_s {
  39. struct list_head timer_q;
  40. };
  41. #define BFA_TIMER_FREQ 200 /* specified in millisecs */
  42. void bfa_timer_beat(struct bfa_timer_mod_s *mod);
  43. void bfa_timer_init(struct bfa_timer_mod_s *mod);
  44. void bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
  45. bfa_timer_cbfn_t timercb, void *arg,
  46. unsigned int timeout);
  47. void bfa_timer_stop(struct bfa_timer_s *timer);
  48. /*
  49. * Generic Scatter Gather Element used by driver
  50. */
  51. struct bfa_sge_s {
  52. u32 sg_len;
  53. void *sg_addr;
  54. };
  55. #define bfa_sge_word_swap(__sge) do { \
  56. ((u32 *)(__sge))[0] = swab32(((u32 *)(__sge))[0]); \
  57. ((u32 *)(__sge))[1] = swab32(((u32 *)(__sge))[1]); \
  58. ((u32 *)(__sge))[2] = swab32(((u32 *)(__sge))[2]); \
  59. } while (0)
  60. #define bfa_swap_words(_x) ( \
  61. ((_x) << 32) | ((_x) >> 32))
  62. #ifdef __BIGENDIAN
  63. #define bfa_sge_to_be(_x)
  64. #define bfa_sge_to_le(_x) bfa_sge_word_swap(_x)
  65. #define bfa_sgaddr_le(_x) bfa_swap_words(_x)
  66. #else
  67. #define bfa_sge_to_be(_x) bfa_sge_word_swap(_x)
  68. #define bfa_sge_to_le(_x)
  69. #define bfa_sgaddr_le(_x) (_x)
  70. #endif
  71. /*
  72. * PCI device information required by IOC
  73. */
  74. struct bfa_pcidev_s {
  75. int pci_slot;
  76. u8 pci_func;
  77. u16 device_id;
  78. void __iomem *pci_bar_kva;
  79. };
  80. /*
  81. * Structure used to remember the DMA-able memory block's KVA and Physical
  82. * Address
  83. */
  84. struct bfa_dma_s {
  85. void *kva; /* ! Kernel virtual address */
  86. u64 pa; /* ! Physical address */
  87. };
  88. #define BFA_DMA_ALIGN_SZ 256
  89. #define BFA_ROUNDUP(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
  90. /*
  91. * smem size for Crossbow and Catapult
  92. */
  93. #define BFI_SMEM_CB_SIZE 0x200000U /* ! 2MB for crossbow */
  94. #define BFI_SMEM_CT_SIZE 0x280000U /* ! 2.5MB for catapult */
  95. #define bfa_dma_addr_set(dma_addr, pa) \
  96. __bfa_dma_addr_set(&dma_addr, (u64)pa)
  97. static inline void
  98. __bfa_dma_addr_set(union bfi_addr_u *dma_addr, u64 pa)
  99. {
  100. dma_addr->a32.addr_lo = (u32) pa;
  101. dma_addr->a32.addr_hi = (u32) (bfa_os_u32(pa));
  102. }
  103. #define bfa_dma_be_addr_set(dma_addr, pa) \
  104. __bfa_dma_be_addr_set(&dma_addr, (u64)pa)
  105. static inline void
  106. __bfa_dma_be_addr_set(union bfi_addr_u *dma_addr, u64 pa)
  107. {
  108. dma_addr->a32.addr_lo = (u32) cpu_to_be32(pa);
  109. dma_addr->a32.addr_hi = (u32) cpu_to_be32(bfa_os_u32(pa));
  110. }
  111. struct bfa_ioc_regs_s {
  112. void __iomem *hfn_mbox_cmd;
  113. void __iomem *hfn_mbox;
  114. void __iomem *lpu_mbox_cmd;
  115. void __iomem *lpu_mbox;
  116. void __iomem *pss_ctl_reg;
  117. void __iomem *pss_err_status_reg;
  118. void __iomem *app_pll_fast_ctl_reg;
  119. void __iomem *app_pll_slow_ctl_reg;
  120. void __iomem *ioc_sem_reg;
  121. void __iomem *ioc_usage_sem_reg;
  122. void __iomem *ioc_init_sem_reg;
  123. void __iomem *ioc_usage_reg;
  124. void __iomem *host_page_num_fn;
  125. void __iomem *heartbeat;
  126. void __iomem *ioc_fwstate;
  127. void __iomem *ll_halt;
  128. void __iomem *err_set;
  129. void __iomem *shirq_isr_next;
  130. void __iomem *shirq_msk_next;
  131. void __iomem *smem_page_start;
  132. u32 smem_pg0;
  133. };
  134. #define bfa_mem_read(_raddr, _off) swab32(readl(((_raddr) + (_off))))
  135. #define bfa_mem_write(_raddr, _off, _val) \
  136. writel(swab32((_val)), ((_raddr) + (_off)))
  137. /*
  138. * IOC Mailbox structures
  139. */
  140. struct bfa_mbox_cmd_s {
  141. struct list_head qe;
  142. u32 msg[BFI_IOC_MSGSZ];
  143. };
  144. /*
  145. * IOC mailbox module
  146. */
  147. typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m);
  148. struct bfa_ioc_mbox_mod_s {
  149. struct list_head cmd_q; /* pending mbox queue */
  150. int nmclass; /* number of handlers */
  151. struct {
  152. bfa_ioc_mbox_mcfunc_t cbfn; /* message handlers */
  153. void *cbarg;
  154. } mbhdlr[BFI_MC_MAX];
  155. };
  156. /*
  157. * IOC callback function interfaces
  158. */
  159. typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
  160. typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa);
  161. typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa);
  162. typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa);
  163. struct bfa_ioc_cbfn_s {
  164. bfa_ioc_enable_cbfn_t enable_cbfn;
  165. bfa_ioc_disable_cbfn_t disable_cbfn;
  166. bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
  167. bfa_ioc_reset_cbfn_t reset_cbfn;
  168. };
  169. /*
  170. * Heartbeat failure notification queue element.
  171. */
  172. struct bfa_ioc_hbfail_notify_s {
  173. struct list_head qe;
  174. bfa_ioc_hbfail_cbfn_t cbfn;
  175. void *cbarg;
  176. };
  177. /*
  178. * Initialize a heartbeat failure notification structure
  179. */
  180. #define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \
  181. (__notify)->cbfn = (__cbfn); \
  182. (__notify)->cbarg = (__cbarg); \
  183. } while (0)
  184. struct bfa_iocpf_s {
  185. bfa_fsm_t fsm;
  186. struct bfa_ioc_s *ioc;
  187. u32 retry_count;
  188. bfa_boolean_t auto_recover;
  189. };
  190. struct bfa_ioc_s {
  191. bfa_fsm_t fsm;
  192. struct bfa_s *bfa;
  193. struct bfa_pcidev_s pcidev;
  194. struct bfa_timer_mod_s *timer_mod;
  195. struct bfa_timer_s ioc_timer;
  196. struct bfa_timer_s sem_timer;
  197. struct bfa_timer_s hb_timer;
  198. u32 hb_count;
  199. struct list_head hb_notify_q;
  200. void *dbg_fwsave;
  201. int dbg_fwsave_len;
  202. bfa_boolean_t dbg_fwsave_once;
  203. enum bfi_mclass ioc_mc;
  204. struct bfa_ioc_regs_s ioc_regs;
  205. struct bfa_trc_mod_s *trcmod;
  206. struct bfa_ioc_drv_stats_s stats;
  207. bfa_boolean_t fcmode;
  208. bfa_boolean_t ctdev;
  209. bfa_boolean_t cna;
  210. bfa_boolean_t pllinit;
  211. bfa_boolean_t stats_busy; /* outstanding stats */
  212. u8 port_id;
  213. struct bfa_dma_s attr_dma;
  214. struct bfi_ioc_attr_s *attr;
  215. struct bfa_ioc_cbfn_s *cbfn;
  216. struct bfa_ioc_mbox_mod_s mbox_mod;
  217. struct bfa_ioc_hwif_s *ioc_hwif;
  218. struct bfa_iocpf_s iocpf;
  219. };
  220. struct bfa_ioc_hwif_s {
  221. bfa_status_t (*ioc_pll_init) (void __iomem *rb, bfa_boolean_t fcmode);
  222. bfa_boolean_t (*ioc_firmware_lock) (struct bfa_ioc_s *ioc);
  223. void (*ioc_firmware_unlock) (struct bfa_ioc_s *ioc);
  224. void (*ioc_reg_init) (struct bfa_ioc_s *ioc);
  225. void (*ioc_map_port) (struct bfa_ioc_s *ioc);
  226. void (*ioc_isr_mode_set) (struct bfa_ioc_s *ioc,
  227. bfa_boolean_t msix);
  228. void (*ioc_notify_hbfail) (struct bfa_ioc_s *ioc);
  229. void (*ioc_ownership_reset) (struct bfa_ioc_s *ioc);
  230. };
  231. #define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func)
  232. #define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id)
  233. #define bfa_ioc_bar0(__ioc) ((__ioc)->pcidev.pci_bar_kva)
  234. #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
  235. #define bfa_ioc_fetch_stats(__ioc, __stats) \
  236. (((__stats)->drv_stats) = (__ioc)->stats)
  237. #define bfa_ioc_clr_stats(__ioc) \
  238. memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats))
  239. #define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize)
  240. #define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit)
  241. #define bfa_ioc_speed_sup(__ioc) \
  242. BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop)
  243. #define bfa_ioc_get_nports(__ioc) \
  244. BFI_ADAPTER_GETP(NPORTS, (__ioc)->attr->adapter_prop)
  245. #define bfa_ioc_stats(_ioc, _stats) ((_ioc)->stats._stats++)
  246. #define BFA_IOC_FWIMG_MINSZ (16 * 1024)
  247. #define BFA_IOC_FWIMG_TYPE(__ioc) \
  248. (((__ioc)->ctdev) ? \
  249. (((__ioc)->fcmode) ? BFI_IMAGE_CT_FC : BFI_IMAGE_CT_CNA) : \
  250. BFI_IMAGE_CB_FC)
  251. #define BFA_IOC_FW_SMEM_SIZE(__ioc) \
  252. (((__ioc)->ctdev) ? BFI_SMEM_CT_SIZE : BFI_SMEM_CB_SIZE)
  253. #define BFA_IOC_FLASH_CHUNK_NO(off) (off / BFI_FLASH_CHUNK_SZ_WORDS)
  254. #define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS)
  255. #define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS)
  256. /*
  257. * IOC mailbox interface
  258. */
  259. void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd);
  260. void bfa_ioc_mbox_register(struct bfa_ioc_s *ioc,
  261. bfa_ioc_mbox_mcfunc_t *mcfuncs);
  262. void bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc);
  263. void bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len);
  264. void bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg);
  265. void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  266. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
  267. /*
  268. * IOC interfaces
  269. */
  270. #define bfa_ioc_pll_init_asic(__ioc) \
  271. ((__ioc)->ioc_hwif->ioc_pll_init((__ioc)->pcidev.pci_bar_kva, \
  272. (__ioc)->fcmode))
  273. bfa_status_t bfa_ioc_pll_init(struct bfa_ioc_s *ioc);
  274. bfa_status_t bfa_ioc_cb_pll_init(void __iomem *rb, bfa_boolean_t fcmode);
  275. bfa_boolean_t bfa_ioc_ct_pll_init_complete(void __iomem *rb);
  276. bfa_status_t bfa_ioc_ct_pll_init(void __iomem *rb, bfa_boolean_t fcmode);
  277. #define bfa_ioc_isr_mode_set(__ioc, __msix) \
  278. ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix))
  279. #define bfa_ioc_ownership_reset(__ioc) \
  280. ((__ioc)->ioc_hwif->ioc_ownership_reset(__ioc))
  281. void bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc);
  282. void bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc);
  283. void bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa,
  284. struct bfa_ioc_cbfn_s *cbfn, struct bfa_timer_mod_s *timer_mod);
  285. void bfa_ioc_auto_recover(bfa_boolean_t auto_recover);
  286. void bfa_ioc_detach(struct bfa_ioc_s *ioc);
  287. void bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  288. enum bfi_mclass mc);
  289. u32 bfa_ioc_meminfo(void);
  290. void bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa);
  291. void bfa_ioc_enable(struct bfa_ioc_s *ioc);
  292. void bfa_ioc_disable(struct bfa_ioc_s *ioc);
  293. bfa_boolean_t bfa_ioc_intx_claim(struct bfa_ioc_s *ioc);
  294. void bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type,
  295. u32 boot_param);
  296. void bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *msg);
  297. void bfa_ioc_error_isr(struct bfa_ioc_s *ioc);
  298. bfa_boolean_t bfa_ioc_is_operational(struct bfa_ioc_s *ioc);
  299. bfa_boolean_t bfa_ioc_is_initialized(struct bfa_ioc_s *ioc);
  300. bfa_boolean_t bfa_ioc_is_disabled(struct bfa_ioc_s *ioc);
  301. bfa_boolean_t bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc);
  302. bfa_boolean_t bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc);
  303. enum bfa_ioc_type_e bfa_ioc_get_type(struct bfa_ioc_s *ioc);
  304. void bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num);
  305. void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver);
  306. void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver);
  307. void bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model);
  308. void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc,
  309. char *manufacturer);
  310. void bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev);
  311. enum bfa_ioc_state bfa_ioc_get_state(struct bfa_ioc_s *ioc);
  312. void bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr);
  313. void bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  314. struct bfa_adapter_attr_s *ad_attr);
  315. int bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover);
  316. void bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave);
  317. bfa_status_t bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata,
  318. int *trclen);
  319. void bfa_ioc_debug_fwsave_clear(struct bfa_ioc_s *ioc);
  320. bfa_status_t bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata,
  321. int *trclen);
  322. bfa_status_t bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
  323. u32 *offset, int *buflen);
  324. u32 bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr);
  325. u32 bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr);
  326. void bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc);
  327. bfa_boolean_t bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc);
  328. void bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
  329. struct bfa_ioc_hbfail_notify_s *notify);
  330. bfa_boolean_t bfa_ioc_sem_get(void __iomem *sem_reg);
  331. void bfa_ioc_sem_release(void __iomem *sem_reg);
  332. void bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc);
  333. void bfa_ioc_fwver_get(struct bfa_ioc_s *ioc,
  334. struct bfi_ioc_image_hdr_s *fwhdr);
  335. bfa_boolean_t bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc,
  336. struct bfi_ioc_image_hdr_s *fwhdr);
  337. bfa_status_t bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats);
  338. bfa_status_t bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc);
  339. /*
  340. * bfa mfg wwn API functions
  341. */
  342. wwn_t bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc);
  343. wwn_t bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc);
  344. mac_t bfa_ioc_get_mac(struct bfa_ioc_s *ioc);
  345. wwn_t bfa_ioc_get_mfg_pwwn(struct bfa_ioc_s *ioc);
  346. wwn_t bfa_ioc_get_mfg_nwwn(struct bfa_ioc_s *ioc);
  347. mac_t bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc);
  348. u64 bfa_ioc_get_adid(struct bfa_ioc_s *ioc);
  349. /*
  350. * F/W Image Size & Chunk
  351. */
  352. extern u32 bfi_image_ct_fc_size;
  353. extern u32 bfi_image_ct_cna_size;
  354. extern u32 bfi_image_cb_fc_size;
  355. extern u32 *bfi_image_ct_fc;
  356. extern u32 *bfi_image_ct_cna;
  357. extern u32 *bfi_image_cb_fc;
  358. static inline u32 *
  359. bfi_image_ct_fc_get_chunk(u32 off)
  360. { return (u32 *)(bfi_image_ct_fc + off); }
  361. static inline u32 *
  362. bfi_image_ct_cna_get_chunk(u32 off)
  363. { return (u32 *)(bfi_image_ct_cna + off); }
  364. static inline u32 *
  365. bfi_image_cb_fc_get_chunk(u32 off)
  366. { return (u32 *)(bfi_image_cb_fc + off); }
  367. static inline u32*
  368. bfa_cb_image_get_chunk(int type, u32 off)
  369. {
  370. switch (type) {
  371. case BFI_IMAGE_CT_FC:
  372. return bfi_image_ct_fc_get_chunk(off); break;
  373. case BFI_IMAGE_CT_CNA:
  374. return bfi_image_ct_cna_get_chunk(off); break;
  375. case BFI_IMAGE_CB_FC:
  376. return bfi_image_cb_fc_get_chunk(off); break;
  377. default: return 0;
  378. }
  379. }
  380. static inline u32
  381. bfa_cb_image_get_size(int type)
  382. {
  383. switch (type) {
  384. case BFI_IMAGE_CT_FC:
  385. return bfi_image_ct_fc_size; break;
  386. case BFI_IMAGE_CT_CNA:
  387. return bfi_image_ct_cna_size; break;
  388. case BFI_IMAGE_CB_FC:
  389. return bfi_image_cb_fc_size; break;
  390. default: return 0;
  391. }
  392. }
  393. /*
  394. * CNA TRCMOD declaration
  395. */
  396. /*
  397. * !!! Only append to the enums defined here to avoid any versioning
  398. * !!! needed between trace utility and driver version
  399. */
  400. enum {
  401. BFA_TRC_CNA_PORT = 1,
  402. BFA_TRC_CNA_IOC = 2,
  403. BFA_TRC_CNA_IOC_CB = 3,
  404. BFA_TRC_CNA_IOC_CT = 4,
  405. };
  406. #endif /* __BFA_IOC_H__ */