1use core::num::NonZeroUsize;
9
10#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub struct BlockRequestId(usize);
13
14impl BlockRequestId {
15 pub const fn new(id: usize) -> Self {
16 Self(id)
17 }
18}
19
20impl From<BlockRequestId> for usize {
21 fn from(value: BlockRequestId) -> Self {
22 value.0
23 }
24}
25
26#[derive(Clone, Copy, Debug, PartialEq, Eq)]
31#[non_exhaustive]
32pub enum BlockTransferMode {
33 Fifo,
35 Dma,
37}
38
39#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41pub struct BlockBufferConfig {
42 pub block_size: NonZeroUsize,
44 pub align: usize,
46 pub dma_mask: Option<u64>,
48}
49
50impl BlockBufferConfig {
51 pub const fn new(block_size: NonZeroUsize, align: usize, dma_mask: Option<u64>) -> Self {
52 Self {
53 block_size,
54 align,
55 dma_mask,
56 }
57 }
58}
59
60#[derive(Clone, Copy, Debug, PartialEq, Eq)]
65#[non_exhaustive]
66pub enum BlockTransferDirection {
67 Read,
68 Write,
69}
70
71#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
77#[non_exhaustive]
78pub enum BlockTransferState {
79 #[default]
80 Idle,
81 Submitted {
82 id: BlockRequestId,
83 mode: BlockTransferMode,
84 direction: BlockTransferDirection,
85 },
86 Complete {
87 id: BlockRequestId,
88 mode: BlockTransferMode,
89 direction: BlockTransferDirection,
90 },
91 Failed {
92 id: BlockRequestId,
93 mode: BlockTransferMode,
94 direction: BlockTransferDirection,
95 },
96}
97
98impl BlockTransferState {
99 pub const fn id(self) -> Option<BlockRequestId> {
100 match self {
101 Self::Idle => None,
102 Self::Submitted { id, .. } | Self::Complete { id, .. } | Self::Failed { id, .. } => {
103 Some(id)
104 }
105 }
106 }
107
108 pub const fn mode(self) -> Option<BlockTransferMode> {
109 match self {
110 Self::Idle => None,
111 Self::Submitted { mode, .. }
112 | Self::Complete { mode, .. }
113 | Self::Failed { mode, .. } => Some(mode),
114 }
115 }
116
117 pub const fn direction(self) -> Option<BlockTransferDirection> {
118 match self {
119 Self::Idle => None,
120 Self::Submitted { direction, .. }
121 | Self::Complete { direction, .. }
122 | Self::Failed { direction, .. } => Some(direction),
123 }
124 }
125}
126
127#[derive(Clone, Copy, Debug, PartialEq, Eq)]
132#[non_exhaustive]
133pub enum BlockPoll {
134 Pending,
135 Complete,
136}
137
138#[derive(Clone, Copy, Debug, PartialEq, Eq)]
142#[non_exhaustive]
143pub enum DataCommandDirection {
144 Read,
145 Write,
146}
147
148#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
152#[non_exhaustive]
153pub enum DataCommandState {
154 #[default]
155 Idle,
156 Submitted {
157 direction: DataCommandDirection,
158 cmd_index: u8,
159 block_size: u32,
160 block_count: u32,
161 },
162}
163
164#[derive(Clone, Copy, Debug)]
168#[non_exhaustive]
169pub enum DataCommandPoll {
170 Pending,
171 Complete(crate::response::Response),
172}
173
174#[derive(Clone, Copy, Debug, PartialEq, Eq)]
178#[non_exhaustive]
179pub enum CommandPoll {
180 Pending,
181 Complete,
182}
183
184#[derive(Clone, Copy, Debug)]
189#[non_exhaustive]
190pub enum CommandResponsePoll {
191 Pending,
192 Complete(crate::response::Response),
193}
194
195#[derive(Clone, Copy, Debug)]
199#[non_exhaustive]
200pub enum OperationPoll<T> {
201 Pending,
202 Complete(T),
203}
204
205impl From<CommandResponsePoll> for OperationPoll<crate::response::Response> {
206 fn from(value: CommandResponsePoll) -> Self {
207 match value {
208 CommandResponsePoll::Pending => Self::Pending,
209 CommandResponsePoll::Complete(response) => Self::Complete(response),
210 }
211 }
212}
213
214impl From<DataCommandPoll> for OperationPoll<crate::response::Response> {
215 fn from(value: DataCommandPoll) -> Self {
216 match value {
217 DataCommandPoll::Pending => Self::Pending,
218 DataCommandPoll::Complete(response) => Self::Complete(response),
219 }
220 }
221}
222
223impl From<BlockPoll> for OperationPoll<()> {
224 fn from(value: BlockPoll) -> Self {
225 match value {
226 BlockPoll::Pending => Self::Pending,
227 BlockPoll::Complete => Self::Complete(()),
228 }
229 }
230}