All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>,
	Jan Blunck <jblunck@infradead.org>,
	Stephen Hemminger <stephen@networkplumber.org>,
	Maxime Coquelin <maxime.coquelin@redhat.com>,
	Jerin Jacob <jerin.jacob@caviumnetworks.com>,
	David Marchand <david.marchand@6wind.com>
Subject: [PATCH 2/3] vdev: implement attach bus operation
Date: Wed, 24 May 2017 17:18:30 +0200	[thread overview]
Message-ID: <0b2ee4823592849eef67bc28896399637d97acad.1495629219.git.gaetan.rivet@6wind.com> (raw)
In-Reply-To: <cover.1495629219.git.gaetan.rivet@6wind.com>
In-Reply-To: <cover.1495629219.git.gaetan.rivet@6wind.com>

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_dev.c  | 53 +++++++++++++++++++--------------
 lib/librte_eal/common/eal_common_vdev.c |  8 ++++-
 2 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 829d7f3..fdd06be 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -61,6 +61,9 @@ static int cmp_detached_dev_name(const struct rte_device *dev,
 int rte_eal_dev_attach(const char *name, const char *devargs)
 {
 	struct rte_device *dev;
+	struct rte_device device;
+	struct rte_devargs da;
+	struct rte_bus *bus;
 	int ret;
 
 	if (name == NULL || devargs == NULL) {
@@ -69,31 +72,35 @@ int rte_eal_dev_attach(const char *name, const char *devargs)
 	}
 
 	dev = rte_bus_find_device(NULL, cmp_detached_dev_name, name);
-	if (dev) {
-		struct rte_bus *bus;
-
+	if (dev)
 		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->attach) {
-			RTE_LOG(ERR, EAL, "Bus function not supported\n");
-			return -ENOTSUP;
-		}
-
-		ret = bus->attach(dev);
-		goto out;
+	else
+		bus = rte_bus_from_dev(name);
+	if (!bus) {
+		RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n",
+			name);
+		return -EINVAL;
 	}
-
-	/*
-	 * 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 (!bus->attach) {
+		RTE_LOG(ERR, EAL, "Bus function not supported\n");
+		return -ENOTSUP;
+	}
+	if (!dev) {
+		char da_str[snprintf(NULL, 0, "%s,%s", name, devargs) + 1];
+
+		/*
+		 * If we haven't found a bus device the user meant to "hotplug"
+		 * a device instead.
+		 */
+		dev = &device;
+		snprintf(da_str, sizeof(da_str), "%s,%s", name, devargs);
+		ret = rte_eal_devargs_parse(da_str, &da);
+		if (ret)
+			return ret;
+		dev->name = da.name;
+		dev->devargs = &da;
+	}
+	ret = bus->attach(dev);
 	if (ret)
 		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
 			name);
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index fc5e2d2..4e83326 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -356,6 +356,12 @@ vdev_find_device(int (*match)(const struct rte_device *dev, const void *data),
 }
 
 static int
+vdev_attach(struct rte_device *dev)
+{
+	return rte_vdev_init(dev->devargs->name, dev->devargs->args);
+}
+
+static int
 vdev_detach(struct rte_device *dev)
 {
 	/*
@@ -369,7 +375,7 @@ static struct rte_bus rte_vdev_bus = {
 	.scan = vdev_scan,
 	.probe = vdev_probe,
 	.find_device = vdev_find_device,
-	/* .attach = NULL, see comment on vdev_detach */
+	.attach = vdev_attach,
 	.detach = vdev_detach,
 	.parse = vdev_parse,
 };
-- 
2.1.4

  parent reply	other threads:[~2017-05-24 15:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 15:18 [PATCH 0/3] eal: complete attach / detach support Gaetan Rivet
2017-05-24 15:18 ` [PATCH 1/3] pci: implement attach/detach bus operation Gaetan Rivet
2017-05-24 15:18 ` Gaetan Rivet [this message]
2017-05-24 15:18 ` [PATCH 3/3] vdev: use standard bus registration function Gaetan Rivet
2017-06-01 10:11 ` [PATCH v2 0/3] eal: complete attach / detach support Gaetan Rivet
2017-06-01 10:12   ` [PATCH v2 1/3] pci: implement plug/unplug bus operation Gaetan Rivet
2017-06-01 10:12   ` [PATCH v2 2/3] dev: remove vdev function dependency Gaetan Rivet
2017-06-01 10:12   ` [PATCH v2 3/3] vdev: use standard bus registration function Gaetan Rivet
2017-06-07 23:58   ` [PATCH v3 0/3] eal: complete attach / detach support Gaetan Rivet
2017-06-07 23:58     ` [PATCH v3 1/3] pci: implement hotplug bus operation Gaetan Rivet
2017-06-07 23:58     ` [PATCH v3 2/3] dev: remove vdev function dependency Gaetan Rivet
2017-06-21 14:42       ` Thomas Monjalon
2017-06-07 23:58     ` [PATCH v3 3/3] vdev: use standard bus registration function Gaetan Rivet
2017-06-21 14:41       ` 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=0b2ee4823592849eef67bc28896399637d97acad.1495629219.git.gaetan.rivet@6wind.com \
    --to=gaetan.rivet@6wind.com \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=jblunck@infradead.org \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=stephen@networkplumber.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.