Skip to contentSkip to conversation

net/mlx5: support meter policy operations

PATCH Superseded Li Zhang 2 participants 42 messages Apr 1, 2021 – Apr 27, 2021 Network drivers

lore
Share & tools
lore

Li Zhang

author
#0 lore raw

cover net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=15998 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=15998

Depends-on: series=16037 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16037

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 doc/guides/nics/mlx5.rst           |   12 +
 drivers/net/mlx5/linux/mlx5_os.c   |   13 +-
 drivers/net/mlx5/mlx5.c            |   76 +-
 drivers/net/mlx5/mlx5.h            |  197 ++-
 drivers/net/mlx5/mlx5_flow.c       |  614 +++++++++-
 drivers/net/mlx5/mlx5_flow.h       |  120 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1842 ++++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c |  738 ++++++++++-
 9 files changed, 3288 insertions(+), 334 deletions(-)
Signature · 1 line
2.27.0
author
#1 lore raw

PATCH 1/4 net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

---
 drivers/net/mlx5/linux/mlx5_os.c   |    2 +-
 drivers/net/mlx5/mlx5.c            |   76 +-
 drivers/net/mlx5/mlx5.h            |  145 ++-
 drivers/net/mlx5/mlx5_flow.c       |  169 +++-
 drivers/net/mlx5/mlx5_flow.h       |   69 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1374 +++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow_meter.c |  449 ++++++++-
 8 files changed, 2176 insertions(+), 118 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +1 -1
index 772feff598..859b9098dc 100644
@@ -1246,7 +1246,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			log_obj_size <=
 			config->hca_attr.qos.log_meter_aso_max_alloc) {
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv);
+				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
 				if (err) {
 					err = -err;
 					goto error;
drivers/net/mlx5/mlx5.c +45 -31

104 lines not on this page · raw message

drivers/net/mlx5/mlx5.h +140 -5

190 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +166 -3

187 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +59 -10

106 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_aso.c +5 -5
index 4d13743ecc..93fe08779e 100644
@@ -312,11 +312,11 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
 		mlx5_aso_age_init_sq(&sh->aso_age_mng->aso_sq);
 		break;
 	case ASO_OPC_MOD_POLICER:
-		if (mlx5_aso_sq_create(sh->ctx,&sh->mtrmng->sq, 0,
+		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->pools_mng.sq, 0,
 				  sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC,
 				  sh->sq_ts_format))
 			return -1;
-		mlx5_aso_mtr_init_sq(&sh->mtrmng->sq);
+		mlx5_aso_mtr_init_sq(&sh->mtrmng->pools_mng.sq);
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -343,7 +343,7 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,
 		sq = &sh->aso_age_mng->aso_sq;
 		break;
 	case ASO_OPC_MOD_POLICER:
-		sq = &sh->mtrmng->sq;
+		sq = &sh->mtrmng->pools_mng.sq;
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -799,7 +799,7 @@ int
 mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_wqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	do {
@@ -831,7 +831,7 @@ int
 mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_cqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	if (__atomic_load_n(&mtr->state, __ATOMIC_RELAXED) ==
drivers/net/mlx5/mlx5_flow_dv.c +1340 -34

1,489 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +420 -29

521 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#2 lore raw

PATCH 2/4 net/mlx5: support meter creation with policy

In reply to Li Zhang

Make meter creation with policy to
support actions per color.

The following cases to be considered:
1.Add entry match with meter_id in global drop table. 2.For non-termination policy (policy id 0),
add jump rule to suffix table for green and jump rule to drop table for red.
3.Allocate counter per meter for drop table. 4.Allocate meter resource per domain per color. 5.It can work with ASO meter and legacy meter both.

---
 doc/guides/nics/mlx5.rst           |  12 +
 drivers/net/mlx5/linux/mlx5_os.c   |  13 +-
 drivers/net/mlx5/mlx5.h            |  60 ++---
 drivers/net/mlx5/mlx5_flow.c       |  26 +-
 drivers/net/mlx5/mlx5_flow.h       |  32 +--
 drivers/net/mlx5/mlx5_flow_dv.c    | 368 ++++++++++++++++++++---------
 drivers/net/mlx5/mlx5_flow_meter.c | 345 +++++++++++++++++++++++----
 7 files changed, 626 insertions(+), 230 deletions(-)
doc/guides/nics/mlx5.rst +12 -0
index fa63e62a5d..6e9a68baf5 100644
@@ -106,6 +106,7 @@ Features
 - E-Switch mirroring and modify.
 - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer
   flow group.
+- Flow metering, including meter policy API.
 
 Limitations
 -----------
@@ -403,6 +404,17 @@ Limitations
   - Green color is not supported with drop action.
   - Yellow detection is not supported.
   - Red color must be with drop action.
+  - Meter statistics are supported only for drop case.
+  - Meter yellow color detection is not supported.
+  - A meter action created with pre-defined policy must be the last action in the
+    flow except single case where the policy actions are
+    green: NULL or END,
+    yellow: NULL or END,
+    RED: DROP / END.
+  - The only supported meter policy actions:
+    green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
+    yellow: must be empty.
+    red: must be DROP.
 
 Statistics
 ----------
drivers/net/mlx5/linux/mlx5_os.c +7 -6
index 859b9098dc..9ef3e31bb3 100644
@@ -1244,13 +1244,14 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			if (log_obj_size >=
 			config->hca_attr.qos.log_meter_aso_granularity &&
 			log_obj_size <=
-			config->hca_attr.qos.log_meter_aso_max_alloc) {
+			config->hca_attr.qos.log_meter_aso_max_alloc)
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
-				if (err) {
-					err = -err;
-					goto error;
-				}
+		}
+		if (priv->mtr_en) {
+			err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
+			if (err) {
+				err = -err;
+				goto error;
 			}
 		}
 #endif
drivers/net/mlx5/mlx5.h +17 -43

97 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +13 -13
index 1ca4ea741c..e76db6ffb7 100644
@@ -4506,14 +4506,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 				"Failed to allocate meter flow id.");
 	flow_id_bits = MLX5_REG_BITS - __builtin_clz(tag_id - 1);
 	flow_id_bits = flow_id_bits ? flow_id_bits : 1;
-	if ((flow_id_bits + priv->max_mtr_bits) > mtr_reg_bits) {
+	if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) > mtr_reg_bits) {
 		mlx5_ipool_free(fm->flow_ipool, tag_id);
 		return rte_flow_error_set(error, EINVAL,
 				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 				"Meter flow id exceeds max limit.");
 	}
-	if (flow_id_bits > priv->max_mtr_flow_bits)
-		priv->max_mtr_flow_bits = flow_id_bits;
+	if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
+		priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
@@ -6785,15 +6785,18 @@ mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  *
  * @return
- *   Pointer to table set on success, NULL otherwise.
+ *   0 on success, -1 otherwise.
  */
-struct mlx5_meter_domains_infos *
-mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
+int
+mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			struct mlx5_flow_meter_info *fm,
+			uint32_t mtr_idx,
+			uint8_t domain_bitmap)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->create_mtr_tbls(dev);
+	return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
 }
 
 /**
@@ -6803,18 +6806,15 @@ mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  * @param[in] tbl
  *   Pointer to the meter table set.
- *
- * @return
- *   0 on success.
  */
-int
+void
 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			   struct mlx5_meter_domains_infos *tbls)
+			   struct mlx5_flow_meter_info *fm)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->destroy_mtr_tbls(dev, tbls);
+	fops->destroy_mtr_tbls(dev, fm);
 }
 
 /**
drivers/net/mlx5/mlx5_flow.h +18 -14
index 5d13053f21..b630cfd661 100644
@@ -222,16 +222,17 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37)
 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)
 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)
+#define MLX5_FLOW_ACTION_METER_WITE_TERMINATED_POLICY (1ull << 40)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
 	 MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
-	 MLX5_FLOW_ACTION_DEFAULT_MISS)
+	 MLX5_FLOW_ACTION_DEFAULT_MISS | \
+	 MLX5_FLOW_ACTION_METER_WITE_TERMINATED_POLICY)
 
 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
-	 MLX5_FLOW_ACTION_JUMP)
-
+	 MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITE_TERMINATED_POLICY)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
 				      MLX5_FLOW_ACTION_SET_IPV4_DST | \
@@ -831,9 +832,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
-	uint32_t meter_id;
-	/**< Meter id. */
-	uint32_t idx; /* Index to meter object. */
+	uint32_t idx;
+	/* Index to meter object. */
 };
 
 #define MLX5_MAX_TUNNELS 256
@@ -1068,10 +1068,12 @@ typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
 				 const struct rte_flow_action *actions,
 				 void *data,
 				 struct rte_flow_error *error);
-typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
-					    (struct rte_eth_dev *dev);
-typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
-					struct mlx5_meter_domains_infos *tbls);
+typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
+					struct mlx5_flow_meter_info *fm,
+					uint32_t mtr_idx,
+					uint8_t domain_bitmap);
+typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1387,10 +1389,12 @@ int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
 				  uint16_t ether_type,
 				  const struct rte_flow_item_ecpri *acc_mask,
 				  struct rte_flow_error *error);
-struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
-					(struct rte_eth_dev *dev);
-int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			       struct mlx5_meter_domains_infos *tbl);
+int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm,
+				uint32_t mtr_idx,
+				uint8_t domain_bitmap);
+void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
+			       struct mlx5_flow_meter_info *fm);
 int mlx5_flow_meter_flush(struct rte_eth_dev *dev,
 			  struct rte_mtr_error *error);
 void flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_dv.c +254 -114

464 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +305 -40

460 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#3 lore raw

PATCH 3/4 net/mlx5: prepare sub-policy for a flow with meter

In reply to Li Zhang

When a flow with RSS action, the MLX5 PMD splitted the flow into several sub flow according to the flow RSS hashfield value, each sub flow requested the different RSS TIR.

The new meter introduces the policy, for the meter flow with RSS in the policy action, each RSS TIR in meter policy maintains own sub-policy table resource.

This patch adds the function that find the correct policy table resource according the RSS sub policy id.

---
 drivers/net/mlx5/mlx5_flow.h    |  10 +++
 drivers/net/mlx5/mlx5_flow_dv.c | 136 ++++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+)
drivers/net/mlx5/mlx5_flow.h +10 -0
index b630cfd661..fc9622b498 100644
@@ -1074,6 +1074,11 @@ typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
 					uint8_t domain_bitmap);
 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
 				struct mlx5_flow_meter_info *fm);
+typedef struct mlx5_flow_meter_sub_policy *
+	(*mlx5_flow_meter_sub_policy_prepare_t)
+		(struct rte_eth_dev *dev,
+		uint32_t policy_id,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1165,6 +1170,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_destroy_policy_rules_t destroy_policy_rules;
 	mlx5_flow_create_def_policy_t create_def_policy;
 	mlx5_flow_destroy_def_policy_t destroy_def_policy;
+	mlx5_flow_meter_sub_policy_prepare_t meter_sub_policy_prepare;
 	mlx5_flow_counter_alloc_t counter_alloc;
 	mlx5_flow_counter_free_t counter_free;
 	mlx5_flow_counter_query_t counter_query;
@@ -1395,6 +1401,10 @@ int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
 				uint8_t domain_bitmap);
 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_flow_meter_info *fm);
+struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_prepare
+		(struct rte_eth_dev *dev,
+		uint32_t policy_id,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 int mlx5_flow_meter_flush(struct rte_eth_dev *dev,
 			  struct rte_mtr_error *error);
 void flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_dv.c +136 -0

148 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#4 lore raw

PATCH 4/4 net/mlx5: connect meter policy to created flows

In reply to Li Zhang

From: Shun Hao <[email protected]>

Currently ASO meter must be followed by policy table, so this adds the support that connecting meter and policy table.

There are several cases to be considered:
1. For non-termination policy, connect meter to the default policy table.
2. For non-RSS termination policy case, simply get the policy table id and connect meter to it.
3. For RSS termination policy case, need to split the flow due to RSS info in policy, and translate each sub-flow using that RSS, then create the sub policy table to be connected.
4. In termination policy case, if there's no actions to modify the packet before meter, no need to use set_tag to save meter id in register. Only add a new flow in drop table using the same match criteria as suf-flow, to save cache miss.

---
 drivers/net/mlx5/mlx5_flow.c    | 425 ++++++++++++++++++++++++++++----
 drivers/net/mlx5/mlx5_flow.h    |   9 +
 drivers/net/mlx5/mlx5_flow_dv.c |  24 +-
 3 files changed, 406 insertions(+), 52 deletions(-)
drivers/net/mlx5/mlx5_flow.c +375 -50
index e76db6ffb7..d97233c309 100644
@@ -3359,18 +3359,52 @@ flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
 	fops->destroy(dev, flow);
 }
 
+/**
+ * Flow driver find RSS policy tbl API. This abstracts calling driver
+ * specific functions. Parent flow (rte_flow) should have driver
+ * type (drv_type). It will find the RSS policy table that has the rss_desc.
+ *
+ * @param[in] dev
+ *   Pointer to Ethernet device.
+ * @param[in, out] flow
+ *   Pointer to flow structure.
+ * @param[in] policy_id
+ *   The policy id of a meter.
+ * @param[in] rss_desc
+ *   Pointer to rss_desc
+ */
+static struct mlx5_flow_meter_sub_policy *
+flow_drv_meter_sub_policy_prepare(struct rte_eth_dev *dev,
+		struct rte_flow *flow,
+		uint32_t policy_id,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
+{
+	const struct mlx5_flow_driver_ops *fops;
+	enum mlx5_flow_drv_type type = flow->drv_type;
+
+	MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
+	fops = flow_get_drv_ops(type);
+	return fops->meter_sub_policy_prepare(dev, policy_id, rss_desc);
+}
+
 /**
  * Get RSS action from the action list.
  *
+ * @param[in] dev
+ *   Pointer to Ethernet device.
  * @param[in] actions
  *   Pointer to the list of actions.
+ * @param[in] flow
+ *   Parent flow structure pointer.
  *
  * @return
  *   Pointer to the RSS action if exist, else return NULL.
  */
 static const struct rte_flow_action_rss*
-flow_get_rss_action(const struct rte_flow_action actions[])
+flow_get_rss_action(struct rte_eth_dev *dev,
+		    const struct rte_flow_action actions[])
 {
+	struct mlx5_priv *priv = dev->data->dev_private;
 	const struct rte_flow_action_rss *rss = NULL;
 
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
@@ -3388,6 +3422,23 @@ flow_get_rss_action(const struct rte_flow_action actions[])
 					rss = act->conf;
 			break;
 		}
+		case RTE_FLOW_ACTION_TYPE_METER:
+		{
+			uint32_t mtr_idx;
+			struct mlx5_flow_meter_info *fm;
+			struct mlx5_flow_meter_policy *policy;
+			const struct rte_flow_action_meter *mtr = actions->conf;
+
+			fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
+			if (fm) {
+				policy = mlx5_flow_meter_policy_find(dev,
+						fm->policy_id, NULL);
+				if (policy && policy->is_rss)
+					rss =
+				policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
+			}
+			break;
+		}
 		default:
 			break;
 		}
@@ -3686,6 +3737,55 @@ flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
 	return actions_n + 1;
 }
 
+/**
+ * Check if the action will change packet.
+ *
+ * @param[in] type
+ *   action type.
+ *
+ * @return
+ *   true if action will change packet, false otherwise.
+ */
+static bool flow_check_modify_action_type(enum rte_flow_action_type type)
+{
+	switch (type) {
+	case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+	case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
+	case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
+	case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+	case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+	case RTE_FLOW_ACTION_TYPE_SET_TTL:
+	case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
+	case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
+	case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
+	case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
+	case RTE_FLOW_ACTION_TYPE_FLAG:
+	case RTE_FLOW_ACTION_TYPE_MARK:
+	case RTE_FLOW_ACTION_TYPE_SET_META:
+	case RTE_FLOW_ACTION_TYPE_SET_TAG:
+	case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
+	case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
+	case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
+	case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
+	case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+	case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
+	case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
+	case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
+	case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
+	case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
+	case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
+		return true;
+	default:
+		return false;
+	}
+}
+
 /**
  * Check meter action from the action list.
  *
@@ -3693,6 +3793,8 @@ flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
  *   Pointer to the list of actions.
  * @param[out] has_mtr
  *   Pointer to the meter exist flag.
+ * @param[out] has_modify
+ *   Pointer to the flag showing there's packet change action.
  * @param[out] meter_id
  *   Pointer to the meter id.
  *
@@ -3701,8 +3803,7 @@ flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
  */
 static int
 flow_check_meter_action(const struct rte_flow_action actions[],
-			bool *has_mtr,
-			uint32_t *meter_id)
+			bool *has_mtr, bool *has_modify, uint32_t *meter_id)
 {
 	const struct rte_flow_action_meter *mtr = NULL;
 	int actions_n = 0;
@@ -3719,6 +3820,9 @@ flow_check_meter_action(const struct rte_flow_action actions[],
 		default:
 			break;
 		}
+		if (!*has_mtr)
+			*has_modify |=
+				flow_check_modify_action_type(actions->type);
 		actions_n++;
 	}
 	/* Count RTE_FLOW_ACTION_TYPE_END. */
@@ -4361,6 +4465,112 @@ flow_create_split_inner(struct rte_eth_dev *dev,
 	return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
 }
 
+/**
+ * Get the table id of meter policy table.
+ *
+ * @param[in] dev
+ *   Pointer to Ethernet device.
+ * @param[in] flow
+ *   Parent flow structure pointer.
+ * @param[in] policy_id;
+ *   Meter Policy id.
+ * @param[in] attr
+ *   Flow rule attributes.
+ * @param[in] items
+ *   Pattern specification (list terminated by the END pattern item).
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *
+ * @return
+ *   The table id, 0 otherwise and rte_errno is set.
+ */
+static uint32_t
+get_sub_policy_tbl_id(struct rte_eth_dev *dev,
+		      struct rte_flow *flow,
+		      uint32_t policy_id,
+		      const struct rte_flow_attr *attr,
+		      const struct rte_flow_item items[],
+		      struct rte_flow_error *error)
+{
+	uint32_t policy_tbl_id = 0;
+	struct mlx5_flow_meter_policy *policy;
+
+	policy = mlx5_flow_meter_policy_find(dev, policy_id, NULL);
+	if (!policy) {
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				   "Failed to find Meter Policy.");
+		goto exit;
+	}
+	if (policy->is_rss) {
+		struct mlx5_flow_workspace *wks =
+				mlx5_flow_get_thread_workspace();
+		struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
+		struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
+		uint32_t i;
+
+		MLX5_ASSERT(wks);
+		/** This is a tmp dev_flow,
+		 *  no need to register any matcher for it in translate.
+		 */
+		wks->skip_matcher_reg = 1;
+		for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
+			struct mlx5_flow dev_flow = {0};
+			struct mlx5_flow_handle dev_handle = {{0}};
+			const void *rss_act = policy->act_cnt[i].rss->conf;
+			struct rte_flow_action rss_actions[2] = {
+				[0] = {
+					.type = RTE_FLOW_ACTION_TYPE_RSS,
+					.conf = rss_act
+				},
+				[1] = {
+					.type = RTE_FLOW_ACTION_TYPE_END,
+					.conf = NULL
+				}
+			};
+
+			dev_flow.handle = &dev_handle;
+			dev_flow.ingress = attr->ingress;
+			dev_flow.flow = flow;
+			dev_flow.external = 0;
+#ifdef HAVE_IBV_FLOW_DV_SUPPORT
+			dev_flow.dv.transfer = attr->transfer;
+#endif
+			/* Translate RSS action to get rss hash fields. */
+			if (flow_drv_translate(dev, &dev_flow, attr,
+						items, rss_actions, error))
+				goto exit;
+			rss_desc_v[i] = wks->rss_desc;
+			rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
+			rss_desc_v[i].hash_fields = dev_flow.hash_fields;
+			rss_desc_v[i].queue_num = rss_desc_v[i].hash_fields ?
+						  rss_desc_v[i].queue_num : 1;
+			rss_desc[i] = &rss_desc_v[i];
+		}
+		sub_policy = flow_drv_meter_sub_policy_prepare(dev,
+						flow, policy_id, rss_desc);
+		if (!sub_policy) {
+			rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				"Failed to get meter RSS policy table.");
+			goto exit;
+		}
+		policy_tbl_id = sub_policy->idx;
+	} else {
+		enum mlx5_meter_domain mtr_domain =
+			attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
+				attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
+					MLX5_MTR_DOMAIN_INGRESS;
+		policy_tbl_id =
+			policy->sub_policys[mtr_domain][0]->idx;
+	}
+exit:
+	return policy_tbl_id;
+}
+
+#define MLX5_MTR_PRE_TAG_NUM 2
+
 /**
  * Split the meter flow.
  *
@@ -4391,13 +4601,15 @@ flow_create_split_inner(struct rte_eth_dev *dev,
  *   Suffix flow actions.
  * @param[out] actions_pre
  *   Prefix flow actions.
+ * @param[out] mtr_flow_id
+ *   Pointer to meter flow id.
  * @param[out] error
  *   Perform verbose error reporting if not NULL.
  *
  * @return
- *   The flow id, 0 otherwise and rte_errno is set.
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-static uint32_t
+static int
 flow_meter_split_prep(struct rte_eth_dev *dev,
 		      struct rte_flow *flow,
 		      struct mlx5_flow_meter_info *fm,
@@ -4407,6 +4619,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 		      const struct rte_flow_action actions[],
 		      struct rte_flow_action actions_sfx[],
 		      struct rte_flow_action actions_pre[],
+		      uint32_t *mtr_flow_id,
 		      struct rte_flow_error *error)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
@@ -4420,7 +4633,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	uint32_t tag_id = 0;
 	bool copy_vlan = false;
 	struct rte_flow_action *hw_mtr_action;
-	struct rte_flow_action_jump *jump_data;
+	struct mlx5_rte_flow_item_mtr_jump *jump_data;
 	struct rte_flow_action *action_pre_head = NULL;
 	bool mtr_first = priv->sh->meter_aso_en &&
 			 (attr->egress ||
@@ -4429,8 +4642,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	uint8_t mtr_reg_bits = priv->mtr_reg_share ?
 				MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
 	uint8_t flow_id_bits = 0;
-	int shift;
-	uint32_t flow_id_val = 0;
 
 	/* For ASO meter, meter must be before tag in TX direction. */
 	if (mtr_first) {
@@ -4474,7 +4685,9 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 			break;
 		}
 		if (!action_cur)
