1#![allow(dead_code)]
2
3use modular_bitfield::prelude::*;
4
5#[derive(BitfieldSpecifier, Debug, Clone, Copy, Default)]
6#[bits = 2]
7pub enum AccessLatency {
8 #[default]
9 NoInfo,
10 Idle,
11 Normal,
12 Low,
13}
14
15#[derive(BitfieldSpecifier, Debug, Clone, Copy, Default)]
16#[bits = 4]
17pub enum AccessFrequency {
18 #[default]
19 NoInfo,
20 Typical,
21 InfrequentBoth,
22 InfrequentWrites,
23 InfrequentReads,
24 FrequentBoth,
25 OneTime,
26 Speculative,
27 OverwriteSoon,
28}
29
30use super::NvmCommand;
31use crate::ds::{
32 namespace::NamespaceId,
33 queue::{
34 subentry::{CommandDword0, CommonCommand, Dptr, FuseSpec, Psdt},
35 CommandId,
36 },
37};
38
39#[bitfield(bits = 32)]
40#[repr(u32)]
41struct DatasetMgmtDword10 {
42 nr_ranges_z: u8,
43 #[skip]
44 resv: B24,
45}
46
47#[bitfield(bits = 32)]
48#[repr(u32)]
49pub struct DatasetMgmtDword11 {
50 integral_for_read: bool,
51 integral_for_write: bool,
52 deallocate: bool,
53 #[skip]
54 resv: B29,
55}
56
57pub struct DatasetMgmtCommand {
58 dw10: DatasetMgmtDword10,
59 dw11: DatasetMgmtDword11,
60 dptr: Dptr,
61 cdw0: CommandDword0,
62 nsid: NamespaceId,
63}
64
65#[bitfield(bits = 32)]
66pub struct ContextAttributes {
67 pub access_frequency: AccessFrequency,
68 pub access_latency: AccessLatency,
69 #[skip]
70 resv: B2,
71 pub seq_read_range: bool,
72 pub seq_write_range: bool,
73 pub write_prepare: bool,
74 #[skip]
75 resv2: B13,
76 pub command_access_size: u8,
77}
78
79impl DatasetMgmtCommand {
80 pub fn new(
82 cid: CommandId,
83 nsid: NamespaceId,
84 dptr: Dptr,
85 nr_ranges: u8,
86 attributes: DatasetMgmtDword11,
87 ) -> Self {
88 Self {
89 dw10: DatasetMgmtDword10::new().with_nr_ranges_z(nr_ranges - 1),
90 dw11: attributes,
91 dptr,
92 cdw0: CommandDword0::build(
93 NvmCommand::DatasetMgmt.into(),
94 cid,
95 FuseSpec::Normal,
96 Psdt::Prp,
97 ),
98 nsid,
99 }
100 }
101}
102
103impl From<DatasetMgmtCommand> for CommonCommand {
104 fn from(c: DatasetMgmtCommand) -> Self {
105 Self::new()
106 .with_cdw0(c.cdw0)
107 .with_cdw10(c.dw10.into())
108 .with_cdw11(c.dw11.into())
109 .with_nsid(c.nsid)
110 .with_dptr(c.dptr)
111 }
112}