Patchwork [RFC,7/9] hw/virtio-net.c: Add virtio-net device.

login
register
mail settings
Submitter Evgeny Voevodin
Date April 25, 2012, 5:54 a.m.
Message ID <1335333257-5128-8-git-send-email-e.voevodin@samsung.com>
Download mbox | patch
Permalink /patch/154810/
State New
Headers show

Comments

Evgeny Voevodin - April 25, 2012, 5:54 a.m.
Signed-off-by: Evgeny Voevodin <e.voevodin@samsung.com>
---
 hw/virtio-net.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-net.h |   11 +++++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index bc5e3a8..febf384 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -13,6 +13,7 @@ 
 
 #include "iov.h"
 #include "virtio.h"
+#include "virtio-transport.h"
 #include "net.h"
 #include "net/checksum.h"
 #include "net/tap.h"
@@ -1076,3 +1077,48 @@  void virtio_net_exit(VirtIODevice *vdev)
     qemu_del_vlan_client(&n->nic->nc);
     virtio_cleanup(&n->vdev);
 }
+
+/******************** VirtIONet Device **********************/
+
+static int virtio_netdev_init(DeviceState *dev)
+{
+    VirtIODevice *vdev;
+    VirtIONetState *proxy = VIRTIO_NET_FROM_QDEV(dev);
+    vdev = virtio_net_init(dev, &proxy->nic, &proxy->net);
+    if (!vdev) {
+        return -1;
+    }
+    return virtio_init_transport(dev, vdev);
+}
+
+static Property virtio_net_properties[] = {
+    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_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;
+    dc->bus_info = &virtio_transport_bus_info;
+}
+
+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..74a55c8 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -14,6 +14,7 @@ 
 #ifndef _QEMU_VIRTIO_NET_H
 #define _QEMU_VIRTIO_NET_H
 
+#include "sysbus.h"
 #include "virtio.h"
 #include "net.h"
 #include "pci.h"
@@ -187,4 +188,14 @@  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;
+} VirtIONetState;
+
+#define VIRTIO_NET_FROM_QDEV(dev) DO_UPCAST(VirtIONetState, qdev, dev)
+
 #endif