-			action_cur = actions_sfx++;
+			action_cur =
+				(fm->policy_id != RTE_MTR_DEFAULT_POLICY_ID) ?
+					actions_pre++ : actions_sfx++;
 		memcpy(action_cur, actions, sizeof(struct rte_flow_action));
 	}
 	/* Add end action to the actions. */
@@ -4483,37 +4696,56 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 		/** For ASO meter, need to add an extra jump action explicitly,
 		 *  to jump from meter to policer table.
 		 */
+		uint32_t sub_policy_tbl_id = 0;
+
+		if (fm->policy_id != RTE_MTR_DEFAULT_POLICY_ID) {
+			sub_policy_tbl_id =
+				get_sub_policy_tbl_id(dev, flow, fm->policy_id,
+						      attr, items, error);
+			if (!sub_policy_tbl_id)
+				return -rte_errno;
+		}
 		hw_mtr_action = actions_pre;
-		hw_mtr_action->type = RTE_FLOW_ACTION_TYPE_JUMP;
+		hw_mtr_action->type = (enum rte_flow_action_type)
+				      MLX5_RTE_FLOW_ACTION_TYPE_MTR_JUMP;
 		actions_pre++;
 		actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
 		actions_pre++;
-		jump_data = (struct rte_flow_action_jump *)actions_pre;
-		jump_data->group = attr->transfer ?
+		jump_data = (struct mlx5_rte_flow_item_mtr_jump *)actions_pre;
+		jump_data->table_group.group = attr->transfer ?
 				(MLX5_FLOW_TABLE_LEVEL_POLICY - 1) :
 				 MLX5_FLOW_TABLE_LEVEL_POLICY;
+		jump_data->table_id = sub_policy_tbl_id;
 		hw_mtr_action->conf = jump_data;
 		actions_pre = (struct rte_flow_action *)(jump_data + 1);
 	} else {
 		actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
 		actions_pre++;
 	}
-	/* Generate meter flow_id only if support multiple flows per meter. */
-	mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
-	if (!tag_id)
-		return rte_flow_error_set(error, ENOMEM,
-				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-				"Failed to allocate meter flow id.");
-	flow_id_bits = MLX5_REG_BITS - __builtin_clz(tag_id - 1);
-	flow_id_bits = flow_id_bits ? flow_id_bits : 1;
-	if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) > mtr_reg_bits) {
-		mlx5_ipool_free(fm->flow_ipool, tag_id);
-		return rte_flow_error_set(error, EINVAL,
-				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-				"Meter flow id exceeds max limit.");
+	MLX5_ASSERT(tag_action);
+	if (!mtr_flow_id) {
+		tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
+		goto exit;
+	}
+	/* Only Non-termination Policy Meter creates mtr flow id. */
+	if (fm->policy_id == RTE_MTR_DEFAULT_POLICY_ID) {
+		mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
+		if (!tag_id)
+			return rte_flow_error_set(error, ENOMEM,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					"Failed to allocate meter flow id.");
+		flow_id_bits = MLX5_REG_BITS - __builtin_clz(tag_id - 1);
+		flow_id_bits = flow_id_bits ? flow_id_bits : 1;
+		if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
+		    mtr_reg_bits) {
+			mlx5_ipool_free(fm->flow_ipool, tag_id);
+			return rte_flow_error_set(error, EINVAL,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					"Meter flow id exceeds max limit.");
+		}
+		if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
+			priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	}
-	if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
-		priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
@@ -4543,7 +4775,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
 	sfx_items++;
 	/* Build tag actions and items for meter_id/meter flow_id. */
-	assert(tag_action);
 	set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
 	tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
 	tag_item_mask = tag_item_spec + 1;
@@ -4554,14 +4785,19 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 		.length = mtr_reg_bits,
 		.data = flow->meter,
 	};
-	/*
-	 * The color Reg bits used by flow_id are growing from
-	 * msb to lsb, so must do bit reverse for flow_id val in RegC.
-	 */
-	for (shift = 0; shift < flow_id_bits; shift++)
-		flow_id_val = (flow_id_val << 1) |
-			      (((tag_id - 1) >> shift) & 0x1);
-	set_tag->data |= flow_id_val << (mtr_reg_bits - flow_id_bits);
+	if (tag_id) {
+		int shift;
+		uint32_t flow_id_val = 0;
+
+		/*
+		 * The color Reg bits used by flow_id are growing from
+		 * msb to lsb, so must do bit reverse for flow_id val in RegC.
+		 */
+		for (shift = 0; shift < flow_id_bits; shift++)
+			flow_id_val = (flow_id_val << 1) |
+					(((tag_id - 1) >> shift) & 0x1);
+		set_tag->data |= flow_id_val << (mtr_reg_bits - flow_id_bits);
+	}
 	tag_item_spec->id = set_tag->id;
 	tag_item_spec->data = set_tag->data << mtr_id_offset;
 	tag_item_mask->data = UINT32_MAX << mtr_id_offset;
@@ -4573,7 +4809,10 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	tag_item->spec = tag_item_spec;
 	tag_item->last = NULL;
 	tag_item->mask = tag_item_mask;
-	return tag_id;
+exit:
+	if (mtr_flow_id)
+		*mtr_flow_id = tag_id;
+	return 0;
 }
 
 /**
@@ -5237,6 +5476,57 @@ flow_create_split_metadata(struct rte_eth_dev *dev,
 	return ret;
 }
 
+/**
+ * Create the Termination Policy Meter drop flow.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param[in] flow
+ *   Parent flow structure pointer.
+ * @param[in] attr
+ *   Flow rule attributes.
+ * @param[in] items
+ *   Pattern specification (list terminated by the END pattern item).
+ * @param[in] flow_split_info
+ *   Pointer to flow split info structure.
+ * @param[in] fm
+ *   Pointer to flow meter structure.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ * @return
+ *   0 on success, negative value otherwise
+ */
+static uint32_t
+flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
+			struct rte_flow *flow,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_item items[],
+			struct mlx5_flow_split_info *flow_split_info,
+			struct mlx5_flow_meter_info *fm,
+			struct rte_flow_error *error)
+{
+	struct mlx5_flow *dev_flow = NULL;
+	struct rte_flow_attr drop_attr = *attr;
+	struct rte_flow_action drop_actions[3] = {{0}};
+	struct mlx5_flow_split_info drop_split_info = *flow_split_info;
+
+	MLX5_ASSERT(fm->drop_cnt);
+	drop_actions[0].type =
+		MLX5_RTE_FLOW_ACTION_TYPE_MTR_COUNT;
+	drop_actions[0].conf =
+		(void *)(uintptr_t)fm->drop_cnt;
+	drop_actions[1].type =
+		RTE_FLOW_ACTION_TYPE_DROP;
+	drop_actions[2].type =
+		RTE_FLOW_ACTION_TYPE_END;
+	drop_split_info.external = false;
+	drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
+	drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER_DROP;
+	return flow_create_split_inner(dev, flow, &dev_flow,
+				&drop_attr, items, drop_actions,
+				&drop_split_info, error);
+}
+
 /**
  * The splitting for meter feature.
  *
@@ -5281,10 +5571,13 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 	struct mlx5_flow *dev_flow = NULL;
 	struct rte_flow_attr sfx_attr = *attr;
 	struct mlx5_flow_meter_info *fm = NULL;
+	uint8_t skip_scale_restore;
 	bool has_mtr = false;
-	uint32_t meter_id;
+	bool has_modify = false;
+	bool set_mtr_reg = true;
+	uint32_t meter_id = 0;
 	uint32_t mtr_idx = 0;
-	uint32_t mtr_tag_id = 0;
+	uint32_t mtr_flow_id = 0;
 	size_t act_size;
 	size_t item_size;
 	int actions_n = 0;
@@ -5292,7 +5585,7 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 
 	if (priv->mtr_en)
 		actions_n = flow_check_meter_action(actions, &has_mtr,
-						    &meter_id);
+						    &has_modify, &meter_id);
 	if (has_mtr) {
 		if (flow->meter) {
 			fm = flow_dv_meter_find_by_idx(priv, flow->meter);
@@ -5312,7 +5605,18 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 				return -rte_errno;
 			flow->meter = mtr_idx;
 		}
+		MLX5_ASSERT(wks);
 		wks->fm = fm;
+		/*
+		 * If it's Termination Policy Meter, and
+		 * 1. There's no action in flow to change
+		 *    packet (modify/encap/decap etc.), OR
+		 * 2. No drop count needed for this meter.
+		 * no need to use regC to save meter id anymore.
+		 */
+		if (fm->policy_id != RTE_MTR_DEFAULT_POLICY_ID &&
+		    (!has_modify || !fm->drop_cnt))
+			set_mtr_reg = false;
 		/* Prefix actions: meter, decap, encap, tag, jump, end. */
 		act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
 			   sizeof(struct mlx5_rte_flow_action_set_tag);
@@ -5329,27 +5633,48 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 						  "meter flow");
 		sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
 			     act_size);
-		pre_actions = sfx_actions + actions_n;
-		mtr_tag_id = flow_meter_split_prep(dev, flow, fm, &sfx_attr,
-						   items, sfx_items, actions,
-						   sfx_actions, pre_actions,
-						   error);
-		if (!mtr_tag_id) {
+		/* There's no suffix flow for Termination Policy Meter. */
+		if (fm->policy_id != RTE_MTR_DEFAULT_POLICY_ID)
+			pre_actions = sfx_actions + 1;
+		else
+			pre_actions = sfx_actions + actions_n;
+		ret = flow_meter_split_prep(dev, flow, fm, &sfx_attr,
+					    items, sfx_items, actions,
+					    sfx_actions, pre_actions,
+					    (set_mtr_reg ? &mtr_flow_id : NULL),
+					    error);
+		if (ret) {
 			ret = -rte_errno;
 			goto exit;
 		}
 		/* Add the prefix subflow. */
 		flow_split_info->prefix_mark = 0;
+		skip_scale_restore = flow_split_info->skip_scale;
+		flow_split_info->skip_scale |=
+			1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
 		ret = flow_create_split_inner(dev, flow, &dev_flow,
 					      attr, items, pre_actions,
 					      flow_split_info, error);
 		if (ret) {
-			mlx5_ipool_free(fm->flow_ipool, mtr_tag_id);
+			if (mtr_flow_id)
+				mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
 			ret = -rte_errno;
 			goto exit;
 		}
-		dev_flow->handle->split_flow_id = mtr_tag_id;
-		dev_flow->handle->is_meter_flow_id = 1;
+		flow_split_info->skip_scale = skip_scale_restore;
+		if (mtr_flow_id) {
+			dev_flow->handle->split_flow_id = mtr_flow_id;
+			dev_flow->handle->is_meter_flow_id = 1;
+		}
+		if (fm->policy_id != RTE_MTR_DEFAULT_POLICY_ID) {
+			if (!set_mtr_reg && fm->drop_cnt)
+				ret =
+			flow_meter_create_drop_flow_with_org_pattern(dev, flow,
+							&sfx_attr, items,
+							flow_split_info,
+							fm, error);
+			goto exit;
+		}
 		/* Setting the sfx group atrr. */
 		sfx_attr.group = sfx_attr.transfer ?
 				(MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
@@ -5743,7 +6068,7 @@ flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
 	memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
 	/* RSS Action only works on NIC RX domain */
 	if (attr->ingress && !attr->transfer)
-		rss = flow_get_rss_action(p_actions_rx);
+		rss = flow_get_rss_action(dev, p_actions_rx);
 	if (rss) {
 		if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
 			return 0;
drivers/net/mlx5/mlx5_flow.h +9 -0
index fc9622b498..20bb8b584f 100644
@@ -37,6 +37,8 @@ enum mlx5_rte_flow_action_type {
 	MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
 	MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET,
 	MLX5_RTE_FLOW_ACTION_TYPE_AGE,
+	MLX5_RTE_FLOW_ACTION_TYPE_MTR_JUMP,
+	MLX5_RTE_FLOW_ACTION_TYPE_MTR_COUNT,
 };
 
 #define MLX5_SHARED_ACTION_TYPE_OFFSET 30
@@ -70,6 +72,11 @@ struct mlx5_rte_flow_item_tx_queue {
 	uint32_t queue;
 };
 
+struct mlx5_rte_flow_item_mtr_jump {
+	struct rte_flow_action_jump table_group;
+	uint32_t table_id;
+};
+
 /* Feature name to allocate metadata register. */
 enum mlx5_feature_name {
 	MLX5_HAIRPIN_RX,
@@ -1029,6 +1036,8 @@ struct mlx5_flow_workspace {
 	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
+	uint32_t skip_matcher_reg:1;
+	/* Indicates if need to skip matcher register in translate. */
 };
 
 struct mlx5_flow_split_info {
drivers/net/mlx5/mlx5_flow_dv.c +22 -2
index d93097b755..b7b2c5a3d2 100644
@@ -7409,6 +7409,7 @@ flow_dv_prepare(struct rte_eth_dev *dev,
 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
 
 	MLX5_ASSERT(wks);
+	wks->skip_matcher_reg = 0;
 	/* In case of corrupting the memory. */
 	if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
 		rte_flow_error_set(error, ENOSPC,
@@ -11252,6 +11253,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 		int action_type = actions->type;
 		const struct rte_flow_action *found_action = NULL;
 		uint32_t jump_group = 0;
+		uint32_t jump_table_id = 0;
+		struct mlx5_flow_counter *cnt;
 
 		if (!mlx5_flow_os_action_supported(action_type))
 			return rte_flow_error_set(error, ENOTSUP,
@@ -11432,6 +11435,15 @@ flow_dv_translate(struct rte_eth_dev *dev,
 				age = action->conf;
 			action_flags |= MLX5_FLOW_ACTION_COUNT;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_MTR_COUNT:
+			cnt = flow_dv_counter_get_by_idx(dev,
+				(uint32_t)(uintptr_t)action->conf, NULL);
+			if (!cnt)
+				return rte_flow_error_set(error, rte_errno,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					NULL, "Failed to get meter counter.");
+			dev_flow->dv.actions[actions_n++] = cnt->action;
+			break;
 		case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
 			dev_flow->dv.actions[actions_n++] =
 						priv->sh->pop_vlan_action;
@@ -11536,6 +11548,11 @@ flow_dv_translate(struct rte_eth_dev *dev,
 			/* If decap is followed by encap, handle it at encap. */
 			action_flags |= MLX5_FLOW_ACTION_DECAP;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_MTR_JUMP:
+			jump_table_id =
+				((const struct mlx5_rte_flow_item_mtr_jump *)
+				 action->conf)->table_id;
+			/* Fall through */
 		case RTE_FLOW_ACTION_TYPE_JUMP:
 			jump_group = ((const struct rte_flow_action_jump *)
 							action->conf)->group;
@@ -11555,7 +11572,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
 						       attr->transfer,
 						       !!dev_flow->external,
 						       tunnel, jump_group, 0,
-						       0, error);
+						       jump_table_id, error);
 			if (!tbl)
 				return rte_flow_error_set
 						(error, errno,
@@ -12091,6 +12108,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 	}
 	dev_flow->dv.actions_n = actions_n;
 	dev_flow->act_flags = action_flags;
+	if (wks->skip_matcher_reg)
+		return 0;
 	/* Register matcher. */
 	matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
 				    matcher.mask.size);
@@ -12242,7 +12261,8 @@ flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
 		dv_h = &dh->dvh;
 		n = dv->actions_n;
 		if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
-			if (dv->transfer) {
+			if (dv->transfer || dev_flow->dv.group ==
+			    MLX5_FLOW_TABLE_LEVEL_METER_DROP) {
 				dv->actions[n++] = priv->sh->esw_drop_action;
 			} else {
 				MLX5_ASSERT(priv->drop_queue.hrxq);
Signature · 1 line
2.27.0
author
#5 lore raw

v2 cover net/mlx5: support meter policy operations

In reply to Li Zhang

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=16087 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16087

Depends-on: series=16082 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16082

V2: Add MLX5_MTR_DEFAULT_POLICY_ID in MLX5 PMD

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 drivers/net/mlx5/linux/mlx5_os.c   |   13 +-
 drivers/net/mlx5/mlx5.c            |   76 +-
 drivers/net/mlx5/mlx5.h            |  204 ++-
 drivers/net/mlx5/mlx5_flow.c       |  629 +++++++++-
 drivers/net/mlx5/mlx5_flow.h       |  123 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1862 ++++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c |  745 ++++++++++-
 8 files changed, 3328 insertions(+), 334 deletions(-)
Signature · 1 line
2.27.0
author
#6 lore raw

PATCH v2 1/4 net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

---
 drivers/net/mlx5/linux/mlx5_os.c   |    2 +-
 drivers/net/mlx5/mlx5.c            |   76 +-
 drivers/net/mlx5/mlx5.h            |  152 ++-
 drivers/net/mlx5/mlx5_flow.c       |  184 +++-
 drivers/net/mlx5/mlx5_flow.h       |   71 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1394 +++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow_meter.c |  456 ++++++++-
 8 files changed, 2227 insertions(+), 118 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +1 -1
index 772feff598..859b9098dc 100644
@@ -1246,7 +1246,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			log_obj_size <=
 			config->hca_attr.qos.log_meter_aso_max_alloc) {
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv);
+				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
 				if (err) {
 					err = -err;
 					goto error;
drivers/net/mlx5/mlx5.c +45 -31

106 lines not on this page · raw message

drivers/net/mlx5/mlx5.h +147 -5

197 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +181 -3

208 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +61 -10

116 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_aso.c +5 -5
index 9ba823f774..93fe08779e 100644
@@ -312,11 +312,11 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
 		mlx5_aso_age_init_sq(&sh->aso_age_mng->aso_sq);
 		break;
 	case ASO_OPC_MOD_POLICER:
-		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->sq, 0,
+		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->pools_mng.sq, 0,
 				  sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC,
 				  sh->sq_ts_format))
 			return -1;
-		mlx5_aso_mtr_init_sq(&sh->mtrmng->sq);
+		mlx5_aso_mtr_init_sq(&sh->mtrmng->pools_mng.sq);
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -343,7 +343,7 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,
 		sq = &sh->aso_age_mng->aso_sq;
 		break;
 	case ASO_OPC_MOD_POLICER:
-		sq = &sh->mtrmng->sq;
+		sq = &sh->mtrmng->pools_mng.sq;
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -799,7 +799,7 @@ int
 mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_wqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	do {
@@ -831,7 +831,7 @@ int
 mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_cqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	if (__atomic_load_n(&mtr->state, __ATOMIC_RELAXED) ==
drivers/net/mlx5/mlx5_flow_dv.c +1360 -34

1,511 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +427 -29

528 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#7 lore raw

PATCH v2 2/4 net/mlx5: support meter creation with policy

In reply to Li Zhang

Make meter creation with policy to
support actions per color.

The following cases to be considered:
1.Add entry match with meter_id in global drop table. 2.For non-termination policy (policy id 0),
add jump rule to suffix table for green and jump rule to drop table for red.
3.Allocate counter per meter for drop table. 4.Allocate meter resource per domain per color. 5.It can work with ASO meter and legacy meter both.

---
 drivers/net/mlx5/linux/mlx5_os.c   |  13 +-
 drivers/net/mlx5/mlx5.h            |  60 ++---
 drivers/net/mlx5/mlx5_flow.c       |  26 +-
 drivers/net/mlx5/mlx5_flow.h       |  32 +--
 drivers/net/mlx5/mlx5_flow_dv.c    | 368 ++++++++++++++++++++---------
 drivers/net/mlx5/mlx5_flow_meter.c | 345 +++++++++++++++++++++++----
 6 files changed, 614 insertions(+), 230 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +7 -6
index 859b9098dc..9ef3e31bb3 100644
@@ -1244,13 +1244,14 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			if (log_obj_size >=
 			config->hca_attr.qos.log_meter_aso_granularity &&
 			log_obj_size <=
-			config->hca_attr.qos.log_meter_aso_max_alloc) {
+			config->hca_attr.qos.log_meter_aso_max_alloc)
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
-				if (err) {
-					err = -err;
-					goto error;
-				}
+		}
+		if (priv->mtr_en) {
+			err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
+			if (err) {
+				err = -err;
+				goto error;
 			}
 		}
 #endif
drivers/net/mlx5/mlx5.h +17 -43

97 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +13 -13
index 15ae8b9528..b41bf6456d 100644
@@ -4506,14 +4506,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 				"Failed to allocate meter flow id.");
 	flow_id_bits = MLX5_REG_BITS - __builtin_clz(tag_id - 1);
 	flow_id_bits = flow_id_bits ? flow_id_bits : 1;
-	if ((flow_id_bits + priv->max_mtr_bits) > mtr_reg_bits) {
+	if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) > mtr_reg_bits) {
 		mlx5_ipool_free(fm->flow_ipool, tag_id);
 		return rte_flow_error_set(error, EINVAL,
 				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 				"Meter flow id exceeds max limit.");
 	}
-	if (flow_id_bits > priv->max_mtr_flow_bits)
-		priv->max_mtr_flow_bits = flow_id_bits;
+	if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
+		priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
@@ -6785,15 +6785,18 @@ mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  *
  * @return
- *   Pointer to table set on success, NULL otherwise.
+ *   0 on success, -1 otherwise.
  */
-struct mlx5_meter_domains_infos *
-mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
+int
+mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			struct mlx5_flow_meter_info *fm,
+			uint32_t mtr_idx,
+			uint8_t domain_bitmap)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->create_mtr_tbls(dev);
+	return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
 }
 
 /**
@@ -6803,18 +6806,15 @@ mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  * @param[in] tbl
  *   Pointer to the meter table set.
- *
- * @return
- *   0 on success.
  */
-int
+void
 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			   struct mlx5_meter_domains_infos *tbls)
+			   struct mlx5_flow_meter_info *fm)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->destroy_mtr_tbls(dev, tbls);
+	fops->destroy_mtr_tbls(dev, fm);
 }
 
 /**
drivers/net/mlx5/mlx5_flow.h +18 -14
index 97e766a6b1..5672df983e 100644
@@ -222,16 +222,17 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37)
 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)
 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)
+#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
 	 MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
-	 MLX5_FLOW_ACTION_DEFAULT_MISS)
+	 MLX5_FLOW_ACTION_DEFAULT_MISS | \
+	 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
-	 MLX5_FLOW_ACTION_JUMP)
-
+	 MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
 				      MLX5_FLOW_ACTION_SET_IPV4_DST | \
@@ -831,9 +832,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
-	uint32_t meter_id;
-	/**< Meter id. */
-	uint32_t idx; /* Index to meter object. */
+	uint32_t idx;
+	/* Index to meter object. */
 };
 
 #define MLX5_MAX_TUNNELS 256
