From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CF95BA0562; Sun, 29 Mar 2020 08:48:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 898291C02A; Sun, 29 Mar 2020 08:47:43 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 785BB1BFD9 for ; Sun, 29 Mar 2020 08:47:40 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from orika@mellanox.com) with ESMTPS (AES256-SHA encrypted); 29 Mar 2020 09:47:38 +0300 Received: from pegasus04.mtr.labs.mlnx. (pegasus04.mtr.labs.mlnx [10.210.16.126]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 02T6lSNx004381; Sun, 29 Mar 2020 09:47:38 +0300 From: Ori Kam To: jerinj@marvell.com, xiang.w.wang@intel.com Cc: dev@dpdk.org, pbhagavatula@marvell.com, shahafs@mellanox.com, hemant.agrawal@nxp.com, opher@mellanox.com, alexr@mellanox.com, dovrat@marvell.com, pkapoor@marvell.com, nipun.gupta@nxp.com, bruce.richardson@intel.com, yang.a.hong@intel.com, harry.chang@intel.com, gu.jian1@zte.com.cn, shanjiangh@chinatelecom.cn, zhangy.yun@chinatelecom.cn, lixingfu@huachentel.com, wushuai@inspur.com, yuyingxia@yxlink.com, fanchenggang@sunyainfo.com, davidfgao@tencent.com, liuzhong1@chinaunicom.cn, zhaoyong11@huawei.com, oc@yunify.com, jim@netgate.com, hongjun.ni@intel.com, j.bromhead@titan-ic.com, deri@ntop.org, fc@napatech.com, arthur.su@lionic.com, thomas@monjalon.net, orika@mellanox.com, Parav Pandit Date: Sun, 29 Mar 2020 06:47:17 +0000 Message-Id: <1585464438-111285-4-git-send-email-orika@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1585464438-111285-1-git-send-email-orika@mellanox.com> References: <1585464438-111285-1-git-send-email-orika@mellanox.com> Subject: [dpdk-dev] [PATCH v1 3/4] regexdev: add regexdev core functions 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" This commit introduce the API that is needed by the RegEx devices in order to work with the RegEX lib. During the probe of a RegEx device, the device should configure itself, and allocate the resources it requires. On completion of the device init, it should call the rte_regex_dev_register in order to register itself as a RegEx device. Signed-off-by: Ori Kam Signed-off-by: Parav Pandit --- config/common_base | 3 +- config/meson.build | 1 + lib/librte_regexdev/Makefile | 1 + lib/librte_regexdev/meson.build | 5 ++- lib/librte_regexdev/rte_regexdev.c | 74 ++++++++++++++++++++++++++++++- lib/librte_regexdev/rte_regexdev.h | 7 +++ lib/librte_regexdev/rte_regexdev_core.h | 2 + lib/librte_regexdev/rte_regexdev_driver.h | 50 +++++++++++++++++++++ meson_options.txt | 2 + 9 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 lib/librte_regexdev/rte_regexdev_driver.h diff --git a/config/common_base b/config/common_base index 58c0865..f6466a8 100644 --- a/config/common_base +++ b/config/common_base @@ -819,10 +819,11 @@ CONFIG_RTE_LIBRTE_PMD_OCTEONTX2_EP_RAWDEV=y CONFIG_RTE_LIBRTE_PMD_NTB_RAWDEV=y # -# Compile regex device support +# Compile RexEx device support # CONFIG_RTE_LIBRTE_REGEXDEV=y CONFIG_RTE_LIBRTE_REGEXDEV_DEBUG=n +CONFIG_RTE_MAX_REGEXDEV_DEVS=32 # # Compile librte_ring diff --git a/config/meson.build b/config/meson.build index abedd76..fb05639 100644 --- a/config/meson.build +++ b/config/meson.build @@ -221,6 +221,7 @@ endforeach dpdk_conf.set('RTE_MAX_LCORE', get_option('max_lcores')) dpdk_conf.set('RTE_MAX_NUMA_NODES', get_option('max_numa_nodes')) dpdk_conf.set('RTE_MAX_ETHPORTS', get_option('max_ethports')) +dpdk_conf.set('RTE_MAX_REGEXDEV_DEVS', get_option('max_regexdev_devs')) dpdk_conf.set('RTE_LIBEAL_USE_HPET', get_option('use_hpet')) # values which have defaults which may be overridden dpdk_conf.set('RTE_MAX_VFIO_GROUPS', 64) diff --git a/lib/librte_regexdev/Makefile b/lib/librte_regexdev/Makefile index 9012d29..6ba09f0 100644 --- a/lib/librte_regexdev/Makefile +++ b/lib/librte_regexdev/Makefile @@ -25,6 +25,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_REGEXDEV) := rte_regexdev.c # export include files SYMLINK-$(CONFIG_RTE_LIBRTE_REGEXDEV)-include += rte_regexdev.h SYMLINK-$(CONFIG_RTE_LIBRTE_REGEXDEV)-include += rte_regexdev_core.h +SYMLINK-$(CONFIG_RTE_LIBRTE_REGEXDEV)-include += rte_regexdev_driver.h # versioning export map EXPORT_MAP := rte_regexdev_version.map diff --git a/lib/librte_regexdev/meson.build b/lib/librte_regexdev/meson.build index 1816754..719ee82 100644 --- a/lib/librte_regexdev/meson.build +++ b/lib/librte_regexdev/meson.build @@ -1,7 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2020 Mellanox Corporation +name = 'regexdev' allow_experimental_apis = true sources = files('rte_regexdev.c') -headers = files('rte_regexdev.h', 'rte_regexdev_core.h') +headers = files('rte_regexdev.h', + 'rte_regexdev_core.h', + 'rte_regexdev_driver.h') deps += ['mbuf'] diff --git a/lib/librte_regexdev/rte_regexdev.c b/lib/librte_regexdev/rte_regexdev.c index b901877..4396bb5 100644 --- a/lib/librte_regexdev/rte_regexdev.c +++ b/lib/librte_regexdev/rte_regexdev.c @@ -3,4 +3,76 @@ * Copyright(C) 2020 Mellanox International Ltd. */ -#include +#include + +#include +#include +#include +#include +#include + +#include "rte_regexdev.h" +#include "rte_regexdev_driver.h" + +static struct rte_regexdev *regex_devices[RTE_MAX_REGEXDEV_DEVS]; + +int rte_regexdev_logtype; + +static uint16_t +regexdev_find_free_dev(void) +{ + uint16_t i; + + for (i = 0; i < RTE_MAX_REGEXDEV_DEVS; i++) { + if (regex_devices[i] == NULL) + return i; + } + return RTE_MAX_REGEXDEV_DEVS; +} + +static const struct rte_regexdev* +regexdev_allocated(const char *name) +{ + uint16_t i; + + for (i = 0; i < RTE_MAX_REGEXDEV_DEVS; i++) { + if (regex_devices[i] != NULL) + if (!strcmp(name, regex_devices[i]->dev_name)) + return regex_devices[i]; + } + return NULL; +} + +int +rte_regexdev_register(struct rte_regexdev *dev) +{ + uint16_t dev_id; + int res; + + if (dev->dev_ops == NULL) { + RTE_REGEXDEV_LOG(ERR, "RegEx device invalid device ops\n"); + return -EINVAL; + } + if (regexdev_allocated(dev->dev_name) != NULL) { + RTE_REGEXDEV_LOG + (ERR, "RegEx device with name %s already allocated\n", + dev->dev_name); + return -ENOMEM; + } + dev_id = regexdev_find_free_dev(); + if (dev_id == RTE_MAX_REGEXDEV_DEVS) { + RTE_REGEXDEV_LOG + (ERR, "Reached maximum number of regex devs\n"); + return -ENOMEM; + } + dev->dev_id = dev_id; + regex_devices[dev_id] = dev; + res = dev_id; + return res; +} + +void +rte_regexdev_unregister(struct rte_regexdev *dev) +{ + regex_devices[dev->dev_id] = NULL; +} diff --git a/lib/librte_regexdev/rte_regexdev.h b/lib/librte_regexdev/rte_regexdev.h index bbc56f9..d901417 100644 --- a/lib/librte_regexdev/rte_regexdev.h +++ b/lib/librte_regexdev/rte_regexdev.h @@ -206,6 +206,13 @@ #include #include +#define RTE_REGEX_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN + +extern int rte_regexdev_logtype; + +#define RTE_REGEXDEV_LOG(level, ...) \ + rte_log(RTE_LOG_ ## level, rte_regexdev_logtype, "" __VA_ARGS__) + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. diff --git a/lib/librte_regexdev/rte_regexdev_core.h b/lib/librte_regexdev/rte_regexdev_core.h index e30865d..e380f84 100644 --- a/lib/librte_regexdev/rte_regexdev_core.h +++ b/lib/librte_regexdev/rte_regexdev_core.h @@ -142,6 +142,8 @@ struct rte_regexdev { const struct rte_regexdev_ops *dev_ops; /**< Functions exported by PMD */ struct rte_device *device; /**< Backing device */ + char dev_name[RTE_REGEX_NAME_MAX_LEN]; /**< Unique identifier name */ + uint16_t dev_id; /**< Device [external] identifier. */ } __rte_cache_aligned; #endif /* _RTE_REGEX_CORE_H_ */ diff --git a/lib/librte_regexdev/rte_regexdev_driver.h b/lib/librte_regexdev/rte_regexdev_driver.h new file mode 100644 index 0000000..cb18640 --- /dev/null +++ b/lib/librte_regexdev/rte_regexdev_driver.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Mellanox Corporation + */ + +#ifndef _RTE_REGEXDEV_DRIVER_H_ +#define _RTE_REGEXDEV_DRIVER_H_ + +/** + * @file + * + * RTE RegEx Device PMD API + * + * APIs that are used by the RegEx drivers, to comunicate with the + * RegEx lib. + */ + +#include "rte_regexdev.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @internal + * Register a new regexdev slot for a RegEx device and returns the id + * to that slot for the driver to use. + * + * @param dev + * RegEx device structure.. + * + * @return + * Slot in the rte_regex_devices array for a new device in case of success, + * negative errno otherwise. + */ +int rte_regexdev_register(struct rte_regexdev *dev); + +/** + * @internal + * Unregister the specified regexdev port. + * + * @param dev + * Device to be released. + */ +void rte_regexdev_unregister(struct rte_regexdev *dev); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_REGEXDEV_DRIVER_H_ */ diff --git a/meson_options.txt b/meson_options.txt index 9e4923a..7e54d8a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -30,6 +30,8 @@ option('max_lcores', type: 'integer', value: 128, description: 'maximum number of cores/threads supported by EAL') option('max_numa_nodes', type: 'integer', value: 4, description: 'maximum number of NUMA nodes supported by EAL') +option('max_regexdev_devs', type: 'integer', value: 32, + description: 'maximum number of RegEx devices') option('tests', type: 'boolean', value: true, description: 'build unit tests') option('use_hpet', type: 'boolean', value: false, -- 1.8.3.1