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