1#![allow(dead_code)]
2
3use std::mem::size_of;
4
5use modular_bitfield_msb::prelude::*;
6
7use crate::{result_data::ResultData, Command, DataDirection, Scsi};
8
9#[derive(Clone, Debug)]
10pub struct ReportSupportedTaskManagementFunctionsCommand<'a> {
11 interface: &'a Scsi,
12 command_buffer: CommandBuffer,
13}
14
15#[derive(Clone, Copy, Debug)]
16pub struct CommandResult {
17 pub abort_task_supported: bool,
18 pub abort_task_set_supported: bool,
19 pub clear_aca_supported: bool,
20 pub clear_task_set_supported: bool,
21 pub logical_unit_reset_supported: bool,
22 pub query_task_supported: bool,
23 pub query_asynchronous_event_supported: bool,
24 pub query_task_set_supported: bool,
25 pub i_t_nexus_reset_supported: bool,
26 pub task_management_function_timeouts_valid: bool,
27 pub abort_task_timeout_selector: bool,
28 pub abort_task_set_timeout_selector: bool,
29 pub clear_aca_timeout_selector: bool,
30 pub clear_task_set_timeout_selector: bool,
31 pub logical_unit_reset_timeout_selector: bool,
32 pub query_task_timeout_selector: bool,
33 pub query_asynchronous_event_timeout_selector: bool,
34 pub query_task_set_timeout_selector: bool,
35 pub i_t_nexus_reset_timeout_selector: bool,
36 pub task_management_functions_long_timeout: u32,
37 pub task_management_functions_short_timeout: u32,
38}
39
40impl<'a> ReportSupportedTaskManagementFunctionsCommand<'a> {
41 fn new(interface: &'a Scsi) -> Self {
42 Self {
43 interface,
44 command_buffer: CommandBuffer::new()
45 .with_operation_code(OPERATION_CODE)
46 .with_service_action(SERVICE_ACTION)
47 .with_allocation_length(size_of::<
48 ReportSupportedTaskManagementFunctionsExtendedParameterData,
49 >() as u32),
50 }
51 }
52
53 pub fn return_extended_parameter_data(&mut self, value: bool) -> &mut Self {
54 self.command_buffer
55 .set_return_extended_parameter_data(value.into());
56 self
57 }
58
59 pub fn control(&mut self, value: u8) -> &mut Self {
60 self.command_buffer.set_control(value);
61 self
62 }
63
64 pub fn issue(&mut self) -> crate::Result<CommandResult> {
65 self.interface.issue(&ThisCommand {
66 command_buffer: self.command_buffer,
67 })
68 }
69}
70
71impl Scsi {
72 pub fn report_supported_task_management_functions(
73 &self,
74 ) -> ReportSupportedTaskManagementFunctionsCommand<'_> {
75 ReportSupportedTaskManagementFunctionsCommand::new(self)
76 }
77}
78
79const OPERATION_CODE: u8 = 0xA3;
80const SERVICE_ACTION: u8 = 0x0D;
81
82#[bitfield]
83#[derive(Clone, Copy, Debug)]
84struct CommandBuffer {
85 operation_code: B8,
86 reserved_0: B3,
87 service_action: B5,
88 return_extended_parameter_data: B1,
89 reserved_1: B31,
90 allocation_length: B32,
91 reserved_2: B8,
92 control: B8,
93}
94
95#[bitfield]
96#[derive(Clone, Copy)]
97struct ReportSupportedTaskManagementFunctionsExtendedParameterData {
98 abort_task_supported: B1,
99 abort_task_set_supported: B1,
100 clear_aca_supported: B1,
101 clear_task_set_supported: B1,
102 logical_unit_reset_supported: B1,
103 query_task_supported: B1,
104 obsolete: B2,
105 reserved_0: B5,
106 query_asynchronous_event_supported: B1,
107 query_task_set_supported: B1,
108 i_t_nexus_reset_supported: B1,
109 reserved_1: B8,
110 report_supported_task_management_functions_additional_data_length: B8,
111 reserved_2: B7,
112 task_management_function_timeouts_valid: B1,
113 reserved_3: B8,
114 abort_task_timeout_selector: B1,
115 abort_task_set_timeout_selector: B1,
116 clear_aca_timeout_selector: B1,
117 clear_task_set_timeout_selector: B1,
118 logical_unit_reset_timeout_selector: B1,
119 query_task_timeout_selector: B1,
120 reserved_4: B2,
121 reserved_5: B5,
122 query_asynchronous_event_timeout_selector: B1,
123 query_task_set_timeout_selector: B1,
124 i_t_nexus_reset_timeout_selector: B1,
125 task_management_functions_long_timeout: B32,
126 task_management_functions_short_timeout: B32,
127}
128
129struct ThisCommand {
130 command_buffer: CommandBuffer,
131}
132
133impl Command for ThisCommand {
134 type CommandBuffer = CommandBuffer;
135
136 type DataBuffer = ReportSupportedTaskManagementFunctionsExtendedParameterData;
137
138 type DataBufferWrapper = ReportSupportedTaskManagementFunctionsExtendedParameterData;
139
140 type ReturnType = crate::Result<CommandResult>;
141
142 fn direction(&self) -> DataDirection {
143 DataDirection::FromDevice
144 }
145
146 fn command(&self) -> Self::CommandBuffer {
147 self.command_buffer
148 }
149
150 fn data(&self) -> Self::DataBufferWrapper {
151 ReportSupportedTaskManagementFunctionsExtendedParameterData::new()
152 }
153
154 fn data_size(&self) -> u32 {
155 self.command_buffer.allocation_length()
156 }
157
158 fn process_result(&self, result: ResultData<Self::DataBufferWrapper>) -> Self::ReturnType {
159 result.check_ioctl_error()?;
160 result.check_common_error()?;
161
162 let data = result.data;
163 Ok(CommandResult {
164 abort_task_supported: data.abort_task_supported() != 0,
165 abort_task_set_supported: data.abort_task_set_supported() != 0,
166 clear_aca_supported: data.clear_aca_supported() != 0,
167 clear_task_set_supported: data.clear_task_set_supported() != 0,
168 logical_unit_reset_supported: data.logical_unit_reset_supported() != 0,
169 query_task_supported: data.query_task_supported() != 0,
170 query_asynchronous_event_supported: data.query_asynchronous_event_supported() != 0,
171 query_task_set_supported: data.query_task_set_supported() != 0,
172 i_t_nexus_reset_supported: data.i_t_nexus_reset_supported() != 0,
173 task_management_function_timeouts_valid: data.task_management_function_timeouts_valid()
174 != 0,
175 abort_task_timeout_selector: data.abort_task_timeout_selector() != 0,
176 abort_task_set_timeout_selector: data.abort_task_set_timeout_selector() != 0,
177 clear_aca_timeout_selector: data.clear_aca_timeout_selector() != 0,
178 clear_task_set_timeout_selector: data.clear_task_set_timeout_selector() != 0,
179 logical_unit_reset_timeout_selector: data.logical_unit_reset_timeout_selector() != 0,
180 query_task_timeout_selector: data.query_task_timeout_selector() != 0,
181 query_asynchronous_event_timeout_selector: data
182 .query_asynchronous_event_timeout_selector()
183 != 0,
184 query_task_set_timeout_selector: data.query_task_set_timeout_selector() != 0,
185 i_t_nexus_reset_timeout_selector: data.i_t_nexus_reset_timeout_selector() != 0,
186 task_management_functions_long_timeout: data.task_management_functions_long_timeout(),
187 task_management_functions_short_timeout: data.task_management_functions_short_timeout(),
188 })
189 }
190}
191
192#[cfg(test)]
193mod tests {
194 use super::*;
195 use std::mem::size_of;
196
197 const COMMAND_LENGTH: usize = 12;
198 const PARAMETER_LENGTH: usize = 16;
199
200 #[test]
201 fn layout_test() {
202 assert_eq!(
203 size_of::<CommandBuffer>(),
204 COMMAND_LENGTH,
205 concat!("Size of: ", stringify!(CommandBuffer))
206 );
207
208 assert_eq!(
209 size_of::<ReportSupportedTaskManagementFunctionsExtendedParameterData>(),
210 PARAMETER_LENGTH,
211 concat!(
212 "Size of: ",
213 stringify!(ReportSupportedTaskManagementFunctionsExtendedParameterData)
214 )
215 );
216 }
217}