From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by dpdk.org (Postfix) with ESMTP id 009ED58CD for ; Wed, 31 May 2017 15:18:20 +0200 (CEST) Received: by mail-wm0-f46.google.com with SMTP id d127so19253893wmf.0 for ; Wed, 31 May 2017 06:18:20 -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=5FukUI6QGFumYaXUJjTPXw8Qfs0fXrDY7cvoSWizM6U=; b=bKkY78Ytf/dof9qEYzJ94dqH3mOnGHZGNSH/ObNg2Ocbb1LRM3TVGLi/7PvT35LExD QmH3S9n79+82GhVr6mW9nTlDVZVvbfLAX3NXLghdiNjmmJg46sF/DODWN23Sm1+BXlHr 2QX96SUJZBKUt8sWY6w7hm/+zyJlquBh2vEbIrpo/xndC+TbB+btqpcqHB0cxVO4+c5T wIgoQNE1OFLujAH5p6wUKc0+217OJdxivAQY+LwJee3ap+6LTSjdDAtewHY9+qM5or0k g3fKrB2c5wXspewUobfw5z/PDMyX1bUxr1AYDCWc27QOLz0bxv94BtavA6ZmPCE0fHY5 sZCw== 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=5FukUI6QGFumYaXUJjTPXw8Qfs0fXrDY7cvoSWizM6U=; b=Q37i2adfS7th2+3UuLxYRYvHiJbC48/YiWqa+VMgu+S7XlS0G5s70CCQnZciDj8d+B CkVOGzGWyLFcH/rQII9InFoe+BL4zC29ZXLK5/ll+F4Ed3cBqv0Eqsws4iLe88YJKUsg VMmqTp/p8+7VWmOWoT2Y280Tw584FaMyO/1KkWCwaDPbwW1DCYOEl7SogcxVehdV7qgC RjCGtiUGCQRDv9fhc4P20Xp6QdCwMyRDHlfu2dPqFgnVMmnKTa5ou7VGBxS5Ux20lQ65 sps/X+o+fB9mIq7pibYTXY0T0qGJiEyAIQCm+i9siPLs2YZyk3vJykw/h//efL5lMzB2 m0yA== X-Gm-Message-State: AODbwcAeH4qGc7djtGkAVO6gg1WxITNxpBslh5BP22A0MM/jq+9s+4tC 2bp7D2FhtOCJEF97pDs= X-Received: by 10.28.184.216 with SMTP id i207mr5780963wmf.31.1496236699637; Wed, 31 May 2017 06:18:19 -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 g77sm10045744wmd.19.2017.05.31.06.18.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 May 2017 06:18:18 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Wed, 31 May 2017 15:17:54 +0200 Message-Id: <015970f45de0f7ec5c89bfddb19f270f567ba41c.1496235017.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 09/11] eal: make virtual driver probe and remove take 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, 31 May 2017 13:18:21 -0000 From: Jan Blunck This is a preparation to embed the generic rte_device into the rte_eth_dev also for virtual devices. Signed-off-by: Jan Blunck Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 93 ++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 22 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index a400ddd..7508b70 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -45,50 +46,98 @@ #include "eal_private.h" +static int cmp_detached_dev_name(const struct rte_device *dev, + const void *_name) +{ + const char *name = _name; + + /* skip attached devices */ + if (dev->driver) + return 0; + + return !strcmp(dev->name, name); +} + int rte_eal_dev_attach(const char *name, const char *devargs) { - struct rte_pci_addr addr; + struct rte_device *dev; + int ret; if (name == NULL || devargs == NULL) { RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n"); return -EINVAL; } - if (eal_parse_pci_DomBDF(name, &addr) == 0) { - if (rte_pci_probe_one(&addr) < 0) - goto err; + dev = rte_bus_find_device(NULL, cmp_detached_dev_name, name); + if (dev) { + struct rte_bus *bus; + + bus = rte_bus_find_by_device(dev); + if (!bus) { + RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", + name); + return -EINVAL; + } - } else { - if (rte_vdev_init(name, devargs)) - goto err; + if (!bus->plug) { + RTE_LOG(ERR, EAL, "Bus function not supported\n"); + return -ENOTSUP; + } + + ret = bus->plug(dev->devargs); + goto out; } - return 0; + /* + * If we haven't found a bus device the user meant to "hotplug" a + * virtual device instead. + */ + ret = rte_vdev_init(name, devargs); +out: + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", + name); + return ret; +} + +static int cmp_dev_name(const struct rte_device *dev, const void *_name) +{ + const char *name = _name; -err: - RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name); - return -EINVAL; + return !strcmp(dev->name, name); } int rte_eal_dev_detach(const char *name) { - struct rte_pci_addr addr; + struct rte_device *dev; + struct rte_bus *bus; + int ret; if (name == NULL) { RTE_LOG(ERR, EAL, "Invalid device provided.\n"); return -EINVAL; } - if (eal_parse_pci_DomBDF(name, &addr) == 0) { - if (rte_pci_detach(&addr) < 0) - goto err; - } else { - if (rte_vdev_uninit(name)) - goto err; + dev = rte_bus_find_device(NULL, cmp_dev_name, name); + if (!dev) { + RTE_LOG(ERR, EAL, "Cannot find device (%s)\n", name); + return -EINVAL; + } + + bus = rte_bus_find_by_device(dev); + if (!bus) { + RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", name); + return -EINVAL; + } + + if (!bus->unplug) { + RTE_LOG(ERR, EAL, "Bus function not supported\n"); + return -ENOTSUP; } - return 0; -err: - RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", name); - return -EINVAL; + ret = bus->unplug(dev->devargs); + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", + name); + return ret; } -- 2.1.4