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 BAA3C7CE1 for ; Wed, 24 May 2017 17:05:45 +0200 (CEST) Received: by mail-wr0-f180.google.com with SMTP id w50so56830596wrc.0 for ; Wed, 24 May 2017 08:05:45 -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=hAuqbXE8pNruIYyzPPwQnVncJfZ0w79ig9I//zn8u4Q=; b=dDs+oMQKg24mQexOCM/stKDAWiAN2EHJOqaG7GIvCUWK33mLsfxyWjt/GVTvTbN0DG kMG+rdRu/LyfYqdAmHmOnBfEsp/HbA6awd23T02zkHdlHTKFIhAfu6UVbafppE9bycHn nbcCDschFJ7MiszQH95wI8HgWVukCtXeES6N5Sv6Pl6iJYpq1v6uKVE7ldf+9nGTbttm cJcfot2p2ADRAUAlErJmbR6PJG9j2w9O26DuILA3ke08ijCHOLmMfB9yHaBcIT5wcUFZ 5Oa9UhIKxpWxm1ru3fUMPS5XIKtmDVxWDDMO8v9psFSVCtaALY78kORt6h0e8PKMl+H7 4EMg== 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=hAuqbXE8pNruIYyzPPwQnVncJfZ0w79ig9I//zn8u4Q=; b=dHS3NcTirghs9kMptbvBGxh2/CnXLNj/OgIEULy25dqG0jeGN0nqzKg67a5rTednkq /0heiPrmhm2cfS1wQ0sUNsKNWoyy73g9ojDFernyWJaL9FylloVBVA+97TeOFWzwoIhE xY5JsExCUHupym7yS7PjBemdExw/rYH1wZae7cPMdw64fmzo7K3I9tXvtL8OqlQL0nKd bw6rgeMtutGA9qSURpPPk7gaXFVzUfI/FdsUhwWmuVta7m4rusfewflWhgbL6Xm5miFZ DtO5mKQMNJky72+levHKg6sgnEFO28q+XMMiFjsWgu+QRPPI+BOrCbWKrn0RhEwI3mVM m/yw== X-Gm-Message-State: AODbwcA7OKTHxSmceCuuboUklQFmXhT6Y+xnTr4Ymu7PUXj8MlGjFfiC ay2K3aQAXbez4RXXo9A= X-Received: by 10.223.177.215 with SMTP id r23mr23180423wra.97.1495638344843; Wed, 24 May 2017 08:05:44 -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 25sm4076017wrz.8.2017.05.24.08.05.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 08:05:44 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck Date: Wed, 24 May 2017 17:05:00 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 8/9] 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, 24 May 2017 15:05:46 -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 --- 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..c2d0f8d 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->attach) { + RTE_LOG(ERR, EAL, "Bus function not supported\n"); + return -ENOTSUP; + } + + ret = bus->attach(dev); + 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->detach) { + 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->detach(dev); + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", + name); + return ret; } -- 2.1.4