Skip to main content

nvme_test/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! An implementation of an NVMe controller emulator.
5
6#![forbid(unsafe_code)]
7
8pub mod command_match;
9mod error;
10mod namespace;
11mod pci;
12mod prp;
13mod queue;
14pub mod resolver;
15mod tdisp;
16mod workers;
17
18#[cfg(test)]
19mod tests;
20
21pub use pci::NvmeFaultController;
22pub use pci::NvmeFaultControllerCaps;
23pub use workers::NvmeFaultControllerClient;
24
25use guestmem::ranges::PagedRange;
26use nvme_spec as spec;
27use workers::AddNamespaceError;
28
29// Device configuration shared by PCI and NVMe.
30const DOORBELL_STRIDE_BITS: u8 = 2;
31const VENDOR_ID: u16 = pci_core::microsoft::VENDOR_ID;
32const DEVICE_ID: u16 = pci_core::microsoft::DeviceId::NVME.0;
33const NVME_VERSION: u32 = 0x00020000;
34const MAX_QES: u16 = 256;
35/// Maximum valid namespace ID for the NVM subsystem, reported in the `NN`
36/// field of Identify Controller. This is a fixed property of the subsystem
37/// (the size of the NSID address space), identical across all controllers,
38/// and is independent of how many namespaces are currently present.
39const MAX_NSID: u32 = 1024;
40const BAR0_LEN: u64 = 0x10000;
41const IOSQES: u8 = 6;
42const IOCQES: u8 = 4;
43
44// NVMe page sizes. This must match the `PagedRange` page size.
45const PAGE_SIZE: usize = 4096;
46const PAGE_SIZE64: u64 = 4096;
47const PAGE_MASK: u64 = !(PAGE_SIZE64 - 1);
48const PAGE_SHIFT: u32 = PAGE_SIZE.trailing_zeros();
49const _: () = assert!(PAGE_SIZE == PagedRange::PAGE_SIZE);