aboutsummaryrefslogtreecommitdiff
path: root/hw/net/virtio-net.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/net/virtio-net.c')
-rw-r--r--hw/net/virtio-net.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 6e6b146022..38b8974144 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -21,12 +21,14 @@
#include "qemu/timer.h"
#include "hw/virtio/virtio-net.h"
#include "net/vhost_net.h"
+#include "net/announce.h"
#include "hw/virtio/virtio-bus.h"
#include "qapi/error.h"
#include "qapi/qapi-events-net.h"
#include "hw/virtio/virtio-access.h"
#include "migration/misc.h"
#include "standard-headers/linux/ethtool.h"
+#include "trace.h"
#define VIRTIO_NET_VM_VERSION 11
@@ -152,8 +154,9 @@ static void virtio_net_announce_timer(void *opaque)
{
VirtIONet *n = opaque;
VirtIODevice *vdev = VIRTIO_DEVICE(n);
+ trace_virtio_net_announce_timer(n->announce_timer.round);
- n->announce_counter--;
+ n->announce_timer.round--;
n->status |= VIRTIO_NET_S_ANNOUNCE;
virtio_notify_config(vdev);
}
@@ -467,8 +470,8 @@ static void virtio_net_reset(VirtIODevice *vdev)
n->nobcast = 0;
/* multiqueue is disabled by default */
n->curr_queues = 1;
- timer_del(n->announce_timer);
- n->announce_counter = 0;
+ timer_del(n->announce_timer.tm);
+ n->announce_timer.round = 0;
n->status &= ~VIRTIO_NET_S_ANNOUNCE;
/* Flush any MAC and VLAN filter table state */
@@ -964,13 +967,12 @@ static int virtio_net_handle_vlan_table(VirtIONet *n, uint8_t cmd,
static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd,
struct iovec *iov, unsigned int iov_cnt)
{
+ trace_virtio_net_handle_announce(n->announce_timer.round);
if (cmd == VIRTIO_NET_CTRL_ANNOUNCE_ACK &&
n->status & VIRTIO_NET_S_ANNOUNCE) {
n->status &= ~VIRTIO_NET_S_ANNOUNCE;
- if (n->announce_counter) {
- timer_mod(n->announce_timer,
- qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
- self_announce_delay(n->announce_counter));
+ if (n->announce_timer.round) {
+ qemu_announce_timer_step(&n->announce_timer);
}
return VIRTIO_NET_OK;
} else {
@@ -2286,6 +2288,7 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
VirtIODevice *vdev = VIRTIO_DEVICE(n);
int i, link_down;
+ trace_virtio_net_post_load_device();
virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs,
virtio_vdev_has_feature(vdev,
VIRTIO_F_VERSION_1));
@@ -2322,8 +2325,15 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
- n->announce_counter = SELF_ANNOUNCE_ROUNDS;
- timer_mod(n->announce_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL));
+ qemu_announce_timer_reset(&n->announce_timer, migrate_announce_params(),
+ QEMU_CLOCK_VIRTUAL,
+ virtio_net_announce_timer, n);
+ if (n->announce_timer.round) {
+ timer_mod(n->announce_timer.tm,
+ qemu_clock_get_ms(n->announce_timer.type));
+ } else {
+ qemu_announce_timer_del(&n->announce_timer);
+ }
}
return 0;
@@ -2679,8 +2689,9 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
qemu_macaddr_default_if_unset(&n->nic_conf.macaddr);
memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac));
n->status = VIRTIO_NET_S_LINK_UP;
- n->announce_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
- virtio_net_announce_timer, n);
+ qemu_announce_timer_reset(&n->announce_timer, migrate_announce_params(),
+ QEMU_CLOCK_VIRTUAL,
+ virtio_net_announce_timer, n);
if (n->netclient_type) {
/*
@@ -2743,8 +2754,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
virtio_net_del_queue(n, i);
}
- timer_del(n->announce_timer);
- timer_free(n->announce_timer);
+ qemu_announce_timer_del(&n->announce_timer);
g_free(n->vqs);
qemu_del_nic(n->nic);
virtio_net_rsc_cleanup(n);