nvme-fc.h 9.7 KB

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