DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/2] Support meter PPS(packet per second) in MLX5 PMD
@ 2021-03-31  9:23 Li Zhang
  2021-03-31  9:23 ` [dpdk-dev] [PATCH 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Li Zhang @ 2021-03-31  9:23 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports rate is bytes per second(BPS).
Add packet_mode flag in meter profile parameters data structure.
So that it can meter traffic by packet per second.

Depends-on: series=16002  ("Support PPS(packet per second) on meter")
https://patchwork.dpdk.org/project/dpdk/list/?series=16002

Li Zhang (2):
  common/mlx5: add meter mode definition in PRM file
  net/mlx5: support meter PPS profile

 doc/guides/nics/mlx5.rst           |  1 +
 drivers/common/mlx5/mlx5_prm.h     |  8 ++++
 drivers/net/mlx5/mlx5_flow_aso.c   | 17 ++++---
 drivers/net/mlx5/mlx5_flow_meter.c | 74 +++++++++++++++++++++++-------
 4 files changed, 77 insertions(+), 23 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH 1/2] common/mlx5: add meter mode definition in PRM file
  2021-03-31  9:23 [dpdk-dev] [PATCH 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
@ 2021-03-31  9:23 ` Li Zhang
  2021-03-31  9:23 ` [dpdk-dev] [PATCH 2/2] net/mlx5: support meter PPS profile Li Zhang
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Li Zhang @ 2021-03-31  9:23 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Add meter mode definition in PRM file

Signed-off-by: Li Zhang <lizh@nvidia.com>
---
 drivers/common/mlx5/mlx5_prm.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index 6d6c7f38bb..0bfa607e31 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -2297,6 +2297,13 @@ struct mlx5_ifc_flow_meter_parameters_bits {
 #define MLX5_IFC_FLOW_METER_PARAM_MASK UINT64_C(0x80FFFFFF)
 #define MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL 0x14BF00C8
 
+enum {
+	MLX5_METER_MODE_IP_LEN = 0x0,
+	MLX5_METER_MODE_L2_LEN = 0x1,
+	MLX5_METER_MODE_L2_IPG_LEN = 0x2,
+	MLX5_METER_MODE_PKT = 0x3,
+};
+
 enum {
 	MLX5_CQE_SIZE_64B = 0x0,
 	MLX5_CQE_SIZE_128B = 0x1,
@@ -2671,6 +2678,7 @@ struct mlx5_aso_mtr_dseg {
 #define ASO_DSEG_VALID_OFFSET 31
 #define ASO_DSEG_BO_OFFSET 30
 #define ASO_DSEG_SC_OFFSET 28
+#define ASO_DSEG_MTR_MODE 24
 #define ASO_DSEG_CBS_EXP_OFFSET 24
 #define ASO_DSEG_CBS_MAN_OFFSET 16
 #define ASO_DSEG_CIR_EXP_MASK 0x1F
-- 
2.21.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH 2/2] net/mlx5: support meter PPS profile
  2021-03-31  9:23 [dpdk-dev] [PATCH 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
  2021-03-31  9:23 ` [dpdk-dev] [PATCH 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
@ 2021-03-31  9:23 ` Li Zhang
  2021-04-10  7:31 ` [dpdk-dev] [PATCH v2 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Li Zhang @ 2021-03-31  9:23 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports bytes per second(BPS).
Such as Single Rate Three Color Marker (srTCM rfc2697)
Add packet_mode flag to support rate is packet per second.
So that it can meter traffic by packet per second (PPS).

Signed-off-by: Li Zhang <lizh@nvidia.com>
---
 doc/guides/nics/mlx5.rst           |  1 +
 drivers/net/mlx5/mlx5_flow_aso.c   | 17 ++++---
 drivers/net/mlx5/mlx5_flow_meter.c | 74 +++++++++++++++++++++++-------
 3 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index 6e9a68baf5..1eb6d3d5da 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -415,6 +415,7 @@ Limitations
     green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
     yellow: must be empty.
     red: must be DROP.
+  - meter profile packet mode is supported.
 
 Statistics
 ----------
diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c
index 879252faa1..f34fc54fa6 100644
--- a/drivers/net/mlx5/mlx5_flow_aso.c
+++ b/drivers/net/mlx5/mlx5_flow_aso.c
@@ -174,7 +174,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 	volatile struct mlx5_aso_wqe *restrict wqe;
 	int i;
 	int size = 1 << sq->log_desc_n;
-	uint32_t idx;
 
 	/* All the next fields state should stay constant. */
 	for (i = 0, wqe = &sq->sq_obj.aso_wqes[0]; i < size; ++i, ++wqe) {
@@ -187,11 +186,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 			 (BYTEWISE_64BYTE << ASO_CSEG_DATA_MASK_MODE_OFFSET));
 		wqe->general_cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS <<
 							 MLX5_COMP_MODE_OFFSET);
-		for (idx = 0; idx < MLX5_ASO_METERS_PER_WQE;
-			idx++)
-			wqe->aso_dseg.mtrs[idx].v_bo_sc_bbog_mm =
-				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
-				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	}
 }
 
@@ -642,6 +636,7 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 {
 	volatile struct mlx5_aso_wqe *wqe = NULL;
 	struct mlx5_flow_meter_info *fm = NULL;
+	struct mlx5_flow_meter_profile *fmp;
 	uint16_t size = 1 << sq->log_desc_n;
 	uint16_t mask = size - 1;
 	uint16_t res;
@@ -682,6 +677,16 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 			RTE_BE32(MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL);
 		wqe->aso_dseg.mtrs[dseg_idx].ebs_eir = 0;
 	}
