net/ena: remove unused macro
[dpdk.git] / drivers / bus / vdev / vdev.c
index 87f0e2b..0e94ea9 100644 (file)
@@ -27,8 +27,6 @@
 
 #define VDEV_MP_KEY    "bus_vdev_mp"
 
-int vdev_logtype_bus;
-
 /* Forward declare to access virtual bus name */
 static struct rte_bus rte_vdev_bus;
 
@@ -136,6 +134,56 @@ vdev_parse(const char *name, void *addr)
        return driver == NULL;
 }
 
+static int
+vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
+{
+       struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
+       const struct rte_vdev_driver *driver;
+
+       if (!vdev) {
+               rte_errno = EINVAL;
+               return -1;
+       }
+
+       if (!vdev->device.driver) {
+               VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
+               return 1;
+       }
+
+       driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
+                       driver);
+
+       if (driver->dma_map)
+               return driver->dma_map(vdev, addr, iova, len);
+
+       return 0;
+}
+
+static int
+vdev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
+{
+       struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
+       const struct rte_vdev_driver *driver;
+
+       if (!vdev) {
+               rte_errno = EINVAL;
+               return -1;
+       }
+
+       if (!vdev->device.driver) {
+               VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
+               return 1;
+       }
+
+       driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
+                       driver);
+
+       if (driver->dma_unmap)
+               return driver->dma_unmap(vdev, addr, iova, len);
+
+       return 0;
+}
+
 static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
@@ -192,7 +240,7 @@ alloc_devargs(const char *name, const char *args)
        else
                devargs->args = strdup("");
 
-       ret = snprintf(devargs->name, sizeof(devargs->name), "%s", name);
+       ret = strlcpy(devargs->name, name, sizeof(devargs->name));
        if (ret < 0 || ret >= (int)sizeof(devargs->name)) {
                free(devargs->args);
                free(devargs);
@@ -409,6 +457,10 @@ vdev_scan(void)
 
        if (rte_mp_action_register(VDEV_MP_KEY, vdev_action) < 0 &&
            rte_errno != EEXIST) {
+               /* for primary, unsupported IPC is not an error */
+               if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
+                               rte_errno == ENOTSUP)
+                       goto scan;
                VDEV_LOG(ERR, "Failed to add vdev mp action");
                return -1;
        }
@@ -436,6 +488,7 @@ vdev_scan(void)
                /* Fall through to allow private vdevs in secondary process */
        }
 
+scan:
        /* call custom scan callbacks if any */
        rte_spinlock_lock(&vdev_custom_scan_lock);
        TAILQ_FOREACH(custom_scan, &vdev_custom_scans, next) {
@@ -548,14 +601,10 @@ static struct rte_bus rte_vdev_bus = {
        .plug = vdev_plug,
        .unplug = vdev_unplug,
        .parse = vdev_parse,
+       .dma_map = vdev_dma_map,
+       .dma_unmap = vdev_dma_unmap,
        .dev_iterate = rte_vdev_dev_iterate,
 };
 
 RTE_REGISTER_BUS(vdev, rte_vdev_bus);
-
-RTE_INIT(vdev_init_log)
-{
-       vdev_logtype_bus = rte_log_register("bus.vdev");
-       if (vdev_logtype_bus >= 0)
-               rte_log_set_level(vdev_logtype_bus, RTE_LOG_NOTICE);
-}
+RTE_LOG_REGISTER(vdev_logtype_bus, bus.vdev, NOTICE);