nvme.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. /*
  2. * Definitions for the NVM Express interface
  3. * Copyright (c) 2011-2014, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _LINUX_NVME_H
  15. #define _LINUX_NVME_H
  16. #include <linux/types.h>
  17. /* NQN names in commands fields specified one size */
  18. #define NVMF_NQN_FIELD_LEN 256
  19. /* However the max length of a qualified name is another size */
  20. #define NVMF_NQN_SIZE 223
  21. #define NVMF_TRSVCID_SIZE 32
  22. #define NVMF_TRADDR_SIZE 256
  23. #define NVMF_TSAS_SIZE 256
  24. #define NVME_DISC_SUBSYS_NAME "nqn.2014-08.org.nvmexpress.discovery"
  25. #define NVME_RDMA_IP_PORT 4420
  26. enum nvme_subsys_type {
  27. NVME_NQN_DISC = 1, /* Discovery type target subsystem */
  28. NVME_NQN_NVME = 2, /* NVME type target subsystem */
  29. };
  30. /* Address Family codes for Discovery Log Page entry ADRFAM field */
  31. enum {
  32. NVMF_ADDR_FAMILY_PCI = 0, /* PCIe */
  33. NVMF_ADDR_FAMILY_IP4 = 1, /* IP4 */
  34. NVMF_ADDR_FAMILY_IP6 = 2, /* IP6 */
  35. NVMF_ADDR_FAMILY_IB = 3, /* InfiniBand */
  36. NVMF_ADDR_FAMILY_FC = 4, /* Fibre Channel */
  37. };
  38. /* Transport Type codes for Discovery Log Page entry TRTYPE field */
  39. enum {
  40. NVMF_TRTYPE_RDMA = 1, /* RDMA */
  41. NVMF_TRTYPE_FC = 2, /* Fibre Channel */
  42. NVMF_TRTYPE_LOOP = 254, /* Reserved for host usage */
  43. NVMF_TRTYPE_MAX,
  44. };
  45. /* Transport Requirements codes for Discovery Log Page entry TREQ field */
  46. enum {
  47. NVMF_TREQ_NOT_SPECIFIED = 0, /* Not specified */
  48. NVMF_TREQ_REQUIRED = 1, /* Required */
  49. NVMF_TREQ_NOT_REQUIRED = 2, /* Not Required */
  50. };
  51. /* RDMA QP Service Type codes for Discovery Log Page entry TSAS
  52. * RDMA_QPTYPE field
  53. */
  54. enum {
  55. NVMF_RDMA_QPTYPE_CONNECTED = 0, /* Reliable Connected */
  56. NVMF_RDMA_QPTYPE_DATAGRAM = 1, /* Reliable Datagram */
  57. };
  58. /* RDMA QP Service Type codes for Discovery Log Page entry TSAS
  59. * RDMA_QPTYPE field
  60. */
  61. enum {
  62. NVMF_RDMA_PRTYPE_NOT_SPECIFIED = 0, /* No Provider Specified */
  63. NVMF_RDMA_PRTYPE_IB = 1, /* InfiniBand */
  64. NVMF_RDMA_PRTYPE_ROCE = 2, /* InfiniBand RoCE */
  65. NVMF_RDMA_PRTYPE_ROCEV2 = 3, /* InfiniBand RoCEV2 */
  66. NVMF_RDMA_PRTYPE_IWARP = 4, /* IWARP */
  67. };
  68. /* RDMA Connection Management Service Type codes for Discovery Log Page
  69. * entry TSAS RDMA_CMS field
  70. */
  71. enum {
  72. NVMF_RDMA_CMS_RDMA_CM = 0, /* Sockets based enpoint addressing */
  73. };
  74. #define NVMF_AQ_DEPTH 32
  75. enum {
  76. NVME_REG_CAP = 0x0000, /* Controller Capabilities */
  77. NVME_REG_VS = 0x0008, /* Version */
  78. NVME_REG_INTMS = 0x000c, /* Interrupt Mask Set */
  79. NVME_REG_INTMC = 0x0010, /* Interrupt Mask Clear */
  80. NVME_REG_CC = 0x0014, /* Controller Configuration */
  81. NVME_REG_CSTS = 0x001c, /* Controller Status */
  82. NVME_REG_NSSR = 0x0020, /* NVM Subsystem Reset */
  83. NVME_REG_AQA = 0x0024, /* Admin Queue Attributes */
  84. NVME_REG_ASQ = 0x0028, /* Admin SQ Base Address */
  85. NVME_REG_ACQ = 0x0030, /* Admin CQ Base Address */
  86. NVME_REG_CMBLOC = 0x0038, /* Controller Memory Buffer Location */
  87. NVME_REG_CMBSZ = 0x003c, /* Controller Memory Buffer Size */
  88. };
  89. #define NVME_CAP_MQES(cap) ((cap) & 0xffff)
  90. #define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff)
  91. #define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf)
  92. #define NVME_CAP_NSSRC(cap) (((cap) >> 36) & 0x1)
  93. #define NVME_CAP_MPSMIN(cap) (((cap) >> 48) & 0xf)
  94. #define NVME_CAP_MPSMAX(cap) (((cap) >> 52) & 0xf)
  95. #define NVME_CMB_BIR(cmbloc) ((cmbloc) & 0x7)
  96. #define NVME_CMB_OFST(cmbloc) (((cmbloc) >> 12) & 0xfffff)
  97. #define NVME_CMB_SZ(cmbsz) (((cmbsz) >> 12) & 0xfffff)
  98. #define NVME_CMB_SZU(cmbsz) (((cmbsz) >> 8) & 0xf)
  99. #define NVME_CMB_WDS(cmbsz) ((cmbsz) & 0x10)
  100. #define NVME_CMB_RDS(cmbsz) ((cmbsz) & 0x8)
  101. #define NVME_CMB_LISTS(cmbsz) ((cmbsz) & 0x4)
  102. #define NVME_CMB_CQS(cmbsz) ((cmbsz) & 0x2)
  103. #define NVME_CMB_SQS(cmbsz) ((cmbsz) & 0x1)
  104. /*
  105. * Submission and Completion Queue Entry Sizes for the NVM command set.
  106. * (In bytes and specified as a power of two (2^n)).
  107. */
  108. #define NVME_NVM_IOSQES 6
  109. #define NVME_NVM_IOCQES 4
  110. enum {
  111. NVME_CC_ENABLE = 1 << 0,
  112. NVME_CC_CSS_NVM = 0 << 4,
  113. NVME_CC_MPS_SHIFT = 7,
  114. NVME_CC_ARB_RR = 0 << 11,
  115. NVME_CC_ARB_WRRU = 1 << 11,
  116. NVME_CC_ARB_VS = 7 << 11,
  117. NVME_CC_SHN_NONE = 0 << 14,
  118. NVME_CC_SHN_NORMAL = 1 << 14,
  119. NVME_CC_SHN_ABRUPT = 2 << 14,
  120. NVME_CC_SHN_MASK = 3 << 14,
  121. NVME_CC_IOSQES = NVME_NVM_IOSQES << 16,
  122. NVME_CC_IOCQES = NVME_NVM_IOCQES << 20,
  123. NVME_CSTS_RDY = 1 << 0,
  124. NVME_CSTS_CFS = 1 << 1,
  125. NVME_CSTS_NSSRO = 1 << 4,
  126. NVME_CSTS_SHST_NORMAL = 0 << 2,
  127. NVME_CSTS_SHST_OCCUR = 1 << 2,
  128. NVME_CSTS_SHST_CMPLT = 2 << 2,
  129. NVME_CSTS_SHST_MASK = 3 << 2,
  130. };
  131. struct nvme_id_power_state {
  132. __le16 max_power; /* centiwatts */
  133. __u8 rsvd2;
  134. __u8 flags;
  135. __le32 entry_lat; /* microseconds */
  136. __le32 exit_lat; /* microseconds */
  137. __u8 read_tput;
  138. __u8 read_lat;
  139. __u8 write_tput;
  140. __u8 write_lat;
  141. __le16 idle_power;
  142. __u8 idle_scale;
  143. __u8 rsvd19;
  144. __le16 active_power;
  145. __u8 active_work_scale;
  146. __u8 rsvd23[9];
  147. };
  148. enum {
  149. NVME_PS_FLAGS_MAX_POWER_SCALE = 1 << 0,
  150. NVME_PS_FLAGS_NON_OP_STATE = 1 << 1,
  151. };
  152. struct nvme_id_ctrl {
  153. __le16 vid;
  154. __le16 ssvid;
  155. char sn[20];
  156. char mn[40];
  157. char fr[8];
  158. __u8 rab;
  159. __u8 ieee[3];
  160. __u8 cmic;
  161. __u8 mdts;
  162. __le16 cntlid;
  163. __le32 ver;
  164. __le32 rtd3r;
  165. __le32 rtd3e;
  166. __le32 oaes;
  167. __le32 ctratt;
  168. __u8 rsvd100[156];
  169. __le16 oacs;
  170. __u8 acl;
  171. __u8 aerl;
  172. __u8 frmw;
  173. __u8 lpa;
  174. __u8 elpe;
  175. __u8 npss;
  176. __u8 avscc;
  177. __u8 apsta;
  178. __le16 wctemp;
  179. __le16 cctemp;
  180. __le16 mtfa;
  181. __le32 hmpre;
  182. __le32 hmmin;
  183. __u8 tnvmcap[16];
  184. __u8 unvmcap[16];
  185. __le32 rpmbs;
  186. __u8 rsvd316[4];
  187. __le16 kas;
  188. __u8 rsvd322[190];
  189. __u8 sqes;
  190. __u8 cqes;
  191. __le16 maxcmd;
  192. __le32 nn;
  193. __le16 oncs;
  194. __le16 fuses;
  195. __u8 fna;
  196. __u8 vwc;
  197. __le16 awun;
  198. __le16 awupf;
  199. __u8 nvscc;
  200. __u8 rsvd531;
  201. __le16 acwu;
  202. __u8 rsvd534[2];
  203. __le32 sgls;
  204. __u8 rsvd540[228];
  205. char subnqn[256];
  206. __u8 rsvd1024[768];
  207. __le32 ioccsz;
  208. __le32 iorcsz;
  209. __le16 icdoff;
  210. __u8 ctrattr;
  211. __u8 msdbd;
  212. __u8 rsvd1804[244];
  213. struct nvme_id_power_state psd[32];
  214. __u8 vs[1024];
  215. };
  216. enum {
  217. NVME_CTRL_ONCS_COMPARE = 1 << 0,
  218. NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1,
  219. NVME_CTRL_ONCS_DSM = 1 << 2,
  220. NVME_CTRL_VWC_PRESENT = 1 << 0,
  221. };
  222. struct nvme_lbaf {
  223. __le16 ms;
  224. __u8 ds;
  225. __u8 rp;
  226. };
  227. struct nvme_id_ns {
  228. __le64 nsze;
  229. __le64 ncap;
  230. __le64 nuse;
  231. __u8 nsfeat;
  232. __u8 nlbaf;
  233. __u8 flbas;
  234. __u8 mc;
  235. __u8 dpc;
  236. __u8 dps;
  237. __u8 nmic;
  238. __u8 rescap;
  239. __u8 fpi;
  240. __u8 rsvd33;
  241. __le16 nawun;
  242. __le16 nawupf;
  243. __le16 nacwu;
  244. __le16 nabsn;
  245. __le16 nabo;
  246. __le16 nabspf;
  247. __u16 rsvd46;
  248. __u8 nvmcap[16];
  249. __u8 rsvd64[40];
  250. __u8 nguid[16];
  251. __u8 eui64[8];
  252. struct nvme_lbaf lbaf[16];
  253. __u8 rsvd192[192];
  254. __u8 vs[3712];
  255. };
  256. enum {
  257. NVME_ID_CNS_NS = 0x00,
  258. NVME_ID_CNS_CTRL = 0x01,
  259. NVME_ID_CNS_NS_ACTIVE_LIST = 0x02,
  260. NVME_ID_CNS_NS_PRESENT_LIST = 0x10,
  261. NVME_ID_CNS_NS_PRESENT = 0x11,
  262. NVME_ID_CNS_CTRL_NS_LIST = 0x12,
  263. NVME_ID_CNS_CTRL_LIST = 0x13,
  264. };
  265. enum {
  266. NVME_NS_FEAT_THIN = 1 << 0,
  267. NVME_NS_FLBAS_LBA_MASK = 0xf,
  268. NVME_NS_FLBAS_META_EXT = 0x10,
  269. NVME_LBAF_RP_BEST = 0,
  270. NVME_LBAF_RP_BETTER = 1,
  271. NVME_LBAF_RP_GOOD = 2,
  272. NVME_LBAF_RP_DEGRADED = 3,
  273. NVME_NS_DPC_PI_LAST = 1 << 4,
  274. NVME_NS_DPC_PI_FIRST = 1 << 3,
  275. NVME_NS_DPC_PI_TYPE3 = 1 << 2,
  276. NVME_NS_DPC_PI_TYPE2 = 1 << 1,
  277. NVME_NS_DPC_PI_TYPE1 = 1 << 0,
  278. NVME_NS_DPS_PI_FIRST = 1 << 3,
  279. NVME_NS_DPS_PI_MASK = 0x7,
  280. NVME_NS_DPS_PI_TYPE1 = 1,
  281. NVME_NS_DPS_PI_TYPE2 = 2,
  282. NVME_NS_DPS_PI_TYPE3 = 3,
  283. };
  284. struct nvme_smart_log {
  285. __u8 critical_warning;
  286. __u8 temperature[2];
  287. __u8 avail_spare;
  288. __u8 spare_thresh;
  289. __u8 percent_used;
  290. __u8 rsvd6[26];
  291. __u8 data_units_read[16];
  292. __u8 data_units_written[16];
  293. __u8 host_reads[16];
  294. __u8 host_writes[16];
  295. __u8 ctrl_busy_time[16];
  296. __u8 power_cycles[16];
  297. __u8 power_on_hours[16];
  298. __u8 unsafe_shutdowns[16];
  299. __u8 media_errors[16];
  300. __u8 num_err_log_entries[16];
  301. __le32 warning_temp_time;
  302. __le32 critical_comp_time;
  303. __le16 temp_sensor[8];
  304. __u8 rsvd216[296];
  305. };
  306. enum {
  307. NVME_SMART_CRIT_SPARE = 1 << 0,
  308. NVME_SMART_CRIT_TEMPERATURE = 1 << 1,
  309. NVME_SMART_CRIT_RELIABILITY = 1 << 2,
  310. NVME_SMART_CRIT_MEDIA = 1 << 3,
  311. NVME_SMART_CRIT_VOLATILE_MEMORY = 1 << 4,
  312. };
  313. enum {
  314. NVME_AER_NOTICE_NS_CHANGED = 0x0002,
  315. };
  316. struct nvme_lba_range_type {
  317. __u8 type;
  318. __u8 attributes;
  319. __u8 rsvd2[14];
  320. __u64 slba;
  321. __u64 nlb;
  322. __u8 guid[16];
  323. __u8 rsvd48[16];
  324. };
  325. enum {
  326. NVME_LBART_TYPE_FS = 0x01,
  327. NVME_LBART_TYPE_RAID = 0x02,
  328. NVME_LBART_TYPE_CACHE = 0x03,
  329. NVME_LBART_TYPE_SWAP = 0x04,
  330. NVME_LBART_ATTRIB_TEMP = 1 << 0,
  331. NVME_LBART_ATTRIB_HIDE = 1 << 1,
  332. };
  333. struct nvme_reservation_status {
  334. __le32 gen;
  335. __u8 rtype;
  336. __u8 regctl[2];
  337. __u8 resv5[2];
  338. __u8 ptpls;
  339. __u8 resv10[13];
  340. struct {
  341. __le16 cntlid;
  342. __u8 rcsts;
  343. __u8 resv3[5];
  344. __le64 hostid;
  345. __le64 rkey;
  346. } regctl_ds[];
  347. };
  348. enum nvme_async_event_type {
  349. NVME_AER_TYPE_ERROR = 0,
  350. NVME_AER_TYPE_SMART = 1,
  351. NVME_AER_TYPE_NOTICE = 2,
  352. };
  353. /* I/O commands */
  354. enum nvme_opcode {
  355. nvme_cmd_flush = 0x00,
  356. nvme_cmd_write = 0x01,
  357. nvme_cmd_read = 0x02,
  358. nvme_cmd_write_uncor = 0x04,
  359. nvme_cmd_compare = 0x05,
  360. nvme_cmd_write_zeroes = 0x08,
  361. nvme_cmd_dsm = 0x09,
  362. nvme_cmd_resv_register = 0x0d,
  363. nvme_cmd_resv_report = 0x0e,
  364. nvme_cmd_resv_acquire = 0x11,
  365. nvme_cmd_resv_release = 0x15,
  366. };
  367. /*
  368. * Descriptor subtype - lower 4 bits of nvme_(keyed_)sgl_desc identifier
  369. *
  370. * @NVME_SGL_FMT_ADDRESS: absolute address of the data block
  371. * @NVME_SGL_FMT_OFFSET: relative offset of the in-capsule data block
  372. * @NVME_SGL_FMT_INVALIDATE: RDMA transport specific remote invalidation
  373. * request subtype
  374. */
  375. enum {
  376. NVME_SGL_FMT_ADDRESS = 0x00,
  377. NVME_SGL_FMT_OFFSET = 0x01,
  378. NVME_SGL_FMT_INVALIDATE = 0x0f,
  379. };
  380. /*
  381. * Descriptor type - upper 4 bits of nvme_(keyed_)sgl_desc identifier
  382. *
  383. * For struct nvme_sgl_desc:
  384. * @NVME_SGL_FMT_DATA_DESC: data block descriptor
  385. * @NVME_SGL_FMT_SEG_DESC: sgl segment descriptor
  386. * @NVME_SGL_FMT_LAST_SEG_DESC: last sgl segment descriptor
  387. *
  388. * For struct nvme_keyed_sgl_desc:
  389. * @NVME_KEY_SGL_FMT_DATA_DESC: keyed data block descriptor
  390. */
  391. enum {
  392. NVME_SGL_FMT_DATA_DESC = 0x00,
  393. NVME_SGL_FMT_SEG_DESC = 0x02,
  394. NVME_SGL_FMT_LAST_SEG_DESC = 0x03,
  395. NVME_KEY_SGL_FMT_DATA_DESC = 0x04,
  396. };
  397. struct nvme_sgl_desc {
  398. __le64 addr;
  399. __le32 length;
  400. __u8 rsvd[3];
  401. __u8 type;
  402. };
  403. struct nvme_keyed_sgl_desc {
  404. __le64 addr;
  405. __u8 length[3];
  406. __u8 key[4];
  407. __u8 type;
  408. };
  409. union nvme_data_ptr {
  410. struct {
  411. __le64 prp1;
  412. __le64 prp2;
  413. };
  414. struct nvme_sgl_desc sgl;
  415. struct nvme_keyed_sgl_desc ksgl;
  416. };
  417. /*
  418. * Lowest two bits of our flags field (FUSE field in the spec):
  419. *
  420. * @NVME_CMD_FUSE_FIRST: Fused Operation, first command
  421. * @NVME_CMD_FUSE_SECOND: Fused Operation, second command
  422. *
  423. * Highest two bits in our flags field (PSDT field in the spec):
  424. *
  425. * @NVME_CMD_PSDT_SGL_METABUF: Use SGLS for this transfer,
  426. * If used, MPTR contains addr of single physical buffer (byte aligned).
  427. * @NVME_CMD_PSDT_SGL_METASEG: Use SGLS for this transfer,
  428. * If used, MPTR contains an address of an SGL segment containing
  429. * exactly 1 SGL descriptor (qword aligned).
  430. */
  431. enum {
  432. NVME_CMD_FUSE_FIRST = (1 << 0),
  433. NVME_CMD_FUSE_SECOND = (1 << 1),
  434. NVME_CMD_SGL_METABUF = (1 << 6),
  435. NVME_CMD_SGL_METASEG = (1 << 7),
  436. NVME_CMD_SGL_ALL = NVME_CMD_SGL_METABUF | NVME_CMD_SGL_METASEG,
  437. };
  438. struct nvme_common_command {
  439. __u8 opcode;
  440. __u8 flags;
  441. __u16 command_id;
  442. __le32 nsid;
  443. __le32 cdw2[2];
  444. __le64 metadata;
  445. union nvme_data_ptr dptr;
  446. __le32 cdw10[6];
  447. };
  448. struct nvme_rw_command {
  449. __u8 opcode;
  450. __u8 flags;
  451. __u16 command_id;
  452. __le32 nsid;
  453. __u64 rsvd2;
  454. __le64 metadata;
  455. union nvme_data_ptr dptr;
  456. __le64 slba;
  457. __le16 length;
  458. __le16 control;
  459. __le32 dsmgmt;
  460. __le32 reftag;
  461. __le16 apptag;
  462. __le16 appmask;
  463. };
  464. enum {
  465. NVME_RW_LR = 1 << 15,
  466. NVME_RW_FUA = 1 << 14,
  467. NVME_RW_DSM_FREQ_UNSPEC = 0,
  468. NVME_RW_DSM_FREQ_TYPICAL = 1,
  469. NVME_RW_DSM_FREQ_RARE = 2,
  470. NVME_RW_DSM_FREQ_READS = 3,
  471. NVME_RW_DSM_FREQ_WRITES = 4,
  472. NVME_RW_DSM_FREQ_RW = 5,
  473. NVME_RW_DSM_FREQ_ONCE = 6,
  474. NVME_RW_DSM_FREQ_PREFETCH = 7,
  475. NVME_RW_DSM_FREQ_TEMP = 8,
  476. NVME_RW_DSM_LATENCY_NONE = 0 << 4,
  477. NVME_RW_DSM_LATENCY_IDLE = 1 << 4,
  478. NVME_RW_DSM_LATENCY_NORM = 2 << 4,
  479. NVME_RW_DSM_LATENCY_LOW = 3 << 4,
  480. NVME_RW_DSM_SEQ_REQ = 1 << 6,
  481. NVME_RW_DSM_COMPRESSED = 1 << 7,
  482. NVME_RW_PRINFO_PRCHK_REF = 1 << 10,
  483. NVME_RW_PRINFO_PRCHK_APP = 1 << 11,
  484. NVME_RW_PRINFO_PRCHK_GUARD = 1 << 12,
  485. NVME_RW_PRINFO_PRACT = 1 << 13,
  486. };
  487. struct nvme_dsm_cmd {
  488. __u8 opcode;
  489. __u8 flags;
  490. __u16 command_id;
  491. __le32 nsid;
  492. __u64 rsvd2[2];
  493. union nvme_data_ptr dptr;
  494. __le32 nr;
  495. __le32 attributes;
  496. __u32 rsvd12[4];
  497. };
  498. enum {
  499. NVME_DSMGMT_IDR = 1 << 0,
  500. NVME_DSMGMT_IDW = 1 << 1,
  501. NVME_DSMGMT_AD = 1 << 2,
  502. };
  503. struct nvme_dsm_range {
  504. __le32 cattr;
  505. __le32 nlb;
  506. __le64 slba;
  507. };
  508. /* Admin commands */
  509. enum nvme_admin_opcode {
  510. nvme_admin_delete_sq = 0x00,
  511. nvme_admin_create_sq = 0x01,
  512. nvme_admin_get_log_page = 0x02,
  513. nvme_admin_delete_cq = 0x04,
  514. nvme_admin_create_cq = 0x05,
  515. nvme_admin_identify = 0x06,
  516. nvme_admin_abort_cmd = 0x08,
  517. nvme_admin_set_features = 0x09,
  518. nvme_admin_get_features = 0x0a,
  519. nvme_admin_async_event = 0x0c,
  520. nvme_admin_ns_mgmt = 0x0d,
  521. nvme_admin_activate_fw = 0x10,
  522. nvme_admin_download_fw = 0x11,
  523. nvme_admin_ns_attach = 0x15,
  524. nvme_admin_keep_alive = 0x18,
  525. nvme_admin_format_nvm = 0x80,
  526. nvme_admin_security_send = 0x81,
  527. nvme_admin_security_recv = 0x82,
  528. };
  529. enum {
  530. NVME_QUEUE_PHYS_CONTIG = (1 << 0),
  531. NVME_CQ_IRQ_ENABLED = (1 << 1),
  532. NVME_SQ_PRIO_URGENT = (0 << 1),
  533. NVME_SQ_PRIO_HIGH = (1 << 1),
  534. NVME_SQ_PRIO_MEDIUM = (2 << 1),
  535. NVME_SQ_PRIO_LOW = (3 << 1),
  536. NVME_FEAT_ARBITRATION = 0x01,
  537. NVME_FEAT_POWER_MGMT = 0x02,
  538. NVME_FEAT_LBA_RANGE = 0x03,
  539. NVME_FEAT_TEMP_THRESH = 0x04,
  540. NVME_FEAT_ERR_RECOVERY = 0x05,
  541. NVME_FEAT_VOLATILE_WC = 0x06,
  542. NVME_FEAT_NUM_QUEUES = 0x07,
  543. NVME_FEAT_IRQ_COALESCE = 0x08,
  544. NVME_FEAT_IRQ_CONFIG = 0x09,
  545. NVME_FEAT_WRITE_ATOMIC = 0x0a,
  546. NVME_FEAT_ASYNC_EVENT = 0x0b,
  547. NVME_FEAT_AUTO_PST = 0x0c,
  548. NVME_FEAT_HOST_MEM_BUF = 0x0d,
  549. NVME_FEAT_KATO = 0x0f,
  550. NVME_FEAT_SW_PROGRESS = 0x80,
  551. NVME_FEAT_HOST_ID = 0x81,
  552. NVME_FEAT_RESV_MASK = 0x82,
  553. NVME_FEAT_RESV_PERSIST = 0x83,
  554. NVME_LOG_ERROR = 0x01,
  555. NVME_LOG_SMART = 0x02,
  556. NVME_LOG_FW_SLOT = 0x03,
  557. NVME_LOG_DISC = 0x70,
  558. NVME_LOG_RESERVATION = 0x80,
  559. NVME_FWACT_REPL = (0 << 3),
  560. NVME_FWACT_REPL_ACTV = (1 << 3),
  561. NVME_FWACT_ACTV = (2 << 3),
  562. };
  563. struct nvme_identify {
  564. __u8 opcode;
  565. __u8 flags;
  566. __u16 command_id;
  567. __le32 nsid;
  568. __u64 rsvd2[2];
  569. union nvme_data_ptr dptr;
  570. __le32 cns;
  571. __u32 rsvd11[5];
  572. };
  573. struct nvme_features {
  574. __u8 opcode;
  575. __u8 flags;
  576. __u16 command_id;
  577. __le32 nsid;
  578. __u64 rsvd2[2];
  579. union nvme_data_ptr dptr;
  580. __le32 fid;
  581. __le32 dword11;
  582. __u32 rsvd12[4];
  583. };
  584. struct nvme_create_cq {
  585. __u8 opcode;
  586. __u8 flags;
  587. __u16 command_id;
  588. __u32 rsvd1[5];
  589. __le64 prp1;
  590. __u64 rsvd8;
  591. __le16 cqid;
  592. __le16 qsize;
  593. __le16 cq_flags;
  594. __le16 irq_vector;
  595. __u32 rsvd12[4];
  596. };
  597. struct nvme_create_sq {
  598. __u8 opcode;
  599. __u8 flags;
  600. __u16 command_id;
  601. __u32 rsvd1[5];
  602. __le64 prp1;
  603. __u64 rsvd8;
  604. __le16 sqid;
  605. __le16 qsize;
  606. __le16 sq_flags;
  607. __le16 cqid;
  608. __u32 rsvd12[4];
  609. };
  610. struct nvme_delete_queue {
  611. __u8 opcode;
  612. __u8 flags;
  613. __u16 command_id;
  614. __u32 rsvd1[9];
  615. __le16 qid;
  616. __u16 rsvd10;
  617. __u32 rsvd11[5];
  618. };
  619. struct nvme_abort_cmd {
  620. __u8 opcode;
  621. __u8 flags;
  622. __u16 command_id;
  623. __u32 rsvd1[9];
  624. __le16 sqid;
  625. __u16 cid;
  626. __u32 rsvd11[5];
  627. };
  628. struct nvme_download_firmware {
  629. __u8 opcode;
  630. __u8 flags;
  631. __u16 command_id;
  632. __u32 rsvd1[5];
  633. union nvme_data_ptr dptr;
  634. __le32 numd;
  635. __le32 offset;
  636. __u32 rsvd12[4];
  637. };
  638. struct nvme_format_cmd {
  639. __u8 opcode;
  640. __u8 flags;
  641. __u16 command_id;
  642. __le32 nsid;
  643. __u64 rsvd2[4];
  644. __le32 cdw10;
  645. __u32 rsvd11[5];
  646. };
  647. struct nvme_get_log_page_command {
  648. __u8 opcode;
  649. __u8 flags;
  650. __u16 command_id;
  651. __le32 nsid;
  652. __u64 rsvd2[2];
  653. union nvme_data_ptr dptr;
  654. __u8 lid;
  655. __u8 rsvd10;
  656. __le16 numdl;
  657. __le16 numdu;
  658. __u16 rsvd11;
  659. __le32 lpol;
  660. __le32 lpou;
  661. __u32 rsvd14[2];
  662. };
  663. /*
  664. * Fabrics subcommands.
  665. */
  666. enum nvmf_fabrics_opcode {
  667. nvme_fabrics_command = 0x7f,
  668. };
  669. enum nvmf_capsule_command {
  670. nvme_fabrics_type_property_set = 0x00,
  671. nvme_fabrics_type_connect = 0x01,
  672. nvme_fabrics_type_property_get = 0x04,
  673. };
  674. struct nvmf_common_command {
  675. __u8 opcode;
  676. __u8 resv1;
  677. __u16 command_id;
  678. __u8 fctype;
  679. __u8 resv2[35];
  680. __u8 ts[24];
  681. };
  682. /*
  683. * The legal cntlid range a NVMe Target will provide.
  684. * Note that cntlid of value 0 is considered illegal in the fabrics world.
  685. * Devices based on earlier specs did not have the subsystem concept;
  686. * therefore, those devices had their cntlid value set to 0 as a result.
  687. */
  688. #define NVME_CNTLID_MIN 1
  689. #define NVME_CNTLID_MAX 0xffef
  690. #define NVME_CNTLID_DYNAMIC 0xffff
  691. #define MAX_DISC_LOGS 255
  692. /* Discovery log page entry */
  693. struct nvmf_disc_rsp_page_entry {
  694. __u8 trtype;
  695. __u8 adrfam;
  696. __u8 subtype;
  697. __u8 treq;
  698. __le16 portid;
  699. __le16 cntlid;
  700. __le16 asqsz;
  701. __u8 resv8[22];
  702. char trsvcid[NVMF_TRSVCID_SIZE];
  703. __u8 resv64[192];
  704. char subnqn[NVMF_NQN_FIELD_LEN];
  705. char traddr[NVMF_TRADDR_SIZE];
  706. union tsas {
  707. char common[NVMF_TSAS_SIZE];
  708. struct rdma {
  709. __u8 qptype;
  710. __u8 prtype;
  711. __u8 cms;
  712. __u8 resv3[5];
  713. __u16 pkey;
  714. __u8 resv10[246];
  715. } rdma;
  716. } tsas;
  717. };
  718. /* Discovery log page header */
  719. struct nvmf_disc_rsp_page_hdr {
  720. __le64 genctr;
  721. __le64 numrec;
  722. __le16 recfmt;
  723. __u8 resv14[1006];
  724. struct nvmf_disc_rsp_page_entry entries[0];
  725. };
  726. struct nvmf_connect_command {
  727. __u8 opcode;
  728. __u8 resv1;
  729. __u16 command_id;
  730. __u8 fctype;
  731. __u8 resv2[19];
  732. union nvme_data_ptr dptr;
  733. __le16 recfmt;
  734. __le16 qid;
  735. __le16 sqsize;
  736. __u8 cattr;
  737. __u8 resv3;
  738. __le32 kato;
  739. __u8 resv4[12];
  740. };
  741. struct nvmf_connect_data {
  742. __u8 hostid[16];
  743. __le16 cntlid;
  744. char resv4[238];
  745. char subsysnqn[NVMF_NQN_FIELD_LEN];
  746. char hostnqn[NVMF_NQN_FIELD_LEN];
  747. char resv5[256];
  748. };
  749. struct nvmf_property_set_command {
  750. __u8 opcode;
  751. __u8 resv1;
  752. __u16 command_id;
  753. __u8 fctype;
  754. __u8 resv2[35];
  755. __u8 attrib;
  756. __u8 resv3[3];
  757. __le32 offset;
  758. __le64 value;
  759. __u8 resv4[8];
  760. };
  761. struct nvmf_property_get_command {
  762. __u8 opcode;
  763. __u8 resv1;
  764. __u16 command_id;
  765. __u8 fctype;
  766. __u8 resv2[35];
  767. __u8 attrib;
  768. __u8 resv3[3];
  769. __le32 offset;
  770. __u8 resv4[16];
  771. };
  772. struct nvme_command {
  773. union {
  774. struct nvme_common_command common;
  775. struct nvme_rw_command rw;
  776. struct nvme_identify identify;
  777. struct nvme_features features;
  778. struct nvme_create_cq create_cq;
  779. struct nvme_create_sq create_sq;
  780. struct nvme_delete_queue delete_queue;
  781. struct nvme_download_firmware dlfw;
  782. struct nvme_format_cmd format;
  783. struct nvme_dsm_cmd dsm;
  784. struct nvme_abort_cmd abort;
  785. struct nvme_get_log_page_command get_log_page;
  786. struct nvmf_common_command fabrics;
  787. struct nvmf_connect_command connect;
  788. struct nvmf_property_set_command prop_set;
  789. struct nvmf_property_get_command prop_get;
  790. };
  791. };
  792. static inline bool nvme_is_write(struct nvme_command *cmd)
  793. {
  794. /*
  795. * What a mess...
  796. *
  797. * Why can't we simply have a Fabrics In and Fabrics out command?
  798. */
  799. if (unlikely(cmd->common.opcode == nvme_fabrics_command))
  800. return cmd->fabrics.opcode & 1;
  801. return cmd->common.opcode & 1;
  802. }
  803. enum {
  804. /*
  805. * Generic Command Status:
  806. */
  807. NVME_SC_SUCCESS = 0x0,
  808. NVME_SC_INVALID_OPCODE = 0x1,
  809. NVME_SC_INVALID_FIELD = 0x2,
  810. NVME_SC_CMDID_CONFLICT = 0x3,
  811. NVME_SC_DATA_XFER_ERROR = 0x4,
  812. NVME_SC_POWER_LOSS = 0x5,
  813. NVME_SC_INTERNAL = 0x6,
  814. NVME_SC_ABORT_REQ = 0x7,
  815. NVME_SC_ABORT_QUEUE = 0x8,
  816. NVME_SC_FUSED_FAIL = 0x9,
  817. NVME_SC_FUSED_MISSING = 0xa,
  818. NVME_SC_INVALID_NS = 0xb,
  819. NVME_SC_CMD_SEQ_ERROR = 0xc,
  820. NVME_SC_SGL_INVALID_LAST = 0xd,
  821. NVME_SC_SGL_INVALID_COUNT = 0xe,
  822. NVME_SC_SGL_INVALID_DATA = 0xf,
  823. NVME_SC_SGL_INVALID_METADATA = 0x10,
  824. NVME_SC_SGL_INVALID_TYPE = 0x11,
  825. NVME_SC_SGL_INVALID_OFFSET = 0x16,
  826. NVME_SC_SGL_INVALID_SUBTYPE = 0x17,
  827. NVME_SC_LBA_RANGE = 0x80,
  828. NVME_SC_CAP_EXCEEDED = 0x81,
  829. NVME_SC_NS_NOT_READY = 0x82,
  830. NVME_SC_RESERVATION_CONFLICT = 0x83,
  831. /*
  832. * Command Specific Status:
  833. */
  834. NVME_SC_CQ_INVALID = 0x100,
  835. NVME_SC_QID_INVALID = 0x101,
  836. NVME_SC_QUEUE_SIZE = 0x102,
  837. NVME_SC_ABORT_LIMIT = 0x103,
  838. NVME_SC_ABORT_MISSING = 0x104,
  839. NVME_SC_ASYNC_LIMIT = 0x105,
  840. NVME_SC_FIRMWARE_SLOT = 0x106,
  841. NVME_SC_FIRMWARE_IMAGE = 0x107,
  842. NVME_SC_INVALID_VECTOR = 0x108,
  843. NVME_SC_INVALID_LOG_PAGE = 0x109,
  844. NVME_SC_INVALID_FORMAT = 0x10a,
  845. NVME_SC_FW_NEEDS_CONV_RESET = 0x10b,
  846. NVME_SC_INVALID_QUEUE = 0x10c,
  847. NVME_SC_FEATURE_NOT_SAVEABLE = 0x10d,
  848. NVME_SC_FEATURE_NOT_CHANGEABLE = 0x10e,
  849. NVME_SC_FEATURE_NOT_PER_NS = 0x10f,
  850. NVME_SC_FW_NEEDS_SUBSYS_RESET = 0x110,
  851. NVME_SC_FW_NEEDS_RESET = 0x111,
  852. NVME_SC_FW_NEEDS_MAX_TIME = 0x112,
  853. NVME_SC_FW_ACIVATE_PROHIBITED = 0x113,
  854. NVME_SC_OVERLAPPING_RANGE = 0x114,
  855. NVME_SC_NS_INSUFFICENT_CAP = 0x115,
  856. NVME_SC_NS_ID_UNAVAILABLE = 0x116,
  857. NVME_SC_NS_ALREADY_ATTACHED = 0x118,
  858. NVME_SC_NS_IS_PRIVATE = 0x119,
  859. NVME_SC_NS_NOT_ATTACHED = 0x11a,
  860. NVME_SC_THIN_PROV_NOT_SUPP = 0x11b,
  861. NVME_SC_CTRL_LIST_INVALID = 0x11c,
  862. /*
  863. * I/O Command Set Specific - NVM commands:
  864. */
  865. NVME_SC_BAD_ATTRIBUTES = 0x180,
  866. NVME_SC_INVALID_PI = 0x181,
  867. NVME_SC_READ_ONLY = 0x182,
  868. /*
  869. * I/O Command Set Specific - Fabrics commands:
  870. */
  871. NVME_SC_CONNECT_FORMAT = 0x180,
  872. NVME_SC_CONNECT_CTRL_BUSY = 0x181,
  873. NVME_SC_CONNECT_INVALID_PARAM = 0x182,
  874. NVME_SC_CONNECT_RESTART_DISC = 0x183,
  875. NVME_SC_CONNECT_INVALID_HOST = 0x184,
  876. NVME_SC_DISCOVERY_RESTART = 0x190,
  877. NVME_SC_AUTH_REQUIRED = 0x191,
  878. /*
  879. * Media and Data Integrity Errors:
  880. */
  881. NVME_SC_WRITE_FAULT = 0x280,
  882. NVME_SC_READ_ERROR = 0x281,
  883. NVME_SC_GUARD_CHECK = 0x282,
  884. NVME_SC_APPTAG_CHECK = 0x283,
  885. NVME_SC_REFTAG_CHECK = 0x284,
  886. NVME_SC_COMPARE_FAILED = 0x285,
  887. NVME_SC_ACCESS_DENIED = 0x286,
  888. NVME_SC_UNWRITTEN_BLOCK = 0x287,
  889. NVME_SC_DNR = 0x4000,
  890. };
  891. struct nvme_completion {
  892. /*
  893. * Used by Admin and Fabrics commands to return data:
  894. */
  895. union {
  896. __le16 result16;
  897. __le32 result;
  898. __le64 result64;
  899. };
  900. __le16 sq_head; /* how much of this queue may be reclaimed */
  901. __le16 sq_id; /* submission queue that generated this entry */
  902. __u16 command_id; /* of the command which completed */
  903. __le16 status; /* did the command fail, and if so, why? */
  904. };
  905. #define NVME_VS(major, minor, tertiary) \
  906. (((major) << 16) | ((minor) << 8) | (tertiary))
  907. #endif /* _LINUX_NVME_H */