Add support for AArch32
[vpp.git] / vnet / vnet / devices / dpdk / vhost_user.c
index b6b31ba..9cdf664 100644 (file)
@@ -63,6 +63,11 @@ static const char *vhost_message_str[] __attribute__((unused)) = {
 #endif
 };
 
+#if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
+static int dpdk_vhost_user_set_vring_enable(u32 hw_if_index,
+    u8 idx, int enable);
+#endif
+
 /*
  * DPDK vhost-user functions 
  */
@@ -196,6 +201,7 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 *hwaddr)
   clib_error_t * error;
   dpdk_device_and_queue_t * dq;
   int num_qpairs = 1;
+  dpdk_vu_intf_t *vui = NULL;
 
 #if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
   num_qpairs = dm->use_rss < 1 ? 1 : tm->n_vlib_mains;
@@ -233,11 +239,14 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 *hwaddr)
           xd->vu_if_id = if_id;
 
       // reset virtqueues
+      vui = xd->vu_intf;
       for (j = 0; j < num_qpairs * VIRTIO_QNUM; j++) {
           memset(xd->vu_vhost_dev.virtqueue[j], 0, sizeof(struct vhost_virtqueue));
           xd->vu_vhost_dev.virtqueue[j]->kickfd = -1; 
           xd->vu_vhost_dev.virtqueue[j]->callfd = -1; 
           xd->vu_vhost_dev.virtqueue[j]->backend = -1; 
+          vui->vrings[j].packets = 0;
+          vui->vrings[j].bytes = 0;
        }
 
       // reset lockp
@@ -278,7 +287,7 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 *hwaddr)
 
       xd->device_index = xd - dm->devices;
       xd->per_interface_next_index = ~0;
-      xd->vu_intf = NULL;
+      xd->vu_intf = clib_mem_alloc (sizeof(*(xd->vu_intf)));
 
       xd->vu_vhost_dev.mem = clib_mem_alloc (sizeof(struct virtio_memory) +
                                              VHOST_MEMORY_MAX_NREGIONS *
@@ -291,12 +300,15 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 *hwaddr)
        * New virtqueue structure is an array of VHOST_MAX_QUEUE_PAIRS * 2
        * We need to allocate numq pairs.
        */
+      vui = xd->vu_intf;
       for (j = 0; j < num_qpairs * VIRTIO_QNUM; j++) {
           xd->vu_vhost_dev.virtqueue[j] = clib_mem_alloc (sizeof(struct vhost_virtqueue));
           memset(xd->vu_vhost_dev.virtqueue[j], 0, sizeof(struct vhost_virtqueue));
           xd->vu_vhost_dev.virtqueue[j]->kickfd = -1; 
           xd->vu_vhost_dev.virtqueue[j]->callfd = -1; 
           xd->vu_vhost_dev.virtqueue[j]->backend = -1; 
+          vui->vrings[j].packets = 0;
+          vui->vrings[j].bytes = 0;
       }
 
       dpdk_device_lock_init(xd);
@@ -356,9 +368,6 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 *hwaddr)
   sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index);
   xd->vlib_sw_if_index = sw->sw_if_index;
 
-  if (!xd->vu_intf)
-      xd->vu_intf = clib_mem_alloc (sizeof(*(xd->vu_intf)));
-
   *hw_if_index = xd->vlib_hw_if_index;
 
   DBG_SOCK("xd->device_index: %d, dm->input_cpu_count: %d, "
@@ -437,10 +446,23 @@ dpdk_vhost_user_set_features(u32 hw_if_index, u64 features)
   int numqs = VIRTIO_QNUM;
   u8 idx;
 #if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
+  int prot_feature = features &
+        (1ULL << VHOST_USER_F_PROTOCOL_FEATURES);
   numqs = xd->vu_vhost_dev.virt_qp_nb * VIRTIO_QNUM;
 #endif
-  for (idx = 0; idx < numqs; idx++)
+  for (idx = 0; idx < numqs; idx++) {
       xd->vu_vhost_dev.virtqueue[idx]->vhost_hlen = hdr_len;
+#if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
+      /*
+       * Spec says, if F_PROTOCOL_FEATURE is not set by the
+       * slave, then all the vrings should start off as
+       * enabled. If slave negotiates F_PROTOCOL_FEATURE, then
+       * slave is responsible to enable it.
+       */
+      if (! prot_feature)
+          dpdk_vhost_user_set_vring_enable(hw_if_index, idx, 1);
+#endif
+  }
 
   return 0;
 }
@@ -473,9 +495,9 @@ dpdk_vhost_user_set_mem_table(u32 hw_if_index, vhost_user_memory_t * vum, int fd
     mem->regions[i].userspace_address      = vum->regions[i].userspace_addr;
 
     mapped_size = mem->regions[i].memory_size + vum->regions[i].mmap_offset;
-    mapped_address = (uint64_t)(uintptr_t)mmap(NULL, mapped_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd[i], 0);
+    mapped_address = pointer_to_uword(mmap(NULL, mapped_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd[i], 0));
 
-    if ((void *)mapped_address == MAP_FAILED)
+    if (uword_to_pointer(mapped_address, void*) == MAP_FAILED)
     {
       clib_warning("mmap error");
       return 0;
@@ -565,11 +587,9 @@ dpdk_vhost_user_get_vring_base(u32 hw_if_index, u8 idx, u32 * num)
  * on the descriptor specified by VHOST_USER_SET_VRING_KICK,
  * and stop ring upon receiving VHOST_USER_GET_VRING_BASE.
  */
-#if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
-  dpdk_vu_intf_t *vui = xd->vu_intf;
-#endif
   DBG_SOCK("Stopping vring Q %u of device %d", idx, hw_if_index);
 #if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
+  dpdk_vu_intf_t *vui = xd->vu_intf;
   vui->vrings[idx].enabled = 0; /* Reset local copy */
   vui->vrings[idx].callfd = -1; /* Reset FD */
   vq->enabled = 0;
@@ -682,7 +702,8 @@ dpdk_vhost_user_set_vring_kick(u32 hw_if_index, u8 idx, int fd)
 }
 
 #if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
-int dpdk_vhost_user_set_vring_enable(u32 hw_if_index, u8 idx, int enable)
+static int
+dpdk_vhost_user_set_vring_enable(u32 hw_if_index, u8 idx, int enable)
 {
   dpdk_device_t * xd;
   struct vhost_virtqueue *vq;