diff mbox series

[RFC,3/5] vhost-net: Add support for presetup

Message ID 20230918044932.1433744-4-yajunw@nvidia.com (mailing list archive)
State New, archived
Headers show
Series virtio-net: Introduce LM early load | expand

Commit Message

Yajun Wu Sept. 18, 2023, 4:49 a.m. UTC
Introduce New API vhost_net_presetup to send virtio net device
configuration to backend in LM setup.

Mainly calling vhost_dev_presetup, then sending out vring enable.

Signed-off-by: Yajun Wu <yajunw@nvidia.com>
Reviewed-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 hw/net/vhost_net.c      | 40 ++++++++++++++++++++++++++++++++++++++++
 include/net/vhost_net.h |  3 +++
 2 files changed, 43 insertions(+)
diff mbox series

Patch

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 6b958d6363..dcb818ccf1 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -345,6 +345,46 @@  static void vhost_net_stop_one(struct vhost_net *net,
     vhost_dev_disable_notifiers(&net->dev, dev);
 }
 
+int vhost_net_presetup(VirtIODevice *dev, NetClientState *ncs,
+                    int data_queue_pairs, int cvq)
+{
+    VirtIONet *n = VIRTIO_NET(dev);
+    int nvhosts = data_queue_pairs + cvq;
+    struct vhost_net *net;
+    int r = 0, i, index_end = data_queue_pairs * 2;
+    NetClientState *peer;
+
+    if (cvq) {
+        index_end += 1;
+    }
+
+    for (i = 0; i < nvhosts; i++) {
+        if (i < data_queue_pairs) {
+            peer = qemu_get_peer(ncs, i);
+        } else { /* Control Virtqueue */
+            peer = qemu_get_peer(ncs, n->max_queue_pairs);
+        }
+
+        net = get_vhost_net(peer);
+        vhost_net_set_vq_index(net, i * 2, index_end);
+
+        r = vhost_dev_presetup(&net->dev, dev);
+        if (r < 0) {
+            return r;
+        }
+
+        if (peer->vring_enable) {
+            /* restore vring enable state */
+            r = vhost_set_vring_enable(peer, peer->vring_enable);
+            if (r < 0) {
+                return r;
+            }
+        }
+    }
+
+    return r;
+}
+
 int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
                     int data_queue_pairs, int cvq)
 {
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index c37aba35e6..2c9020c5a2 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -26,6 +26,9 @@  int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
                     int data_queue_pairs, int cvq);
 
+int vhost_net_presetup(VirtIODevice *dev, NetClientState *ncs,
+                           int data_queue_pairs, int cvq);
+
 void vhost_net_cleanup(VHostNetState *net);
 
 uint64_t vhost_net_get_features(VHostNetState *net, uint64_t features);