All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bing Zhao <bingz@nvidia.com>
To: <viacheslavo@nvidia.com>, <matan@nvidia.com>
Cc: <dev@dpdk.org>, <orika@nvidia.com>, <rasland@nvidia.com>,
	<thomas@monjalon.net>, <lizh@nvidia.com>, <shunh@nvidia.com>
Subject: [dpdk-dev] [PATCH v2 7/7] net/mlx5: add meter support for trTCM profiles
Date: Sun, 18 Jul 2021 20:18:17 +0300	[thread overview]
Message-ID: <20210718171817.23822-8-bingz@nvidia.com> (raw)
In-Reply-To: <20210718171817.23822-1-bingz@nvidia.com>

The support of RFC2698 and RFC4115 are added in mlx5 PMD. Only the
ASO metering supports these two profiles.

Signed-off-by: Bing Zhao <bingz@nvidia.com>
---
 doc/guides/nics/mlx5.rst               |   1 +
 doc/guides/rel_notes/release_21_08.rst |   1 +
 drivers/common/mlx5/mlx5_prm.h         |   5 +-
 drivers/net/mlx5/mlx5_flow_aso.c       |  23 ++++-
 drivers/net/mlx5/mlx5_flow_meter.c     | 112 ++++++++++++++++---------
 5 files changed, 98 insertions(+), 44 deletions(-)

diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index 9396074b5a..e20d02d607 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -434,6 +434,7 @@ Limitations
      - RED: must be DROP.
   - Policy actions of RSS for green and yellow should have the same configuration except queues.
   - meter profile packet mode is supported.
+  - meter profiles of RFC2697, RFC2698 and RFC4115 are supported.
 
 - Integrity:
 
diff --git a/doc/guides/rel_notes/release_21_08.rst b/doc/guides/rel_notes/release_21_08.rst
index 03d4fd059a..e159615deb 100644
--- a/doc/guides/rel_notes/release_21_08.rst
+++ b/doc/guides/rel_notes/release_21_08.rst
@@ -92,6 +92,7 @@ New Features
   * Added support for matching on VXLAN header last 8-bits reserved field.
   * Optimized multi-thread flow rule insertion rate.
   * Added support for metering policy actions of yellow color.
+  * Added support for metering trTCM RFC2698 and RFC4115.
 
 * **Added Wangxun ngbe PMD.**
 
diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index 7950070976..88705be9d6 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -3031,11 +3031,12 @@ 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_BBOG_OFFSET 27
 #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
-#define ASO_DSEG_CIR_EXP_OFFSET 8
+#define ASO_DSEG_XIR_EXP_MASK 0x1F
+#define ASO_DSEG_XIR_EXP_OFFSET 8
 #define ASO_DSEG_EBS_EXP_OFFSET 24
 #define ASO_DSEG_EBS_MAN_OFFSET 16
 #define ASO_DSEG_EXP_MASK 0x1F
diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c
index 23e22e560a..e11327a11b 100644
--- a/drivers/net/mlx5/mlx5_flow_aso.c
+++ b/drivers/net/mlx5/mlx5_flow_aso.c
@@ -747,10 +747,27 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq,
 		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));
-	/* Only needed for RFC2697. */
-	if (fm->profile->srtcm_prm.ebs_eir)
+	switch (fmp->profile.alg) {
+	case RTE_MTR_SRTCM_RFC2697:
+		/* Only needed for RFC2697. */
+		if (fm->profile->srtcm_prm.ebs_eir)
+			wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm |=
+					RTE_BE32(1 << ASO_DSEG_BO_OFFSET);
+		break;
+	case RTE_MTR_TRTCM_RFC2698:
 		wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm |=
-				RTE_BE32(1 << ASO_DSEG_BO_OFFSET);
+				RTE_BE32(1 << ASO_DSEG_BBOG_OFFSET);
+		break;
+	case RTE_MTR_TRTCM_RFC4115:
+	default:
+		break;
+	}
+	/*
+	 * Note:
+	 * Due to software performance reason, the token fields will not be
+	 * set when posting the WQE to ASO SQ. It will be filled by the HW
+	 * automatically.
+	 */
 	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 cf3fb8aa9d..b077a01896 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -55,7 +55,7 @@ mlx5_flow_meter_action_create(struct mlx5_priv *priv,
 	MLX5_SET(flow_meter_parameters, fmp, cbs_exponent, val);
 	val = (cbs_cir >> ASO_DSEG_CBS_MAN_OFFSET) & ASO_DSEG_MAN_MASK;
 	MLX5_SET(flow_meter_parameters, fmp, cbs_mantissa, val);
-	val = (cbs_cir >> ASO_DSEG_CIR_EXP_OFFSET) & ASO_DSEG_EXP_MASK;
+	val = (cbs_cir >> ASO_DSEG_XIR_EXP_OFFSET) & ASO_DSEG_EXP_MASK;
 	MLX5_SET(flow_meter_parameters, fmp, cir_exponent, val);
 	val = (cbs_cir & ASO_DSEG_MAN_MASK);
 	MLX5_SET(flow_meter_parameters, fmp, cir_mantissa, val);
@@ -194,18 +194,18 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev,
 				  NULL, "Metering algorithm not supported.");
 }
 
