nvme/ds/sgl/
mod.rs

1#![allow(dead_code)]
2
3use modular_bitfield::prelude::*;
4
5use super::Address;
6#[bitfield(bits = 128)]
7#[derive(Debug, Clone, Copy)]
8pub struct SglDescriptor {
9    data0: B120,
10    ident: SglIdentifier,
11}
12
13#[bitfield(bits = 8)]
14#[derive(BitfieldSpecifier, Debug, Clone, Copy)]
15struct SglIdentifier {
16    sub_type: B4,
17    desc_type: SglDescType,
18}
19
20#[derive(BitfieldSpecifier, Debug, Clone, Copy)]
21#[bits = 4]
22enum SglDescType {
23    DataBlock,
24    BitBucket,
25    Segment,
26    LastSegment,
27    KeyedDataBlock,
28    TransportDataBlock,
29    VendorSpecific = 0xf,
30}
31
32#[derive(BitfieldSpecifier)]
33#[bits = 4]
34enum SglSubType {
35    Address,
36    Offset,
37    TransportSpecific0 = 0xa,
38    TransportSpecific1 = 0xb,
39    TransportSpecific2 = 0xc,
40    TransportSpecific3 = 0xd,
41    TransportSpecific4 = 0xe,
42    TransportSpecific5 = 0xf,
43}
44
45#[bitfield]
46struct SglDataBlock {
47    addr: Address,
48    len: u32,
49    #[skip]
50    res: B24,
51    id: SglIdentifier,
52}
53
54impl From<SglDataBlock> for SglDescriptor {
55    fn from(s: SglDataBlock) -> Self {
56        Self::from_bytes(s.into_bytes())
57    }
58}
59
60#[bitfield]
61struct SglBitBucket {
62    #[skip]
63    res0: u64,
64    len: u32,
65    #[skip]
66    res1: B24,
67    id: SglIdentifier,
68}
69
70impl From<SglBitBucket> for SglDescriptor {
71    fn from(s: SglBitBucket) -> Self {
72        Self::from_bytes(s.into_bytes())
73    }
74}
75
76#[bitfield]
77struct SglSegment {
78    addr: Address,
79    len: u32,
80    #[skip]
81    res: B24,
82    id: SglIdentifier,
83}
84
85impl From<SglSegment> for SglDescriptor {
86    fn from(s: SglSegment) -> Self {
87        Self::from_bytes(s.into_bytes())
88    }
89}
90
91#[bitfield]
92struct SglKeyedDataBlock {
93    addr: Address,
94    len: B24,
95    key: u32,
96    id: SglIdentifier,
97}
98
99impl From<SglKeyedDataBlock> for SglDescriptor {
100    fn from(s: SglKeyedDataBlock) -> Self {
101        Self::from_bytes(s.into_bytes())
102    }
103}
104
105#[bitfield]
106struct SglTransportDataBlock {
107    #[skip]
108    res0: u64,
109    len: u32,
110    #[skip]
111    res1: B24,
112    id: SglIdentifier,
113}
114
115impl From<SglTransportDataBlock> for SglDescriptor {
116    fn from(s: SglTransportDataBlock) -> Self {
117        Self::from_bytes(s.into_bytes())
118    }
119}