1 /* 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 5 * 1.0 of the CDDL. 6 * 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. 10 */ 11 12 /* 13 * Copyright 2016 Nexenta Systems, Inc. 14 * Copyright 2020 Joyent, Inc. 15 * Copyright 2019 Western Digital Corporation 16 * Copyright 2026 Oxide Computer Company 17 * Copyright 2022 OmniOS Community Edition (OmniOSce) Association. 18 */ 19 20 #ifndef _SYS_NVME_H 21 #define _SYS_NVME_H 22 23 #include <sys/types.h> 24 #include <sys/debug.h> 25 #include <sys/stddef.h> 26 27 #ifdef _KERNEL 28 #include <sys/types32.h> 29 #else 30 #include <sys/uuid.h> 31 #include <stdint.h> 32 #endif 33 34 /* 35 * Declarations used for communication between nvme(4D) and libnvme. 36 */ 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 /* 43 * NVMe ioctl definitions 44 */ 45 46 #define NVME_IOC (('N' << 24) | ('V' << 16) | ('M' << 8)) 47 #define NVME_IOC_CTRL_INFO (NVME_IOC | 0) 48 #define NVME_IOC_IDENTIFY (NVME_IOC | 1) 49 #define NVME_IOC_GET_LOGPAGE (NVME_IOC | 2) 50 #define NVME_IOC_GET_FEATURE (NVME_IOC | 3) 51 #define NVME_IOC_FORMAT (NVME_IOC | 4) 52 #define NVME_IOC_BD_DETACH (NVME_IOC | 5) 53 #define NVME_IOC_BD_ATTACH (NVME_IOC | 6) 54 #define NVME_IOC_FIRMWARE_DOWNLOAD (NVME_IOC | 7) 55 #define NVME_IOC_FIRMWARE_COMMIT (NVME_IOC | 8) 56 #define NVME_IOC_PASSTHRU (NVME_IOC | 9) 57 #define NVME_IOC_NS_INFO (NVME_IOC | 10) 58 #define NVME_IOC_LOCK (NVME_IOC | 11) 59 #define NVME_IOC_UNLOCK (NVME_IOC | 12) 60 #define NVME_IOC_CTRL_ATTACH (NVME_IOC | 13) 61 #define NVME_IOC_CTRL_DETACH (NVME_IOC | 14) 62 #define NVME_IOC_NS_CREATE (NVME_IOC | 15) 63 #define NVME_IOC_NS_DELETE (NVME_IOC | 16) 64 #define NVME_IOC_MAX NVME_IOC_NS_DELETE 65 66 #define IS_NVME_IOC(x) ((x) > NVME_IOC && (x) <= NVME_IOC_MAX) 67 #define NVME_IOC_CMD(x) ((x) & 0xff) 68 69 /* 70 * This represents the set of all possible errors that can be returned from an 71 * ioctl. Our general rule of thumb is that we only will use an errno value to 72 * indicate that certain processing failed: a lack of privileges, bad minor, or 73 * failure to copy in and out the initial ioctl structure. However, if we get 74 * far enough that there is any other failure (including a failure to copy in 75 * and out nested data such as the identify command payload) then we will issue 76 * an error here. Put differently, our basic promise is that there should be a 77 * single straightforward meaning for any errno returned and instead all the 78 * nuance is here. Our goal is that no one should guess what of two dozen things 79 * an EINVAL might have referred to. 80 * 81 * When we are dealing with field parameters, there are three general classes of 82 * errors that we define that are common across all request structures: 83 * 84 * <REQ>_<FIELD>_RANGE RANGE class errors indicate that the value 85 * passed in is outside the range that the device 86 * supports. The range may vary based on the 87 * specification. This is used both for issues like 88 * bad alignment in a value (e.g. not 4-byte 89 * aligned) or a value that is larger than the 90 * maximum possible size. Because the namespace ID 91 * is shared in every request in the controller and 92 * is part of our standard ioctl handling, we use a 93 * single set of errors for that. 94 * 95 * <REQ>_<FIELD>_UNSUP This indicates that the controller cannot 96 * support any value in the given field. This is 97 * either because the field was introduced in an 98 * NVMe specification later than the controller 99 * supports or because there is an explicit feature 100 * bit that indicates whether or not this field is 101 * valid. Entries here may or may not have a 102 * namespace unsupported entry due to the fact that 103 * this is command specific. 104 * 105 * <REQ>_<FIELD>_UNUSE This class is perhaps the weirdest. This 106 * represents a case where a given field cannot be 107 * set because it is not used based on the 108 * specifics of the request. For example, if you're 109 * getting the health log page, you may not set the 110 * LSP or LSI for that log page, even if you have 111 * an NVMe 1.4 controller that supports both fields 112 * because they have no meaning. A similar example 113 * would be setting a controller ID when it has no 114 * meaning in a particular identify request. 115 * 116 * While every field will have a RANGE class error, some fields will not have an 117 * UNSUP or UNUSE class error depending on the specifics. A field that has 118 * always been present since NVMe 1.0 and is always valid, such as say the log 119 * page ID field for a get log page request or the length of a firmware download 120 * request, currently are always valid. It is possible that future revisions to 121 * the specification or our logic may change this. 122 */ 123 typedef enum { 124 /* 125 * Indicates that the command actually completed successfully. 126 */ 127 NVME_IOCTL_E_OK = 0, 128 /* 129 * Indicates that the controller failed the command and the controller 130 * specific (SC/SCT) are available. For all other errors, those fields 131 * are reserved. 132 */ 133 NVME_IOCTL_E_CTRL_ERROR, 134 /* 135 * Indicates that the controller is considered "dead" by the system and 136 * therefore is unusable. Separately, the controller may have been 137 * removed from the system due to hotplug or related. In that case, the 138 * gone variant is used to distinguish this. 139 */ 140 NVME_IOCTL_E_CTRL_DEAD, 141 NVME_IOCTL_E_CTRL_GONE, 142 /* 143 * Indicates that a bad namespace was requested. This would generally 144 * happen when referring to a namespace that is outside of controller's 145 * range. 146 */ 147 NVME_IOCTL_E_NS_RANGE, 148 /* 149 * Indicates that a namespace is not usable in this context. 150 */ 151 NVME_IOCTL_E_NS_UNUSE, 152 /* 153 * Indicates that the requested namespace could not be used because we 154 * are operating on a namespace minor and asked to operate on a 155 * different namespace. 156 */ 157 NVME_IOCTL_E_MINOR_WRONG_NS, 158 /* 159 * Indicates that the requested ioctl can only operate on the controller 160 * minor and we were on a namespace minor. This is not used for when a 161 * namespace is incorrectly requested otherwise. 162 */ 163 NVME_IOCTL_E_NOT_CTRL, 164 /* 165 * Indicates that we were asked to operate on the broadcast namespace 166 * either because it was specified or that was how the request was 167 * transformed and the broadcast namespace is not supported for this 168 * operation. 169 */ 170 NVME_IOCTL_E_NO_BCAST_NS, 171 /* 172 * Indicates that the operation failed because the operation requires a 173 * controller or namespace write lock and the caller did not have it. 174 */ 175 NVME_IOCTL_E_NEED_CTRL_WRLOCK, 176 NVME_IOCTL_E_NEED_NS_WRLOCK, 177 /* 178 * Indicates that the operation could not proceed because someone else 179 * has exclusive access currently to the controller or namespace and 180 * therefore this request (which does not require exclusive access) 181 * could not proceed. 182 */ 183 NVME_IOCTL_E_CTRL_LOCKED, 184 NVME_IOCTL_E_NS_LOCKED, 185 /* 186 * Indicates that a standard log page was requested that the kernel 187 * doesn't know about. 188 */ 189 NVME_IOCTL_E_UNKNOWN_LOG_PAGE, 190 /* 191 * Indicates that the controller does not support the requested log 192 * page; however, the kernel knows about it. 193 */ 194 NVME_IOCTL_E_UNSUP_LOG_PAGE, 195 /* 196 * Indicates that the log page's scope requires operating on something 197 * that isn't what was requested. For example, trying to request the 198 * firmware information page on a namespace. 199 */ 200 NVME_IOCTL_E_BAD_LOG_SCOPE, 201 /* 202 * Log page fields with bad values. 203 */ 204 NVME_IOCTL_E_LOG_CSI_RANGE, 205 NVME_IOCTL_E_LOG_LID_RANGE, 206 NVME_IOCTL_E_LOG_LSP_RANGE, 207 NVME_IOCTL_E_LOG_LSI_RANGE, 208 NVME_IOCTL_E_LOG_RAE_RANGE, 209 NVME_IOCTL_E_LOG_SIZE_RANGE, 210 NVME_IOCTL_E_LOG_OFFSET_RANGE, 211 /* 212 * Log page fields that may not be supported. 213 */ 214 NVME_IOCTL_E_LOG_CSI_UNSUP, 215 NVME_IOCTL_E_LOG_LSP_UNSUP, 216 NVME_IOCTL_E_LOG_LSI_UNSUP, 217 NVME_IOCTL_E_LOG_RAE_UNSUP, 218 NVME_IOCTL_E_LOG_OFFSET_UNSUP, 219 /* 220 * Log page fields that may not be usable, depending on context. 221 */ 222 NVME_IOCTL_E_LOG_LSP_UNUSE, 223 NVME_IOCTL_E_LOG_LSI_UNUSE, 224 NVME_IOCTL_E_LOG_RAE_UNUSE, 225 /* 226 * Indicates that no DMA memory was available for a request. 227 */ 228 NVME_IOCTL_E_NO_DMA_MEM, 229 /* 230 * Indicates that there was no kernel memory avilable for the request. 231 */ 232 NVME_IOCTL_E_NO_KERN_MEM, 233 /* 234 * Indicates that an error occurred while trying to fill out the DMA PRP 235 */ 236 NVME_IOCTL_E_BAD_PRP, 237 /* 238 * Indicates that a pointer to user data to read from or write to was 239 * not valid and generated a fault. Specifically this is for items that 240 * an ioctl structure points to. 241 */ 242 NVME_IOCTL_E_BAD_USER_DATA, 243 /* 244 * Indicates that the kernel does not know about the requested identify 245 * command. 246 */ 247 NVME_IOCTL_E_UNKNOWN_IDENTIFY, 248 /* 249 * Indicates that the controller does not support the requested identify 250 * command. 251 */ 252 NVME_IOCTL_E_UNSUP_IDENTIFY, 253 /* 254 * The following errors indicate either a bad value for a given identify 255 * argument. This would happen because the value is outside the 256 * supported range. There is no CNS or below as those are the 257 * higher-level errors right above this. 258 */ 259 NVME_IOCTL_E_IDENTIFY_CTRLID_RANGE, 260 /* 261 * Next, we have the unsupported and unusable pieces. The nsid was 262 * supported starting in NVMe 1.0, therefore it is never unsupported. 263 * However, the controller ID both requires controller support and is 264 * not usable in several requests. 265 */ 266 NVME_IOCTL_E_IDENTIFY_CTRLID_UNSUP, 267 NVME_IOCTL_E_IDENTIFY_CTRLID_UNUSE, 268 /* 269 * Indicates that the controller does not support the NVMe spec's 270 * general vendor unique command format. 271 */ 272 NVME_IOCTL_E_CTRL_VUC_UNSUP, 273 /* 274 * The following indicate bad values for given NVMe vendor unique 275 * command fields. All of the cdw1[2-5] fields are not part of this 276 * because there is nothing that we can validate. 277 */ 278 NVME_IOCTL_E_VUC_TIMEOUT_RANGE, 279 NVME_IOCTL_E_VUC_OPCODE_RANGE, 280 NVME_IOCTL_E_VUC_FLAGS_RANGE, 281 NVME_IOCTL_E_VUC_IMPACT_RANGE, 282 NVME_IOCTL_E_VUC_NDT_RANGE, 283 /* 284 * These indicate that the VUC data and that the corresponding pair of 285 * fields do not agree with each other. 286 */ 287 NVME_IOCTL_E_INCONSIST_VUC_FLAGS_NDT, 288 NVME_IOCTL_E_INCONSIST_VUC_BUF_NDT, 289 /* 290 * Indicates that the operation in question did not succeed because 291 * blkdev failed to detach. Most often this happens because the device 292 * node is busy. Reasons the device node could be busy include that the 293 * device is in a zpool, a file system is mounted, a process has the 294 * block device open, etc. 295 */ 296 NVME_IOCTL_E_BLKDEV_DETACH, 297 /* 298 * Indicates that the operation in question failed because we were 299 * unable to create and online a new blkdev child. 300 */ 301 NVME_IOCTL_E_BLKDEV_ATTACH, 302 /* 303 * Indicates that the namespace requested for an attach is not supported 304 * by the system. This would happen due to properties of the namespace 305 * itself (e.g. utilizing metadata sectors). 306 */ 307 NVME_IOCTL_E_UNSUP_ATTACH_NS, 308 /* 309 * Indicates that the format operation is not supported by the 310 * controller at all. 311 */ 312 NVME_IOCTL_E_CTRL_FORMAT_UNSUP, 313 /* 314 * Indicates that the controller does not support the ability to perform 315 * a cryptographic secure erase. 316 */ 317 NVME_IOCTL_E_CTRL_CRYPTO_SE_UNSUP, 318 /* 319 * Indicates that a format operation is targeting a namespace, but 320 * cannot be performed because it does not support formatting an 321 * individual namespace or performing a secure-erase of an individual 322 * namespace respectively. 323 */ 324 NVME_IOCTL_E_CTRL_NS_FORMAT_UNSUP, 325 NVME_IOCTL_E_CTRL_NS_SE_UNSUP, 326 /* 327 * The following indicate bad values for a format NVM request. 328 */ 329 NVME_IOCTL_E_FORMAT_LBAF_RANGE, 330 NVME_IOCTL_E_FORMAT_SES_RANGE, 331 /* 332 * Indicates that the requested LBA format is not supported due to its 333 * use of metadata. 334 */ 335 NVME_IOCTL_E_UNSUP_LBAF_META, 336 /* 337 * Indicates that the firmware commands are not supported by the 338 * controller at all. 339 */ 340 NVME_IOCTL_E_CTRL_FW_UNSUP, 341 /* 342 * Indicates that the controller has reported a firmware update 343 * granularity that exceeds the calculated / driver supported maximum 344 * DMA transfer size. As such we cannot perform this operation. 345 */ 346 NVME_IOCTL_E_FW_LOAD_IMPOS_GRAN, 347 /* 348 * The following indicate bad values for a firmware load's length and 349 * offset. 350 */ 351 NVME_IOCTL_E_FW_LOAD_LEN_RANGE, 352 NVME_IOCTL_E_FW_LOAD_OFFSET_RANGE, 353 /* 354 * The following indicate bad values for a firmware commit's slot and 355 * action. 356 */ 357 NVME_IOCTL_E_FW_COMMIT_SLOT_RANGE, 358 NVME_IOCTL_E_FW_COMMIT_ACTION_RANGE, 359 /* 360 * Indicates that an explicit attempt was made to download an image into 361 * a read-only slot. Note, some instances of this cannot be caught prior 362 * to issuing a command to the controller (commit action 0b11 as it can 363 * be used whether there is or isn't a staged image) and will result in 364 * a controller error. 365 */ 366 NVME_IOCTL_E_RO_FW_SLOT, 367 /* 368 * Indicates that the kernel doesn't know about the NVMe feature in 369 * question and therefore cannot proceed. 370 */ 371 NVME_IOCTL_E_UNKNOWN_FEATURE, 372 /* 373 * Indicates that while the system knows about the feature in question, 374 * it is not supported by the controller. 375 */ 376 NVME_IOCTL_E_UNSUP_FEATURE, 377 /* 378 * The following errors indicate a bad value for a given get feature 379 * field. This would happen because the value is outside the supported 380 * range. 381 */ 382 NVME_IOCTL_E_GET_FEAT_SEL_RANGE, 383 NVME_IOCTL_E_GET_FEAT_CDW11_RANGE, 384 NVME_IOCTL_E_GET_FEAT_DATA_RANGE, 385 /* 386 * This set of errors indicate that the field is not supported. This can 387 * happen because a given get feature command doesn't support setting 388 * this value, the field isn't supported in this revision of the 389 * controller, or similar issues. 390 */ 391 NVME_IOCTL_E_GET_FEAT_SEL_UNSUP, 392 /* 393 * Fields that may be circumstantially unusable. 394 */ 395 NVME_IOCTL_E_GET_FEAT_CDW11_UNUSE, 396 NVME_IOCTL_E_GET_FEAT_DATA_UNUSE, 397 /* 398 * The following errors indicate a bad lock type. 399 */ 400 NVME_IOCTL_E_BAD_LOCK_ENTITY, 401 NVME_IOCTL_E_BAD_LOCK_LEVEL, 402 NVME_IOCTL_E_BAD_LOCK_FLAGS, 403 /* 404 * Indicates that a namespace open cannot lock or unlock a controller. 405 */ 406 NVME_IOCTL_E_NS_CANNOT_LOCK_CTRL, 407 NVME_IOCTL_E_NS_CANNOT_UNLOCK_CTRL, 408 /* 409 * Indicates that this lock is already held by the caller. 410 */ 411 NVME_IOCTL_E_LOCK_ALREADY_HELD, 412 /* 413 * Indicates that we cannot take the controller lock, because the 414 * caller already has an active namespace lock. 415 */ 416 NVME_IOCTL_E_LOCK_NO_CTRL_WITH_NS, 417 /* 418 * Indicates that we cannot take a namespace lock because a controller 419 * write lock already exists. 420 */ 421 NVME_IOCTL_LOCK_NO_NS_WITH_CTRL_WRLOCK, 422 /* 423 * Indicates that we cannot take a namespace lock because we already 424 * have one. 425 */ 426 NVME_IOCTL_E_LOCK_NO_2ND_NS, 427 /* 428 * Indicate that a blocking wait for a lock was interrupted due to a 429 * signal. 430 */ 431 NVME_IOCTL_E_LOCK_WAIT_SIGNAL, 432 /* 433 * Indicates that the lock could not be acquired because it was already 434 * held and we were asked not to block on the lock. 435 */ 436 NVME_IOCTL_E_LOCK_WOULD_BLOCK, 437 /* 438 * Indicates that the lock operation could not proceed because the minor 439 * is already blocking on another lock operation. 440 */ 441 NVME_IOCTL_E_LOCK_PENDING, 442 /* 443 * Indicates that the requested lock could not be unlocked because it is 444 * not held. The minor may not hold the lock or it may be blocking for 445 * acquisition. 446 */ 447 NVME_IOCTL_E_LOCK_NOT_HELD, 448 /* 449 * Indicates that the requested lock could not be unlocked because the 450 * namespace requested is not the namespace that is currently locked. 451 */ 452 NVME_IOCTL_E_LOCK_WRONG_NS, 453 /* 454 * Indicates that the request could not proceed because a namespace is 455 * attached to blkdev. This would block a format operation, a vendor 456 * unique command that indicated that it would impact all namespaces, 457 * etc. 458 */ 459 NVME_IOCTL_E_NS_BLKDEV_ATTACH, 460 /* 461 * Indicates that the blkdev address somehow would have overflowed our 462 * internal buffer. 463 */ 464 NVME_IOCTL_E_BD_ADDR_OVER, 465 /* 466 * Indicates that Namespace Management commands are not supported by the 467 * controller at all. 468 */ 469 NVME_IOCTL_E_CTRL_NS_MGMT_UNSUP, 470 /* 471 * Indicates that the request could not proceed because the namespace is 472 * currently attached to a controller. 473 */ 474 NVME_IOCTL_E_NS_CTRL_ATTACHED, 475 NVME_IOCTL_E_NS_CTRL_NOT_ATTACHED, 476 /* 477 * This indicates that the namespace ID is valid; however, there is no 478 * namespace actually allocated for this ID. For example, when trying to 479 * attach or detach a controller to an unallocated namespace. 480 * 481 * When a namespace ID is invalid, the kernel will generally instead 482 * return NVME_IOCTL_E_NS_RANGE. 483 */ 484 NVME_IOCTL_E_NS_NO_NS, 485 /* 486 * Namespace Create fields with bad values 487 */ 488 NVME_IOCTL_E_NS_CREATE_NSZE_RANGE, 489 NVME_IOCTL_E_NS_CREATE_NCAP_RANGE, 490 NVME_IOCTL_E_NS_CREATE_CSI_RANGE, 491 NVME_IOCTL_E_NS_CREATE_FLBAS_RANGE, 492 NVME_IOCTL_E_NS_CREATE_NMIC_RANGE, 493 /* 494 * Namespace Create fields with unsupported versions. Currently this can 495 * only apply to the CSI. Note, there aren't unusable errors yet; 496 * however, that'll change when we support other CSI types. 497 */ 498 NVME_IOCTL_E_NS_CREATE_CSI_UNSUP, 499 /* 500 * We may have a valid CSI, but not support it at our end. This error 501 * indicates that. Similarly, the device may not support thin 502 * provisioning. 503 */ 504 NVME_IOCTL_E_DRV_CSI_UNSUP, 505 NVME_IOCTL_E_CTRL_THIN_PROV_UNSUP 506 } nvme_ioctl_errno_t; 507 508 /* 509 * This structure is embedded as the first item of every ioctl. It is also used 510 * directly for the following ioctls: 511 * 512 * - blkdev attach (NVME_IOC_ATTACH) 513 * - blkdev detach (NVME_IOC_DETACH) 514 * - controller attach (NVME_IOC_CTRL_ATTACH) 515 * - controller detach (NVME_IOC_CTRL_DETACH) 516 * - namespace delete (NVME_IOC_NS_DELETE) 517 */ 518 typedef struct { 519 /* 520 * This allows one to specify the namespace ID that the ioctl may 521 * target, if it supports it. This field may be left to zero to indicate 522 * that the current open device (whether the controller or a namespace) 523 * should be targeted. If a namespace is open, a value other than 0 or 524 * the current namespace's ID is invalid. 525 */ 526 uint32_t nioc_nsid; 527 /* 528 * These next three values represent a possible error that may have 529 * occurred. On every ioctl nioc_drv_err is set to a value from the 530 * nvme_ioctl_errno_t enumeration. Anything other than NVME_IOCTL_E_OK 531 * indicates a failure of some kind. Some error values will put 532 * supplemental information in sct and sc. For example, 533 * NVME_IOCTL_E_CTRL_ERROR uses that as a way to return the raw error 534 * values from the controller for someone to inspect. Others may use 535 * this for their own well-defined supplemental information. 536 */ 537 uint32_t nioc_drv_err; 538 uint32_t nioc_ctrl_sct; 539 uint32_t nioc_ctrl_sc; 540 } nvme_ioctl_common_t; 541 542 /* 543 * NVMe Identify Command (NVME_IOC_IDENTIFY). 544 */ 545 typedef struct { 546 nvme_ioctl_common_t nid_common; 547 uint32_t nid_cns; 548 uint32_t nid_ctrlid; 549 uintptr_t nid_data; 550 } nvme_ioctl_identify_t; 551 552 /* 553 * The following constants describe the maximum values that may be used in 554 * various identify requests. 555 */ 556 #define NVME_IDENTIFY_MAX_CTRLID 0xffff 557 #define NVME_IDENTIFY_MAX_NSID 0xffffffff 558 #define NVME_IDENTIFY_MAX_CNS_1v2 0xff 559 #define NVME_IDENTIFY_MAX_CNS_1v1 0x3 560 #define NVME_IDENTIFY_MAX_CNS 0x1 561 562 /* 563 * Get a specific feature (NVME_IOC_GET_FEATURE). 564 */ 565 typedef struct { 566 nvme_ioctl_common_t nigf_common; 567 uint32_t nigf_fid; 568 uint32_t nigf_sel; 569 uint32_t nigf_cdw11; 570 uintptr_t nigf_data; 571 uint64_t nigf_len; 572 uint32_t nigf_cdw0; 573 } nvme_ioctl_get_feature_t; 574 575 /* 576 * Feature maximums. 577 */ 578 #define NVME_FEAT_MAX_FID 0xff 579 #define NVME_FEAT_MAX_SEL 0x3 580 581 /* 582 * Get a specific log page (NVME_IOC_GET_LOGPAGE). By default, unused fields 583 * should be left at zero. The input data length is specified by nigl_len, in 584 * bytes. The NVMe specification does not provide a way for a controller to 585 * write less bytes than requested for a log page. It is undefined behavior if a 586 * log page read requests more data than is supported. If this is successful, 587 * nigl_len bytes will be copied out. 588 */ 589 typedef struct { 590 nvme_ioctl_common_t nigl_common; 591 uint32_t nigl_csi; 592 uint32_t nigl_lid; 593 uint32_t nigl_lsp; 594 uint32_t nigl_lsi; 595 uint32_t nigl_rae; 596 uint64_t nigl_len; 597 uint64_t nigl_offset; 598 uintptr_t nigl_data; 599 } nvme_ioctl_get_logpage_t; 600 601 /* 602 * The following constants describe the maximum values for fields that used in 603 * the log page request. Note, some of these change with the version. These 604 * values are inclusive. The default max is the lowest common value. Larger 605 * values are included here. While these values are what the command set 606 * maximums are, the device driver may support smaller minimums (e.g. for size). 607 */ 608 #define NVME_LOG_MAX_LID 0xff 609 #define NVME_LOG_MAX_LSP 0x0f 610 #define NVME_LOG_MAX_LSP_2v0 0x7f 611 #define NVME_LOG_MAX_LSI 0xffff 612 #define NVME_LOG_MAX_UUID 0x7f 613 #define NVME_LOG_MAX_CSI 0xff 614 #define NVME_LOG_MAX_RAE 0x1 615 #define NVME_LOG_MAX_OFFSET UINT64_MAX 616 617 /* 618 * These maximum size values are inclusive like the others. The fields are 12 619 * and 32-bits wide respectively, but are zero based. That is accounted for by 620 * the shifts below. 621 */ 622 #define NVME_LOG_MAX_SIZE ((1ULL << 12ULL) * 4ULL) 623 #define NVME_LOG_MAX_SIZE_1v2 ((1ULL << 32ULL) * 4ULL) 624 625 /* 626 * Inject a vendor-specific admin command (NVME_IOC_PASSTHRU). 627 */ 628 typedef struct { 629 nvme_ioctl_common_t npc_common; /* NSID and status */ 630 uint32_t npc_opcode; /* Command opcode. */ 631 uint32_t npc_timeout; /* Command timeout, in seconds. */ 632 uint32_t npc_flags; /* Flags for the command. */ 633 uint32_t npc_impact; /* Impact information */ 634 uint32_t npc_cdw0; /* Command-specific result DWord 0 */ 635 uint32_t npc_cdw12; /* Command-specific DWord 12 */ 636 uint32_t npc_cdw13; /* Command-specific DWord 13 */ 637 uint32_t npc_cdw14; /* Command-specific DWord 14 */ 638 uint32_t npc_cdw15; /* Command-specific DWord 15 */ 639 uint64_t npc_buflen; /* Size of npc_buf. */ 640 uintptr_t npc_buf; /* I/O source or destination */ 641 } nvme_ioctl_passthru_t; 642 643 /* 644 * Constants for the passthru admin commands. Because the timeout is a kernel 645 * property, we don't include that here. 646 */ 647 #define NVME_PASSTHRU_MIN_ADMIN_OPC 0xc0 648 #define NVME_PASSTHRU_MAX_ADMIN_OPC 0xff 649 650 /* Flags for NVMe passthru commands. */ 651 #define NVME_PASSTHRU_READ 0x1 /* Read from device */ 652 #define NVME_PASSTHRU_WRITE 0x2 /* Write to device */ 653 654 /* 655 * Impact information for NVMe passthru commands. The current impact flags are 656 * defined as follows: 657 * 658 * NVME_IMPACT_NS This implies that one or all of the namespaces may be 659 * changed. This command will rescan all namespace after 660 * this occurs and update our state as a result. However, 661 * this requires that all such namespaces not be attached 662 * to blkdev to continue. 663 */ 664 #define NVME_IMPACT_NS 0x01 665 666 667 /* 668 * Firmware download (NVME_IOC_FIRMWARE_DOWNLOAD). 669 */ 670 typedef struct { 671 nvme_ioctl_common_t fwl_common; 672 uintptr_t fwl_buf; 673 uint64_t fwl_len; 674 uint64_t fwl_off; 675 } nvme_ioctl_fw_load_t; 676 677 /* 678 * Firmware commit (NVME_IOC_FIRMWARE_COMMIT). This was previously called 679 * firmware activate in earlier specification revisions. 680 */ 681 typedef struct { 682 nvme_ioctl_common_t fwc_common; 683 uint32_t fwc_slot; 684 uint32_t fwc_action; 685 } nvme_ioctl_fw_commit_t; 686 687 /* 688 * Format NVM command (NVME_IOC_FORMAT) 689 */ 690 typedef struct { 691 nvme_ioctl_common_t nif_common; 692 uint32_t nif_lbaf; 693 uint32_t nif_ses; 694 } nvme_ioctl_format_t; 695 696 typedef enum { 697 NVME_LOCK_E_CTRL = 1, 698 NVME_LOCK_E_NS 699 } nvme_lock_ent_t; 700 701 typedef enum { 702 NVME_LOCK_L_READ = 1, 703 NVME_LOCK_L_WRITE 704 } nvme_lock_level_t; 705 706 typedef enum { 707 NVME_LOCK_F_DONT_BLOCK = 1 << 0 708 } nvme_lock_flags_t; 709 710 /* 711 * Lock structure (NVME_IOC_LOCK). 712 */ 713 typedef struct { 714 nvme_ioctl_common_t nil_common; 715 nvme_lock_ent_t nil_ent; 716 nvme_lock_level_t nil_level; 717 nvme_lock_flags_t nil_flags; 718 } nvme_ioctl_lock_t; 719 720 /* 721 * Unlock structure (NVME_IOC_UNLOCK). 722 */ 723 typedef struct { 724 nvme_ioctl_common_t niu_common; 725 nvme_lock_ent_t niu_ent; 726 } nvme_ioctl_unlock_t; 727 728 /* 729 * Namespace Management related structures and constants. Note, namespace 730 * controller attach, controller detach, and namespace delete all use the common 731 * ioctl structure at this time. 732 */ 733 #define NVME_NS_ATTACH_CTRL_ATTACH 0 734 #define NVME_NS_ATTACH_CTRL_DETACH 1 735 736 /* 737 * Constants related to fields here. These represent the specifications maximum 738 * size, even though there are additional constraints placed on it by the driver 739 * (e.g. we only allow creating a namespace with the NVM CSI). 740 */ 741 #define NVME_NS_MGMT_MAX_CSI 0xff 742 #define NVME_NS_MGMT_MAX_FLBAS 0xf 743 #define NVME_NS_MGMT_NMIC_MASK 0x1 744 745 /* 746 * Logical values for namespace multipath I/O and sharing capabilities (NMIC). 747 */ 748 typedef enum { 749 /* 750 * Indicates that no NVMe namespace sharing is permitted between 751 * controllers. 752 */ 753 NVME_NS_NMIC_T_NONE = 0, 754 /* 755 * Indicates that namespace sharing is allowed between controllers. This 756 * is equivalent to the SHRNS bit being set. 757 */ 758 NVME_NS_NMIC_T_SHARED, 759 /* 760 * Indicates that this is a dispersed namespace. A dispersed namespace 761 * implies a shared namespace and indicates that DISNS and SHRNS are 762 * both set. 763 */ 764 NVME_NS_NMIC_T_DISPERSED 765 } nvme_ns_nmic_t; 766 767 /* 768 * Namespace create structure (NVME_IOC_NS_CREATE). 769 */ 770 typedef struct { 771 nvme_ioctl_common_t nnc_common; 772 uint64_t nnc_nsze; 773 uint64_t nnc_ncap; 774 uint32_t nnc_csi; 775 uint32_t nnc_flbas; 776 uint32_t nnc_nmic; 777 uint32_t nnc_nsid; 778 } nvme_ioctl_ns_create_t; 779 780 /* 781 * 32-bit ioctl structures. These must be packed to be 4 bytes to get the proper 782 * ILP32 sizing. 783 */ 784 #if defined(_KERNEL) && defined(_SYSCALL32) 785 #pragma pack(4) 786 typedef struct { 787 nvme_ioctl_common_t nid_common; 788 uint32_t nid_cns; 789 uint32_t nid_ctrlid; 790 uintptr32_t nid_data; 791 } nvme_ioctl_identify32_t; 792 793 typedef struct { 794 nvme_ioctl_common_t nigf_common; 795 uint32_t nigf_fid; 796 uint32_t nigf_sel; 797 uint32_t nigf_cdw11; 798 uintptr32_t nigf_data; 799 uint64_t nigf_len; 800 uint32_t nigf_cdw0; 801 } nvme_ioctl_get_feature32_t; 802 803 typedef struct { 804 nvme_ioctl_common_t nigl_common; 805 uint32_t nigl_csi; 806 uint32_t nigl_lid; 807 uint32_t nigl_lsp; 808 uint32_t nigl_lsi; 809 uint32_t nigl_rae; 810 uint64_t nigl_len; 811 uint64_t nigl_offset; 812 uintptr32_t nigl_data; 813 } nvme_ioctl_get_logpage32_t; 814 815 typedef struct { 816 nvme_ioctl_common_t npc_common; /* NSID and status */ 817 uint32_t npc_opcode; /* Command opcode. */ 818 uint32_t npc_timeout; /* Command timeout, in seconds. */ 819 uint32_t npc_flags; /* Flags for the command. */ 820 uint32_t npc_impact; /* Impact information */ 821 uint32_t npc_cdw0; /* Command-specific result DWord 0 */ 822 uint32_t npc_cdw12; /* Command-specific DWord 12 */ 823 uint32_t npc_cdw13; /* Command-specific DWord 13 */ 824 uint32_t npc_cdw14; /* Command-specific DWord 14 */ 825 uint32_t npc_cdw15; /* Command-specific DWord 15 */ 826 uint64_t npc_buflen; /* Size of npc_buf. */ 827 uintptr32_t npc_buf; /* I/O source or destination */ 828 } nvme_ioctl_passthru32_t; 829 830 typedef struct { 831 nvme_ioctl_common_t fwl_common; 832 uintptr32_t fwl_buf; 833 uint64_t fwl_len; 834 uint64_t fwl_off; 835 } nvme_ioctl_fw_load32_t; 836 #pragma pack() /* pack(4) */ 837 #endif /* _KERNEL && _SYSCALL32 */ 838 839 /* 840 * NVMe capabilities. This is a set of fields that come from the controller's 841 * PCIe register space. 842 */ 843 typedef struct { 844 uint32_t cap_mpsmax; /* Memory Page Size Maximum */ 845 uint32_t cap_mpsmin; /* Memory Page Size Minimum */ 846 } nvme_capabilities_t; 847 848 /* 849 * NVMe version 850 */ 851 typedef struct { 852 uint16_t v_minor; 853 uint16_t v_major; 854 } nvme_version_t; 855 856 #define NVME_VERSION_ATLEAST(v, maj, min) \ 857 (((v)->v_major) > (maj) || \ 858 ((v)->v_major == (maj) && (v)->v_minor >= (min))) 859 860 #define NVME_VERSION_HIGHER(v, maj, min) \ 861 (((v)->v_major) > (maj) || \ 862 ((v)->v_major == (maj) && (v)->v_minor > (min))) 863 864 /* 865 * NVMe Namespace related constants. The maximum NSID is determined by the 866 * identify controller data structure. 867 */ 868 #define NVME_NSID_MIN 1 869 #define NVME_NSID_BCAST 0xffffffff 870 871 #pragma pack(1) 872 873 typedef struct { 874 uint64_t lo; 875 uint64_t hi; 876 } nvme_uint128_t; 877 878 /* 879 * NVMe Identify data structures 880 */ 881 882 #define NVME_IDENTIFY_BUFSIZE 4096 /* buffer size for Identify */ 883 884 /* NVMe Identify parameters (cdw10) */ 885 #define NVME_IDENTIFY_NSID 0x0 /* Identify Namespace */ 886 #define NVME_IDENTIFY_CTRL 0x1 /* Identify Controller */ 887 #define NVME_IDENTIFY_NSID_LIST 0x2 /* List Active Namespaces */ 888 #define NVME_IDENTIFY_NSID_DESC 0x3 /* Namespace ID Descriptors */ 889 890 #define NVME_IDENTIFY_NSID_ALLOC_LIST 0x10 /* List Allocated NSID */ 891 #define NVME_IDENTIFY_NSID_ALLOC 0x11 /* Identify Allocated NSID */ 892 #define NVME_IDENTIFY_NSID_CTRL_LIST 0x12 /* List Controllers on NSID */ 893 #define NVME_IDENTIFY_CTRL_LIST 0x13 /* Controller List */ 894 #define NVME_IDENTIFY_PRIMARY_CAPS 0x14 /* Primary Controller Caps */ 895 896 897 /* NVMe Queue Entry Size bitfield */ 898 typedef struct { 899 uint8_t qes_min:4; /* minimum entry size */ 900 uint8_t qes_max:4; /* maximum entry size */ 901 } nvme_idctl_qes_t; 902 903 /* NVMe Power State Descriptor */ 904 typedef struct { 905 uint16_t psd_mp; /* Maximum Power */ 906 uint8_t psd_rsvd16; 907 uint8_t psd_mps:1; /* Max Power Scale (1.1) */ 908 uint8_t psd_nops:1; /* Non-Operational State (1.1) */ 909 uint8_t psd_rsvd26:6; 910 uint32_t psd_enlat; /* Entry Latency */ 911 uint32_t psd_exlat; /* Exit Latency */ 912 uint8_t psd_rrt:5; /* Relative Read Throughput */ 913 uint8_t psd_rsvd101:3; 914 uint8_t psd_rrl:5; /* Relative Read Latency */ 915 uint8_t psd_rsvd109:3; 916 uint8_t psd_rwt:5; /* Relative Write Throughput */ 917 uint8_t psd_rsvd117:3; 918 uint8_t psd_rwl:5; /* Relative Write Latency */ 919 uint8_t psd_rsvd125:3; 920 uint16_t psd_idlp; /* Idle Power (1.2) */ 921 uint8_t psd_rsvd144:6; 922 uint8_t psd_ips:2; /* Idle Power Scale (1.2) */ 923 uint8_t psd_rsvd152; 924 uint16_t psd_actp; /* Active Power (1.2) */ 925 uint8_t psd_apw:3; /* Active Power Workload (1.2) */ 926 uint8_t psd_rsvd179:3; 927 uint8_t psd_aps:2; /* Active Power Scale */ 928 /* NVMe 2.1 additions */ 929 uint8_t psd_epfrt; /* Emergency Power Fail Recovery Time */ 930 uint8_t psd_fqvt; /* Forced Quiescence Vault Time */ 931 uint8_t psd_epfvt; /* Emergency Power Fail Vault Time */ 932 uint8_t psd_epfrts:4; /* EPFRT Scale */ 933 uint8_t psd_fqvts:4; /* FQVTS Scale */ 934 uint8_t psd_epfvts:4; /* EPFVTS Scale */ 935 uint8_t psd_rsvd216:4; 936 uint8_t psd_mbw; /* Max Bandwidth (2.3) */ 937 uint8_t psd_mbws:3; /* Max Bandwidth Scale (2.3) */ 938 uint8_t psd_rsvd:5; 939 uint8_t psd_rsvd240[2]; 940 } nvme_idctl_psd_t; 941 942 CTASSERT(sizeof (nvme_idctl_psd_t) == 32); 943 944 #define NVME_SERIAL_SZ 20 945 #define NVME_MODEL_SZ 40 946 #define NVME_FWVER_SZ 8 947 948 /* NVMe Identify Controller Data Structure */ 949 typedef struct { 950 /* Controller Capabilities & Features */ 951 uint16_t id_vid; /* PCI vendor ID */ 952 uint16_t id_ssvid; /* PCI subsystem vendor ID */ 953 char id_serial[NVME_SERIAL_SZ]; /* Serial Number */ 954 char id_model[NVME_MODEL_SZ]; /* Model Number */ 955 char id_fwrev[NVME_FWVER_SZ]; /* Firmware Revision */ 956 uint8_t id_rab; /* Recommended Arbitration Burst */ 957 uint8_t id_oui[3]; /* vendor IEEE OUI */ 958 struct { /* Multi-Interface Capabilities */ 959 uint8_t m_multi_pci:1; /* HW has multiple PCIe interfaces */ 960 uint8_t m_multi_ctrl:1; /* HW has multiple controllers (1.1) */ 961 uint8_t m_sr_iov:1; /* Controller is SR-IOV virt fn (1.1) */ 962 uint8_t m_anar_sup:1; /* ANA Reporting Supported (1.4) */ 963 uint8_t m_rsvd:4; 964 } id_mic; 965 uint8_t id_mdts; /* Maximum Data Transfer Size */ 966 uint16_t id_cntlid; /* Unique Controller Identifier (1.1) */ 967 /* Added in NVMe 1.2 */ 968 uint32_t id_ver; /* Version (1.2) */ 969 uint32_t id_rtd3r; /* RTD3 Resume Latency (1.2) */ 970 uint32_t id_rtd3e; /* RTD3 Entry Latency (1.2) */ 971 struct { 972 uint32_t oaes_rsvd0:8; 973 uint32_t oaes_nsan:1; /* Namespace Attribute Notices (1.2) */ 974 uint32_t oaes_fwact:1; /* Firmware Activation Notices (1.2) */ 975 uint32_t oaes_rsvd10:1; 976 uint32_t oaes_ansacn:1; /* Asymmetric NS Access Change (1.4) */ 977 uint32_t oaes_plat:1; /* Predictable Lat Event Agg. (1.4) */ 978 uint32_t oaes_lbasi:1; /* LBA Status Information (1.4) */ 979 uint32_t oaes_egeal:1; /* Endurance Group Event Agg. (1.4) */ 980 uint32_t oaes_nnss:1; /* Normal NVM Subsys Shutdown (2.0) */ 981 uint32_t oaes_tthr:1; /* Temp. Tresh. Hysteresis Rec (2.1) */ 982 uint32_t oaes_rgcns:1; /* Reach Group Change Notice (2.1) */ 983 uint32_t oaes_rsvd18:1; 984 uint32_t oaes_ansan:1; /* Allocated Namespace Attr. (2.1) */ 985 uint32_t oaes_ccrcn:1; /* X-Ctrl Reset Compl. Notices (2.3) */ 986 uint32_t oaes_lhcn:1; /* Lost Host Comms. Notices (2.3) */ 987 uint32_t oaes_rsvd22:5; 988 uint32_t oaes_zdcn:1; /* Zone Descriptor Change (2.0) */ 989 uint32_t oaes_rsvd28:3; 990 uint32_t oaes_dlpcn:1; /* Disc Log Page Change (2.0) */ 991 } id_oaes; 992 struct { 993 uint32_t ctrat_hid:1; /* 128-bit Host Identifier (1.2) */ 994 uint32_t ctrat_nops:1; /* Non-Operational Power State (1.3) */ 995 uint32_t ctrat_nvmset:1; /* NVMe Sets (1.4) */ 996 uint32_t ctrat_rrl:1; /* Read Recovery Levels (1.4) */ 997 uint32_t ctrat_engrp:1; /* Endurance Groups (1.4) */ 998 uint32_t ctrat_plm:1; /* Predictable Latency Mode (1.4) */ 999 uint32_t ctrat_tbkas:1; /* Traffic Based Keep Alive (1.4) */ 1000 uint32_t ctrat_nsg:1; /* Namespace Granularity (1.4) */ 1001 uint32_t ctrat_sqass:1; /* SQ Associations (1.4) */ 1002 uint32_t ctrat_uuid:1; /* UUID List (1.4) */ 1003 uint32_t ctrat_mds:1; /* Multi-Domain Subsys (2.0) */ 1004 uint32_t ctrat_fcm:1; /* Fixed Cap Management (2.0) */ 1005 uint32_t ctrat_vcm:1; /* Variable Cap Management (2.0) */ 1006 uint32_t ctrat_deg:1; /* Delete Endurance Group (2.0) */ 1007 uint32_t ctrat_dnvms:1; /* Delete NVM Set (2.0) */ 1008 uint32_t ctrat_elbas:1; /* Ext. LBA Formats (2.0) */ 1009 uint32_t ctrat_mem:1; /* MDTS and Size exclude Meta (2.1) */ 1010 uint32_t ctrat_hmbr:1; /* HMB Restrictions (2.1) */ 1011 uint32_t ctrat_rhii:1; /* Reservations and Host ID (2.1) */ 1012 uint32_t ctrat_fdps:1; /* Flexible Data Placement (2.1) */ 1013 uint32_t ctrat_pls:1; /* Power Limit Support (2.3) */ 1014 uint32_t ctrat_pms:1; /* Power Measurement Support (2.3) */ 1015 uint32_t ctrat_rsvd22:10; 1016 } id_ctratt; 1017 uint16_t id_rrls; /* Read Recovery Levels (1.4) */ 1018 struct { 1019 uint8_t bpcap_rpmbbpwps:2; /* RPMB Prot Write (2.1) */ 1020 uint8_t bpcap_sfbpwps:1; /* Set Feat RPMB (2.1) */ 1021 uint8_t bpcap_rsvd3:5; 1022 } id_bpcap; 1023 uint8_t id_rsvd_103; 1024 uint32_t id_nssl; /* NVM Subsystem Shutdown Lat. (2.1) */ 1025 uint8_t id_rsvd_108[2]; 1026 struct { 1027 uint8_t plsi_plsepf:1; /* PLS Emergency Power Fail (2.1) */ 1028 uint8_t plsi_plsfq:1; /* PLS Force Quiesce (2.1) */ 1029 uint8_t plsi_rvsd:6; 1030 } id_plsi; 1031 uint8_t id_cntrltype; /* Controller Type (1.4) */ 1032 uint8_t id_frguid[16]; /* FRU GUID (1.3) */ 1033 uint16_t id_crdt1; /* Command Retry Delay Time 1 (1.4) */ 1034 uint16_t id_crdt2; /* Command Retry Delay Time 2 (1.4) */ 1035 uint16_t id_crdt3; /* Command Retry Delay Time 3 (1.4) */ 1036 struct { 1037 uint8_t crcap_rrsup:1; /* Reachability Reporting (2.1) */ 1038 uint8_t crcap_rgidc:1; /* Group ID Changeable (2.1) */ 1039 uint8_t crcap_rsvd2:6; 1040 } id_crcap; 1041 uint8_t id_ciu; /* Controller Inst. Uniquifier (2.3) */ 1042 uint8_t id_cirn[8]; /* Controller Inst. Random Num. (2.3) */ 1043 uint8_t id_rsvd2_cc[240 - 144]; 1044 uint8_t id_rsvd_nvmemi[253 - 240]; 1045 /* NVMe-MI region */ 1046 struct { /* NVMe Subsystem Report */ 1047 uint8_t nvmsr_nvmesd:1; /* NVMe Storage Device */ 1048 uint8_t nvmsr_nvmee:1; /* NVMe Enclosure */ 1049 uint8_t nvmsr_rsvd:6; 1050 } id_nvmsr; 1051 struct { /* VPD Write Cycle Information */ 1052 uint8_t vwci_crem:7; /* Write Cycles Remaining */ 1053 uint8_t vwci_valid:1; /* Write Cycles Remaining Valid */ 1054 } id_vpdwc; 1055 struct { /* Management Endpoint Capabilities */ 1056 uint8_t mec_smbusme:1; /* SMBus Port Management Endpoint */ 1057 uint8_t mec_pcieme:1; /* PCIe Port Management Endpoint */ 1058 uint8_t mec_rsvd:6; 1059 } id_mec; 1060 1061 /* Admin Command Set Attributes */ 1062 struct { /* Optional Admin Command Support */ 1063 uint16_t oa_security:1; /* Security Send & Receive */ 1064 uint16_t oa_format:1; /* Format NVM */ 1065 uint16_t oa_firmware:1; /* Firmware Activate & Download */ 1066 uint16_t oa_nsmgmt:1; /* Namespace Management (1.2) */ 1067 uint16_t oa_selftest:1; /* Self Test (1.3) */ 1068 uint16_t oa_direct:1; /* Directives (1.3) */ 1069 uint16_t oa_nvmemi:1; /* MI-Send/Recv (1.3) */ 1070 uint16_t oa_virtmgmt:1; /* Virtualization Management (1.3) */ 1071 uint16_t oa_doorbell:1; /* Doorbell Buffer Config (1.3) */ 1072 uint16_t oa_lbastat:1; /* LBA Status (1.4) */ 1073 uint16_t oa_clfs:1; /* Command and Feat Lockdown (2.0) */ 1074 uint16_t oa_hmlms:1; /* Host Managed Live Migration (2.0) */ 1075 uint16_t oa_rsvd12:4; 1076 } id_oacs; 1077 uint8_t id_acl; /* Abort Command Limit */ 1078 uint8_t id_aerl; /* Asynchronous Event Request Limit */ 1079 struct { /* Firmware Updates */ 1080 uint8_t fw_readonly:1; /* Slot 1 is Read-Only */ 1081 uint8_t fw_nslot:3; /* number of firmware slots */ 1082 uint8_t fw_norst:1; /* Activate w/o reset (1.2) */ 1083 uint8_t fw_smud:1; /* Support Multiple Update Det. (2.0) */ 1084 uint8_t fw_rsvd6:2; 1085 } id_frmw; 1086 struct { /* Log Page Attributes */ 1087 uint8_t lp_smart:1; /* SMART/Health information per NS */ 1088 uint8_t lp_cmdeff:1; /* Command Effects (1.2) */ 1089 uint8_t lp_extsup:1; /* Extended Get Log Page (1.2) */ 1090 uint8_t lp_telemetry:1; /* Telemetry Log Pages (1.3) */ 1091 uint8_t lp_persist:1; /* Persistent Log Page (1.4) */ 1092 uint8_t lp_mlps:1; /* Misc. Log Page (2.0) */ 1093 uint8_t lp_da4s:1; /* Data Area 4 Support (2.0) */ 1094 uint8_t lp_rsvd7:1; 1095 } id_lpa; 1096 uint8_t id_elpe; /* Error Log Page Entries */ 1097 uint8_t id_npss; /* Number of Power States */ 1098 struct { /* Admin Vendor Specific Command Conf */ 1099 uint8_t av_spec:1; /* use format from spec */ 1100 uint8_t av_rsvd:7; 1101 } id_avscc; 1102 struct { /* Autonomous Power State Trans (1.1) */ 1103 uint8_t ap_sup:1; /* APST supported (1.1) */ 1104 uint8_t ap_rsvd:7; 1105 } id_apsta; 1106 uint16_t ap_wctemp; /* Warning Composite Temp. (1.2) */ 1107 uint16_t ap_cctemp; /* Critical Composite Temp. (1.2) */ 1108 uint16_t ap_mtfa; /* Maximum Firmware Activation (1.2) */ 1109 uint32_t ap_hmpre; /* Host Memory Buf Pref Size (1.2) */ 1110 uint32_t ap_hmmin; /* Host Memory Buf Min Size (1.2) */ 1111 nvme_uint128_t ap_tnvmcap; /* Total NVM Capacity in Bytes (1.2) */ 1112 nvme_uint128_t ap_unvmcap; /* Unallocated NVM Capacity (1.2) */ 1113 struct { /* Replay Protected Mem. Block (1.2) */ 1114 uint32_t rpmbs_units:3; /* Number of targets */ 1115 uint32_t rpmbs_auth:3; /* Auth method */ 1116 uint32_t rpmbs_rsvd:10; 1117 uint32_t rpmbs_tot:8; /* Total size in 128KB */ 1118 uint32_t rpmbs_acc:8; /* Access size in 512B */ 1119 } ap_rpmbs; 1120 /* Added in NVMe 1.3 */ 1121 uint16_t ap_edstt; /* Ext. Device Self-test time (1.3) */ 1122 struct { /* Device Self-test Options */ 1123 uint8_t dsto_sub:1; /* Subsystem level self-test (1.3) */ 1124 uint8_t dsto_hirs:1; /* Host-Initiated Refresh (2.1) */ 1125 uint8_t dsto_rsvd:6; 1126 } ap_dsto; 1127 uint8_t ap_fwug; /* Firmware Update Granularity (1.3) */ 1128 uint16_t ap_kas; /* Keep Alive Support (1.2) */ 1129 struct { /* Host Thermal Management (1.3) */ 1130 uint16_t hctma_hctm:1; /* Host Controlled (1.3) */ 1131 uint16_t hctma_rsvd:15; 1132 } ap_hctma; 1133 uint16_t ap_mntmt; /* Minimum Thermal Temperature (1.3) */ 1134 uint16_t ap_mxtmt; /* Maximum Thermal Temperature (1.3) */ 1135 struct { /* Sanitize Caps */ 1136 uint32_t san_ces:1; /* Crypto Erase Support (1.3) */ 1137 uint32_t san_bes:1; /* Block Erase Support (1.3) */ 1138 uint32_t san_ows:1; /* Overwite Support (1.3) */ 1139 uint32_t san_vers:1; /* Verification Support (2.1) */ 1140 uint32_t san_rsvd:25; 1141 uint32_t san_ndi:1; /* No-deallocate Inhibited (1.4) */ 1142 uint32_t san_nodmmas:2; /* No-Deallocate Modifies Media (1.4) */ 1143 } ap_sanitize; 1144 uint32_t ap_hmminds; /* Host Mem Buf Min Desc Entry (1.4) */ 1145 uint16_t ap_hmmaxd; /* How Mem Max Desc Entries (1.4) */ 1146 uint16_t ap_nsetidmax; /* Max NVMe set identifier (1.4) */ 1147 uint16_t ap_engidmax; /* Max Endurance Group ID (1.4) */ 1148 uint8_t ap_anatt; /* ANA Transition Time (1.4) */ 1149 struct { /* Asymmetric Namespace Access Caps */ 1150 uint8_t anacap_opt:1; /* Optimized State (1.4) */ 1151 uint8_t anacap_unopt:1; /* Un-optimized State (1.4) */ 1152 uint8_t anacap_inacc:1; /* Inaccessible State (1.4) */ 1153 uint8_t anacap_ploss:1; /* Persistent Loss (1.4) */ 1154 uint8_t anacap_chg:1; /* Change State (1.4 ) */ 1155 uint8_t anacap_rsvd:1; 1156 uint8_t anacap_grpns:1; /* ID Changes with NS Attach (1.4) */ 1157 uint8_t anacap_grpid:1; /* Supports Group ID (1.4) */ 1158 } ap_anacap; 1159 uint32_t ap_anagrpmax; /* ANA Group ID Max (1.4) */ 1160 uint32_t ap_nanagrpid; /* Number of ANA Group IDs (1.4) */ 1161 uint32_t ap_pels; /* Persistent Event Log Size (1.4) */ 1162 uint16_t ap_did; /* Domain ID (2.0) */ 1163 struct { 1164 uint8_t kpioc_kpios:1; /* Key Per I/O Sup (2.1) */ 1165 uint8_t kpioc_kpisc:1; /* Key Per I/O Scope (2.1) */ 1166 uint8_t kpioc_rsvd:6; 1167 } ap_kpioc; 1168 uint8_t ap_rsvd359; 1169 uint16_t ap_mptfawr; /* Max FW Act Time w/o Reset (2.1) */ 1170 uint8_t ap_rsvd362[368-362]; 1171 nvme_uint128_t ap_megcap; /* Max Endurance Group Cap (2.1) */ 1172 struct { 1173 uint8_t tmpthha_tmpthmh:3; /* Temp Tresh Max Hyst (2.1) */ 1174 uint8_t tmpthha_rsvd3:5; 1175 } ap_tmpthha; 1176 struct { 1177 uint8_t mupa_mups:2; /* Max. Unlimited Power Scale (2.3) */ 1178 uint8_t mupa_rsvd2:6; 1179 } ap_mupa; /* Max. Unlimited Power Attrs. (2.3) */ 1180 uint16_t ap_cqt; /* Command Quiesce Time (2.1) */ 1181 struct { 1182 struct { 1183 uint8_t cdpalg_hs3:1; /* HMAC-SHA-384 (2.3) */ 1184 uint8_t cdpalg_rsvd:7; 1185 } cdpa_cdpalg; /* CDP Authentication Algorithm (2.3) */ 1186 uint8_t cdpa_rsvd8; 1187 } ap_cdpa; /* Cfg. Device Personality Attr (2.3) */ 1188 uint16_t ap_mup; /* Maximum Unlimited Power (2.3) */ 1189 struct { 1190 uint8_t impsr_srv; /* Sample Rate Value (2.3) */ 1191 uint8_t impsr_srs; /* Sample Rate Scale (2.3) */ 1192 } ap_impsr; /* Interval Power Sample Rate (2.3) */ 1193 uint16_t ap_msmt; /* Maximum Stop Measure. Time (2.3) */ 1194 uint8_t ap_rsvd_ac[512 - 396]; 1195 1196 /* NVM Command Set Attributes */ 1197 nvme_idctl_qes_t id_sqes; /* Submission Queue Entry Size */ 1198 nvme_idctl_qes_t id_cqes; /* Completion Queue Entry Size */ 1199 uint16_t id_maxcmd; /* Max Outstanding Commands (1.3) */ 1200 uint32_t id_nn; /* Number of Namespaces */ 1201 struct { /* Optional NVM Command Support */ 1202 uint16_t on_compare:1; /* Compare */ 1203 uint16_t on_wr_unc:1; /* Write Uncorrectable */ 1204 uint16_t on_dset_mgmt:1; /* Dataset Management */ 1205 uint16_t on_wr_zero:1; /* Write Zeroes (1.1) */ 1206 uint16_t on_save:1; /* Save/Select in Get/Set Feat (1.1) */ 1207 uint16_t on_reserve:1; /* Reservations (1.1) */ 1208 uint16_t on_ts:1; /* Timestamp (1.3) */ 1209 uint16_t on_verify:1; /* Verify (1.4) */ 1210 uint16_t on_nvmcpys:1; /* Copy (2.0) */ 1211 uint16_t on_nvmcsa:1; /* NVM Copy Single Atomicity (2.1) */ 1212 uint16_t on_nvmafc:1; /* NVM All Fast Copy (2.1) */ 1213 uint16_t on_maxwzd:1; /* Max Write Zeroes w/ Dealloc (2.1) */ 1214 uint16_t on_nszs:1; /* Namespace zeros (2.1) */ 1215 uint16_t on_rsvd13:3; 1216 } id_oncs; 1217 struct { /* Fused Operation Support */ 1218 uint16_t f_cmp_wr:1; /* Compare and Write */ 1219 uint16_t f_rsvd:15; 1220 } id_fuses; 1221 struct { /* Format NVM Attributes */ 1222 uint8_t fn_format:1; /* Format applies to all NS */ 1223 uint8_t fn_sec_erase:1; /* Secure Erase applies to all NS */ 1224 uint8_t fn_crypt_erase:1; /* Cryptographic Erase supported */ 1225 uint8_t fn_fnvmbs:1; /* Format NVM Broadcast (2.0) */ 1226 uint8_t fn_rsvd:4; 1227 } id_fna; 1228 struct { /* Volatile Write Cache */ 1229 uint8_t vwc_present:1; /* Volatile Write Cache present */ 1230 uint8_t vwc_nsflush:2; /* Flush with NS ffffffff (1.4) */ 1231 uint8_t rsvd:5; 1232 } id_vwc; 1233 uint16_t id_awun; /* Atomic Write Unit Normal */ 1234 uint16_t id_awupf; /* Atomic Write Unit Power Fail */ 1235 struct { /* NVM Vendor Specific Command Conf */ 1236 uint8_t nv_spec:1; /* use format from spec */ 1237 uint8_t nv_rsvd:7; 1238 } id_nvscc; 1239 struct { /* Namespace Write Protection Caps */ 1240 uint8_t nwpc_base:1; /* Base support (1.4) */ 1241 uint8_t nwpc_wpupc:1; /* Write prot until power cycle (1.4) */ 1242 uint8_t nwpc_permwp:1; /* Permanent write prot (1.4) */ 1243 uint8_t nwpc_rsvd:5; 1244 } id_nwpc; 1245 uint16_t id_acwu; /* Atomic Compare & Write Unit (1.1) */ 1246 struct { 1247 uint16_t cdfs_cdf0s:1; /* Copy Desc Format 0 (2.0) */ 1248 uint16_t cdfs_cdf1s:1; /* Copy Desc Format 1 (2.0) */ 1249 uint16_t cdfs_cdf2s:1; /* Copy Desc Format 2 (2.1) */ 1250 uint16_t cdfs_cdf3s:1; /* Copy Desc Format 3 (2.1) */ 1251 uint16_t cdfs_cdf4s:1; /* Copy Desc Format 4 (2.1) */ 1252 uint16_t cdfs_rsvd5:11; 1253 } id_cdfs; 1254 struct { /* SGL Support (1.1) */ 1255 uint16_t sgl_sup:2; /* SGL Supported in NVM cmds (1.3) */ 1256 uint16_t sgl_keyed:1; /* Keyed SGL Support (1.2) */ 1257 uint16_t sgl_rsvd3:5; 1258 uint16_t sgl_sdt:8; /* SGL Desc Threshold (2.0) */ 1259 uint16_t sgl_bucket:1; /* SGL Bit Bucket supported (1.1) */ 1260 uint16_t sgl_balign:1; /* SGL Byte Aligned (1.2) */ 1261 uint16_t sgl_sglgtd:1; /* SGL Length Longer than Data (1.2) */ 1262 uint16_t sgl_mptr:1; /* SGL MPTR w/ SGL (1.2) */ 1263 uint16_t sgl_offset:1; /* SGL Address is offset (1.2) */ 1264 uint16_t sgl_tport:1; /* Transport SGL Data Block (1.4) */ 1265 uint16_t sgl_rsvd22:10; 1266 } id_sgls; 1267 uint32_t id_mnan; /* Maximum Num of Allowed NSes (1.4) */ 1268 nvme_uint128_t id_maxdna; /* Maximum Domain NS Attach (2.0) */ 1269 uint32_t id_maxcna; /* Maximum I/O Ctrl NS Attach (2.0) */ 1270 uint32_t id_oaqd; /* Optimal Agg. Queue Depth (2.1) */ 1271 uint8_t id_rhiri; /* Host-Init Refresh Ival (2.1) */ 1272 uint8_t id_hirt; /* Host-Init refresh time (2.1) */ 1273 uint16_t id_cmmrtd; /* Ctrl. Max Mem Track Desc (2.1) */ 1274 uint16_t id_nmmrtd; /* NVM Max Mem Track Desc (2.1) */ 1275 uint8_t id_minmrtg; /* Min Mem Range Track Gran (2.1) */ 1276 uint8_t id_maxmrtg; /* Max Mem Range Track Gran (2.1) */ 1277 struct { 1278 uint8_t trattr_thmcs:1; /* Track Host Memory Changes (2.1) */ 1279 uint8_t trattr_tudcs:1; /* Track User Data Changes (2.1) */ 1280 uint8_t trattr_mrtll:1; /* Memory Range Tracking Lim (2.1) */ 1281 uint8_t trattr_rsvd3:5; 1282 } id_trattr; 1283 uint8_t id_rsvd577; 1284 uint16_t id_mcudmq; /* Max Ctrl User Mig Queues (2.1) */ 1285 uint16_t id_mnsudmq; /* Max NVM Sys Mig Queues (2.1) */ 1286 uint16_t id_mcmr; /* Max CDQ Memory Ranges (2.1) */ 1287 uint16_t id_nmcmr; /* NVM Sub Max CDQ Mem Ranges (2.1) */ 1288 uint16_t id_mcdqpc; /* Max Ctrl Data Queue PRP (2.1) */ 1289 uint8_t id_rsvd_nc_4[768 - 588]; 1290 1291 /* I/O Command Set Attributes */ 1292 uint8_t id_subnqn[1024 - 768]; /* Subsystem Qualified Name (1.2.1+) */ 1293 uint8_t id_rsvd_ioc[1792 - 1024]; 1294 uint8_t id_nvmof[2048 - 1792]; /* NVMe over Fabrics */ 1295 1296 /* Power State Descriptors */ 1297 nvme_idctl_psd_t id_psd[32]; 1298 1299 /* Vendor Specific */ 1300 uint8_t id_vs[1024]; 1301 } nvme_identify_ctrl_t; 1302 1303 /* 1304 * NVMe Controller Types 1305 */ 1306 #define NVME_CNTRLTYPE_RSVD 0 1307 #define NVME_CNTRLTYPE_IO 1 1308 #define NVME_CNTRLTYPE_DISC 2 1309 #define NVME_CNTRLTYPE_ADMIN 3 1310 1311 /* 1312 * RPMBS Authentication Types 1313 */ 1314 #define NVME_RPMBS_AUTH_HMAC_SHA256 0 1315 1316 /* 1317 * NODMMAS Values 1318 */ 1319 #define NVME_NODMMAS_UNDEF 0x00 1320 #define NVME_NODMMAS_NOMOD 0x01 1321 #define NVME_NODMMAS_DOMOD 0x02 1322 1323 /* 1324 * VWC NSID flushes 1325 */ 1326 #define NVME_VWCNS_UNKNOWN 0x00 1327 #define NVME_VWCNS_UNSUP 0x02 1328 #define NVME_VWCNS_SUP 0x03 1329 1330 /* 1331 * SGL Support Values 1332 */ 1333 #define NVME_SGL_UNSUP 0x00 1334 #define NVME_SGL_SUP_UNALIGN 0x01 1335 #define NVME_SGL_SUP_ALIGN 0x02 1336 1337 /* NVMe Identify Namespace LBA Format */ 1338 typedef struct { 1339 uint16_t lbaf_ms; /* Metadata Size */ 1340 uint8_t lbaf_lbads; /* LBA Data Size */ 1341 uint8_t lbaf_rp:2; /* Relative Performance */ 1342 uint8_t lbaf_rsvd1:6; 1343 } nvme_idns_lbaf_t; 1344 1345 #define NVME_MAX_LBAF 16 1346 1347 /* NVMe Identify Namespace Data Structure */ 1348 typedef struct { 1349 uint64_t id_nsize; /* Namespace Size */ 1350 uint64_t id_ncap; /* Namespace Capacity */ 1351 uint64_t id_nuse; /* Namespace Utilization */ 1352 struct { /* Namespace Features */ 1353 uint8_t f_thin:1; /* Thin Provisioning */ 1354 uint8_t f_nsabp:1; /* Namespace atomics (1.2) */ 1355 uint8_t f_dae:1; /* Deallocated errors supported (1.2) */ 1356 uint8_t f_uidreuse:1; /* GUID reuse impossible (1.3) */ 1357 uint8_t f_optperf:2; /* Namespace I/O opt (1.4, N1.1) */ 1358 uint8_t f_mam:1; /* Multiple Atomicity (N1.1) */ 1359 uint8_t f_optrperf:1; /* Optional Read Perf (N1.1) */ 1360 } id_nsfeat; 1361 uint8_t id_nlbaf; /* Number of LBA formats */ 1362 struct { /* Formatted LBA size */ 1363 uint8_t lba_format:4; /* LBA format */ 1364 uint8_t lba_extlba:1; /* extended LBA (includes metadata) */ 1365 uint8_t lba_fidxu:2; /* Format Index Upper (N1.0) */ 1366 uint8_t lba_rsvd:1; 1367 } id_flbas; 1368 struct { /* Metadata Capabilities */ 1369 uint8_t mc_extlba:1; /* extended LBA transfers */ 1370 uint8_t mc_separate:1; /* separate metadata transfers */ 1371 uint8_t mc_rsvd:6; 1372 } id_mc; 1373 struct { /* Data Protection Capabilities */ 1374 uint8_t dp_type1:1; /* Protection Information Type 1 */ 1375 uint8_t dp_type2:1; /* Protection Information Type 2 */ 1376 uint8_t dp_type3:1; /* Protection Information Type 3 */ 1377 uint8_t dp_first:1; /* first 8 bytes of metadata */ 1378 uint8_t dp_last:1; /* last 8 bytes of metadata */ 1379 uint8_t dp_rsvd:3; 1380 } id_dpc; 1381 struct { /* Data Protection Settings */ 1382 uint8_t dp_pinfo:3; /* Protection Information enabled */ 1383 uint8_t dp_first:1; /* first 8 bytes of metadata */ 1384 uint8_t dp_rsvd:4; 1385 } id_dps; 1386 struct { /* NS Multi-Path/Sharing Cap (1.1) */ 1387 uint8_t nm_shared:1; /* NS is shared (1.1) */ 1388 uint8_t nm_disperse:1; /* NS is dispersed (2.1) */ 1389 uint8_t nm_rsvd:6; 1390 } id_nmic; 1391 struct { /* Reservation Capabilities (1.1) */ 1392 uint8_t rc_persist:1; /* Persist Through Power Loss (1.1) */ 1393 uint8_t rc_wr_excl:1; /* Write Exclusive (1.1) */ 1394 uint8_t rc_excl:1; /* Exclusive Access (1.1) */ 1395 uint8_t rc_wr_excl_r:1; /* Wr Excl - Registrants Only (1.1) */ 1396 uint8_t rc_excl_r:1; /* Excl Acc - Registrants Only (1.1) */ 1397 uint8_t rc_wr_excl_a:1; /* Wr Excl - All Registrants (1.1) */ 1398 uint8_t rc_excl_a:1; /* Excl Acc - All Registrants (1.1) */ 1399 uint8_t rc_ign_ekey:1; /* Ignore Existing Key (1.3) */ 1400 } id_rescap; 1401 struct { /* Format Progress Indicator (1.2) */ 1402 uint8_t fpi_remp:7; /* Percent NVM Format Remaining (1.2) */ 1403 uint8_t fpi_sup:1; /* Supported (1.2) */ 1404 } id_fpi; 1405 struct { 1406 uint8_t dlfeat_drb:3; /* Deallocation Read Behavior (1.3) */ 1407 uint8_t dlfeat_wzds:1; /* Write Zeroes Deallocation (1.3) */ 1408 uint8_t dlfeat_gds:1; /* Guard Deallocation Status (1.3) */ 1409 uint8_t dlfeat_rsvd5:3; 1410 } id_dlfeat; 1411 uint16_t id_nawun; /* Atomic Write Unit Normal (1.2) */ 1412 uint16_t id_nawupf; /* Atomic Write Unit Power Fail (1.2) */ 1413 uint16_t id_nacwu; /* Atomic Compare & Write Unit (1.2) */ 1414 uint16_t id_nabsn; /* Atomic Boundary Size Normal (1.2) */ 1415 uint16_t id_nbao; /* Atomic Boundary Offset (1.2) */ 1416 uint16_t id_nabspf; /* Atomic Boundary Size Fail (1.2) */ 1417 uint16_t id_noiob; /* Optimal I/O Boundary (1.3) */ 1418 nvme_uint128_t id_nvmcap; /* NVM Capacity */ 1419 uint16_t id_npwg; /* NS Pref. Write Gran. (1.4) */ 1420 uint16_t id_npwa; /* NS Pref. Write Align. (1.4) */ 1421 uint16_t id_npdg; /* NS Pref. Deallocate Gran. (1.4) */ 1422 uint16_t id_npda; /* NS Pref. Deallocate Align. (1.4) */ 1423 uint16_t id_nows; /* NS. Optimal Write Size (1.4) */ 1424 uint16_t id_mssrl; /* Max Single Source Range (N1.0) */ 1425 uint32_t id_mcl; /* Max Copy Length (N1.0) */ 1426 uint8_t id_msrc; /* Max Source Range (N1.0) */ 1427 struct { 1428 uint8_t kpios_kpioens:1; /* Key Per I/O En (N1.1) */ 1429 uint8_t kpios_kpiosns:1; /* Key Per I/O Sup (N1.1) */ 1430 uint8_t kpios_rsvd2:6; 1431 } id_kpios; 1432 uint8_t id_nulbaf; /* Unique Attr. LBA Formats (N1.1) */ 1433 uint8_t id_rsvd83; 1434 uint32_t id_kpiodaag; /* Key Per I/O Access Gran (N1.1) */ 1435 uint8_t id_rsvd1[92 - 88]; 1436 uint32_t id_anagrpid; /* ANA Group Identifier (1.4) */ 1437 uint8_t id_rsvd2[99 - 96]; 1438 struct { 1439 uint8_t nsa_wprot:1; /* Write Protected (1.4) */ 1440 uint8_t nsa_rsvd:7; 1441 } id_nsattr; 1442 uint16_t id_nvmsetid; /* NVM Set Identifier (1.4) */ 1443 uint16_t id_endgid; /* Endurance Group Identifier (1.4) */ 1444 uint8_t id_nguid[16]; /* Namespace GUID (1.2) */ 1445 uint8_t id_eui64[8]; /* IEEE Extended Unique Id (1.1) */ 1446 nvme_idns_lbaf_t id_lbaf[NVME_MAX_LBAF]; /* LBA Formats */ 1447 /* 1448 * This region contains additional LBAF and should be updated as part of 1449 * enabling support for additional LBA formats in the stack. 1450 */ 1451 uint8_t id_rsvd3[384 - 192]; 1452 1453 uint8_t id_vs[4096 - 384]; /* Vendor Specific */ 1454 } nvme_identify_nsid_t; 1455 1456 /* NVMe Identify Namespace ID List */ 1457 typedef struct { 1458 /* Ordered list of Namespace IDs */ 1459 uint32_t nl_nsid[NVME_IDENTIFY_BUFSIZE / sizeof (uint32_t)]; 1460 } nvme_identify_nsid_list_t; 1461 1462 /* NVME Identify Controller ID List */ 1463 typedef struct { 1464 uint16_t cl_nid; /* Number of controller entries */ 1465 /* unique controller identifiers */ 1466 uint16_t cl_ctlid[NVME_IDENTIFY_BUFSIZE / sizeof (uint16_t) - 1]; 1467 } nvme_identify_ctrl_list_t; 1468 1469 /* NVMe Identify Namespace Descriptor */ 1470 typedef struct { 1471 uint8_t nd_nidt; /* Namespace Identifier Type */ 1472 uint8_t nd_nidl; /* Namespace Identifier Length */ 1473 uint8_t nd_resv[2]; 1474 uint8_t nd_nid[]; /* Namespace Identifier */ 1475 } nvme_identify_nsid_desc_t; 1476 1477 #define NVME_NSID_DESC_EUI64 1 1478 #define NVME_NSID_DESC_NGUID 2 1479 #define NVME_NSID_DESC_NUUID 3 1480 #define NVME_NSID_DESC_CSI 4 /* 2.1 */ 1481 #define NVME_NSID_DESC_MIN NVME_NSID_DESC_EUI64 1482 #define NVME_NSID_DESC_MAX NVME_NSID_DESC_CSI 1483 1484 #define NVME_NSID_DESC_LEN_EUI64 8 1485 #define NVME_NSID_DESC_LEN_NGUID 16 1486 #define NVME_NSID_DESC_LEN_NUUID UUID_LEN 1487 #define NVME_NSID_DESC_LEN_CSI 1 1488 1489 /* NVMe Identify Primary Controller Capabilities */ 1490 typedef struct { 1491 uint16_t nipc_cntlid; /* Controller ID */ 1492 uint16_t nipc_portid; /* Port Identifier */ 1493 uint8_t nipc_crt; /* Controller Resource Types */ 1494 uint8_t nipc_rsvd0[32 - 5]; 1495 uint32_t nipc_vqfrt; /* VQ Resources Flexible Total */ 1496 uint32_t nipc_vqrfa; /* VQ Resources Flexible Assigned */ 1497 uint16_t nipc_vqrfap; /* VQ Resources to Primary */ 1498 uint16_t nipc_vqprt; /* VQ Resources Private Total */ 1499 uint16_t nipc_vqfrsm; /* VQ Resources Secondary Max */ 1500 uint16_t nipc_vqgran; /* VQ Flexible Resource Gran */ 1501 uint8_t nipc_rvsd1[64 - 48]; 1502 uint32_t nipc_vifrt; /* VI Flexible total */ 1503 uint32_t nipc_virfa; /* VI Flexible Assigned */ 1504 uint16_t nipc_virfap; /* VI Flexible Allocated to Primary */ 1505 uint16_t nipc_viprt; /* VI Resources Private Total */ 1506 uint16_t nipc_vifrsm; /* VI Resources Secondary Max */ 1507 uint16_t nipc_vigran; /* VI Flexible Granularity */ 1508 uint8_t nipc_rsvd2[4096 - 80]; 1509 } nvme_identify_primary_caps_t; 1510 1511 /* 1512 * NVMe completion queue entry status field 1513 */ 1514 typedef struct { 1515 uint16_t sf_p:1; /* Phase Tag */ 1516 uint16_t sf_sc:8; /* Status Code */ 1517 uint16_t sf_sct:3; /* Status Code Type */ 1518 uint16_t sf_rsvd2:2; 1519 uint16_t sf_m:1; /* More */ 1520 uint16_t sf_dnr:1; /* Do Not Retry */ 1521 } nvme_cqe_sf_t; 1522 1523 1524 /* 1525 * NVMe Get Log Page 1526 */ 1527 #define NVME_LOGPAGE_SUP 0x00 /* Supported Logs (2.0) */ 1528 #define NVME_LOGPAGE_ERROR 0x01 /* Error Information */ 1529 #define NVME_LOGPAGE_HEALTH 0x02 /* SMART/Health Information */ 1530 #define NVME_LOGPAGE_FWSLOT 0x03 /* Firmware Slot Information */ 1531 #define NVME_LOGPAGE_NSCHANGE 0x04 /* Changed namespace (1.2) */ 1532 #define NVME_LOGPAGE_CMDSUP 0x05 /* Cmds. Supported and Effects (1.3) */ 1533 #define NVME_LOGPAGE_SELFTEST 0x06 /* Device self-test (1.3) */ 1534 #define NVME_LOGPAGE_TELMHOST 0x07 /* Telemetry Host-Initiated */ 1535 #define NVME_LOGPAGE_TELMCTRL 0x08 /* Telemetry Controller-Initiated */ 1536 #define NVME_LOGPAGE_ENDGRP 0x09 /* Endurance Group Information (1.4) */ 1537 #define NVME_LOGPAGE_PLATSET 0x0a /* Predictable Lat. per NVM Set (1.4) */ 1538 #define NVME_LOGPAGE_PLATAGG 0x0b /* Predictable Lat. Event Agg (1.4) */ 1539 #define NVME_LOGPAGE_ASYMNS 0x0c /* Asymmetric Namespace Access (1.4) */ 1540 #define NVME_LOGPAGE_PEV 0x0d /* Persistent Event Log (1.4) */ 1541 #define NVME_LOGPAGE_LBASTS 0x0e /* LBA Status Information (1.4) */ 1542 #define NVME_LOGPAGE_ENDAGG 0x0f /* Endurance Group Event Agg. (1.4) */ 1543 #define NVME_LOGPAGE_MEDIA 0x10 /* Media Unit Status (2.0) */ 1544 #define NVME_LOGPAGE_CAPCFG 0x11 /* Supported Capacity cfg. (2.0) */ 1545 #define NVME_LOGPAGE_SUPFEAT 0x12 /* Supported Features (2.0) */ 1546 #define NVME_LOGPAGE_SUPMI 0x13 /* Supported NVMe-MI Commands (2.0) */ 1547 #define NVME_LOGPAGE_LOCKDOWN 0x14 /* Command and Feature Lockdown (2.0) */ 1548 #define NVME_LOGPAGE_BOOTPART 0x15 /* Boot Partition (2.0) */ 1549 #define NVME_LOGPAGE_ROTMEDIA 0x16 /* Rotational Media (2.0) */ 1550 #define NVME_LOGPAGE_DISPNS 0x17 /* Dispersed Namespace (2.1) */ 1551 #define NVME_LOGPAGE_MGMTADDR 0x18 /* Management Address List (2.1) */ 1552 #define NVME_LOGPAGE_PHYEYE 0x19 /* Physical Interface Eye (PCIe 1.1) */ 1553 #define NVME_LOGPAGE_REACHGRP 0x1a /* Reachability Groups (2.1) */ 1554 #define NVME_LOGPAGE_REACHASC 0x1b /* Reachability Associations (2.1) */ 1555 #define NVME_LOGPAGE_NSACHANGE 0x1c /* Changed allocated namespaces (2.1) */ 1556 #define NVME_LOGPAGE_DEVPERS 0x1d /* Device Personalities (2.3) */ 1557 #define NVME_LOGPAGE_XCTRLRST 0x1e /* Cross-Controller Reset (2.3) */ 1558 #define NVME_LOGPAGE_LOSTHOST 0x1f /* Lost Host Communication (2.3) */ 1559 #define NVME_LOGPAGE_FDPCFG 0x20 /* FDP Configuration (2.1) */ 1560 #define NVME_LOGPAGE_RECLAIM 0x21 /* Reclaim Unit Handle Usage (2.1) */ 1561 #define NVME_LOGPAGE_FDPSTAT 0x22 /* FDP Statistics (2.1) */ 1562 #define NVME_LOGPAGE_FDPEVENT 0x23 /* FDP Events (2.1) */ 1563 /* 0x24 is not currently defined */ 1564 #define NVME_LOGPAGE_POWER 0x25 /* Power Measurement (2.3) */ 1565 1566 1567 #define NVME_LOGPAGE_VEND_MIN 0xc0 1568 #define NVME_LOGPAGE_VEND_MAX 0xff 1569 1570 /* 1571 * Supported Log Pages (2.0). There is one entry of an nvme_logsup_t that then 1572 * exists on a per-log basis. 1573 */ 1574 1575 /* 1576 * The NVMe Log Identifier specific parameter field. Currently there is only one 1577 * defined field for the persistent event log (pel). 1578 */ 1579 typedef union { 1580 uint16_t nsl_lidsp; /* Raw Value */ 1581 struct { /* Persistent Event Log */ 1582 uint16_t nsl_ec512:1; 1583 uint16_t nsl_pel_rsvd0p1:15; 1584 } nsl_pel; 1585 } nvme_suplog_lidsp_t; 1586 1587 typedef struct { 1588 uint16_t ns_lsupp:1; 1589 uint16_t ns_ios:1; 1590 uint16_t ns_rsvd0p2:14; 1591 nvme_suplog_lidsp_t ns_lidsp; 1592 } nvme_suplog_t; 1593 1594 CTASSERT(sizeof (nvme_suplog_lidsp_t) == 2); 1595 CTASSERT(sizeof (nvme_suplog_t) == 4); 1596 1597 typedef struct { 1598 nvme_suplog_t nl_logs[256]; 1599 } nvme_suplog_log_t; 1600 1601 CTASSERT(sizeof (nvme_suplog_log_t) == 1024); 1602 1603 /* 1604 * SMART / Health information 1605 */ 1606 typedef struct { 1607 uint64_t el_count; /* Error Count */ 1608 uint16_t el_sqid; /* Submission Queue ID */ 1609 uint16_t el_cid; /* Command ID */ 1610 nvme_cqe_sf_t el_sf; /* Status Field */ 1611 uint8_t el_byte; /* Parameter Error Location byte */ 1612 uint8_t el_bit:3; /* Parameter Error Location bit */ 1613 uint8_t el_rsvd1:5; 1614 uint64_t el_lba; /* Logical Block Address */ 1615 uint32_t el_nsid; /* Namespace ID */ 1616 uint8_t el_vendor; /* Vendor Specific Information avail */ 1617 uint8_t el_trtype; /* Transport Type (2.0) */ 1618 uint8_t el_csi; /* Command Set Indicator (2.1) */ 1619 uint8_t el_opc; /* Opcode (2.1) */ 1620 uint8_t el_csinfo[8]; /* Command Specific Info (1.2) */ 1621 uint16_t el_ttsi; /* Transport Type Specific Info (1.4) */ 1622 uint8_t el_rsvd2[63 - 42]; 1623 uint8_t el_lpver; /* Log Page Version (2.1) */ 1624 } nvme_error_log_entry_t; 1625 1626 CTASSERT(sizeof (nvme_error_log_entry_t) == 64); 1627 1628 typedef struct { 1629 struct { /* Critical Warning */ 1630 uint8_t cw_avail:1; /* available space too low */ 1631 uint8_t cw_temp:1; /* temperature too high */ 1632 uint8_t cw_reliab:1; /* degraded reliability */ 1633 uint8_t cw_readonly:1; /* media is read-only */ 1634 uint8_t cw_volatile:1; /* volatile memory backup failed */ 1635 uint8_t cw_pmrro:1; /* Persistent Memory Region R/O (1.4) */ 1636 uint8_t cw_ips:1; /* Indeterminate Pers. State (2.3) */ 1637 uint8_t cw_rsvd:1; 1638 } hl_crit_warn; 1639 uint16_t hl_temp; /* Temperature */ 1640 uint8_t hl_avail_spare; /* Available Spare */ 1641 uint8_t hl_avail_spare_thr; /* Available Spare Threshold */ 1642 uint8_t hl_used; /* Percentage Used */ 1643 struct { 1644 uint8_t ecgws_egascbt:1; /* Egrp. Available Spare Low (1.4) */ 1645 uint8_t ecgws_rsvd1:1; 1646 uint8_t ecgws_egdr:1; /* Egrp. Degraded Reliability (1.4) */ 1647 uint8_t ecgws_egro:1; /* Endurance Group Read-Only (1.4) */ 1648 uint8_t ecgws_rsvd:4; 1649 } hl_ecgcws; 1650 uint8_t hl_rsvd1[32 - 7]; 1651 nvme_uint128_t hl_data_read; /* Data Units Read */ 1652 nvme_uint128_t hl_data_write; /* Data Units Written */ 1653 nvme_uint128_t hl_host_read; /* Host Read Commands */ 1654 nvme_uint128_t hl_host_write; /* Host Write Commands */ 1655 nvme_uint128_t hl_ctrl_busy; /* Controller Busy Time */ 1656 nvme_uint128_t hl_power_cycles; /* Power Cycles */ 1657 nvme_uint128_t hl_power_on_hours; /* Power On Hours */ 1658 nvme_uint128_t hl_unsafe_shutdn; /* Unsafe Shutdowns */ 1659 nvme_uint128_t hl_media_errors; /* Media Errors */ 1660 nvme_uint128_t hl_errors_logged; /* Number of errors logged */ 1661 /* Added in NVMe 1.2 */ 1662 uint32_t hl_warn_temp_time; /* Warning Composite Temp Time */ 1663 uint32_t hl_crit_temp_time; /* Critical Composite Temp Time */ 1664 uint16_t hl_temp_sensor_1; /* Temperature Sensor 1 */ 1665 uint16_t hl_temp_sensor_2; /* Temperature Sensor 2 */ 1666 uint16_t hl_temp_sensor_3; /* Temperature Sensor 3 */ 1667 uint16_t hl_temp_sensor_4; /* Temperature Sensor 4 */ 1668 uint16_t hl_temp_sensor_5; /* Temperature Sensor 5 */ 1669 uint16_t hl_temp_sensor_6; /* Temperature Sensor 6 */ 1670 uint16_t hl_temp_sensor_7; /* Temperature Sensor 7 */ 1671 uint16_t hl_temp_sensor_8; /* Temperature Sensor 8 */ 1672 /* Added in NVMe 1.3 */ 1673 uint32_t hl_tmtemp_1_tc; /* Thermal Mgmt Temp 1 Transition # */ 1674 uint32_t hl_tmtemp_2_tc; /* Thermal Mgmt Temp 1 Transition # */ 1675 uint32_t hl_tmtemp_1_time; /* Time in Thermal Mgmt Temp 1 */ 1676 uint32_t hl_tmtemp_2_time; /* Time in Thermal Mgmt Temp 2 */ 1677 /* Added in NVMe 2.3 */ 1678 uint64_t hl_olec; /* Operational Lifetime Energy */ 1679 struct { 1680 uint16_t ipm_ipmv; /* Interval Power Measurement */ 1681 uint8_t ipm_ipms:2; /* Interval Power Measurement Scale */ 1682 uint8_t ipm_rsvd18:2; 1683 uint8_t ipm_pmt:4; /* Power Measurement Type */ 1684 uint8_t ipm_rsvd24; 1685 } hl_ipm; /* Interval Power Measurement */ 1686 uint8_t hl_rsvd2[512 - 244]; 1687 } nvme_health_log_t; 1688 1689 #ifndef __CHECKER__ 1690 CTASSERT(offsetof(nvme_health_log_t, hl_olec) == 232); 1691 CTASSERT(sizeof (nvme_health_log_t) == 512); 1692 #endif 1693 1694 /* 1695 * The NVMe spec allows for up to seven firmware slots. 1696 */ 1697 #define NVME_MAX_FWSLOTS 7 1698 1699 typedef struct { 1700 /* Active Firmware Slot */ 1701 uint8_t fw_afi:3; 1702 uint8_t fw_rsvd1:1; 1703 /* Next Active Firmware Slot */ 1704 uint8_t fw_next:3; 1705 uint8_t fw_rsvd2:1; 1706 uint8_t fw_rsvd3[7]; 1707 /* Firmware Revision / Slot */ 1708 char fw_frs[NVME_MAX_FWSLOTS][NVME_FWVER_SZ]; 1709 uint8_t fw_rsvd4[512 - 64]; 1710 } nvme_fwslot_log_t; 1711 1712 /* 1713 * The NVMe spec specifies that the changed namespace list contains up to 1714 * 1024 entries. 1715 */ 1716 #define NVME_NSCHANGE_LIST_SIZE 1024 1717 1718 typedef struct { 1719 uint32_t nscl_ns[NVME_NSCHANGE_LIST_SIZE]; 1720 } nvme_nschange_list_t; 1721 1722 /* 1723 * Commands Supported and Effects log page and information structure. This was 1724 * an optional log page added in NVMe 1.2. NVMe 2.0 added variants of this to 1725 * cover supported features and supported NVMe-MI commands. While these use 1726 * similar structures and information, today we define all three top level items 1727 * as their own structure, but leverage similar information. We reuse the 1728 * nvme_cmdeff_csp_t for the corresponding scope fields for all of them. 1729 */ 1730 typedef struct { 1731 uint8_t cmd_csupp:1; /* Command supported */ 1732 uint8_t cmd_lbcc:1; /* Logical block content change */ 1733 uint8_t cmd_ncc:1; /* Namespace capability change */ 1734 uint8_t cmd_nic:1; /* Namespace inventory change */ 1735 uint8_t cmd_ccc:1; /* Controller capability change */ 1736 uint8_t cmd_rsvd5:3; 1737 uint8_t cmd_rsvd8:6; 1738 uint8_t cmd_cser:2; /* Cmd. Submission and Exec Relaxations (2.1) */ 1739 uint16_t cmd_cse:3; /* Command submission and execution */ 1740 uint16_t cmd_uuid:1; /* UUID select supported, 1.4 */ 1741 uint16_t cmd_csp:12; /* Command Scope, 2.0 */ 1742 } nvme_cmdeff_t; 1743 1744 CTASSERT(sizeof (nvme_cmdeff_t) == 4); 1745 1746 typedef enum { 1747 NVME_CMDEFF_CSP_NS = 1 << 0, 1748 NVME_CMDEFF_CSP_CTRL = 1 << 1, 1749 NVME_CMDEFF_CSP_SET = 1 << 2, 1750 NVME_CMDEFF_CSP_ENDURANCE = 1 << 3, 1751 NVME_CMDEFF_CSP_DOMAIN = 1 << 4, 1752 NVME_CMDEFF_CSP_NVM = 1 << 5, 1753 /* This is currently only defined for supported features */ 1754 NVME_CMDEFF_CSP_CDQSCP = 1 << 6 1755 } nvme_cmdeff_csp_t; 1756 1757 typedef enum { 1758 NVME_CMDEFF_CSE_NONE = 0, 1759 NVME_CMDEFF_CSE_NS, 1760 NVME_CMDEFF_CSE_CTRL 1761 } nvme_cmdeff_cse_t; 1762 1763 typedef struct { 1764 nvme_cmdeff_t cme_admin[256]; 1765 nvme_cmdeff_t cme_io[256]; 1766 uint8_t cme_rsvd2048[2048]; 1767 } nvme_cmdeff_log_t; 1768 1769 CTASSERT(sizeof (nvme_cmdeff_log_t) == 4096); 1770 CTASSERT(offsetof(nvme_cmdeff_log_t, cme_rsvd2048) == 2048); 1771 1772 typedef struct { 1773 uint8_t feat_fupp:1; /* FID supported */ 1774 uint8_t feat_udcc:1; /* User data content change */ 1775 uint8_t feat_ncc:1; /* Namespace capability change */ 1776 uint8_t feat_nic:1; /* Namespace inventory change */ 1777 uint8_t feat_ccc:1; /* Controller capability change */ 1778 uint8_t feat_rsvd0p5:3; 1779 uint8_t feat_rsvd1; 1780 uint16_t feat_rsvd2:3; 1781 uint16_t feat_uuid:1; /* UUID select supported */ 1782 uint16_t feat_fsp:12; /* Command Scope */ 1783 } nvme_supfeat_t; 1784 1785 CTASSERT(sizeof (nvme_supfeat_t) == 4); 1786 1787 typedef struct { 1788 nvme_supfeat_t nsl_feats[256]; 1789 } nvme_supfeat_log_t; 1790 1791 CTASSERT(sizeof (nvme_supfeat_log_t) == 1024); 1792 1793 typedef struct { 1794 uint8_t smi_csupp:1; /* Command supported */ 1795 uint8_t smi_lbcc:1; /* Logical block content change */ 1796 uint8_t smi_ncc:1; /* Namespace capability change */ 1797 uint8_t smi_nic:1; /* Namespace inventory change */ 1798 uint8_t smi_ccc:1; /* Controller capability change */ 1799 uint8_t smi_rsvd0p5:3; 1800 uint8_t smi_rsvd1; 1801 uint16_t smi_cse:3; /* Command submission and execution */ 1802 uint16_t smi_uuid:1; /* UUID select supported, 1.4 */ 1803 uint16_t smi_csp:12; /* Command Scope, 2.0 */ 1804 } nvme_supmicmd_t; 1805 1806 CTASSERT(sizeof (nvme_supmicmd_t) == 4); 1807 1808 typedef struct { 1809 nvme_supmicmd_t mcl_cmds[256]; 1810 uint8_t mcl_rsvd1024[4096 - 1024]; 1811 } nvme_supmicmd_log_t; 1812 1813 CTASSERT(sizeof (nvme_supmicmd_log_t) == 4096); 1814 1815 /* 1816 * Persistent Event Log Header. This log was added in NVMe 1.4. It begins with a 1817 * 512 byte header which is defined below. It uses the log specific parameter to 1818 * determine how to access it. Internally the drive contains the notion of a 1819 * context that must be released and accessed. 1820 */ 1821 typedef struct { 1822 uint8_t pel_lid; /* Log Identifier */ 1823 uint8_t pel_rsvd1[3]; 1824 uint32_t pel_tnev; /* Total Number of Events */ 1825 uint64_t pel_tll; /* Total Log Length */ 1826 uint8_t pel_lrev; /* Log Revision */ 1827 uint8_t pel_rsvd17[1]; 1828 uint16_t pel_lhl; /* Log Header Length */ 1829 uint64_t pel_tstmp; /* Timestamp */ 1830 nvme_uint128_t pel_poh; /* Power on Hours */ 1831 uint64_t pel_pwrcc; /* Power Cycle Count */ 1832 uint16_t pel_vid; /* PCI Vendor ID */ 1833 uint16_t pel_ssvid; /* PCI Subsystem Vendor ID */ 1834 uint8_t pel_sn[NVME_SERIAL_SZ]; /* Serial Number */ 1835 uint8_t pel_mn[NVME_MODEL_SZ]; /* Model Number */ 1836 uint8_t pel_subnqn[372 - 116]; /* NVM Subsystem Qual. Name */ 1837 uint16_t pel_gnum; /* Generation Number (2.0) */ 1838 struct { /* Reporting Context Info (2.0) */ 1839 uint16_t pel_rcpid; /* Port Identifier */ 1840 uint16_t pel_rcpit:2; /* Port Identifier Type */ 1841 uint16_t pel_rce:1; /* Reporting Context Exists */ 1842 uint16_t pel_rsvd19:13; 1843 } pel_rci; 1844 uint8_t pel_rsvd378[480 - 378]; 1845 uint8_t pel_seb[32]; /* Supported Events Bitmap */ 1846 uint8_t pel_data[]; 1847 } nvme_pev_log_t; 1848 1849 /* 1850 * This enum represents the bit index for various features in the supported 1851 * events bitmap. 1852 */ 1853 typedef enum { 1854 NVME_SEB_SHLSES = 1, /* SMART / Health Log */ 1855 NVME_SEB_FCES = 2, /* Firmware Commit */ 1856 NVME_SEB_TCES = 3, /* Timestamp Change */ 1857 NVME_SEB_PRES = 4, /* Power-on or Reset */ 1858 NVME_SEB_NSHEES = 5, /* NVM Subsystem Hardware Error */ 1859 NVME_SEB_CNES = 6, /* Change Namespace */ 1860 NVME_SEB_FNSES = 7, /* Format NVM Start */ 1861 NVME_SEB_FNCES = 8, /* Format NVM Completion */ 1862 NVME_SEB_SSES = 9, /* Sanitize Start */ 1863 NVME_SEB_SCES = 10, /* Sanitize Completion */ 1864 NVME_SEB_SFES = 11, /* Set Feature */ 1865 NVME_SEB_TLCES = 12, /* Telemetry Log Create */ 1866 NVME_SEB_TEES = 13, /* Thermal Excursion */ 1867 NVME_SEB_SMVES = 14, /* Sanitize Media Verification (2.1) */ 1868 NVME_SEB_CDPCES = 15, /* Configurable Device Pers. (2.3) */ 1869 NVME_SEB_VSES = 222, /* Vendor Specific */ 1870 NVME_SEB_TCG = 223 /* TCG */ 1871 } nvme_pev_seb_t; 1872 1873 /* 1874 * Log specific fields for the persistent event log. These are required by the 1875 * log. 1876 */ 1877 typedef enum { 1878 /* 1879 * Read the persistent event log, presumes that a context has already 1880 * been established. 1881 */ 1882 NVME_PEV_LSP_READ = 0, 1883 /* 1884 * Establish a new context and then read a portion of the event log. Any 1885 * prior existing context must already have been released. 1886 */ 1887 NVME_PEV_LSP_EST_CTX_READ, 1888 /* 1889 * Releases the persistent event log context. It is legal for this 1890 * context to already have been released. 1891 */ 1892 NVME_PEV_LSP_REL_CTX, 1893 /* 1894 * This establishes a context and reads the fixed 512 bytes. The 1895 * controller is supposed to ignore any offset and length fields and 1896 * always read 512 bytes regardless. This is present starting in NVMe 1897 * 2.0. 1898 */ 1899 NVME_PEV_LSP_EST_CTX_READ_512 1900 } nvme_pev_log_lsp_t; 1901 1902 #ifndef __CHECKER__ 1903 CTASSERT(sizeof (nvme_pev_log_t) == 512); 1904 CTASSERT(offsetof(nvme_pev_log_t, pel_gnum) == 372); 1905 #endif 1906 1907 /* 1908 * NVMe Telemetry Header 1909 */ 1910 typedef struct { 1911 uint8_t ntl_lid; 1912 uint8_t ntl_rsvd1[4]; 1913 uint8_t ntl_ieee[3]; 1914 uint16_t ntl_thda1lb; 1915 uint16_t ntl_thda2lb; 1916 uint16_t ntl_thda3lb; 1917 uint8_t ntl_rsvd14[2]; 1918 uint32_t ntl_thda4lb; 1919 uint8_t ntl_rsvd20[380 - 20]; 1920 uint8_t ntl_ths; 1921 uint8_t ntl_thdgn; 1922 uint8_t ntl_tcda; 1923 uint8_t ntl_tcdgn; 1924 uint8_t ntl_rid[512 - 384]; 1925 uint8_t ntl_data[]; 1926 } nvme_telemetry_log_t; 1927 1928 CTASSERT(sizeof (nvme_telemetry_log_t) == 512); 1929 1930 #define NVME_TELMCTRL_LSP_CTHID 1 1931 1932 /* 1933 * Physical Interface Receiver Eye Opening Measurement Log or in a PCIe eye 1934 * diagram. It consists of a header and a variable number of data descriptors. 1935 */ 1936 1937 /* 1938 * Eye Opening Measurement Header 1939 */ 1940 typedef struct { 1941 uint8_t eom_lid; 1942 uint8_t eom_eomip; 1943 uint16_t eom_hsize; 1944 uint32_t eom_rsz; 1945 uint8_t eom_edgn; 1946 uint8_t eom_lrev; 1947 struct { 1948 uint8_t odp_pefp:1; 1949 uint8_t odp_edfp:1; 1950 uint8_t odp_rsvd2:6; 1951 } eom_odp; 1952 uint8_t eom_lns; 1953 uint8_t eom_epl; 1954 struct { 1955 uint8_t lspfc_lspfv:7; 1956 uint8_t lspfc_rsvd1:1; 1957 } eom_lspfc; 1958 struct { 1959 uint8_t linfo_mls:4; 1960 uint8_t linfo_rsvd4:4; 1961 } eom_linfo; 1962 uint8_t eom_rsvd15[18 - 15]; 1963 uint16_t eom_lsic; 1964 uint32_t eom_ds; 1965 uint16_t eom_nd; 1966 uint16_t eom_maxtb; 1967 uint16_t eom_maxlr; 1968 uint16_t eom_etgood; 1969 uint16_t eom_etbetter; 1970 uint16_t eom_etbest; 1971 uint8_t eom_rsvd[64 - 36]; 1972 } nvme_eom_hdr_t; 1973 1974 CTASSERT(sizeof (nvme_eom_hdr_t) == 64); 1975 1976 /* 1977 * Eye Opening Lane Descriptor 1978 */ 1979 typedef struct { 1980 uint8_t eld_rsvd0[1]; 1981 struct { 1982 uint8_t mstat_mcsc:1; 1983 uint8_t mstat_rsvd1:7; 1984 } eld_mstat; 1985 uint8_t eld_ln; 1986 uint8_t eld_eye; 1987 uint16_t eld_top; 1988 uint16_t eld_btm; 1989 uint16_t eld_lft; 1990 uint16_t eld_rgt; 1991 uint16_t eld_nrows; 1992 uint16_t eld_ncols; 1993 /* 1994 * In revision 2 (NVMe PCIe 1.1) this field is only a uint16_t. It was 1995 * extended to a uint32_t in revision 3 of the log. 1996 */ 1997 uint32_t eld_edlen; 1998 uint8_t eld_rsvd20[32 - 20]; 1999 /* 2000 * The Lane Descriptor follows this with three different variable data 2001 * regions depending on what bits have been set as present in the 2002 * header: 2003 * 2004 * 1. The first eld_nrows * eld_ncols bytes cover the printable eye. 2005 * 2. The next eld_edlen bytes cover any vendor-specific eye data. 2006 * 3. The final portion of this is padding to ensure this is dword 2007 * aligned. This is based on the header's eom_ds field. 2008 */ 2009 uint8_t eld_data[]; 2010 } nvme_eom_lane_desc_t; 2011 2012 typedef enum { 2013 NVME_EOM_NOT_STARTED = 0, 2014 NVME_EOM_IN_PROGRESS, 2015 NVME_EOM_DONE 2016 } nvme_eom_eomip_t; 2017 2018 CTASSERT(sizeof (nvme_eom_lane_desc_t) == 32); 2019 2020 typedef enum { 2021 NVME_EOM_LSP_MQUAL_GOOD = 0, 2022 NVME_EOM_LSP_MQUAL_BETTER, 2023 NVME_EOM_LSP_MQUAL_BEST 2024 } nvme_eom_lsp_mqual_t; 2025 2026 typedef enum { 2027 /* 2028 * Read the current eye opening measurement log. This honors a specific 2029 * offset to start reading at. This assumes that a measurement is 2030 * already in progress. 2031 */ 2032 NVME_EOM_LSP_READ = 0, 2033 /* 2034 * This causes the controller to abort any in progress measurements, 2035 * start a new eye opening measurement, and return the initial requested 2036 * data. 2037 */ 2038 NVME_EOM_LSP_START = 1, 2039 /* 2040 * This aborts any in progress measurement and clears the log page. 2041 */ 2042 NVME_EOM_LSP_ABORT = 2 2043 } nvme_eom_lsp_act_t; 2044 2045 typedef union { 2046 struct { 2047 uint8_t nel_mqual:2; 2048 uint8_t nel_act:2; 2049 }; 2050 /* 2051 * The spec has this fixed as a 7-bit value. We round it up to a uint8_t 2052 * here for ABI purposes. 2053 */ 2054 uint8_t r; 2055 } nvme_eom_lsp_t; 2056 2057 /* 2058 * NVMe Format NVM 2059 */ 2060 #define NVME_FRMT_SES_NONE 0 2061 #define NVME_FRMT_SES_USER 1 2062 #define NVME_FRMT_SES_CRYPTO 2 2063 #define NVME_FRMT_MAX_SES 2 2064 2065 #define NVME_FRMT_MAX_LBAF 15 2066 2067 typedef union { 2068 struct { 2069 uint32_t fm_lbaf:4; /* LBA Format */ 2070 uint32_t fm_ms:1; /* Metadata Settings */ 2071 uint32_t fm_pi:3; /* Protection Information */ 2072 uint32_t fm_pil:1; /* Prot. Information Location */ 2073 uint32_t fm_ses:3; /* Secure Erase Settings */ 2074 uint32_t fm_resvd:20; 2075 } b; 2076 uint32_t r; 2077 } nvme_format_nvm_t; 2078 2079 2080 /* 2081 * NVMe Get / Set Features 2082 */ 2083 #define NVME_FEAT_ARBITRATION 0x01 /* Command Arbitration */ 2084 #define NVME_FEAT_POWER_MGMT 0x02 /* Power Management */ 2085 #define NVME_FEAT_LBA_RANGE 0x03 /* LBA Range Type */ 2086 #define NVME_FEAT_TEMPERATURE 0x04 /* Temperature Threshold */ 2087 #define NVME_FEAT_ERROR 0x05 /* Error Recovery */ 2088 #define NVME_FEAT_WRITE_CACHE 0x06 /* Volatile Write Cache */ 2089 #define NVME_FEAT_NQUEUES 0x07 /* Number of Queues */ 2090 #define NVME_FEAT_INTR_COAL 0x08 /* Interrupt Coalescing */ 2091 #define NVME_FEAT_INTR_VECT 0x09 /* Interrupt Vector Configuration */ 2092 #define NVME_FEAT_WRITE_ATOM 0x0a /* Write Atomicity */ 2093 #define NVME_FEAT_ASYNC_EVENT 0x0b /* Asynchronous Event Configuration */ 2094 #define NVME_FEAT_AUTO_PST 0x0c /* Autonomous Power State Transition */ 2095 /* (1.1) */ 2096 #define NVME_FEAT_HMB 0x0d /* Host Memory Buffer (1.2) */ 2097 #define NVME_FEAT_TIMESTAMP 0x0e /* Timestamp (1.3) */ 2098 #define NVME_FEAT_KEEP_ALIVE 0x0f /* Keep Alive Timer (1.2) */ 2099 #define NVME_FEAT_HCTM 0x10 /* Host Controlled Thermal Mgmt (1.3) */ 2100 #define NVME_FEAT_NOPSC 0x11 /* Non-op Power State Cfg. (1.3) */ 2101 #define NVME_FEAT_READ_REC 0x12 /* Read Recovery Level Cfg (1.4) */ 2102 #define NVME_FEAT_PLM_CFG 0x13 /* Predictable Lat. Mode Cfg. (1.4) */ 2103 #define NVME_FEAT_PLM_WIN 0x14 /* ^ Window (1.4) */ 2104 #define NVME_FEAT_LBA_STS_ATTR 0x15 /* LBA Status Info Attr (1.4) */ 2105 #define NVME_FEAT_HOST_BEHAVE 0x16 /* Host Behavior (1.4) */ 2106 #define NVME_FEAT_SAN_CFG 0x17 /* Sanitize Config (1.4) */ 2107 #define NVME_FEAT_EGRP_EVENT 0x18 /* Endurance Group Event Config (1.4) */ 2108 #define NVME_FEAT_IO_CMD_SET 0x19 /* I/O Command Set Profile (2.0) */ 2109 #define NVME_FEAT_IO_CMD_SET 0x19 /* I/O Command Set Profile (2.0) */ 2110 #define NVME_FEAT_SPINUP 0x1a /* Spinup Control (2.0) */ 2111 #define NVME_FEAT_PLS 0x1b /* Power Loss Signaling (2.1) */ 2112 #define NVME_FEAT_PERF_CHAR 0x1c /* Perf. Characteristics (N1.1) */ 2113 #define NVME_FEAT_FDP 0x1d /* Flexible Device Placement (2.1) */ 2114 #define NVME_FEAT_FDP_EVENTS 0x1e /* ^ Events (2.1) */ 2115 #define NVME_FEAT_NS_LABEL 0x1f /* Namespace Admin Label (2.1) */ 2116 #define NVME_FEAT_CTRL_DQ 0x21 /* Controller Data Queue (2.1) */ 2117 #define NVME_FEAT_DEV_PERS 0x22 /* Device Personality (2.3) */ 2118 #define NVME_FEAT_POWER_LIMIT 0x23 /* Power Limit (2.3) */ 2119 #define NVME_FEAT_POWER_THRESH 0x24 /* Power Threshold (2.3) */ 2120 #define NVME_FEAT_POWER_MEASURE 0x25 /* Power Measurement (2.3) */ 2121 2122 #define NVME_FEAT_ENH_CTRL_META 0x7d /* Enhanced Controller Metadata (2.0) */ 2123 #define NVME_FEAT_CTRL_META 0x7e /* Controller Metadata (2.0) */ 2124 #define NVME_FEAT_NS_META 0x7f /* Namespace Metadata (2.0) */ 2125 2126 #define NVME_FEAT_PROGRESS 0x80 /* Software Progress Marker */ 2127 2128 /* 2129 * This enumeration represents the capabilities in the Get Features select / Set 2130 * Features save options. This was introduced in NVMe 1.1 and the values below 2131 * match the specification. An optional feature in the identify controller data 2132 * structure is set to indicate that this is supported (id_oncs.on_save). 2133 */ 2134 typedef enum { 2135 NVME_FEATURE_SEL_CURRENT = 0, 2136 NVME_FEATURE_SEL_DEFAULT, 2137 NVME_FEATURE_SEL_SAVED, 2138 NVME_FEATURE_SEL_SUPPORTED 2139 } nvme_feature_sel_t; 2140 2141 typedef union { 2142 struct { 2143 uint32_t gt_fid:8; /* Feature ID */ 2144 uint32_t gt_sel:3; /* Select */ 2145 uint32_t gt_rsvd:21; 2146 } b; 2147 uint32_t r; 2148 } nvme_get_features_dw10_t; 2149 2150 /* Arbitration Feature */ 2151 typedef union { 2152 struct { 2153 uint8_t arb_ab:3; /* Arbitration Burst */ 2154 uint8_t arb_rsvd:5; 2155 uint8_t arb_lpw; /* Low Priority Weight */ 2156 uint8_t arb_mpw; /* Medium Priority Weight */ 2157 uint8_t arb_hpw; /* High Priority Weight */ 2158 } b; 2159 uint32_t r; 2160 } nvme_arbitration_t; 2161 2162 /* Power Management Feature */ 2163 typedef union { 2164 struct { 2165 uint32_t pm_ps:5; /* Power State */ 2166 uint32_t pm_wh:3; /* Workload Hint (1.2) */ 2167 uint32_t pm_rsvd:24; 2168 } b; 2169 uint32_t r; 2170 } nvme_power_mgmt_t; 2171 2172 /* LBA Range Type Feature */ 2173 typedef union { 2174 struct { 2175 uint32_t lr_num:6; /* Number of LBA ranges */ 2176 uint32_t lr_rsvd:26; 2177 } b; 2178 uint32_t r; 2179 } nvme_lba_range_type_t; 2180 2181 typedef struct { 2182 uint8_t lr_type; /* Type */ 2183 struct { /* Attributes */ 2184 uint8_t lr_write:1; /* may be overwritten */ 2185 uint8_t lr_hidden:1; /* hidden from OS/EFI/BIOS */ 2186 uint8_t lr_rsvd1:6; 2187 } lr_attr; 2188 uint8_t lr_rsvd2[14]; 2189 uint64_t lr_slba; /* Starting LBA */ 2190 uint64_t lr_nlb; /* Number of Logical Blocks */ 2191 uint8_t lr_guid[16]; /* Unique Identifier */ 2192 uint8_t lr_rsvd3[16]; 2193 } nvme_lba_range_t; 2194 2195 #define NVME_LBA_RANGE_BUFSIZE 4096 2196 2197 /* Temperature Threshold Feature */ 2198 typedef union { 2199 struct { 2200 uint16_t tt_tmpth; /* Temperature Threshold */ 2201 uint16_t tt_tmpsel:4; /* Temperature Select */ 2202 uint16_t tt_thsel:2; /* Temperature Type */ 2203 uint16_t tt_tmpthh:3; /* Threshold Hysteresis (2.1) */ 2204 uint16_t tt_resv:7; 2205 } b; 2206 uint32_t r; 2207 } nvme_temp_threshold_t; 2208 2209 #define NVME_TEMP_THRESH_MAX_SENSOR 8 2210 #define NVME_TEMP_THRESH_ALL 0xf 2211 #define NVME_TEMP_THRESH_OVER 0x00 2212 #define NVME_TEMP_THRESH_UNDER 0x01 2213 2214 /* Error Recovery Feature */ 2215 typedef union { 2216 struct { 2217 uint16_t er_tler; /* Time-Limited Error Recovery */ 2218 uint16_t er_dulbe:1; /* Deallocated or Unwritten (1.2) */ 2219 uint16_t er_rsvd:15; 2220 } b; 2221 uint32_t r; 2222 } nvme_error_recovery_t; 2223 2224 /* Volatile Write Cache Feature */ 2225 typedef union { 2226 struct { 2227 uint32_t wc_wce:1; /* Volatile Write Cache Enable */ 2228 uint32_t wc_rsvd:31; 2229 } b; 2230 uint32_t r; 2231 } nvme_write_cache_t; 2232 2233 /* Number of Queues Feature */ 2234 typedef union { 2235 struct { 2236 uint16_t nq_nsq; /* Number of Submission Queues */ 2237 uint16_t nq_ncq; /* Number of Completion Queues */ 2238 } b; 2239 uint32_t r; 2240 } nvme_nqueues_t; 2241 2242 /* Interrupt Coalescing Feature */ 2243 typedef union { 2244 struct { 2245 uint8_t ic_thr; /* Aggregation Threshold */ 2246 uint8_t ic_time; /* Aggregation Time */ 2247 uint16_t ic_rsvd; 2248 } b; 2249 uint32_t r; 2250 } nvme_intr_coal_t; 2251 2252 /* Interrupt Configuration Features */ 2253 typedef union { 2254 struct { 2255 uint16_t iv_iv; /* Interrupt Vector */ 2256 uint16_t iv_cd:1; /* Coalescing Disable */ 2257 uint16_t iv_rsvd:15; 2258 } b; 2259 uint32_t r; 2260 } nvme_intr_vect_t; 2261 2262 /* Write Atomicity Feature */ 2263 typedef union { 2264 struct { 2265 uint32_t wa_dn:1; /* Disable Normal */ 2266 uint32_t wa_rsvd:31; 2267 } b; 2268 uint32_t r; 2269 } nvme_write_atomicity_t; 2270 2271 /* Asynchronous Event Configuration Feature */ 2272 typedef union { 2273 struct { 2274 uint32_t aec_avail:1; /* Available space too low */ 2275 uint32_t aec_temp:1; /* Temperature too high */ 2276 uint32_t aec_reliab:1; /* Degraded reliability */ 2277 uint32_t aec_readonly:1; /* Media is read-only */ 2278 uint32_t aec_volatile:1; /* Volatile mem backup failed */ 2279 uint32_t aec_pmrro:1; /* Persist Memory Read Only (X.X) */ 2280 uint32_t aec_rsvd1:2; 2281 uint32_t aec_nsan:1; /* Namespace attribute notices (1.2) */ 2282 uint32_t aec_fwact:1; /* Firmware activation notices (1.2) */ 2283 uint32_t aec_telln:1; /* Telemetry log notices (1.3) */ 2284 uint32_t aec_ansacn:1; /* Asymm. NS access change (1.4) */ 2285 uint32_t aec_plat:1; /* Predictable latency ev. agg. (1.4) */ 2286 uint32_t aec_lbasi:1; /* LBA status information (1.4) */ 2287 uint32_t aec_egeal:1; /* Endurance group ev. agg. (1.4) */ 2288 uint32_t aec_nnsshdn:1; /* Normal NVM Subsys Shutdown (2.0) */ 2289 uint32_t aec_tthry:1; /* Temp Thres Hysteresis (2.1) */ 2290 uint32_t aec_rassn:1; /* Reachability Association (2.1) */ 2291 uint32_t aec_rgpr0:1; /* Reachability Group (2.1) */ 2292 uint32_t aec_ansan:1; /* Allocated Namespace Attr. (2.1) */ 2293 uint32_t aec_ccrun:1; /* X-Ctrl Reset Compl. Notices (2.3) */ 2294 uint32_t aec_lhcn:1; /* Lost Host Comms. Notices (2.3) */ 2295 uint32_t aec_rsvd20:5; 2296 uint32_t aec_zdcn:1; /* Zone Descriptor Changed (2.0) */ 2297 /* Fabrics Specific */ 2298 uint32_t aec_pmdrlpcn:1; /* Pull Model Change (2.1) */ 2299 uint32_t aec_adlpcn:1; /* AVE Discovery Change (2.1) */ 2300 uint32_t aec_hdlpcn:1; /* Host Discovery Change (2.1) */ 2301 uint32_t aec_dlpcn:1; /* Discovery Change (2.0) */ 2302 } b; 2303 uint32_t r; 2304 } nvme_async_event_conf_t; 2305 2306 CTASSERT(sizeof (nvme_async_event_conf_t) == 4); 2307 2308 /* Autonomous Power State Transition Feature (1.1) */ 2309 typedef union { 2310 struct { 2311 uint32_t apst_apste:1; /* APST enabled */ 2312 uint32_t apst_rsvd:31; 2313 } b; 2314 uint32_t r; 2315 } nvme_auto_power_state_trans_t; 2316 2317 typedef struct { 2318 uint32_t apst_rsvd1:3; 2319 uint32_t apst_itps:5; /* Idle Transition Power State */ 2320 uint32_t apst_itpt:24; /* Idle Time Prior to Transition */ 2321 uint32_t apst_rsvd2; 2322 } nvme_auto_power_state_t; 2323 2324 #define NVME_AUTO_PST_BUFSIZE 256 2325 2326 /* Host Behavior */ 2327 typedef struct { 2328 uint8_t nhb_acre; /* Advanced Command Retry (1.4) */ 2329 uint8_t nhb_etdas; /* Telemetry Area 4 (2.0) */ 2330 uint8_t nhb_lbafee; /* Extended LBA Formats (2.0) */ 2331 uint8_t nhb_hdisns; /* Dispersed Namespaces (2.1) */ 2332 uint16_t nhb_cdfe; /* Copy Descriptor (2.1) */ 2333 uint8_t nhb_rsvd[512 - 6]; 2334 } nvme_host_behavior_t; 2335 2336 CTASSERT(sizeof (nvme_host_behavior_t) == 512); 2337 2338 /* Software Progress Marker Feature */ 2339 typedef union { 2340 struct { 2341 uint8_t spm_pbslc; /* Pre-Boot Software Load Count */ 2342 uint8_t spm_rsvd[3]; 2343 } b; 2344 uint32_t r; 2345 } nvme_software_progress_marker_t; 2346 2347 /* 2348 * Firmware Commit - Command Dword 10 2349 */ 2350 #define NVME_FWC_SAVE 0x0 /* Save image only */ 2351 #define NVME_FWC_SAVE_ACTIVATE 0x1 /* Save and activate at next reset */ 2352 #define NVME_FWC_ACTIVATE 0x2 /* Activate slot at next reset */ 2353 #define NVME_FWC_ACTIVATE_IMMED 0x3 /* Activate slot immediately */ 2354 2355 /* 2356 * Firmware slot number is only 3 bits, and zero is not allowed. 2357 * Valid range is 1 to 7. 2358 */ 2359 #define NVME_FW_SLOT_MIN 1U /* lowest allowable slot number ... */ 2360 #define NVME_FW_SLOT_MAX 7U /* ... and highest */ 2361 2362 /* 2363 * Some constants to make verification of DWORD variables and arguments easier. 2364 * A DWORD is 4 bytes. 2365 */ 2366 #define NVME_DWORD_SHIFT 2 2367 #define NVME_DWORD_SIZE (1 << NVME_DWORD_SHIFT) 2368 #define NVME_DWORD_MASK (NVME_DWORD_SIZE - 1) 2369 2370 /* 2371 * The maximum offset a firmware image segment can be loaded at is the number 2372 * of DWORDS in a 32 bit field. The maximum length of such a segment is the 2373 * same. Expressed in bytes it is: 2374 */ 2375 #define NVME_FW_OFFSETB_MAX ((u_longlong_t)UINT32_MAX << NVME_DWORD_SHIFT) 2376 #define NVME_FW_LENB_MAX NVME_FW_OFFSETB_MAX 2377 2378 typedef union { 2379 struct { 2380 uint32_t fc_slot:3; /* Firmware slot */ 2381 uint32_t fc_action:3; /* Commit action */ 2382 uint32_t fc_rsvd:26; 2383 } b; 2384 uint32_t r; 2385 } nvme_firmware_commit_dw10_t; 2386 2387 #pragma pack() /* pack(1) */ 2388 2389 /* NVMe completion status code type */ 2390 #define NVME_CQE_SCT_GENERIC 0 /* Generic Command Status */ 2391 #define NVME_CQE_SCT_SPECIFIC 1 /* Command Specific Status */ 2392 #define NVME_CQE_SCT_INTEGRITY 2 /* Media and Data Integrity Errors */ 2393 #define NVME_CQE_SCT_PATH 3 /* Path Related Status (1.4) */ 2394 #define NVME_CQE_SCT_VENDOR 7 /* Vendor Specific */ 2395 2396 /* 2397 * Status code ranges 2398 */ 2399 #define NVME_CQE_SC_GEN_MIN 0x00 2400 #define NVME_CQE_SC_GEN_MAX 0x7f 2401 #define NVME_CQE_SC_CSI_MIN 0x80 2402 #define NVME_CQE_SC_CSI_MAX 0xbf 2403 #define NVME_CQE_SC_VEND_MIN 0xc0 2404 #define NVME_CQE_SC_VEND_MAX 0xff 2405 2406 /* NVMe completion status code (generic) */ 2407 #define NVME_CQE_SC_GEN_SUCCESS 0x0 /* Successful Completion */ 2408 #define NVME_CQE_SC_GEN_INV_OPC 0x1 /* Invalid Command Opcode */ 2409 #define NVME_CQE_SC_GEN_INV_FLD 0x2 /* Invalid Field in Command */ 2410 #define NVME_CQE_SC_GEN_ID_CNFL 0x3 /* Command ID Conflict */ 2411 #define NVME_CQE_SC_GEN_DATA_XFR_ERR 0x4 /* Data Transfer Error */ 2412 #define NVME_CQE_SC_GEN_ABORT_PWRLOSS 0x5 /* Cmds Aborted / Pwr Loss */ 2413 #define NVME_CQE_SC_GEN_INTERNAL_ERR 0x6 /* Internal Error */ 2414 #define NVME_CQE_SC_GEN_ABORT_REQUEST 0x7 /* Command Abort Requested */ 2415 #define NVME_CQE_SC_GEN_ABORT_SQ_DEL 0x8 /* Cmd Aborted / SQ deletion */ 2416 #define NVME_CQE_SC_GEN_ABORT_FUSE_FAIL 0x9 /* Cmd Aborted / Failed Fused */ 2417 #define NVME_CQE_SC_GEN_ABORT_FUSE_MISS 0xa /* Cmd Aborted / Missing Fusd */ 2418 #define NVME_CQE_SC_GEN_INV_NS 0xb /* Inval Namespace or Format */ 2419 #define NVME_CQE_SC_GEN_CMD_SEQ_ERR 0xc /* Command Sequence Error */ 2420 #define NVME_CQE_SC_GEN_INV_SGL_LAST 0xd /* Inval SGL Last Seg Desc */ 2421 #define NVME_CQE_SC_GEN_INV_SGL_NUM 0xe /* Inval Number of SGL Desc */ 2422 #define NVME_CQE_SC_GEN_INV_DSGL_LEN 0xf /* Data SGL Length Invalid */ 2423 #define NVME_CQE_SC_GEN_INV_MSGL_LEN 0x10 /* Metadata SGL Length Inval */ 2424 #define NVME_CQE_SC_GEN_INV_SGL_DESC 0x11 /* SGL Descriptor Type Inval */ 2425 /* Added in NVMe 1.2 */ 2426 #define NVME_CQE_SC_GEN_INV_USE_CMB 0x12 /* Inval use of Ctrl Mem Buf */ 2427 #define NVME_CQE_SC_GEN_INV_PRP_OFF 0x13 /* PRP Offset Invalid */ 2428 #define NVME_CQE_SC_GEN_AWU_EXCEEDED 0x14 /* Atomic Write Unit Exceeded */ 2429 #define NVME_CQE_SC_GEN_OP_DENIED 0x15 /* Operation Denied */ 2430 #define NVME_CQE_SC_GEN_INV_SGL_OFF 0x16 /* SGL Offset Invalid */ 2431 #define NVME_CQE_SC_GEN_INV_SGL_ST 0x17 /* SGL Sub type Invalid */ 2432 #define NVME_CQE_SC_GEN_INCON_HOSTID 0x18 /* Host ID Inconsistent fmt */ 2433 #define NVME_CQE_SC_GEN_KA_EXP 0x19 /* Keep Alive Timer Expired */ 2434 #define NVME_CQE_SC_GEN_INV_KA_TO 0x1a /* Keep Alive Timeout Invalid */ 2435 /* Added in NVMe 1.3 */ 2436 #define NVME_CQE_SC_GEN_ABORT_PREEMPT 0x1b /* Cmd aborted due to preempt */ 2437 #define NVME_CQE_SC_GEN_SANITIZE_FAIL 0x1c /* Sanitize Failed */ 2438 #define NVME_CQE_SC_GEN_SANITIZING 0x1d /* Sanitize in Progress */ 2439 #define NVME_CQE_SC_GEN_INV_SGL_GRAN 0x1e /* SGL Data Block Gran. Inval */ 2440 #define NVME_CQE_SC_GEN_NO_CMD_Q_CMD 0x1f /* Command not sup for CMB Q */ 2441 /* Added in NVMe 1.4 */ 2442 #define NVME_CQE_SC_GEN_NS_RDONLY 0x20 /* Namespace is write prot. */ 2443 #define NVME_CQE_SC_GEN_CMD_INTR 0x21 /* Command Interrupted */ 2444 #define NVME_CQE_SC_GEN_TRANSIENT 0x22 /* Transient Transport Error */ 2445 /* Added in NVMe 2.0 */ 2446 #define NVME_CQE_SC_GEN_CMD_LOCK 0x23 /* Command/Feature Lockdown */ 2447 #define NVME_CQE_SC_GEN_ADM_MEDIA_NR 0x24 /* Admin Cmd Media Not Ready */ 2448 /* Added in NVMe 2.1 */ 2449 #define NVME_CQE_SC_GEN_INV_KEY 0x25 /* Invalid Key Tag */ 2450 #define NVME_CQE_SC_GEN_HOST_DISPNS_DIS 0x26 /* Host Dispersed NS not en. */ 2451 #define NVME_CQE_SC_GEN_HOSTID_UNINIT 0x27 /* Host Identifier Not Init. */ 2452 #define NVME_CQE_SC_GEN_WRONG_KEY 0x28 /* Incorrect Key */ 2453 #define NVME_CQE_SC_GEN_FDP_DIS 0x29 /* FDP Disabled */ 2454 #define NVME_CQE_SC_GEN_INV_PHL 0x2a /* Invalid Placement Handle */ 2455 /* Added in NVMe 2.3 */ 2456 #define NVME_CQE_SC_GEN_SAN_NS_FAIL 0x2b /* Sanitize NS failed */ 2457 #define NVME_CQE_SC_GEN_SAN_NS_PROG 0x2c /* Sanitize NS in progress */ 2458 2459 /* NVMe completion status code (generic NVM commands) */ 2460 #define NVME_CQE_SC_GEN_NVM_LBA_RANGE 0x80 /* LBA Out Of Range */ 2461 #define NVME_CQE_SC_GEN_NVM_CAP_EXC 0x81 /* Capacity Exceeded */ 2462 #define NVME_CQE_SC_GEN_NVM_NS_NOTRDY 0x82 /* Namespace Not Ready */ 2463 #define NVME_CQE_SC_GEN_NVM_RSV_CNFLCT 0x83 /* Reservation Conflict */ 2464 #define NVME_CQE_SC_GEN_NVM_FORMATTING 0x84 /* Format in progress (1.2) */ 2465 /* Added in NVMe 2.0 */ 2466 #define NVME_CQE_SC_GEN_KEY_INV_VAL 0x85 /* Invalid value size */ 2467 #define NVME_CQE_SC_GEN_KEY_INV_KEY 0x86 /* Invalid key size */ 2468 #define NVME_CQE_SC_GEN_KEY_ENOENT 0x87 /* KV Key Does Not Exist */ 2469 #define NVME_CQE_SC_GEN_KEY_UNRECOV 0x88 /* Unrecovered Error */ 2470 #define NVME_CQE_SC_GEN_KEY_EXISTS 0x89 /* Key already exists */ 2471 2472 /* NVMe completion status code (command specific) */ 2473 #define NVME_CQE_SC_SPC_INV_CQ 0x0 /* Completion Queue Invalid */ 2474 #define NVME_CQE_SC_SPC_INV_QID 0x1 /* Invalid Queue Identifier */ 2475 #define NVME_CQE_SC_SPC_MAX_QSZ_EXC 0x2 /* Max Queue Size Exceeded */ 2476 #define NVME_CQE_SC_SPC_ABRT_CMD_EXC 0x3 /* Abort Cmd Limit Exceeded */ 2477 #define NVME_CQE_SC_SPC_ASYNC_EVREQ_EXC 0x5 /* Async Event Request Limit */ 2478 #define NVME_CQE_SC_SPC_INV_FW_SLOT 0x6 /* Invalid Firmware Slot */ 2479 #define NVME_CQE_SC_SPC_INV_FW_IMG 0x7 /* Invalid Firmware Image */ 2480 #define NVME_CQE_SC_SPC_INV_INT_VECT 0x8 /* Invalid Interrupt Vector */ 2481 #define NVME_CQE_SC_SPC_INV_LOG_PAGE 0x9 /* Invalid Log Page */ 2482 #define NVME_CQE_SC_SPC_INV_FORMAT 0xa /* Invalid Format */ 2483 #define NVME_CQE_SC_SPC_FW_RESET 0xb /* FW Application Reset Reqd */ 2484 #define NVME_CQE_SC_SPC_INV_Q_DEL 0xc /* Invalid Queue Deletion */ 2485 #define NVME_CQE_SC_SPC_FEAT_SAVE 0xd /* Feature Id Not Saveable */ 2486 #define NVME_CQE_SC_SPC_FEAT_CHG 0xe /* Feature Not Changeable */ 2487 #define NVME_CQE_SC_SPC_FEAT_NS_SPEC 0xf /* Feature Not Namespace Spec */ 2488 /* Added in NVMe 1.2 */ 2489 #define NVME_CQE_SC_SPC_FW_NSSR 0x10 /* FW Application NSSR Reqd */ 2490 #define NVME_CQE_SC_SPC_FW_NEXT_RESET 0x11 /* FW Application Next Reqd */ 2491 #define NVME_CQE_SC_SPC_FW_MTFA 0x12 /* FW Application Exceed MTFA */ 2492 #define NVME_CQE_SC_SPC_FW_PROHIBITED 0x13 /* FW Application Prohibited */ 2493 #define NVME_CQE_SC_SPC_FW_OVERLAP 0x14 /* Overlapping FW ranges */ 2494 #define NVME_CQE_SC_SPC_NS_INSUF_CAP 0x15 /* NS Insufficient Capacity */ 2495 #define NVME_CQE_SC_SPC_NS_NO_ID 0x16 /* NS ID Unavailable */ 2496 /* 0x17 is reserved */ 2497 #define NVME_CQE_SC_SPC_NS_ATTACHED 0x18 /* NS Already Attached */ 2498 #define NVME_CQE_SC_SPC_NS_PRIV 0x19 /* NS is private */ 2499 #define NVME_CQE_SC_SPC_NS_NOT_ATTACH 0x1a /* NS Not Attached */ 2500 #define NVME_CQE_SC_SPC_THIN_ENOTSUP 0x1b /* Thin Provisioning ENOTSUP */ 2501 #define NVME_CQE_SC_SPC_INV_CTRL_LIST 0x1c /* Controller list invalid */ 2502 /* Added in NVMe 1.3 */ 2503 #define NVME_CQE_SC_SPC_SELF_TESTING 0x1d /* Self-test in progress */ 2504 #define NVME_CQE_SC_SPC_NO_BP_WRITE 0x1e /* No Boot Partition Write */ 2505 #define NVME_CQE_SC_SPC_INV_CTRL_ID 0x1f /* Invalid Controller Id */ 2506 #define NVME_CQE_SC_SPC_INV_SEC_CTRL 0x20 /* Invalid Sec. Ctrl state */ 2507 #define NVME_CQE_SC_SPC_INV_CTRL_NRSRC 0x21 /* Inv. # Ctrl Resources */ 2508 #define NVME_CQE_SC_SPC_INV_RSRC_ID 0x22 /* Inv. Resource ID */ 2509 /* Added in NVMe 1.4 */ 2510 #define NVME_CQE_SC_SPC_NO_SAN_PMR 0x23 /* Sanitize prohib. w/ pmem */ 2511 #define NVME_CQE_SC_SPC_INV_ANA_GID 0x24 /* Invalid ANA group ID */ 2512 #define NVME_CQE_SC_SPC_ANA_ATTACH 0x25 /* ANA Attach Failed */ 2513 /* Added in NVMe 2.0 */ 2514 #define NVME_CQE_SC_SPC_INSUF_CAP 0x26 /* Insufficient Capacity */ 2515 #define NVME_CQE_SC_SPC_NS_ATTACH_LIM 0x27 /* NS Attach Limit Exceeded */ 2516 #define NVME_CQE_SC_SPC_LOCKDOWN_UNSUP 0x28 /* Prohib Cmd Exec Not Sup */ 2517 #define NVME_CQE_SC_SPC_UNSUP_IO_CMD 0x29 /* I/O Command set not sup */ 2518 #define NVME_CQE_SC_SPC_DIS_IO_CMD 0x2a /* I/O Command set not enab */ 2519 #define NVME_CQE_SC_SPC_INV_CMD_COMBO 0x2b /* I/O command set combo rej */ 2520 #define NVME_CQE_SC_SPC_INV_IO_CMD 0x2c /* Invalid I/O command set */ 2521 #define NVME_CQE_SC_SPC_UNAVAIL_ID 0x2d /* Unavailable ID */ 2522 /* Added in NVMe 2.1 */ 2523 #define NVME_CQE_SC_SPC_DISPERSE_NS 0x2e /* Namespace is dispersed */ 2524 #define NVME_CQE_SC_SPC_INV_DISC 0x2f /* Invalid Discovery */ 2525 #define NVME_CQE_SC_SPC_ZONE_LOCKED 0x30 /* Zoning Data Struct. Locked */ 2526 #define NVME_CQE_SC_SPC_ZONE_ENOENT 0x31 /* Zoning DS Not Found */ 2527 #define NVME_CQE_SC_SPC_DISC_RSRCS 0x32 /* Insufficient Disc. Rsrcs */ 2528 #define NVME_CQE_SC_SPC_FUNC_DIS 0x33 /* Requested Func. Disabled */ 2529 #define NVME_CQE_SC_SPC_INV_ZGRP_ORIG 0x34 /* ZoneGroup Originator Inv. */ 2530 #define NVME_CQE_SC_SPC_INV_HOST 0x35 /* Invalid Host */ 2531 #define NVME_CQE_SC_SPC_INV_NVM_SYS 0x36 /* Invalid NVM Subsystem */ 2532 #define NVME_CQE_SC_SPC_INV_CTL_DQ 0x37 /* Invalid Controller Data Q. */ 2533 #define NVME_CQE_SC_SPC_ERSRC 0x38 /* Not Enough Resources */ 2534 #define NVME_CQE_SC_SPC_CTL_SUSPEND 0x39 /* Controller Suspended */ 2535 #define NVME_CQE_SC_SPC_CTL_NOT_SUSPEND 0x3a /* Controller Not Suspended */ 2536 #define NVME_CQE_SC_SPC_CTL_DQ_FULL 0x3b /* Controller Data Queue Full */ 2537 /* Added in NVMe 2.3 */ 2538 #define NVME_CQE_SC_SPC_MAX_NS_SAN 0x3c /* Req Exceeds Max NS in San */ 2539 #define NVME_CQE_SC_SPC_REQ_DEF_PERS 0x3d /* Default Personality Req. */ 2540 #define NVME_CQE_SC_SPC_INV_PLIMIT 0x3e /* Invalid Power Limit */ 2541 #define NVME_CQE_SC_SPC_XCTL_RST_PROG 0x3f /* X-Ctrl Reset in Progress */ 2542 #define NVME_CQE_SC_SPC_XCTL_RST_LPF 0x40 /* X-Ctrl Log Page Full */ 2543 #define NVME_CQE_SC_SPC_XCTL_RST_LIM 0x41 /* X-Ctrl Reset Limit */ 2544 2545 /* NVMe completion status code (I/O command specific) */ 2546 #define NVME_CQE_SC_SPC_NVM_CNFL_ATTR 0x80 /* Conflicting Attributes */ 2547 #define NVME_CQE_SC_SPC_NVM_INV_PROT 0x81 /* Invalid Protection */ 2548 #define NVME_CQE_SC_SPC_NVM_READONLY 0x82 /* Write to Read Only Range */ 2549 /* Added in NVMe 2.0 */ 2550 #define NVME_CQE_SC_SPC_IO_LIMIT 0x83 /* Cmd Size Limit Exceeded */ 2551 /* Added in NVMe 2.1 */ 2552 #define NVME_CQE_SC_SPC_INV_CID 0x84 /* Invalid Command ID */ 2553 #define NVME_CQE_SC_SPC_INCOMPAT_NS 0x85 /* Incompatible NS or FMT */ 2554 #define NVME_CQE_SC_SPC_NO_FAST_COPY 0x86 /* Fast Copy Not Possible */ 2555 #define NVME_CQE_SC_SPC_OVLP_IO 0x87 /* Overlapping I/O Range */ 2556 #define NVME_CQE_SC_SPC_NS_UNREACH 0x88 /* Namespace Not reachable */ 2557 #define NVME_CQE_SC_SPC_INSUF_RSRC 0x89 /* Insufficient Resources */ 2558 #define NVME_CQE_SC_SPC_INSUF_PROG 0x8a /* Insufficient Prog Rsrcs. */ 2559 #define NVME_CQE_SC_SPC_INV_MEM_NS 0x8b /* Invalid Memory NS */ 2560 #define NVME_CQE_SC_SPC_INV_MEM_RANGE 0x8c /* Invalid Memory Range Set */ 2561 #define NVME_CQE_SC_SPC_INV_MEM_SETID 0x8d /* Invalid Memory Range SetId */ 2562 #define NVME_CQE_SC_SPC_INV_PROG_DATA 0x8e /* Invalid Program Data */ 2563 #define NVME_CQE_SC_SPC_INV_PROG_IDX 0x8f /* Invalid Program Index */ 2564 #define NVME_CQE_SC_SPC_INV_PROG_TYPE 0x90 /* Invalid Program Type */ 2565 #define NVME_CQE_SC_SPC_MAX_MEM_RANGE 0x91 /* Max. Memory Range Exceeded */ 2566 #define NVME_CQE_SC_SPC_MAX_MEM_SETIDS 0x92 /* Max. Mem Sets Ids Exceeded */ 2567 #define NVME_CQE_SC_SPC_MAX_PROG_ACT 0x93 /* Maximum Programs Activated */ 2568 #define NVME_CQE_SC_SPC_MAX_PROG_BYTES 0x94 /* Max. Prog Bytes Exceeded */ 2569 #define NVME_CQE_SC_SPC_MEM_SET_IN_USE 0x95 /* Memory Range Set In Use */ 2570 #define NVME_CQE_SC_SPC_NO_PROG 0x96 /* No Program */ 2571 #define NVME_CQE_SC_SPC_OVLP_MEM_RANGE 0x97 /* Overlap Memory Ranges */ 2572 #define NVME_CQE_SC_SPC_PROG_NOT_ACT 0x98 /* Program not activated */ 2573 #define NVME_CQE_SC_SPC_PROG_IN_USE 0x99 /* Program in Use */ 2574 #define NVME_CQE_SC_SPC_PROG_IDX_NO_DL 0x9a /* Program index not dl */ 2575 #define NVME_CQE_SC_SPC_PROG_2BIG 0x9b /* Program Too Big */ 2576 #define NVME_CQE_SC_SPC_MEDIA_VERIF 0x9c /* Success. Media Verif Read */ 2577 /* 0x9d to 0xb7 are reserved */ 2578 #define NVME_CQE_SC_SPC_ZONE_BDRY_ERR 0xb8 /* Zoned Boundary Error */ 2579 #define NVME_CQE_SC_SPC_ZONE_FULL 0xb9 /* Zone is Full */ 2580 #define NVME_CQE_SC_SPC_ZONE_RDONLY 0xba /* Zone is Read Only */ 2581 #define NVME_CQE_SC_SPC_ZONE_OFFLINE 0xbb /* Zone is Offline */ 2582 #define NVME_CQE_SC_SPC_ZONE_INV_WRITE 0xbc /* Zone Invalid Write */ 2583 #define NVME_CQE_SC_SPC_ZONE_ACT 0xbd /* Too May Active Zones */ 2584 #define NVME_CQE_SC_SPC_ZONE_OPEN 0xbe /* Too May Open Zones */ 2585 #define NVME_CQE_SC_SPC_INV_ZONE_TRANS 0xbf /* Invalid Zone State Trans */ 2586 2587 /* NVMe completion status code (data / metadata integrity) */ 2588 #define NVME_CQE_SC_INT_NVM_WRITE 0x80 /* Write Fault */ 2589 #define NVME_CQE_SC_INT_NVM_READ 0x81 /* Unrecovered Read Error */ 2590 #define NVME_CQE_SC_INT_NVM_GUARD 0x82 /* Guard Check Error */ 2591 #define NVME_CQE_SC_INT_NVM_APPL_TAG 0x83 /* Application Tag Check Err */ 2592 #define NVME_CQE_SC_INT_NVM_REF_TAG 0x84 /* Reference Tag Check Err */ 2593 #define NVME_CQE_SC_INT_NVM_COMPARE 0x85 /* Compare Failure */ 2594 #define NVME_CQE_SC_INT_NVM_ACCESS 0x86 /* Access Denied */ 2595 /* Added in 1.2 */ 2596 #define NVME_CQE_SC_INT_NVM_DEALLOC 0x87 /* Dealloc Log Block */ 2597 /* Added in 2.0 */ 2598 #define NVME_CQE_SC_INT_NVM_TAG 0x88 /* End-to-End Storage Tag Err */ 2599 2600 /* NVMe completion status code (path related) */ 2601 /* Added in NVMe 1.4 */ 2602 #define NVME_CQE_SC_PATH_INT_ERR 0x00 /* Internal Path Error */ 2603 #define NVME_CQE_SC_PATH_AA_PLOSS 0x01 /* Asym Access Pers Loss */ 2604 #define NVME_CQE_SC_PATH_AA_INACC 0x02 /* Asym Access Inaccessible */ 2605 #define NVME_CQE_SC_PATH_AA_TRANS 0x03 /* Asym Access Transition */ 2606 #define NVME_CQE_SC_PATH_CTRL_ERR 0x60 /* Controller Path Error */ 2607 #define NVME_CQE_SC_PATH_HOST_ERR 0x70 /* Host Path Error */ 2608 #define NVME_CQE_SC_PATH_HOST_ABRT 0x71 /* Cmd aborted by host */ 2609 2610 /* 2611 * Controller information (NVME_IOC_CTRL_INFO). This is a consolidation of misc. 2612 * information that we want to know about a controller. 2613 */ 2614 typedef struct { 2615 nvme_ioctl_common_t nci_common; 2616 nvme_identify_ctrl_t nci_ctrl_id; 2617 nvme_identify_nsid_t nci_common_ns; 2618 nvme_version_t nci_vers; 2619 nvme_capabilities_t nci_caps; 2620 uint32_t nci_nintrs; 2621 } nvme_ioctl_ctrl_info_t; 2622 2623 /* 2624 * NVME namespace states. 2625 * 2626 * The values are defined entirely by the driver. Some states correspond to 2627 * namespace states described by the NVMe specification r1.3 section 6.1, others 2628 * are specific to the implementation of this driver. These are present in the 2629 * nvme_ns_kinfo_t that is used with the NVME_IOC_NS_INFO ioctl. Devices that 2630 * support Namespace Management have the ability to transition through these 2631 * states directly. Devices without it may be able to have namespaces in these 2632 * states depending on the version. 2633 * 2634 * The states are as follows: 2635 * - UNALLOCATED: The namespace ID exists, but has no corresponding NVM 2636 * allocation as per the NVMe spec. It leaves this state with an NVMe 2637 * Namespace Management NS create command: NVME_IOC_NS_CREATE. 2638 * 2639 * - ALLOCATED: The namespace exists in the controller as per the NVMe spec. It 2640 * becomes ACTIVE (or IGNORED) by performing a controller attach comand: 2641 * NVME_IOC_CTRL_ATTACH. It becomes unallocated by performing an NVMe 2642 * Namespace Management NS delete command: NVME_IOC_NS_DELETE. 2643 * 2644 * - ACTIVE: The namespace exists and is attached to this controller as per the 2645 * NVMe spec. From the hardware's perspective the namespace is usable. 2646 * 2647 * Not all namespaces are supported by the kernel. For example, a namespace 2648 * may use features that the NVMe device driver does not support such as 2649 * end-to-end data protection features or a different command set. 2650 * 2651 * When a namespace enters the active state, we will immediately evaluate 2652 * whether or not we can support a block device (via blkdev(4D)) on this 2653 * namespace. If we can, then we will immediately advance to the NOT_IGNORED 2654 * state. Otherwise, to transition to the NOT_IGNORED state, the namespace 2655 * must be formatted with the FORMAT NVM command with supported settings. The 2656 * namespace can transition back to the ALLOCATED state by performing a 2657 * NVME_IOC_CTRL_DETACH ioctl. 2658 * 2659 * - NOT_IGNORED: The namespace is active from the controller perspective and is 2660 * formatted with settings that would support blkdev(4D) being attached; 2661 * however, there is no blkdev(4D) instance currently attached. A device 2662 * transitions from the NOT_IGNORED to the ATTACHED state by actively 2663 * attaching a blkdev(4D) instance to the namespace through the 2664 * NVME_IOC_BD_ATTACH ioctl. A namespace can transition back to the ACTIVE 2665 * state by issuing a FORMAT NVM command with unsupported settings. It can 2666 * also go to the ALLOCATED state by performing the NVME_IOC_CTRL_DETACH 2667 * ioctl. 2668 * 2669 * - ATTACHED: the driver has attached a blkdev(4D) instance to this namespace 2670 * and it is usable as a block device. Certain operations such as a FORMAT NVM 2671 * or similar are rejected during this state. The device can go back to ACTIVE 2672 * with the NVME_IOC_BD_DETACH ioctl. 2673 */ 2674 typedef enum { 2675 NVME_NS_STATE_UNALLOCATED = 0, 2676 NVME_NS_STATE_ALLOCATED, 2677 NVME_NS_STATE_ACTIVE, 2678 NVME_NS_STATE_NOT_IGNORED, 2679 NVME_NS_STATE_ATTACHED 2680 } nvme_ns_state_t; 2681 2682 #define NVME_NS_NSTATES 5 2683 2684 /* 2685 * This is the maximum length of the NVMe namespace's blkdev address. This is 2686 * only valid in the structure with the NVME_NS_STATE_ATTACHED flag is set. 2687 * Otherwise the entry will be all zeros. This is useful when you need to 2688 * determine what the corresponding blkdev instance in libdevinfo for the 2689 * device. 2690 */ 2691 #define NVME_BLKDEV_NAMELEN 128 2692 2693 /* 2694 * Namespace Information (NVME_IOC_NS_INFO). 2695 */ 2696 typedef struct { 2697 nvme_ioctl_common_t nni_common; 2698 nvme_ns_state_t nni_state; 2699 char nni_addr[NVME_BLKDEV_NAMELEN]; 2700 nvme_identify_nsid_t nni_id; 2701 } nvme_ioctl_ns_info_t; 2702 2703 /* 2704 * NVMe Command Set Identifiers. This was added in NVMe 2.0, but in all the 2705 * places it was required to be specified, the default value of 0 indicates the 2706 * traditional NVM command set. 2707 */ 2708 typedef enum { 2709 NVME_CSI_NVM = 0, 2710 NVME_CSI_KV, 2711 NVME_CSI_ZNS 2712 } nvme_csi_t; 2713 2714 #ifdef __cplusplus 2715 } 2716 #endif 2717 2718 #endif /* _SYS_NVME_H */ 2719