dpdk: remove support for dpdk 2.2
[vpp.git] / vnet / vnet / devices / dpdk / vhost_user.c
index 58cff7b..e37dfde 100644 (file)
@@ -137,7 +137,7 @@ dpdk_vhost_user_device_from_hw_if_index (u32 hw_if_index)
   vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
   dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
 
-  if (xd->dev_type != VNET_DPDK_DEV_VHOST_USER)
+  if ((xd->flags DPDK_DEVICE_FLAG_VHOST_USER) == 0)
     return 0;
 
   return xd;
@@ -221,7 +221,7 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 * hwaddr)
       if (vec_len (dm->devices) > vui_idx)
        {
          xd = vec_elt_at_index (dm->devices, vui_idx);
-         if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER)
+         if (xd->flags & DPDK_DEVICE_FLAG_VHOST_USER)
            {
              DBG_SOCK
                ("reusing inactive vhost-user interface sw_if_index %d",
@@ -266,7 +266,7 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 * hwaddr)
       // reset tx vectors
       for (j = 0; j < tm->n_vlib_mains; j++)
        {
-         vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
+         vec_validate_ha (xd->tx_vectors[j], xd->nb_tx_desc,
                           sizeof (tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
          vec_reset_length (xd->tx_vectors[j]);
        }
@@ -283,7 +283,7 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 * hwaddr)
     {
       // vui was not retrieved from inactive ifaces - create new
       vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES);
-      xd->dev_type = VNET_DPDK_DEV_VHOST_USER;
+      xd->flags |= DPDK_DEVICE_FLAG_VHOST_USER;
       xd->rx_q_used = num_qpairs;
       xd->tx_q_used = num_qpairs;
       xd->vu_vhost_dev.virt_qp_nb = num_qpairs;
@@ -338,7 +338,7 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 * hwaddr)
 
       for (j = 0; j < tm->n_vlib_mains; j++)
        {
-         vec_validate_ha (xd->tx_vectors[j], DPDK_TX_RING_SIZE,
+         vec_validate_ha (xd->tx_vectors[j], xd->nb_tx_desc,
                           sizeof (tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES);
          vec_reset_length (xd->tx_vectors[j]);
        }
@@ -393,7 +393,7 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 * hwaddr)
     {
       int cpu = dm->input_cpu_first_index + (next_cpu % dm->input_cpu_count);
 
-      unsigned lcore = vlib_worker_threads[cpu].dpdk_lcore_id;
+      unsigned lcore = vlib_worker_threads[cpu].lcore_id;
       vec_validate (xd->cpu_socket_id_by_queue, q);
       xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id (lcore);
 
@@ -418,7 +418,6 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 * hwaddr)
   return 0;
 }
 
-#if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
 static long
 get_huge_page_size (int fd)
 {
@@ -426,7 +425,6 @@ get_huge_page_size (int fd)
   fstatfs (fd, &s);
   return s.f_bsize;
 }
-#endif
 
 static clib_error_t *
 dpdk_vhost_user_set_protocol_features (u32 hw_if_index, u64 prot_features)
@@ -443,7 +441,6 @@ dpdk_vhost_user_get_features (u32 hw_if_index, u64 * features)
 {
   *features = rte_vhost_feature_get ();
 
-#if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
 #define OFFLOAD_FEATURES ((1ULL << VIRTIO_NET_F_HOST_TSO4) | \
                (1ULL << VIRTIO_NET_F_HOST_TSO6) | \
                (1ULL << VIRTIO_NET_F_CSUM)    | \
@@ -456,7 +453,6 @@ dpdk_vhost_user_get_features (u32 hw_if_index, u64 * features)
    * not support offloading breaks L4 traffic.
    */
   *features &= (~OFFLOAD_FEATURES);
-#endif
 
   DBG_SOCK ("supported features: 0x%lx", *features);
   return 0;
@@ -604,9 +600,7 @@ dpdk_vhost_user_set_vring_addr (u32 hw_if_index, u8 idx, uword desc,
   vq->desc = (struct vring_desc *) qva_to_vva (&xd->vu_vhost_dev, desc);
   vq->used = (struct vring_used *) qva_to_vva (&xd->vu_vhost_dev, used);
   vq->avail = (struct vring_avail *) qva_to_vva (&xd->vu_vhost_dev, avail);
-#if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
   vq->log_guest_addr = log;
-#endif
 
   if (!(vq->desc && vq->used && vq->avail))
     {
@@ -660,15 +654,22 @@ dpdk_vhost_user_get_vring_base (u32 hw_if_index, u8 idx, u32 * num)
  */
   DBG_SOCK ("Stopping vring Q %u of device %d", idx, hw_if_index);
   dpdk_vu_intf_t *vui = xd->vu_intf;
+
+  /* if there is old fd, delete it */
+  if (vui->vrings[idx].callfd > 0)
+    {
+      unix_file_t *uf = pool_elt_at_index (unix_main.file_pool,
+                                          vui->vrings[idx].callfd_idx);
+      unix_file_del (&unix_main, uf);
+    }
+
   vui->vrings[idx].enabled = 0;        /* Reset local copy */
   vui->vrings[idx].callfd = -1;        /* Reset FD */
   vq->enabled = 0;
   vq->desc = NULL;
   vq->used = NULL;
   vq->avail = NULL;
-#if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
   vq->log_guest_addr = 0;
-#endif
 
   /* Check if all Qs are disabled */
   int numqs = xd->vu_vhost_dev.virt_qp_nb * VIRTIO_QNUM;
@@ -833,7 +834,7 @@ dpdk_vhost_user_set_vring_call (u32 hw_if_index, u8 idx, int fd)
   dpdk_vu_intf_t *vui = xd->vu_intf;
 
   /* if there is old fd, delete it */
-  if (vui->vrings[idx].callfd > 0)
+  if (vui->vrings[idx].callfd > -1)
     {
       unix_file_t *uf = pool_elt_at_index (unix_main.file_pool,
                                           vui->vrings[idx].callfd_idx);
@@ -863,7 +864,7 @@ dpdk_vhost_user_want_interrupt (dpdk_device_t * xd, int idx)
   struct vhost_virtqueue *vq = xd->vu_vhost_dev.virtqueue[idx];
 
   /* return if vm is interested in interrupts */
-  return (vring->callfd > 0)
+  return (vring->callfd > -1)
     && !(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT);
 }
 
@@ -881,7 +882,8 @@ dpdk_vhost_user_send_interrupt (vlib_main_t * vm, dpdk_device_t * xd, int idx)
   struct vhost_virtqueue *vq = xd->vu_vhost_dev.virtqueue[idx];
 
   /* if vm is interested in interrupts */
-  if ((vring->callfd > 0) && !(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT))
+  if ((vring->callfd > -1)
+      && !(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT))
     {
       eventfd_write (vring->callfd, (eventfd_t) 1);
       vring->n_since_last_int = 0;
@@ -901,6 +903,7 @@ dpdk_vhost_user_vui_init (vnet_main_t * vnm,
                          const char *sock_filename,
                          u8 is_server, u64 feature_mask, u32 * sw_if_index)
 {
+  int q;
   dpdk_vu_intf_t *vui = xd->vu_intf;
   memset (vui, 0, sizeof (*vui));
 
@@ -916,6 +919,13 @@ dpdk_vhost_user_vui_init (vnet_main_t * vnm,
   vui->active = 1;
   vui->unix_file_index = ~0;
 
+  for (q = 0; q < vui->num_vrings; q++)
+    {
+      vui->vrings[q].enabled = 0;
+      vui->vrings[q].callfd = -1;
+      vui->vrings[q].kickfd = -1;
+    }
+
   vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, 0);
 
   if (sw_if_index)
@@ -997,12 +1007,23 @@ dpdk_vhost_user_if_disconnect (dpdk_device_t * xd)
   for (q = 0; q < vui->num_vrings; q++)
     {
       vq = xd->vu_vhost_dev.virtqueue[q];
+      if (vui->vrings[q].callfd > -1)
+       {
+         unix_file_t *uf = pool_elt_at_index (unix_main.file_pool,
+                                              vui->vrings[q].callfd_idx);
+         unix_file_del (&unix_main, uf);
+       }
+
+      if (vui->vrings[q].kickfd > -1)
+       {
+         close (vui->vrings[q].kickfd);
+         vui->vrings[q].kickfd = -1;
+       }
+
       vui->vrings[q].enabled = 0;      /* Reset local copy */
       vui->vrings[q].callfd = -1;      /* Reset FD */
       vq->enabled = 0;
-#if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
       vq->log_guest_addr = 0;
-#endif
       vq->desc = NULL;
       vq->used = NULL;
       vq->avail = NULL;
@@ -1200,6 +1221,9 @@ dpdk_vhost_user_socket_read (unix_file_t * uf)
          if (number_of_fds != 1)
            goto close_socket;
 
+         if (vui->vrings[q].kickfd > -1)
+           close (vui->vrings[q].kickfd);
+
          vui->vrings[q].kickfd = fds[0];
        }
       else
@@ -1253,7 +1277,6 @@ dpdk_vhost_user_socket_read (unix_file_t * uf)
       break;
 
     case VHOST_USER_SET_LOG_BASE:
-#if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0)
       DBG_SOCK ("if %d msg VHOST_USER_SET_LOG_BASE", xd->vlib_hw_if_index);
 
       if (msg.size != sizeof (msg.log))
@@ -1295,10 +1318,6 @@ dpdk_vhost_user_socket_read (unix_file_t * uf)
       xd->vu_vhost_dev.log_size = msg.log.size;
       msg.flags |= VHOST_USER_REPLY_MASK;
       msg.size = sizeof (msg.u64);
-#else
-      DBG_SOCK ("if %d msg VHOST_USER_SET_LOG_BASE Not-Implemented",
-               xd->vlib_hw_if_index);
-#endif
       break;
 
     case VHOST_USER_SET_LOG_FD:
@@ -1661,7 +1680,7 @@ dpdk_vhost_user_dump_ifs (vnet_main_t * vnm, vlib_main_t * vm,
 
   vec_foreach (xd, dm->devices)
   {
-    if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER && xd->vu_intf->active)
+    if ((xd->flags & DPDK_DEVICE_FLAG_VHOST_USER) && xd->vu_intf->active)
       vec_add1 (hw_if_indices, xd->vlib_hw_if_index);
   }
 
@@ -1988,7 +2007,7 @@ show_dpdk_vhost_user_command_fn (vlib_main_t * vm,
     {
       vec_foreach (xd, dm->devices)
       {
-       if (xd->dev_type == VNET_DPDK_DEV_VHOST_USER && xd->vu_intf->active)
+       if ((xd->flags DPDK_DEVICE_FLAG_VHOST_USER) && xd->vu_intf->active)
          vec_add1 (hw_if_indices, xd->vlib_hw_if_index);
       }
     }