blob: e8c30b39bb27f72ac73a3ed0dc6d3aad46cfbe86 [file] [log] [blame]
Christoph Hellwig8638b242019-02-18 09:33:28 +01001/* SPDX-License-Identifier: GPL-2.0 */
James Smartb1ad14752016-12-02 00:28:40 -08002/*
3 * Copyright (c) 2016 Avago Technologies. All rights reserved.
James Smartb1ad14752016-12-02 00:28:40 -08004 */
5
6/*
James Smartf1658362019-09-27 14:51:34 -07007 * This file contains definitions relative to FC-NVME-2 r1.06
8 * (T11-2019-00210-v001).
James Smartb1ad14752016-12-02 00:28:40 -08009 */
10
11#ifndef _NVME_FC_H
12#define _NVME_FC_H 1
13
James Smartf1658362019-09-27 14:51:34 -070014#include <uapi/scsi/fc/fc_fs.h>
James Smartb1ad14752016-12-02 00:28:40 -080015
James Smartf1658362019-09-27 14:51:34 -070016#define NVME_CMD_FORMAT_ID 0xFD
James Smartb1ad14752016-12-02 00:28:40 -080017#define NVME_CMD_FC_ID FC_TYPE_NVME
18
19/* FC-NVME Cmd IU Flags */
James Smartf1658362019-09-27 14:51:34 -070020enum {
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
28enum {
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
35static inline __u8 fccmnd_set_cat_admin(__u8 rsv_cat)
36{
37 return (rsv_cat & ~FCNVME_CMD_CAT_MASK) | FCNVME_CMD_CAT_ADMINQ;
38}
39
40static 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}
James Smartb1ad14752016-12-02 00:28:40 -080045
46struct nvme_fc_cmd_iu {
James Smartf1658362019-09-27 14:51:34 -070047 __u8 format_id;
James Smartb1ad14752016-12-02 00:28:40 -080048 __u8 fc_id;
49 __be16 iu_len;
James Smartf1658362019-09-27 14:51:34 -070050 __u8 rsvd4[2];
51 __u8 rsv_cat;
James Smartb1ad14752016-12-02 00:28:40 -080052 __u8 flags;
53 __be64 connection_id;
54 __be32 csn;
55 __be32 data_len;
56 struct nvme_command sqe;
James Smartf1658362019-09-27 14:51:34 -070057 __u8 dps;
58 __u8 lbads;
59 __be16 ms;
60 __be32 rsvd92;
James Smartb1ad14752016-12-02 00:28:40 -080061};
62
63#define NVME_FC_SIZEOF_ZEROS_RSP 12
64
James Smart0f222cc2017-03-23 20:41:22 -070065enum {
66 FCNVME_SC_SUCCESS = 0,
67 FCNVME_SC_INVALID_FIELD = 1,
James Smartf1658362019-09-27 14:51:34 -070068 /* reserved 2 */
69 FCNVME_SC_ILL_CONN_PARAMS = 3,
James Smart0f222cc2017-03-23 20:41:22 -070070};
71
James Smartb1ad14752016-12-02 00:28:40 -080072struct nvme_fc_ersp_iu {
James Smartf1658362019-09-27 14:51:34 -070073 __u8 ersp_result;
James Smart0f222cc2017-03-23 20:41:22 -070074 __u8 rsvd1;
James Smartb1ad14752016-12-02 00:28:40 -080075 __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
James Smartf1658362019-09-27 14:51:34 -070084#define FCNVME_NVME_SR_OPCODE 0x01
85
86struct nvme_fc_nvme_sr_iu {
87 __u8 fc_id;
88 __u8 opcode;
89 __u8 rsvd2;
90 __u8 retry_rctl;
91 __be32 rsvd4;
92};
93
94
95enum {
96 FCNVME_SRSTAT_ACC = 0x0,
97 FCNVME_SRSTAT_INV_FCID = 0x1,
98 /* reserved 0x2 */
99 FCNVME_SRSTAT_LOGICAL_ERR = 0x3,
100 FCNVME_SRSTAT_INV_QUALIF = 0x4,
101 FCNVME_SRSTAT_UNABL2PERFORM = 0x9,
102};
103
104struct nvme_fc_nvme_sr_rsp_iu {
105 __u8 fc_id;
106 __u8 opcode;
107 __u8 rsvd2;
108 __u8 status;
109 __be32 rsvd4;
110};
111
112
113/* FC-NVME Link Services - LS cmd values (w0 bits 31:24) */
James Smartb1ad14752016-12-02 00:28:40 -0800114enum {
115 FCNVME_LS_RSVD = 0,
116 FCNVME_LS_RJT = 1,
117 FCNVME_LS_ACC = 2,
James Smartf1658362019-09-27 14:51:34 -0700118 FCNVME_LS_CREATE_ASSOCIATION = 3, /* Create Association */
119 FCNVME_LS_CREATE_CONNECTION = 4, /* Create I/O Connection */
120 FCNVME_LS_DISCONNECT_ASSOC = 5, /* Disconnect Association */
121 FCNVME_LS_DISCONNECT_CONN = 6, /* Disconnect Connection */
James Smartb1ad14752016-12-02 00:28:40 -0800122};
123
James Smart0f222cc2017-03-23 20:41:22 -0700124/* FC-NVME Link Service Descriptors */
James Smartb1ad14752016-12-02 00:28:40 -0800125enum {
126 FCNVME_LSDESC_RSVD = 0x0,
127 FCNVME_LSDESC_RQST = 0x1,
128 FCNVME_LSDESC_RJT = 0x2,
129 FCNVME_LSDESC_CREATE_ASSOC_CMD = 0x3,
130 FCNVME_LSDESC_CREATE_CONN_CMD = 0x4,
131 FCNVME_LSDESC_DISCONN_CMD = 0x5,
132 FCNVME_LSDESC_CONN_ID = 0x6,
133 FCNVME_LSDESC_ASSOC_ID = 0x7,
134};
135
136
137/* ********** start of Link Service Descriptors ********** */
138
139
140/*
141 * fills in length of a descriptor. Struture minus descriptor header
142 */
143static inline __be32 fcnvme_lsdesc_len(size_t sz)
144{
145 return cpu_to_be32(sz - (2 * sizeof(u32)));
146}
147
James Smartb1ad14752016-12-02 00:28:40 -0800148struct fcnvme_ls_rqst_w0 {
149 u8 ls_cmd; /* FCNVME_LS_xxx */
150 u8 zeros[3];
151};
152
153/* FCNVME_LSDESC_RQST */
154struct fcnvme_lsdesc_rqst {
155 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
156 __be32 desc_len;
157 struct fcnvme_ls_rqst_w0 w0;
158 __be32 rsvd12;
159};
160
James Smart0f222cc2017-03-23 20:41:22 -0700161/* FC-NVME LS RJT reason_code values */
162enum fcnvme_ls_rjt_reason {
163 FCNVME_RJT_RC_NONE = 0,
164 /* no reason - not to be sent */
James Smartb1ad14752016-12-02 00:28:40 -0800165
James Smart0f222cc2017-03-23 20:41:22 -0700166 FCNVME_RJT_RC_INVAL = 0x01,
167 /* invalid NVMe_LS command code */
James Smartb1ad14752016-12-02 00:28:40 -0800168
James Smart0f222cc2017-03-23 20:41:22 -0700169 FCNVME_RJT_RC_LOGIC = 0x03,
170 /* logical error */
171
172 FCNVME_RJT_RC_UNAB = 0x09,
173 /* unable to perform command request */
174
175 FCNVME_RJT_RC_UNSUP = 0x0b,
176 /* command not supported */
177
James Smart0f222cc2017-03-23 20:41:22 -0700178 FCNVME_RJT_RC_INV_ASSOC = 0x40,
James Smartf1658362019-09-27 14:51:34 -0700179 /* Invalid Association ID */
James Smart0f222cc2017-03-23 20:41:22 -0700180
181 FCNVME_RJT_RC_INV_CONN = 0x41,
James Smartf1658362019-09-27 14:51:34 -0700182 /* Invalid Connection ID */
183
184 FCNVME_RJT_RC_INV_PARAM = 0x42,
185 /* Invalid Parameters */
186
187 FCNVME_RJT_RC_INSUF_RES = 0x43,
188 /* Insufficient Resources */
James Smart0f222cc2017-03-23 20:41:22 -0700189
190 FCNVME_RJT_RC_VENDOR = 0xff,
191 /* vendor specific error */
192};
193
194/* FC-NVME LS RJT reason_explanation values */
195enum fcnvme_ls_rjt_explan {
196 FCNVME_RJT_EXP_NONE = 0x00,
197 /* No additional explanation */
198
199 FCNVME_RJT_EXP_OXID_RXID = 0x17,
200 /* invalid OX_ID-RX_ID combination */
201
James Smart0f222cc2017-03-23 20:41:22 -0700202 FCNVME_RJT_EXP_UNAB_DATA = 0x2a,
203 /* unable to supply requested data */
204
205 FCNVME_RJT_EXP_INV_LEN = 0x2d,
206 /* Invalid payload length */
James Smartf1658362019-09-27 14:51:34 -0700207
208 FCNVME_RJT_EXP_INV_ERSP_RAT = 0x40,
209 /* Invalid NVMe_ERSP Ratio */
210
211 FCNVME_RJT_EXP_INV_CTLR_ID = 0x41,
212 /* Invalid Controller ID */
213
214 FCNVME_RJT_EXP_INV_QUEUE_ID = 0x42,
215 /* Invalid Queue ID */
216
217 FCNVME_RJT_EXP_INV_SQSIZE = 0x43,
218 /* Invalid Submission Queue Size */
219
220 FCNVME_RJT_EXP_INV_HOSTID = 0x44,
221 /* Invalid HOST ID */
222
223 FCNVME_RJT_EXP_INV_HOSTNQN = 0x45,
224 /* Invalid HOSTNQN */
225
226 FCNVME_RJT_EXP_INV_SUBNQN = 0x46,
227 /* Invalid SUBNQN */
James Smart0f222cc2017-03-23 20:41:22 -0700228};
James Smartb1ad14752016-12-02 00:28:40 -0800229
230/* FCNVME_LSDESC_RJT */
231struct fcnvme_lsdesc_rjt {
232 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
233 __be32 desc_len;
234 u8 rsvd8;
235
236 /*
237 * Reject reason and explanaction codes are generic
238 * to ELs's from LS-3.
239 */
James Smart0f222cc2017-03-23 20:41:22 -0700240 u8 reason_code; /* fcnvme_ls_rjt_reason */
241 u8 reason_explanation; /* fcnvme_ls_rjt_explan */
James Smartb1ad14752016-12-02 00:28:40 -0800242
243 u8 vendor;
244 __be32 rsvd12;
245};
246
247
James Smartb1ad14752016-12-02 00:28:40 -0800248#define FCNVME_ASSOC_HOSTNQN_LEN 256
249#define FCNVME_ASSOC_SUBNQN_LEN 256
250
251/* FCNVME_LSDESC_CREATE_ASSOC_CMD */
252struct fcnvme_lsdesc_cr_assoc_cmd {
253 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
254 __be32 desc_len;
255 __be16 ersp_ratio;
256 __be16 rsvd10;
257 __be32 rsvd12[9];
258 __be16 cntlid;
259 __be16 sqsize;
260 __be32 rsvd52;
Christoph Hellwig8e412262017-05-17 09:54:27 +0200261 uuid_t hostid;
James Smartb1ad14752016-12-02 00:28:40 -0800262 u8 hostnqn[FCNVME_ASSOC_HOSTNQN_LEN];
263 u8 subnqn[FCNVME_ASSOC_SUBNQN_LEN];
James Smartd1438ad2017-07-07 18:08:25 -0700264 __be32 rsvd584[108]; /* pad to 1016 bytes,
265 * which makes overall LS rqst
266 * payload 1024 bytes
267 */
James Smartb1ad14752016-12-02 00:28:40 -0800268};
269
James Smartd1438ad2017-07-07 18:08:25 -0700270#define FCNVME_LSDESC_CRA_CMD_DESC_MINLEN \
271 offsetof(struct fcnvme_lsdesc_cr_assoc_cmd, rsvd584)
272
273#define FCNVME_LSDESC_CRA_CMD_DESC_MIN_DESCLEN \
274 (FCNVME_LSDESC_CRA_CMD_DESC_MINLEN - \
275 offsetof(struct fcnvme_lsdesc_cr_assoc_cmd, ersp_ratio))
276
277
278
James Smartb1ad14752016-12-02 00:28:40 -0800279/* FCNVME_LSDESC_CREATE_CONN_CMD */
280struct fcnvme_lsdesc_cr_conn_cmd {
281 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
282 __be32 desc_len;
283 __be16 ersp_ratio;
284 __be16 rsvd10;
285 __be32 rsvd12[9];
286 __be16 qid;
287 __be16 sqsize;
288 __be32 rsvd52;
289};
290
James Smartb1ad14752016-12-02 00:28:40 -0800291/* FCNVME_LSDESC_DISCONN_CMD */
292struct fcnvme_lsdesc_disconn_cmd {
293 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
294 __be32 desc_len;
James Smartf1658362019-09-27 14:51:34 -0700295 __be32 rsvd8[4];
James Smartb1ad14752016-12-02 00:28:40 -0800296};
297
298/* FCNVME_LSDESC_CONN_ID */
299struct fcnvme_lsdesc_conn_id {
300 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
301 __be32 desc_len;
302 __be64 connection_id;
303};
304
305/* FCNVME_LSDESC_ASSOC_ID */
306struct fcnvme_lsdesc_assoc_id {
307 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
308 __be32 desc_len;
309 __be64 association_id;
310};
311
312/* r_ctl values */
313enum {
James Smartf1658362019-09-27 14:51:34 -0700314 FCNVME_RS_RCTL_CMND = 0x6,
315 FCNVME_RS_RCTL_DATA = 0x1,
316 FCNVME_RS_RCTL_CONF = 0x3,
317 FCNVME_RS_RCTL_SR = 0x9,
318 FCNVME_RS_RCTL_XFER_RDY = 0x5,
319 FCNVME_RS_RCTL_RSP = 0x7,
320 FCNVME_RS_RCTL_ERSP = 0x8,
321 FCNVME_RS_RCTL_SR_RSP = 0xA,
James Smartb1ad14752016-12-02 00:28:40 -0800322};
323
324
325/* ********** start of Link Services ********** */
326
327
328/* FCNVME_LS_RJT */
329struct fcnvme_ls_rjt {
330 struct fcnvme_ls_rqst_w0 w0;
331 __be32 desc_list_len;
332 struct fcnvme_lsdesc_rqst rqst;
333 struct fcnvme_lsdesc_rjt rjt;
334};
335
336/* FCNVME_LS_ACC */
337struct fcnvme_ls_acc_hdr {
338 struct fcnvme_ls_rqst_w0 w0;
339 __be32 desc_list_len;
340 struct fcnvme_lsdesc_rqst rqst;
James Smartf1658362019-09-27 14:51:34 -0700341 /*
342 * Followed by cmd-specific ACCEPT descriptors, see xxx_acc
343 * definitions below
344 */
James Smartb1ad14752016-12-02 00:28:40 -0800345};
346
347/* FCNVME_LS_CREATE_ASSOCIATION */
348struct fcnvme_ls_cr_assoc_rqst {
349 struct fcnvme_ls_rqst_w0 w0;
350 __be32 desc_list_len;
351 struct fcnvme_lsdesc_cr_assoc_cmd assoc_cmd;
352};
353
James Smartd1438ad2017-07-07 18:08:25 -0700354#define FCNVME_LSDESC_CRA_RQST_MINLEN \
355 (offsetof(struct fcnvme_ls_cr_assoc_rqst, assoc_cmd) + \
356 FCNVME_LSDESC_CRA_CMD_DESC_MINLEN)
357
358#define FCNVME_LSDESC_CRA_RQST_MIN_LISTLEN \
359 FCNVME_LSDESC_CRA_CMD_DESC_MINLEN
360
361
James Smartb1ad14752016-12-02 00:28:40 -0800362struct fcnvme_ls_cr_assoc_acc {
363 struct fcnvme_ls_acc_hdr hdr;
364 struct fcnvme_lsdesc_assoc_id associd;
365 struct fcnvme_lsdesc_conn_id connectid;
366};
367
368
369/* FCNVME_LS_CREATE_CONNECTION */
370struct fcnvme_ls_cr_conn_rqst {
371 struct fcnvme_ls_rqst_w0 w0;
372 __be32 desc_list_len;
373 struct fcnvme_lsdesc_assoc_id associd;
374 struct fcnvme_lsdesc_cr_conn_cmd connect_cmd;
375};
376
377struct fcnvme_ls_cr_conn_acc {
378 struct fcnvme_ls_acc_hdr hdr;
379 struct fcnvme_lsdesc_conn_id connectid;
380};
381
James Smartf1658362019-09-27 14:51:34 -0700382/* FCNVME_LS_DISCONNECT_ASSOC */
383struct fcnvme_ls_disconnect_assoc_rqst {
James Smartb1ad14752016-12-02 00:28:40 -0800384 struct fcnvme_ls_rqst_w0 w0;
385 __be32 desc_list_len;
386 struct fcnvme_lsdesc_assoc_id associd;
387 struct fcnvme_lsdesc_disconn_cmd discon_cmd;
388};
389
James Smartf1658362019-09-27 14:51:34 -0700390struct fcnvme_ls_disconnect_assoc_acc {
391 struct fcnvme_ls_acc_hdr hdr;
392};
393
394
395/* FCNVME_LS_DISCONNECT_CONN */
396struct fcnvme_ls_disconnect_conn_rqst {
397 struct fcnvme_ls_rqst_w0 w0;
398 __be32 desc_list_len;
399 struct fcnvme_lsdesc_assoc_id associd;
400 struct fcnvme_lsdesc_disconn_cmd connectid;
401};
402
403struct fcnvme_ls_disconnect_conn_acc {
James Smartb1ad14752016-12-02 00:28:40 -0800404 struct fcnvme_ls_acc_hdr hdr;
405};
406
407
408/*
James Smartf1658362019-09-27 14:51:34 -0700409 * Default R_A_TOV is pulled in from fc_fs.h but needs conversion
410 * from ms to seconds for our use.
James Smartb1ad14752016-12-02 00:28:40 -0800411 */
James Smartf1658362019-09-27 14:51:34 -0700412#define FC_TWO_TIMES_R_A_TOV (2 * (FC_DEF_R_A_TOV / 1000))
413#define NVME_FC_LS_TIMEOUT_SEC FC_TWO_TIMES_R_A_TOV
414#define NVME_FC_TGTOP_TIMEOUT_SEC FC_TWO_TIMES_R_A_TOV
James Smartb1ad14752016-12-02 00:28:40 -0800415
James Smart9c5358e2017-07-17 13:59:39 -0700416/*
417 * TRADDR string must be of form "nn-<16hexdigits>:pn-<16hexdigits>"
418 * the string is allowed to be specified with or without a "0x" prefix
419 * infront of the <16hexdigits>. Without is considered the "min" string
420 * and with is considered the "max" string. The hexdigits may be upper
421 * or lower case.
James Smartf1658362019-09-27 14:51:34 -0700422 * Note: FC-NVME-2 standard requires a "0x" prefix.
James Smart9c5358e2017-07-17 13:59:39 -0700423 */
424#define NVME_FC_TRADDR_NNLEN 3 /* "?n-" */
425#define NVME_FC_TRADDR_OXNNLEN 5 /* "?n-0x" */
426#define NVME_FC_TRADDR_HEXNAMELEN 16
427#define NVME_FC_TRADDR_MINLENGTH \
428 (2 * (NVME_FC_TRADDR_NNLEN + NVME_FC_TRADDR_HEXNAMELEN) + 1)
429#define NVME_FC_TRADDR_MAXLENGTH \
430 (2 * (NVME_FC_TRADDR_OXNNLEN + NVME_FC_TRADDR_HEXNAMELEN) + 1)
431#define NVME_FC_TRADDR_MIN_PN_OFFSET \
432 (NVME_FC_TRADDR_NNLEN + NVME_FC_TRADDR_HEXNAMELEN + 1)
433#define NVME_FC_TRADDR_MAX_PN_OFFSET \
434 (NVME_FC_TRADDR_OXNNLEN + NVME_FC_TRADDR_HEXNAMELEN + 1)
435
James Smartb1ad14752016-12-02 00:28:40 -0800436
437#endif /* _NVME_FC_H */