scsi_defs/
srb.rs

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