xref: /linux/include/linux/nvme-fc.h (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2016 Avago Technologies.  All rights reserved.
4  */
5 
6 /*
7  * This file contains definitions relative to FC-NVME-2 r1.08
8  * (T11-2019-00210-v004).
9  */
10 
11 #ifndef _NVME_FC_H
12 #define _NVME_FC_H 1
13 
14 #include <uapi/scsi/fc/fc_fs.h>
15 
16 #define NVME_CMD_FORMAT_ID		0xFD
17 #define NVME_CMD_FC_ID			FC_TYPE_NVME
18 
19 /* FC-NVME Cmd IU Flags */
20 enum {
21 	FCNVME_CMD_FLAGS_DIRMASK	= 0x03,
22 	FCNVME_CMD_FLAGS_WRITE		= (1 << 0),
23 	FCNVME_CMD_FLAGS_READ		= (1 << 1),
24 
25 	FCNVME_CMD_FLAGS_PICWP		= (1 << 2),
26 };
27 
28 enum {
29 	FCNVME_CMD_CAT_MASK		= 0x0F,
30 	FCNVME_CMD_CAT_ADMINQ		= 0x01,
31 	FCNVME_CMD_CAT_CSSMASK		= 0x07,
32 	FCNVME_CMD_CAT_CSSFLAG		= 0x08,
33 };
34 
fccmnd_set_cat_admin(__u8 rsv_cat)35 static inline __u8 fccmnd_set_cat_admin(__u8 rsv_cat)
36 {
37 	return (rsv_cat & ~FCNVME_CMD_CAT_MASK) | FCNVME_CMD_CAT_ADMINQ;
38 }
39 
fccmnd_set_cat_css(__u8 rsv_cat,__u8 css)40 static inline __u8 fccmnd_set_cat_css(__u8 rsv_cat, __u8 css)
41 {
42 	return (rsv_cat & ~FCNVME_CMD_CAT_MASK) | FCNVME_CMD_CAT_CSSFLAG |
43 		(css & FCNVME_CMD_CAT_CSSMASK);
44 }
45 
46 struct nvme_fc_cmd_iu {
47 	__u8			format_id;
48 	__u8			fc_id;
49 	__be16			iu_len;
50 	__u8			rsvd4[2];
51 	__u8			rsv_cat;
52 	__u8			flags;
53 	__be64			connection_id;
54 	__be32			csn;
55 	__be32			data_len;
56 	struct nvme_command	sqe;
57 	__u8			dps;
58 	__u8			lbads;
59 	__be16			ms;
60 	__be32			rsvd92;
61 };
62 
63 #define NVME_FC_SIZEOF_ZEROS_RSP	12
64 
65 enum {
66 	FCNVME_SC_SUCCESS		= 0,
67 	FCNVME_SC_INVALID_FIELD		= 1,
68 	/* reserved			  2 */
69 	FCNVME_SC_ILL_CONN_PARAMS	= 3,
70 };
71 
72 struct nvme_fc_ersp_iu {
73 	__u8			ersp_result;
74 	__u8			rsvd1;
75 	__be16			iu_len;
76 	__be32			rsn;
77 	__be32			xfrd_len;
78 	__be32			rsvd12;
79 	struct nvme_completion	cqe;
80 	/* for now - no additional payload */
81 };
82 
83 
84 #define FCNVME_NVME_SR_OPCODE		0x01
85 #define FCNVME_NVME_SR_RSP_OPCODE	0x02
86 
87 struct nvme_fc_nvme_sr_iu {
88 	__u8			fc_id;
89 	__u8			opcode;
90 	__u8			rsvd2;
91 	__u8			retry_rctl;
92 	__be32			rsvd4;
93 };
94 
95 
96 enum {
97 	FCNVME_SRSTAT_ACC		= 0x0,
98 	/* reserved			  0x1 */
99 	/* reserved			  0x2 */
100 	FCNVME_SRSTAT_LOGICAL_ERR	= 0x3,
101 	FCNVME_SRSTAT_INV_QUALIF	= 0x4,
102 	FCNVME_SRSTAT_UNABL2PERFORM	= 0x9,
103 };
104 
105 struct nvme_fc_nvme_sr_rsp_iu {
106 	__u8			fc_id;
107 	__u8			opcode;
108 	__u8			rsvd2;
109 	__u8			status;
110 	__be32			rsvd4;
111 };
112 
113 
114 /* FC-NVME Link Services - LS cmd values (w0 bits 31:24) */
115 enum {
116 	FCNVME_LS_RSVD			= 0,
117 	FCNVME_LS_RJT			= 1,
118 	FCNVME_LS_ACC			= 2,
119 	FCNVME_LS_CREATE_ASSOCIATION	= 3,	/* Create Association */
120 	FCNVME_LS_CREATE_CONNECTION	= 4,	/* Create I/O Connection */
121 	FCNVME_LS_DISCONNECT_ASSOC	= 5,	/* Disconnect Association */
122 	FCNVME_LS_DISCONNECT_CONN	= 6,	/* Disconnect Connection */
123 };
124 
125 /* FC-NVME Link Service Descriptors */
126 enum {
127 	FCNVME_LSDESC_RSVD		= 0x0,
128 	FCNVME_LSDESC_RQST		= 0x1,
129 	FCNVME_LSDESC_RJT		= 0x2,
130 	FCNVME_LSDESC_CREATE_ASSOC_CMD	= 0x3,
131 	FCNVME_LSDESC_CREATE_CONN_CMD	= 0x4,
132 	FCNVME_LSDESC_DISCONN_CMD	= 0x5,
133 	FCNVME_LSDESC_CONN_ID		= 0x6,
134 	FCNVME_LSDESC_ASSOC_ID		= 0x7,
135 };
136 
137 
138 /* ********** start of Link Service Descriptors ********** */
139 
140 
141 /*
142  * fills in length of a descriptor. Struture minus descriptor header
143  */
fcnvme_lsdesc_len(size_t sz)144 static inline __be32 fcnvme_lsdesc_len(size_t sz)
145 {
146 	return cpu_to_be32(sz - (2 * sizeof(u32)));
147 }
148 
149 struct fcnvme_ls_rqst_w0 {
150 	u8	ls_cmd;			/* FCNVME_LS_xxx */
151 	u8	zeros[3];
152 };
153 
154 /* FCNVME_LSDESC_RQST */
155 struct fcnvme_lsdesc_rqst {
156 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
157 	__be32	desc_len;
158 	struct fcnvme_ls_rqst_w0	w0;
159 	__be32	rsvd12;
160 };
161 
162 /* FC-NVME LS RJT reason_code values */
163 enum fcnvme_ls_rjt_reason {
164 	FCNVME_RJT_RC_NONE		= 0,
165 	/* no reason - not to be sent */
166 
167 	FCNVME_RJT_RC_INVAL		= 0x01,
168 	/* invalid NVMe_LS command code */
169 
170 	FCNVME_RJT_RC_LOGIC		= 0x03,
171 	/* logical error */
172 
173 	FCNVME_RJT_RC_UNAB		= 0x09,
174 	/* unable to perform command request */
175 
176 	FCNVME_RJT_RC_UNSUP		= 0x0b,
177 	/* command not supported */
178 
179 	FCNVME_RJT_RC_INV_ASSOC		= 0x40,
180 	/* Invalid Association ID */
181 
182 	FCNVME_RJT_RC_INV_CONN		= 0x41,
183 	/* Invalid Connection ID */
184 
185 	FCNVME_RJT_RC_INV_PARAM		= 0x42,
186 	/* Invalid Parameters */
187 
188 	FCNVME_RJT_RC_INSUF_RES		= 0x43,
189 	/* Insufficient Resources */
190 
191 	FCNVME_RJT_RC_VENDOR		= 0xff,
192 	/* vendor specific error */
193 };
194 
195 /* FC-NVME LS RJT reason_explanation values */
196 enum fcnvme_ls_rjt_explan {
197 	FCNVME_RJT_EXP_NONE		= 0x00,
198 	/* No additional explanation */
199 
200 	FCNVME_RJT_EXP_OXID_RXID	= 0x17,
201 	/* invalid OX_ID-RX_ID combination */
202 
203 	FCNVME_RJT_EXP_UNAB_DATA	= 0x2a,
204 	/* unable to supply requested data */
205 
206 	FCNVME_RJT_EXP_INV_LEN		= 0x2d,
207 	/* Invalid payload length */
208 
209 	FCNVME_RJT_EXP_INV_ERSP_RAT	= 0x40,
210 	/* Invalid NVMe_ERSP Ratio */
211 
212 	FCNVME_RJT_EXP_INV_CTLR_ID	= 0x41,
213 	/* Invalid Controller ID */
214 
215 	FCNVME_RJT_EXP_INV_QUEUE_ID	= 0x42,
216 	/* Invalid Queue ID */
217 
218 	FCNVME_RJT_EXP_INV_SQSIZE	= 0x43,
219 	/* Invalid Submission Queue Size */
220 
221 	FCNVME_RJT_EXP_INV_HOSTID	= 0x44,
222 	/* Invalid HOST ID */
223 
224 	FCNVME_RJT_EXP_INV_HOSTNQN	= 0x45,
225 	/* Invalid HOSTNQN */
226 
227 	FCNVME_RJT_EXP_INV_SUBNQN	= 0x46,
228 	/* Invalid SUBNQN */
229 };
230 
231 /* FCNVME_LSDESC_RJT */
232 struct fcnvme_lsdesc_rjt {
233 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
234 	__be32	desc_len;
235 	u8	rsvd8;
236 
237 	/*
238 	 * Reject reason and explanaction codes are generic
239 	 * to ELs's from LS-3.
240 	 */
241 	u8	reason_code;		/* fcnvme_ls_rjt_reason */
242 	u8	reason_explanation;	/* fcnvme_ls_rjt_explan */
243 
244 	u8	vendor;
245 	__be32	rsvd12;
246 };
247 
248 
249 #define FCNVME_ASSOC_HOSTNQN_LEN	256
250 #define FCNVME_ASSOC_SUBNQN_LEN		256
251 
252 /* FCNVME_LSDESC_CREATE_ASSOC_CMD */
253 struct fcnvme_lsdesc_cr_assoc_cmd {
254 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
255 	__be32	desc_len;
256 	__be16	ersp_ratio;
257 	__be16	rsvd10;
258 	__be32	rsvd12[9];
259 	__be16	cntlid;
260 	__be16	sqsize;
261 	__be32	rsvd52;
262 	uuid_t	hostid;
263 	u8	hostnqn[FCNVME_ASSOC_HOSTNQN_LEN];
264 	u8	subnqn[FCNVME_ASSOC_SUBNQN_LEN];
265 	__be32	rsvd584[108];		/* pad to 1016 bytes,
266 					 * which makes overall LS rqst
267 					 * payload 1024 bytes
268 					 */
269 };
270 
271 #define FCNVME_LSDESC_CRA_CMD_DESC_MINLEN	\
272 		offsetof(struct fcnvme_lsdesc_cr_assoc_cmd, rsvd584)
273 
274 #define FCNVME_LSDESC_CRA_CMD_DESC_MIN_DESCLEN	\
275 		(FCNVME_LSDESC_CRA_CMD_DESC_MINLEN - \
276 		 offsetof(struct fcnvme_lsdesc_cr_assoc_cmd, ersp_ratio))
277 
278 
279 
280 /* FCNVME_LSDESC_CREATE_CONN_CMD */
281 struct fcnvme_lsdesc_cr_conn_cmd {
282 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
283 	__be32	desc_len;
284 	__be16	ersp_ratio;
285 	__be16	rsvd10;
286 	__be32	rsvd12[9];
287 	__be16	qid;
288 	__be16	sqsize;
289 	__be32  rsvd52;
290 };
291 
292 /* FCNVME_LSDESC_DISCONN_CMD */
293 struct fcnvme_lsdesc_disconn_cmd {
294 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
295 	__be32	desc_len;
296 	__be32	rsvd8[4];
297 };
298 
299 /* FCNVME_LSDESC_CONN_ID */
300 struct fcnvme_lsdesc_conn_id {
301 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
302 	__be32	desc_len;
303 	__be64	connection_id;
304 };
305 
306 /* FCNVME_LSDESC_ASSOC_ID */
307 struct fcnvme_lsdesc_assoc_id {
308 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
309 	__be32	desc_len;
310 	__be64	association_id;
311 };
312 
313 /* r_ctl values */
314 enum {
315 	FCNVME_RS_RCTL_CMND		= 0x6,
316 	FCNVME_RS_RCTL_DATA		= 0x1,
317 	FCNVME_RS_RCTL_CONF		= 0x3,
318 	FCNVME_RS_RCTL_SR		= 0x9,
319 	FCNVME_RS_RCTL_XFER_RDY		= 0x5,
320 	FCNVME_RS_RCTL_RSP		= 0x7,
321 	FCNVME_RS_RCTL_ERSP		= 0x8,
322 	FCNVME_RS_RCTL_SR_RSP		= 0xA,
323 };
324 
325 
326 /* ********** start of Link Services ********** */
327 
328 
329 /* FCNVME_LS_RJT */
330 struct fcnvme_ls_rjt {
331 	struct fcnvme_ls_rqst_w0		w0;
332 	__be32					desc_list_len;
333 	struct fcnvme_lsdesc_rqst		rqst;
334 	struct fcnvme_lsdesc_rjt		rjt;
335 };
336 
337 /* FCNVME_LS_ACC */
338 struct fcnvme_ls_acc_hdr {
339 	struct fcnvme_ls_rqst_w0		w0;
340 	__be32					desc_list_len;
341 	struct fcnvme_lsdesc_rqst		rqst;
342 	/*
343 	 * Followed by cmd-specific ACCEPT descriptors, see xxx_acc
344 	 * definitions below
345 	 */
346 };
347 
348 /* FCNVME_LS_CREATE_ASSOCIATION */
349 struct fcnvme_ls_cr_assoc_rqst {
350 	struct fcnvme_ls_rqst_w0		w0;
351 	__be32					desc_list_len;
352 	struct fcnvme_lsdesc_cr_assoc_cmd	assoc_cmd;
353 };
354 
355 #define FCNVME_LSDESC_CRA_RQST_MINLEN	\
356 		(offsetof(struct fcnvme_ls_cr_assoc_rqst, assoc_cmd) + \
357 			FCNVME_LSDESC_CRA_CMD_DESC_MINLEN)
358 
359 #define FCNVME_LSDESC_CRA_RQST_MIN_LISTLEN	\
360 		FCNVME_LSDESC_CRA_CMD_DESC_MINLEN
361 
362 
363 struct fcnvme_ls_cr_assoc_acc {
364 	struct fcnvme_ls_acc_hdr		hdr;
365 	struct fcnvme_lsdesc_assoc_id		associd;
366 	struct fcnvme_lsdesc_conn_id		connectid;
367 };
368 
369 
370 /* FCNVME_LS_CREATE_CONNECTION */
371 struct fcnvme_ls_cr_conn_rqst {
372 	struct fcnvme_ls_rqst_w0		w0;
373 	__be32					desc_list_len;
374 	struct fcnvme_lsdesc_assoc_id		associd;
375 	struct fcnvme_lsdesc_cr_conn_cmd	connect_cmd;
376 };
377 
378 struct fcnvme_ls_cr_conn_acc {
379 	struct fcnvme_ls_acc_hdr		hdr;
380 	struct fcnvme_lsdesc_conn_id		connectid;
381 };
382 
383 /* FCNVME_LS_DISCONNECT_ASSOC */
384 struct fcnvme_ls_disconnect_assoc_rqst {
385 	struct fcnvme_ls_rqst_w0		w0;
386 	__be32					desc_list_len;
387 	struct fcnvme_lsdesc_assoc_id		associd;
388 	struct fcnvme_lsdesc_disconn_cmd	discon_cmd;
389 };
390 
391 struct fcnvme_ls_disconnect_assoc_acc {
392 	struct fcnvme_ls_acc_hdr		hdr;
393 };
394 
395 
396 /* FCNVME_LS_DISCONNECT_CONN */
397 struct fcnvme_ls_disconnect_conn_rqst {
398 	struct fcnvme_ls_rqst_w0		w0;
399 	__be32					desc_list_len;
400 	struct fcnvme_lsdesc_assoc_id		associd;
401 	struct fcnvme_lsdesc_conn_id		connectid;
402 };
403 
404 struct fcnvme_ls_disconnect_conn_acc {
405 	struct fcnvme_ls_acc_hdr		hdr;
406 };
407 
408 
409 /*
410  * Default R_A_TOV is pulled in from fc_fs.h but needs conversion
411  * from ms to seconds for our use.
412  */
413 #define FC_TWO_TIMES_R_A_TOV		(2 * (FC_DEF_R_A_TOV / 1000))
414 #define NVME_FC_LS_TIMEOUT_SEC		FC_TWO_TIMES_R_A_TOV
415 #define NVME_FC_TGTOP_TIMEOUT_SEC	FC_TWO_TIMES_R_A_TOV
416 
417 /*
418  * TRADDR string must be of form "nn-<16hexdigits>:pn-<16hexdigits>"
419  * the string is allowed to be specified with or without a "0x" prefix
420  * infront of the <16hexdigits>.  Without is considered the "min" string
421  * and with is considered the "max" string. The hexdigits may be upper
422  * or lower case.
423  * Note: FC-NVME-2 standard requires a "0x" prefix.
424  */
425 #define NVME_FC_TRADDR_NNLEN		3	/* "?n-" */
426 #define NVME_FC_TRADDR_OXNNLEN		5	/* "?n-0x" */
427 #define NVME_FC_TRADDR_HEXNAMELEN	16
428 #define NVME_FC_TRADDR_MINLENGTH	\
429 		(2 * (NVME_FC_TRADDR_NNLEN + NVME_FC_TRADDR_HEXNAMELEN) + 1)
430 #define NVME_FC_TRADDR_MAXLENGTH	\
431 		(2 * (NVME_FC_TRADDR_OXNNLEN + NVME_FC_TRADDR_HEXNAMELEN) + 1)
432 #define NVME_FC_TRADDR_MIN_PN_OFFSET	\
433 		(NVME_FC_TRADDR_NNLEN + NVME_FC_TRADDR_HEXNAMELEN + 1)
434 #define NVME_FC_TRADDR_MAX_PN_OFFSET	\
435 		(NVME_FC_TRADDR_OXNNLEN + NVME_FC_TRADDR_HEXNAMELEN + 1)
436 
437 
438 #endif /* _NVME_FC_H */
439