nvme/
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
8mod error;
9mod namespace;
10mod pci;
11mod prp;
12mod queue;
13pub mod resolver;
14mod workers;
15
16#[cfg(test)]
17mod tests;
18
19pub use pci::NvmeController;
20pub use pci::NvmeControllerCaps;
21pub use workers::NsidConflict;
22pub use workers::NvmeControllerClient;
23
24use guestmem::ranges::PagedRange;
25use nvme_spec as spec;
26
27// Device configuration shared by PCI and NVMe.
28const DOORBELL_STRIDE_BITS: u8 = 2;
29const VENDOR_ID: u16 = 0x1414;
30const NVME_VERSION: u32 = 0x00020000;
31const MAX_QES: u16 = 256;
32const BAR0_LEN: u64 = 0x10000;
33const IOSQES: u8 = 6;
34const IOCQES: u8 = 4;
35
36// NVMe page sizes. This must match the `PagedRange` page size.
37const PAGE_SIZE: usize = 4096;
38const PAGE_SIZE64: u64 = 4096;
39const PAGE_MASK: u64 = !(PAGE_SIZE64 - 1);
40const PAGE_SHIFT: u32 = PAGE_SIZE.trailing_zeros();
41const _: () = assert!(PAGE_SIZE == PagedRange::PAGE_SIZE);