From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [51.163.158.102]) by mx.groups.io with SMTP id smtpd.web10.10748.1594885601862393413 for ; Thu, 16 Jul 2020 00:46:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=MJ3BrH7k; spf=pass (domain: suse.com, ip: 51.163.158.102, mailfrom: glin@suse.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1594885600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KlILA3hQLQCpYvQnIal/iSU0/pEsU9nfydqB2EQDfj4=; b=MJ3BrH7k4VvNOu3LVdLLTKFJkfxPH/1mbAdLIASyI0/+NI7IbF0gbYJBBw2iZrDaMtnENW H/vjQHUb/CjXO4+1A2KIWlIyfLzaNceV7zNVEwPpOJshW+HbD8jQV5uxJQGW6EIvyRNfzp 72IZ30YE1kEIMqtoV3SLDvQk8IsY5rs= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2054.outbound.protection.outlook.com [104.47.9.54]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-7-1pu9P3tiMX6qXmhjKeEtBg-2; Thu, 16 Jul 2020 09:46:38 +0200 X-MC-Unique: 1pu9P3tiMX6qXmhjKeEtBg-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zxpy3xkc6zFo/qZ74pq4dfTOKPTUYad5i9QhFUyBjKs2fqvfONOPPbPhlCCuEjQjzBSxNY6ItR2m4s8sPL/a4LjVseKmJMeGhe6RO1FHBdx8cZsTIduOoBBU72HVyPgg8YjaGeMCzpXTjlCpq9Zi7bgWF7sxqOo7bZW2GTSxmUcdtqRLk8eRsB4/0ibJj0Nfd+WXPA0Ct9iv5GVQ8PBmUQj1QWwCVC0OeWTKZHmGHJ161in0mnsxarCg7VojcD5qEpEtZBMiTvHMpT0oyNNUHFj4HWmRBPz4aV++NYdtHKXbzkcQoCEfEnABjOp1z7cW3FkPba7wRjun3VSaMNMDSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KlILA3hQLQCpYvQnIal/iSU0/pEsU9nfydqB2EQDfj4=; b=cjLH+paxrHcqHHsgzIEaPtfPXCf8Y/eFd9moDPuy0kFAGsw5diSI7XFEqMdRfNcl7JmmIHadx/FmdTNix68DTdYtlxlKELyzotAlJA7bFjwqTcUE3Us8xIEPdVdmE2mHSoz/Agvp8HxMqiKCvzAEFNQ2YRZs9LAwJ6ig2nVg9+DyI07IxIZ0q9L8QfQWXkYCc+UcoE98StbBpXgq0Gqev6nS7ip5IeZl5XtLWnVZQd5sZRHWHlkPot0t4ghQOAkomZ3PQBUtn8Yz1or65m/g0r/GfwfKot/yMKBpIM6pMcbXpQkQuiFJ30IVYz7RvLTsz+I17T1TNtO0PB6KYJOeww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=suse.com; Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com (2603:10a6:208:10::30) by AM0PR04MB5122.eurprd04.prod.outlook.com (2603:10a6:208:ca::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.25; Thu, 16 Jul 2020 07:46:38 +0000 Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::a14c:d441:c8a9:77ba]) by AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::a14c:d441:c8a9:77ba%6]) with mapi id 15.20.3174.026; Thu, 16 Jul 2020 07:46:38 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH v2 06/12] OvmfPkg/LsiScsiDxe: Report Targets and LUNs Date: Thu, 16 Jul 2020 15:46:01 +0800 Message-Id: <20200716074607.18048-7-glin@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200716074607.18048-1-glin@suse.com> References: <20200716074607.18048-1-glin@suse.com> X-ClientProxiedBy: AM3PR07CA0118.eurprd07.prod.outlook.com (2603:10a6:207:7::28) To AM0PR0402MB3809.eurprd04.prod.outlook.com (2603:10a6:208:10::30) Return-Path: glin@suse.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryWorkstation.suse.cz (60.251.47.115) by AM3PR07CA0118.eurprd07.prod.outlook.com (2603:10a6:207:7::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Thu, 16 Jul 2020 07:46:36 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [60.251.47.115] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 32440ab1-bbf4-4107-d9d0-08d8295c5ed7 X-MS-TrafficTypeDiagnostic: AM0PR04MB5122: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:913; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NPN6FykMILrZtPk8DV5SIbLWYRvDP/+52DNAIP/hBBF9VdetJPHg1+AmkbuEdRyrOVfGRuzzBG08uiuF9kyfdU2j2usn29kAxz4YzrizCwK5KqicAm9aiPNxdxsJn3auU7MNavUlRLIgHjwM6LYHng5xtB3y6gSCCJHsh+we43VncUem9EcSunUmVbrtURBUsTn7a0es90Cp9YQPTPmv5YF4RV5Y2uqJzzp5sdxBonLnuAyq1PhvBkZwWVvq56afmfR+MzZf4OjAWE6QN9kKCtVMaN/d5HQr0q9MMdFBDTF4Zd++zKa3knWrMu0zBzwsDOR5BfjBhx++oCuNOsEGCQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR0402MB3809.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(376002)(396003)(366004)(39860400002)(346002)(136003)(55236004)(6506007)(4326008)(8936002)(6512007)(86362001)(83380400001)(8676002)(6486002)(1076003)(52116002)(6916009)(36756003)(66946007)(66556008)(956004)(478600001)(5660300002)(6666004)(26005)(2616005)(316002)(54906003)(66476007)(16526019)(2906002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: lstgB6x0QhMw6ETyJMzPHmODvvx7RXaYcotqhJPnUVQSVHJ0B/YB2PwKWJS3i1X/yhtLavQ71ZwT3u3bYEIAJ7nB5wPUZy/QoP7cZLL+9bryIbpvB3j6VHiqhl9AAV3h3y9J8E5UfWkZQ+FwEe2QM5r5ILqeXp5sbYes6vZaEywEwy1SCx/NduFo15NHJza/fkBjT27qe2q2c+n11eiZRIBE2knyMvxKP+7eqZwVG/ryJdSxI49Lp8HcfpRQTXzKNuK/AOlxcz3bWrXa9VXuflCHvlB3mLOxxKgBKZPsDfvpWsHdxU4lyohTMAU+14x4KhvPD23iovwM7tX92KwmIoeZwiLk4a6NFh5W1V9suKNKRWGt6ZCwiSTsSJdqsBsJmGSk5ITYjyUB2/qRuoNLEvlAc11w9xvMySDad1AH9bR0XIN3p5gBrxZQbHs7HtNxTqisEE/ZkHFuRMO6WLLkuI4AXz4W4droQXuaHFUbhJk= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32440ab1-bbf4-4107-d9d0-08d8295c5ed7 X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3809.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2020 07:46:38.0817 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Jn0V2i5xnryzzi+cFQVF1nQWhPh3IVlCrZxGBfJErfXvwTXfaqJbeHOIpsYBeApK X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5122 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Implement LsiScsiGetNextTargetLun(), LsiScsiBuildDevicePath(), LsiScsiGetTargetLun(), and LsiScsiGetNextTarget() to report Targets and LUNs and build the device path. This commit also introduces two PCD value: PcdLsiScsiMaxTargetLimit and PcdLsiScsiMaxLunLimit as the limits for Targets and LUNs. v2: - Zero out (*Target) in LsiScsiGetTargetLun() - Use CopyMem() instead of the one-byte shortcut to copy target from ScsiDevicePath->Pun - Add asserts for PcdLsiScsiMaxTargetLimit and PcdLsiScsiMaxLunLimit Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin --- OvmfPkg/LsiScsiDxe/LsiScsi.c | 148 +++++++++++++++++++++++++++++- OvmfPkg/LsiScsiDxe/LsiScsi.h | 3 + OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf | 6 ++ OvmfPkg/OvmfPkg.dec | 5 + 4 files changed, 160 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c index 67fadb411e85..989bda88d209 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c @@ -15,6 +15,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -53,6 +54,49 @@ LsiScsiGetNextTargetLun ( IN OUT UINT64 *Lun=0D )=0D {=0D + LSI_SCSI_DEV *Dev;=0D + UINTN Idx;=0D + UINT8 *Target;=0D + UINT16 LastTarget;=0D +=0D + //=0D + // the TargetPointer input parameter is unnecessarily a pointer-to-point= er=0D + //=0D + Target =3D *TargetPointer;=0D +=0D + //=0D + // Search for first non-0xFF byte. If not found, return first target & L= UN.=0D + //=0D + for (Idx =3D 0; Idx < TARGET_MAX_BYTES && Target[Idx] =3D=3D 0xFF; ++Idx= )=0D + ;=0D + if (Idx =3D=3D TARGET_MAX_BYTES) {=0D + SetMem (Target, TARGET_MAX_BYTES, 0x00);=0D + *Lun =3D 0;=0D + return EFI_SUCCESS;=0D + }=0D +=0D + CopyMem (&LastTarget, Target, sizeof LastTarget);=0D +=0D + //=0D + // increment (target, LUN) pair if valid on input=0D + //=0D + Dev =3D LSI_SCSI_FROM_PASS_THRU (This);=0D + if (LastTarget > Dev->MaxTarget || *Lun > Dev->MaxLun) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (*Lun < Dev->MaxLun) {=0D + ++*Lun;=0D + return EFI_SUCCESS;=0D + }=0D +=0D + if (LastTarget < Dev->MaxTarget) {=0D + *Lun =3D 0;=0D + ++LastTarget;=0D + CopyMem (Target, &LastTarget, sizeof LastTarget);=0D + return EFI_SUCCESS;=0D + }=0D +=0D return EFI_NOT_FOUND;=0D }=0D =0D @@ -65,7 +109,34 @@ LsiScsiBuildDevicePath ( IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath=0D )=0D {=0D - return EFI_NOT_FOUND;=0D + UINT16 TargetValue;=0D + LSI_SCSI_DEV *Dev;=0D + SCSI_DEVICE_PATH *ScsiDevicePath;=0D +=0D + if (DevicePath =3D=3D NULL) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + CopyMem (&TargetValue, Target, sizeof TargetValue);=0D + Dev =3D LSI_SCSI_FROM_PASS_THRU (This);=0D + if (TargetValue > Dev->MaxTarget || Lun > Dev->MaxLun || Lun > 0xFFFF) {= =0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + ScsiDevicePath =3D AllocatePool (sizeof *ScsiDevicePath);=0D + if (ScsiDevicePath =3D=3D NULL) {=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + ScsiDevicePath->Header.Type =3D MESSAGING_DEVICE_PATH;=0D + ScsiDevicePath->Header.SubType =3D MSG_SCSI_DP;=0D + ScsiDevicePath->Header.Length[0] =3D (UINT8) sizeof *ScsiDevicePath;=0D + ScsiDevicePath->Header.Length[1] =3D (UINT8) (sizeof *ScsiDevicePath >> = 8);=0D + ScsiDevicePath->Pun =3D TargetValue;=0D + ScsiDevicePath->Lun =3D (UINT16) Lun;=0D +=0D + *DevicePath =3D &ScsiDevicePath->Header;=0D + return EFI_SUCCESS;=0D }=0D =0D EFI_STATUS=0D @@ -77,7 +148,33 @@ LsiScsiGetTargetLun ( OUT UINT64 *Lun=0D )=0D {=0D - return EFI_UNSUPPORTED;=0D + SCSI_DEVICE_PATH *ScsiDevicePath;=0D + LSI_SCSI_DEV *Dev;=0D + UINT8 *Target;=0D +=0D + if (DevicePath =3D=3D NULL || TargetPointer =3D=3D NULL || *TargetPointe= r =3D=3D NULL ||=0D + Lun =3D=3D NULL) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (DevicePath->Type !=3D MESSAGING_DEVICE_PATH ||=0D + DevicePath->SubType !=3D MSG_SCSI_DP) {=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + ScsiDevicePath =3D (SCSI_DEVICE_PATH *) DevicePath;=0D + Dev =3D LSI_SCSI_FROM_PASS_THRU (This);=0D + if (ScsiDevicePath->Pun > Dev->MaxTarget ||=0D + ScsiDevicePath->Lun > Dev->MaxLun) {=0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + Target =3D *TargetPointer;=0D + ZeroMem (Target, TARGET_MAX_BYTES);=0D + CopyMem (Target, &ScsiDevicePath->Pun, sizeof ScsiDevicePath->Pun);=0D + *Lun =3D ScsiDevicePath->Lun;=0D +=0D + return EFI_SUCCESS;=0D }=0D =0D EFI_STATUS=0D @@ -107,6 +204,42 @@ LsiScsiGetNextTarget ( IN OUT UINT8 **TargetPointer=0D )=0D {=0D + LSI_SCSI_DEV *Dev;=0D + UINTN Idx;=0D + UINT8 *Target;=0D + UINT16 LastTarget;=0D +=0D + //=0D + // the TargetPointer input parameter is unnecessarily a pointer-to-point= er=0D + //=0D + Target =3D *TargetPointer;=0D +=0D + //=0D + // Search for first non-0xFF byte. If not found, return first target.=0D + //=0D + for (Idx =3D 0; Idx < TARGET_MAX_BYTES && Target[Idx] =3D=3D 0xFF; ++Idx= )=0D + ;=0D + if (Idx =3D=3D TARGET_MAX_BYTES) {=0D + SetMem (Target, TARGET_MAX_BYTES, 0x00);=0D + return EFI_SUCCESS;=0D + }=0D +=0D + CopyMem (&LastTarget, Target, sizeof LastTarget);=0D +=0D + //=0D + // increment target if valid on input=0D + //=0D + Dev =3D LSI_SCSI_FROM_PASS_THRU (This);=0D + if (LastTarget > Dev->MaxTarget) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (LastTarget < Dev->MaxTarget) {=0D + ++LastTarget;=0D + CopyMem (Target, &LastTarget, sizeof LastTarget);=0D + return EFI_SUCCESS;=0D + }=0D +=0D return EFI_NOT_FOUND;=0D }=0D =0D @@ -189,6 +322,17 @@ LsiScsiControllerStart ( =0D Dev->Signature =3D LSI_SCSI_DEV_SIGNATURE;=0D =0D + STATIC_ASSERT (=0D + FixedPcdGet8 (PcdLsiScsiMaxTargetLimit) < 8,=0D + "LSI 53C895A supports targets [0..7]"=0D + );=0D + STATIC_ASSERT (=0D + FixedPcdGet8 (PcdLsiScsiMaxLunLimit) < 128,=0D + "LSI 53C895A supports LUNs [0..128]"=0D + );=0D + Dev->MaxTarget =3D PcdGet8 (PcdLsiScsiMaxTargetLimit);=0D + Dev->MaxLun =3D PcdGet8 (PcdLsiScsiMaxLunLimit);=0D +=0D //=0D // Host adapter channel, doesn't exist=0D //=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.h b/OvmfPkg/LsiScsiDxe/LsiScsi.h index c194dfbf3347..6c6ed25f1c33 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.h +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.h @@ -14,6 +14,8 @@ =0D typedef struct {=0D UINT32 Signature;=0D + UINT8 MaxTarget;=0D + UINT8 MaxLun;=0D EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode;=0D EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;=0D } LSI_SCSI_DEV;=0D @@ -23,6 +25,7 @@ typedef struct { #define LSI_SCSI_FROM_PASS_THRU(PassThruPtr) \=0D CR (PassThruPtr, LSI_SCSI_DEV, PassThru, LSI_SCSI_DEV_SIGNATURE)=0D =0D +=0D //=0D // Probe, start and stop functions of this driver, called by the DXE core = for=0D // specific devices.=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf b/OvmfPkg/LsiScsiDxe/LsiScsi= Dxe.inf index 14f9c68308cc..6111449577a8 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf +++ b/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf @@ -27,7 +27,9 @@ [Packages] [LibraryClasses]=0D BaseLib=0D BaseMemoryLib=0D + DebugLib=0D MemoryAllocationLib=0D + PcdLib=0D UefiBootServicesTableLib=0D UefiDriverEntryPoint=0D UefiLib=0D @@ -35,3 +37,7 @@ [LibraryClasses] [Protocols]=0D gEfiExtScsiPassThruProtocolGuid ## BY_START=0D gEfiPciIoProtocolGuid ## TO_START=0D +=0D +[FixedPcd]=0D + gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiMaxTargetLimit ## CONSUMES=0D + gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiMaxLunLimit ## CONSUMES=0D diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 2b0f137cbcce..ca13a3cb11d3 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -174,6 +174,11 @@ [PcdsFixedAtBuild] ## Microseconds to stall between polling for MptScsi request result=0D gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiStallPerPollUsec|5|UINT32|0x3a=0D =0D + ## Set the *inclusive* number of targets and LUNs that LsiScsi exposes f= or=0D + # scan by ScsiBusDxe.=0D + gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiMaxTargetLimit|7|UINT8|0x3b=0D + gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiMaxLunLimit|0|UINT8|0x3c=0D +=0D gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogBase|0x0|UINT32|= 0x8=0D gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogSize|0x0|UINT32|= 0x9=0D gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize|0x0|UINT32|0xa=0D --=20 2.25.1