This commit refactors how the maximum transmit queue size for
virtio-net devices is determined, making the mechanism more generic
and extensible.

Previously, virtio_net_max_tx_queue_size() contained hardcoded
checks for specific network backend types (vhost-user and
vhost-vdpa) to determine their supported maximum queue size. This
created direct dependencies and would require modifications for
every new backend that supports variable queue sizes.

To improve flexibility, a new max_tx_queue_size field is added
to the NetClientInfo structure. This allows each network backend
to advertise its supported maximum transmit queue size directly.

This change centralizes the configuration of transmit queue sizes,
simplifying the virtio-net driver and making it easier to integrate
new network backends with diverse queue size capabilities.

Signed-off-by: Laurent Vivier <lviv...@redhat.com>
---
 hw/net/virtio-net.c | 16 ++--------------
 include/net/net.h   |  1 +
 net/vhost-user.c    |  1 +
 net/vhost-vdpa.c    |  2 ++
 4 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 1367d2b581b1..2468621375e9 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -671,23 +671,11 @@ static int virtio_net_max_tx_queue_size(VirtIONet *n)
 {
     NetClientState *peer = n->nic_conf.peers.ncs[0];
 
-    /*
-     * Backends other than vhost-user or vhost-vdpa don't support max queue
-     * size.
-     */
-    if (!peer) {
+    if (!peer || !peer->info->max_tx_queue_size) {
         return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE;
     }
 
-    if (qemu_is_vhost_user(peer)) {
-        return VIRTQUEUE_MAX_SIZE;
-    }
-
-    if (peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
-        return VIRTQUEUE_MAX_SIZE;
-    }
-
-    return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE;
+    return peer->info->max_tx_queue_size;
 }
 
 static int peer_attach(VirtIONet *n, int index)
diff --git a/include/net/net.h b/include/net/net.h
index 179ffee5bd11..25dd29e07d7f 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -101,6 +101,7 @@ typedef struct NetClientInfo {
     GetVHostNet *get_vhost_net;
     GetAckedFeatures *get_acked_features;
     SaveAcketFeatures *save_acked_features;
+    int max_tx_queue_size;
 } NetClientInfo;
 
 struct NetClientState {
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 15609faedb88..89d216714c13 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -284,6 +284,7 @@ static NetClientInfo net_vhost_user_info = {
         .vhost_feature_bits = user_feature_bits,
         .get_acked_features = vhost_user_get_acked_features,
         .save_acked_features = vhost_user_save_acked_features,
+        .max_tx_queue_size = VIRTQUEUE_MAX_SIZE,
 };
 
 static gboolean net_vhost_user_watch(void *do_not_use, GIOCondition cond,
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index bd699066a3ab..4fc5d381ceef 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -434,6 +434,7 @@ static NetClientInfo net_vhost_vdpa_info = {
         .set_steering_ebpf = vhost_vdpa_set_steering_ebpf,
         .get_vhost_net = vhost_vdpa_get_vhost_net,
         .vhost_feature_bits = vdpa_feature_bits,
+        .max_tx_queue_size = VIRTQUEUE_MAX_SIZE,
 };
 
 static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index,
@@ -1291,6 +1292,7 @@ static NetClientInfo net_vhost_vdpa_cvq_info = {
     .set_steering_ebpf = vhost_vdpa_set_steering_ebpf,
     .get_vhost_net = vhost_vdpa_get_vhost_net,
     .vhost_feature_bits = vdpa_feature_bits,
+    .max_tx_queue_size = VIRTQUEUE_MAX_SIZE,
 };
 
 /*
-- 
2.49.0


Reply via email to