From patchwork Tue Apr 3 18:17:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Jia" X-Patchwork-Id: 36979 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 F2AD51B87B; Tue, 3 Apr 2018 20:18:39 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 604F41B85C for ; Tue, 3 Apr 2018 20:18:38 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2018 11:18:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,402,1517904000"; d="scan'208";a="188366587" Received: from jeffguo-z170x-ud5.sh.intel.com (HELO localhost.localdomain) ([10.67.104.10]) by orsmga004.jf.intel.com with ESMTP; 03 Apr 2018 11:18:35 -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: Wed, 4 Apr 2018 02:17:22 +0800 Message-Id: <1522779443-1932-5-git-send-email-jia.guo@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522779443-1932-1-git-send-email-jia.guo@intel.com> References: <1522779443-1932-1-git-send-email-jia.guo@intel.com> Subject: [dpdk-dev] [PATCH V18 4/5] 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 --- 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 #include +#include #include #include #include @@ -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;