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