From patchwork Tue Mar 9 08:15:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haifei Luo X-Patchwork-Id: 88774 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3F8AAA0567; Wed, 10 Mar 2021 00:52:34 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 372F022A579; Wed, 10 Mar 2021 00:52:30 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id 31A7D4068A for ; Tue, 9 Mar 2021 09:15:39 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from haifeil@nvidia.com) with SMTP; 9 Mar 2021 10:15:36 +0200 Received: from nvidia.com (gen-l-vrt-173.mtl.labs.mlnx [10.234.173.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 1298FMsF007468; Tue, 9 Mar 2021 10:15:36 +0200 From: Haifei Luo To: ferruh.yigit@intel.com, viacheslavo@nvidia.com, matan@nvidia.com, xiaoyun.li@intel.com, thomas@monjalon.net, orika@nvidia.com Cc: dev@dpdk.org, rasland@nvidia.com, xuemingl@nvidia.com Date: Tue, 9 Mar 2021 10:15:13 +0200 Message-Id: <1615277716-64404-2-git-send-email-haifeil@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1615277716-64404-1-git-send-email-haifeil@nvidia.com> References: <1615277716-64404-1-git-send-email-haifeil@nvidia.com> X-Mailman-Approved-At: Wed, 10 Mar 2021 00:52:28 +0100 Subject: [dpdk-dev] [PATCH 1/4] ethdev: add rte API for single flow dump X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Previous implementations support dump all the flows.Add new ones to dump one flow. New API added: rte_flow_dump. Signed-off-by: Haifei Luo --- doc/guides/nics/mlx5.rst | 10 +++++++-- doc/guides/prog_guide/rte_flow.rst | 44 +++++++++++++++++++++++++++++++++++++ lib/librte_ethdev/rte_flow.c | 21 ++++++++++++++++++ lib/librte_ethdev/rte_flow.h | 24 ++++++++++++++++++++ lib/librte_ethdev/rte_flow_driver.h | 6 +++++ lib/librte_ethdev/version.map | 1 + 6 files changed, 104 insertions(+), 2 deletions(-) diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst index 7c50497..b8b6b02 100644 --- a/doc/guides/nics/mlx5.rst +++ b/doc/guides/nics/mlx5.rst @@ -1778,13 +1778,19 @@ all flows with assistance of external tools. .. code-block:: console - testpmd> flow dump + To dump all flows: + testpmd> flow dump all + and dump one flow: + testpmd> flow dump rule - call rte_flow_dev_dump api: .. code-block:: console + To dump all flows: rte_flow_dev_dump(port, file, NULL); + and dump one flow: + rte_flow_dump(port, flow, file, NULL); #. Dump human-readable flows from raw file: @@ -1792,4 +1798,4 @@ all flows with assistance of external tools. .. code-block:: console - mlx_steering_dump.py -f + mlx_steering_dump.py -f -flowptr diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index 62a5791..17e4351 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -3023,6 +3023,50 @@ Return values: - 0 on success, a negative errno value otherwise and ``rte_errno`` is set. +Dump +~~~~~ + +Dump information for all or one flows. + +This Function rte_flow_dev_dump will dump the information for all the flows. + +.. code-block:: c + + int + rte_flow_dev_dump(uint16_t port_id, FILE *file, + struct rte_flow_error *error); + +Arguments: + +- ``port_id``: port identifier of Ethernet device. +- ``file``: a pointer to a file for output +- ``error``: perform verbose error reporting if not NULL. PMDs initialize + this structure in case of error only. + +Return values: + +- 0 on success, a negative errno value otherwise and ``rte_errno`` is set. + +This Function rte_flow_dump will dump the information for one flow. + +.. code-block:: c + + int + rte_flow_dump(uint16_t port_id, struct rte_flow *flow, FILE *file, + struct rte_flow_error *error); + +Arguments: + +- ``port_id``: port identifier of Ethernet device. +- ``file``: a pointer to a file for output +- ``flow``: flow rule handle to dump. +- ``error``: perform verbose error reporting if not NULL. PMDs initialize + this structure in case of error only. + +Return values: + +- 0 on success, a negative errno value otherwise and ``rte_errno`` is set. + Query ~~~~~ diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c index 241af6c..ff051e7 100644 --- a/lib/librte_ethdev/rte_flow.c +++ b/lib/librte_ethdev/rte_flow.c @@ -1044,6 +1044,27 @@ enum rte_flow_conv_item_spec_type { } int +rte_flow_dump(uint16_t port_id, struct rte_flow *flow, + FILE *file, struct rte_flow_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); + int ret; + + if (unlikely(!ops)) + return -rte_errno; + if (likely(!!ops->dev_single_dump)) { + fts_enter(dev); + ret = ops->dev_single_dump(dev, flow, file, error); + fts_exit(dev); + return flow_err(port_id, ret, error); + } + return rte_flow_error_set(error, ENOSYS, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOSYS)); +} + +int rte_flow_get_aged_flows(uint16_t port_id, void **contexts, uint32_t nb_contexts, struct rte_flow_error *error) { diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h index 68c68cd..aac9e6c 100644 --- a/lib/librte_ethdev/rte_flow.h +++ b/lib/librte_ethdev/rte_flow.h @@ -3214,6 +3214,30 @@ enum rte_flow_conv_op { rte_flow_dev_dump(uint16_t port_id, FILE *file, struct rte_flow_error *error); /** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Dump hardware internal representation information of + * one rte flow to file. + * + * @param[in] port_id + * The port identifier of the Ethernet device. + * @param[in] flow + * The pointer of rte flow. + * @param[in] file + * A pointer to a file for output. + * @param[out] error + * Perform verbose error reporting if not NULL. PMDs initialize this + * structure in case of error only. + * @return + * 0 on success, a nagative value otherwise. + */ +__rte_experimental +int +rte_flow_dump(uint16_t port_id, struct rte_flow *flow, + FILE *file, struct rte_flow_error *error); + +/** * Check if mbuf dynamic field for metadata is registered. * * @return diff --git a/lib/librte_ethdev/rte_flow_driver.h b/lib/librte_ethdev/rte_flow_driver.h index dabd819..8aa4510 100644 --- a/lib/librte_ethdev/rte_flow_driver.h +++ b/lib/librte_ethdev/rte_flow_driver.h @@ -102,6 +102,12 @@ struct rte_flow_ops { (struct rte_eth_dev *dev, FILE *file, struct rte_flow_error *error); + /** See rte_flow_dump(). */ + int (*dev_single_dump) + (struct rte_eth_dev *dev, + struct rte_flow *flow, + FILE *file, + struct rte_flow_error *error); /** See rte_flow_get_aged_flows() */ int (*get_aged_flows) (struct rte_eth_dev *dev, diff --git a/lib/librte_ethdev/version.map b/lib/librte_ethdev/version.map index a124e1e..234798e 100644 --- a/lib/librte_ethdev/version.map +++ b/lib/librte_ethdev/version.map @@ -231,6 +231,7 @@ EXPERIMENTAL { rte_eth_fec_get_capability; rte_eth_fec_get; rte_eth_fec_set; + rte_flow_dump; rte_flow_shared_action_create; rte_flow_shared_action_destroy; rte_flow_shared_action_query; From patchwork Tue Mar 9 08:15:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haifei Luo X-Patchwork-Id: 88775 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B1B5AA0567; Wed, 10 Mar 2021 00:52:39 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6D91E22A569; Wed, 10 Mar 2021 00:52:31 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id 3FDD24069D for ; Tue, 9 Mar 2021 09:15:39 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from haifeil@nvidia.com) with SMTP; 9 Mar 2021 10:15:37 +0200 Received: from nvidia.com (gen-l-vrt-173.mtl.labs.mlnx [10.234.173.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 1298FMsG007468; Tue, 9 Mar 2021 10:15:37 +0200 From: Haifei Luo To: ferruh.yigit@intel.com, viacheslavo@nvidia.com, matan@nvidia.com, xiaoyun.li@intel.com, thomas@monjalon.net, orika@nvidia.com Cc: dev@dpdk.org, rasland@nvidia.com, xuemingl@nvidia.com Date: Tue, 9 Mar 2021 10:15:14 +0200 Message-Id: <1615277716-64404-3-git-send-email-haifeil@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1615277716-64404-1-git-send-email-haifeil@nvidia.com> References: <1615277716-64404-1-git-send-email-haifeil@nvidia.com> X-Mailman-Approved-At: Wed, 10 Mar 2021 00:52:28 +0100 Subject: [dpdk-dev] [PATCH 2/4] app/testpmd: add CLIs for single flow dump feature X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Add support for single flow dump. The CLIs to dump one rule: flow dump PORT rule ID to dump all: flow dump PORT all Examples: testpmd> flow dump 0 all testpmd> flow dump 0 rule 0 Signed-off-by: Haifei Luo --- app/test-pmd/cmdline_flow.c | 55 +++++++++++++++++++++++++---- app/test-pmd/config.c | 38 ++++++++++++++++++-- app/test-pmd/testpmd.h | 3 +- doc/guides/testpmd_app_ug/testpmd_funcs.rst | 6 +++- 4 files changed, 90 insertions(+), 12 deletions(-) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 49d9f9c..7f53b83 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -108,6 +108,10 @@ enum index { TUNNEL_SET, TUNNEL_MATCH, + /* Dump arguments */ + DUMP_ALL, + DUMP_ONE, + /* Shared action arguments */ SHARED_ACTION_CREATE, SHARED_ACTION_UPDATE, @@ -791,6 +795,8 @@ struct buffer { } destroy; /**< Destroy arguments. */ struct { char file[128]; + bool mode; + uint32_t rule; } dump; /**< Dump arguments. */ struct { uint32_t rule; @@ -842,6 +848,12 @@ struct parse_action_priv { ZERO, }; +static const enum index next_dump_subcmd[] = { + DUMP_ALL, + DUMP_ONE, + ZERO, +}; + static const enum index next_sa_subcmd[] = { SHARED_ACTION_CREATE, SHARED_ACTION_UPDATE, @@ -2028,10 +2040,9 @@ static int comp_set_modify_field_id(struct context *, const struct token *, }, [DUMP] = { .name = "dump", - .help = "dump all flow rules to file", - .next = NEXT(next_dump_attr, NEXT_ENTRY(PORT_ID)), - .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file), - ARGS_ENTRY(struct buffer, port)), + .help = "dump single/all flow rules to file", + .next = NEXT(next_dump_subcmd, NEXT_ENTRY(PORT_ID)), + .args = ARGS(ARGS_ENTRY(struct buffer, port)), .call = parse_dump, }, [QUERY] = { @@ -2121,6 +2132,22 @@ static int comp_set_modify_field_id(struct context *, const struct token *, .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)), .call = parse_destroy, }, + /* Dump arguments. */ + [DUMP_ALL] = { + .name = "all", + .help = "dump all", + .next = NEXT(next_dump_attr), + .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file)), + .call = parse_dump, + }, + [DUMP_ONE] = { + .name = "rule", + .help = "dump one rule", + .next = NEXT(next_dump_attr, NEXT_ENTRY(RULE_ID)), + .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file), + ARGS_ENTRY(struct buffer, args.dump.rule)), + .call = parse_dump, + }, /* Query arguments. */ [QUERY_ACTION] = { .name = "{action}", @@ -6342,8 +6369,20 @@ static int comp_set_modify_field_id(struct context *, const struct token *, ctx->objdata = 0; ctx->object = out; ctx->objmask = NULL; + return len; + } + switch (ctx->curr) { + case DUMP_ALL: + case DUMP_ONE: + out->args.dump.mode = (ctx->curr == DUMP_ALL) ? true : false; + out->command = ctx->curr; + ctx->objdata = 0; + ctx->object = out; + ctx->objmask = NULL; + return len; + default: + return -1; } - return len; } /** Parse tokens for query command. */ @@ -7637,8 +7676,10 @@ static int comp_set_modify_field_id(struct context *, const struct token *, case FLUSH: port_flow_flush(in->port); break; - case DUMP: - port_flow_dump(in->port, in->args.dump.file); + case DUMP_ONE: + case DUMP_ALL: + port_flow_dump(in->port, in->args.dump.mode, + in->args.dump.rule, in->args.dump.file); break; case QUERY: port_flow_query(in->port, in->args.query.rule, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 576d5ac..c6e54b6 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -1915,13 +1915,41 @@ struct rte_flow_shared_action * return ret; } -/** Dump all flow rules. */ +/** Dump flow rules. */ int -port_flow_dump(portid_t port_id, const char *file_name) +port_flow_dump(portid_t port_id, bool dump_all, uint32_t rule_id, + const char *file_name) { int ret = 0; FILE *file = stdout; struct rte_flow_error error; + struct rte_port *port; + struct port_flow *pflow; + struct rte_flow *tmpFlow = NULL; + bool found = false; + + if (port_id_is_invalid(port_id, ENABLED_WARN) || + port_id == (portid_t)RTE_PORT_ALL) + return -EINVAL; + + if (!dump_all) { + port = &ports[port_id]; + pflow = port->flow_list; + while (pflow) { + if (rule_id != pflow->id) { + pflow = pflow->next; + } else { + tmpFlow = pflow->flow; + if (tmpFlow) + found = true; + break; + } + } + if (found == false) { + printf("Failed to dump to flow %d\n", rule_id); + return -EINVAL; + } + } if (file_name && strlen(file_name)) { file = fopen(file_name, "w"); @@ -1931,7 +1959,11 @@ struct rte_flow_shared_action * return -errno; } } - ret = rte_flow_dev_dump(port_id, file, &error); + if (!dump_all) + ret = rte_flow_dump(port_id, tmpFlow, file, &error); + else + ret = rte_flow_dev_dump(port_id, file, &error); + if (ret) { port_flow_complain(&error); printf("Failed to dump flow: %s\n", strerror(-ret)); diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index ce83f31..3dcbac1 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -824,7 +824,8 @@ void update_age_action_context(const struct rte_flow_action *actions, struct port_flow *pf); int port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule); int port_flow_flush(portid_t port_id); -int port_flow_dump(portid_t port_id, const char *file_name); +int port_flow_dump(portid_t port_id, bool dump_all, + uint32_t rule, const char *file_name); int port_flow_query(portid_t port_id, uint32_t rule, const struct rte_flow_action *action); void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group); diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index f59eb8a..278e1ea 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -3314,7 +3314,11 @@ following sections. - Dump internal representation information of all flows in hardware:: - flow dump {port_id} {output_file} + flow dump {port_id} all {output_file} + + for one flow : + + flow dump {port_id} rule {rule_id} {output_file} - List and destroy aged flow rules:: From patchwork Tue Mar 9 08:15:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haifei Luo X-Patchwork-Id: 88776 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D6F83A0567; Wed, 10 Mar 2021 00:52:45 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9E4F822A592; Wed, 10 Mar 2021 00:52:32 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id 4732F22A3C1 for ; Tue, 9 Mar 2021 09:15:39 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from haifeil@nvidia.com) with SMTP; 9 Mar 2021 10:15:38 +0200 Received: from nvidia.com (gen-l-vrt-173.mtl.labs.mlnx [10.234.173.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 1298FMsH007468; Tue, 9 Mar 2021 10:15:38 +0200 From: Haifei Luo To: ferruh.yigit@intel.com, viacheslavo@nvidia.com, matan@nvidia.com, xiaoyun.li@intel.com, thomas@monjalon.net, orika@nvidia.com Cc: dev@dpdk.org, rasland@nvidia.com, xuemingl@nvidia.com Date: Tue, 9 Mar 2021 10:15:15 +0200 Message-Id: <1615277716-64404-4-git-send-email-haifeil@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1615277716-64404-1-git-send-email-haifeil@nvidia.com> References: <1615277716-64404-1-git-send-email-haifeil@nvidia.com> X-Mailman-Approved-At: Wed, 10 Mar 2021 00:52:28 +0100 Subject: [dpdk-dev] [PATCH 3/4] common/mlx5: add mlx5 APIs for single flow dump feature X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" add mlx5 APIs for single flow dump feature Signed-off-by: Haifei Luo --- drivers/common/mlx5/linux/meson.build | 4 ++++ drivers/common/mlx5/linux/mlx5_glue.c | 13 +++++++++++++ drivers/common/mlx5/linux/mlx5_glue.h | 1 + drivers/common/mlx5/mlx5_devx_cmds.c | 10 ++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 2 ++ drivers/common/mlx5/version.map | 1 + 6 files changed, 31 insertions(+) diff --git a/drivers/common/mlx5/linux/meson.build b/drivers/common/mlx5/linux/meson.build index 220de35..e8fcbd9 100644 --- a/drivers/common/mlx5/linux/meson.build +++ b/drivers/common/mlx5/linux/meson.build @@ -186,6 +186,10 @@ has_sym_args = [ 'mlx5dv_dr_action_create_aso' ], [ 'HAVE_INFINIBAND_VERBS_H', 'infiniband/verbs.h', 'INFINIBAND_VERBS_H' ], + [ 'HAVE_MLX5_UMR_IMKEY', 'infiniband/mlx5dv.h', + 'MLX5_WQE_UMR_CTRL_FLAG_INLINE' ], + [ 'HAVE_MLX5_DR_FLOW_DUMP_RULE', 'infiniband/mlx5dv.h', + 'mlx5dv_dump_dr_rule' ], ] config = configuration_data() foreach arg:has_sym_args diff --git a/drivers/common/mlx5/linux/mlx5_glue.c b/drivers/common/mlx5/linux/mlx5_glue.c index 964f7e7..d3bd645 100644 --- a/drivers/common/mlx5/linux/mlx5_glue.c +++ b/drivers/common/mlx5/linux/mlx5_glue.c @@ -1101,6 +1101,18 @@ } static int +mlx5_glue_dr_dump_single_rule(FILE *file, void *rule) +{ +#ifdef HAVE_MLX5_DR_FLOW_DUMP_RULE + return mlx5dv_dump_dr_rule(file, rule); +#else + RTE_SET_USED(file); + RTE_SET_USED(rule); + return -ENOTSUP; +#endif +} + +static int mlx5_glue_dr_dump_domain(FILE *file, void *domain) { #ifdef HAVE_MLX5_DR_FLOW_DUMP @@ -1423,6 +1435,7 @@ .devx_wq_query = mlx5_glue_devx_wq_query, .devx_port_query = mlx5_glue_devx_port_query, .dr_dump_domain = mlx5_glue_dr_dump_domain, + .dr_dump_rule = mlx5_glue_dr_dump_single_rule, .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, .dr_create_flow_action_sampler = mlx5_glue_dr_create_flow_action_sampler, diff --git a/drivers/common/mlx5/linux/mlx5_glue.h b/drivers/common/mlx5/linux/mlx5_glue.h index 9e385be..97462e9 100644 --- a/drivers/common/mlx5/linux/mlx5_glue.h +++ b/drivers/common/mlx5/linux/mlx5_glue.h @@ -313,6 +313,7 @@ struct mlx5_glue { uint32_t port_num, struct mlx5dv_devx_port *mlx5_devx_port); int (*dr_dump_domain)(FILE *file, void *domain); + int (*dr_dump_rule)(FILE *file, void *rule); int (*devx_query_eqn)(struct ibv_context *context, uint32_t cpus, uint32_t *eqn); struct mlx5dv_devx_event_channel *(*devx_create_event_channel) diff --git a/drivers/common/mlx5/mlx5_devx_cmds.c b/drivers/common/mlx5/mlx5_devx_cmds.c index 0060c37..7ddd6a7 100644 --- a/drivers/common/mlx5/mlx5_devx_cmds.c +++ b/drivers/common/mlx5/mlx5_devx_cmds.c @@ -1551,6 +1551,16 @@ struct mlx5_devx_obj * return -ret; } +int +mlx5_devx_cmd_flow_single_dump(void *rule_info __rte_unused, + FILE *file __rte_unused) +{ + int ret = 0; + if (rule_info) + ret = mlx5_glue->dr_dump_rule(file, rule_info); + return -ret; +} + /* * Create CQ using DevX API. * diff --git a/drivers/common/mlx5/mlx5_devx_cmds.h b/drivers/common/mlx5/mlx5_devx_cmds.h index bc66d28..1ea4d27 100644 --- a/drivers/common/mlx5/mlx5_devx_cmds.h +++ b/drivers/common/mlx5/mlx5_devx_cmds.h @@ -467,6 +467,8 @@ struct mlx5_devx_obj *mlx5_devx_cmd_create_tis(void *ctx, int mlx5_devx_cmd_flow_dump(void *fdb_domain, void *rx_domain, void *tx_domain, FILE *file); __rte_internal +int mlx5_devx_cmd_flow_single_dump(void *rule, FILE *file); +__rte_internal struct mlx5_devx_obj *mlx5_devx_cmd_create_cq(void *ctx, struct mlx5_devx_cq_attr *attr); __rte_internal diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map index 91f3fa5..4d49011 100644 --- a/drivers/common/mlx5/version.map +++ b/drivers/common/mlx5/version.map @@ -28,6 +28,7 @@ INTERNAL { mlx5_devx_cmd_flow_counter_alloc; mlx5_devx_cmd_flow_counter_query; mlx5_devx_cmd_flow_dump; + mlx5_devx_cmd_flow_single_dump; mlx5_devx_cmd_mkey_create; mlx5_devx_cmd_modify_qp_state; mlx5_devx_cmd_modify_rq; From patchwork Tue Mar 9 08:15:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haifei Luo X-Patchwork-Id: 88777 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3915EA0567; Wed, 10 Mar 2021 00:52:51 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CF83D22A598; Wed, 10 Mar 2021 00:52:33 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id 1E74422A3E5 for ; Tue, 9 Mar 2021 09:15:44 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from haifeil@nvidia.com) with SMTP; 9 Mar 2021 10:15:39 +0200 Received: from nvidia.com (gen-l-vrt-173.mtl.labs.mlnx [10.234.173.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 1298FMsI007468; Tue, 9 Mar 2021 10:15:39 +0200 From: Haifei Luo To: ferruh.yigit@intel.com, viacheslavo@nvidia.com, matan@nvidia.com, xiaoyun.li@intel.com, thomas@monjalon.net, orika@nvidia.com Cc: dev@dpdk.org, rasland@nvidia.com, xuemingl@nvidia.com Date: Tue, 9 Mar 2021 10:15:16 +0200 Message-Id: <1615277716-64404-5-git-send-email-haifeil@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1615277716-64404-1-git-send-email-haifeil@nvidia.com> References: <1615277716-64404-1-git-send-email-haifeil@nvidia.com> X-Mailman-Approved-At: Wed, 10 Mar 2021 00:52:28 +0100 Subject: [dpdk-dev] [PATCH 4/4] net/mlx5: add mlx5 APIs for single flow dump feature X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Add API mlx5_flow_dump_rule to support the feature. Modify mlx5_socket since one extra arg flow_ptr is added. Signed-off-by: Haifei Luo --- drivers/net/mlx5/linux/mlx5_socket.c | 27 ++++++++++++++++++------- drivers/net/mlx5/mlx5.h | 3 +++ drivers/net/mlx5/mlx5_flow.c | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_socket.c b/drivers/net/mlx5/linux/mlx5_socket.c index 1938453..88ca8e1 100644 --- a/drivers/net/mlx5/linux/mlx5_socket.c +++ b/drivers/net/mlx5/linux/mlx5_socket.c @@ -32,12 +32,15 @@ mlx5_pmd_socket_handle(void *cb __rte_unused) { int conn_sock; - int ret; + int ret, j; struct cmsghdr *cmsg = NULL; - int data; + #define LENGTH 9 + /*The first byte for port_id and the rest for flowptr.*/ + int data[LENGTH]; + uint64_t flow_ptr = 0; char buf[CMSG_SPACE(sizeof(int))] = { 0 }; struct iovec io = { - .iov_base = &data, + .iov_base = &data[0], .iov_len = sizeof(data), }; struct msghdr msg = { @@ -50,7 +53,9 @@ int fd; FILE *file = NULL; struct rte_eth_dev *dev; + struct rte_flow_error err; + memset(data, 0, sizeof(data)); /* Accept the connection from the client. */ conn_sock = accept(server_socket, NULL, NULL); if (conn_sock < 0) { @@ -88,15 +93,23 @@ } /* Dump flow. */ dev = &rte_eth_devices[port_id]; - ret = mlx5_flow_dev_dump(dev, file, NULL); + /*The first byte in data for port_id and the following 8 for flowptr*/ + for (j = 1; j < LENGTH; j++) + flow_ptr = (flow_ptr << 8) + data[j]; + if (flow_ptr == 0) + ret = mlx5_flow_dev_dump(dev, file, NULL); + else + ret = mlx5_flow_dump_rule(dev, + (struct rte_flow *)((uintptr_t)flow_ptr), file, &err); + /* Set-up the ancillary data and reply. */ msg.msg_controllen = 0; msg.msg_control = NULL; msg.msg_iovlen = 1; msg.msg_iov = &io; - data = -ret; - io.iov_len = sizeof(data); - io.iov_base = &data; + data[0] = -ret; + io.iov_len = sizeof(data[0]); + io.iov_base = &data[0]; do { ret = sendmsg(conn_sock, &msg, 0); } while (ret < 0 && errno == EINTR); diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index a281fd2..c5d4cee 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1222,6 +1222,9 @@ int mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt, bool clear, uint64_t *pkts, uint64_t *bytes); int mlx5_flow_dev_dump(struct rte_eth_dev *dev, FILE *file, struct rte_flow_error *error); +int mlx5_flow_dump_rule(struct rte_eth_dev *dev, struct rte_flow *flow, + FILE *file, + struct rte_flow_error *error); void mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev); int mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts, uint32_t nb_contexts, struct rte_flow_error *error); diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index ab5be3d..6d031ba 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -635,6 +635,7 @@ enum mlx5_expansion { .isolate = mlx5_flow_isolate, .query = mlx5_flow_query, .dev_dump = mlx5_flow_dev_dump, + .dev_single_dump = mlx5_flow_dump_rule, .get_aged_flows = mlx5_flow_get_aged_flows, .shared_action_create = mlx5_shared_action_create, .shared_action_destroy = mlx5_shared_action_destroy, @@ -7200,6 +7201,43 @@ struct mlx5_meter_domains_infos * sh->tx_domain, file); } +int +mlx5_flow_dump_rule(struct rte_eth_dev *dev, struct rte_flow *flow_idx, + FILE *file, + struct rte_flow_error *error __rte_unused) +{ + struct mlx5_priv *priv = dev->data->dev_private; + uint32_t handle_idx; + int ret; + struct mlx5_flow_handle *dh; + struct rte_flow *flow = mlx5_ipool_get(priv->sh->ipool + [MLX5_IPOOL_RTE_FLOW], (uintptr_t)(void *)flow_idx); + + if (!priv->config.dv_flow_en) { + if (fputs("device dv flow disabled\n", file) <= 0) + return -errno; + return -ENOTSUP; + } + + if (!flow) + return -ENOENT; + handle_idx = flow->dev_handles; + while (handle_idx) { + dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], + handle_idx); + if (!dh) + return -ENOENT; + if (dh->drv_flow) { + ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow, + file); + if (ret) + return -ENOENT; + } + handle_idx = dh->next.next; + } + return 0; +} + /** * Get aged-out flows. *