DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bing Zhao <bingz@nvidia.com>
To: <viacheslavo@nvidia.com>, <matan@nvidia.com>
Cc: <dev@dpdk.org>, <orika@nvidia.com>, <rasland@nvidia.com>
Subject: [dpdk-dev] [PATCH 1/6] net/mlx5: add yellow color default policy
Date: Mon, 5 Jul 2021 18:57:51 +0300	[thread overview]
Message-ID: <20210705155756.21443-2-bingz@nvidia.com> (raw)
In-Reply-To: <20210705155756.21443-1-bingz@nvidia.com>

To support the yellow color for the default meter policy, the
default policy action for yellow should be created together with
the green policy.

The default policy action for yellow action is the same as that for
green. In the same table, the same matcher will be reused for yellow
and the destination group will be the same.

Signed-off-by: Bing Zhao <bingz@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_dv.c | 88 +++++++++++++++++++++------------
 1 file changed, 57 insertions(+), 31 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index a04a3c2bb8..c6a06d9def 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -15365,19 +15365,18 @@ __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
 	if (!is_default_policy && (priv->representor || priv->master)) {
 		if (flow_dv_translate_item_port_id(dev, matcher.buf,
 						   value.buf, NULL, attr)) {
-			DRV_LOG(ERR,
-			"Failed to create meter policy flow with port.");
+			DRV_LOG(ERR, "Failed to create meter policy%d flow's"
+				" value with port.", color);
 			return -1;
 		}
 	}
 	flow_dv_match_meta_reg(matcher.buf, value.buf,
-				(enum modify_reg)color_reg_c_idx,
-				rte_col_2_mlx5_col(color),
-				UINT32_MAX);
-	ret = mlx5_flow_os_create_flow(matcher_object,
-			(void *)&value, actions_n, actions, rule);
+			       (enum modify_reg)color_reg_c_idx,
+			       rte_col_2_mlx5_col(color), UINT32_MAX);
+	ret = mlx5_flow_os_create_flow(matcher_object, (void *)&value,
+				       actions_n, actions, rule);
 	if (ret) {
-		DRV_LOG(ERR, "Failed to create meter policy flow.");
+		DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
 		return -1;
 	}
 	return 0;
@@ -15416,8 +15415,8 @@ __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
 	if (!is_default_policy && (priv->representor || priv->master)) {
 		if (flow_dv_translate_item_port_id(dev, matcher.mask.buf,
 						   value.buf, NULL, attr)) {
-			DRV_LOG(ERR,
-			"Failed to register meter drop matcher with port.");
+			DRV_LOG(ERR, "Failed to register meter policy%d matcher"
+				" with port.", priority);
 			return -1;
 		}
 	}
@@ -15425,9 +15424,11 @@ __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
 	if (priority < RTE_COLOR_RED)
 		flow_dv_match_meta_reg(matcher.mask.buf, value.buf,
 			(enum modify_reg)color_reg_c_idx, 0, color_mask);
-	matcher.priority = priority;
+	/* Adjust the priority */
+	matcher.priority = (priority == RTE_COLOR_YELLOW) ?
+			   RTE_COLOR_GREEN : priority;
 	matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
-					matcher.mask.size);
+				    matcher.mask.size);
 	entry = mlx5_cache_register(&tbl_data->matchers, &ctx);
 	if (!entry) {
 		DRV_LOG(ERR, "Failed to register meter drop matcher.");
@@ -15490,15 +15491,18 @@ __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
 	/* Prepare matchers. */
 	color_reg_c_idx = ret;
 	for (i = 0; i < RTE_COLORS; i++) {
-		if (i == RTE_COLOR_YELLOW || !acts[i].actions_n)
+		if (!acts[i].actions_n)
 			continue;
 		attr.priority = i;
 		if (!sub_policy->color_matcher[i]) {
 			/* Create matchers for Color. */
 			if (__flow_dv_create_policy_matcher(dev,
 				color_reg_c_idx, i, sub_policy,
-				&attr, is_default_policy, &flow_err))
+				&attr, is_default_policy, &flow_err)) {
+				DRV_LOG(ERR,
+					"Failed to create color%u matcher.", i);
 				return -1;
+			}
 		}
 		/* Create flow, matching color. */
 		if (acts[i].actions_n)