-/**
- * Calculate mantissa and exponent for cir.
+/*
+ * Calculate mantissa and exponent for cir / eir.
  *
- * @param[in] cir
+ * @param[in] xir
  *   Value to be calculated.
  * @param[out] man
  *   Pointer to the mantissa.
  * @param[out] exp
  *   Pointer to the exp.
  */
-static void
-mlx5_flow_meter_cir_man_exp_calc(int64_t cir, uint8_t *man, uint8_t *exp)
+static inline void
+mlx5_flow_meter_xir_man_exp_calc(int64_t xir, uint8_t *man, uint8_t *exp)
 {
 	int64_t _cir;
 	int64_t delta = INT64_MAX;
@@ -216,8 +216,8 @@ mlx5_flow_meter_cir_man_exp_calc(int64_t cir, uint8_t *man, uint8_t *exp)
 	for (m = 0; m <= 0xFF; m++) { /* man width 8 bit */
 		for (e = 0; e <= 0x1F; e++) { /* exp width 5bit */
 			_cir = (1000000000ULL * m) >> e;
-			if (llabs(cir - _cir) <= delta) {
-				delta = llabs(cir - _cir);
+			if (llabs(xir - _cir) <= delta) {
+				delta = llabs(xir - _cir);
 				_man = m;
 				_exp = e;
 			}
@@ -227,7 +227,7 @@ mlx5_flow_meter_cir_man_exp_calc(int64_t cir, uint8_t *man, uint8_t *exp)
 	*exp = _exp;
 }
 
-/**
+/*
  * Calculate mantissa and exponent for xbs.
  *
  * @param[in] xbs
@@ -237,7 +237,7 @@ mlx5_flow_meter_cir_man_exp_calc(int64_t cir, uint8_t *man, uint8_t *exp)
  * @param[out] exp
  *   Pointer to the exp.
  */
-static void
+static inline void
 mlx5_flow_meter_xbs_man_exp_calc(uint64_t xbs, uint8_t *man, uint8_t *exp)
 {
 	int _exp;
@@ -275,37 +275,63 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 	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;
+	uint32_t eir_exp, eir_man, ebs_exp, ebs_man;
+	uint64_t cir, cbs, eir, ebs;
 
-	if (fmp->profile.alg != RTE_MTR_SRTCM_RFC2697)
-		return -rte_mtr_error_set(error, ENOTSUP,
+	if (!priv->sh->meter_aso_en) {
+		/* Legacy FW metering will only support srTCM. */
+		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 {
+				NULL, "Metering algorithm is not supported.");
+		if (fmp->profile.packet_mode)
+			return -rte_mtr_error_set(error, ENOTSUP,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"Metering algorithm packet mode is not supported.");
+	}
+	switch (fmp->profile.alg) {
+	case RTE_MTR_SRTCM_RFC2697:
 		cir = fmp->profile.srtcm_rfc2697.cir;
 		cbs = fmp->profile.srtcm_rfc2697.cbs;
+		eir = 0;
 		ebs = fmp->profile.srtcm_rfc2697.ebs;
+		break;
+	case RTE_MTR_TRTCM_RFC2698:
+		MLX5_ASSERT(fmp->profile.trtcm_rfc2698.pir >
+			    fmp->profile.trtcm_rfc2698.cir &&
+			    fmp->profile.trtcm_rfc2698.pbs >
+			    fmp->profile.trtcm_rfc2698.cbs);
+		cir = fmp->profile.trtcm_rfc2698.cir;
+		cbs = fmp->profile.trtcm_rfc2698.cbs;
+		/* EIR / EBS are filled with PIR / PBS. */
+		eir = fmp->profile.trtcm_rfc2698.pir;
+		ebs = fmp->profile.trtcm_rfc2698.pbs;
+		break;
+	case RTE_MTR_TRTCM_RFC4115:
+		cir = fmp->profile.trtcm_rfc4115.cir;
+		cbs = fmp->profile.trtcm_rfc4115.cbs;
+		eir = fmp->profile.trtcm_rfc4115.eir;
+		ebs = fmp->profile.trtcm_rfc4115.ebs;
+		break;
+	default:
+		return -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"Metering algorithm mode is invalid");
+	}
+	/* Adjust the values for PPS mode. */
+	if (fmp->profile.packet_mode) {
+		cir <<= MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		cbs <<= MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		eir <<= MLX5_MTRS_PPS_MAP_BPS_SHIFT;
+		ebs <<= MLX5_MTRS_PPS_MAP_BPS_SHIFT;
 	}
 	/* cir = 8G * cir_mantissa * 1/(2^cir_exponent)) Bytes/Sec */
-	mlx5_flow_meter_cir_man_exp_calc(cir, &man, &exp);
+	mlx5_flow_meter_xir_man_exp_calc(cir, &man, &exp);
 	/* Check if cir mantissa is too large. */
-	if (exp > ASO_DSEG_CIR_EXP_MASK)
+	if (exp > ASO_DSEG_XIR_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
 					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
-					  "meter profile parameter cir is"
-					  " not supported.");
+					  "meter profile parameter cir is not supported.");
 	cir_man = man;
 	cir_exp = exp;
 	 /* cbs = cbs_mantissa * 2^cbs_exponent */
@@ -314,25 +340,33 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp,
 	if (exp > ASO_DSEG_EXP_MASK)
 		return -rte_mtr_error_set(error, ENOTSUP,
 					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
-					  "meter profile parameter cbs is"
-					  " not supported.");
+					  "meter profile parameter cbs is not supported.");
 	cbs_man = man;
 	cbs_exp = exp;
 	srtcm->cbs_cir = rte_cpu_to_be_32(cbs_exp << ASO_DSEG_CBS_EXP_OFFSET |
 					  cbs_man << ASO_DSEG_CBS_MAN_OFFSET |
-					  cir_exp << ASO_DSEG_CIR_EXP_OFFSET |
+					  cir_exp << ASO_DSEG_XIR_EXP_OFFSET |
 					  cir_man);
+	mlx5_flow_meter_xir_man_exp_calc(eir, &man, &exp);
+	/* Check if eir mantissa is too large. */
+	if (exp > ASO_DSEG_XIR_EXP_MASK)
+		return -rte_mtr_error_set(error, ENOTSUP,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "meter profile parameter eir is not supported.");
+	eir_man = man;
+	eir_exp = 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,
 					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
-					  "meter profile parameter ebs is"
-					  " not supported.");
+					  "meter profile parameter ebs is not supported.");
 	ebs_man = man;
 	ebs_exp = exp;
 	srtcm->ebs_eir = rte_cpu_to_be_32(ebs_exp << ASO_DSEG_EBS_EXP_OFFSET |
-					  ebs_man << ASO_DSEG_EBS_MAN_OFFSET);
+					  ebs_man << ASO_DSEG_EBS_MAN_OFFSET |
+					  eir_exp << ASO_DSEG_XIR_EXP_OFFSET |
+					  eir_man);
 	if (srtcm->cbs_cir)
 		fmp->g_support = 1;
 	if (srtcm->ebs_eir)
@@ -1008,7 +1042,7 @@ mlx5_flow_meter_action_modify(struct mlx5_priv *priv,
 				cbs_mantissa, val);
 		}
 		if (modify_bits & MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CIR) {
-			val = (cbs_cir >> ASO_DSEG_CIR_EXP_OFFSET) &
+			val = (cbs_cir >> ASO_DSEG_XIR_EXP_OFFSET) &
 				ASO_DSEG_EXP_MASK;
 			MLX5_SET(flow_meter_parameters, attr,
 				cir_exponent, val);
@@ -1389,7 +1423,7 @@ mlx5_flow_meter_modify_state(struct mlx5_priv *priv,
 				&srtcm, modify_bits, 0, 0);
 	else
 		ret = mlx5_flow_meter_action_modify(priv, fm,
-						   &fm->profile->srtcm_prm,
+						    &fm->profile->srtcm_prm,
 						    modify_bits, 0, 1);
 	if (ret)
 		return -rte_mtr_error_set(error, -ret,
-- 
2.27.0


  parent reply	other threads:[~2021-07-18 17:19 UTC|newest]

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

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20210718171817.23822-8-bingz@nvidia.com \
    --to=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=lizh@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=shunh@nvidia.com \
    --cc=thomas@monjalon.net \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.