From patchwork Mon Mar 14 12:53:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 63818 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp18145lbc; Mon, 14 Mar 2016 05:54:05 -0700 (PDT) X-Received: by 10.66.120.202 with SMTP id le10mr37595793pab.155.1457960043068; Mon, 14 Mar 2016 05:54:03 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id hq1si3619579pac.56.2016.03.14.05.54.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Mar 2016 05:54:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0F34A1A1FB9; Mon, 14 Mar 2016 05:54:13 -0700 (PDT) X-Original-To: edk2-devel@ml01.01.org Delivered-To: edk2-devel@ml01.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A296E1A1E63 for ; Mon, 14 Mar 2016 05:54:11 -0700 (PDT) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 6E04B6E791; Mon, 14 Mar 2016 12:53:53 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-101.phx2.redhat.com [10.3.113.101]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2ECraIO012537; Mon, 14 Mar 2016 08:53:52 -0400 From: Laszlo Ersek To: edk2-devel@ml01.01.org Date: Mon, 14 Mar 2016 13:53:26 +0100 Message-Id: <1457960012-29481-10-git-send-email-lersek@redhat.com> In-Reply-To: <1457960012-29481-1-git-send-email-lersek@redhat.com> References: <56E6B2D9.5010507@redhat.com> <1457960012-29481-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Cc: Jordan Justen , Ard Biesheuvel Subject: [edk2] [wave 3 PATCH 09/15] OvmfPkg: VirtioNetDxe: adapt feature negotiation to virtio-1.0 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Relative to virtio-0.9.5, virtio-1.0 reverses the order of queue discovery and feature negotiation. In virtio-1.0, feature negotiation has to complete first, and the device can also reject a self-inconsistent feature request through the new VSTAT_FEATURES_OK status bit. (For example if the driver requests a higher level feature but clears a prerequisite feature.) Furthermore, we retain the VIRTIO_F_VERSION_1 feature bit if the VIRTIO_DEVICE_PROTOCOL provider has high enough revision. Cc: Ard Biesheuvel Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/VirtioNetDxe/SnpInitialize.c | 23 ++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) -- 1.8.3.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c index f06b0a5a5742..38012a0df8d6 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -413,14 +413,27 @@ VirtioNetInitialize ( goto DeviceFailed; } ASSERT (Features & VIRTIO_NET_F_MAC); ASSERT (Dev->Snm.MediaPresentSupported == !!(Features & VIRTIO_NET_F_STATUS)); + Features &= VIRTIO_NET_F_MAC | VIRTIO_NET_F_STATUS | VIRTIO_F_VERSION_1; + + // + // In virtio-1.0, feature negotiation is expected to complete before queue + // discovery, and the device can also reject the selected set of features. + // + if (Dev->VirtIo->Revision >= VIRTIO_SPEC_REVISION (1, 0, 0)) { + Status = Virtio10WriteFeatures (Dev->VirtIo, Features, &NextDevStat); + if (EFI_ERROR (Status)) { + goto DeviceFailed; + } + } + // // step 4b, 4c -- allocate and report virtqueues // Status = VirtioNetInitRing (Dev, VIRTIO_NET_Q_RX, &Dev->RxRing); if (EFI_ERROR (Status)) { goto DeviceFailed; } @@ -429,18 +442,20 @@ VirtioNetInitialize ( if (EFI_ERROR (Status)) { goto ReleaseRxRing; } // // step 5 -- keep only the features we want // - Features &= VIRTIO_NET_F_MAC | VIRTIO_NET_F_STATUS; - Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features); - if (EFI_ERROR (Status)) { - goto ReleaseTxRing; + if (Dev->VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) { + Features &= ~(UINT64)VIRTIO_F_VERSION_1; + Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features); + if (EFI_ERROR (Status)) { + goto ReleaseTxRing; + } } // // step 6 -- virtio-net initialization complete // NextDevStat |= VSTAT_DRIVER_OK; Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);