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.web11.14078.1593576346464702525 for ; Tue, 30 Jun 2020 21:05:46 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: suse.com, ip: 51.163.158.102, mailfrom: glin@suse.com) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02lp2058.outbound.protection.outlook.com [104.47.4.58]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-27-zHoeg4-zPU6PRNHRxuyaYA-1; Wed, 01 Jul 2020 06:05:42 +0200 X-MC-Unique: zHoeg4-zPU6PRNHRxuyaYA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dpc2OvjSxJgNyXhc3EPfnk3+lCWrIKG247uK/Q7tdr5tBXaso9a7w73elQBF/fpRnVN/Y5FZXgCo/dspBkGsED6bbXzxLN3SWob/i8aRpWkcgbgn+jaCiUr1ZMjjWQdyWpLsquubZUfFBE4n4XAvkSuliUYENcUNpU0UhWtlCTzNhsQM6seqoaQPHoNigJVbOf0uexFD5yPkXE7nVa84vFLzOOHplaAbOEbTZG8Y82Ur0OFZA7eB4cHtleJK+6AwyeDOCybCG1MowOPqwTDMlOUkFAaKn2hcJdEwVV49JpogzeUhIrxnz4qkVt+TF/1QMHqz3RiXiaFCKRHz13m+Cg== 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=e0CYp4Il9hxFSVkxPGyyUaCXq+CIwtFzyGkKhCImZQQ=; b=R9p0czqpekj1xDk+f9EoVw6Y+10zmSyu4nbJjolPJbZQHUxeCSibtXMHh9rVL3+mDgiVrhqnmDSNnu3PodnuiU/gLbIh3d+GNJM8vD/a3RPWD3YKfuVCNwY7XK/PKUaIMlbeGwH2Orek8z9889GCVJyJ/ebsq7xcBKTtssMoOCTYV3eK1yO4jsDOfXkvcKBbHEMPNsfWiYbFFBTjVkQ6dVwGUc6uhOjd0GYqcdKh91rvY0M62selprK46IvVjqs2CuDLE3x+TEml+lCg3FTHVn7c9MUa9941GYqpaKdJb/IU3sQoGGPFhtauQwBaAVCPiS6mNtfsKakry4O/7D8R6A== 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 AM0PR04MB4481.eurprd04.prod.outlook.com (2603:10a6:208:70::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21; Wed, 1 Jul 2020 04:05:41 +0000 Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::8806:715f:1409:8c6b]) by AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::8806:715f:1409:8c6b%7]) with mapi id 15.20.3153.021; Wed, 1 Jul 2020 04:05:41 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH 06/11] OvmfPkg/LsiScsiDxe: Report Targets and LUNs Date: Wed, 1 Jul 2020 12:04:43 +0800 Message-Id: <20200701040448.14871-7-glin@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200701040448.14871-1-glin@suse.com> References: <20200701040448.14871-1-glin@suse.com> X-ClientProxiedBy: AM0PR10CA0047.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::27) 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 AM0PR10CA0047.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.21 via Frontend Transport; Wed, 1 Jul 2020 04:05:40 +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: 3dbf4084-9611-4fed-2d7a-08d81d74053e X-MS-TrafficTypeDiagnostic: AM0PR04MB4481: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:758; X-Forefront-PRVS: 04519BA941 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jEKal5BOjWH6Rug++sHSDfxU53Eex8IZWj1bB9su4bBfeMTfXsCRD5V47z8ta9GbsL3nLzD9Di5ak2CbqDBf5usBJF7XeqtopBBLF66sK9nprEnfcyLyojaTSBlsNBP4IoB+/ULXswAEEM6Tso9PslyazmggLYSjY72u52xkq2KrRvO/jK8RbWDE1fJYRzUrGiwND9PeNPamqwAV9M9U0f4QQgqO0nS3Sq/utdOkCUSDNB9URjVprOzPACcYXV11Ej84GVcu5FzyGNU6yuzxiuZgiZ7VYJFWY0fKNRM9vhHdT9hTBV2leXNYzFosvpZsPPucDNNd1M2znv00m8KmSg== 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:(366004)(136003)(376002)(39860400002)(396003)(346002)(2616005)(83380400001)(26005)(54906003)(4326008)(16526019)(1076003)(956004)(86362001)(6506007)(186003)(66476007)(66556008)(8936002)(6486002)(52116002)(6916009)(5660300002)(8676002)(36756003)(66946007)(55236004)(316002)(6512007)(478600001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 3+Ww4koPxg4qybpjJy2Zm/B0AVhOfDqbYGgbgpkyV1jX0gNhr0CKnffTkmpmHFssefrPcyQK2ZNCxb5ojkbjzXIlrLJAgGoYxvbFwyB9fVBX5GkRTqFgrnwzExiCtDxGw8t1GzhE3f/yso1RAj1mYWgDoLCZzJp/jVjUdgkkGv2wu8Ipa8n5nDn/vSBXj4k1cCDYDtTJwvodvByWnsiCf87HkXDAgfakGO5uS+gqy6LL4A+3Rob3taorM6jmujR7OOOZ4zuLchqtYQb9MWn0yn1fsXO2ZoRNDPOYu7KjLEUw89+R2h2lyEaXgyTGlFu81503CUYj0KSFVl/1WsW7XwBABn/ej9R2DTrROPWlYPuaCDLHAFGGL+Gv2EKZx73OSUEJ5uaGeVHcy2uKuk4qsUkUsX3TExzl63YSbo2McoQ3ZAosu5hNkScaVxKfnqbgW1sdigJqiIqdo3ek2VBWbA/dQAbK+IuGj1q53M4H+Ns= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3dbf4084-9611-4fed-2d7a-08d81d74053e X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3809.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2020 04:05:41.7746 (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: sytUyCmb6KOwUL2NtKNDZHVEM9cYIw425vlSQmykQBhYXMVWDk0aq+fF4WoYQoKo X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4481 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. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin --- OvmfPkg/LsiScsiDxe/LsiScsi.c | 143 +++++++++++++++++++++++++++++- OvmfPkg/LsiScsiDxe/LsiScsi.h | 3 + OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf | 6 ++ OvmfPkg/OvmfPkg.dec | 5 ++ 4 files changed, 155 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c index f633c6793298..e10a81a5f9f7 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,36 @@ 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 + //=0D + // This device support 8 targets only, so it's enough to set the LSB=0D + // of Target.=0D + //=0D + Target =3D *TargetPointer;=0D + *Target =3D (UINT8)ScsiDevicePath->Pun;=0D + *Lun =3D ScsiDevicePath->Lun;=0D +=0D + return EFI_SUCCESS;=0D }=0D =0D EFI_STATUS=0D @@ -107,6 +207,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 +325,9 @@ LsiScsiControllerStart ( =0D Dev->Signature =3D LSI_SCSI_DEV_SIGNATURE;=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 fca1007f9b98..a3d51d8f2386 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 8660513e2ffd..68844c6772e3 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 65bb2bb0eb4c..ae7d1d648d22 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|0x40=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