tap: add gro support
[vpp.git] / src / vnet / devices / virtio / virtio.c
index c0c163f..f8b6a39 100644 (file)
@@ -55,7 +55,8 @@ call_read_ready (clib_file_t * uf)
 
   CLIB_UNUSED (ssize_t size) = read (uf->file_descriptor, &b, sizeof (b));
   if ((qid & 1) == 0)
-    vnet_device_input_set_interrupt_pending (vnm, vif->hw_if_index, qid);
+    vnet_device_input_set_interrupt_pending (vnm, vif->hw_if_index,
+                                            RX_QUEUE_ACCESS (qid));
 
   return 0;
 }
@@ -113,6 +114,11 @@ virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, u16 sz)
   ASSERT (vring->buffers == 0);
   vec_validate_aligned (vring->buffers, sz, CLIB_CACHE_LINE_BYTES);
 
+  if (idx & 1)
+    {
+      clib_memset_u32 (vring->buffers, ~0, sz);
+    }
+
   vring->size = sz;
   vring->call_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
   vring->kick_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
@@ -211,10 +217,25 @@ virtio_vring_free_tx (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
   if (vring->avail)
     clib_mem_free (vring->avail);
   vec_free (vring->buffers);
+  gro_flow_table_free (vring->flow_table);
   clib_spinlock_free (&vring->lockp);
   return 0;
 }
 
+void
+virtio_set_packet_coalesce (virtio_if_t * vif)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
+  virtio_vring_t *vring;
+  vec_foreach (vring, vif->txq_vrings)
+  {
+    gro_flow_table_init (&vring->flow_table,
+                        vif->type & (VIRTIO_IF_TYPE_TAP |
+                                     VIRTIO_IF_TYPE_PCI), hw->tx_node_index);
+  }
+}
+
 void
 virtio_vring_set_numa_node (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
 {
@@ -289,7 +310,7 @@ virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type)
          vlib_cli_output (vm, "  PCI Address: %U", format_vlib_pci_addr,
                           &vif->pci_addr);
        }
-      if (type == VIRTIO_IF_TYPE_TAP)
+      if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
        {
          u8 *str = 0;
          if (vif->host_if_name)
@@ -299,17 +320,25 @@ virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type)
          if (vif->host_mtu_size)
            vlib_cli_output (vm, "  host-mtu-size \"%d\"",
                             vif->host_mtu_size);
+         if (type == VIRTIO_IF_TYPE_TAP)
+           vlib_cli_output (vm, "  host-mac-addr: %U",
+                            format_ethernet_address, vif->host_mac_addr);
 
          vec_foreach_index (i, vif->vhost_fds)
            str = format (str, " %d", vif->vhost_fds[i]);
          vlib_cli_output (vm, "  vhost-fds%v", str);
          vec_free (str);
-         vlib_cli_output (vm, "  tap-fd %d", vif->tap_fd);
+         vec_foreach_index (i, vif->tap_fds)
+           str = format (str, " %d", vif->tap_fds[i]);
+         vlib_cli_output (vm, "  tap-fds%v", str);
+         vec_free (str);
        }
       vlib_cli_output (vm, "  gso-enabled %d", vif->gso_enabled);
       vlib_cli_output (vm, "  csum-enabled %d", vif->csum_offload_enabled);
-      vlib_cli_output (vm, "  Mac Address: %U", format_ethernet_address,
-                      vif->mac_addr);
+      vlib_cli_output (vm, "  packet-coalesce %d", vif->packet_coalesce);
+      if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_PCI))
+       vlib_cli_output (vm, "  Mac Address: %U", format_ethernet_address,
+                        vif->mac_addr);
       vlib_cli_output (vm, "  Device instance: %u", vif->dev_instance);
       vlib_cli_output (vm, "  flags 0x%x", vif->flags);
       flag_entry = (struct feat_struct *) &flags_array;
@@ -359,7 +388,7 @@ virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type)
                         "    avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
                         vring->avail->flags, vring->avail->idx,
                         vring->used->flags, vring->used->idx);
-       if (type == VIRTIO_IF_TYPE_TAP)
+       if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
          {
            vlib_cli_output (vm, "    kickfd %d, callfd %d", vring->kick_fd,
                             vring->call_fd);
@@ -394,11 +423,16 @@ virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type)
                         "    avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
                         vring->avail->flags, vring->avail->idx,
                         vring->used->flags, vring->used->idx);
-       if (type == VIRTIO_IF_TYPE_TAP)
+       if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
          {
            vlib_cli_output (vm, "    kickfd %d, callfd %d", vring->kick_fd,
                             vring->call_fd);
          }
+       if (vring->flow_table)
+         {
+           vlib_cli_output (vm, "    %U", gro_flow_table_format,
+                            vring->flow_table);
+         }
        if (show_descr)
          {
            vlib_cli_output (vm, "\n  descriptor table:\n");
@@ -430,7 +464,7 @@ virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type)
                           "    avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
                           vring->avail->flags, vring->avail->idx,
                           vring->used->flags, vring->used->idx);
-         if (type == VIRTIO_IF_TYPE_TAP)
+         if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
            {
              vlib_cli_output (vm, "    kickfd %d, callfd %d", vring->kick_fd,
                               vring->call_fd);