From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by dpdk.org (Postfix) with ESMTP id 9DDE56A70 for ; Tue, 11 Apr 2017 17:44:38 +0200 (CEST) Received: by mail-wm0-f43.google.com with SMTP id t189so4271882wmt.1 for ; Tue, 11 Apr 2017 08:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=c8Hjn8QiLxXgaSBfkBVbaIa2RHA5QbF4JaatAcKXrhY=; b=wiqBj/nbVUpB4ow2M9akVi74QHkhPct6MsoPPVy2u5NIdkkTCSxOtNJ1D0tdOuRjy7 M3fs6AoQVAyBSgqZrFsRteMRiT9QH4L4rW4ONHlf+eV4iFLsQTFxKy6O9+jlauazxXQ9 2ye7nWlA0pE5YdQ4K1iiCrxoHyfUiFik9oI0qCJiWLIMKzEvWOkyO9oNqgIES0u1QHz7 Hry8m4ZKQjjodABhyNflOfEnqq2ClpfX7OEhQaouxBFbaJnckvHWMkJ4SNbpAYh/2e1t q1cbq8lnMOvs6VFZU/X0pGrgQa77OUIwpBXz4QnpPvbzsM0OyJ3amAbcMJdM1g26RXsM 8kuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=c8Hjn8QiLxXgaSBfkBVbaIa2RHA5QbF4JaatAcKXrhY=; b=dQI68Zsf5+Aj4OczBxFyC8O3TUNF/2ygaw50iB2fFfAzPinWbkJxTguXwJt8NfJxnB f3uhlkNFgff3sfIvb0Qj+tGxg/PEkYFPcrsOU2Kh1OXe37fCr0NjvKt6lB7OkItots9W ZYAXbnUiSkBNAPPc9zlrTQ/W1Zm50am+pnxpVo5JUhEdH18BYnkjcnkPuvq21JdobD9V wrPDtBootKVjMwBYRBcRCD4iFuInNUNGSYXrzNsYotPn12nJO9l5GJQjzhSVIKybWsv0 ZGK+qeplKdHfVYaGz3wni+PH/640snbU5S+bjveTmfllaZZz5Vo43xXoRVYUgSTzhnpw GkjQ== X-Gm-Message-State: AN3rC/57RmE2n+rUXsdee03kVwLA8+y+ErSJJZ9rDGx81H02Ussm+bj2qSz/v/OtQxgPRF3t X-Received: by 10.28.103.84 with SMTP id b81mr14426473wmc.124.1491925477460; Tue, 11 Apr 2017 08:44:37 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id v14sm2936830wmv.24.2017.04.11.08.44.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 08:44:36 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck Date: Tue, 11 Apr 2017 17:44:12 +0200 Message-Id: <8bbc807c13ee98855d90317f23fff3fdeda853bc.1491925092.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: <1488797809-12917-1-git-send-email-jblunck@infradead.org> In-Reply-To: References: Subject: [dpdk-dev] [PATCH v5 08/12] eal: make virtual bus use rte_vdev_device X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Apr 2017 15:44:39 -0000 From: Jan Blunck This allows the virtual bus to be rescanned and probed by tracking the creation of rte_vdev_device. Signed-off-by: Jan Blunck Tested-by: Ferruh Yigit Acked-by: Shreyansh Jain --- lib/librte_eal/common/eal_common_vdev.c | 195 +++++++++++++++++++++++++------- 1 file changed, 155 insertions(+), 40 deletions(-) diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c index e3a75fd..70da608 100644 --- a/lib/librte_eal/common/eal_common_vdev.c +++ b/lib/librte_eal/common/eal_common_vdev.c @@ -42,6 +42,7 @@ #include #include #include +#include /** Double linked list of virtual device drivers. */ TAILQ_HEAD(vdev_device_list, rte_vdev_device); @@ -72,9 +73,12 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver) } static int -vdev_probe_all_drivers(const char *name, const char *args) +vdev_probe_all_drivers(struct rte_vdev_device *dev) { + const char *name = rte_vdev_device_name(dev); + const char *args = rte_vdev_device_args(dev); struct rte_vdev_driver *driver; + int ret; TAILQ_FOREACH(driver, &vdev_driver_list, next) { /* @@ -84,90 +88,202 @@ vdev_probe_all_drivers(const char *name, const char *args) * So use strncmp to compare. */ if (!strncmp(driver->driver.name, name, - strlen(driver->driver.name))) - return driver->probe(name, args); + strlen(driver->driver.name))) { + dev->device.driver = &driver->driver; + ret = driver->probe(name, args); + if (ret) + dev->device.driver = NULL; + return ret; + } } /* Give new names precedence over aliases. */ TAILQ_FOREACH(driver, &vdev_driver_list, next) { if (driver->driver.alias && !strncmp(driver->driver.alias, name, - strlen(driver->driver.alias))) - return driver->probe(name, args); + strlen(driver->driver.alias))) { + dev->device.driver = &driver->driver; + ret = driver->probe(name, args); + if (ret) + dev->device.driver = NULL; + return ret; + } } return 1; } +static struct rte_vdev_device * +find_vdev(const char *name) +{ + struct rte_vdev_device *dev; + + if (!name) + return NULL; + + TAILQ_FOREACH(dev, &vdev_device_list, next) { + const char *devname = rte_vdev_device_name(dev); + if (!strncmp(devname, name, strlen(name))) + return dev; + } + + return NULL; +} + +static struct rte_devargs * +alloc_devargs(const char *name, const char *args) +{ + struct rte_devargs *devargs; + int ret; + + devargs = calloc(1, sizeof(*devargs)); + if (!devargs) + return NULL; + + devargs->type = RTE_DEVTYPE_VIRTUAL; + if (args) + devargs->args = strdup(args); + + ret = snprintf(devargs->virt.drv_name, + sizeof(devargs->virt.drv_name), "%s", name); + if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name)) { + free(devargs->args); + free(devargs); + return NULL; + } + + return devargs; +} + int rte_eal_vdev_init(const char *name, const char *args) { + struct rte_vdev_device *dev; + struct rte_devargs *devargs; int ret; if (name == NULL) return -EINVAL; - ret = vdev_probe_all_drivers(name, args); - if (ret > 0) - RTE_LOG(ERR, EAL, "no driver found for %s\n", name); + dev = find_vdev(name); + if (dev) + return -EEXIST; + + devargs = alloc_devargs(name, args); + if (!devargs) + return -ENOMEM; + + dev = calloc(1, sizeof(*dev)); + if (!dev) { + ret = -ENOMEM; + goto fail; + } + + dev->device.devargs = devargs; + dev->device.numa_node = SOCKET_ID_ANY; + + ret = vdev_probe_all_drivers(dev); + if (ret) { + if (ret > 0) + RTE_LOG(ERR, EAL, "no driver found for %s\n", name); + goto fail; + } + + TAILQ_INSERT_TAIL(&devargs_list, devargs, next); + + rte_eal_device_insert(&dev->device); + TAILQ_INSERT_TAIL(&vdev_device_list, dev, next); + return 0; +fail: + free(devargs->args); + free(devargs); + free(dev); return ret; } static int -vdev_remove_driver(const char *name) +vdev_remove_driver(struct rte_vdev_device *dev) { - struct rte_vdev_driver *driver; + const char *name = rte_vdev_device_name(dev); + const struct rte_vdev_driver *driver; - TAILQ_FOREACH(driver, &vdev_driver_list, next) { - /* - * search a driver prefix in virtual device name. - * For example, if the driver is pcap PMD, driver->name - * will be "net_pcap", but "name" will be "net_pcapN". - * So use strncmp to compare. - */ - if (!strncmp(driver->driver.name, name, - strlen(driver->driver.name))) - return driver->remove(name); - } - - /* Give new names precedence over aliases. */ - TAILQ_FOREACH(driver, &vdev_driver_list, next) { - if (driver->driver.alias && - !strncmp(driver->driver.alias, name, - strlen(driver->driver.alias))) - return driver->remove(name); + if (!dev->device.driver) { + RTE_LOG(DEBUG, EAL, "no driver attach to device %s\n", name); + return 1; } - return 1; + driver = container_of(dev->device.driver, const struct rte_vdev_driver, + driver); + return driver->remove(name); } int rte_eal_vdev_uninit(const char *name) { + struct rte_vdev_device *dev; + struct rte_devargs *devargs; int ret; if (name == NULL) return -EINVAL; - ret = vdev_remove_driver(name); - if (ret > 0) - RTE_LOG(ERR, EAL, "no driver found for %s\n", name); + dev = find_vdev(name); + if (!dev) + return -ENOENT; - return ret; + devargs = dev->device.devargs; + + ret = vdev_remove_driver(dev); + if (ret) + return ret; + + TAILQ_REMOVE(&vdev_device_list, dev, next); + rte_eal_device_remove(&dev->device); + + TAILQ_REMOVE(&devargs_list, devargs, next); + + free(devargs->args); + free(devargs); + free(dev); + return 0; } static int vdev_scan(void) { - /* for virtual devices we don't need to scan anything */ + struct rte_vdev_device *dev; + struct rte_devargs *devargs; + + /* for virtual devices we scan the devargs_list populated via cmdline */ + + TAILQ_FOREACH(devargs, &devargs_list, next) { + + if (devargs->type != RTE_DEVTYPE_VIRTUAL) + continue; + + dev = find_vdev(devargs->virt.drv_name); + if (dev) + continue; + + dev = calloc(1, sizeof(*dev)); + if (!dev) + return -1; + + dev->device.devargs = devargs; + dev->device.numa_node = SOCKET_ID_ANY; + + rte_eal_device_insert(&dev->device); + TAILQ_INSERT_TAIL(&vdev_device_list, dev, next); + } + return 0; } static int vdev_probe(void) { - struct rte_devargs *devargs; + struct rte_vdev_device *dev; /* * Note that the dev_driver_list is populated here @@ -176,15 +292,14 @@ vdev_probe(void) */ /* call the init function for each virtual device */ - TAILQ_FOREACH(devargs, &devargs_list, next) { + TAILQ_FOREACH(dev, &vdev_device_list, next) { - if (devargs->type != RTE_DEVTYPE_VIRTUAL) + if (dev->device.driver) continue; - if (rte_eal_vdev_init(devargs->virt.drv_name, - devargs->args)) { + if (vdev_probe_all_drivers(dev)) { RTE_LOG(ERR, EAL, "failed to initialize %s device\n", - devargs->virt.drv_name); + rte_vdev_device_name(dev)); return -1; } } -- 2.1.4