vlib: move pci api types from vnet/pci to vlib/pci
[vpp.git] / src / vnet / devices / virtio / device.c
index 588c84b..76f8558 100644 (file)
@@ -158,9 +158,21 @@ set_checksum_offsets (vlib_main_t * vm, virtio_if_t * vif, vlib_buffer_t * b,
       hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
       hdr->csum_start = gho.l4_hdr_offset;     // 0x22;
       if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
-       hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
+       {
+         tcp_header_t *tcp =
+           (tcp_header_t *) (vlib_buffer_get_current (b) +
+                             gho.l4_hdr_offset);
+         tcp->checksum = 0;
+         hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
+       }
       else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
-       hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum);
+       {
+         udp_header_t *udp =
+           (udp_header_t *) (vlib_buffer_get_current (b) +
+                             gho.l4_hdr_offset);
+         udp->checksum = 0;
+         hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum);
+       }
 
       /*
        * virtio devices do not support IP4 checksum offload. So driver takes care
@@ -177,9 +189,21 @@ set_checksum_offsets (vlib_main_t * vm, virtio_if_t * vif, vlib_buffer_t * b,
       hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
       hdr->csum_start = gho.l4_hdr_offset;     // 0x36;
       if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
-       hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
+       {
+         tcp_header_t *tcp =
+           (tcp_header_t *) (vlib_buffer_get_current (b) +
+                             gho.l4_hdr_offset);
+         tcp->checksum = 0;
+         hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
+       }
       else if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
-       hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum);
+       {
+         udp_header_t *udp =
+           (udp_header_t *) (vlib_buffer_get_current (b) +
+                             gho.l4_hdr_offset);
+         udp->checksum = 0;
+         hdr->csum_offset = STRUCT_OFFSET_OF (udp_header_t, checksum);
+       }
     }
 }
 
@@ -202,10 +226,15 @@ add_buffer_to_slot (vlib_main_t * vm, virtio_if_t * vif,
       if (b->flags & VNET_BUFFER_F_IS_IP4)
        {
          ip4_header_t *ip4;
+         tcp_header_t *tcp;
          gso_header_offset_t gho = vnet_gso_header_offset_parser (b, 0);
          hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
          hdr->gso_size = vnet_buffer2 (b)->gso_size;
          hdr->hdr_len = gho.l4_hdr_offset + gho.l4_hdr_sz;
+         tcp =
+           (tcp_header_t *) (vlib_buffer_get_current (b) +
+                             gho.l4_hdr_offset);
+         tcp->checksum = 0;
          hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
          hdr->csum_start = gho.l4_hdr_offset;  // 0x22;
          hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
@@ -221,11 +250,16 @@ add_buffer_to_slot (vlib_main_t * vm, virtio_if_t * vif,
        }
       else if (b->flags & VNET_BUFFER_F_IS_IP6)
        {
+         tcp_header_t *tcp;
          gso_header_offset_t gho = vnet_gso_header_offset_parser (b, 1);
          hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
          hdr->gso_size = vnet_buffer2 (b)->gso_size;
          hdr->hdr_len = gho.l4_hdr_offset + gho.l4_hdr_sz;
          hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
+         tcp =
+           (tcp_header_t *) (vlib_buffer_get_current (b) +
+                             gho.l4_hdr_offset);
+         tcp->checksum = 0;
          hdr->csum_start = gho.l4_hdr_offset;  // 0x36;
          hdr->csum_offset = STRUCT_OFFSET_OF (tcp_header_t, checksum);
        }
@@ -531,10 +565,16 @@ virtio_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
   virtio_if_t *vif = pool_elt_at_index (mm->interfaces, hw->dev_instance);
 
   if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
-    vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
+    {
+      vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
+      vnet_hw_interface_set_flags (vnm, vif->hw_if_index,
+                                  VNET_HW_INTERFACE_FLAG_LINK_UP);
+    }
   else
-    vif->flags &= ~VIRTIO_IF_FLAG_ADMIN_UP;
-
+    {
+      vif->flags &= ~VIRTIO_IF_FLAG_ADMIN_UP;
+      vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
+    }
   return 0;
 }