nvme.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. * Definitions for the NVM Express interface
  3. * Copyright (c) 2011, 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. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #ifndef _LINUX_NVME_H
  19. #define _LINUX_NVME_H
  20. #include <linux/types.h>
  21. struct nvme_bar {
  22. __u64 cap; /* Controller Capabilities */
  23. __u32 vs; /* Version */
  24. __u32 intms; /* Interrupt Mask Set */
  25. __u32 intmc; /* Interrupt Mask Clear */
  26. __u32 cc; /* Controller Configuration */
  27. __u32 rsvd1; /* Reserved */
  28. __u32 csts; /* Controller Status */
  29. __u32 rsvd2; /* Reserved */
  30. __u32 aqa; /* Admin Queue Attributes */
  31. __u64 asq; /* Admin SQ Base Address */
  32. __u64 acq; /* Admin CQ Base Address */
  33. };
  34. #define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff)
  35. #define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf)
  36. enum {
  37. NVME_CC_ENABLE = 1 << 0,
  38. NVME_CC_CSS_NVM = 0 << 4,
  39. NVME_CC_MPS_SHIFT = 7,
  40. NVME_CC_ARB_RR = 0 << 11,
  41. NVME_CC_ARB_WRRU = 1 << 11,
  42. NVME_CC_ARB_VS = 7 << 11,
  43. NVME_CC_SHN_NONE = 0 << 14,
  44. NVME_CC_SHN_NORMAL = 1 << 14,
  45. NVME_CC_SHN_ABRUPT = 2 << 14,
  46. NVME_CC_IOSQES = 6 << 16,
  47. NVME_CC_IOCQES = 4 << 20,
  48. NVME_CSTS_RDY = 1 << 0,
  49. NVME_CSTS_CFS = 1 << 1,
  50. NVME_CSTS_SHST_NORMAL = 0 << 2,
  51. NVME_CSTS_SHST_OCCUR = 1 << 2,
  52. NVME_CSTS_SHST_CMPLT = 2 << 2,
  53. };
  54. struct nvme_id_power_state {
  55. __le16 max_power; /* centiwatts */
  56. __u16 rsvd2;
  57. __le32 entry_lat; /* microseconds */
  58. __le32 exit_lat; /* microseconds */
  59. __u8 read_tput;
  60. __u8 read_lat;
  61. __u8 write_tput;
  62. __u8 write_lat;
  63. __u8 rsvd16[16];
  64. };
  65. #define NVME_VS(major, minor) (major << 16 | minor)
  66. struct nvme_id_ctrl {
  67. __le16 vid;
  68. __le16 ssvid;
  69. char sn[20];
  70. char mn[40];
  71. char fr[8];
  72. __u8 rab;
  73. __u8 ieee[3];
  74. __u8 mic;
  75. __u8 mdts;
  76. __u8 rsvd78[178];
  77. __le16 oacs;
  78. __u8 acl;
  79. __u8 aerl;
  80. __u8 frmw;
  81. __u8 lpa;
  82. __u8 elpe;
  83. __u8 npss;
  84. __u8 rsvd264[248];
  85. __u8 sqes;
  86. __u8 cqes;
  87. __u8 rsvd514[2];
  88. __le32 nn;
  89. __le16 oncs;
  90. __le16 fuses;
  91. __u8 fna;
  92. __u8 vwc;
  93. __le16 awun;
  94. __le16 awupf;
  95. __u8 rsvd530[1518];
  96. struct nvme_id_power_state psd[32];
  97. __u8 vs[1024];
  98. };
  99. struct nvme_lbaf {
  100. __le16 ms;
  101. __u8 ds;
  102. __u8 rp;
  103. };
  104. struct nvme_id_ns {
  105. __le64 nsze;
  106. __le64 ncap;
  107. __le64 nuse;
  108. __u8 nsfeat;
  109. __u8 nlbaf;
  110. __u8 flbas;
  111. __u8 mc;
  112. __u8 dpc;
  113. __u8 dps;
  114. __u8 rsvd30[98];
  115. struct nvme_lbaf lbaf[16];
  116. __u8 rsvd192[192];
  117. __u8 vs[3712];
  118. };
  119. enum {
  120. NVME_NS_FEAT_THIN = 1 << 0,
  121. NVME_LBAF_RP_BEST = 0,
  122. NVME_LBAF_RP_BETTER = 1,
  123. NVME_LBAF_RP_GOOD = 2,
  124. NVME_LBAF_RP_DEGRADED = 3,
  125. };
  126. struct nvme_lba_range_type {
  127. __u8 type;
  128. __u8 attributes;
  129. __u8 rsvd2[14];
  130. __u64 slba;
  131. __u64 nlb;
  132. __u8 guid[16];
  133. __u8 rsvd48[16];
  134. };
  135. enum {
  136. NVME_LBART_TYPE_FS = 0x01,
  137. NVME_LBART_TYPE_RAID = 0x02,
  138. NVME_LBART_TYPE_CACHE = 0x03,
  139. NVME_LBART_TYPE_SWAP = 0x04,
  140. NVME_LBART_ATTRIB_TEMP = 1 << 0,
  141. NVME_LBART_ATTRIB_HIDE = 1 << 1,
  142. };
  143. /* I/O commands */
  144. enum nvme_opcode {
  145. nvme_cmd_flush = 0x00,
  146. nvme_cmd_write = 0x01,
  147. nvme_cmd_read = 0x02,
  148. nvme_cmd_write_uncor = 0x04,
  149. nvme_cmd_compare = 0x05,
  150. nvme_cmd_dsm = 0x09,
  151. };
  152. struct nvme_common_command {
  153. __u8 opcode;
  154. __u8 flags;
  155. __u16 command_id;
  156. __le32 nsid;
  157. __u32 cdw2[2];
  158. __le64 metadata;
  159. __le64 prp1;
  160. __le64 prp2;
  161. __u32 cdw10[6];
  162. };
  163. struct nvme_rw_command {
  164. __u8 opcode;
  165. __u8 flags;
  166. __u16 command_id;
  167. __le32 nsid;
  168. __u64 rsvd2;
  169. __le64 metadata;
  170. __le64 prp1;
  171. __le64 prp2;
  172. __le64 slba;
  173. __le16 length;
  174. __le16 control;
  175. __le32 dsmgmt;
  176. __le32 reftag;
  177. __le16 apptag;
  178. __le16 appmask;
  179. };
  180. enum {
  181. NVME_RW_LR = 1 << 15,
  182. NVME_RW_FUA = 1 << 14,
  183. NVME_RW_DSM_FREQ_UNSPEC = 0,
  184. NVME_RW_DSM_FREQ_TYPICAL = 1,
  185. NVME_RW_DSM_FREQ_RARE = 2,
  186. NVME_RW_DSM_FREQ_READS = 3,
  187. NVME_RW_DSM_FREQ_WRITES = 4,
  188. NVME_RW_DSM_FREQ_RW = 5,
  189. NVME_RW_DSM_FREQ_ONCE = 6,
  190. NVME_RW_DSM_FREQ_PREFETCH = 7,
  191. NVME_RW_DSM_FREQ_TEMP = 8,
  192. NVME_RW_DSM_LATENCY_NONE = 0 << 4,
  193. NVME_RW_DSM_LATENCY_IDLE = 1 << 4,
  194. NVME_RW_DSM_LATENCY_NORM = 2 << 4,
  195. NVME_RW_DSM_LATENCY_LOW = 3 << 4,
  196. NVME_RW_DSM_SEQ_REQ = 1 << 6,
  197. NVME_RW_DSM_COMPRESSED = 1 << 7,
  198. };
  199. /* Admin commands */
  200. enum nvme_admin_opcode {
  201. nvme_admin_delete_sq = 0x00,
  202. nvme_admin_create_sq = 0x01,
  203. nvme_admin_get_log_page = 0x02,
  204. nvme_admin_delete_cq = 0x04,
  205. nvme_admin_create_cq = 0x05,
  206. nvme_admin_identify = 0x06,
  207. nvme_admin_abort_cmd = 0x08,
  208. nvme_admin_set_features = 0x09,
  209. nvme_admin_get_features = 0x0a,
  210. nvme_admin_async_event = 0x0c,
  211. nvme_admin_activate_fw = 0x10,
  212. nvme_admin_download_fw = 0x11,
  213. nvme_admin_format_nvm = 0x80,
  214. nvme_admin_security_send = 0x81,
  215. nvme_admin_security_recv = 0x82,
  216. };
  217. enum {
  218. NVME_QUEUE_PHYS_CONTIG = (1 << 0),
  219. NVME_CQ_IRQ_ENABLED = (1 << 1),
  220. NVME_SQ_PRIO_URGENT = (0 << 1),
  221. NVME_SQ_PRIO_HIGH = (1 << 1),
  222. NVME_SQ_PRIO_MEDIUM = (2 << 1),
  223. NVME_SQ_PRIO_LOW = (3 << 1),
  224. NVME_FEAT_ARBITRATION = 0x01,
  225. NVME_FEAT_POWER_MGMT = 0x02,
  226. NVME_FEAT_LBA_RANGE = 0x03,
  227. NVME_FEAT_TEMP_THRESH = 0x04,
  228. NVME_FEAT_ERR_RECOVERY = 0x05,
  229. NVME_FEAT_VOLATILE_WC = 0x06,
  230. NVME_FEAT_NUM_QUEUES = 0x07,
  231. NVME_FEAT_IRQ_COALESCE = 0x08,
  232. NVME_FEAT_IRQ_CONFIG = 0x09,
  233. NVME_FEAT_WRITE_ATOMIC = 0x0a,
  234. NVME_FEAT_ASYNC_EVENT = 0x0b,
  235. NVME_FEAT_SW_PROGRESS = 0x0c,
  236. };
  237. struct nvme_identify {
  238. __u8 opcode;
  239. __u8 flags;
  240. __u16 command_id;
  241. __le32 nsid;
  242. __u64 rsvd2[2];
  243. __le64 prp1;
  244. __le64 prp2;
  245. __le32 cns;
  246. __u32 rsvd11[5];
  247. };
  248. struct nvme_features {
  249. __u8 opcode;
  250. __u8 flags;
  251. __u16 command_id;
  252. __le32 nsid;
  253. __u64 rsvd2[2];
  254. __le64 prp1;
  255. __le64 prp2;
  256. __le32 fid;
  257. __le32 dword11;
  258. __u32 rsvd12[4];
  259. };
  260. struct nvme_create_cq {
  261. __u8 opcode;
  262. __u8 flags;
  263. __u16 command_id;
  264. __u32 rsvd1[5];
  265. __le64 prp1;
  266. __u64 rsvd8;
  267. __le16 cqid;
  268. __le16 qsize;
  269. __le16 cq_flags;
  270. __le16 irq_vector;
  271. __u32 rsvd12[4];
  272. };
  273. struct nvme_create_sq {
  274. __u8 opcode;
  275. __u8 flags;
  276. __u16 command_id;
  277. __u32 rsvd1[5];
  278. __le64 prp1;
  279. __u64 rsvd8;
  280. __le16 sqid;
  281. __le16 qsize;
  282. __le16 sq_flags;
  283. __le16 cqid;
  284. __u32 rsvd12[4];
  285. };
  286. struct nvme_delete_queue {
  287. __u8 opcode;
  288. __u8 flags;
  289. __u16 command_id;
  290. __u32 rsvd1[9];
  291. __le16 qid;
  292. __u16 rsvd10;
  293. __u32 rsvd11[5];
  294. };
  295. struct nvme_download_firmware {
  296. __u8 opcode;
  297. __u8 flags;
  298. __u16 command_id;
  299. __u32 rsvd1[5];
  300. __le64 prp1;
  301. __le64 prp2;
  302. __le32 numd;
  303. __le32 offset;
  304. __u32 rsvd12[4];
  305. };
  306. struct nvme_command {
  307. union {
  308. struct nvme_common_command common;
  309. struct nvme_rw_command rw;
  310. struct nvme_identify identify;
  311. struct nvme_features features;
  312. struct nvme_create_cq create_cq;
  313. struct nvme_create_sq create_sq;
  314. struct nvme_delete_queue delete_queue;
  315. struct nvme_download_firmware dlfw;
  316. };
  317. };
  318. enum {
  319. NVME_SC_SUCCESS = 0x0,
  320. NVME_SC_INVALID_OPCODE = 0x1,
  321. NVME_SC_INVALID_FIELD = 0x2,
  322. NVME_SC_CMDID_CONFLICT = 0x3,
  323. NVME_SC_DATA_XFER_ERROR = 0x4,
  324. NVME_SC_POWER_LOSS = 0x5,
  325. NVME_SC_INTERNAL = 0x6,
  326. NVME_SC_ABORT_REQ = 0x7,
  327. NVME_SC_ABORT_QUEUE = 0x8,
  328. NVME_SC_FUSED_FAIL = 0x9,
  329. NVME_SC_FUSED_MISSING = 0xa,
  330. NVME_SC_INVALID_NS = 0xb,
  331. NVME_SC_LBA_RANGE = 0x80,
  332. NVME_SC_CAP_EXCEEDED = 0x81,
  333. NVME_SC_NS_NOT_READY = 0x82,
  334. NVME_SC_CQ_INVALID = 0x100,
  335. NVME_SC_QID_INVALID = 0x101,
  336. NVME_SC_QUEUE_SIZE = 0x102,
  337. NVME_SC_ABORT_LIMIT = 0x103,
  338. NVME_SC_ABORT_MISSING = 0x104,
  339. NVME_SC_ASYNC_LIMIT = 0x105,
  340. NVME_SC_FIRMWARE_SLOT = 0x106,
  341. NVME_SC_FIRMWARE_IMAGE = 0x107,
  342. NVME_SC_INVALID_VECTOR = 0x108,
  343. NVME_SC_INVALID_LOG_PAGE = 0x109,
  344. NVME_SC_INVALID_FORMAT = 0x10a,
  345. NVME_SC_BAD_ATTRIBUTES = 0x180,
  346. NVME_SC_WRITE_FAULT = 0x280,
  347. NVME_SC_READ_ERROR = 0x281,
  348. NVME_SC_GUARD_CHECK = 0x282,
  349. NVME_SC_APPTAG_CHECK = 0x283,
  350. NVME_SC_REFTAG_CHECK = 0x284,
  351. NVME_SC_COMPARE_FAILED = 0x285,
  352. NVME_SC_ACCESS_DENIED = 0x286,
  353. };
  354. struct nvme_completion {
  355. __le32 result; /* Used by admin commands to return data */
  356. __u32 rsvd;
  357. __le16 sq_head; /* how much of this queue may be reclaimed */
  358. __le16 sq_id; /* submission queue that generated this entry */
  359. __u16 command_id; /* of the command which completed */
  360. __le16 status; /* did the command fail, and if so, why? */
  361. };
  362. struct nvme_user_io {
  363. __u8 opcode;
  364. __u8 flags;
  365. __u16 control;
  366. __u16 nblocks;
  367. __u16 rsvd;
  368. __u64 metadata;
  369. __u64 addr;
  370. __u64 slba;
  371. __u32 dsmgmt;
  372. __u32 reftag;
  373. __u16 apptag;
  374. __u16 appmask;
  375. };
  376. struct nvme_admin_cmd {
  377. __u8 opcode;
  378. __u8 flags;
  379. __u16 rsvd1;
  380. __u32 nsid;
  381. __u32 cdw2;
  382. __u32 cdw3;
  383. __u64 metadata;
  384. __u64 addr;
  385. __u32 metadata_len;
  386. __u32 data_len;
  387. __u32 cdw10;
  388. __u32 cdw11;
  389. __u32 cdw12;
  390. __u32 cdw13;
  391. __u32 cdw14;
  392. __u32 cdw15;
  393. __u32 timeout_ms;
  394. __u32 result;
  395. };
  396. #define NVME_IOCTL_ID _IO('N', 0x40)
  397. #define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd)
  398. #define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io)
  399. #endif /* _LINUX_NVME_H */