bfa_ioc.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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 "bfad_drv.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 __BIG_ENDIAN
  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) (pa >> 32);
  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(pa >> 32);
  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 *alt_ioc_fwstate;
  132. void __iomem *ll_halt;
  133. void __iomem *alt_ll_halt;
  134. void __iomem *err_set;
  135. void __iomem *ioc_fail_sync;
  136. void __iomem *shirq_isr_next;
  137. void __iomem *shirq_msk_next;
  138. void __iomem *smem_page_start;
  139. u32 smem_pg0;
  140. };
  141. #define bfa_mem_read(_raddr, _off) swab32(readl(((_raddr) + (_off))))
  142. #define bfa_mem_write(_raddr, _off, _val) \
  143. writel(swab32((_val)), ((_raddr) + (_off)))
  144. /*
  145. * IOC Mailbox structures
  146. */
  147. struct bfa_mbox_cmd_s {
  148. struct list_head qe;
  149. u32 msg[BFI_IOC_MSGSZ];
  150. };
  151. /*
  152. * IOC mailbox module
  153. */
  154. typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m);
  155. struct bfa_ioc_mbox_mod_s {
  156. struct list_head cmd_q; /* pending mbox queue */
  157. int nmclass; /* number of handlers */
  158. struct {
  159. bfa_ioc_mbox_mcfunc_t cbfn; /* message handlers */
  160. void *cbarg;
  161. } mbhdlr[BFI_MC_MAX];
  162. };
  163. /*
  164. * IOC callback function interfaces
  165. */
  166. typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
  167. typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa);
  168. typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa);
  169. typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa);
  170. struct bfa_ioc_cbfn_s {
  171. bfa_ioc_enable_cbfn_t enable_cbfn;
  172. bfa_ioc_disable_cbfn_t disable_cbfn;
  173. bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
  174. bfa_ioc_reset_cbfn_t reset_cbfn;
  175. };
  176. /*
  177. * Heartbeat failure notification queue element.
  178. */
  179. struct bfa_ioc_hbfail_notify_s {
  180. struct list_head qe;
  181. bfa_ioc_hbfail_cbfn_t cbfn;
  182. void *cbarg;
  183. };
  184. /*
  185. * Initialize a heartbeat failure notification structure
  186. */
  187. #define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \
  188. (__notify)->cbfn = (__cbfn); \
  189. (__notify)->cbarg = (__cbarg); \
  190. } while (0)
  191. struct bfa_iocpf_s {
  192. bfa_fsm_t fsm;
  193. struct bfa_ioc_s *ioc;
  194. u32 retry_count;
  195. bfa_boolean_t auto_recover;
  196. };
  197. struct bfa_ioc_s {
  198. bfa_fsm_t fsm;
  199. struct bfa_s *bfa;
  200. struct bfa_pcidev_s pcidev;
  201. struct bfa_timer_mod_s *timer_mod;
  202. struct bfa_timer_s ioc_timer;
  203. struct bfa_timer_s sem_timer;
  204. struct bfa_timer_s hb_timer;
  205. u32 hb_count;
  206. struct list_head hb_notify_q;
  207. void *dbg_fwsave;
  208. int dbg_fwsave_len;
  209. bfa_boolean_t dbg_fwsave_once;
  210. enum bfi_mclass ioc_mc;
  211. struct bfa_ioc_regs_s ioc_regs;
  212. struct bfa_trc_mod_s *trcmod;
  213. struct bfa_ioc_drv_stats_s stats;
  214. bfa_boolean_t fcmode;
  215. bfa_boolean_t ctdev;
  216. bfa_boolean_t cna;
  217. bfa_boolean_t pllinit;
  218. bfa_boolean_t stats_busy; /* outstanding stats */
  219. u8 port_id;
  220. struct bfa_dma_s attr_dma;
  221. struct bfi_ioc_attr_s *attr;
  222. struct bfa_ioc_cbfn_s *cbfn;
  223. struct bfa_ioc_mbox_mod_s mbox_mod;
  224. struct bfa_ioc_hwif_s *ioc_hwif;
  225. struct bfa_iocpf_s iocpf;
  226. };
  227. struct bfa_ioc_hwif_s {
  228. bfa_status_t (*ioc_pll_init) (void __iomem *rb, bfa_boolean_t fcmode);
  229. bfa_boolean_t (*ioc_firmware_lock) (struct bfa_ioc_s *ioc);
  230. void (*ioc_firmware_unlock) (struct bfa_ioc_s *ioc);
  231. void (*ioc_reg_init) (struct bfa_ioc_s *ioc);
  232. void (*ioc_map_port) (struct bfa_ioc_s *ioc);
  233. void (*ioc_isr_mode_set) (struct bfa_ioc_s *ioc,
  234. bfa_boolean_t msix);
  235. void (*ioc_notify_fail) (struct bfa_ioc_s *ioc);
  236. void (*ioc_ownership_reset) (struct bfa_ioc_s *ioc);
  237. void (*ioc_sync_join) (struct bfa_ioc_s *ioc);
  238. void (*ioc_sync_leave) (struct bfa_ioc_s *ioc);
  239. void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
  240. bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
  241. };
  242. #define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func)
  243. #define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id)
  244. #define bfa_ioc_bar0(__ioc) ((__ioc)->pcidev.pci_bar_kva)
  245. #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
  246. #define bfa_ioc_fetch_stats(__ioc, __stats) \
  247. (((__stats)->drv_stats) = (__ioc)->stats)
  248. #define bfa_ioc_clr_stats(__ioc) \
  249. memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats))
  250. #define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize)
  251. #define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit)
  252. #define bfa_ioc_speed_sup(__ioc) \
  253. BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop)
  254. #define bfa_ioc_get_nports(__ioc) \
  255. BFI_ADAPTER_GETP(NPORTS, (__ioc)->attr->adapter_prop)
  256. #define bfa_ioc_stats(_ioc, _stats) ((_ioc)->stats._stats++)
  257. #define BFA_IOC_FWIMG_MINSZ (16 * 1024)
  258. #define BFA_IOC_FWIMG_TYPE(__ioc) \
  259. (((__ioc)->ctdev) ? \
  260. (((__ioc)->fcmode) ? BFI_IMAGE_CT_FC : BFI_IMAGE_CT_CNA) : \
  261. BFI_IMAGE_CB_FC)
  262. #define BFA_IOC_FW_SMEM_SIZE(__ioc) \
  263. (((__ioc)->ctdev) ? BFI_SMEM_CT_SIZE : BFI_SMEM_CB_SIZE)
  264. #define BFA_IOC_FLASH_CHUNK_NO(off) (off / BFI_FLASH_CHUNK_SZ_WORDS)
  265. #define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS)
  266. #define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS)
  267. /*
  268. * IOC mailbox interface
  269. */
  270. void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd);
  271. void bfa_ioc_mbox_register(struct bfa_ioc_s *ioc,
  272. bfa_ioc_mbox_mcfunc_t *mcfuncs);
  273. void bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc);
  274. void bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len);
  275. void bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg);
  276. void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  277. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
  278. /*
  279. * IOC interfaces
  280. */
  281. #define bfa_ioc_pll_init_asic(__ioc) \
  282. ((__ioc)->ioc_hwif->ioc_pll_init((__ioc)->pcidev.pci_bar_kva, \
  283. (__ioc)->fcmode))
  284. bfa_status_t bfa_ioc_pll_init(struct bfa_ioc_s *ioc);
  285. bfa_status_t bfa_ioc_cb_pll_init(void __iomem *rb, bfa_boolean_t fcmode);
  286. bfa_boolean_t bfa_ioc_ct_pll_init_complete(void __iomem *rb);
  287. bfa_status_t bfa_ioc_ct_pll_init(void __iomem *rb, bfa_boolean_t fcmode);
  288. #define bfa_ioc_isr_mode_set(__ioc, __msix) \
  289. ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix))
  290. #define bfa_ioc_ownership_reset(__ioc) \
  291. ((__ioc)->ioc_hwif->ioc_ownership_reset(__ioc))
  292. void bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc);
  293. void bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc);
  294. void bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa,
  295. struct bfa_ioc_cbfn_s *cbfn, struct bfa_timer_mod_s *timer_mod);
  296. void bfa_ioc_auto_recover(bfa_boolean_t auto_recover);
  297. void bfa_ioc_detach(struct bfa_ioc_s *ioc);
  298. void bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  299. enum bfi_mclass mc);
  300. void bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa);
  301. void bfa_ioc_enable(struct bfa_ioc_s *ioc);
  302. void bfa_ioc_disable(struct bfa_ioc_s *ioc);
  303. bfa_boolean_t bfa_ioc_intx_claim(struct bfa_ioc_s *ioc);
  304. void bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type,
  305. u32 boot_param);
  306. void bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *msg);
  307. void bfa_ioc_error_isr(struct bfa_ioc_s *ioc);
  308. bfa_boolean_t bfa_ioc_is_operational(struct bfa_ioc_s *ioc);
  309. bfa_boolean_t bfa_ioc_is_initialized(struct bfa_ioc_s *ioc);
  310. bfa_boolean_t bfa_ioc_is_disabled(struct bfa_ioc_s *ioc);
  311. bfa_boolean_t bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc);
  312. bfa_boolean_t bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc);
  313. void bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc);
  314. enum bfa_ioc_type_e bfa_ioc_get_type(struct bfa_ioc_s *ioc);
  315. void bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num);
  316. void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver);
  317. void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver);
  318. void bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model);
  319. void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc,
  320. char *manufacturer);
  321. void bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev);
  322. enum bfa_ioc_state bfa_ioc_get_state(struct bfa_ioc_s *ioc);
  323. void bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr);
  324. void bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  325. struct bfa_adapter_attr_s *ad_attr);
  326. void bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave);
  327. bfa_status_t bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata,
  328. int *trclen);
  329. bfa_status_t bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata,
  330. int *trclen);
  331. bfa_status_t bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
  332. u32 *offset, int *buflen);
  333. void bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc);
  334. bfa_boolean_t bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc);
  335. bfa_boolean_t bfa_ioc_sem_get(void __iomem *sem_reg);
  336. void bfa_ioc_fwver_get(struct bfa_ioc_s *ioc,
  337. struct bfi_ioc_image_hdr_s *fwhdr);
  338. bfa_boolean_t bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc,
  339. struct bfi_ioc_image_hdr_s *fwhdr);
  340. bfa_status_t bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats);
  341. bfa_status_t bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc);
  342. /*
  343. * bfa mfg wwn API functions
  344. */
  345. mac_t bfa_ioc_get_mac(struct bfa_ioc_s *ioc);
  346. mac_t bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc);
  347. /*
  348. * F/W Image Size & Chunk
  349. */
  350. extern u32 bfi_image_ct_fc_size;
  351. extern u32 bfi_image_ct_cna_size;
  352. extern u32 bfi_image_cb_fc_size;
  353. extern u32 *bfi_image_ct_fc;
  354. extern u32 *bfi_image_ct_cna;
  355. extern u32 *bfi_image_cb_fc;
  356. static inline u32 *
  357. bfi_image_ct_fc_get_chunk(u32 off)
  358. { return (u32 *)(bfi_image_ct_fc + off); }
  359. static inline u32 *
  360. bfi_image_ct_cna_get_chunk(u32 off)
  361. { return (u32 *)(bfi_image_ct_cna + off); }
  362. static inline u32 *
  363. bfi_image_cb_fc_get_chunk(u32 off)
  364. { return (u32 *)(bfi_image_cb_fc + off); }
  365. static inline u32*
  366. bfa_cb_image_get_chunk(int type, u32 off)
  367. {
  368. switch (type) {
  369. case BFI_IMAGE_CT_FC:
  370. return bfi_image_ct_fc_get_chunk(off); break;
  371. case BFI_IMAGE_CT_CNA:
  372. return bfi_image_ct_cna_get_chunk(off); break;
  373. case BFI_IMAGE_CB_FC:
  374. return bfi_image_cb_fc_get_chunk(off); break;
  375. default: return NULL;
  376. }
  377. }
  378. static inline u32
  379. bfa_cb_image_get_size(int type)
  380. {
  381. switch (type) {
  382. case BFI_IMAGE_CT_FC:
  383. return bfi_image_ct_fc_size; break;
  384. case BFI_IMAGE_CT_CNA:
  385. return bfi_image_ct_cna_size; break;
  386. case BFI_IMAGE_CB_FC:
  387. return bfi_image_cb_fc_size; break;
  388. default: return 0;
  389. }
  390. }
  391. /*
  392. * CNA TRCMOD declaration
  393. */
  394. /*
  395. * !!! Only append to the enums defined here to avoid any versioning
  396. * !!! needed between trace utility and driver version
  397. */
  398. enum {
  399. BFA_TRC_CNA_PORT = 1,
  400. BFA_TRC_CNA_IOC = 2,
  401. BFA_TRC_CNA_IOC_CB = 3,
  402. BFA_TRC_CNA_IOC_CT = 4,
  403. };
  404. #endif /* __BFA_IOC_H__ */