bfa_ioc.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. #ifndef __BFA_IOC_H__
  18. #define __BFA_IOC_H__
  19. #include <cs/bfa_sm.h>
  20. #include <bfi/bfi.h>
  21. #include <bfi/bfi_ioc.h>
  22. #include <bfi/bfi_boot.h>
  23. #include <bfa_timer.h>
  24. /**
  25. * PCI device information required by IOC
  26. */
  27. struct bfa_pcidev_s {
  28. int pci_slot;
  29. u8 pci_func;
  30. u16 device_id;
  31. bfa_os_addr_t pci_bar_kva;
  32. };
  33. /**
  34. * Structure used to remember the DMA-able memory block's KVA and Physical
  35. * Address
  36. */
  37. struct bfa_dma_s {
  38. void *kva; /*! Kernel virtual address */
  39. u64 pa; /*! Physical address */
  40. };
  41. #define BFA_DMA_ALIGN_SZ 256
  42. #define BFA_ROUNDUP(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
  43. #define bfa_dma_addr_set(dma_addr, pa) \
  44. __bfa_dma_addr_set(&dma_addr, (u64)pa)
  45. static inline void
  46. __bfa_dma_addr_set(union bfi_addr_u *dma_addr, u64 pa)
  47. {
  48. dma_addr->a32.addr_lo = (u32) pa;
  49. dma_addr->a32.addr_hi = (u32) (bfa_os_u32(pa));
  50. }
  51. #define bfa_dma_be_addr_set(dma_addr, pa) \
  52. __bfa_dma_be_addr_set(&dma_addr, (u64)pa)
  53. static inline void
  54. __bfa_dma_be_addr_set(union bfi_addr_u *dma_addr, u64 pa)
  55. {
  56. dma_addr->a32.addr_lo = (u32) bfa_os_htonl(pa);
  57. dma_addr->a32.addr_hi = (u32) bfa_os_htonl(bfa_os_u32(pa));
  58. }
  59. struct bfa_ioc_regs_s {
  60. bfa_os_addr_t hfn_mbox_cmd;
  61. bfa_os_addr_t hfn_mbox;
  62. bfa_os_addr_t lpu_mbox_cmd;
  63. bfa_os_addr_t lpu_mbox;
  64. bfa_os_addr_t pss_ctl_reg;
  65. bfa_os_addr_t app_pll_fast_ctl_reg;
  66. bfa_os_addr_t app_pll_slow_ctl_reg;
  67. bfa_os_addr_t ioc_sem_reg;
  68. bfa_os_addr_t ioc_usage_sem_reg;
  69. bfa_os_addr_t ioc_init_sem_reg;
  70. bfa_os_addr_t ioc_usage_reg;
  71. bfa_os_addr_t host_page_num_fn;
  72. bfa_os_addr_t heartbeat;
  73. bfa_os_addr_t ioc_fwstate;
  74. bfa_os_addr_t ll_halt;
  75. bfa_os_addr_t err_set;
  76. bfa_os_addr_t shirq_isr_next;
  77. bfa_os_addr_t shirq_msk_next;
  78. bfa_os_addr_t smem_page_start;
  79. u32 smem_pg0;
  80. };
  81. #define bfa_reg_read(_raddr) bfa_os_reg_read(_raddr)
  82. #define bfa_reg_write(_raddr, _val) bfa_os_reg_write(_raddr, _val)
  83. #define bfa_mem_read(_raddr, _off) bfa_os_mem_read(_raddr, _off)
  84. #define bfa_mem_write(_raddr, _off, _val) \
  85. bfa_os_mem_write(_raddr, _off, _val)
  86. /**
  87. * IOC Mailbox structures
  88. */
  89. struct bfa_mbox_cmd_s {
  90. struct list_head qe;
  91. u32 msg[BFI_IOC_MSGSZ];
  92. };
  93. /**
  94. * IOC mailbox module
  95. */
  96. typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m);
  97. struct bfa_ioc_mbox_mod_s {
  98. struct list_head cmd_q; /* pending mbox queue */
  99. int nmclass; /* number of handlers */
  100. struct {
  101. bfa_ioc_mbox_mcfunc_t cbfn; /* message handlers */
  102. void *cbarg;
  103. } mbhdlr[BFI_MC_MAX];
  104. };
  105. /**
  106. * IOC callback function interfaces
  107. */
  108. typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
  109. typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa);
  110. typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa);
  111. typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa);
  112. struct bfa_ioc_cbfn_s {
  113. bfa_ioc_enable_cbfn_t enable_cbfn;
  114. bfa_ioc_disable_cbfn_t disable_cbfn;
  115. bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
  116. bfa_ioc_reset_cbfn_t reset_cbfn;
  117. };
  118. /**
  119. * Heartbeat failure notification queue element.
  120. */
  121. struct bfa_ioc_hbfail_notify_s {
  122. struct list_head qe;
  123. bfa_ioc_hbfail_cbfn_t cbfn;
  124. void *cbarg;
  125. };
  126. /**
  127. * Initialize a heartbeat failure notification structure
  128. */
  129. #define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \
  130. (__notify)->cbfn = (__cbfn); \
  131. (__notify)->cbarg = (__cbarg); \
  132. } while (0)
  133. struct bfa_ioc_s {
  134. bfa_fsm_t fsm;
  135. struct bfa_s *bfa;
  136. struct bfa_pcidev_s pcidev;
  137. struct bfa_timer_mod_s *timer_mod;
  138. struct bfa_timer_s ioc_timer;
  139. struct bfa_timer_s sem_timer;
  140. u32 hb_count;
  141. u32 retry_count;
  142. struct list_head hb_notify_q;
  143. void *dbg_fwsave;
  144. int dbg_fwsave_len;
  145. bfa_boolean_t dbg_fwsave_once;
  146. enum bfi_mclass ioc_mc;
  147. struct bfa_ioc_regs_s ioc_regs;
  148. struct bfa_trc_mod_s *trcmod;
  149. struct bfa_aen_s *aen;
  150. struct bfa_log_mod_s *logm;
  151. struct bfa_ioc_drv_stats_s stats;
  152. bfa_boolean_t auto_recover;
  153. bfa_boolean_t fcmode;
  154. bfa_boolean_t ctdev;
  155. bfa_boolean_t cna;
  156. bfa_boolean_t pllinit;
  157. u8 port_id;
  158. struct bfa_dma_s attr_dma;
  159. struct bfi_ioc_attr_s *attr;
  160. struct bfa_ioc_cbfn_s *cbfn;
  161. struct bfa_ioc_mbox_mod_s mbox_mod;
  162. struct bfa_ioc_hwif_s *ioc_hwif;
  163. };
  164. struct bfa_ioc_hwif_s {
  165. bfa_status_t (*ioc_pll_init) (struct bfa_ioc_s *ioc);
  166. bfa_boolean_t (*ioc_firmware_lock) (struct bfa_ioc_s *ioc);
  167. void (*ioc_firmware_unlock) (struct bfa_ioc_s *ioc);
  168. u32 * (*ioc_fwimg_get_chunk) (struct bfa_ioc_s *ioc,
  169. u32 off);
  170. u32 (*ioc_fwimg_get_size) (struct bfa_ioc_s *ioc);
  171. void (*ioc_reg_init) (struct bfa_ioc_s *ioc);
  172. void (*ioc_map_port) (struct bfa_ioc_s *ioc);
  173. void (*ioc_isr_mode_set) (struct bfa_ioc_s *ioc,
  174. bfa_boolean_t msix);
  175. void (*ioc_notify_hbfail) (struct bfa_ioc_s *ioc);
  176. void (*ioc_ownership_reset) (struct bfa_ioc_s *ioc);
  177. };
  178. #define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func)
  179. #define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id)
  180. #define bfa_ioc_bar0(__ioc) ((__ioc)->pcidev.pci_bar_kva)
  181. #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
  182. #define bfa_ioc_fetch_stats(__ioc, __stats) \
  183. (((__stats)->drv_stats) = (__ioc)->stats)
  184. #define bfa_ioc_clr_stats(__ioc) \
  185. bfa_os_memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats))
  186. #define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize)
  187. #define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit)
  188. #define bfa_ioc_speed_sup(__ioc) \
  189. BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop)
  190. #define bfa_ioc_get_nports(__ioc) \
  191. BFI_ADAPTER_GETP(NPORTS, (__ioc)->attr->adapter_prop)
  192. #define bfa_ioc_stats(_ioc, _stats) ((_ioc)->stats._stats++)
  193. #define BFA_IOC_FWIMG_MINSZ (16 * 1024)
  194. #define BFA_IOC_FLASH_CHUNK_NO(off) (off / BFI_FLASH_CHUNK_SZ_WORDS)
  195. #define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS)
  196. #define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS)
  197. /**
  198. * IOC mailbox interface
  199. */
  200. void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd);
  201. void bfa_ioc_mbox_register(struct bfa_ioc_s *ioc,
  202. bfa_ioc_mbox_mcfunc_t *mcfuncs);
  203. void bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc);
  204. void bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len);
  205. void bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg);
  206. void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  207. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
  208. /**
  209. * IOC interfaces
  210. */
  211. #define bfa_ioc_pll_init(__ioc) ((__ioc)->ioc_hwif->ioc_pll_init(__ioc))
  212. #define bfa_ioc_isr_mode_set(__ioc, __msix) \
  213. ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix))
  214. #define bfa_ioc_ownership_reset(__ioc) \
  215. ((__ioc)->ioc_hwif->ioc_ownership_reset(__ioc))
  216. void bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc);
  217. void bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc);
  218. void bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa,
  219. struct bfa_ioc_cbfn_s *cbfn, struct bfa_timer_mod_s *timer_mod,
  220. struct bfa_trc_mod_s *trcmod,
  221. struct bfa_aen_s *aen, struct bfa_log_mod_s *logm);
  222. void bfa_ioc_detach(struct bfa_ioc_s *ioc);
  223. void bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  224. enum bfi_mclass mc);
  225. u32 bfa_ioc_meminfo(void);
  226. void bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa);
  227. void bfa_ioc_enable(struct bfa_ioc_s *ioc);
  228. void bfa_ioc_disable(struct bfa_ioc_s *ioc);
  229. bfa_boolean_t bfa_ioc_intx_claim(struct bfa_ioc_s *ioc);
  230. void bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_param);
  231. void bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *msg);
  232. void bfa_ioc_error_isr(struct bfa_ioc_s *ioc);
  233. bfa_boolean_t bfa_ioc_is_operational(struct bfa_ioc_s *ioc);
  234. bfa_boolean_t bfa_ioc_is_disabled(struct bfa_ioc_s *ioc);
  235. bfa_boolean_t bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc);
  236. bfa_boolean_t bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc);
  237. void bfa_ioc_cfg_complete(struct bfa_ioc_s *ioc);
  238. void bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr);
  239. void bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  240. struct bfa_adapter_attr_s *ad_attr);
  241. int bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover);
  242. void bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave);
  243. bfa_status_t bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata,
  244. int *trclen);
  245. bfa_status_t bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata,
  246. int *trclen);
  247. u32 bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr);
  248. u32 bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr);
  249. void bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc);
  250. bfa_boolean_t bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc);
  251. void bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
  252. struct bfa_ioc_hbfail_notify_s *notify);
  253. bfa_boolean_t bfa_ioc_sem_get(bfa_os_addr_t sem_reg);
  254. void bfa_ioc_sem_release(bfa_os_addr_t sem_reg);
  255. void bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc);
  256. void bfa_ioc_fwver_get(struct bfa_ioc_s *ioc,
  257. struct bfi_ioc_image_hdr_s *fwhdr);
  258. bfa_boolean_t bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc,
  259. struct bfi_ioc_image_hdr_s *fwhdr);
  260. /*
  261. * bfa mfg wwn API functions
  262. */
  263. wwn_t bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc);
  264. wwn_t bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc);
  265. wwn_t bfa_ioc_get_wwn_naa5(struct bfa_ioc_s *ioc, u16 inst);
  266. mac_t bfa_ioc_get_mac(struct bfa_ioc_s *ioc);
  267. u64 bfa_ioc_get_adid(struct bfa_ioc_s *ioc);
  268. #endif /* __BFA_IOC_H__ */