From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>
Subject: [dpdk-dev] [PATCH 1/9] eal: return device handle upon plugin
Date: Sun, 9 Jul 2017 03:45:37 +0200 [thread overview]
Message-ID: <d93892883d6e9ba8ef563357e86625b8b141deaf.1499563730.git.gaetan.rivet@6wind.com> (raw)
In-Reply-To: <cover.1499563730.git.gaetan.rivet@6wind.com>
In-Reply-To: <cover.1499563730.git.gaetan.rivet@6wind.com>
This device handle can be useful for other systems calling hotplug
functions, to retrieve for example any associated ethdev.
This change avoids unecessary calls to rte_bus_find, as the handle is
already known and available.
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
lib/librte_eal/common/eal_common_dev.c | 40 +++++++++++++++++++++++----------
lib/librte_eal/common/include/rte_dev.h | 10 +++++----
2 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 32e12b5..292fefe 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -42,6 +42,7 @@
#include <rte_devargs.h>
#include <rte_debug.h>
#include <rte_devargs.h>
+#include <rte_errno.h>
#include <rte_log.h>
#include "eal_private.h"
@@ -67,6 +68,7 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
int rte_eal_dev_attach(const char *name, const char *devargs)
{
+ struct rte_device *dev;
int ret;
if (name == NULL || devargs == NULL) {
@@ -74,9 +76,9 @@ int rte_eal_dev_attach(const char *name, const char *devargs)
return -EINVAL;
}
- ret = rte_eal_hotplug_add("pci", name, devargs);
- if (ret && ret != -EINVAL)
- return ret;
+ dev = rte_eal_hotplug_add("pci", name, devargs);
+ if (dev == NULL && rte_errno != EINVAL)
+ return -rte_errno;
/*
* If we haven't found a bus device the user meant to "hotplug" a
@@ -118,7 +120,8 @@ int rte_eal_dev_detach(struct rte_device *dev)
return ret;
}
-int rte_eal_hotplug_add(const char *busname, const char *devname,
+struct rte_device *
+rte_eal_hotplug_add(const char *busname, const char *devname,
const char *devargs)
{
struct rte_bus *bus;
@@ -128,31 +131,39 @@ int rte_eal_hotplug_add(const char *busname, const char *devname,
bus = rte_bus_find_by_name(busname);
if (bus == NULL) {
RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname);
- return -ENOENT;
+ rte_errno = ENOENT;
+ return NULL;
}
if (bus->plug == NULL) {
RTE_LOG(ERR, EAL, "Function plug not supported by bus (%s)\n",
bus->name);
- return -ENOTSUP;
+ rte_errno = ENOTSUP;
+ return NULL;
}
ret = bus->scan();
- if (ret)
- return ret;
+ if (ret) {
+ rte_errno = -ret;
+ return NULL;
+ }
dev = bus->find_device(NULL, cmp_detached_dev_name, devname);
if (dev == NULL) {
RTE_LOG(ERR, EAL, "Cannot find unplugged device (%s)\n",
devname);
- return -EINVAL;
+ rte_errno = EINVAL;
+ return NULL;
}
ret = bus->plug(dev, devargs);
- if (ret)
+ if (ret) {
RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
dev->name);
- return ret;
+ rte_errno = -ret;
+ return NULL;
+ }
+ return dev;
}
int rte_eal_hotplug_remove(const char *busname, const char *devname)
@@ -164,24 +175,29 @@ int rte_eal_hotplug_remove(const char *busname, const char *devname)
bus = rte_bus_find_by_name(busname);
if (bus == NULL) {
RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", busname);
+ rte_errno = ENOENT;
return -ENOENT;
}
if (bus->unplug == NULL) {
RTE_LOG(ERR, EAL, "Function unplug not supported by bus (%s)\n",
bus->name);
+ rte_errno = ENOTSUP;
return -ENOTSUP;
}
dev = bus->find_device(NULL, cmp_dev_name, devname);
if (dev == NULL) {
RTE_LOG(ERR, EAL, "Cannot find plugged device (%s)\n", devname);
+ rte_errno = EINVAL;
return -EINVAL;
}
ret = bus->unplug(dev);
- if (ret)
+ if (ret) {
RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n",
dev->name);
+ rte_errno = -ret;
+ }
return ret;
}
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index bcd8b1e..30d1f2e 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -218,10 +218,12 @@ int rte_eal_dev_detach(struct rte_device *dev);
* @param devargs
* Device arguments to be passed to the driver.
* @return
- * 0 on success, negative on error.
+ * The pointer to the plugged rte_device on success.
+ * NULL on error. rte_errno is then set.
*/
-int rte_eal_hotplug_add(const char *busname, const char *devname,
- const char *devargs);
+struct rte_device *rte_eal_hotplug_add(const char *busname,
+ const char *devname,
+ const char *devargs);
/**
* @warning
@@ -234,7 +236,7 @@ int rte_eal_hotplug_add(const char *busname, const char *devname,
* @param devname
* The device name being removed.
* @return
- * 0 on success, negative on error.
+ * 0 on success, negative on error. rte_errno is then set.
*/
int rte_eal_hotplug_remove(const char *busname, const char *devname);
--
2.1.4
next prev parent reply other threads:[~2017-07-09 1:46 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-09 1:45 [dpdk-dev] [PATCH 0/9] fix hotplug API Gaetan Rivet
2017-07-09 1:45 ` Gaetan Rivet [this message]
2017-07-09 1:45 ` [dpdk-dev] [PATCH 2/9] eal: fix hotplug add Gaetan Rivet
2017-07-09 1:45 ` [dpdk-dev] [PATCH 3/9] devargs: introduce removal function Gaetan Rivet
2017-07-09 1:45 ` [dpdk-dev] [PATCH 4/9] eal: release devargs on device removal Gaetan Rivet
2017-07-09 1:45 ` [dpdk-dev] [PATCH 5/9] pci: use given name as generic name Gaetan Rivet
2017-07-09 1:45 ` [dpdk-dev] [PATCH 6/9] pci: fix generic driver pointer on probe error Gaetan Rivet
2017-07-09 1:45 ` [dpdk-dev] [PATCH 7/9] pci: fix hotplug operations Gaetan Rivet
2017-07-09 1:45 ` [dpdk-dev] [PATCH 8/9] vdev: implement plug operation Gaetan Rivet
2017-07-09 1:45 ` [dpdk-dev] [PATCH 9/9] bus: remove useless plug parameter Gaetan Rivet
2017-07-09 10:38 ` [dpdk-dev] [PATCH 0/9] fix hotplug API Jan Blunck
2017-07-09 12:19 ` Gaëtan Rivet
2017-07-09 14:19 ` Thomas Monjalon
[not found] ` <20170711160211.GW11154@bidouze.vm.6wind.com>
[not found] ` <CALe+Z00Rc_6cn_ckWrK1cD2RsdWENM3s+ytOpxNymTmaqh8e0g@mail.gmail.com>
2017-07-11 19:21 ` Gaëtan Rivet
2017-07-10 23:18 ` [dpdk-dev] [PATCH v2 0/8] " Gaetan Rivet
2017-07-10 23:19 ` [dpdk-dev] [PATCH v2 1/8] vdev: implement plug operation Gaetan Rivet
2017-07-10 23:19 ` [dpdk-dev] [PATCH v2 2/8] devargs: introduce removal function Gaetan Rivet
2017-07-10 23:19 ` [dpdk-dev] [PATCH v2 3/8] devargs: introduce insert function Gaetan Rivet
2017-07-11 22:13 ` Thomas Monjalon
2017-07-10 23:19 ` [dpdk-dev] [PATCH v2 4/8] eal: fix hotplug add / remove Gaetan Rivet
2017-07-11 22:18 ` Thomas Monjalon
2017-07-10 23:19 ` [dpdk-dev] [PATCH v2 5/8] pci: use given name as generic name Gaetan Rivet
2017-07-11 22:05 ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2017-07-10 23:19 ` [dpdk-dev] [PATCH v2 6/8] pci: fix generic driver pointer on probe error Gaetan Rivet
2017-07-10 23:19 ` [dpdk-dev] [PATCH v2 7/8] pci: fix hotplug operations Gaetan Rivet
2017-07-10 23:19 ` [dpdk-dev] [PATCH v2 8/8] bus: remove useless plug parameter Gaetan Rivet
2017-07-11 23:25 ` [dpdk-dev] [PATCH v3 0/8] fix hotplug API Gaetan Rivet
2017-07-11 23:25 ` [dpdk-dev] [PATCH v3 1/8] vdev: implement plug operation Gaetan Rivet
2017-07-11 23:25 ` [dpdk-dev] [PATCH v3 2/8] devargs: introduce removal function Gaetan Rivet
2017-07-12 8:27 ` Jan Blunck
2017-07-12 17:22 ` Gaëtan Rivet
2017-07-11 23:25 ` [dpdk-dev] [PATCH v3 3/8] devargs: introduce insert function Gaetan Rivet
2017-07-12 8:20 ` Jan Blunck
2017-07-12 17:20 ` Gaëtan Rivet
2017-07-13 19:44 ` Jan Blunck
2017-07-11 23:25 ` [dpdk-dev] [PATCH v3 4/8] eal: fix hotplug add / remove Gaetan Rivet
2017-07-12 8:44 ` Jan Blunck
2017-07-12 17:33 ` Gaëtan Rivet
2017-07-11 23:25 ` [dpdk-dev] [PATCH v3 5/8] pci: use given name as generic name Gaetan Rivet
2017-07-11 23:25 ` [dpdk-dev] [PATCH v3 6/8] pci: fix generic driver pointer on probe error Gaetan Rivet
2017-07-11 23:25 ` [dpdk-dev] [PATCH v3 7/8] pci: fix hotplug operations Gaetan Rivet
2017-07-11 23:25 ` [dpdk-dev] [PATCH v3 8/8] bus: remove useless plug parameter Gaetan Rivet
2017-07-15 17:56 ` [dpdk-dev] [PATCH v4 0/8] fix hotplug API Gaetan Rivet
2017-07-15 17:56 ` [dpdk-dev] [PATCH v4 1/8] vdev: implement plug operation Gaetan Rivet
2017-07-15 17:56 ` [dpdk-dev] [PATCH v4 2/8] devargs: introduce removal function Gaetan Rivet
2017-07-15 17:56 ` [dpdk-dev] [PATCH v4 3/8] devargs: introduce insert function Gaetan Rivet
2017-07-15 17:56 ` [dpdk-dev] [PATCH v4 4/8] eal: fix hotplug add / remove Gaetan Rivet
2017-07-15 17:56 ` [dpdk-dev] [PATCH v4 5/8] pci: use given name as generic name Gaetan Rivet
2017-07-15 17:56 ` [dpdk-dev] [PATCH v4 6/8] pci: fix generic driver pointer on probe error Gaetan Rivet
2017-07-15 17:56 ` [dpdk-dev] [PATCH v4 7/8] pci: fix hotplug operations Gaetan Rivet
2017-07-15 17:56 ` [dpdk-dev] [PATCH v4 8/8] bus: remove useless plug parameter Gaetan Rivet
2017-07-19 21:27 ` [dpdk-dev] [PATCH v4 0/8] fix hotplug API Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d93892883d6e9ba8ef563357e86625b8b141deaf.1499563730.git.gaetan.rivet@6wind.com \
--to=gaetan.rivet@6wind.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).