DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jeff Guo <jia.guo@intel.com>
To: stephen@networkplumber.org, bruce.richardson@intel.com,
	ferruh.yigit@intel.com, konstantin.ananyev@intel.com,
	gaetan.rivet@6wind.com, jingjing.wu@intel.com,
	thomas@monjalon.net, motih@mellanox.com,
	harry.van.haaren@intel.com, jianfeng.tan@intel.com
Cc: jblunck@infradead.org, shreyansh.jain@nxp.com, dev@dpdk.org,
	jia.guo@intel.com, helin.zhang@intel.com
Subject: [dpdk-dev] [PATCH V18 4/5] eal: add driver auto bind for hot insertion
Date: Wed,  4 Apr 2018 02:17:22 +0800	[thread overview]
Message-ID: <1522779443-1932-5-git-send-email-jia.guo@intel.com> (raw)
In-Reply-To: <1522779443-1932-1-git-send-email-jia.guo@intel.com>

Normally we use driverctl or dpdk-devbind.py to bind kernel driver before
application running, but lack of an function to automatically bind driver
at runtime. This patch introduce a new API (rte_dev_bind_kernel_driver),
aim to let user call it to bind the specific kernel driver according
their own policy, that would preparing for the next step of attach device,
let app running smoothly when hotplug behavior occur.

Signed-off-by: Jeff Guo <jia.guo@intel.com>
---
v16->v15:
add document.
---
 doc/guides/rel_notes/release_18_05.rst  |  6 ++--
 lib/librte_eal/bsdapp/eal/eal_dev.c     |  7 +++++
 lib/librte_eal/common/include/rte_dev.h | 16 ++++++++++
 lib/librte_eal/linuxapp/eal/eal_dev.c   | 54 +++++++++++++++++++++++++++++++++
 lib/librte_eal/rte_eal_version.map      |  1 +
 5 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/doc/guides/rel_notes/release_18_05.rst b/doc/guides/rel_notes/release_18_05.rst
index 3aacbf1..36e505c 100644
--- a/doc/guides/rel_notes/release_18_05.rst
+++ b/doc/guides/rel_notes/release_18_05.rst
@@ -51,11 +51,13 @@ New Features
   * ``rte_dev_event_callback_register`` and ``rte_dev_event_callback_unregister``
     are for the user's callbacks register and unregister.
 
-* **Added hot plug failure handler.**
+* **Added hot plug failure handler and kernel driver auto-bind func**
 
-  Added a failure handler machenism to handle hot plug removal.
+  Added a failure handler machenism to handle hot plug removal, and added an kernel driver
+  auto bind function for hot plug insertion. The list of new APIs:
 
   * ``rte_dev_handle_hot_unplug`` for handle hot plug removel failure.
+  * ``rte_dev_bind_kernel_driver`` for hot plug insertion.
 
 API Changes
 -----------
diff --git a/lib/librte_eal/bsdapp/eal/eal_dev.c b/lib/librte_eal/bsdapp/eal/eal_dev.c
index 1c6c51b..e953a87 100644
--- a/lib/librte_eal/bsdapp/eal/eal_dev.c
+++ b/lib/librte_eal/bsdapp/eal/eal_dev.c
@@ -19,3 +19,10 @@ rte_dev_event_monitor_stop(void)
 	RTE_LOG(ERR, EAL, "Device event is not supported for FreeBSD\n");
 	return -1;
 }
+
+int __rte_experimental
+rte_dev_bind_driver(const char *dev_name, enum rte_kernel_driver kdrv_type)
+{
+	RTE_LOG(ERR, EAL, "Bind driver is not supported for FreeBSD\n");
+	return -1;
+}
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index 7075e56..6829514 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -380,4 +380,20 @@ rte_dev_event_monitor_stop(void);
  */
 int __rte_experimental
 rte_dev_handle_hot_unplug(void);
+
+/**
+ * It can be used to bind a device to a specific type of kernel driver.
+ *
+ * @param dev_name
+ *  The device name.
+ * @param kdrv_type
+ *  The specific kernel driver's type.
+ *
+ * @return
+ *  - On success, zero.
+ *  - On failure, a negative value.
+ */
+int __rte_experimental
+rte_dev_bind_kernel_driver(const char *dev_name,
+			   enum rte_kernel_driver kdrv_type);
 #endif /* _RTE_DEV_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/eal_dev.c b/lib/librte_eal/linuxapp/eal/eal_dev.c
index fabb37a..eb8275f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_dev.c
+++ b/lib/librte_eal/linuxapp/eal/eal_dev.c
@@ -4,6 +4,7 @@
 
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <signal.h>
 #include <setjmp.h>
 #include <pthread.h>
@@ -326,3 +327,56 @@ rte_dev_event_monitor_stop(void)
 
 	return 0;
 }
