X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fbus%2Fvdev%2Fvdev.c;h=281a2c34e8772e34a0e445a595040f70263b2b8f;hb=37ff91c158a342f1f4757983da078d0a9d4992d0;hp=72254117917b3dc5c8d6f07fe1f447c6e37ca1a4;hpb=4169ed6ed1c31b75f070cdccf3ee82561d4b79ce;p=dpdk.git diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index 7225411791..281a2c34e8 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -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,18 +134,80 @@ 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) { const char *name; struct rte_vdev_driver *driver; + enum rte_iova_mode iova_mode; int ret; + if (rte_dev_is_probed(&dev->device)) + return -EEXIST; + name = rte_vdev_device_name(dev); VDEV_LOG(DEBUG, "Search driver to probe device %s", name); if (vdev_parse(name, &driver)) return -1; + + iova_mode = rte_eal_iova_mode(); + if ((driver->drv_flags & RTE_VDEV_DRV_NEED_IOVA_AS_VA) && (iova_mode == RTE_IOVA_PA)) { + VDEV_LOG(ERR, "%s requires VA IOVA mode but current mode is PA, not initializing", + name); + return -1; + } + ret = driver->probe(dev); if (ret == 0) dev->device.driver = &driver->driver; @@ -185,13 +245,14 @@ alloc_devargs(const char *name, const char *args) devargs->bus = &rte_vdev_bus; if (args) - devargs->args = strdup(args); + devargs->data = strdup(args); else - devargs->args = strdup(""); + devargs->data = strdup(""); + devargs->args = devargs->data; - 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); + rte_devargs_reset(devargs); free(devargs); return NULL; } @@ -245,7 +306,7 @@ insert_vdev(const char *name, const char *args, return 0; fail: - free(devargs->args); + rte_devargs_reset(devargs); free(devargs); free(dev); return ret; @@ -406,6 +467,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; } @@ -433,6 +498,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) { @@ -442,7 +508,7 @@ vdev_scan(void) * by calling rte_devargs_insert() with * devargs.bus = rte_bus_find_by_name("vdev"); * devargs.type = RTE_DEVTYPE_VIRTUAL; - * devargs.policy = RTE_DEV_WHITELISTED; + * devargs.policy = RTE_DEV_ALLOWED; */ custom_scan->callback(custom_scan->user_arg); } @@ -480,7 +546,7 @@ static int vdev_probe(void) { struct rte_vdev_device *dev; - int ret = 0; + int r, ret = 0; /* call the init function for each virtual device */ TAILQ_FOREACH(dev, &vdev_device_list, next) { @@ -489,10 +555,10 @@ vdev_probe(void) * we call each driver probe. */ - if (rte_dev_is_probed(&dev->device)) - continue; - - if (vdev_probe_all_drivers(dev)) { + r = vdev_probe_all_drivers(dev); + if (r != 0) { + if (r == -EEXIST) + continue; VDEV_LOG(ERR, "failed to initialize %s device", rte_vdev_device_name(dev)); ret = -1; @@ -538,6 +604,25 @@ vdev_unplug(struct rte_device *dev) return rte_vdev_uninit(dev->name); } +static enum rte_iova_mode +vdev_get_iommu_class(void) +{ + const char *name; + struct rte_vdev_device *dev; + struct rte_vdev_driver *driver; + + TAILQ_FOREACH(dev, &vdev_device_list, next) { + name = rte_vdev_device_name(dev); + if (vdev_parse(name, &driver)) + continue; + + if (driver->drv_flags & RTE_VDEV_DRV_NEED_IOVA_AS_VA) + return RTE_IOVA_VA; + } + + return RTE_IOVA_DC; +} + static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, @@ -545,14 +630,11 @@ 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, + .get_iommu_class = vdev_get_iommu_class, .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_DEFAULT(vdev_logtype_bus, NOTICE);