From nobody Tue Nov 26 08:23:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+56539+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56539+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1585425529; cv=none; d=zohomail.com; s=zohoarc; b=G63BZczj3FxXeMFBE/g3YUHRJMj/7e6/LvszGy2b6eBGS4xx62DuIpaFY2AFlZn7B7jyKu6m+hFn26snQE56mV8sqRFfEbM7d6M81+k6YZwWTKIhD5UIj8/VWw8G5QvV0uPM4BPUED0xvtoSqHnyBpziaeo96Gud32rk8uHSO9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585425529; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=4Vj8hcGcaa+LDS3RASDahORVNSt9jN8H5JwIVXBqQsA=; b=IrcJyEQrZE9e+hhqxAMnBr5Vi40e8VG8lZNlxzoUA2tnrLvjbZ6xXik5LqP5eaJpHcPqyB6AgnlNHXVk5adTNuDR4cB64qHKJILD9bUBhYe44j2U2UkbwKpch0Dcuk5/5jhKs2j6/7ZN0jk9pIU01WaIAPfhM5msBY9Vcx1WjD0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56539+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1585425529586624.7052752173778; Sat, 28 Mar 2020 12:58:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id KhhhYY1788612xBaunZOH8IJ; Sat, 28 Mar 2020 12:58:49 -0700 X-Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web10.14120.1585425528785011826 for ; Sat, 28 Mar 2020 12:58:48 -0700 X-Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02SJwmSb104274; Sat, 28 Mar 2020 19:58:48 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 301x0qsj8e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 28 Mar 2020 19:58:48 +0000 X-Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02SJoOk4071594; Sat, 28 Mar 2020 19:58:47 GMT X-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 301wwhmwh2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 28 Mar 2020 19:58:47 +0000 X-Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 02SJwkgv017068; Sat, 28 Mar 2020 19:58:46 GMT X-Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 28 Mar 2020 12:58:46 -0700 From: "Liran Alon" To: devel@edk2.groups.io, lersek@redhat.com Cc: nikita.leshchenko@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, ard.biesheuvel@linaro.org, Liran Alon Subject: [edk2-devel] [PATCH v3 06/17] OvmfPkg/PvScsiDxe: Report the number of targets and LUNs Date: Sat, 28 Mar 2020 23:00:49 +0300 Message-Id: <20200328200100.60786-7-liran.alon@oracle.com> In-Reply-To: <20200328200100.60786-1-liran.alon@oracle.com> References: <20200328200100.60786-1-liran.alon@oracle.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,liran.alon@oracle.com X-Gm-Message-State: 2YYsbwBZjaUZPifQ142cnChWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1585425529; bh=Qv4KMRjCf5372cEJ9wzeQrS+zMhJQ5y3BjUPiOCHcjQ=; h=Cc:Date:From:Reply-To:Subject:To; b=GBCEJo+YntQmjrNIUcNjdAsFobQv60DgXJ5iQd43QIA9tS5jXTJCJmqBmtHR4fOiYK4 0WJpUvUYM34KkjWZGF1zvrMEpZURbOfjfjE1Bzel+G+zUGavy8hND60AVc/LkeMIORgER 3SqFMqT13rrzam3KTSjFFwJ9mlJh1x9Z57A= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Implement EXT_SCSI_PASS_THRU.GetNextTarget() and EXT_SCSI_PASS_THRU.GetNextTargetLun(). ScsiBusDxe scans all MaxTarget * MaxLun possible devices. This can take unnecessarily long for large number of targets. To deal with this, VirtioScsiDxe has defined PCDs to limit the MaxTarget & MaxLun to desired values which gives sufficient performance. It is very important in virtio-scsi as it can have very big MaxTarget & MaxLun. Even though a common PVSCSI device has a default MaxTarget=3D64 and MaxLun=3D0, we implement similar mechanism as virtio-scsi for completeness. This may be useful in the future when PVSCSI will have bigger values for MaxTarget and MaxLun. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2567 Reviewed-by: Laszlo Ersek Signed-off-by: Liran Alon --- OvmfPkg/OvmfPkg.dec | 9 +++ OvmfPkg/PvScsiDxe/PvScsi.c | 122 +++++++++++++++++++++++++++++++- OvmfPkg/PvScsiDxe/PvScsi.h | 2 + OvmfPkg/PvScsiDxe/PvScsiDxe.inf | 5 ++ 4 files changed, 136 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 4c5b6511cb97..a04aee5c2cd4 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -121,6 +121,15 @@ gUefiOvmfPkgTokenSpaceGuid.PcdVirtioScsiMaxTargetLimit|31|UINT16|6 gUefiOvmfPkgTokenSpaceGuid.PcdVirtioScsiMaxLunLimit|7|UINT32|7 =20 + ## Sets the *inclusive* number of targets and LUNs that PvScsi exposes f= or + # scan by ScsiBusDxe. + # As specified above for VirtioScsi, ScsiBusDxe scans all MaxTarget * M= axLun + # possible devices, which can take extremely long. Thus, the below cons= tants + # are used so that scanning the number of devices given by their product + # is still acceptably fast. + gUefiOvmfPkgTokenSpaceGuid.PcdPvScsiMaxTargetLimit|64|UINT8|0x36 + gUefiOvmfPkgTokenSpaceGuid.PcdPvScsiMaxLunLimit|0|UINT8|0x37 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogBase|0x0|UINT32|= 0x8 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogSize|0x0|UINT32|= 0x9 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize|0x0|UINT32|0xa diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c index 04c08036b799..7f51ada19a1a 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.c +++ b/OvmfPkg/PvScsiDxe/PvScsi.c @@ -11,6 +11,7 @@ =20 #include #include +#include #include #include #include @@ -25,6 +26,30 @@ // #define PVSCSI_BINDING_VERSION 0x10 =20 +// +// Ext SCSI Pass Thru utilities +// + +/** + Check if Target argument to EXT_SCSI_PASS_THRU.GetNextTarget() and + EXT_SCSI_PASS_THRU.GetNextTargetLun() is initialized +**/ +STATIC +BOOLEAN +IsTargetInitialized ( + IN UINT8 *Target + ) +{ + UINTN Idx; + + for (Idx =3D 0; Idx < TARGET_MAX_BYTES; ++Idx) { + if (Target[Idx] !=3D 0xFF) { + return TRUE; + } + } + return FALSE; +} + // // Ext SCSI Pass Thru // @@ -52,7 +77,54 @@ PvScsiGetNextTargetLun ( IN OUT UINT64 *Lun ) { - return EFI_UNSUPPORTED; + UINT8 *TargetPtr; + UINT8 LastTarget; + PVSCSI_DEV *Dev; + + if (Target =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // The Target input parameter is unnecessarily a pointer-to-pointer + // + TargetPtr =3D *Target; + + // + // If target not initialized, return first target & LUN + // + if (!IsTargetInitialized (TargetPtr)) { + ZeroMem (TargetPtr, TARGET_MAX_BYTES); + *Lun =3D 0; + return EFI_SUCCESS; + } + + // + // We only use first byte of target identifer + // + LastTarget =3D *TargetPtr; + + // + // Increment (target, LUN) pair if valid on input + // + Dev =3D PVSCSI_FROM_PASS_THRU (This); + if (LastTarget > Dev->MaxTarget || *Lun > Dev->MaxLun) { + return EFI_INVALID_PARAMETER; + } + + if (*Lun < Dev->MaxLun) { + ++*Lun; + return EFI_SUCCESS; + } + + if (LastTarget < Dev->MaxTarget) { + *Lun =3D 0; + ++LastTarget; + *TargetPtr =3D LastTarget; + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; } =20 STATIC @@ -111,7 +183,47 @@ PvScsiGetNextTarget ( IN OUT UINT8 **Target ) { - return EFI_UNSUPPORTED; + UINT8 *TargetPtr; + UINT8 LastTarget; + PVSCSI_DEV *Dev; + + if (Target =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // The Target input parameter is unnecessarily a pointer-to-pointer + // + TargetPtr =3D *Target; + + // + // If target not initialized, return first target + // + if (!IsTargetInitialized (TargetPtr)) { + ZeroMem (TargetPtr, TARGET_MAX_BYTES); + return EFI_SUCCESS; + } + + // + // We only use first byte of target identifer + // + LastTarget =3D *TargetPtr; + + // + // Increment target if valid on input + // + Dev =3D PVSCSI_FROM_PASS_THRU (This); + if (LastTarget > Dev->MaxTarget) { + return EFI_INVALID_PARAMETER; + } + + if (LastTarget < Dev->MaxTarget) { + ++LastTarget; + *TargetPtr =3D LastTarget; + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; } =20 STATIC @@ -120,6 +232,12 @@ PvScsiInit ( IN OUT PVSCSI_DEV *Dev ) { + // + // Init configuration + // + Dev->MaxTarget =3D PcdGet8 (PcdPvScsiMaxTargetLimit); + Dev->MaxLun =3D PcdGet8 (PcdPvScsiMaxLunLimit); + // // Populate the exported interface's attributes // diff --git a/OvmfPkg/PvScsiDxe/PvScsi.h b/OvmfPkg/PvScsiDxe/PvScsi.h index 3940b4c20019..dd3e0c68e6da 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.h +++ b/OvmfPkg/PvScsiDxe/PvScsi.h @@ -19,6 +19,8 @@ =20 typedef struct { UINT32 Signature; + UINT8 MaxTarget; + UINT8 MaxLun; EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; } PVSCSI_DEV; diff --git a/OvmfPkg/PvScsiDxe/PvScsiDxe.inf b/OvmfPkg/PvScsiDxe/PvScsiDxe.= inf index f4d452c6c3d2..fcffc90d46c8 100644 --- a/OvmfPkg/PvScsiDxe/PvScsiDxe.inf +++ b/OvmfPkg/PvScsiDxe/PvScsiDxe.inf @@ -26,6 +26,7 @@ OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] + BaseMemoryLib DebugLib MemoryAllocationLib UefiBootServicesTableLib @@ -35,3 +36,7 @@ [Protocols] gEfiExtScsiPassThruProtocolGuid ## BY_START gEfiPciIoProtocolGuid ## TO_START + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdPvScsiMaxLunLimit ## CONSUMES + gUefiOvmfPkgTokenSpaceGuid.PcdPvScsiMaxTargetLimit ## CONSUMES --=20 2.20.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#56539): https://edk2.groups.io/g/devel/message/56539 Mute This Topic: https://groups.io/mt/72617130/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-