qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PULL 21/27] virtio-net: make VirtIOFeature usable for other virtio devices
Date: Fri, 22 Feb 2019 14:07:50 +0000	[thread overview]
Message-ID: <20190222140756.29834-22-stefanha@redhat.com> (raw)
In-Reply-To: <20190222140756.29834-1-stefanha@redhat.com>

From: Stefano Garzarella <sgarzare@redhat.com>

In order to use VirtIOFeature also in other virtio devices, we move
its declaration and the endof() macro (renamed in virtio_endof())
in virtio.h.
We add virtio_feature_get_config_size() function to iterate the array
of VirtIOFeature and to return the config size depending on the
features enabled. (as virtio_net_set_config_size() did)

Suggested-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-id: 20190221103314.58500-5-sgarzare@redhat.com
Message-Id: <20190221103314.58500-5-sgarzare@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/hw/virtio/virtio.h | 15 +++++++++++++++
 hw/net/virtio-net.c        | 31 +++++++------------------------
 hw/virtio/virtio.c         | 15 +++++++++++++++
 3 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 9c1fa07d6d..ce9516236a 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -37,6 +37,21 @@ static inline hwaddr vring_align(hwaddr addr,
     return QEMU_ALIGN_UP(addr, align);
 }
 
+/*
+ * Calculate the number of bytes up to and including the given 'field' of
+ * 'container'.
+ */
+#define virtio_endof(container, field) \
+    (offsetof(container, field) + sizeof_field(container, field))
+
+typedef struct VirtIOFeature {
+    uint64_t flags;
+    size_t end;
+} VirtIOFeature;
+
+size_t virtio_feature_get_config_size(VirtIOFeature *features,
+                                      uint64_t host_features);
+
 typedef struct VirtQueue VirtQueue;
 
 #define VIRTQUEUE_MAX_SIZE 1024
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 3f319ef723..6e6b146022 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -82,29 +82,17 @@ static inline __virtio16 *virtio_net_rsc_ext_num_dupacks(
 
 #endif
 
-/*
- * Calculate the number of bytes up to and including the given 'field' of
- * 'container'.
- */
-#define endof(container, field) \
-    (offsetof(container, field) + sizeof_field(container, field))
-
-typedef struct VirtIOFeature {
-    uint64_t flags;
-    size_t end;
-} VirtIOFeature;
-
 static VirtIOFeature feature_sizes[] = {
     {.flags = 1ULL << VIRTIO_NET_F_MAC,
-     .end = endof(struct virtio_net_config, mac)},
+     .end = virtio_endof(struct virtio_net_config, mac)},
     {.flags = 1ULL << VIRTIO_NET_F_STATUS,
-     .end = endof(struct virtio_net_config, status)},
+     .end = virtio_endof(struct virtio_net_config, status)},
     {.flags = 1ULL << VIRTIO_NET_F_MQ,
-     .end = endof(struct virtio_net_config, max_virtqueue_pairs)},
+     .end = virtio_endof(struct virtio_net_config, max_virtqueue_pairs)},
     {.flags = 1ULL << VIRTIO_NET_F_MTU,
-     .end = endof(struct virtio_net_config, mtu)},
+     .end = virtio_endof(struct virtio_net_config, mtu)},
     {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX,
-     .end = endof(struct virtio_net_config, duplex)},
+     .end = virtio_endof(struct virtio_net_config, duplex)},
     {}
 };
 
@@ -2580,15 +2568,10 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
 
 static void virtio_net_set_config_size(VirtIONet *n, uint64_t host_features)
 {
-    int i, config_size = 0;
     virtio_add_feature(&host_features, VIRTIO_NET_F_MAC);
 
-    for (i = 0; feature_sizes[i].flags != 0; i++) {
-        if (host_features & feature_sizes[i].flags) {
-            config_size = MAX(feature_sizes[i].end, config_size);
-        }
-    }
-    n->config_size = config_size;
+    n->config_size = virtio_feature_get_config_size(feature_sizes,
+                                                    host_features);
 }
 
 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index a1ff647a66..2626a895cb 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2036,6 +2036,21 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)
     return ret;
 }
 
+size_t virtio_feature_get_config_size(VirtIOFeature *feature_sizes,
+                                      uint64_t host_features)
+{
+    size_t config_size = 0;
+    int i;
+
+    for (i = 0; feature_sizes[i].flags != 0; i++) {
+        if (host_features & feature_sizes[i].flags) {
+            config_size = MAX(feature_sizes[i].end, config_size);
+        }
+    }
+
+    return config_size;
+}
+
 int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
 {
     int i, ret;
-- 
2.20.1

  parent reply	other threads:[~2019-02-22 14:09 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 14:07 [Qemu-devel] [PULL 00/27] Block patches Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 01/27] block: enhance QEMUIOVector structure Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 02/27] block/io: use qemu_iovec_init_buf Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 03/27] block/block-backend: use QEMU_IOVEC_INIT_BUF Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 04/27] block/backup: use qemu_iovec_init_buf Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 05/27] block/commit: use QEMU_IOVEC_INIT_BUF Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 06/27] block/stream: " Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 07/27] block/parallels: " Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 08/27] block/qcow: use qemu_iovec_init_buf Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 09/27] block/qcow2: " Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 10/27] block/qed: " Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 11/27] block/vmdk: " Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 12/27] qemu-img: " Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 13/27] migration/block: " Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 14/27] tests/test-bdrv-drain: use QEMU_IOVEC_INIT_BUF Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 15/27] hw/ide: drop iov field from IDEState Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 16/27] hw/ide: drop iov field from IDEBufferedRequest Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 17/27] hw/ide: drop iov field from IDEDMA Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 18/27] virtio-blk: add acct_failed param to virtio_blk_handle_rw_error() Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 19/27] virtio-blk: add host_features field in VirtIOBlock Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 20/27] virtio-blk: add "discard" and "write-zeroes" properties Stefan Hajnoczi
2019-02-22 14:07 ` Stefan Hajnoczi [this message]
2019-02-22 14:07 ` [Qemu-devel] [PULL 22/27] virtio-blk: set config size depending on the features enabled Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 23/27] virtio-blk: add DISCARD and WRITE_ZEROES features Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 24/27] tests/virtio-blk: change assert on data_size in virtio_blk_request() Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 25/27] tests/virtio-blk: add virtio_blk_fix_dwz_hdr() function Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 26/27] tests/virtio-blk: add test for WRITE_ZEROES command Stefan Hajnoczi
2019-02-22 14:07 ` [Qemu-devel] [PULL 27/27] tests/virtio-blk: add test for DISCARD command Stefan Hajnoczi
2019-02-26 14:06 ` [Qemu-devel] [PULL 00/27] Block patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190222140756.29834-22-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).