Patchwork [8/9] virtio net: enable dataplane for virtio net

login
register
mail settings
Submitter pingfan liu
Date Feb. 21, 2013, 12:54 p.m.
Message ID <1361451293-5181-9-git-send-email-qemulist@gmail.com>
Download mbox | patch
Permalink /patch/222293/
State New
Headers show

Comments

pingfan liu - Feb. 21, 2013, 12:54 p.m.
From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>

Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 hw/virtio-net.c |   38 ++++++++++++++++++++++++++++++++++++++
 hw/virtio-net.h |    3 +++
 hw/virtio-pci.c |    2 +-
 3 files changed, 42 insertions(+), 1 deletions(-)

Patch

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 6bf4a40..d9d6c10 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -98,10 +98,32 @@  static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
     }
 }
 
+#ifdef CONFIG_VIRTIO_NET_DATA_PLANE
+static void virtio_net_dataplane_status(VirtIONet *n, uint8_t status)
+{
+    if (!!n->dp_start == virtio_net_started(n, status) &&
+                              !n->nic->nc.peer->link_down) {
+        return;
+    }
+
+    if (!n->dp_start) {
+        virtnet_dataplane_start(n);
+        n->dp_start = true;
+    } else {
+        virtnet_dataplane_stop(n);
+        n->dp_start = false;
+    }
+}
+#endif
+
 static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
 {
     VirtIONet *n = to_virtio_net(vdev);
 
+#ifdef CONFIG_VIRTIO_NET_DATA_PLANE
+    virtio_net_dataplane_status(n, status);
+#endif
+
     virtio_net_vhost_status(n, status);
 
     if (!n->tx_waiting) {
@@ -422,6 +444,11 @@  static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIONet *n = to_virtio_net(vdev);
 
+#ifdef CONFIG_VIRTIO_NET_DATA_PLANE
+    if (n->dp_start) {
+        return;
+    }
+#endif
     qemu_flush_queued_packets(&n->nic->nc);
 }
 
@@ -762,6 +789,11 @@  static void virtio_net_handle_tx_bh(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIONet *n = to_virtio_net(vdev);
 
+#ifdef CONFIG_VIRTIO_NET_DATA_PLANE
+    if (n->dp_start) {
+        return;
+    }
+#endif
     if (unlikely(n->tx_waiting)) {
         return;
     }
@@ -1034,6 +1066,9 @@  VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
 
     add_boot_device_path(conf->bootindex, dev, "/ethernet-phy@0");
 
+#ifdef CONFIG_VIRTIO_NET_DATA_PLANE
+    virtnet_dataplane_create(n);
+#endif
     return &n->vdev;
 }
 
@@ -1060,4 +1095,7 @@  void virtio_net_exit(VirtIODevice *vdev)
 
     qemu_del_net_client(&n->nic->nc);
     virtio_cleanup(&n->vdev);
+#ifdef CONFIG_VIRTIO_NET_DATA_PLANE
+    virtnet_dataplane_destroy(n);
+#endif
 }
diff --git a/hw/virtio-net.h b/hw/virtio-net.h
index ed91a02..4370ed3 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -218,6 +218,9 @@  void virtio_net_cleanup(NetClientState *nc);
 
 #ifdef CONFIG_VIRTIO_NET_DATA_PLANE
 void virtnet_dataplane_create(VirtIONet *n);
+void virtnet_dataplane_start(VirtIONet *n);
+void virtnet_dataplane_stop(VirtIONet *n);
+void virtnet_dataplane_destroy(VirtIONet *n);
 #endif
 
 #endif
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index c7f0c4d..3c478d7 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -969,7 +969,7 @@  static TypeInfo virtio_blk_info = {
 };
 
 static Property virtio_net_properties[] = {
-    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
     DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
     DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),