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::NsidConflict;
27
28// Device configuration shared by PCI and NVMe.
29const DOORBELL_STRIDE_BITS: u8 = 2;
30const VENDOR_ID: u16 = 0x1414;
31const NVME_VERSION: u32 = 0x00020000;
32const MAX_QES: u16 = 256;
33const BAR0_LEN: u64 = 0x10000;
34const IOSQES: u8 = 6;
35const IOCQES: u8 = 4;
36
37// NVMe page sizes. This must match the `PagedRange` page size.
38const PAGE_SIZE: usize = 4096;
39const PAGE_SIZE64: u64 = 4096;
40const PAGE_MASK: u64 = !(PAGE_SIZE64 - 1);
41const PAGE_SHIFT: u32 = PAGE_SIZE.trailing_zeros();
42const _: () = assert!(PAGE_SIZE == PagedRange::PAGE_SIZE);