xref: /openbmc/linux/include/uapi/scsi/scsi_bsg_fc.h (revision b830f94f)
1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2 /*
3  *  FC Transport BSG Interface
4  *
5  *  Copyright (C) 2008   James Smart, Emulex Corporation
6  */
7 
8 #ifndef SCSI_BSG_FC_H
9 #define SCSI_BSG_FC_H
10 
11 /*
12  * This file intended to be included by both kernel and user space
13  */
14 
15 /*
16  * FC Transport SGIO v4 BSG Message Support
17  */
18 
19 /* Default BSG request timeout (in seconds) */
20 #define FC_DEFAULT_BSG_TIMEOUT		(10 * HZ)
21 
22 
23 /*
24  * Request Message Codes supported by the FC Transport
25  */
26 
27 /* define the class masks for the message codes */
28 #define FC_BSG_CLS_MASK		0xF0000000	/* find object class */
29 #define FC_BSG_HST_MASK		0x80000000	/* fc host class */
30 #define FC_BSG_RPT_MASK		0x40000000	/* fc rport class */
31 
32 	/* fc_host Message Codes */
33 #define FC_BSG_HST_ADD_RPORT		(FC_BSG_HST_MASK | 0x00000001)
34 #define FC_BSG_HST_DEL_RPORT		(FC_BSG_HST_MASK | 0x00000002)
35 #define FC_BSG_HST_ELS_NOLOGIN		(FC_BSG_HST_MASK | 0x00000003)
36 #define FC_BSG_HST_CT			(FC_BSG_HST_MASK | 0x00000004)
37 #define FC_BSG_HST_VENDOR		(FC_BSG_HST_MASK | 0x000000FF)
38 
39 	/* fc_rport Message Codes */
40 #define FC_BSG_RPT_ELS			(FC_BSG_RPT_MASK | 0x00000001)
41 #define FC_BSG_RPT_CT			(FC_BSG_RPT_MASK | 0x00000002)
42 
43 
44 
45 /*
46  * FC Address Identifiers in Message Structures :
47  *
48  *   Whenever a command payload contains a FC Address Identifier
49  *   (aka port_id), the value is effectively in big-endian
50  *   order, thus the array elements are decoded as follows:
51  *     element [0] is bits 23:16 of the FC Address Identifier
52  *     element [1] is bits 15:8 of the FC Address Identifier
53  *     element [2] is bits 7:0 of the FC Address Identifier
54  */
55 
56 
57 /*
58  * FC Host Messages
59  */
60 
61 /* FC_BSG_HST_ADDR_PORT : */
62 
63 /* Request:
64  * This message requests the FC host to login to the remote port
65  * at the specified N_Port_Id.  The remote port is to be enumerated
66  * with the transport upon completion of the login.
67  */
68 struct fc_bsg_host_add_rport {
69 	uint8_t		reserved;
70 
71 	/* FC Address Identier of the remote port to login to */
72 	uint8_t		port_id[3];
73 };
74 
75 /* Response:
76  * There is no additional response data - fc_bsg_reply->result is sufficient
77  */
78 
79 
80 /* FC_BSG_HST_DEL_RPORT : */
81 
82 /* Request:
83  * This message requests the FC host to remove an enumerated
84  * remote port and to terminate the login to it.
85  *
86  * Note: The driver is free to reject this request if it desires to
87  * remain logged in with the remote port.
88  */
89 struct fc_bsg_host_del_rport {
90 	uint8_t		reserved;
91 
92 	/* FC Address Identier of the remote port to logout of */
93 	uint8_t		port_id[3];
94 };
95 
96 /* Response:
97  * There is no additional response data - fc_bsg_reply->result is sufficient
98  */
99 
100 
101 /* FC_BSG_HST_ELS_NOLOGIN : */
102 
103 /* Request:
104  * This message requests the FC_Host to send an ELS to a specific
105  * N_Port_ID. The host does not need to log into the remote port,
106  * nor does it need to enumerate the rport for further traffic
107  * (although, the FC host is free to do so if it desires).
108  */
109 struct fc_bsg_host_els {
110 	/*
111 	 * ELS Command Code being sent (must be the same as byte 0
112 	 * of the payload)
113 	 */
114 	uint8_t 	command_code;
115 
116 	/* FC Address Identier of the remote port to send the ELS to */
117 	uint8_t		port_id[3];
118 };
119 
120 /* Response:
121  */
122 /* fc_bsg_ctels_reply->status values */
123 #define FC_CTELS_STATUS_OK	0x00000000
124 #define FC_CTELS_STATUS_REJECT	0x00000001
125 #define FC_CTELS_STATUS_P_RJT	0x00000002
126 #define FC_CTELS_STATUS_F_RJT	0x00000003
127 #define FC_CTELS_STATUS_P_BSY	0x00000004
128 #define FC_CTELS_STATUS_F_BSY	0x00000006
129 struct fc_bsg_ctels_reply {
130 	/*
131 	 * Note: An ELS LS_RJT may be reported in 2 ways:
132 	 *  a) A status of FC_CTELS_STATUS_OK is returned. The caller
133 	 *     is to look into the ELS receive payload to determine
134 	 *     LS_ACC or LS_RJT (by contents of word 0). The reject
135 	 *     data will be in word 1.
136 	 *  b) A status of FC_CTELS_STATUS_REJECT is returned, The
137 	 *     rjt_data field will contain valid data.
138 	 *
139 	 * Note: ELS LS_ACC is determined by an FC_CTELS_STATUS_OK, and
140 	 *   the receive payload word 0 indicates LS_ACC
141 	 *   (e.g. value is 0x02xxxxxx).
142 	 *
143 	 * Note: Similarly, a CT Reject may be reported in 2 ways:
144 	 *  a) A status of FC_CTELS_STATUS_OK is returned. The caller
145 	 *     is to look into the CT receive payload to determine
146 	 *     Accept or Reject (by contents of word 2). The reject
147 	 *     data will be in word 3.
148 	 *  b) A status of FC_CTELS_STATUS_REJECT is returned, The
149 	 *     rjt_data field will contain valid data.
150 	 *
151 	 * Note: x_RJT/BSY status will indicae that the rjt_data field
152 	 *   is valid and contains the reason/explanation values.
153 	 */
154 	uint32_t	status;		/* See FC_CTELS_STATUS_xxx */
155 
156 	/* valid if status is not FC_CTELS_STATUS_OK */
157 	struct	{
158 		uint8_t	action;		/* fragment_id for CT REJECT */
159 		uint8_t	reason_code;
160 		uint8_t	reason_explanation;
161 		uint8_t	vendor_unique;
162 	} rjt_data;
163 };
164 
165 
166 /* FC_BSG_HST_CT : */
167 
168 /* Request:
169  * This message requests that a CT Request be performed with the
170  * indicated N_Port_ID. The driver is responsible for logging in with
171  * the fabric and/or N_Port_ID, etc as per FC rules. This request does
172  * not mandate that the driver must enumerate the destination in the
173  * transport. The driver is allowed to decide whether to enumerate it,
174  * and whether to tear it down after the request.
175  */
176 struct fc_bsg_host_ct {
177 	uint8_t		reserved;
178 
179 	/* FC Address Identier of the remote port to send the ELS to */
180 	uint8_t		port_id[3];
181 
182 	/*
183 	 * We need words 0-2 of the generic preamble for the LLD's
184 	 */
185 	uint32_t	preamble_word0;	/* revision & IN_ID */
186 	uint32_t	preamble_word1;	/* GS_Type, GS_SubType, Options, Rsvd */
187 	uint32_t	preamble_word2;	/* Cmd Code, Max Size */
188 
189 };
190 /* Response:
191  *
192  * The reply structure is an fc_bsg_ctels_reply structure
193  */
194 
195 
196 /* FC_BSG_HST_VENDOR : */
197 
198 /* Request:
199  * Note: When specifying vendor_id, be sure to read the Vendor Type and ID
200  *   formatting requirements specified in scsi_netlink.h
201  */
202 struct fc_bsg_host_vendor {
203 	/*
204 	 * Identifies the vendor that the message is formatted for. This
205 	 * should be the recipient of the message.
206 	 */
207 	uint64_t vendor_id;
208 
209 	/* start of vendor command area */
210 	uint32_t vendor_cmd[0];
211 };
212 
213 /* Response:
214  */
215 struct fc_bsg_host_vendor_reply {
216 	/* start of vendor response area */
217 	uint32_t vendor_rsp[0];
218 };
219 
220 
221 
222 /*
223  * FC Remote Port Messages
224  */
225 
226 /* FC_BSG_RPT_ELS : */
227 
228 /* Request:
229  * This message requests that an ELS be performed with the rport.
230  */
231 struct fc_bsg_rport_els {
232 	/*
233 	 * ELS Command Code being sent (must be the same as
234 	 * byte 0 of the payload)
235 	 */
236 	uint8_t els_code;
237 };
238 
239 /* Response:
240  *
241  * The reply structure is an fc_bsg_ctels_reply structure
242  */
243 
244 
245 /* FC_BSG_RPT_CT : */
246 
247 /* Request:
248  * This message requests that a CT Request be performed with the rport.
249  */
250 struct fc_bsg_rport_ct {
251 	/*
252 	 * We need words 0-2 of the generic preamble for the LLD's
253 	 */
254 	uint32_t	preamble_word0;	/* revision & IN_ID */
255 	uint32_t	preamble_word1;	/* GS_Type, GS_SubType, Options, Rsvd */
256 	uint32_t	preamble_word2;	/* Cmd Code, Max Size */
257 };
258 /* Response:
259  *
260  * The reply structure is an fc_bsg_ctels_reply structure
261  */
262 
263 
264 
265 
266 /* request (CDB) structure of the sg_io_v4 */
267 struct fc_bsg_request {
268 	uint32_t msgcode;
269 	union {
270 		struct fc_bsg_host_add_rport	h_addrport;
271 		struct fc_bsg_host_del_rport	h_delrport;
272 		struct fc_bsg_host_els		h_els;
273 		struct fc_bsg_host_ct		h_ct;
274 		struct fc_bsg_host_vendor	h_vendor;
275 
276 		struct fc_bsg_rport_els		r_els;
277 		struct fc_bsg_rport_ct		r_ct;
278 	} rqst_data;
279 } __attribute__((packed));
280 
281 
282 /* response (request sense data) structure of the sg_io_v4 */
283 struct fc_bsg_reply {
284 	/*
285 	 * The completion result. Result exists in two forms:
286 	 *  if negative, it is an -Exxx system errno value. There will
287 	 *    be no further reply information supplied.
288 	 *  else, it's the 4-byte scsi error result, with driver, host,
289 	 *    msg and status fields. The per-msgcode reply structure
290 	 *    will contain valid data.
291 	 */
292 	uint32_t result;
293 
294 	/* If there was reply_payload, how much was recevied ? */
295 	uint32_t reply_payload_rcv_len;
296 
297 	union {
298 		struct fc_bsg_host_vendor_reply		vendor_reply;
299 
300 		struct fc_bsg_ctels_reply		ctels_reply;
301 	} reply_data;
302 };
303 
304 
305 #endif /* SCSI_BSG_FC_H */
306 
307