qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jesse Larrew <jlarrew@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: jasowang@redhat.com, Jesse Larrew <jlarrew@linux.vnet.ibm.com>,
	mdroth@linux.vnet.ibm.com, fred.konrad@greensocs.com
Subject: [Qemu-devel] [PATCH 2/3] virtio-net: implement bus_plugged()
Date: Tue,  4 Jun 2013 11:22:44 -0500	[thread overview]
Message-ID: <1370362965-3937-3-git-send-email-jlarrew@linux.vnet.ibm.com> (raw)
In-Reply-To: <1370362965-3937-1-git-send-email-jlarrew@linux.vnet.ibm.com>

Use the new bus_plugged() callback to calculate and (if necessary) resize
the config struct based on the requested host_features. This will help to
keep the size of the config struct as small as possible, which will help
prevent it from requiring a larger BAR size as future features are added.

Signed-off-by: Jesse Larrew <jlarrew@linux.vnet.ibm.com>
---
 hw/net/virtio-net.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 3a6829c..e09288f 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -21,6 +21,7 @@
 #include "hw/virtio/virtio-net.h"
 #include "net/vhost_net.h"
 #include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-pci.h"
 
 #define VIRTIO_NET_VM_VERSION    11
 
@@ -1322,6 +1323,7 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
 
 void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     int i, config_size = 0;
     host_features |= (1 << VIRTIO_NET_F_MAC);
     for (i = 0; feature_sizes[i].flags != 0; i++) {
@@ -1330,6 +1332,21 @@ void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features)
         }
     }
     n->config_size = config_size;
+    assert(config_size != 0);
+    if (config_size != vdev->config_len) {
+        vdev->config = g_realloc(vdev->config, config_size);
+        vdev->config_len = config_size;
+    }
+}
+
+static void virtio_net_bus_plugged(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    BusState *qbus = BUS(qdev_get_parent_bus(qdev));
+    VirtIOPCIProxy *proxy = VIRTIO_PCI(qbus->parent);
+    VirtIONet *n = VIRTIO_NET(vdev);
+
+    virtio_net_set_config_size(n, proxy->host_features);
 }
 
 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
@@ -1515,6 +1532,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
     vdc->set_status = virtio_net_set_status;
     vdc->guest_notifier_mask = virtio_net_guest_notifier_mask;
     vdc->guest_notifier_pending = virtio_net_guest_notifier_pending;
+    vdc->bus_plugged = virtio_net_bus_plugged;
 }
 
 static const TypeInfo virtio_net_info = {
-- 
1.7.11.7

  parent reply	other threads:[~2013-06-04 16:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-04 16:22 [Qemu-devel] [PATCH 0/3] Notify devices when a bus is attached Jesse Larrew
2013-06-04 16:22 ` [Qemu-devel] [PATCH 1/3] virtio: add bus_plugged() callback to VirtioDeviceClass Jesse Larrew
2013-06-04 17:35   ` Andreas Färber
2013-06-04 20:02     ` Jesse Larrew
2013-06-05 15:18       ` Frederic Konrad
2013-06-05 15:09     ` Frederic Konrad
2013-06-04 16:22 ` Jesse Larrew [this message]
2013-06-04 16:22 ` [Qemu-devel] [PATCH 3/3] virtio-net: revert MAC address workaround Jesse Larrew

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1370362965-3937-3-git-send-email-jlarrew@linux.vnet.ibm.com \
    --to=jlarrew@linux.vnet.ibm.com \
    --cc=fred.konrad@greensocs.com \
    --cc=jasowang@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).