@@ -1068,10 +1068,12 @@ typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
 				 const struct rte_flow_action *actions,
 				 void *data,
 				 struct rte_flow_error *error);
-typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
-					    (struct rte_eth_dev *dev);
-typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
-					struct mlx5_meter_domains_infos *tbls);
+typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
+					struct mlx5_flow_meter_info *fm,
+					uint32_t mtr_idx,
+					uint8_t domain_bitmap);
+typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
@@ -1389,10 +1391,12 @@ int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
 				  uint16_t ether_type,
 				  const struct rte_flow_item_ecpri *acc_mask,
 				  struct rte_flow_error *error);
-struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
-					(struct rte_eth_dev *dev);
-int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			       struct mlx5_meter_domains_infos *tbl);
+int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm,
+				uint32_t mtr_idx,
+				uint8_t domain_bitmap);
+void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
+			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
 int mlx5_flow_meter_flush(struct rte_eth_dev *dev,
 			  struct rte_mtr_error *error);
drivers/net/mlx5/mlx5_flow_dv.c +254 -114

464 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +305 -40

460 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#8 lore raw

PATCH v2 3/4 net/mlx5: prepare sub-policy for a flow with meter

In reply to Li Zhang

When a flow with RSS action, the MLX5 PMD split the flow into several sub flow according to the flow RSS hashfield value, each sub flow requested the different RSS TIR.

The new meter introduces the policy, for the meter flow with RSS in the policy action, each RSS TIR in meter policy maintains own sub-policy table resource.

This patch adds the function that find the correct policy table resource according the RSS sub policy id.

---
 drivers/net/mlx5/mlx5_flow.h    |  11 +++
 drivers/net/mlx5/mlx5_flow_dv.c | 136 ++++++++++++++++++++++++++++++++
 2 files changed, 147 insertions(+)
drivers/net/mlx5/mlx5_flow.h +11 -0
index 5672df983e..3024bd9b60 100644
@@ -1075,6 +1075,11 @@ typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
 				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
+typedef struct mlx5_flow_meter_sub_policy *
+	(*mlx5_flow_meter_sub_policy_prepare_t)
+		(struct rte_eth_dev *dev,
+		uint32_t policy_id,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1167,6 +1172,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_destroy_policy_rules_t destroy_policy_rules;
 	mlx5_flow_create_def_policy_t create_def_policy;
 	mlx5_flow_destroy_def_policy_t destroy_def_policy;
+	mlx5_flow_meter_sub_policy_prepare_t meter_sub_policy_prepare;
 	mlx5_flow_counter_alloc_t counter_alloc;
 	mlx5_flow_counter_free_t counter_free;
 	mlx5_flow_counter_query_t counter_query;
@@ -1398,6 +1404,11 @@ int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
+
+struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_prepare
+		(struct rte_eth_dev *dev,
+		uint32_t policy_id,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 int mlx5_flow_meter_flush(struct rte_eth_dev *dev,
 			  struct rte_mtr_error *error);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_dv.c +136 -0

148 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#9 lore raw

PATCH v2 4/4 net/mlx5: connect meter policy to created flows

In reply to Li Zhang

From: Shun Hao <[email protected]>

Currently ASO meter must be followed by policy table, so this adds the support that connecting meter and policy table.

There are several cases to be considered:
1. For non-termination policy, connect meter to the default policy table.
2. For non-RSS termination policy case, simply get the policy table id and connect meter to it.
3. For RSS termination policy case, need to split the flow due to RSS info in policy, and translate each sub-flow using that RSS, then create the sub policy table to be connected.
4. In termination policy case, if there's no actions to modify the packet before meter, no need to use set_tag to save meter id in register. Only add a new flow in drop table using the same match criteria as suf-flow, to save cache miss.

---
 drivers/net/mlx5/mlx5_flow.c    | 425 ++++++++++++++++++++++++++++----
 drivers/net/mlx5/mlx5_flow.h    |   9 +
 drivers/net/mlx5/mlx5_flow_dv.c |  24 +-
 3 files changed, 406 insertions(+), 52 deletions(-)
drivers/net/mlx5/mlx5_flow.c +375 -50
index b41bf6456d..56d0e480cb 100644
@@ -3359,18 +3359,52 @@ flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
 	fops->destroy(dev, flow);
 }
 
+/**
+ * Flow driver find RSS policy tbl API. This abstracts calling driver
+ * specific functions. Parent flow (rte_flow) should have driver
+ * type (drv_type). It will find the RSS policy table that has the rss_desc.
+ *
+ * @param[in] dev
+ *   Pointer to Ethernet device.
+ * @param[in, out] flow
+ *   Pointer to flow structure.
+ * @param[in] policy_id
+ *   The policy id of a meter.
+ * @param[in] rss_desc
+ *   Pointer to rss_desc
+ */
+static struct mlx5_flow_meter_sub_policy *
+flow_drv_meter_sub_policy_prepare(struct rte_eth_dev *dev,
+		struct rte_flow *flow,
+		uint32_t policy_id,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
+{
+	const struct mlx5_flow_driver_ops *fops;
+	enum mlx5_flow_drv_type type = flow->drv_type;
+
+	MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
+	fops = flow_get_drv_ops(type);
+	return fops->meter_sub_policy_prepare(dev, policy_id, rss_desc);
+}
+
 /**
  * Get RSS action from the action list.
  *
+ * @param[in] dev
+ *   Pointer to Ethernet device.
  * @param[in] actions
  *   Pointer to the list of actions.
+ * @param[in] flow
+ *   Parent flow structure pointer.
  *
  * @return
  *   Pointer to the RSS action if exist, else return NULL.
  */
 static const struct rte_flow_action_rss*
-flow_get_rss_action(const struct rte_flow_action actions[])
+flow_get_rss_action(struct rte_eth_dev *dev,
+		    const struct rte_flow_action actions[])
 {
+	struct mlx5_priv *priv = dev->data->dev_private;
 	const struct rte_flow_action_rss *rss = NULL;
 
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
@@ -3388,6 +3422,23 @@ flow_get_rss_action(const struct rte_flow_action actions[])
 					rss = act->conf;
 			break;
 		}
+		case RTE_FLOW_ACTION_TYPE_METER:
+		{
+			uint32_t mtr_idx;
+			struct mlx5_flow_meter_info *fm;
+			struct mlx5_flow_meter_policy *policy;
+			const struct rte_flow_action_meter *mtr = actions->conf;
+
+			fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
+			if (fm) {
+				policy = mlx5_flow_meter_policy_find(dev,
+						fm->policy_id, NULL);
+				if (policy && policy->is_rss)
+					rss =
+				policy->act_cnt[RTE_COLOR_GREEN].rss->conf;
+			}
+			break;
+		}
 		default:
 			break;
 		}
@@ -3686,6 +3737,55 @@ flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
 	return actions_n + 1;
 }
 
+/**
+ * Check if the action will change packet.
+ *
+ * @param[in] type
+ *   action type.
+ *
+ * @return
+ *   true if action will change packet, false otherwise.
+ */
+static bool flow_check_modify_action_type(enum rte_flow_action_type type)
+{
+	switch (type) {
+	case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+	case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
+	case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
+	case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+	case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+	case RTE_FLOW_ACTION_TYPE_SET_TTL:
+	case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
+	case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
+	case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
+	case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
+	case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
+	case RTE_FLOW_ACTION_TYPE_FLAG:
+	case RTE_FLOW_ACTION_TYPE_MARK:
+	case RTE_FLOW_ACTION_TYPE_SET_META:
+	case RTE_FLOW_ACTION_TYPE_SET_TAG:
+	case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
+	case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
+	case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
+	case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
+	case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+	case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
+	case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
+	case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
+	case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
+	case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
+	case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
+		return true;
+	default:
+		return false;
+	}
+}
+
 /**
  * Check meter action from the action list.
  *
@@ -3693,6 +3793,8 @@ flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
  *   Pointer to the list of actions.
  * @param[out] has_mtr
  *   Pointer to the meter exist flag.
+ * @param[out] has_modify
+ *   Pointer to the flag showing there's packet change action.
  * @param[out] meter_id
  *   Pointer to the meter id.
  *
@@ -3701,8 +3803,7 @@ flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
  */
 static int
 flow_check_meter_action(const struct rte_flow_action actions[],
-			bool *has_mtr,
-			uint32_t *meter_id)
+			bool *has_mtr, bool *has_modify, uint32_t *meter_id)
 {
 	const struct rte_flow_action_meter *mtr = NULL;
 	int actions_n = 0;
@@ -3719,6 +3820,9 @@ flow_check_meter_action(const struct rte_flow_action actions[],
 		default:
 			break;
 		}
+		if (!*has_mtr)
+			*has_modify |=
+				flow_check_modify_action_type(actions->type);
 		actions_n++;
 	}
 	/* Count RTE_FLOW_ACTION_TYPE_END. */
@@ -4361,6 +4465,112 @@ flow_create_split_inner(struct rte_eth_dev *dev,
 	return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
 }
 
+/**
+ * Get the table id of meter policy table.
+ *
+ * @param[in] dev
+ *   Pointer to Ethernet device.
+ * @param[in] flow
+ *   Parent flow structure pointer.
+ * @param[in] policy_id;
+ *   Meter Policy id.
+ * @param[in] attr
+ *   Flow rule attributes.
+ * @param[in] items
+ *   Pattern specification (list terminated by the END pattern item).
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *
+ * @return
+ *   The table id, 0 otherwise and rte_errno is set.
+ */
+static uint32_t
+get_sub_policy_tbl_id(struct rte_eth_dev *dev,
+		      struct rte_flow *flow,
+		      uint32_t policy_id,
+		      const struct rte_flow_attr *attr,
+		      const struct rte_flow_item items[],
+		      struct rte_flow_error *error)
+{
+	uint32_t policy_tbl_id = 0;
+	struct mlx5_flow_meter_policy *policy;
+
+	policy = mlx5_flow_meter_policy_find(dev, policy_id, NULL);
+	if (!policy) {
+		rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				   "Failed to find Meter Policy.");
+		goto exit;
+	}
+	if (policy->is_rss) {
+		struct mlx5_flow_workspace *wks =
+				mlx5_flow_get_thread_workspace();
+		struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
+		struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
+		uint32_t i;
+
+		MLX5_ASSERT(wks);
+		/** This is a tmp dev_flow,
+		 *  no need to register any matcher for it in translate.
+		 */
+		wks->skip_matcher_reg = 1;
+		for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
+			struct mlx5_flow dev_flow = {0};
+			struct mlx5_flow_handle dev_handle = {{0}};
+			const void *rss_act = policy->act_cnt[i].rss->conf;
+			struct rte_flow_action rss_actions[2] = {
+				[0] = {
+					.type = RTE_FLOW_ACTION_TYPE_RSS,
+					.conf = rss_act
+				},
+				[1] = {
+					.type = RTE_FLOW_ACTION_TYPE_END,
+					.conf = NULL
+				}
+			};
+
+			dev_flow.handle = &dev_handle;
+			dev_flow.ingress = attr->ingress;
+			dev_flow.flow = flow;
+			dev_flow.external = 0;
+#ifdef HAVE_IBV_FLOW_DV_SUPPORT
+			dev_flow.dv.transfer = attr->transfer;
+#endif
+			/* Translate RSS action to get rss hash fields. */
+			if (flow_drv_translate(dev, &dev_flow, attr,
+						items, rss_actions, error))
+				goto exit;
+			rss_desc_v[i] = wks->rss_desc;
+			rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
+			rss_desc_v[i].hash_fields = dev_flow.hash_fields;
+			rss_desc_v[i].queue_num = rss_desc_v[i].hash_fields ?
+						  rss_desc_v[i].queue_num : 1;
+			rss_desc[i] = &rss_desc_v[i];
+		}
+		sub_policy = flow_drv_meter_sub_policy_prepare(dev,
+						flow, policy_id, rss_desc);
+		if (!sub_policy) {
+			rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				"Failed to get meter RSS policy table.");
+			goto exit;
+		}
+		policy_tbl_id = sub_policy->idx;
+	} else {
+		enum mlx5_meter_domain mtr_domain =
+			attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
+				attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
+					MLX5_MTR_DOMAIN_INGRESS;
+		policy_tbl_id =
+			policy->sub_policys[mtr_domain][0]->idx;
+	}
+exit:
+	return policy_tbl_id;
+}
+
+#define MLX5_MTR_PRE_TAG_NUM 2
+
 /**
  * Split the meter flow.
  *
@@ -4391,13 +4601,15 @@ flow_create_split_inner(struct rte_eth_dev *dev,
  *   Suffix flow actions.
  * @param[out] actions_pre
  *   Prefix flow actions.
+ * @param[out] mtr_flow_id
+ *   Pointer to meter flow id.
  * @param[out] error
  *   Perform verbose error reporting if not NULL.
  *
  * @return
- *   The flow id, 0 otherwise and rte_errno is set.
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-static uint32_t
+static int
 flow_meter_split_prep(struct rte_eth_dev *dev,
 		      struct rte_flow *flow,
 		      struct mlx5_flow_meter_info *fm,
@@ -4407,6 +4619,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 		      const struct rte_flow_action actions[],
 		      struct rte_flow_action actions_sfx[],
 		      struct rte_flow_action actions_pre[],
+		      uint32_t *mtr_flow_id,
 		      struct rte_flow_error *error)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
@@ -4420,7 +4633,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	uint32_t tag_id = 0;
 	bool copy_vlan = false;
 	struct rte_flow_action *hw_mtr_action;
-	struct rte_flow_action_jump *jump_data;
+	struct mlx5_rte_flow_item_mtr_jump *jump_data;
 	struct rte_flow_action *action_pre_head = NULL;
 	bool mtr_first = priv->sh->meter_aso_en &&
 			 (attr->egress ||
@@ -4429,8 +4642,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	uint8_t mtr_reg_bits = priv->mtr_reg_share ?
 				MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
 	uint8_t flow_id_bits = 0;
-	int shift;
-	uint32_t flow_id_val = 0;
 
 	/* For ASO meter, meter must be before tag in TX direction. */
 	if (mtr_first) {
@@ -4474,7 +4685,9 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 			break;
 		}
 		if (!action_cur)
-			action_cur = actions_sfx++;
+			action_cur =
+				(fm->policy_id != MLX5_MTR_DEFAULT_POLICY_ID) ?
+					actions_pre++ : actions_sfx++;
 		memcpy(action_cur, actions, sizeof(struct rte_flow_action));
 	}
 	/* Add end action to the actions. */
@@ -4483,37 +4696,56 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 		/** For ASO meter, need to add an extra jump action explicitly,
 		 *  to jump from meter to policer table.
 		 */
+		uint32_t sub_policy_tbl_id = 0;
+
+		if (fm->policy_id != MLX5_MTR_DEFAULT_POLICY_ID) {
+			sub_policy_tbl_id =
+				get_sub_policy_tbl_id(dev, flow, fm->policy_id,
+						      attr, items, error);
+			if (!sub_policy_tbl_id)
+				return -rte_errno;
+		}
 		hw_mtr_action = actions_pre;
-		hw_mtr_action->type = RTE_FLOW_ACTION_TYPE_JUMP;
+		hw_mtr_action->type = (enum rte_flow_action_type)
+				      MLX5_RTE_FLOW_ACTION_TYPE_MTR_JUMP;
 		actions_pre++;
 		actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
 		actions_pre++;
-		jump_data = (struct rte_flow_action_jump *)actions_pre;
-		jump_data->group = attr->transfer ?
+		jump_data = (struct mlx5_rte_flow_item_mtr_jump *)actions_pre;
+		jump_data->table_group.group = attr->transfer ?
 				(MLX5_FLOW_TABLE_LEVEL_POLICY - 1) :
 				 MLX5_FLOW_TABLE_LEVEL_POLICY;
+		jump_data->table_id = sub_policy_tbl_id;
 		hw_mtr_action->conf = jump_data;
 		actions_pre = (struct rte_flow_action *)(jump_data + 1);
 	} else {
 		actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
 		actions_pre++;
 	}
-	/* Generate meter flow_id only if support multiple flows per meter. */
-	mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
-	if (!tag_id)
-		return rte_flow_error_set(error, ENOMEM,
-				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-				"Failed to allocate meter flow id.");
-	flow_id_bits = MLX5_REG_BITS - __builtin_clz(tag_id - 1);
-	flow_id_bits = flow_id_bits ? flow_id_bits : 1;
-	if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) > mtr_reg_bits) {
-		mlx5_ipool_free(fm->flow_ipool, tag_id);
-		return rte_flow_error_set(error, EINVAL,
-				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-				"Meter flow id exceeds max limit.");
+	MLX5_ASSERT(tag_action);
+	if (!mtr_flow_id) {
+		tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
+		goto exit;
+	}
+	/* Only Non-termination Policy Meter creates mtr flow id. */
+	if (fm->policy_id == MLX5_MTR_DEFAULT_POLICY_ID) {
+		mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
+		if (!tag_id)
+			return rte_flow_error_set(error, ENOMEM,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					"Failed to allocate meter flow id.");
+		flow_id_bits = MLX5_REG_BITS - __builtin_clz(tag_id - 1);
+		flow_id_bits = flow_id_bits ? flow_id_bits : 1;
+		if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
+		    mtr_reg_bits) {
+			mlx5_ipool_free(fm->flow_ipool, tag_id);
+			return rte_flow_error_set(error, EINVAL,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					"Meter flow id exceeds max limit.");
+		}
+		if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
+			priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	}
-	if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
-		priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
@@ -4543,7 +4775,6 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
 	sfx_items++;
 	/* Build tag actions and items for meter_id/meter flow_id. */
-	assert(tag_action);
 	set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
 	tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
 	tag_item_mask = tag_item_spec + 1;
@@ -4554,14 +4785,19 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 		.length = mtr_reg_bits,
 		.data = flow->meter,
 	};
-	/*
-	 * The color Reg bits used by flow_id are growing from
-	 * msb to lsb, so must do bit reverse for flow_id val in RegC.
-	 */
-	for (shift = 0; shift < flow_id_bits; shift++)
-		flow_id_val = (flow_id_val << 1) |
-			      (((tag_id - 1) >> shift) & 0x1);
-	set_tag->data |= flow_id_val << (mtr_reg_bits - flow_id_bits);
+	if (tag_id) {
+		int shift;
+		uint32_t flow_id_val = 0;
+
+		/*
+		 * The color Reg bits used by flow_id are growing from
+		 * msb to lsb, so must do bit reverse for flow_id val in RegC.
+		 */
+		for (shift = 0; shift < flow_id_bits; shift++)
+			flow_id_val = (flow_id_val << 1) |
+					(((tag_id - 1) >> shift) & 0x1);
+		set_tag->data |= flow_id_val << (mtr_reg_bits - flow_id_bits);
+	}
 	tag_item_spec->id = set_tag->id;
 	tag_item_spec->data = set_tag->data << mtr_id_offset;
 	tag_item_mask->data = UINT32_MAX << mtr_id_offset;
@@ -4573,7 +4809,10 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	tag_item->spec = tag_item_spec;
 	tag_item->last = NULL;
 	tag_item->mask = tag_item_mask;
-	return tag_id;
+exit:
+	if (mtr_flow_id)
+		*mtr_flow_id = tag_id;
+	return 0;
 }
 
 /**
@@ -5237,6 +5476,57 @@ flow_create_split_metadata(struct rte_eth_dev *dev,
 	return ret;
 }
 
+/**
+ * Create the Termination Policy Meter drop flow.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param[in] flow
+ *   Parent flow structure pointer.
+ * @param[in] attr
+ *   Flow rule attributes.
+ * @param[in] items
+ *   Pattern specification (list terminated by the END pattern item).
+ * @param[in] flow_split_info
+ *   Pointer to flow split info structure.
+ * @param[in] fm
+ *   Pointer to flow meter structure.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ * @return
+ *   0 on success, negative value otherwise
+ */
+static uint32_t
+flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
+			struct rte_flow *flow,
+			const struct rte_flow_attr *attr,
+			const struct rte_flow_item items[],
+			struct mlx5_flow_split_info *flow_split_info,
+			struct mlx5_flow_meter_info *fm,
+			struct rte_flow_error *error)
+{
+	struct mlx5_flow *dev_flow = NULL;
+	struct rte_flow_attr drop_attr = *attr;
+	struct rte_flow_action drop_actions[3] = {{0}};
+	struct mlx5_flow_split_info drop_split_info = *flow_split_info;
+
+	MLX5_ASSERT(fm->drop_cnt);
+	drop_actions[0].type =
+		(enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_MTR_COUNT;
+	drop_actions[0].conf =
+		(void *)(uintptr_t)fm->drop_cnt;
+	drop_actions[1].type =
+		RTE_FLOW_ACTION_TYPE_DROP;
+	drop_actions[2].type =
+		RTE_FLOW_ACTION_TYPE_END;
+	drop_split_info.external = false;
+	drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
+	drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER_DROP;
+	return flow_create_split_inner(dev, flow, &dev_flow,
+				&drop_attr, items, drop_actions,
+				&drop_split_info, error);
+}
+
 /**
  * The splitting for meter feature.
  *
@@ -5281,10 +5571,13 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 	struct mlx5_flow *dev_flow = NULL;
 	struct rte_flow_attr sfx_attr = *attr;
 	struct mlx5_flow_meter_info *fm = NULL;
+	uint8_t skip_scale_restore;
 	bool has_mtr = false;
-	uint32_t meter_id;
+	bool has_modify = false;
+	bool set_mtr_reg = true;
+	uint32_t meter_id = 0;
 	uint32_t mtr_idx = 0;
-	uint32_t mtr_tag_id = 0;
+	uint32_t mtr_flow_id = 0;
 	size_t act_size;
 	size_t item_size;
 	int actions_n = 0;
@@ -5292,7 +5585,7 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 
 	if (priv->mtr_en)
 		actions_n = flow_check_meter_action(actions, &has_mtr,
-						    &meter_id);
+						    &has_modify, &meter_id);
 	if (has_mtr) {
 		if (flow->meter) {
 			fm = flow_dv_meter_find_by_idx(priv, flow->meter);
@@ -5312,7 +5605,18 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 				return -rte_errno;
 			flow->meter = mtr_idx;
 		}
+		MLX5_ASSERT(wks);
 		wks->fm = fm;
+		/*
+		 * If it's Termination Policy Meter, and
+		 * 1. There's no action in flow to change
+		 *    packet (modify/encap/decap etc.), OR
+		 * 2. No drop count needed for this meter.
+		 * no need to use regC to save meter id anymore.
+		 */
+		if (fm->policy_id != MLX5_MTR_DEFAULT_POLICY_ID &&
+		    (!has_modify || !fm->drop_cnt))
+			set_mtr_reg = false;
 		/* Prefix actions: meter, decap, encap, tag, jump, end. */
 		act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
 			   sizeof(struct mlx5_rte_flow_action_set_tag);
@@ -5329,27 +5633,48 @@ flow_create_split_meter(struct rte_eth_dev *dev,
 						  "meter flow");
 		sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
 			     act_size);
