1 /*
2  * Copyright (c) 2016 Avago Technologies.  All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful.
9  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
10  * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
11  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO
12  * THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.
13  * See the GNU General Public License for more details, a copy of which
14  * can be found in the file COPYING included with this package
15  *
16  */
17 
18 /*
19  * This file contains definitions relative to FC-NVME r1.14 (16-020vB).
20  * The fcnvme_lsdesc_cr_assoc_cmd struct reflects expected r1.16 content.
21  */
22 
23 #ifndef _NVME_FC_H
24 #define _NVME_FC_H 1
25 
26 
27 #define NVME_CMD_SCSI_ID		0xFD
28 #define NVME_CMD_FC_ID			FC_TYPE_NVME
29 
30 /* FC-NVME Cmd IU Flags */
31 #define FCNVME_CMD_FLAGS_DIRMASK	0x03
32 #define FCNVME_CMD_FLAGS_WRITE		0x01
33 #define FCNVME_CMD_FLAGS_READ		0x02
34 
35 struct nvme_fc_cmd_iu {
36 	__u8			scsi_id;
37 	__u8			fc_id;
38 	__be16			iu_len;
39 	__u8			rsvd4[3];
40 	__u8			flags;
41 	__be64			connection_id;
42 	__be32			csn;
43 	__be32			data_len;
44 	struct nvme_command	sqe;
45 	__be32			rsvd88[2];
46 };
47 
48 #define NVME_FC_SIZEOF_ZEROS_RSP	12
49 
50 enum {
51 	FCNVME_SC_SUCCESS		= 0,
52 	FCNVME_SC_INVALID_FIELD		= 1,
53 	FCNVME_SC_INVALID_CONNID	= 2,
54 };
55 
56 struct nvme_fc_ersp_iu {
57 	__u8			status_code;
58 	__u8			rsvd1;
59 	__be16			iu_len;
60 	__be32			rsn;
61 	__be32			xfrd_len;
62 	__be32			rsvd12;
63 	struct nvme_completion	cqe;
64 	/* for now - no additional payload */
65 };
66 
67 
68 /* FC-NVME Link Services */
69 enum {
70 	FCNVME_LS_RSVD			= 0,
71 	FCNVME_LS_RJT			= 1,
72 	FCNVME_LS_ACC			= 2,
73 	FCNVME_LS_CREATE_ASSOCIATION	= 3,
74 	FCNVME_LS_CREATE_CONNECTION	= 4,
75 	FCNVME_LS_DISCONNECT		= 5,
76 };
77 
78 /* FC-NVME Link Service Descriptors */
79 enum {
80 	FCNVME_LSDESC_RSVD		= 0x0,
81 	FCNVME_LSDESC_RQST		= 0x1,
82 	FCNVME_LSDESC_RJT		= 0x2,
83 	FCNVME_LSDESC_CREATE_ASSOC_CMD	= 0x3,
84 	FCNVME_LSDESC_CREATE_CONN_CMD	= 0x4,
85 	FCNVME_LSDESC_DISCONN_CMD	= 0x5,
86 	FCNVME_LSDESC_CONN_ID		= 0x6,
87 	FCNVME_LSDESC_ASSOC_ID		= 0x7,
88 };
89 
90 
91 /* ********** start of Link Service Descriptors ********** */
92 
93 
94 /*
95  * fills in length of a descriptor. Struture minus descriptor header
96  */
fcnvme_lsdesc_len(size_t sz)97 static inline __be32 fcnvme_lsdesc_len(size_t sz)
98 {
99 	return cpu_to_be32(sz - (2 * sizeof(u32)));
100 }
101 
102 struct fcnvme_ls_rqst_w0 {
103 	u8	ls_cmd;			/* FCNVME_LS_xxx */
104 	u8	zeros[3];
105 };
106 
107 /* FCNVME_LSDESC_RQST */
108 struct fcnvme_lsdesc_rqst {
109 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
110 	__be32	desc_len;
111 	struct fcnvme_ls_rqst_w0	w0;
112 	__be32	rsvd12;
113 };
114 
115 /* FC-NVME LS RJT reason_code values */
116 enum fcnvme_ls_rjt_reason {
117 	FCNVME_RJT_RC_NONE		= 0,
118 	/* no reason - not to be sent */
119 
120 	FCNVME_RJT_RC_INVAL		= 0x01,
121 	/* invalid NVMe_LS command code */
122 
123 	FCNVME_RJT_RC_LOGIC		= 0x03,
124 	/* logical error */
125 
126 	FCNVME_RJT_RC_UNAB		= 0x09,
127 	/* unable to perform command request */
128 
129 	FCNVME_RJT_RC_UNSUP		= 0x0b,
130 	/* command not supported */
131 
132 	FCNVME_RJT_RC_INPROG		= 0x0e,
133 	/* command already in progress */
134 
135 	FCNVME_RJT_RC_INV_ASSOC		= 0x40,
136 	/* Invalid Association ID*/
137 
138 	FCNVME_RJT_RC_INV_CONN		= 0x41,
139 	/* Invalid Connection ID*/
140 
141 	FCNVME_RJT_RC_VENDOR		= 0xff,
142 	/* vendor specific error */
143 };
144 
145 /* FC-NVME LS RJT reason_explanation values */
146 enum fcnvme_ls_rjt_explan {
147 	FCNVME_RJT_EXP_NONE		= 0x00,
148 	/* No additional explanation */
149 
150 	FCNVME_RJT_EXP_OXID_RXID	= 0x17,
151 	/* invalid OX_ID-RX_ID combination */
152 
153 	FCNVME_RJT_EXP_INSUF_RES	= 0x29,
154 	/* insufficient resources */
155 
156 	FCNVME_RJT_EXP_UNAB_DATA	= 0x2a,
157 	/* unable to supply requested data */
158 
159 	FCNVME_RJT_EXP_INV_LEN		= 0x2d,
160 	/* Invalid payload length */
161 };
162 
163 /* FCNVME_LSDESC_RJT */
164 struct fcnvme_lsdesc_rjt {
165 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
166 	__be32	desc_len;
167 	u8	rsvd8;
168 
169 	/*
170 	 * Reject reason and explanaction codes are generic
171 	 * to ELs's from LS-3.
172 	 */
173 	u8	reason_code;		/* fcnvme_ls_rjt_reason */
174 	u8	reason_explanation;	/* fcnvme_ls_rjt_explan */
175 
176 	u8	vendor;
177 	__be32	rsvd12;
178 };
179 
180 
181 #define FCNVME_ASSOC_HOSTNQN_LEN	256
182 #define FCNVME_ASSOC_SUBNQN_LEN		256
183 
184 /* FCNVME_LSDESC_CREATE_ASSOC_CMD */
185 struct fcnvme_lsdesc_cr_assoc_cmd {
186 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
187 	__be32	desc_len;
188 	__be16	ersp_ratio;
189 	__be16	rsvd10;
190 	__be32	rsvd12[9];
191 	__be16	cntlid;
192 	__be16	sqsize;
193 	__be32	rsvd52;
194 	uuid_t	hostid;
195 	u8	hostnqn[FCNVME_ASSOC_HOSTNQN_LEN];
196 	u8	subnqn[FCNVME_ASSOC_SUBNQN_LEN];
197 	__be32	rsvd584[108];		/* pad to 1016 bytes,
198 					 * which makes overall LS rqst
199 					 * payload 1024 bytes
200 					 */
201 };
202 
203 #define FCNVME_LSDESC_CRA_CMD_DESC_MINLEN	\
204 		offsetof(struct fcnvme_lsdesc_cr_assoc_cmd, rsvd584)
205 
206 #define FCNVME_LSDESC_CRA_CMD_DESC_MIN_DESCLEN	\
207 		(FCNVME_LSDESC_CRA_CMD_DESC_MINLEN - \
208 		 offsetof(struct fcnvme_lsdesc_cr_assoc_cmd, ersp_ratio))
209 
210 
211 
212 /* FCNVME_LSDESC_CREATE_CONN_CMD */
213 struct fcnvme_lsdesc_cr_conn_cmd {
214 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
215 	__be32	desc_len;
216 	__be16	ersp_ratio;
217 	__be16	rsvd10;
218 	__be32	rsvd12[9];
219 	__be16	qid;
220 	__be16	sqsize;
221 	__be32  rsvd52;
222 };
223 
224 /* Disconnect Scope Values */
225 enum {
226 	FCNVME_DISCONN_ASSOCIATION	= 0,
227 	FCNVME_DISCONN_CONNECTION	= 1,
228 };
229 
230 /* FCNVME_LSDESC_DISCONN_CMD */
231 struct fcnvme_lsdesc_disconn_cmd {
232 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
233 	__be32	desc_len;
234 	u8	rsvd8[3];
235 	/* note: scope is really a 1 bit field */
236 	u8	scope;			/* FCNVME_DISCONN_xxx */
237 	__be32	rsvd12;
238 	__be64	id;
239 };
240 
241 /* FCNVME_LSDESC_CONN_ID */
242 struct fcnvme_lsdesc_conn_id {
243 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
244 	__be32	desc_len;
245 	__be64	connection_id;
246 };
247 
248 /* FCNVME_LSDESC_ASSOC_ID */
249 struct fcnvme_lsdesc_assoc_id {
250 	__be32	desc_tag;		/* FCNVME_LSDESC_xxx */
251 	__be32	desc_len;
252 	__be64	association_id;
253 };
254 
255 /* r_ctl values */
256 enum {
257 	FCNVME_RS_RCTL_DATA		= 1,
258 	FCNVME_RS_RCTL_XFER_RDY		= 5,
259 	FCNVME_RS_RCTL_RSP		= 8,
260 };
261 
262 
263 /* ********** start of Link Services ********** */
264 
265 
266 /* FCNVME_LS_RJT */
267 struct fcnvme_ls_rjt {
268 	struct fcnvme_ls_rqst_w0		w0;
269 	__be32					desc_list_len;
270 	struct fcnvme_lsdesc_rqst		rqst;
271 	struct fcnvme_lsdesc_rjt		rjt;
272 };
273 
274 /* FCNVME_LS_ACC */
275 struct fcnvme_ls_acc_hdr {
276 	struct fcnvme_ls_rqst_w0		w0;
277 	__be32					desc_list_len;
278 	struct fcnvme_lsdesc_rqst		rqst;
279 	/* Followed by cmd-specific ACC descriptors, see next definitions */
280 };
281 
282 /* FCNVME_LS_CREATE_ASSOCIATION */
283 struct fcnvme_ls_cr_assoc_rqst {
284 	struct fcnvme_ls_rqst_w0		w0;
285 	__be32					desc_list_len;
286 	struct fcnvme_lsdesc_cr_assoc_cmd	assoc_cmd;
287 };
288 
289 #define FCNVME_LSDESC_CRA_RQST_MINLEN	\
290 		(offsetof(struct fcnvme_ls_cr_assoc_rqst, assoc_cmd) + \
291 			FCNVME_LSDESC_CRA_CMD_DESC_MINLEN)
292 
293 #define FCNVME_LSDESC_CRA_RQST_MIN_LISTLEN	\
294 		FCNVME_LSDESC_CRA_CMD_DESC_MINLEN
295 
296 
297 struct fcnvme_ls_cr_assoc_acc {
298 	struct fcnvme_ls_acc_hdr		hdr;
299 	struct fcnvme_lsdesc_assoc_id		associd;
300 	struct fcnvme_lsdesc_conn_id		connectid;
301 };
302 
303 
304 /* FCNVME_LS_CREATE_CONNECTION */
305 struct fcnvme_ls_cr_conn_rqst {
306 	struct fcnvme_ls_rqst_w0		w0;
307 	__be32					desc_list_len;
308 	struct fcnvme_lsdesc_assoc_id		associd;
309 	struct fcnvme_lsdesc_cr_conn_cmd	connect_cmd;
310 };
311 
312 struct fcnvme_ls_cr_conn_acc {
313 	struct fcnvme_ls_acc_hdr		hdr;
314 	struct fcnvme_lsdesc_conn_id		connectid;
315 };
316 
317 /* FCNVME_LS_DISCONNECT */
318 struct fcnvme_ls_disconnect_rqst {
319 	struct fcnvme_ls_rqst_w0		w0;
320 	__be32					desc_list_len;
321 	struct fcnvme_lsdesc_assoc_id		associd;
322 	struct fcnvme_lsdesc_disconn_cmd	discon_cmd;
323 };
324 
325 struct fcnvme_ls_disconnect_acc {
326 	struct fcnvme_ls_acc_hdr		hdr;
327 };
328 
329 
330 /*
331  * Yet to be defined in FC-NVME:
332  */
333 #define NVME_FC_CONNECT_TIMEOUT_SEC	2		/* 2 seconds */
334 #define NVME_FC_LS_TIMEOUT_SEC		2		/* 2 seconds */
335 #define NVME_FC_TGTOP_TIMEOUT_SEC	2		/* 2 seconds */
336 
337 /*
338  * TRADDR string must be of form "nn-<16hexdigits>:pn-<16hexdigits>"
339  * the string is allowed to be specified with or without a "0x" prefix
340  * infront of the <16hexdigits>.  Without is considered the "min" string
341  * and with is considered the "max" string. The hexdigits may be upper
342  * or lower case.
343  */
344 #define NVME_FC_TRADDR_NNLEN		3	/* "?n-" */
345 #define NVME_FC_TRADDR_OXNNLEN		5	/* "?n-0x" */
346 #define NVME_FC_TRADDR_HEXNAMELEN	16
347 #define NVME_FC_TRADDR_MINLENGTH	\
348 		(2 * (NVME_FC_TRADDR_NNLEN + NVME_FC_TRADDR_HEXNAMELEN) + 1)
349 #define NVME_FC_TRADDR_MAXLENGTH	\
350 		(2 * (NVME_FC_TRADDR_OXNNLEN + NVME_FC_TRADDR_HEXNAMELEN) + 1)
351 #define NVME_FC_TRADDR_MIN_PN_OFFSET	\
352 		(NVME_FC_TRADDR_NNLEN + NVME_FC_TRADDR_HEXNAMELEN + 1)
353 #define NVME_FC_TRADDR_MAX_PN_OFFSET	\
354 		(NVME_FC_TRADDR_OXNNLEN + NVME_FC_TRADDR_HEXNAMELEN + 1)
355 
356 
357 #endif /* _NVME_FC_H */
358