+	fmp = fm->profile;
+	if (fmp->profile.packet_mode)
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET) |
+				(MLX5_METER_MODE_PKT << ASO_DSEG_MTR_MODE));
+	else
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	sq->head++;
 	sq->pi += 2;/* Each WQE contains 2 WQEBB's. */
 	rte_io_wmb();
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index 2c08359107..4aa87fd53c 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -144,13 +144,19 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 	if (profile->alg == RTE_MTR_SRTCM_RFC2697) {
 		if (priv->config.hca_attr.qos.flow_meter_old) {
 			/* Verify support for flow meter parameters. */
-			if (profile->srtcm_rfc2697.cir > 0 &&
-			    profile->srtcm_rfc2697.cir <= MLX5_SRTCM_CIR_MAX &&
-			    profile->srtcm_rfc2697.cbs > 0 &&
-			    profile->srtcm_rfc2697.cbs <= MLX5_SRTCM_CBS_MAX &&
-			    profile->srtcm_rfc2697.ebs <= MLX5_SRTCM_EBS_MAX)
-				return 0;
-			else
+			if (priv->sh->meter_aso_en && profile->packet_mode) {
+				if (profile->srtcm_rfc2697.cir > 0 &&
+					(profile->srtcm_rfc2697.cir <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CIR_MAX &&
+					profile->srtcm_rfc2697.cbs > 0 &&
+					(profile->srtcm_rfc2697.cbs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CBS_MAX &&
+					(profile->srtcm_rfc2697.ebs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_EBS_MAX)
+					return 0;
 				return -rte_mtr_error_set
 					     (error, ENOTSUP,
 					      RTE_MTR_ERROR_TYPE_MTR_PARAMS,
@@ -158,6 +164,22 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 					      profile->srtcm_rfc2697.ebs ?
 					      "Metering value ebs must be 0." :
 					      "Invalid metering parameters.");
+			}
+			if (profile->srtcm_rfc2697.cir > 0 &&
+				profile->srtcm_rfc2697.cir <=
+						MLX5_SRTCM_CIR_MAX &&
+				profile->srtcm_rfc2697.cbs > 0 &&
+				profile->srtcm_rfc2697.cbs <=
+						MLX5_SRTCM_CBS_MAX &&
+				profile->srtcm_rfc2697.ebs <=
+						MLX5_SRTCM_EBS_MAX)
+				return 0;
+			return -rte_mtr_error_set(error, ENOTSUP,
+					RTE_MTR_ERROR_TYPE_MTR_PARAMS,
+					NULL,
+					profile->srtcm_rfc2697.ebs ?
+					"Metering value ebs must be 0." :
+					"Invalid metering parameters.");
 		}
 	}
 	return -rte_mtr_error_set(error, ENOTSUP,
@@ -241,20 +263,36 @@ mlx5_flow_meter_xbs_man_exp_calc(uint64_t xbs, uint8_t *man, uint8_t *exp)
  */
 static int
 mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
-			  struct rte_mtr_error *error)
+			struct mlx5_priv *priv, struct rte_mtr_error *error)
 {
 	struct mlx5_flow_meter_srtcm_rfc2697_prm *srtcm = &fmp->srtcm_prm;
 	uint8_t man, exp;
 	uint32_t cbs_exp, cbs_man, cir_exp, cir_man;
 	uint32_t ebs_exp, ebs_man;
+	uint64_t cir, cbs, ebs;
 
 	if (fmp->profile.alg != RTE_MTR_SRTCM_RFC2697)
 		return -rte_mtr_error_set(error, ENOTSUP,
 				RTE_MTR_ERROR_TYPE_METER_PROFILE,
 				NULL, "Metering algorithm not supported.");
+	if (!priv->sh->meter_aso_en && fmp->profile.packet_mode)
+		return -rte_mtr_error_set(error, ENOTSUP,
+			RTE_MTR_ERROR_TYPE_METER_PROFILE,
+			NULL, "Metering algorithm packet mode not supported.");
+	if (priv->sh->meter_aso_en && fmp->profile.packet_mode) {
+		cir = fmp->profile.srtcm_rfc2697.cir <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		cbs = fmp->profile.srtcm_rfc2697.cbs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		ebs = fmp->profile.srtcm_rfc2697.ebs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+	} else {
+		cir = fmp->profile.srtcm_rfc2697.cir;
+		cbs = fmp->profile.srtcm_rfc2697.cbs;
+		ebs = fmp->profile.srtcm_rfc2697.ebs;
+	}
 	/* cir = 8G * cir_mantissa * 1/(2^cir_exponent)) Bytes/Sec */
-	mlx5_flow_meter_cir_man_exp_calc(fmp->profile.srtcm_rfc2697.cir,
-				    &man, &exp);
+	mlx5_flow_meter_cir_man_exp_calc(cir, &man, &exp);
 	/* Check if cir mantissa is too large. */
 	if (exp > ASO_DSEG_CIR_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -264,8 +302,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 	cir_man = man;
 	cir_exp = exp;
 	 /* cbs = cbs_mantissa * 2^cbs_exponent */
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.cbs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(cbs, &man, &exp);
 	/* Check if cbs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -278,8 +315,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 				cbs_man << ASO_DSEG_CBS_MAN_OFFSET |
 				cir_exp << ASO_DSEG_CIR_EXP_OFFSET |
 				cir_man);
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.ebs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(ebs, &man, &exp);
 	/* Check if ebs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -319,11 +355,15 @@ mlx5_flow_mtr_cap_get(struct rte_eth_dev *dev,
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
 					  "Meter is not supported");
 	memset(cap, 0, sizeof(*cap));
-	if (priv->sh->meter_aso_en)
+	if (priv->sh->meter_aso_en) {
 		/* 2 meters per one ASO cache line. */
 		cap->n_max = 1 << (qattr->log_max_num_meter_aso + 1);
-	else
+		cap->srtcm_rfc2697_packet_mode_supported = 1;
+	} else {
 		cap->n_max = 1 << qattr->log_max_flow_meter;
+		cap->srtcm_rfc2697_packet_mode_supported = 0;
+	}
+	cap->srtcm_rfc2697_byte_mode_supported = 1;
 	cap->n_shared_max = cap->n_max;
 	cap->identical = 1;
 	cap->shared_identical = 1;
@@ -384,7 +424,7 @@ mlx5_flow_meter_profile_add(struct rte_eth_dev *dev,
 	fmp->id = meter_profile_id;
 	fmp->profile = *profile;
 	/* Fill the flow meter parameters for the PRM. */
-	ret = mlx5_flow_meter_param_fill(fmp, error);
+	ret = mlx5_flow_meter_param_fill(fmp, priv, error);
 	if (ret)
 		goto error;
 	/* Add to list. */
-- 
2.21.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v2 0/2] Support meter PPS(packet per second) in MLX5 PMD
  2021-03-31  9:23 [dpdk-dev] [PATCH 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
  2021-03-31  9:23 ` [dpdk-dev] [PATCH 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
  2021-03-31  9:23 ` [dpdk-dev] [PATCH 2/2] net/mlx5: support meter PPS profile Li Zhang
@ 2021-04-10  7:31 ` Li Zhang
  2021-04-10  7:31   ` [dpdk-dev] [PATCH v2 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
  2021-04-10  7:31   ` [dpdk-dev] [PATCH v2 2/2] net/mlx5: support meter PPS profile Li Zhang
  2021-04-13  4:06 ` [dpdk-dev] [PATCH v3 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-10  7:31 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports rate is bytes per second(BPS).
Add packet_mode flag in meter profile parameters data structure.
So that it can meter traffic by packet per second.

Depends-on: series=16256  ("Support PPS(packet per second) on meter")
https://patchwork.dpdk.org/project/dpdk/list/?series=16256

V2: Fix comments from Matan.

Li Zhang (2):
  common/mlx5: add meter mode definition in PRM file
  net/mlx5: support meter PPS profile

 doc/guides/nics/mlx5.rst           |  1 +
 drivers/common/mlx5/mlx5_prm.h     |  8 ++++
 drivers/net/mlx5/mlx5_flow_aso.c   | 17 ++++---
 drivers/net/mlx5/mlx5_flow_meter.c | 74 +++++++++++++++++++++++-------
 4 files changed, 77 insertions(+), 23 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v2 1/2] common/mlx5: add meter mode definition in PRM file
  2021-04-10  7:31 ` [dpdk-dev] [PATCH v2 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
@ 2021-04-10  7:31   ` Li Zhang
  2021-04-10  7:31   ` [dpdk-dev] [PATCH v2 2/2] net/mlx5: support meter PPS profile Li Zhang
  1 sibling, 0 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-10  7:31 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Add meter mode definitions in PRM file

Signed-off-by: Li Zhang <lizh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/common/mlx5/mlx5_prm.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index c6d8060bb9..efa5ae67bf 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -2297,6 +2297,13 @@ struct mlx5_ifc_flow_meter_parameters_bits {
 #define MLX5_IFC_FLOW_METER_PARAM_MASK UINT64_C(0x80FFFFFF)
 #define MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL 0x14BF00C8
 
+enum {
+	MLX5_METER_MODE_IP_LEN = 0x0,
+	MLX5_METER_MODE_L2_LEN = 0x1,
+	MLX5_METER_MODE_L2_IPG_LEN = 0x2,
+	MLX5_METER_MODE_PKT = 0x3,
+};
+
 enum {
 	MLX5_CQE_SIZE_64B = 0x0,
 	MLX5_CQE_SIZE_128B = 0x1,
@@ -2671,6 +2678,7 @@ struct mlx5_aso_mtr_dseg {
 #define ASO_DSEG_VALID_OFFSET 31
 #define ASO_DSEG_BO_OFFSET 30
 #define ASO_DSEG_SC_OFFSET 28
+#define ASO_DSEG_MTR_MODE 24
 #define ASO_DSEG_CBS_EXP_OFFSET 24
 #define ASO_DSEG_CBS_MAN_OFFSET 16
 #define ASO_DSEG_CIR_EXP_MASK 0x1F
-- 
2.21.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v2 2/2] net/mlx5: support meter PPS profile
  2021-04-10  7:31 ` [dpdk-dev] [PATCH v2 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
  2021-04-10  7:31   ` [dpdk-dev] [PATCH v2 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
@ 2021-04-10  7:31   ` Li Zhang
  1 sibling, 0 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-10  7:31 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports bytes per second(BPS).
Such as Single Rate Three Color Marker (srTCM rfc2697)
Add packet_mode flag to support rate is packet per second.
So that it can meter traffic by packet per second (PPS).

Signed-off-by: Li Zhang <lizh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 doc/guides/nics/mlx5.rst           |  1 +
 drivers/net/mlx5/mlx5_flow_aso.c   | 17 ++++---
 drivers/net/mlx5/mlx5_flow_meter.c | 74 +++++++++++++++++++++++-------
 3 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index 9d36d27fa9..cf81ad5c09 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -416,6 +416,7 @@ Limitations
      - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
      - yellow: must be empty.
      - RED: must be DROP.
+  - meter profile packet mode is supported.
 
 Statistics
 ----------
diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c
index 20cd4fe18c..da513a600c 100644
--- a/drivers/net/mlx5/mlx5_flow_aso.c
+++ b/drivers/net/mlx5/mlx5_flow_aso.c
@@ -191,7 +191,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 	volatile struct mlx5_aso_wqe *restrict wqe;
 	int i;
 	int size = 1 << sq->log_desc_n;
-	uint32_t idx;
 
 	/* All the next fields state should stay constant. */
 	for (i = 0, wqe = &sq->sq_obj.aso_wqes[0]; i < size; ++i, ++wqe) {
@@ -204,11 +203,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 			 (BYTEWISE_64BYTE << ASO_CSEG_DATA_MASK_MODE_OFFSET));
 		wqe->general_cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS <<
 							 MLX5_COMP_MODE_OFFSET);
-		for (idx = 0; idx < MLX5_ASO_METERS_PER_WQE;
-			idx++)
-			wqe->aso_dseg.mtrs[idx].v_bo_sc_bbog_mm =
-				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
-				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	}
 }
 
@@ -664,6 +658,7 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 {
 	volatile struct mlx5_aso_wqe *wqe = NULL;
 	struct mlx5_flow_meter_info *fm = NULL;
+	struct mlx5_flow_meter_profile *fmp;
 	uint16_t size = 1 << sq->log_desc_n;
 	uint16_t mask = size - 1;
 	uint16_t res;
@@ -704,6 +699,16 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 			RTE_BE32(MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL);
 		wqe->aso_dseg.mtrs[dseg_idx].ebs_eir = 0;
 	}
+	fmp = fm->profile;
+	if (fmp->profile.packet_mode)
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET) |
+				(MLX5_METER_MODE_PKT << ASO_DSEG_MTR_MODE));
+	else
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	sq->head++;
 	sq->pi += 2;/* Each WQE contains 2 WQEBB's. */
 	rte_io_wmb();
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index b8fcc6e658..7b77cb5202 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -144,13 +144,19 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 	if (profile->alg == RTE_MTR_SRTCM_RFC2697) {
 		if (priv->config.hca_attr.qos.flow_meter_old) {
 			/* Verify support for flow meter parameters. */
-			if (profile->srtcm_rfc2697.cir > 0 &&
-			    profile->srtcm_rfc2697.cir <= MLX5_SRTCM_CIR_MAX &&
-			    profile->srtcm_rfc2697.cbs > 0 &&
-			    profile->srtcm_rfc2697.cbs <= MLX5_SRTCM_CBS_MAX &&
-			    profile->srtcm_rfc2697.ebs <= MLX5_SRTCM_EBS_MAX)
-				return 0;
-			else
+			if (priv->sh->meter_aso_en && profile->packet_mode) {
+				if (profile->srtcm_rfc2697.cir > 0 &&
+					(profile->srtcm_rfc2697.cir <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CIR_MAX &&
+					profile->srtcm_rfc2697.cbs > 0 &&
+					(profile->srtcm_rfc2697.cbs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CBS_MAX &&
+					(profile->srtcm_rfc2697.ebs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_EBS_MAX)
+					return 0;
 				return -rte_mtr_error_set
 					     (error, ENOTSUP,
 					      RTE_MTR_ERROR_TYPE_MTR_PARAMS,
@@ -158,6 +164,22 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 					      profile->srtcm_rfc2697.ebs ?
 					      "Metering value ebs must be 0." :
 					      "Invalid metering parameters.");
+			}
+			if (profile->srtcm_rfc2697.cir > 0 &&
+				profile->srtcm_rfc2697.cir <=
+						MLX5_SRTCM_CIR_MAX &&
+				profile->srtcm_rfc2697.cbs > 0 &&
+				profile->srtcm_rfc2697.cbs <=
+						MLX5_SRTCM_CBS_MAX &&
+				profile->srtcm_rfc2697.ebs <=
+						MLX5_SRTCM_EBS_MAX)
+				return 0;
+			return -rte_mtr_error_set(error, ENOTSUP,
+					RTE_MTR_ERROR_TYPE_MTR_PARAMS,
+					NULL,
+					profile->srtcm_rfc2697.ebs ?
+					"Metering value ebs must be 0." :
+					"Invalid metering parameters.");
 		}
 	}
 	return -rte_mtr_error_set(error, ENOTSUP,
@@ -241,20 +263,36 @@ mlx5_flow_meter_xbs_man_exp_calc(uint64_t xbs, uint8_t *man, uint8_t *exp)
  */
 static int
 mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
-			  struct rte_mtr_error *error)
+			struct mlx5_priv *priv, struct rte_mtr_error *error)
 {
 	struct mlx5_flow_meter_srtcm_rfc2697_prm *srtcm = &fmp->srtcm_prm;
 	uint8_t man, exp;
 	uint32_t cbs_exp, cbs_man, cir_exp, cir_man;
 	uint32_t ebs_exp, ebs_man;
+	uint64_t cir, cbs, ebs;
 
 	if (fmp->profile.alg != RTE_MTR_SRTCM_RFC2697)
 		return -rte_mtr_error_set(error, ENOTSUP,
 				RTE_MTR_ERROR_TYPE_METER_PROFILE,
 				NULL, "Metering algorithm not supported.");
+	if (!priv->sh->meter_aso_en && fmp->profile.packet_mode)
+		return -rte_mtr_error_set(error, ENOTSUP,
+			RTE_MTR_ERROR_TYPE_METER_PROFILE,
+			NULL, "Metering algorithm packet mode not supported.");
+	if (priv->sh->meter_aso_en && fmp->profile.packet_mode) {
+		cir = fmp->profile.srtcm_rfc2697.cir <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		cbs = fmp->profile.srtcm_rfc2697.cbs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		ebs = fmp->profile.srtcm_rfc2697.ebs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+	} else {
+		cir = fmp->profile.srtcm_rfc2697.cir;
+		cbs = fmp->profile.srtcm_rfc2697.cbs;
+		ebs = fmp->profile.srtcm_rfc2697.ebs;
+	}
 	/* cir = 8G * cir_mantissa * 1/(2^cir_exponent)) Bytes/Sec */
-	mlx5_flow_meter_cir_man_exp_calc(fmp->profile.srtcm_rfc2697.cir,
-				    &man, &exp);
+	mlx5_flow_meter_cir_man_exp_calc(cir, &man, &exp);
 	/* Check if cir mantissa is too large. */
 	if (exp > ASO_DSEG_CIR_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -264,8 +302,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 	cir_man = man;
 	cir_exp = exp;
 	 /* cbs = cbs_mantissa * 2^cbs_exponent */
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.cbs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(cbs, &man, &exp);
 	/* Check if cbs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -278,8 +315,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 				cbs_man << ASO_DSEG_CBS_MAN_OFFSET |
 				cir_exp << ASO_DSEG_CIR_EXP_OFFSET |
 				cir_man);
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.ebs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(ebs, &man, &exp);
 	/* Check if ebs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -319,11 +355,15 @@ mlx5_flow_mtr_cap_get(struct rte_eth_dev *dev,
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
 					  "Meter is not supported");
 	memset(cap, 0, sizeof(*cap));
-	if (priv->sh->meter_aso_en)
+	if (priv->sh->meter_aso_en) {
 		/* 2 meters per one ASO cache line. */
 		cap->n_max = 1 << (qattr->log_max_num_meter_aso + 1);
-	else
+		cap->srtcm_rfc2697_packet_mode_supported = 1;
+	} else {
 		cap->n_max = 1 << qattr->log_max_flow_meter;
+		cap->srtcm_rfc2697_packet_mode_supported = 0;
+	}
+	cap->srtcm_rfc2697_byte_mode_supported = 1;
 	cap->n_shared_max = cap->n_max;
 	cap->identical = 1;
 	cap->shared_identical = 1;
@@ -384,7 +424,7 @@ mlx5_flow_meter_profile_add(struct rte_eth_dev *dev,
 	fmp->id = meter_profile_id;
 	fmp->profile = *profile;
 	/* Fill the flow meter parameters for the PRM. */
-	ret = mlx5_flow_meter_param_fill(fmp, error);
+	ret = mlx5_flow_meter_param_fill(fmp, priv, error);
 	if (ret)
 		goto error;
 	/* Add to list. */
-- 
2.21.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v3 0/2] Support meter PPS(packet per second) in MLX5 PMD
  2021-03-31  9:23 [dpdk-dev] [PATCH 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
                   ` (2 preceding siblings ...)
  2021-04-10  7:31 ` [dpdk-dev] [PATCH v2 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
@ 2021-04-13  4:06 ` Li Zhang
  2021-04-13  4:06   ` [dpdk-dev] [PATCH v3 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
  2021-04-13  4:06   ` [dpdk-dev] [PATCH v3 2/2] net/mlx5: support meter PPS profile Li Zhang
  2021-04-21  4:19 ` [dpdk-dev] [PATCH v4 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
  2021-04-27 10:41 ` [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
  5 siblings, 2 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-13  4:06 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports rate is bytes per second(BPS).
Add packet_mode flag in meter profile parameters data structure.
So that it can meter traffic by packet per second.

Depends-on: series=16312  ("Support PPS(packet per second) on meter")
https://patchwork.dpdk.org/project/dpdk/list/?series=16312

Depends-on: series=16302  ("support meter policy operations")
https://patchwork.dpdk.org/project/dpdk/list/?series=16302

V2: Fix comments about commit-log.
V3: Fix comments about Depends-on and rebase.

Li Zhang (2):
  common/mlx5: add meter mode definition in PRM file
  net/mlx5: support meter PPS profile

 doc/guides/nics/mlx5.rst           |  1 +
 drivers/common/mlx5/mlx5_prm.h     |  8 ++++
 drivers/net/mlx5/mlx5_flow_aso.c   | 17 ++++---
 drivers/net/mlx5/mlx5_flow_meter.c | 74 +++++++++++++++++++++++-------
 4 files changed, 77 insertions(+), 23 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v3 1/2] common/mlx5: add meter mode definition in PRM file
  2021-04-13  4:06 ` [dpdk-dev] [PATCH v3 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
@ 2021-04-13  4:06   ` Li Zhang
  2021-04-13  4:06   ` [dpdk-dev] [PATCH v3 2/2] net/mlx5: support meter PPS profile Li Zhang
  1 sibling, 0 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-13  4:06 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Add meter mode definitions in PRM file

Signed-off-by: Li Zhang <lizh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/common/mlx5/mlx5_prm.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index c6d8060bb9..efa5ae67bf 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -2297,6 +2297,13 @@ struct mlx5_ifc_flow_meter_parameters_bits {
 #define MLX5_IFC_FLOW_METER_PARAM_MASK UINT64_C(0x80FFFFFF)
 #define MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL 0x14BF00C8
 
+enum {
+	MLX5_METER_MODE_IP_LEN = 0x0,
+	MLX5_METER_MODE_L2_LEN = 0x1,
+	MLX5_METER_MODE_L2_IPG_LEN = 0x2,
+	MLX5_METER_MODE_PKT = 0x3,
+};
+
 enum {
 	MLX5_CQE_SIZE_64B = 0x0,
 	MLX5_CQE_SIZE_128B = 0x1,
@@ -2671,6 +2678,7 @@ struct mlx5_aso_mtr_dseg {
 #define ASO_DSEG_VALID_OFFSET 31
 #define ASO_DSEG_BO_OFFSET 30
 #define ASO_DSEG_SC_OFFSET 28
+#define ASO_DSEG_MTR_MODE 24
 #define ASO_DSEG_CBS_EXP_OFFSET 24
 #define ASO_DSEG_CBS_MAN_OFFSET 16
 #define ASO_DSEG_CIR_EXP_MASK 0x1F
-- 
2.27.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v3 2/2] net/mlx5: support meter PPS profile
  2021-04-13  4:06 ` [dpdk-dev] [PATCH v3 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
  2021-04-13  4:06   ` [dpdk-dev] [PATCH v3 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
@ 2021-04-13  4:06   ` Li Zhang
  1 sibling, 0 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-13  4:06 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports bytes per second(BPS).
Such as Single Rate Three Color Marker (srTCM rfc2697)
Add packet_mode flag to support rate is packet per second.
So that it can meter traffic by packet per second (PPS).

Signed-off-by: Li Zhang <lizh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 doc/guides/nics/mlx5.rst           |  1 +
 drivers/net/mlx5/mlx5_flow_aso.c   | 17 ++++---
 drivers/net/mlx5/mlx5_flow_meter.c | 74 +++++++++++++++++++++++-------
 3 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index 1e67a91ee7..3990db16b7 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -416,6 +416,7 @@ Limitations
      - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
      - yellow: must be empty.
      - RED: must be DROP.
+  - meter profile packet mode is supported.
 
 Statistics
 ----------
diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c
index 20cd4fe18c..da513a600c 100644
--- a/drivers/net/mlx5/mlx5_flow_aso.c
+++ b/drivers/net/mlx5/mlx5_flow_aso.c
@@ -191,7 +191,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 	volatile struct mlx5_aso_wqe *restrict wqe;
 	int i;
 	int size = 1 << sq->log_desc_n;
-	uint32_t idx;
 
 	/* All the next fields state should stay constant. */
 	for (i = 0, wqe = &sq->sq_obj.aso_wqes[0]; i < size; ++i, ++wqe) {
@@ -204,11 +203,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 			 (BYTEWISE_64BYTE << ASO_CSEG_DATA_MASK_MODE_OFFSET));
 		wqe->general_cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS <<
 							 MLX5_COMP_MODE_OFFSET);
-		for (idx = 0; idx < MLX5_ASO_METERS_PER_WQE;
-			idx++)
-			wqe->aso_dseg.mtrs[idx].v_bo_sc_bbog_mm =
-				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
-				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	}
 }
 
@@ -664,6 +658,7 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 {
 	volatile struct mlx5_aso_wqe *wqe = NULL;
 	struct mlx5_flow_meter_info *fm = NULL;
+	struct mlx5_flow_meter_profile *fmp;
 	uint16_t size = 1 << sq->log_desc_n;
 	uint16_t mask = size - 1;
 	uint16_t res;
@@ -704,6 +699,16 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 			RTE_BE32(MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL);
 		wqe->aso_dseg.mtrs[dseg_idx].ebs_eir = 0;
 	}
+	fmp = fm->profile;
+	if (fmp->profile.packet_mode)
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET) |
+				(MLX5_METER_MODE_PKT << ASO_DSEG_MTR_MODE));
+	else
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	sq->head++;
 	sq->pi += 2;/* Each WQE contains 2 WQEBB's. */
 	rte_io_wmb();
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index fe608a33ec..6b8ac64215 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -144,13 +144,19 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 	if (profile->alg == RTE_MTR_SRTCM_RFC2697) {
 		if (priv->config.hca_attr.qos.flow_meter_old) {
 			/* Verify support for flow meter parameters. */
-			if (profile->srtcm_rfc2697.cir > 0 &&
-			    profile->srtcm_rfc2697.cir <= MLX5_SRTCM_CIR_MAX &&
-			    profile->srtcm_rfc2697.cbs > 0 &&
-			    profile->srtcm_rfc2697.cbs <= MLX5_SRTCM_CBS_MAX &&
-			    profile->srtcm_rfc2697.ebs <= MLX5_SRTCM_EBS_MAX)
-				return 0;
-			else
+			if (priv->sh->meter_aso_en && profile->packet_mode) {
+				if (profile->srtcm_rfc2697.cir > 0 &&
+					(profile->srtcm_rfc2697.cir <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CIR_MAX &&
+					profile->srtcm_rfc2697.cbs > 0 &&
+					(profile->srtcm_rfc2697.cbs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CBS_MAX &&
+					(profile->srtcm_rfc2697.ebs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_EBS_MAX)
+					return 0;
 				return -rte_mtr_error_set
 					     (error, ENOTSUP,
 					      RTE_MTR_ERROR_TYPE_MTR_PARAMS,
@@ -158,6 +164,22 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 					      profile->srtcm_rfc2697.ebs ?
 					      "Metering value ebs must be 0." :
 					      "Invalid metering parameters.");
+			}
+			if (profile->srtcm_rfc2697.cir > 0 &&
+				profile->srtcm_rfc2697.cir <=
+						MLX5_SRTCM_CIR_MAX &&
+				profile->srtcm_rfc2697.cbs > 0 &&
+				profile->srtcm_rfc2697.cbs <=
+						MLX5_SRTCM_CBS_MAX &&
+				profile->srtcm_rfc2697.ebs <=
+						MLX5_SRTCM_EBS_MAX)
+				return 0;
+			return -rte_mtr_error_set(error, ENOTSUP,
+					RTE_MTR_ERROR_TYPE_MTR_PARAMS,
+					NULL,
+					profile->srtcm_rfc2697.ebs ?
+					"Metering value ebs must be 0." :
+					"Invalid metering parameters.");
 		}
 	}
 	return -rte_mtr_error_set(error, ENOTSUP,
@@ -241,20 +263,36 @@ mlx5_flow_meter_xbs_man_exp_calc(uint64_t xbs, uint8_t *man, uint8_t *exp)
  */
 static int
 mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
-			  struct rte_mtr_error *error)
+			struct mlx5_priv *priv, struct rte_mtr_error *error)
 {
 	struct mlx5_flow_meter_srtcm_rfc2697_prm *srtcm = &fmp->srtcm_prm;
 	uint8_t man, exp;
 	uint32_t cbs_exp, cbs_man, cir_exp, cir_man;
 	uint32_t ebs_exp, ebs_man;
+	uint64_t cir, cbs, ebs;
 
 	if (fmp->profile.alg != RTE_MTR_SRTCM_RFC2697)
 		return -rte_mtr_error_set(error, ENOTSUP,
 				RTE_MTR_ERROR_TYPE_METER_PROFILE,
 				NULL, "Metering algorithm not supported.");
+	if (!priv->sh->meter_aso_en && fmp->profile.packet_mode)
+		return -rte_mtr_error_set(error, ENOTSUP,
+			RTE_MTR_ERROR_TYPE_METER_PROFILE,
+			NULL, "Metering algorithm packet mode not supported.");
+	if (priv->sh->meter_aso_en && fmp->profile.packet_mode) {
+		cir = fmp->profile.srtcm_rfc2697.cir <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		cbs = fmp->profile.srtcm_rfc2697.cbs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		ebs = fmp->profile.srtcm_rfc2697.ebs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+	} else {
+		cir = fmp->profile.srtcm_rfc2697.cir;
+		cbs = fmp->profile.srtcm_rfc2697.cbs;
+		ebs = fmp->profile.srtcm_rfc2697.ebs;
+	}
 	/* cir = 8G * cir_mantissa * 1/(2^cir_exponent)) Bytes/Sec */
-	mlx5_flow_meter_cir_man_exp_calc(fmp->profile.srtcm_rfc2697.cir,
-				    &man, &exp);
+	mlx5_flow_meter_cir_man_exp_calc(cir, &man, &exp);
 	/* Check if cir mantissa is too large. */
 	if (exp > ASO_DSEG_CIR_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -264,8 +302,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 	cir_man = man;
 	cir_exp = exp;
 	 /* cbs = cbs_mantissa * 2^cbs_exponent */
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.cbs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(cbs, &man, &exp);
 	/* Check if cbs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -278,8 +315,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 				cbs_man << ASO_DSEG_CBS_MAN_OFFSET |
 				cir_exp << ASO_DSEG_CIR_EXP_OFFSET |
 				cir_man);
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.ebs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(ebs, &man, &exp);
 	/* Check if ebs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -319,11 +355,15 @@ mlx5_flow_mtr_cap_get(struct rte_eth_dev *dev,
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
 					  "Meter is not supported");
 	memset(cap, 0, sizeof(*cap));
-	if (priv->sh->meter_aso_en)
+	if (priv->sh->meter_aso_en) {
 		/* 2 meters per one ASO cache line. */
 		cap->n_max = 1 << (qattr->log_max_num_meter_aso + 1);
-	else
+		cap->srtcm_rfc2697_packet_mode_supported = 1;
+	} else {
 		cap->n_max = 1 << qattr->log_max_flow_meter;
+		cap->srtcm_rfc2697_packet_mode_supported = 0;
+	}
+	cap->srtcm_rfc2697_byte_mode_supported = 1;
 	cap->n_shared_max = cap->n_max;
 	cap->identical = 1;
 	cap->shared_identical = 1;
@@ -384,7 +424,7 @@ mlx5_flow_meter_profile_add(struct rte_eth_dev *dev,
 	fmp->id = meter_profile_id;
 	fmp->profile = *profile;
 	/* Fill the flow meter parameters for the PRM. */
-	ret = mlx5_flow_meter_param_fill(fmp, error);
+	ret = mlx5_flow_meter_param_fill(fmp, priv, error);
 	if (ret)
 		goto error;
 	/* Add to list. */
-- 
2.27.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v4 0/2] Support meter PPS(packet per second) in MLX5 PMD
  2021-03-31  9:23 [dpdk-dev] [PATCH 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
                   ` (3 preceding siblings ...)
  2021-04-13  4:06 ` [dpdk-dev] [PATCH v3 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
@ 2021-04-21  4:19 ` Li Zhang
  2021-04-21  4:19   ` [dpdk-dev] [PATCH v4 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
  2021-04-21  4:19   ` [dpdk-dev] [PATCH v4 2/2] net/mlx5: support meter PPS profile Li Zhang
  2021-04-27 10:41 ` [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
  5 siblings, 2 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-21  4:19 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports rate is bytes per second(BPS).
Add packet_mode flag in meter profile parameters data structure.
So that it can meter traffic by packet per second.

Depends-on: series=16312  ("Support PPS(packet per second) on meter")
https://patchwork.dpdk.org/project/dpdk/list/?series=16312

Depends-on: series=16535  ("support meter policy operations")
https://patchwork.dpdk.org/project/dpdk/list/?series=16535

v4:
* Rebase.
V3:
* Rebase.
* Fix comments about Depends-on.
V2:
* Fix comments about commit-log

Li Zhang (2):
  common/mlx5: add meter mode definition in PRM file
  net/mlx5: support meter PPS profile

 doc/guides/nics/mlx5.rst           |  1 +
 drivers/common/mlx5/mlx5_prm.h     |  8 ++++
 drivers/net/mlx5/mlx5_flow_aso.c   | 17 ++++---
 drivers/net/mlx5/mlx5_flow_meter.c | 74 +++++++++++++++++++++++-------
 4 files changed, 77 insertions(+), 23 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v4 1/2] common/mlx5: add meter mode definition in PRM file
  2021-04-21  4:19 ` [dpdk-dev] [PATCH v4 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
@ 2021-04-21  4:19   ` Li Zhang
  2021-04-21  4:19   ` [dpdk-dev] [PATCH v4 2/2] net/mlx5: support meter PPS profile Li Zhang
  1 sibling, 0 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-21  4:19 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Add meter mode definitions in PRM file

Signed-off-by: Li Zhang <lizh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/common/mlx5/mlx5_prm.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index c6d8060bb9..efa5ae67bf 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -2297,6 +2297,13 @@ struct mlx5_ifc_flow_meter_parameters_bits {
 #define MLX5_IFC_FLOW_METER_PARAM_MASK UINT64_C(0x80FFFFFF)
 #define MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL 0x14BF00C8
 
+enum {
+	MLX5_METER_MODE_IP_LEN = 0x0,
+	MLX5_METER_MODE_L2_LEN = 0x1,
+	MLX5_METER_MODE_L2_IPG_LEN = 0x2,
+	MLX5_METER_MODE_PKT = 0x3,
+};
+
 enum {
 	MLX5_CQE_SIZE_64B = 0x0,
 	MLX5_CQE_SIZE_128B = 0x1,
@@ -2671,6 +2678,7 @@ struct mlx5_aso_mtr_dseg {
 #define ASO_DSEG_VALID_OFFSET 31
 #define ASO_DSEG_BO_OFFSET 30
 #define ASO_DSEG_SC_OFFSET 28
+#define ASO_DSEG_MTR_MODE 24
 #define ASO_DSEG_CBS_EXP_OFFSET 24
 #define ASO_DSEG_CBS_MAN_OFFSET 16
 #define ASO_DSEG_CIR_EXP_MASK 0x1F
-- 
2.27.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v4 2/2] net/mlx5: support meter PPS profile
  2021-04-21  4:19 ` [dpdk-dev] [PATCH v4 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
  2021-04-21  4:19   ` [dpdk-dev] [PATCH v4 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
@ 2021-04-21  4:19   ` Li Zhang
  1 sibling, 0 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-21  4:19 UTC (permalink / raw)
  To: dekelp, orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports bytes per second(BPS).
Such as Single Rate Three Color Marker (srTCM rfc2697)
Add packet_mode flag to support rate is packet per second.
So that it can meter traffic by packet per second (PPS).

Signed-off-by: Li Zhang <lizh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 doc/guides/nics/mlx5.rst           |  1 +
 drivers/net/mlx5/mlx5_flow_aso.c   | 17 ++++---
 drivers/net/mlx5/mlx5_flow_meter.c | 74 +++++++++++++++++++++++-------
 3 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index b27a9a69f6..2bb4f18a08 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -416,6 +416,7 @@ Limitations
      - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
      - yellow: must be empty.
      - RED: must be DROP.
+  - meter profile packet mode is supported.
 
 Statistics
 ----------
diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c
index 20cd4fe18c..da513a600c 100644
--- a/drivers/net/mlx5/mlx5_flow_aso.c
+++ b/drivers/net/mlx5/mlx5_flow_aso.c
@@ -191,7 +191,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 	volatile struct mlx5_aso_wqe *restrict wqe;
 	int i;
 	int size = 1 << sq->log_desc_n;
-	uint32_t idx;
 
 	/* All the next fields state should stay constant. */
 	for (i = 0, wqe = &sq->sq_obj.aso_wqes[0]; i < size; ++i, ++wqe) {
@@ -204,11 +203,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 			 (BYTEWISE_64BYTE << ASO_CSEG_DATA_MASK_MODE_OFFSET));
 		wqe->general_cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS <<
 							 MLX5_COMP_MODE_OFFSET);
-		for (idx = 0; idx < MLX5_ASO_METERS_PER_WQE;
-			idx++)
-			wqe->aso_dseg.mtrs[idx].v_bo_sc_bbog_mm =
-				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
-				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	}
 }
 
@@ -664,6 +658,7 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 {
 	volatile struct mlx5_aso_wqe *wqe = NULL;
 	struct mlx5_flow_meter_info *fm = NULL;
+	struct mlx5_flow_meter_profile *fmp;
 	uint16_t size = 1 << sq->log_desc_n;
 	uint16_t mask = size - 1;
 	uint16_t res;
@@ -704,6 +699,16 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 			RTE_BE32(MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL);
 		wqe->aso_dseg.mtrs[dseg_idx].ebs_eir = 0;
 	}
+	fmp = fm->profile;
+	if (fmp->profile.packet_mode)
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET) |
+				(MLX5_METER_MODE_PKT << ASO_DSEG_MTR_MODE));
+	else
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	sq->head++;
 	sq->pi += 2;/* Each WQE contains 2 WQEBB's. */
 	rte_io_wmb();
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index e97a1d77a6..ac2735e6e2 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -144,13 +144,19 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 	if (profile->alg == RTE_MTR_SRTCM_RFC2697) {
 		if (priv->config.hca_attr.qos.flow_meter_old) {
 			/* Verify support for flow meter parameters. */
-			if (profile->srtcm_rfc2697.cir > 0 &&
-			    profile->srtcm_rfc2697.cir <= MLX5_SRTCM_CIR_MAX &&
-			    profile->srtcm_rfc2697.cbs > 0 &&
-			    profile->srtcm_rfc2697.cbs <= MLX5_SRTCM_CBS_MAX &&
-			    profile->srtcm_rfc2697.ebs <= MLX5_SRTCM_EBS_MAX)
-				return 0;
-			else
+			if (priv->sh->meter_aso_en && profile->packet_mode) {
+				if (profile->srtcm_rfc2697.cir > 0 &&
+					(profile->srtcm_rfc2697.cir <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CIR_MAX &&
+					profile->srtcm_rfc2697.cbs > 0 &&
+					(profile->srtcm_rfc2697.cbs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CBS_MAX &&
+					(profile->srtcm_rfc2697.ebs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_EBS_MAX)
+					return 0;
 				return -rte_mtr_error_set
 					     (error, ENOTSUP,
 					      RTE_MTR_ERROR_TYPE_MTR_PARAMS,
@@ -158,6 +164,22 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 					      profile->srtcm_rfc2697.ebs ?
 					      "Metering value ebs must be 0." :
 					      "Invalid metering parameters.");
+			}
+			if (profile->srtcm_rfc2697.cir > 0 &&
+				profile->srtcm_rfc2697.cir <=
+						MLX5_SRTCM_CIR_MAX &&
+				profile->srtcm_rfc2697.cbs > 0 &&
+				profile->srtcm_rfc2697.cbs <=
+						MLX5_SRTCM_CBS_MAX &&
+				profile->srtcm_rfc2697.ebs <=
+						MLX5_SRTCM_EBS_MAX)
+				return 0;
+			return -rte_mtr_error_set(error, ENOTSUP,
+					RTE_MTR_ERROR_TYPE_MTR_PARAMS,
+					NULL,
+					profile->srtcm_rfc2697.ebs ?
+					"Metering value ebs must be 0." :
+					"Invalid metering parameters.");
 		}
 	}
 	return -rte_mtr_error_set(error, ENOTSUP,
@@ -241,20 +263,36 @@ mlx5_flow_meter_xbs_man_exp_calc(uint64_t xbs, uint8_t *man, uint8_t *exp)
  */
 static int
 mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
-			  struct rte_mtr_error *error)
+			struct mlx5_priv *priv, struct rte_mtr_error *error)
 {
 	struct mlx5_flow_meter_srtcm_rfc2697_prm *srtcm = &fmp->srtcm_prm;
 	uint8_t man, exp;
 	uint32_t cbs_exp, cbs_man, cir_exp, cir_man;
 	uint32_t ebs_exp, ebs_man;
+	uint64_t cir, cbs, ebs;
 
 	if (fmp->profile.alg != RTE_MTR_SRTCM_RFC2697)
 		return -rte_mtr_error_set(error, ENOTSUP,
 				RTE_MTR_ERROR_TYPE_METER_PROFILE,
 				NULL, "Metering algorithm not supported.");
+	if (!priv->sh->meter_aso_en && fmp->profile.packet_mode)
+		return -rte_mtr_error_set(error, ENOTSUP,
+			RTE_MTR_ERROR_TYPE_METER_PROFILE,
+			NULL, "Metering algorithm packet mode not supported.");
+	if (priv->sh->meter_aso_en && fmp->profile.packet_mode) {
+		cir = fmp->profile.srtcm_rfc2697.cir <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		cbs = fmp->profile.srtcm_rfc2697.cbs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		ebs = fmp->profile.srtcm_rfc2697.ebs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+	} else {
+		cir = fmp->profile.srtcm_rfc2697.cir;
+		cbs = fmp->profile.srtcm_rfc2697.cbs;
+		ebs = fmp->profile.srtcm_rfc2697.ebs;
+	}
 	/* cir = 8G * cir_mantissa * 1/(2^cir_exponent)) Bytes/Sec */
-	mlx5_flow_meter_cir_man_exp_calc(fmp->profile.srtcm_rfc2697.cir,
-				    &man, &exp);
+	mlx5_flow_meter_cir_man_exp_calc(cir, &man, &exp);
 	/* Check if cir mantissa is too large. */
 	if (exp > ASO_DSEG_CIR_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -264,8 +302,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 	cir_man = man;
 	cir_exp = exp;
 	 /* cbs = cbs_mantissa * 2^cbs_exponent */
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.cbs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(cbs, &man, &exp);
 	/* Check if cbs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -278,8 +315,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 				cbs_man << ASO_DSEG_CBS_MAN_OFFSET |
 				cir_exp << ASO_DSEG_CIR_EXP_OFFSET |
 				cir_man);
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.ebs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(ebs, &man, &exp);
 	/* Check if ebs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -319,11 +355,15 @@ mlx5_flow_mtr_cap_get(struct rte_eth_dev *dev,
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
 					  "Meter is not supported");
 	memset(cap, 0, sizeof(*cap));
-	if (priv->sh->meter_aso_en)
+	if (priv->sh->meter_aso_en) {
 		/* 2 meters per one ASO cache line. */
 		cap->n_max = 1 << (qattr->log_max_num_meter_aso + 1);
-	else
+		cap->srtcm_rfc2697_packet_mode_supported = 1;
+	} else {
 		cap->n_max = 1 << qattr->log_max_flow_meter;
+		cap->srtcm_rfc2697_packet_mode_supported = 0;
+	}
+	cap->srtcm_rfc2697_byte_mode_supported = 1;
 	cap->n_shared_max = cap->n_max;
 	cap->identical = 1;
 	cap->shared_identical = 1;
@@ -384,7 +424,7 @@ mlx5_flow_meter_profile_add(struct rte_eth_dev *dev,
 	fmp->id = meter_profile_id;
 	fmp->profile = *profile;
 	/* Fill the flow meter parameters for the PRM. */
-	ret = mlx5_flow_meter_param_fill(fmp, error);
+	ret = mlx5_flow_meter_param_fill(fmp, priv, error);
 	if (ret)
 		goto error;
 	/* Add to list. */
-- 
2.27.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD
  2021-03-31  9:23 [dpdk-dev] [PATCH 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
                   ` (4 preceding siblings ...)
  2021-04-21  4:19 ` [dpdk-dev] [PATCH v4 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
@ 2021-04-27 10:41 ` Li Zhang
  2021-04-27 10:41   ` [dpdk-dev] [PATCH v5 1/1] net/mlx5: support meter PPS profile Li Zhang
  2021-04-28  6:42   ` [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD Raslan Darawsheh
  5 siblings, 2 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-27 10:41 UTC (permalink / raw)
  To: orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports rate is bytes per second(BPS).
Add packet_mode flag in meter profile parameters data structure.
So that it can meter traffic by packet per second.

Depends-on: series=16312  ("Support PPS(packet per second) on meter")
https://patchwork.dpdk.org/project/dpdk/list/?series=16312

Depends-on: series=16535  ("support meter policy operations")
https://patchwork.dpdk.org/project/dpdk/list/?series=16535

V5:
* Fix comments about release-note and merge two patches.
v4:
* Rebase.
V3:
* Rebase.
* Fix comments about Depends-on.
V2:
* Fix comments about commit-log

Li Zhang (1):
  net/mlx5: support meter PPS profile

 doc/guides/nics/mlx5.rst               |  1 +
 doc/guides/rel_notes/release_21_05.rst |  1 +
 drivers/common/mlx5/mlx5_prm.h         |  8 +++
 drivers/net/mlx5/mlx5_flow_aso.c       | 17 +++---
 drivers/net/mlx5/mlx5_flow_meter.c     | 74 ++++++++++++++++++++------
 5 files changed, 78 insertions(+), 23 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [dpdk-dev] [PATCH v5 1/1] net/mlx5: support meter PPS profile
  2021-04-27 10:41 ` [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
@ 2021-04-27 10:41   ` Li Zhang
  2021-04-28  6:42   ` [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD Raslan Darawsheh
  1 sibling, 0 replies; 15+ messages in thread
From: Li Zhang @ 2021-04-27 10:41 UTC (permalink / raw)
  To: orika, viacheslavo, matan, shahafs; +Cc: dev, thomas, rasland, roniba

Currently meter algorithms only supports bytes units for meter profiles.
Using ASO feature, the driver can support metering in per packet units.

Add support for packet units in meter profiles.

Signed-off-by: Li Zhang <lizh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 doc/guides/nics/mlx5.rst               |  1 +
 doc/guides/rel_notes/release_21_05.rst |  1 +
 drivers/common/mlx5/mlx5_prm.h         |  8 +++
 drivers/net/mlx5/mlx5_flow_aso.c       | 17 +++---
 drivers/net/mlx5/mlx5_flow_meter.c     | 74 ++++++++++++++++++++------
 5 files changed, 78 insertions(+), 23 deletions(-)

diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index b27a9a69f6..2bb4f18a08 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -416,6 +416,7 @@ Limitations
      - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
      - yellow: must be empty.
      - RED: must be DROP.
+  - meter profile packet mode is supported.
 
 Statistics
 ----------
diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst
index 58d70bd19f..133a0dbbf2 100644
--- a/doc/guides/rel_notes/release_21_05.rst
+++ b/doc/guides/rel_notes/release_21_05.rst
@@ -164,6 +164,7 @@ New Features
   * 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.
+  * Added support for ASO metering by PPS (packet per second).
 
 * **Updated NXP DPAA driver.**
 
diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index c6d8060bb9..efa5ae67bf 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -2297,6 +2297,13 @@ struct mlx5_ifc_flow_meter_parameters_bits {
 #define MLX5_IFC_FLOW_METER_PARAM_MASK UINT64_C(0x80FFFFFF)
 #define MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL 0x14BF00C8
 
+enum {
+	MLX5_METER_MODE_IP_LEN = 0x0,
+	MLX5_METER_MODE_L2_LEN = 0x1,
+	MLX5_METER_MODE_L2_IPG_LEN = 0x2,
+	MLX5_METER_MODE_PKT = 0x3,
+};
+
 enum {
 	MLX5_CQE_SIZE_64B = 0x0,
 	MLX5_CQE_SIZE_128B = 0x1,
@@ -2671,6 +2678,7 @@ struct mlx5_aso_mtr_dseg {
 #define ASO_DSEG_VALID_OFFSET 31
 #define ASO_DSEG_BO_OFFSET 30
 #define ASO_DSEG_SC_OFFSET 28
+#define ASO_DSEG_MTR_MODE 24
 #define ASO_DSEG_CBS_EXP_OFFSET 24
 #define ASO_DSEG_CBS_MAN_OFFSET 16
 #define ASO_DSEG_CIR_EXP_MASK 0x1F
diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c
index 20cd4fe18c..da513a600c 100644
--- a/drivers/net/mlx5/mlx5_flow_aso.c
+++ b/drivers/net/mlx5/mlx5_flow_aso.c
@@ -191,7 +191,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 	volatile struct mlx5_aso_wqe *restrict wqe;
 	int i;
 	int size = 1 << sq->log_desc_n;
-	uint32_t idx;
 
 	/* All the next fields state should stay constant. */
 	for (i = 0, wqe = &sq->sq_obj.aso_wqes[0]; i < size; ++i, ++wqe) {
@@ -204,11 +203,6 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq)
 			 (BYTEWISE_64BYTE << ASO_CSEG_DATA_MASK_MODE_OFFSET));
 		wqe->general_cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS <<
 							 MLX5_COMP_MODE_OFFSET);
-		for (idx = 0; idx < MLX5_ASO_METERS_PER_WQE;
-			idx++)
-			wqe->aso_dseg.mtrs[idx].v_bo_sc_bbog_mm =
-				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
-				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	}
 }
 
@@ -664,6 +658,7 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 {
 	volatile struct mlx5_aso_wqe *wqe = NULL;
 	struct mlx5_flow_meter_info *fm = NULL;
+	struct mlx5_flow_meter_profile *fmp;
 	uint16_t size = 1 << sq->log_desc_n;
 	uint16_t mask = size - 1;
 	uint16_t res;
@@ -704,6 +699,16 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 			RTE_BE32(MLX5_IFC_FLOW_METER_DISABLE_CBS_CIR_VAL);
 		wqe->aso_dseg.mtrs[dseg_idx].ebs_eir = 0;
 	}
+	fmp = fm->profile;
+	if (fmp->profile.packet_mode)
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET) |
+				(MLX5_METER_MODE_PKT << ASO_DSEG_MTR_MODE));
+	else
+		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =
+				RTE_BE32((1 << ASO_DSEG_VALID_OFFSET) |
+				(MLX5_FLOW_COLOR_GREEN << ASO_DSEG_SC_OFFSET));
 	sq->head++;
 	sq->pi += 2;/* Each WQE contains 2 WQEBB's. */
 	rte_io_wmb();
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index 753d4abd61..382b8bcdeb 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -144,13 +144,19 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 	if (profile->alg == RTE_MTR_SRTCM_RFC2697) {
 		if (priv->config.hca_attr.qos.flow_meter_old) {
 			/* Verify support for flow meter parameters. */
-			if (profile->srtcm_rfc2697.cir > 0 &&
-			    profile->srtcm_rfc2697.cir <= MLX5_SRTCM_CIR_MAX &&
-			    profile->srtcm_rfc2697.cbs > 0 &&
-			    profile->srtcm_rfc2697.cbs <= MLX5_SRTCM_CBS_MAX &&
-			    profile->srtcm_rfc2697.ebs <= MLX5_SRTCM_EBS_MAX)
-				return 0;
-			else
+			if (priv->sh->meter_aso_en && profile->packet_mode) {
+				if (profile->srtcm_rfc2697.cir > 0 &&
+					(profile->srtcm_rfc2697.cir <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CIR_MAX &&
+					profile->srtcm_rfc2697.cbs > 0 &&
+					(profile->srtcm_rfc2697.cbs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_CBS_MAX &&
+					(profile->srtcm_rfc2697.ebs <<
+					MLX5_MTRS_PPS_MAP_BPS_SHIFT)
+					<= MLX5_SRTCM_EBS_MAX)
+					return 0;
 				return -rte_mtr_error_set
 					     (error, ENOTSUP,
 					      RTE_MTR_ERROR_TYPE_MTR_PARAMS,
@@ -158,6 +164,22 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 					      profile->srtcm_rfc2697.ebs ?
 					      "Metering value ebs must be 0." :
 					      "Invalid metering parameters.");
+			}
+			if (profile->srtcm_rfc2697.cir > 0 &&
+				profile->srtcm_rfc2697.cir <=
+						MLX5_SRTCM_CIR_MAX &&
+				profile->srtcm_rfc2697.cbs > 0 &&
+				profile->srtcm_rfc2697.cbs <=
+						MLX5_SRTCM_CBS_MAX &&
+				profile->srtcm_rfc2697.ebs <=
+						MLX5_SRTCM_EBS_MAX)
+				return 0;
+			return -rte_mtr_error_set(error, ENOTSUP,
+					RTE_MTR_ERROR_TYPE_MTR_PARAMS,
+					NULL,
+					profile->srtcm_rfc2697.ebs ?
+					"Metering value ebs must be 0." :
+					"Invalid metering parameters.");
 		}
 	}
 	return -rte_mtr_error_set(error, ENOTSUP,
@@ -241,20 +263,36 @@ mlx5_flow_meter_xbs_man_exp_calc(uint64_t xbs, uint8_t *man, uint8_t *exp)
  */
 static int
 mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
-			  struct rte_mtr_error *error)
+			struct mlx5_priv *priv, struct rte_mtr_error *error)
 {
 	struct mlx5_flow_meter_srtcm_rfc2697_prm *srtcm = &fmp->srtcm_prm;
 	uint8_t man, exp;
 	uint32_t cbs_exp, cbs_man, cir_exp, cir_man;
 	uint32_t ebs_exp, ebs_man;
+	uint64_t cir, cbs, ebs;
 
 	if (fmp->profile.alg != RTE_MTR_SRTCM_RFC2697)
 		return -rte_mtr_error_set(error, ENOTSUP,
 				RTE_MTR_ERROR_TYPE_METER_PROFILE,
 				NULL, "Metering algorithm not supported.");
+	if (!priv->sh->meter_aso_en && fmp->profile.packet_mode)
+		return -rte_mtr_error_set(error, ENOTSUP,
+			RTE_MTR_ERROR_TYPE_METER_PROFILE,
+			NULL, "Metering algorithm packet mode not supported.");
+	if (priv->sh->meter_aso_en && fmp->profile.packet_mode) {
+		cir = fmp->profile.srtcm_rfc2697.cir <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		cbs = fmp->profile.srtcm_rfc2697.cbs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		ebs = fmp->profile.srtcm_rfc2697.ebs <<
+				MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+	} else {
+		cir = fmp->profile.srtcm_rfc2697.cir;
+		cbs = fmp->profile.srtcm_rfc2697.cbs;
+		ebs = fmp->profile.srtcm_rfc2697.ebs;
+	}
 	/* cir = 8G * cir_mantissa * 1/(2^cir_exponent)) Bytes/Sec */
-	mlx5_flow_meter_cir_man_exp_calc(fmp->profile.srtcm_rfc2697.cir,
-				    &man, &exp);
+	mlx5_flow_meter_cir_man_exp_calc(cir, &man, &exp);
 	/* Check if cir mantissa is too large. */
 	if (exp > ASO_DSEG_CIR_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -264,8 +302,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 	cir_man = man;
 	cir_exp = exp;
 	 /* cbs = cbs_mantissa * 2^cbs_exponent */
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.cbs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(cbs, &man, &exp);
 	/* Check if cbs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -278,8 +315,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 				cbs_man << ASO_DSEG_CBS_MAN_OFFSET |
 				cir_exp << ASO_DSEG_CIR_EXP_OFFSET |
 				cir_man);
-	mlx5_flow_meter_xbs_man_exp_calc(fmp->profile.srtcm_rfc2697.ebs,
-				    &man, &exp);
+	mlx5_flow_meter_xbs_man_exp_calc(ebs, &man, &exp);
 	/* Check if ebs mantissa is too large. */
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -319,11 +355,15 @@ mlx5_flow_mtr_cap_get(struct rte_eth_dev *dev,
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
 					  "Meter is not supported");
 	memset(cap, 0, sizeof(*cap));
-	if (priv->sh->meter_aso_en)
+	if (priv->sh->meter_aso_en) {
 		/* 2 meters per one ASO cache line. */
 		cap->n_max = 1 << (qattr->log_max_num_meter_aso + 1);
-	else
+		cap->srtcm_rfc2697_packet_mode_supported = 1;
+	} else {
 		cap->n_max = 1 << qattr->log_max_flow_meter;
+		cap->srtcm_rfc2697_packet_mode_supported = 0;
+	}
+	cap->srtcm_rfc2697_byte_mode_supported = 1;
 	cap->n_shared_max = cap->n_max;
 	cap->identical = 1;
 	cap->shared_identical = 1;
@@ -384,7 +424,7 @@ mlx5_flow_meter_profile_add(struct rte_eth_dev *dev,
 	fmp->id = meter_profile_id;
 	fmp->profile = *profile;
 	/* Fill the flow meter parameters for the PRM. */
-	ret = mlx5_flow_meter_param_fill(fmp, error);
+	ret = mlx5_flow_meter_param_fill(fmp, priv, error);
 	if (ret)
 		goto error;
 	/* Add to list. */
-- 
2.27.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD
  2021-04-27 10:41 ` [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
  2021-04-27 10:41   ` [dpdk-dev] [PATCH v5 1/1] net/mlx5: support meter PPS profile Li Zhang
@ 2021-04-28  6:42   ` Raslan Darawsheh
  1 sibling, 0 replies; 15+ messages in thread
From: Raslan Darawsheh @ 2021-04-28  6:42 UTC (permalink / raw)
  To: Li Zhang, Ori Kam, Slava Ovsiienko, Matan Azrad, Shahaf Shuler
  Cc: dev, NBU-Contact-Thomas Monjalon, Roni Bar Yanai

Hi,


> -----Original Message-----
> From: Li Zhang <lizh@nvidia.com>
> Sent: Tuesday, April 27, 2021 1:42 PM
> To: Ori Kam <orika@nvidia.com>; Slava Ovsiienko
> <viacheslavo@nvidia.com>; Matan Azrad <matan@nvidia.com>; Shahaf
> Shuler <shahafs@nvidia.com>
> Cc: dev@dpdk.org; NBU-Contact-Thomas Monjalon
> <thomas@monjalon.net>; Raslan Darawsheh <rasland@nvidia.com>; Roni
> Bar Yanai <roniba@nvidia.com>
> Subject: [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD
> 
> Currently meter algorithms only supports rate is bytes per second(BPS).
> Add packet_mode flag in meter profile parameters data structure.
> So that it can meter traffic by packet per second.
> 
> Depends-on: series=16312  ("Support PPS(packet per second) on meter")
> https://patchwork.dpdk.org/project/dpdk/list/?series=16312
> 
> Depends-on: series=16535  ("support meter policy operations")
> https://patchwork.dpdk.org/project/dpdk/list/?series=16535
> 
> V5:
> * Fix comments about release-note and merge two patches.
> v4:
> * Rebase.
> V3:
> * Rebase.
> * Fix comments about Depends-on.
> V2:
> * Fix comments about commit-log
> 
> Li Zhang (1):
>   net/mlx5: support meter PPS profile
> 
>  doc/guides/nics/mlx5.rst               |  1 +
>  doc/guides/rel_notes/release_21_05.rst |  1 +
>  drivers/common/mlx5/mlx5_prm.h         |  8 +++
>  drivers/net/mlx5/mlx5_flow_aso.c       | 17 +++---
>  drivers/net/mlx5/mlx5_flow_meter.c     | 74 ++++++++++++++++++++------
>  5 files changed, 78 insertions(+), 23 deletions(-)
> 
> --
> 2.27.0

Series applied to next-net-mlx,
Raslan Darawsheh

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-04-28  6:42 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31  9:23 [dpdk-dev] [PATCH 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
2021-03-31  9:23 ` [dpdk-dev] [PATCH 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
2021-03-31  9:23 ` [dpdk-dev] [PATCH 2/2] net/mlx5: support meter PPS profile Li Zhang
2021-04-10  7:31 ` [dpdk-dev] [PATCH v2 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
2021-04-10  7:31   ` [dpdk-dev] [PATCH v2 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
2021-04-10  7:31   ` [dpdk-dev] [PATCH v2 2/2] net/mlx5: support meter PPS profile Li Zhang
2021-04-13  4:06 ` [dpdk-dev] [PATCH v3 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
2021-04-13  4:06   ` [dpdk-dev] [PATCH v3 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
2021-04-13  4:06   ` [dpdk-dev] [PATCH v3 2/2] net/mlx5: support meter PPS profile Li Zhang
2021-04-21  4:19 ` [dpdk-dev] [PATCH v4 0/2] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
2021-04-21  4:19   ` [dpdk-dev] [PATCH v4 1/2] common/mlx5: add meter mode definition in PRM file Li Zhang
2021-04-21  4:19   ` [dpdk-dev] [PATCH v4 2/2] net/mlx5: support meter PPS profile Li Zhang
2021-04-27 10:41 ` [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD Li Zhang
2021-04-27 10:41   ` [dpdk-dev] [PATCH v5 1/1] net/mlx5: support meter PPS profile Li Zhang
2021-04-28  6:42   ` [dpdk-dev] [PATCH v5 0/1] Support meter PPS(packet per second) in MLX5 PMD Raslan Darawsheh

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git