bfa_ioc.h 13 KB

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