@@ -15509,8 +15513,11 @@ __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
 				acts[i].dv_actions,
 				is_default_policy,
 				&sub_policy->color_rule[i],
-				&attr))
+				&attr)) {
+				DRV_LOG(ERR,
+					"Failed to create color%u rule.", i);
 				return -1;
+			}
 	}
 	return 0;
 }
@@ -15665,8 +15672,7 @@ __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
 			sizeof(struct mlx5_flow_meter_def_policy),
 			RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
 		if (!def_policy) {
-			DRV_LOG(ERR, "Failed to alloc "
-					"default policy table.");
+			DRV_LOG(ERR, "Failed to alloc default policy table.");
 			goto def_policy_error;
 		}
 		mtrmng->def_policy[domain] = def_policy;
@@ -15682,26 +15688,46 @@ __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
 		}
 		def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
 		tbl_data = container_of(jump_tbl,
-				struct mlx5_flow_tbl_data_entry, tbl);
+					struct mlx5_flow_tbl_data_entry, tbl);
 		def_policy->dr_jump_action[RTE_COLOR_GREEN] =
 						tbl_data->jump.action;
-		acts[RTE_COLOR_GREEN].dv_actions[0] =
-						tbl_data->jump.action;
+		acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
 		acts[RTE_COLOR_GREEN].actions_n = 1;
+		/*
+		 * YELLOW has the same default policy as GREEN does.
+		 * G & Y share the same table and action.
+		 */
+		jump_tbl = flow_dv_tbl_resource_get(dev,
+				MLX5_FLOW_TABLE_LEVEL_METER,
+				egress, transfer, false, NULL, 0,
+				0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
+		if (!jump_tbl) {
+			DRV_LOG(ERR,
+				"Failed to get meter suffix table.");
+			goto def_policy_error;
+		}
+		def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
+		tbl_data = container_of(jump_tbl,
+					struct mlx5_flow_tbl_data_entry, tbl);
+		def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
+						tbl_data->jump.action;
+		acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
+		acts[RTE_COLOR_YELLOW].actions_n = 1;
 		/* Create jump action to the drop table. */
 		if (!mtrmng->drop_tbl[domain]) {
 			mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
 				(dev, MLX5_FLOW_TABLE_LEVEL_METER,
-				egress, transfer, false, NULL, 0,
-				0, MLX5_MTR_TABLE_ID_DROP, &error);
+				 egress, transfer, false, NULL, 0,
+				 0, MLX5_MTR_TABLE_ID_DROP, &error);
 			if (!mtrmng->drop_tbl[domain]) {
-				DRV_LOG(ERR, "Failed to create "
-				"meter drop table for default policy.");
+				DRV_LOG(ERR, "Failed to create meter "
+					"drop table for default policy.");
 				goto def_policy_error;
 			}
 		}
+		/* all RED: unique Drop table for jump action. */
 		tbl_data = container_of(mtrmng->drop_tbl[domain],
-				struct mlx5_flow_tbl_data_entry, tbl);
+					struct mlx5_flow_tbl_data_entry, tbl);
 		def_policy->dr_jump_action[RTE_COLOR_RED] =
 						tbl_data->jump.action;
 		acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
@@ -15711,15 +15737,14 @@ __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
 					&def_policy->sub_policy,
 					egress, transfer, true, acts);
 		if (ret) {
-			DRV_LOG(ERR, "Failed to create "
-				"default policy rules.");
-				goto def_policy_error;
+			DRV_LOG(ERR, "Failed to create default policy rules.");
+			goto def_policy_error;
 		}
 	}
 	return 0;
 def_policy_error:
 	__flow_dv_destroy_domain_def_policy(dev,
-			(enum mlx5_meter_domain)domain);
+					    (enum mlx5_meter_domain)domain);
 	return -1;
 }
 
