bfa_svc.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  4. * Copyright (c) 2014- QLogic Corporation.
  5. * All rights reserved
  6. * www.qlogic.com
  7. *
  8. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  9. */
  10. #ifndef __BFA_SVC_H__
  11. #define __BFA_SVC_H__
  12. #include "bfa_cs.h"
  13. #include "bfi_ms.h"
  14. /*
  15. * Scatter-gather DMA related defines
  16. */
  17. #define BFA_SGPG_MIN (16)
  18. #define BFA_SGPG_MAX (8192)
  19. /*
  20. * Alignment macro for SG page allocation
  21. */
  22. #define BFA_SGPG_ROUNDUP(_l) (((_l) + (sizeof(struct bfi_sgpg_s) - 1)) \
  23. & ~(sizeof(struct bfi_sgpg_s) - 1))
  24. struct bfa_sgpg_wqe_s {
  25. struct list_head qe; /* queue sg page element */
  26. int nsgpg; /* pages to be allocated */
  27. int nsgpg_total; /* total pages required */
  28. void (*cbfn) (void *cbarg); /* callback function */
  29. void *cbarg; /* callback arg */
  30. struct list_head sgpg_q; /* queue of alloced sgpgs */
  31. };
  32. struct bfa_sgpg_s {
  33. struct list_head qe; /* queue sg page element */
  34. struct bfi_sgpg_s *sgpg; /* va of SG page */
  35. union bfi_addr_u sgpg_pa; /* pa of SG page */
  36. };
  37. /*
  38. * Given number of SG elements, BFA_SGPG_NPAGE() returns the number of
  39. * SG pages required.
  40. */
  41. #define BFA_SGPG_NPAGE(_nsges) (((_nsges) / BFI_SGPG_DATA_SGES) + 1)
  42. /* Max SGPG dma segs required */
  43. #define BFA_SGPG_DMA_SEGS \
  44. BFI_MEM_DMA_NSEGS(BFA_SGPG_MAX, (uint32_t)sizeof(struct bfi_sgpg_s))
  45. struct bfa_sgpg_mod_s {
  46. struct bfa_s *bfa;
  47. int num_sgpgs; /* number of SG pages */
  48. int free_sgpgs; /* number of free SG pages */
  49. struct list_head sgpg_q; /* queue of free SG pages */
  50. struct list_head sgpg_wait_q; /* wait queue for SG pages */
  51. struct bfa_mem_dma_s dma_seg[BFA_SGPG_DMA_SEGS];
  52. struct bfa_mem_kva_s kva_seg;
  53. };
  54. #define BFA_SGPG_MOD(__bfa) (&(__bfa)->modules.sgpg_mod)
  55. #define BFA_MEM_SGPG_KVA(__bfa) (&(BFA_SGPG_MOD(__bfa)->kva_seg))
  56. bfa_status_t bfa_sgpg_malloc(struct bfa_s *bfa, struct list_head *sgpg_q,
  57. int nsgpgs);
  58. void bfa_sgpg_mfree(struct bfa_s *bfa, struct list_head *sgpg_q, int nsgpgs);
  59. void bfa_sgpg_winit(struct bfa_sgpg_wqe_s *wqe,
  60. void (*cbfn) (void *cbarg), void *cbarg);
  61. void bfa_sgpg_wait(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe, int nsgpgs);
  62. void bfa_sgpg_wcancel(struct bfa_s *bfa, struct bfa_sgpg_wqe_s *wqe);
  63. /*
  64. * FCXP related defines
  65. */
  66. #define BFA_FCXP_MIN (1)
  67. #define BFA_FCXP_MAX (256)
  68. #define BFA_FCXP_MAX_IBUF_SZ (2 * 1024 + 256)
  69. #define BFA_FCXP_MAX_LBUF_SZ (4 * 1024 + 256)
  70. /* Max FCXP dma segs required */
  71. #define BFA_FCXP_DMA_SEGS \
  72. BFI_MEM_DMA_NSEGS(BFA_FCXP_MAX, \
  73. (u32)BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ)
  74. struct bfa_fcxp_mod_s {
  75. struct bfa_s *bfa; /* backpointer to BFA */
  76. struct bfa_fcxp_s *fcxp_list; /* array of FCXPs */
  77. u16 num_fcxps; /* max num FCXP requests */
  78. struct list_head fcxp_req_free_q; /* free FCXPs used for sending req */
  79. struct list_head fcxp_rsp_free_q; /* free FCXPs used for sending req */
  80. struct list_head fcxp_active_q; /* active FCXPs */
  81. struct list_head req_wait_q; /* wait queue for free req_fcxp */
  82. struct list_head rsp_wait_q; /* wait queue for free rsp_fcxp */
  83. struct list_head fcxp_req_unused_q; /* unused req_fcxps */
  84. struct list_head fcxp_rsp_unused_q; /* unused rsp_fcxps */
  85. u32 req_pld_sz;
  86. u32 rsp_pld_sz;
  87. struct bfa_mem_dma_s dma_seg[BFA_FCXP_DMA_SEGS];
  88. struct bfa_mem_kva_s kva_seg;
  89. };
  90. #define BFA_FCXP_MOD(__bfa) (&(__bfa)->modules.fcxp_mod)
  91. #define BFA_FCXP_FROM_TAG(__mod, __tag) (&(__mod)->fcxp_list[__tag])
  92. #define BFA_MEM_FCXP_KVA(__bfa) (&(BFA_FCXP_MOD(__bfa)->kva_seg))
  93. typedef void (*fcxp_send_cb_t) (struct bfa_s *ioc, struct bfa_fcxp_s *fcxp,
  94. void *cb_arg, bfa_status_t req_status,
  95. u32 rsp_len, u32 resid_len,
  96. struct fchs_s *rsp_fchs);
  97. typedef u64 (*bfa_fcxp_get_sgaddr_t) (void *bfad_fcxp, int sgeid);
  98. typedef u32 (*bfa_fcxp_get_sglen_t) (void *bfad_fcxp, int sgeid);
  99. typedef void (*bfa_cb_fcxp_send_t) (void *bfad_fcxp, struct bfa_fcxp_s *fcxp,
  100. void *cbarg, enum bfa_status req_status,
  101. u32 rsp_len, u32 resid_len,
  102. struct fchs_s *rsp_fchs);
  103. typedef void (*bfa_fcxp_alloc_cbfn_t) (void *cbarg, struct bfa_fcxp_s *fcxp);
  104. /*
  105. * Information needed for a FCXP request
  106. */
  107. struct bfa_fcxp_req_info_s {
  108. struct bfa_rport_s *bfa_rport;
  109. /* Pointer to the bfa rport that was
  110. * returned from bfa_rport_create().
  111. * This could be left NULL for WKA or
  112. * for FCXP interactions before the
  113. * rport nexus is established
  114. */
  115. struct fchs_s fchs; /* request FC header structure */
  116. u8 cts; /* continuous sequence */
  117. u8 class; /* FC class for the request/response */
  118. u16 max_frmsz; /* max send frame size */
  119. u16 vf_id; /* vsan tag if applicable */
  120. u8 lp_tag; /* lport tag */
  121. u32 req_tot_len; /* request payload total length */
  122. };
  123. struct bfa_fcxp_rsp_info_s {
  124. struct fchs_s rsp_fchs;
  125. /* Response frame's FC header will
  126. * be sent back in this field */
  127. u8 rsp_timeout;
  128. /* timeout in seconds, 0-no response */
  129. u8 rsvd2[3];
  130. u32 rsp_maxlen; /* max response length expected */
  131. };
  132. struct bfa_fcxp_s {
  133. struct list_head qe; /* fcxp queue element */
  134. bfa_sm_t sm; /* state machine */
  135. void *caller; /* driver or fcs */
  136. struct bfa_fcxp_mod_s *fcxp_mod;
  137. /* back pointer to fcxp mod */
  138. u16 fcxp_tag; /* internal tag */
  139. struct bfa_fcxp_req_info_s req_info;
  140. /* request info */
  141. struct bfa_fcxp_rsp_info_s rsp_info;
  142. /* response info */
  143. u8 use_ireqbuf; /* use internal req buf */
  144. u8 use_irspbuf; /* use internal rsp buf */
  145. u32 nreq_sgles; /* num request SGLEs */
  146. u32 nrsp_sgles; /* num response SGLEs */
  147. struct list_head req_sgpg_q; /* SG pages for request buf */
  148. struct list_head req_sgpg_wqe; /* wait queue for req SG page */
  149. struct list_head rsp_sgpg_q; /* SG pages for response buf */
  150. struct list_head rsp_sgpg_wqe; /* wait queue for rsp SG page */
  151. bfa_fcxp_get_sgaddr_t req_sga_cbfn;
  152. /* SG elem addr user function */
  153. bfa_fcxp_get_sglen_t req_sglen_cbfn;
  154. /* SG elem len user function */
  155. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn;
  156. /* SG elem addr user function */
  157. bfa_fcxp_get_sglen_t rsp_sglen_cbfn;
  158. /* SG elem len user function */
  159. bfa_cb_fcxp_send_t send_cbfn; /* send completion callback */
  160. void *send_cbarg; /* callback arg */
  161. struct bfa_sge_s req_sge[BFA_FCXP_MAX_SGES];
  162. /* req SG elems */
  163. struct bfa_sge_s rsp_sge[BFA_FCXP_MAX_SGES];
  164. /* rsp SG elems */
  165. u8 rsp_status; /* comp: rsp status */
  166. u32 rsp_len; /* comp: actual response len */
  167. u32 residue_len; /* comp: residual rsp length */
  168. struct fchs_s rsp_fchs; /* comp: response fchs */
  169. struct bfa_cb_qe_s hcb_qe; /* comp: callback qelem */
  170. struct bfa_reqq_wait_s reqq_wqe;
  171. bfa_boolean_t reqq_waiting;
  172. bfa_boolean_t req_rsp; /* Used to track req/rsp fcxp */
  173. };
  174. struct bfa_fcxp_wqe_s {
  175. struct list_head qe;
  176. bfa_fcxp_alloc_cbfn_t alloc_cbfn;
  177. void *alloc_cbarg;
  178. void *caller;
  179. struct bfa_s *bfa;
  180. int nreq_sgles;
  181. int nrsp_sgles;
  182. bfa_fcxp_get_sgaddr_t req_sga_cbfn;
  183. bfa_fcxp_get_sglen_t req_sglen_cbfn;
  184. bfa_fcxp_get_sgaddr_t rsp_sga_cbfn;
  185. bfa_fcxp_get_sglen_t rsp_sglen_cbfn;
  186. };
  187. #define BFA_FCXP_REQ_PLD(_fcxp) (bfa_fcxp_get_reqbuf(_fcxp))
  188. #define BFA_FCXP_RSP_FCHS(_fcxp) (&((_fcxp)->rsp_info.fchs))
  189. #define BFA_FCXP_RSP_PLD(_fcxp) (bfa_fcxp_get_rspbuf(_fcxp))
  190. #define BFA_FCXP_REQ_PLD_PA(_fcxp) \
  191. bfa_mem_get_dmabuf_pa((_fcxp)->fcxp_mod, (_fcxp)->fcxp_tag, \
  192. (_fcxp)->fcxp_mod->req_pld_sz + (_fcxp)->fcxp_mod->rsp_pld_sz)
  193. /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
  194. #define BFA_FCXP_RSP_PLD_PA(_fcxp) \
  195. (bfa_mem_get_dmabuf_pa((_fcxp)->fcxp_mod, (_fcxp)->fcxp_tag, \
  196. (_fcxp)->fcxp_mod->req_pld_sz + (_fcxp)->fcxp_mod->rsp_pld_sz) + \
  197. (_fcxp)->fcxp_mod->req_pld_sz)
  198. void bfa_fcxp_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
  199. #define BFA_RPORT_MIN 4
  200. struct bfa_rport_mod_s {
  201. struct bfa_rport_s *rps_list; /* list of rports */
  202. struct list_head rp_free_q; /* free bfa_rports */
  203. struct list_head rp_active_q; /* free bfa_rports */
  204. struct list_head rp_unused_q; /* unused bfa rports */
  205. u16 num_rports; /* number of rports */
  206. struct bfa_mem_kva_s kva_seg;
  207. };
  208. #define BFA_RPORT_MOD(__bfa) (&(__bfa)->modules.rport_mod)
  209. #define BFA_MEM_RPORT_KVA(__bfa) (&(BFA_RPORT_MOD(__bfa)->kva_seg))
  210. /*
  211. * Convert rport tag to RPORT
  212. */
  213. #define BFA_RPORT_FROM_TAG(__bfa, _tag) \
  214. (BFA_RPORT_MOD(__bfa)->rps_list + \
  215. ((_tag) & (BFA_RPORT_MOD(__bfa)->num_rports - 1)))
  216. /*
  217. * protected functions
  218. */
  219. void bfa_rport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
  220. void bfa_rport_res_recfg(struct bfa_s *bfa, u16 num_rport_fw);
  221. /*
  222. * BFA rport information.
  223. */
  224. struct bfa_rport_info_s {
  225. u16 max_frmsz; /* max rcv pdu size */
  226. u32 pid:24, /* remote port ID */
  227. lp_tag:8; /* tag */
  228. u32 local_pid:24, /* local port ID */
  229. cisc:8; /* CIRO supported */
  230. u8 fc_class; /* supported FC classes. enum fc_cos */
  231. u8 vf_en; /* virtual fabric enable */
  232. u16 vf_id; /* virtual fabric ID */
  233. enum bfa_port_speed speed; /* Rport's current speed */
  234. };
  235. /*
  236. * RPORT related defines
  237. */
  238. enum bfa_rport_event {
  239. BFA_RPORT_SM_CREATE = 1, /* rport create event */
  240. BFA_RPORT_SM_DELETE = 2, /* deleting an existing rport */
  241. BFA_RPORT_SM_ONLINE = 3, /* rport is online */
  242. BFA_RPORT_SM_OFFLINE = 4, /* rport is offline */
  243. BFA_RPORT_SM_FWRSP = 5, /* firmware response */
  244. BFA_RPORT_SM_HWFAIL = 6, /* IOC h/w failure */
  245. BFA_RPORT_SM_QOS_SCN = 7, /* QoS SCN from firmware */
  246. BFA_RPORT_SM_SET_SPEED = 8, /* Set Rport Speed */
  247. BFA_RPORT_SM_QRESUME = 9, /* space in requeue queue */
  248. };
  249. struct bfa_rport_s;
  250. typedef void (*bfa_rport_sm_t)(struct bfa_rport_s *, enum bfa_rport_event);
  251. /*
  252. * BFA rport data structure
  253. */
  254. struct bfa_rport_s {
  255. struct list_head qe; /* queue element */
  256. bfa_rport_sm_t sm; /* state machine */
  257. struct bfa_s *bfa; /* backpointer to BFA */
  258. void *rport_drv; /* fcs/driver rport object */
  259. u16 fw_handle; /* firmware rport handle */
  260. u16 rport_tag; /* BFA rport tag */
  261. u8 lun_mask; /* LUN mask flag */
  262. struct bfa_rport_info_s rport_info; /* rport info from fcs/driver */
  263. struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */
  264. struct bfa_cb_qe_s hcb_qe; /* BFA callback qelem */
  265. struct bfa_rport_hal_stats_s stats; /* BFA rport statistics */
  266. struct bfa_rport_qos_attr_s qos_attr;
  267. union a {
  268. bfa_status_t status; /* f/w status */
  269. void *fw_msg; /* QoS scn event */
  270. } event_arg;
  271. };
  272. #define BFA_RPORT_FC_COS(_rport) ((_rport)->rport_info.fc_class)
  273. /*
  274. * UF - unsolicited receive related defines
  275. */
  276. #define BFA_UF_MIN (4)
  277. #define BFA_UF_MAX (256)
  278. struct bfa_uf_s {
  279. struct list_head qe; /* queue element */
  280. struct bfa_s *bfa; /* bfa instance */
  281. u16 uf_tag; /* identifying tag fw msgs */
  282. u16 vf_id;
  283. u16 src_rport_handle;
  284. u16 rsvd;
  285. u8 *data_ptr;
  286. u16 data_len; /* actual receive length */
  287. u16 pb_len; /* posted buffer length */
  288. void *buf_kva; /* buffer virtual address */
  289. u64 buf_pa; /* buffer physical address */
  290. struct bfa_cb_qe_s hcb_qe; /* comp: BFA comp qelem */
  291. struct bfa_sge_s sges[BFI_SGE_INLINE_MAX];
  292. };
  293. /*
  294. * Callback prototype for unsolicited frame receive handler.
  295. *
  296. * @param[in] cbarg callback arg for receive handler
  297. * @param[in] uf unsolicited frame descriptor
  298. *
  299. * @return None
  300. */
  301. typedef void (*bfa_cb_uf_recv_t) (void *cbarg, struct bfa_uf_s *uf);
  302. #define BFA_UF_BUFSZ (2 * 1024 + 256)
  303. struct bfa_uf_buf_s {
  304. u8 d[BFA_UF_BUFSZ];
  305. };
  306. #define BFA_PER_UF_DMA_SZ \
  307. (u32)BFA_ROUNDUP(sizeof(struct bfa_uf_buf_s), BFA_DMA_ALIGN_SZ)
  308. /* Max UF dma segs required */
  309. #define BFA_UF_DMA_SEGS BFI_MEM_DMA_NSEGS(BFA_UF_MAX, BFA_PER_UF_DMA_SZ)
  310. struct bfa_uf_mod_s {
  311. struct bfa_s *bfa; /* back pointer to BFA */
  312. struct bfa_uf_s *uf_list; /* array of UFs */
  313. u16 num_ufs; /* num unsolicited rx frames */
  314. struct list_head uf_free_q; /* free UFs */
  315. struct list_head uf_posted_q; /* UFs posted to IOC */
  316. struct list_head uf_unused_q; /* unused UF's */
  317. struct bfi_uf_buf_post_s *uf_buf_posts;
  318. /* pre-built UF post msgs */
  319. bfa_cb_uf_recv_t ufrecv; /* uf recv handler function */
  320. void *cbarg; /* uf receive handler arg */
  321. struct bfa_mem_dma_s dma_seg[BFA_UF_DMA_SEGS];
  322. struct bfa_mem_kva_s kva_seg;
  323. };
  324. #define BFA_UF_MOD(__bfa) (&(__bfa)->modules.uf_mod)
  325. #define BFA_MEM_UF_KVA(__bfa) (&(BFA_UF_MOD(__bfa)->kva_seg))
  326. #define ufm_pbs_pa(_ufmod, _uftag) \
  327. bfa_mem_get_dmabuf_pa(_ufmod, _uftag, BFA_PER_UF_DMA_SZ)
  328. void bfa_uf_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
  329. void bfa_uf_res_recfg(struct bfa_s *bfa, u16 num_uf_fw);
  330. /*
  331. * lps_pvt BFA LPS private functions
  332. */
  333. enum bfa_lps_event {
  334. BFA_LPS_SM_LOGIN = 1, /* login request from user */
  335. BFA_LPS_SM_LOGOUT = 2, /* logout request from user */
  336. BFA_LPS_SM_FWRSP = 3, /* f/w response to login/logout */
  337. BFA_LPS_SM_RESUME = 4, /* space present in reqq queue */
  338. BFA_LPS_SM_DELETE = 5, /* lps delete from user */
  339. BFA_LPS_SM_OFFLINE = 6, /* Link is offline */
  340. BFA_LPS_SM_RX_CVL = 7, /* Rx clear virtual link */
  341. BFA_LPS_SM_SET_N2N_PID = 8, /* Set assigned PID for n2n */
  342. };
  343. struct bfa_lps_s;
  344. typedef void (*bfa_lps_sm_t)(struct bfa_lps_s *, enum bfa_lps_event);
  345. /*
  346. * LPS - bfa lport login/logout service interface
  347. */
  348. struct bfa_lps_s {
  349. struct list_head qe; /* queue element */
  350. struct bfa_s *bfa; /* parent bfa instance */
  351. bfa_lps_sm_t sm; /* finite state machine */
  352. u8 bfa_tag; /* lport tag */
  353. u8 fw_tag; /* lport fw tag */
  354. u8 reqq; /* lport request queue */
  355. u8 alpa; /* ALPA for loop topologies */
  356. u32 lp_pid; /* lport port ID */
  357. bfa_boolean_t fdisc; /* snd FDISC instead of FLOGI */
  358. bfa_boolean_t auth_en; /* enable authentication */
  359. bfa_boolean_t auth_req; /* authentication required */
  360. bfa_boolean_t npiv_en; /* NPIV is allowed by peer */
  361. bfa_boolean_t fport; /* attached peer is F_PORT */
  362. bfa_boolean_t brcd_switch; /* attached peer is brcd sw */
  363. bfa_status_t status; /* login status */
  364. u16 pdusz; /* max receive PDU size */
  365. u16 pr_bbcred; /* BB_CREDIT from peer */
  366. u8 lsrjt_rsn; /* LSRJT reason */
  367. u8 lsrjt_expl; /* LSRJT explanation */
  368. u8 lun_mask; /* LUN mask flag */
  369. wwn_t pwwn; /* port wwn of lport */
  370. wwn_t nwwn; /* node wwn of lport */
  371. wwn_t pr_pwwn; /* port wwn of lport peer */
  372. wwn_t pr_nwwn; /* node wwn of lport peer */
  373. mac_t lp_mac; /* fpma/spma MAC for lport */
  374. mac_t fcf_mac; /* FCF MAC of lport */
  375. struct bfa_reqq_wait_s wqe; /* request wait queue element */
  376. void *uarg; /* user callback arg */
  377. struct bfa_cb_qe_s hcb_qe; /* comp: callback qelem */
  378. struct bfi_lps_login_rsp_s *loginrsp;
  379. bfa_eproto_status_t ext_status;
  380. };
  381. struct bfa_lps_mod_s {
  382. struct list_head lps_free_q;
  383. struct list_head lps_active_q;
  384. struct list_head lps_login_q;
  385. struct bfa_lps_s *lps_arr;
  386. int num_lps;
  387. struct bfa_mem_kva_s kva_seg;
  388. };
  389. #define BFA_LPS_MOD(__bfa) (&(__bfa)->modules.lps_mod)
  390. #define BFA_LPS_FROM_TAG(__mod, __tag) (&(__mod)->lps_arr[__tag])
  391. #define BFA_MEM_LPS_KVA(__bfa) (&(BFA_LPS_MOD(__bfa)->kva_seg))
  392. /*
  393. * external functions
  394. */
  395. void bfa_lps_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
  396. /*
  397. * FCPORT related defines
  398. */
  399. #define BFA_FCPORT(_bfa) (&((_bfa)->modules.port))
  400. /*
  401. * BFA port link notification state machine events
  402. */
  403. enum bfa_fcport_ln_sm_event {
  404. BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
  405. BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
  406. BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
  407. };
  408. struct bfa_fcport_ln_s;
  409. typedef void (*bfa_fcport_ln_sm_t)(struct bfa_fcport_ln_s *, enum bfa_fcport_ln_sm_event);
  410. /*
  411. * Link notification data structure
  412. */
  413. struct bfa_fcport_ln_s {
  414. struct bfa_fcport_s *fcport;
  415. bfa_fcport_ln_sm_t sm;
  416. struct bfa_cb_qe_s ln_qe; /* BFA callback queue elem for ln */
  417. enum bfa_port_linkstate ln_event; /* ln event for callback */
  418. };
  419. struct bfa_fcport_trunk_s {
  420. struct bfa_trunk_attr_s attr;
  421. };
  422. /*
  423. * BFA port state machine events
  424. */
  425. enum bfa_fcport_sm_event {
  426. BFA_FCPORT_SM_START = 1, /* start port state machine */
  427. BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
  428. BFA_FCPORT_SM_ENABLE = 3, /* enable port */
  429. BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
  430. BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
  431. BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
  432. BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
  433. BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
  434. BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
  435. BFA_FCPORT_SM_DPORTENABLE = 10, /* enable dport */
  436. BFA_FCPORT_SM_DPORTDISABLE = 11,/* disable dport */
  437. BFA_FCPORT_SM_FAA_MISCONFIG = 12, /* FAA misconfiguratin */
  438. BFA_FCPORT_SM_DDPORTENABLE = 13, /* enable ddport */
  439. BFA_FCPORT_SM_DDPORTDISABLE = 14, /* disable ddport */
  440. };
  441. struct bfa_fcport_s;
  442. typedef void (*bfa_fcport_sm_t)(struct bfa_fcport_s *, enum bfa_fcport_sm_event);
  443. /*
  444. * BFA FC port data structure
  445. */
  446. struct bfa_fcport_s {
  447. struct bfa_s *bfa; /* parent BFA instance */
  448. bfa_fcport_sm_t sm; /* port state machine */
  449. wwn_t nwwn; /* node wwn of physical port */
  450. wwn_t pwwn; /* port wwn of physical oprt */
  451. enum bfa_port_speed speed_sup;
  452. /* supported speeds */
  453. enum bfa_port_speed speed; /* current speed */
  454. enum bfa_port_topology topology; /* current topology */
  455. u8 rsvd[3];
  456. u8 myalpa; /* my ALPA in LOOP topology */
  457. u8 alpabm_valid; /* alpa bitmap valid or not */
  458. struct fc_alpabm_s alpabm; /* alpa bitmap */
  459. struct bfa_port_cfg_s cfg; /* current port configuration */
  460. bfa_boolean_t use_flash_cfg; /* get port cfg from flash */
  461. struct bfa_qos_attr_s qos_attr; /* QoS Attributes */
  462. struct bfa_qos_vc_attr_s qos_vc_attr; /* VC info from ELP */
  463. struct bfa_reqq_wait_s reqq_wait;
  464. /* to wait for room in reqq */
  465. struct bfa_reqq_wait_s svcreq_wait;
  466. /* to wait for room in reqq */
  467. struct bfa_reqq_wait_s stats_reqq_wait;
  468. /* to wait for room in reqq (stats) */
  469. void *event_cbarg;
  470. void (*event_cbfn) (void *cbarg,
  471. enum bfa_port_linkstate event);
  472. union {
  473. union bfi_fcport_i2h_msg_u i2hmsg;
  474. } event_arg;
  475. void *bfad; /* BFA driver handle */
  476. struct bfa_fcport_ln_s ln; /* Link Notification */
  477. struct bfa_cb_qe_s hcb_qe; /* BFA callback queue elem */
  478. struct bfa_timer_s timer; /* timer */
  479. u32 msgtag; /* fimrware msg tag for reply */
  480. u8 *stats_kva;
  481. u64 stats_pa;
  482. union bfa_fcport_stats_u *stats;
  483. bfa_status_t stats_status; /* stats/statsclr status */
  484. struct list_head stats_pending_q;
  485. struct list_head statsclr_pending_q;
  486. bfa_boolean_t stats_qfull;
  487. time64_t stats_reset_time; /* stats reset time stamp */
  488. bfa_boolean_t diag_busy; /* diag busy status */
  489. bfa_boolean_t beacon; /* port beacon status */
  490. bfa_boolean_t link_e2e_beacon; /* link beacon status */
  491. struct bfa_fcport_trunk_s trunk;
  492. u16 fcoe_vlan;
  493. struct bfa_mem_dma_s fcport_dma;
  494. bfa_boolean_t stats_dma_ready;
  495. struct bfa_bbcr_attr_s bbcr_attr;
  496. enum bfa_fec_state_s fec_state;
  497. };
  498. #define BFA_FCPORT_MOD(__bfa) (&(__bfa)->modules.fcport)
  499. #define BFA_MEM_FCPORT_DMA(__bfa) (&(BFA_FCPORT_MOD(__bfa)->fcport_dma))
  500. /*
  501. * protected functions
  502. */
  503. void bfa_fcport_init(struct bfa_s *bfa);
  504. void bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
  505. /*
  506. * bfa fcport API functions
  507. */
  508. bfa_status_t bfa_fcport_enable(struct bfa_s *bfa);
  509. bfa_status_t bfa_fcport_disable(struct bfa_s *bfa);
  510. bfa_status_t bfa_fcport_cfg_speed(struct bfa_s *bfa,
  511. enum bfa_port_speed speed);
  512. enum bfa_port_speed bfa_fcport_get_speed(struct bfa_s *bfa);
  513. bfa_status_t bfa_fcport_cfg_topology(struct bfa_s *bfa,
  514. enum bfa_port_topology topo);
  515. enum bfa_port_topology bfa_fcport_get_topology(struct bfa_s *bfa);
  516. enum bfa_port_topology bfa_fcport_get_cfg_topology(struct bfa_s *bfa);
  517. bfa_status_t bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa);
  518. bfa_boolean_t bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa);
  519. u8 bfa_fcport_get_myalpa(struct bfa_s *bfa);
  520. bfa_status_t bfa_fcport_clr_hardalpa(struct bfa_s *bfa);
  521. bfa_status_t bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxsize);
  522. u16 bfa_fcport_get_maxfrsize(struct bfa_s *bfa);
  523. u8 bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa);
  524. void bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_port_attr_s *attr);
  525. wwn_t bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node);
  526. void bfa_fcport_event_register(struct bfa_s *bfa,
  527. void (*event_cbfn) (void *cbarg,
  528. enum bfa_port_linkstate event), void *event_cbarg);
  529. bfa_boolean_t bfa_fcport_is_disabled(struct bfa_s *bfa);
  530. bfa_boolean_t bfa_fcport_is_dport(struct bfa_s *bfa);
  531. bfa_boolean_t bfa_fcport_is_ddport(struct bfa_s *bfa);
  532. bfa_status_t bfa_fcport_set_qos_bw(struct bfa_s *bfa,
  533. struct bfa_qos_bw_s *qos_bw);
  534. enum bfa_port_speed bfa_fcport_get_ratelim_speed(struct bfa_s *bfa);
  535. void bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit);
  536. bfa_boolean_t bfa_fcport_is_ratelim(struct bfa_s *bfa);
  537. void bfa_fcport_beacon(void *dev, bfa_boolean_t beacon,
  538. bfa_boolean_t link_e2e_beacon);
  539. bfa_boolean_t bfa_fcport_is_linkup(struct bfa_s *bfa);
  540. bfa_status_t bfa_fcport_get_stats(struct bfa_s *bfa,
  541. struct bfa_cb_pending_q_s *cb);
  542. bfa_status_t bfa_fcport_clear_stats(struct bfa_s *bfa,
  543. struct bfa_cb_pending_q_s *cb);
  544. bfa_boolean_t bfa_fcport_is_qos_enabled(struct bfa_s *bfa);
  545. bfa_boolean_t bfa_fcport_is_trunk_enabled(struct bfa_s *bfa);
  546. void bfa_fcport_dportenable(struct bfa_s *bfa);
  547. void bfa_fcport_dportdisable(struct bfa_s *bfa);
  548. bfa_status_t bfa_fcport_is_pbcdisabled(struct bfa_s *bfa);
  549. void bfa_fcport_cfg_faa(struct bfa_s *bfa, u8 state);
  550. bfa_status_t bfa_fcport_cfg_bbcr(struct bfa_s *bfa,
  551. bfa_boolean_t on_off, u8 bb_scn);
  552. bfa_status_t bfa_fcport_get_bbcr_attr(struct bfa_s *bfa,
  553. struct bfa_bbcr_attr_s *bbcr_attr);
  554. /*
  555. * bfa rport API functions
  556. */
  557. struct bfa_rport_s *bfa_rport_create(struct bfa_s *bfa, void *rport_drv);
  558. void bfa_rport_online(struct bfa_rport_s *rport,
  559. struct bfa_rport_info_s *rport_info);
  560. void bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed);
  561. void bfa_cb_rport_online(void *rport);
  562. void bfa_cb_rport_offline(void *rport);
  563. void bfa_cb_rport_qos_scn_flowid(void *rport,
  564. struct bfa_rport_qos_attr_s old_qos_attr,
  565. struct bfa_rport_qos_attr_s new_qos_attr);
  566. void bfa_cb_rport_scn_online(struct bfa_s *bfa);
  567. void bfa_cb_rport_scn_offline(struct bfa_s *bfa);
  568. void bfa_cb_rport_scn_no_dev(void *rp);
  569. void bfa_cb_rport_qos_scn_prio(void *rport,
  570. struct bfa_rport_qos_attr_s old_qos_attr,
  571. struct bfa_rport_qos_attr_s new_qos_attr);
  572. /*
  573. * Rport LUN masking related
  574. */
  575. #define BFA_RPORT_TAG_INVALID 0xffff
  576. #define BFA_LP_TAG_INVALID 0xff
  577. void bfa_rport_set_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp);
  578. void bfa_rport_unset_lunmask(struct bfa_s *bfa, struct bfa_rport_s *rp);
  579. /*
  580. * bfa fcxp API functions
  581. */
  582. struct bfa_fcxp_s *bfa_fcxp_req_rsp_alloc(void *bfad_fcxp, struct bfa_s *bfa,
  583. int nreq_sgles, int nrsp_sgles,
  584. bfa_fcxp_get_sgaddr_t get_req_sga,
  585. bfa_fcxp_get_sglen_t get_req_sglen,
  586. bfa_fcxp_get_sgaddr_t get_rsp_sga,
  587. bfa_fcxp_get_sglen_t get_rsp_sglen,
  588. bfa_boolean_t req);
  589. void bfa_fcxp_req_rsp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
  590. bfa_fcxp_alloc_cbfn_t alloc_cbfn,
  591. void *cbarg, void *bfad_fcxp,
  592. int nreq_sgles, int nrsp_sgles,
  593. bfa_fcxp_get_sgaddr_t get_req_sga,
  594. bfa_fcxp_get_sglen_t get_req_sglen,
  595. bfa_fcxp_get_sgaddr_t get_rsp_sga,
  596. bfa_fcxp_get_sglen_t get_rsp_sglen,
  597. bfa_boolean_t req);
  598. void bfa_fcxp_walloc_cancel(struct bfa_s *bfa,
  599. struct bfa_fcxp_wqe_s *wqe);
  600. void bfa_fcxp_discard(struct bfa_fcxp_s *fcxp);
  601. void *bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp);
  602. void *bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp);
  603. void bfa_fcxp_free(struct bfa_fcxp_s *fcxp);
  604. void bfa_fcxp_send(struct bfa_fcxp_s *fcxp, struct bfa_rport_s *rport,
  605. u16 vf_id, u8 lp_tag,
  606. bfa_boolean_t cts, enum fc_cos cos,
  607. u32 reqlen, struct fchs_s *fchs,
  608. bfa_cb_fcxp_send_t cbfn,
  609. void *cbarg,
  610. u32 rsp_maxlen, u8 rsp_timeout);
  611. bfa_status_t bfa_fcxp_abort(struct bfa_fcxp_s *fcxp);
  612. u32 bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp);
  613. u32 bfa_fcxp_get_maxrsp(struct bfa_s *bfa);
  614. void bfa_fcxp_res_recfg(struct bfa_s *bfa, u16 num_fcxp_fw);
  615. static inline void *
  616. bfa_uf_get_frmbuf(struct bfa_uf_s *uf)
  617. {
  618. return uf->data_ptr;
  619. }
  620. static inline u16
  621. bfa_uf_get_frmlen(struct bfa_uf_s *uf)
  622. {
  623. return uf->data_len;
  624. }
  625. /*
  626. * bfa uf API functions
  627. */
  628. void bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv,
  629. void *cbarg);
  630. void bfa_uf_free(struct bfa_uf_s *uf);
  631. /*
  632. * bfa lport service api
  633. */
  634. u32 bfa_lps_get_max_vport(struct bfa_s *bfa);
  635. struct bfa_lps_s *bfa_lps_alloc(struct bfa_s *bfa);
  636. void bfa_lps_delete(struct bfa_lps_s *lps);
  637. void bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa,
  638. u16 pdusz, wwn_t pwwn, wwn_t nwwn,
  639. bfa_boolean_t auth_en);
  640. void bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz,
  641. wwn_t pwwn, wwn_t nwwn);
  642. void bfa_lps_fdisclogo(struct bfa_lps_s *lps);
  643. void bfa_lps_set_n2n_pid(struct bfa_lps_s *lps, u32 n2n_pid);
  644. u8 bfa_lps_get_fwtag(struct bfa_s *bfa, u8 lp_tag);
  645. u32 bfa_lps_get_base_pid(struct bfa_s *bfa);
  646. u8 bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid);
  647. void bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status);
  648. void bfa_cb_lps_flogo_comp(void *bfad, void *uarg);
  649. void bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status);
  650. void bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg);
  651. void bfa_cb_lps_cvl_event(void *bfad, void *uarg);
  652. /* FAA specific APIs */
  653. bfa_status_t bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
  654. bfa_cb_iocfc_t cbfn, void *cbarg);
  655. /*
  656. * FC DIAG data structure
  657. */
  658. struct bfa_fcdiag_qtest_s {
  659. struct bfa_diag_qtest_result_s *result;
  660. bfa_cb_diag_t cbfn;
  661. void *cbarg;
  662. struct bfa_timer_s timer;
  663. u32 status;
  664. u32 count;
  665. u8 lock;
  666. u8 queue;
  667. u8 all;
  668. u8 timer_active;
  669. };
  670. struct bfa_fcdiag_lb_s {
  671. bfa_cb_diag_t cbfn;
  672. void *cbarg;
  673. void *result;
  674. bfa_boolean_t lock;
  675. u32 status;
  676. };
  677. /*
  678. * BFA DPORT state machine events
  679. */
  680. enum bfa_dport_sm_event {
  681. BFA_DPORT_SM_ENABLE = 1, /* dport enable event */
  682. BFA_DPORT_SM_DISABLE = 2, /* dport disable event */
  683. BFA_DPORT_SM_FWRSP = 3, /* fw enable/disable rsp */
  684. BFA_DPORT_SM_QRESUME = 4, /* CQ space available */
  685. BFA_DPORT_SM_HWFAIL = 5, /* IOC h/w failure */
  686. BFA_DPORT_SM_START = 6, /* re-start dport test */
  687. BFA_DPORT_SM_REQFAIL = 7, /* request failure */
  688. BFA_DPORT_SM_SCN = 8, /* state change notify frm fw */
  689. };
  690. struct bfa_dport_s;
  691. typedef void (*bfa_dport_sm_t)(struct bfa_dport_s *, enum bfa_dport_sm_event);
  692. struct bfa_dport_s {
  693. struct bfa_s *bfa; /* Back pointer to BFA */
  694. bfa_dport_sm_t sm; /* finite state machine */
  695. struct bfa_reqq_wait_s reqq_wait;
  696. bfa_cb_diag_t cbfn;
  697. void *cbarg;
  698. union bfi_diag_dport_msg_u i2hmsg;
  699. u8 test_state; /* enum dport_test_state */
  700. u8 dynamic; /* boolean_t */
  701. u8 rsvd[2];
  702. u32 lpcnt;
  703. u32 payload; /* user defined payload pattern */
  704. wwn_t rp_pwwn;
  705. wwn_t rp_nwwn;
  706. struct bfa_diag_dport_result_s result;
  707. };
  708. struct bfa_fcdiag_s {
  709. struct bfa_s *bfa; /* Back pointer to BFA */
  710. struct bfa_trc_mod_s *trcmod;
  711. struct bfa_fcdiag_lb_s lb;
  712. struct bfa_fcdiag_qtest_s qtest;
  713. struct bfa_dport_s dport;
  714. };
  715. #define BFA_FCDIAG_MOD(__bfa) (&(__bfa)->modules.fcdiag)
  716. void bfa_fcdiag_intr(struct bfa_s *bfa, struct bfi_msg_s *msg);
  717. bfa_status_t bfa_fcdiag_loopback(struct bfa_s *bfa,
  718. enum bfa_port_opmode opmode,
  719. enum bfa_port_speed speed, u32 lpcnt, u32 pat,
  720. struct bfa_diag_loopback_result_s *result,
  721. bfa_cb_diag_t cbfn, void *cbarg);
  722. bfa_status_t bfa_fcdiag_queuetest(struct bfa_s *bfa, u32 ignore,
  723. u32 queue, struct bfa_diag_qtest_result_s *result,
  724. bfa_cb_diag_t cbfn, void *cbarg);
  725. bfa_status_t bfa_fcdiag_lb_is_running(struct bfa_s *bfa);
  726. bfa_status_t bfa_dport_enable(struct bfa_s *bfa, u32 lpcnt, u32 pat,
  727. bfa_cb_diag_t cbfn, void *cbarg);
  728. bfa_status_t bfa_dport_disable(struct bfa_s *bfa, bfa_cb_diag_t cbfn,
  729. void *cbarg);
  730. bfa_status_t bfa_dport_start(struct bfa_s *bfa, u32 lpcnt, u32 pat,
  731. bfa_cb_diag_t cbfn, void *cbarg);
  732. bfa_status_t bfa_dport_show(struct bfa_s *bfa,
  733. struct bfa_diag_dport_result_s *result);
  734. #endif /* __BFA_SVC_H__ */