diff mbox

[qemu-kvm] Add generic peer_* routines for the remaining tap specific routines

Message ID 1264538417.24933.143.camel@w-sridhar.beaverton.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sridhar Samudrala Jan. 26, 2010, 8:40 p.m. UTC
None
diff mbox

Patch

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 6e48997..eba578a 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -129,10 +129,13 @@  static int peer_has_vnet_hdr(VirtIONet *n)
     if (!n->nic->nc.peer)
         return 0;
 
-    if (n->nic->nc.peer->info->type != NET_CLIENT_TYPE_TAP)
-        return 0;
-
-    n->has_vnet_hdr = tap_has_vnet_hdr(n->nic->nc.peer);
+    switch (n->nic->nc.peer->info->type) {
+    case NET_CLIENT_TYPE_TAP:
+        n->has_vnet_hdr = tap_has_vnet_hdr(n->nic->nc.peer);
+        break;
+    default:
+        return 0;            
+    }
 
     return n->has_vnet_hdr;
 }
@@ -142,11 +145,46 @@  static int peer_has_ufo(VirtIONet *n)
     if (!peer_has_vnet_hdr(n))
         return 0;
 
-    n->has_ufo = tap_has_ufo(n->nic->nc.peer);
+    switch (n->nic->nc.peer->info->type) {
+    case NET_CLIENT_TYPE_TAP:
+        n->has_ufo = tap_has_ufo(n->nic->nc.peer);
+        break;
+    default:
+        return 0;            
+    }
 
     return n->has_ufo;
 }
 
+static void peer_using_vnet_hdr(VirtIONet *n, int using_vnet_hdr)
+{
+    if (!n->nic->nc.peer)
+        return;
+
+    switch (n->nic->nc.peer->info->type) {
+    case NET_CLIENT_TYPE_TAP:
+        tap_using_vnet_hdr(n->nic->nc.peer, using_vnet_hdr);
+        break;
+    default:
+        break; 
+    }
+}
+
+static void peer_set_offload(VirtIONet *n, int csum, int tso4, int tso6,
+                             int ecn, int ufo)
+{
+    if (!n->nic->nc.peer)
+        return;
+
+    switch (n->nic->nc.peer->info->type) {
+    case NET_CLIENT_TYPE_TAP:
+        tap_set_offload(n->nic->nc.peer, csum, tso4, tso6, ecn, ufo);
+        break;
+    default:
+        break; 
+    }
+}
+
 static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)
 {
     VirtIONet *n = to_virtio_net(vdev);
@@ -154,7 +192,7 @@  static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)
     features |= (1 << VIRTIO_NET_F_MAC);
 
     if (peer_has_vnet_hdr(n)) {
-        tap_using_vnet_hdr(n->nic->nc.peer, 1);
+        peer_using_vnet_hdr(n, 1);
     } else {
         features &= ~(0x1 << VIRTIO_NET_F_CSUM);
         features &= ~(0x1 << VIRTIO_NET_F_HOST_TSO4);
@@ -197,7 +235,7 @@  static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
     n->mergeable_rx_bufs = !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF));
 
     if (n->has_vnet_hdr) {
-        tap_set_offload(n->nic->nc.peer,
+        peer_set_offload(n,
                         (features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
                         (features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
                         (features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
@@ -761,8 +799,8 @@  static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
         }
 
         if (n->has_vnet_hdr) {
-            tap_using_vnet_hdr(n->nic->nc.peer, 1);
-            tap_set_offload(n->nic->nc.peer,
+            peer_using_vnet_hdr(n, 1);
+            peer_set_offload(n,
                     (n->vdev.guest_features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
                     (n->vdev.guest_features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
                     (n->vdev.guest_features >> VIRTIO_NET_F_GUEST_TSO6) & 1,