virtio: split gso and checksum offload functionality
[vpp.git] / src / vnet / devices / virtio / virtio_api.c
index 5035799..4d98e72 100644 (file)
@@ -25,6 +25,7 @@
 #include <vnet/ip/ip.h>
 #include <vnet/devices/virtio/virtio.h>
 #include <vnet/devices/virtio/pci.h>
+#include <vnet/pci/pci_types_api.h>
 
 #include <vnet/vnet_msg_enum.h>
 
@@ -59,15 +60,22 @@ vl_api_virtio_pci_create_t_handler (vl_api_virtio_pci_create_t * mp)
 
   clib_memset (ap, 0, sizeof (*ap));
 
-  ap->addr = ntohl (mp->pci_addr);
+  pci_address_decode (&mp->pci_addr, (vlib_pci_addr_t *) & ap->addr);
   if (!mp->use_random_mac)
     {
       clib_memcpy (ap->mac_addr, mp->mac_address, 6);
       ap->mac_addr_set = 1;
     }
-  ap->rxq_size = ntohs (mp->rx_ring_sz);
-  ap->txq_size = ntohs (mp->tx_ring_sz);
   ap->sw_if_index = (u32) ~ 0;
+  if (mp->gso_enabled)
+    ap->gso_enabled = 1;
+  else
+    ap->gso_enabled = 0;
+  if (mp->checksum_offload_enabled)
+    ap->checksum_offload_enabled = 1;
+  else
+    ap->checksum_offload_enabled = 0;
+
   ap->features = clib_net_to_host_u64 (mp->features);
 
   virtio_pci_create_if (vm, ap);
@@ -85,24 +93,6 @@ vl_api_virtio_pci_create_t_handler (vl_api_virtio_pci_create_t * mp)
   vl_api_send_msg (reg, (u8 *) rmp);
 }
 
-static void
-virtio_pci_send_sw_interface_event_deleted (vpe_api_main_t * am,
-                                           vl_api_registration_t * reg,
-                                           u32 sw_if_index)
-{
-  vl_api_sw_interface_event_t *mp;
-
-  mp = vl_msg_api_alloc (sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_EVENT);
-  mp->sw_if_index = htonl (sw_if_index);
-
-  mp->admin_up_down = 0;
-  mp->link_up_down = 0;
-  mp->deleted = 1;
-  vl_api_send_msg (reg, (u8 *) mp);
-}
-
 static void
 vl_api_virtio_pci_delete_t_handler (vl_api_virtio_pci_delete_t * mp)
 {
@@ -112,15 +102,15 @@ vl_api_virtio_pci_delete_t_handler (vl_api_virtio_pci_delete_t * mp)
   int rv = 0;
   vnet_hw_interface_t *hw;
   virtio_if_t *vif;
-  vpe_api_main_t *vam = &vpe_api_main;
   vl_api_virtio_pci_delete_reply_t *rmp;
   vl_api_registration_t *reg;
-  u32 sw_if_index = ntohl (mp->sw_if_index);
 
-  hw = vnet_get_sup_hw_interface (vnm, htonl (mp->sw_if_index));
+  hw =
+    vnet_get_sup_hw_interface_api_visible_or_null (vnm,
+                                                  htonl (mp->sw_if_index));
   if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
     {
-      rv = VNET_API_ERROR_INVALID_INTERFACE;
+      rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
       goto reply;
     }
 
@@ -139,11 +129,6 @@ reply:
   rmp->retval = htonl (rv);
 
   vl_api_send_msg (reg, (u8 *) rmp);
-
-  if (!rv)
-    {
-      virtio_pci_send_sw_interface_event_deleted (vam, reg, sw_if_index);
-    }
 }
 
 static void
@@ -157,10 +142,13 @@ virtio_pci_send_sw_interface_details (vpe_api_main_t * am,
   clib_memset (mp, 0, sizeof (*mp));
 
   mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_VIRTIO_PCI_DETAILS);
-  mp->pci_addr = htonl (vif->pci_addr.as_u32);
+  pci_address_encode ((vlib_pci_addr_t *) & vif->pci_addr.as_u32,
+                     &mp->pci_addr);
   mp->sw_if_index = htonl (vif->sw_if_index);
-  mp->rx_ring_sz = htons (vif->rx_ring_sz);
-  mp->tx_ring_sz = htons (vif->tx_ring_sz);
+  virtio_vring_t *vring = vec_elt_at_index (vif->rxq_vrings, 0);
+  mp->rx_ring_sz = htons (vring->size);
+  vring = vec_elt_at_index (vif->txq_vrings, 0);
+  mp->tx_ring_sz = htons (vring->size);
   clib_memcpy (mp->mac_addr, vif->mac_addr, 6);
   mp->features = clib_host_to_net_u64 (vif->features);
 
@@ -206,7 +194,7 @@ setup_message_id_table (api_main_t * am)
 static clib_error_t *
 virtio_pci_api_hookup (vlib_main_t * vm)
 {
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
 
 #define _(N,n)                                                  \
     vl_msg_api_set_handlers(VL_API_##N, #n,                     \