nvme.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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 _UAPI_LINUX_NVME_H
  15. #define _UAPI_LINUX_NVME_H
  16. #include <linux/types.h>
  17. struct nvme_id_power_state {
  18. __le16 max_power; /* centiwatts */
  19. __u8 rsvd2;
  20. __u8 flags;
  21. __le32 entry_lat; /* microseconds */
  22. __le32 exit_lat; /* microseconds */
  23. __u8 read_tput;
  24. __u8 read_lat;
  25. __u8 write_tput;
  26. __u8 write_lat;
  27. __le16 idle_power;
  28. __u8 idle_scale;
  29. __u8 rsvd19;
  30. __le16 active_power;
  31. __u8 active_work_scale;
  32. __u8 rsvd23[9];
  33. };
  34. enum {
  35. NVME_PS_FLAGS_MAX_POWER_SCALE = 1 << 0,
  36. NVME_PS_FLAGS_NON_OP_STATE = 1 << 1,
  37. };
  38. struct nvme_id_ctrl {
  39. __le16 vid;
  40. __le16 ssvid;
  41. char sn[20];
  42. char mn[40];
  43. char fr[8];
  44. __u8 rab;
  45. __u8 ieee[3];
  46. __u8 mic;
  47. __u8 mdts;
  48. __u16 cntlid;
  49. __u32 ver;
  50. __u8 rsvd84[172];
  51. __le16 oacs;
  52. __u8 acl;
  53. __u8 aerl;
  54. __u8 frmw;
  55. __u8 lpa;
  56. __u8 elpe;
  57. __u8 npss;
  58. __u8 avscc;
  59. __u8 apsta;
  60. __le16 wctemp;
  61. __le16 cctemp;
  62. __u8 rsvd270[242];
  63. __u8 sqes;
  64. __u8 cqes;
  65. __u8 rsvd514[2];
  66. __le32 nn;
  67. __le16 oncs;
  68. __le16 fuses;
  69. __u8 fna;
  70. __u8 vwc;
  71. __le16 awun;
  72. __le16 awupf;
  73. __u8 nvscc;
  74. __u8 rsvd531;
  75. __le16 acwu;
  76. __u8 rsvd534[2];
  77. __le32 sgls;
  78. __u8 rsvd540[1508];
  79. struct nvme_id_power_state psd[32];
  80. __u8 vs[1024];
  81. };
  82. enum {
  83. NVME_CTRL_ONCS_COMPARE = 1 << 0,
  84. NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1,
  85. NVME_CTRL_ONCS_DSM = 1 << 2,
  86. NVME_CTRL_VWC_PRESENT = 1 << 0,
  87. };
  88. struct nvme_lbaf {
  89. __le16 ms;
  90. __u8 ds;
  91. __u8 rp;
  92. };
  93. struct nvme_id_ns {
  94. __le64 nsze;
  95. __le64 ncap;
  96. __le64 nuse;
  97. __u8 nsfeat;
  98. __u8 nlbaf;
  99. __u8 flbas;
  100. __u8 mc;
  101. __u8 dpc;
  102. __u8 dps;
  103. __u8 nmic;
  104. __u8 rescap;
  105. __u8 fpi;
  106. __u8 rsvd33;
  107. __le16 nawun;
  108. __le16 nawupf;
  109. __le16 nacwu;
  110. __le16 nabsn;
  111. __le16 nabo;
  112. __le16 nabspf;
  113. __u16 rsvd46;
  114. __le64 nvmcap[2];
  115. __u8 rsvd64[40];
  116. __u8 nguid[16];
  117. __u8 eui64[8];
  118. struct nvme_lbaf lbaf[16];
  119. __u8 rsvd192[192];
  120. __u8 vs[3712];
  121. };
  122. enum {
  123. NVME_NS_FEAT_THIN = 1 << 0,
  124. NVME_NS_FLBAS_LBA_MASK = 0xf,
  125. NVME_NS_FLBAS_META_EXT = 0x10,
  126. NVME_LBAF_RP_BEST = 0,
  127. NVME_LBAF_RP_BETTER = 1,
  128. NVME_LBAF_RP_GOOD = 2,
  129. NVME_LBAF_RP_DEGRADED = 3,
  130. NVME_NS_DPC_PI_LAST = 1 << 4,
  131. NVME_NS_DPC_PI_FIRST = 1 << 3,
  132. NVME_NS_DPC_PI_TYPE3 = 1 << 2,
  133. NVME_NS_DPC_PI_TYPE2 = 1 << 1,
  134. NVME_NS_DPC_PI_TYPE1 = 1 << 0,
  135. NVME_NS_DPS_PI_FIRST = 1 << 3,
  136. NVME_NS_DPS_PI_MASK = 0x7,
  137. NVME_NS_DPS_PI_TYPE1 = 1,
  138. NVME_NS_DPS_PI_TYPE2 = 2,
  139. NVME_NS_DPS_PI_TYPE3 = 3,
  140. };
  141. struct nvme_smart_log {
  142. __u8 critical_warning;
  143. __u8 temperature[2];
  144. __u8 avail_spare;
  145. __u8 spare_thresh;
  146. __u8 percent_used;
  147. __u8 rsvd6[26];
  148. __u8 data_units_read[16];
  149. __u8 data_units_written[16];
  150. __u8 host_reads[16];
  151. __u8 host_writes[16];
  152. __u8 ctrl_busy_time[16];
  153. __u8 power_cycles[16];
  154. __u8 power_on_hours[16];
  155. __u8 unsafe_shutdowns[16];
  156. __u8 media_errors[16];
  157. __u8 num_err_log_entries[16];
  158. __le32 warning_temp_time;
  159. __le32 critical_comp_time;
  160. __le16 temp_sensor[8];
  161. __u8 rsvd216[296];
  162. };
  163. enum {
  164. NVME_SMART_CRIT_SPARE = 1 << 0,
  165. NVME_SMART_CRIT_TEMPERATURE = 1 << 1,
  166. NVME_SMART_CRIT_RELIABILITY = 1 << 2,
  167. NVME_SMART_CRIT_MEDIA = 1 << 3,
  168. NVME_SMART_CRIT_VOLATILE_MEMORY = 1 << 4,
  169. };
  170. enum {
  171. NVME_AER_NOTICE_NS_CHANGED = 0x0002,
  172. };
  173. struct nvme_lba_range_type {
  174. __u8 type;
  175. __u8 attributes;
  176. __u8 rsvd2[14];
  177. __u64 slba;
  178. __u64 nlb;
  179. __u8 guid[16];
  180. __u8 rsvd48[16];
  181. };
  182. enum {
  183. NVME_LBART_TYPE_FS = 0x01,
  184. NVME_LBART_TYPE_RAID = 0x02,
  185. NVME_LBART_TYPE_CACHE = 0x03,
  186. NVME_LBART_TYPE_SWAP = 0x04,
  187. NVME_LBART_ATTRIB_TEMP = 1 << 0,
  188. NVME_LBART_ATTRIB_HIDE = 1 << 1,
  189. };
  190. struct nvme_reservation_status {
  191. __le32 gen;
  192. __u8 rtype;
  193. __u8 regctl[2];
  194. __u8 resv5[2];
  195. __u8 ptpls;
  196. __u8 resv10[13];
  197. struct {
  198. __le16 cntlid;
  199. __u8 rcsts;
  200. __u8 resv3[5];
  201. __le64 hostid;
  202. __le64 rkey;
  203. } regctl_ds[];
  204. };
  205. /* I/O commands */
  206. enum nvme_opcode {
  207. nvme_cmd_flush = 0x00,
  208. nvme_cmd_write = 0x01,
  209. nvme_cmd_read = 0x02,
  210. nvme_cmd_write_uncor = 0x04,
  211. nvme_cmd_compare = 0x05,
  212. nvme_cmd_write_zeroes = 0x08,
  213. nvme_cmd_dsm = 0x09,
  214. nvme_cmd_resv_register = 0x0d,
  215. nvme_cmd_resv_report = 0x0e,
  216. nvme_cmd_resv_acquire = 0x11,
  217. nvme_cmd_resv_release = 0x15,
  218. };
  219. struct nvme_common_command {
  220. __u8 opcode;
  221. __u8 flags;
  222. __u16 command_id;
  223. __le32 nsid;
  224. __le32 cdw2[2];
  225. __le64 metadata;
  226. __le64 prp1;
  227. __le64 prp2;
  228. __le32 cdw10[6];
  229. };
  230. struct nvme_rw_command {
  231. __u8 opcode;
  232. __u8 flags;
  233. __u16 command_id;
  234. __le32 nsid;
  235. __u64 rsvd2;
  236. __le64 metadata;
  237. __le64 prp1;
  238. __le64 prp2;
  239. __le64 slba;
  240. __le16 length;
  241. __le16 control;
  242. __le32 dsmgmt;
  243. __le32 reftag;
  244. __le16 apptag;
  245. __le16 appmask;
  246. };
  247. enum {
  248. NVME_RW_LR = 1 << 15,
  249. NVME_RW_FUA = 1 << 14,
  250. NVME_RW_DSM_FREQ_UNSPEC = 0,
  251. NVME_RW_DSM_FREQ_TYPICAL = 1,
  252. NVME_RW_DSM_FREQ_RARE = 2,
  253. NVME_RW_DSM_FREQ_READS = 3,
  254. NVME_RW_DSM_FREQ_WRITES = 4,
  255. NVME_RW_DSM_FREQ_RW = 5,
  256. NVME_RW_DSM_FREQ_ONCE = 6,
  257. NVME_RW_DSM_FREQ_PREFETCH = 7,
  258. NVME_RW_DSM_FREQ_TEMP = 8,
  259. NVME_RW_DSM_LATENCY_NONE = 0 << 4,
  260. NVME_RW_DSM_LATENCY_IDLE = 1 << 4,
  261. NVME_RW_DSM_LATENCY_NORM = 2 << 4,
  262. NVME_RW_DSM_LATENCY_LOW = 3 << 4,
  263. NVME_RW_DSM_SEQ_REQ = 1 << 6,
  264. NVME_RW_DSM_COMPRESSED = 1 << 7,
  265. NVME_RW_PRINFO_PRCHK_REF = 1 << 10,
  266. NVME_RW_PRINFO_PRCHK_APP = 1 << 11,
  267. NVME_RW_PRINFO_PRCHK_GUARD = 1 << 12,
  268. NVME_RW_PRINFO_PRACT = 1 << 13,
  269. };
  270. struct nvme_dsm_cmd {
  271. __u8 opcode;
  272. __u8 flags;
  273. __u16 command_id;
  274. __le32 nsid;
  275. __u64 rsvd2[2];
  276. __le64 prp1;
  277. __le64 prp2;
  278. __le32 nr;
  279. __le32 attributes;
  280. __u32 rsvd12[4];
  281. };
  282. enum {
  283. NVME_DSMGMT_IDR = 1 << 0,
  284. NVME_DSMGMT_IDW = 1 << 1,
  285. NVME_DSMGMT_AD = 1 << 2,
  286. };
  287. struct nvme_dsm_range {
  288. __le32 cattr;
  289. __le32 nlb;
  290. __le64 slba;
  291. };
  292. /* Admin commands */
  293. enum nvme_admin_opcode {
  294. nvme_admin_delete_sq = 0x00,
  295. nvme_admin_create_sq = 0x01,
  296. nvme_admin_get_log_page = 0x02,
  297. nvme_admin_delete_cq = 0x04,
  298. nvme_admin_create_cq = 0x05,
  299. nvme_admin_identify = 0x06,
  300. nvme_admin_abort_cmd = 0x08,
  301. nvme_admin_set_features = 0x09,
  302. nvme_admin_get_features = 0x0a,
  303. nvme_admin_async_event = 0x0c,
  304. nvme_admin_activate_fw = 0x10,
  305. nvme_admin_download_fw = 0x11,
  306. nvme_admin_format_nvm = 0x80,
  307. nvme_admin_security_send = 0x81,
  308. nvme_admin_security_recv = 0x82,
  309. };
  310. enum {
  311. NVME_QUEUE_PHYS_CONTIG = (1 << 0),
  312. NVME_CQ_IRQ_ENABLED = (1 << 1),
  313. NVME_SQ_PRIO_URGENT = (0 << 1),
  314. NVME_SQ_PRIO_HIGH = (1 << 1),
  315. NVME_SQ_PRIO_MEDIUM = (2 << 1),
  316. NVME_SQ_PRIO_LOW = (3 << 1),
  317. NVME_FEAT_ARBITRATION = 0x01,
  318. NVME_FEAT_POWER_MGMT = 0x02,
  319. NVME_FEAT_LBA_RANGE = 0x03,
  320. NVME_FEAT_TEMP_THRESH = 0x04,
  321. NVME_FEAT_ERR_RECOVERY = 0x05,
  322. NVME_FEAT_VOLATILE_WC = 0x06,
  323. NVME_FEAT_NUM_QUEUES = 0x07,
  324. NVME_FEAT_IRQ_COALESCE = 0x08,
  325. NVME_FEAT_IRQ_CONFIG = 0x09,
  326. NVME_FEAT_WRITE_ATOMIC = 0x0a,
  327. NVME_FEAT_ASYNC_EVENT = 0x0b,
  328. NVME_FEAT_AUTO_PST = 0x0c,
  329. NVME_FEAT_SW_PROGRESS = 0x80,
  330. NVME_FEAT_HOST_ID = 0x81,
  331. NVME_FEAT_RESV_MASK = 0x82,
  332. NVME_FEAT_RESV_PERSIST = 0x83,
  333. NVME_LOG_ERROR = 0x01,
  334. NVME_LOG_SMART = 0x02,
  335. NVME_LOG_FW_SLOT = 0x03,
  336. NVME_LOG_RESERVATION = 0x80,
  337. NVME_FWACT_REPL = (0 << 3),
  338. NVME_FWACT_REPL_ACTV = (1 << 3),
  339. NVME_FWACT_ACTV = (2 << 3),
  340. };
  341. struct nvme_identify {
  342. __u8 opcode;
  343. __u8 flags;
  344. __u16 command_id;
  345. __le32 nsid;
  346. __u64 rsvd2[2];
  347. __le64 prp1;
  348. __le64 prp2;
  349. __le32 cns;
  350. __u32 rsvd11[5];
  351. };
  352. struct nvme_features {
  353. __u8 opcode;
  354. __u8 flags;
  355. __u16 command_id;
  356. __le32 nsid;
  357. __u64 rsvd2[2];
  358. __le64 prp1;
  359. __le64 prp2;
  360. __le32 fid;
  361. __le32 dword11;
  362. __u32 rsvd12[4];
  363. };
  364. struct nvme_create_cq {
  365. __u8 opcode;
  366. __u8 flags;
  367. __u16 command_id;
  368. __u32 rsvd1[5];
  369. __le64 prp1;
  370. __u64 rsvd8;
  371. __le16 cqid;
  372. __le16 qsize;
  373. __le16 cq_flags;
  374. __le16 irq_vector;
  375. __u32 rsvd12[4];
  376. };
  377. struct nvme_create_sq {
  378. __u8 opcode;
  379. __u8 flags;
  380. __u16 command_id;
  381. __u32 rsvd1[5];
  382. __le64 prp1;
  383. __u64 rsvd8;
  384. __le16 sqid;
  385. __le16 qsize;
  386. __le16 sq_flags;
  387. __le16 cqid;
  388. __u32 rsvd12[4];
  389. };
  390. struct nvme_delete_queue {
  391. __u8 opcode;
  392. __u8 flags;
  393. __u16 command_id;
  394. __u32 rsvd1[9];
  395. __le16 qid;
  396. __u16 rsvd10;
  397. __u32 rsvd11[5];
  398. };
  399. struct nvme_abort_cmd {
  400. __u8 opcode;
  401. __u8 flags;
  402. __u16 command_id;
  403. __u32 rsvd1[9];
  404. __le16 sqid;
  405. __u16 cid;
  406. __u32 rsvd11[5];
  407. };
  408. struct nvme_download_firmware {
  409. __u8 opcode;
  410. __u8 flags;
  411. __u16 command_id;
  412. __u32 rsvd1[5];
  413. __le64 prp1;
  414. __le64 prp2;
  415. __le32 numd;
  416. __le32 offset;
  417. __u32 rsvd12[4];
  418. };
  419. struct nvme_format_cmd {
  420. __u8 opcode;
  421. __u8 flags;
  422. __u16 command_id;
  423. __le32 nsid;
  424. __u64 rsvd2[4];
  425. __le32 cdw10;
  426. __u32 rsvd11[5];
  427. };
  428. struct nvme_command {
  429. union {
  430. struct nvme_common_command common;
  431. struct nvme_rw_command rw;
  432. struct nvme_identify identify;
  433. struct nvme_features features;
  434. struct nvme_create_cq create_cq;
  435. struct nvme_create_sq create_sq;
  436. struct nvme_delete_queue delete_queue;
  437. struct nvme_download_firmware dlfw;
  438. struct nvme_format_cmd format;
  439. struct nvme_dsm_cmd dsm;
  440. struct nvme_abort_cmd abort;
  441. };
  442. };
  443. enum {
  444. NVME_SC_SUCCESS = 0x0,
  445. NVME_SC_INVALID_OPCODE = 0x1,
  446. NVME_SC_INVALID_FIELD = 0x2,
  447. NVME_SC_CMDID_CONFLICT = 0x3,
  448. NVME_SC_DATA_XFER_ERROR = 0x4,
  449. NVME_SC_POWER_LOSS = 0x5,
  450. NVME_SC_INTERNAL = 0x6,
  451. NVME_SC_ABORT_REQ = 0x7,
  452. NVME_SC_ABORT_QUEUE = 0x8,
  453. NVME_SC_FUSED_FAIL = 0x9,
  454. NVME_SC_FUSED_MISSING = 0xa,
  455. NVME_SC_INVALID_NS = 0xb,
  456. NVME_SC_CMD_SEQ_ERROR = 0xc,
  457. NVME_SC_SGL_INVALID_LAST = 0xd,
  458. NVME_SC_SGL_INVALID_COUNT = 0xe,
  459. NVME_SC_SGL_INVALID_DATA = 0xf,
  460. NVME_SC_SGL_INVALID_METADATA = 0x10,
  461. NVME_SC_SGL_INVALID_TYPE = 0x11,
  462. NVME_SC_LBA_RANGE = 0x80,
  463. NVME_SC_CAP_EXCEEDED = 0x81,
  464. NVME_SC_NS_NOT_READY = 0x82,
  465. NVME_SC_RESERVATION_CONFLICT = 0x83,
  466. NVME_SC_CQ_INVALID = 0x100,
  467. NVME_SC_QID_INVALID = 0x101,
  468. NVME_SC_QUEUE_SIZE = 0x102,
  469. NVME_SC_ABORT_LIMIT = 0x103,
  470. NVME_SC_ABORT_MISSING = 0x104,
  471. NVME_SC_ASYNC_LIMIT = 0x105,
  472. NVME_SC_FIRMWARE_SLOT = 0x106,
  473. NVME_SC_FIRMWARE_IMAGE = 0x107,
  474. NVME_SC_INVALID_VECTOR = 0x108,
  475. NVME_SC_INVALID_LOG_PAGE = 0x109,
  476. NVME_SC_INVALID_FORMAT = 0x10a,
  477. NVME_SC_FIRMWARE_NEEDS_RESET = 0x10b,
  478. NVME_SC_INVALID_QUEUE = 0x10c,
  479. NVME_SC_FEATURE_NOT_SAVEABLE = 0x10d,
  480. NVME_SC_FEATURE_NOT_CHANGEABLE = 0x10e,
  481. NVME_SC_FEATURE_NOT_PER_NS = 0x10f,
  482. NVME_SC_FW_NEEDS_RESET_SUBSYS = 0x110,
  483. NVME_SC_BAD_ATTRIBUTES = 0x180,
  484. NVME_SC_INVALID_PI = 0x181,
  485. NVME_SC_READ_ONLY = 0x182,
  486. NVME_SC_WRITE_FAULT = 0x280,
  487. NVME_SC_READ_ERROR = 0x281,
  488. NVME_SC_GUARD_CHECK = 0x282,
  489. NVME_SC_APPTAG_CHECK = 0x283,
  490. NVME_SC_REFTAG_CHECK = 0x284,
  491. NVME_SC_COMPARE_FAILED = 0x285,
  492. NVME_SC_ACCESS_DENIED = 0x286,
  493. NVME_SC_DNR = 0x4000,
  494. };
  495. struct nvme_completion {
  496. __le32 result; /* Used by admin commands to return data */
  497. __u32 rsvd;
  498. __le16 sq_head; /* how much of this queue may be reclaimed */
  499. __le16 sq_id; /* submission queue that generated this entry */
  500. __u16 command_id; /* of the command which completed */
  501. __le16 status; /* did the command fail, and if so, why? */
  502. };
  503. struct nvme_user_io {
  504. __u8 opcode;
  505. __u8 flags;
  506. __u16 control;
  507. __u16 nblocks;
  508. __u16 rsvd;
  509. __u64 metadata;
  510. __u64 addr;
  511. __u64 slba;
  512. __u32 dsmgmt;
  513. __u32 reftag;
  514. __u16 apptag;
  515. __u16 appmask;
  516. };
  517. struct nvme_passthru_cmd {
  518. __u8 opcode;
  519. __u8 flags;
  520. __u16 rsvd1;
  521. __u32 nsid;
  522. __u32 cdw2;
  523. __u32 cdw3;
  524. __u64 metadata;
  525. __u64 addr;
  526. __u32 metadata_len;
  527. __u32 data_len;
  528. __u32 cdw10;
  529. __u32 cdw11;
  530. __u32 cdw12;
  531. __u32 cdw13;
  532. __u32 cdw14;
  533. __u32 cdw15;
  534. __u32 timeout_ms;
  535. __u32 result;
  536. };
  537. #define NVME_VS(major, minor) (((major) << 16) | ((minor) << 8))
  538. #define nvme_admin_cmd nvme_passthru_cmd
  539. #define NVME_IOCTL_ID _IO('N', 0x40)
  540. #define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd)
  541. #define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io)
  542. #define NVME_IOCTL_IO_CMD _IOWR('N', 0x43, struct nvme_passthru_cmd)
  543. #define NVME_IOCTL_RESET _IO('N', 0x44)
  544. #endif /* _UAPI_LINUX_NVME_H */