DPDK patches and discussions
 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: [dpdk-dev] [PATCH 1/3] pci: implement attach/detach bus operation
Date: Wed, 24 May 2017 17:18:29 +0200	[thread overview]
Message-ID: <4ae996fef85b87917d442f7700c7a0239531d641.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_pci.c | 50 ++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 6d9fdda..269abb8 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -76,6 +76,7 @@
 #include <rte_pci.h>
 #include <rte_per_lcore.h>
 #include <rte_memory.h>
+#include <rte_memcpy.h>
 #include <rte_memzone.h>
 #include <rte_eal.h>
 #include <rte_string_fns.h>
@@ -546,12 +547,61 @@ pci_find_device(int (*match)(const struct rte_device *dev, const void *data),
 	return NULL;
 }
 
+static int
+pci_attach(struct rte_device *dev)
+{
+	struct rte_pci_device *pdev;
+	struct rte_pci_addr addr;
+
+	if (dev == NULL)
+		return -EINVAL;
+	if (pci_parse(dev->name, &addr))
+		return -EFAULT;
+	/*
+	 * Update eventual pci device in global list.
+	 * Insert it if none was found.
+	 */
+	if (pci_update_device(&addr) < 0)
+		return -EIO;
+	/* Find the current device holding this address in the bus. */
+	FOREACH_DEVICE_ON_PCIBUS(pdev) {
+		if (rte_eal_compare_pci_addr(&pdev->addr, &addr))
+			continue;
+		/* Update eventual devargs, others device infos. */
+		if (dev != &pdev->device)
+			rte_memcpy(&pdev->device, dev, sizeof(*dev));
+		break;
+	}
+	if (rte_pci_probe_one(&addr))
+		return -ENODEV;
+	/* Get back new device info. */
+	if (dev != &pdev->device)
+		rte_memcpy(dev, &pdev->device, sizeof(*dev));
+	return 0;
+}
+
+static int
+pci_detach(struct rte_device *dev)
+{
+	struct rte_pci_addr addr;
+
+	if (dev == NULL)
+		return -EINVAL;
+	if (pci_parse(dev->name, &addr))
+		return -EFAULT;
+	if (rte_pci_detach(&addr))
+		return -ENODEV;
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
 		.parse = pci_parse,
+		.attach = pci_attach,
+		.detach = pci_detach,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
-- 
2.1.4

  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 [dpdk-dev] [PATCH 0/3] eal: complete attach / detach support Gaetan Rivet
2017-05-24 15:18 ` Gaetan Rivet [this message]
2017-05-24 15:18 ` [dpdk-dev] [PATCH 2/3] vdev: implement attach bus operation Gaetan Rivet
2017-05-24 15:18 ` [dpdk-dev] [PATCH 3/3] vdev: use standard bus registration function Gaetan Rivet
2017-06-01 10:11 ` [dpdk-dev] [PATCH v2 0/3] eal: complete attach / detach support Gaetan Rivet
2017-06-01 10:12   ` [dpdk-dev] [PATCH v2 1/3] pci: implement plug/unplug bus operation Gaetan Rivet
2017-06-01 10:12   ` [dpdk-dev] [PATCH v2 2/3] dev: remove vdev function dependency Gaetan Rivet
2017-06-01 10:12   ` [dpdk-dev] [PATCH v2 3/3] vdev: use standard bus registration function Gaetan Rivet
2017-06-07 23:58   ` [dpdk-dev] [PATCH v3 0/3] eal: complete attach / detach support Gaetan Rivet
2017-06-07 23:58     ` [dpdk-dev] [PATCH v3 1/3] pci: implement hotplug bus operation Gaetan Rivet
2017-06-07 23:58     ` [dpdk-dev] [PATCH v3 2/3] dev: remove vdev function dependency Gaetan Rivet
2017-06-21 14:42       ` Thomas Monjalon
2017-06-07 23:58     ` [dpdk-dev] [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=4ae996fef85b87917d442f7700c7a0239531d641.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 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).