nvme/ds/controller/properties/
capabilities.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use modular_bitfield::prelude::*;

use crate::ds::HalfSeconds;

#[derive(Clone, Copy)]
#[bitfield(bits = 64)]
#[repr(u64)]
pub struct ControllerCap {
    #[skip(setters)]
    pub max_queue_entries: u16,
    #[skip(setters)]
    pub contiguous_queues_required: bool,
    #[skip(setters)]
    arbitration_mechanism: B2,
    #[skip]
    res: B5,
    #[skip(setters)]
    pub timeout: HalfSeconds,
    #[skip(setters)]
    pub doorbell_stride: B4,
    #[skip(setters)]
    pub nvm_subsystem_reset_supported: bool,
    #[skip(setters)]
    command_sets_supported: B8,
    #[skip(setters)]
    pub boot_partition_supported: bool,
    #[skip(setters)]
    pub controller_power_scope: ControllerPowerScope,
    #[skip(setters)]
    pub memory_page_sz_min: B4,
    #[skip(setters)]
    pub memory_page_sz_max: B4,
    #[skip(setters)]
    pub persistent_mem_region_supported: bool,
    #[skip(setters)]
    pub controller_mem_buffer_supported: bool,
    #[skip(setters)]
    pub nvm_subsystem_shutdown_supported: bool,
    #[skip(setters)]
    pub controller_ready_modes_supported: B2,
    #[skip]
    res2: B3,
}

#[derive(Clone, Copy, BitfieldSpecifier)]
#[bits = 2]
pub enum ControllerPowerScope {
    NotReported,
    Controller,
    Domain,
    NVMSubSystem,
}

impl ControllerCap {
    pub fn controller_ready_with_media_support(&self) -> bool {
        self.controller_ready_modes_supported() & 1 != 0
    }

    pub fn controller_ready_independent_of_media_support(&self) -> bool {
        self.controller_ready_modes_supported() & 2 != 0
    }

    pub fn arbitration_urgent_with_wrr(&self) -> bool {
        self.arbitration_mechanism() & 1 != 0
    }

    pub fn arbitration_vendor_specific(&self) -> bool {
        self.arbitration_mechanism() & 2 != 0
    }

    pub fn supports_nvm_command_set(&self) -> bool {
        self.command_sets_supported() & 1 != 0
    }

    pub fn supports_more_io_command_sets(&self) -> bool {
        self.command_sets_supported() & (1 << 6) != 0
    }

    pub fn doorbell_stride_bytes(&self) -> usize {
        1 << (self.doorbell_stride() as usize + 2)
    }

    pub fn memory_page_sz_min_bytes(&self) -> usize {
        1 << (self.memory_page_sz_min() + 12)
    }

    pub fn memory_page_sz_max_bytes(&self) -> usize {
        1 << (self.memory_page_sz_max() + 12)
    }
}