From patchwork Sun Jul 5 09:23:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ori Kam X-Patchwork-Id: 73117 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C610DA00C5; Sun, 5 Jul 2020 11:25:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7D84D1DAF3; Sun, 5 Jul 2020 11:24:44 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id C5A481DAAC for ; Sun, 5 Jul 2020 11:24:42 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from orika@mellanox.com) with SMTP; 5 Jul 2020 12:24: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 0659OC3q028191; Sun, 5 Jul 2020 12:24:38 +0300 From: Ori Kam To: jerinj@marvell.com, xiang.w.wang@intel.com, matan@mellanox.com, viacheslavo@mellanox.com, Thomas Monjalon Cc: guyk@marvell.com, 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, deri@ntop.org, fc@napatech.com, arthur.su@lionic.com, orika@mellanox.com, rasland@mellanox.com, Parav Pandit Date: Sun, 5 Jul 2020 09:23:33 +0000 Message-Id: <1593941027-86651-7-git-send-email-orika@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1593941027-86651-1-git-send-email-orika@mellanox.com> References: <1593941027-86651-1-git-send-email-orika@mellanox.com> Subject: [dpdk-dev] [PATCH 06/20] regex/mlx5: add probe function 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 adds the probe function to the RegEx PMD. Signed-off-by: Parav Pandit Signed-off-by: Ori Kam --- drivers/regex/mlx5/Makefile | 3 + drivers/regex/mlx5/meson.build | 2 +- drivers/regex/mlx5/mlx5_regex.c | 215 ++++++++++++++++++++++++++++++++++++++++ drivers/regex/mlx5/mlx5_regex.h | 6 ++ mk/rte.app.mk | 1 + 5 files changed, 226 insertions(+), 1 deletion(-) diff --git a/drivers/regex/mlx5/Makefile b/drivers/regex/mlx5/Makefile index 40c03ab..c66df7f 100644 --- a/drivers/regex/mlx5/Makefile +++ b/drivers/regex/mlx5/Makefile @@ -16,6 +16,8 @@ CFLAGS += -g CFLAGS += -I$(RTE_SDK)/drivers/common/mlx5 CFLAGS += -I$(BUILDDIR)/drivers/common/mlx5 CFLAGS += -I$(RTE_SDK)/drivers/common/mlx5/linux +CFLAGS += -I$(RTE_SDK)/drivers/common/mlx5/linux +CFLAGS += -I$(BUILDDIR)/drivers/common/mlx5/linux CFLAGS += -D_BSD_SOURCE CFLAGS += -D_DEFAULT_SOURCE CFLAGS += -D_XOPEN_SOURCE=600 @@ -26,6 +28,7 @@ LDLIBS += -lm LDLIBS += -lrte_eal -lrte_mbuf LDLIBS += -lrte_kvargs LDLIBS += -lrte_bus_pci +LDLIBS += -lrte_regexdev # A few warnings cannot be avoided in external headers. CFLAGS += -Wno-error=cast-qual diff --git a/drivers/regex/mlx5/meson.build b/drivers/regex/mlx5/meson.build index 768a9d1..d56c4da 100644 --- a/drivers/regex/mlx5/meson.build +++ b/drivers/regex/mlx5/meson.build @@ -8,7 +8,7 @@ if not is_linux endif fmt_name = 'mlx5_regex' -deps += ['common_mlx5', 'pci', 'bus_pci', 'eal', 'sched'] +deps += ['common_mlx5', 'pci', 'bus_pci', 'eal', 'sched', 'regexdev'] sources = files( 'mlx5_regex.c', ) diff --git a/drivers/regex/mlx5/mlx5_regex.c b/drivers/regex/mlx5/mlx5_regex.c index 06826a6..d264ecd 100644 --- a/drivers/regex/mlx5/mlx5_regex.c +++ b/drivers/regex/mlx5/mlx5_regex.c @@ -2,8 +2,223 @@ * Copyright 2020 Mellanox Technologies, Ltd */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + #include "mlx5_regex.h" #include "mlx5_regex_utils.h" int mlx5_regex_logtype; +static const struct rte_regexdev_ops mlx5_regexdev_ops = {}; + +static struct ibv_device * +mlx5_regex_get_ib_device_match(struct rte_pci_addr *addr) +{ + int n; + struct ibv_device **ibv_list = mlx5_glue->get_device_list(&n); + struct ibv_device *ibv_match = NULL; + + if (!ibv_list) { + rte_errno = ENOSYS; + return NULL; + } + while (n-- > 0) { + struct rte_pci_addr pci_addr; + + DRV_LOG(DEBUG, "Checking device \"%s\"..", ibv_list[n]->name); + if (mlx5_dev_to_pci_addr(ibv_list[n]->ibdev_path, &pci_addr)) + continue; + if (rte_pci_addr_cmp(addr, &pci_addr)) + continue; + ibv_match = ibv_list[n]; + break; + } + if (!ibv_match) + rte_errno = ENOENT; + mlx5_glue->free_device_list(ibv_list); + return ibv_match; +} + +static void +mlx5_regex_get_name(char *name, struct rte_pci_device *pci_dev __rte_unused) +{ + sprintf(name, "mlx5_regex_%02x:%02x.%02x", pci_dev->addr.bus, + pci_dev->addr.devid, pci_dev->addr.function); +} + +/** + * DPDK callback to register a PCI device. + * + * This function spawns RegEx device out of a given PCI device. + * + * @param[in] pci_drv + * PCI driver structure (mlx5_regex_driver). + * @param[in] pci_dev + * PCI device information. + * + * @return + * 0 on success, 1 to skip this driver, a negative errno value otherwise + * and rte_errno is set. + */ +static int +mlx5_regex_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev) +{ + struct ibv_device *ibv; + struct mlx5_regex_priv *priv = NULL; + struct ibv_context *ctx = NULL; + struct mlx5_hca_attr attr; + char name[RTE_REGEXDEV_NAME_MAX_LEN]; + int ret; + + ibv = mlx5_regex_get_ib_device_match(&pci_dev->addr); + if (!ibv) { + DRV_LOG(ERR, "No matching IB device for PCI slot " + PCI_PRI_FMT ".", pci_dev->addr.domain, + pci_dev->addr.bus, pci_dev->addr.devid, + pci_dev->addr.function); + return -rte_errno; + } + DRV_LOG(INFO, "PCI information matches for device \"%s\".", + ibv->name); + ctx = mlx5_glue->dv_open_device(ibv); + if (!ctx) { + DRV_LOG(ERR, "Failed to open IB device \"%s\".", ibv->name); + rte_errno = ENODEV; + return -rte_errno; + } + ret = mlx5_devx_cmd_query_hca_attr(ctx, &attr); + if (ret) { + DRV_LOG(ERR, "Unable to read HCA capabilities."); + rte_errno = ENOTSUP; + goto error; + } else if (!attr.regex || attr.regexp_num_of_engines == 0) { + DRV_LOG(ERR, "Not enough capabilities to support RegEx, maybe " + "old FW/OFED version?"); + rte_errno = ENOTSUP; + goto error; + } + priv = rte_zmalloc("mlx5 regex device private", sizeof(*priv), + RTE_CACHE_LINE_SIZE); + if (!priv) { + DRV_LOG(ERR, "Failed to allocate private memory."); + rte_errno = ENOMEM; + goto error; + } + priv->ctx = ctx; + mlx5_regex_get_name(name, pci_dev); + priv->regexdev = rte_regexdev_register(name); + if (priv->regexdev == NULL) { + DRV_LOG(ERR, "Failed to register RegEx device."); + rte_errno = rte_errno ? rte_errno : EINVAL; + goto error; + } + priv->regexdev->dev_ops = &mlx5_regexdev_ops; + priv->regexdev->device = (struct rte_device *)pci_dev; + priv->regexdev->data->dev_private = priv; + return 0; + +error: + if (ctx) + mlx5_glue->close_device(ctx); + if (priv) + rte_free(priv); + return -rte_errno; +} + +/** + * DPDK callback to remove a PCI device. + * + * This function removes all RegEx devices belong to a given PCI device. + * + * @param[in] pci_dev + * Pointer to the PCI device. + * + * @return + * 0 on success, the function cannot fail. + */ +static int +mlx5_regex_pci_remove(struct rte_pci_device *pci_dev) +{ + char name[RTE_REGEXDEV_NAME_MAX_LEN]; + struct rte_regexdev *dev; + struct mlx5_regex_priv *priv = NULL; + + mlx5_regex_get_name(name, pci_dev); + dev = rte_regexdev_get_device_by_name(name); + if (!dev) + return 0; + priv = dev->data->dev_private; + if (priv) { + if (priv->ctx) + mlx5_glue->close_device(priv->ctx); + if (priv->regexdev) + rte_regexdev_unregister(priv->regexdev); + rte_free(priv); + } + return 0; +} + +static const struct rte_pci_id mlx5_regex_pci_id_map[] = { + { + RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, + PCI_DEVICE_ID_MELLANOX_CONNECTX6) + }, + { + RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, + PCI_DEVICE_ID_MELLANOX_CONNECTX6VF) + }, + { + RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, + PCI_DEVICE_ID_MELLANOX_CONNECTX6DX) + }, + { + RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, + PCI_DEVICE_ID_MELLANOX_CONNECTX6DXVF) + }, + { + RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX, + PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF) + }, + { + .vendor_id = 0 + } +}; + +static struct rte_pci_driver mlx5_regex_driver = { + .driver = { + .name = "mlx5_regex", + }, + .id_table = mlx5_regex_pci_id_map, + .probe = mlx5_regex_pci_probe, + .remove = mlx5_regex_pci_remove, + .drv_flags = 0, +}; + +/** + * Driver initialization routine. + */ +RTE_INIT(rte_mlx5_regex_init) +{ + /* Initialize common log type. */ + mlx5_regex_logtype = rte_log_register("pmd.regex.mlx5"); + if (mlx5_regex_logtype >= 0) + rte_log_set_level(mlx5_regex_logtype, RTE_LOG_NOTICE); + if (mlx5_glue) + rte_pci_register(&mlx5_regex_driver); +} + +RTE_PMD_EXPORT_NAME(net_mlx5_regex, __COUNTER__); +RTE_PMD_REGISTER_PCI_TABLE(net_mlx5_regex, mlx5_regex_pci_id_map); +RTE_PMD_REGISTER_KMOD_DEP(net_mlx5_regex, "* ib_uverbs & mlx5_core & mlx5_ib"); diff --git a/drivers/regex/mlx5/mlx5_regex.h b/drivers/regex/mlx5/mlx5_regex.h index 0e0495c..0ce1e4d 100644 --- a/drivers/regex/mlx5/mlx5_regex.h +++ b/drivers/regex/mlx5/mlx5_regex.h @@ -5,4 +5,10 @@ #ifndef MLX5_REGEX_H #define MLX5_REGEX_H +struct mlx5_regex_priv { + TAILQ_ENTRY(mlx5_regex_priv) next; + struct ibv_context *ctx; /* Device context. */ + struct rte_pci_device *pci_dev; + struct rte_regexdev *regexdev; /* Pointer to the RegEx dev. */ +}; #endif /* MLX5_REGEX_H */ diff --git a/mk/rte.app.mk b/mk/rte.app.mk index 1b9551e..6efd7ae 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -101,6 +101,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED) += -lrte_sched _LDLIBS-$(CONFIG_RTE_LIBRTE_RCU) += -lrte_rcu _LDLIBS-$(CONFIG_RTE_LIBRTE_GRAPH) += -lrte_graph _LDLIBS-$(CONFIG_RTE_LIBRTE_NODE) += -lrte_node +_LDLIBS-$(CONFIG_RTE_LIBRTE_REGEXDEV) += -lrte_regexdev ifeq ($(CONFIG_RTE_EXEC_ENV_LINUX),y) _LDLIBS-$(CONFIG_RTE_LIBRTE_KNI) += -lrte_kni