-		pre_actions = sfx_actions + actions_n;
-		mtr_tag_id = flow_meter_split_prep(dev, flow, fm, &sfx_attr,
-						   items, sfx_items, actions,
-						   sfx_actions, pre_actions,
-						   error);
-		if (!mtr_tag_id) {
+		/* There's no suffix flow for Termination Policy Meter. */
+		if (fm->policy_id != MLX5_MTR_DEFAULT_POLICY_ID)
+			pre_actions = sfx_actions + 1;
+		else
+			pre_actions = sfx_actions + actions_n;
+		ret = flow_meter_split_prep(dev, flow, fm, &sfx_attr,
+					    items, sfx_items, actions,
+					    sfx_actions, pre_actions,
+					    (set_mtr_reg ? &mtr_flow_id : NULL),
+					    error);
+		if (ret) {
 			ret = -rte_errno;
 			goto exit;
 		}
 		/* Add the prefix subflow. */
 		flow_split_info->prefix_mark = 0;
+		skip_scale_restore = flow_split_info->skip_scale;
+		flow_split_info->skip_scale |=
+			1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
 		ret = flow_create_split_inner(dev, flow, &dev_flow,
 					      attr, items, pre_actions,
 					      flow_split_info, error);
 		if (ret) {
-			mlx5_ipool_free(fm->flow_ipool, mtr_tag_id);
+			if (mtr_flow_id)
+				mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
 			ret = -rte_errno;
 			goto exit;
 		}
-		dev_flow->handle->split_flow_id = mtr_tag_id;
-		dev_flow->handle->is_meter_flow_id = 1;
+		flow_split_info->skip_scale = skip_scale_restore;
+		if (mtr_flow_id) {
+			dev_flow->handle->split_flow_id = mtr_flow_id;
+			dev_flow->handle->is_meter_flow_id = 1;
+		}
+		if (fm->policy_id != MLX5_MTR_DEFAULT_POLICY_ID) {
+			if (!set_mtr_reg && fm->drop_cnt)
+				ret =
+			flow_meter_create_drop_flow_with_org_pattern(dev, flow,
+							&sfx_attr, items,
+							flow_split_info,
+							fm, error);
+			goto exit;
+		}
 		/* Setting the sfx group atrr. */
 		sfx_attr.group = sfx_attr.transfer ?
 				(MLX5_FLOW_TABLE_LEVEL_SUFFIX - 1) :
@@ -5743,7 +6068,7 @@ flow_list_create(struct rte_eth_dev *dev, uint32_t *list,
 	memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
 	/* RSS Action only works on NIC RX domain */
 	if (attr->ingress && !attr->transfer)
-		rss = flow_get_rss_action(p_actions_rx);
+		rss = flow_get_rss_action(dev, p_actions_rx);
 	if (rss) {
 		if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
 			return 0;
drivers/net/mlx5/mlx5_flow.h +9 -0
index 3024bd9b60..cdbaf95085 100644
@@ -37,6 +37,8 @@ enum mlx5_rte_flow_action_type {
 	MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
 	MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET,
 	MLX5_RTE_FLOW_ACTION_TYPE_AGE,
+	MLX5_RTE_FLOW_ACTION_TYPE_MTR_JUMP,
+	MLX5_RTE_FLOW_ACTION_TYPE_MTR_COUNT,
 };
 
 #define MLX5_SHARED_ACTION_TYPE_OFFSET 30
@@ -70,6 +72,11 @@ struct mlx5_rte_flow_item_tx_queue {
 	uint32_t queue;
 };
 
+struct mlx5_rte_flow_item_mtr_jump {
+	struct rte_flow_action_jump table_group;
+	uint32_t table_id;
+};
+
 /* Feature name to allocate metadata register. */
 enum mlx5_feature_name {
 	MLX5_HAIRPIN_RX,
@@ -1029,6 +1036,8 @@ struct mlx5_flow_workspace {
 	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
+	uint32_t skip_matcher_reg:1;
+	/* Indicates if need to skip matcher register in translate. */
 };
 
 struct mlx5_flow_split_info {
drivers/net/mlx5/mlx5_flow_dv.c +22 -2
index b646b330ac..9f5945379e 100644
@@ -7409,6 +7409,7 @@ flow_dv_prepare(struct rte_eth_dev *dev,
 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
 
 	MLX5_ASSERT(wks);
+	wks->skip_matcher_reg = 0;
 	/* In case of corrupting the memory. */
 	if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
 		rte_flow_error_set(error, ENOSPC,
@@ -11252,6 +11253,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 		int action_type = actions->type;
 		const struct rte_flow_action *found_action = NULL;
 		uint32_t jump_group = 0;
+		uint32_t jump_table_id = 0;
+		struct mlx5_flow_counter *cnt;
 
 		if (!mlx5_flow_os_action_supported(action_type))
 			return rte_flow_error_set(error, ENOTSUP,
@@ -11432,6 +11435,15 @@ flow_dv_translate(struct rte_eth_dev *dev,
 				age = action->conf;
 			action_flags |= MLX5_FLOW_ACTION_COUNT;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_MTR_COUNT:
+			cnt = flow_dv_counter_get_by_idx(dev,
+				(uint32_t)(uintptr_t)action->conf, NULL);
+			if (!cnt)
+				return rte_flow_error_set(error, rte_errno,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					NULL, "Failed to get meter counter.");
+			dev_flow->dv.actions[actions_n++] = cnt->action;
+			break;
 		case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
 			dev_flow->dv.actions[actions_n++] =
 						priv->sh->pop_vlan_action;
@@ -11536,6 +11548,11 @@ flow_dv_translate(struct rte_eth_dev *dev,
 			/* If decap is followed by encap, handle it at encap. */
 			action_flags |= MLX5_FLOW_ACTION_DECAP;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_MTR_JUMP:
+			jump_table_id =
+				((const struct mlx5_rte_flow_item_mtr_jump *)
+				 action->conf)->table_id;
+			/* Fall through */
 		case RTE_FLOW_ACTION_TYPE_JUMP:
 			jump_group = ((const struct rte_flow_action_jump *)
 							action->conf)->group;
@@ -11555,7 +11572,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
 						       attr->transfer,
 						       !!dev_flow->external,
 						       tunnel, jump_group, 0,
-						       0, error);
+						       jump_table_id, error);
 			if (!tbl)
 				return rte_flow_error_set
 						(error, errno,
@@ -12091,6 +12108,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 	}
 	dev_flow->dv.actions_n = actions_n;
 	dev_flow->act_flags = action_flags;
+	if (wks->skip_matcher_reg)
+		return 0;
 	/* Register matcher. */
 	matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
 				    matcher.mask.size);
@@ -12242,7 +12261,8 @@ flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
 		dv_h = &dh->dvh;
 		n = dv->actions_n;
 		if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
-			if (dv->transfer) {
+			if (dv->transfer || dev_flow->dv.group ==
+			    MLX5_FLOW_TABLE_LEVEL_METER_DROP) {
 				dv->actions[n++] = priv->sh->esw_drop_action;
 			} else {
 				MLX5_ASSERT(priv->drop_queue.hrxq);
Signature · 1 line
2.27.0
author
#10 lore raw

v3 cover net/mlx5: support meter policy operations

In reply to Li Zhang

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=16300 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16300

Depends-on: series=16301 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16301

V2: Add MLX5_MTR_DEFAULT_POLICY_ID in MLX5 PMD
V3: Fix comments.

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 doc/guides/nics/mlx5.rst           |   12 +
 drivers/net/mlx5/linux/mlx5_os.c   |   13 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  212 +++-
 drivers/net/mlx5/mlx5_flow.c       |  654 ++++++++--
 drivers/net/mlx5/mlx5_flow.h       |  119 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1896 ++++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c |  728 ++++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 10 files changed, 3365 insertions(+), 357 deletions(-)
Signature · 1 line
2.27.0
author
#11 lore raw

PATCH v3 1/4 net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

Implement the next policy operations:
validate:
The driver doesn't support to configure actions in the flow after the meter action except one case when the meter policy is configured to do nothing in GREEN\YELLOW and only DROP action in RED, this special policy is called non-terminated policy and is handed as a singleton object internally.

For all the terminated policies, the next actions are supported:
GREEN - QUEUE, RSS, PORT_ID, JUMP, DROP, MARK and SET_TAG. YELLOW - not supported at all -> must be empty.
RED - must include DROP action.

Hence, in ingress case, for example,
QUEUE\RSS\JUMP must be configured as last action for GREEN color.

All the above limitations will be validated.

create:
Validate the policy configuration.
Prepare the related tables and actions.

destroy:
Release the created policy resources.

---
 drivers/net/mlx5/linux/mlx5_os.c   |    2 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  158 +++-
 drivers/net/mlx5/mlx5_flow.c       |  192 +++-
 drivers/net/mlx5/mlx5_flow.h       |   73 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1412 +++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow_meter.c |  445 ++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 9 files changed, 2242 insertions(+), 128 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +1 -1
index bec288c840..276283d492 100644
@@ -1299,7 +1299,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			log_obj_size <=
 			config->hca_attr.qos.log_meter_aso_max_alloc) {
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv);
+				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
 				if (err) {
 					err = -err;
 					goto error;
drivers/net/mlx5/mlx5.c +46 -31

110 lines not on this page · raw message

drivers/net/mlx5/mlx5.h +152 -6

203 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +185 -7

228 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +61 -12

118 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_aso.c +5 -5
index 62d2df054b..20cd4fe18c 100644
@@ -311,11 +311,11 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
 		mlx5_aso_age_init_sq(&sh->aso_age_mng->aso_sq);
 		break;
 	case ASO_OPC_MOD_POLICER:
-		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->sq, 0,
+		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->pools_mng.sq, 0,
 				  sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC,
 				  sh->sq_ts_format))
 			return -1;
-		mlx5_aso_mtr_init_sq(&sh->mtrmng->sq);
+		mlx5_aso_mtr_init_sq(&sh->mtrmng->pools_mng.sq);
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -342,7 +342,7 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,
 		sq = &sh->aso_age_mng->aso_sq;
 		break;
 	case ASO_OPC_MOD_POLICER:
-		sq = &sh->mtrmng->sq;
+		sq = &sh->mtrmng->pools_mng.sq;
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -798,7 +798,7 @@ int
 mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_wqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	do {
@@ -830,7 +830,7 @@ int
 mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_cqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	if (__atomic_load_n(&mtr->state, __ATOMIC_RELAXED) ==
drivers/net/mlx5/mlx5_flow_dv.c +1375 -37

1,532 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +416 -29

517 lines not on this page · raw message

drivers/net/mlx5/mlx5_trigger.c +1 -0
index 94dd56709e..90d918849a 100644
@@ -1179,6 +1179,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev)
 	mlx5_traffic_disable(dev);
 	/* All RX queue flags will be cleared in the flush interface. */
 	mlx5_flow_list_flush(dev, &priv->flows, true);
+	mlx5_flow_meter_flush(dev, NULL);
 	mlx5_rx_intr_vec_disable(dev);
 	priv->sh->port[priv->dev_port - 1].ih_port_id = RTE_MAX_ETHPORTS;
 	priv->sh->port[priv->dev_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS;
Signature · 1 line
2.27.0
author
#12 lore raw

PATCH v3 2/4 net/mlx5: support meter creation with policy

In reply to Li Zhang

Create a meter with the new pre-defined policy.

The following cases to be considered:
1.Add entry match with meter_id in global drop table. 2.For non-termination policy (policy id 0),
add jump rule to suffix table for green and jump rule to drop table for red.
3.Allocate counter per meter in drop table. 4.Allocate meter resource per domain per color. 5.It can work with both ASO and legacy meter HW objects.

---
 drivers/net/mlx5/linux/mlx5_os.c   |  13 +-
 drivers/net/mlx5/mlx5.h            |  62 ++---
 drivers/net/mlx5/mlx5_flow.c       |  26 +-
 drivers/net/mlx5/mlx5_flow.h       |  32 +--
 drivers/net/mlx5/mlx5_flow_dv.c    | 367 ++++++++++++++++++++---------
 drivers/net/mlx5/mlx5_flow_meter.c | 337 ++++++++++++++++++++++----
 6 files changed, 607 insertions(+), 230 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +7 -6
index 276283d492..c1d4e2a0dc 100644
@@ -1297,13 +1297,14 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			if (log_obj_size >=
 			config->hca_attr.qos.log_meter_aso_granularity &&
 			log_obj_size <=
-			config->hca_attr.qos.log_meter_aso_max_alloc) {
+			config->hca_attr.qos.log_meter_aso_max_alloc)
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
-				if (err) {
-					err = -err;
-					goto error;
-				}
+		}
+		if (priv->mtr_en) {
+			err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
+			if (err) {
+				err = -err;
+				goto error;
 			}
 		}
 #endif
drivers/net/mlx5/mlx5.h +19 -43

99 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +13 -13
index 81e0e3b7a9..77590bbbed 100644
@@ -4496,14 +4496,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	flow_id = tag_id - 1;
 	flow_id_bits = MLX5_REG_BITS - __builtin_clz(flow_id);
 	flow_id_bits = flow_id_bits ? flow_id_bits : 1;
-	if ((flow_id_bits + priv->max_mtr_bits) > mtr_reg_bits) {
+	if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) > mtr_reg_bits) {
 		mlx5_ipool_free(fm->flow_ipool, tag_id);
 		return rte_flow_error_set(error, EINVAL,
 				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 				"Meter flow id exceeds max limit.");
 	}
-	if (flow_id_bits > priv->max_mtr_flow_bits)
-		priv->max_mtr_flow_bits = flow_id_bits;
+	if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
+		priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
@@ -6778,15 +6778,18 @@ mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  *
  * @return
- *   Pointer to table set on success, NULL otherwise.
+ *   0 on success, -1 otherwise.
  */
-struct mlx5_meter_domains_infos *
-mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
+int
+mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			struct mlx5_flow_meter_info *fm,
+			uint32_t mtr_idx,
+			uint8_t domain_bitmap)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->create_mtr_tbls(dev);
+	return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
 }
 
 /**
@@ -6796,18 +6799,15 @@ mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  * @param[in] tbl
  *   Pointer to the meter table set.
- *
- * @return
- *   0 on success.
  */
-int
+void
 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			   struct mlx5_meter_domains_infos *tbls)
+			   struct mlx5_flow_meter_info *fm)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->destroy_mtr_tbls(dev, tbls);
+	fops->destroy_mtr_tbls(dev, fm);
 }
 
 /**
drivers/net/mlx5/mlx5_flow.h +18 -14
index 51d040c4d2..89e43f2de6 100644
@@ -222,16 +222,17 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37)
 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)
 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)
+#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
 	 MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
-	 MLX5_FLOW_ACTION_DEFAULT_MISS)
+	 MLX5_FLOW_ACTION_DEFAULT_MISS | \
+	 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
-	 MLX5_FLOW_ACTION_JUMP)
-
+	 MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
 				      MLX5_FLOW_ACTION_SET_IPV4_DST | \
@@ -832,9 +833,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
-	uint32_t meter_id;
-	/**< Meter id. */
-	uint32_t idx; /* Index to meter object. */
+	uint32_t idx;
+	/* Index to meter object. */
 };
 
 #define MLX5_MAX_TUNNELS 256
@@ -1088,10 +1088,12 @@ typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
 				 const struct rte_flow_action *actions,
 				 void *data,
 				 struct rte_flow_error *error);
-typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
-					    (struct rte_eth_dev *dev);
-typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
-					struct mlx5_meter_domains_infos *tbls);
+typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
+					struct mlx5_flow_meter_info *fm,
+					uint32_t mtr_idx,
+					uint8_t domain_bitmap);
+typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
@@ -1409,10 +1411,12 @@ int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
 				  uint16_t ether_type,
 				  const struct rte_flow_item_ecpri *acc_mask,
 				  struct rte_flow_error *error);
-struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
-					(struct rte_eth_dev *dev);
-int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			       struct mlx5_meter_domains_infos *tbl);
+int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm,
+				uint32_t mtr_idx,
+				uint8_t domain_bitmap);
+void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
+			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_shared_action_flush(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_dv.c +253 -114

463 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +297 -40

447 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#13 lore raw

PATCH v3 3/4 net/mlx5: prepare sub-policy for a flow with meter

In reply to Li Zhang

When a flow has a RSS action, the driver splits each sub flow finally is configured with
a different HW TIR action.

Any RSS action configured in meter policy may cause a split in the flow configuration.
To save performance, any TIR action will be configured in different flow table, so policy can be split to sub-policies per TIR in the flow creation time.

Create a function to prepare the policy and its sub-policies for a configured flow with meter.

---
 drivers/net/mlx5/mlx5_flow.h    |  10 +++
 drivers/net/mlx5/mlx5_flow_dv.c | 144 ++++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+)
drivers/net/mlx5/mlx5_flow.h +10 -0
index 89e43f2de6..cc9b37b9eb 100644
@@ -1095,6 +1095,11 @@ typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
 				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
+typedef struct mlx5_flow_meter_sub_policy *
+	(*mlx5_flow_meter_sub_policy_rss_prepare_t)
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1187,6 +1192,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_destroy_policy_rules_t destroy_policy_rules;
 	mlx5_flow_create_def_policy_t create_def_policy;
 	mlx5_flow_destroy_def_policy_t destroy_def_policy;
+	mlx5_flow_meter_sub_policy_rss_prepare_t meter_sub_policy_rss_prepare;
 	mlx5_flow_counter_alloc_t counter_alloc;
 	mlx5_flow_counter_free_t counter_free;
 	mlx5_flow_counter_query_t counter_query;
@@ -1418,6 +1424,10 @@ int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
+struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_rss_prepare
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_shared_action_flush(struct rte_eth_dev *dev);
 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id);
drivers/net/mlx5/mlx5_flow_dv.c +144 -0

156 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#14 lore raw

PATCH v3 4/4 net/mlx5: connect meter policy to created flows

In reply to Li Zhang

From: Shun Hao <[email protected]>

Currently ASO meter must be followed by policy table, so this adds the support that connecting meter and policy table.

There are several cases to be considered:
1. For non-termination policy, connect meter to the default policy table.
2. For non-RSS termination policy case, simply get the policy table id and connect meter to it.
3. For RSS termination policy case, need to split the flow due to RSS info in policy, and translate each sub-flow using that RSS, then create the sub policy table to be connected.
4. In termination policy case, if there's no actions to modify the packet before meter, no need to use set_tag to save meter id in register. Only add a new flow in drop table using the same match criteria as suf-flow, to save cache miss.

---
 doc/guides/nics/mlx5.rst        |  12 +
 drivers/net/mlx5/mlx5_flow.c    | 446 ++++++++++++++++++++++++++++----
 drivers/net/mlx5/mlx5_flow.h    |   4 +
 drivers/net/mlx5/mlx5_flow_dv.c |  15 ++
 4 files changed, 420 insertions(+), 57 deletions(-)
doc/guides/nics/mlx5.rst +12 -0
index d287b3aca1..1e67a91ee7 100644
@@ -106,6 +106,7 @@ Features
 - E-Switch mirroring and modify.
 - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer
   flow group.
+- Flow metering, including meter policy API.
 
 Limitations
 -----------
@@ -400,10 +401,21 @@ Limitations
   - Hairpin in switchdev SR-IOV mode is not supported till now.
 
 - Meter:
+
   - All the meter colors with drop action will be counted only by the global drop statistics.
   - Green color is not supported with drop action.
   - Yellow detection is not supported.
   - Red color must be with drop action.
+  - Meter statistics are supported only for drop case.
+  - Meter yellow color detection is not supported.
+  - A meter action created with pre-defined policy must be the last action in the flow except single case where the policy actions are:
+     - green: NULL or END.
+     - yellow: NULL or END.
+     - RED: DROP / END.
+  - The only supported meter policy actions:
+     - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
+     - yellow: must be empty.
+     - RED: must be DROP.
 
 Statistics
 ----------
drivers/net/mlx5/mlx5_flow.c +389 -57

615 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +4 -0
index cc9b37b9eb..8a0a84a604 100644
@@ -37,6 +37,8 @@ enum mlx5_rte_flow_action_type {
 	MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
 	MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET,
 	MLX5_RTE_FLOW_ACTION_TYPE_AGE,
+	MLX5_RTE_FLOW_ACTION_TYPE_JUMP,
+	MLX5_RTE_FLOW_ACTION_TYPE_COUNT,
 };
 
 #define MLX5_SHARED_ACTION_TYPE_OFFSET 30
