From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web11.14081.1585425545041524695 for ; Sat, 28 Mar 2020 12:59:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=h4J/UVvj; spf=pass (domain: oracle.com, ip: 156.151.31.86, mailfrom: liran.alon@oracle.com) 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 02SJnLcd014007; Sat, 28 Mar 2020 19:59:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=icBhGIRENlOdGYAB4enHd+CSJKk1YZMwTxDdXJmcI8k=; b=h4J/UVvjOLnzGICHFtkHqaBb3Er6WNNT9oTZqtvmox4KJ+qlv6uNM9UVoN5oKeAfP5ht WycHOm5imcehWVBt2j5WEQTL89AlFMNASK47ymwn0qACj1kOzjgriNztxSI40UqQt14b MOMF4Cwc9oGjMJptEqNVAJOkgviElmViRDlTcOLk4JcqHNbX0Igng32id7io5W6SWc3s D1Bi01bafc2+owAThG439Yneqfg96Sw22dqsT3u8XHK6Fw5TvEjrfggN07t0j9KWRrtj h38R6hj0DLT4cg1S3ChJplLK9Sl3ndLFE3fcsfW/WwObMRPcQtYdC77CTSb1B4glhNHt 4Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 301x0qsj8p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 28 Mar 2020 19:59:04 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02SJomAL164617; Sat, 28 Mar 2020 19:59:04 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 301ups6hbc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 28 Mar 2020 19:59:04 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 02SJx3j3007284; Sat, 28 Mar 2020 19:59:03 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 28 Mar 2020 12:59:01 -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: [PATCH v3 12/17] OvmfPkg/PvScsiDxe: Reset adapter on init Date: Sat, 28 Mar 2020 23:00:55 +0300 Message-Id: <20200328200100.60786-13-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200328200100.60786-1-liran.alon@oracle.com> References: <20200328200100.60786-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9574 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003280189 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9574 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 clxscore=1015 adultscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003280189 Content-Transfer-Encoding: 8bit The following commits will complete the implementation of device initialization. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2567 Reviewed-by: Laszlo Ersek Signed-off-by: Liran Alon --- OvmfPkg/PvScsiDxe/PvScsi.c | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c index 531bed4e5ab7..cf75884350ee 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.c +++ b/OvmfPkg/PvScsiDxe/PvScsi.c @@ -30,6 +30,107 @@ // Ext SCSI Pass Thru utilities // +/** + Writes a 32-bit value into BAR0 using MMIO +**/ +STATIC +EFI_STATUS +PvScsiMmioWrite32 ( + IN CONST PVSCSI_DEV *Dev, + IN UINT64 Offset, + IN UINT32 Value + ) +{ + return Dev->PciIo->Mem.Write ( + Dev->PciIo, + EfiPciIoWidthUint32, + PCI_BAR_IDX0, + Offset, + 1, // Count + &Value + ); +} + +/** + Writes multiple words of data into BAR0 using MMIO +**/ +STATIC +EFI_STATUS +PvScsiMmioWrite32Multiple ( + IN CONST PVSCSI_DEV *Dev, + IN UINT64 Offset, + IN UINTN Count, + IN UINT32 *Words + ) +{ + return Dev->PciIo->Mem.Write ( + Dev->PciIo, + EfiPciIoWidthFifoUint32, + PCI_BAR_IDX0, + Offset, + Count, + Words + ); +} + +/** + Send a PVSCSI command to device. + + @param[in] Dev The pvscsi host device. + @param[in] Cmd The command to send to device. + @param[in] OPTIONAL DescWords An optional command descriptor (If command + have a descriptor). The descriptor is + provided as an array of UINT32 words and + is must be 32-bit aligned. + @param[in] DescWordsCount The number of words in command descriptor. + Caller must specify here 0 if DescWords + is not supplied (It is optional). In that + case, DescWords is ignored. + + @return Status codes returned by Dev->PciIo->Mem.Write(). + +**/ +STATIC +EFI_STATUS +PvScsiWriteCmdDesc ( + IN CONST PVSCSI_DEV *Dev, + IN UINT32 Cmd, + IN UINT32 *DescWords OPTIONAL, + IN UINTN DescWordsCount + ) +{ + EFI_STATUS Status; + + if (DescWordsCount > PVSCSI_MAX_CMD_DATA_WORDS) { + return EFI_INVALID_PARAMETER; + } + + Status = PvScsiMmioWrite32 (Dev, PvScsiRegOffsetCommand, Cmd); + if (EFI_ERROR (Status)) { + return Status; + } + + if (DescWordsCount > 0) { + return PvScsiMmioWrite32Multiple ( + Dev, + PvScsiRegOffsetCommandData, + DescWordsCount, + DescWords + ); + } + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +PvScsiResetAdapter ( + IN CONST PVSCSI_DEV *Dev + ) +{ + return PvScsiWriteCmdDesc (Dev, PvScsiCmdAdapterReset, NULL, 0); +} + /** Check if Target argument to EXT_SCSI_PASS_THRU.GetNextTarget() and EXT_SCSI_PASS_THRU.GetNextTargetLun() is initialized @@ -357,6 +458,14 @@ PvScsiInit ( return Status; } + // + // Reset adapter + // + Status = PvScsiResetAdapter (Dev); + if (EFI_ERROR (Status)) { + goto RestorePciAttributes; + } + // // Populate the exported interface's attributes // @@ -387,6 +496,11 @@ PvScsiInit ( Dev->PassThruMode.IoAlign = 0; return EFI_SUCCESS; + +RestorePciAttributes: + PvScsiRestorePciAttributes (Dev); + + return Status; } STATIC -- 2.20.1