bfa_ioc.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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_usage_reg;
  70. bfa_os_addr_t host_page_num_fn;
  71. bfa_os_addr_t heartbeat;
  72. bfa_os_addr_t ioc_fwstate;
  73. bfa_os_addr_t ll_halt;
  74. bfa_os_addr_t shirq_isr_next;
  75. bfa_os_addr_t shirq_msk_next;
  76. bfa_os_addr_t smem_page_start;
  77. u32 smem_pg0;
  78. };
  79. #define bfa_reg_read(_raddr) bfa_os_reg_read(_raddr)
  80. #define bfa_reg_write(_raddr, _val) bfa_os_reg_write(_raddr, _val)
  81. #define bfa_mem_read(_raddr, _off) bfa_os_mem_read(_raddr, _off)
  82. #define bfa_mem_write(_raddr, _off, _val) \
  83. bfa_os_mem_write(_raddr, _off, _val)
  84. /**
  85. * IOC Mailbox structures
  86. */
  87. struct bfa_mbox_cmd_s {
  88. struct list_head qe;
  89. u32 msg[BFI_IOC_MSGSZ];
  90. };
  91. /**
  92. * IOC mailbox module
  93. */
  94. typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m);
  95. struct bfa_ioc_mbox_mod_s {
  96. struct list_head cmd_q; /* pending mbox queue */
  97. int nmclass; /* number of handlers */
  98. struct {
  99. bfa_ioc_mbox_mcfunc_t cbfn; /* message handlers */
  100. void *cbarg;
  101. } mbhdlr[BFI_MC_MAX];
  102. };
  103. /**
  104. * IOC callback function interfaces
  105. */
  106. typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
  107. typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa);
  108. typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa);
  109. typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa);
  110. struct bfa_ioc_cbfn_s {
  111. bfa_ioc_enable_cbfn_t enable_cbfn;
  112. bfa_ioc_disable_cbfn_t disable_cbfn;
  113. bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
  114. bfa_ioc_reset_cbfn_t reset_cbfn;
  115. };
  116. /**
  117. * Heartbeat failure notification queue element.
  118. */
  119. struct bfa_ioc_hbfail_notify_s {
  120. struct list_head qe;
  121. bfa_ioc_hbfail_cbfn_t cbfn;
  122. void *cbarg;
  123. };
  124. /**
  125. * Initialize a heartbeat failure notification structure
  126. */
  127. #define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \
  128. (__notify)->cbfn = (__cbfn); \
  129. (__notify)->cbarg = (__cbarg); \
  130. } while (0)
  131. struct bfa_ioc_s {
  132. bfa_fsm_t fsm;
  133. struct bfa_s *bfa;
  134. struct bfa_pcidev_s pcidev;
  135. struct bfa_timer_mod_s *timer_mod;
  136. struct bfa_timer_s ioc_timer;
  137. struct bfa_timer_s sem_timer;
  138. u32 hb_count;
  139. u32 hb_fail;
  140. u32 retry_count;
  141. struct list_head hb_notify_q;
  142. void *dbg_fwsave;
  143. int dbg_fwsave_len;
  144. bfa_boolean_t dbg_fwsave_once;
  145. enum bfi_mclass ioc_mc;
  146. struct bfa_ioc_regs_s ioc_regs;
  147. struct bfa_trc_mod_s *trcmod;
  148. struct bfa_aen_s *aen;
  149. struct bfa_log_mod_s *logm;
  150. struct bfa_ioc_drv_stats_s stats;
  151. bfa_boolean_t auto_recover;
  152. bfa_boolean_t fcmode;
  153. bfa_boolean_t ctdev;
  154. bfa_boolean_t cna;
  155. bfa_boolean_t pllinit;
  156. u8 port_id;
  157. struct bfa_dma_s attr_dma;
  158. struct bfi_ioc_attr_s *attr;
  159. struct bfa_ioc_cbfn_s *cbfn;
  160. struct bfa_ioc_mbox_mod_s mbox_mod;
  161. };
  162. #define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func)
  163. #define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id)
  164. #define bfa_ioc_bar0(__ioc) ((__ioc)->pcidev.pci_bar_kva)
  165. #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
  166. #define bfa_ioc_fetch_stats(__ioc, __stats) \
  167. (((__stats)->drv_stats) = (__ioc)->stats)
  168. #define bfa_ioc_clr_stats(__ioc) \
  169. bfa_os_memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats))
  170. #define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize)
  171. #define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit)
  172. #define bfa_ioc_speed_sup(__ioc) \
  173. BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop)
  174. /**
  175. * IOC mailbox interface
  176. */
  177. void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd);
  178. void bfa_ioc_mbox_register(struct bfa_ioc_s *ioc,
  179. bfa_ioc_mbox_mcfunc_t *mcfuncs);
  180. void bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc);
  181. void bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len);
  182. void bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg);
  183. void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  184. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
  185. /**
  186. * IOC interfaces
  187. */
  188. void bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa,
  189. struct bfa_ioc_cbfn_s *cbfn, struct bfa_timer_mod_s *timer_mod,
  190. struct bfa_trc_mod_s *trcmod,
  191. struct bfa_aen_s *aen, struct bfa_log_mod_s *logm);
  192. void bfa_ioc_detach(struct bfa_ioc_s *ioc);
  193. void bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  194. enum bfi_mclass mc);
  195. u32 bfa_ioc_meminfo(void);
  196. void bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa);
  197. void bfa_ioc_enable(struct bfa_ioc_s *ioc);
  198. void bfa_ioc_disable(struct bfa_ioc_s *ioc);
  199. bfa_boolean_t bfa_ioc_intx_claim(struct bfa_ioc_s *ioc);
  200. void bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_param);
  201. void bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *msg);
  202. void bfa_ioc_error_isr(struct bfa_ioc_s *ioc);
  203. void bfa_ioc_isr_mode_set(struct bfa_ioc_s *ioc, bfa_boolean_t intx);
  204. bfa_status_t bfa_ioc_pll_init(struct bfa_ioc_s *ioc);
  205. bfa_boolean_t bfa_ioc_is_operational(struct bfa_ioc_s *ioc);
  206. bfa_boolean_t bfa_ioc_is_disabled(struct bfa_ioc_s *ioc);
  207. bfa_boolean_t bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc);
  208. bfa_boolean_t bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc);
  209. void bfa_ioc_cfg_complete(struct bfa_ioc_s *ioc);
  210. void bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr);
  211. void bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  212. struct bfa_adapter_attr_s *ad_attr);
  213. int bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover);
  214. void bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave);
  215. bfa_status_t bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata,
  216. int *trclen);
  217. bfa_status_t bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata,
  218. int *trclen);
  219. u32 bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr);
  220. u32 bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr);
  221. void bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc);
  222. bfa_boolean_t bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc);
  223. void bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
  224. struct bfa_ioc_hbfail_notify_s *notify);
  225. /*
  226. * bfa mfg wwn API functions
  227. */
  228. wwn_t bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc);
  229. wwn_t bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc);
  230. wwn_t bfa_ioc_get_wwn_naa5(struct bfa_ioc_s *ioc, u16 inst);
  231. mac_t bfa_ioc_get_mac(struct bfa_ioc_s *ioc);
  232. u64 bfa_ioc_get_adid(struct bfa_ioc_s *ioc);
  233. #endif /* __BFA_IOC_H__ */