From nobody Fri Dec 27 03:30:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1503491062062812.6263002352015; Wed, 23 Aug 2017 05:24:22 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8826021E47D4B; Wed, 23 Aug 2017 05:20:43 -0700 (PDT) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0040.outbound.protection.outlook.com [104.47.40.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5CC3D21D2E634 for ; Wed, 23 Aug 2017 05:20:36 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1362.18; Wed, 23 Aug 2017 12:23:06 +0000 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=jP8riQ++Nl1IaoX3VZ3/fDoabQyH4dYJv6iAUCImO/w=; b=NbZ1RbdxB2Rcte/2E+rvrWCMCa5z216P6xqoLDPuntIOaiUf6AYlo9nAXvqgrjX+DPVPjoS64riDxhi6oIdDCGSTErvuDNFQwWqtUdhpwjnKsjbDMx2dRDjtoVxree9Du2a4FC0dl10XfGuN9vzE83lOseZmY/QJuPFm3KsEzbA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Wed, 23 Aug 2017 08:22:42 -0400 Message-Id: <1503490967-5559-19-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> References: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR12CA0069.namprd12.prod.outlook.com (2603:10b6:3:103::31) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ac0d075e-a632-4604-d4d5-08d4ea21b55d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:svfzHp0scNhac91nuB6Jcux/SNzg3hHOL+2ahImUrgtStJs0zwCXtM71Ll5gNepqzvL0fAsRrRdhFl3XK8PuQUNyXajnSI6I/3QeIINpf4xYwGfyNWMzuWf+UbPwnMMec466O3FkCb1WalIgjmI0jvKJrnD0OQzrSRbms9TdNSBA7NJiprf9FehZYoQktljHAzdXWhBFShmWnO4vz6PPjST4M8Q767+9HXgFBDikbg8ug99KESToTUq15/C2Y4uN; 25:oCjfEcSo1YXakfW/BIg0dQeBotj29UH1Pp9oIcqzyemP7MHqkEd/s+gyo/c9AdAJTbzA6Zm2DQsdCBDBI4c2TEkizpzafrojpzOs2JCfBYKEPH5CjIav3lx/8ylAzLhgQ6HKyvbCRXr+MfEgmV6ankj8kGfOUo1+CLts3IHh8x5r5Ge2pp+B124toabYKA6UcVrOdITTMjO+WCht09ohI9iH3XvBa1rreAuiN0j+6DBUvO+1YthwBN8EZDEYiRc5ABrvqF4S3PHr8pqWdlvAoU/OIfKIkMqSXWcVbq0tDIQv149ZFL+afIj7s/hFqRidl64BzjcC0QPb+naeLujaAw==; 31:coLf4Ioc/NQdIfuzWWudngsgvleOdDL64kdXgmYVSIQghwn66OI7QdjuqrbHL0vzTnndKZqAi4q89CIXBVV7ms2/U/w7f82PFgoJux2gTzB0YHGIO2nRpSrhBThWNuKl/hP2RguMNJKAtLpa4VCgwzwzRVIporQ+bFStIgcfzscPB2uQ28709rB7bJDZyP4DrFPaGkIFRb11/PutA9aoHF0WunB+AAGDB7VZShTY4DU= X-MS-TrafficTypeDiagnostic: DM2PR12MB0155: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:GDKLlDLA1gx7EkFQ1RHHSBhHsj7fAEx2TZ8iBRQvEJXn7zPoGHGC9tufwJA4ymSVOX/upy60pT0QtZYilJ1IuUejT0xUpltjJp3V6muASRIIWIPB0z2o4lwARhUIVDb02AT6fM7BrunGpc1penMYX6uuek+ncIhgYtjsWmInVXgj6KfAlj9XoM2MH8XOSzBzCmQnoOr4gW+WFTX1OKKeWS8q2hNh6VldYuiwzstrWOVMqOKOu0BTLYxsCMMITd9l7Th/Luki+1g9dYp+LPjWpR0y+DpKLioY+33+iR4iQo888FctFOnUDGkyBhhGsR7eELeWe6O2eFqzgWH78jxM/7z62318QJbUwoVImNBXPTsYihkU8u7jPdKP4x+TeDM+dEwpc3vVixrfmdZC8PXDGSHmhPn1EZ8iHV98I/3sf9jueAUCQr/V/a2sk485h1UP7mb3pupOsoeB4ET9JlAiJxGb4+awKJn8LlcY0BND7UHhOTVIdfjPF0Y38jN4frLF; 4:YcZ2c1Ulwzc2MzZzcqEWR071OwzAeBtrARWLVIV4H7u2W4YPZw5AhxpM48wDAih357FAiSJVc/gZlV11Lfa5IUD4mHTjy9RE7EUnqYYoQh0nrRszPBy3uL9ioAJNvyiZS+adcnf5aqY0UwVnb//Ha4iwo10oj6o/RrzPPpEkO2w2/l5IhfjpTp5co/f7YUDaXiBj4hWFSoD+h0Ht7UTOa/5qnyW3DM5Zj/2yXQ9Csd5GUZOWK2rGBIGqZPN8b33bNFCoYfXyv0lBbPo4+X2ckWxuLVd3xsuQr2TlnOpzTrRYQXnUJPFML4lZYmyWaMelPLr6Rr0yjDqmiUL+/P4nuJb8pvFKmcrdAL0caZD3QEw= X-Exchange-Antispam-Report-Test: UriScan:(20558992708506)(767451399110)(228905959029699); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0155; X-Forefront-PRVS: 040866B734 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39860400002)(189002)(199003)(575784001)(305945005)(47776003)(97736004)(101416001)(110136004)(6666003)(189998001)(478600001)(7736002)(3846002)(66066001)(5003940100001)(6116002)(6486002)(48376002)(86362001)(105586002)(2950100002)(4326008)(106356001)(36756003)(6916009)(50466002)(2906002)(50226002)(42186005)(2351001)(33646002)(53416004)(25786009)(7350300001)(81156014)(76176999)(5660300001)(68736007)(54906002)(8676002)(53936002)(50986999)(81166006)(2361001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR12MB0155; 23:bMic3gxIEjRSF5iJIasqBignxXdqlBMoki4/mlMsC?= =?us-ascii?Q?GU2Cv5V0hHSXd1u+ZiWc/5mgpDV7GwYq56fT2Dz3zC+IsWdeXVbLulFPwmBp?= =?us-ascii?Q?2KVlS/EXDs1n2TaaGnhckE2ozW5Tj7Lh7ETq0bnVeUtPK24jiayZ4FFNl/rX?= =?us-ascii?Q?Z4FmbCqmSIKWjqi115gXTeMJ+n3jUZhdv5dPfkeB+K6Y18uXJ4jva3wQmWNx?= =?us-ascii?Q?Muzwldt2ejzVjZRNuyOIFVRBHG2dLnHg+PCM4ZEklK+zFV8jhafC1CXGNQuU?= =?us-ascii?Q?yyuhdmlAxyPuED3cwplX/Jdc4DBtZITTEvkkanAqi+497kXMt3QscpeVaPcF?= =?us-ascii?Q?8jhVLRBXXzqj75IH7lNanDLjgKfnpDPrfRTOFLtRrQke35PSDmnBu42DqkVU?= =?us-ascii?Q?BBa5/8LbTRCCsHr5wqJbtqvpGypjW4KoJx7bpXWPSKOUPrcWEPj9SOl/m85z?= =?us-ascii?Q?kfnoevBuSVDFYv9HLlcVzlBOhyjTOXOI+9luwV+ZMvz03EQt2VSuwddoX0GG?= =?us-ascii?Q?inIcP9tC1p+rxGLD8kPu0LLiMfvsOxM1YwBCOW1dNK3qpiVHsl5siJlH9Uzt?= =?us-ascii?Q?o4ivQqr8jdB4A5oE22wdFRfVdTGnbEDKKGM99eDwusjIY4iH7BzdK3MNWViH?= =?us-ascii?Q?PtwHEsdqamPbBC+qCh2HZ19lyk9VO/AVD11w3TW+AhNB2xVuFNGmcm5ufoaA?= =?us-ascii?Q?2tbRUQX+wKeEbC3HMS/fIt0w4ZuQEjveyvvFbJ4V7+DeP4MR9ZohPeXA5GnH?= =?us-ascii?Q?0DwFOcDQpeC4F9AEEHUOqye61QnMneQ9Oa42908eBfqMt44eRpDlfEY2Me5G?= =?us-ascii?Q?Bm+VbluxGaJmL/bMbU8oXpDIOAECfmA1oas60cVw1QO8iktNP80xSaRjKfSy?= =?us-ascii?Q?Wu82kWLDHFcBjJK22j2w9Nek0IOiU3rqN3qN3j6/4nJG3U2FGqt9MnAHLIrh?= =?us-ascii?Q?6b5lnazbLThm5mx5ihAsYT4RbMO96mBgDlH4zhJxne0FXSAkjZenFscjIH4o?= =?us-ascii?Q?GmNH8AUKP3lDUzE4kOHmrw0MWSOM3SGageawil5wEoQ+nLn9o3jKmWofJeG7?= =?us-ascii?Q?XeLE0gF6Mm0nPphVgtCWMdQttr4DtEe933YXABZQAJm2cfxQiOFvIfTDCues?= =?us-ascii?Q?ENl6s413uR7WZ24sIvbOCUTj4neAKqRb9nhQxUV3rOcd/SyrxbQkTdc6OVDq?= =?us-ascii?Q?f+K/HByi5a+aQQ=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 6:5f4bLIWMlgE2eatFyiegLf5sKLapsa+nOtn/gxXt8xTOdarKF+EFuh3tW705DXZq0cq58kxcLuB0GrD7VknXU/TYu0iV2xpKwvv/ppTn/TP+EhVOQEVpwkquTCbabpTCVgR3Ao+tULCx2CS5B52nykGaQdW4AFrbIaTvpwdFZZj/OVgxTWLoQbXtv+d0N8LiL1d8eCoKlOvMHajcH8iwKW0YTlexvbZgwZVcLpFvXUZrd8YgNCZ/ENCb7Yu6Dqe2UcnaWwojbdcZCggoDh3cf3IJbbqRLURMpGY+ubXVAeKEEL3y48d9NM0mcVfG5wj5zHITHVMQkRONSKc7Rxa7Yg==; 5:4KlmARS2nQ1i6bRtnxUiWXYFNEJwQG2o2lJxGPylNZ76tqgDkaDHkFgiKhc/0okNZOLRDm5pStikhXANlJnPeZwjctYVHqrIuVwJn2O1UjEqCtH0cGSA5hSsJCGxDqLfSPQJNyXnlt+ENScjtl3KGw==; 24:zIZx538ofOj2jLHI+XZJupq11UUQBNB7YjhlG9Pq1MiZYq7lW3TYVBDnRSzGTiMNZU2ck0WER+BTozlFrJ6yhS81KZVK0YQbDm/y3Ae5pU4=; 7:uBP2ed7ejyDiqzpQNydgeSmrcx/t/IspHk6PitiZ6ZLCQki4JJmEeGKHB+4whazEghzemkEDemTyn/ledJq4eZZ5n0qrk/SrfA+p7Af+MnUA/WcY0ssxdwPJyh8UBi5tFCuy1q7lmEU/meWUeeFC+pzb3EIYnfFpn/RYmADZbRFf+/azZNzoVOp6PuU6JIaqRlXHwOFDwb1dqc3MU81DNm+OcXkXj2jaWQN070XdYY8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:dXbCuxrXCK3pFfbFENAWJuEZiYfDLVcC+umslAqLlIYkHuW+NDVIO1AlCxbYhAriJaTL+R66uDd2Km43aYsBCuqK9usA3qPEAtPYYNI6xbpikVFw1Esw7bCXZqH32gV1pDYYoJQWqwweGkqvBMYVU4pfWSyZG/XI0l3y6nu6iygmRQ2B49HmLW2kATnThrENHle26LHvAvE2g42UoZP8J2eXAZ9j0KZRD9Ju9P/I79abvr+Rok66dPzmmjXcPhwX X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 12:23:06.1853 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [edk2] [PATCH v3 18/23] OvmfPkg/VirtioNetDxe: map transmit buffer host address to device address X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen , Tom Lendacky , Laszlo Ersek , Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Update VirtioNetTransmit() function, to map the callers transmit buffer host address to a device address. Since the transmit buffers are returned back to caller in VirtioNetGetStatus() hence we maintain a simple list to maintain 1:1 mapping between host address to device address. The list is consulted when we return back the callers buffer after data is successfully transmitted. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh --- OvmfPkg/VirtioNetDxe/VirtioNet.h | 17 +++ OvmfPkg/VirtioNetDxe/SnpGetStatus.c | 29 ++++- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 119 ++++++++++++++++++++ OvmfPkg/VirtioNetDxe/SnpTransmit.c | 30 +++-- 4 files changed, 184 insertions(+), 11 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 3efe95a735d8..ac75bdeeb449 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -269,6 +269,23 @@ VirtioNetShutdownTx ( IN OUT VNET_DEV *Dev ); =20 +EFI_STATUS +EFIAPI +VirtioMapTxBuf ( + IN VNET_DEV *Dev, + IN EFI_PHYSICAL_ADDRESS HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress + ); + +EFI_STATUS +EFIAPI +VirtioUnmapTxBuf ( + IN VNET_DEV *Dev, + OUT EFI_PHYSICAL_ADDRESS *HostAddress, + IN EFI_PHYSICAL_ADDRESS DeviceAddress + ); + // // event callbacks // diff --git a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c b/OvmfPkg/VirtioNetDxe/Snp= GetStatus.c index 694940ea1d97..d532551456d0 100644 --- a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c +++ b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c @@ -5,6 +5,7 @@ =20 Copyright (C) 2013, Red Hat, Inc. Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Inc, All rights reserved.
=20 This program and the accompanying materials are licensed and made availa= ble under the terms and conditions of the BSD License which accompanies this @@ -47,7 +48,8 @@ @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value. @retval EFI_DEVICE_ERROR The command could not be sent to the netwo= rk - interface. + interface or failed to map TxBuf to bus ma= ster + address. @retval EFI_UNSUPPORTED This function is not supported by the netw= ork interface. =20 @@ -126,8 +128,10 @@ VirtioNetGetStatus ( *TxBuf =3D NULL; } else { - UINT16 UsedElemIdx; - UINT32 DescIdx; + UINT16 UsedElemIdx; + UINT32 DescIdx; + EFI_PHYSICAL_ADDRESS BufferAddress; + EFI_PHYSICAL_ADDRESS DeviceAddress; =20 // // fetch the first descriptor among those that the hypervisor reports @@ -141,9 +145,26 @@ VirtioNetGetStatus ( ASSERT (DescIdx < (UINT32) (2 * Dev->TxMaxPending - 1)); =20 // + // Ring descriptor contains the device address of buffer. + // Lets unmap the device address and get its corresponding + // host buffer address. + // + DeviceAddress =3D Dev->TxRing.Desc[DescIdx + 1].Addr; + Status =3D VirtioUnmapTxBuf ( + Dev, + &BufferAddress, + DeviceAddress + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto Exit; + } + + // + // // report buffer address to caller that has been enqueued by caller // - *TxBuf =3D (VOID *)(UINTN) Dev->TxRing.Desc[DescIdx + 1].Addr; + *TxBuf =3D (VOID *)(UINTN) BufferAddress; =20 // // now this descriptor can be used again to enqueue a transmit buffer diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index aeb9e6605f0d..5e1c610c4a18 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -14,10 +14,29 @@ =20 **/ =20 +#include #include =20 #include "VirtioNet.h" =20 +#define PRIVATE_TXBUF_SIGNATURE SIGNATURE_32 ('t', 'x', 'b', 'f') +typedef struct { + UINT32 Signature; + LIST_ENTRY Link; + EFI_PHYSICAL_ADDRESS HostAddress; + EFI_PHYSICAL_ADDRESS DeviceAddress; + VOID *Mapping; +} PRIVATE_TXBUF_ENTRY; +#define PRIVATE_TXBUF_FROM_LINK(a) CR (a, PRIVATE_TXBUF_ENTRY, Link, \ + PRIVATE_TXBUF_SIGNATURE) + +// +// List of Txbuf queued +// +STATIC LIST_ENTRY mTxBufMapList =3D INITIALIZE_LIST_HEAD_VARIABLE ( + mTxBufMapList + ); + /** Release RX and TX resources on the boundary of the EfiSimpleNetworkInitialized state. @@ -63,3 +82,103 @@ VirtioNetShutdownTx ( =20 FreePool (Dev->TxFreeStack); } + +EFI_STATUS +EFIAPI +VirtioMapTxBuf ( + IN VNET_DEV *Dev, + IN EFI_PHYSICAL_ADDRESS HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress + ) +{ + EFI_STATUS Status; + PRIVATE_TXBUF_ENTRY *Private; + + Private =3D AllocatePool (sizeof (*Private)); + if (Private =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Private->Signature =3D PRIVATE_TXBUF_SIGNATURE; + Private->HostAddress =3D HostAddress; + + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + (VOID *) (UINTN) Private->HostAddress, + NumberOfBytes, + &Private->DeviceAddress, + &Private->Mapping + ); + if (EFI_ERROR (Status)) { + goto FreePool; + } + + *DeviceAddress =3D Private->DeviceAddress; + + // + // Add the mapping information into internal list so that we can retrieve + // the HostAddress from Unmap(). + // + InsertTailList (&mTxBufMapList, &Private->Link); + + return EFI_SUCCESS; + +FreePool: + FreePool (Private); + return Status; +} + +EFI_STATUS +EFIAPI +VirtioUnmapTxBuf ( + IN VNET_DEV *Dev, + OUT EFI_PHYSICAL_ADDRESS *HostAddress, + IN EFI_PHYSICAL_ADDRESS DeviceAddress + ) +{ + EFI_STATUS Status; + PRIVATE_TXBUF_ENTRY *Private; + LIST_ENTRY *Link; + BOOLEAN Found; + + // + //set Private to suppress incorrect compiler/analyzer warnings + // + Private =3D NULL; + + // + // Iterate through internal txbuf list to find mapping for a given + // DeviceAddress. + // + Found =3D FALSE; + for (Link =3D GetFirstNode (&mTxBufMapList) + ; !IsNull (&mTxBufMapList, Link) + ; Link =3D GetNextNode (&mTxBufMapList, Link) + ) { + Private =3D PRIVATE_TXBUF_FROM_LINK (Link); + if (Private->DeviceAddress =3D=3D DeviceAddress) { + Found =3D TRUE; + break; + } + } + + // + // We failed to find mapping for the given DeviceAddress + // (this should never happen) + // + ASSERT (Found); + + Status =3D Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Private->Mapping= ); + if (EFI_ERROR (Status)) { + return Status; + } + + *HostAddress =3D Private->HostAddress; + + RemoveEntryList (&Private->Link); + FreePool (Private); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/VirtioNetDxe/SnpTransmit.c b/OvmfPkg/VirtioNetDxe/SnpT= ransmit.c index 7ca40d5d0650..f71953c92c99 100644 --- a/OvmfPkg/VirtioNetDxe/SnpTransmit.c +++ b/OvmfPkg/VirtioNetDxe/SnpTransmit.c @@ -55,7 +55,8 @@ @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value. @retval EFI_DEVICE_ERROR The command could not be sent to the netwo= rk - interface. + interface or failed to map the Buffer to + bus master address. @retval EFI_UNSUPPORTED This function is not supported by the netw= ork interface. =20 @@ -73,11 +74,12 @@ VirtioNetTransmit ( IN UINT16 *Protocol OPTIONAL ) { - VNET_DEV *Dev; - EFI_TPL OldTpl; - EFI_STATUS Status; - UINT16 DescIdx; - UINT16 AvailIdx; + VNET_DEV *Dev; + EFI_TPL OldTpl; + EFI_STATUS Status; + UINT16 DescIdx; + UINT16 AvailIdx; + EFI_PHYSICAL_ADDRESS DeviceAddress; =20 if (This =3D=3D NULL || BufferSize =3D=3D 0 || Buffer =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -144,10 +146,24 @@ VirtioNetTransmit ( } =20 // + // Map the transmit buffer HostAddress to a DeviceAddress + // + Status =3D VirtioMapTxBuf ( + Dev, + (EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, + BufferSize, + &DeviceAddress + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto Exit; + } + + // // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device // DescIdx =3D Dev->TxFreeStack[Dev->TxCurPending++]; - Dev->TxRing.Desc[DescIdx + 1].Addr =3D (UINTN) Buffer; + Dev->TxRing.Desc[DescIdx + 1].Addr =3D (UINTN) DeviceAddress; Dev->TxRing.Desc[DescIdx + 1].Len =3D (UINT32) BufferSize; =20 // --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel