[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v5 04/10] virtio-net: make VirtIOFeature usable for
From: |
Stefano Garzarella |
Subject: |
[Qemu-block] [PATCH v5 04/10] virtio-net: make VirtIOFeature usable for other virtio devices |
Date: |
Mon, 18 Feb 2019 15:02:55 +0100 |
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 <address@hidden>
Signed-off-by: Stefano Garzarella <address@hidden>
---
hw/net/virtio-net.c | 31 +++++++------------------------
hw/virtio/virtio.c | 15 +++++++++++++++
include/hw/virtio/virtio.h | 15 +++++++++++++++
3 files changed, 37 insertions(+), 24 deletions(-)
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;
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
--
2.20.1
- [Qemu-block] [PATCH v5 00/10] virtio-blk: add DISCARD and WRITE_ZEROES features, Stefano Garzarella, 2019/02/18
- [Qemu-block] [PATCH v5 01/10] virtio-blk: add acct_failed param to virtio_blk_handle_rw_error(), Stefano Garzarella, 2019/02/18
- [Qemu-block] [PATCH v5 02/10] virtio-blk: add host_features field in VirtIOBlock, Stefano Garzarella, 2019/02/18
- [Qemu-block] [PATCH v5 03/10] virtio-blk: add "discard" and "write-zeroes" properties, Stefano Garzarella, 2019/02/18
- [Qemu-block] [PATCH v5 04/10] virtio-net: make VirtIOFeature usable for other virtio devices,
Stefano Garzarella <=
- [Qemu-block] [PATCH v5 05/10] virtio-blk: set config size depending on the features enabled, Stefano Garzarella, 2019/02/18
- [Qemu-block] [PATCH v5 07/10] tests/virtio-blk: change assert on data_size in virtio_blk_request(), Stefano Garzarella, 2019/02/18
- [Qemu-block] [PATCH v5 06/10] virtio-blk: add DISCARD and WRITE_ZEROES features, Stefano Garzarella, 2019/02/18
- [Qemu-block] [PATCH v5 08/10] tests/virtio-blk: add virtio_blk_fix_dwz_hdr() function, Stefano Garzarella, 2019/02/18
- [Qemu-block] [PATCH v5 09/10] tests/virtio-blk: add test for WRITE_ZEROES command, Stefano Garzarella, 2019/02/18
- [Qemu-block] [PATCH v5 10/10] tests/virtio-blk: add test for DISCARD command, Stefano Garzarella, 2019/02/18