xref: /OK3568_Linux_fs/kernel/drivers/scsi/libfc/fc_libfc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright(c) 2009 Intel Corporation. All rights reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Maintained at www.Open-FCoE.org
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef _FC_LIBFC_H_
9*4882a593Smuzhiyun #define _FC_LIBFC_H_
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #define FC_LIBFC_LOGGING 0x01 /* General logging, not categorized */
12*4882a593Smuzhiyun #define FC_LPORT_LOGGING 0x02 /* lport layer logging */
13*4882a593Smuzhiyun #define FC_DISC_LOGGING	 0x04 /* discovery layer logging */
14*4882a593Smuzhiyun #define FC_RPORT_LOGGING 0x08 /* rport layer logging */
15*4882a593Smuzhiyun #define FC_FCP_LOGGING	 0x10 /* I/O path logging */
16*4882a593Smuzhiyun #define FC_EM_LOGGING	 0x20 /* Exchange Manager logging */
17*4882a593Smuzhiyun #define FC_EXCH_LOGGING	 0x40 /* Exchange/Sequence logging */
18*4882a593Smuzhiyun #define FC_SCSI_LOGGING	 0x80 /* SCSI logging (mostly error handling) */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun extern unsigned int fc_debug_logging;
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #define FC_CHECK_LOGGING(LEVEL, CMD)			\
23*4882a593Smuzhiyun 	do {						\
24*4882a593Smuzhiyun 		if (unlikely(fc_debug_logging & LEVEL))	\
25*4882a593Smuzhiyun 			do {				\
26*4882a593Smuzhiyun 				CMD;			\
27*4882a593Smuzhiyun 			} while (0);			\
28*4882a593Smuzhiyun 	} while (0)
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #define FC_LIBFC_DBG(fmt, args...)					\
31*4882a593Smuzhiyun 	FC_CHECK_LOGGING(FC_LIBFC_LOGGING,				\
32*4882a593Smuzhiyun 			 pr_info("libfc: " fmt, ##args))
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #define FC_LPORT_DBG(lport, fmt, args...)				\
35*4882a593Smuzhiyun 	FC_CHECK_LOGGING(FC_LPORT_LOGGING,				\
36*4882a593Smuzhiyun 			 pr_info("host%u: lport %6.6x: " fmt,		\
37*4882a593Smuzhiyun 				 (lport)->host->host_no,		\
38*4882a593Smuzhiyun 				 (lport)->port_id, ##args))
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun #define FC_DISC_DBG(disc, fmt, args...)					\
41*4882a593Smuzhiyun 	FC_CHECK_LOGGING(FC_DISC_LOGGING,				\
42*4882a593Smuzhiyun 			 pr_info("host%u: disc: " fmt,			\
43*4882a593Smuzhiyun 				 fc_disc_lport(disc)->host->host_no,	\
44*4882a593Smuzhiyun 				 ##args))
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #define FC_RPORT_ID_DBG(lport, port_id, fmt, args...)			\
47*4882a593Smuzhiyun 	FC_CHECK_LOGGING(FC_RPORT_LOGGING,				\
48*4882a593Smuzhiyun 			 pr_info("host%u: rport %6.6x: " fmt,		\
49*4882a593Smuzhiyun 				 (lport)->host->host_no,		\
50*4882a593Smuzhiyun 				 (port_id), ##args))
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #define FC_RPORT_DBG(rdata, fmt, args...)				\
53*4882a593Smuzhiyun 	FC_RPORT_ID_DBG((rdata)->local_port, (rdata)->ids.port_id, fmt, ##args)
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun #define FC_FCP_DBG(pkt, fmt, args...)					\
56*4882a593Smuzhiyun 	FC_CHECK_LOGGING(FC_FCP_LOGGING,				\
57*4882a593Smuzhiyun 	{								\
58*4882a593Smuzhiyun 		if ((pkt)->seq_ptr) {					\
59*4882a593Smuzhiyun 			struct fc_exch *_ep = NULL;			\
60*4882a593Smuzhiyun 			_ep = fc_seq_exch((pkt)->seq_ptr);		\
61*4882a593Smuzhiyun 			pr_info("host%u: fcp: %6.6x: "			\
62*4882a593Smuzhiyun 				"xid %04x-%04x: " fmt,			\
63*4882a593Smuzhiyun 				(pkt)->lp->host->host_no,		\
64*4882a593Smuzhiyun 				(pkt)->rport->port_id,			\
65*4882a593Smuzhiyun 				(_ep)->oxid, (_ep)->rxid, ##args);	\
66*4882a593Smuzhiyun 		} else {						\
67*4882a593Smuzhiyun 			pr_info("host%u: fcp: %6.6x: " fmt,		\
68*4882a593Smuzhiyun 				(pkt)->lp->host->host_no,		\
69*4882a593Smuzhiyun 				(pkt)->rport->port_id, ##args);		\
70*4882a593Smuzhiyun 		}							\
71*4882a593Smuzhiyun 	})
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #define FC_EXCH_DBG(exch, fmt, args...)					\
74*4882a593Smuzhiyun 	FC_CHECK_LOGGING(FC_EXCH_LOGGING,				\
75*4882a593Smuzhiyun 			 pr_info("host%u: xid %4x: " fmt,		\
76*4882a593Smuzhiyun 				 (exch)->lp->host->host_no,		\
77*4882a593Smuzhiyun 				 exch->xid, ##args))
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun #define FC_SCSI_DBG(lport, fmt, args...)				\
80*4882a593Smuzhiyun 	FC_CHECK_LOGGING(FC_SCSI_LOGGING,				\
81*4882a593Smuzhiyun 			 pr_info("host%u: scsi: " fmt,			\
82*4882a593Smuzhiyun 				 (lport)->host->host_no, ##args))
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /*
85*4882a593Smuzhiyun  * FC-4 Providers.
86*4882a593Smuzhiyun  */
87*4882a593Smuzhiyun extern struct fc4_prov *fc_active_prov[];	/* providers without recv */
88*4882a593Smuzhiyun extern struct fc4_prov *fc_passive_prov[];	/* providers with recv */
89*4882a593Smuzhiyun extern struct mutex fc_prov_mutex;		/* lock over table changes */
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun extern struct fc4_prov fc_rport_t0_prov;	/* type 0 provider */
92*4882a593Smuzhiyun extern struct fc4_prov fc_lport_els_prov;	/* ELS provider */
93*4882a593Smuzhiyun extern struct fc4_prov fc_rport_fcp_init;	/* FCP initiator provider */
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /*
96*4882a593Smuzhiyun  * Set up direct-data placement for this I/O request
97*4882a593Smuzhiyun  */
98*4882a593Smuzhiyun void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid);
99*4882a593Smuzhiyun void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /*
102*4882a593Smuzhiyun  * Module setup functions
103*4882a593Smuzhiyun  */
104*4882a593Smuzhiyun int fc_setup_exch_mgr(void);
105*4882a593Smuzhiyun void fc_destroy_exch_mgr(void);
106*4882a593Smuzhiyun int fc_setup_rport(void);
107*4882a593Smuzhiyun void fc_destroy_rport(void);
108*4882a593Smuzhiyun int fc_setup_fcp(void);
109*4882a593Smuzhiyun void fc_destroy_fcp(void);
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /*
112*4882a593Smuzhiyun  * Internal libfc functions
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun const char *fc_els_resp_type(struct fc_frame *);
115*4882a593Smuzhiyun extern void fc_fc4_add_lport(struct fc_lport *);
116*4882a593Smuzhiyun extern void fc_fc4_del_lport(struct fc_lport *);
117*4882a593Smuzhiyun extern void fc_fc4_conf_lport_params(struct fc_lport *, enum fc_fh_type);
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun /*
120*4882a593Smuzhiyun  * Copies a buffer into an sg list
121*4882a593Smuzhiyun  */
122*4882a593Smuzhiyun u32 fc_copy_buffer_to_sglist(void *buf, size_t len,
123*4882a593Smuzhiyun 			     struct scatterlist *sg,
124*4882a593Smuzhiyun 			     u32 *nents, size_t *offset,
125*4882a593Smuzhiyun 			     u32 *crc);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun #endif /* _FC_LIBFC_H_ */
128