1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2016 Avago Technologies. All rights reserved.
7 * This file contains definitions relative to FC-NVME-2 r1.08
8 * (T11-2019-00210-v004).
14 #include <uapi/scsi/fc/fc_fs.h>
16 #define NVME_CMD_FORMAT_ID 0xFD
17 #define NVME_CMD_FC_ID FC_TYPE_NVME
19 /* FC-NVME Cmd IU Flags */
21 FCNVME_CMD_FLAGS_DIRMASK = 0x03,
22 FCNVME_CMD_FLAGS_WRITE = (1 << 0),
23 FCNVME_CMD_FLAGS_READ = (1 << 1),
25 FCNVME_CMD_FLAGS_PICWP = (1 << 2),
29 FCNVME_CMD_CAT_MASK = 0x0F,
30 FCNVME_CMD_CAT_ADMINQ = 0x01,
31 FCNVME_CMD_CAT_CSSMASK = 0x07,
32 FCNVME_CMD_CAT_CSSFLAG = 0x08,
35 static inline __u8 fccmnd_set_cat_admin(__u8 rsv_cat)
37 return (rsv_cat & ~FCNVME_CMD_CAT_MASK) | FCNVME_CMD_CAT_ADMINQ;
40 static inline __u8 fccmnd_set_cat_css(__u8 rsv_cat, __u8 css)
42 return (rsv_cat & ~FCNVME_CMD_CAT_MASK) | FCNVME_CMD_CAT_CSSFLAG |
43 (css & FCNVME_CMD_CAT_CSSMASK);
46 struct nvme_fc_cmd_iu {
56 struct nvme_command sqe;
63 #define NVME_FC_SIZEOF_ZEROS_RSP 12
66 FCNVME_SC_SUCCESS = 0,
67 FCNVME_SC_INVALID_FIELD = 1,
69 FCNVME_SC_ILL_CONN_PARAMS = 3,
72 struct nvme_fc_ersp_iu {
79 struct nvme_completion cqe;
80 /* for now - no additional payload */
84 #define FCNVME_NVME_SR_OPCODE 0x01
85 #define FCNVME_NVME_SR_RSP_OPCODE 0x02
87 struct nvme_fc_nvme_sr_iu {
97 FCNVME_SRSTAT_ACC = 0x0,
100 FCNVME_SRSTAT_LOGICAL_ERR = 0x3,
101 FCNVME_SRSTAT_INV_QUALIF = 0x4,
102 FCNVME_SRSTAT_UNABL2PERFORM = 0x9,
105 struct nvme_fc_nvme_sr_rsp_iu {
114 /* FC-NVME Link Services - LS cmd values (w0 bits 31:24) */
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 */
125 /* FC-NVME Link Service Descriptors */
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,
138 /* ********** start of Link Service Descriptors ********** */
142 * fills in length of a descriptor. Struture minus descriptor header
144 static inline __be32 fcnvme_lsdesc_len(size_t sz)
146 return cpu_to_be32(sz - (2 * sizeof(u32)));
149 struct fcnvme_ls_rqst_w0 {
150 u8 ls_cmd; /* FCNVME_LS_xxx */
154 /* FCNVME_LSDESC_RQST */
155 struct fcnvme_lsdesc_rqst {
156 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
158 struct fcnvme_ls_rqst_w0 w0;
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 */
167 FCNVME_RJT_RC_INVAL = 0x01,
168 /* invalid NVMe_LS command code */
170 FCNVME_RJT_RC_LOGIC = 0x03,
173 FCNVME_RJT_RC_UNAB = 0x09,
174 /* unable to perform command request */
176 FCNVME_RJT_RC_UNSUP = 0x0b,
177 /* command not supported */
179 FCNVME_RJT_RC_INV_ASSOC = 0x40,
180 /* Invalid Association ID */
182 FCNVME_RJT_RC_INV_CONN = 0x41,
183 /* Invalid Connection ID */
185 FCNVME_RJT_RC_INV_PARAM = 0x42,
186 /* Invalid Parameters */
188 FCNVME_RJT_RC_INSUF_RES = 0x43,
189 /* Insufficient Resources */
191 FCNVME_RJT_RC_VENDOR = 0xff,
192 /* vendor specific error */
195 /* FC-NVME LS RJT reason_explanation values */
196 enum fcnvme_ls_rjt_explan {
197 FCNVME_RJT_EXP_NONE = 0x00,
198 /* No additional explanation */
200 FCNVME_RJT_EXP_OXID_RXID = 0x17,
201 /* invalid OX_ID-RX_ID combination */
203 FCNVME_RJT_EXP_UNAB_DATA = 0x2a,
204 /* unable to supply requested data */
206 FCNVME_RJT_EXP_INV_LEN = 0x2d,
207 /* Invalid payload length */
209 FCNVME_RJT_EXP_INV_ERSP_RAT = 0x40,
210 /* Invalid NVMe_ERSP Ratio */
212 FCNVME_RJT_EXP_INV_CTLR_ID = 0x41,
213 /* Invalid Controller ID */
215 FCNVME_RJT_EXP_INV_QUEUE_ID = 0x42,
216 /* Invalid Queue ID */
218 FCNVME_RJT_EXP_INV_SQSIZE = 0x43,
219 /* Invalid Submission Queue Size */
221 FCNVME_RJT_EXP_INV_HOSTID = 0x44,
222 /* Invalid HOST ID */
224 FCNVME_RJT_EXP_INV_HOSTNQN = 0x45,
225 /* Invalid HOSTNQN */
227 FCNVME_RJT_EXP_INV_SUBNQN = 0x46,
231 /* FCNVME_LSDESC_RJT */
232 struct fcnvme_lsdesc_rjt {
233 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
238 * Reject reason and explanaction codes are generic
239 * to ELs's from LS-3.
241 u8 reason_code; /* fcnvme_ls_rjt_reason */
242 u8 reason_explanation; /* fcnvme_ls_rjt_explan */
249 #define FCNVME_ASSOC_HOSTNQN_LEN 256
250 #define FCNVME_ASSOC_SUBNQN_LEN 256
252 /* FCNVME_LSDESC_CREATE_ASSOC_CMD */
253 struct fcnvme_lsdesc_cr_assoc_cmd {
254 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
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
271 #define FCNVME_LSDESC_CRA_CMD_DESC_MINLEN \
272 offsetof(struct fcnvme_lsdesc_cr_assoc_cmd, rsvd584)
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))
280 /* FCNVME_LSDESC_CREATE_CONN_CMD */
281 struct fcnvme_lsdesc_cr_conn_cmd {
282 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
292 /* FCNVME_LSDESC_DISCONN_CMD */
293 struct fcnvme_lsdesc_disconn_cmd {
294 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
299 /* FCNVME_LSDESC_CONN_ID */
300 struct fcnvme_lsdesc_conn_id {
301 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
303 __be64 connection_id;
306 /* FCNVME_LSDESC_ASSOC_ID */
307 struct fcnvme_lsdesc_assoc_id {
308 __be32 desc_tag; /* FCNVME_LSDESC_xxx */
310 __be64 association_id;
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,
326 /* ********** start of Link Services ********** */
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;
338 struct fcnvme_ls_acc_hdr {
339 struct fcnvme_ls_rqst_w0 w0;
340 __be32 desc_list_len;
341 struct fcnvme_lsdesc_rqst rqst;
343 * Followed by cmd-specific ACCEPT descriptors, see xxx_acc
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;
355 #define FCNVME_LSDESC_CRA_RQST_MINLEN \
356 (offsetof(struct fcnvme_ls_cr_assoc_rqst, assoc_cmd) + \
357 FCNVME_LSDESC_CRA_CMD_DESC_MINLEN)
359 #define FCNVME_LSDESC_CRA_RQST_MIN_LISTLEN \
360 FCNVME_LSDESC_CRA_CMD_DESC_MINLEN
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;
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;
378 struct fcnvme_ls_cr_conn_acc {
379 struct fcnvme_ls_acc_hdr hdr;
380 struct fcnvme_lsdesc_conn_id connectid;
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;
391 struct fcnvme_ls_disconnect_assoc_acc {
392 struct fcnvme_ls_acc_hdr hdr;
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;
404 struct fcnvme_ls_disconnect_conn_acc {
405 struct fcnvme_ls_acc_hdr hdr;
410 * Default R_A_TOV is pulled in from fc_fs.h but needs conversion
411 * from ms to seconds for our use.
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
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
423 * Note: FC-NVME-2 standard requires a "0x" prefix.
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)
438 #endif /* _NVME_FC_H */