* limitations under the License.
*/
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <linux/vfio.h>
+#include <sys/ioctl.h>
+
#include <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <dpdk/device/dpdk.h>
* Return 1 if to skip the delay loop because we are suspending
* the calling vlib process instead.
*/
-int
+static int
rte_delay_us_override (unsigned us)
{
vlib_main_t *vm;
* thread then do not intercept. (Must not be called from an
* independent pthread).
*/
- if (os_get_cpu_number () == 0)
+ if (vlib_get_thread_index () == 0)
{
/*
* We're in the vlib main thread or a vlib process. Make sure
VLIB_INIT_FUNCTION (dpdk_main_init);
+
+clib_error_t *
+dpdk_early_init (vlib_main_t *vm)
+{
+ int fd = -1;
+ u64 *pt = 0;
+ clib_error_t *err = 0;
+ clib_mem_vm_alloc_t alloc = { 0 };
+
+ /* check if pagemap is accessible - if we get zero result
+ dpdk will not be able to get physical memory address and game is over
+ unless we have IOMMU */
+ pt = clib_mem_vm_get_paddr (&pt, min_log2 (sysconf (_SC_PAGESIZE)), 1);
+ if (pt && pt[0])
+ goto check_hugetlb;
+
+ if ((fd = open ("/dev/vfio/vfio", O_RDWR)) == -1)
+ goto error;
+
+ if (ioctl (fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION)
+ goto error;
+
+ /* if we have type 1 IOMMU page map is not needed */
+ if (ioctl (fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) != 1)
+ goto error;
+
+check_hugetlb:
+ alloc.flags = CLIB_MEM_VM_F_SHARED | CLIB_MEM_VM_F_HUGETLB | CLIB_MEM_VM_F_HUGETLB_PREALLOC;
+ alloc.size = 1;
+
+ if ((err = clib_mem_vm_ext_alloc (&alloc)))
+ {
+ clib_error_free (err);
+ goto error;
+ }
+ else
+ clib_mem_vm_free (alloc.addr, 1 << alloc.log2_page_size);
+
+ goto done;
+
+error:
+ err = clib_error_return (0, "access to physical devices is not allowed");
+
+done:
+ if (fd != -1)
+ close (fd);
+ vec_free (pt);
+ return err;
+}
+
/* *INDENT-OFF* */
VLIB_PLUGIN_REGISTER () = {
.version = VPP_BUILD_VER,
+ .description = "Data Plane Development Kit (DPDK)",
+ .early_init = "dpdk_early_init",
};
/* *INDENT-ON* */