• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
4  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
5  */
6 
7 #ifndef __EFCLIB_H__
8 #define __EFCLIB_H__
9 
10 #include "scsi/fc/fc_els.h"
11 #include "scsi/fc/fc_fs.h"
12 #include "scsi/fc/fc_ns.h"
13 #include "scsi/fc/fc_gs.h"
14 #include "scsi/fc_frame.h"
15 #include "../include/efc_common.h"
16 #include "../libefc_sli/sli4.h"
17 
18 #define EFC_SERVICE_PARMS_LENGTH	120
19 #define EFC_NAME_LENGTH			32
20 #define EFC_SM_NAME_LENGTH		64
21 #define EFC_DISPLAY_BUS_INFO_LENGTH	16
22 
23 #define EFC_WWN_LENGTH			32
24 
25 #define EFC_FC_ELS_DEFAULT_RETRIES	3
26 
27 /* Timeouts */
28 #define EFC_FC_ELS_SEND_DEFAULT_TIMEOUT	0
29 #define EFC_FC_FLOGI_TIMEOUT_SEC	5
30 #define EFC_SHUTDOWN_TIMEOUT_USEC	30000000
31 
32 /* Return values for calls from base driver to libefc */
33 #define EFC_SCSI_CALL_COMPLETE		0
34 #define EFC_SCSI_CALL_ASYNC		1
35 
36 /* Local port topology */
37 enum efc_nport_topology {
38 	EFC_NPORT_TOPO_UNKNOWN = 0,
39 	EFC_NPORT_TOPO_FABRIC,
40 	EFC_NPORT_TOPO_P2P,
41 	EFC_NPORT_TOPO_FC_AL,
42 };
43 
44 #define enable_target_rscn(efc)		1
45 
46 enum efc_node_shutd_rsn {
47 	EFC_NODE_SHUTDOWN_DEFAULT = 0,
48 	EFC_NODE_SHUTDOWN_EXPLICIT_LOGO,
49 	EFC_NODE_SHUTDOWN_IMPLICIT_LOGO,
50 };
51 
52 enum efc_node_send_ls_acc {
53 	EFC_NODE_SEND_LS_ACC_NONE = 0,
54 	EFC_NODE_SEND_LS_ACC_PLOGI,
55 	EFC_NODE_SEND_LS_ACC_PRLI,
56 };
57 
58 #define EFC_LINK_STATUS_UP		0
59 #define EFC_LINK_STATUS_DOWN		1
60 
61 enum efc_sm_event;
62 
63 /* State machine context header  */
64 struct efc_sm_ctx {
65 	void (*current_state)(struct efc_sm_ctx *ctx,
66 			      enum efc_sm_event evt, void *arg);
67 
68 	const char	*description;
69 	void		*app;
70 };
71 
72 /* Description of discovered Fabric Domain */
73 struct efc_domain_record {
74 	u32		index;
75 	u32		priority;
76 	u8		address[6];
77 	u8		wwn[8];
78 	union {
79 		u8	vlan[512];
80 		u8	loop[128];
81 	} map;
82 	u32		speed;
83 	u32		fc_id;
84 	bool		is_loop;
85 	bool		is_nport;
86 };
87 
88 /* Domain events */
89 enum efc_hw_domain_event {
90 	EFC_HW_DOMAIN_ALLOC_OK,
91 	EFC_HW_DOMAIN_ALLOC_FAIL,
92 	EFC_HW_DOMAIN_ATTACH_OK,
93 	EFC_HW_DOMAIN_ATTACH_FAIL,
94 	EFC_HW_DOMAIN_FREE_OK,
95 	EFC_HW_DOMAIN_FREE_FAIL,
96 	EFC_HW_DOMAIN_LOST,
97 	EFC_HW_DOMAIN_FOUND,
98 	EFC_HW_DOMAIN_CHANGED,
99 };
100 
101 /**
102  * Fibre Channel port object
103  *
104  * @list_entry:		nport list entry
105  * @ref:		reference count, each node takes a reference
106  * @release:		function to free nport object
107  * @efc:		pointer back to efc
108  * @instance_index:	unique instance index value
109  * @display_name:	port display name
110  * @is_vport:		Is NPIV port
111  * @free_req_pending:	pending request to free resources
112  * @attached:		mark attached if reg VPI succeeds
113  * @p2p_winner:		TRUE if we're the point-to-point winner
114  * @domain:		pointer back to domain
115  * @wwpn:		port wwpn
116  * @wwnn:		port wwnn
117  * @tgt_data:		target backend private port data
118  * @ini_data:		initiator backend private port data
119  * @indicator:		VPI
120  * @fc_id:		port FC address
121  * @dma:		memory for Service Parameters
122  * @wwnn_str:		wwpn string
123  * @sli_wwpn:		SLI provided wwpn
124  * @sli_wwnn:		SLI provided wwnn
125  * @sm:			nport state machine context
126  * @lookup:		fc_id to node lookup object
127  * @enable_ini:		SCSI initiator enabled for this port
128  * @enable_tgt:		SCSI target enabled for this port
129  * @enable_rscn:	port will be expecting RSCN
130  * @shutting_down:	nport in process of shutting down
131  * @p2p_port_id:	our port id for point-to-point
132  * @topology:		topology: fabric/p2p/unknown
133  * @service_params:	login parameters
134  * @p2p_remote_port_id:	remote node's port id for point-to-point
135  */
136 
137 struct efc_nport {
138 	struct list_head	list_entry;
139 	struct kref		ref;
140 	void			(*release)(struct kref *arg);
141 	struct efc		*efc;
142 	u32			instance_index;
143 	char			display_name[EFC_NAME_LENGTH];
144 	bool			is_vport;
145 	bool			free_req_pending;
146 	bool			attached;
147 	bool			p2p_winner;
148 	struct efc_domain	*domain;
149 	u64			wwpn;
150 	u64			wwnn;
151 	void			*tgt_data;
152 	void			*ini_data;
153 
154 	u32			indicator;
155 	u32			fc_id;
156 	struct efc_dma		dma;
157 
158 	u8			wwnn_str[EFC_WWN_LENGTH];
159 	__be64			sli_wwpn;
160 	__be64			sli_wwnn;
161 
162 	struct efc_sm_ctx	sm;
163 	struct xarray		lookup;
164 	bool			enable_ini;
165 	bool			enable_tgt;
166 	bool			enable_rscn;
167 	bool			shutting_down;
168 	u32			p2p_port_id;
169 	enum efc_nport_topology topology;
170 	u8			service_params[EFC_SERVICE_PARMS_LENGTH];
171 	u32			p2p_remote_port_id;
172 };
173 
174 /**
175  * Fibre Channel domain object
176  *
177  * This object is a container for the various SLI components needed
178  * to connect to the domain of a FC or FCoE switch
179  * @efc:		pointer back to efc
180  * @instance_index:	unique instance index value
181  * @display_name:	Node display name
182  * @nport_list:		linked list of nports associated with this domain
183  * @ref:		Reference count, each nport takes a reference
184  * @release:		Function to free domain object
185  * @ini_domain:		initiator backend private domain data
186  * @tgt_domain:		target backend private domain data
187  * @sm:			state machine context
188  * @fcf:		FC Forwarder table index
189  * @fcf_indicator:	FCFI
190  * @indicator:		VFI
191  * @nport_count:	Number of nports allocated
192  * @dma:		memory for Service Parameters
193  * @fcf_wwn:		WWN for FCF/switch
194  * @drvsm:		driver domain sm context
195  * @attached:		set true after attach completes
196  * @is_fc:		is FC
197  * @is_loop:		is loop topology
198  * @is_nlport:		is public loop
199  * @domain_found_pending:A domain found is pending, drec is updated
200  * @req_domain_free:	True if domain object should be free'd
201  * @req_accept_frames:	set in domain state machine to enable frames
202  * @domain_notify_pend:	Set in domain SM to avoid duplicate node event post
203  * @pending_drec:	Pending drec if a domain found is pending
204  * @service_params:	any nports service parameters
205  * @flogi_service_params:Fabric/P2p service parameters from FLOGI
206  * @lookup:		d_id to node lookup object
207  * @nport:		Pointer to first (physical) SLI port
208  */
209 struct efc_domain {
210 	struct efc		*efc;
211 	char			display_name[EFC_NAME_LENGTH];
212 	struct list_head	nport_list;
213 	struct kref		ref;
214 	void			(*release)(struct kref *arg);
215 	void			*ini_domain;
216 	void			*tgt_domain;
217 
218 	/* Declarations private to HW/SLI */
219 	u32			fcf;
220 	u32			fcf_indicator;
221 	u32			indicator;
222 	u32			nport_count;
223 	struct efc_dma		dma;
224 
225 	/* Declarations private to FC trannport */
226 	u64			fcf_wwn;
227 	struct efc_sm_ctx	drvsm;
228 	bool			attached;
229 	bool			is_fc;
230 	bool			is_loop;
231 	bool			is_nlport;
232 	bool			domain_found_pending;
233 	bool			req_domain_free;
234 	bool			req_accept_frames;
235 	bool			domain_notify_pend;
236 
237 	struct efc_domain_record pending_drec;
238 	u8			service_params[EFC_SERVICE_PARMS_LENGTH];
239 	u8			flogi_service_params[EFC_SERVICE_PARMS_LENGTH];
240 
241 	struct xarray		lookup;
242 
243 	struct efc_nport	*nport;
244 };
245 
246 /**
247  * Remote Node object
248  *
249  * This object represents a connection between the SLI port and another
250  * Nx_Port on the fabric. Note this can be either a well known port such
251  * as a F_Port (i.e. ff:ff:fe) or another N_Port.
252  * @indicator:		RPI
253  * @fc_id:		FC address
254  * @attached:		true if attached
255  * @nport:		associated SLI port
256  * @node:		associated node
257  */
258 struct efc_remote_node {
259 	u32			indicator;
260 	u32			index;
261 	u32			fc_id;
262 
263 	bool			attached;
264 
265 	struct efc_nport	*nport;
266 	void			*node;
267 };
268 
269 /**
270  * FC Node object
271  * @efc:		pointer back to efc structure
272  * @display_name:	Node display name
273  * @nort:		Assosiated nport pointer.
274  * @hold_frames:	hold incoming frames if true
275  * @els_io_enabled:	Enable allocating els ios for this node
276  * @els_ios_lock:	lock to protect the els ios list
277  * @els_ios_list:	ELS I/O's for this node
278  * @ini_node:		backend initiator private node data
279  * @tgt_node:		backend target private node data
280  * @rnode:		Remote node
281  * @sm:			state machine context
282  * @evtdepth:		current event posting nesting depth
283  * @req_free:		this node is to be free'd
284  * @attached:		node is attached (REGLOGIN complete)
285  * @fcp_enabled:	node is enabled to handle FCP
286  * @rscn_pending:	for name server node RSCN is pending
287  * @send_plogi:		send PLOGI accept, upon completion of node attach
288  * @send_plogi_acc:	TRUE if io_alloc() is enabled.
289  * @send_ls_acc:	type of LS acc to send
290  * @ls_acc_io:		SCSI IO for LS acc
291  * @ls_acc_oxid:	OX_ID for pending accept
292  * @ls_acc_did:		D_ID for pending accept
293  * @shutdown_reason:	reason for node shutdown
294  * @sparm_dma_buf:	service parameters buffer
295  * @service_params:	plogi/acc frame from remote device
296  * @pend_frames_lock:	lock for inbound pending frames list
297  * @pend_frames:	inbound pending frames list
298  * @pend_frames_processed:count of frames processed in hold frames interval
299  * @ox_id_in_use:	used to verify one at a time us of ox_id
300  * @els_retries_remaining:for ELS, number of retries remaining
301  * @els_req_cnt:	number of outstanding ELS requests
302  * @els_cmpl_cnt:	number of outstanding ELS completions
303  * @abort_cnt:		Abort counter for debugging purpos
304  * @current_state_name:	current node state
305  * @prev_state_name:	previous node state
306  * @current_evt:	current event
307  * @prev_evt:		previous event
308  * @targ:		node is target capable
309  * @init:		node is init capable
310  * @refound:		Handle node refound case when node is being deleted
311  * @els_io_pend_list:	list of pending (not yet processed) ELS IOs
312  * @els_io_active_list:	list of active (processed) ELS IOs
313  * @nodedb_state:	Node debugging, saved state
314  * @gidpt_delay_timer:	GIDPT delay timer
315  * @time_last_gidpt_msec:Start time of last target RSCN GIDPT
316  * @wwnn:		remote port WWNN
317  * @wwpn:		remote port WWPN
318  */
319 struct efc_node {
320 	struct efc		*efc;
321 	char			display_name[EFC_NAME_LENGTH];
322 	struct efc_nport	*nport;
323 	struct kref		ref;
324 	void			(*release)(struct kref *arg);
325 	bool			hold_frames;
326 	bool			els_io_enabled;
327 	bool			send_plogi_acc;
328 	bool			send_plogi;
329 	bool			rscn_pending;
330 	bool			fcp_enabled;
331 	bool			attached;
332 	bool			req_free;
333 
334 	spinlock_t		els_ios_lock;
335 	struct list_head	els_ios_list;
336 	void			*ini_node;
337 	void			*tgt_node;
338 
339 	struct efc_remote_node	rnode;
340 	/* Declarations private to FC trannport */
341 	struct efc_sm_ctx	sm;
342 	u32			evtdepth;
343 
344 	enum efc_node_send_ls_acc send_ls_acc;
345 	void			*ls_acc_io;
346 	u32			ls_acc_oxid;
347 	u32			ls_acc_did;
348 	enum efc_node_shutd_rsn	shutdown_reason;
349 	bool			targ;
350 	bool			init;
351 	bool			refound;
352 	struct efc_dma		sparm_dma_buf;
353 	u8			service_params[EFC_SERVICE_PARMS_LENGTH];
354 	spinlock_t		pend_frames_lock;
355 	struct list_head	pend_frames;
356 	u32			pend_frames_processed;
357 	u32			ox_id_in_use;
358 	u32			els_retries_remaining;
359 	u32			els_req_cnt;
360 	u32			els_cmpl_cnt;
361 	u32			abort_cnt;
362 
363 	char			current_state_name[EFC_SM_NAME_LENGTH];
364 	char			prev_state_name[EFC_SM_NAME_LENGTH];
365 	int			current_evt;
366 	int			prev_evt;
367 
368 	void (*nodedb_state)(struct efc_sm_ctx *ctx,
369 			     enum efc_sm_event evt, void *arg);
370 	struct timer_list	gidpt_delay_timer;
371 	u64			time_last_gidpt_msec;
372 
373 	char			wwnn[EFC_WWN_LENGTH];
374 	char			wwpn[EFC_WWN_LENGTH];
375 };
376 
377 /**
378  * NPIV port
379  *
380  * Collection of the information required to restore a virtual port across
381  * link events
382  * @wwnn:		node name
383  * @wwpn:		port name
384  * @fc_id:		port id
385  * @tgt_data:		target backend pointer
386  * @ini_data:		initiator backend pointe
387  * @nport:		Used to match record after attaching for update
388  *
389  */
390 
391 struct efc_vport {
392 	struct list_head	list_entry;
393 	u64			wwnn;
394 	u64			wwpn;
395 	u32			fc_id;
396 	bool			enable_tgt;
397 	bool			enable_ini;
398 	void			*tgt_data;
399 	void			*ini_data;
400 	struct efc_nport	*nport;
401 };
402 
403 #define node_printf(node, fmt, args...) \
404 	efc_log_info(node->efc, "[%s] " fmt, node->display_name, ##args)
405 
406 /* Node SM IO Context Callback structure */
407 struct efc_node_cb {
408 	int			status;
409 	int			ext_status;
410 	struct efc_hw_rq_buffer *header;
411 	struct efc_hw_rq_buffer *payload;
412 	struct efc_dma		els_rsp;
413 
414 	/* Actual length of data received */
415 	int			rsp_len;
416 };
417 
418 struct efc_hw_rq_buffer {
419 	u16			rqindex;
420 	struct efc_dma		dma;
421 };
422 
423 /**
424  * FC sequence object
425  *
426  * Defines a general FC sequence object
427  * @hw:			HW that owns this sequence
428  * @fcfi:		FCFI associated with sequence
429  * @header:		Received frame header
430  * @payload:		Received frame header
431  * @hw_priv:		HW private context
432  */
433 struct efc_hw_sequence {
434 	struct list_head	list_entry;
435 	void			*hw;
436 	u8			fcfi;
437 	struct efc_hw_rq_buffer *header;
438 	struct efc_hw_rq_buffer *payload;
439 	void			*hw_priv;
440 };
441 
442 enum efc_disc_io_type {
443 	EFC_DISC_IO_ELS_REQ,
444 	EFC_DISC_IO_ELS_RESP,
445 	EFC_DISC_IO_CT_REQ,
446 	EFC_DISC_IO_CT_RESP
447 };
448 
449 struct efc_io_els_params {
450 	u32             s_id;
451 	u16             ox_id;
452 	u8              timeout;
453 };
454 
455 struct efc_io_ct_params {
456 	u8              r_ctl;
457 	u8              type;
458 	u8              df_ctl;
459 	u8              timeout;
460 	u16             ox_id;
461 };
462 
463 union efc_disc_io_param {
464 	struct efc_io_els_params els;
465 	struct efc_io_ct_params ct;
466 };
467 
468 struct efc_disc_io {
469 	struct efc_dma		req;         /* send buffer */
470 	struct efc_dma		rsp;         /* receive buffer */
471 	enum efc_disc_io_type	io_type;     /* EFC_DISC_IO_TYPE enum*/
472 	u16			xmit_len;    /* Length of els request*/
473 	u16			rsp_len;     /* Max length of rsps to be rcvd */
474 	u32			rpi;         /* Registered RPI */
475 	u32			vpi;         /* VPI for this nport */
476 	u32			s_id;
477 	u32			d_id;
478 	bool			rpi_registered; /* if false, use tmp RPI */
479 	union efc_disc_io_param iparam;
480 };
481 
482 /* Return value indiacating the sequence can not be freed */
483 #define EFC_HW_SEQ_HOLD		0
484 /* Return value indiacating the sequence can be freed */
485 #define EFC_HW_SEQ_FREE		1
486 
487 struct libefc_function_template {
488 	/*Sport*/
489 	int (*new_nport)(struct efc *efc, struct efc_nport *sp);
490 	void (*del_nport)(struct efc *efc, struct efc_nport *sp);
491 
492 	/*Scsi Node*/
493 	int (*scsi_new_node)(struct efc *efc, struct efc_node *n);
494 	int (*scsi_del_node)(struct efc *efc, struct efc_node *n, int reason);
495 
496 	int (*issue_mbox_rqst)(void *efct, void *buf, void *cb, void *arg);
497 	/*Send ELS IO*/
498 	int (*send_els)(struct efc *efc, struct efc_disc_io *io);
499 	/*Send BLS IO*/
500 	int (*send_bls)(struct efc *efc, u32 type, struct sli_bls_params *bls);
501 	/*Free HW frame*/
502 	int (*hw_seq_free)(struct efc *efc, struct efc_hw_sequence *seq);
503 };
504 
505 #define EFC_LOG_LIB		0x01
506 #define EFC_LOG_NODE		0x02
507 #define EFC_LOG_PORT		0x04
508 #define EFC_LOG_DOMAIN		0x08
509 #define EFC_LOG_ELS		0x10
510 #define EFC_LOG_DOMAIN_SM	0x20
511 #define EFC_LOG_SM		0x40
512 
513 /* efc library port structure */
514 struct efc {
515 	void			*base;
516 	struct pci_dev		*pci;
517 	struct sli4		*sli;
518 	u32			fcfi;
519 	u64			req_wwpn;
520 	u64			req_wwnn;
521 
522 	u64			def_wwpn;
523 	u64			def_wwnn;
524 	u64			max_xfer_size;
525 	mempool_t		*node_pool;
526 	struct dma_pool		*node_dma_pool;
527 	u32			nodes_count;
528 
529 	u32			link_status;
530 
531 	struct list_head	vport_list;
532 	/* lock to protect the vport list */
533 	spinlock_t		vport_lock;
534 
535 	struct libefc_function_template tt;
536 	/* lock to protect the discovery library.
537 	 * Refer to efclib.c for more details.
538 	 */
539 	spinlock_t		lock;
540 
541 	bool			enable_ini;
542 	bool			enable_tgt;
543 
544 	u32			log_level;
545 
546 	struct efc_domain	*domain;
547 	void (*domain_free_cb)(struct efc *efc, void *arg);
548 	void			*domain_free_cb_arg;
549 
550 	u64			tgt_rscn_delay_msec;
551 	u64			tgt_rscn_period_msec;
552 
553 	bool			external_loopback;
554 	u32			nodedb_mask;
555 	u32			logmask;
556 	mempool_t		*els_io_pool;
557 	atomic_t		els_io_alloc_failed_count;
558 
559 	/* hold pending frames */
560 	bool			hold_frames;
561 	/* lock to protect pending frames list access */
562 	spinlock_t		pend_frames_lock;
563 	struct list_head	pend_frames;
564 	/* count of pending frames that were processed */
565 	u32			pend_frames_processed;
566 
567 };
568 
569 /*
570  * EFC library registration
571  * **********************************/
572 int efcport_init(struct efc *efc);
573 void efcport_destroy(struct efc *efc);
574 /*
575  * EFC Domain
576  * **********************************/
577 int efc_domain_cb(void *arg, int event, void *data);
578 void
579 efc_register_domain_free_cb(struct efc *efc,
580 			    void (*callback)(struct efc *efc, void *arg),
581 			    void *arg);
582 
583 /*
584  * EFC nport
585  * **********************************/
586 void efc_nport_cb(void *arg, int event, void *data);
587 struct efc_vport *
588 efc_vport_create_spec(struct efc *efc, u64 wwnn, u64 wwpn, u32 fc_id,
589 		      bool enable_ini, bool enable_tgt,
590 		      void *tgt_data, void *ini_data);
591 int efc_nport_vport_new(struct efc_domain *domain, u64 wwpn,
592 			u64 wwnn, u32 fc_id, bool ini, bool tgt,
593 			void *tgt_data, void *ini_data);
594 int efc_nport_vport_del(struct efc *efc, struct efc_domain *domain,
595 			u64 wwpn, u64 wwnn);
596 
597 void efc_vport_del_all(struct efc *efc);
598 
599 /*
600  * EFC Node
601  * **********************************/
602 int efc_remote_node_cb(void *arg, int event, void *data);
603 void efc_node_fcid_display(u32 fc_id, char *buffer, u32 buf_len);
604 void efc_node_post_shutdown(struct efc_node *node, void *arg);
605 u64 efc_node_get_wwpn(struct efc_node *node);
606 
607 /*
608  * EFC FCP/ELS/CT interface
609  * **********************************/
610 void efc_dispatch_frame(struct efc *efc, struct efc_hw_sequence *seq);
611 void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
612 			  u32 ext_status);
613 
614 /*
615  * EFC SCSI INTERACTION LAYER
616  * **********************************/
617 void efc_scsi_sess_reg_complete(struct efc_node *node, u32 status);
618 void efc_scsi_del_initiator_complete(struct efc *efc, struct efc_node *node);
619 void efc_scsi_del_target_complete(struct efc *efc, struct efc_node *node);
620 void efc_scsi_io_list_empty(struct efc *efc, struct efc_node *node);
621 
622 #endif /* __EFCLIB_H__ */
623