@@ -15742,8 +15767,9 @@ flow_dv_create_def_policy(struct rte_eth_dev *dev)
 		if (!priv->config.dv_esw_en && i == MLX5_MTR_DOMAIN_TRANSFER)
 			continue;
 		if (__flow_dv_create_domain_def_policy(dev, i)) {
-			DRV_LOG(ERR,
-			"Failed to create default policy");
+			DRV_LOG(ERR, "Failed to create default policy");
+			/* Rollback the created default policies for others. */
+			flow_dv_destroy_def_policy(dev);
 			return -1;
 		}
 	}
-- 
2.27.0


  reply	other threads:[~2021-07-05 15:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-05 15:57 [dpdk-dev] [PATCH 0/6] support yellow color policy in mlx5 Bing Zhao
2021-07-05 15:57 ` Bing Zhao [this message]
2021-07-05 15:57 ` [dpdk-dev] [PATCH 2/6] net/mlx5: support yellow in meter policy validation Bing Zhao
2021-07-05 15:57 ` [dpdk-dev] [PATCH 3/6] net/mlx5: enable meter bucket overflow for yellow color Bing Zhao
2021-07-05 15:57 ` [dpdk-dev] [PATCH 4/6] net/mlx5: added support for yellow policy rules Bing Zhao
2021-07-05 15:57 ` [dpdk-dev] [PATCH 5/6] net/mlx5: split policies handling of colors Bing Zhao
2021-07-05 15:57 ` [dpdk-dev] [PATCH 6/6] doc: update mlx5 metering policy part Bing Zhao
2021-07-18 17:18 ` [dpdk-dev] [PATCH v2 0/7] support yellow color policy in mlx5 Bing Zhao
2021-07-18 17:18   ` [dpdk-dev] [PATCH v2 1/7] net/mlx5: handle yellow case in default meter policy Bing Zhao
2021-07-18 17:18   ` [dpdk-dev] [PATCH v2 2/7] net/mlx5: enable meter bucket overflow for yellow color Bing Zhao
2021-07-18 17:18   ` [dpdk-dev] [PATCH v2 3/7] net/mlx5: added support for yellow policy rules Bing Zhao
2021-07-18 17:18   ` [dpdk-dev] [PATCH v2 4/7] net/mlx5: split policies handling of colors Bing Zhao
2021-07-18 17:18   ` [dpdk-dev] [PATCH v2 5/7] net/mlx5: support yellow in meter policy validation Bing Zhao
2021-07-18 17:18   ` [dpdk-dev] [PATCH v2 6/7] net/mlx5: check consistency of meter policy and profile Bing Zhao
2021-07-18 17:18   ` [dpdk-dev] [PATCH v2 7/7] net/mlx5: add meter support for trTCM profiles Bing Zhao
2021-07-21  8:54 ` [dpdk-dev] [PATCH v3 0/7] support yellow color policy in mlx5 Bing Zhao
2021-07-21  8:54   ` [dpdk-dev] [PATCH v3 1/7] net/mlx5: handle yellow case in default meter policy Bing Zhao
2021-07-21  8:54   ` [dpdk-dev] [PATCH v3 2/7] net/mlx5: enable meter bucket overflow for yellow color Bing Zhao
2021-07-21  8:54   ` [dpdk-dev] [PATCH v3 3/7] net/mlx5: added support for yellow policy rules Bing Zhao
2021-07-21  8:54   ` [dpdk-dev] [PATCH v3 4/7] net/mlx5: split policies handling of colors Bing Zhao
2021-07-21  8:54   ` [dpdk-dev] [PATCH v3 5/7] net/mlx5: support yellow in meter policy validation Bing Zhao
2021-07-21  8:54   ` [dpdk-dev] [PATCH v3 6/7] net/mlx5: check consistency of meter policy and profile Bing Zhao
2021-07-21  8:54   ` [dpdk-dev] [PATCH v3 7/7] net/mlx5: add meter support for trTCM profiles Bing Zhao
2021-07-22 11:28   ` [dpdk-dev] [PATCH v3 0/7] support yellow color policy in mlx5 Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210705155756.21443-2-bingz@nvidia.com \
    --to=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).