2 * Definitions for the NVM Express interface
3 * Copyright (c) 2011, Intel Corporation.
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.
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
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.
22 #include <linux/types.h>
25 __u64 cap; /* Controller Capabilities */
26 __u32 vs; /* Version */
27 __u32 intms; /* Interrupt Mask Set */
28 __u32 intmc; /* Interrupt Mask Clear */
29 __u32 cc; /* Controller Configuration */
30 __u32 rsvd1; /* Reserved */
31 __u32 csts; /* Controller Status */
32 __u32 rsvd2; /* Reserved */
33 __u32 aqa; /* Admin Queue Attributes */
34 __u64 asq; /* Admin SQ Base Address */
35 __u64 acq; /* Admin CQ Base Address */
39 NVME_CC_ENABLE = 1 << 0,
40 NVME_CC_CSS_NVM = 0 << 4,
41 NVME_CC_MPS_SHIFT = 7,
42 NVME_CC_ARB_RR = 0 << 11,
43 NVME_CC_ARB_WRRU = 1 << 11,
44 NVME_CC_ARB_VS = 3 << 11,
45 NVME_CC_SHN_NONE = 0 << 13,
46 NVME_CC_SHN_NORMAL = 1 << 13,
47 NVME_CC_SHN_ABRUPT = 2 << 13,
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,
55 #define NVME_VS(major, minor) (major << 16 | minor)
103 struct nvme_lbaf lbaf[16];
109 NVME_NS_FEAT_THIN = 1 << 0,
110 NVME_LBAF_RP_BEST = 0,
111 NVME_LBAF_RP_BETTER = 1,
112 NVME_LBAF_RP_GOOD = 2,
113 NVME_LBAF_RP_DEGRADED = 3,
116 struct nvme_lba_range_type {
127 NVME_LBART_TYPE_FS = 0x01,
128 NVME_LBART_TYPE_RAID = 0x02,
129 NVME_LBART_TYPE_CACHE = 0x03,
130 NVME_LBART_TYPE_SWAP = 0x04,
132 NVME_LBART_ATTRIB_TEMP = 1 << 0,
133 NVME_LBART_ATTRIB_HIDE = 1 << 1,
139 nvme_cmd_flush = 0x00,
140 nvme_cmd_write = 0x01,
141 nvme_cmd_read = 0x02,
142 nvme_cmd_write_uncor = 0x04,
143 nvme_cmd_compare = 0x05,
147 struct nvme_common_command {
159 struct nvme_rw_command {
178 NVME_RW_LR = 1 << 15,
179 NVME_RW_FUA = 1 << 14,
180 NVME_RW_DSM_FREQ_UNSPEC = 0,
181 NVME_RW_DSM_FREQ_TYPICAL = 1,
182 NVME_RW_DSM_FREQ_RARE = 2,
183 NVME_RW_DSM_FREQ_READS = 3,
184 NVME_RW_DSM_FREQ_WRITES = 4,
185 NVME_RW_DSM_FREQ_RW = 5,
186 NVME_RW_DSM_FREQ_ONCE = 6,
187 NVME_RW_DSM_FREQ_PREFETCH = 7,
188 NVME_RW_DSM_FREQ_TEMP = 8,
189 NVME_RW_DSM_LATENCY_NONE = 0 << 4,
190 NVME_RW_DSM_LATENCY_IDLE = 1 << 4,
191 NVME_RW_DSM_LATENCY_NORM = 2 << 4,
192 NVME_RW_DSM_LATENCY_LOW = 3 << 4,
193 NVME_RW_DSM_SEQ_REQ = 1 << 6,
194 NVME_RW_DSM_COMPRESSED = 1 << 7,
199 enum nvme_admin_opcode {
200 nvme_admin_delete_sq = 0x00,
201 nvme_admin_create_sq = 0x01,
202 nvme_admin_get_log_page = 0x02,
203 nvme_admin_delete_cq = 0x04,
204 nvme_admin_create_cq = 0x05,
205 nvme_admin_identify = 0x06,
206 nvme_admin_abort_cmd = 0x08,
207 nvme_admin_set_features = 0x09,
208 nvme_admin_get_features = 0x0a,
209 nvme_admin_async_event = 0x0c,
210 nvme_admin_activate_fw = 0x10,
211 nvme_admin_download_fw = 0x11,
212 nvme_admin_format_nvm = 0x80,
213 nvme_admin_security_send = 0x81,
214 nvme_admin_security_recv = 0x82,
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,
238 struct nvme_identify {
250 struct nvme_features {
263 struct nvme_create_cq {
277 struct nvme_create_sq {
291 struct nvme_delete_queue {
301 struct nvme_download_firmware {
313 struct nvme_command {
315 struct nvme_common_command common;
316 struct nvme_rw_command rw;
317 struct nvme_identify identify;
318 struct nvme_features features;
319 struct nvme_create_cq create_cq;
320 struct nvme_create_sq create_sq;
321 struct nvme_delete_queue delete_queue;
322 struct nvme_download_firmware dlfw;
326 /* XXX: Sync with spec */
328 NVME_SC_SUCCESS = 0x0,
329 NVME_SC_INVALID_OPCODE = 0x1,
330 NVME_SC_INVALID_FIELD = 0x2,
331 NVME_SC_CMDID_CONFLICT = 0x3,
332 NVME_SC_DATA_XFER_ERROR = 0x4,
333 NVME_SC_POWER_LOSS = 0x5,
334 NVME_SC_INTERNAL = 0x6,
335 NVME_SC_ABORT_REQ = 0x7,
336 NVME_SC_ABORT_QUEUE = 0x8,
337 NVME_SC_FUSED_FAIL = 0x9,
338 NVME_SC_FUSED_MISSING = 0xa,
339 NVME_SC_INVALID_NS = 0xb,
340 NVME_SC_LBA_RANGE = 0x80,
341 NVME_SC_CAP_EXCEEDED = 0x81,
342 NVME_SC_NS_NOT_READY = 0x82,
343 NVME_SC_CQ_INVALID = 0x100,
344 NVME_SC_QID_INVALID = 0x101,
345 NVME_SC_QUEUE_SIZE = 0x102,
346 NVME_SC_ABORT_LIMIT = 0x103,
347 NVME_SC_ABORT_MISSING = 0x104,
348 NVME_SC_ASYNC_LIMIT = 0x105,
349 NVME_SC_FIRMWARE_SLOT = 0x106,
350 NVME_SC_FIRMWARE_IMAGE = 0x107,
351 NVME_SC_INVALID_VECTOR = 0x108,
352 NVME_SC_INVALID_LOG_PAGE = 0x109,
353 NVME_SC_INVALID_FORMAT = 0x10a,
354 NVME_SC_BAD_ATTRIBUTES = 0x180,
355 NVME_SC_WRITE_FAULT = 0x280,
356 NVME_SC_READ_ERROR = 0x281,
357 NVME_SC_GUARD_CHECK = 0x282,
358 NVME_SC_APPTAG_CHECK = 0x283,
359 NVME_SC_REFTAG_CHECK = 0x284,
360 NVME_SC_COMPARE_FAILED = 0x285,
361 NVME_SC_ACCESS_DENIED = 0x286,
364 struct nvme_completion {
365 __le32 result; /* Used by admin commands to return data */
367 __le16 sq_head; /* how much of this queue may be reclaimed */
368 __le16 sq_id; /* submission queue that generated this entry */
369 __u16 command_id; /* of the command which completed */
370 __le16 status; /* did the command fail, and if so, why? */
373 struct nvme_user_io {
392 __u32 length; /* In dwords */
393 __u32 offset; /* In dwords */
396 #define NVME_IOCTL_IDENTIFY_NS _IOW('N', 0x40, struct nvme_id_ns)
397 #define NVME_IOCTL_IDENTIFY_CTRL _IOW('N', 0x41, struct nvme_id_ctrl)
398 #define NVME_IOCTL_GET_RANGE_TYPE _IOW('N', 0x42, struct nvme_lba_range_type)
399 #define NVME_IOCTL_SUBMIT_IO _IOWR('N', 0x43, struct nvme_rw_command)
400 #define NVME_IOCTL_DOWNLOAD_FW _IOR('N', 0x44, struct nvme_dlfw)
401 #define NVME_IOCTL_ACTIVATE_FW _IO('N', 0x45)
403 #endif /* _LINUX_NVME_H */