uefi_raw/protocol/
scsi.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3use crate::{guid, Event, Guid, Status};
4use core::ffi::c_void;
5
6newtype_enum! {
7    /// Corresponds to the `EFI_SCSI_IO_TYPE_*` defines.
8    #[derive(Default)]
9    pub enum ScsiIoType: u8  => {
10        DISK = 0x00,
11        TAPE = 0x01,
12        PRINTER = 0x02,
13        PROCESSOR = 0x03,
14        WRITE_ONCE_READ_MULTIPLE = 0x04,
15        CDROM = 0x05,
16        SCANNER = 0x06,
17        OPTICAL = 0x07,
18        MEDIUM_CHANGER = 0x08,
19        COMMUNICATION = 0x09,
20        RAID = 0x0c,
21        ENCLOSURE_SERVICES = 0x0d,
22        REDUCED_BLOCK_COMMANDS = 0x0e,
23        OPTICAL_CARD_READER_WRITER = 0x0f,
24        BRIDGE_CONTROLLER = 0x10,
25        OBJECT_BASED_STORAGE = 0x11,
26        RESERVED_LOW = 0x12,
27        RESERVED_HIGH = 0x1e,
28        UNKNOWN = 0x1f,
29    }
30}
31
32newtype_enum! {
33    /// Corresponds to the `EFI_SCSI_IO_DATA_DIRECTION_*` defines.
34    #[derive(Default)]
35    pub enum ScsiIoDataDirection: u8 => {
36        READ = 0,
37        WRITE = 1,
38        BIDIRECTIONAL = 2,
39    }
40}
41
42newtype_enum! {
43    /// Corresponds to the `EFI_SCSI_IO_STATUS_HOST_ADAPTER_*` defines.
44    #[derive(Default)]
45    pub enum ScsiIoHostAdapterStatus: u8 => {
46       OK = 0x00,
47       TIMEOUT_COMMAND = 0x09,
48       TIMEOUT = 0x0b,
49       MESSAGE_REJECT = 0x0d,
50       BUS_RESET = 0x0e,
51       PARITY_ERROR = 0x0f,
52       REQUEST_SENSE_FAILED = 0x10,
53       SELECTION_TIMEOUT = 0x11,
54       DATA_OVERRUN_UNDERRUN = 0x12,
55       BUS_FREE = 0x13,
56       PHASE_ERROR = 0x14,
57       OTHER = 0x7f,
58    }
59}
60
61newtype_enum! {
62    /// Corresponds to the `EFI_SCSI_IO_STATUS_TARGET_*` defines.
63    #[derive(Default)]
64    pub enum ScsiIoTargetStatus: u8 => {
65        GOOD = 0x00,
66        CHECK_CONDITION = 0x02,
67        CONDITION_MET = 0x04,
68        BUSY = 0x08,
69        INTERMEDIATE = 0x10,
70        INTERMEDIATE_CONDITION_MET = 0x14,
71        RESERVATION_CONFLICT = 0x18,
72        COMMAND_TERMINATED = 0x22,
73        QUEUE_FULL = 0x28,
74    }
75}
76
77#[derive(Debug, Copy, Clone)]
78#[repr(C)]
79pub struct ScsiIoScsiRequestPacket {
80    pub timeout: u64,
81    pub in_data_buffer: *mut c_void,
82    pub out_data_buffer: *mut c_void,
83    pub sense_data: *mut c_void,
84    pub cdb: *mut c_void,
85    pub in_transfer_length: u32,
86    pub out_transfer_length: u32,
87    pub cdb_length: u8,
88    pub data_direction: ScsiIoDataDirection,
89    pub host_adapter_status: ScsiIoHostAdapterStatus,
90    pub target_status: ScsiIoTargetStatus,
91    pub sense_data_length: u8,
92}
93
94#[derive(Debug)]
95#[repr(C)]
96pub struct ScsiIoProtocol {
97    pub get_device_type:
98        unsafe extern "efiapi" fn(this: *const Self, device_type: *mut ScsiIoType) -> Status,
99    pub get_device_location:
100        unsafe extern "efiapi" fn(this: *const Self, target: *mut *mut u8, lun: *mut u64) -> Status,
101    pub reset_bus: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
102    pub reset_device: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
103    pub execute_scsi_command: unsafe extern "efiapi" fn(
104        this: *const Self,
105        packet: *mut ScsiIoScsiRequestPacket,
106        event: Event,
107    ) -> Status,
108    pub io_align: u32,
109}
110
111impl ScsiIoProtocol {
112    pub const GUID: Guid = guid!("932f47e6-2362-4002-803e-3cd54b138f85");
113}