Fix CLI for adding negative LISP fwd entries
[vpp.git] / vlib / vlib / dpdk_buffer.c
index 7e6e842..e617be2 100644 (file)
  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+/**
+ * @cond DPDK
+ * @file
+ *
+ * Allocate/free network buffers with DPDK.
+ */
+
 #include <rte_config.h>
 
 #include <rte_common.h>
@@ -62,6 +69,7 @@
 #include <rte_ring.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
+#include <rte_version.h>
 
 #include <vlib/vlib.h>
 
@@ -963,7 +971,9 @@ vlib_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs,
   vlib_buffer_main_t *bm = vm->buffer_main;
   vlib_physmem_main_t *vpm = &vm->physmem_main;
   struct rte_mempool *rmp;
+#if RTE_VERSION < RTE_VERSION_NUM(16, 7, 0, 0)
   uword new_start, new_size;
+#endif
   int i;
 
   if (!rte_pktmbuf_pool_create)
@@ -984,10 +994,76 @@ vlib_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs,
                                 VLIB_BUFFER_PRE_DATA_SIZE + VLIB_BUFFER_DATA_SIZE,     /* dataroom size */
                                 socket_id);    /* cpu socket */
 
-  vec_free (pool_name);
-
   if (rmp)
     {
+#if RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 0)
+      {
+       uword this_pool_end;
+       uword this_pool_start;
+       uword this_pool_size;
+       uword save_vpm_start, save_vpm_end, save_vpm_size;
+       struct rte_mempool_memhdr *memhdr;
+
+       this_pool_start = ~0ULL;
+       this_pool_end = 0LL;
+
+       STAILQ_FOREACH (memhdr, &rmp->mem_list, next)
+       {
+         if (((uword) (memhdr->addr + memhdr->len)) > this_pool_end)
+           this_pool_end = (uword) (memhdr->addr + memhdr->len);
+         if (((uword) memhdr->addr) < this_pool_start)
+           this_pool_start = (uword) (memhdr->addr);
+       }
+       ASSERT (this_pool_start < ~0ULL && this_pool_end > 0);
+       this_pool_size = this_pool_end - this_pool_start;
+
+       if (CLIB_DEBUG > 1)
+         {
+           clib_warning ("%s: pool start %llx pool end %llx pool size %lld",
+                         pool_name, this_pool_start, this_pool_end,
+                         this_pool_size);
+           clib_warning
+             ("before: virtual.start %llx virtual.end %llx virtual.size %lld",
+              vpm->virtual.start, vpm->virtual.end, vpm->virtual.size);
+         }
+
+       save_vpm_start = vpm->virtual.start;
+       save_vpm_end = vpm->virtual.end;
+       save_vpm_size = vpm->virtual.size;
+
+       if ((this_pool_start < vpm->virtual.start) || vpm->virtual.start == 0)
+         vpm->virtual.start = this_pool_start;
+       if (this_pool_end > vpm->virtual.end)
+         vpm->virtual.end = this_pool_end;
+
+       vpm->virtual.size = vpm->virtual.end - vpm->virtual.start;
+
+       if (CLIB_DEBUG > 1)
+         {
+           clib_warning
+             ("after: virtual.start %llx virtual.end %llx virtual.size %lld",
+              vpm->virtual.start, vpm->virtual.end, vpm->virtual.size);
+         }
+
+       /* check if fits into buffer index range */
+       if ((u64) vpm->virtual.size >
+           ((u64) 1 << (32 + CLIB_LOG2_CACHE_LINE_BYTES)))
+         {
+           clib_warning ("physmem: virtual size out of range!");
+           vpm->virtual.start = save_vpm_start;
+           vpm->virtual.end = save_vpm_end;
+           vpm->virtual.size = save_vpm_size;
+           rmp = 0;
+         }
+      }
+      if (rmp)
+       {
+         bm->pktmbuf_pools[socket_id] = rmp;
+         vec_free (pool_name);
+         return 0;
+       }
+    }
+#else
       new_start = pointer_to_uword (rmp);
       new_size = rmp->elt_va_end - new_start;
 
@@ -1016,8 +1092,12 @@ vlib_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs,
       vpm->virtual.start = new_start;
       vpm->virtual.size = new_size;
       vpm->virtual.end = new_start + new_size;
+      vec_free (pool_name);
       return 0;
     }
+#endif
+
+  vec_free (pool_name);
 
   /* no usable pool for this socket, try to use pool from another one */
   for (i = 0; i < vec_len (bm->pktmbuf_pools); i++)
@@ -1325,6 +1405,7 @@ buffer_state_validation_init (vlib_main_t * vm)
 VLIB_INIT_FUNCTION (buffer_state_validation_init);
 #endif
 
+/** @endcond */
 /*
  * fd.io coding-style-patch-verification: ON
  *