Signed-off-by: Evgeny Voevodin <e.voevo...@samsung.com>
---
 hw/virtio-net.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-net.h |   16 +++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index b1998b2..b7cfb1c 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -13,6 +13,8 @@
 
 #include "iov.h"
 #include "virtio.h"
+#include "virtio-transport.h"
+#include "virtio-pci.h"
 #include "net.h"
 #include "net/checksum.h"
 #include "net/tap.h"
@@ -1080,3 +1082,60 @@ void virtio_net_exit(VirtIODevice *vdev)
     qemu_del_net_client(&n->nic->nc);
     virtio_cleanup(&n->vdev);
 }
+
+/******************** VirtIONet Device **********************/
+
+static int virtio_netdev_init(DeviceState *dev)
+{
+    VirtIODevice *vdev;
+    VirtIONetState *s = VIRTIO_NET_FROM_QDEV(dev);
+
+    assert(s->trl != NULL);
+
+    vdev = virtio_net_init(dev, &s->nic, &s->net);
+
+    /* Pass default host_features to transport */
+    s->trl->host_features = s->host_features;
+
+    if (virtio_call_backend_init_cb(dev, s->trl, vdev) != 0) {
+        return -1;
+    }
+
+    /* Binding should be ready here, let's get final features */
+    if (vdev->binding->get_features) {
+       s->host_features = vdev->binding->get_features(vdev->binding_opaque);
+    }
+    return 0;
+}
+
+static Property virtio_net_properties[] = {
+    DEFINE_VIRTIO_NET_FEATURES(VirtIONetState, host_features),
+    DEFINE_NIC_PROPERTIES(VirtIONetState, nic),
+    DEFINE_PROP_UINT32("x-txtimer", VirtIONetState, net.txtimer,
+            TX_TIMER_INTERVAL),
+    DEFINE_PROP_INT32("x-txburst", VirtIONetState, net.txburst, TX_BURST),
+    DEFINE_PROP_STRING("tx", VirtIONetState, net.tx),
+    DEFINE_PROP_TRANSPORT("transport", VirtIONetState, trl),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_net_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->init = virtio_netdev_init;
+    dc->props = virtio_net_properties;
+}
+
+static TypeInfo virtio_net_info = {
+    .name = "virtio-net",
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIONetState),
+    .class_init = virtio_net_class_init,
+};
+
+static void virtio_net_register_types(void)
+{
+    type_register_static(&virtio_net_info);
+}
+
+type_init(virtio_net_register_types)
diff --git a/hw/virtio-net.h b/hw/virtio-net.h
index 36aa463..8dd49d3 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -14,7 +14,9 @@
 #ifndef _QEMU_VIRTIO_NET_H
 #define _QEMU_VIRTIO_NET_H
 
+#include "sysbus.h"
 #include "virtio.h"
+#include "virtio-transport.h"
 #include "net.h"
 #include "pci.h"
 
@@ -187,4 +189,18 @@ struct virtio_net_ctrl_mac {
         DEFINE_PROP_BIT("ctrl_rx", _state, _field, VIRTIO_NET_F_CTRL_RX, 
true), \
         DEFINE_PROP_BIT("ctrl_vlan", _state, _field, VIRTIO_NET_F_CTRL_VLAN, 
true), \
         DEFINE_PROP_BIT("ctrl_rx_extra", _state, _field, 
VIRTIO_NET_F_CTRL_RX_EXTRA, true)
+
+typedef struct {
+    DeviceState qdev;
+    /* virtio-net */
+    NICConf nic;
+    virtio_net_conf net;
+
+    uint32_t host_features;
+
+    VirtIOTransportLink *trl;
+} VirtIONetState;
+
+#define VIRTIO_NET_FROM_QDEV(dev) DO_UPCAST(VirtIONetState, qdev, dev)
+
 #endif
-- 
1.7.9.5


Reply via email to