bfa_ioc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 pss_err_status_reg;
  66. bfa_os_addr_t app_pll_fast_ctl_reg;
  67. bfa_os_addr_t app_pll_slow_ctl_reg;
  68. bfa_os_addr_t ioc_sem_reg;
  69. bfa_os_addr_t ioc_usage_sem_reg;
  70. bfa_os_addr_t ioc_init_sem_reg;
  71. bfa_os_addr_t ioc_usage_reg;
  72. bfa_os_addr_t host_page_num_fn;
  73. bfa_os_addr_t heartbeat;
  74. bfa_os_addr_t ioc_fwstate;
  75. bfa_os_addr_t ll_halt;
  76. bfa_os_addr_t err_set;
  77. bfa_os_addr_t shirq_isr_next;
  78. bfa_os_addr_t shirq_msk_next;
  79. bfa_os_addr_t smem_page_start;
  80. u32 smem_pg0;
  81. };
  82. #define bfa_reg_read(_raddr) bfa_os_reg_read(_raddr)
  83. #define bfa_reg_write(_raddr, _val) bfa_os_reg_write(_raddr, _val)
  84. #define bfa_mem_read(_raddr, _off) bfa_os_mem_read(_raddr, _off)
  85. #define bfa_mem_write(_raddr, _off, _val) \
  86. bfa_os_mem_write(_raddr, _off, _val)
  87. /**
  88. * IOC Mailbox structures
  89. */
  90. struct bfa_mbox_cmd_s {
  91. struct list_head qe;
  92. u32 msg[BFI_IOC_MSGSZ];
  93. };
  94. /**
  95. * IOC mailbox module
  96. */
  97. typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m);
  98. struct bfa_ioc_mbox_mod_s {
  99. struct list_head cmd_q; /* pending mbox queue */
  100. int nmclass; /* number of handlers */
  101. struct {
  102. bfa_ioc_mbox_mcfunc_t cbfn; /* message handlers */
  103. void *cbarg;
  104. } mbhdlr[BFI_MC_MAX];
  105. };
  106. /**
  107. * IOC callback function interfaces
  108. */
  109. typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
  110. typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa);
  111. typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa);
  112. typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa);
  113. struct bfa_ioc_cbfn_s {
  114. bfa_ioc_enable_cbfn_t enable_cbfn;
  115. bfa_ioc_disable_cbfn_t disable_cbfn;
  116. bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
  117. bfa_ioc_reset_cbfn_t reset_cbfn;
  118. };
  119. /**
  120. * Heartbeat failure notification queue element.
  121. */
  122. struct bfa_ioc_hbfail_notify_s {
  123. struct list_head qe;
  124. bfa_ioc_hbfail_cbfn_t cbfn;
  125. void *cbarg;
  126. };
  127. /**
  128. * Initialize a heartbeat failure notification structure
  129. */
  130. #define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \
  131. (__notify)->cbfn = (__cbfn); \
  132. (__notify)->cbarg = (__cbarg); \
  133. } while (0)
  134. struct bfa_ioc_s {
  135. bfa_fsm_t fsm;
  136. struct bfa_s *bfa;
  137. struct bfa_pcidev_s pcidev;
  138. struct bfa_timer_mod_s *timer_mod;
  139. struct bfa_timer_s ioc_timer;
  140. struct bfa_timer_s sem_timer;
  141. u32 hb_count;
  142. u32 retry_count;
  143. struct list_head hb_notify_q;
  144. void *dbg_fwsave;
  145. int dbg_fwsave_len;
  146. bfa_boolean_t dbg_fwsave_once;
  147. enum bfi_mclass ioc_mc;
  148. struct bfa_ioc_regs_s ioc_regs;
  149. struct bfa_trc_mod_s *trcmod;
  150. struct bfa_aen_s *aen;
  151. struct bfa_log_mod_s *logm;
  152. struct bfa_ioc_drv_stats_s stats;
  153. bfa_boolean_t auto_recover;
  154. bfa_boolean_t fcmode;
  155. bfa_boolean_t ctdev;
  156. bfa_boolean_t cna;
  157. bfa_boolean_t pllinit;
  158. u8 port_id;
  159. struct bfa_dma_s attr_dma;
  160. struct bfi_ioc_attr_s *attr;
  161. struct bfa_ioc_cbfn_s *cbfn;
  162. struct bfa_ioc_mbox_mod_s mbox_mod;
  163. struct bfa_ioc_hwif_s *ioc_hwif;
  164. };
  165. struct bfa_ioc_hwif_s {
  166. bfa_status_t (*ioc_pll_init) (struct bfa_ioc_s *ioc);
  167. bfa_boolean_t (*ioc_firmware_lock) (struct bfa_ioc_s *ioc);
  168. void (*ioc_firmware_unlock) (struct bfa_ioc_s *ioc);
  169. void (*ioc_reg_init) (struct bfa_ioc_s *ioc);
  170. void (*ioc_map_port) (struct bfa_ioc_s *ioc);
  171. void (*ioc_isr_mode_set) (struct bfa_ioc_s *ioc,
  172. bfa_boolean_t msix);
  173. void (*ioc_notify_hbfail) (struct bfa_ioc_s *ioc);
  174. void (*ioc_ownership_reset) (struct bfa_ioc_s *ioc);
  175. };
  176. #define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func)
  177. #define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id)
  178. #define bfa_ioc_bar0(__ioc) ((__ioc)->pcidev.pci_bar_kva)
  179. #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
  180. #define bfa_ioc_fetch_stats(__ioc, __stats) \
  181. (((__stats)->drv_stats) = (__ioc)->stats)
  182. #define bfa_ioc_clr_stats(__ioc) \
  183. bfa_os_memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats))
  184. #define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize)
  185. #define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit)
  186. #define bfa_ioc_speed_sup(__ioc) \
  187. BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop)
  188. #define bfa_ioc_get_nports(__ioc) \
  189. BFI_ADAPTER_GETP(NPORTS, (__ioc)->attr->adapter_prop)
  190. #define bfa_ioc_stats(_ioc, _stats) ((_ioc)->stats._stats++)
  191. #define BFA_IOC_FWIMG_MINSZ (16 * 1024)
  192. #define BFA_IOC_FWIMG_TYPE(__ioc) \
  193. (((__ioc)->ctdev) ? \
  194. (((__ioc)->fcmode) ? BFI_IMAGE_CT_FC : BFI_IMAGE_CT_CNA) : \
  195. BFI_IMAGE_CB_FC)
  196. #define BFA_IOC_FLASH_CHUNK_NO(off) (off / BFI_FLASH_CHUNK_SZ_WORDS)
  197. #define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS)
  198. #define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS)
  199. /**
  200. * IOC mailbox interface
  201. */
  202. void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd);
  203. void bfa_ioc_mbox_register(struct bfa_ioc_s *ioc,
  204. bfa_ioc_mbox_mcfunc_t *mcfuncs);
  205. void bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc);
  206. void bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len);
  207. void bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg);
  208. void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  209. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
  210. /**
  211. * IOC interfaces
  212. */
  213. #define bfa_ioc_pll_init(__ioc) ((__ioc)->ioc_hwif->ioc_pll_init(__ioc))
  214. #define bfa_ioc_isr_mode_set(__ioc, __msix) \
  215. ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix))
  216. #define bfa_ioc_ownership_reset(__ioc) \
  217. ((__ioc)->ioc_hwif->ioc_ownership_reset(__ioc))
  218. void bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc);
  219. void bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc);
  220. void bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa,
  221. struct bfa_ioc_cbfn_s *cbfn, struct bfa_timer_mod_s *timer_mod,
  222. struct bfa_trc_mod_s *trcmod,
  223. struct bfa_aen_s *aen, struct bfa_log_mod_s *logm);
  224. void bfa_ioc_detach(struct bfa_ioc_s *ioc);
  225. void bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  226. enum bfi_mclass mc);
  227. u32 bfa_ioc_meminfo(void);
  228. void bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa);
  229. void bfa_ioc_enable(struct bfa_ioc_s *ioc);
  230. void bfa_ioc_disable(struct bfa_ioc_s *ioc);
  231. bfa_boolean_t bfa_ioc_intx_claim(struct bfa_ioc_s *ioc);
  232. void bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_param);
  233. void bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *msg);
  234. void bfa_ioc_error_isr(struct bfa_ioc_s *ioc);
  235. bfa_boolean_t bfa_ioc_is_operational(struct bfa_ioc_s *ioc);
  236. bfa_boolean_t bfa_ioc_is_disabled(struct bfa_ioc_s *ioc);
  237. bfa_boolean_t bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc);
  238. bfa_boolean_t bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc);
  239. void bfa_ioc_cfg_complete(struct bfa_ioc_s *ioc);
  240. enum bfa_ioc_type_e bfa_ioc_get_type(struct bfa_ioc_s *ioc);
  241. void bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num);
  242. void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver);
  243. void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver);
  244. void bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model);
  245. void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc,
  246. char *manufacturer);
  247. void bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev);
  248. enum bfa_ioc_state bfa_ioc_get_state(struct bfa_ioc_s *ioc);
  249. void bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr);
  250. void bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  251. struct bfa_adapter_attr_s *ad_attr);
  252. int bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover);
  253. void bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave);
  254. bfa_status_t bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata,
  255. int *trclen);
  256. void bfa_ioc_debug_fwsave_clear(struct bfa_ioc_s *ioc);
  257. bfa_status_t bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata,
  258. int *trclen);
  259. u32 bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr);
  260. u32 bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr);
  261. void bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc);
  262. bfa_boolean_t bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc);
  263. void bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
  264. struct bfa_ioc_hbfail_notify_s *notify);
  265. bfa_boolean_t bfa_ioc_sem_get(bfa_os_addr_t sem_reg);
  266. void bfa_ioc_sem_release(bfa_os_addr_t sem_reg);
  267. void bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc);
  268. void bfa_ioc_fwver_get(struct bfa_ioc_s *ioc,
  269. struct bfi_ioc_image_hdr_s *fwhdr);
  270. bfa_boolean_t bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc,
  271. struct bfi_ioc_image_hdr_s *fwhdr);
  272. void bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event);
  273. /*
  274. * bfa mfg wwn API functions
  275. */
  276. wwn_t bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc);
  277. wwn_t bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc);
  278. mac_t bfa_ioc_get_mac(struct bfa_ioc_s *ioc);
  279. wwn_t bfa_ioc_get_mfg_pwwn(struct bfa_ioc_s *ioc);
  280. wwn_t bfa_ioc_get_mfg_nwwn(struct bfa_ioc_s *ioc);
  281. mac_t bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc);
  282. u64 bfa_ioc_get_adid(struct bfa_ioc_s *ioc);
  283. #endif /* __BFA_IOC_H__ */