Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SCSI Protocol support #1155

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

add SCSI Protocol support #1155

wants to merge 12 commits into from

Conversation

sky5454
Copy link
Contributor

@sky5454 sky5454 commented May 1, 2024

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

Only preliminary support.
some problem I faced:

  • the buffer of I/O data. maybe the best way is to wrap by Reader/Writer trait
    • uefi-raw/src/protocol/scsi.rs: ScsiIoProtocol::execute_scsi_command()
    • uefi/src/proto/scsi.rs: ExtScsiPassThru::pass_thru()
    • wrap and make the ScsiIoScsiRequestPacket/ExtScsiIoScsiRequestPacket to be conveniently used in Rust
  • The dev path which using the Device Path Protocol
  • TARGET_MAX_BYTES unused, for: The Target is an array of size TARGET_MAX_BYTES and it represents the id of the SCSI device to send the SCSI Request Packet.
  • The naming rule of enum.
  • The data sync with c and rust ffi, vec <-> c data ptr and len.
#[derive(Debug)]
#[repr(C)]
pub struct ScsiIoScsiRequestPacket {
    pub timeout: u64,

  /// DataBuffer: A pointer to the data buffer to transfer from or to the SCSI device.
  ///  - InDataBuffer: A pointer to the data buffer to transfer between the SCSI controller and the SCSI device for SCSI READ command. For all SCSI WRITE Commands this must point to NULL .
  ///  - OutDataBuffer: A pointer to the data buffer to transfer between the SCSI controller and the SCSI device for SCSI WRITE command. For all SCSI READ commands this field must point to NULL .
    


    pub in_data_buffer: *mut c_void,
    pub out_data_buffer: *mut c_void,
    pub sense_data: *mut c_void,
    pub cdb: *mut c_void,

    pub in_transfer_length: u32,
    pub out_transfer_length: u32,

    pub cdb_length: u8,
    pub data_direction: DataDirection,
    pub host_adapter_status: HostAdapterStatus,
    pub target_status: TargetStatus,
    pub sense_data_length: u8,
}

#[derive(Debug)]
#[repr(C)]
pub struct ExtScsiIoScsiRequestPacket {
    pub timeout: u64,

    pub in_data_buffer: *mut c_void,
    pub out_data_buffer: *mut c_void,
    pub sense_data: *mut c_void,
    pub cdb: *mut c_void,

    pub in_transfer_length: u32,
    pub out_transfer_length: u32,

    pub cdb_length: u8,
    pub data_direction: ExtDataDirection,
    pub host_adapter_status: ExtHostAdapterStatus,
    pub target_status: ExtTargetStatus,
    pub sense_data_length: u8,
}

After read "SPC" which docs from T10 (SCSI Standard Groups), I Know that in_data_buffer,out_data_buffer,sense_data,cdb have variable length. so I decide to make a struct like

    pub timeout: u64,
    /// data_buffer is in_data_buffer or out_data_buffer
    pub data_buffer: Vec<u8>
    pub cdb: Vec<u8>
    pub sense_data: Vec<u8>
    pub data_direction: ExtDataDirection,
    pub host_adapter_status: ExtHostAdapterStatus,
    pub target_status: ExtTargetStatus,

but data couldn't share between FFI and c. That's a problem. We should share those data by ptr.

according to uefi scsi usage from edk2:

…w `execute_scsi_command` send req packet is ok.

**PASSED**:
 - SCSI_IO all api, SCSI_THRU `mode()` and `reset()` api, are test passed.
**PROBLEM**:
 1. panic at allocator.rs while test_scsi_io return;
 2. still problem with `DevicePath`,`target_id`,`pass_thru`;
**UNKNOWN**:
 - scsi req ok but resp without test at `execute_scsi_command()`.
@sky5454
Copy link
Contributor Author

sky5454 commented May 5, 2024

SCSI_IO

The main part of SCSI_IO is finished. though something need some optimization.

  • data_buf maybe need in and out at the sametime.?
  • resp no test still.

Running at VMWare with two SCSI sample TestUnitReady and InquiryCommand:
image

EXT_SCSI_THRU

only test mode() and reset() passed.
some trouble.

  • DevicePath/DevicePathProtocol
  • Target ids
  • the packet sample about scsi thru. I couldn't find it clearly.

image

@sky5454 sky5454 marked this pull request as ready for review May 11, 2024 03:04
@sky5454
Copy link
Contributor Author

sky5454 commented May 11, 2024

  • Now UEFI SCSI I/O protocol is ready.
  • And UEFI Scsi Thru I/O protocol Will not be published in this PR. I would continue to code it at branch sky5454:dev-scsi

image

after you review the code and resolve the panic, you could merge it.

@nicholasbishop
Copy link
Contributor

Before I review fully, it would help to do some cleanup:

  • Fix CI errors (run formatting, fix lints, etc)
  • Remove all unused code
  • Resolve TODOs if possible

This will make review easier :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants