DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shreyansh Jain <shreyansh.jain@nxp.com>
To: <dev@dpdk.org>
Cc: <viktorin@rehivetech.com>, <thomas.monjalon@6wind.com>,
	<david.marchand@6wind.com>,
	Shreyansh Jain <shreyansh.jain@nxp.com>
Subject: [dpdk-dev] [PATCH v2 3/4] eal/linux: generalize PCI kernel unbinding driver to EAL
Date: Fri, 14 Oct 2016 16:25:26 +0530	[thread overview]
Message-ID: <1476442527-30726-4-git-send-email-shreyansh.jain@nxp.com> (raw)
In-Reply-To: <1476442527-30726-1-git-send-email-shreyansh.jain@nxp.com>

From: Jan Viktorin <viktorin@rehivetech.com>

Generalize the PCI-specific pci_unbind_kernel_driver. It is now divided
into two parts. First, determination of the path and string identification
of the device to be unbound. Second, the actual unbind operation which is
generic.

BSD implementation updated as ENOTSUP

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
--
Changes since v1:
 - update BSD support for unbind kernel driver

---
 lib/librte_eal/bsdapp/eal/eal.c       |  7 +++++++
 lib/librte_eal/bsdapp/eal/eal_pci.c   |  4 ++--
 lib/librte_eal/common/eal_private.h   | 13 +++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c     | 26 ++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c | 33 +++++++++------------------------
 5 files changed, 57 insertions(+), 26 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 35e3117..5271fc2 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -633,3 +633,10 @@ rte_eal_process_type(void)
 {
 	return rte_config.process_type;
 }
+
+int
+rte_eal_unbind_kernel_driver(const char *devpath __rte_unused,
+			     const char *devid __rte_unused)
+{
+	return -ENOTSUP;
+}
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 7ed0115..703f034 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -89,11 +89,11 @@
 
 /* unbind kernel driver for this device */
 int
-pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
+pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented "
 		"for BSD\n");
-	return -ENOTSUP;
+	return rte_eal_unbind_kernel_driver(dev);
 }
 
 /* Map pci device */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 9e7d8f6..b0c208a 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -256,6 +256,19 @@ int rte_eal_alarm_init(void);
 int rte_eal_check_module(const char *module_name);
 
 /**
+ * Unbind kernel driver bound to the device specified by the given devpath,
+ * and its string identification.
+ *
+ * @param devpath  path to the device directory ("/sys/.../devices/<name>")
+ * @param devid    identification of the device (<name>)
+ *
+ * @return
+ *      -1  unbind has failed
+ *       0  module has been unbound
+ */
+int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid);
+
+/**
  * Get cpu core_id.
  *
  * This function is private to the EAL.
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 2075282..5f6676d 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -943,3 +943,29 @@ rte_eal_check_module(const char *module_name)
 	/* Module has been found */
 	return 1;
 }
+
+int
+rte_eal_unbind_kernel_driver(const char *devpath, const char *devid)
+{
+	char filename[PATH_MAX];
+	FILE *f;
+
+	snprintf(filename, sizeof(filename),
+		 "%s/driver/unbind", devpath);
+
+	f = fopen(filename, "w");
+	if (f == NULL) /* device was not bound */
+		return 0;
+
+	if (fwrite(devid, strlen(devid), 1, f) == 0) {
+		RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
+				filename);
+		goto error;
+	}
+
+	fclose(f);
+	return 0;
+error:
+	fclose(f);
+	return -1;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 876ba38..a03553f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -59,38 +59,23 @@ int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
-	FILE *f;
-	char filename[PATH_MAX];
-	char buf[BUFSIZ];
+	char devpath[PATH_MAX];
+	char devid[BUFSIZ];
 	struct rte_pci_addr *loc = &dev->addr;
 
-	/* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
-	snprintf(filename, sizeof(filename),
-		"%s/" PCI_PRI_FMT "/driver/unbind", pci_get_sysfs_path(),
+	/* devpath /sys/bus/pci/devices/AAAA:BB:CC.D */
+	snprintf(devpath, sizeof(devpath),
+		"%s/" PCI_PRI_FMT, pci_get_sysfs_path(),
 		loc->domain, loc->bus, loc->devid, loc->function);
 
-	f = fopen(filename, "w");
-	if (f == NULL) /* device was not bound */
-		return 0;
-
-	n = snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
+	n = snprintf(devid, sizeof(devid), PCI_PRI_FMT "\n",
 	             loc->domain, loc->bus, loc->devid, loc->function);
-	if ((n < 0) || (n >= (int)sizeof(buf))) {
+	if ((n < 0) || (n >= (int)sizeof(devid))) {
 		RTE_LOG(ERR, EAL, "%s(): snprintf failed\n", __func__);
-		goto error;
-	}
-	if (fwrite(buf, n, 1, f) == 0) {
-		RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
-				filename);
-		goto error;
+		return -1;
 	}
 
-	fclose(f);
-	return 0;
-
-error:
-	fclose(f);
-	return -1;
+	return rte_eal_unbind_kernel_driver(devpath, devid);
 }
 
 static int
-- 
2.7.4

  parent reply	other threads:[~2016-10-14 10:54 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-01  4:41 [dpdk-dev] [PATCH 0/5] Generalize PCI specific EAL function/structures Shreyansh Jain
2016-09-01  4:41 ` [dpdk-dev] [PATCH 1/5] eal: make enum rte_kernel_driver non-PCI specific Shreyansh Jain
2016-09-11 12:15   ` Yuanhan Liu
2016-09-12  5:10     ` Shreyansh Jain
2016-09-01  4:41 ` [dpdk-dev] [PATCH 2/5] eal: extract function eal_parse_sysfs_valuef Shreyansh Jain
2016-09-01  6:30   ` Stephen Hemminger
2016-09-01  9:01     ` Shreyansh Jain
2016-09-01  4:41 ` [dpdk-dev] [PATCH 3/5] eal: Convert pci_(un)map_resource to rte_eal_(un)map_resource Shreyansh Jain
2016-09-01  4:41 ` [dpdk-dev] [PATCH 4/5] eal/linux: extract function rte_eal_unbind_kernel_driver Shreyansh Jain
2016-09-01  4:41 ` [dpdk-dev] [PATCH 5/5] eal/linux: extract function rte_eal_get_kernel_driver_by_path Shreyansh Jain
2016-09-27 14:12 ` [dpdk-dev] [PATCH v1 0/4] Generalize PCI specific EAL function/structures Shreyansh Jain
2016-09-27 14:12   ` [dpdk-dev] [PATCH v1 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
2016-09-27 14:12   ` [dpdk-dev] [PATCH v1 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
2016-09-27 14:12   ` [dpdk-dev] [PATCH v1 3/4] eal/linux: generalize PCI kernel unbinding driver " Shreyansh Jain
2016-09-27 14:12   ` [dpdk-dev] [PATCH v1 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain
2016-09-30 15:31   ` [dpdk-dev] [PATCH v1 0/4] Generalize PCI specific EAL function/structures David Marchand
2016-10-03  5:37     ` Shreyansh Jain
2016-10-03 13:12       ` Jan Viktorin
2016-10-03 13:36       ` Thomas Monjalon
2016-10-06 11:43         ` Shreyansh Jain
2016-10-06 13:01           ` Thomas Monjalon
2016-10-13  6:47     ` Shreyansh Jain
2016-10-14 10:55   ` [dpdk-dev] [PATCH v2 " Shreyansh Jain
2016-10-14 10:55     ` [dpdk-dev] [PATCH v2 1/4] eal: generalize PCI kernel driver enum to EAL Shreyansh Jain
2016-10-14 10:55     ` [dpdk-dev] [PATCH v2 2/4] eal: generalize PCI map/unmap resource " Shreyansh Jain
2016-10-14 10:55     ` Shreyansh Jain [this message]
2016-10-14 10:55     ` [dpdk-dev] [PATCH v2 4/4] eal/linux: generalize PCI kernel driver extraction " Shreyansh Jain

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=1476442527-30726-4-git-send-email-shreyansh.jain@nxp.com \
    --to=shreyansh.jain@nxp.com \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=thomas.monjalon@6wind.com \
    --cc=viktorin@rehivetech.com \
    /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).