From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.61]) by mx.groups.io with SMTP id smtpd.web11.5468.1588708950629650262 for ; Tue, 05 May 2020 13:02:30 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SfQhIj/l; spf=pass (domain: redhat.com, ip: 205.139.110.61, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588708949; 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=0FG6a0i6zgeVlcaWjDtjvp/fxSzAdQA0fSn8kuMkDnA=; b=SfQhIj/lqf9djdWpMs91M6Xd02L7Fl1KU59LPLbdu6JsjClwwT5mwzgmYAgG03XtENc0HV hp8HsNnxXuteH5pJZCfm7SJ0JrYxOk8H/gYrPOV/zQojibaDnoQisjb+AHJpxpsz/+tMU9 iPMMTO7EAdeEEZZRND+OwdjvKUwDrn0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-320-jezhSD3WP_-ckMA6Pw8o5w-1; Tue, 05 May 2020 16:02:21 -0400 X-MC-Unique: jezhSD3WP_-ckMA6Pw8o5w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9A8B835B8D; Tue, 5 May 2020 20:02:19 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-134.ams2.redhat.com [10.36.114.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 436CD62482; Tue, 5 May 2020 20:02:18 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v6 06/12] OvmfPkg/MptScsiDxe: Report targets and one LUN To: devel@edk2.groups.io, nikita.leshchenko@oracle.com Cc: liran.alon@oracle.com, aaron.young@oracle.com, Jordan Justen , Ard Biesheuvel References: <20200504210607.144434-1-nikita.leshchenko@oracle.com> <20200504210607.144434-7-nikita.leshchenko@oracle.com> From: "Laszlo Ersek" Message-ID: <01a1d062-b04b-5cdf-cdef-29f6fb3b6bef@redhat.com> Date: Tue, 5 May 2020 22:02:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200504210607.144434-7-nikita.leshchenko@oracle.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 05/04/20 23:06, Nikita Leshenko wrote: > The controller supports up to 8 targets in practice (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 > Reviewed-by: Laszlo Ersek > --- > OvmfPkg/MptScsiDxe/MptScsi.c | 63 ++++++++++++++++++++++++++++++- > OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 5 +++ > OvmfPkg/OvmfPkg.dec | 4 ++ > 3 files changed, 70 insertions(+), 2 deletions(-) Thanks for the PcdLib-related updates! Laszlo > diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c > index 40d392c2346f..d396bff85cb6 100644 > --- a/OvmfPkg/MptScsiDxe/MptScsi.c > +++ b/OvmfPkg/MptScsiDxe/MptScsi.c > @@ -11,8 +11,10 @@ > > #include > #include > +#include > #include > #include > +#include > #include > #include > #include > @@ -34,6 +36,7 @@ typedef struct { > UINT32 Signature; > EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; > EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; > + UINT8 MaxTarget; > } MPT_SCSI_DEV; > > #define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \ > @@ -57,6 +60,22 @@ MptScsiPassThru ( > return EFI_UNSUPPORTED; > } > > +STATIC > +BOOLEAN > +IsTargetInitialized ( > + IN UINT8 *Target > + ) > +{ > + UINTN Idx; > + > + for (Idx = 0; Idx < TARGET_MAX_BYTES; ++Idx) { > + if (Target[Idx] != 0xFF) { > + return TRUE; > + } > + } > + return FALSE; > +} > + > STATIC > EFI_STATUS > EFIAPI > @@ -66,7 +85,28 @@ MptScsiGetNextTargetLun ( > IN OUT UINT64 *Lun > ) > { > - return EFI_UNSUPPORTED; > + MPT_SCSI_DEV *Dev; > + > + Dev = MPT_SCSI_FROM_PASS_THRU (This); > + // > + // Currently support only LUN 0, so hardcode it > + // > + if (!IsTargetInitialized (*Target)) { > + ZeroMem (*Target, TARGET_MAX_BYTES); > + *Lun = 0; > + } else if (**Target > Dev->MaxTarget || *Lun > 0) { > + return EFI_INVALID_PARAMETER; > + } else if (**Target < Dev->MaxTarget) { > + // > + // This device interface 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; > + } > + > + return EFI_SUCCESS; > } > > STATIC > @@ -77,7 +117,24 @@ MptScsiGetNextTarget ( > IN OUT UINT8 **Target > ) > { > - return EFI_UNSUPPORTED; > + MPT_SCSI_DEV *Dev; > + > + Dev = MPT_SCSI_FROM_PASS_THRU (This); > + if (!IsTargetInitialized (*Target)) { > + ZeroMem (*Target, TARGET_MAX_BYTES); > + } else if (**Target > Dev->MaxTarget) { > + return EFI_INVALID_PARAMETER; > + } else if (**Target < Dev->MaxTarget) { > + // > + // This device interface 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; > + } > + > + return EFI_SUCCESS; > } > > STATIC > @@ -206,6 +263,8 @@ MptScsiControllerStart ( > > Dev->Signature = MPT_SCSI_DEV_SIGNATURE; > > + Dev->MaxTarget = PcdGet8 (PcdMptScsiMaxTargetLimit); > + > // > // Host adapter channel, doesn't exist > // > diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf > index 9f7c98829ee1..d5fd2516e475 100644 > --- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf > +++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf > @@ -24,8 +24,10 @@ [Packages] > OvmfPkg/OvmfPkg.dec > > [LibraryClasses] > + BaseMemoryLib > DebugLib > MemoryAllocationLib > + PcdLib > UefiBootServicesTableLib > UefiDriverEntryPoint > UefiLib > @@ -33,3 +35,6 @@ [LibraryClasses] > [Protocols] > gEfiExtScsiPassThruProtocolGuid ## BY_START > gEfiPciIoProtocolGuid ## TO_START > + > +[FixedPcd] > + gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiMaxTargetLimit ## CONSUMES > diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec > index 28030391cff2..2d09444bbb16 100644 > --- a/OvmfPkg/OvmfPkg.dec > +++ b/OvmfPkg/OvmfPkg.dec > @@ -163,6 +163,10 @@ [PcdsFixedAtBuild] > # polling loop iteration. > gUefiOvmfPkgTokenSpaceGuid.PcdPvScsiWaitForCmpStallInUsecs|5|UINT32|0x38 > > + ## Set the *inclusive* number of targets that MptScsi exposes for scan > + # by ScsiBusDxe. > + gUefiOvmfPkgTokenSpaceGuid.PcdMptScsiMaxTargetLimit|7|UINT8|0x39 > + > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogBase|0x0|UINT32|0x8 > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogSize|0x0|UINT32|0x9 > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize|0x0|UINT32|0xa >