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