From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.81]) by mx.groups.io with SMTP id smtpd.web12.268.1587407521159075646 for ; Mon, 20 Apr 2020 11:32:02 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZyYqPGKU; spf=pass (domain: redhat.com, ip: 207.211.31.81, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587407520; 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=udZN8iIu0i9naIZ3mInCby+OpD+fTz4JGNLa0b4LAow=; b=ZyYqPGKUtPIQzM64Vaj2R6G35JVQBY4L9oSQEEHFkSmkqibKaf7NGFgJiwbIL++xaFI5c+ uApl4NnK6BVxtNNXOjs94ZmlQn2RPGR2ogtBLX9NIYFCwBxsgNOGmf+wDj79+4Ld53cDrW 4K5xHkImYXuSVHufQKX0mhQMI+Zb7JA= 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-359-03Bo5KhPPfemNPa6XtyYpg-1; Mon, 20 Apr 2020 14:31:55 -0400 X-MC-Unique: 03Bo5KhPPfemNPa6XtyYpg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9D7C190B2A5; Mon, 20 Apr 2020 18:31:53 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-228.ams2.redhat.com [10.36.114.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 496425C1B2; Mon, 20 Apr 2020 18:31:52 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v4 12/13] OvmfPkg/MptScsiDxe: Report multiple targets To: devel@edk2.groups.io, nikita.leshchenko@oracle.com Cc: liran.alon@oracle.com, aaron.young@oracle.com, Jordan Justen , Ard Biesheuvel References: <20200414173813.7715-1-nikita.leshchenko@oracle.com> <20200414173813.7715-13-nikita.leshchenko@oracle.com> From: "Laszlo Ersek" Message-ID: Date: Mon, 20 Apr 2020 20:31:51 +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: <20200414173813.7715-13-nikita.leshchenko@oracle.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 04/14/20 19:38, Nikita Leshenko wrote: > 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 > Reviewed-by: Liran Alon > --- > 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; (1) If Dev->MaxTarget is 255, then the RHS will evaluate to 256. But the LHS can only fit a UINT8. Can you introduce the PCD in the INF file under a [FixedPcd] section, and add: STATIC_ASSERT (FixedPcdGet8 (...) < 255, "..."); to MptScsiInit()? (I'm unsure (and I'm too tired to check) whether FixedPcdGet8() will expand to an integer constant. If it doesn't, then STATIC_ASSERT() won't work. In that case we should likely use a plain ASSERT().) > 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; > } (2) Please implement the EFI_INVALID_PARAMETER branch as well, as seen in PvScsiGetNextTargetLun(). It's a check on input: if (**Target > Dev->MaxTarget || *Lun > 0) { return EFI_INVALID_PARAMETER; } And then, as a consequence, the "*Lun = 0" assignment is no longer necessary, near the target increment. (Until you implement multi-LUN.) To confirm, (Target==MaxTarget) on input should return EFI_NOT_FOUND, while (Target>MaxTarget) on input should return EFI_INVALID_PARAMETER. > @@ -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; > } (3) Same as (2). Hmmm. Maybe I should have pointed these out under patch#6 ("OvmfPkg/MptScsiDxe: Report one Target and one LUN"). Because, even while we only support Target=0, the EFI_NOT_FOUND and EFI_INVALID_PARAMETER return values of GetNextTarget() and GetNextTargetLun(), could be distinguished. Sorry for missing this under patch#6. > @@ -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 (4) Please keep the PCD list alphabetically sorted, and also keep the "## ... " comments lined up. > 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 > + (5) Please keep this near the PcdPvScsi* group of PCDs. > [PcdsDynamic, PcdsDynamicEx] > gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 > Thanks Laszlo