+
+int __rte_experimental
+rte_dev_bind_kernel_driver(const char *dev_name,
+			   enum rte_kernel_driver kdrv_type)
+{
+	const char *kdrv_name = NULL;
+	char drv_override_path[1024];
+	int drv_override_fd = -1;
+
+	if (!dev_name || !kdrv_type)
+		return -1;
+
+	switch (kdrv_type) {
+	case RTE_KDRV_IGB_UIO:
+		kdrv_name = "igb_uio";
+		break;
+	case RTE_KDRV_VFIO:
+		kdrv_name = "vfio-pci";
+		break;
+	case RTE_KDRV_UIO_GENERIC:
+		kdrv_name = "uio_pci_generic";
+		break;
+	case RTE_KDRV_NIC_UIO:
+		RTE_LOG(ERR, EAL, "Don't support to bind nic uio driver.\n");
+		goto err;
+	default:
+		break;
+	}
+
+	snprintf(drv_override_path, sizeof(drv_override_path),
+		"/sys/bus/pci/devices/%s/driver_override", dev_name);
+
+	/* specify the driver for a device by writing to driver_override */
+	drv_override_fd = open(drv_override_path, O_WRONLY);
+	if (drv_override_fd < 0) {
+		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+			drv_override_path, strerror(errno));
+		goto err;
+	}
+
+	if (write(drv_override_fd, kdrv_name, sizeof(kdrv_name)) < 0) {
+		RTE_LOG(ERR, EAL,
+			"Error: bind failed - Cannot write "
+			"driver %s to device %s\n", kdrv_name, dev_name);
+		goto err;
+	}
+
+	close(drv_override_fd);
+	return 0;
+err:
+	close(drv_override_fd);
+	return -1;
+}
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index d37dd29..0c2ee3f 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -263,5 +263,6 @@ EXPERIMENTAL {
         rte_dev_event_callback_register;
         rte_dev_event_callback_unregister;
 	rte_dev_handle_hot_unplug;
+	rte_dev_bind_kernel_driver;
 
 } DPDK_18.05;
-- 
2.7.4

  parent reply	other threads:[~2018-04-03 18:18 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-03 18:17 [dpdk-dev] [PATCH V18 0/5] add hot plug failure and auto bind handler Jeff Guo
2018-04-03 18:17 ` [dpdk-dev] [PATCH V18 1/5] bus: introduce device hot unplug handle Jeff Guo
2018-04-04  4:31   ` Tan, Jianfeng
2018-04-06 10:54     ` Guo, Jia
2018-04-03 18:17 ` [dpdk-dev] [PATCH V18 2/5] bus/pci: implement handle hot unplug operation Jeff Guo
2018-04-04  5:25   ` Tan, Jianfeng
2018-04-06 10:57     ` Guo, Jia
2018-04-03 18:17 ` [dpdk-dev] [PATCH V18 3/5] eal: add failure handler mechanism for hot plug Jeff Guo
2018-04-04  2:58   ` Zhang, Qi Z
2018-04-06 10:53     ` Guo, Jia
2018-04-03 18:17 ` Jeff Guo [this message]
2018-04-03 18:17 ` [dpdk-dev] [PATCH V18 5/5] app/testpmd: use auto handle for hotplug Jeff Guo
2018-04-06 10:56   ` [dpdk-dev] [PATCH V19 0/4] add hot plug failure and auto bind handler Jeff Guo
2018-04-06 10:56     ` [dpdk-dev] [PATCH V19 1/4] bus/pci: introduce device hot unplug handle Jeff Guo
2018-04-09 17:47       ` Ananyev, Konstantin
2018-04-11 11:37         ` Guo, Jia
2018-04-06 10:56     ` [dpdk-dev] [PATCH V19 2/4] eal: add failure handler mechanism for hot plug Jeff Guo
2018-04-06 14:03       ` Zhang, Qi Z
2018-04-06 14:24         ` Zhang, Qi Z
2018-04-11 11:50           ` Guo, Jia
2018-04-11 11:49         ` Guo, Jia
2018-04-09 17:42       ` Ananyev, Konstantin
2018-04-11 11:34         ` Guo, Jia
2018-04-06 10:56     ` [dpdk-dev] [PATCH V19 3/4] eal: add driver auto bind for hot insertion Jeff Guo
2018-04-06 10:56     ` [dpdk-dev] [PATCH V19 4/4] app/testpmd: use auto handle for hotplug Jeff Guo
2018-04-12  5:31       ` Matan Azrad
2018-04-13 10:48         ` Guo, Jia
2018-04-13 14:58           ` Matan Azrad

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=1522779443-1932-5-git-send-email-jia.guo@intel.com \
    --to=jia.guo@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=gaetan.rivet@6wind.com \
    --cc=harry.van.haaren@intel.com \
    --cc=helin.zhang@intel.com \
    --cc=jblunck@infradead.org \
    --cc=jianfeng.tan@intel.com \
    --cc=jingjing.wu@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=motih@mellanox.com \
    --cc=shreyansh.jain@nxp.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /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).