2 NvmExpressDxe driver is used to manage non-volatile memory subsystem which follows
3 NVM Express specification.
5 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 // controller register offsets
24 #define NVME_CAP_OFFSET 0x0000 // Controller Capabilities
25 #define NVME_VER_OFFSET 0x0008 // Version
26 #define NVME_INTMS_OFFSET 0x000c // Interrupt Mask Set
27 #define NVME_INTMC_OFFSET 0x0010 // Interrupt Mask Clear
28 #define NVME_CC_OFFSET 0x0014 // Controller Configuration
29 #define NVME_CSTS_OFFSET 0x001c // Controller Status
30 #define NVME_AQA_OFFSET 0x0024 // Admin Queue Attributes
31 #define NVME_ASQ_OFFSET 0x0028 // Admin Submission Queue Base Address
32 #define NVME_ACQ_OFFSET 0x0030 // Admin Completion Queue Base Address
33 #define NVME_SQ0_OFFSET 0x1000 // Submission Queue 0 (admin) Tail Doorbell
34 #define NVME_CQ0_OFFSET 0x1004 // Completion Queue 0 (admin) Head Doorbell
37 // These register offsets are defined as 0x1000 + (N * (4 << CAP.DSTRD))
38 // Get the doorbell stride bit shift value from the controller capabilities.
40 #define NVME_SQTDBL_OFFSET(QID, DSTRD) 0x1000 + ((2 * (QID)) * (4 << (DSTRD))) // Submission Queue y (NVM) Tail Doorbell
41 #define NVME_CQHDBL_OFFSET(QID, DSTRD) 0x1000 + (((2 * (QID)) + 1) * (4 << (DSTRD))) // Completion Queue y (NVM) Head Doorbell
47 // 3.1.1 Offset 00h: CAP - Controller Capabilities
50 UINT16 Mqes
; // Maximum Queue Entries Supported
51 UINT8 Cqr
:1; // Contiguous Queues Required
52 UINT8 Ams
:2; // Arbitration Mechanism Supported
57 UINT16 Css
:4; // Command Sets Supported
65 // 3.1.2 Offset 08h: VS - Version
68 UINT16 Mnr
; // Minor version number
69 UINT16 Mjr
; // Major version number
73 // 3.1.5 Offset 14h: CC - Controller Configuration
76 UINT16 En
:1; // Enable
78 UINT16 Css
:3; // Command Set Selected
79 UINT16 Mps
:4; // Memory Page Size
80 UINT16 Ams
:3; // Arbitration Mechanism Selected
81 UINT16 Shn
:2; // Shutdown Notification
82 UINT8 Iosqes
:4; // I/O Submission Queue Entry Size
83 UINT8 Iocqes
:4; // I/O Completion Queue Entry Size
88 // 3.1.6 Offset 1Ch: CSTS - Controller Status
91 UINT32 Rdy
:1; // Ready
92 UINT32 Cfs
:1; // Controller Fatal Status
93 UINT32 Shst
:2; // Shutdown Status
94 UINT32 Nssro
:1; // NVM Subsystem Reset Occurred
99 // 3.1.8 Offset 24h: AQA - Admin Queue Attributes
102 UINT16 Asqs
:12; // Submission Queue Size
104 UINT16 Acqs
:12; // Completion Queue Size
109 // 3.1.9 Offset 28h: ASQ - Admin Submission Queue Base Address
113 UINT64 Asqb
:52; // Admin Submission Queue Base Address
117 // 3.1.10 Offset 30h: ACQ - Admin Completion Queue Base Address
121 UINT64 Acqb
:52; // Admin Completion Queue Base Address
125 // 3.1.11 Offset (1000h + ((2y) * (4 << CAP.DSTRD))): SQyTDBL - Submission Queue y Tail Doorbell
133 // 3.1.12 Offset (1000h + ((2y + 1) * (4 << CAP.DSTRD))): CQyHDBL - Completion Queue y Head Doorbell
141 // NVM command set structures
149 UINT64 Slba
; /* Starting Sector Address */
153 UINT16 Nlb
; /* Number of Sectors */
155 UINT16 Prinfo
:4; /* Protection Info Check */
156 UINT16 Fua
:1; /* Force Unit Access */
157 UINT16 Lr
:1; /* Limited Retry */
161 UINT32 Af
:4; /* Access Frequency */
162 UINT32 Al
:2; /* Access Latency */
163 UINT32 Sr
:1; /* Sequential Request */
164 UINT32 In
:1; /* Incompressible */
169 UINT32 Eilbrt
; /* Expected Initial Logical Block Reference Tag */
173 UINT16 Elbat
; /* Expected Logical Block Application Tag */
174 UINT16 Elbatm
; /* Expected Logical Block Application Tag Mask */
184 UINT64 Slba
; /* Starting Sector Address */
188 UINT16 Nlb
; /* Number of Sectors */
190 UINT16 Prinfo
:4; /* Protection Info Check */
191 UINT16 Fua
:1; /* Force Unit Access */
192 UINT16 Lr
:1; /* Limited Retry */
196 UINT32 Af
:4; /* Access Frequency */
197 UINT32 Al
:2; /* Access Latency */
198 UINT32 Sr
:1; /* Sequential Request */
199 UINT32 In
:1; /* Incompressible */
204 UINT32 Ilbrt
; /* Initial Logical Block Reference Tag */
208 UINT16 Lbat
; /* Logical Block Application Tag */
209 UINT16 Lbatm
; /* Logical Block Application Tag Mask */
219 UINT32 Flush
; /* Flush */
223 // Write Uncorrectable command
229 UINT64 Slba
; /* Starting LBA */
233 UINT32 Nlb
:16; /* Number of Logical Blocks */
235 } NVME_WRITE_UNCORRECTABLE
;
238 // Write Zeroes command
244 UINT64 Slba
; /* Starting LBA */
248 UINT16 Nlb
; /* Number of Logical Blocks */
250 UINT16 Prinfo
:4; /* Protection Info Check */
251 UINT16 Fua
:1; /* Force Unit Access */
252 UINT16 Lr
:1; /* Limited Retry */
260 UINT32 Ilbrt
; /* Initial Logical Block Reference Tag */
264 UINT16 Lbat
; /* Logical Block Application Tag */
265 UINT16 Lbatm
; /* Logical Block Application Tag Mask */
275 UINT64 Slba
; /* Starting LBA */
279 UINT16 Nlb
; /* Number of Logical Blocks */
281 UINT16 Prinfo
:4; /* Protection Info Check */
282 UINT16 Fua
:1; /* Force Unit Access */
283 UINT16 Lr
:1; /* Limited Retry */
291 UINT32 Eilbrt
; /* Expected Initial Logical Block Reference Tag */
295 UINT16 Elbat
; /* Expected Logical Block Application Tag */
296 UINT16 Elbatm
; /* Expected Logical Block Application Tag Mask */
303 NVME_WRITE_UNCORRECTABLE WriteUncorrectable
;
304 NVME_WRITE_ZEROES WriteZeros
;
305 NVME_COMPARE Compare
;
309 UINT16 Mp
; /* Maximum Power */
310 UINT8 Rsvd1
; /* Reserved as of Nvm Express 1.1 Spec */
311 UINT8 Mps
:1; /* Max Power Scale */
312 UINT8 Nops
:1; /* Non-Operational State */
313 UINT8 Rsvd2
:6; /* Reserved as of Nvm Express 1.1 Spec */
314 UINT32 Enlat
; /* Entry Latency */
315 UINT32 Exlat
; /* Exit Latency */
316 UINT8 Rrt
:5; /* Relative Read Throughput */
317 UINT8 Rsvd3
:3; /* Reserved as of Nvm Express 1.1 Spec */
318 UINT8 Rrl
:5; /* Relative Read Leatency */
319 UINT8 Rsvd4
:3; /* Reserved as of Nvm Express 1.1 Spec */
320 UINT8 Rwt
:5; /* Relative Write Throughput */
321 UINT8 Rsvd5
:3; /* Reserved as of Nvm Express 1.1 Spec */
322 UINT8 Rwl
:5; /* Relative Write Leatency */
323 UINT8 Rsvd6
:3; /* Reserved as of Nvm Express 1.1 Spec */
324 UINT8 Rsvd7
[16]; /* Reserved as of Nvm Express 1.1 Spec */
328 // Identify Controller Data
332 // Controller Capabilities and Features 0-255
334 UINT16 Vid
; /* PCI Vendor ID */
335 UINT16 Ssvid
; /* PCI sub-system vendor ID */
336 UINT8 Sn
[20]; /* Produce serial number */
338 UINT8 Mn
[40]; /* Proeduct model number */
339 UINT8 Fr
[8]; /* Firmware Revision */
340 UINT8 Rab
; /* Recommended Arbitration Burst */
341 UINT8 Ieee_oiu
[3]; /* Organization Unique Identifier */
342 UINT8 Cmic
; /* Multi-interface Capabilities */
343 UINT8 Mdts
; /* Maximum Data Transfer Size */
344 UINT8 Cntlid
[2]; /* Controller ID */
345 UINT8 Rsvd1
[176]; /* Reserved as of Nvm Express 1.1 Spec */
347 // Admin Command Set Attributes
349 UINT16 Oacs
; /* Optional Admin Command Support */
350 UINT8 Acl
; /* Abort Command Limit */
351 UINT8 Aerl
; /* Async Event Request Limit */
352 UINT8 Frmw
; /* Firmware updates */
353 UINT8 Lpa
; /* Log Page Attributes */
354 UINT8 Elpe
; /* Error Log Page Entries */
355 UINT8 Npss
; /* Number of Power States Support */
356 UINT8 Avscc
; /* Admin Vendor Specific Command Configuration */
357 UINT8 Apsta
; /* Autonomous Power State Transition Attributes */
358 UINT8 Rsvd2
[246]; /* Reserved as of Nvm Express 1.1 Spec */
360 // NVM Command Set Attributes
362 UINT8 Sqes
; /* Submission Queue Entry Size */
363 UINT8 Cqes
; /* Completion Queue Entry Size */
364 UINT16 Rsvd3
; /* Reserved as of Nvm Express 1.1 Spec */
365 UINT32 Nn
; /* Number of Namespaces */
366 UINT16 Oncs
; /* Optional NVM Command Support */
367 UINT16 Fuses
; /* Fused Operation Support */
368 UINT8 Fna
; /* Format NVM Attributes */
369 UINT8 Vwc
; /* Volatile Write Cache */
370 UINT16 Awun
; /* Atomic Write Unit Normal */
371 UINT16 Awupf
; /* Atomic Write Unit Power Fail */
372 UINT8 Nvscc
; /* NVM Vendor Specific Command Configuration */
373 UINT8 Rsvd4
; /* Reserved as of Nvm Express 1.1 Spec */
374 UINT16 Acwu
; /* Atomic Compare & Write Unit */
375 UINT16 Rsvd5
; /* Reserved as of Nvm Express 1.1 Spec */
376 UINT32 Sgls
; /* SGL Support */
377 UINT8 Rsvd6
[164]; /* Reserved as of Nvm Express 1.1 Spec */
379 // I/O Command set Attributes
381 UINT8 Rsvd7
[1344]; /* Reserved as of Nvm Express 1.1 Spec */
383 // Power State Descriptors
385 NVME_PSDESCRIPTOR PsDescriptor
[32];
387 UINT8 VendorData
[1024]; /* Vendor specific data */
388 } NVME_ADMIN_CONTROLLER_DATA
;
391 UINT16 Ms
; /* Metadata Size */
392 UINT8 Lbads
; /* LBA Data Size */
393 UINT8 Rp
:2; /* Relative Performance */
394 #define LBAF_RP_BEST 00b
395 #define LBAF_RP_BETTER 01b
396 #define LBAF_RP_GOOD 10b
397 #define LBAF_RP_DEGRADED 11b
398 UINT8 Rsvd1
:6; /* Reserved as of Nvm Express 1.1 Spec */
402 // Identify Namespace Data
406 // NVM Command Set Specific
408 UINT64 Nsze
; /* Namespace Size (total number of blocks in formatted namespace) */
409 UINT64 Ncap
; /* Namespace Capacity (max number of logical blocks) */
410 UINT64 Nuse
; /* Namespace Utilization */
411 UINT8 Nsfeat
; /* Namespace Features */
412 UINT8 Nlbaf
; /* Number of LBA Formats */
413 UINT8 Flbas
; /* Formatted LBA size */
414 UINT8 Mc
; /* Metadata Capabilities */
415 UINT8 Dpc
; /* End-to-end Data Protection capabilities */
416 UINT8 Dps
; /* End-to-end Data Protection Type Settings */
417 UINT8 Nmic
; /* Namespace Multi-path I/O and Namespace Sharing Capabilities */
418 UINT8 Rescap
; /* Reservation Capabilities */
419 UINT8 Rsvd1
[88]; /* Reserved as of Nvm Express 1.1 Spec */
420 UINT64 Eui64
; /* IEEE Extended Unique Identifier */
424 NVME_LBAFORMAT LbaFormat
[16];
426 UINT8 Rsvd2
[192]; /* Reserved as of Nvm Express 1.1 Spec */
427 UINT8 VendorData
[3712]; /* Vendor specific data */
428 } NVME_ADMIN_NAMESPACE_DATA
;
431 // NvmExpress Admin Identify Cmd
439 } NVME_ADMIN_IDENTIFY
;
442 // NvmExpress Admin Create I/O Completion Queue
448 UINT32 Qid
:16; /* Queue Identifier */
449 UINT32 Qsize
:16; /* Queue Size */
454 UINT32 Pc
:1; /* Physically Contiguous */
455 UINT32 Ien
:1; /* Interrupts Enabled */
456 UINT32 Rsvd1
:14; /* reserved as of Nvm Express 1.1 Spec */
457 UINT32 Iv
:16; /* Interrupt Vector */
461 // NvmExpress Admin Create I/O Submission Queue
467 UINT32 Qid
:16; /* Queue Identifier */
468 UINT32 Qsize
:16; /* Queue Size */
473 UINT32 Pc
:1; /* Physically Contiguous */
474 UINT32 Qprio
:2; /* Queue Priority */
475 UINT32 Rsvd1
:13; /* Reserved as of Nvm Express 1.1 Spec */
476 UINT32 Cqid
:16; /* Completion Queue ID */
480 // NvmExpress Admin Delete I/O Completion Queue
491 // NvmExpress Admin Delete I/O Submission Queue
502 // NvmExpress Admin Abort Command
508 UINT32 Sqid
:16; /* Submission Queue identifier */
509 UINT32 Cid
:16; /* Command Identifier */
513 // NvmExpress Admin Firmware Activate Command
519 UINT32 Fs
:3; /* Submission Queue identifier */
520 UINT32 Aa
:2; /* Command Identifier */
522 } NVME_ADMIN_FIRMWARE_ACTIVATE
;
525 // NvmExpress Admin Firmware Image Download Command
531 UINT32 Numd
; /* Number of Dwords */
535 UINT32 Ofst
; /* Offset */
536 } NVME_ADMIN_FIRMWARE_IMAGE_DOWNLOAD
;
539 // NvmExpress Admin Get Features Command
545 UINT32 Fid
:8; /* Feature Identifier */
546 UINT32 Sel
:3; /* Select */
548 } NVME_ADMIN_GET_FEATURES
;
551 // NvmExpress Admin Get Log Page Command
557 UINT32 Lid
:8; /* Log Page Identifier */
558 #define LID_ERROR_INFO
559 #define LID_SMART_INFO
560 #define LID_FW_SLOT_INFO
562 UINT32 Numd
:12; /* Number of Dwords */
563 UINT32 Rsvd2
:4; /* Reserved as of Nvm Express 1.1 Spec */
564 } NVME_ADMIN_GET_LOG_PAGE
;
567 // NvmExpress Admin Set Features Command
573 UINT32 Fid
:8; /* Feature Identifier */
575 UINT32 Sv
:1; /* Save */
576 } NVME_ADMIN_SET_FEATURES
;
579 // NvmExpress Admin Format NVM Command
585 UINT32 Lbaf
:4; /* LBA Format */
586 UINT32 Ms
:1; /* Metadata Settings */
587 UINT32 Pi
:3; /* Protection Information */
588 UINT32 Pil
:1; /* Protection Information Location */
589 UINT32 Ses
:3; /* Secure Erase Settings */
591 } NVME_ADMIN_FORMAT_NVM
;
594 // NvmExpress Admin Security Receive Command
601 UINT32 Spsp
:16; /* SP Specific */
602 UINT32 Secp
:8; /* Security Protocol */
606 UINT32 Al
; /* Allocation Length */
607 } NVME_ADMIN_SECURITY_RECEIVE
;
610 // NvmExpress Admin Security Send Command
617 UINT32 Spsp
:16; /* SP Specific */
618 UINT32 Secp
:8; /* Security Protocol */
622 UINT32 Tl
; /* Transfer Length */
623 } NVME_ADMIN_SECURITY_SEND
;
626 NVME_ADMIN_IDENTIFY Identify
;
627 NVME_ADMIN_CRIOCQ CrIoCq
;
628 NVME_ADMIN_CRIOSQ CrIoSq
;
629 NVME_ADMIN_DEIOCQ DeIoCq
;
630 NVME_ADMIN_DEIOSQ DeIoSq
;
631 NVME_ADMIN_ABORT Abort
;
632 NVME_ADMIN_FIRMWARE_ACTIVATE Activate
;
633 NVME_ADMIN_FIRMWARE_IMAGE_DOWNLOAD FirmwareImageDownload
;
634 NVME_ADMIN_GET_FEATURES GetFeatures
;
635 NVME_ADMIN_GET_LOG_PAGE GetLogPage
;
636 NVME_ADMIN_SET_FEATURES SetFeatures
;
637 NVME_ADMIN_FORMAT_NVM FormatNvm
;
638 NVME_ADMIN_SECURITY_RECEIVE SecurityReceive
;
639 NVME_ADMIN_SECURITY_SEND SecuritySend
;
652 NVME_ADMIN_CMD Admin
; // Union of Admin commands
653 NVME_CMD Nvm
; // Union of Nvm commands
662 // CDW 0, Common to all comnmands
665 UINT8 Fuse
:2; // Fused Operation
667 UINT8 Psdt
:1; // PRP or SGL for Data Transfer
668 UINT16 Cid
; // Command Identifier
673 UINT32 Nsid
; // Namespace Identifier
683 UINT64 Mptr
; // Metadata Pointer
688 UINT64 Prp
[2]; // First and second PRP entries
690 NVME_PAYLOAD Payload
;
709 UINT16 Sqhd
; // Submission Queue Head Pointer
710 UINT16 Sqid
; // Submission Queue Identifier
714 UINT16 Cid
; // Command Identifier
715 UINT16 Pt
:1; // Phase Tag
716 UINT16 Sc
:8; // Status Code
717 UINT16 Sct
:3; // Status Code Type
720 UINT16 Dnr
:1; // Retry
724 // Nvm Express Admin cmd opcodes
726 #define NVME_ADMIN_CRIOSQ_OPC 1
727 #define NVME_ADMIN_CRIOCQ_OPC 5
728 #define NVME_ADMIN_IDENTIFY_OPC 6
730 #define NVME_IO_FLUSH_OPC 0
731 #define NVME_IO_WRITE_OPC 1
732 #define NVME_IO_READ_OPC 2
735 // Offset from the beginning of private data queue buffer
737 #define NVME_ASQ_BUF_OFFSET EFI_PAGE_SIZE
740 Initialize the Nvm Express controller.
742 @param[in] Private The pointer to the NVME_CONTROLLER_PRIVATE_DATA data structure.
744 @retval EFI_SUCCESS The NVM Express Controller is initialized successfully.
745 @retval Others A device error occurred while initializing the controller.
750 IN NVME_CONTROLLER_PRIVATE_DATA
*Private
754 Get identify controller data.
756 @param Private The pointer to the NVME_CONTROLLER_PRIVATE_DATA data structure.
757 @param Buffer The buffer used to store the identify controller data.
759 @return EFI_SUCCESS Successfully get the identify controller data.
760 @return EFI_DEVICE_ERROR Fail to get the identify controller data.
764 NvmeIdentifyController (
765 IN NVME_CONTROLLER_PRIVATE_DATA
*Private
,
770 Get specified identify namespace data.
772 @param Private The pointer to the NVME_CONTROLLER_PRIVATE_DATA data structure.
773 @param NamespaceId The specified namespace identifier.
774 @param Buffer The buffer used to store the identify namespace data.
776 @return EFI_SUCCESS Successfully get the identify namespace data.
777 @return EFI_DEVICE_ERROR Fail to get the identify namespace data.
781 NvmeIdentifyNamespace (
782 IN NVME_CONTROLLER_PRIVATE_DATA
*Private
,
783 IN UINT32 NamespaceId
,