]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioScsiDxe: add helper to create a fake host adapter error
authorBrijesh Singh <brijesh.singh@amd.com>
Thu, 31 Aug 2017 14:25:27 +0000 (10:25 -0400)
committerLaszlo Ersek <lersek@redhat.com>
Thu, 31 Aug 2017 19:01:31 +0000 (21:01 +0200)
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 <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
[lersek@redhat.com: fix style & typo in ReportHostAdapterError() comment]
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/VirtioScsiDxe/VirtioScsi.c

index 5e72b1a24b591958a2bf5ea12ba48d04e0f5a91c..5e5ad88e5e52d55a2cc4eed9e93b3234080c0c4d 100644 (file)
@@ -97,7 +97,7 @@
 // set some fields in the EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET in/out\r
 // parameter on return. The following is a full list of those fields, for\r
 // easier validation of PopulateRequest(), ParseResponse(), and\r
-// VirtioScsiPassThru() below.\r
+// ReportHostAdapterError() below.\r
 //\r
 // - InTransferLength\r
 // - OutTransferLength\r
@@ -388,6 +388,37 @@ ParseResponse (
 }\r
 \r
 \r
+/**\r
+\r
+  The function can be used to create a fake host adapter error.\r
+\r
+  When VirtioScsiPassThru() is failed due to some reasons then this function\r
+  can be called to construct a host adapter error.\r
+\r
+  @param[out] Packet  The Extended SCSI Pass Thru Protocol packet that the host\r
+                      adapter error shall be placed in.\r
+\r
+\r
+  @retval EFI_DEVICE_ERROR  The function returns this status code\r
+                            unconditionally, to be propagated by\r
+                            VirtioScsiPassThru().\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+ReportHostAdapterError (\r
+  OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET  *Packet\r
+  )\r
+{\r
+  Packet->InTransferLength  = 0;\r
+  Packet->OutTransferLength = 0;\r
+  Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER;\r
+  Packet->TargetStatus      = EFI_EXT_SCSI_STATUS_TARGET_GOOD;\r
+  Packet->SenseDataLength   = 0;\r
+  return EFI_DEVICE_ERROR;\r
+}\r
+\r
+\r
 //\r
 // The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL\r
 // for the virtio-scsi HBA. Refer to UEFI Spec 2.3.1 + Errata C, sections\r
@@ -472,12 +503,7 @@ VirtioScsiPassThru (
   //\r
   if (VirtioFlush (Dev->VirtIo, VIRTIO_SCSI_REQUEST_QUEUE, &Dev->Ring,\r
         &Indices, NULL) != EFI_SUCCESS) {\r
-    Packet->InTransferLength  = 0;\r
-    Packet->OutTransferLength = 0;\r
-    Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER;\r
-    Packet->TargetStatus      = EFI_EXT_SCSI_STATUS_TARGET_GOOD;\r
-    Packet->SenseDataLength   = 0;\r
-    return EFI_DEVICE_ERROR;\r
+    return ReportHostAdapterError (Packet);\r
   }\r
 \r
   return ParseResponse (Packet, &Response);\r