2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016 Nexenta Systems, Inc.
19 #include <sys/types.h>
22 #include <sys/types32.h>
28 * Declarations used for communication between nvmeadm(8) and nvme(7D)
36 * NVMe ioctl definitions
39 #define NVME_IOC (('N' << 24) | ('V' << 16) | ('M' << 8))
40 #define NVME_IOC_IDENTIFY_CTRL (NVME_IOC | 1)
41 #define NVME_IOC_IDENTIFY_NSID (NVME_IOC | 2)
42 #define NVME_IOC_CAPABILITIES (NVME_IOC | 3)
43 #define NVME_IOC_GET_LOGPAGE (NVME_IOC | 4)
44 #define NVME_IOC_GET_FEATURES (NVME_IOC | 5)
45 #define NVME_IOC_INTR_CNT (NVME_IOC | 6)
46 #define NVME_IOC_VERSION (NVME_IOC | 7)
47 #define NVME_IOC_FORMAT (NVME_IOC | 8)
48 #define NVME_IOC_DETACH (NVME_IOC | 9)
49 #define NVME_IOC_ATTACH (NVME_IOC | 10)
50 #define NVME_IOC_MAX NVME_IOC_ATTACH
52 #define IS_NVME_IOC(x) ((x) > NVME_IOC && (x) <= NVME_IOC_MAX)
53 #define NVME_IOC_CMD(x) ((x) & 0xff)
73 uint32_t mpsmax
; /* Memory Page Size Maximum */
74 uint32_t mpsmin
; /* Memory Page Size Minimum */
75 } nvme_capabilities_t
;
85 #define NVME_VERSION_ATLEAST(v, maj, min) \
86 (((v)->v_major) > (maj) || \
87 ((v)->v_major == (maj) && (v)->v_minor >= (min)))
89 #define NVME_VERSION_HIGHER(v, maj, min) \
90 (((v)->v_major) > (maj) || \
91 ((v)->v_major == (maj) && (v)->v_minor > (min)))
97 * NVMe Identify data structures
100 #define NVME_IDENTIFY_BUFSIZE 4096 /* buffer size for Identify */
102 /* NVMe Queue Entry Size bitfield */
104 uint8_t qes_min
:4; /* minimum entry size */
105 uint8_t qes_max
:4; /* maximum entry size */
108 /* NVMe Power State Descriptor */
110 uint16_t psd_mp
; /* Maximum Power */
112 uint8_t psd_mps
:1; /* Max Power Scale (1.1) */
113 uint8_t psd_nops
:1; /* Non-Operational State (1.1) */
115 uint32_t psd_enlat
; /* Entry Latency */
116 uint32_t psd_exlat
; /* Exit Latency */
117 uint8_t psd_rrt
:5; /* Relative Read Throughput */
119 uint8_t psd_rrl
:5; /* Relative Read Latency */
121 uint8_t psd_rwt
:5; /* Relative Write Throughput */
123 uint8_t psd_rwl
:5; /* Relative Write Latency */
125 uint8_t psd_rsvd7
[16];
128 /* NVMe Identify Controller Data Structure */
130 /* Controller Capabilities & Features */
131 uint16_t id_vid
; /* PCI vendor ID */
132 uint16_t id_ssvid
; /* PCI subsystem vendor ID */
133 char id_serial
[20]; /* Serial Number */
134 char id_model
[40]; /* Model Number */
135 char id_fwrev
[8]; /* Firmware Revision */
136 uint8_t id_rab
; /* Recommended Arbitration Burst */
137 uint8_t id_oui
[3]; /* vendor IEEE OUI */
138 struct { /* Multi-Interface Capabilities */
139 uint8_t m_multi_pci
:1; /* HW has multiple PCIe interfaces */
140 uint8_t m_multi_ctrl
:1; /* HW has multiple controllers (1.1) */
141 uint8_t m_sr_iov
:1; /* controller is SR-IOV virt fn (1.1) */
144 uint8_t id_mdts
; /* Maximum Data Transfer Size */
145 uint16_t id_cntlid
; /* Unique Controller Identifier (1.1) */
146 uint8_t id_rsvd_cc
[256 - 80];
148 /* Admin Command Set Attributes */
149 struct { /* Optional Admin Command Support */
150 uint16_t oa_security
:1; /* Security Send & Receive */
151 uint16_t oa_format
:1; /* Format NVM */
152 uint16_t oa_firmware
:1; /* Firmware Activate & Download */
155 uint8_t id_acl
; /* Abort Command Limit */
156 uint8_t id_aerl
; /* Asynchronous Event Request Limit */
157 struct { /* Firmware Updates */
158 uint8_t fw_readonly
:1; /* Slot 1 is Read-Only */
159 uint8_t fw_nslot
:3; /* number of firmware slots */
162 struct { /* Log Page Attributes */
163 uint8_t lp_smart
:1; /* SMART/Health information per NS */
166 uint8_t id_elpe
; /* Error Log Page Entries */
167 uint8_t id_npss
; /* Number of Power States */
168 struct { /* Admin Vendor Specific Command Conf */
169 uint8_t av_spec
:1; /* use format from spec */
172 struct { /* Autonomous Power State Trans (1.1) */
173 uint8_t ap_sup
:1; /* APST supported (1.1) */
176 uint8_t id_rsvd_ac
[256 - 10];
178 /* NVM Command Set Attributes */
179 nvme_idctl_qes_t id_sqes
; /* Submission Queue Entry Size */
180 nvme_idctl_qes_t id_cqes
; /* Completion Queue Entry Size */
181 uint16_t id_rsvd_nc_1
;
182 uint32_t id_nn
; /* Number of Namespaces */
183 struct { /* Optional NVM Command Support */
184 uint16_t on_compare
:1; /* Compare */
185 uint16_t on_wr_unc
:1; /* Write Uncorrectable */
186 uint16_t on_dset_mgmt
:1; /* Dataset Management */
187 uint16_t on_wr_zero
:1; /* Write Zeros (1.1) */
188 uint16_t on_save
:1; /* Save/Select in Get/Set Feat (1.1) */
189 uint16_t on_reserve
:1; /* Reservations (1.1) */
192 struct { /* Fused Operation Support */
193 uint16_t f_cmp_wr
:1; /* Compare and Write */
196 struct { /* Format NVM Attributes */
197 uint8_t fn_format
:1; /* Format applies to all NS */
198 uint8_t fn_sec_erase
:1; /* Secure Erase applies to all NS */
199 uint8_t fn_crypt_erase
:1; /* Cryptographic Erase supported */
202 struct { /* Volatile Write Cache */
203 uint8_t vwc_present
:1; /* Volatile Write Cache present */
206 uint16_t id_awun
; /* Atomic Write Unit Normal */
207 uint16_t id_awupf
; /* Atomic Write Unit Power Fail */
208 struct { /* NVM Vendor Specific Command Conf */
209 uint8_t nv_spec
:1; /* use format from spec */
212 uint8_t id_rsvd_nc_2
;
213 uint16_t id_acwu
; /* Atomic Compare & Write Unit (1.1) */
214 uint16_t id_rsvd_nc_3
;
215 struct { /* SGL Support (1.1) */
216 uint16_t sgl_sup
:1; /* SGL Supported in NVM cmds (1.1) */
217 uint16_t sgl_rsvd1
:15;
218 uint16_t sgl_bucket
:1; /* SGL Bit Bucket supported (1.1) */
219 uint16_t sgl_rsvd2
:15;
221 uint8_t id_rsvd_nc_4
[192 - 28];
223 /* I/O Command Set Attributes */
224 uint8_t id_rsvd_ioc
[1344];
226 /* Power State Descriptors */
227 nvme_idctl_psd_t id_psd
[32];
229 /* Vendor Specific */
231 } nvme_identify_ctrl_t
;
233 /* NVMe Identify Namespace LBA Format */
235 uint16_t lbaf_ms
; /* Metadata Size */
236 uint8_t lbaf_lbads
; /* LBA Data Size */
237 uint8_t lbaf_rp
:2; /* Relative Performance */
238 uint8_t lbaf_rsvd1
:6;
241 /* NVMe Identify Namespace Data Structure */
243 uint64_t id_nsize
; /* Namespace Size */
244 uint64_t id_ncap
; /* Namespace Capacity */
245 uint64_t id_nuse
; /* Namespace Utilization */
246 struct { /* Namespace Features */
247 uint8_t f_thin
:1; /* Thin Provisioning */
250 uint8_t id_nlbaf
; /* Number of LBA formats */
251 struct { /* Formatted LBA size */
252 uint8_t lba_format
:4; /* LBA format */
253 uint8_t lba_extlba
:1; /* extended LBA (includes metadata) */
256 struct { /* Metadata Capabilities */
257 uint8_t mc_extlba
:1; /* extended LBA transfers */
258 uint8_t mc_separate
:1; /* separate metadata transfers */
261 struct { /* Data Protection Capabilities */
262 uint8_t dp_type1
:1; /* Protection Information Type 1 */
263 uint8_t dp_type2
:1; /* Protection Information Type 2 */
264 uint8_t dp_type3
:1; /* Protection Information Type 3 */
265 uint8_t dp_first
:1; /* first 8 bytes of metadata */
266 uint8_t dp_last
:1; /* last 8 bytes of metadata */
269 struct { /* Data Protection Settings */
270 uint8_t dp_pinfo
:3; /* Protection Information enabled */
271 uint8_t dp_first
:1; /* first 8 bytes of metadata */
274 struct { /* NS Multi-Path/Sharing Cap (1.1) */
275 uint8_t nm_shared
:1; /* NS is shared (1.1) */
278 struct { /* Reservation Capabilities (1.1) */
279 uint8_t rc_persist
:1; /* Persist Through Power Loss (1.1) */
280 uint8_t rc_wr_excl
:1; /* Write Exclusive (1.1) */
281 uint8_t rc_excl
:1; /* Exclusive Access (1.1) */
282 uint8_t rc_wr_excl_r
:1; /* Wr Excl - Registrants Only (1.1) */
283 uint8_t rc_excl_r
:1; /* Excl Acc - Registrants Only (1.1) */
284 uint8_t rc_wr_excl_a
:1; /* Wr Excl - All Registrants (1.1) */
285 uint8_t rc_excl_a
:1; /* Excl Acc - All Registrants (1.1) */
288 uint8_t id_rsvd1
[120 - 32];
289 uint8_t id_eui64
[8]; /* IEEE Extended Unique Id (1.1) */
290 nvme_idns_lbaf_t id_lbaf
[16]; /* LBA Formats */
292 uint8_t id_rsvd2
[192];
294 uint8_t id_vs
[3712]; /* Vendor Specific */
295 } nvme_identify_nsid_t
;
299 * NVMe completion queue entry status field
302 uint16_t sf_p
:1; /* Phase Tag */
303 uint16_t sf_sc
:8; /* Status Code */
304 uint16_t sf_sct
:3; /* Status Code Type */
306 uint16_t sf_m
:1; /* More */
307 uint16_t sf_dnr
:1; /* Do Not Retry */
314 #define NVME_LOGPAGE_ERROR 0x1 /* Error Information */
315 #define NVME_LOGPAGE_HEALTH 0x2 /* SMART/Health Information */
316 #define NVME_LOGPAGE_FWSLOT 0x3 /* Firmware Slot Information */
319 uint64_t el_count
; /* Error Count */
320 uint16_t el_sqid
; /* Submission Queue ID */
321 uint16_t el_cid
; /* Command ID */
322 nvme_cqe_sf_t el_sf
; /* Status Field */
323 uint8_t el_byte
; /* Parameter Error Location byte */
324 uint8_t el_bit
:3; /* Parameter Error Location bit */
326 uint64_t el_lba
; /* Logical Block Address */
327 uint32_t el_nsid
; /* Namespace ID */
328 uint8_t el_vendor
; /* Vendor Specific Information avail */
329 uint8_t el_rsvd2
[64 - 29];
330 } nvme_error_log_entry_t
;
338 struct { /* Critical Warning */
339 uint8_t cw_avail
:1; /* available space too low */
340 uint8_t cw_temp
:1; /* temperature too high */
341 uint8_t cw_reliab
:1; /* degraded reliability */
342 uint8_t cw_readonly
:1; /* media is read-only */
343 uint8_t cw_volatile
:1; /* volatile memory backup failed */
346 uint16_t hl_temp
; /* Temperature */
347 uint8_t hl_avail_spare
; /* Available Spare */
348 uint8_t hl_avail_spare_thr
; /* Available Spare Threshold */
349 uint8_t hl_used
; /* Percentage Used */
350 uint8_t hl_rsvd1
[32 - 6];
351 nvme_uint128_t hl_data_read
; /* Data Units Read */
352 nvme_uint128_t hl_data_write
; /* Data Units Written */
353 nvme_uint128_t hl_host_read
; /* Host Read Commands */
354 nvme_uint128_t hl_host_write
; /* Host Write Commands */
355 nvme_uint128_t hl_ctrl_busy
; /* Controller Busy Time */
356 nvme_uint128_t hl_power_cycles
; /* Power Cycles */
357 nvme_uint128_t hl_power_on_hours
; /* Power On Hours */
358 nvme_uint128_t hl_unsafe_shutdn
; /* Unsafe Shutdowns */
359 nvme_uint128_t hl_media_errors
; /* Media Errors */
360 nvme_uint128_t hl_errors_logged
; /* Number of errors logged */
361 uint8_t hl_rsvd2
[512 - 192];
365 uint8_t fw_afi
:3; /* Active Firmware Slot */
368 char fw_frs
[7][8]; /* Firmware Revision / Slot */
369 uint8_t fw_rsvd3
[512 - 64];
376 #define NVME_FRMT_SES_NONE 0
377 #define NVME_FRMT_SES_USER 1
378 #define NVME_FRMT_SES_CRYPTO 2
379 #define NVME_FRMT_MAX_SES 2
381 #define NVME_FRMT_MAX_LBAF 15
385 uint32_t fm_lbaf
:4; /* LBA Format */
386 uint32_t fm_ms
:1; /* Metadata Settings */
387 uint32_t fm_pi
:3; /* Protection Information */
388 uint32_t fm_pil
:1; /* Prot. Information Location */
389 uint32_t fm_ses
:3; /* Secure Erase Settings */
390 uint32_t fm_resvd
:20;
397 * NVMe Get / Set Features
399 #define NVME_FEAT_ARBITRATION 0x1 /* Command Arbitration */
400 #define NVME_FEAT_POWER_MGMT 0x2 /* Power Management */
401 #define NVME_FEAT_LBA_RANGE 0x3 /* LBA Range Type */
402 #define NVME_FEAT_TEMPERATURE 0x4 /* Temperature Threshold */
403 #define NVME_FEAT_ERROR 0x5 /* Error Recovery */
404 #define NVME_FEAT_WRITE_CACHE 0x6 /* Volatile Write Cache */
405 #define NVME_FEAT_NQUEUES 0x7 /* Number of Queues */
406 #define NVME_FEAT_INTR_COAL 0x8 /* Interrupt Coalescing */
407 #define NVME_FEAT_INTR_VECT 0x9 /* Interrupt Vector Configuration */
408 #define NVME_FEAT_WRITE_ATOM 0xa /* Write Atomicity */
409 #define NVME_FEAT_ASYNC_EVENT 0xb /* Asynchronous Event Configuration */
410 #define NVME_FEAT_AUTO_PST 0xc /* Autonomous Power State Transition */
413 #define NVME_FEAT_PROGRESS 0x80 /* Software Progress Marker */
415 /* Arbitration Feature */
418 uint8_t arb_ab
:3; /* Arbitration Burst */
420 uint8_t arb_lpw
; /* Low Priority Weight */
421 uint8_t arb_mpw
; /* Medium Priority Weight */
422 uint8_t arb_hpw
; /* High Priority Weight */
425 } nvme_arbitration_t
;
427 /* Power Management Feature */
430 uint32_t pm_ps
:5; /* Power State */
436 /* LBA Range Type Feature */
439 uint32_t lr_num
:6; /* Number of LBA ranges */
443 } nvme_lba_range_type_t
;
446 uint8_t lr_type
; /* Type */
447 struct { /* Attributes */
448 uint8_t lr_write
:1; /* may be overwritten */
449 uint8_t lr_hidden
:1; /* hidden from OS/EFI/BIOS */
452 uint8_t lr_rsvd2
[14];
453 uint64_t lr_slba
; /* Starting LBA */
454 uint64_t lr_nlb
; /* Number of Logical Blocks */
455 uint8_t lr_guid
[16]; /* Unique Identifier */
456 uint8_t lr_rsvd3
[16];
459 #define NVME_LBA_RANGE_BUFSIZE 4096
461 /* Temperature Threshold Feature */
464 uint16_t tt_tmpth
; /* Temperature Threshold */
468 } nvme_temp_threshold_t
;
470 /* Error Recovery Feature */
473 uint16_t er_tler
; /* Time-Limited Error Recovery */
477 } nvme_error_recovery_t
;
479 /* Volatile Write Cache Feature */
482 uint32_t wc_wce
:1; /* Volatile Write Cache Enable */
486 } nvme_write_cache_t
;
488 /* Number of Queues Feature */
491 uint16_t nq_nsq
; /* Number of Submission Queues */
492 uint16_t nq_ncq
; /* Number of Completion Queues */
497 /* Interrupt Coalescing Feature */
500 uint8_t ic_thr
; /* Aggregation Threshold */
501 uint8_t ic_time
; /* Aggregation Time */
507 /* Interrupt Configuration Features */
510 uint16_t iv_iv
; /* Interrupt Vector */
511 uint16_t iv_cd
:1; /* Coalescing Disable */
517 /* Write Atomicity Feature */
520 uint32_t wa_dn
:1; /* Disable Normal */
524 } nvme_write_atomicity_t
;
526 /* Asynchronous Event Configuration Feature */
529 uint8_t aec_avail
:1; /* available space too low */
530 uint8_t aec_temp
:1; /* temperature too high */
531 uint8_t aec_reliab
:1; /* degraded reliability */
532 uint8_t aec_readonly
:1; /* media is read-only */
533 uint8_t aec_volatile
:1; /* volatile memory backup failed */
535 uint8_t aec_rsvd2
[3];
538 } nvme_async_event_conf_t
;
540 /* Autonomous Power State Transition Feature (1.1) */
543 uint8_t apst_apste
:1; /* APST enabled */
547 } nvme_auto_power_state_trans_t
;
550 uint32_t apst_rsvd1
:3;
551 uint32_t apst_itps
:5; /* Idle Transition Power State */
552 uint32_t apst_itpt
:24; /* Idle Time Prior to Transition */
554 } nvme_auto_power_state_t
;
556 #define NVME_AUTO_PST_BUFSIZE 256
558 /* Software Progress Marker Feature */
561 uint8_t spm_pbslc
; /* Pre-Boot Software Load Count */
565 } nvme_software_progress_marker_t
;
567 #pragma pack() /* pack(1) */
574 #endif /* _SYS_NVME_H */