nvme.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  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. #include <linux/uuid.h>
  18. /* NQN names in commands fields specified one size */
  19. #define NVMF_NQN_FIELD_LEN 256
  20. /* However the max length of a qualified name is another size */
  21. #define NVMF_NQN_SIZE 223
  22. #define NVMF_TRSVCID_SIZE 32
  23. #define NVMF_TRADDR_SIZE 256
  24. #define NVMF_TSAS_SIZE 256
  25. #define NVME_DISC_SUBSYS_NAME "nqn.2014-08.org.nvmexpress.discovery"
  26. #define NVME_RDMA_IP_PORT 4420
  27. #define NVME_NSID_ALL 0xffffffff
  28. enum nvme_subsys_type {
  29. NVME_NQN_DISC = 1, /* Discovery type target subsystem */
  30. NVME_NQN_NVME = 2, /* NVME type target subsystem */
  31. };
  32. /* Address Family codes for Discovery Log Page entry ADRFAM field */
  33. enum {
  34. NVMF_ADDR_FAMILY_PCI = 0, /* PCIe */
  35. NVMF_ADDR_FAMILY_IP4 = 1, /* IP4 */
  36. NVMF_ADDR_FAMILY_IP6 = 2, /* IP6 */
  37. NVMF_ADDR_FAMILY_IB = 3, /* InfiniBand */
  38. NVMF_ADDR_FAMILY_FC = 4, /* Fibre Channel */
  39. };
  40. /* Transport Type codes for Discovery Log Page entry TRTYPE field */
  41. enum {
  42. NVMF_TRTYPE_RDMA = 1, /* RDMA */
  43. NVMF_TRTYPE_FC = 2, /* Fibre Channel */
  44. NVMF_TRTYPE_LOOP = 254, /* Reserved for host usage */
  45. NVMF_TRTYPE_MAX,
  46. };
  47. /* Transport Requirements codes for Discovery Log Page entry TREQ field */
  48. enum {
  49. NVMF_TREQ_NOT_SPECIFIED = 0, /* Not specified */
  50. NVMF_TREQ_REQUIRED = 1, /* Required */
  51. NVMF_TREQ_NOT_REQUIRED = 2, /* Not Required */
  52. };
  53. /* RDMA QP Service Type codes for Discovery Log Page entry TSAS
  54. * RDMA_QPTYPE field
  55. */
  56. enum {
  57. NVMF_RDMA_QPTYPE_CONNECTED = 1, /* Reliable Connected */
  58. NVMF_RDMA_QPTYPE_DATAGRAM = 2, /* Reliable Datagram */
  59. };
  60. /* RDMA QP Service Type codes for Discovery Log Page entry TSAS
  61. * RDMA_QPTYPE field
  62. */
  63. enum {
  64. NVMF_RDMA_PRTYPE_NOT_SPECIFIED = 1, /* No Provider Specified */
  65. NVMF_RDMA_PRTYPE_IB = 2, /* InfiniBand */
  66. NVMF_RDMA_PRTYPE_ROCE = 3, /* InfiniBand RoCE */
  67. NVMF_RDMA_PRTYPE_ROCEV2 = 4, /* InfiniBand RoCEV2 */
  68. NVMF_RDMA_PRTYPE_IWARP = 5, /* IWARP */
  69. };
  70. /* RDMA Connection Management Service Type codes for Discovery Log Page
  71. * entry TSAS RDMA_CMS field
  72. */
  73. enum {
  74. NVMF_RDMA_CMS_RDMA_CM = 1, /* Sockets based endpoint addressing */
  75. };
  76. #define NVME_AQ_DEPTH 32
  77. #define NVME_NR_AEN_COMMANDS 1
  78. #define NVME_AQ_BLK_MQ_DEPTH (NVME_AQ_DEPTH - NVME_NR_AEN_COMMANDS)
  79. /*
  80. * Subtract one to leave an empty queue entry for 'Full Queue' condition. See
  81. * NVM-Express 1.2 specification, section 4.1.2.
  82. */
  83. #define NVME_AQ_MQ_TAG_DEPTH (NVME_AQ_BLK_MQ_DEPTH - 1)
  84. enum {
  85. NVME_REG_CAP = 0x0000, /* Controller Capabilities */
  86. NVME_REG_VS = 0x0008, /* Version */
  87. NVME_REG_INTMS = 0x000c, /* Interrupt Mask Set */
  88. NVME_REG_INTMC = 0x0010, /* Interrupt Mask Clear */
  89. NVME_REG_CC = 0x0014, /* Controller Configuration */
  90. NVME_REG_CSTS = 0x001c, /* Controller Status */
  91. NVME_REG_NSSR = 0x0020, /* NVM Subsystem Reset */
  92. NVME_REG_AQA = 0x0024, /* Admin Queue Attributes */
  93. NVME_REG_ASQ = 0x0028, /* Admin SQ Base Address */
  94. NVME_REG_ACQ = 0x0030, /* Admin CQ Base Address */
  95. NVME_REG_CMBLOC = 0x0038, /* Controller Memory Buffer Location */
  96. NVME_REG_CMBSZ = 0x003c, /* Controller Memory Buffer Size */
  97. NVME_REG_DBS = 0x1000, /* SQ 0 Tail Doorbell */
  98. };
  99. #define NVME_CAP_MQES(cap) ((cap) & 0xffff)
  100. #define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff)
  101. #define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf)
  102. #define NVME_CAP_NSSRC(cap) (((cap) >> 36) & 0x1)
  103. #define NVME_CAP_MPSMIN(cap) (((cap) >> 48) & 0xf)
  104. #define NVME_CAP_MPSMAX(cap) (((cap) >> 52) & 0xf)
  105. #define NVME_CMB_BIR(cmbloc) ((cmbloc) & 0x7)
  106. #define NVME_CMB_OFST(cmbloc) (((cmbloc) >> 12) & 0xfffff)
  107. enum {
  108. NVME_CMBSZ_SQS = 1 << 0,
  109. NVME_CMBSZ_CQS = 1 << 1,
  110. NVME_CMBSZ_LISTS = 1 << 2,
  111. NVME_CMBSZ_RDS = 1 << 3,
  112. NVME_CMBSZ_WDS = 1 << 4,
  113. NVME_CMBSZ_SZ_SHIFT = 12,
  114. NVME_CMBSZ_SZ_MASK = 0xfffff,
  115. NVME_CMBSZ_SZU_SHIFT = 8,
  116. NVME_CMBSZ_SZU_MASK = 0xf,
  117. };
  118. /*
  119. * Submission and Completion Queue Entry Sizes for the NVM command set.
  120. * (In bytes and specified as a power of two (2^n)).
  121. */
  122. #define NVME_NVM_IOSQES 6
  123. #define NVME_NVM_IOCQES 4
  124. enum {
  125. NVME_CC_ENABLE = 1 << 0,
  126. NVME_CC_CSS_NVM = 0 << 4,
  127. NVME_CC_EN_SHIFT = 0,
  128. NVME_CC_CSS_SHIFT = 4,
  129. NVME_CC_MPS_SHIFT = 7,
  130. NVME_CC_AMS_SHIFT = 11,
  131. NVME_CC_SHN_SHIFT = 14,
  132. NVME_CC_IOSQES_SHIFT = 16,
  133. NVME_CC_IOCQES_SHIFT = 20,
  134. NVME_CC_AMS_RR = 0 << NVME_CC_AMS_SHIFT,
  135. NVME_CC_AMS_WRRU = 1 << NVME_CC_AMS_SHIFT,
  136. NVME_CC_AMS_VS = 7 << NVME_CC_AMS_SHIFT,
  137. NVME_CC_SHN_NONE = 0 << NVME_CC_SHN_SHIFT,
  138. NVME_CC_SHN_NORMAL = 1 << NVME_CC_SHN_SHIFT,
  139. NVME_CC_SHN_ABRUPT = 2 << NVME_CC_SHN_SHIFT,
  140. NVME_CC_SHN_MASK = 3 << NVME_CC_SHN_SHIFT,
  141. NVME_CC_IOSQES = NVME_NVM_IOSQES << NVME_CC_IOSQES_SHIFT,
  142. NVME_CC_IOCQES = NVME_NVM_IOCQES << NVME_CC_IOCQES_SHIFT,
  143. NVME_CSTS_RDY = 1 << 0,
  144. NVME_CSTS_CFS = 1 << 1,
  145. NVME_CSTS_NSSRO = 1 << 4,
  146. NVME_CSTS_PP = 1 << 5,
  147. NVME_CSTS_SHST_NORMAL = 0 << 2,
  148. NVME_CSTS_SHST_OCCUR = 1 << 2,
  149. NVME_CSTS_SHST_CMPLT = 2 << 2,
  150. NVME_CSTS_SHST_MASK = 3 << 2,
  151. };
  152. struct nvme_id_power_state {
  153. __le16 max_power; /* centiwatts */
  154. __u8 rsvd2;
  155. __u8 flags;
  156. __le32 entry_lat; /* microseconds */
  157. __le32 exit_lat; /* microseconds */
  158. __u8 read_tput;
  159. __u8 read_lat;
  160. __u8 write_tput;
  161. __u8 write_lat;
  162. __le16 idle_power;
  163. __u8 idle_scale;
  164. __u8 rsvd19;
  165. __le16 active_power;
  166. __u8 active_work_scale;
  167. __u8 rsvd23[9];
  168. };
  169. enum {
  170. NVME_PS_FLAGS_MAX_POWER_SCALE = 1 << 0,
  171. NVME_PS_FLAGS_NON_OP_STATE = 1 << 1,
  172. };
  173. struct nvme_id_ctrl {
  174. __le16 vid;
  175. __le16 ssvid;
  176. char sn[20];
  177. char mn[40];
  178. char fr[8];
  179. __u8 rab;
  180. __u8 ieee[3];
  181. __u8 cmic;
  182. __u8 mdts;
  183. __le16 cntlid;
  184. __le32 ver;
  185. __le32 rtd3r;
  186. __le32 rtd3e;
  187. __le32 oaes;
  188. __le32 ctratt;
  189. __u8 rsvd100[156];
  190. __le16 oacs;
  191. __u8 acl;
  192. __u8 aerl;
  193. __u8 frmw;
  194. __u8 lpa;
  195. __u8 elpe;
  196. __u8 npss;
  197. __u8 avscc;
  198. __u8 apsta;
  199. __le16 wctemp;
  200. __le16 cctemp;
  201. __le16 mtfa;
  202. __le32 hmpre;
  203. __le32 hmmin;
  204. __u8 tnvmcap[16];
  205. __u8 unvmcap[16];
  206. __le32 rpmbs;
  207. __le16 edstt;
  208. __u8 dsto;
  209. __u8 fwug;
  210. __le16 kas;
  211. __le16 hctma;
  212. __le16 mntmt;
  213. __le16 mxtmt;
  214. __le32 sanicap;
  215. __le32 hmminds;
  216. __le16 hmmaxd;
  217. __u8 rsvd338[4];
  218. __u8 anatt;
  219. __u8 anacap;
  220. __le32 anagrpmax;
  221. __le32 nanagrpid;
  222. __u8 rsvd352[160];
  223. __u8 sqes;
  224. __u8 cqes;
  225. __le16 maxcmd;
  226. __le32 nn;
  227. __le16 oncs;
  228. __le16 fuses;
  229. __u8 fna;
  230. __u8 vwc;
  231. __le16 awun;
  232. __le16 awupf;
  233. __u8 nvscc;
  234. __u8 nwpc;
  235. __le16 acwu;
  236. __u8 rsvd534[2];
  237. __le32 sgls;
  238. __le32 mnan;
  239. __u8 rsvd544[224];
  240. char subnqn[256];
  241. __u8 rsvd1024[768];
  242. __le32 ioccsz;
  243. __le32 iorcsz;
  244. __le16 icdoff;
  245. __u8 ctrattr;
  246. __u8 msdbd;
  247. __u8 rsvd1804[244];
  248. struct nvme_id_power_state psd[32];
  249. __u8 vs[1024];
  250. };
  251. enum {
  252. NVME_CTRL_ONCS_COMPARE = 1 << 0,
  253. NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1,
  254. NVME_CTRL_ONCS_DSM = 1 << 2,
  255. NVME_CTRL_ONCS_WRITE_ZEROES = 1 << 3,
  256. NVME_CTRL_ONCS_TIMESTAMP = 1 << 6,
  257. NVME_CTRL_VWC_PRESENT = 1 << 0,
  258. NVME_CTRL_OACS_SEC_SUPP = 1 << 0,
  259. NVME_CTRL_OACS_DIRECTIVES = 1 << 5,
  260. NVME_CTRL_OACS_DBBUF_SUPP = 1 << 8,
  261. NVME_CTRL_LPA_CMD_EFFECTS_LOG = 1 << 1,
  262. };
  263. struct nvme_lbaf {
  264. __le16 ms;
  265. __u8 ds;
  266. __u8 rp;
  267. };
  268. struct nvme_id_ns {
  269. __le64 nsze;
  270. __le64 ncap;
  271. __le64 nuse;
  272. __u8 nsfeat;
  273. __u8 nlbaf;
  274. __u8 flbas;
  275. __u8 mc;
  276. __u8 dpc;
  277. __u8 dps;
  278. __u8 nmic;
  279. __u8 rescap;
  280. __u8 fpi;
  281. __u8 rsvd33;
  282. __le16 nawun;
  283. __le16 nawupf;
  284. __le16 nacwu;
  285. __le16 nabsn;
  286. __le16 nabo;
  287. __le16 nabspf;
  288. __le16 noiob;
  289. __u8 nvmcap[16];
  290. __u8 rsvd64[28];
  291. __le32 anagrpid;
  292. __u8 rsvd96[3];
  293. __u8 nsattr;
  294. __u8 rsvd100[4];
  295. __u8 nguid[16];
  296. __u8 eui64[8];
  297. struct nvme_lbaf lbaf[16];
  298. __u8 rsvd192[192];
  299. __u8 vs[3712];
  300. };
  301. enum {
  302. NVME_ID_CNS_NS = 0x00,
  303. NVME_ID_CNS_CTRL = 0x01,
  304. NVME_ID_CNS_NS_ACTIVE_LIST = 0x02,
  305. NVME_ID_CNS_NS_DESC_LIST = 0x03,
  306. NVME_ID_CNS_NS_PRESENT_LIST = 0x10,
  307. NVME_ID_CNS_NS_PRESENT = 0x11,
  308. NVME_ID_CNS_CTRL_NS_LIST = 0x12,
  309. NVME_ID_CNS_CTRL_LIST = 0x13,
  310. };
  311. enum {
  312. NVME_DIR_IDENTIFY = 0x00,
  313. NVME_DIR_STREAMS = 0x01,
  314. NVME_DIR_SND_ID_OP_ENABLE = 0x01,
  315. NVME_DIR_SND_ST_OP_REL_ID = 0x01,
  316. NVME_DIR_SND_ST_OP_REL_RSC = 0x02,
  317. NVME_DIR_RCV_ID_OP_PARAM = 0x01,
  318. NVME_DIR_RCV_ST_OP_PARAM = 0x01,
  319. NVME_DIR_RCV_ST_OP_STATUS = 0x02,
  320. NVME_DIR_RCV_ST_OP_RESOURCE = 0x03,
  321. NVME_DIR_ENDIR = 0x01,
  322. };
  323. enum {
  324. NVME_NS_FEAT_THIN = 1 << 0,
  325. NVME_NS_FLBAS_LBA_MASK = 0xf,
  326. NVME_NS_FLBAS_META_EXT = 0x10,
  327. NVME_LBAF_RP_BEST = 0,
  328. NVME_LBAF_RP_BETTER = 1,
  329. NVME_LBAF_RP_GOOD = 2,
  330. NVME_LBAF_RP_DEGRADED = 3,
  331. NVME_NS_DPC_PI_LAST = 1 << 4,
  332. NVME_NS_DPC_PI_FIRST = 1 << 3,
  333. NVME_NS_DPC_PI_TYPE3 = 1 << 2,
  334. NVME_NS_DPC_PI_TYPE2 = 1 << 1,
  335. NVME_NS_DPC_PI_TYPE1 = 1 << 0,
  336. NVME_NS_DPS_PI_FIRST = 1 << 3,
  337. NVME_NS_DPS_PI_MASK = 0x7,
  338. NVME_NS_DPS_PI_TYPE1 = 1,
  339. NVME_NS_DPS_PI_TYPE2 = 2,
  340. NVME_NS_DPS_PI_TYPE3 = 3,
  341. };
  342. struct nvme_ns_id_desc {
  343. __u8 nidt;
  344. __u8 nidl;
  345. __le16 reserved;
  346. };
  347. #define NVME_NIDT_EUI64_LEN 8
  348. #define NVME_NIDT_NGUID_LEN 16
  349. #define NVME_NIDT_UUID_LEN 16
  350. enum {
  351. NVME_NIDT_EUI64 = 0x01,
  352. NVME_NIDT_NGUID = 0x02,
  353. NVME_NIDT_UUID = 0x03,
  354. };
  355. struct nvme_smart_log {
  356. __u8 critical_warning;
  357. __u8 temperature[2];
  358. __u8 avail_spare;
  359. __u8 spare_thresh;
  360. __u8 percent_used;
  361. __u8 rsvd6[26];
  362. __u8 data_units_read[16];
  363. __u8 data_units_written[16];
  364. __u8 host_reads[16];
  365. __u8 host_writes[16];
  366. __u8 ctrl_busy_time[16];
  367. __u8 power_cycles[16];
  368. __u8 power_on_hours[16];
  369. __u8 unsafe_shutdowns[16];
  370. __u8 media_errors[16];
  371. __u8 num_err_log_entries[16];
  372. __le32 warning_temp_time;
  373. __le32 critical_comp_time;
  374. __le16 temp_sensor[8];
  375. __u8 rsvd216[296];
  376. };
  377. struct nvme_fw_slot_info_log {
  378. __u8 afi;
  379. __u8 rsvd1[7];
  380. __le64 frs[7];
  381. __u8 rsvd64[448];
  382. };
  383. enum {
  384. NVME_CMD_EFFECTS_CSUPP = 1 << 0,
  385. NVME_CMD_EFFECTS_LBCC = 1 << 1,
  386. NVME_CMD_EFFECTS_NCC = 1 << 2,
  387. NVME_CMD_EFFECTS_NIC = 1 << 3,
  388. NVME_CMD_EFFECTS_CCC = 1 << 4,
  389. NVME_CMD_EFFECTS_CSE_MASK = 3 << 16,
  390. };
  391. struct nvme_effects_log {
  392. __le32 acs[256];
  393. __le32 iocs[256];
  394. __u8 resv[2048];
  395. };
  396. enum nvme_ana_state {
  397. NVME_ANA_OPTIMIZED = 0x01,
  398. NVME_ANA_NONOPTIMIZED = 0x02,
  399. NVME_ANA_INACCESSIBLE = 0x03,
  400. NVME_ANA_PERSISTENT_LOSS = 0x04,
  401. NVME_ANA_CHANGE = 0x0f,
  402. };
  403. struct nvme_ana_group_desc {
  404. __le32 grpid;
  405. __le32 nnsids;
  406. __le64 chgcnt;
  407. __u8 state;
  408. __u8 rsvd17[15];
  409. __le32 nsids[];
  410. };
  411. /* flag for the log specific field of the ANA log */
  412. #define NVME_ANA_LOG_RGO (1 << 0)
  413. struct nvme_ana_rsp_hdr {
  414. __le64 chgcnt;
  415. __le16 ngrps;
  416. __le16 rsvd10[3];
  417. };
  418. enum {
  419. NVME_SMART_CRIT_SPARE = 1 << 0,
  420. NVME_SMART_CRIT_TEMPERATURE = 1 << 1,
  421. NVME_SMART_CRIT_RELIABILITY = 1 << 2,
  422. NVME_SMART_CRIT_MEDIA = 1 << 3,
  423. NVME_SMART_CRIT_VOLATILE_MEMORY = 1 << 4,
  424. };
  425. enum {
  426. NVME_AER_ERROR = 0,
  427. NVME_AER_SMART = 1,
  428. NVME_AER_NOTICE = 2,
  429. NVME_AER_CSS = 6,
  430. NVME_AER_VS = 7,
  431. };
  432. enum {
  433. NVME_AER_NOTICE_NS_CHANGED = 0x00,
  434. NVME_AER_NOTICE_FW_ACT_STARTING = 0x01,
  435. NVME_AER_NOTICE_ANA = 0x03,
  436. };
  437. enum {
  438. NVME_AEN_CFG_NS_ATTR = 1 << 8,
  439. NVME_AEN_CFG_FW_ACT = 1 << 9,
  440. NVME_AEN_CFG_ANA_CHANGE = 1 << 11,
  441. };
  442. struct nvme_lba_range_type {
  443. __u8 type;
  444. __u8 attributes;
  445. __u8 rsvd2[14];
  446. __u64 slba;
  447. __u64 nlb;
  448. __u8 guid[16];
  449. __u8 rsvd48[16];
  450. };
  451. enum {
  452. NVME_LBART_TYPE_FS = 0x01,
  453. NVME_LBART_TYPE_RAID = 0x02,
  454. NVME_LBART_TYPE_CACHE = 0x03,
  455. NVME_LBART_TYPE_SWAP = 0x04,
  456. NVME_LBART_ATTRIB_TEMP = 1 << 0,
  457. NVME_LBART_ATTRIB_HIDE = 1 << 1,
  458. };
  459. struct nvme_reservation_status {
  460. __le32 gen;
  461. __u8 rtype;
  462. __u8 regctl[2];
  463. __u8 resv5[2];
  464. __u8 ptpls;
  465. __u8 resv10[13];
  466. struct {
  467. __le16 cntlid;
  468. __u8 rcsts;
  469. __u8 resv3[5];
  470. __le64 hostid;
  471. __le64 rkey;
  472. } regctl_ds[];
  473. };
  474. enum nvme_async_event_type {
  475. NVME_AER_TYPE_ERROR = 0,
  476. NVME_AER_TYPE_SMART = 1,
  477. NVME_AER_TYPE_NOTICE = 2,
  478. };
  479. /* I/O commands */
  480. enum nvme_opcode {
  481. nvme_cmd_flush = 0x00,
  482. nvme_cmd_write = 0x01,
  483. nvme_cmd_read = 0x02,
  484. nvme_cmd_write_uncor = 0x04,
  485. nvme_cmd_compare = 0x05,
  486. nvme_cmd_write_zeroes = 0x08,
  487. nvme_cmd_dsm = 0x09,
  488. nvme_cmd_resv_register = 0x0d,
  489. nvme_cmd_resv_report = 0x0e,
  490. nvme_cmd_resv_acquire = 0x11,
  491. nvme_cmd_resv_release = 0x15,
  492. };
  493. /*
  494. * Descriptor subtype - lower 4 bits of nvme_(keyed_)sgl_desc identifier
  495. *
  496. * @NVME_SGL_FMT_ADDRESS: absolute address of the data block
  497. * @NVME_SGL_FMT_OFFSET: relative offset of the in-capsule data block
  498. * @NVME_SGL_FMT_TRANSPORT_A: transport defined format, value 0xA
  499. * @NVME_SGL_FMT_INVALIDATE: RDMA transport specific remote invalidation
  500. * request subtype
  501. */
  502. enum {
  503. NVME_SGL_FMT_ADDRESS = 0x00,
  504. NVME_SGL_FMT_OFFSET = 0x01,
  505. NVME_SGL_FMT_TRANSPORT_A = 0x0A,
  506. NVME_SGL_FMT_INVALIDATE = 0x0f,
  507. };
  508. /*
  509. * Descriptor type - upper 4 bits of nvme_(keyed_)sgl_desc identifier
  510. *
  511. * For struct nvme_sgl_desc:
  512. * @NVME_SGL_FMT_DATA_DESC: data block descriptor
  513. * @NVME_SGL_FMT_SEG_DESC: sgl segment descriptor
  514. * @NVME_SGL_FMT_LAST_SEG_DESC: last sgl segment descriptor
  515. *
  516. * For struct nvme_keyed_sgl_desc:
  517. * @NVME_KEY_SGL_FMT_DATA_DESC: keyed data block descriptor
  518. *
  519. * Transport-specific SGL types:
  520. * @NVME_TRANSPORT_SGL_DATA_DESC: Transport SGL data dlock descriptor
  521. */
  522. enum {
  523. NVME_SGL_FMT_DATA_DESC = 0x00,
  524. NVME_SGL_FMT_SEG_DESC = 0x02,
  525. NVME_SGL_FMT_LAST_SEG_DESC = 0x03,
  526. NVME_KEY_SGL_FMT_DATA_DESC = 0x04,
  527. NVME_TRANSPORT_SGL_DATA_DESC = 0x05,
  528. };
  529. struct nvme_sgl_desc {
  530. __le64 addr;
  531. __le32 length;
  532. __u8 rsvd[3];
  533. __u8 type;
  534. };
  535. struct nvme_keyed_sgl_desc {
  536. __le64 addr;
  537. __u8 length[3];
  538. __u8 key[4];
  539. __u8 type;
  540. };
  541. union nvme_data_ptr {
  542. struct {
  543. __le64 prp1;
  544. __le64 prp2;
  545. };
  546. struct nvme_sgl_desc sgl;
  547. struct nvme_keyed_sgl_desc ksgl;
  548. };
  549. /*
  550. * Lowest two bits of our flags field (FUSE field in the spec):
  551. *
  552. * @NVME_CMD_FUSE_FIRST: Fused Operation, first command
  553. * @NVME_CMD_FUSE_SECOND: Fused Operation, second command
  554. *
  555. * Highest two bits in our flags field (PSDT field in the spec):
  556. *
  557. * @NVME_CMD_PSDT_SGL_METABUF: Use SGLS for this transfer,
  558. * If used, MPTR contains addr of single physical buffer (byte aligned).
  559. * @NVME_CMD_PSDT_SGL_METASEG: Use SGLS for this transfer,
  560. * If used, MPTR contains an address of an SGL segment containing
  561. * exactly 1 SGL descriptor (qword aligned).
  562. */
  563. enum {
  564. NVME_CMD_FUSE_FIRST = (1 << 0),
  565. NVME_CMD_FUSE_SECOND = (1 << 1),
  566. NVME_CMD_SGL_METABUF = (1 << 6),
  567. NVME_CMD_SGL_METASEG = (1 << 7),
  568. NVME_CMD_SGL_ALL = NVME_CMD_SGL_METABUF | NVME_CMD_SGL_METASEG,
  569. };
  570. struct nvme_common_command {
  571. __u8 opcode;
  572. __u8 flags;
  573. __u16 command_id;
  574. __le32 nsid;
  575. __le32 cdw2[2];
  576. __le64 metadata;
  577. union nvme_data_ptr dptr;
  578. __le32 cdw10[6];
  579. };
  580. struct nvme_rw_command {
  581. __u8 opcode;
  582. __u8 flags;
  583. __u16 command_id;
  584. __le32 nsid;
  585. __u64 rsvd2;
  586. __le64 metadata;
  587. union nvme_data_ptr dptr;
  588. __le64 slba;
  589. __le16 length;
  590. __le16 control;
  591. __le32 dsmgmt;
  592. __le32 reftag;
  593. __le16 apptag;
  594. __le16 appmask;
  595. };
  596. enum {
  597. NVME_RW_LR = 1 << 15,
  598. NVME_RW_FUA = 1 << 14,
  599. NVME_RW_DSM_FREQ_UNSPEC = 0,
  600. NVME_RW_DSM_FREQ_TYPICAL = 1,
  601. NVME_RW_DSM_FREQ_RARE = 2,
  602. NVME_RW_DSM_FREQ_READS = 3,
  603. NVME_RW_DSM_FREQ_WRITES = 4,
  604. NVME_RW_DSM_FREQ_RW = 5,
  605. NVME_RW_DSM_FREQ_ONCE = 6,
  606. NVME_RW_DSM_FREQ_PREFETCH = 7,
  607. NVME_RW_DSM_FREQ_TEMP = 8,
  608. NVME_RW_DSM_LATENCY_NONE = 0 << 4,
  609. NVME_RW_DSM_LATENCY_IDLE = 1 << 4,
  610. NVME_RW_DSM_LATENCY_NORM = 2 << 4,
  611. NVME_RW_DSM_LATENCY_LOW = 3 << 4,
  612. NVME_RW_DSM_SEQ_REQ = 1 << 6,
  613. NVME_RW_DSM_COMPRESSED = 1 << 7,
  614. NVME_RW_PRINFO_PRCHK_REF = 1 << 10,
  615. NVME_RW_PRINFO_PRCHK_APP = 1 << 11,
  616. NVME_RW_PRINFO_PRCHK_GUARD = 1 << 12,
  617. NVME_RW_PRINFO_PRACT = 1 << 13,
  618. NVME_RW_DTYPE_STREAMS = 1 << 4,
  619. };
  620. struct nvme_dsm_cmd {
  621. __u8 opcode;
  622. __u8 flags;
  623. __u16 command_id;
  624. __le32 nsid;
  625. __u64 rsvd2[2];
  626. union nvme_data_ptr dptr;
  627. __le32 nr;
  628. __le32 attributes;
  629. __u32 rsvd12[4];
  630. };
  631. enum {
  632. NVME_DSMGMT_IDR = 1 << 0,
  633. NVME_DSMGMT_IDW = 1 << 1,
  634. NVME_DSMGMT_AD = 1 << 2,
  635. };
  636. #define NVME_DSM_MAX_RANGES 256
  637. struct nvme_dsm_range {
  638. __le32 cattr;
  639. __le32 nlb;
  640. __le64 slba;
  641. };
  642. struct nvme_write_zeroes_cmd {
  643. __u8 opcode;
  644. __u8 flags;
  645. __u16 command_id;
  646. __le32 nsid;
  647. __u64 rsvd2;
  648. __le64 metadata;
  649. union nvme_data_ptr dptr;
  650. __le64 slba;
  651. __le16 length;
  652. __le16 control;
  653. __le32 dsmgmt;
  654. __le32 reftag;
  655. __le16 apptag;
  656. __le16 appmask;
  657. };
  658. /* Features */
  659. struct nvme_feat_auto_pst {
  660. __le64 entries[32];
  661. };
  662. enum {
  663. NVME_HOST_MEM_ENABLE = (1 << 0),
  664. NVME_HOST_MEM_RETURN = (1 << 1),
  665. };
  666. /* Admin commands */
  667. enum nvme_admin_opcode {
  668. nvme_admin_delete_sq = 0x00,
  669. nvme_admin_create_sq = 0x01,
  670. nvme_admin_get_log_page = 0x02,
  671. nvme_admin_delete_cq = 0x04,
  672. nvme_admin_create_cq = 0x05,
  673. nvme_admin_identify = 0x06,
  674. nvme_admin_abort_cmd = 0x08,
  675. nvme_admin_set_features = 0x09,
  676. nvme_admin_get_features = 0x0a,
  677. nvme_admin_async_event = 0x0c,
  678. nvme_admin_ns_mgmt = 0x0d,
  679. nvme_admin_activate_fw = 0x10,
  680. nvme_admin_download_fw = 0x11,
  681. nvme_admin_ns_attach = 0x15,
  682. nvme_admin_keep_alive = 0x18,
  683. nvme_admin_directive_send = 0x19,
  684. nvme_admin_directive_recv = 0x1a,
  685. nvme_admin_dbbuf = 0x7C,
  686. nvme_admin_format_nvm = 0x80,
  687. nvme_admin_security_send = 0x81,
  688. nvme_admin_security_recv = 0x82,
  689. nvme_admin_sanitize_nvm = 0x84,
  690. };
  691. enum {
  692. NVME_QUEUE_PHYS_CONTIG = (1 << 0),
  693. NVME_CQ_IRQ_ENABLED = (1 << 1),
  694. NVME_SQ_PRIO_URGENT = (0 << 1),
  695. NVME_SQ_PRIO_HIGH = (1 << 1),
  696. NVME_SQ_PRIO_MEDIUM = (2 << 1),
  697. NVME_SQ_PRIO_LOW = (3 << 1),
  698. NVME_FEAT_ARBITRATION = 0x01,
  699. NVME_FEAT_POWER_MGMT = 0x02,
  700. NVME_FEAT_LBA_RANGE = 0x03,
  701. NVME_FEAT_TEMP_THRESH = 0x04,
  702. NVME_FEAT_ERR_RECOVERY = 0x05,
  703. NVME_FEAT_VOLATILE_WC = 0x06,
  704. NVME_FEAT_NUM_QUEUES = 0x07,
  705. NVME_FEAT_IRQ_COALESCE = 0x08,
  706. NVME_FEAT_IRQ_CONFIG = 0x09,
  707. NVME_FEAT_WRITE_ATOMIC = 0x0a,
  708. NVME_FEAT_ASYNC_EVENT = 0x0b,
  709. NVME_FEAT_AUTO_PST = 0x0c,
  710. NVME_FEAT_HOST_MEM_BUF = 0x0d,
  711. NVME_FEAT_TIMESTAMP = 0x0e,
  712. NVME_FEAT_KATO = 0x0f,
  713. NVME_FEAT_HCTM = 0x10,
  714. NVME_FEAT_NOPSC = 0x11,
  715. NVME_FEAT_RRL = 0x12,
  716. NVME_FEAT_PLM_CONFIG = 0x13,
  717. NVME_FEAT_PLM_WINDOW = 0x14,
  718. NVME_FEAT_SW_PROGRESS = 0x80,
  719. NVME_FEAT_HOST_ID = 0x81,
  720. NVME_FEAT_RESV_MASK = 0x82,
  721. NVME_FEAT_RESV_PERSIST = 0x83,
  722. NVME_FEAT_WRITE_PROTECT = 0x84,
  723. NVME_LOG_ERROR = 0x01,
  724. NVME_LOG_SMART = 0x02,
  725. NVME_LOG_FW_SLOT = 0x03,
  726. NVME_LOG_CHANGED_NS = 0x04,
  727. NVME_LOG_CMD_EFFECTS = 0x05,
  728. NVME_LOG_ANA = 0x0c,
  729. NVME_LOG_DISC = 0x70,
  730. NVME_LOG_RESERVATION = 0x80,
  731. NVME_FWACT_REPL = (0 << 3),
  732. NVME_FWACT_REPL_ACTV = (1 << 3),
  733. NVME_FWACT_ACTV = (2 << 3),
  734. };
  735. /* NVMe Namespace Write Protect State */
  736. enum {
  737. NVME_NS_NO_WRITE_PROTECT = 0,
  738. NVME_NS_WRITE_PROTECT,
  739. NVME_NS_WRITE_PROTECT_POWER_CYCLE,
  740. NVME_NS_WRITE_PROTECT_PERMANENT,
  741. };
  742. #define NVME_MAX_CHANGED_NAMESPACES 1024
  743. struct nvme_identify {
  744. __u8 opcode;
  745. __u8 flags;
  746. __u16 command_id;
  747. __le32 nsid;
  748. __u64 rsvd2[2];
  749. union nvme_data_ptr dptr;
  750. __u8 cns;
  751. __u8 rsvd3;
  752. __le16 ctrlid;
  753. __u32 rsvd11[5];
  754. };
  755. #define NVME_IDENTIFY_DATA_SIZE 4096
  756. struct nvme_features {
  757. __u8 opcode;
  758. __u8 flags;
  759. __u16 command_id;
  760. __le32 nsid;
  761. __u64 rsvd2[2];
  762. union nvme_data_ptr dptr;
  763. __le32 fid;
  764. __le32 dword11;
  765. __le32 dword12;
  766. __le32 dword13;
  767. __le32 dword14;
  768. __le32 dword15;
  769. };
  770. struct nvme_host_mem_buf_desc {
  771. __le64 addr;
  772. __le32 size;
  773. __u32 rsvd;
  774. };
  775. struct nvme_create_cq {
  776. __u8 opcode;
  777. __u8 flags;
  778. __u16 command_id;
  779. __u32 rsvd1[5];
  780. __le64 prp1;
  781. __u64 rsvd8;
  782. __le16 cqid;
  783. __le16 qsize;
  784. __le16 cq_flags;
  785. __le16 irq_vector;
  786. __u32 rsvd12[4];
  787. };
  788. struct nvme_create_sq {
  789. __u8 opcode;
  790. __u8 flags;
  791. __u16 command_id;
  792. __u32 rsvd1[5];
  793. __le64 prp1;
  794. __u64 rsvd8;
  795. __le16 sqid;
  796. __le16 qsize;
  797. __le16 sq_flags;
  798. __le16 cqid;
  799. __u32 rsvd12[4];
  800. };
  801. struct nvme_delete_queue {
  802. __u8 opcode;
  803. __u8 flags;
  804. __u16 command_id;
  805. __u32 rsvd1[9];
  806. __le16 qid;
  807. __u16 rsvd10;
  808. __u32 rsvd11[5];
  809. };
  810. struct nvme_abort_cmd {
  811. __u8 opcode;
  812. __u8 flags;
  813. __u16 command_id;
  814. __u32 rsvd1[9];
  815. __le16 sqid;
  816. __u16 cid;
  817. __u32 rsvd11[5];
  818. };
  819. struct nvme_download_firmware {
  820. __u8 opcode;
  821. __u8 flags;
  822. __u16 command_id;
  823. __u32 rsvd1[5];
  824. union nvme_data_ptr dptr;
  825. __le32 numd;
  826. __le32 offset;
  827. __u32 rsvd12[4];
  828. };
  829. struct nvme_format_cmd {
  830. __u8 opcode;
  831. __u8 flags;
  832. __u16 command_id;
  833. __le32 nsid;
  834. __u64 rsvd2[4];
  835. __le32 cdw10;
  836. __u32 rsvd11[5];
  837. };
  838. struct nvme_get_log_page_command {
  839. __u8 opcode;
  840. __u8 flags;
  841. __u16 command_id;
  842. __le32 nsid;
  843. __u64 rsvd2[2];
  844. union nvme_data_ptr dptr;
  845. __u8 lid;
  846. __u8 lsp; /* upper 4 bits reserved */
  847. __le16 numdl;
  848. __le16 numdu;
  849. __u16 rsvd11;
  850. __le32 lpol;
  851. __le32 lpou;
  852. __u32 rsvd14[2];
  853. };
  854. struct nvme_directive_cmd {
  855. __u8 opcode;
  856. __u8 flags;
  857. __u16 command_id;
  858. __le32 nsid;
  859. __u64 rsvd2[2];
  860. union nvme_data_ptr dptr;
  861. __le32 numd;
  862. __u8 doper;
  863. __u8 dtype;
  864. __le16 dspec;
  865. __u8 endir;
  866. __u8 tdtype;
  867. __u16 rsvd15;
  868. __u32 rsvd16[3];
  869. };
  870. /*
  871. * Fabrics subcommands.
  872. */
  873. enum nvmf_fabrics_opcode {
  874. nvme_fabrics_command = 0x7f,
  875. };
  876. enum nvmf_capsule_command {
  877. nvme_fabrics_type_property_set = 0x00,
  878. nvme_fabrics_type_connect = 0x01,
  879. nvme_fabrics_type_property_get = 0x04,
  880. };
  881. struct nvmf_common_command {
  882. __u8 opcode;
  883. __u8 resv1;
  884. __u16 command_id;
  885. __u8 fctype;
  886. __u8 resv2[35];
  887. __u8 ts[24];
  888. };
  889. /*
  890. * The legal cntlid range a NVMe Target will provide.
  891. * Note that cntlid of value 0 is considered illegal in the fabrics world.
  892. * Devices based on earlier specs did not have the subsystem concept;
  893. * therefore, those devices had their cntlid value set to 0 as a result.
  894. */
  895. #define NVME_CNTLID_MIN 1
  896. #define NVME_CNTLID_MAX 0xffef
  897. #define NVME_CNTLID_DYNAMIC 0xffff
  898. #define MAX_DISC_LOGS 255
  899. /* Discovery log page entry */
  900. struct nvmf_disc_rsp_page_entry {
  901. __u8 trtype;
  902. __u8 adrfam;
  903. __u8 subtype;
  904. __u8 treq;
  905. __le16 portid;
  906. __le16 cntlid;
  907. __le16 asqsz;
  908. __u8 resv8[22];
  909. char trsvcid[NVMF_TRSVCID_SIZE];
  910. __u8 resv64[192];
  911. char subnqn[NVMF_NQN_FIELD_LEN];
  912. char traddr[NVMF_TRADDR_SIZE];
  913. union tsas {
  914. char common[NVMF_TSAS_SIZE];
  915. struct rdma {
  916. __u8 qptype;
  917. __u8 prtype;
  918. __u8 cms;
  919. __u8 resv3[5];
  920. __u16 pkey;
  921. __u8 resv10[246];
  922. } rdma;
  923. } tsas;
  924. };
  925. /* Discovery log page header */
  926. struct nvmf_disc_rsp_page_hdr {
  927. __le64 genctr;
  928. __le64 numrec;
  929. __le16 recfmt;
  930. __u8 resv14[1006];
  931. struct nvmf_disc_rsp_page_entry entries[0];
  932. };
  933. struct nvmf_connect_command {
  934. __u8 opcode;
  935. __u8 resv1;
  936. __u16 command_id;
  937. __u8 fctype;
  938. __u8 resv2[19];
  939. union nvme_data_ptr dptr;
  940. __le16 recfmt;
  941. __le16 qid;
  942. __le16 sqsize;
  943. __u8 cattr;
  944. __u8 resv3;
  945. __le32 kato;
  946. __u8 resv4[12];
  947. };
  948. struct nvmf_connect_data {
  949. uuid_t hostid;
  950. __le16 cntlid;
  951. char resv4[238];
  952. char subsysnqn[NVMF_NQN_FIELD_LEN];
  953. char hostnqn[NVMF_NQN_FIELD_LEN];
  954. char resv5[256];
  955. };
  956. struct nvmf_property_set_command {
  957. __u8 opcode;
  958. __u8 resv1;
  959. __u16 command_id;
  960. __u8 fctype;
  961. __u8 resv2[35];
  962. __u8 attrib;
  963. __u8 resv3[3];
  964. __le32 offset;
  965. __le64 value;
  966. __u8 resv4[8];
  967. };
  968. struct nvmf_property_get_command {
  969. __u8 opcode;
  970. __u8 resv1;
  971. __u16 command_id;
  972. __u8 fctype;
  973. __u8 resv2[35];
  974. __u8 attrib;
  975. __u8 resv3[3];
  976. __le32 offset;
  977. __u8 resv4[16];
  978. };
  979. struct nvme_dbbuf {
  980. __u8 opcode;
  981. __u8 flags;
  982. __u16 command_id;
  983. __u32 rsvd1[5];
  984. __le64 prp1;
  985. __le64 prp2;
  986. __u32 rsvd12[6];
  987. };
  988. struct streams_directive_params {
  989. __le16 msl;
  990. __le16 nssa;
  991. __le16 nsso;
  992. __u8 rsvd[10];
  993. __le32 sws;
  994. __le16 sgs;
  995. __le16 nsa;
  996. __le16 nso;
  997. __u8 rsvd2[6];
  998. };
  999. struct nvme_command {
  1000. union {
  1001. struct nvme_common_command common;
  1002. struct nvme_rw_command rw;
  1003. struct nvme_identify identify;
  1004. struct nvme_features features;
  1005. struct nvme_create_cq create_cq;
  1006. struct nvme_create_sq create_sq;
  1007. struct nvme_delete_queue delete_queue;
  1008. struct nvme_download_firmware dlfw;
  1009. struct nvme_format_cmd format;
  1010. struct nvme_dsm_cmd dsm;
  1011. struct nvme_write_zeroes_cmd write_zeroes;
  1012. struct nvme_abort_cmd abort;
  1013. struct nvme_get_log_page_command get_log_page;
  1014. struct nvmf_common_command fabrics;
  1015. struct nvmf_connect_command connect;
  1016. struct nvmf_property_set_command prop_set;
  1017. struct nvmf_property_get_command prop_get;
  1018. struct nvme_dbbuf dbbuf;
  1019. struct nvme_directive_cmd directive;
  1020. };
  1021. };
  1022. static inline bool nvme_is_write(struct nvme_command *cmd)
  1023. {
  1024. /*
  1025. * What a mess...
  1026. *
  1027. * Why can't we simply have a Fabrics In and Fabrics out command?
  1028. */
  1029. if (unlikely(cmd->common.opcode == nvme_fabrics_command))
  1030. return cmd->fabrics.fctype & 1;
  1031. return cmd->common.opcode & 1;
  1032. }
  1033. enum {
  1034. /*
  1035. * Generic Command Status:
  1036. */
  1037. NVME_SC_SUCCESS = 0x0,
  1038. NVME_SC_INVALID_OPCODE = 0x1,
  1039. NVME_SC_INVALID_FIELD = 0x2,
  1040. NVME_SC_CMDID_CONFLICT = 0x3,
  1041. NVME_SC_DATA_XFER_ERROR = 0x4,
  1042. NVME_SC_POWER_LOSS = 0x5,
  1043. NVME_SC_INTERNAL = 0x6,
  1044. NVME_SC_ABORT_REQ = 0x7,
  1045. NVME_SC_ABORT_QUEUE = 0x8,
  1046. NVME_SC_FUSED_FAIL = 0x9,
  1047. NVME_SC_FUSED_MISSING = 0xa,
  1048. NVME_SC_INVALID_NS = 0xb,
  1049. NVME_SC_CMD_SEQ_ERROR = 0xc,
  1050. NVME_SC_SGL_INVALID_LAST = 0xd,
  1051. NVME_SC_SGL_INVALID_COUNT = 0xe,
  1052. NVME_SC_SGL_INVALID_DATA = 0xf,
  1053. NVME_SC_SGL_INVALID_METADATA = 0x10,
  1054. NVME_SC_SGL_INVALID_TYPE = 0x11,
  1055. NVME_SC_SGL_INVALID_OFFSET = 0x16,
  1056. NVME_SC_SGL_INVALID_SUBTYPE = 0x17,
  1057. NVME_SC_NS_WRITE_PROTECTED = 0x20,
  1058. NVME_SC_LBA_RANGE = 0x80,
  1059. NVME_SC_CAP_EXCEEDED = 0x81,
  1060. NVME_SC_NS_NOT_READY = 0x82,
  1061. NVME_SC_RESERVATION_CONFLICT = 0x83,
  1062. /*
  1063. * Command Specific Status:
  1064. */
  1065. NVME_SC_CQ_INVALID = 0x100,
  1066. NVME_SC_QID_INVALID = 0x101,
  1067. NVME_SC_QUEUE_SIZE = 0x102,
  1068. NVME_SC_ABORT_LIMIT = 0x103,
  1069. NVME_SC_ABORT_MISSING = 0x104,
  1070. NVME_SC_ASYNC_LIMIT = 0x105,
  1071. NVME_SC_FIRMWARE_SLOT = 0x106,
  1072. NVME_SC_FIRMWARE_IMAGE = 0x107,
  1073. NVME_SC_INVALID_VECTOR = 0x108,
  1074. NVME_SC_INVALID_LOG_PAGE = 0x109,
  1075. NVME_SC_INVALID_FORMAT = 0x10a,
  1076. NVME_SC_FW_NEEDS_CONV_RESET = 0x10b,
  1077. NVME_SC_INVALID_QUEUE = 0x10c,
  1078. NVME_SC_FEATURE_NOT_SAVEABLE = 0x10d,
  1079. NVME_SC_FEATURE_NOT_CHANGEABLE = 0x10e,
  1080. NVME_SC_FEATURE_NOT_PER_NS = 0x10f,
  1081. NVME_SC_FW_NEEDS_SUBSYS_RESET = 0x110,
  1082. NVME_SC_FW_NEEDS_RESET = 0x111,
  1083. NVME_SC_FW_NEEDS_MAX_TIME = 0x112,
  1084. NVME_SC_FW_ACIVATE_PROHIBITED = 0x113,
  1085. NVME_SC_OVERLAPPING_RANGE = 0x114,
  1086. NVME_SC_NS_INSUFFICENT_CAP = 0x115,
  1087. NVME_SC_NS_ID_UNAVAILABLE = 0x116,
  1088. NVME_SC_NS_ALREADY_ATTACHED = 0x118,
  1089. NVME_SC_NS_IS_PRIVATE = 0x119,
  1090. NVME_SC_NS_NOT_ATTACHED = 0x11a,
  1091. NVME_SC_THIN_PROV_NOT_SUPP = 0x11b,
  1092. NVME_SC_CTRL_LIST_INVALID = 0x11c,
  1093. /*
  1094. * I/O Command Set Specific - NVM commands:
  1095. */
  1096. NVME_SC_BAD_ATTRIBUTES = 0x180,
  1097. NVME_SC_INVALID_PI = 0x181,
  1098. NVME_SC_READ_ONLY = 0x182,
  1099. NVME_SC_ONCS_NOT_SUPPORTED = 0x183,
  1100. /*
  1101. * I/O Command Set Specific - Fabrics commands:
  1102. */
  1103. NVME_SC_CONNECT_FORMAT = 0x180,
  1104. NVME_SC_CONNECT_CTRL_BUSY = 0x181,
  1105. NVME_SC_CONNECT_INVALID_PARAM = 0x182,
  1106. NVME_SC_CONNECT_RESTART_DISC = 0x183,
  1107. NVME_SC_CONNECT_INVALID_HOST = 0x184,
  1108. NVME_SC_DISCOVERY_RESTART = 0x190,
  1109. NVME_SC_AUTH_REQUIRED = 0x191,
  1110. /*
  1111. * Media and Data Integrity Errors:
  1112. */
  1113. NVME_SC_WRITE_FAULT = 0x280,
  1114. NVME_SC_READ_ERROR = 0x281,
  1115. NVME_SC_GUARD_CHECK = 0x282,
  1116. NVME_SC_APPTAG_CHECK = 0x283,
  1117. NVME_SC_REFTAG_CHECK = 0x284,
  1118. NVME_SC_COMPARE_FAILED = 0x285,
  1119. NVME_SC_ACCESS_DENIED = 0x286,
  1120. NVME_SC_UNWRITTEN_BLOCK = 0x287,
  1121. /*
  1122. * Path-related Errors:
  1123. */
  1124. NVME_SC_ANA_PERSISTENT_LOSS = 0x301,
  1125. NVME_SC_ANA_INACCESSIBLE = 0x302,
  1126. NVME_SC_ANA_TRANSITION = 0x303,
  1127. NVME_SC_HOST_PATH_ERROR = 0x370,
  1128. NVME_SC_DNR = 0x4000,
  1129. };
  1130. struct nvme_completion {
  1131. /*
  1132. * Used by Admin and Fabrics commands to return data:
  1133. */
  1134. union nvme_result {
  1135. __le16 u16;
  1136. __le32 u32;
  1137. __le64 u64;
  1138. } result;
  1139. __le16 sq_head; /* how much of this queue may be reclaimed */
  1140. __le16 sq_id; /* submission queue that generated this entry */
  1141. __u16 command_id; /* of the command which completed */
  1142. __le16 status; /* did the command fail, and if so, why? */
  1143. };
  1144. #define NVME_VS(major, minor, tertiary) \
  1145. (((major) << 16) | ((minor) << 8) | (tertiary))
  1146. #define NVME_MAJOR(ver) ((ver) >> 16)
  1147. #define NVME_MINOR(ver) (((ver) >> 8) & 0xff)
  1148. #define NVME_TERTIARY(ver) ((ver) & 0xff)
  1149. #endif /* _LINUX_NVME_H */