From 1b15eb06c7f2687ee92cf90f1581c7044691d71f Mon Sep 17 00:00:00 2001 From: Brijesh Singh Date: Thu, 31 Aug 2017 10:25:27 -0400 Subject: OvmfPkg/VirtioScsiDxe: add helper to create a fake host adapter error When virtio request fails we return EFI_DEVICE_ERROR, as per the spec EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru() member function is required to implement elaborated error reporting. The patch refactors out entire block of the code that creates the host adapter error into a separate helper function (ReportHostAdapterError). Suggested-by: Laszlo Ersek Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh [lersek@redhat.com: fix style & typo in ReportHostAdapterError() comment] Reviewed-by: Laszlo Ersek Regression-tested-by: Laszlo Ersek Tested-by: Laszlo Ersek --- OvmfPkg/VirtioScsiDxe/VirtioScsi.c | 40 +++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'OvmfPkg/VirtioScsiDxe') diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c index 5e72b1a24b..5e5ad88e5e 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c @@ -97,7 +97,7 @@ // set some fields in the EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET in/out // parameter on return. The following is a full list of those fields, for // easier validation of PopulateRequest(), ParseResponse(), and -// VirtioScsiPassThru() below. +// ReportHostAdapterError() below. // // - InTransferLength // - OutTransferLength @@ -388,6 +388,37 @@ ParseResponse ( } +/** + + The function can be used to create a fake host adapter error. + + When VirtioScsiPassThru() is failed due to some reasons then this function + can be called to construct a host adapter error. + + @param[out] Packet The Extended SCSI Pass Thru Protocol packet that the host + adapter error shall be placed in. + + + @retval EFI_DEVICE_ERROR The function returns this status code + unconditionally, to be propagated by + VirtioScsiPassThru(). + +**/ +STATIC +EFI_STATUS +ReportHostAdapterError ( + OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet + ) +{ + Packet->InTransferLength = 0; + Packet->OutTransferLength = 0; + Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER; + Packet->TargetStatus = EFI_EXT_SCSI_STATUS_TARGET_GOOD; + Packet->SenseDataLength = 0; + return EFI_DEVICE_ERROR; +} + + // // The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL // for the virtio-scsi HBA. Refer to UEFI Spec 2.3.1 + Errata C, sections @@ -472,12 +503,7 @@ VirtioScsiPassThru ( // if (VirtioFlush (Dev->VirtIo, VIRTIO_SCSI_REQUEST_QUEUE, &Dev->Ring, &Indices, NULL) != EFI_SUCCESS) { - Packet->InTransferLength = 0; - Packet->OutTransferLength = 0; - Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER; - Packet->TargetStatus = EFI_EXT_SCSI_STATUS_TARGET_GOOD; - Packet->SenseDataLength = 0; - return EFI_DEVICE_ERROR; + return ReportHostAdapterError (Packet); } return ParseResponse (Packet, &Response); -- cgit v1.2.3