@@ -1048,6 +1050,8 @@ struct mlx5_flow_workspace {
 	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
+	uint32_t skip_matcher_reg:1;
+	/* Indicates if need to skip matcher register in translate. */
 };
 
 struct mlx5_flow_split_info {
drivers/net/mlx5/mlx5_flow_dv.c +15 -0
index ed17bd903f..eedbe2e43b 100644
@@ -7423,6 +7423,7 @@ flow_dv_prepare(struct rte_eth_dev *dev,
 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
 
 	MLX5_ASSERT(wks);
+	wks->skip_matcher_reg = 0;
 	/* In case of corrupting the memory. */
 	if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
 		rte_flow_error_set(error, ENOSPC,
@@ -11254,6 +11255,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
 		int action_type = actions->type;
 		const struct rte_flow_action *found_action = NULL;
 		uint32_t jump_group = 0;
+		struct mlx5_flow_counter *cnt;
 
 		if (!mlx5_flow_os_action_supported(action_type))
 			return rte_flow_error_set(error, ENOTSUP,
@@ -11434,6 +11436,12 @@ flow_dv_translate(struct rte_eth_dev *dev,
 				age = action->conf;
 			action_flags |= MLX5_FLOW_ACTION_COUNT;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
+			cnt = flow_dv_counter_get_by_idx(dev,
+				(uint32_t)(uintptr_t)action->conf, NULL);
+			MLX5_ASSERT(cnt != NULL);
+			dev_flow->dv.actions[actions_n++] = cnt->action;
+			break;
 		case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
 			dev_flow->dv.actions[actions_n++] =
 						priv->sh->pop_vlan_action;
@@ -11538,6 +11546,11 @@ flow_dv_translate(struct rte_eth_dev *dev,
 			/* If decap is followed by encap, handle it at encap. */
 			action_flags |= MLX5_FLOW_ACTION_DECAP;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
+			dev_flow->dv.actions[actions_n++] =
+				(void *)(uintptr_t)action->conf;
+			action_flags |= MLX5_FLOW_ACTION_JUMP;
+			break;
 		case RTE_FLOW_ACTION_TYPE_JUMP:
 			jump_group = ((const struct rte_flow_action_jump *)
 							action->conf)->group;
@@ -12093,6 +12106,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 	}
 	dev_flow->dv.actions_n = actions_n;
 	dev_flow->act_flags = action_flags;
+	if (wks->skip_matcher_reg)
+		return 0;
 	/* Register matcher. */
 	matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
 				    matcher.mask.size);
Signature · 1 line
2.27.0
author
#15 lore raw

v4 cover net/mlx5: support meter policy operations

In reply to Li Zhang

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=16351 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16351

Depends-on: series=16357 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16357

V2: Add MLX5_MTR_DEFAULT_POLICY_ID in MLX5 PMD
V3: Fix comments about Depends-on
V4: Fix comments about rte_mtr_meter_policy_add.

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 doc/guides/nics/mlx5.rst           |   12 +
 drivers/net/mlx5/linux/mlx5_os.c   |   13 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  216 +++-
 drivers/net/mlx5/mlx5_flow.c       |  639 ++++++++--
 drivers/net/mlx5/mlx5_flow.h       |  116 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1868 ++++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c |  740 ++++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 10 files changed, 3340 insertions(+), 352 deletions(-)
Signature · 1 line
2.27.0
author
#16 lore raw

PATCH v4 1/4 net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

Implement the next policy operations:
validate:
The driver doesn't support to configure actions in the flow after the meter action except one case when the meter policy is configured to do nothing in GREEN\YELLOW and only DROP action in RED, this special policy is called non-terminated policy and is handed as a singleton object internally.

For all the terminated policies, the next actions are supported:
GREEN - QUEUE, RSS, PORT_ID, JUMP, DROP, MARK and SET_TAG. YELLOW - not supported at all -> must be empty.
RED - must include DROP action.

Hence, in ingress case, for example,
QUEUE\RSS\JUMP must be configured as last action for GREEN color.

All the above limitations will be validated.

create:
Validate the policy configuration.
Prepare the related tables and actions.

destroy:
Release the created policy resources.

---
 drivers/net/mlx5/linux/mlx5_os.c   |    2 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  158 +++-
 drivers/net/mlx5/mlx5_flow.c       |  192 +++-
 drivers/net/mlx5/mlx5_flow.h       |   73 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1412 +++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow_meter.c |  445 ++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 9 files changed, 2242 insertions(+), 128 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +1 -1
index bec288c840..276283d492 100644
@@ -1299,7 +1299,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			log_obj_size <=
 			config->hca_attr.qos.log_meter_aso_max_alloc) {
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv);
+				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
 				if (err) {
 					err = -err;
 					goto error;
drivers/net/mlx5/mlx5.c +46 -31

110 lines not on this page · raw message

drivers/net/mlx5/mlx5.h +152 -6

203 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +185 -7

228 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +61 -12

118 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_aso.c +5 -5
index 62d2df054b..20cd4fe18c 100644
@@ -311,11 +311,11 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
 		mlx5_aso_age_init_sq(&sh->aso_age_mng->aso_sq);
 		break;
 	case ASO_OPC_MOD_POLICER:
-		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->sq, 0,
+		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->pools_mng.sq, 0,
 				  sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC,
 				  sh->sq_ts_format))
 			return -1;
-		mlx5_aso_mtr_init_sq(&sh->mtrmng->sq);
+		mlx5_aso_mtr_init_sq(&sh->mtrmng->pools_mng.sq);
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -342,7 +342,7 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,
 		sq = &sh->aso_age_mng->aso_sq;
 		break;
 	case ASO_OPC_MOD_POLICER:
-		sq = &sh->mtrmng->sq;
+		sq = &sh->mtrmng->pools_mng.sq;
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -798,7 +798,7 @@ int
 mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_wqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	do {
@@ -830,7 +830,7 @@ int
 mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_cqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	if (__atomic_load_n(&mtr->state, __ATOMIC_RELAXED) ==
drivers/net/mlx5/mlx5_flow_dv.c +1375 -37

1,532 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +416 -29

517 lines not on this page · raw message

drivers/net/mlx5/mlx5_trigger.c +1 -0
index 94dd56709e..90d918849a 100644
@@ -1179,6 +1179,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev)
 	mlx5_traffic_disable(dev);
 	/* All RX queue flags will be cleared in the flush interface. */
 	mlx5_flow_list_flush(dev, &priv->flows, true);
+	mlx5_flow_meter_flush(dev, NULL);
 	mlx5_rx_intr_vec_disable(dev);
 	priv->sh->port[priv->dev_port - 1].ih_port_id = RTE_MAX_ETHPORTS;
 	priv->sh->port[priv->dev_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS;
Signature · 1 line
2.27.0
author
#17 lore raw

PATCH v4 2/4 net/mlx5: support meter creation with policy

In reply to Li Zhang

Create a meter with the new pre-defined policy.

The following cases to be considered:
1.Add entry match with meter_id in global drop table. 2.For non-termination policy (policy id 0),
add jump rule to suffix table for green and jump rule to drop table for red.
3.Allocate counter per meter in drop table. 4.Allocate meter resource per domain per color. 5.It can work with both ASO and legacy meter HW objects.

---
 drivers/net/mlx5/linux/mlx5_os.c   |  13 +-
 drivers/net/mlx5/mlx5.h            |  66 ++---
 drivers/net/mlx5/mlx5_flow.c       |  41 +--
 drivers/net/mlx5/mlx5_flow.h       |  35 +--
 drivers/net/mlx5/mlx5_flow_dv.c    | 395 +++++++++++++++++++----------
 drivers/net/mlx5/mlx5_flow_meter.c | 363 ++++++++++++++++++++++----
 6 files changed, 635 insertions(+), 278 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +7 -6
index 276283d492..c1d4e2a0dc 100644
@@ -1297,13 +1297,14 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			if (log_obj_size >=
 			config->hca_attr.qos.log_meter_aso_granularity &&
 			log_obj_size <=
-			config->hca_attr.qos.log_meter_aso_max_alloc) {
+			config->hca_attr.qos.log_meter_aso_max_alloc)
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
-				if (err) {
-					err = -err;
-					goto error;
-				}
+		}
+		if (priv->mtr_en) {
+			err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
+			if (err) {
+				err = -err;
+				goto error;
 			}
 		}
 #endif
drivers/net/mlx5/mlx5.h +23 -43

103 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +13 -28

75 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +18 -17
index 51d040c4d2..7d1684d02d 100644
@@ -222,16 +222,17 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37)
 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)
 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)
+#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
 	 MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
-	 MLX5_FLOW_ACTION_DEFAULT_MISS)
+	 MLX5_FLOW_ACTION_DEFAULT_MISS | \
+	 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
-	 MLX5_FLOW_ACTION_JUMP)
-
+	 MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
 				      MLX5_FLOW_ACTION_SET_IPV4_DST | \
@@ -832,9 +833,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
-	uint32_t meter_id;
-	/**< Meter id. */
-	uint32_t idx; /* Index to meter object. */
+	uint32_t idx;
+	/* Index to meter object. */
 };
 
 #define MLX5_MAX_TUNNELS 256
@@ -1088,11 +1088,12 @@ typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
 				 const struct rte_flow_action *actions,
 				 void *data,
 				 struct rte_flow_error *error);
-typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
-					    (struct rte_eth_dev *dev);
-typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
-					struct mlx5_meter_domains_infos *tbls);
-typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
+typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
+					struct mlx5_flow_meter_info *fm,
+					uint32_t mtr_idx,
+					uint8_t domain_bitmap);
+typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1175,7 +1176,6 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_query_t query;
 	mlx5_flow_create_mtr_tbls_t create_mtr_tbls;
 	mlx5_flow_destroy_mtr_tbls_t destroy_mtr_tbls;
-	mlx5_flow_destroy_mtr_drop_tbls_t destroy_mtr_drop_tbls;
 	mlx5_flow_mtr_alloc_t create_meter;
 	mlx5_flow_mtr_free_t free_meter;
 	mlx5_flow_validate_mtr_acts_t validate_mtr_acts;
@@ -1409,11 +1409,12 @@ int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
 				  uint16_t ether_type,
 				  const struct rte_flow_item_ecpri *acc_mask,
 				  struct rte_flow_error *error);
-struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
-					(struct rte_eth_dev *dev);
-int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			       struct mlx5_meter_domains_infos *tbl);
-void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
+int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm,
+				uint32_t mtr_idx,
+				uint8_t domain_bitmap);
+void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
+			       struct mlx5_flow_meter_info *fm);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_shared_action_flush(struct rte_eth_dev *dev);
 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id);
drivers/net/mlx5/mlx5_flow_dv.c +264 -131

489 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +310 -53

498 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#18 lore raw

PATCH v4 3/4 net/mlx5: prepare sub-policy for a flow with meter

In reply to Li Zhang

When a flow has a RSS action, the driver splits each sub flow finally is configured with
a different HW TIR action.

Any RSS action configured in meter policy may cause a split in the flow configuration.
To save performance, any TIR action will be configured in different flow table, so policy can be split to sub-policies per TIR in the flow creation time.

Create a function to prepare the policy and its sub-policies for a configured flow with meter.

---
 drivers/net/mlx5/mlx5_flow.h    |  10 +++
 drivers/net/mlx5/mlx5_flow_dv.c | 144 ++++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+)
drivers/net/mlx5/mlx5_flow.h +10 -0
index 7d1684d02d..ddfab494b8 100644
@@ -1094,6 +1094,11 @@ typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
 					uint8_t domain_bitmap);
 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
 				struct mlx5_flow_meter_info *fm);
+typedef struct mlx5_flow_meter_sub_policy *
+	(*mlx5_flow_meter_sub_policy_rss_prepare_t)
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1185,6 +1190,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_destroy_policy_rules_t destroy_policy_rules;
 	mlx5_flow_create_def_policy_t create_def_policy;
 	mlx5_flow_destroy_def_policy_t destroy_def_policy;
+	mlx5_flow_meter_sub_policy_rss_prepare_t meter_sub_policy_rss_prepare;
 	mlx5_flow_counter_alloc_t counter_alloc;
 	mlx5_flow_counter_free_t counter_free;
 	mlx5_flow_counter_query_t counter_query;
@@ -1415,6 +1421,10 @@ int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
 				uint8_t domain_bitmap);
 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_flow_meter_info *fm);
+struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_rss_prepare
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_shared_action_flush(struct rte_eth_dev *dev);
 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id);
drivers/net/mlx5/mlx5_flow_dv.c +144 -0

156 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#19 lore raw

PATCH v4 4/4 net/mlx5: connect meter policy to created flows

In reply to Li Zhang

From: Shun Hao <[email protected]>

Currently ASO meter must be followed by policy table, so this adds the support that connecting meter and policy table.

There are several cases to be considered:
1. For non-termination policy, connect meter to the default policy table.
2. For non-RSS termination policy case, simply get the policy table id and connect meter to it.
3. For RSS termination policy case, need to split the flow due to RSS info in policy, and translate each sub-flow using that RSS, then create the sub policy table to be connected.
4. In termination policy case, if there's no actions to modify the packet before meter, no need to use set_tag to save meter id in register. Only add a new flow in drop table using the same match criteria as suf-flow, to save cache miss.

---
 doc/guides/nics/mlx5.rst        |  12 +
 drivers/net/mlx5/mlx5_flow.c    | 446 ++++++++++++++++++++++++++++----
 drivers/net/mlx5/mlx5_flow.h    |   4 +
 drivers/net/mlx5/mlx5_flow_dv.c |  15 ++
 4 files changed, 420 insertions(+), 57 deletions(-)
doc/guides/nics/mlx5.rst +12 -0
index d287b3aca1..1e67a91ee7 100644
@@ -106,6 +106,7 @@ Features
 - E-Switch mirroring and modify.
 - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer
   flow group.
+- Flow metering, including meter policy API.
 
 Limitations
 -----------
@@ -400,10 +401,21 @@ Limitations
   - Hairpin in switchdev SR-IOV mode is not supported till now.
 
 - Meter:
+
   - All the meter colors with drop action will be counted only by the global drop statistics.
   - Green color is not supported with drop action.
   - Yellow detection is not supported.
   - Red color must be with drop action.
+  - Meter statistics are supported only for drop case.
+  - Meter yellow color detection is not supported.
+  - A meter action created with pre-defined policy must be the last action in the flow except single case where the policy actions are:
+     - green: NULL or END.
+     - yellow: NULL or END.
+     - RED: DROP / END.
+  - The only supported meter policy actions:
+     - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
+     - yellow: must be empty.
+     - RED: must be DROP.
 
 Statistics
 ----------
drivers/net/mlx5/mlx5_flow.c +389 -57

615 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +4 -0
index ddfab494b8..211ebe20bb 100644
@@ -37,6 +37,8 @@ enum mlx5_rte_flow_action_type {
 	MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
 	MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET,
 	MLX5_RTE_FLOW_ACTION_TYPE_AGE,
+	MLX5_RTE_FLOW_ACTION_TYPE_JUMP,
+	MLX5_RTE_FLOW_ACTION_TYPE_COUNT,
 };
 
 #define MLX5_SHARED_ACTION_TYPE_OFFSET 30
@@ -1048,6 +1050,8 @@ struct mlx5_flow_workspace {
 	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
+	uint32_t skip_matcher_reg:1;
+	/* Indicates if need to skip matcher register in translate. */
 };
 
 struct mlx5_flow_split_info {
drivers/net/mlx5/mlx5_flow_dv.c +15 -0
index 96adf3f9cb..f0cfa47f99 100644
@@ -7423,6 +7423,7 @@ flow_dv_prepare(struct rte_eth_dev *dev,
 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
 
 	MLX5_ASSERT(wks);
+	wks->skip_matcher_reg = 0;
 	/* In case of corrupting the memory. */
 	if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
 		rte_flow_error_set(error, ENOSPC,
@@ -11254,6 +11255,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
 		int action_type = actions->type;
 		const struct rte_flow_action *found_action = NULL;
 		uint32_t jump_group = 0;
+		struct mlx5_flow_counter *cnt;
 
 		if (!mlx5_flow_os_action_supported(action_type))
 			return rte_flow_error_set(error, ENOTSUP,
@@ -11434,6 +11436,12 @@ flow_dv_translate(struct rte_eth_dev *dev,
 				age = action->conf;
 			action_flags |= MLX5_FLOW_ACTION_COUNT;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
+			cnt = flow_dv_counter_get_by_idx(dev,
+				(uint32_t)(uintptr_t)action->conf, NULL);
+			MLX5_ASSERT(cnt != NULL);
+			dev_flow->dv.actions[actions_n++] = cnt->action;
+			break;
 		case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
 			dev_flow->dv.actions[actions_n++] =
 						priv->sh->pop_vlan_action;
@@ -11538,6 +11546,11 @@ flow_dv_translate(struct rte_eth_dev *dev,
 			/* If decap is followed by encap, handle it at encap. */
 			action_flags |= MLX5_FLOW_ACTION_DECAP;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
+			dev_flow->dv.actions[actions_n++] =
+				(void *)(uintptr_t)action->conf;
+			action_flags |= MLX5_FLOW_ACTION_JUMP;
+			break;
 		case RTE_FLOW_ACTION_TYPE_JUMP:
 			jump_group = ((const struct rte_flow_action_jump *)
 							action->conf)->group;
@@ -12093,6 +12106,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 	}
 	dev_flow->dv.actions_n = actions_n;
 	dev_flow->act_flags = action_flags;
+	if (wks->skip_matcher_reg)
+		return 0;
 	/* Register matcher. */
 	matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
 				    matcher.mask.size);
Signature · 1 line
2.27.0
author
#20 lore raw

v5 cover net/mlx5: support meter policy operations

In reply to Li Zhang

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=16351 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16351

Depends-on: series=16357 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16357

V2: Add MLX5_MTR_DEFAULT_POLICY_ID in MLX5 PMD
V3: Fix comments about Depends-on
V4: Fix comments about rte_mtr_meter_policy_add.
V5: Fix comments about destory meter on different ports.

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 doc/guides/nics/mlx5.rst           |   12 +
 drivers/net/mlx5/linux/mlx5_os.c   |   13 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  212 +++-
 drivers/net/mlx5/mlx5_flow.c       |  654 ++++++++--
 drivers/net/mlx5/mlx5_flow.h       |  119 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1896 ++++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c |  742 ++++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 10 files changed, 3373 insertions(+), 363 deletions(-)
Signature · 1 line
2.27.0
author
#21 lore raw

PATCH v5 1/4 net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

Implement the next policy operations:
validate:
The driver doesn't support to configure actions in the flow after the meter action except one case when the meter policy is configured to do nothing in GREEN\YELLOW and only DROP action in RED, this special policy is called non-terminated policy and is handed as a singleton object internally.

For all the terminated policies, the next actions are supported:
GREEN - QUEUE, RSS, PORT_ID, JUMP, DROP, MARK and SET_TAG. YELLOW - not supported at all -> must be empty.
RED - must include DROP action.

Hence, in ingress case, for example,
QUEUE\RSS\JUMP must be configured as last action for GREEN color.

All the above limitations will be validated.

create:
Validate the policy configuration.
Prepare the related tables and actions.

destroy:
Release the created policy resources.

---
 drivers/net/mlx5/linux/mlx5_os.c   |    2 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  158 +++-
 drivers/net/mlx5/mlx5_flow.c       |  192 +++-
 drivers/net/mlx5/mlx5_flow.h       |   73 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1412 +++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow_meter.c |  445 ++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 9 files changed, 2242 insertions(+), 128 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +1 -1
index bec288c840..276283d492 100644
@@ -1299,7 +1299,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			log_obj_size <=
 			config->hca_attr.qos.log_meter_aso_max_alloc) {
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv);
+				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
 				if (err) {
 					err = -err;
 					goto error;
drivers/net/mlx5/mlx5.c +46 -31

110 lines not on this page · raw message

drivers/net/mlx5/mlx5.h +152 -6

203 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +185 -7

228 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +61 -12

118 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_aso.c +5 -5
index 62d2df054b..20cd4fe18c 100644
@@ -311,11 +311,11 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
 		mlx5_aso_age_init_sq(&sh->aso_age_mng->aso_sq);
 		break;
 	case ASO_OPC_MOD_POLICER:
-		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->sq, 0,
+		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->pools_mng.sq, 0,
 				  sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC,
 				  sh->sq_ts_format))
 			return -1;
-		mlx5_aso_mtr_init_sq(&sh->mtrmng->sq);
+		mlx5_aso_mtr_init_sq(&sh->mtrmng->pools_mng.sq);
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -342,7 +342,7 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,
 		sq = &sh->aso_age_mng->aso_sq;
 		break;
 	case ASO_OPC_MOD_POLICER:
-		sq = &sh->mtrmng->sq;
+		sq = &sh->mtrmng->pools_mng.sq;
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -798,7 +798,7 @@ int
 mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_wqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	do {
@@ -830,7 +830,7 @@ int
 mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_cqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	if (__atomic_load_n(&mtr->state, __ATOMIC_RELAXED) ==
drivers/net/mlx5/mlx5_flow_dv.c +1375 -37

1,532 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +416 -29

517 lines not on this page · raw message

drivers/net/mlx5/mlx5_trigger.c +1 -0
index 94dd56709e..90d918849a 100644
@@ -1179,6 +1179,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev)
 	mlx5_traffic_disable(dev);
 	/* All RX queue flags will be cleared in the flush interface. */
 	mlx5_flow_list_flush(dev, &priv->flows, true);
+	mlx5_flow_meter_flush(dev, NULL);
 	mlx5_rx_intr_vec_disable(dev);
 	priv->sh->port[priv->dev_port - 1].ih_port_id = RTE_MAX_ETHPORTS;
 	priv->sh->port[priv->dev_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS;
Signature · 1 line
2.27.0
author
#22 lore raw

PATCH v5 2/4 net/mlx5: support meter creation with policy

In reply to Li Zhang

Create a meter with the new pre-defined policy.

The following cases to be considered:
1.Add entry match with meter_id in global drop table. 2.For non-termination policy (policy id 0),
add jump rule to suffix table for green and jump rule to drop table for red.
3.Allocate counter per meter in drop table. 4.Allocate meter resource per domain per color. 5.It can work with both ASO and legacy meter HW objects.

---
 drivers/net/mlx5/linux/mlx5_os.c   |  13 +-
 drivers/net/mlx5/mlx5.h            |  62 ++---
 drivers/net/mlx5/mlx5_flow.c       |  26 +-
 drivers/net/mlx5/mlx5_flow.h       |  32 +--
 drivers/net/mlx5/mlx5_flow_dv.c    | 367 ++++++++++++++++++++---------
 drivers/net/mlx5/mlx5_flow_meter.c | 367 ++++++++++++++++++++++++-----
 6 files changed, 623 insertions(+), 244 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +7 -6
index 276283d492..c1d4e2a0dc 100644
@@ -1297,13 +1297,14 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			if (log_obj_size >=
 			config->hca_attr.qos.log_meter_aso_granularity &&
 			log_obj_size <=
-			config->hca_attr.qos.log_meter_aso_max_alloc) {
+			config->hca_attr.qos.log_meter_aso_max_alloc)
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
-				if (err) {
-					err = -err;
-					goto error;
-				}
+		}
+		if (priv->mtr_en) {
+			err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
+			if (err) {
+				err = -err;
+				goto error;
 			}
 		}
 #endif
drivers/net/mlx5/mlx5.h +19 -43

99 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +13 -13
index 81e0e3b7a9..77590bbbed 100644
@@ -4496,14 +4496,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	flow_id = tag_id - 1;
 	flow_id_bits = MLX5_REG_BITS - __builtin_clz(flow_id);
 	flow_id_bits = flow_id_bits ? flow_id_bits : 1;
-	if ((flow_id_bits + priv->max_mtr_bits) > mtr_reg_bits) {
+	if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) > mtr_reg_bits) {
 		mlx5_ipool_free(fm->flow_ipool, tag_id);
 		return rte_flow_error_set(error, EINVAL,
 				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 				"Meter flow id exceeds max limit.");
 	}
-	if (flow_id_bits > priv->max_mtr_flow_bits)
-		priv->max_mtr_flow_bits = flow_id_bits;
+	if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
+		priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
@@ -6778,15 +6778,18 @@ mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  *
  * @return
- *   Pointer to table set on success, NULL otherwise.
+ *   0 on success, -1 otherwise.
  */
-struct mlx5_meter_domains_infos *
-mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
+int
+mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			struct mlx5_flow_meter_info *fm,
+			uint32_t mtr_idx,
+			uint8_t domain_bitmap)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->create_mtr_tbls(dev);
+	return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
 }
 
 /**
@@ -6796,18 +6799,15 @@ mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  * @param[in] tbl
  *   Pointer to the meter table set.
- *
- * @return
- *   0 on success.
  */
