From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id A108FA2F for ; Wed, 15 Feb 2017 11:02:31 +0100 (CET) Received: by mail-wm0-f66.google.com with SMTP id u63so7332638wmu.2 for ; Wed, 15 Feb 2017 02:02:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZJyfLmKVJkmvkHooJ6YRHYJgIq9HNafCzitTzUTYJf4=; b=kawGo1gjgj/Ij4l0CeXWEQ623goBcISJP9NbF+zMdPX9S7SGNmMYHLgovP4HcIsgLY SBCGz2cGfjlw4NzmKToZ2cmP5VGa99KdixuyMi2P+WtnC0u9vfAFZr/CxcSDCxqQx5mq NItKWbXw3soygx51wUKsY+2hpieiUSXGMZKrQehh6zM4vbY4QE9YKK3LoQyBLaq8m0v4 Cha/cRt9HIurHetA5ar3wKfTq72Bvzy61aGYwu5rS8WKU72UTRT1rLw/tF7XvcVBxu9S GzHyz/v8JbUJ72x5W+8JmkbTeoq3KaXJ6hM5nJ4rG7qHUc4X2n4pPw6SvraXT39S+ttf Y+yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ZJyfLmKVJkmvkHooJ6YRHYJgIq9HNafCzitTzUTYJf4=; b=VnbZiJwDQYSlMcI80A6GD1J4YzL1+TxsVd5TT13Gg4SY7ca0SapSy+Mv6YC/LEwrgS 2uXFr2JG8+2cJ8sSnVBf6XNK/BXZ2BobQzJWw/onGwKJ21Nwb6OoXB3gFHT2CP1YfLvp 3twWr79Au5d3f0t8ZUNcLbKFl1gAHXzjCY1fijEkjHqhM96S5CGJWCzNcgpKrMJK+qiX s/kLgDdqwUT+xBKM3ZNP8BSA1UdSGEpLPqjbd6I13Vp3/nru+B9Aj07SV3KYxxr/7MGp s2Ppzm0SXMKFuC2rMPRwqoQ2WZlyXH37gO9PCxXIyqtnDOO1m7A93W7Rea9kVEemwwB/ Yqog== X-Gm-Message-State: AMke39lmn+/DafK5xaKLn4YDjGTYPiAof+1ViPKktVsgIYdeWO7AteON7lMX3TXxV8O1/A== X-Received: by 10.28.142.16 with SMTP id q16mr7058592wmd.78.1487152951054; Wed, 15 Feb 2017 02:02:31 -0800 (PST) Received: from weierstrass.local.net ([91.200.109.169]) by smtp.gmail.com with ESMTPSA id k195sm4716061wmd.7.2017.02.15.02.02.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Feb 2017 02:02:30 -0800 (PST) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Cc: shreyansh.jain@nxp.com Date: Wed, 15 Feb 2017 11:02:09 +0100 Message-Id: <1487152929-23627-8-git-send-email-jblunck@infradead.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487152929-23627-1-git-send-email-jblunck@infradead.org> References: <1487152929-23627-1-git-send-email-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH 7/7] 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: Wed, 15 Feb 2017 10:02:31 -0000 This allows the virtual bus to be rescanned and probed by tracking the creation of rte_vdev_device. Signed-off-by: Jan Blunck --- lib/librte_eal/common/eal_common_vdev.c | 194 +++++++++++++++++++++++++------- 1 file changed, 154 insertions(+), 40 deletions(-) diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c index 61677de..5909c85 100644 --- a/lib/librte_eal/common/eal_common_vdev.c +++ b/lib/librte_eal/common/eal_common_vdev.c @@ -67,9 +67,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) { + char *name = dev->device.devargs->virt.drv_name; + char *args = dev->device.devargs->args; struct rte_vdev_driver *driver; + int ret; TAILQ_FOREACH(driver, &vdev_driver_list, next) { /* @@ -79,90 +82,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) { + if (!strncmp(dev->device.devargs->virt.drv_name, 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 = -1; + + 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; + char *name = dev->device.devargs->virt.drv_name; + 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 = -1; + + 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 @@ -171,15 +286,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); + dev->device.devargs->virt.drv_name); return -1; } } -- 2.7.4