Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/62556/?format=api
https://patches.dpdk.org/api/patches/62556/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1573053090-179521-9-git-send-email-suanmingm@mellanox.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1573053090-179521-9-git-send-email-suanmingm@mellanox.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1573053090-179521-9-git-send-email-suanmingm@mellanox.com", "date": "2019-11-06T15:11:17", "name": "[08/19] net/mlx5: support basic meter operations", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "7de0d65dd47795c997bd5273f1ea106be36fc8d9", "submitter": { "id": 1358, "url": "https://patches.dpdk.org/api/people/1358/?format=api", "name": "Suanming Mou", "email": "suanmingm@mellanox.com" }, "delegate": { "id": 3268, "url": "https://patches.dpdk.org/api/users/3268/?format=api", "username": "rasland", "first_name": "Raslan", "last_name": "Darawsheh", "email": "rasland@nvidia.com" }, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1573053090-179521-9-git-send-email-suanmingm@mellanox.com/mbox/", "series": [ { "id": 7297, "url": "https://patches.dpdk.org/api/series/7297/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=7297", "date": "2019-11-06T15:11:09", "name": "net/mlx5: support meter", "version": 1, "mbox": "https://patches.dpdk.org/series/7297/mbox/" } ], "comments": "https://patches.dpdk.org/api/patches/62556/comments/", "check": "fail", "checks": "https://patches.dpdk.org/api/patches/62556/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@inbox.dpdk.org", "Delivered-To": "patchwork@inbox.dpdk.org", "Received": [ "from dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 99966A04AB;\n\tWed, 6 Nov 2019 16:13:04 +0100 (CET)", "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 44CBF1C241;\n\tWed, 6 Nov 2019 16:12:14 +0100 (CET)", "from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130])\n by dpdk.org (Postfix) with ESMTP id 53F511C195\n for <dev@dpdk.org>; Wed, 6 Nov 2019 16:11:58 +0100 (CET)" ], "From": "Suanming Mou <suanmingm@mellanox.com>", "To": "Matan Azrad <matan@mellanox.com>, Shahaf Shuler <shahafs@mellanox.com>,\n Viacheslav Ovsiienko <viacheslavo@mellanox.com>", "Cc": "dev@dpdk.org", "Date": "Wed, 6 Nov 2019 17:11:17 +0200", "Message-Id": "<1573053090-179521-9-git-send-email-suanmingm@mellanox.com>", "X-Mailer": "git-send-email 1.8.3.1", "In-Reply-To": "<1573053090-179521-1-git-send-email-suanmingm@mellanox.com>", "References": "<1573053090-179521-1-git-send-email-suanmingm@mellanox.com>", "Subject": "[dpdk-dev] [PATCH 08/19] net/mlx5: support basic meter operations", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "This commit add the basic meter operations for meter create and destroy.\n\nNew internal functions in rte_mtr_ops callback:\n1. create()\n2. destroy()\n\nThe create() callback will create the corresponding flow rules on the\nmeter table.\nThe destroy() callback destroys the flow rules on the meter table.\n\nSigned-off-by: Suanming Mou <suanmingm@mellanox.com>\n---\n drivers/net/mlx5/mlx5.c | 1 +\n drivers/net/mlx5/mlx5.h | 5 +\n drivers/net/mlx5/mlx5_flow.h | 8 ++\n drivers/net/mlx5/mlx5_flow_meter.c | 242 ++++++++++++++++++++++++++++++++++++-\n 4 files changed, 254 insertions(+), 2 deletions(-)", "diff": "diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c\nindex 7958067..1a2fef6 100644\n--- a/drivers/net/mlx5/mlx5.c\n+++ b/drivers/net/mlx5/mlx5.c\n@@ -2405,6 +2405,7 @@ struct mlx5_flow_id_pool *\n \t\tmlx5_nl_mac_addr_sync(eth_dev);\n \tTAILQ_INIT(&priv->flows);\n \tTAILQ_INIT(&priv->ctrl_flows);\n+\tTAILQ_INIT(&priv->flow_meters);\n \tTAILQ_INIT(&priv->flow_meter_profiles);\n \t/* Hint libmlx5 to use PMD allocator for data plane resources */\n \tstruct mlx5dv_ctx_allocators alctr = {\ndiff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h\nindex 58bd7d0..35abb3f 100644\n--- a/drivers/net/mlx5/mlx5.h\n+++ b/drivers/net/mlx5/mlx5.h\n@@ -692,6 +692,8 @@ struct mlx5_proc_priv {\n \n /* MTR profile list. */\n TAILQ_HEAD(mlx5_mtr_profiles, mlx5_flow_meter_profile);\n+/* MTR list. */\n+TAILQ_HEAD(mlx5_flow_meters, mlx5_flow_meter);\n \n #define MLX5_PROC_PRIV(port_id) \\\n \t((struct mlx5_proc_priv *)rte_eth_devices[port_id].process_private)\n@@ -764,6 +766,7 @@ struct mlx5_priv {\n \tuint8_t mtr_sfx_reg; /* Meter prefix-suffix flow match REG_C. */\n \tuint8_t mtr_color_reg; /* Meter color match REG_C. */\n \tstruct mlx5_mtr_profiles flow_meter_profiles; /* MTR profile list. */\n+\tstruct mlx5_flow_meters flow_meters; /* MTR list. */\n #ifndef RTE_ARCH_64\n \trte_spinlock_t uar_lock_cq; /* CQs share a common distinct UAR */\n \trte_spinlock_t uar_lock[MLX5_UAR_PAGE_NUM_MAX];\n@@ -1029,5 +1032,7 @@ struct mlx5_devx_obj *mlx5_devx_cmd_create_tis\n /* mlx5_flow_meter.c */\n \n int mlx5_flow_meter_ops_get(struct rte_eth_dev *dev, void *arg);\n+struct mlx5_flow_meter *mlx5_flow_meter_find(struct mlx5_priv *priv,\n+\t\t\t\t\t uint32_t meter_id);\n \n #endif /* RTE_PMD_MLX5_H_ */\ndiff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h\nindex ca0a98d..e7bd787 100644\n--- a/drivers/net/mlx5/mlx5_flow.h\n+++ b/drivers/net/mlx5/mlx5_flow.h\n@@ -557,14 +557,22 @@ struct mlx5_meter_domains_infos {\n \n /* Meter parameter structure. */\n struct mlx5_flow_meter {\n+\tTAILQ_ENTRY(mlx5_flow_meter) next;\n+\t/**< Pointer to the next flow meter structure. */\n \tuint32_t meter_id;\n \t/**< Meter id. */\n \tstruct rte_mtr_params params;\n \t/**< Meter rule parameters. */\n+\tstruct mlx5_flow_meter_profile *profile;\n+\t/**< Meter profile parameters. */\n \tstruct mlx5_meter_domains_infos *mfts;\n \t/**< Flow table created for this meter. */\n \tuint32_t ref_cnt;\n \t/**< Use count. */\n+\tuint32_t active_state:1;\n+\t/**< Meter state. */\n+\tuint32_t shared:1;\n+\t/**< Meter shared or not. */\n };\n \n /* RFC2697 parameter structure. */\ndiff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c\nindex 5ad5e14..76a3180 100644\n--- a/drivers/net/mlx5/mlx5_flow_meter.c\n+++ b/drivers/net/mlx5/mlx5_flow_meter.c\n@@ -362,12 +362,227 @@\n \treturn 0;\n }\n \n+/**\n+ * Convert wrong color setting action to verbose error.\n+ *\n+ * @param[in] action\n+ * Policy color action.\n+ *\n+ * @return\n+ * Verbose meter color error type.\n+ */\n+static inline enum rte_mtr_error_type\n+action2error(enum rte_mtr_policer_action action)\n+{\n+\tswitch (action) {\n+\tcase MTR_POLICER_ACTION_COLOR_GREEN:\n+\t\treturn RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN;\n+\tcase MTR_POLICER_ACTION_COLOR_YELLOW:\n+\t\treturn RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW;\n+\tcase MTR_POLICER_ACTION_COLOR_RED:\n+\t\treturn RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\treturn RTE_MTR_ERROR_TYPE_UNSPECIFIED;\n+}\n+\n+/**\n+ * Check meter validation.\n+ *\n+ * @param[in] priv\n+ * Pointer to mlx5 private data structure.\n+ * @param[in] meter_id\n+ * Meter id.\n+ * @param[in] params\n+ * Pointer to rte meter parameters.\n+ * @param[out] error\n+ * Pointer to rte meter error structure.\n+ *\n+ * @return\n+ * 0 on success, a negative errno value otherwise and rte_errno is set.\n+ */\n+static int\n+mlx5_flow_meter_validate(struct mlx5_priv *priv, uint32_t meter_id,\n+\t\t\t struct rte_mtr_params *params,\n+\t\t\t struct rte_mtr_error *error)\n+{\n+\tstatic enum rte_mtr_policer_action\n+\t\t\t\tvalid_recol_action[RTE_COLORS] = {\n+\t\t\t\t\t MTR_POLICER_ACTION_COLOR_GREEN,\n+\t\t\t\t\t MTR_POLICER_ACTION_COLOR_YELLOW,\n+\t\t\t\t\t MTR_POLICER_ACTION_COLOR_RED };\n+\tint i;\n+\n+\t/* Meter params must not be NULL. */\n+\tif (params == NULL)\n+\t\treturn -rte_mtr_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_MTR_ERROR_TYPE_MTR_PARAMS,\n+\t\t\t\t\t NULL, \"Meter object params null.\");\n+\t/* Previous meter color is not supported. */\n+\tif (params->use_prev_mtr_color)\n+\t\treturn -rte_mtr_error_set(error, ENOTSUP,\n+\t\t\t\t\t RTE_MTR_ERROR_TYPE_MTR_PARAMS,\n+\t\t\t\t\t NULL,\n+\t\t\t\t\t \"Previous meter color \"\n+\t\t\t\t\t \"not supported.\");\n+\t/* Validate policer settings. */\n+\tfor (i = 0; i < RTE_COLORS; i++)\n+\t\tif (params->action[i] != valid_recol_action[i] &&\n+\t\t params->action[i] != MTR_POLICER_ACTION_DROP)\n+\t\t\treturn -rte_mtr_error_set\n+\t\t\t\t\t(error, ENOTSUP,\n+\t\t\t\t\t action2error(params->action[i]), NULL,\n+\t\t\t\t\t \"Recolor action not supported.\");\n+\t/* Validate meter id. */\n+\tif (mlx5_flow_meter_find(priv, meter_id))\n+\t\treturn -rte_mtr_error_set(error, EEXIST,\n+\t\t\t\t\t RTE_MTR_ERROR_TYPE_MTR_ID, NULL,\n+\t\t\t\t\t \"Meter object already exists.\");\n+\treturn 0;\n+}\n+\n+/**\n+ * Create meter rules.\n+ *\n+ * @param[in] dev\n+ * Pointer to Ethernet device.\n+ * @param[in] meter_id\n+ * Meter id.\n+ * @param[in] params\n+ * Pointer to rte meter parameters.\n+ * @param[in] shared\n+ * Meter shared with other flow or not.\n+ * @param[out] error\n+ * Pointer to rte meter error structure.\n+ *\n+ * @return\n+ * 0 on success, a negative errno value otherwise and rte_errno is set.\n+ */\n+static int\n+mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id,\n+\t\t struct rte_mtr_params *params, int shared,\n+\t\t struct rte_mtr_error *error)\n+{\n+\tstruct mlx5_priv *priv = dev->data->dev_private;\n+\tstruct mlx5_flow_meters *fms = &priv->flow_meters;\n+\tstruct mlx5_flow_meter_profile *fmp;\n+\tstruct mlx5_flow_meter *fm;\n+\tconst struct rte_flow_attr attr = {\n+\t\t\t\t.ingress = 1,\n+\t\t\t\t.egress = 1,\n+\t\t\t\t.transfer = priv->config.dv_esw_en ? 1 : 0,\n+\t\t\t};\n+\tint ret;\n+\n+\tif (!priv->mtr_en)\n+\t\treturn -rte_mtr_error_set(error, ENOTSUP,\n+\t\t\t\t\t RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,\n+\t\t\t\t\t \"Meter is not support\");\n+\t/* Validate the parameters. */\n+\tret = mlx5_flow_meter_validate(priv, meter_id, params, error);\n+\tif (ret)\n+\t\treturn ret;\n+\t/* Meter profile must exist. */\n+\tfmp = mlx5_flow_meter_profile_find(priv, params->meter_profile_id);\n+\tif (fmp == NULL)\n+\t\treturn -rte_mtr_error_set(error, ENOENT,\n+\t\t\t\t\t RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,\n+\t\t\t\t\t NULL, \"Meter profile id not valid.\");\n+\t/* Allocate the flow meter memory. */\n+\tfm = rte_calloc(__func__, 1,\n+\t\t\tsizeof(struct mlx5_flow_meter), RTE_CACHE_LINE_SIZE);\n+\tif (fm == NULL)\n+\t\treturn -rte_mtr_error_set(error, ENOMEM,\n+\t\t\t\t\t RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,\n+\t\t\t\t\t \"Memory alloc failed for meter.\");\n+\t/* Fill the flow meter parameters. */\n+\tfm->meter_id = meter_id;\n+\tfm->profile = fmp;\n+\tfm->params = *params;\n+\tfm->mfts = mlx5_flow_create_mtr_tbls(dev);\n+\tif (!fm->mfts)\n+\t\tgoto error;\n+\tret = mlx5_flow_create_policer_rules(dev, fm, &attr);\n+\tif (ret)\n+\t\tgoto error;\n+\t/* Add to the flow meter list. */\n+\tTAILQ_INSERT_TAIL(fms, fm, next);\n+\tfm->active_state = 1; /* Config meter starts as active. */\n+\tfm->shared = !!shared;\n+\tfm->profile->ref_cnt++;\n+\treturn 0;\n+error:\n+\tmlx5_flow_destroy_policer_rules(dev, fm, &attr);\n+\tmlx5_flow_destroy_mtr_tbls(dev, fm->mfts);\n+\trte_free(fm);\n+\treturn -rte_mtr_error_set(error, -ret,\n+\t\t\t\t RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t NULL, \"Failed to create devx meter.\");\n+}\n+\n+/**\n+ * Destroy meter rules.\n+ *\n+ * @param[in] dev\n+ * Pointer to Ethernet device.\n+ * @param[in] meter_id\n+ * Meter id.\n+ * @param[out] error\n+ * Pointer to rte meter error structure.\n+ *\n+ * @return\n+ * 0 on success, a negative errno value otherwise and rte_errno is set.\n+ */\n+static int\n+mlx5_flow_meter_destroy(struct rte_eth_dev *dev, uint32_t meter_id,\n+\t\t\tstruct rte_mtr_error *error)\n+{\n+\tstruct mlx5_priv *priv = dev->data->dev_private;\n+\tstruct mlx5_flow_meters *fms = &priv->flow_meters;\n+\tstruct mlx5_flow_meter_profile *fmp;\n+\tstruct mlx5_flow_meter *fm;\n+\tconst struct rte_flow_attr attr = {\n+\t\t\t\t.ingress = 1,\n+\t\t\t\t.egress = 1,\n+\t\t\t\t.transfer = priv->config.dv_esw_en ? 1 : 0,\n+\t\t\t};\n+\n+\tif (!priv->mtr_en)\n+\t\treturn -rte_mtr_error_set(error, ENOTSUP,\n+\t\t\t\t\t RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,\n+\t\t\t\t\t \"Meter is not support\");\n+\t/* Meter object must exist. */\n+\tfm = mlx5_flow_meter_find(priv, meter_id);\n+\tif (fm == NULL)\n+\t\treturn -rte_mtr_error_set(error, ENOENT,\n+\t\t\t\t\t RTE_MTR_ERROR_TYPE_MTR_ID,\n+\t\t\t\t\t NULL, \"Meter object id not valid.\");\n+\t/* Meter object must not have any owner. */\n+\tif (fm->ref_cnt > 0)\n+\t\treturn -rte_mtr_error_set(error, EBUSY,\n+\t\t\t\t\t RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, \"Meter object is being used.\");\n+\t/* Get the meter profile. */\n+\tfmp = fm->profile;\n+\tRTE_ASSERT(fmp);\n+\t/* Update dependencies. */\n+\tfmp->ref_cnt--;\n+\t/* Remove from the flow meter list. */\n+\tTAILQ_REMOVE(fms, fm, next);\n+\t/* Free meter flow table */\n+\tmlx5_flow_destroy_policer_rules(dev, fm, &attr);\n+\tmlx5_flow_destroy_mtr_tbls(dev, fm->mfts);\n+\trte_free(fm);\n+\treturn 0;\n+}\n+\n static const struct rte_mtr_ops mlx5_flow_mtr_ops = {\n \t.capabilities_get = mlx5_flow_mtr_cap_get,\n \t.meter_profile_add = mlx5_flow_meter_profile_add,\n \t.meter_profile_delete = mlx5_flow_meter_profile_delete,\n-\t.create = NULL,\n-\t.destroy = NULL,\n+\t.create = mlx5_flow_meter_create,\n+\t.destroy = mlx5_flow_meter_destroy,\n \t.meter_enable = NULL,\n \t.meter_disable = NULL,\n \t.meter_profile_update = NULL,\n@@ -394,3 +609,26 @@\n \t*(const struct rte_mtr_ops **)arg = &mlx5_flow_mtr_ops;\n \treturn 0;\n }\n+\n+/**\n+ * Find meter by id.\n+ *\n+ * @param priv\n+ * Pointer to mlx5_priv.\n+ * @param meter_id\n+ * Meter id.\n+ *\n+ * @return\n+ * Pointer to the profile found on success, NULL otherwise.\n+ */\n+struct mlx5_flow_meter *\n+mlx5_flow_meter_find(struct mlx5_priv *priv, uint32_t meter_id)\n+{\n+\tstruct mlx5_flow_meters *fms = &priv->flow_meters;\n+\tstruct mlx5_flow_meter *fm;\n+\n+\tTAILQ_FOREACH(fm, fms, next)\n+\t\tif (meter_id == fm->meter_id)\n+\t\t\treturn fm;\n+\treturn NULL;\n+}\n", "prefixes": [ "08/19" ] }{ "id": 62556, "url": "