From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by dpdk.org (Postfix) with ESMTP id D9C19326B for ; Thu, 8 Jun 2017 01:53:47 +0200 (CEST) Received: by mail-wr0-f180.google.com with SMTP id g76so11967976wrd.1 for ; Wed, 07 Jun 2017 16:53:47 -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=jNkBOKUIdoJ9SlwQzEZqLaswsUA02fbgKJ1ki6BIAh0=; b=BGKfyG9hbbzR1wFjFSeo0AXo0LjwqiLw9U95xvxm+6bpYE8C8pJZkst5CHFg7J8no0 39oFlPJalXkoeep7b+ap68PCzjnFxqd++CRwPMSVKyAunUIQj6DEgS9eiceyTlN59Hr/ z/MeAXRJ65TyCNv5ZaLVV5UmA6HFXGTiFXzGbh5M3kiRClCSYWD1Tk7Yb+8cW8I3a6/2 KpJH36vUSJERMnQLcBV3FvEOv+tVx8e48KHrLi6qPpve2kLiCDtzKXwo6w0Ak/qb3ULw YguIia6cp58Pp8O6FmH1NEp4lqds5nnzOZrOqr6gN2qclWevK3MnomB2jF7uI7CXIAD/ CsEw== 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=jNkBOKUIdoJ9SlwQzEZqLaswsUA02fbgKJ1ki6BIAh0=; b=Tn+eIwTjUbQbWhYOMcuLGqA0g8LRjrde7wecXoj5MOSdolsgtIczkVSixYIWNlPGqD do2iH8IuJBG2FRv8IXtNh8FqkRgRhFBLAVJpJs/AoHCroCVfTHnI0+Lcyd7ejX1pua1r b3E36HTFW4kQHrNSKInYzbx4LVn7gbPmmve82Iz0H5EiLybOtJkUWgpUCU8EXWedpuIO Bo+kexTHXBzhvIMRmHkmMeHQGdOwETnv9iXVgEMakSGRztqA8/3U/10EcCMyWhi4pumd 0bCua3ArxrER7ndwXxeCgP0aKe7eAw9TK3An+cKXHzKY6nlgyWqkDMLjhMo7eN6dLk2n NMSg== X-Gm-Message-State: AODbwcCjYfBhYF7/01Mx38+oaNIc03qscMWJMbaQkMZsj2vwnVzH16KH A05jO24iibCmziVIVN4= X-Received: by 10.223.167.75 with SMTP id e11mr13002493wrd.95.1496879627102; Wed, 07 Jun 2017 16:53:47 -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 z23sm4589942wrz.0.2017.06.07.16.53.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 16:53:46 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck , Gaetan Rivet Date: Thu, 8 Jun 2017 01:53:22 +0200 Message-Id: <5508f9ca7c784444f1ac2908ff8aa89f8481136b.1496876710.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 v3 08/10] 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, 07 Jun 2017 23:53:48 -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..733da91 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) == NULL); + 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); + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", + name); + return ret; } -- 2.1.4