From patchwork Wed Apr 4 12:53:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Xu X-Patchwork-Id: 10322579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4311A602C8 for ; Wed, 4 Apr 2018 12:57:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3397028E95 for ; Wed, 4 Apr 2018 12:57:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 283F728E98; Wed, 4 Apr 2018 12:57:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A26AD28E95 for ; Wed, 4 Apr 2018 12:57:23 +0000 (UTC) Received: from localhost ([::1]:56257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3hyb-0002Ux-Rn for patchwork-qemu-devel@patchwork.kernel.org; Wed, 04 Apr 2018 08:57:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3hx9-0001De-5A for qemu-devel@nongnu.org; Wed, 04 Apr 2018 08:55:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f3hwz-0005XJ-KS for qemu-devel@nongnu.org; Wed, 04 Apr 2018 08:55:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44928 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f3hwz-0005WK-1x for qemu-devel@nongnu.org; Wed, 04 Apr 2018 08:55:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A132140201A4; Wed, 4 Apr 2018 12:55:38 +0000 (UTC) Received: from localhost.localdomain (dhcp-14-122.nay.redhat.com [10.66.14.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68945215CDAF; Wed, 4 Apr 2018 12:55:36 +0000 (UTC) From: wexu@redhat.com To: wexu@redhat.com, jasowang@redhat.com, mst@redhat.com, tiwei.bie@intel.com, jfreimann@redhat.com, qemu-devel@nongnu.org Date: Wed, 4 Apr 2018 20:53:57 +0800 Message-Id: <1522846444-31725-2-git-send-email-wexu@redhat.com> In-Reply-To: <1522846444-31725-1-git-send-email-wexu@redhat.com> References: <1522846444-31725-1-git-send-email-wexu@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 04 Apr 2018 12:55:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 04 Apr 2018 12:55:38 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'wexu@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/8] virtio: feature bit, data structure for packed ring X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Wei Xu Only minimum definitions from the spec are included for prototype. Signed-off-by: Wei Xu --- hw/virtio/virtio.c | 47 +++++++++++++++++++++++--- include/hw/virtio/virtio.h | 12 ++++++- include/standard-headers/linux/virtio_config.h | 2 ++ 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 006d3d1..9a6bfe7 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -39,6 +39,14 @@ typedef struct VRingDesc uint16_t next; } VRingDesc; +typedef struct VRingDescPacked +{ + uint64_t addr; + uint32_t len; + uint16_t id; + uint16_t flags; +} VRingDescPacked; + typedef struct VRingAvail { uint16_t flags; @@ -61,9 +69,18 @@ typedef struct VRingUsed typedef struct VRingMemoryRegionCaches { struct rcu_head rcu; - MemoryRegionCache desc; - MemoryRegionCache avail; - MemoryRegionCache used; + union { + struct { + MemoryRegionCache desc; + MemoryRegionCache avail; + MemoryRegionCache used; + }; + struct { + MemoryRegionCache desc_packed; + MemoryRegionCache driver; + MemoryRegionCache device; + }; + }; } VRingMemoryRegionCaches; typedef struct VRing @@ -77,10 +94,31 @@ typedef struct VRing VRingMemoryRegionCaches *caches; } VRing; +typedef struct VRingPackedDescEvent { + uint16_t desc_event_off:15, + desc_event_wrap:1; + uint16_t desc_event_flags:2; +} VRingPackedDescEvent ; + +typedef struct VRingPacked +{ + unsigned int num; + unsigned int num_default; + unsigned int align; + hwaddr desc; + hwaddr driver; + hwaddr device; + VRingMemoryRegionCaches *caches; +} VRingPacked; + struct VirtQueue { - VRing vring; + union { + struct VRing vring; + struct VRingPacked packed; + }; + uint8_t wrap_counter:1; /* Next head to pop */ uint16_t last_avail_idx; @@ -1220,6 +1258,7 @@ void virtio_reset(void *opaque) vdev->vq[i].vring.num = vdev->vq[i].vring.num_default; vdev->vq[i].inuse = 0; virtio_virtqueue_reset_region_cache(&vdev->vq[i]); + vdev->vq[i].wrap_counter = 1; } } diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 098bdaa..563e88e 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -46,6 +46,14 @@ typedef struct VirtQueueElement unsigned int index; unsigned int out_num; unsigned int in_num; + + /* Number of descriptors used by packed ring */ + uint16_t count; + uint8_t wrap_counter:1; + /* FIXME: Length of every used buffer for a descriptor, + move to dynamical allocating due to out/in sgs numbers */ + uint32_t len[VIRTQUEUE_MAX_SIZE]; + hwaddr *in_addr; hwaddr *out_addr; struct iovec *in_sg; @@ -262,7 +270,9 @@ typedef struct VirtIORNGConf VirtIORNGConf; DEFINE_PROP_BIT64("any_layout", _state, _field, \ VIRTIO_F_ANY_LAYOUT, true), \ DEFINE_PROP_BIT64("iommu_platform", _state, _field, \ - VIRTIO_F_IOMMU_PLATFORM, false) + VIRTIO_F_IOMMU_PLATFORM, false), \ + DEFINE_PROP_BIT64("ring_packed", _state, _field, \ + VIRTIO_F_RING_PACKED, true) hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_avail_addr(VirtIODevice *vdev, int n); diff --git a/include/standard-headers/linux/virtio_config.h b/include/standard-headers/linux/virtio_config.h index b777069..6ee5529 100644 --- a/include/standard-headers/linux/virtio_config.h +++ b/include/standard-headers/linux/virtio_config.h @@ -71,4 +71,6 @@ * this is for compatibility with legacy systems. */ #define VIRTIO_F_IOMMU_PLATFORM 33 + +#define VIRTIO_F_RING_PACKED 34 #endif /* _LINUX_VIRTIO_CONFIG_H */