-int
+void
 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			   struct mlx5_meter_domains_infos *tbls)
+			   struct mlx5_flow_meter_info *fm)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->destroy_mtr_tbls(dev, tbls);
+	fops->destroy_mtr_tbls(dev, fm);
 }
 
 /**
drivers/net/mlx5/mlx5_flow.h +18 -14
index 51d040c4d2..89e43f2de6 100644
@@ -222,16 +222,17 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37)
 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)
 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)
+#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
 	 MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
-	 MLX5_FLOW_ACTION_DEFAULT_MISS)
+	 MLX5_FLOW_ACTION_DEFAULT_MISS | \
+	 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
-	 MLX5_FLOW_ACTION_JUMP)
-
+	 MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
 				      MLX5_FLOW_ACTION_SET_IPV4_DST | \
@@ -832,9 +833,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
-	uint32_t meter_id;
-	/**< Meter id. */
-	uint32_t idx; /* Index to meter object. */
+	uint32_t idx;
+	/* Index to meter object. */
 };
 
 #define MLX5_MAX_TUNNELS 256
@@ -1088,10 +1088,12 @@ typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
 				 const struct rte_flow_action *actions,
 				 void *data,
 				 struct rte_flow_error *error);
-typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
-					    (struct rte_eth_dev *dev);
-typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
-					struct mlx5_meter_domains_infos *tbls);
+typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
+					struct mlx5_flow_meter_info *fm,
+					uint32_t mtr_idx,
+					uint8_t domain_bitmap);
+typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
@@ -1409,10 +1411,12 @@ int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
 				  uint16_t ether_type,
 				  const struct rte_flow_item_ecpri *acc_mask,
 				  struct rte_flow_error *error);
-struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
-					(struct rte_eth_dev *dev);
-int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			       struct mlx5_meter_domains_infos *tbl);
+int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm,
+				uint32_t mtr_idx,
+				uint8_t domain_bitmap);
+void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
+			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_shared_action_flush(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_dv.c +253 -114

463 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +313 -54

508 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#23 lore raw

PATCH v5 3/4 net/mlx5: prepare sub-policy for a flow with meter

In reply to Li Zhang

When a flow has a RSS action, the driver splits each sub flow finally is configured with
a different HW TIR action.

Any RSS action configured in meter policy may cause a split in the flow configuration.
To save performance, any TIR action will be configured in different flow table, so policy can be split to sub-policies per TIR in the flow creation time.

Create a function to prepare the policy and its sub-policies for a configured flow with meter.

---
 drivers/net/mlx5/mlx5_flow.h    |  10 +++
 drivers/net/mlx5/mlx5_flow_dv.c | 144 ++++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+)
drivers/net/mlx5/mlx5_flow.h +10 -0
index 89e43f2de6..cc9b37b9eb 100644
@@ -1095,6 +1095,11 @@ typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
 				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
+typedef struct mlx5_flow_meter_sub_policy *
+	(*mlx5_flow_meter_sub_policy_rss_prepare_t)
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1187,6 +1192,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_destroy_policy_rules_t destroy_policy_rules;
 	mlx5_flow_create_def_policy_t create_def_policy;
 	mlx5_flow_destroy_def_policy_t destroy_def_policy;
+	mlx5_flow_meter_sub_policy_rss_prepare_t meter_sub_policy_rss_prepare;
 	mlx5_flow_counter_alloc_t counter_alloc;
 	mlx5_flow_counter_free_t counter_free;
 	mlx5_flow_counter_query_t counter_query;
@@ -1418,6 +1424,10 @@ int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
+struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_rss_prepare
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_shared_action_flush(struct rte_eth_dev *dev);
 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id);
drivers/net/mlx5/mlx5_flow_dv.c +144 -0

156 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#24 lore raw

PATCH v5 4/4 net/mlx5: connect meter policy to created flows

In reply to Li Zhang

From: Shun Hao <[email protected]>

Currently ASO meter must be followed by policy table, so this adds the support that connecting meter and policy table.

There are several cases to be considered:
1. For non-termination policy, connect meter to the default policy table.
2. For non-RSS termination policy case, simply get the policy table id and connect meter to it.
3. For RSS termination policy case, need to split the flow due to RSS info in policy, and translate each sub-flow using that RSS, then create the sub policy table to be connected.
4. In termination policy case, if there's no actions to modify the packet before meter, no need to use set_tag to save meter id in register. Only add a new flow in drop table using the same match criteria as suf-flow, to save cache miss.

---
 doc/guides/nics/mlx5.rst        |  12 +
 drivers/net/mlx5/mlx5_flow.c    | 446 ++++++++++++++++++++++++++++----
 drivers/net/mlx5/mlx5_flow.h    |   4 +
 drivers/net/mlx5/mlx5_flow_dv.c |  15 ++
 4 files changed, 420 insertions(+), 57 deletions(-)
doc/guides/nics/mlx5.rst +12 -0
index d287b3aca1..1e67a91ee7 100644
@@ -106,6 +106,7 @@ Features
 - E-Switch mirroring and modify.
 - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer
   flow group.
+- Flow metering, including meter policy API.
 
 Limitations
 -----------
@@ -400,10 +401,21 @@ Limitations
   - Hairpin in switchdev SR-IOV mode is not supported till now.
 
 - Meter:
+
   - All the meter colors with drop action will be counted only by the global drop statistics.
   - Green color is not supported with drop action.
   - Yellow detection is not supported.
   - Red color must be with drop action.
+  - Meter statistics are supported only for drop case.
+  - Meter yellow color detection is not supported.
+  - A meter action created with pre-defined policy must be the last action in the flow except single case where the policy actions are:
+     - green: NULL or END.
+     - yellow: NULL or END.
+     - RED: DROP / END.
+  - The only supported meter policy actions:
+     - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
+     - yellow: must be empty.
+     - RED: must be DROP.
 
 Statistics
 ----------
drivers/net/mlx5/mlx5_flow.c +389 -57

615 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +4 -0
index cc9b37b9eb..8a0a84a604 100644
@@ -37,6 +37,8 @@ enum mlx5_rte_flow_action_type {
 	MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
 	MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET,
 	MLX5_RTE_FLOW_ACTION_TYPE_AGE,
+	MLX5_RTE_FLOW_ACTION_TYPE_JUMP,
+	MLX5_RTE_FLOW_ACTION_TYPE_COUNT,
 };
 
 #define MLX5_SHARED_ACTION_TYPE_OFFSET 30
@@ -1048,6 +1050,8 @@ struct mlx5_flow_workspace {
 	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
+	uint32_t skip_matcher_reg:1;
+	/* Indicates if need to skip matcher register in translate. */
 };
 
 struct mlx5_flow_split_info {
drivers/net/mlx5/mlx5_flow_dv.c +15 -0
index ed17bd903f..eedbe2e43b 100644
@@ -7423,6 +7423,7 @@ flow_dv_prepare(struct rte_eth_dev *dev,
 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
 
 	MLX5_ASSERT(wks);
+	wks->skip_matcher_reg = 0;
 	/* In case of corrupting the memory. */
 	if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
 		rte_flow_error_set(error, ENOSPC,
@@ -11254,6 +11255,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
 		int action_type = actions->type;
 		const struct rte_flow_action *found_action = NULL;
 		uint32_t jump_group = 0;
+		struct mlx5_flow_counter *cnt;
 
 		if (!mlx5_flow_os_action_supported(action_type))
 			return rte_flow_error_set(error, ENOTSUP,
@@ -11434,6 +11436,12 @@ flow_dv_translate(struct rte_eth_dev *dev,
 				age = action->conf;
 			action_flags |= MLX5_FLOW_ACTION_COUNT;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
+			cnt = flow_dv_counter_get_by_idx(dev,
+				(uint32_t)(uintptr_t)action->conf, NULL);
+			MLX5_ASSERT(cnt != NULL);
+			dev_flow->dv.actions[actions_n++] = cnt->action;
+			break;
 		case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
 			dev_flow->dv.actions[actions_n++] =
 						priv->sh->pop_vlan_action;
@@ -11538,6 +11546,11 @@ flow_dv_translate(struct rte_eth_dev *dev,
 			/* If decap is followed by encap, handle it at encap. */
 			action_flags |= MLX5_FLOW_ACTION_DECAP;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
+			dev_flow->dv.actions[actions_n++] =
+				(void *)(uintptr_t)action->conf;
+			action_flags |= MLX5_FLOW_ACTION_JUMP;
+			break;
 		case RTE_FLOW_ACTION_TYPE_JUMP:
 			jump_group = ((const struct rte_flow_action_jump *)
 							action->conf)->group;
@@ -12093,6 +12106,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 	}
 	dev_flow->dv.actions_n = actions_n;
 	dev_flow->act_flags = action_flags;
+	if (wks->skip_matcher_reg)
+		return 0;
 	/* Register matcher. */
 	matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
 				    matcher.mask.size);
Signature · 1 line
2.27.0
author
#25 lore raw

v6 cover net/mlx5: support meter policy operations

In reply to Li Zhang

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=16351 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16351

Depends-on: series=16389 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16389

V2: Add MLX5_MTR_DEFAULT_POLICY_ID in MLX5 PMD
V3: Fix comments about Depends-on
V4: Fix comments about rte_mtr_meter_policy_add.
V5: Fix comments about destory meter on different ports.
V6: Fix comments about Depends-on

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 doc/guides/nics/mlx5.rst           |   12 +
 drivers/net/mlx5/linux/mlx5_os.c   |   13 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  212 +++-
 drivers/net/mlx5/mlx5_flow.c       |  654 ++++++++--
 drivers/net/mlx5/mlx5_flow.h       |  119 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1896 ++++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c |  742 ++++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 10 files changed, 3373 insertions(+), 363 deletions(-)
Signature · 1 line
2.27.0
author
#26 lore raw

PATCH v6 1/4 net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

Implement the next policy operations:
validate:
The driver doesn't support to configure actions in the flow after the meter action except one case when the meter policy is configured to do nothing in GREEN\YELLOW and only DROP action in RED, this special policy is called non-terminated policy and is handed as a singleton object internally.

For all the terminated policies, the next actions are supported:
GREEN - QUEUE, RSS, PORT_ID, JUMP, DROP, MARK and SET_TAG. YELLOW - not supported at all -> must be empty.
RED - must include DROP action.

Hence, in ingress case, for example,
QUEUE\RSS\JUMP must be configured as last action for GREEN color.

All the above limitations will be validated.

create:
Validate the policy configuration.
Prepare the related tables and actions.

destroy:
Release the created policy resources.

---
 drivers/net/mlx5/linux/mlx5_os.c   |    2 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  158 +++-
 drivers/net/mlx5/mlx5_flow.c       |  192 +++-
 drivers/net/mlx5/mlx5_flow.h       |   73 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1412 +++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow_meter.c |  445 ++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 9 files changed, 2242 insertions(+), 128 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +1 -1
index bec288c840..276283d492 100644
@@ -1299,7 +1299,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			log_obj_size <=
 			config->hca_attr.qos.log_meter_aso_max_alloc) {
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv);
+				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
 				if (err) {
 					err = -err;
 					goto error;
drivers/net/mlx5/mlx5.c +46 -31

110 lines not on this page · raw message

drivers/net/mlx5/mlx5.h +152 -6

203 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +185 -7

228 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +61 -12

118 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_aso.c +5 -5
index 62d2df054b..20cd4fe18c 100644
@@ -311,11 +311,11 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
 		mlx5_aso_age_init_sq(&sh->aso_age_mng->aso_sq);
 		break;
 	case ASO_OPC_MOD_POLICER:
-		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->sq, 0,
+		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->pools_mng.sq, 0,
 				  sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC,
 				  sh->sq_ts_format))
 			return -1;
-		mlx5_aso_mtr_init_sq(&sh->mtrmng->sq);
+		mlx5_aso_mtr_init_sq(&sh->mtrmng->pools_mng.sq);
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -342,7 +342,7 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,
 		sq = &sh->aso_age_mng->aso_sq;
 		break;
 	case ASO_OPC_MOD_POLICER:
-		sq = &sh->mtrmng->sq;
+		sq = &sh->mtrmng->pools_mng.sq;
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -798,7 +798,7 @@ int
 mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_wqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	do {
@@ -830,7 +830,7 @@ int
 mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_cqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	if (__atomic_load_n(&mtr->state, __ATOMIC_RELAXED) ==
drivers/net/mlx5/mlx5_flow_dv.c +1375 -37

1,532 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +416 -29

517 lines not on this page · raw message

drivers/net/mlx5/mlx5_trigger.c +1 -0
index 94dd56709e..90d918849a 100644
@@ -1179,6 +1179,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev)
 	mlx5_traffic_disable(dev);
 	/* All RX queue flags will be cleared in the flush interface. */
 	mlx5_flow_list_flush(dev, &priv->flows, true);
+	mlx5_flow_meter_flush(dev, NULL);
 	mlx5_rx_intr_vec_disable(dev);
 	priv->sh->port[priv->dev_port - 1].ih_port_id = RTE_MAX_ETHPORTS;
 	priv->sh->port[priv->dev_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS;
Signature · 1 line
2.27.0
author
#27 lore raw

PATCH v6 2/4 net/mlx5: support meter creation with policy

In reply to Li Zhang

Create a meter with the new pre-defined policy.

The following cases to be considered:
1.Add entry match with meter_id in global drop table. 2.For non-termination policy (policy id 0),
add jump rule to suffix table for green and jump rule to drop table for red.
3.Allocate counter per meter in drop table. 4.Allocate meter resource per domain per color. 5.It can work with both ASO and legacy meter HW objects.

---
 drivers/net/mlx5/linux/mlx5_os.c   |  13 +-
 drivers/net/mlx5/mlx5.h            |  62 ++---
 drivers/net/mlx5/mlx5_flow.c       |  26 +-
 drivers/net/mlx5/mlx5_flow.h       |  32 +--
 drivers/net/mlx5/mlx5_flow_dv.c    | 367 ++++++++++++++++++++---------
 drivers/net/mlx5/mlx5_flow_meter.c | 367 ++++++++++++++++++++++++-----
 6 files changed, 623 insertions(+), 244 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +7 -6
index 276283d492..c1d4e2a0dc 100644
@@ -1297,13 +1297,14 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			if (log_obj_size >=
 			config->hca_attr.qos.log_meter_aso_granularity &&
 			log_obj_size <=
-			config->hca_attr.qos.log_meter_aso_max_alloc) {
+			config->hca_attr.qos.log_meter_aso_max_alloc)
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
-				if (err) {
-					err = -err;
-					goto error;
-				}
+		}
+		if (priv->mtr_en) {
+			err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
+			if (err) {
+				err = -err;
+				goto error;
 			}
 		}
 #endif
drivers/net/mlx5/mlx5.h +19 -43

99 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +13 -13
index 81e0e3b7a9..77590bbbed 100644
@@ -4496,14 +4496,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	flow_id = tag_id - 1;
 	flow_id_bits = MLX5_REG_BITS - __builtin_clz(flow_id);
 	flow_id_bits = flow_id_bits ? flow_id_bits : 1;
-	if ((flow_id_bits + priv->max_mtr_bits) > mtr_reg_bits) {
+	if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) > mtr_reg_bits) {
 		mlx5_ipool_free(fm->flow_ipool, tag_id);
 		return rte_flow_error_set(error, EINVAL,
 				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 				"Meter flow id exceeds max limit.");
 	}
-	if (flow_id_bits > priv->max_mtr_flow_bits)
-		priv->max_mtr_flow_bits = flow_id_bits;
+	if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
+		priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
@@ -6778,15 +6778,18 @@ mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  *
  * @return
- *   Pointer to table set on success, NULL otherwise.
+ *   0 on success, -1 otherwise.
  */
-struct mlx5_meter_domains_infos *
-mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
+int
+mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			struct mlx5_flow_meter_info *fm,
+			uint32_t mtr_idx,
+			uint8_t domain_bitmap)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->create_mtr_tbls(dev);
+	return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
 }
 
 /**
@@ -6796,18 +6799,15 @@ mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  * @param[in] tbl
  *   Pointer to the meter table set.
- *
- * @return
- *   0 on success.
  */
-int
+void
 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			   struct mlx5_meter_domains_infos *tbls)
+			   struct mlx5_flow_meter_info *fm)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->destroy_mtr_tbls(dev, tbls);
+	fops->destroy_mtr_tbls(dev, fm);
 }
 
 /**
drivers/net/mlx5/mlx5_flow.h +18 -14
index 51d040c4d2..89e43f2de6 100644
@@ -222,16 +222,17 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37)
 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)
 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)
+#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
 	 MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
-	 MLX5_FLOW_ACTION_DEFAULT_MISS)
+	 MLX5_FLOW_ACTION_DEFAULT_MISS | \
+	 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
-	 MLX5_FLOW_ACTION_JUMP)
-
+	 MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
 				      MLX5_FLOW_ACTION_SET_IPV4_DST | \
@@ -832,9 +833,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
-	uint32_t meter_id;
-	/**< Meter id. */
-	uint32_t idx; /* Index to meter object. */
+	uint32_t idx;
+	/* Index to meter object. */
 };
 
 #define MLX5_MAX_TUNNELS 256
@@ -1088,10 +1088,12 @@ typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
 				 const struct rte_flow_action *actions,
 				 void *data,
 				 struct rte_flow_error *error);
-typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
-					    (struct rte_eth_dev *dev);
-typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
-					struct mlx5_meter_domains_infos *tbls);
+typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
+					struct mlx5_flow_meter_info *fm,
+					uint32_t mtr_idx,
+					uint8_t domain_bitmap);
+typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
@@ -1409,10 +1411,12 @@ int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
 				  uint16_t ether_type,
 				  const struct rte_flow_item_ecpri *acc_mask,
 				  struct rte_flow_error *error);
-struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
-					(struct rte_eth_dev *dev);
-int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			       struct mlx5_meter_domains_infos *tbl);
+int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm,
+				uint32_t mtr_idx,
+				uint8_t domain_bitmap);
+void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
+			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_shared_action_flush(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_dv.c +253 -114

463 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +313 -54

508 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#28 lore raw

PATCH v6 3/4 net/mlx5: prepare sub-policy for a flow with meter

In reply to Li Zhang

When a flow has a RSS action, the driver splits each sub flow finally is configured with
a different HW TIR action.

Any RSS action configured in meter policy may cause a split in the flow configuration.
To save performance, any TIR action will be configured in different flow table, so policy can be split to sub-policies per TIR in the flow creation time.

Create a function to prepare the policy and its sub-policies for a configured flow with meter.

---
 drivers/net/mlx5/mlx5_flow.h    |  10 +++
 drivers/net/mlx5/mlx5_flow_dv.c | 144 ++++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+)
drivers/net/mlx5/mlx5_flow.h +10 -0
index 89e43f2de6..cc9b37b9eb 100644
@@ -1095,6 +1095,11 @@ typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
 				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
+typedef struct mlx5_flow_meter_sub_policy *
+	(*mlx5_flow_meter_sub_policy_rss_prepare_t)
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1187,6 +1192,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_destroy_policy_rules_t destroy_policy_rules;
 	mlx5_flow_create_def_policy_t create_def_policy;
 	mlx5_flow_destroy_def_policy_t destroy_def_policy;
+	mlx5_flow_meter_sub_policy_rss_prepare_t meter_sub_policy_rss_prepare;
 	mlx5_flow_counter_alloc_t counter_alloc;
 	mlx5_flow_counter_free_t counter_free;
 	mlx5_flow_counter_query_t counter_query;
