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.
14 * Copyright (c) 2018, Joyent, Inc.
20 #include <sys/types.h>
23 #include <sys/types32.h>
29 * Declarations used for communication between nvmeadm(8) and nvme(7D)
37 * NVMe ioctl definitions
40 #define NVME_IOC (('N' << 24) | ('V' << 16) | ('M' << 8))
41 #define NVME_IOC_IDENTIFY_CTRL (NVME_IOC | 1)
42 #define NVME_IOC_IDENTIFY_NSID (NVME_IOC | 2)
43 #define NVME_IOC_CAPABILITIES (NVME_IOC | 3)
44 #define NVME_IOC_GET_LOGPAGE (NVME_IOC | 4)
45 #define NVME_IOC_GET_FEATURES (NVME_IOC | 5)
46 #define NVME_IOC_INTR_CNT (NVME_IOC | 6)
47 #define NVME_IOC_VERSION (NVME_IOC | 7)
48 #define NVME_IOC_FORMAT (NVME_IOC | 8)
49 #define NVME_IOC_DETACH (NVME_IOC | 9)
50 #define NVME_IOC_ATTACH (NVME_IOC | 10)
51 #define NVME_IOC_MAX NVME_IOC_ATTACH
53 #define IS_NVME_IOC(x) ((x) > NVME_IOC && (x) <= NVME_IOC_MAX)
54 #define NVME_IOC_CMD(x) ((x) & 0xff)
74 uint32_t mpsmax
; /* Memory Page Size Maximum */
75 uint32_t mpsmin
; /* Memory Page Size Minimum */
76 } nvme_capabilities_t
;
86 #define NVME_VERSION_ATLEAST(v, maj, min) \
87 (((v)->v_major) > (maj) || \
88 ((v)->v_major == (maj) && (v)->v_minor >= (min)))
90 #define NVME_VERSION_HIGHER(v, maj, min) \
91 (((v)->v_major) > (maj) || \
92 ((v)->v_major == (maj) && (v)->v_minor > (min)))
98 * NVMe Identify data structures
101 #define NVME_IDENTIFY_BUFSIZE 4096 /* buffer size for Identify */
103 /* NVMe Queue Entry Size bitfield */
105 uint8_t qes_min
:4; /* minimum entry size */
106 uint8_t qes_max
:4; /* maximum entry size */
109 /* NVMe Power State Descriptor */
111 uint16_t psd_mp
; /* Maximum Power */
113 uint8_t psd_mps
:1; /* Max Power Scale (1.1) */
114 uint8_t psd_nops
:1; /* Non-Operational State (1.1) */
116 uint32_t psd_enlat
; /* Entry Latency */
117 uint32_t psd_exlat
; /* Exit Latency */
118 uint8_t psd_rrt
:5; /* Relative Read Throughput */
120 uint8_t psd_rrl
:5; /* Relative Read Latency */
122 uint8_t psd_rwt
:5; /* Relative Write Throughput */
124 uint8_t psd_rwl
:5; /* Relative Write Latency */
126 uint16_t psd_idlp
; /* Idle Power (1.2) */
128 uint8_t psd_ips
:2; /* Idle Power Scale (1.2) */
130 uint16_t psd_actp
; /* Active Power (1.2) */
131 uint8_t psd_apw
:3; /* Active Power Workload (1.2) */
133 uint8_t psd_aps
:2; /* Active Power Scale */
134 uint8_t psd_rsvd10
[9];
137 /* NVMe Identify Controller Data Structure */
139 /* Controller Capabilities & Features */
140 uint16_t id_vid
; /* PCI vendor ID */
141 uint16_t id_ssvid
; /* PCI subsystem vendor ID */
142 char id_serial
[20]; /* Serial Number */
143 char id_model
[40]; /* Model Number */
144 char id_fwrev
[8]; /* Firmware Revision */
145 uint8_t id_rab
; /* Recommended Arbitration Burst */
146 uint8_t id_oui
[3]; /* vendor IEEE OUI */
147 struct { /* Multi-Interface Capabilities */
148 uint8_t m_multi_pci
:1; /* HW has multiple PCIe interfaces */
149 uint8_t m_multi_ctrl
:1; /* HW has multiple controllers (1.1) */
150 uint8_t m_sr_iov
:1; /* controller is SR-IOV virt fn (1.1) */
153 uint8_t id_mdts
; /* Maximum Data Transfer Size */
154 uint16_t id_cntlid
; /* Unique Controller Identifier (1.1) */
155 /* Added in NVMe 1.2 */
156 uint32_t id_ver
; /* Version */
157 uint32_t id_rtd3r
; /* RTD3 Resume Latency */
158 uint32_t id_rtd3e
; /* RTD3 Entry Latency */
159 uint32_t id_oaes
; /* Optional Asynchronous Events */
160 /* Added in NVMe 1.3 */
161 uint32_t id_ctratt
; /* Controller Attributes */
162 uint8_t id_rsvd_cc
[12];
163 uint8_t id_frguid
[16]; /* FRU GUID */
164 uint8_t id_rsvd2_cc
[240 - 128];
165 uint8_t id_rsvd_nvmemi
[255 - 240];
166 uint8_t id_mec
; /* Management Endpiont Capabilities */
168 /* Admin Command Set Attributes */
169 struct { /* Optional Admin Command Support */
170 uint16_t oa_security
:1; /* Security Send & Receive */
171 uint16_t oa_format
:1; /* Format NVM */
172 uint16_t oa_firmware
:1; /* Firmware Activate & Download */
175 uint8_t id_acl
; /* Abort Command Limit */
176 uint8_t id_aerl
; /* Asynchronous Event Request Limit */
177 struct { /* Firmware Updates */
178 uint8_t fw_readonly
:1; /* Slot 1 is Read-Only */
179 uint8_t fw_nslot
:3; /* number of firmware slots */
182 struct { /* Log Page Attributes */
183 uint8_t lp_smart
:1; /* SMART/Health information per NS */
186 uint8_t id_elpe
; /* Error Log Page Entries */
187 uint8_t id_npss
; /* Number of Power States */
188 struct { /* Admin Vendor Specific Command Conf */
189 uint8_t av_spec
:1; /* use format from spec */
192 struct { /* Autonomous Power State Trans (1.1) */
193 uint8_t ap_sup
:1; /* APST supported (1.1) */
196 /* Added in NVMe 1.2 */
197 uint16_t ap_wctemp
; /* Warning Composite Temperature */
198 uint16_t ap_cctemp
; /* Critical Composite Temperature */
199 uint16_t ap_mtfa
; /* Maximum Firmware Activation Time */
200 uint32_t ap_hmpre
; /* Host Memory Buffer Preferred Size */
201 uint32_t ap_hmmin
; /* Host Memory Buffer Min Size */
202 uint8_t ap_tnvmcap
[16]; /* Total NVM Capacity in Bytes */
203 uint8_t ap_unvmcap
[16]; /* Unallocated NVM Capacity */
204 uint32_t ap_rpmbs
; /* Replay Protected Memory Block */
205 /* Added in NVMe 1.3 */
206 uint16_t ap_edstt
; /* Extended Device Self-test time */
207 uint8_t ap_dsto
; /* Device Self-test Options */
208 uint8_t ap_fwug
; /* Firmware Update Granularity */
209 uint16_t ap_kas
; /* Keep Alive Support */
210 uint16_t ap_hctma
; /* Host Thermal Management */
211 uint16_t ap_mntmt
; /* Minimum Thermal Temperature */
212 uint16_t ap_mxtmt
; /* Maximum Thermal Temperature */
213 uint32_t ap_sanitize
; /* Sanitize Caps */
214 uint8_t id_rsvd_ac
[512 - 332];
216 /* NVM Command Set Attributes */
217 nvme_idctl_qes_t id_sqes
; /* Submission Queue Entry Size */
218 nvme_idctl_qes_t id_cqes
; /* Completion Queue Entry Size */
219 uint16_t id_maxcmd
; /* Max Outstanding Commands (1.3) */
220 uint32_t id_nn
; /* Number of Namespaces */
221 struct { /* Optional NVM Command Support */
222 uint16_t on_compare
:1; /* Compare */
223 uint16_t on_wr_unc
:1; /* Write Uncorrectable */
224 uint16_t on_dset_mgmt
:1; /* Dataset Management */
225 uint16_t on_wr_zero
:1; /* Write Zeros (1.1) */
226 uint16_t on_save
:1; /* Save/Select in Get/Set Feat (1.1) */
227 uint16_t on_reserve
:1; /* Reservations (1.1) */
230 struct { /* Fused Operation Support */
231 uint16_t f_cmp_wr
:1; /* Compare and Write */
234 struct { /* Format NVM Attributes */
235 uint8_t fn_format
:1; /* Format applies to all NS */
236 uint8_t fn_sec_erase
:1; /* Secure Erase applies to all NS */
237 uint8_t fn_crypt_erase
:1; /* Cryptographic Erase supported */
240 struct { /* Volatile Write Cache */
241 uint8_t vwc_present
:1; /* Volatile Write Cache present */
244 uint16_t id_awun
; /* Atomic Write Unit Normal */
245 uint16_t id_awupf
; /* Atomic Write Unit Power Fail */
246 struct { /* NVM Vendor Specific Command Conf */
247 uint8_t nv_spec
:1; /* use format from spec */
250 uint8_t id_rsvd_nc_2
;
251 uint16_t id_acwu
; /* Atomic Compare & Write Unit (1.1) */
252 uint16_t id_rsvd_nc_3
;
253 struct { /* SGL Support (1.1) */
254 uint16_t sgl_sup
:1; /* SGL Supported in NVM cmds (1.1) */
255 uint16_t sgl_rsvd1
:15;
256 uint16_t sgl_bucket
:1; /* SGL Bit Bucket supported (1.1) */
257 uint16_t sgl_rsvd2
:15;
259 uint8_t id_rsvd_nc_4
[768 - 540];
261 /* I/O Command Set Attributes */
262 uint8_t id_subnqn
[1024 - 768]; /* Subsystem Qualified Name (1.2.1+) */
263 uint8_t id_rsvd_ioc
[1792 - 1024];
264 uint8_t id_nvmof
[2048 - 1792]; /* NVMe over Fabrics */
266 /* Power State Descriptors */
267 nvme_idctl_psd_t id_psd
[32];
269 /* Vendor Specific */
271 } nvme_identify_ctrl_t
;
273 /* NVMe Identify Namespace LBA Format */
275 uint16_t lbaf_ms
; /* Metadata Size */
276 uint8_t lbaf_lbads
; /* LBA Data Size */
277 uint8_t lbaf_rp
:2; /* Relative Performance */
278 uint8_t lbaf_rsvd1
:6;
281 /* NVMe Identify Namespace Data Structure */
283 uint64_t id_nsize
; /* Namespace Size */
284 uint64_t id_ncap
; /* Namespace Capacity */
285 uint64_t id_nuse
; /* Namespace Utilization */
286 struct { /* Namespace Features */
287 uint8_t f_thin
:1; /* Thin Provisioning */
290 uint8_t id_nlbaf
; /* Number of LBA formats */
291 struct { /* Formatted LBA size */
292 uint8_t lba_format
:4; /* LBA format */
293 uint8_t lba_extlba
:1; /* extended LBA (includes metadata) */
296 struct { /* Metadata Capabilities */
297 uint8_t mc_extlba
:1; /* extended LBA transfers */
298 uint8_t mc_separate
:1; /* separate metadata transfers */
301 struct { /* Data Protection Capabilities */
302 uint8_t dp_type1
:1; /* Protection Information Type 1 */
303 uint8_t dp_type2
:1; /* Protection Information Type 2 */
304 uint8_t dp_type3
:1; /* Protection Information Type 3 */
305 uint8_t dp_first
:1; /* first 8 bytes of metadata */
306 uint8_t dp_last
:1; /* last 8 bytes of metadata */
309 struct { /* Data Protection Settings */
310 uint8_t dp_pinfo
:3; /* Protection Information enabled */
311 uint8_t dp_first
:1; /* first 8 bytes of metadata */
314 struct { /* NS Multi-Path/Sharing Cap (1.1) */
315 uint8_t nm_shared
:1; /* NS is shared (1.1) */
318 struct { /* Reservation Capabilities (1.1) */
319 uint8_t rc_persist
:1; /* Persist Through Power Loss (1.1) */
320 uint8_t rc_wr_excl
:1; /* Write Exclusive (1.1) */
321 uint8_t rc_excl
:1; /* Exclusive Access (1.1) */
322 uint8_t rc_wr_excl_r
:1; /* Wr Excl - Registrants Only (1.1) */
323 uint8_t rc_excl_r
:1; /* Excl Acc - Registrants Only (1.1) */
324 uint8_t rc_wr_excl_a
:1; /* Wr Excl - All Registrants (1.1) */
325 uint8_t rc_excl_a
:1; /* Excl Acc - All Registrants (1.1) */
328 uint8_t id_fpi
; /* Format Progress Indicator (1.2) */
329 uint8_t id_dfleat
; /* Deallocate Log. Block (1.3) */
330 uint16_t id_nawun
; /* Atomic Write Unit Normal (1.2) */
331 uint16_t id_nawupf
; /* Atomic Write Unit Power Fail (1.2) */
332 uint16_t id_nacwu
; /* Atomic Compare & Write Unit (1.2) */
333 uint16_t id_nabsn
; /* Atomic Boundary Size Normal (1.2) */
334 uint16_t id_nbao
; /* Atomic Boundary Offset (1.2) */
335 uint16_t id_nabspf
; /* Atomic Boundary Size Fail (1.2) */
336 uint16_t id_noiob
; /* Optimal I/O Bondary (1.3) */
337 uint8_t id_nvmcap
[16]; /* NVM Capacity */
338 uint8_t id_rsvd1
[104 - 64];
339 uint8_t id_nguid
[16]; /* Namespace GUID (1.2) */
340 uint8_t id_eui64
[8]; /* IEEE Extended Unique Id (1.1) */
341 nvme_idns_lbaf_t id_lbaf
[16]; /* LBA Formats */
343 uint8_t id_rsvd2
[384 - 192];
345 uint8_t id_vs
[4096 - 384]; /* Vendor Specific */
346 } nvme_identify_nsid_t
;
348 /* NVMe Identify Primary Controller Capabilities */
350 uint16_t nipc_cntlid
; /* Controller ID */
351 uint16_t nipc_portid
; /* Port Identifier */
352 uint8_t nipc_crt
; /* Controller Resource Types */
353 uint8_t nipc_rsvd0
[32 - 5];
354 uint32_t nipc_vqfrt
; /* VQ Resources Flexible Total */
355 uint32_t nipc_vqrfa
; /* VQ Resources Flexible Assigned */
356 uint16_t nipc_vqrfap
; /* VQ Resources to Primary */
357 uint16_t nipc_vqprt
; /* VQ Resources Private Total */
358 uint16_t nipc_vqfrsm
; /* VQ Resources Secondary Max */
359 uint16_t nipc_vqgran
; /* VQ Flexible Resource Gran */
360 uint8_t nipc_rvsd1
[64 - 48];
361 uint32_t nipc_vifrt
; /* VI Flexible total */
362 uint32_t nipc_virfa
; /* VI Flexible Assigned */
363 uint16_t nipc_virfap
; /* VI Flexible Allocatd to Primary */
364 uint16_t nipc_viprt
; /* VI Resources Private Total */
365 uint16_t nipc_vifrsm
; /* VI Resources Secondary Max */
366 uint16_t nipc_vigran
; /* VI Flexible Granularity */
367 uint8_t nipc_rsvd2
[4096 - 80];
368 } nvme_identify_primary_caps_t
;
371 * NVMe completion queue entry status field
374 uint16_t sf_p
:1; /* Phase Tag */
375 uint16_t sf_sc
:8; /* Status Code */
376 uint16_t sf_sct
:3; /* Status Code Type */
378 uint16_t sf_m
:1; /* More */
379 uint16_t sf_dnr
:1; /* Do Not Retry */
386 #define NVME_LOGPAGE_ERROR 0x1 /* Error Information */
387 #define NVME_LOGPAGE_HEALTH 0x2 /* SMART/Health Information */
388 #define NVME_LOGPAGE_FWSLOT 0x3 /* Firmware Slot Information */
391 uint64_t el_count
; /* Error Count */
392 uint16_t el_sqid
; /* Submission Queue ID */
393 uint16_t el_cid
; /* Command ID */
394 nvme_cqe_sf_t el_sf
; /* Status Field */
395 uint8_t el_byte
; /* Parameter Error Location byte */
396 uint8_t el_bit
:3; /* Parameter Error Location bit */
398 uint64_t el_lba
; /* Logical Block Address */
399 uint32_t el_nsid
; /* Namespace ID */
400 uint8_t el_vendor
; /* Vendor Specific Information avail */
401 uint8_t el_rsvd2
[64 - 29];
402 } nvme_error_log_entry_t
;
410 struct { /* Critical Warning */
411 uint8_t cw_avail
:1; /* available space too low */
412 uint8_t cw_temp
:1; /* temperature too high */
413 uint8_t cw_reliab
:1; /* degraded reliability */
414 uint8_t cw_readonly
:1; /* media is read-only */
415 uint8_t cw_volatile
:1; /* volatile memory backup failed */
418 uint16_t hl_temp
; /* Temperature */
419 uint8_t hl_avail_spare
; /* Available Spare */
420 uint8_t hl_avail_spare_thr
; /* Available Spare Threshold */
421 uint8_t hl_used
; /* Percentage Used */
422 uint8_t hl_rsvd1
[32 - 6];
423 nvme_uint128_t hl_data_read
; /* Data Units Read */
424 nvme_uint128_t hl_data_write
; /* Data Units Written */
425 nvme_uint128_t hl_host_read
; /* Host Read Commands */
426 nvme_uint128_t hl_host_write
; /* Host Write Commands */
427 nvme_uint128_t hl_ctrl_busy
; /* Controller Busy Time */
428 nvme_uint128_t hl_power_cycles
; /* Power Cycles */
429 nvme_uint128_t hl_power_on_hours
; /* Power On Hours */
430 nvme_uint128_t hl_unsafe_shutdn
; /* Unsafe Shutdowns */
431 nvme_uint128_t hl_media_errors
; /* Media Errors */
432 nvme_uint128_t hl_errors_logged
; /* Number of errors logged */
433 uint8_t hl_rsvd2
[512 - 192];
437 uint8_t fw_afi
:3; /* Active Firmware Slot */
440 char fw_frs
[7][8]; /* Firmware Revision / Slot */
441 uint8_t fw_rsvd3
[512 - 64];
448 #define NVME_FRMT_SES_NONE 0
449 #define NVME_FRMT_SES_USER 1
450 #define NVME_FRMT_SES_CRYPTO 2
451 #define NVME_FRMT_MAX_SES 2
453 #define NVME_FRMT_MAX_LBAF 15
457 uint32_t fm_lbaf
:4; /* LBA Format */
458 uint32_t fm_ms
:1; /* Metadata Settings */
459 uint32_t fm_pi
:3; /* Protection Information */
460 uint32_t fm_pil
:1; /* Prot. Information Location */
461 uint32_t fm_ses
:3; /* Secure Erase Settings */
462 uint32_t fm_resvd
:20;
469 * NVMe Get / Set Features
471 #define NVME_FEAT_ARBITRATION 0x1 /* Command Arbitration */
472 #define NVME_FEAT_POWER_MGMT 0x2 /* Power Management */
473 #define NVME_FEAT_LBA_RANGE 0x3 /* LBA Range Type */
474 #define NVME_FEAT_TEMPERATURE 0x4 /* Temperature Threshold */
475 #define NVME_FEAT_ERROR 0x5 /* Error Recovery */
476 #define NVME_FEAT_WRITE_CACHE 0x6 /* Volatile Write Cache */
477 #define NVME_FEAT_NQUEUES 0x7 /* Number of Queues */
478 #define NVME_FEAT_INTR_COAL 0x8 /* Interrupt Coalescing */
479 #define NVME_FEAT_INTR_VECT 0x9 /* Interrupt Vector Configuration */
480 #define NVME_FEAT_WRITE_ATOM 0xa /* Write Atomicity */
481 #define NVME_FEAT_ASYNC_EVENT 0xb /* Asynchronous Event Configuration */
482 #define NVME_FEAT_AUTO_PST 0xc /* Autonomous Power State Transition */
485 #define NVME_FEAT_PROGRESS 0x80 /* Software Progress Marker */
487 /* Arbitration Feature */
490 uint8_t arb_ab
:3; /* Arbitration Burst */
492 uint8_t arb_lpw
; /* Low Priority Weight */
493 uint8_t arb_mpw
; /* Medium Priority Weight */
494 uint8_t arb_hpw
; /* High Priority Weight */
497 } nvme_arbitration_t
;
499 /* Power Management Feature */
502 uint32_t pm_ps
:5; /* Power State */
508 /* LBA Range Type Feature */
511 uint32_t lr_num
:6; /* Number of LBA ranges */
515 } nvme_lba_range_type_t
;
518 uint8_t lr_type
; /* Type */
519 struct { /* Attributes */
520 uint8_t lr_write
:1; /* may be overwritten */
521 uint8_t lr_hidden
:1; /* hidden from OS/EFI/BIOS */
524 uint8_t lr_rsvd2
[14];
525 uint64_t lr_slba
; /* Starting LBA */
526 uint64_t lr_nlb
; /* Number of Logical Blocks */
527 uint8_t lr_guid
[16]; /* Unique Identifier */
528 uint8_t lr_rsvd3
[16];
531 #define NVME_LBA_RANGE_BUFSIZE 4096
533 /* Temperature Threshold Feature */
536 uint16_t tt_tmpth
; /* Temperature Threshold */
540 } nvme_temp_threshold_t
;
542 /* Error Recovery Feature */
545 uint16_t er_tler
; /* Time-Limited Error Recovery */
549 } nvme_error_recovery_t
;
551 /* Volatile Write Cache Feature */
554 uint32_t wc_wce
:1; /* Volatile Write Cache Enable */
558 } nvme_write_cache_t
;
560 /* Number of Queues Feature */
563 uint16_t nq_nsq
; /* Number of Submission Queues */
564 uint16_t nq_ncq
; /* Number of Completion Queues */
569 /* Interrupt Coalescing Feature */
572 uint8_t ic_thr
; /* Aggregation Threshold */
573 uint8_t ic_time
; /* Aggregation Time */
579 /* Interrupt Configuration Features */
582 uint16_t iv_iv
; /* Interrupt Vector */
583 uint16_t iv_cd
:1; /* Coalescing Disable */
589 /* Write Atomicity Feature */
592 uint32_t wa_dn
:1; /* Disable Normal */
596 } nvme_write_atomicity_t
;
598 /* Asynchronous Event Configuration Feature */
601 uint8_t aec_avail
:1; /* available space too low */
602 uint8_t aec_temp
:1; /* temperature too high */
603 uint8_t aec_reliab
:1; /* degraded reliability */
604 uint8_t aec_readonly
:1; /* media is read-only */
605 uint8_t aec_volatile
:1; /* volatile memory backup failed */
607 uint8_t aec_rsvd2
[3];
610 } nvme_async_event_conf_t
;
612 /* Autonomous Power State Transition Feature (1.1) */
615 uint8_t apst_apste
:1; /* APST enabled */
619 } nvme_auto_power_state_trans_t
;
622 uint32_t apst_rsvd1
:3;
623 uint32_t apst_itps
:5; /* Idle Transition Power State */
624 uint32_t apst_itpt
:24; /* Idle Time Prior to Transition */
626 } nvme_auto_power_state_t
;
628 #define NVME_AUTO_PST_BUFSIZE 256
630 /* Software Progress Marker Feature */
633 uint8_t spm_pbslc
; /* Pre-Boot Software Load Count */
637 } nvme_software_progress_marker_t
;
639 #pragma pack() /* pack(1) */
646 #endif /* _SYS_NVME_H */