1use bitfield_struct::bitfield;
11use open_enum::open_enum;
12use zerocopy::FromBytes;
13use zerocopy::Immutable;
14use zerocopy::IntoBytes;
15use zerocopy::KnownLayout;
16
17#[bitfield(u8)]
18#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
19#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
20pub struct SrbStatusAndFlags {
21 #[bits(6)]
22 status_bits: u8,
23 pub frozen: bool,
24 pub autosense_valid: bool,
25}
26
27impl SrbStatusAndFlags {
28 pub fn status(&self) -> SrbStatus {
29 SrbStatus(self.status_bits())
30 }
31
32 pub fn with_status(self, status: SrbStatus) -> Self {
33 self.with_status_bits(status.0)
34 }
35
36 pub fn set_status(&mut self, status: SrbStatus) {
37 self.set_status_bits(status.0)
38 }
39}
40
41open_enum! {
42 #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
43 pub enum SrbStatus: u8 {
44 PENDING = 0x00,
45 SUCCESS = 0x01,
46 ABORTED = 0x02,
47 ABORT_FAILED = 0x03,
48 ERROR = 0x04,
49 BUSY = 0x05,
50 INVALID_REQUEST = 0x06,
51 INVALID_PATH_ID = 0x07,
52 NO_DEVICE = 0x08,
53 TIMEOUT = 0x09,
54 SELECTION_TIMEOUT = 0x0A,
55 COMMAND_TIMEOUT = 0x0B,
56 MESSAGE_REJECTED = 0x0D,
57 BUS_RESET = 0x0E,
58 PARITY_ERROR = 0x0F,
59 REQUEST_SENSE_FAILED = 0x10,
60 NO_HBA = 0x11,
61 DATA_OVERRUN = 0x12,
62 UNEXPECTED_BUS_FREE = 0x13,
63 PHASE_SEQUENCE_FAILURE = 0x14,
64 BAD_SRB_BLOCK_LENGTH = 0x15,
65 REQUEST_FLUSHED = 0x16,
66 INVALID_LUN = 0x20,
67 INVALID_TARGET_ID = 0x21,
68 BAD_FUNCTION = 0x22,
69 ERROR_RECOVERY = 0x23,
70 NOT_POWERED = 0x24,
71 LINK_DOWN = 0x25,
72 }
73}
74
75pub const SRB_FLAGS_DATA_IN: u32 = 0x00000040;
76pub const SRB_FLAGS_DATA_OUT: u32 = 0x00000080;