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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#![allow(dead_code)]
use std::mem::size_of;
use modular_bitfield_msb::prelude::*;
use crate::{result_data::ResultData, Command, DataDirection, Scsi};
#[derive(Clone, Debug)]
pub struct ReportSupportedTaskManagementFunctionsCommand<'a> {
interface: &'a Scsi,
command_buffer: CommandBuffer,
}
#[derive(Clone, Copy, Debug)]
pub struct CommandResult {
pub abort_task_supported: bool,
pub abort_task_set_supported: bool,
pub clear_aca_supported: bool,
pub clear_task_set_supported: bool,
pub logical_unit_reset_supported: bool,
pub query_task_supported: bool,
pub query_asynchronous_event_supported: bool,
pub query_task_set_supported: bool,
pub i_t_nexus_reset_supported: bool,
pub task_management_function_timeouts_valid: bool,
pub abort_task_timeout_selector: bool,
pub abort_task_set_timeout_selector: bool,
pub clear_aca_timeout_selector: bool,
pub clear_task_set_timeout_selector: bool,
pub logical_unit_reset_timeout_selector: bool,
pub query_task_timeout_selector: bool,
pub query_asynchronous_event_timeout_selector: bool,
pub query_task_set_timeout_selector: bool,
pub i_t_nexus_reset_timeout_selector: bool,
pub task_management_functions_long_timeout: u32,
pub task_management_functions_short_timeout: u32,
}
impl<'a> ReportSupportedTaskManagementFunctionsCommand<'a> {
fn new(interface: &'a Scsi) -> Self {
Self {
interface,
command_buffer: CommandBuffer::new()
.with_operation_code(OPERATION_CODE)
.with_service_action(SERVICE_ACTION)
.with_allocation_length(size_of::<
ReportSupportedTaskManagementFunctionsExtendedParameterData,
>() as u32),
}
}
pub fn return_extended_parameter_data(&mut self, value: bool) -> &mut Self {
self.command_buffer
.set_return_extended_parameter_data(value.into());
self
}
pub fn control(&mut self, value: u8) -> &mut Self {
self.command_buffer.set_control(value);
self
}
pub fn issue(&mut self) -> crate::Result<CommandResult> {
self.interface.issue(&ThisCommand {
command_buffer: self.command_buffer,
})
}
}
impl Scsi {
pub fn report_supported_task_management_functions(
&self,
) -> ReportSupportedTaskManagementFunctionsCommand {
ReportSupportedTaskManagementFunctionsCommand::new(self)
}
}
const OPERATION_CODE: u8 = 0xA3;
const SERVICE_ACTION: u8 = 0x0D;
#[bitfield]
#[derive(Clone, Copy, Debug)]
struct CommandBuffer {
operation_code: B8,
reserved_0: B3,
service_action: B5,
return_extended_parameter_data: B1,
reserved_1: B31,
allocation_length: B32,
reserved_2: B8,
control: B8,
}
#[bitfield]
#[derive(Clone, Copy)]
struct ReportSupportedTaskManagementFunctionsExtendedParameterData {
abort_task_supported: B1,
abort_task_set_supported: B1,
clear_aca_supported: B1,
clear_task_set_supported: B1,
logical_unit_reset_supported: B1,
query_task_supported: B1,
obsolete: B2,
reserved_0: B5,
query_asynchronous_event_supported: B1,
query_task_set_supported: B1,
i_t_nexus_reset_supported: B1,
reserved_1: B8,
report_supported_task_management_functions_additional_data_length: B8,
reserved_2: B7,
task_management_function_timeouts_valid: B1,
reserved_3: B8,
abort_task_timeout_selector: B1,
abort_task_set_timeout_selector: B1,
clear_aca_timeout_selector: B1,
clear_task_set_timeout_selector: B1,
logical_unit_reset_timeout_selector: B1,
query_task_timeout_selector: B1,
reserved_4: B2,
reserved_5: B5,
query_asynchronous_event_timeout_selector: B1,
query_task_set_timeout_selector: B1,
i_t_nexus_reset_timeout_selector: B1,
task_management_functions_long_timeout: B32,
task_management_functions_short_timeout: B32,
}
struct ThisCommand {
command_buffer: CommandBuffer,
}
impl Command for ThisCommand {
type CommandBuffer = CommandBuffer;
type DataBuffer = ReportSupportedTaskManagementFunctionsExtendedParameterData;
type DataBufferWrapper = ReportSupportedTaskManagementFunctionsExtendedParameterData;
type ReturnType = crate::Result<CommandResult>;
fn direction(&self) -> DataDirection {
DataDirection::FromDevice
}
fn command(&self) -> Self::CommandBuffer {
self.command_buffer
}
fn data(&self) -> Self::DataBufferWrapper {
ReportSupportedTaskManagementFunctionsExtendedParameterData::new()
}
fn data_size(&self) -> u32 {
self.command_buffer.allocation_length()
}
fn process_result(&self, result: ResultData<Self::DataBufferWrapper>) -> Self::ReturnType {
result.check_ioctl_error()?;
result.check_common_error()?;
let data = result.data;
Ok(CommandResult {
abort_task_supported: data.abort_task_supported() != 0,
abort_task_set_supported: data.abort_task_set_supported() != 0,
clear_aca_supported: data.clear_aca_supported() != 0,
clear_task_set_supported: data.clear_task_set_supported() != 0,
logical_unit_reset_supported: data.logical_unit_reset_supported() != 0,
query_task_supported: data.query_task_supported() != 0,
query_asynchronous_event_supported: data.query_asynchronous_event_supported() != 0,
query_task_set_supported: data.query_task_set_supported() != 0,
i_t_nexus_reset_supported: data.i_t_nexus_reset_supported() != 0,
task_management_function_timeouts_valid: data.task_management_function_timeouts_valid()
!= 0,
abort_task_timeout_selector: data.abort_task_timeout_selector() != 0,
abort_task_set_timeout_selector: data.abort_task_set_timeout_selector() != 0,
clear_aca_timeout_selector: data.clear_aca_timeout_selector() != 0,
clear_task_set_timeout_selector: data.clear_task_set_timeout_selector() != 0,
logical_unit_reset_timeout_selector: data.logical_unit_reset_timeout_selector() != 0,
query_task_timeout_selector: data.query_task_timeout_selector() != 0,
query_asynchronous_event_timeout_selector: data
.query_asynchronous_event_timeout_selector()
!= 0,
query_task_set_timeout_selector: data.query_task_set_timeout_selector() != 0,
i_t_nexus_reset_timeout_selector: data.i_t_nexus_reset_timeout_selector() != 0,
task_management_functions_long_timeout: data.task_management_functions_long_timeout(),
task_management_functions_short_timeout: data.task_management_functions_short_timeout(),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::mem::size_of;
const COMMAND_LENGTH: usize = 12;
const PARAMETER_LENGTH: usize = 16;
#[test]
fn layout_test() {
assert_eq!(
size_of::<CommandBuffer>(),
COMMAND_LENGTH,
concat!("Size of: ", stringify!(CommandBuffer))
);
assert_eq!(
size_of::<ReportSupportedTaskManagementFunctionsExtendedParameterData>(),
PARAMETER_LENGTH,
concat!(
"Size of: ",
stringify!(ReportSupportedTaskManagementFunctionsExtendedParameterData)
)
);
}
}