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 workers;
16
17#[cfg(test)]
18mod tests;
19
20pub use pci::NvmeFaultController;
21pub use pci::NvmeFaultControllerCaps;
22pub use workers::NvmeFaultControllerClient;
23
24use guestmem::ranges::PagedRange;
25use nvme_spec as spec;
26use workers::AddNamespaceError;
27
28// Device configuration shared by PCI and NVMe.
29const DOORBELL_STRIDE_BITS: u8 = 2;
30const VENDOR_ID: u16 = pci_core::microsoft::VENDOR_ID;
31const DEVICE_ID: u16 = pci_core::microsoft::DeviceId::NVME.0;
32const NVME_VERSION: u32 = 0x00020000;
33const MAX_QES: u16 = 256;
34/// Maximum valid namespace ID for the NVM subsystem, reported in the `NN`
35/// field of Identify Controller. This is a fixed property of the subsystem
36/// (the size of the NSID address space), identical across all controllers,
37/// and is independent of how many namespaces are currently present.
38const MAX_NSID: u32 = 1024;
39const BAR0_LEN: u64 = 0x10000;
40const IOSQES: u8 = 6;
41const IOCQES: u8 = 4;
42
43// NVMe page sizes. This must match the `PagedRange` page size.
44const PAGE_SIZE: usize = 4096;
45const PAGE_SIZE64: u64 = 4096;
46const PAGE_MASK: u64 = !(PAGE_SIZE64 - 1);
47const PAGE_SHIFT: u32 = PAGE_SIZE.trailing_zeros();
48const _: () = assert!(PAGE_SIZE == PagedRange::PAGE_SIZE);