blob: 2a2c535c8345902dcc3b57a97e4e8bd25dcd71ac [file] [log] [blame]
Matthew Wilcoxb60503b2011-01-20 12:50:14 -05001/*
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
19#ifndef _LINUX_NVME_H
20#define _LINUX_NVME_H
21
22#include <linux/types.h>
23
24struct nvme_bar {
25 __u64 cap; /* Controller Capabilities */
26 __u32 vs; /* Version */
Matthew Wilcox897cfe12011-02-14 12:20:15 -050027 __u32 intms; /* Interrupt Mask Set */
28 __u32 intmc; /* Interrupt Mask Clear */
Matthew Wilcoxb60503b2011-01-20 12:50:14 -050029 __u32 cc; /* Controller Configuration */
Matthew Wilcox897cfe12011-02-14 12:20:15 -050030 __u32 rsvd1; /* Reserved */
Matthew Wilcoxb60503b2011-01-20 12:50:14 -050031 __u32 csts; /* Controller Status */
Matthew Wilcox897cfe12011-02-14 12:20:15 -050032 __u32 rsvd2; /* Reserved */
Matthew Wilcoxb60503b2011-01-20 12:50:14 -050033 __u32 aqa; /* Admin Queue Attributes */
34 __u64 asq; /* Admin SQ Base Address */
35 __u64 acq; /* Admin CQ Base Address */
36};
37
Matthew Wilcox22605f92011-04-19 15:04:20 -040038#define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff)
Matthew Wilcoxf1938f62011-10-20 17:00:41 -040039#define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf)
Matthew Wilcox22605f92011-04-19 15:04:20 -040040
Matthew Wilcoxb60503b2011-01-20 12:50:14 -050041enum {
42 NVME_CC_ENABLE = 1 << 0,
43 NVME_CC_CSS_NVM = 0 << 4,
44 NVME_CC_MPS_SHIFT = 7,
45 NVME_CC_ARB_RR = 0 << 11,
46 NVME_CC_ARB_WRRU = 1 << 11,
Matthew Wilcox7f53f9d2011-03-22 15:55:45 -040047 NVME_CC_ARB_VS = 7 << 11,
48 NVME_CC_SHN_NONE = 0 << 14,
49 NVME_CC_SHN_NORMAL = 1 << 14,
50 NVME_CC_SHN_ABRUPT = 2 << 14,
51 NVME_CC_IOSQES = 6 << 16,
52 NVME_CC_IOCQES = 4 << 20,
Matthew Wilcoxb60503b2011-01-20 12:50:14 -050053 NVME_CSTS_RDY = 1 << 0,
54 NVME_CSTS_CFS = 1 << 1,
55 NVME_CSTS_SHST_NORMAL = 0 << 2,
56 NVME_CSTS_SHST_OCCUR = 1 << 2,
57 NVME_CSTS_SHST_CMPLT = 2 << 2,
58};
59
60#define NVME_VS(major, minor) (major << 16 | minor)
61
62struct nvme_id_ctrl {
63 __le16 vid;
64 __le16 ssvid;
65 char sn[20];
66 char mn[40];
67 char fr[8];
68 __le32 nn;
69 __u8 rab;
70 __u8 rsvd77[178];
71 __le16 oacs;
72 __u8 acl;
73 __u8 aerl;
74 __u8 frmw;
75 __u8 lpa;
76 __u8 elpe;
77 __u8 npss;
78 __u8 rsvd264[248];
79 __le64 psd[32];
80 __le16 oncs;
81 __le16 fuses;
82 __u8 fna;
83 __u8 vwc;
84 __le16 awun;
85 __le16 awupf;
86 __u8 rsvd778[246];
87 __u8 cmdset[2048];
88 __u8 vs[1024];
89};
90
91struct nvme_lbaf {
92 __le16 ms;
93 __u8 ds;
94 __u8 rp;
95};
96
97struct nvme_id_ns {
98 __le64 nsze;
99 __le64 ncap;
100 __le64 nuse;
101 __u8 nsfeat;
102 __u8 nlbaf;
103 __u8 flbas;
104 __u8 mc;
105 __u8 dpc;
106 __u8 dps;
107 __u8 rsvd30[98];
108 struct nvme_lbaf lbaf[16];
109 __u8 rsvd192[192];
110 __u8 vs[3712];
111};
112
113enum {
114 NVME_NS_FEAT_THIN = 1 << 0,
115 NVME_LBAF_RP_BEST = 0,
116 NVME_LBAF_RP_BETTER = 1,
117 NVME_LBAF_RP_GOOD = 2,
118 NVME_LBAF_RP_DEGRADED = 3,
119};
120
121struct nvme_lba_range_type {
122 __u8 type;
123 __u8 attributes;
124 __u8 rsvd2[14];
125 __u64 slba;
126 __u64 nlb;
127 __u8 guid[16];
128 __u8 rsvd48[16];
129};
130
131enum {
132 NVME_LBART_TYPE_FS = 0x01,
133 NVME_LBART_TYPE_RAID = 0x02,
134 NVME_LBART_TYPE_CACHE = 0x03,
135 NVME_LBART_TYPE_SWAP = 0x04,
136
137 NVME_LBART_ATTRIB_TEMP = 1 << 0,
138 NVME_LBART_ATTRIB_HIDE = 1 << 1,
139};
140
141/* I/O commands */
142
143enum nvme_opcode {
144 nvme_cmd_flush = 0x00,
145 nvme_cmd_write = 0x01,
146 nvme_cmd_read = 0x02,
147 nvme_cmd_write_uncor = 0x04,
148 nvme_cmd_compare = 0x05,
149 nvme_cmd_dsm = 0x09,
150};
151
Matthew Wilcox7b4fe9b2011-01-26 10:01:21 -0500152struct nvme_common_command {
153 __u8 opcode;
154 __u8 flags;
155 __u16 command_id;
156 __le32 nsid;
Matthew Wilcox6bbf1ac2011-05-20 13:03:42 -0400157 __u32 cdw2[2];
Matthew Wilcox7b4fe9b2011-01-26 10:01:21 -0500158 __le64 metadata;
159 __le64 prp1;
160 __le64 prp2;
Matthew Wilcox6bbf1ac2011-05-20 13:03:42 -0400161 __u32 cdw10[6];
Matthew Wilcox7b4fe9b2011-01-26 10:01:21 -0500162};
163
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500164struct nvme_rw_command {
165 __u8 opcode;
166 __u8 flags;
167 __u16 command_id;
168 __le32 nsid;
169 __u64 rsvd2;
170 __le64 metadata;
171 __le64 prp1;
172 __le64 prp2;
173 __le64 slba;
174 __le16 length;
175 __le16 control;
176 __le32 dsmgmt;
177 __le32 reftag;
178 __le16 apptag;
179 __le16 appmask;
180};
181
182enum {
183 NVME_RW_LR = 1 << 15,
184 NVME_RW_FUA = 1 << 14,
185 NVME_RW_DSM_FREQ_UNSPEC = 0,
186 NVME_RW_DSM_FREQ_TYPICAL = 1,
187 NVME_RW_DSM_FREQ_RARE = 2,
188 NVME_RW_DSM_FREQ_READS = 3,
189 NVME_RW_DSM_FREQ_WRITES = 4,
190 NVME_RW_DSM_FREQ_RW = 5,
191 NVME_RW_DSM_FREQ_ONCE = 6,
192 NVME_RW_DSM_FREQ_PREFETCH = 7,
193 NVME_RW_DSM_FREQ_TEMP = 8,
194 NVME_RW_DSM_LATENCY_NONE = 0 << 4,
195 NVME_RW_DSM_LATENCY_IDLE = 1 << 4,
196 NVME_RW_DSM_LATENCY_NORM = 2 << 4,
197 NVME_RW_DSM_LATENCY_LOW = 3 << 4,
198 NVME_RW_DSM_SEQ_REQ = 1 << 6,
199 NVME_RW_DSM_COMPRESSED = 1 << 7,
200};
201
202/* Admin commands */
203
204enum nvme_admin_opcode {
205 nvme_admin_delete_sq = 0x00,
206 nvme_admin_create_sq = 0x01,
Krzysztof Wierzbicki2ddc4f72011-02-28 08:27:13 +0100207 nvme_admin_get_log_page = 0x02,
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500208 nvme_admin_delete_cq = 0x04,
209 nvme_admin_create_cq = 0x05,
210 nvme_admin_identify = 0x06,
211 nvme_admin_abort_cmd = 0x08,
212 nvme_admin_set_features = 0x09,
Krzysztof Wierzbicki2ddc4f72011-02-28 08:27:13 +0100213 nvme_admin_get_features = 0x0a,
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500214 nvme_admin_async_event = 0x0c,
Krzysztof Wierzbicki2ddc4f72011-02-28 08:27:13 +0100215 nvme_admin_activate_fw = 0x10,
216 nvme_admin_download_fw = 0x11,
217 nvme_admin_format_nvm = 0x80,
218 nvme_admin_security_send = 0x81,
219 nvme_admin_security_recv = 0x82,
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500220};
221
222enum {
223 NVME_QUEUE_PHYS_CONTIG = (1 << 0),
224 NVME_CQ_IRQ_ENABLED = (1 << 1),
225 NVME_SQ_PRIO_URGENT = (0 << 1),
226 NVME_SQ_PRIO_HIGH = (1 << 1),
227 NVME_SQ_PRIO_MEDIUM = (2 << 1),
228 NVME_SQ_PRIO_LOW = (3 << 1),
229 NVME_FEAT_ARBITRATION = 0x01,
230 NVME_FEAT_POWER_MGMT = 0x02,
231 NVME_FEAT_LBA_RANGE = 0x03,
232 NVME_FEAT_TEMP_THRESH = 0x04,
233 NVME_FEAT_ERR_RECOVERY = 0x05,
234 NVME_FEAT_VOLATILE_WC = 0x06,
235 NVME_FEAT_NUM_QUEUES = 0x07,
236 NVME_FEAT_IRQ_COALESCE = 0x08,
237 NVME_FEAT_IRQ_CONFIG = 0x09,
238 NVME_FEAT_WRITE_ATOMIC = 0x0a,
239 NVME_FEAT_ASYNC_EVENT = 0x0b,
240 NVME_FEAT_SW_PROGRESS = 0x0c,
241};
242
243struct nvme_identify {
244 __u8 opcode;
245 __u8 flags;
246 __u16 command_id;
247 __le32 nsid;
248 __u64 rsvd2[2];
249 __le64 prp1;
250 __le64 prp2;
251 __le32 cns;
252 __u32 rsvd11[5];
253};
254
255struct nvme_features {
256 __u8 opcode;
257 __u8 flags;
258 __u16 command_id;
259 __le32 nsid;
260 __u64 rsvd2[2];
261 __le64 prp1;
262 __le64 prp2;
263 __le32 fid;
264 __le32 dword11;
265 __u32 rsvd12[4];
266};
267
268struct nvme_create_cq {
269 __u8 opcode;
270 __u8 flags;
271 __u16 command_id;
Matthew Wilcox6ee44cd2011-02-03 10:58:26 -0500272 __u32 rsvd1[5];
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500273 __le64 prp1;
274 __u64 rsvd8;
275 __le16 cqid;
276 __le16 qsize;
277 __le16 cq_flags;
278 __le16 irq_vector;
279 __u32 rsvd12[4];
280};
281
282struct nvme_create_sq {
283 __u8 opcode;
284 __u8 flags;
285 __u16 command_id;
Matthew Wilcox6ee44cd2011-02-03 10:58:26 -0500286 __u32 rsvd1[5];
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500287 __le64 prp1;
288 __u64 rsvd8;
289 __le16 sqid;
290 __le16 qsize;
291 __le16 sq_flags;
292 __le16 cqid;
Matthew Wilcox6ee44cd2011-02-03 10:58:26 -0500293 __u32 rsvd12[4];
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500294};
295
296struct nvme_delete_queue {
297 __u8 opcode;
298 __u8 flags;
299 __u16 command_id;
300 __u32 rsvd1[9];
301 __le16 qid;
Matthew Wilcox6ee44cd2011-02-03 10:58:26 -0500302 __u16 rsvd10;
303 __u32 rsvd11[5];
304};
305
306struct nvme_download_firmware {
307 __u8 opcode;
308 __u8 flags;
309 __u16 command_id;
310 __u32 rsvd1[5];
311 __le64 prp1;
312 __le64 prp2;
313 __le32 numd;
314 __le32 offset;
315 __u32 rsvd12[4];
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500316};
317
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500318struct nvme_command {
319 union {
320 struct nvme_common_command common;
321 struct nvme_rw_command rw;
322 struct nvme_identify identify;
323 struct nvme_features features;
324 struct nvme_create_cq create_cq;
325 struct nvme_create_sq create_sq;
326 struct nvme_delete_queue delete_queue;
Matthew Wilcox6ee44cd2011-02-03 10:58:26 -0500327 struct nvme_download_firmware dlfw;
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500328 };
329};
330
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500331enum {
332 NVME_SC_SUCCESS = 0x0,
333 NVME_SC_INVALID_OPCODE = 0x1,
334 NVME_SC_INVALID_FIELD = 0x2,
335 NVME_SC_CMDID_CONFLICT = 0x3,
336 NVME_SC_DATA_XFER_ERROR = 0x4,
337 NVME_SC_POWER_LOSS = 0x5,
338 NVME_SC_INTERNAL = 0x6,
339 NVME_SC_ABORT_REQ = 0x7,
340 NVME_SC_ABORT_QUEUE = 0x8,
341 NVME_SC_FUSED_FAIL = 0x9,
342 NVME_SC_FUSED_MISSING = 0xa,
Matthew Wilcox7a63e072011-02-03 09:20:57 -0500343 NVME_SC_INVALID_NS = 0xb,
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500344 NVME_SC_LBA_RANGE = 0x80,
345 NVME_SC_CAP_EXCEEDED = 0x81,
346 NVME_SC_NS_NOT_READY = 0x82,
347 NVME_SC_CQ_INVALID = 0x100,
348 NVME_SC_QID_INVALID = 0x101,
349 NVME_SC_QUEUE_SIZE = 0x102,
Matthew Wilcox7a63e072011-02-03 09:20:57 -0500350 NVME_SC_ABORT_LIMIT = 0x103,
351 NVME_SC_ABORT_MISSING = 0x104,
352 NVME_SC_ASYNC_LIMIT = 0x105,
353 NVME_SC_FIRMWARE_SLOT = 0x106,
354 NVME_SC_FIRMWARE_IMAGE = 0x107,
355 NVME_SC_INVALID_VECTOR = 0x108,
356 NVME_SC_INVALID_LOG_PAGE = 0x109,
357 NVME_SC_INVALID_FORMAT = 0x10a,
358 NVME_SC_BAD_ATTRIBUTES = 0x180,
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500359 NVME_SC_WRITE_FAULT = 0x280,
360 NVME_SC_READ_ERROR = 0x281,
Matthew Wilcox7a63e072011-02-03 09:20:57 -0500361 NVME_SC_GUARD_CHECK = 0x282,
362 NVME_SC_APPTAG_CHECK = 0x283,
363 NVME_SC_REFTAG_CHECK = 0x284,
364 NVME_SC_COMPARE_FAILED = 0x285,
365 NVME_SC_ACCESS_DENIED = 0x286,
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500366};
367
368struct nvme_completion {
369 __le32 result; /* Used by admin commands to return data */
Matthew Wilcox6ee44cd2011-02-03 10:58:26 -0500370 __u32 rsvd;
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500371 __le16 sq_head; /* how much of this queue may be reclaimed */
372 __le16 sq_id; /* submission queue that generated this entry */
373 __u16 command_id; /* of the command which completed */
374 __le16 status; /* did the command fail, and if so, why? */
375};
376
Matthew Wilcoxa53295b2011-02-01 16:13:29 -0500377struct nvme_user_io {
378 __u8 opcode;
379 __u8 flags;
380 __u16 control;
Matthew Wilcox6c7d4942011-03-21 09:48:57 -0400381 __u16 nblocks;
382 __u16 rsvd;
Matthew Wilcoxa53295b2011-02-01 16:13:29 -0500383 __u64 metadata;
384 __u64 addr;
385 __u64 slba;
Matthew Wilcoxa53295b2011-02-01 16:13:29 -0500386 __u32 dsmgmt;
387 __u32 reftag;
388 __u16 apptag;
389 __u16 appmask;
Matthew Wilcoxa53295b2011-02-01 16:13:29 -0500390};
391
Matthew Wilcox6bbf1ac2011-05-20 13:03:42 -0400392struct nvme_admin_cmd {
393 __u8 opcode;
394 __u8 flags;
395 __u16 rsvd1;
396 __u32 nsid;
397 __u32 cdw2;
398 __u32 cdw3;
399 __u64 metadata;
Matthew Wilcox6ee44cd2011-02-03 10:58:26 -0500400 __u64 addr;
Matthew Wilcox6bbf1ac2011-05-20 13:03:42 -0400401 __u32 metadata_len;
402 __u32 data_len;
403 __u32 cdw10;
404 __u32 cdw11;
405 __u32 cdw12;
406 __u32 cdw13;
407 __u32 cdw14;
408 __u32 cdw15;
409 __u32 timeout_ms;
410 __u32 result;
Matthew Wilcox6ee44cd2011-02-03 10:58:26 -0500411};
412
Matthew Wilcox6bbf1ac2011-05-20 13:03:42 -0400413#define NVME_IOCTL_ID _IO('N', 0x40)
414#define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd)
415#define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io)
Matthew Wilcoxb60503b2011-01-20 12:50:14 -0500416
417#endif /* _LINUX_NVME_H */