@@ -1418,6 +1424,10 @@ int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
+struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_rss_prepare
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_shared_action_flush(struct rte_eth_dev *dev);
 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id);
drivers/net/mlx5/mlx5_flow_dv.c +144 -0

156 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#29 lore raw

PATCH v6 4/4 net/mlx5: connect meter policy to created flows

In reply to Li Zhang

From: Shun Hao <[email protected]>

Currently ASO meter must be followed by policy table, so this adds the support that connecting meter and policy table.

There are several cases to be considered:
1. For non-termination policy, connect meter to the default policy table.
2. For non-RSS termination policy case, simply get the policy table id and connect meter to it.
3. For RSS termination policy case, need to split the flow due to RSS info in policy, and translate each sub-flow using that RSS, then create the sub policy table to be connected.
4. In termination policy case, if there's no actions to modify the packet before meter, no need to use set_tag to save meter id in register. Only add a new flow in drop table using the same match criteria as suf-flow, to save cache miss.

---
 doc/guides/nics/mlx5.rst        |  12 +
 drivers/net/mlx5/mlx5_flow.c    | 446 ++++++++++++++++++++++++++++----
 drivers/net/mlx5/mlx5_flow.h    |   4 +
 drivers/net/mlx5/mlx5_flow_dv.c |  15 ++
 4 files changed, 420 insertions(+), 57 deletions(-)
doc/guides/nics/mlx5.rst +12 -0
index d287b3aca1..1e67a91ee7 100644
@@ -106,6 +106,7 @@ Features
 - E-Switch mirroring and modify.
 - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer
   flow group.
+- Flow metering, including meter policy API.
 
 Limitations
 -----------
@@ -400,10 +401,21 @@ Limitations
   - Hairpin in switchdev SR-IOV mode is not supported till now.
 
 - Meter:
+
   - All the meter colors with drop action will be counted only by the global drop statistics.
   - Green color is not supported with drop action.
   - Yellow detection is not supported.
   - Red color must be with drop action.
+  - Meter statistics are supported only for drop case.
+  - Meter yellow color detection is not supported.
+  - A meter action created with pre-defined policy must be the last action in the flow except single case where the policy actions are:
+     - green: NULL or END.
+     - yellow: NULL or END.
+     - RED: DROP / END.
+  - The only supported meter policy actions:
+     - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
+     - yellow: must be empty.
+     - RED: must be DROP.
 
 Statistics
 ----------
drivers/net/mlx5/mlx5_flow.c +389 -57

615 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +4 -0
index cc9b37b9eb..8a0a84a604 100644
@@ -37,6 +37,8 @@ enum mlx5_rte_flow_action_type {
 	MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
 	MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET,
 	MLX5_RTE_FLOW_ACTION_TYPE_AGE,
+	MLX5_RTE_FLOW_ACTION_TYPE_JUMP,
+	MLX5_RTE_FLOW_ACTION_TYPE_COUNT,
 };
 
 #define MLX5_SHARED_ACTION_TYPE_OFFSET 30
@@ -1048,6 +1050,8 @@ struct mlx5_flow_workspace {
 	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
+	uint32_t skip_matcher_reg:1;
+	/* Indicates if need to skip matcher register in translate. */
 };
 
 struct mlx5_flow_split_info {
drivers/net/mlx5/mlx5_flow_dv.c +15 -0
index ed17bd903f..eedbe2e43b 100644
@@ -7423,6 +7423,7 @@ flow_dv_prepare(struct rte_eth_dev *dev,
 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
 
 	MLX5_ASSERT(wks);
+	wks->skip_matcher_reg = 0;
 	/* In case of corrupting the memory. */
 	if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
 		rte_flow_error_set(error, ENOSPC,
@@ -11254,6 +11255,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
 		int action_type = actions->type;
 		const struct rte_flow_action *found_action = NULL;
 		uint32_t jump_group = 0;
+		struct mlx5_flow_counter *cnt;
 
 		if (!mlx5_flow_os_action_supported(action_type))
 			return rte_flow_error_set(error, ENOTSUP,
@@ -11434,6 +11436,12 @@ flow_dv_translate(struct rte_eth_dev *dev,
 				age = action->conf;
 			action_flags |= MLX5_FLOW_ACTION_COUNT;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
+			cnt = flow_dv_counter_get_by_idx(dev,
+				(uint32_t)(uintptr_t)action->conf, NULL);
+			MLX5_ASSERT(cnt != NULL);
+			dev_flow->dv.actions[actions_n++] = cnt->action;
+			break;
 		case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
 			dev_flow->dv.actions[actions_n++] =
 						priv->sh->pop_vlan_action;
@@ -11538,6 +11546,11 @@ flow_dv_translate(struct rte_eth_dev *dev,
 			/* If decap is followed by encap, handle it at encap. */
 			action_flags |= MLX5_FLOW_ACTION_DECAP;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
+			dev_flow->dv.actions[actions_n++] =
+				(void *)(uintptr_t)action->conf;
+			action_flags |= MLX5_FLOW_ACTION_JUMP;
+			break;
 		case RTE_FLOW_ACTION_TYPE_JUMP:
 			jump_group = ((const struct rte_flow_action_jump *)
 							action->conf)->group;
@@ -12093,6 +12106,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 	}
 	dev_flow->dv.actions_n = actions_n;
 	dev_flow->act_flags = action_flags;
+	if (wks->skip_matcher_reg)
+		return 0;
 	/* Register matcher. */
 	matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
 				    matcher.mask.size);
Signature · 1 line
2.27.0
author
#30 lore raw

v7 cover net/mlx5: support meter policy operations

In reply to Li Zhang

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=16520 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16520

Depends-on: series=16524 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16524

v7:
* Rebase.
V6:
* Fix comments about Depends-on.
V5:
* Fix comments about destory meter on different ports. V4:
* Fix comments about rte_mtr_meter_policy_add. V3:
* Fix comments about Depends-on.
V2:
* Add MLX5_MTR_DEFAULT_POLICY_ID in MLX5 PMD.

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 doc/guides/nics/mlx5.rst           |   12 +
 drivers/net/mlx5/linux/mlx5_os.c   |   13 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  212 +++-
 drivers/net/mlx5/mlx5_flow.c       |  654 ++++++++--
 drivers/net/mlx5/mlx5_flow.h       |  119 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1896 ++++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c |  742 ++++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 10 files changed, 3373 insertions(+), 363 deletions(-)
Signature · 1 line
2.27.0
author
#31 lore raw

PATCH v7 1/4 net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

Implement the next policy operations:
validate:
The driver doesn't support to configure actions in the flow after the meter action except one case when the meter policy is configured to do nothing in GREEN\YELLOW and only DROP action in RED, this special policy is called non-terminated policy and is handed as a singleton object internally.

For all the terminated policies, the next actions are supported:
GREEN - QUEUE, RSS, PORT_ID, JUMP, DROP, MARK and SET_TAG. YELLOW - not supported at all -> must be empty.
RED - must include DROP action.

Hence, in ingress case, for example,
QUEUE\RSS\JUMP must be configured as last action for GREEN color.

All the above limitations will be validated.

create:
Validate the policy configuration.
Prepare the related tables and actions.

destroy:
Release the created policy resources.

---
 drivers/net/mlx5/linux/mlx5_os.c   |    2 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  158 +++-
 drivers/net/mlx5/mlx5_flow.c       |  192 +++-
 drivers/net/mlx5/mlx5_flow.h       |   73 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1412 +++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow_meter.c |  445 ++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 9 files changed, 2242 insertions(+), 128 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +1 -1
index 41622c1bf7..8206640aa4 100644
@@ -1301,7 +1301,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			log_obj_size <=
 			config->hca_attr.qos.log_meter_aso_max_alloc) {
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv);
+				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
 				if (err) {
 					err = -err;
 					goto error;
drivers/net/mlx5/mlx5.c +46 -31

110 lines not on this page · raw message

drivers/net/mlx5/mlx5.h +152 -6

203 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +185 -7

228 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +61 -12

118 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_aso.c +5 -5
index 62d2df054b..20cd4fe18c 100644
@@ -311,11 +311,11 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
 		mlx5_aso_age_init_sq(&sh->aso_age_mng->aso_sq);
 		break;
 	case ASO_OPC_MOD_POLICER:
-		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->sq, 0,
+		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->pools_mng.sq, 0,
 				  sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC,
 				  sh->sq_ts_format))
 			return -1;
-		mlx5_aso_mtr_init_sq(&sh->mtrmng->sq);
+		mlx5_aso_mtr_init_sq(&sh->mtrmng->pools_mng.sq);
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -342,7 +342,7 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,
 		sq = &sh->aso_age_mng->aso_sq;
 		break;
 	case ASO_OPC_MOD_POLICER:
-		sq = &sh->mtrmng->sq;
+		sq = &sh->mtrmng->pools_mng.sq;
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -798,7 +798,7 @@ int
 mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_wqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	do {
@@ -830,7 +830,7 @@ int
 mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_cqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	if (__atomic_load_n(&mtr->state, __ATOMIC_RELAXED) ==
drivers/net/mlx5/mlx5_flow_dv.c +1375 -37

1,532 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +416 -29

517 lines not on this page · raw message

drivers/net/mlx5/mlx5_trigger.c +1 -0
index 001c0b5311..eb8c99cd93 100644
@@ -1180,6 +1180,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev)
 	mlx5_traffic_disable(dev);
 	/* All RX queue flags will be cleared in the flush interface. */
 	mlx5_flow_list_flush(dev, &priv->flows, true);
+	mlx5_flow_meter_flush(dev, NULL);
 	mlx5_rx_intr_vec_disable(dev);
 	priv->sh->port[priv->dev_port - 1].ih_port_id = RTE_MAX_ETHPORTS;
 	priv->sh->port[priv->dev_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS;
Signature · 1 line
2.27.0
author
#32 lore raw

PATCH v7 2/4 net/mlx5: support meter creation with policy

In reply to Li Zhang

Create a meter with the new pre-defined policy.

The following cases to be considered:
1.Add entry match with meter_id in global drop table. 2.For non-termination policy (policy id 0),
add jump rule to suffix table for green and jump rule to drop table for red.
3.Allocate counter per meter in drop table. 4.Allocate meter resource per domain per color. 5.It can work with both ASO and legacy meter HW objects.

---
 drivers/net/mlx5/linux/mlx5_os.c   |  13 +-
 drivers/net/mlx5/mlx5.h            |  62 ++---
 drivers/net/mlx5/mlx5_flow.c       |  26 +-
 drivers/net/mlx5/mlx5_flow.h       |  32 +--
 drivers/net/mlx5/mlx5_flow_dv.c    | 367 ++++++++++++++++++++---------
 drivers/net/mlx5/mlx5_flow_meter.c | 367 ++++++++++++++++++++++++-----
 6 files changed, 623 insertions(+), 244 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +7 -6
index 8206640aa4..17d0533c1b 100644
@@ -1299,13 +1299,14 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			if (log_obj_size >=
 			config->hca_attr.qos.log_meter_aso_granularity &&
 			log_obj_size <=
-			config->hca_attr.qos.log_meter_aso_max_alloc) {
+			config->hca_attr.qos.log_meter_aso_max_alloc)
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
-				if (err) {
-					err = -err;
-					goto error;
-				}
+		}
+		if (priv->mtr_en) {
+			err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
+			if (err) {
+				err = -err;
+				goto error;
 			}
 		}
 #endif
drivers/net/mlx5/mlx5.h +19 -43

99 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +13 -13
index 6a69c053a4..23f5cde4ad 100644
@@ -4496,14 +4496,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	flow_id = tag_id - 1;
 	flow_id_bits = MLX5_REG_BITS - __builtin_clz(flow_id);
 	flow_id_bits = flow_id_bits ? flow_id_bits : 1;
-	if ((flow_id_bits + priv->max_mtr_bits) > mtr_reg_bits) {
+	if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) > mtr_reg_bits) {
 		mlx5_ipool_free(fm->flow_ipool, tag_id);
 		return rte_flow_error_set(error, EINVAL,
 				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 				"Meter flow id exceeds max limit.");
 	}
-	if (flow_id_bits > priv->max_mtr_flow_bits)
-		priv->max_mtr_flow_bits = flow_id_bits;
+	if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
+		priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
@@ -6786,15 +6786,18 @@ mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  *
  * @return
- *   Pointer to table set on success, NULL otherwise.
+ *   0 on success, -1 otherwise.
  */
-struct mlx5_meter_domains_infos *
-mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
+int
+mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			struct mlx5_flow_meter_info *fm,
+			uint32_t mtr_idx,
+			uint8_t domain_bitmap)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->create_mtr_tbls(dev);
+	return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
 }
 
 /**
@@ -6804,18 +6807,15 @@ mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  * @param[in] tbl
  *   Pointer to the meter table set.
- *
- * @return
- *   0 on success.
  */
-int
+void
 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			   struct mlx5_meter_domains_infos *tbls)
+			   struct mlx5_flow_meter_info *fm)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->destroy_mtr_tbls(dev, tbls);
+	fops->destroy_mtr_tbls(dev, fm);
 }
 
 /**
drivers/net/mlx5/mlx5_flow.h +18 -14
index f0509b14b0..98f6132332 100644
@@ -221,16 +221,17 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37)
 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)
 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)
+#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
 	 MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
-	 MLX5_FLOW_ACTION_DEFAULT_MISS)
+	 MLX5_FLOW_ACTION_DEFAULT_MISS | \
+	 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
-	 MLX5_FLOW_ACTION_JUMP)
-
+	 MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
 				      MLX5_FLOW_ACTION_SET_IPV4_DST | \
@@ -831,9 +832,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
-	uint32_t meter_id;
-	/**< Meter id. */
-	uint32_t idx; /* Index to meter object. */
+	uint32_t idx;
+	/* Index to meter object. */
 };
 
 #define MLX5_MAX_TUNNELS 256
@@ -1087,10 +1087,12 @@ typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
 				 const struct rte_flow_action *actions,
 				 void *data,
 				 struct rte_flow_error *error);
-typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
-					    (struct rte_eth_dev *dev);
-typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
-					struct mlx5_meter_domains_infos *tbls);
+typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
+					struct mlx5_flow_meter_info *fm,
+					uint32_t mtr_idx,
+					uint8_t domain_bitmap);
+typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
@@ -1408,10 +1410,12 @@ int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
 				  uint16_t ether_type,
 				  const struct rte_flow_item_ecpri *acc_mask,
 				  struct rte_flow_error *error);
-struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
-					(struct rte_eth_dev *dev);
-int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			       struct mlx5_meter_domains_infos *tbl);
+int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			      struct mlx5_flow_meter_info *fm,
+			      uint32_t mtr_idx,
+			      uint8_t domain_bitmap);
+void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
+			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_action_handle_flush(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_dv.c +253 -114

463 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +313 -54

508 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#33 lore raw

PATCH v7 3/4 net/mlx5: prepare sub-policy for a flow with meter

In reply to Li Zhang

When a flow has a RSS action, the driver splits each sub flow finally is configured with
a different HW TIR action.

Any RSS action configured in meter policy may cause a split in the flow configuration.
To save performance, any TIR action will be configured in different flow table, so policy can be split to sub-policies per TIR in the flow creation time.

Create a function to prepare the policy and its sub-policies for a configured flow with meter.

---
 drivers/net/mlx5/mlx5_flow.h    |  10 +++
 drivers/net/mlx5/mlx5_flow_dv.c | 144 ++++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+)
drivers/net/mlx5/mlx5_flow.h +10 -0
index 98f6132332..a80c7903a2 100644
@@ -1094,6 +1094,11 @@ typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
 				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
+typedef struct mlx5_flow_meter_sub_policy *
+	(*mlx5_flow_meter_sub_policy_rss_prepare_t)
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1186,6 +1191,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_destroy_policy_rules_t destroy_policy_rules;
 	mlx5_flow_create_def_policy_t create_def_policy;
 	mlx5_flow_destroy_def_policy_t destroy_def_policy;
+	mlx5_flow_meter_sub_policy_rss_prepare_t meter_sub_policy_rss_prepare;
 	mlx5_flow_counter_alloc_t counter_alloc;
 	mlx5_flow_counter_free_t counter_free;
 	mlx5_flow_counter_query_t counter_query;
@@ -1417,6 +1423,10 @@ int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
+struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_rss_prepare
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_action_handle_flush(struct rte_eth_dev *dev);
 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id);
drivers/net/mlx5/mlx5_flow_dv.c +144 -0

156 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#34 lore raw

PATCH v7 4/4 net/mlx5: connect meter policy to created flows

In reply to Li Zhang

From: Shun Hao <[email protected]>

Currently ASO meter must be followed by policy table, so this adds the support that connecting meter and policy table.

There are several cases to be considered:
1. For non-termination policy, connect meter to the default policy table.
2. For non-RSS termination policy case, simply get the policy table id and connect meter to it.
3. For RSS termination policy case, need to split the flow due to RSS info in policy, and translate each sub-flow using that RSS, then create the sub policy table to be connected.
4. In termination policy case, if there's no actions to modify the packet before meter, no need to use set_tag to save meter id in register. Only add a new flow in drop table using the same match criteria as suf-flow, to save cache miss.

---
 doc/guides/nics/mlx5.rst        |  12 +
 drivers/net/mlx5/mlx5_flow.c    | 446 ++++++++++++++++++++++++++++----
 drivers/net/mlx5/mlx5_flow.h    |   4 +
 drivers/net/mlx5/mlx5_flow_dv.c |  15 ++
 4 files changed, 420 insertions(+), 57 deletions(-)
doc/guides/nics/mlx5.rst +12 -0
index 98817e93cd..b27a9a69f6 100644
@@ -106,6 +106,7 @@ Features
 - E-Switch mirroring and modify.
 - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer
   flow group.
+- Flow metering, including meter policy API.
 
 Limitations
 -----------
@@ -400,10 +401,21 @@ Limitations
   - Hairpin in switchdev SR-IOV mode is not supported till now.
 
 - Meter:
+
   - All the meter colors with drop action will be counted only by the global drop statistics.
   - Green color is not supported with drop action.
   - Yellow detection is not supported.
   - Red color must be with drop action.
+  - Meter statistics are supported only for drop case.
+  - Meter yellow color detection is not supported.
+  - A meter action created with pre-defined policy must be the last action in the flow except single case where the policy actions are:
+     - green: NULL or END.
+     - yellow: NULL or END.
+     - RED: DROP / END.
+  - The only supported meter policy actions:
+     - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
+     - yellow: must be empty.
+     - RED: must be DROP.
 
 Statistics
 ----------
drivers/net/mlx5/mlx5_flow.c +389 -57

615 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +4 -0
index a80c7903a2..56908ae08b 100644
@@ -36,6 +36,8 @@ enum mlx5_rte_flow_action_type {
 	MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
 	MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET,
 	MLX5_RTE_FLOW_ACTION_TYPE_AGE,
+	MLX5_RTE_FLOW_ACTION_TYPE_JUMP,
+	MLX5_RTE_FLOW_ACTION_TYPE_COUNT,
 };
 
 #define MLX5_INDIRECT_ACTION_TYPE_OFFSET 30
