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