From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [62.140.7.102]) by mx.groups.io with SMTP id smtpd.web11.10948.1594885616112271889 for ; Thu, 16 Jul 2020 00:46:56 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=SvdN+fy9; spf=pass (domain: suse.com, ip: 62.140.7.102, mailfrom: glin@suse.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1594885614; 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=YSSucCD8XiFb9gigHNOTwHfucJPQ3jV89TTOc0JvaEY=; b=SvdN+fy937Uyngv0AO+qHhrfSsGxUz2q/qQv+eN2fY1aKYLDyq8cthdhc6uDDACL/aMxGI /ddPyWY2/leuEP+f3VH7b06EL+CHfXYqDhUQWNxXy2sZNHDA2W4qeXBN9gsVJ85+MbuMg/ hja/yaErONW7QvHO59sTh4QRj3DcBAY= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2172.outbound.protection.outlook.com [104.47.17.172]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-4-f9Pq84a_PteN2rlMW_4GqQ-2; Thu, 16 Jul 2020 09:46:53 +0200 X-MC-Unique: f9Pq84a_PteN2rlMW_4GqQ-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WHHbIUlcjo7SHL2vbyLVva5nGze4+1Vf1RDYwiDp432ftWV6KZT3KC899QDTfZUiFP0i27wqK6yR30dbaZZWGGrNgv552sEa1Yvi0G3CdA5qXF+B8wEu+l7aNQ17gg3RTgXhhv0YJdDMuSdPx15vZiqKfMCUYgOZdNDMIITBBXXCp2m0E9g8p2oQ+U+L2GQjcCWOHvQYvsQS+9HwPrd9K3dNe6TC7AtFSwoQZ8up7P9iZHLTk4kksRdCh6Qx3FcDtWSaV42vEywKNlNWqIK+MLoU2v3By7n3cW40lx4yWrucIYKcPPXienwkNBD1wSvQwQQIiwK9KIIe9P3ByOtf+Q== 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=YSSucCD8XiFb9gigHNOTwHfucJPQ3jV89TTOc0JvaEY=; b=G2vrRV7sggS8pAAEyxDWQEza/gEEJro1fRBj2+ppkrsIqlkrKBGzYsJGjPQCYLAbKlC2dA1ymSi6zSg/khX0BI0uCSxa2/7bHWKYtPVlr9RNHtFc124MqqpaEBWF430L/JMztnQ+2KOjl53zxWSoO5DM+rsdFXTc54xQNbEkW4YTD1k5PcpWCcG04imTJVm7cT+GNKnhfj7H3kg3gep7cbfGYYu31Y2rvVv04IzcWn3QWyXBwg+mTwbRQSlj2nBHLnMOEjJdE3/FhkYoE6SU8Glbi5ENjC7fliTeoNnSKuMWWeuqQZ3psBB+7BSvMjTG8B5paof1W1ui5U6HzjdG9w== 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 AM0PR04MB4740.eurprd04.prod.outlook.com (2603:10a6:208:c8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Thu, 16 Jul 2020 07:46:48 +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:48 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH v2 11/12] OvmfPkg/LsiScsiDxe: Calculate the transferred bytes Date: Thu, 16 Jul 2020 15:46:06 +0800 Message-Id: <20200716074607.18048-12-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:46 +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: fccefa15-c33b-460d-13b2-08d8295c6504 X-MS-TrafficTypeDiagnostic: AM0PR04MB4740: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ePewCBL/1JhwrrcRaECN4r2VphwzEAFUQVzazDZZFIeP2OyoBKtS3zA0JDu6ZmVS3H/U64pMdmV9NDZLtmaua5BPsH4vsl8xZdW3Re+x0w/4MCOY3MCx6ZnL8WrhZGhFnW8qLv+c4ZlGR5G/CmhqTAxhH1E9TPpN44YDaYkpyC7Bi0xSjsQN7drvXgp6wh7jxVafndXIlf/8cNjqBCdRNl5bWqPv5PG8wTQDVgE2r9wfUarhYtQ+QeStESHuCV9V50HbffUNTvd3FUA9BFe5NxTcZFKQT/rfWRm8gntKCibw12i0dC1Ik+FWCBz9ANPzQdJ8KkyOKW+0WqfGXuxdeA== 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:(136003)(376002)(346002)(39860400002)(366004)(396003)(2616005)(956004)(26005)(478600001)(8936002)(36756003)(2906002)(54906003)(8676002)(52116002)(6916009)(316002)(6512007)(186003)(16526019)(1076003)(6486002)(5660300002)(66556008)(66476007)(66946007)(6666004)(83380400001)(86362001)(6506007)(55236004)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Og656L1oKgsVXyu6lwvtRwgTVWdneXbn4qf+A4GuCd7AAUwdxpCgFCzH+Z0dk9WBsdsIDn/1aXbFHwoRgm2g6WdgnTzV5Ais9ctMYraKHqH0pVs0qCamYbjdsZC2eHLr4a7lTp0xlNSq+rfOCJ0F9s5A5514oy/L8szT4aKvzX/yY4WjCFwxdBK1UATb0Tdl2aikVGEAX942Vzw0kKETHR7DInGLpVSEz1krdh+VmJlcC7/sadtnqiO9CnZfm3i2Jbr4DJgT0Z0jZ1qx4GFsAGoVutO7VgBrLAt+8pweZD1SJU6wKsQ9lto7tt5aq4G7guzz55HXy0lsKz02KwIeaenVAx4q2T0gDSJcJoe4ocP+2edPPUChxpJGRR0CFcUrP4qCefbrfHEMSakbJLgV402/xsuo8CVol7xUDrWZZRKir7yj09Nb8Ov1JCJi/4CR8N+EpWu6u7b+qkpAnSSIBhyWX1QVtZ6is3ixi5M4a0s= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: fccefa15-c33b-460d-13b2-08d8295c6504 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:48.5139 (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: 6gDoPVs+bO9LTdRicPZKILywtWc1C8C+lh9ANCv82khOmSIvY6AOuRcCAUlCAiTJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4740 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Calculate the transferred bytes during data phases based on the Cumulative SCSI Byte Count (CSBC) and update InTransferLength/OutTransferLength of the request packet. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin --- OvmfPkg/Include/IndustryStandard/LsiScsi.h | 1 + OvmfPkg/LsiScsiDxe/LsiScsi.c | 50 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/LsiScsi.h b/OvmfPkg/Include/I= ndustryStandard/LsiScsi.h index 9964bd40385c..01d75323cdbc 100644 --- a/OvmfPkg/Include/IndustryStandard/LsiScsi.h +++ b/OvmfPkg/Include/IndustryStandard/LsiScsi.h @@ -25,6 +25,7 @@ #define LSI_REG_DSP 0x2C=0D #define LSI_REG_SIST0 0x42=0D #define LSI_REG_SIST1 0x43=0D +#define LSI_REG_CSBC 0xDC=0D =0D //=0D // The status bits for DMA Status (DSTAT)=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c index d5fe1d4ab3b8..10483ed02bd7 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c @@ -79,6 +79,24 @@ In8 ( );=0D }=0D =0D +STATIC=0D +EFI_STATUS=0D +In32 (=0D + IN LSI_SCSI_DEV *Dev,=0D + IN UINT32 Addr,=0D + OUT UINT32 *Data=0D + )=0D +{=0D + return Dev->PciIo->Io.Read (=0D + Dev->PciIo,=0D + EfiPciIoWidthUint32,=0D + PCI_BAR_IDX0,=0D + Addr,=0D + 1,=0D + Data=0D + );=0D +}=0D +=0D STATIC=0D EFI_STATUS=0D LsiScsiReset (=0D @@ -219,6 +237,8 @@ LsiScsiProcessRequest ( UINT8 DStat;=0D UINT8 SIst0;=0D UINT8 SIst1;=0D + UINT32 Csbc;=0D + UINT32 CsbcBase;=0D =0D Script =3D Dev->Dma->Script;=0D Cdb =3D Dev->Dma->Cdb;=0D @@ -232,6 +252,18 @@ LsiScsiProcessRequest ( SetMem (Cdb, sizeof Dev->Dma->Cdb, 0x00);=0D CopyMem (Cdb, Packet->Cdb, Packet->CdbLength);=0D =0D + //=0D + // Fetch the first Cumulative SCSI Byte Count (CSBC).=0D + //=0D + // CSBC is a cumulative counter of the actual number of bytes that has b= een=0D + // transferred across the SCSI bus during data phases, i.e. it will not= =0D + // bytes sent in command, status, message in and out phases.=0D + //=0D + Status =3D In32 (Dev, LSI_REG_CSBC, &CsbcBase);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D //=0D // Clean up the DMA buffer for the script.=0D //=0D @@ -407,6 +439,24 @@ LsiScsiProcessRequest ( gBS->Stall (Dev->StallPerPollUsec);=0D }=0D =0D + //=0D + // Fetch CSBC again to calculate the transferred bytes and update=0D + // InTransferLength/OutTransferLength.=0D + //=0D + // Note: The number of transferred bytes is bounded by=0D + // "sizeof Dev->Dma->Data", so it's safe to subtract CsbcBase=0D + // from Csbc.=0D + //=0D + Status =3D In32 (Dev, LSI_REG_CSBC, &Csbc);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D + if (Packet->InTransferLength > 0) {=0D + Packet->InTransferLength =3D Csbc - CsbcBase;=0D + } else if (Packet->OutTransferLength > 0) {=0D + Packet->OutTransferLength =3D Csbc - CsbcBase;=0D + }=0D +=0D //=0D // Check if everything is good.=0D // SCSI Message Code 0x00: COMMAND COMPLETE=0D --=20 2.25.1