From patchwork Wed Oct 21 11:27:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [16/19] virtio-net: enable tap offload if guest supports it From: Mark McLoughlin X-Patchwork-Id: 36550 Message-Id: <1256124478-2988-17-git-send-email-markmc@redhat.com> To: qemu-devel@nongnu.org Cc: Mark McLoughlin Date: Wed, 21 Oct 2009 12:27:55 +0100 We query the guest's feature set to see if it supports offload and, if so, we enable those features on the tap interface. Signed-off-by: Mark McLoughlin --- hw/virtio-net.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 5ce4b42..19d00a6 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -149,6 +149,11 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev) features |= (1 << VIRTIO_NET_F_HOST_TSO4); features |= (1 << VIRTIO_NET_F_HOST_TSO6); features |= (1 << VIRTIO_NET_F_HOST_ECN); + + features |= (1 << VIRTIO_NET_F_GUEST_CSUM); + features |= (1 << VIRTIO_NET_F_GUEST_TSO4); + features |= (1 << VIRTIO_NET_F_GUEST_TSO6); + features |= (1 << VIRTIO_NET_F_GUEST_ECN); } return features; @@ -174,6 +179,14 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features) VirtIONet *n = to_virtio_net(vdev); n->mergeable_rx_bufs = !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF)); + + if (peer_has_vnet_hdr(n)) { + tap_set_offload(n->vc->peer, + (features >> VIRTIO_NET_F_GUEST_CSUM) & 1, + (features >> VIRTIO_NET_F_GUEST_TSO4) & 1, + (features >> VIRTIO_NET_F_GUEST_TSO6) & 1, + (features >> VIRTIO_NET_F_GUEST_ECN) & 1); + } } static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, @@ -700,6 +713,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) if (peer_has_vnet_hdr(n)) { tap_using_vnet_hdr(n->vc->peer, 1); + tap_set_offload(n->vc->peer, + (n->vdev.features >> VIRTIO_NET_F_GUEST_CSUM) & 1, + (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO4) & 1, + (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO6) & 1, + (n->vdev.features >> VIRTIO_NET_F_GUEST_ECN) & 1); } }