[edk2-devel] [PATCH v4 12/13] OvmfPkg/MptScsiDxe: Report multiple targets

Nikita Leshenko nikita.leshchenko at oracle.com
Tue Apr 14 17:38:12 UTC 2020


The controller supports up to 8 targets (Not reported by the
controller, but based on the implementation of the virtual device),
report them in GetNextTarget and GetNextTargetLun. The firmware will
then try to communicate with them and create a block device for each
one that responds.

Support for multiple LUNs will be implemented in another series.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Signed-off-by: Nikita Leshenko <nikita.leshchenko at oracle.com>
Reviewed-by: Liran Alon <liran.alon at oracle.com>
---
 OvmfPkg/MptScsiDxe/MptScsi.c      | 38 ++++++++++++++++++++++++-------
 OvmfPkg/MptScsiDxe/MptScsiDxe.inf |  1 +
 OvmfPkg/OvmfPkg.dec               |  4 ++++
 3 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index fcdaa4c338a4..3ea08857df5d 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -46,6 +46,7 @@ typedef struct {
   EFI_PCI_IO_PROTOCOL             *PciIo;
   UINT64                          OriginalPciAttributes;
   UINT32                          StallPerPollUsec;
+  UINT8                           MaxTarget;
   MPT_SCSI_DMA_BUFFER             *Dma;
   EFI_PHYSICAL_ADDRESS            DmaPhysical;
   VOID                            *DmaMapping;
@@ -159,6 +160,7 @@ MptScsiInit (
   UINT32                         ReplyWord;
 
   Dev->StallPerPollUsec = PcdGet32 (PcdMptScsiStallPerPollUsec);
+  Dev->MaxTarget = PcdGet8 (PcdMptScsiMaxTargetLimit);
 
   Status = MptScsiReset (Dev);
   if (EFI_ERROR (Status)) {
@@ -169,7 +171,7 @@ MptScsiInit (
   ZeroMem (&Reply, sizeof (Reply));
   Req.Data.WhoInit = MPT_IOC_WHOINIT_ROM_BIOS;
   Req.Data.Function = MPT_MESSAGE_HDR_FUNCTION_IOC_INIT;
-  Req.Data.MaxDevices = 1;
+  Req.Data.MaxDevices = Dev->MaxTarget + 1;
   Req.Data.MaxBuses = 1;
   Req.Data.ReplyFrameSize = sizeof (MPT_SCSI_IO_REPLY);
 
@@ -240,7 +242,7 @@ MptScsiPopulateRequest (
     return EFI_UNSUPPORTED;
   }
 
-  if (Target > 0 || Lun > 0 ||
+  if (Target > Dev->MaxTarget || Lun > 0 ||
       Packet->DataDirection > EFI_EXT_SCSI_DATA_DIRECTION_BIDIRECTIONAL ||
       //
       // Trying to receive, but destination pointer is NULL, or contradicting
@@ -552,12 +554,22 @@ MptScsiGetNextTargetLun (
   IN OUT UINT64                                     *Lun
   )
 {
+  MPT_SCSI_DEV *Dev;
+
+  Dev = MPT_SCSI_FROM_PASS_THRU (This);
   //
-  // Currently support only target 0 LUN 0, so hardcode it
+  // Currently support only LUN 0, so hardcode it
   //
   if (!IsTargetInitialized (*Target)) {
     ZeroMem (*Target, TARGET_MAX_BYTES);
     *Lun = 0;
+  } else if (**Target < Dev->MaxTarget) {
+    //
+    // This device support 256 targets only, so it's enough to increment
+    // the LSB of Target, as it will never overflow.
+    //
+    **Target += 1;
+    *Lun = 0;
   } else {
     return EFI_NOT_FOUND;
   }
@@ -573,11 +585,17 @@ MptScsiGetNextTarget (
   IN OUT UINT8                                     **Target
   )
 {
-  //
-  // Currently support only target 0 LUN 0, so hardcode it
-  //
+  MPT_SCSI_DEV *Dev;
+
+  Dev = MPT_SCSI_FROM_PASS_THRU (This);
   if (!IsTargetInitialized (*Target)) {
     ZeroMem (*Target, TARGET_MAX_BYTES);
+  } else if (**Target < Dev->MaxTarget) {
+    //
+    // This device support 256 targets only, so it's enough to increment
+    // the LSB of Target, as it will never overflow.
+    //
+    **Target += 1;
   } else {
     return EFI_NOT_FOUND;
   }
@@ -595,6 +613,7 @@ MptScsiBuildDevicePath (
   IN OUT EFI_DEVICE_PATH_PROTOCOL                  **DevicePath
   )
 {
+  MPT_SCSI_DEV     *Dev;
   SCSI_DEVICE_PATH *ScsiDevicePath;
 
   if (DevicePath == NULL) {
@@ -605,7 +624,8 @@ MptScsiBuildDevicePath (
   // This device support 256 targets only, so it's enough to dereference
   // the LSB of Target.
   //
-  if (*Target > 0 || Lun > 0) {
+  Dev = MPT_SCSI_FROM_PASS_THRU (This);
+  if (*Target > Dev->MaxTarget || Lun > 0) {
     return EFI_NOT_FOUND;
   }
 
@@ -635,6 +655,7 @@ MptScsiGetTargetLun (
   OUT UINT64                                       *Lun
   )
 {
+  MPT_SCSI_DEV     *Dev;
   SCSI_DEVICE_PATH *ScsiDevicePath;
 
   if (DevicePath == NULL ||
@@ -647,8 +668,9 @@ MptScsiGetTargetLun (
     return EFI_UNSUPPORTED;
   }
 
+  Dev = MPT_SCSI_FROM_PASS_THRU (This);
   ScsiDevicePath = (SCSI_DEVICE_PATH *)DevicePath;
-  if (ScsiDevicePath->Pun > 0 ||
+  if (ScsiDevicePath->Pun > Dev->MaxTarget ||
       ScsiDevicePath->Lun > 0) {
     return EFI_NOT_FOUND;
   }
diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
index ef1f6a5ebb3a..26aca7f95315 100644
--- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
+++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf
@@ -37,3 +37,4 @@ [Protocols]
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiStallPerPollUsec ## CONSUMES
+  gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiMaxTargetLimit ## CONSUMES
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 7fa1581f2101..7b56998abc9b 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -273,6 +273,10 @@ [PcdsFixedAtBuild]
   ## Microseconds to stall between polling for MptScsi request result
   gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiStallPerPollUsec|5|UINT32|0x39
 
+  ## Set the *inclusive* number of targets that MptScsi exposes for scan
+  #  by ScsiBusDxe.
+  gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiMaxTargetLimit|7|UINT8|0x40
+
 [PcdsDynamic, PcdsDynamicEx]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
-- 
2.20.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57371): https://edk2.groups.io/g/devel/message/57371
Mute This Topic: https://groups.io/mt/73015393/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list