bfa_ioc.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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. * BFA memory resources
  77. */
  78. struct bfa_mem_dma_s {
  79. struct list_head qe; /* Queue of DMA elements */
  80. u32 mem_len; /* Total Length in Bytes */
  81. u8 *kva; /* kernel virtual address */
  82. u64 dma; /* dma address if DMA memory */
  83. u8 *kva_curp; /* kva allocation cursor */
  84. u64 dma_curp; /* dma allocation cursor */
  85. };
  86. #define bfa_mem_dma_t struct bfa_mem_dma_s
  87. struct bfa_mem_kva_s {
  88. struct list_head qe; /* Queue of KVA elements */
  89. u32 mem_len; /* Total Length in Bytes */
  90. u8 *kva; /* kernel virtual address */
  91. u8 *kva_curp; /* kva allocation cursor */
  92. };
  93. #define bfa_mem_kva_t struct bfa_mem_kva_s
  94. struct bfa_meminfo_s {
  95. struct bfa_mem_dma_s dma_info;
  96. struct bfa_mem_kva_s kva_info;
  97. };
  98. /* BFA memory segment setup macros */
  99. #define bfa_mem_dma_setup(_meminfo, _dm_ptr, _seg_sz) do { \
  100. ((bfa_mem_dma_t *)(_dm_ptr))->mem_len = (_seg_sz); \
  101. if (_seg_sz) \
  102. list_add_tail(&((bfa_mem_dma_t *)_dm_ptr)->qe, \
  103. &(_meminfo)->dma_info.qe); \
  104. } while (0)
  105. #define bfa_mem_kva_setup(_meminfo, _kva_ptr, _seg_sz) do { \
  106. ((bfa_mem_kva_t *)(_kva_ptr))->mem_len = (_seg_sz); \
  107. if (_seg_sz) \
  108. list_add_tail(&((bfa_mem_kva_t *)_kva_ptr)->qe, \
  109. &(_meminfo)->kva_info.qe); \
  110. } while (0)
  111. /* BFA dma memory segments iterator */
  112. #define bfa_mem_dma_sptr(_mod, _i) (&(_mod)->dma_seg[(_i)])
  113. #define bfa_mem_dma_seg_iter(_mod, _sptr, _nr, _i) \
  114. for (_i = 0, _sptr = bfa_mem_dma_sptr(_mod, _i); _i < (_nr); \
  115. _i++, _sptr = bfa_mem_dma_sptr(_mod, _i))
  116. #define bfa_mem_kva_curp(_mod) ((_mod)->kva_seg.kva_curp)
  117. #define bfa_mem_dma_virt(_sptr) ((_sptr)->kva_curp)
  118. #define bfa_mem_dma_phys(_sptr) ((_sptr)->dma_curp)
  119. #define bfa_mem_dma_len(_sptr) ((_sptr)->mem_len)
  120. /* Get the corresponding dma buf kva for a req - from the tag */
  121. #define bfa_mem_get_dmabuf_kva(_mod, _tag, _rqsz) \
  122. (((u8 *)(_mod)->dma_seg[BFI_MEM_SEG_FROM_TAG(_tag, _rqsz)].kva_curp) +\
  123. BFI_MEM_SEG_REQ_OFFSET(_tag, _rqsz) * (_rqsz))
  124. /* Get the corresponding dma buf pa for a req - from the tag */
  125. #define bfa_mem_get_dmabuf_pa(_mod, _tag, _rqsz) \
  126. ((_mod)->dma_seg[BFI_MEM_SEG_FROM_TAG(_tag, _rqsz)].dma_curp + \
  127. BFI_MEM_SEG_REQ_OFFSET(_tag, _rqsz) * (_rqsz))
  128. /*
  129. * PCI device information required by IOC
  130. */
  131. struct bfa_pcidev_s {
  132. int pci_slot;
  133. u8 pci_func;
  134. u16 device_id;
  135. u16 ssid;
  136. void __iomem *pci_bar_kva;
  137. };
  138. /*
  139. * Structure used to remember the DMA-able memory block's KVA and Physical
  140. * Address
  141. */
  142. struct bfa_dma_s {
  143. void *kva; /* ! Kernel virtual address */
  144. u64 pa; /* ! Physical address */
  145. };
  146. #define BFA_DMA_ALIGN_SZ 256
  147. #define BFA_ROUNDUP(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
  148. /*
  149. * smem size for Crossbow and Catapult
  150. */
  151. #define BFI_SMEM_CB_SIZE 0x200000U /* ! 2MB for crossbow */
  152. #define BFI_SMEM_CT_SIZE 0x280000U /* ! 2.5MB for catapult */
  153. #define bfa_dma_be_addr_set(dma_addr, pa) \
  154. __bfa_dma_be_addr_set(&dma_addr, (u64)pa)
  155. static inline void
  156. __bfa_dma_be_addr_set(union bfi_addr_u *dma_addr, u64 pa)
  157. {
  158. dma_addr->a32.addr_lo = cpu_to_be32(pa);
  159. dma_addr->a32.addr_hi = cpu_to_be32(pa >> 32);
  160. }
  161. #define bfa_alen_set(__alen, __len, __pa) \
  162. __bfa_alen_set(__alen, __len, (u64)__pa)
  163. static inline void
  164. __bfa_alen_set(struct bfi_alen_s *alen, u32 len, u64 pa)
  165. {
  166. alen->al_len = cpu_to_be32(len);
  167. bfa_dma_be_addr_set(alen->al_addr, pa);
  168. }
  169. struct bfa_ioc_regs_s {
  170. void __iomem *hfn_mbox_cmd;
  171. void __iomem *hfn_mbox;
  172. void __iomem *lpu_mbox_cmd;
  173. void __iomem *lpu_mbox;
  174. void __iomem *lpu_read_stat;
  175. void __iomem *pss_ctl_reg;
  176. void __iomem *pss_err_status_reg;
  177. void __iomem *app_pll_fast_ctl_reg;
  178. void __iomem *app_pll_slow_ctl_reg;
  179. void __iomem *ioc_sem_reg;
  180. void __iomem *ioc_usage_sem_reg;
  181. void __iomem *ioc_init_sem_reg;
  182. void __iomem *ioc_usage_reg;
  183. void __iomem *host_page_num_fn;
  184. void __iomem *heartbeat;
  185. void __iomem *ioc_fwstate;
  186. void __iomem *alt_ioc_fwstate;
  187. void __iomem *ll_halt;
  188. void __iomem *alt_ll_halt;
  189. void __iomem *err_set;
  190. void __iomem *ioc_fail_sync;
  191. void __iomem *shirq_isr_next;
  192. void __iomem *shirq_msk_next;
  193. void __iomem *smem_page_start;
  194. u32 smem_pg0;
  195. };
  196. #define bfa_mem_read(_raddr, _off) swab32(readl(((_raddr) + (_off))))
  197. #define bfa_mem_write(_raddr, _off, _val) \
  198. writel(swab32((_val)), ((_raddr) + (_off)))
  199. /*
  200. * IOC Mailbox structures
  201. */
  202. struct bfa_mbox_cmd_s {
  203. struct list_head qe;
  204. u32 msg[BFI_IOC_MSGSZ];
  205. };
  206. /*
  207. * IOC mailbox module
  208. */
  209. typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m);
  210. struct bfa_ioc_mbox_mod_s {
  211. struct list_head cmd_q; /* pending mbox queue */
  212. int nmclass; /* number of handlers */
  213. struct {
  214. bfa_ioc_mbox_mcfunc_t cbfn; /* message handlers */
  215. void *cbarg;
  216. } mbhdlr[BFI_MC_MAX];
  217. };
  218. /*
  219. * IOC callback function interfaces
  220. */
  221. typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
  222. typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa);
  223. typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa);
  224. typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa);
  225. struct bfa_ioc_cbfn_s {
  226. bfa_ioc_enable_cbfn_t enable_cbfn;
  227. bfa_ioc_disable_cbfn_t disable_cbfn;
  228. bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
  229. bfa_ioc_reset_cbfn_t reset_cbfn;
  230. };
  231. /*
  232. * IOC event notification mechanism.
  233. */
  234. enum bfa_ioc_event_e {
  235. BFA_IOC_E_ENABLED = 1,
  236. BFA_IOC_E_DISABLED = 2,
  237. BFA_IOC_E_FAILED = 3,
  238. };
  239. typedef void (*bfa_ioc_notify_cbfn_t)(void *, enum bfa_ioc_event_e);
  240. struct bfa_ioc_notify_s {
  241. struct list_head qe;
  242. bfa_ioc_notify_cbfn_t cbfn;
  243. void *cbarg;
  244. };
  245. /*
  246. * Initialize a IOC event notification structure
  247. */
  248. #define bfa_ioc_notify_init(__notify, __cbfn, __cbarg) do { \
  249. (__notify)->cbfn = (__cbfn); \
  250. (__notify)->cbarg = (__cbarg); \
  251. } while (0)
  252. struct bfa_iocpf_s {
  253. bfa_fsm_t fsm;
  254. struct bfa_ioc_s *ioc;
  255. bfa_boolean_t fw_mismatch_notified;
  256. bfa_boolean_t auto_recover;
  257. u32 poll_time;
  258. };
  259. struct bfa_ioc_s {
  260. bfa_fsm_t fsm;
  261. struct bfa_s *bfa;
  262. struct bfa_pcidev_s pcidev;
  263. struct bfa_timer_mod_s *timer_mod;
  264. struct bfa_timer_s ioc_timer;
  265. struct bfa_timer_s sem_timer;
  266. struct bfa_timer_s hb_timer;
  267. u32 hb_count;
  268. struct list_head notify_q;
  269. void *dbg_fwsave;
  270. int dbg_fwsave_len;
  271. bfa_boolean_t dbg_fwsave_once;
  272. enum bfi_pcifn_class clscode;
  273. struct bfa_ioc_regs_s ioc_regs;
  274. struct bfa_trc_mod_s *trcmod;
  275. struct bfa_ioc_drv_stats_s stats;
  276. bfa_boolean_t fcmode;
  277. bfa_boolean_t pllinit;
  278. bfa_boolean_t stats_busy; /* outstanding stats */
  279. u8 port_id;
  280. struct bfa_dma_s attr_dma;
  281. struct bfi_ioc_attr_s *attr;
  282. struct bfa_ioc_cbfn_s *cbfn;
  283. struct bfa_ioc_mbox_mod_s mbox_mod;
  284. struct bfa_ioc_hwif_s *ioc_hwif;
  285. struct bfa_iocpf_s iocpf;
  286. enum bfi_asic_gen asic_gen;
  287. enum bfi_asic_mode asic_mode;
  288. enum bfi_port_mode port0_mode;
  289. enum bfi_port_mode port1_mode;
  290. enum bfa_mode_s port_mode;
  291. u8 ad_cap_bm; /* adapter cap bit mask */
  292. u8 port_mode_cfg; /* config port mode */
  293. };
  294. struct bfa_ioc_hwif_s {
  295. bfa_status_t (*ioc_pll_init) (void __iomem *rb, enum bfi_asic_mode m);
  296. bfa_boolean_t (*ioc_firmware_lock) (struct bfa_ioc_s *ioc);
  297. void (*ioc_firmware_unlock) (struct bfa_ioc_s *ioc);
  298. void (*ioc_reg_init) (struct bfa_ioc_s *ioc);
  299. void (*ioc_map_port) (struct bfa_ioc_s *ioc);
  300. void (*ioc_isr_mode_set) (struct bfa_ioc_s *ioc,
  301. bfa_boolean_t msix);
  302. void (*ioc_notify_fail) (struct bfa_ioc_s *ioc);
  303. void (*ioc_ownership_reset) (struct bfa_ioc_s *ioc);
  304. bfa_boolean_t (*ioc_sync_start) (struct bfa_ioc_s *ioc);
  305. void (*ioc_sync_join) (struct bfa_ioc_s *ioc);
  306. void (*ioc_sync_leave) (struct bfa_ioc_s *ioc);
  307. void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
  308. bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
  309. bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
  310. };
  311. /*
  312. * Queue element to wait for room in request queue. FIFO order is
  313. * maintained when fullfilling requests.
  314. */
  315. struct bfa_reqq_wait_s {
  316. struct list_head qe;
  317. void (*qresume) (void *cbarg);
  318. void *cbarg;
  319. };
  320. typedef void (*bfa_cb_cbfn_t) (void *cbarg, bfa_boolean_t complete);
  321. /*
  322. * Generic BFA callback element.
  323. */
  324. struct bfa_cb_qe_s {
  325. struct list_head qe;
  326. bfa_cb_cbfn_t cbfn;
  327. bfa_boolean_t once;
  328. void *cbarg;
  329. };
  330. /*
  331. * ASIC block configurtion related
  332. */
  333. typedef void (*bfa_ablk_cbfn_t)(void *, enum bfa_status);
  334. struct bfa_ablk_s {
  335. struct bfa_ioc_s *ioc;
  336. struct bfa_ablk_cfg_s *cfg;
  337. u16 *pcifn;
  338. struct bfa_dma_s dma_addr;
  339. bfa_boolean_t busy;
  340. struct bfa_mbox_cmd_s mb;
  341. bfa_ablk_cbfn_t cbfn;
  342. void *cbarg;
  343. struct bfa_ioc_notify_s ioc_notify;
  344. struct bfa_mem_dma_s ablk_dma;
  345. };
  346. #define BFA_MEM_ABLK_DMA(__bfa) (&((__bfa)->modules.ablk.ablk_dma))
  347. /*
  348. * SFP module specific
  349. */
  350. typedef void (*bfa_cb_sfp_t) (void *cbarg, bfa_status_t status);
  351. struct bfa_sfp_s {
  352. void *dev;
  353. struct bfa_ioc_s *ioc;
  354. struct bfa_trc_mod_s *trcmod;
  355. struct sfp_mem_s *sfpmem;
  356. bfa_cb_sfp_t cbfn;
  357. void *cbarg;
  358. enum bfi_sfp_mem_e memtype; /* mem access type */
  359. u32 status;
  360. struct bfa_mbox_cmd_s mbcmd;
  361. u8 *dbuf_kva; /* dma buf virtual address */
  362. u64 dbuf_pa; /* dma buf physical address */
  363. struct bfa_ioc_notify_s ioc_notify;
  364. enum bfa_defs_sfp_media_e *media;
  365. enum bfa_port_speed portspeed;
  366. bfa_cb_sfp_t state_query_cbfn;
  367. void *state_query_cbarg;
  368. u8 lock;
  369. u8 data_valid; /* data in dbuf is valid */
  370. u8 state; /* sfp state */
  371. u8 state_query_lock;
  372. struct bfa_mem_dma_s sfp_dma;
  373. u8 is_elb; /* eloopback */
  374. };
  375. #define BFA_SFP_MOD(__bfa) (&(__bfa)->modules.sfp)
  376. #define BFA_MEM_SFP_DMA(__bfa) (&(BFA_SFP_MOD(__bfa)->sfp_dma))
  377. u32 bfa_sfp_meminfo(void);
  378. void bfa_sfp_attach(struct bfa_sfp_s *sfp, struct bfa_ioc_s *ioc,
  379. void *dev, struct bfa_trc_mod_s *trcmod);
  380. void bfa_sfp_memclaim(struct bfa_sfp_s *diag, u8 *dm_kva, u64 dm_pa);
  381. void bfa_sfp_intr(void *bfaarg, struct bfi_mbmsg_s *msg);
  382. bfa_status_t bfa_sfp_show(struct bfa_sfp_s *sfp, struct sfp_mem_s *sfpmem,
  383. bfa_cb_sfp_t cbfn, void *cbarg);
  384. bfa_status_t bfa_sfp_media(struct bfa_sfp_s *sfp,
  385. enum bfa_defs_sfp_media_e *media,
  386. bfa_cb_sfp_t cbfn, void *cbarg);
  387. bfa_status_t bfa_sfp_speed(struct bfa_sfp_s *sfp,
  388. enum bfa_port_speed portspeed,
  389. bfa_cb_sfp_t cbfn, void *cbarg);
  390. /*
  391. * Flash module specific
  392. */
  393. typedef void (*bfa_cb_flash_t) (void *cbarg, bfa_status_t status);
  394. struct bfa_flash_s {
  395. struct bfa_ioc_s *ioc; /* back pointer to ioc */
  396. struct bfa_trc_mod_s *trcmod;
  397. u32 type; /* partition type */
  398. u8 instance; /* partition instance */
  399. u8 rsv[3];
  400. u32 op_busy; /* operation busy flag */
  401. u32 residue; /* residual length */
  402. u32 offset; /* offset */
  403. bfa_status_t status; /* status */
  404. u8 *dbuf_kva; /* dma buf virtual address */
  405. u64 dbuf_pa; /* dma buf physical address */
  406. struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */
  407. bfa_cb_flash_t cbfn; /* user callback function */
  408. void *cbarg; /* user callback arg */
  409. u8 *ubuf; /* user supplied buffer */
  410. struct bfa_cb_qe_s hcb_qe; /* comp: BFA callback qelem */
  411. u32 addr_off; /* partition address offset */
  412. struct bfa_mbox_cmd_s mb; /* mailbox */
  413. struct bfa_ioc_notify_s ioc_notify; /* ioc event notify */
  414. struct bfa_mem_dma_s flash_dma;
  415. };
  416. #define BFA_FLASH(__bfa) (&(__bfa)->modules.flash)
  417. #define BFA_MEM_FLASH_DMA(__bfa) (&(BFA_FLASH(__bfa)->flash_dma))
  418. bfa_status_t bfa_flash_get_attr(struct bfa_flash_s *flash,
  419. struct bfa_flash_attr_s *attr,
  420. bfa_cb_flash_t cbfn, void *cbarg);
  421. bfa_status_t bfa_flash_erase_part(struct bfa_flash_s *flash,
  422. enum bfa_flash_part_type type, u8 instance,
  423. bfa_cb_flash_t cbfn, void *cbarg);
  424. bfa_status_t bfa_flash_update_part(struct bfa_flash_s *flash,
  425. enum bfa_flash_part_type type, u8 instance,
  426. void *buf, u32 len, u32 offset,
  427. bfa_cb_flash_t cbfn, void *cbarg);
  428. bfa_status_t bfa_flash_read_part(struct bfa_flash_s *flash,
  429. enum bfa_flash_part_type type, u8 instance, void *buf,
  430. u32 len, u32 offset, bfa_cb_flash_t cbfn, void *cbarg);
  431. u32 bfa_flash_meminfo(bfa_boolean_t mincfg);
  432. void bfa_flash_attach(struct bfa_flash_s *flash, struct bfa_ioc_s *ioc,
  433. void *dev, struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg);
  434. void bfa_flash_memclaim(struct bfa_flash_s *flash,
  435. u8 *dm_kva, u64 dm_pa, bfa_boolean_t mincfg);
  436. /*
  437. * DIAG module specific
  438. */
  439. typedef void (*bfa_cb_diag_t) (void *cbarg, bfa_status_t status);
  440. typedef void (*bfa_cb_diag_beacon_t) (void *dev, bfa_boolean_t beacon,
  441. bfa_boolean_t link_e2e_beacon);
  442. /*
  443. * Firmware ping test results
  444. */
  445. struct bfa_diag_results_fwping {
  446. u32 data; /* store the corrupted data */
  447. u32 status;
  448. u32 dmastatus;
  449. u8 rsvd[4];
  450. };
  451. struct bfa_diag_qtest_result_s {
  452. u32 status;
  453. u16 count; /* sucessful queue test count */
  454. u8 queue;
  455. u8 rsvd; /* 64-bit align */
  456. };
  457. /*
  458. * Firmware ping test results
  459. */
  460. struct bfa_diag_fwping_s {
  461. struct bfa_diag_results_fwping *result;
  462. bfa_cb_diag_t cbfn;
  463. void *cbarg;
  464. u32 data;
  465. u8 lock;
  466. u8 rsv[3];
  467. u32 status;
  468. u32 count;
  469. struct bfa_mbox_cmd_s mbcmd;
  470. u8 *dbuf_kva; /* dma buf virtual address */
  471. u64 dbuf_pa; /* dma buf physical address */
  472. };
  473. /*
  474. * Temperature sensor query results
  475. */
  476. struct bfa_diag_results_tempsensor_s {
  477. u32 status;
  478. u16 temp; /* 10-bit A/D value */
  479. u16 brd_temp; /* 9-bit board temp */
  480. u8 ts_junc; /* show junction tempsensor */
  481. u8 ts_brd; /* show board tempsensor */
  482. u8 rsvd[6]; /* keep 8 bytes alignment */
  483. };
  484. struct bfa_diag_tsensor_s {
  485. bfa_cb_diag_t cbfn;
  486. void *cbarg;
  487. struct bfa_diag_results_tempsensor_s *temp;
  488. u8 lock;
  489. u8 rsv[3];
  490. u32 status;
  491. struct bfa_mbox_cmd_s mbcmd;
  492. };
  493. struct bfa_diag_sfpshow_s {
  494. struct sfp_mem_s *sfpmem;
  495. bfa_cb_diag_t cbfn;
  496. void *cbarg;
  497. u8 lock;
  498. u8 static_data;
  499. u8 rsv[2];
  500. u32 status;
  501. struct bfa_mbox_cmd_s mbcmd;
  502. u8 *dbuf_kva; /* dma buf virtual address */
  503. u64 dbuf_pa; /* dma buf physical address */
  504. };
  505. struct bfa_diag_led_s {
  506. struct bfa_mbox_cmd_s mbcmd;
  507. bfa_boolean_t lock; /* 1: ledtest is operating */
  508. };
  509. struct bfa_diag_beacon_s {
  510. struct bfa_mbox_cmd_s mbcmd;
  511. bfa_boolean_t state; /* port beacon state */
  512. bfa_boolean_t link_e2e; /* link beacon state */
  513. };
  514. struct bfa_diag_s {
  515. void *dev;
  516. struct bfa_ioc_s *ioc;
  517. struct bfa_trc_mod_s *trcmod;
  518. struct bfa_diag_fwping_s fwping;
  519. struct bfa_diag_tsensor_s tsensor;
  520. struct bfa_diag_sfpshow_s sfpshow;
  521. struct bfa_diag_led_s ledtest;
  522. struct bfa_diag_beacon_s beacon;
  523. void *result;
  524. struct bfa_timer_s timer;
  525. bfa_cb_diag_beacon_t cbfn_beacon;
  526. bfa_cb_diag_t cbfn;
  527. void *cbarg;
  528. u8 block;
  529. u8 timer_active;
  530. u8 rsvd[2];
  531. u32 status;
  532. struct bfa_ioc_notify_s ioc_notify;
  533. struct bfa_mem_dma_s diag_dma;
  534. };
  535. #define BFA_DIAG_MOD(__bfa) (&(__bfa)->modules.diag_mod)
  536. #define BFA_MEM_DIAG_DMA(__bfa) (&(BFA_DIAG_MOD(__bfa)->diag_dma))
  537. u32 bfa_diag_meminfo(void);
  538. void bfa_diag_memclaim(struct bfa_diag_s *diag, u8 *dm_kva, u64 dm_pa);
  539. void bfa_diag_attach(struct bfa_diag_s *diag, struct bfa_ioc_s *ioc, void *dev,
  540. bfa_cb_diag_beacon_t cbfn_beacon,
  541. struct bfa_trc_mod_s *trcmod);
  542. bfa_status_t bfa_diag_reg_read(struct bfa_diag_s *diag, u32 offset,
  543. u32 len, u32 *buf, u32 force);
  544. bfa_status_t bfa_diag_reg_write(struct bfa_diag_s *diag, u32 offset,
  545. u32 len, u32 value, u32 force);
  546. bfa_status_t bfa_diag_tsensor_query(struct bfa_diag_s *diag,
  547. struct bfa_diag_results_tempsensor_s *result,
  548. bfa_cb_diag_t cbfn, void *cbarg);
  549. bfa_status_t bfa_diag_fwping(struct bfa_diag_s *diag, u32 cnt,
  550. u32 pattern, struct bfa_diag_results_fwping *result,
  551. bfa_cb_diag_t cbfn, void *cbarg);
  552. bfa_status_t bfa_diag_sfpshow(struct bfa_diag_s *diag,
  553. struct sfp_mem_s *sfpmem, u8 static_data,
  554. bfa_cb_diag_t cbfn, void *cbarg);
  555. bfa_status_t bfa_diag_memtest(struct bfa_diag_s *diag,
  556. struct bfa_diag_memtest_s *memtest, u32 pattern,
  557. struct bfa_diag_memtest_result *result,
  558. bfa_cb_diag_t cbfn, void *cbarg);
  559. bfa_status_t bfa_diag_ledtest(struct bfa_diag_s *diag,
  560. struct bfa_diag_ledtest_s *ledtest);
  561. bfa_status_t bfa_diag_beacon_port(struct bfa_diag_s *diag,
  562. bfa_boolean_t beacon, bfa_boolean_t link_e2e_beacon,
  563. u32 sec);
  564. #define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func)
  565. #define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id)
  566. #define bfa_ioc_bar0(__ioc) ((__ioc)->pcidev.pci_bar_kva)
  567. #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
  568. #define bfa_ioc_asic_gen(__ioc) ((__ioc)->asic_gen)
  569. #define bfa_ioc_is_cna(__ioc) \
  570. ((bfa_ioc_get_type(__ioc) == BFA_IOC_TYPE_FCoE) || \
  571. (bfa_ioc_get_type(__ioc) == BFA_IOC_TYPE_LL))
  572. #define bfa_ioc_fetch_stats(__ioc, __stats) \
  573. (((__stats)->drv_stats) = (__ioc)->stats)
  574. #define bfa_ioc_clr_stats(__ioc) \
  575. memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats))
  576. #define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize)
  577. #define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit)
  578. #define bfa_ioc_speed_sup(__ioc) \
  579. BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop)
  580. #define bfa_ioc_get_nports(__ioc) \
  581. BFI_ADAPTER_GETP(NPORTS, (__ioc)->attr->adapter_prop)
  582. #define bfa_ioc_stats(_ioc, _stats) ((_ioc)->stats._stats++)
  583. #define BFA_IOC_FWIMG_MINSZ (16 * 1024)
  584. #define BFA_IOC_FW_SMEM_SIZE(__ioc) \
  585. ((bfa_ioc_asic_gen(__ioc) == BFI_ASIC_GEN_CB) \
  586. ? BFI_SMEM_CB_SIZE : BFI_SMEM_CT_SIZE)
  587. #define BFA_IOC_FLASH_CHUNK_NO(off) (off / BFI_FLASH_CHUNK_SZ_WORDS)
  588. #define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS)
  589. #define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS)
  590. /*
  591. * IOC mailbox interface
  592. */
  593. void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd);
  594. void bfa_ioc_mbox_register(struct bfa_ioc_s *ioc,
  595. bfa_ioc_mbox_mcfunc_t *mcfuncs);
  596. void bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc);
  597. void bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len);
  598. bfa_boolean_t bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg);
  599. void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  600. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
  601. /*
  602. * IOC interfaces
  603. */
  604. #define bfa_ioc_pll_init_asic(__ioc) \
  605. ((__ioc)->ioc_hwif->ioc_pll_init((__ioc)->pcidev.pci_bar_kva, \
  606. (__ioc)->asic_mode))
  607. bfa_status_t bfa_ioc_pll_init(struct bfa_ioc_s *ioc);
  608. bfa_status_t bfa_ioc_cb_pll_init(void __iomem *rb, enum bfi_asic_mode mode);
  609. bfa_status_t bfa_ioc_ct_pll_init(void __iomem *rb, enum bfi_asic_mode mode);
  610. bfa_status_t bfa_ioc_ct2_pll_init(void __iomem *rb, enum bfi_asic_mode mode);
  611. #define bfa_ioc_isr_mode_set(__ioc, __msix) do { \
  612. if ((__ioc)->ioc_hwif->ioc_isr_mode_set) \
  613. ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix)); \
  614. } while (0)
  615. #define bfa_ioc_ownership_reset(__ioc) \
  616. ((__ioc)->ioc_hwif->ioc_ownership_reset(__ioc))
  617. #define bfa_ioc_get_fcmode(__ioc) ((__ioc)->fcmode)
  618. #define bfa_ioc_lpu_read_stat(__ioc) do { \
  619. if ((__ioc)->ioc_hwif->ioc_lpu_read_stat) \
  620. ((__ioc)->ioc_hwif->ioc_lpu_read_stat(__ioc)); \
  621. } while (0)
  622. void bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc);
  623. void bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc);
  624. void bfa_ioc_set_ct2_hwif(struct bfa_ioc_s *ioc);
  625. void bfa_ioc_ct2_poweron(struct bfa_ioc_s *ioc);
  626. void bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa,
  627. struct bfa_ioc_cbfn_s *cbfn, struct bfa_timer_mod_s *timer_mod);
  628. void bfa_ioc_auto_recover(bfa_boolean_t auto_recover);
  629. void bfa_ioc_detach(struct bfa_ioc_s *ioc);
  630. void bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  631. enum bfi_pcifn_class clscode);
  632. void bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa);
  633. void bfa_ioc_enable(struct bfa_ioc_s *ioc);
  634. void bfa_ioc_disable(struct bfa_ioc_s *ioc);
  635. bfa_boolean_t bfa_ioc_intx_claim(struct bfa_ioc_s *ioc);
  636. void bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type,
  637. u32 boot_env);
  638. void bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *msg);
  639. void bfa_ioc_error_isr(struct bfa_ioc_s *ioc);
  640. bfa_boolean_t bfa_ioc_is_operational(struct bfa_ioc_s *ioc);
  641. bfa_boolean_t bfa_ioc_is_initialized(struct bfa_ioc_s *ioc);
  642. bfa_boolean_t bfa_ioc_is_disabled(struct bfa_ioc_s *ioc);
  643. bfa_boolean_t bfa_ioc_is_acq_addr(struct bfa_ioc_s *ioc);
  644. bfa_boolean_t bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc);
  645. bfa_boolean_t bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc);
  646. void bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc);
  647. enum bfa_ioc_type_e bfa_ioc_get_type(struct bfa_ioc_s *ioc);
  648. void bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num);
  649. void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver);
  650. void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver);
  651. void bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model);
  652. void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc,
  653. char *manufacturer);
  654. void bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev);
  655. enum bfa_ioc_state bfa_ioc_get_state(struct bfa_ioc_s *ioc);
  656. void bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr);
  657. void bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  658. struct bfa_adapter_attr_s *ad_attr);
  659. void bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave);
  660. bfa_status_t bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata,
  661. int *trclen);
  662. bfa_status_t bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata,
  663. int *trclen);
  664. bfa_status_t bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
  665. u32 *offset, int *buflen);
  666. bfa_boolean_t bfa_ioc_sem_get(void __iomem *sem_reg);
  667. void bfa_ioc_fwver_get(struct bfa_ioc_s *ioc,
  668. struct bfi_ioc_image_hdr_s *fwhdr);
  669. bfa_boolean_t bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc,
  670. struct bfi_ioc_image_hdr_s *fwhdr);
  671. bfa_status_t bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats);
  672. bfa_status_t bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc);
  673. /*
  674. * asic block configuration related APIs
  675. */
  676. u32 bfa_ablk_meminfo(void);
  677. void bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa);
  678. void bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc);
  679. bfa_status_t bfa_ablk_query(struct bfa_ablk_s *ablk,
  680. struct bfa_ablk_cfg_s *ablk_cfg,
  681. bfa_ablk_cbfn_t cbfn, void *cbarg);
  682. bfa_status_t bfa_ablk_adapter_config(struct bfa_ablk_s *ablk,
  683. enum bfa_mode_s mode, int max_pf, int max_vf,
  684. bfa_ablk_cbfn_t cbfn, void *cbarg);
  685. bfa_status_t bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port,
  686. enum bfa_mode_s mode, int max_pf, int max_vf,
  687. bfa_ablk_cbfn_t cbfn, void *cbarg);
  688. bfa_status_t bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
  689. u8 port, enum bfi_pcifn_class personality, int bw,
  690. bfa_ablk_cbfn_t cbfn, void *cbarg);
  691. bfa_status_t bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
  692. bfa_ablk_cbfn_t cbfn, void *cbarg);
  693. bfa_status_t bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, int bw,
  694. bfa_ablk_cbfn_t cbfn, void *cbarg);
  695. bfa_status_t bfa_ablk_optrom_en(struct bfa_ablk_s *ablk,
  696. bfa_ablk_cbfn_t cbfn, void *cbarg);
  697. bfa_status_t bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk,
  698. bfa_ablk_cbfn_t cbfn, void *cbarg);
  699. /*
  700. * bfa mfg wwn API functions
  701. */
  702. mac_t bfa_ioc_get_mac(struct bfa_ioc_s *ioc);
  703. mac_t bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc);
  704. /*
  705. * F/W Image Size & Chunk
  706. */
  707. extern u32 bfi_image_cb_size;
  708. extern u32 bfi_image_ct_size;
  709. extern u32 bfi_image_ct2_size;
  710. extern u32 *bfi_image_cb;
  711. extern u32 *bfi_image_ct;
  712. extern u32 *bfi_image_ct2;
  713. static inline u32 *
  714. bfi_image_cb_get_chunk(u32 off)
  715. {
  716. return (u32 *)(bfi_image_cb + off);
  717. }
  718. static inline u32 *
  719. bfi_image_ct_get_chunk(u32 off)
  720. {
  721. return (u32 *)(bfi_image_ct + off);
  722. }
  723. static inline u32 *
  724. bfi_image_ct2_get_chunk(u32 off)
  725. {
  726. return (u32 *)(bfi_image_ct2 + off);
  727. }
  728. static inline u32*
  729. bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off)
  730. {
  731. switch (asic_gen) {
  732. case BFI_ASIC_GEN_CB:
  733. return bfi_image_cb_get_chunk(off);
  734. break;
  735. case BFI_ASIC_GEN_CT:
  736. return bfi_image_ct_get_chunk(off);
  737. break;
  738. case BFI_ASIC_GEN_CT2:
  739. return bfi_image_ct2_get_chunk(off);
  740. break;
  741. default:
  742. return NULL;
  743. }
  744. }
  745. static inline u32
  746. bfa_cb_image_get_size(enum bfi_asic_gen asic_gen)
  747. {
  748. switch (asic_gen) {
  749. case BFI_ASIC_GEN_CB:
  750. return bfi_image_cb_size;
  751. break;
  752. case BFI_ASIC_GEN_CT:
  753. return bfi_image_ct_size;
  754. break;
  755. case BFI_ASIC_GEN_CT2:
  756. return bfi_image_ct2_size;
  757. break;
  758. default:
  759. return 0;
  760. }
  761. }
  762. /*
  763. * CNA TRCMOD declaration
  764. */
  765. /*
  766. * !!! Only append to the enums defined here to avoid any versioning
  767. * !!! needed between trace utility and driver version
  768. */
  769. enum {
  770. BFA_TRC_CNA_PORT = 1,
  771. BFA_TRC_CNA_IOC = 2,
  772. BFA_TRC_CNA_IOC_CB = 3,
  773. BFA_TRC_CNA_IOC_CT = 4,
  774. };
  775. #endif /* __BFA_IOC_H__ */