qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC 2/2] virtio-net: Implement VIRTIO_NET_F_STANDBY featur


From: Sameeh Jubran
Subject: [Qemu-devel] [RFC 2/2] virtio-net: Implement VIRTIO_NET_F_STANDBY feature
Date: Thu, 25 Oct 2018 17:06:31 +0300

From: Sameeh Jubran <address@hidden>

Signed-off-by: Sameeh Jubran <address@hidden>
---
 hw/net/virtio-net.c            | 25 +++++++++++++++++++++++++
 include/hw/virtio/virtio-net.h |  5 +++++
 2 files changed, 30 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index f154756e85..f478445cbd 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -686,6 +686,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, 
uint64_t features)
 {
     VirtIONet *n = VIRTIO_NET(vdev);
     int i;
+    Error *err;
 
     if (n->mtu_bypass_backend &&
             !virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_MTU)) {
@@ -721,6 +722,10 @@ static void virtio_net_set_features(VirtIODevice *vdev, 
uint64_t features)
     } else {
         memset(n->vlans, 0xff, MAX_VLAN >> 3);
     }
+
+    if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) {
+        qdev_unhide(n->net_conf.primary_id_str, n->primary_parent_bus, &err);
+    }
 }
 
 static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
@@ -1946,6 +1951,20 @@ void virtio_net_set_netclient_name(VirtIONet *n, const 
char *name,
     n->netclient_type = g_strdup(type);
 }
 
+static void virtio_net_primary_should_be_hidden(DeviceListener *listener,const 
char *dev_id, BusState *bus, bool *res)
+{
+   VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
+    if (!strcmp(n->net_conf.primary_id_str ,dev_id) && bus)
+    {
+        printf("net_confnet_confnet_confnet_confnet_conf\n");
+        n->host_features |= (1ULL << VIRTIO_NET_F_STANDBY);
+        n->primary_parent_bus = bus;
+        *res = true;
+        return;
+    }
+    *res = false;
+}
+
 static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -1976,6 +1995,11 @@ static void virtio_net_device_realize(DeviceState *dev, 
Error **errp)
         n->host_features |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX);
     }
 
+    if (n->net_conf.primary_id_str) {
+        n->primary_listener.should_be_hidden = 
virtio_net_primary_should_be_hidden;
+        device_listener_register(&n->primary_listener);
+    }
+
     virtio_net_set_config_size(n, n->host_features);
     virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
 
@@ -2198,6 +2222,7 @@ static Property virtio_net_properties[] = {
                      true),
     DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN),
     DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str),
+    DEFINE_PROP_STRING("primary", VirtIONet, net_conf.primary_id_str),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 4d7f3c82ca..6aca93e461 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -42,6 +42,7 @@ typedef struct virtio_net_conf
     int32_t speed;
     char *duplex_str;
     uint8_t duplex;
+    char *primary_id_str;
 } virtio_net_conf;
 
 /* Maximum packet size we can receive from tap device: header + 64k */
@@ -103,9 +104,13 @@ typedef struct VirtIONet {
     int announce_counter;
     bool needs_vnet_hdr_swap;
     bool mtu_bypass_backend;
+    BusState *primary_parent_bus;
+    DeviceListener primary_listener;
 } VirtIONet;
 
 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
                                    const char *type);
+void virtio_net_register_primary_device(DeviceState *vdev, DeviceState *pdev);
+
 
 #endif
-- 
2.17.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]