From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 219871B1A3 for ; Tue, 9 Jan 2018 00:25:34 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 8C928206DE; Mon, 8 Jan 2018 18:25:33 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Mon, 08 Jan 2018 18:25:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=58bCTk2e0Zdnv8 rYbtLU4YiZ9VzxMoSqqgCwNgSVPrU=; b=lx3NwIGUAvku4WP98DMJURKtpwuxSX Riz0Xrpbcc4zBkindpQssXls3OncHJs2PtZpaI63vavh6ormaKsWzbk/q9uHi/3A EzNi0879QIKzSzU2vmDEWaynL7t7Y/PI5DxPoTf7pm0MxtGeDPanRZV2J8HYlSXH KujM//idT9PZQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=58bCTk2e0Zdnv8rYbtLU4YiZ9VzxMoSqqgCwNgSVPrU=; b=Uv0h0hlz 4qi8tILErrVNgURNAXKT0ehjxkd+vO0a6timnGbabl45T5y0sF5UtTqjbduVAAdX Y9xMiWDkaFePDmII1tVJ5YFisNQJ8rwCRhE83WXt3DPfPDffxikc6M532GiusX9P p8XyYUv9yW0f3mPqt0KoeZMpDFRNctI2bq/zM7zQnG9miJ87jJI+baOxSASyfk9w 1lsJfRtIKXVD9RFkSsfWGTdlBzk6E1L0THZmCSH5LDQWZ8ZMjc2MZCXIzoFuWhFM vxQEdT/tr6GAEQ5ILvUpEW+TqcrwGfFCxQ0tyW3Vbpc9insep6mo8rDuWZI84erz UfQwgX+p6OJymQ== X-ME-Sender: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id DB04924724; Mon, 8 Jan 2018 18:25:32 -0500 (EST) From: Thomas Monjalon To: jianfeng.tan@intel.com Cc: dev@dpdk.org Date: Tue, 9 Jan 2018 00:25:05 +0100 Message-Id: <20180108232505.714-1-thomas@monjalon.net> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171201003642.19827-1-thomas@monjalon.net> References: <20171201003642.19827-1-thomas@monjalon.net> Subject: [dpdk-dev] [PATCH v3] bus/vdev: add custom scan hook 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: , X-List-Received-Date: Mon, 08 Jan 2018 23:25:34 -0000 The scan callback allows to spawn a vdev automatically given some custom scan rules. It is especially useful to create a TAP device automatically connected to a netdevice as remote. Signed-off-by: Thomas Monjalon Acked-by: Jianfeng Tan --- v3: - add deadlock comment - return -1 on add error (no mem or already exist) instead of -ENOMEM v2: - update .map file --- drivers/bus/vdev/rte_bus_vdev.h | 35 +++++++++++++++ drivers/bus/vdev/rte_bus_vdev_version.map | 8 ++++ drivers/bus/vdev/vdev.c | 75 +++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) diff --git a/drivers/bus/vdev/rte_bus_vdev.h b/drivers/bus/vdev/rte_bus_vdev.h index 41762b853..f9d8a2383 100644 --- a/drivers/bus/vdev/rte_bus_vdev.h +++ b/drivers/bus/vdev/rte_bus_vdev.h @@ -124,6 +124,41 @@ RTE_PMD_EXPORT_NAME(nm, __COUNTER__) #define RTE_PMD_REGISTER_ALIAS(nm, alias)\ static const char *vdrvinit_ ## nm ## _alias = RTE_STR(alias) +typedef void (*rte_vdev_scan_callback)(void *user_arg); + +/** + * Add a callback to be called on vdev scan + * before reading the devargs list. + * + * This function cannot be called in a scan callback + * because of deadlock. + * + * @param callback + * The function to be called which can update the devargs list. + * @param user_arg + * An opaque pointer passed to callback. + * @return + * 0 on success, negative on error + */ +int +rte_vdev_add_custom_scan(rte_vdev_scan_callback callback, void *user_arg); + +/** + * Remove a registered scan callback. + * + * This function cannot be called in a scan callback + * because of deadlock. + * + * @param callback + * The registered function to be removed. + * @param user_arg + * The associated opaque pointer or (void*)-1 for any. + * @return + * 0 on success + */ +int +rte_vdev_remove_custom_scan(rte_vdev_scan_callback callback, void *user_arg); + /** * Initialize a driver specified by name. * diff --git a/drivers/bus/vdev/rte_bus_vdev_version.map b/drivers/bus/vdev/rte_bus_vdev_version.map index 707b870c0..590cf9b43 100644 --- a/drivers/bus/vdev/rte_bus_vdev_version.map +++ b/drivers/bus/vdev/rte_bus_vdev_version.map @@ -8,3 +8,11 @@ DPDK_17.11 { local: *; }; + +DPDK_18.02 { + global: + + rte_vdev_add_custom_scan; + rte_vdev_remove_custom_scan; + +} DPDK_17.11; diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index fd7736d63..0c8a6a85e 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -44,6 +44,8 @@ #include #include #include +#include +#include #include #include "rte_bus_vdev.h" @@ -62,6 +64,16 @@ static struct vdev_device_list vdev_device_list = struct vdev_driver_list vdev_driver_list = TAILQ_HEAD_INITIALIZER(vdev_driver_list); +struct vdev_custom_scan { + TAILQ_ENTRY(vdev_custom_scan) next; + rte_vdev_scan_callback callback; + void *user_arg; +}; +TAILQ_HEAD(vdev_custom_scans, vdev_custom_scan); +static struct vdev_custom_scans vdev_custom_scans = + TAILQ_HEAD_INITIALIZER(vdev_custom_scans); +static rte_spinlock_t vdev_custom_scan_lock = RTE_SPINLOCK_INITIALIZER; + /* register a driver */ void rte_vdev_register(struct rte_vdev_driver *driver) @@ -76,6 +88,53 @@ rte_vdev_unregister(struct rte_vdev_driver *driver) TAILQ_REMOVE(&vdev_driver_list, driver, next); } +int +rte_vdev_add_custom_scan(rte_vdev_scan_callback callback, void *user_arg) +{ + struct vdev_custom_scan *custom_scan; + + rte_spinlock_lock(&vdev_custom_scan_lock); + + /* check if already registered */ + TAILQ_FOREACH(custom_scan, &vdev_custom_scans, next) { + if (custom_scan->callback == callback && + custom_scan->user_arg == user_arg) + break; + } + + if (custom_scan == NULL) { + custom_scan = malloc(sizeof(struct vdev_custom_scan)); + if (custom_scan != NULL) { + custom_scan->callback = callback; + custom_scan->user_arg = user_arg; + TAILQ_INSERT_TAIL(&vdev_custom_scans, custom_scan, next); + } + } + + rte_spinlock_unlock(&vdev_custom_scan_lock); + + return (custom_scan == NULL) ? -1 : 0; +} + +int +rte_vdev_remove_custom_scan(rte_vdev_scan_callback callback, void *user_arg) +{ + struct vdev_custom_scan *custom_scan, *tmp_scan; + + rte_spinlock_lock(&vdev_custom_scan_lock); + TAILQ_FOREACH_SAFE(custom_scan, &vdev_custom_scans, next, tmp_scan) { + if (custom_scan->callback != callback || + (custom_scan->user_arg != (void *)-1 && + custom_scan->user_arg != user_arg)) + continue; + TAILQ_REMOVE(&vdev_custom_scans, custom_scan, next); + free(custom_scan); + } + rte_spinlock_unlock(&vdev_custom_scan_lock); + + return 0; +} + static int vdev_parse(const char *name, void *addr) { @@ -260,6 +319,22 @@ vdev_scan(void) { struct rte_vdev_device *dev; struct rte_devargs *devargs; + struct vdev_custom_scan *custom_scan; + + /* call custom scan callbacks if any */ + rte_spinlock_lock(&vdev_custom_scan_lock); + TAILQ_FOREACH(custom_scan, &vdev_custom_scans, next) { + if (custom_scan->callback != NULL) + /* + * the callback should update devargs list + * by calling rte_eal_devargs_insert() with + * devargs.bus = rte_bus_find_by_name("vdev"); + * devargs.type = RTE_DEVTYPE_VIRTUAL; + * devargs.policy = RTE_DEV_WHITELISTED; + */ + custom_scan->callback(custom_scan->user_arg); + } + rte_spinlock_unlock(&vdev_custom_scan_lock); /* for virtual devices we scan the devargs_list populated via cmdline */ TAILQ_FOREACH(devargs, &devargs_list, next) { -- 2.15.1