From patchwork Fri Apr 6 10:56:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Jia" X-Patchwork-Id: 37353 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7610F1CF40; Fri, 6 Apr 2018 12:58:15 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 12D4D1CF30 for ; Fri, 6 Apr 2018 12:58:09 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Apr 2018 03:58:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,415,1517904000"; d="scan'208";a="34849825" Received: from jeffguo-z170x-ud5.sh.intel.com (HELO localhost.localdomain) ([10.67.104.10]) by fmsmga002.fm.intel.com with ESMTP; 06 Apr 2018 03:58:07 -0700 From: Jeff Guo 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 Date: Fri, 6 Apr 2018 18:56:56 +0800 Message-Id: <1523012217-31146-4-git-send-email-jia.guo@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523012217-31146-1-git-send-email-jia.guo@intel.com> References: <1522779443-1932-6-git-send-email-jia.guo@intel.com> <1523012217-31146-1-git-send-email-jia.guo@intel.com> Subject: [dpdk-dev] [PATCH V19 3/4] eal: add driver auto bind for hot insertion X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- v19->v18: no change --- doc/guides/rel_notes/release_18_05.rst | 8 +++-- 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, 83 insertions(+), 3 deletions(-) diff --git a/doc/guides/rel_notes/release_18_05.rst b/doc/guides/rel_notes/release_18_05.rst index 2707e73..f8822d3 100644 --- a/doc/guides/rel_notes/release_18_05.rst +++ b/doc/guides/rel_notes/release_18_05.rst @@ -70,11 +70,13 @@ New Features Linux uevent is supported as backend of this device event notification framework. -* **Added hot plug failure handler.** +* **Added hot plug failure handler and kernel driver auto-bind func** - Added a failure handler machenism to handle hot unplug device. + Added a failure handler machenism to handle hot unplug device, 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 unplug device failure. + * ``rte_dev_handle_hot_unplug`` for handle hot uplug device 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 17c446d..35f45d3 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 84b7efc..2ad7444 100644 --- a/lib/librte_eal/linuxapp/eal/eal_dev.c +++ b/lib/librte_eal/linuxapp/eal/eal_dev.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -359,3 +360,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 873ef38..664a837 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.02;