@@ -1047,6 +1049,8 @@ struct mlx5_flow_workspace {
 	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
+	uint32_t skip_matcher_reg:1;
+	/* Indicates if need to skip matcher register in translate. */
 };
 
 struct mlx5_flow_split_info {
drivers/net/mlx5/mlx5_flow_dv.c +15 -0
index 0fb8f519fe..b07c135c32 100644
@@ -7439,6 +7439,7 @@ flow_dv_prepare(struct rte_eth_dev *dev,
 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
 
 	MLX5_ASSERT(wks);
+	wks->skip_matcher_reg = 0;
 	/* In case of corrupting the memory. */
 	if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
 		rte_flow_error_set(error, ENOSPC,
@@ -11270,6 +11271,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
 		int action_type = actions->type;
 		const struct rte_flow_action *found_action = NULL;
 		uint32_t jump_group = 0;
+		struct mlx5_flow_counter *cnt;
 
 		if (!mlx5_flow_os_action_supported(action_type))
 			return rte_flow_error_set(error, ENOTSUP,
@@ -11450,6 +11452,12 @@ flow_dv_translate(struct rte_eth_dev *dev,
 				age = action->conf;
 			action_flags |= MLX5_FLOW_ACTION_COUNT;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
+			cnt = flow_dv_counter_get_by_idx(dev,
+				(uint32_t)(uintptr_t)action->conf, NULL);
+			MLX5_ASSERT(cnt != NULL);
+			dev_flow->dv.actions[actions_n++] = cnt->action;
+			break;
 		case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
 			dev_flow->dv.actions[actions_n++] =
 						priv->sh->pop_vlan_action;
@@ -11554,6 +11562,11 @@ flow_dv_translate(struct rte_eth_dev *dev,
 			/* If decap is followed by encap, handle it at encap. */
 			action_flags |= MLX5_FLOW_ACTION_DECAP;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
+			dev_flow->dv.actions[actions_n++] =
+				(void *)(uintptr_t)action->conf;
+			action_flags |= MLX5_FLOW_ACTION_JUMP;
+			break;
 		case RTE_FLOW_ACTION_TYPE_JUMP:
 			jump_group = ((const struct rte_flow_action_jump *)
 							action->conf)->group;
@@ -12109,6 +12122,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 	}
 	dev_flow->dv.actions_n = actions_n;
 	dev_flow->act_flags = action_flags;
+	if (wks->skip_matcher_reg)
+		return 0;
 	/* Register matcher. */
 	matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
 				    matcher.mask.size);
Signature · 1 line
2.27.0
#35 lore raw
In reply to Li Zhang

Hi,

Quoted 73 lines

-----Original Message-----
From: Li Zhang <[email protected]>
Sent: Wednesday, April 21, 2021 6:12 AM
To: [email protected]; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>
Cc: [email protected]; NBU-Contact-Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; Roni Bar Yanai <[email protected]>
Subject: [PATCH v7 0/4] net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG
actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=16520 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16520

Depends-on: series=16524 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16524

v7:
* Rebase.
V6:
* Fix comments about Depends-on.
V5:
* Fix comments about destory meter on different ports. V4:
* Fix comments about rte_mtr_meter_policy_add. V3:
* Fix comments about Depends-on.
V2:
* Add MLX5_MTR_DEFAULT_POLICY_ID in MLX5 PMD.

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 doc/guides/nics/mlx5.rst           |   12 +
 drivers/net/mlx5/linux/mlx5_os.c   |   13 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  212 +++-
 drivers/net/mlx5/mlx5_flow.c       |  654 ++++++++--
 drivers/net/mlx5/mlx5_flow.h       |  119 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1896
++++++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c |  742 ++++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 10 files changed, 3373 insertions(+), 363 deletions(-)
Quoted 2 lines

--
2.27.0

Series applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh

author
#36 lore raw

v8 cover net/mlx5: support meter policy operations

In reply to Li Zhang

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table. Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=16520 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16520

Depends-on: series=16524 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16524

V8:
* Fix comments about release-note
v7:
* Rebase.
V6:
* Fix comments about Depends-on.
V5:
* Fix comments about destory meter on different ports. V4:
* Fix comments about rte_mtr_meter_policy_add. V3:
* Fix comments about Depends-on.
V2:
* Add MLX5_MTR_DEFAULT_POLICY_ID in MLX5 PMD.

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 doc/guides/nics/mlx5.rst               |   12 +
 doc/guides/rel_notes/release_21_05.rst |    1 +
 drivers/net/mlx5/linux/mlx5_os.c       |   13 +-
 drivers/net/mlx5/mlx5.c                |   77 +-
 drivers/net/mlx5/mlx5.h                |  212 ++-
 drivers/net/mlx5/mlx5_flow.c           |  654 +++++++-
 drivers/net/mlx5/mlx5_flow.h           |  119 +-
 drivers/net/mlx5/mlx5_flow_aso.c       |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c        | 1895 ++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c     |  742 +++++++++-
 drivers/net/mlx5/mlx5_trigger.c        |    1 +
 11 files changed, 3373 insertions(+), 363 deletions(-)
Signature · 1 line
2.27.0
author
#37 lore raw

PATCH v8 1/4 net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no-termination policy.

Implement the next policy operations:
validate:
The driver doesn't support to configure actions in the flow after the meter action except one case when the meter policy is configured to do nothing in GREEN\YELLOW and only DROP action in RED, this special policy is called non-terminated policy and is handed as a singleton object internally.

For all the terminated policies, the next actions are supported:
GREEN - QUEUE, RSS, PORT_ID, JUMP, DROP, MARK and SET_TAG. YELLOW - not supported at all -> must be empty.
RED - must include DROP action.

Hence, in ingress case, for example,
QUEUE\RSS\JUMP must be configured as last action for GREEN color.

All the above limitations will be validated.

create:
Validate the policy configuration.
Prepare the related tables and actions.

destroy:
Release the created policy resources.

---
 drivers/net/mlx5/linux/mlx5_os.c   |    2 +-
 drivers/net/mlx5/mlx5.c            |   77 +-
 drivers/net/mlx5/mlx5.h            |  158 +++-
 drivers/net/mlx5/mlx5_flow.c       |  192 +++-
 drivers/net/mlx5/mlx5_flow.h       |   73 +-
 drivers/net/mlx5/mlx5_flow_aso.c   |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c    | 1412 +++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow_meter.c |  445 ++++++++-
 drivers/net/mlx5/mlx5_trigger.c    |    1 +
 9 files changed, 2242 insertions(+), 128 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +1 -1
index 41622c1bf7..8206640aa4 100644
@@ -1301,7 +1301,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			log_obj_size <=
 			config->hca_attr.qos.log_meter_aso_max_alloc) {
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv);
+				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
 				if (err) {
 					err = -err;
 					goto error;
drivers/net/mlx5/mlx5.c +46 -31

110 lines not on this page · raw message

drivers/net/mlx5/mlx5.h +152 -6

203 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +185 -7

228 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +61 -12

118 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_aso.c +5 -5
index 62d2df054b..20cd4fe18c 100644
@@ -311,11 +311,11 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
 		mlx5_aso_age_init_sq(&sh->aso_age_mng->aso_sq);
 		break;
 	case ASO_OPC_MOD_POLICER:
-		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->sq, 0,
+		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->pools_mng.sq, 0,
 				  sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC,
 				  sh->sq_ts_format))
 			return -1;
-		mlx5_aso_mtr_init_sq(&sh->mtrmng->sq);
+		mlx5_aso_mtr_init_sq(&sh->mtrmng->pools_mng.sq);
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -342,7 +342,7 @@ mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,
 		sq = &sh->aso_age_mng->aso_sq;
 		break;
 	case ASO_OPC_MOD_POLICER:
-		sq = &sh->mtrmng->sq;
+		sq = &sh->mtrmng->pools_mng.sq;
 		break;
 	default:
 		DRV_LOG(ERR, "Unknown ASO operation mode");
@@ -798,7 +798,7 @@ int
 mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_wqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	do {
@@ -830,7 +830,7 @@ int
 mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 			struct mlx5_aso_mtr *mtr)
 {
-	struct mlx5_aso_sq *sq = &sh->mtrmng->sq;
+	struct mlx5_aso_sq *sq = &sh->mtrmng->pools_mng.sq;
 	uint32_t poll_cqe_times = MLX5_MTR_POLL_WQE_CQE_TIMES;
 
 	if (__atomic_load_n(&mtr->state, __ATOMIC_RELAXED) ==
drivers/net/mlx5/mlx5_flow_dv.c +1375 -37

1,532 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +416 -29

517 lines not on this page · raw message

drivers/net/mlx5/mlx5_trigger.c +1 -0
index 001c0b5311..eb8c99cd93 100644
@@ -1180,6 +1180,7 @@ mlx5_dev_stop(struct rte_eth_dev *dev)
 	mlx5_traffic_disable(dev);
 	/* All RX queue flags will be cleared in the flush interface. */
 	mlx5_flow_list_flush(dev, &priv->flows, true);
+	mlx5_flow_meter_flush(dev, NULL);
 	mlx5_rx_intr_vec_disable(dev);
 	priv->sh->port[priv->dev_port - 1].ih_port_id = RTE_MAX_ETHPORTS;
 	priv->sh->port[priv->dev_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS;
Signature · 1 line
2.27.0
author
#38 lore raw

PATCH v8 2/4 net/mlx5: support meter creation with policy

In reply to Li Zhang

Create a meter with the new pre-defined policy.

The following cases to be considered:
1.Add entry match with meter_id in global drop table. 2.For non-termination policy (policy id 0),
add jump rule to suffix table for green and jump rule to drop table for red.
3.Allocate counter per meter in drop table. 4.Allocate meter resource per domain per color. 5.It can work with both ASO and legacy meter HW objects.

---
 drivers/net/mlx5/linux/mlx5_os.c   |  13 +-
 drivers/net/mlx5/mlx5.h            |  62 ++---
 drivers/net/mlx5/mlx5_flow.c       |  26 +-
 drivers/net/mlx5/mlx5_flow.h       |  32 +--
 drivers/net/mlx5/mlx5_flow_dv.c    | 365 +++++++++++++++++++---------
 drivers/net/mlx5/mlx5_flow_meter.c | 367 ++++++++++++++++++++++++-----
 6 files changed, 621 insertions(+), 244 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +7 -6
index 8206640aa4..17d0533c1b 100644
@@ -1299,13 +1299,14 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			if (log_obj_size >=
 			config->hca_attr.qos.log_meter_aso_granularity &&
 			log_obj_size <=
-			config->hca_attr.qos.log_meter_aso_max_alloc) {
+			config->hca_attr.qos.log_meter_aso_max_alloc)
 				sh->meter_aso_en = 1;
-				err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
-				if (err) {
-					err = -err;
-					goto error;
-				}
+		}
+		if (priv->mtr_en) {
+			err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
+			if (err) {
+				err = -err;
+				goto error;
 			}
 		}
 #endif
drivers/net/mlx5/mlx5.h +19 -43

99 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.c +13 -13
index 6a69c053a4..23f5cde4ad 100644
@@ -4496,14 +4496,14 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
 	flow_id = tag_id - 1;
 	flow_id_bits = MLX5_REG_BITS - __builtin_clz(flow_id);
 	flow_id_bits = flow_id_bits ? flow_id_bits : 1;
-	if ((flow_id_bits + priv->max_mtr_bits) > mtr_reg_bits) {
+	if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) > mtr_reg_bits) {
 		mlx5_ipool_free(fm->flow_ipool, tag_id);
 		return rte_flow_error_set(error, EINVAL,
 				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 				"Meter flow id exceeds max limit.");
 	}
-	if (flow_id_bits > priv->max_mtr_flow_bits)
-		priv->max_mtr_flow_bits = flow_id_bits;
+	if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
+		priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
 	/* Prepare the suffix subflow items. */
 	tag_item = sfx_items++;
 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
@@ -6786,15 +6786,18 @@ mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  *
  * @return
- *   Pointer to table set on success, NULL otherwise.
+ *   0 on success, -1 otherwise.
  */
-struct mlx5_meter_domains_infos *
-mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
+int
+mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			struct mlx5_flow_meter_info *fm,
+			uint32_t mtr_idx,
+			uint8_t domain_bitmap)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->create_mtr_tbls(dev);
+	return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
 }
 
 /**
@@ -6804,18 +6807,15 @@ mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
  *   Pointer to Ethernet device.
  * @param[in] tbl
  *   Pointer to the meter table set.
- *
- * @return
- *   0 on success.
  */
-int
+void
 mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			   struct mlx5_meter_domains_infos *tbls)
+			   struct mlx5_flow_meter_info *fm)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->destroy_mtr_tbls(dev, tbls);
+	fops->destroy_mtr_tbls(dev, fm);
 }
 
 /**
drivers/net/mlx5/mlx5_flow.h +18 -14
index f0509b14b0..98f6132332 100644
@@ -221,16 +221,17 @@ enum mlx5_feature_name {
 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37)
 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)
 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)
+#define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
 	 MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
-	 MLX5_FLOW_ACTION_DEFAULT_MISS)
+	 MLX5_FLOW_ACTION_DEFAULT_MISS | \
+	 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
-	 MLX5_FLOW_ACTION_JUMP)
-
+	 MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
 				      MLX5_FLOW_ACTION_SET_IPV4_DST | \
@@ -831,9 +832,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
-	uint32_t meter_id;
-	/**< Meter id. */
-	uint32_t idx; /* Index to meter object. */
+	uint32_t idx;
+	/* Index to meter object. */
 };
 
 #define MLX5_MAX_TUNNELS 256
@@ -1087,10 +1087,12 @@ typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
 				 const struct rte_flow_action *actions,
 				 void *data,
 				 struct rte_flow_error *error);
-typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
-					    (struct rte_eth_dev *dev);
-typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
-					struct mlx5_meter_domains_infos *tbls);
+typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
+					struct mlx5_flow_meter_info *fm,
+					uint32_t mtr_idx,
+					uint8_t domain_bitmap);
+typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
+				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
@@ -1408,10 +1410,12 @@ int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
 				  uint16_t ether_type,
 				  const struct rte_flow_item_ecpri *acc_mask,
 				  struct rte_flow_error *error);
-struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
-					(struct rte_eth_dev *dev);
-int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
-			       struct mlx5_meter_domains_infos *tbl);
+int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			      struct mlx5_flow_meter_info *fm,
+			      uint32_t mtr_idx,
+			      uint8_t domain_bitmap);
+void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
+			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_action_handle_flush(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_dv.c +251 -114

461 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +313 -54

508 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#39 lore raw

PATCH v8 3/4 net/mlx5: prepare sub-policy for a flow with meter

In reply to Li Zhang

When a flow has a RSS action, the driver splits each sub flow finally is configured with
a different HW TIR action.

Any RSS action configured in meter policy may cause a split in the flow configuration.
To save performance, any TIR action will be configured in different flow table, so policy can be split to sub-policies per TIR in the flow creation time.

Create a function to prepare the policy and its sub-policies for a configured flow with meter.

---
 drivers/net/mlx5/mlx5_flow.h    |  10 +++
 drivers/net/mlx5/mlx5_flow_dv.c | 145 ++++++++++++++++++++++++++++++++
 2 files changed, 155 insertions(+)
drivers/net/mlx5/mlx5_flow.h +10 -0
index 98f6132332..a80c7903a2 100644
@@ -1094,6 +1094,11 @@ typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
 				struct mlx5_flow_meter_info *fm);
 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
+typedef struct mlx5_flow_meter_sub_policy *
+	(*mlx5_flow_meter_sub_policy_rss_prepare_t)
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1186,6 +1191,7 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_destroy_policy_rules_t destroy_policy_rules;
 	mlx5_flow_create_def_policy_t create_def_policy;
 	mlx5_flow_destroy_def_policy_t destroy_def_policy;
+	mlx5_flow_meter_sub_policy_rss_prepare_t meter_sub_policy_rss_prepare;
 	mlx5_flow_counter_alloc_t counter_alloc;
 	mlx5_flow_counter_free_t counter_free;
 	mlx5_flow_counter_query_t counter_query;
@@ -1417,6 +1423,10 @@ int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_flow_meter_info *fm);
 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
+struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_rss_prepare
+		(struct rte_eth_dev *dev,
+		struct mlx5_flow_meter_policy *mtr_policy,
+		struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
 int mlx5_action_handle_flush(struct rte_eth_dev *dev);
 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id);
drivers/net/mlx5/mlx5_flow_dv.c +145 -0

157 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#40 lore raw

PATCH v8 4/4 net/mlx5: connect meter policy to created flows

In reply to Li Zhang

From: Shun Hao <[email protected]>

Currently ASO meter must be followed by policy table, so this adds the support that connecting meter and policy table.

There are several cases to be considered:
1. For non-termination policy, connect meter to the default policy table.
2. For non-RSS termination policy case, simply get the policy table id and connect meter to it.
3. For RSS termination policy case, need to split the flow due to RSS info in policy, and translate each sub-flow using that RSS, then create the sub policy table to be connected.
4. In termination policy case, if there's no actions to modify the packet before meter, no need to use set_tag to save meter id in register. Only add a new flow in drop table using the same match criteria as suf-flow, to save cache miss.

---
 doc/guides/nics/mlx5.rst               |  12 +
 doc/guides/rel_notes/release_21_05.rst |   1 +
 drivers/net/mlx5/mlx5_flow.c           | 446 +++++++++++++++++++++----
 drivers/net/mlx5/mlx5_flow.h           |   4 +
 drivers/net/mlx5/mlx5_flow_dv.c        |  15 +
 5 files changed, 421 insertions(+), 57 deletions(-)
doc/guides/nics/mlx5.rst +12 -0
index 98817e93cd..b27a9a69f6 100644
@@ -106,6 +106,7 @@ Features
 - E-Switch mirroring and modify.
 - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer
   flow group.
+- Flow metering, including meter policy API.
 
 Limitations
 -----------
@@ -400,10 +401,21 @@ Limitations
   - Hairpin in switchdev SR-IOV mode is not supported till now.
 
 - Meter:
+
   - All the meter colors with drop action will be counted only by the global drop statistics.
   - Green color is not supported with drop action.
   - Yellow detection is not supported.
   - Red color must be with drop action.
+  - Meter statistics are supported only for drop case.
+  - Meter yellow color detection is not supported.
+  - A meter action created with pre-defined policy must be the last action in the flow except single case where the policy actions are:
+     - green: NULL or END.
+     - yellow: NULL or END.
+     - RED: DROP / END.
+  - The only supported meter policy actions:
+     - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
+     - yellow: must be empty.
+     - RED: must be DROP.
 
 Statistics
 ----------
doc/guides/rel_notes/release_21_05.rst +1 -0
index b3224dc332..58d70bd19f 100644
@@ -162,6 +162,7 @@ New Features
 
   * Added support for VXLAN and NVGRE encap as sample actions.
   * Support push VLAN on ingress traffic and pop VLAN on egress traffic in E-Switch mode.
+  * Added support for pre-defined meter policy API.
   * Added support for ASO (Advanced Steering Operation) meter.
 
 * **Updated NXP DPAA driver.**
drivers/net/mlx5/mlx5_flow.c +389 -57

615 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +4 -0
index a80c7903a2..56908ae08b 100644
@@ -36,6 +36,8 @@ enum mlx5_rte_flow_action_type {
 	MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
 	MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET,
 	MLX5_RTE_FLOW_ACTION_TYPE_AGE,
+	MLX5_RTE_FLOW_ACTION_TYPE_JUMP,
+	MLX5_RTE_FLOW_ACTION_TYPE_COUNT,
 };
 
 #define MLX5_INDIRECT_ACTION_TYPE_OFFSET 30
@@ -1047,6 +1049,8 @@ struct mlx5_flow_workspace {
 	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
+	uint32_t skip_matcher_reg:1;
+	/* Indicates if need to skip matcher register in translate. */
 };
 
 struct mlx5_flow_split_info {
drivers/net/mlx5/mlx5_flow_dv.c +15 -0
index 6bccdf5b16..d810466242 100644
@@ -7439,6 +7439,7 @@ flow_dv_prepare(struct rte_eth_dev *dev,
 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
 
 	MLX5_ASSERT(wks);
+	wks->skip_matcher_reg = 0;
 	/* In case of corrupting the memory. */
 	if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
 		rte_flow_error_set(error, ENOSPC,
@@ -11270,6 +11271,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
 		int action_type = actions->type;
 		const struct rte_flow_action *found_action = NULL;
 		uint32_t jump_group = 0;
+		struct mlx5_flow_counter *cnt;
 
 		if (!mlx5_flow_os_action_supported(action_type))
 			return rte_flow_error_set(error, ENOTSUP,
@@ -11450,6 +11452,12 @@ flow_dv_translate(struct rte_eth_dev *dev,
 				age = action->conf;
 			action_flags |= MLX5_FLOW_ACTION_COUNT;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
+			cnt = flow_dv_counter_get_by_idx(dev,
+				(uint32_t)(uintptr_t)action->conf, NULL);
+			MLX5_ASSERT(cnt != NULL);
+			dev_flow->dv.actions[actions_n++] = cnt->action;
+			break;
 		case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
 			dev_flow->dv.actions[actions_n++] =
 						priv->sh->pop_vlan_action;
@@ -11554,6 +11562,11 @@ flow_dv_translate(struct rte_eth_dev *dev,
 			/* If decap is followed by encap, handle it at encap. */
 			action_flags |= MLX5_FLOW_ACTION_DECAP;
 			break;
+		case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
+			dev_flow->dv.actions[actions_n++] =
+				(void *)(uintptr_t)action->conf;
+			action_flags |= MLX5_FLOW_ACTION_JUMP;
+			break;
 		case RTE_FLOW_ACTION_TYPE_JUMP:
 			jump_group = ((const struct rte_flow_action_jump *)
 							action->conf)->group;
@@ -12109,6 +12122,8 @@ flow_dv_translate(struct rte_eth_dev *dev,
 	}
 	dev_flow->dv.actions_n = actions_n;
 	dev_flow->act_flags = action_flags;
+	if (wks->skip_matcher_reg)
+		return 0;
 	/* Register matcher. */
 	matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
 				    matcher.mask.size);
Signature · 1 line
2.27.0
#41 lore raw
In reply to Li Zhang

Hi,

Quoted 73 lines

-----Original Message-----
From: Li Zhang <[email protected]>
Sent: Tuesday, April 27, 2021 1:44 PM
To: [email protected]; Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>
Cc: [email protected]; NBU-Contact-Thomas Monjalon <[email protected]>; Raslan Darawsheh <[email protected]>; Roni Bar Yanai <[email protected]>
Subject: [PATCH v8 0/4] net/mlx5: support meter policy operations

MLX5 PMD checks the validation of actions in policy while add a new meter policy, if pass the validation, allocates the new policy object from the meter policy indexed memory pool.

It is common to use the same policy for multiple meters. MLX5 PMD supports two types of policy: termination policy and no- termination policy.

The termination policy must have a fate action as in the policy actions, it can support QUEUE, RSS, PORT_ID, DROP, JUMP, MARK and SET_TAG actions if policy color is GREEN, also supports DROP action if policy color is RED.

The no-termination policy uses policy ID 0 as default policy, it is created internal and cannot be changed by API. The default policy red action is drop, green action is jump to suffix table.
Create this policy by policy API with green/yellow no action, red with drop action.
One example in testpmd command:
add port meter policy 0 g_actions end y_actions end r_actions drop / end

Depends-on: series=16520 ("Add ASO meter support in MLX5 PMD ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16520

Depends-on: series=16524 ("Support meter policy API ")
https://patchwork.dpdk.org/project/dpdk/list/?series=16524

V8:
* Fix comments about release-note
v7:
* Rebase.
V6:
* Fix comments about Depends-on.
V5:
* Fix comments about destory meter on different ports. V4:
* Fix comments about rte_mtr_meter_policy_add. V3:
* Fix comments about Depends-on.
V2:
* Add MLX5_MTR_DEFAULT_POLICY_ID in MLX5 PMD.

Li Zhang (3):
net/mlx5: support meter policy operations net/mlx5: support meter creation with policy net/mlx5: prepare sub-policy for a flow with meter

Shun Hao (1):
net/mlx5: connect meter policy to created flows

 doc/guides/nics/mlx5.rst               |   12 +
 doc/guides/rel_notes/release_21_05.rst |    1 +
 drivers/net/mlx5/linux/mlx5_os.c       |   13 +-
 drivers/net/mlx5/mlx5.c                |   77 +-
 drivers/net/mlx5/mlx5.h                |  212 ++-
 drivers/net/mlx5/mlx5_flow.c           |  654 +++++++-
 drivers/net/mlx5/mlx5_flow.h           |  119 +-
 drivers/net/mlx5/mlx5_flow_aso.c       |   10 +-
 drivers/net/mlx5/mlx5_flow_dv.c        | 1895 ++++++++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_meter.c     |  742 +++++++++-
 drivers/net/mlx5/mlx5_trigger.c        |    1 +
 11 files changed, 3373 insertions(+), 363 deletions(-)
Quoted 2 lines

--
2.27.0

Series applied to next-net-mlx,
And removed v7,
Kindest regards
Raslan Darawsheh