DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions
@ 2021-09-27  8:21 skori
  2021-09-27  8:21 ` [dpdk-dev] [PATCH v2 02/27] common/cnxk: support RoC API to get level to index skori
                   ` (26 more replies)
  0 siblings, 27 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:21 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao; +Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

To support ingress policer on CN10K, MBOX interfaces and HW
definitions are synced.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/hw/nix.h   | 13 ++++++++++---
 drivers/common/cnxk/roc_mbox.h | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/common/cnxk/hw/nix.h b/drivers/common/cnxk/hw/nix.h
index 6b86002ead..53cdfbb142 100644
--- a/drivers/common/cnxk/hw/nix.h
+++ b/drivers/common/cnxk/hw/nix.h
@@ -692,9 +692,16 @@
 #define NIX_RX_BAND_PROF_ACTIONRESULT_DROP (0x1ull) /* [CN10K, .) */
 #define NIX_RX_BAND_PROF_ACTIONRESULT_RED  (0x2ull) /* [CN10K, .) */
 
-#define NIX_RX_BAND_PROF_LAYER_LEAF   (0x0ull) /* [CN10K, .) */
-#define NIX_RX_BAND_PROF_LAYER_MIDDLE (0x1ull) /* [CN10K, .) */
-#define NIX_RX_BAND_PROF_LAYER_TOP    (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_LEAF    (0x0ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_INVALID (0x1ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_MIDDLE  (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_TOP     (0x3ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_MAX     (0x4ull) /* [CN10K, .) */
+
+#define NIX_RX_BAND_PROF_PC_MODE_VLAN (0x0ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_DSCP (0x1ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_GEN  (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_RSVD (0x3ull) /* [CN10K, .) */
 
 #define NIX_RX_COLORRESULT_GREEN  (0x0ull) /* [CN10K, .) */
 #define NIX_RX_COLORRESULT_YELLOW (0x1ull) /* [CN10K, .) */
diff --git a/drivers/common/cnxk/roc_mbox.h b/drivers/common/cnxk/roc_mbox.h
index b5da931b81..c8b97e9aee 100644
--- a/drivers/common/cnxk/roc_mbox.h
+++ b/drivers/common/cnxk/roc_mbox.h
@@ -234,7 +234,11 @@ struct mbox_msghdr {
 	  nix_inline_ipsec_lf_cfg, msg_rsp)                                    \
 	M(NIX_CN10K_AQ_ENQ, 0x801b, nix_cn10k_aq_enq, nix_cn10k_aq_enq_req,    \
 	  nix_cn10k_aq_enq_rsp)                                                \
-	M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info)
+	M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info)      \
+	M(NIX_BANDPROF_ALLOC, 0x801d, nix_bandprof_alloc,                      \
+	  nix_bandprof_alloc_req, nix_bandprof_alloc_rsp)                      \
+	M(NIX_BANDPROF_FREE, 0x801e, nix_bandprof_free, nix_bandprof_free_req, \
+	  msg_rsp)
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES                                                   \
@@ -771,6 +775,10 @@ struct nix_cn10k_aq_enq_req {
 		__io struct nix_rsse_s rss;
 		/* Valid when op == WRITE/INIT and ctype == NIX_AQ_CTYPE_MCE */
 		__io struct nix_rx_mce_s mce;
+		/* Valid when op == WRITE/INIT and
+		 * ctype == NIX_AQ_CTYPE_BAND_PROF
+		 */
+		__io struct nix_band_prof_s prof;
 	};
 	/* Mask data when op == WRITE (1=write, 0=don't write) */
 	union {
@@ -784,6 +792,8 @@ struct nix_cn10k_aq_enq_req {
 		__io struct nix_rsse_s rss_mask;
 		/* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_MCE */
 		__io struct nix_rx_mce_s mce_mask;
+		/* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_BAND_PROF */
+		__io struct nix_band_prof_s prof_mask;
 	};
 };
 
@@ -795,6 +805,7 @@ struct nix_cn10k_aq_enq_rsp {
 		struct nix_cq_ctx_s cq;
 		struct nix_rsse_s rss;
 		struct nix_rx_mce_s mce;
+		struct nix_band_prof_s prof;
 	};
 };
 
@@ -1129,6 +1140,27 @@ struct nix_hw_info {
 	uint16_t __io rsvd[15];
 };
 
+struct nix_bandprof_alloc_req {
+	struct mbox_msghdr hdr;
+	/* Count of profiles needed per layer */
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+};
+
+struct nix_bandprof_alloc_rsp {
+	struct mbox_msghdr hdr;
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+
+#define BANDPROF_PER_PFFUNC 64
+	uint16_t __io prof_idx[NIX_RX_BAND_PROF_LAYER_MAX][BANDPROF_PER_PFFUNC];
+};
+
+struct nix_bandprof_free_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io free_all;
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+	uint16_t __io prof_idx[NIX_RX_BAND_PROF_LAYER_MAX][BANDPROF_PER_PFFUNC];
+};
+
 /* SSO mailbox error codes
  * Range 501 - 600.
  */
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 02/27] common/cnxk: support RoC API to get level to index
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
@ 2021-09-27  8:21 ` skori
  2021-09-27  8:21 ` [dpdk-dev] [PATCH v2 03/27] common/cnxk: support RoC API to get profile count skori
                   ` (25 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:21 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform supports policer up to 3 level of hierarchy.
Implement RoC API to get corresponding index for given level.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/meson.build    |  1 +
 drivers/common/cnxk/roc_nix.h      | 11 +++++++++++
 drivers/common/cnxk/roc_nix_bpf.c  | 22 ++++++++++++++++++++++
 drivers/common/cnxk/roc_nix_priv.h |  1 +
 drivers/common/cnxk/version.map    |  1 +
 5 files changed, 36 insertions(+)
 create mode 100644 drivers/common/cnxk/roc_nix_bpf.c

diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build
index 8a551d15d6..62901e66e7 100644
--- a/drivers/common/cnxk/meson.build
+++ b/drivers/common/cnxk/meson.build
@@ -25,6 +25,7 @@ sources = files(
         'roc_mbox.c',
         'roc_model.c',
         'roc_nix.c',
+        'roc_nix_bpf.c',
         'roc_nix_debug.c',
         'roc_nix_fc.c',
         'roc_nix_irq.c',
diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index b0e6fabe31..1488c24f59 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -6,6 +6,8 @@
 #define _ROC_NIX_H_
 
 /* Constants */
+#define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
+
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
 	ROC_NIX_RSS_RETA_SZ_128 = 128,
@@ -29,6 +31,12 @@ enum roc_nix_vlan_type {
 	ROC_NIX_VLAN_TYPE_OUTER = 0x02,
 };
 
+enum roc_nix_bpf_level_flag {
+	ROC_NIX_BPF_LEVEL_F_LEAF = BIT(0),
+	ROC_NIX_BPF_LEVEL_F_MID = BIT(1),
+	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -468,6 +476,9 @@ int __roc_api roc_nix_tm_rsrc_count(struct roc_nix *roc_nix,
 int __roc_api roc_nix_tm_node_name_get(struct roc_nix *roc_nix,
 				       uint32_t node_id, char *buf,
 				       size_t buflen);
+/* Ingress Policer API */
+uint8_t __roc_api
+roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
 /* MAC */
 int __roc_api roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start);
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
new file mode 100644
index 0000000000..b588cc16e4
--- /dev/null
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell.
+ */
+
+#include "roc_api.h"
+#include "roc_priv.h"
+
+uint8_t
+roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
+{
+	uint8_t idx;
+
+	if (level_f & ROC_NIX_BPF_LEVEL_F_LEAF)
+		idx = 0;
+	else if (level_f & ROC_NIX_BPF_LEVEL_F_MID)
+		idx = 1;
+	else if (level_f & ROC_NIX_BPF_LEVEL_F_TOP)
+		idx = 2;
+	else
+		idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	return idx;
+}
diff --git a/drivers/common/cnxk/roc_nix_priv.h b/drivers/common/cnxk/roc_nix_priv.h
index 9dc0c88a6f..94040fc744 100644
--- a/drivers/common/cnxk/roc_nix_priv.h
+++ b/drivers/common/cnxk/roc_nix_priv.h
@@ -170,6 +170,7 @@ enum nix_err_status {
 	NIX_ERR_INVALID_RANGE,
 	NIX_ERR_INTERNAL,
 	NIX_ERR_OP_NOTSUP,
+	NIX_ERR_HW_NOTSUP,
 	NIX_ERR_QUEUE_INVALID_RANGE,
 	NIX_ERR_AQ_READ_FAILED,
 	NIX_ERR_AQ_WRITE_FAILED,
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 5df2e56ce6..c19f74fe91 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -77,6 +77,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 03/27] common/cnxk: support RoC API to get profile count
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
  2021-09-27  8:21 ` [dpdk-dev] [PATCH v2 02/27] common/cnxk: support RoC API to get level to index skori
@ 2021-09-27  8:21 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 04/27] common/cnxk: support RoC API to alloc bandwidth profiles skori
                   ` (24 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:21 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement interface to get available profile count for given
nixlf.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  5 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 46 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 52 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 1488c24f59..3d3e169977 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -7,6 +7,7 @@
 
 /* Constants */
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
+#define ROC_NIX_BPF_LEVEL_MAX	      3
 
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
@@ -477,6 +478,10 @@ int __roc_api roc_nix_tm_node_name_get(struct roc_nix *roc_nix,
 				       uint32_t node_id, char *buf,
 				       size_t buflen);
 /* Ingress Policer API */
+int __roc_api
+roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX] /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index b588cc16e4..af9dffa90c 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -5,6 +5,14 @@
 #include "roc_api.h"
 #include "roc_priv.h"
 
+#define NIX_MAX_BPF_COUNT_LEAF_LAYER 64
+#define NIX_MAX_BPF_COUNT_MID_LAYER  8
+#define NIX_MAX_BPF_COUNT_TOP_LAYER  1
+
+#define NIX_BPF_LEVEL_F_MASK                                                   \
+	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
+	 ROC_NIX_BPF_LEVEL_F_TOP)
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -20,3 +28,41 @@ roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 		idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
 	return idx;
 }
+
+int
+roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
+{
+	uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
+	uint8_t leaf_idx, mid_idx, top_idx;
+
+	PLT_SET_USED(roc_nix);
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!mask)
+		return NIX_ERR_PARAM;
+
+	/* Currently No MBOX interface is available to get number
+	 * of bandwidth profiles. So numbers per level are hard coded,
+	 * considering 3 RPM blocks and each block has 4 LMAC's.
+	 * So total 12 physical interfaces are in system. Each interface
+	 * supports following bandwidth profiles.
+	 */
+
+	leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
+	mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
+	top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[leaf_idx] = NIX_MAX_BPF_COUNT_LEAF_LAYER;
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[mid_idx] = NIX_MAX_BPF_COUNT_MID_LAYER;
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[top_idx] = NIX_MAX_BPF_COUNT_TOP_LAYER;
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index c19f74fe91..790a32e2e0 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -77,6 +77,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_count_get;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 04/27] common/cnxk: support RoC API to alloc bandwidth profiles
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
  2021-09-27  8:21 ` [dpdk-dev] [PATCH v2 02/27] common/cnxk: support RoC API to get level to index skori
  2021-09-27  8:21 ` [dpdk-dev] [PATCH v2 03/27] common/cnxk: support RoC API to get profile count skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 05/27] common/cnxk: support RoC API to free " skori
                   ` (23 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to allocate HW resources i.e. bandwidth
profiles for policer processing on CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  11 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 104 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 3 files changed, 116 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 3d3e169977..b55333a01c 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -6,6 +6,7 @@
 #define _ROC_NIX_H_
 
 /* Constants */
+#define ROC_NIX_BPF_PER_PFFUNC	      64
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
 
@@ -38,6 +39,12 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+struct roc_nix_bpf_objs {
+	uint16_t level;
+	uint16_t count;
+	uint16_t ids[ROC_NIX_BPF_PER_PFFUNC];
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -482,6 +489,10 @@ int __roc_api
 roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
+				uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
+				struct roc_nix_bpf_objs *profs /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index af9dffa90c..06394bda07 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -13,6 +13,19 @@
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
 
+static uint8_t sw_to_hw_lvl_map[] = {NIX_RX_BAND_PROF_LAYER_LEAF,
+				     NIX_RX_BAND_PROF_LAYER_MIDDLE,
+				     NIX_RX_BAND_PROF_LAYER_TOP};
+
+static inline struct mbox *
+get_mbox(struct roc_nix *roc_nix)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct dev *dev = &nix->dev;
+
+	return dev->mbox;
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -66,3 +79,94 @@ roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 
 	return 0;
 }
+
+int
+roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		  uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
+		  struct roc_nix_bpf_objs *profs)
+{
+	uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_alloc_req *req;
+	struct nix_bandprof_alloc_rsp *rsp;
+	uint8_t leaf_idx, mid_idx, top_idx;
+	int rc = -ENOSPC, i;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!mask)
+		return NIX_ERR_PARAM;
+
+	leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
+	mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
+	top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
+
+	if ((leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[leaf_idx] > NIX_MAX_BPF_COUNT_LEAF_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	if ((mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[mid_idx] > NIX_MAX_BPF_COUNT_MID_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	if ((top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[top_idx] > NIX_MAX_BPF_COUNT_TOP_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	req = mbox_alloc_msg_nix_bandprof_alloc(mbox);
+	if (req == NULL)
+		goto exit;
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[leaf_idx]] =
+			per_lvl_cnt[leaf_idx];
+	}
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[mid_idx]] =
+			per_lvl_cnt[mid_idx];
+	}
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[top_idx]] =
+			per_lvl_cnt[top_idx];
+	}
+
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		goto exit;
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[leaf_idx].level = leaf_idx;
+		profs[leaf_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[leaf_idx]];
+		for (i = 0; i < profs[leaf_idx].count; i++) {
+			profs[leaf_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[leaf_idx]][i];
+		}
+	}
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[mid_idx].level = mid_idx;
+		profs[mid_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[mid_idx]];
+		for (i = 0; i < profs[mid_idx].count; i++) {
+			profs[mid_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[mid_idx]][i];
+		}
+	}
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[top_idx].level = top_idx;
+		profs[top_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[top_idx]];
+		for (i = 0; i < profs[top_idx].count; i++) {
+			profs[top_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[top_idx]][i];
+		}
+	}
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 790a32e2e0..81e76919b5 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -77,6 +77,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_alloc;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 05/27] common/cnxk: support RoC API to free bandwidth profiles
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (2 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 04/27] common/cnxk: support RoC API to alloc bandwidth profiles skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 06/27] common/cnxk: support RoC API to configure bandwidth profile skori
                   ` (22 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC interface to free HW bandwidth profiles on
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  6 +++++
 drivers/common/cnxk/roc_nix_bpf.c | 40 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  2 ++
 3 files changed, 48 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index b55333a01c..bf451ecdbc 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -493,6 +493,12 @@ int __roc_api roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
 				uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
 				struct roc_nix_bpf_objs *profs /* Out */);
 
+int __roc_api roc_nix_bpf_free(struct roc_nix *roc_nix,
+			       struct roc_nix_bpf_objs *profs,
+			       uint8_t num_prof);
+
+int __roc_api roc_nix_bpf_free_all(struct roc_nix *roc_nix);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 06394bda07..41d31bc6cd 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -170,3 +170,43 @@ roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_free(struct roc_nix *roc_nix, struct roc_nix_bpf_objs *profs,
+		 uint8_t num_prof)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_free_req *req;
+	uint8_t level;
+	int i, j;
+
+	if (num_prof >= NIX_RX_BAND_PROF_LAYER_MAX)
+		return NIX_ERR_INVALID_RANGE;
+
+	req = mbox_alloc_msg_nix_bandprof_free(mbox);
+	if (req == NULL)
+		return -ENOSPC;
+
+	for (i = 0; i < num_prof; i++) {
+		level = sw_to_hw_lvl_map[profs[i].level];
+		req->prof_count[level] = profs[i].count;
+		for (j = 0; j < profs[i].count; j++)
+			req->prof_idx[level][j] = profs[i].ids[j];
+	}
+
+	return mbox_process(mbox);
+}
+
+int
+roc_nix_bpf_free_all(struct roc_nix *roc_nix)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_free_req *req;
+
+	req = mbox_alloc_msg_nix_bandprof_free(mbox);
+	if (req == NULL)
+		return -ENOSPC;
+
+	req->free_all = true;
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 81e76919b5..c45d524d65 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -79,6 +79,8 @@ INTERNAL {
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_free;
+	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 06/27] common/cnxk: support RoC API to configure bandwidth profile
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (3 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 05/27] common/cnxk: support RoC API to free " skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 07/27] common/cnxk: support RoC API to toggle profile state skori
                   ` (21 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to configure HW bandwidth profile for
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     | 108 ++++++++++++++
 drivers/common/cnxk/roc_nix_bpf.c | 231 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 3 files changed, 340 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index bf451ecdbc..af9bbb659c 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -10,6 +10,54 @@
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
 
+/** NIX rate limits */
+#define MAX_RATE_DIV_EXP  12
+#define MAX_RATE_EXPONENT 0xf
+#define MAX_RATE_MANTISSA 0xff
+
+#define NIX_METER_RATE_CONST 2000000ULL
+
+/* NIX rate calculation in Bits/Sec
+ *	PIR_ADD = ((256 + NIX_*_PIR[RATE_MANTISSA])
+ *		<< NIX_*_PIR[RATE_EXPONENT]) / 256
+ *	PIR = (2E6 * PIR_ADD / (1 << NIX_*_PIR[RATE_DIVIDER_EXPONENT]))
+ *
+ *	CIR_ADD = ((256 + NIX_*_CIR[RATE_MANTISSA])
+ *		<< NIX_*_CIR[RATE_EXPONENT]) / 256
+ *	CIR = (2E6 * CIR_ADD / (CCLK_TICKS << NIX_*_CIR[RATE_DIVIDER_EXPONENT]))
+ */
+#define METER_RATE(exponent, mantissa, div_exp)                                \
+	((NIX_METER_RATE_CONST * ((256 + (mantissa)) << (exponent))) /         \
+	 (((1ull << (div_exp)) * 256)))
+
+/* Meter rate limits in Bits/Sec */
+#define ROC_NIX_BPF_RATE_MIN METER_RATE(0, 0, MAX_RATE_DIV_EXP)
+#define ROC_NIX_BPF_RATE_MAX METER_RATE(MAX_RATE_EXPONENT, MAX_RATE_MANTISSA, 0)
+
+#define ROC_NIX_DEFAULT_ADJUST_MANTISSA 511
+#define ROC_NIX_DEFAULT_ADJUST_EXPONENT 0
+
+/** NIX burst limits */
+#define MAX_BURST_EXPONENT 0xf
+#define MAX_BURST_MANTISSA 0xff
+
+/* NIX burst calculation
+ *	PIR_BURST = ((256 + NIX_*_PIR[BURST_MANTISSA])
+ *		<< (NIX_*_PIR[BURST_EXPONENT] + 1))
+ *			/ 256
+ *
+ *	CIR_BURST = ((256 + NIX_*_CIR[BURST_MANTISSA])
+ *		<< (NIX_*_CIR[BURST_EXPONENT] + 1))
+ *			/ 256
+ */
+#define METER_BURST(exponent, mantissa)                                        \
+	(((256 + (mantissa)) << ((exponent) + 1)) / 256)
+
+/** Meter burst limits */
+#define ROC_NIX_BPF_BURST_MIN METER_BURST(0, 0)
+#define ROC_NIX_BPF_BURST_MAX                                                  \
+	METER_BURST(MAX_BURST_EXPONENT, MAX_BURST_MANTISSA)
+
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
 	ROC_NIX_RSS_RETA_SZ_128 = 128,
@@ -39,6 +87,62 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+enum roc_nix_bpf_color {
+	ROC_NIX_BPF_COLOR_GREEN,
+	ROC_NIX_BPF_COLOR_YELLOW,
+	ROC_NIX_BPF_COLOR_RED,
+	ROC_NIX_BPF_COLOR_MAX
+};
+
+enum roc_nix_bpf_algo {
+	ROC_NIX_BPF_ALGO_NONE,
+	ROC_NIX_BPF_ALGO_2698,
+	ROC_NIX_BPF_ALGO_4115,
+	ROC_NIX_BPF_ALGO_2697
+};
+
+enum roc_nix_bpf_lmode { ROC_NIX_BPF_LMODE_BYTE, ROC_NIX_BPF_LMODE_PACKET };
+
+enum roc_nix_bpf_action {
+	ROC_NIX_BPF_ACTION_PASS,
+	ROC_NIX_BPF_ACTION_DROP,
+	ROC_NIX_BPF_ACTION_RED
+};
+
+struct roc_nix_bpf_cfg {
+	enum roc_nix_bpf_algo alg;
+	enum roc_nix_bpf_lmode lmode;
+	union {
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2697. */
+		struct {
+			uint64_t cir;
+			uint64_t cbs;
+			uint64_t ebs;
+		} algo2697;
+
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2698. */
+		struct {
+			uint64_t cir;
+			uint64_t pir;
+			uint64_t cbs;
+			uint64_t pbs;
+		} algo2698;
+
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_4115. */
+		struct {
+			uint64_t cir;
+			uint64_t eir;
+			uint64_t cbs;
+			uint64_t ebs;
+		} algo4115;
+	};
+
+	enum roc_nix_bpf_action action[ROC_NIX_BPF_COLOR_MAX];
+
+	/* Reserved for future config*/
+	uint32_t rsvd[3];
+};
+
 struct roc_nix_bpf_objs {
 	uint16_t level;
 	uint16_t count;
@@ -499,6 +603,10 @@ int __roc_api roc_nix_bpf_free(struct roc_nix *roc_nix,
 
 int __roc_api roc_nix_bpf_free_all(struct roc_nix *roc_nix);
 
+int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+				 enum roc_nix_bpf_level_flag lvl_flag,
+				 struct roc_nix_bpf_cfg *cfg);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 41d31bc6cd..b1a427caaf 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -26,6 +26,103 @@ get_mbox(struct roc_nix *roc_nix)
 	return dev->mbox;
 }
 
+static inline uint64_t
+meter_rate_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p,
+		  uint64_t *div_exp_p)
+{
+	uint64_t div_exp, exponent, mantissa;
+
+	/* Boundary checks */
+	if (value < ROC_NIX_BPF_RATE_MIN || value > ROC_NIX_BPF_RATE_MAX)
+		return 0;
+
+	if (value <= METER_RATE(0, 0, 0)) {
+		/* Calculate rate div_exp and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * (256 + mantissa)
+		 *              / ((1 << div_exp) * 256))
+		 */
+		div_exp = 0;
+		exponent = 0;
+		mantissa = MAX_RATE_MANTISSA;
+
+		while (value < (NIX_METER_RATE_CONST / (1 << div_exp)))
+			div_exp += 1;
+
+		while (value < ((NIX_METER_RATE_CONST * (256 + mantissa)) /
+				((1 << div_exp) * 256)))
+			mantissa -= 1;
+	} else {
+		/* Calculate rate exponent and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * ((256 + mantissa) << exponent)) / 256
+		 *
+		 */
+		div_exp = 0;
+		exponent = MAX_RATE_EXPONENT;
+		mantissa = MAX_RATE_MANTISSA;
+
+		while (value < (NIX_METER_RATE_CONST * (1 << exponent)))
+			exponent -= 1;
+
+		while (value < ((NIX_METER_RATE_CONST *
+				 ((256 + mantissa) << exponent)) /
+				256))
+			mantissa -= 1;
+	}
+
+	if (div_exp > MAX_RATE_DIV_EXP || exponent > MAX_RATE_EXPONENT ||
+	    mantissa > MAX_RATE_MANTISSA)
+		return 0;
+
+	if (div_exp_p)
+		*div_exp_p = div_exp;
+	if (exponent_p)
+		*exponent_p = exponent;
+	if (mantissa_p)
+		*mantissa_p = mantissa;
+
+	/* Calculate real rate value */
+	return METER_RATE(exponent, mantissa, div_exp);
+}
+
+static inline uint64_t
+meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
+{
+	uint64_t exponent, mantissa;
+
+	if (value < ROC_NIX_BPF_BURST_MIN || value > ROC_NIX_BPF_BURST_MAX)
+		return 0;
+
+	/* Calculate burst exponent and mantissa using
+	 * the following formula:
+	 *
+	 * value = (((256 + mantissa) << (exponent + 1)
+	 / 256)
+	 *
+	 */
+	exponent = MAX_BURST_EXPONENT;
+	mantissa = MAX_BURST_MANTISSA;
+
+	while (value < (1ull << (exponent + 1)))
+		exponent -= 1;
+
+	while (value < ((256 + mantissa) << (exponent + 1)) / 256)
+		mantissa -= 1;
+
+	if (exponent > MAX_BURST_EXPONENT || mantissa > MAX_BURST_MANTISSA)
+		return 0;
+
+	if (exponent_p)
+		*exponent_p = exponent;
+	if (mantissa_p)
+		*mantissa_p = mantissa;
+
+	return METER_BURST(exponent, mantissa);
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -210,3 +307,137 @@ roc_nix_bpf_free_all(struct roc_nix *roc_nix)
 	req->free_all = true;
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+		   enum roc_nix_bpf_level_flag lvl_flag,
+		   struct roc_nix_bpf_cfg *cfg)
+{
+	uint64_t exponent_p = 0, mantissa_p = 0, div_exp_p = 0;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!cfg)
+		return NIX_ERR_PARAM;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	aq->prof.adjust_exponent = ROC_NIX_DEFAULT_ADJUST_EXPONENT;
+	aq->prof.adjust_mantissa = ROC_NIX_DEFAULT_ADJUST_MANTISSA;
+	if (cfg->lmode == ROC_NIX_BPF_LMODE_BYTE)
+		aq->prof.adjust_mantissa = ROC_NIX_DEFAULT_ADJUST_MANTISSA / 2;
+
+	aq->prof_mask.adjust_exponent = ~(aq->prof_mask.adjust_exponent);
+	aq->prof_mask.adjust_mantissa = ~(aq->prof_mask.adjust_mantissa);
+
+	switch (cfg->alg) {
+	case ROC_NIX_BPF_ALGO_2697:
+		meter_rate_to_nix(cfg->algo2697.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2697.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2697.ebs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	case ROC_NIX_BPF_ALGO_2698:
+		meter_rate_to_nix(cfg->algo2698.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_rate_to_nix(cfg->algo2698.pir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.peir_mantissa = mantissa_p;
+		aq->prof.peir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2698.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2698.pbs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	case ROC_NIX_BPF_ALGO_4115:
+		meter_rate_to_nix(cfg->algo4115.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_rate_to_nix(cfg->algo4115.eir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.peir_mantissa = mantissa_p;
+		aq->prof.peir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo4115.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo4115.ebs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	default:
+		return NIX_ERR_PARAM;
+	}
+
+	aq->prof.lmode = cfg->lmode;
+	aq->prof.gc_action = cfg->action[ROC_NIX_BPF_COLOR_GREEN];
+	aq->prof.yc_action = cfg->action[ROC_NIX_BPF_COLOR_YELLOW];
+	aq->prof.rc_action = cfg->action[ROC_NIX_BPF_COLOR_RED];
+
+	aq->prof_mask.lmode = ~(aq->prof_mask.lmode);
+	aq->prof_mask.gc_action = ~(aq->prof_mask.gc_action);
+	aq->prof_mask.yc_action = ~(aq->prof_mask.yc_action);
+	aq->prof_mask.rc_action = ~(aq->prof_mask.rc_action);
+
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index c45d524d65..6a009eaf35 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -78,6 +78,7 @@ INTERNAL {
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
+	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 07/27] common/cnxk: support RoC API to toggle profile state
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (4 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 06/27] common/cnxk: support RoC API to configure bandwidth profile skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 08/27] common/cnxk: support RoC API to dump bandwidth profile skori
                   ` (20 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to enable or disable HW bandwidth profiles
on CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  4 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 39 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 44 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index af9bbb659c..b4995cd014 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -262,6 +262,7 @@ struct roc_nix_stats_queue {
 struct roc_nix_rq {
 	/* Input parameters */
 	uint16_t qid;
+	uint16_t bpf_id;
 	uint64_t aura_handle;
 	bool ipsech_ena;
 	uint16_t first_skip;
@@ -607,6 +608,9 @@ int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 				 enum roc_nix_bpf_level_flag lvl_flag,
 				 struct roc_nix_bpf_cfg *cfg);
 
+int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
+				  struct roc_nix_rq *rq, bool enable);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index b1a427caaf..4dcf4cd5b9 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -441,3 +441,42 @@ roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id, struct roc_nix_rq *rq,
+		    bool enable)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (rq->qid >= nix->nb_rx_queues)
+		return NIX_ERR_QUEUE_INVALID_RANGE;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = rq->qid;
+	aq->ctype = NIX_AQ_CTYPE_RQ;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	aq->rq.policer_ena = enable;
+	aq->rq_mask.policer_ena = ~(aq->rq_mask.policer_ena);
+	if (enable) {
+		aq->rq.band_prof_id = id;
+		aq->rq_mask.band_prof_id = ~(aq->rq_mask.band_prof_id);
+	}
+
+	rc = mbox_process(mbox);
+	if (rc)
+		goto exit;
+
+	rq->bpf_id = id;
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 6a009eaf35..4c5adb8212 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -80,6 +80,7 @@ INTERNAL {
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_ena_dis;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 08/27] common/cnxk: support RoC API to dump bandwidth profile
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (5 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 07/27] common/cnxk: support RoC API to toggle profile state skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 09/27] common/cnxk: support RoC API to setup precolor table skori
                   ` (19 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to dump bandwidth profile on CN10K
platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h      |  3 ++
 drivers/common/cnxk/roc_nix_bpf.c  | 86 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_platform.h |  1 +
 drivers/common/cnxk/version.map    |  1 +
 4 files changed, 91 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index b4995cd014..de8d41e42e 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -611,6 +611,9 @@ int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
 				  struct roc_nix_rq *rq, bool enable);
 
+int __roc_api roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
+			       enum roc_nix_bpf_level_flag lvl_flag);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 4dcf4cd5b9..1e495159f4 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -123,6 +123,60 @@ meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
 	return METER_BURST(exponent, mantissa);
 }
 
+static inline void
+nix_lf_bpf_dump(__io struct nix_band_prof_s *bpf)
+{
+	plt_dump("W0: cir_mantissa  \t\t\t%d\nW0: pebs_mantissa \t\t\t0x%03x",
+		 bpf->cir_mantissa, bpf->pebs_mantissa);
+	plt_dump("W0: peir_matissa \t\t\t\t%d\nW0: cbs_exponent \t\t\t%d",
+		 bpf->peir_mantissa, bpf->cbs_exponent);
+	plt_dump("W0: cir_exponent \t\t\t%d\nW0: pebs_exponent \t\t\t%d",
+		 bpf->cir_exponent, bpf->pebs_exponent);
+	plt_dump("W0: peir_exponent \t\t\t%d\n", bpf->peir_exponent);
+	plt_dump("W0: tnl_ena \t\t\t%d\n", bpf->tnl_ena);
+	plt_dump("W0: icolor \t\t\t%d\n", bpf->icolor);
+	plt_dump("W0: pc_mode \t\t\t%d\n", bpf->pc_mode);
+	plt_dump("W1: hl_en \t\t%d\nW1: band_prof_id \t\t%d", bpf->hl_en,
+		 bpf->band_prof_id);
+	plt_dump("W1: meter_algo \t\t%d\nW1: rc_action \t\t%d", bpf->meter_algo,
+		 bpf->rc_action);
+	plt_dump("W1: yc_action \t\t\t%d\nW1: gc_action \t\t\t%d",
+		 bpf->yc_action, bpf->gc_action);
+	plt_dump("W1: adjust_mantissa\t\t\t%d\nW1: adjust_exponent \t\t\t%d",
+		 bpf->adjust_mantissa, bpf->adjust_exponent);
+	plt_dump("W1: rdiv \t\t\t%d\n", bpf->rdiv);
+	plt_dump("W1: l_select \t\t%d\nW2: lmode \t\t%d", bpf->l_sellect,
+		 bpf->lmode);
+	plt_dump("W1: cbs_mantissa \t\t\t%d\n", bpf->cbs_mantissa);
+	plt_dump("W2: tsa \t\t\t0x%" PRIx64 "\n", (uint64_t)bpf->ts);
+	plt_dump("W3: c_accum \t\t%d\nW3: pe_accum \t\t%d", bpf->c_accum,
+		 bpf->pe_accum);
+	plt_dump("W4: green_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_pkt_pass);
+	plt_dump("W5: yellow_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_pkt_pass);
+	plt_dump("W6: red_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_pkt_pass);
+	plt_dump("W7: green_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_octs_pass);
+	plt_dump("W8: yellow_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_octs_pass);
+	plt_dump("W9: red_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_octs_pass);
+	plt_dump("W10: green_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_pkt_drop);
+	plt_dump("W11: yellow_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_pkt_drop);
+	plt_dump("W12: red_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_pkt_drop);
+	plt_dump("W13: green_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_octs_drop);
+	plt_dump("W14: yellow_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_octs_drop);
+	plt_dump("W15: red_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_octs_drop);
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -480,3 +534,35 @@ roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id, struct roc_nix_rq *rq,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
+		 enum roc_nix_bpf_level_flag lvl_flag)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_rsp *rsp;
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_READ;
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (!rc) {
+		plt_dump("============= band prof id =%d ===============", id);
+		nix_lf_bpf_dump(&rsp->prof);
+	}
+
+	return rc;
+}
diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h
index 285b24b82d..69b7c49d8b 100644
--- a/drivers/common/cnxk/roc_platform.h
+++ b/drivers/common/cnxk/roc_platform.h
@@ -155,6 +155,7 @@ extern int cnxk_logtype_tm;
 #define plt_info(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
 #define plt_warn(fmt, args...) RTE_LOG(WARNING, PMD, fmt "\n", ##args)
 #define plt_print(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
+#define plt_dump(fmt, ...)      fprintf(stderr, fmt "\n", ##__VA_ARGS__)
 
 /**
  * Log debug message if given subsystem logging is enabled.
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 4c5adb8212..97386ef273 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -80,6 +80,7 @@ INTERNAL {
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_dump;
 	roc_nix_bpf_ena_dis;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 09/27] common/cnxk: support RoC API to setup precolor table
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (6 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 08/27] common/cnxk: support RoC API to dump bandwidth profile skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 10/27] common/cnxk: support RoC API to connect bandwidth profiles skori
                   ` (18 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

For initial coloring of input packet, CN10K platform maintains
precolor table for VLAN, DSCP and Generic. Implement RoC
interface to setup pre color table.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  20 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 193 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 3 files changed, 214 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index de8d41e42e..4090826a03 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -87,6 +87,15 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+enum roc_nix_bpf_pc_mode {
+	ROC_NIX_BPF_PC_MODE_VLAN_INNER,
+	ROC_NIX_BPF_PC_MODE_VLAN_OUTER,
+	ROC_NIX_BPF_PC_MODE_DSCP_INNER,
+	ROC_NIX_BPF_PC_MODE_DSCP_OUTER,
+	ROC_NIX_BPF_PC_MODE_GEN_INNER,
+	ROC_NIX_BPF_PC_MODE_GEN_OUTER
+};
+
 enum roc_nix_bpf_color {
 	ROC_NIX_BPF_COLOR_GREEN,
 	ROC_NIX_BPF_COLOR_YELLOW,
@@ -149,6 +158,13 @@ struct roc_nix_bpf_objs {
 	uint16_t ids[ROC_NIX_BPF_PER_PFFUNC];
 };
 
+struct roc_nix_bpf_precolor {
+#define ROC_NIX_BPF_PRE_COLOR_MAX 64
+	uint8_t count;
+	enum roc_nix_bpf_pc_mode mode;
+	enum roc_nix_bpf_color color[ROC_NIX_BPF_PRE_COLOR_MAX];
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -614,6 +630,10 @@ int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
 int __roc_api roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
 			       enum roc_nix_bpf_level_flag lvl_flag);
 
+int __roc_api roc_nix_bpf_pre_color_tbl_setup(
+	struct roc_nix *roc_nix, uint16_t id,
+	enum roc_nix_bpf_level_flag lvl_flag, struct roc_nix_bpf_precolor *tbl);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 1e495159f4..5099d22570 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -9,6 +9,10 @@
 #define NIX_MAX_BPF_COUNT_MID_LAYER  8
 #define NIX_MAX_BPF_COUNT_TOP_LAYER  1
 
+#define NIX_BPF_PRECOLOR_GEN_TABLE_SIZE	 16
+#define NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE 16
+#define NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE 64
+
 #define NIX_BPF_LEVEL_F_MASK                                                   \
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
@@ -177,6 +181,107 @@ nix_lf_bpf_dump(__io struct nix_band_prof_s *bpf)
 		 (uint64_t)bpf->red_octs_drop);
 }
 
+static inline void
+nix_precolor_conv_table_write(struct roc_nix *roc_nix, uint64_t val,
+			      uint32_t off)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	int64_t *addr;
+
+	addr = PLT_PTR_ADD(nix->base, off);
+	/* FIXME: Currently writing to this register throwing kernel dump.
+	 * plt_write64(val, addr);
+	 */
+	PLT_SET_USED(val);
+	PLT_SET_USED(addr);
+}
+
+static uint8_t
+nix_precolor_vlan_table_update(struct roc_nix *roc_nix,
+			       struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val = 0, i;
+	uint8_t tn_ena;
+	uint32_t off;
+
+	for (i = 0; i < tbl->count; i++)
+		val |= (((uint64_t)tbl->color[i]) << (2 * i));
+
+	if (tbl->mode == ROC_NIX_BPF_PC_MODE_VLAN_INNER) {
+		off = NIX_LF_RX_VLAN1_COLOR_CONV;
+		tn_ena = true;
+	} else {
+		off = NIX_LF_RX_VLAN0_COLOR_CONV;
+		tn_ena = false;
+	}
+
+	nix_precolor_conv_table_write(roc_nix, val, off);
+	return tn_ena;
+}
+
+static uint8_t
+nix_precolor_inner_dscp_table_update(struct roc_nix *roc_nix,
+				     struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val_lo = 0, val_hi = 0, i, j;
+
+	for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
+		val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	for (j = 0; i < tbl->count; i++, j++)
+		val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	nix_precolor_conv_table_write(roc_nix, val_lo,
+				      NIX_LF_RX_IIP_COLOR_CONV_LO);
+	nix_precolor_conv_table_write(roc_nix, val_hi,
+				      NIX_LF_RX_IIP_COLOR_CONV_HI);
+
+	return true;
+}
+
+static uint8_t
+nix_precolor_outer_dscp_table_update(struct roc_nix *roc_nix,
+				     struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val_lo = 0, val_hi = 0, i, j;
+
+	for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
+		val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	for (j = 0; i < tbl->count; i++, j++)
+		val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	nix_precolor_conv_table_write(roc_nix, val_lo,
+				      NIX_LF_RX_OIP_COLOR_CONV_LO);
+	nix_precolor_conv_table_write(roc_nix, val_hi,
+				      NIX_LF_RX_OIP_COLOR_CONV_HI);
+
+	return false;
+}
+
+static uint8_t
+nix_precolor_gen_table_update(struct roc_nix *roc_nix,
+			      struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val = 0, i;
+	uint8_t tn_ena;
+	uint32_t off;
+
+	for (i = 0; i < tbl->count; i++)
+		val |= (((uint64_t)tbl->color[i]) << (2 * i));
+
+	if (tbl->mode == ROC_NIX_BPF_PC_MODE_GEN_INNER) {
+		off = NIX_LF_RX_GEN_COLOR_CONVX(1);
+		tn_ena = true;
+	} else {
+		off = NIX_LF_RX_GEN_COLOR_CONVX(0);
+		tn_ena = false;
+	}
+
+	nix_precolor_conv_table_write(roc_nix, val, off);
+	return tn_ena;
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -566,3 +671,91 @@ roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
 
 	return rc;
 }
+
+int
+roc_nix_bpf_pre_color_tbl_setup(struct roc_nix *roc_nix, uint16_t id,
+				enum roc_nix_bpf_level_flag lvl_flag,
+				struct roc_nix_bpf_precolor *tbl)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t pc_mode, tn_ena;
+	uint8_t level_idx;
+	int rc;
+
+	if (!tbl || !tbl->count)
+		return NIX_ERR_PARAM;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	switch (tbl->mode) {
+	case ROC_NIX_BPF_PC_MODE_VLAN_INNER:
+	case ROC_NIX_BPF_PC_MODE_VLAN_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_vlan_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_VLAN;
+		break;
+	case ROC_NIX_BPF_PC_MODE_DSCP_INNER:
+		if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_inner_dscp_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
+		break;
+	case ROC_NIX_BPF_PC_MODE_DSCP_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_outer_dscp_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
+		break;
+	case ROC_NIX_BPF_PC_MODE_GEN_INNER:
+	case ROC_NIX_BPF_PC_MODE_GEN_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_GEN_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_GEN_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+
+		tn_ena = nix_precolor_gen_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_GEN;
+		break;
+	default:
+		rc = NIX_ERR_PARAM;
+		goto exit;
+	}
+
+	/* Update corresponding bandwidth profile too */
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+	aq->prof.pc_mode = pc_mode;
+	aq->prof.tnl_ena = tn_ena;
+	aq->prof_mask.pc_mode = ~(aq->prof_mask.pc_mode);
+	aq->prof_mask.tnl_ena = ~(aq->prof_mask.tnl_ena);
+
+	return mbox_process(mbox);
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 97386ef273..a08fbe6013 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -85,6 +85,7 @@ INTERNAL {
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
+	roc_nix_bpf_pre_color_tbl_setup;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 10/27] common/cnxk: support RoC API to connect bandwidth profiles
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (7 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 09/27] common/cnxk: support RoC API to setup precolor table skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 11/27] common/cnxk: support RoC API to get stats to index skori
                   ` (17 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

To maintain chain of bandwidth profiles, they needs to be
connected. Implement RoC API to connect two bandwidth profiles
at different levels.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  6 ++++++
 drivers/common/cnxk/roc_nix_bpf.c | 36 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 43 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 4090826a03..ec279f1f6c 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -7,6 +7,7 @@
 
 /* Constants */
 #define ROC_NIX_BPF_PER_PFFUNC	      64
+#define ROC_NIX_BPF_ID_INVALID	      0xFFFF
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
 
@@ -634,6 +635,11 @@ int __roc_api roc_nix_bpf_pre_color_tbl_setup(
 	struct roc_nix *roc_nix, uint16_t id,
 	enum roc_nix_bpf_level_flag lvl_flag, struct roc_nix_bpf_precolor *tbl);
 
+/* Use ROC_NIX_BPF_ID_INVALID as dst_id to disconnect */
+int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
+				  enum roc_nix_bpf_level_flag lvl_flag,
+				  uint16_t src_id, uint16_t dst_id);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 5099d22570..579ea9b81c 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -759,3 +759,39 @@ roc_nix_bpf_pre_color_tbl_setup(struct roc_nix *roc_nix, uint16_t id,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_connect(struct roc_nix *roc_nix,
+		    enum roc_nix_bpf_level_flag lvl_flag, uint16_t src_id,
+		    uint16_t dst_id)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | src_id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	if (dst_id == ROC_NIX_BPF_ID_INVALID) {
+		aq->prof.hl_en = false;
+		aq->prof_mask.hl_en = ~(aq->prof_mask.hl_en);
+	} else {
+		aq->prof.hl_en = true;
+		aq->prof.band_prof_id = dst_id;
+		aq->prof_mask.hl_en = ~(aq->prof_mask.hl_en);
+		aq->prof_mask.band_prof_id = ~(aq->prof_mask.band_prof_id);
+	}
+
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index a08fbe6013..c04a8ca9da 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -79,6 +79,7 @@ INTERNAL {
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
+	roc_nix_bpf_connect;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_dump;
 	roc_nix_bpf_ena_dis;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 11/27] common/cnxk: support RoC API to get stats to index
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (8 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 10/27] common/cnxk: support RoC API to connect bandwidth profiles skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 12/27] common/cnxk: support RoC API to read profile statistics skori
                   ` (16 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform supports different stats for HW bandwidth profiles.
Implement RoC API to get index for given stats type.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     | 18 ++++++++++++++++
 drivers/common/cnxk/roc_nix_bpf.c | 34 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 53 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index ec279f1f6c..cb465959b8 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -10,6 +10,7 @@
 #define ROC_NIX_BPF_ID_INVALID	      0xFFFF
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
+#define ROC_NIX_BPF_STATS_MAX	      12
 
 /** NIX rate limits */
 #define MAX_RATE_DIV_EXP  12
@@ -119,6 +120,21 @@ enum roc_nix_bpf_action {
 	ROC_NIX_BPF_ACTION_RED
 };
 
+enum roc_nix_bpf_stats {
+	ROC_NIX_BPF_GREEN_PKT_F_PASS = BIT_ULL(0),
+	ROC_NIX_BPF_GREEN_OCTS_F_PASS = BIT_ULL(1),
+	ROC_NIX_BPF_GREEN_PKT_F_DROP = BIT_ULL(2),
+	ROC_NIX_BPF_GREEN_OCTS_F_DROP = BIT_ULL(3),
+	ROC_NIX_BPF_YELLOW_PKT_F_PASS = BIT_ULL(4),
+	ROC_NIX_BPF_YELLOW_OCTS_F_PASS = BIT_ULL(5),
+	ROC_NIX_BPF_YELLOW_PKT_F_DROP = BIT_ULL(6),
+	ROC_NIX_BPF_YELLOW_OCTS_F_DROP = BIT_ULL(7),
+	ROC_NIX_BPF_RED_PKT_F_PASS = BIT_ULL(8),
+	ROC_NIX_BPF_RED_OCTS_F_PASS = BIT_ULL(9),
+	ROC_NIX_BPF_RED_PKT_F_DROP = BIT_ULL(10),
+	ROC_NIX_BPF_RED_OCTS_F_DROP = BIT_ULL(11),
+};
+
 struct roc_nix_bpf_cfg {
 	enum roc_nix_bpf_algo alg;
 	enum roc_nix_bpf_lmode lmode;
@@ -643,6 +659,8 @@ int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
+uint8_t __roc_api roc_nix_bpf_stats_to_idx(enum roc_nix_bpf_stats lvl_flag);
+
 /* MAC */
 int __roc_api roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start);
 int __roc_api roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix,
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 579ea9b81c..5d39f26add 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -298,6 +298,40 @@ roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 	return idx;
 }
 
+uint8_t
+roc_nix_bpf_stats_to_idx(enum roc_nix_bpf_stats level_f)
+{
+	uint8_t idx;
+
+	if (level_f & ROC_NIX_BPF_GREEN_PKT_F_PASS)
+		idx = 0;
+	else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
+		idx = 1;
+	else if (level_f & ROC_NIX_BPF_GREEN_PKT_F_DROP)
+		idx = 2;
+	else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
+		idx = 3;
+	else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
+		idx = 4;
+	else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
+		idx = 5;
+	else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
+		idx = 6;
+	else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
+		idx = 7;
+	else if (level_f & ROC_NIX_BPF_RED_PKT_F_PASS)
+		idx = 8;
+	else if (level_f & ROC_NIX_BPF_RED_OCTS_F_PASS)
+		idx = 9;
+	else if (level_f & ROC_NIX_BPF_RED_PKT_F_DROP)
+		idx = 10;
+	else if (level_f & ROC_NIX_BPF_RED_OCTS_F_DROP)
+		idx = 11;
+	else
+		idx = ROC_NIX_BPF_STATS_MAX;
+	return idx;
+}
+
 int
 roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index c04a8ca9da..5d4bdd57a9 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -87,6 +87,7 @@ INTERNAL {
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_bpf_pre_color_tbl_setup;
+	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 12/27] common/cnxk: support RoC API to read profile statistics
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (9 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 11/27] common/cnxk: support RoC API to get stats to index skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 13/27] common/cnxk: support RoC API to reset profile stats skori
                   ` (15 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform provides statistics per bandwidth profile and
per nixlf. Implement RoC API to read stats for given bandwidth
profile.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |   9 ++
 drivers/common/cnxk/roc_nix_bpf.c | 197 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   2 +
 3 files changed, 208 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index cb465959b8..1ad8a0ca04 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -656,6 +656,15 @@ int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
 				  enum roc_nix_bpf_level_flag lvl_flag,
 				  uint16_t src_id, uint16_t dst_id);
 
+int __roc_api
+roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+		       enum roc_nix_bpf_level_flag lvl_flag,
+		       uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
+
+int __roc_api
+roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
+			  uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 5d39f26add..137d2260bb 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -17,6 +17,9 @@
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
 
+#define NIX_RD_STATS(val)  plt_read64(nix->base + NIX_LF_RX_STATX(val))
+#define NIX_RST_STATS(val) plt_write64(0, nix->base + NIX_LF_RX_STATX(val))
+
 static uint8_t sw_to_hw_lvl_map[] = {NIX_RX_BAND_PROF_LAYER_LEAF,
 				     NIX_RX_BAND_PROF_LAYER_MIDDLE,
 				     NIX_RX_BAND_PROF_LAYER_TOP};
@@ -829,3 +832,197 @@ roc_nix_bpf_connect(struct roc_nix *roc_nix,
 
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+		       enum roc_nix_bpf_level_flag lvl_flag,
+		       uint64_t stats[ROC_NIX_BPF_STATS_MAX])
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_rsp *rsp;
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_READ;
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		return rc;
+
+	green_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[green_pkt_pass] = rsp->prof.green_pkt_pass;
+
+	if (green_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[green_octs_pass] = rsp->prof.green_octs_pass;
+
+	if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[green_pkt_drop] = rsp->prof.green_pkt_drop;
+
+	if (green_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[green_octs_drop] = rsp->prof.green_octs_pass;
+
+	if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_pkt_pass] = rsp->prof.yellow_pkt_pass;
+
+	if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_octs_pass] = rsp->prof.yellow_octs_pass;
+
+	if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_pkt_drop] = rsp->prof.yellow_pkt_drop;
+
+	if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_octs_drop] = rsp->prof.yellow_octs_drop;
+
+	if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[red_pkt_pass] = rsp->prof.red_pkt_pass;
+
+	if (red_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[red_octs_pass] = rsp->prof.red_octs_pass;
+
+	if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[red_pkt_drop] = rsp->prof.red_pkt_drop;
+
+	if (red_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[red_octs_drop] = rsp->prof.red_octs_drop;
+
+	return 0;
+}
+
+int
+roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
+			  uint64_t stats[ROC_NIX_BPF_STATS_MAX])
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+
+	green_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_PASSED);
+	}
+
+	if (green_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_PASSED);
+	}
+
+	if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_DROP);
+	}
+
+	if (green_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_DROP);
+	}
+
+	if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_PASSED);
+	}
+
+	if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_PASSED);
+	}
+
+	if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_DROP);
+	}
+
+	if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_DROP);
+	}
+
+	if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_PASSED);
+	}
+
+	if (red_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_PASSED);
+	}
+
+	if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_DROP);
+	}
+
+	if (red_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_DROP);
+	}
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 5d4bdd57a9..52e7fa1e89 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -86,7 +86,9 @@ INTERNAL {
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
+	roc_nix_bpf_lf_stats_read;
 	roc_nix_bpf_pre_color_tbl_setup;
+	roc_nix_bpf_stats_read;
 	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 13/27] common/cnxk: support RoC API to reset profile stats
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (10 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 12/27] common/cnxk: support RoC API to read profile statistics skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 14/27] common/cnxk: support meter in action list skori
                   ` (14 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to reset stats per bandwidth profile
or per nixlf.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |   7 ++
 drivers/common/cnxk/roc_nix_bpf.c | 113 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   2 +
 3 files changed, 122 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 1ad8a0ca04..c1a561928e 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -661,10 +661,17 @@ roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
 		       enum roc_nix_bpf_level_flag lvl_flag,
 		       uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_stats_reset(struct roc_nix *roc_nix, uint16_t id,
+				      uint64_t mask,
+				      enum roc_nix_bpf_level_flag lvl_flag);
+
 int __roc_api
 roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 			  uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_lf_stats_reset(struct roc_nix *roc_nix,
+					 uint64_t mask);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 137d2260bb..220d78ed84 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -929,6 +929,86 @@ roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
 	return 0;
 }
 
+int
+roc_nix_bpf_stats_reset(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+			enum roc_nix_bpf_level_flag lvl_flag)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS) {
+		aq->prof.green_pkt_pass = 0;
+		aq->prof_mask.green_pkt_pass = ~(aq->prof_mask.green_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS) {
+		aq->prof.green_octs_pass = 0;
+		aq->prof_mask.green_octs_pass =
+			~(aq->prof_mask.green_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP) {
+		aq->prof.green_pkt_drop = 0;
+		aq->prof_mask.green_pkt_drop = ~(aq->prof_mask.green_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP) {
+		aq->prof.green_octs_drop = 0;
+		aq->prof_mask.green_octs_drop =
+			~(aq->prof_mask.green_octs_drop);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS) {
+		aq->prof.yellow_pkt_pass = 0;
+		aq->prof_mask.yellow_pkt_pass =
+			~(aq->prof_mask.yellow_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS) {
+		aq->prof.yellow_octs_pass = 0;
+		aq->prof_mask.yellow_octs_pass =
+			~(aq->prof_mask.yellow_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP) {
+		aq->prof.yellow_pkt_drop = 0;
+		aq->prof_mask.yellow_pkt_drop =
+			~(aq->prof_mask.yellow_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP) {
+		aq->prof.yellow_octs_drop = 0;
+		aq->prof_mask.yellow_octs_drop =
+			~(aq->prof_mask.yellow_octs_drop);
+	}
+	if (mask & ROC_NIX_BPF_RED_PKT_F_PASS) {
+		aq->prof.red_pkt_pass = 0;
+		aq->prof_mask.red_pkt_pass = ~(aq->prof_mask.red_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS) {
+		aq->prof.red_octs_pass = 0;
+		aq->prof_mask.red_octs_pass = ~(aq->prof_mask.red_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_RED_PKT_F_DROP) {
+		aq->prof.red_pkt_drop = 0;
+		aq->prof_mask.red_pkt_drop = ~(aq->prof_mask.red_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP) {
+		aq->prof.red_octs_drop = 0;
+		aq->prof_mask.red_octs_drop = ~(aq->prof_mask.red_octs_drop);
+	}
+
+	return mbox_process(mbox);
+}
+
 int
 roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 			  uint64_t stats[ROC_NIX_BPF_STATS_MAX])
@@ -1026,3 +1106,36 @@ roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 
 	return 0;
 }
+
+int
+roc_nix_bpf_lf_stats_reset(struct roc_nix *roc_nix, uint64_t mask)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	if (mask & ROC_NIX_BPF_RED_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_RED_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 52e7fa1e89..3b08fb0025 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -87,8 +87,10 @@ INTERNAL {
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_bpf_lf_stats_read;
+	roc_nix_bpf_lf_stats_reset;
 	roc_nix_bpf_pre_color_tbl_setup;
 	roc_nix_bpf_stats_read;
+	roc_nix_bpf_stats_reset;
 	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 14/27] common/cnxk: support meter in action list
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (11 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 13/27] common/cnxk: support RoC API to reset profile stats skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 15/27] net/cnxk: support meter ops get API skori
                   ` (13 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao; +Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Meter action is added in supported action list.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_npc.c | 3 +++
 drivers/common/cnxk/roc_npc.h | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/common/cnxk/roc_npc.c b/drivers/common/cnxk/roc_npc.c
index 52a54b3990..8f88e254b3 100644
--- a/drivers/common/cnxk/roc_npc.c
+++ b/drivers/common/cnxk/roc_npc.c
@@ -447,6 +447,9 @@ npc_parse_actions(struct npc *npc, const struct roc_npc_attr *attr,
 		case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
 			req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
 			break;
+		case ROC_NPC_ACTION_TYPE_METER:
+			req_act |= ROC_NPC_ACTION_TYPE_METER;
+			break;
 		default:
 			errcode = NPC_ERR_ACTION_NOTSUP;
 			goto err_exit;
diff --git a/drivers/common/cnxk/roc_npc.h b/drivers/common/cnxk/roc_npc.h
index 4d6f8f8cd9..86365df754 100644
--- a/drivers/common/cnxk/roc_npc.h
+++ b/drivers/common/cnxk/roc_npc.h
@@ -58,7 +58,7 @@ struct roc_npc_flow_item_raw {
 	const uint8_t *pattern; /**< Byte string to look for. */
 };
 
-#define ROC_NPC_MAX_ACTION_COUNT 12
+#define ROC_NPC_MAX_ACTION_COUNT 17
 
 enum roc_npc_action_type {
 	ROC_NPC_ACTION_TYPE_END = (1 << 0),
@@ -77,6 +77,7 @@ enum roc_npc_action_type {
 	ROC_NPC_ACTION_TYPE_VLAN_INSERT = (1 << 13),
 	ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT = (1 << 14),
 	ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT = (1 << 15),
+	ROC_NPC_ACTION_TYPE_METER = (1 << 16),
 };
 
 struct roc_npc_action {
@@ -110,6 +111,10 @@ struct roc_npc_action_of_set_vlan_pcp {
 	uint8_t vlan_pcp; /**< VLAN priority. */
 };
 
+struct roc_npc_action_meter {
+	uint32_t mtr_id; /**< Meter id to be applied. > */
+};
+
 struct roc_npc_attr {
 	uint32_t priority;	/**< Rule priority level within group. */
 	uint32_t ingress : 1;	/**< Rule applies to ingress traffic. */
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 15/27] net/cnxk: support meter ops get API
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (12 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 14/27] common/cnxk: support meter in action list skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 16/27] net/cnxk: support ops to get meter capabilities skori
                   ` (12 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

To enable support for ingress meter, supported operations
are exposed for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev.c     |  1 +
 drivers/net/cnxk/cn10k_ethdev.h     |  2 ++
 drivers/net/cnxk/cn10k_ethdev_mtr.c | 18 ++++++++++++++++++
 drivers/net/cnxk/meson.build        |  1 +
 4 files changed, 22 insertions(+)
 create mode 100644 drivers/net/cnxk/cn10k_ethdev_mtr.c

diff --git a/drivers/net/cnxk/cn10k_ethdev.c b/drivers/net/cnxk/cn10k_ethdev.c
index 7caec6cf14..8c1f6a4408 100644
--- a/drivers/net/cnxk/cn10k_ethdev.c
+++ b/drivers/net/cnxk/cn10k_ethdev.c
@@ -457,6 +457,7 @@ nix_eth_dev_ops_override(void)
 	cnxk_eth_dev_ops.dev_ptypes_set = cn10k_nix_ptypes_set;
 	cnxk_eth_dev_ops.timesync_enable = cn10k_nix_timesync_enable;
 	cnxk_eth_dev_ops.timesync_disable = cn10k_nix_timesync_disable;
+	cnxk_eth_dev_ops.mtr_ops_get = cn10k_nix_mtr_ops_get;
 }
 
 static void
diff --git a/drivers/net/cnxk/cn10k_ethdev.h b/drivers/net/cnxk/cn10k_ethdev.h
index 8b6e0f2b3f..117aa2a62d 100644
--- a/drivers/net/cnxk/cn10k_ethdev.h
+++ b/drivers/net/cnxk/cn10k_ethdev.h
@@ -38,4 +38,6 @@ struct cn10k_eth_rxq {
 void cn10k_eth_set_rx_function(struct rte_eth_dev *eth_dev);
 void cn10k_eth_set_tx_function(struct rte_eth_dev *eth_dev);
 
+/* MTR */
+int cn10k_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops);
 #endif /* __CN10K_ETHDEV_H__ */
diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
new file mode 100644
index 0000000000..9b46032858
--- /dev/null
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell.
+ */
+
+#include "cn10k_ethdev.h"
+#include <rte_mtr_driver.h>
+
+const struct rte_mtr_ops nix_mtr_ops = {
+};
+
+int
+cn10k_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops)
+{
+	RTE_SET_USED(dev);
+
+	*(const void **)ops = &nix_mtr_ops;
+	return 0;
+}
diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build
index d4cdd1744a..91afc1de4c 100644
--- a/drivers/net/cnxk/meson.build
+++ b/drivers/net/cnxk/meson.build
@@ -35,6 +35,7 @@ sources += files(
 # CN10K
 sources += files(
         'cn10k_ethdev.c',
+        'cn10k_ethdev_mtr.c',
         'cn10k_rte_flow.c',
         'cn10k_rx.c',
         'cn10k_rx_mseg.c',
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 16/27] net/cnxk: support ops to get meter capabilities
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (13 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 15/27] net/cnxk: support meter ops get API skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 17/27] net/cnxk: support ops to create meter profile skori
                   ` (11 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement ethdev operation to get meter capabilities for
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 48 +++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 9b46032858..f87871f149 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -5,7 +5,55 @@
 #include "cn10k_ethdev.h"
 #include <rte_mtr_driver.h>
 
+#define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
+#define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
+
+static struct rte_mtr_capabilities mtr_capa = {
+	.n_max = NIX_MTR_COUNT_MAX,
+	.n_shared_max = NIX_MTR_COUNT_PER_FLOW,
+	/* .identical = , */
+	.shared_identical = true,
+	/* .shared_n_flows_per_mtr_max = ,*/
+	.chaining_n_mtrs_per_flow_max = NIX_MTR_COUNT_PER_FLOW,
+	.chaining_use_prev_mtr_color_supported = true,
+	.chaining_use_prev_mtr_color_enforced = true,
+	.meter_srtcm_rfc2697_n_max = NIX_MTR_COUNT_MAX,
+	.meter_trtcm_rfc2698_n_max = NIX_MTR_COUNT_MAX,
+	.meter_trtcm_rfc4115_n_max = NIX_MTR_COUNT_MAX,
+	.meter_rate_max = ROC_NIX_BPF_RATE_MAX / 8, /* Bytes per second */
+	.meter_policy_n_max = NIX_MTR_COUNT_MAX,
+	.color_aware_srtcm_rfc2697_supported = true,
+	.color_aware_trtcm_rfc2698_supported = true,
+	.color_aware_trtcm_rfc4115_supported = true,
+	.srtcm_rfc2697_byte_mode_supported = true,
+	.srtcm_rfc2697_packet_mode_supported = true,
+	.trtcm_rfc2698_byte_mode_supported = true,
+	.trtcm_rfc2698_packet_mode_supported = true,
+	.trtcm_rfc4115_byte_mode_supported = true,
+	.trtcm_rfc4115_packet_mode_supported = true,
+	.stats_mask = RTE_MTR_STATS_N_PKTS_GREEN | RTE_MTR_STATS_N_PKTS_YELLOW |
+		      RTE_MTR_STATS_N_PKTS_RED | RTE_MTR_STATS_N_PKTS_DROPPED |
+		      RTE_MTR_STATS_N_BYTES_GREEN |
+		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
+		      RTE_MTR_STATS_N_BYTES_DROPPED};
+
+static int
+cn10k_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
+			       struct rte_mtr_capabilities *capa,
+			       struct rte_mtr_error *error)
+{
+	RTE_SET_USED(dev);
+
+	if (!capa)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "NULL input parameter");
+	*capa = mtr_capa;
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
+	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 17/27] net/cnxk: support ops to create meter profile
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (14 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 16/27] net/cnxk: support ops to get meter capabilities skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 18/27] net/cnxk: support ops to delete " skori
                   ` (10 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to add meter profile for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 138 ++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev.c      |  14 +++
 drivers/net/cnxk/cnxk_ethdev.h      |  13 +++
 3 files changed, 165 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index f87871f149..dadfd1c0ff 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -37,6 +37,106 @@ static struct rte_mtr_capabilities mtr_capa = {
 		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
 		      RTE_MTR_STATS_N_BYTES_DROPPED};
 
+static struct cnxk_mtr_profile_node *
+nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
+{
+	struct cnxk_mtr_profiles *fmps = &dev->mtr_profiles;
+	struct cnxk_mtr_profile_node *fmp;
+
+	TAILQ_FOREACH(fmp, fmps, next)
+		if (profile_id == fmp->id)
+			return fmp;
+
+	return NULL;
+}
+
+static int
+nix_mtr_profile_validate(struct cnxk_eth_dev *dev, uint32_t profile_id,
+			 struct rte_mtr_meter_profile *profile,
+			 struct rte_mtr_error *error)
+{
+	int rc = 0;
+
+	PLT_SET_USED(dev);
+
+	if (profile == NULL)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE,
+					  NULL, "Meter profile is null.");
+
+	if (profile_id == UINT32_MAX)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile id not valid.");
+
+	switch (profile->alg) {
+	case RTE_MTR_SRTCM_RFC2697:
+		if (profile->srtcm_rfc2697.cir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CIR exceeds max meter rate");
+
+		if (profile->srtcm_rfc2697.cbs > ROC_NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->srtcm_rfc2697.ebs > ROC_NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"EBS exceeds max meter burst size");
+		break;
+
+	case RTE_MTR_TRTCM_RFC2698:
+		if (profile->trtcm_rfc2698.cir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CIR exceeds max meter rate");
+
+		if (profile->trtcm_rfc2698.pir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PIR exceeds max meter rate");
+
+		if (profile->trtcm_rfc2698.cbs > ROC_NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->trtcm_rfc2698.pbs > ROC_NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PBS exceeds max meter burst size");
+		break;
+
+	case RTE_MTR_TRTCM_RFC4115:
+		if ((profile->trtcm_rfc4115.cir + profile->trtcm_rfc4115.eir) >
+		    mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PIR + EIR exceeds max rate");
+
+		if (profile->trtcm_rfc4115.cbs > ROC_NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->trtcm_rfc4115.ebs > ROC_NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PBS exceeds max meter burst size");
+		break;
+
+	default:
+		rc = -rte_mtr_error_set(error, EINVAL,
+					RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+					"alg is invalid");
+		break;
+	}
+
+	return rc;
+}
+
 static int
 cn10k_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
 			       struct rte_mtr_capabilities *capa,
@@ -52,8 +152,46 @@ cn10k_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_profile_add(struct rte_eth_dev *eth_dev, uint32_t profile_id,
+			  struct rte_mtr_meter_profile *profile,
+			  struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profiles *fmps = &dev->mtr_profiles;
+	struct cnxk_mtr_profile_node *fmp;
+	int ret;
+
+	/* Check input params. */
+	ret = nix_mtr_profile_validate(dev, profile_id, profile, error);
+	if (ret)
+		return ret;
+
+	fmp = nix_mtr_profile_find(dev, profile_id);
+	if (fmp) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Profile already exist");
+	}
+
+	fmp = plt_zmalloc(sizeof(struct cnxk_mtr_profile_node), ROC_ALIGN);
+	if (fmp == NULL)
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Meter profile memory "
+					  "alloc failed.");
+
+	fmp->id = profile_id;
+	fmp->profile = *profile;
+
+	TAILQ_INSERT_TAIL(fmps, fmp, next);
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
+	.meter_profile_add = cn10k_nix_mtr_profile_add,
 };
 
 int
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index 7152dcd002..e952aa5ec5 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -504,6 +504,14 @@ nix_free_queue_mem(struct cnxk_eth_dev *dev)
 	dev->sqs = NULL;
 }
 
+static int
+nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
+{
+	TAILQ_INIT(&dev->mtr_profiles);
+
+	return 0;
+}
+
 static int
 nix_rss_default_setup(struct cnxk_eth_dev *dev)
 {
@@ -901,6 +909,12 @@ cnxk_nix_configure(struct rte_eth_dev *eth_dev)
 		goto free_nix_lf;
 	}
 
+	rc = nix_ingress_policer_setup(dev);
+	if (rc) {
+		plt_err("Failed to setup ingress policer rc=%d", rc);
+		goto free_nix_lf;
+	}
+
 	rc = roc_nix_tm_hierarchy_enable(nix, ROC_NIX_TM_DEFAULT, false);
 	if (rc) {
 		plt_err("Failed to enable default tm hierarchy, rc=%d", rc);
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 27920c84f2..2b9b5beb83 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -13,6 +13,7 @@
 #include <rte_mbuf.h>
 #include <rte_mbuf_pool_ops.h>
 #include <rte_mempool.h>
+#include <rte_mtr_driver.h>
 #include <rte_time.h>
 
 #include "roc_api.h"
@@ -144,6 +145,15 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct cnxk_mtr_profile_node {
+	TAILQ_ENTRY(cnxk_mtr_profile_node) next;
+	struct rte_mtr_meter_profile profile; /**< Profile detail. */
+	uint32_t ref_cnt;		      /**< Use count. */
+	uint32_t id;			      /**< Profile id. */
+};
+
+TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
+
 struct cnxk_eth_dev {
 	/* ROC NIX */
 	struct roc_nix nix;
@@ -211,6 +221,9 @@ struct cnxk_eth_dev {
 	double clk_freq_mult;
 	uint64_t clk_delta;
 
+	/* Ingress policer */
+	struct cnxk_mtr_profiles mtr_profiles;
+
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
 
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 18/27] net/cnxk: support ops to delete meter profile
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (15 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 17/27] net/cnxk: support ops to create meter profile skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 19/27] net/cnxk: support ops to validate meter policy skori
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter profile for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 30 +++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index dadfd1c0ff..cc21462880 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -189,9 +189,39 @@ cn10k_nix_mtr_profile_add(struct rte_eth_dev *eth_dev, uint32_t profile_id,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,
+			     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *fmp;
+
+	if (profile_id == UINT32_MAX)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile id not valid.");
+
+	fmp = nix_mtr_profile_find(dev, profile_id);
+	if (fmp == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  &profile_id,
+					  "Meter profile is invalid.");
+
+	if (fmp->ref_cnt)
+		return -rte_mtr_error_set(error, EBUSY,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile is in use.");
+
+	TAILQ_REMOVE(&dev->mtr_profiles, fmp, next);
+	plt_free(fmp);
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
+	.meter_profile_delete = cn10k_nix_mtr_profile_delete,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 19/27] net/cnxk: support ops to validate meter policy
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (16 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 18/27] net/cnxk: support ops to delete " skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 20/27] net/cnxk: support ops to create " skori
                   ` (8 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to validate meter policy for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 49 +++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index cc21462880..922b06cb2b 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -218,10 +218,59 @@ cn10k_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_policy_validate(struct rte_eth_dev *dev,
+			      struct rte_mtr_meter_policy_params *policy,
+			      struct rte_mtr_error *error)
+{
+	static const char *const action_color[] = {"Green", "Yellow", "Red"};
+	bool supported[RTE_COLORS] = {false, false, false};
+	const struct rte_flow_action *action;
+	char message[1024];
+	uint32_t i;
+
+	RTE_SET_USED(dev);
+
+	if (!policy)
+		return 0; /* Nothing to be validated */
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		if (policy->actions[i]) {
+			for (action = policy->actions[i];
+			     action->type != RTE_FLOW_ACTION_TYPE_END;
+			     action++) {
+				if (action->type == RTE_FLOW_ACTION_TYPE_METER)
+					supported[i] = true;
+
+				if (action->type == RTE_FLOW_ACTION_TYPE_DROP)
+					supported[i] = true;
+
+				if (!supported[i]) {
+					sprintf(message,
+						"%s action is not valid",
+						action_color[i]);
+					return -rte_mtr_error_set(error,
+					  ENOTSUP,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+					  message);
+				}
+			}
+		} else {
+			sprintf(message, "%s action is null", action_color[i]);
+			return -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+				message);
+		}
+	}
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
 	.meter_profile_delete = cn10k_nix_mtr_profile_delete,
+	.meter_policy_validate = cn10k_nix_mtr_policy_validate,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 20/27] net/cnxk: support ops to create meter policy
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (17 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 19/27] net/cnxk: support ops to validate meter policy skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 21/27] net/cnxk: support ops to delete " skori
                   ` (7 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to add meter policy for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 84 +++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev.c      |  1 +
 drivers/net/cnxk/cnxk_ethdev.h      | 31 +++++++++++
 3 files changed, 116 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 922b06cb2b..14f33cfe91 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -50,6 +50,18 @@ nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
 	return NULL;
 }
 
+static struct cnxk_mtr_policy_node *
+nix_mtr_policy_find(struct cnxk_eth_dev *dev, uint32_t meter_policy_id)
+{
+	struct cnxk_mtr_policy *fmps = &dev->mtr_policy;
+	struct cnxk_mtr_policy_node *fmp;
+
+	TAILQ_FOREACH(fmp, fmps, next)
+		if (meter_policy_id == fmp->id)
+			return fmp;
+	return NULL;
+}
+
 static int
 nix_mtr_profile_validate(struct cnxk_eth_dev *dev, uint32_t profile_id,
 			 struct rte_mtr_meter_profile *profile,
@@ -266,11 +278,83 @@ cn10k_nix_mtr_policy_validate(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static void
+cn10k_fill_policy_actions(struct cnxk_mtr_policy_node *fmp,
+			  struct rte_mtr_meter_policy_params *policy)
+
+{
+	const struct rte_flow_action *action;
+	const struct rte_flow_action_meter *mtr;
+	int i;
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		if (policy->actions[i]) {
+			for (action = policy->actions[i];
+			     action->type != RTE_FLOW_ACTION_TYPE_END;
+			     action++) {
+				if (action->type ==
+				    RTE_FLOW_ACTION_TYPE_METER) {
+					fmp->actions[i].action_fate =
+						action->type;
+					mtr = (const struct
+					       rte_flow_action_meter *)
+						      action->conf;
+					fmp->actions[i].mtr_id = mtr->mtr_id;
+				}
+
+				if (action->type == RTE_FLOW_ACTION_TYPE_DROP) {
+					fmp->actions[i].action_fate =
+						action->type;
+				}
+			}
+		}
+	}
+}
+
+static int
+cn10k_nix_mtr_policy_add(struct rte_eth_dev *eth_dev, uint32_t policy_id,
+			 struct rte_mtr_meter_policy_params *policy,
+			 struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy *fmps = &dev->mtr_policy;
+	struct cnxk_mtr_policy_node *fmp;
+	int rc;
+
+	fmp = nix_mtr_policy_find(dev, policy_id);
+	if (fmp) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "Policy already exist");
+	}
+
+	fmp = plt_zmalloc(sizeof(struct cnxk_mtr_policy_node), ROC_ALIGN);
+	if (fmp == NULL) {
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Memory allocation failure");
+	} else {
+		rc = cn10k_nix_mtr_policy_validate(eth_dev, policy, error);
+		if (rc)
+			goto exit;
+	}
+
+	fmp->id = policy_id;
+	cn10k_fill_policy_actions(fmp, policy);
+	TAILQ_INSERT_TAIL(fmps, fmp, next);
+	return 0;
+
+exit:
+	plt_free(fmp);
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
 	.meter_profile_delete = cn10k_nix_mtr_profile_delete,
 	.meter_policy_validate = cn10k_nix_mtr_policy_validate,
+	.meter_policy_add = cn10k_nix_mtr_policy_add,
 };
 
 int
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index e952aa5ec5..9e75060513 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -508,6 +508,7 @@ static int
 nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
 	TAILQ_INIT(&dev->mtr_profiles);
+	TAILQ_INIT(&dev->mtr_policy);
 
 	return 0;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 2b9b5beb83..4e45061c86 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -145,6 +145,35 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct action_rss {
+	enum rte_eth_hash_function func;
+	uint32_t level;
+	uint64_t types;
+	uint32_t key_len;
+	uint32_t queue_num;
+	uint8_t *key;
+	uint16_t *queue;
+};
+
+struct policy_actions {
+	uint32_t action_fate;
+	union {
+		uint16_t queue;
+		uint32_t mtr_id;
+		struct action_rss *rss_desc;
+	};
+};
+
+struct cnxk_mtr_policy_node {
+	TAILQ_ENTRY(cnxk_mtr_policy_node) next;
+	/**< Pointer to the next flow meter structure. */
+	uint32_t id;	 /**< Policy id */
+	uint32_t mtr_id; /** Meter id */
+	struct rte_mtr_meter_policy_params policy;
+	struct policy_actions actions[RTE_COLORS];
+	uint32_t ref_cnt;
+};
+
 struct cnxk_mtr_profile_node {
 	TAILQ_ENTRY(cnxk_mtr_profile_node) next;
 	struct rte_mtr_meter_profile profile; /**< Profile detail. */
@@ -153,6 +182,7 @@ struct cnxk_mtr_profile_node {
 };
 
 TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
+TAILQ_HEAD(cnxk_mtr_policy, cnxk_mtr_policy_node);
 
 struct cnxk_eth_dev {
 	/* ROC NIX */
@@ -223,6 +253,7 @@ struct cnxk_eth_dev {
 
 	/* Ingress policer */
 	struct cnxk_mtr_profiles mtr_profiles;
+	struct cnxk_mtr_policy mtr_policy;
 
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 21/27] net/cnxk: support ops to delete meter policy
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (18 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 20/27] net/cnxk: support ops to create " skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 22/27] net/cnxk: support ops to create meter skori
                   ` (6 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter policy for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 14f33cfe91..46f0bdd5fc 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -349,12 +349,38 @@ cn10k_nix_mtr_policy_add(struct rte_eth_dev *eth_dev, uint32_t policy_id,
 	return rc;
 }
 
+static int
+cn10k_nix_mtr_policy_delete(struct rte_eth_dev *eth_dev, uint32_t policy_id,
+			    struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy_node *fmp;
+
+	fmp = nix_mtr_policy_find(dev, policy_id);
+	if (fmp == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "No policy found");
+	}
+
+	if (fmp->ref_cnt)
+		return -rte_mtr_error_set(error, EBUSY,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "Meter policy is in use.");
+
+	TAILQ_REMOVE(&dev->mtr_policy, fmp, next);
+	plt_free(fmp);
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
 	.meter_profile_delete = cn10k_nix_mtr_profile_delete,
 	.meter_policy_validate = cn10k_nix_mtr_policy_validate,
 	.meter_policy_add = cn10k_nix_mtr_policy_add,
+	.meter_policy_delete = cn10k_nix_mtr_policy_delete,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 22/27] net/cnxk: support ops to create meter
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (19 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 21/27] net/cnxk: support ops to delete " skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 23/27] net/cnxk: support ops to delete meter skori
                   ` (5 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to create meter instance for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 76 +++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev.c      |  1 +
 drivers/net/cnxk/cnxk_ethdev.h      | 22 +++++++++
 3 files changed, 99 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 46f0bdd5fc..9a8459d919 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -37,6 +37,18 @@ static struct rte_mtr_capabilities mtr_capa = {
 		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
 		      RTE_MTR_STATS_N_BYTES_DROPPED};
 
+static struct cnxk_meter_node *
+nix_mtr_find(struct cnxk_eth_dev *dev, uint32_t meter_id)
+{
+	struct cnxk_mtr *fms = &dev->mtr;
+	struct cnxk_meter_node *fm;
+
+	TAILQ_FOREACH(fm, fms, next)
+		if (meter_id == fm->id)
+			return fm;
+	return NULL;
+}
+
 static struct cnxk_mtr_profile_node *
 nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
 {
@@ -374,6 +386,69 @@ cn10k_nix_mtr_policy_delete(struct rte_eth_dev *eth_dev, uint32_t policy_id,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_create(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		     struct rte_mtr_params *params, int shared,
+		     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_mtr *fm = &dev->mtr;
+	struct cnxk_meter_node *mtr;
+
+	RTE_SET_USED(shared);
+
+	if (params == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "Meter params are invalid.");
+
+	profile = nix_mtr_profile_find(dev, params->meter_profile_id);
+	if (profile == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  &params->meter_profile_id,
+					  "Meter profile is invalid.");
+
+	policy = nix_mtr_policy_find(dev, params->meter_policy_id);
+	if (policy == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  &params->meter_policy_id,
+					  "Meter policy is invalid.");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		mtr = plt_zmalloc(sizeof(struct cnxk_meter_node), ROC_ALIGN);
+		if (mtr == NULL) {
+			return -rte_mtr_error_set(error, ENOMEM,
+				RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+				"Meter memory alloc failed.");
+		} else {
+			mtr->id = mtr_id;
+			mtr->profile = profile;
+			mtr->policy = policy;
+			mtr->params = *params;
+			mtr->bpf_id = ROC_NIX_BPF_ID_INVALID;
+			mtr->prev_id = ROC_NIX_BPF_ID_INVALID;
+			mtr->next_id = ROC_NIX_BPF_ID_INVALID;
+			mtr->is_prev = false;
+			mtr->is_next = false;
+			mtr->level = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+		}
+	} else {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_MTR_ID,
+					  NULL, "Meter already exist");
+	}
+
+	profile->ref_cnt++;
+	policy->ref_cnt++;
+	TAILQ_INSERT_TAIL(fm, mtr, next);
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -381,6 +456,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_validate = cn10k_nix_mtr_policy_validate,
 	.meter_policy_add = cn10k_nix_mtr_policy_add,
 	.meter_policy_delete = cn10k_nix_mtr_policy_delete,
+	.create = cn10k_nix_mtr_create,
 };
 
 int
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index 9e75060513..4c12715756 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -509,6 +509,7 @@ nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
 	TAILQ_INIT(&dev->mtr_profiles);
 	TAILQ_INIT(&dev->mtr_policy);
+	TAILQ_INIT(&dev->mtr);
 
 	return 0;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 4e45061c86..0ad06f1536 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -145,6 +145,25 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct cnxk_meter_node {
+	TAILQ_ENTRY(cnxk_meter_node) next;
+	/**< Pointer to the next flow meter structure. */
+	uint32_t id; /**< Usr mtr id. */
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	uint32_t bpf_id; /**< Hw mtr id. */
+	uint32_t rq_num;
+	uint32_t *rq_id;
+	uint16_t level;
+	uint32_t prev_id; /**< Prev mtr id for chaining */
+	uint32_t next_id; /**< Next mtr id for chaining */
+	bool is_prev;
+	bool is_next;
+	struct rte_mtr_params params;
+	struct roc_nix_bpf_objs profs;
+	uint32_t ref_cnt;
+};
+
 struct action_rss {
 	enum rte_eth_hash_function func;
 	uint32_t level;
@@ -183,6 +202,7 @@ struct cnxk_mtr_profile_node {
 
 TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
 TAILQ_HEAD(cnxk_mtr_policy, cnxk_mtr_policy_node);
+TAILQ_HEAD(cnxk_mtr, cnxk_meter_node);
 
 struct cnxk_eth_dev {
 	/* ROC NIX */
@@ -252,8 +272,10 @@ struct cnxk_eth_dev {
 	uint64_t clk_delta;
 
 	/* Ingress policer */
+	enum roc_nix_bpf_color precolor_tbl[ROC_NIX_BPF_PRE_COLOR_MAX];
 	struct cnxk_mtr_profiles mtr_profiles;
 	struct cnxk_mtr_policy mtr_policy;
+	struct cnxk_mtr mtr;
 
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 23/27] net/cnxk: support ops to delete meter
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (20 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 22/27] net/cnxk: support ops to create meter skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 24/27] net/cnxk: support ops to enable/disable meter skori
                   ` (4 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter instance for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 79 +++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 9a8459d919..8bd70df2ed 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -8,6 +8,10 @@
 #define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
 #define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
 
+static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
+						      ROC_NIX_BPF_LEVEL_F_MID,
+						      ROC_NIX_BPF_LEVEL_F_TOP};
+
 static struct rte_mtr_capabilities mtr_capa = {
 	.n_max = NIX_MTR_COUNT_MAX,
 	.n_shared_max = NIX_MTR_COUNT_PER_FLOW,
@@ -449,6 +453,80 @@ cn10k_nix_mtr_create(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		      struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_objs profs = {0};
+	struct cnxk_mtr *fm = &dev->mtr;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, &mtr_id,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->ref_cnt) {
+		return -rte_mtr_error_set(error, EADDRINUSE,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, &mtr_id,
+					  "Meter id in use.");
+	}
+
+	switch (lvl_map[mtr->level]) {
+	case ROC_NIX_BPF_LEVEL_F_LEAF:
+		if (mtr->is_next) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_LEAF,
+						 mtr_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		break;
+	case ROC_NIX_BPF_LEVEL_F_MID:
+		if (mtr->is_prev) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_LEAF,
+						 mtr->prev_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		if (mtr->is_next) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_MID,
+						 mtr_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		break;
+	case ROC_NIX_BPF_LEVEL_F_TOP:
+		if (mtr->is_prev) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_MID,
+						 mtr->prev_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		break;
+	default:
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Invalid meter level");
+	}
+
+	if (rc)
+		goto exit;
+
+	profs.level = mtr->level;
+	profs.count = 1;
+	profs.ids[0] = mtr->bpf_id;
+	rc = roc_nix_bpf_free(nix, &profs, 1);
+	if (rc)
+		goto exit;
+
+	TAILQ_REMOVE(fm, mtr, next);
+	plt_free(fm);
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -457,6 +535,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_add = cn10k_nix_mtr_policy_add,
 	.meter_policy_delete = cn10k_nix_mtr_policy_delete,
 	.create = cn10k_nix_mtr_create,
+	.destroy = cn10k_nix_mtr_destroy,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 24/27] net/cnxk: support ops to enable/disable meter
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (21 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 23/27] net/cnxk: support ops to delete meter skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 25/27] net/cnxk: support ops to update precolor DSCP table skori
                   ` (3 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to enable or disable meter instance for
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 60 +++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 8bd70df2ed..2f82bd08ec 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -527,6 +527,64 @@ cn10k_nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cn10k_nix_mtr_enable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->level != 0)
+		return 0;
+
+	for (i = 0; i < mtr->rq_num; i++) {
+		rq = &dev->rqs[mtr->rq_id[i]];
+		rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, true);
+	}
+
+	return rc;
+}
+
+static int
+cn10k_nix_mtr_disable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		      struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->level != 0)
+		return 0;
+
+	for (i = 0; i < mtr->rq_num; i++) {
+		rq = &dev->rqs[mtr->rq_id[i]];
+		rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, false);
+	}
+
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -536,6 +594,8 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_delete = cn10k_nix_mtr_policy_delete,
 	.create = cn10k_nix_mtr_create,
 	.destroy = cn10k_nix_mtr_destroy,
+	.meter_enable = cn10k_nix_mtr_enable,
+	.meter_disable = cn10k_nix_mtr_disable,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 25/27] net/cnxk: support ops to update precolor DSCP table
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (22 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 24/27] net/cnxk: support ops to enable/disable meter skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 26/27] net/cnxk: support ops to read/update meter stats skori
                   ` (2 subsequent siblings)
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to update DSCP table for pre-coloring for
incoming packet per nixlf for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 43 +++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 2f82bd08ec..63abcb9788 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -585,6 +585,48 @@ cn10k_nix_mtr_disable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cn10k_nix_mtr_dscp_table_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+				enum rte_color *dscp_table,
+				struct rte_mtr_error *error)
+{
+	enum roc_nix_bpf_color nix_dscp_tbl[ROC_NIX_BPF_PRE_COLOR_MAX];
+	enum roc_nix_bpf_color color_map[] = {ROC_NIX_BPF_COLOR_GREEN,
+					      ROC_NIX_BPF_COLOR_YELLOW,
+					      ROC_NIX_BPF_COLOR_RED};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint8_t lvl_flag = ROC_NIX_BPF_LEVEL_F_LEAF;
+	struct roc_nix_bpf_precolor table;
+	struct roc_nix *nix = &dev->nix;
+	int rc, i;
+
+	if (!dscp_table) {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			nix_dscp_tbl[i] = ROC_NIX_BPF_COLOR_GREEN;
+	} else {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			nix_dscp_tbl[i] = color_map[dscp_table[i]];
+	}
+
+	table.count = ROC_NIX_BPF_PRE_COLOR_MAX;
+	table.mode = ROC_NIX_BPF_PC_MODE_DSCP_OUTER;
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		table.color[i] = nix_dscp_tbl[i];
+
+	rc = roc_nix_bpf_pre_color_tbl_setup(nix, mtr_id, lvl_flag, &table);
+	if (rc) {
+		rte_mtr_error_set(error, rc, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+				  NULL, NULL);
+		goto exit;
+	}
+
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		dev->precolor_tbl[i] = nix_dscp_tbl[i];
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -596,6 +638,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.destroy = cn10k_nix_mtr_destroy,
 	.meter_enable = cn10k_nix_mtr_enable,
 	.meter_disable = cn10k_nix_mtr_disable,
+	.meter_dscp_table_update = cn10k_nix_mtr_dscp_table_update,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 26/27] net/cnxk: support ops to read/update meter stats
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (23 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 25/27] net/cnxk: support ops to update precolor DSCP table skori
@ 2021-09-27  8:22 ` skori
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 27/27] net/cnxk: support meter action to flow create skori
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to read and update stats corresponding to
given meter instance for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 141 ++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 63abcb9788..c0482d1418 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -8,6 +8,21 @@
 #define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
 #define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
 
+#define NIX_BPF_STATS_MASK_ALL                                                 \
+	{                                                                      \
+		ROC_NIX_BPF_GREEN_PKT_F_PASS | ROC_NIX_BPF_GREEN_OCTS_F_PASS | \
+			ROC_NIX_BPF_GREEN_PKT_F_DROP |                         \
+			ROC_NIX_BPF_GREEN_OCTS_F_DROP |                        \
+			ROC_NIX_BPF_YELLOW_PKT_F_PASS |                        \
+			ROC_NIX_BPF_YELLOW_OCTS_F_PASS |                       \
+			ROC_NIX_BPF_YELLOW_PKT_F_DROP |                        \
+			ROC_NIX_BPF_YELLOW_OCTS_F_DROP |                       \
+			ROC_NIX_BPF_RED_PKT_F_PASS |                           \
+			ROC_NIX_BPF_RED_OCTS_F_PASS |                          \
+			ROC_NIX_BPF_RED_PKT_F_DROP |                           \
+			ROC_NIX_BPF_RED_OCTS_F_DROP                            \
+	}
+
 static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
 						      ROC_NIX_BPF_LEVEL_F_MID,
 						      ROC_NIX_BPF_LEVEL_F_TOP};
@@ -627,6 +642,130 @@ cn10k_nix_mtr_dscp_table_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cn10k_nix_mtr_stats_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+			   uint64_t stats_mask, struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	if (!stats_mask)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "no bit is set to stats mask");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	mtr->params.stats_mask = stats_mask;
+	return 0;
+}
+
+static int
+cn10k_nix_mtr_stats_read(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+			 struct rte_mtr_stats *stats, uint64_t *stats_mask,
+			 int clear, struct rte_mtr_error *error)
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	uint64_t bpf_stats[ROC_NIX_BPF_STATS_MAX] = {0};
+	uint8_t lvl_flag = ROC_NIX_BPF_LEVEL_F_LEAF;
+	uint64_t mask = NIX_BPF_STATS_MASK_ALL;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	int rc;
+
+	if (!stats)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "stats pointer is NULL");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	rc = roc_nix_bpf_stats_read(nix, mtr->bpf_id, mask, lvl_flag,
+				    bpf_stats);
+	if (rc) {
+		rte_mtr_error_set(error, rc, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+				  NULL, NULL);
+		goto exit;
+	}
+
+	green_pkt_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
+		stats->n_pkts[RTE_COLOR_GREEN] = bpf_stats[green_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
+		stats->n_pkts[RTE_COLOR_YELLOW] = bpf_stats[yellow_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_RED)
+		stats->n_pkts[RTE_COLOR_RED] = bpf_stats[red_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
+		stats->n_bytes[RTE_COLOR_GREEN] = bpf_stats[green_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
+		stats->n_bytes[RTE_COLOR_YELLOW] = bpf_stats[yellow_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_RED)
+		stats->n_bytes[RTE_COLOR_RED] = bpf_stats[red_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
+		stats->n_pkts_dropped = bpf_stats[green_pkt_drop] +
+					bpf_stats[yellow_pkt_drop] +
+					bpf_stats[red_pkt_drop];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
+		stats->n_bytes_dropped = bpf_stats[green_octs_drop] +
+					 bpf_stats[yellow_octs_drop] +
+					 bpf_stats[red_octs_drop];
+
+	if (stats_mask)
+		*stats_mask = mtr->params.stats_mask;
+
+	if (clear) {
+		rc = roc_nix_bpf_stats_reset(nix, mtr->bpf_id, mask, lvl_flag);
+		if (rc) {
+			rte_mtr_error_set(error, rc,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  NULL);
+			goto exit;
+		}
+	}
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -639,6 +778,8 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_enable = cn10k_nix_mtr_enable,
 	.meter_disable = cn10k_nix_mtr_disable,
 	.meter_dscp_table_update = cn10k_nix_mtr_dscp_table_update,
+	.stats_update = cn10k_nix_mtr_stats_update,
+	.stats_read = cn10k_nix_mtr_stats_read,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v2 27/27] net/cnxk: support meter action to flow create
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (24 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 26/27] net/cnxk: support ops to read/update meter stats skori
@ 2021-09-27  8:22 ` skori
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
  26 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-27  8:22 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Meters are configured per flow using rte_flow_create API.
Implement support for meter action applied on the flow.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 doc/guides/nics/features/cnxk.ini    |   1 +
 doc/guides/nics/features/cnxk_vf.ini |   1 +
 drivers/net/cnxk/cn10k_ethdev_mtr.c  | 388 +++++++++++++++++++++++++++
 drivers/net/cnxk/cn10k_rte_flow.c    | 155 ++++++++++-
 drivers/net/cnxk/cnxk_ethdev.h       |  15 ++
 drivers/net/cnxk/cnxk_rte_flow.c     |   4 +
 6 files changed, 563 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/cnxk.ini b/doc/guides/nics/features/cnxk.ini
index 5d456257bd..7bbce7dafc 100644
--- a/doc/guides/nics/features/cnxk.ini
+++ b/doc/guides/nics/features/cnxk.ini
@@ -78,6 +78,7 @@ count                = Y
 drop                 = Y
 flag                 = Y
 mark                 = Y
+meter                = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
 of_set_vlan_pcp      = Y
diff --git a/doc/guides/nics/features/cnxk_vf.ini b/doc/guides/nics/features/cnxk_vf.ini
index 7b4299f0be..89802a27f9 100644
--- a/doc/guides/nics/features/cnxk_vf.ini
+++ b/doc/guides/nics/features/cnxk_vf.ini
@@ -70,6 +70,7 @@ count                = Y
 drop                 = Y
 flag                 = Y
 mark                 = Y
+meter                = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
 of_set_vlan_pcp      = Y
diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index c0482d1418..75193b3db1 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -790,3 +790,391 @@ cn10k_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops)
 	*(const void **)ops = &nix_mtr_ops;
 	return 0;
 }
+
+int
+nix_mtr_validate(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	profile = nix_mtr_profile_find(dev, mtr->params.meter_profile_id);
+	if (profile == NULL)
+		return -EINVAL;
+
+	policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id);
+	if (policy == NULL)
+		return -EINVAL;
+
+	return 0;
+}
+
+int
+nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id,
+		       struct cnxk_mtr_policy_node **policy_act)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id);
+	if (policy == NULL)
+		return -EINVAL;
+
+	*policy_act = policy;
+
+	return 0;
+}
+
+int
+nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t queue_num,
+		  const uint16_t *queue)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+	uint32_t i;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	mtr->rq_id = plt_zmalloc(queue_num * sizeof(uint32_t), ROC_ALIGN);
+	if (mtr->rq_id == NULL)
+		return -ENOMEM;
+
+	mtr->rq_num = queue_num;
+	for (i = 0; i < queue_num; i++)
+		mtr->rq_id[i] = queue[i];
+
+	return 0;
+}
+
+int
+nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id)
+{
+	struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint32_t mtr_id = cur_id;
+	int i = 0;
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		mtr[i] = nix_mtr_find(dev, mtr_id);
+		if (mtr[i])
+			mtr_id = mtr[i]->next_id;
+	}
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		if (mtr[i]) {
+			mtr[i]->level = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+			mtr[i]->prev_id = ROC_NIX_BPF_ID_INVALID;
+			mtr[i]->next_id = ROC_NIX_BPF_ID_INVALID;
+			mtr[i]->is_prev = false;
+			mtr[i]->is_next = false;
+		}
+	}
+	return 0;
+}
+
+int
+nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id,
+		     uint32_t prev_id, uint32_t next_id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, cur_id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	switch (lvl_map[mtr->level]) {
+	case ROC_NIX_BPF_LEVEL_F_LEAF:
+		mtr->prev_id = ROC_NIX_BPF_ID_INVALID;
+		mtr->next_id = next_id;
+		mtr->is_prev = false;
+		mtr->is_next = true;
+		break;
+	case ROC_NIX_BPF_LEVEL_F_MID:
+		mtr->prev_id = prev_id;
+		mtr->next_id = next_id;
+		mtr->is_prev = true;
+		mtr->is_next = true;
+		break;
+	case ROC_NIX_BPF_LEVEL_F_TOP:
+		mtr->prev_id = prev_id;
+		mtr->next_id = ROC_NIX_BPF_ID_INVALID;
+		mtr->is_prev = true;
+		mtr->is_next = false;
+		break;
+	default:
+		plt_err("Invalid meter level");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int
+nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t level)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	mtr->level = level;
+	return 0;
+}
+
+static void
+nix_mtr_config_map(struct cnxk_meter_node *mtr, struct roc_nix_bpf_cfg *cfg)
+{
+	enum roc_nix_bpf_algo alg_map[] = {
+		ROC_NIX_BPF_ALGO_NONE, ROC_NIX_BPF_ALGO_2697,
+		ROC_NIX_BPF_ALGO_2698, ROC_NIX_BPF_ALGO_4115};
+	struct cnxk_mtr_profile_node *profile = mtr->profile;
+	struct cnxk_mtr_policy_node *policy = mtr->policy;
+
+	cfg->alg = alg_map[profile->profile.alg];
+	cfg->lmode = profile->profile.packet_mode;
+
+	switch (cfg->alg) {
+	case ROC_NIX_BPF_ALGO_2697:
+		cfg->algo2697.cir = profile->profile.srtcm_rfc2697.cir * 8;
+		cfg->algo2697.cbs = profile->profile.srtcm_rfc2697.cbs;
+		cfg->algo2697.ebs = profile->profile.srtcm_rfc2697.ebs;
+		break;
+	case ROC_NIX_BPF_ALGO_2698:
+		cfg->algo2698.cir = profile->profile.trtcm_rfc2698.cir * 8;
+		cfg->algo2698.pir = profile->profile.trtcm_rfc2698.pir * 8;
+		cfg->algo2698.cbs = profile->profile.trtcm_rfc2698.cbs;
+		cfg->algo2698.pbs = profile->profile.trtcm_rfc2698.pbs;
+		break;
+	case ROC_NIX_BPF_ALGO_4115:
+		cfg->algo4115.cir = profile->profile.trtcm_rfc4115.cir * 8;
+		cfg->algo4115.eir = profile->profile.trtcm_rfc4115.eir * 8;
+		cfg->algo4115.cbs = profile->profile.trtcm_rfc4115.cbs;
+		cfg->algo4115.ebs = profile->profile.trtcm_rfc4115.ebs;
+		break;
+	default:
+		break;
+	}
+
+	cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_PASS;
+	cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_PASS;
+	cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_PASS;
+
+	if (policy->actions[RTE_COLOR_GREEN].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_DROP;
+
+	if (policy->actions[RTE_COLOR_YELLOW].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_DROP;
+
+	if (policy->actions[RTE_COLOR_RED].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_DROP;
+}
+
+static void
+nix_dscp_table_map(struct cnxk_meter_node *mtr,
+		   struct roc_nix_bpf_precolor *tbl)
+{
+	enum roc_nix_bpf_color color_map[] = {ROC_NIX_BPF_COLOR_GREEN,
+					      ROC_NIX_BPF_COLOR_YELLOW,
+					      ROC_NIX_BPF_COLOR_RED};
+	int i;
+
+	tbl->count = ROC_NIX_BPF_PRE_COLOR_MAX;
+	tbl->mode = ROC_NIX_BPF_PC_MODE_DSCP_OUTER;
+
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		tbl->color[i] = ROC_NIX_BPF_COLOR_GREEN;
+
+	if (mtr->params.dscp_table) {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			tbl->color[i] = color_map[mtr->params.dscp_table[i]];
+	}
+}
+
+int
+nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_objs profs[ROC_NIX_BPF_LEVEL_MAX];
+	uint8_t idx0 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint8_t idx1 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint8_t idx2 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX];
+	int num_mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct roc_nix *nix = &dev->nix;
+	struct roc_nix_bpf_precolor tbl;
+	struct roc_nix_bpf_cfg cfg;
+	struct roc_nix_rq *rq;
+	uint8_t lvl_mask;
+	uint32_t i;
+	uint32_t j;
+	int rc;
+
+	mtr[0] = nix_mtr_find(dev, id);
+	if (mtr[0] == NULL)
+		return -EINVAL;
+
+	num_mtr[0] = 1;
+	idx0 = roc_nix_bpf_level_to_idx(lvl_map[mtr[0]->level]);
+	if (idx0 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return -EINVAL;
+
+	lvl_mask = ROC_NIX_BPF_LEVEL_F_LEAF;
+	per_lvl_cnt[idx0] = 1;
+
+	if (mtr[0]->is_next) {
+		mtr[1] = nix_mtr_find(dev, mtr[0]->next_id);
+		if (mtr[1] == NULL)
+			return -EINVAL;
+		num_mtr[1] = 1;
+		idx1 = roc_nix_bpf_level_to_idx(lvl_map[mtr[1]->level]);
+		if (idx1 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			return -EINVAL;
+
+		lvl_mask |= ROC_NIX_BPF_LEVEL_F_MID;
+		per_lvl_cnt[idx1] = 1;
+	}
+
+	if (mtr[1] && mtr[1]->is_next) {
+		mtr[2] = nix_mtr_find(dev, mtr[1]->next_id);
+		if (mtr[2] == NULL)
+			return -EINVAL;
+
+		num_mtr[2] = 1;
+		idx2 = roc_nix_bpf_level_to_idx(lvl_map[mtr[2]->level]);
+		if (idx2 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			return -EINVAL;
+
+		lvl_mask |= ROC_NIX_BPF_LEVEL_F_TOP;
+		per_lvl_cnt[idx2] = 1;
+	}
+
+	rc = roc_nix_bpf_alloc(nix, lvl_mask, per_lvl_cnt, profs);
+	if (rc)
+		return rc;
+
+	mtr[0]->bpf_id = profs[idx0].ids[0];
+
+	if (num_mtr[0])
+		if (mtr[0]->is_next && idx1 != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			mtr[1]->bpf_id = profs[idx1].ids[0];
+
+	if (num_mtr[1])
+		if (mtr[1]->is_next && idx2 != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			mtr[2]->bpf_id = profs[idx2].ids[0];
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		if (num_mtr[i]) {
+			memset(&cfg, 0, sizeof(struct roc_nix_bpf_cfg));
+			nix_mtr_config_map(mtr[i], &cfg);
+			rc = roc_nix_bpf_config(nix, mtr[i]->bpf_id,
+						lvl_map[mtr[i]->level], &cfg);
+
+			memset(&tbl, 0, sizeof(struct roc_nix_bpf_precolor));
+			nix_dscp_table_map(mtr[i], &tbl);
+			rc = roc_nix_bpf_pre_color_tbl_setup(nix,
+						     mtr[i]->bpf_id,
+						     lvl_map[mtr[i]->level],
+						     &tbl);
+
+			if (mtr[i]->params.meter_enable) {
+				for (j = 0; j < mtr[i]->rq_num; j++) {
+					rq = &dev->rqs[mtr[i]->rq_id[j]];
+					rc = roc_nix_bpf_ena_dis(nix,
+							 mtr[i]->bpf_id, rq,
+							 true);
+				}
+			}
+		}
+	}
+
+	return rc;
+}
+
+int
+nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
+			      uint32_t *prev_id, uint32_t *next_id,
+			      struct cnxk_mtr_policy_node *policy,
+			      int *tree_level)
+{
+	uint32_t action_fate_red = policy->actions[RTE_COLOR_RED].action_fate;
+	uint32_t action_fate_green =
+		policy->actions[RTE_COLOR_GREEN].action_fate;
+	uint32_t action_fate_yellow =
+		policy->actions[RTE_COLOR_YELLOW].action_fate;
+
+	uint32_t cur_mtr_id = *next_id;
+	uint32_t next_mtr_id = 0xffff;
+	uint32_t prev_mtr_id = 0xffff;
+
+	if (action_fate_green == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_GREEN].mtr_id;
+
+	if (action_fate_yellow == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_YELLOW].mtr_id;
+
+	if (action_fate_red == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_RED].mtr_id;
+
+	if (next_mtr_id != 0xffff) {
+		switch (*tree_level) {
+		case 0:
+			nix_mtr_level_update(eth_dev, cur_mtr_id, 0);
+			nix_mtr_chain_update(eth_dev, cur_mtr_id, -1,
+					     next_mtr_id);
+			(*tree_level)++;
+			*next_id = next_mtr_id;
+			break;
+		case 1:
+			nix_mtr_level_update(eth_dev, cur_mtr_id, 1);
+			prev_mtr_id = id;
+			nix_mtr_chain_update(eth_dev, cur_mtr_id, prev_mtr_id,
+					     next_mtr_id);
+			(*tree_level)++;
+			*next_id = next_mtr_id;
+			*prev_id = cur_mtr_id;
+			break;
+		case 2:
+			nix_mtr_chain_reset(eth_dev, id);
+			return -EINVAL;
+		}
+	} else {
+		switch (*tree_level) {
+		case 0:
+			nix_mtr_level_update(eth_dev, cur_mtr_id, 0);
+			break;
+		case 1:
+			nix_mtr_level_update(eth_dev, cur_mtr_id, 1);
+			prev_mtr_id = id;
+			nix_mtr_chain_update(eth_dev, cur_mtr_id, prev_mtr_id,
+					     -1);
+			break;
+		case 2:
+			nix_mtr_level_update(eth_dev, cur_mtr_id, 2);
+			prev_mtr_id = *prev_id;
+			nix_mtr_chain_update(eth_dev, cur_mtr_id, prev_mtr_id,
+					     -1);
+			break;
+		}
+		*next_id = 0xffff;
+	}
+
+	return 0;
+}
diff --git a/drivers/net/cnxk/cn10k_rte_flow.c b/drivers/net/cnxk/cn10k_rte_flow.c
index b04de6a7e6..128dc2dd4f 100644
--- a/drivers/net/cnxk/cn10k_rte_flow.c
+++ b/drivers/net/cnxk/cn10k_rte_flow.c
@@ -6,6 +6,107 @@
 #include "cn10k_ethdev.h"
 #include "cn10k_rx.h"
 
+static int
+cn10k_mtr_configure(struct rte_eth_dev *eth_dev,
+		    const struct rte_flow_action actions[])
+{
+	uint32_t mtr_id = 0xffff, prev_mtr_id = 0xffff, next_mtr_id = 0xffff;
+	const struct rte_flow_action_meter *mtr_conf;
+	const struct rte_flow_action_queue *q_conf;
+	const struct rte_flow_action_rss *rss_conf;
+	struct cnxk_mtr_policy_node *policy;
+	bool is_mtr_act = false;
+	int tree_level = 0;
+	int rc = -EINVAL, i;
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) {
+			mtr_conf = (const struct rte_flow_action_meter
+					    *)(actions->conf);
+			mtr_id = mtr_conf->mtr_id;
+			is_mtr_act = true;
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE) {
+			q_conf = (const struct rte_flow_action_queue
+					  *)(actions->conf);
+			if (is_mtr_act)
+				nix_mtr_rq_update(eth_dev, mtr_id, 1,
+						  &q_conf->index);
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
+			rss_conf = (const struct rte_flow_action_rss
+					    *)(actions->conf);
+			if (is_mtr_act)
+				nix_mtr_rq_update(eth_dev, mtr_id,
+						  rss_conf->queue_num,
+						  rss_conf->queue);
+		}
+	}
+
+	if (!is_mtr_act)
+		return rc;
+
+	prev_mtr_id = mtr_id;
+	next_mtr_id = mtr_id;
+	while (next_mtr_id != 0xffff) {
+		rc = nix_mtr_validate(eth_dev, next_mtr_id);
+		if (rc)
+			return rc;
+
+		rc = nix_mtr_policy_act_get(eth_dev, next_mtr_id, &policy);
+		if (rc)
+			return rc;
+
+		rc = nix_mtr_color_action_validate(eth_dev, mtr_id,
+						   &prev_mtr_id, &next_mtr_id,
+						   policy, &tree_level);
+		if (rc)
+			return rc;
+	}
+
+	return nix_mtr_configure(eth_dev, mtr_id);
+}
+
+static int
+cn10k_rss_action_validate(struct rte_eth_dev *eth_dev,
+			  const struct rte_flow_attr *attr,
+			  const struct rte_flow_action *act)
+{
+	const struct rte_flow_action_rss *rss;
+
+	if (act == NULL)
+		return -EINVAL;
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (attr->egress) {
+		plt_err("No support of RSS in egress");
+		return -EINVAL;
+	}
+
+	if (eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
+		plt_err("multi-queue mode is disabled");
+		return -ENOTSUP;
+	}
+
+	if (!rss || !rss->queue_num) {
+		plt_err("no valid queues");
+		return -EINVAL;
+	}
+
+	if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
+		plt_err("non-default RSS hash functions are not supported");
+		return -ENOTSUP;
+	}
+
+	if (rss->key_len && rss->key_len > ROC_NIX_RSS_KEY_LEN) {
+		plt_err("RSS hash key too large");
+		return -ENOTSUP;
+	}
+
+	return 0;
+}
+
 struct rte_flow *
 cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		  const struct rte_flow_item pattern[],
@@ -13,13 +114,65 @@ cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		  struct rte_flow_error *error)
 {
 	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	const struct rte_flow_action *action_rss = NULL;
+	const struct rte_flow_action_meter *mtr = NULL;
 	int mark_actions = 0, vtag_actions = 0;
 	struct roc_npc *npc = &dev->npc;
 	struct roc_npc_flow *flow;
+	uint32_t req_act = 0;
+	int i, rc;
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER)
+			req_act |= ROC_NPC_ACTION_TYPE_METER;
+
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE)
+			req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
+
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
+			req_act |= ROC_NPC_ACTION_TYPE_RSS;
+			action_rss = &actions[i];
+		}
+	}
+
+	if (req_act & ROC_NPC_ACTION_TYPE_METER) {
+		if ((req_act & ROC_NPC_ACTION_TYPE_RSS) &&
+		    ((req_act & ROC_NPC_ACTION_TYPE_QUEUE))) {
+			return NULL;
+		}
+		if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
+			rc = cn10k_rss_action_validate(eth_dev, attr,
+						       action_rss);
+			if (rc)
+				return NULL;
+		} else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
+		} else {
+			return NULL;
+		}
+	}
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) {
+			mtr = (const struct rte_flow_action_meter *)actions[i]
+				      .conf;
+			rc = cn10k_mtr_configure(eth_dev, actions);
+			if (rc) {
+				rte_flow_error_set(error, 0,
+					RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+					"Failed to configure mtr ");
+				return NULL;
+			}
+			break;
+		}
+	}
 
 	flow = cnxk_flow_create(eth_dev, attr, pattern, actions, error);
-	if (!flow)
+	if (!flow) {
+		if (mtr)
+			nix_mtr_chain_reset(eth_dev, mtr->mtr_id);
+
 		return NULL;
+	}
 
 	mark_actions = roc_npc_mark_actions_get(npc);
 
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 0ad06f1536..2dce42e20c 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -454,6 +454,21 @@ int cnxk_nix_dev_get_reg(struct rte_eth_dev *eth_dev,
 
 /* Other private functions */
 int nix_recalc_mtu(struct rte_eth_dev *eth_dev);
+int nix_mtr_validate(struct rte_eth_dev *dev, uint32_t id);
+int nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id,
+			   struct cnxk_mtr_policy_node **policy);
+int nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id,
+		      uint32_t queue_num, const uint16_t *queue);
+int nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id,
+			 uint32_t prev_id, uint32_t next_id);
+int nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id);
+int nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id,
+			 uint32_t level);
+int nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id);
+int nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
+				  uint32_t *prev_id, uint32_t *next_id,
+				  struct cnxk_mtr_policy_node *policy,
+				  int *tree_level);
 
 /* Inlines */
 static __rte_always_inline uint64_t
diff --git a/drivers/net/cnxk/cnxk_rte_flow.c b/drivers/net/cnxk/cnxk_rte_flow.c
index 32c1b5dee5..56dcd36c61 100644
--- a/drivers/net/cnxk/cnxk_rte_flow.c
+++ b/drivers/net/cnxk/cnxk_rte_flow.c
@@ -195,6 +195,10 @@ cnxk_map_actions(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 				ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
 			in_actions[i].conf = actions->conf;
 			break;
+		case RTE_FLOW_ACTION_TYPE_METER:
+			in_actions[i].type = ROC_NPC_ACTION_TYPE_METER;
+			in_actions[i].conf = actions->conf;
+			break;
 		default:
 			plt_npc_dbg("Action is not supported = %d",
 				    actions->type);
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions
  2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                   ` (25 preceding siblings ...)
  2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 27/27] net/cnxk: support meter action to flow create skori
@ 2021-09-30  9:08 ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 02/27] common/cnxk: support RoC API to get level to index skori
                     ` (27 more replies)
  26 siblings, 28 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao; +Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

To support ingress policer on CN10K, MBOX interfaces and HW
definitions are synced.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/hw/nix.h   | 13 ++++++++++---
 drivers/common/cnxk/roc_mbox.h | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/common/cnxk/hw/nix.h b/drivers/common/cnxk/hw/nix.h
index 6b86002ead..53cdfbb142 100644
--- a/drivers/common/cnxk/hw/nix.h
+++ b/drivers/common/cnxk/hw/nix.h
@@ -692,9 +692,16 @@
 #define NIX_RX_BAND_PROF_ACTIONRESULT_DROP (0x1ull) /* [CN10K, .) */
 #define NIX_RX_BAND_PROF_ACTIONRESULT_RED  (0x2ull) /* [CN10K, .) */
 
-#define NIX_RX_BAND_PROF_LAYER_LEAF   (0x0ull) /* [CN10K, .) */
-#define NIX_RX_BAND_PROF_LAYER_MIDDLE (0x1ull) /* [CN10K, .) */
-#define NIX_RX_BAND_PROF_LAYER_TOP    (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_LEAF    (0x0ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_INVALID (0x1ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_MIDDLE  (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_TOP     (0x3ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_MAX     (0x4ull) /* [CN10K, .) */
+
+#define NIX_RX_BAND_PROF_PC_MODE_VLAN (0x0ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_DSCP (0x1ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_GEN  (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_RSVD (0x3ull) /* [CN10K, .) */
 
 #define NIX_RX_COLORRESULT_GREEN  (0x0ull) /* [CN10K, .) */
 #define NIX_RX_COLORRESULT_YELLOW (0x1ull) /* [CN10K, .) */
diff --git a/drivers/common/cnxk/roc_mbox.h b/drivers/common/cnxk/roc_mbox.h
index b5da931b81..c8b97e9aee 100644
--- a/drivers/common/cnxk/roc_mbox.h
+++ b/drivers/common/cnxk/roc_mbox.h
@@ -234,7 +234,11 @@ struct mbox_msghdr {
 	  nix_inline_ipsec_lf_cfg, msg_rsp)                                    \
 	M(NIX_CN10K_AQ_ENQ, 0x801b, nix_cn10k_aq_enq, nix_cn10k_aq_enq_req,    \
 	  nix_cn10k_aq_enq_rsp)                                                \
-	M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info)
+	M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info)      \
+	M(NIX_BANDPROF_ALLOC, 0x801d, nix_bandprof_alloc,                      \
+	  nix_bandprof_alloc_req, nix_bandprof_alloc_rsp)                      \
+	M(NIX_BANDPROF_FREE, 0x801e, nix_bandprof_free, nix_bandprof_free_req, \
+	  msg_rsp)
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES                                                   \
@@ -771,6 +775,10 @@ struct nix_cn10k_aq_enq_req {
 		__io struct nix_rsse_s rss;
 		/* Valid when op == WRITE/INIT and ctype == NIX_AQ_CTYPE_MCE */
 		__io struct nix_rx_mce_s mce;
+		/* Valid when op == WRITE/INIT and
+		 * ctype == NIX_AQ_CTYPE_BAND_PROF
+		 */
+		__io struct nix_band_prof_s prof;
 	};
 	/* Mask data when op == WRITE (1=write, 0=don't write) */
 	union {
@@ -784,6 +792,8 @@ struct nix_cn10k_aq_enq_req {
 		__io struct nix_rsse_s rss_mask;
 		/* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_MCE */
 		__io struct nix_rx_mce_s mce_mask;
+		/* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_BAND_PROF */
+		__io struct nix_band_prof_s prof_mask;
 	};
 };
 
@@ -795,6 +805,7 @@ struct nix_cn10k_aq_enq_rsp {
 		struct nix_cq_ctx_s cq;
 		struct nix_rsse_s rss;
 		struct nix_rx_mce_s mce;
+		struct nix_band_prof_s prof;
 	};
 };
 
@@ -1129,6 +1140,27 @@ struct nix_hw_info {
 	uint16_t __io rsvd[15];
 };
 
+struct nix_bandprof_alloc_req {
+	struct mbox_msghdr hdr;
+	/* Count of profiles needed per layer */
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+};
+
+struct nix_bandprof_alloc_rsp {
+	struct mbox_msghdr hdr;
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+
+#define BANDPROF_PER_PFFUNC 64
+	uint16_t __io prof_idx[NIX_RX_BAND_PROF_LAYER_MAX][BANDPROF_PER_PFFUNC];
+};
+
+struct nix_bandprof_free_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io free_all;
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+	uint16_t __io prof_idx[NIX_RX_BAND_PROF_LAYER_MAX][BANDPROF_PER_PFFUNC];
+};
+
 /* SSO mailbox error codes
  * Range 501 - 600.
  */
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 02/27] common/cnxk: support RoC API to get level to index
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 03/27] common/cnxk: support RoC API to get profile count skori
                     ` (26 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform supports policer up to 3 level of hierarchy.
Implement RoC API to get corresponding index for given level.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/meson.build    |  1 +
 drivers/common/cnxk/roc_nix.h      | 11 +++++++++++
 drivers/common/cnxk/roc_nix_bpf.c  | 22 ++++++++++++++++++++++
 drivers/common/cnxk/roc_nix_priv.h |  1 +
 drivers/common/cnxk/roc_utils.c    |  3 +++
 drivers/common/cnxk/version.map    |  1 +
 6 files changed, 39 insertions(+)
 create mode 100644 drivers/common/cnxk/roc_nix_bpf.c

diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build
index 8a551d15d6..62901e66e7 100644
--- a/drivers/common/cnxk/meson.build
+++ b/drivers/common/cnxk/meson.build
@@ -25,6 +25,7 @@ sources = files(
         'roc_mbox.c',
         'roc_model.c',
         'roc_nix.c',
+        'roc_nix_bpf.c',
         'roc_nix_debug.c',
         'roc_nix_fc.c',
         'roc_nix_irq.c',
diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index b0e6fabe31..1488c24f59 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -6,6 +6,8 @@
 #define _ROC_NIX_H_
 
 /* Constants */
+#define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
+
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
 	ROC_NIX_RSS_RETA_SZ_128 = 128,
@@ -29,6 +31,12 @@ enum roc_nix_vlan_type {
 	ROC_NIX_VLAN_TYPE_OUTER = 0x02,
 };
 
+enum roc_nix_bpf_level_flag {
+	ROC_NIX_BPF_LEVEL_F_LEAF = BIT(0),
+	ROC_NIX_BPF_LEVEL_F_MID = BIT(1),
+	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -468,6 +476,9 @@ int __roc_api roc_nix_tm_rsrc_count(struct roc_nix *roc_nix,
 int __roc_api roc_nix_tm_node_name_get(struct roc_nix *roc_nix,
 				       uint32_t node_id, char *buf,
 				       size_t buflen);
+/* Ingress Policer API */
+uint8_t __roc_api
+roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
 /* MAC */
 int __roc_api roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start);
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
new file mode 100644
index 0000000000..b588cc16e4
--- /dev/null
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell.
+ */
+
+#include "roc_api.h"
+#include "roc_priv.h"
+
+uint8_t
+roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
+{
+	uint8_t idx;
+
+	if (level_f & ROC_NIX_BPF_LEVEL_F_LEAF)
+		idx = 0;
+	else if (level_f & ROC_NIX_BPF_LEVEL_F_MID)
+		idx = 1;
+	else if (level_f & ROC_NIX_BPF_LEVEL_F_TOP)
+		idx = 2;
+	else
+		idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	return idx;
+}
diff --git a/drivers/common/cnxk/roc_nix_priv.h b/drivers/common/cnxk/roc_nix_priv.h
index 9dc0c88a6f..94040fc744 100644
--- a/drivers/common/cnxk/roc_nix_priv.h
+++ b/drivers/common/cnxk/roc_nix_priv.h
@@ -170,6 +170,7 @@ enum nix_err_status {
 	NIX_ERR_INVALID_RANGE,
 	NIX_ERR_INTERNAL,
 	NIX_ERR_OP_NOTSUP,
+	NIX_ERR_HW_NOTSUP,
 	NIX_ERR_QUEUE_INVALID_RANGE,
 	NIX_ERR_AQ_READ_FAILED,
 	NIX_ERR_AQ_WRITE_FAILED,
diff --git a/drivers/common/cnxk/roc_utils.c b/drivers/common/cnxk/roc_utils.c
index 9cb8708a74..77dc279bcb 100644
--- a/drivers/common/cnxk/roc_utils.c
+++ b/drivers/common/cnxk/roc_utils.c
@@ -34,6 +34,9 @@ roc_error_msg_get(int errorcode)
 	case NIX_ERR_OP_NOTSUP:
 		err_msg = "Operation not supported";
 		break;
+	case NIX_ERR_HW_NOTSUP:
+		err_msg = "Hardware does not support";
+		break;
 	case NIX_ERR_QUEUE_INVALID_RANGE:
 		err_msg = "Invalid Queue range";
 		break;
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 5df2e56ce6..c19f74fe91 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -77,6 +77,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 03/27] common/cnxk: support RoC API to get profile count
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 02/27] common/cnxk: support RoC API to get level to index skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 04/27] common/cnxk: support RoC API to alloc bandwidth profiles skori
                     ` (25 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement interface to get available profile count for given
nixlf.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  5 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 46 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 52 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 1488c24f59..3d3e169977 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -7,6 +7,7 @@
 
 /* Constants */
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
+#define ROC_NIX_BPF_LEVEL_MAX	      3
 
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
@@ -477,6 +478,10 @@ int __roc_api roc_nix_tm_node_name_get(struct roc_nix *roc_nix,
 				       uint32_t node_id, char *buf,
 				       size_t buflen);
 /* Ingress Policer API */
+int __roc_api
+roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX] /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index b588cc16e4..af9dffa90c 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -5,6 +5,14 @@
 #include "roc_api.h"
 #include "roc_priv.h"
 
+#define NIX_MAX_BPF_COUNT_LEAF_LAYER 64
+#define NIX_MAX_BPF_COUNT_MID_LAYER  8
+#define NIX_MAX_BPF_COUNT_TOP_LAYER  1
+
+#define NIX_BPF_LEVEL_F_MASK                                                   \
+	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
+	 ROC_NIX_BPF_LEVEL_F_TOP)
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -20,3 +28,41 @@ roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 		idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
 	return idx;
 }
+
+int
+roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
+{
+	uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
+	uint8_t leaf_idx, mid_idx, top_idx;
+
+	PLT_SET_USED(roc_nix);
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!mask)
+		return NIX_ERR_PARAM;
+
+	/* Currently No MBOX interface is available to get number
+	 * of bandwidth profiles. So numbers per level are hard coded,
+	 * considering 3 RPM blocks and each block has 4 LMAC's.
+	 * So total 12 physical interfaces are in system. Each interface
+	 * supports following bandwidth profiles.
+	 */
+
+	leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
+	mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
+	top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[leaf_idx] = NIX_MAX_BPF_COUNT_LEAF_LAYER;
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[mid_idx] = NIX_MAX_BPF_COUNT_MID_LAYER;
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[top_idx] = NIX_MAX_BPF_COUNT_TOP_LAYER;
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index c19f74fe91..790a32e2e0 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -77,6 +77,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_count_get;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 04/27] common/cnxk: support RoC API to alloc bandwidth profiles
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 02/27] common/cnxk: support RoC API to get level to index skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 03/27] common/cnxk: support RoC API to get profile count skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 05/27] common/cnxk: support RoC API to free " skori
                     ` (24 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to allocate HW resources i.e. bandwidth
profiles for policer processing on CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  11 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 104 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 3 files changed, 116 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 3d3e169977..b55333a01c 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -6,6 +6,7 @@
 #define _ROC_NIX_H_
 
 /* Constants */
+#define ROC_NIX_BPF_PER_PFFUNC	      64
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
 
@@ -38,6 +39,12 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+struct roc_nix_bpf_objs {
+	uint16_t level;
+	uint16_t count;
+	uint16_t ids[ROC_NIX_BPF_PER_PFFUNC];
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -482,6 +489,10 @@ int __roc_api
 roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
+				uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
+				struct roc_nix_bpf_objs *profs /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index af9dffa90c..06394bda07 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -13,6 +13,19 @@
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
 
+static uint8_t sw_to_hw_lvl_map[] = {NIX_RX_BAND_PROF_LAYER_LEAF,
+				     NIX_RX_BAND_PROF_LAYER_MIDDLE,
+				     NIX_RX_BAND_PROF_LAYER_TOP};
+
+static inline struct mbox *
+get_mbox(struct roc_nix *roc_nix)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct dev *dev = &nix->dev;
+
+	return dev->mbox;
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -66,3 +79,94 @@ roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 
 	return 0;
 }
+
+int
+roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		  uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
+		  struct roc_nix_bpf_objs *profs)
+{
+	uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_alloc_req *req;
+	struct nix_bandprof_alloc_rsp *rsp;
+	uint8_t leaf_idx, mid_idx, top_idx;
+	int rc = -ENOSPC, i;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!mask)
+		return NIX_ERR_PARAM;
+
+	leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
+	mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
+	top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
+
+	if ((leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[leaf_idx] > NIX_MAX_BPF_COUNT_LEAF_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	if ((mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[mid_idx] > NIX_MAX_BPF_COUNT_MID_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	if ((top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[top_idx] > NIX_MAX_BPF_COUNT_TOP_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	req = mbox_alloc_msg_nix_bandprof_alloc(mbox);
+	if (req == NULL)
+		goto exit;
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[leaf_idx]] =
+			per_lvl_cnt[leaf_idx];
+	}
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[mid_idx]] =
+			per_lvl_cnt[mid_idx];
+	}
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[top_idx]] =
+			per_lvl_cnt[top_idx];
+	}
+
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		goto exit;
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[leaf_idx].level = leaf_idx;
+		profs[leaf_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[leaf_idx]];
+		for (i = 0; i < profs[leaf_idx].count; i++) {
+			profs[leaf_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[leaf_idx]][i];
+		}
+	}
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[mid_idx].level = mid_idx;
+		profs[mid_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[mid_idx]];
+		for (i = 0; i < profs[mid_idx].count; i++) {
+			profs[mid_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[mid_idx]][i];
+		}
+	}
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[top_idx].level = top_idx;
+		profs[top_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[top_idx]];
+		for (i = 0; i < profs[top_idx].count; i++) {
+			profs[top_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[top_idx]][i];
+		}
+	}
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 790a32e2e0..81e76919b5 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -77,6 +77,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_alloc;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 05/27] common/cnxk: support RoC API to free bandwidth profiles
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (2 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 04/27] common/cnxk: support RoC API to alloc bandwidth profiles skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 06/27] common/cnxk: support RoC API to configure bandwidth profile skori
                     ` (23 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC interface to free HW bandwidth profiles on
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  6 +++++
 drivers/common/cnxk/roc_nix_bpf.c | 40 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  2 ++
 3 files changed, 48 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index b55333a01c..bf451ecdbc 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -493,6 +493,12 @@ int __roc_api roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
 				uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
 				struct roc_nix_bpf_objs *profs /* Out */);
 
+int __roc_api roc_nix_bpf_free(struct roc_nix *roc_nix,
+			       struct roc_nix_bpf_objs *profs,
+			       uint8_t num_prof);
+
+int __roc_api roc_nix_bpf_free_all(struct roc_nix *roc_nix);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 06394bda07..41d31bc6cd 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -170,3 +170,43 @@ roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_free(struct roc_nix *roc_nix, struct roc_nix_bpf_objs *profs,
+		 uint8_t num_prof)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_free_req *req;
+	uint8_t level;
+	int i, j;
+
+	if (num_prof >= NIX_RX_BAND_PROF_LAYER_MAX)
+		return NIX_ERR_INVALID_RANGE;
+
+	req = mbox_alloc_msg_nix_bandprof_free(mbox);
+	if (req == NULL)
+		return -ENOSPC;
+
+	for (i = 0; i < num_prof; i++) {
+		level = sw_to_hw_lvl_map[profs[i].level];
+		req->prof_count[level] = profs[i].count;
+		for (j = 0; j < profs[i].count; j++)
+			req->prof_idx[level][j] = profs[i].ids[j];
+	}
+
+	return mbox_process(mbox);
+}
+
+int
+roc_nix_bpf_free_all(struct roc_nix *roc_nix)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_free_req *req;
+
+	req = mbox_alloc_msg_nix_bandprof_free(mbox);
+	if (req == NULL)
+		return -ENOSPC;
+
+	req->free_all = true;
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 81e76919b5..c45d524d65 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -79,6 +79,8 @@ INTERNAL {
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_free;
+	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 06/27] common/cnxk: support RoC API to configure bandwidth profile
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (3 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 05/27] common/cnxk: support RoC API to free " skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 07/27] common/cnxk: support RoC API to toggle profile state skori
                     ` (22 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to configure HW bandwidth profile for
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/hw/nix.h      |  49 +++++++
 drivers/common/cnxk/roc_nix.h     |  60 ++++++++
 drivers/common/cnxk/roc_nix_bpf.c | 233 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 4 files changed, 343 insertions(+)

diff --git a/drivers/common/cnxk/hw/nix.h b/drivers/common/cnxk/hw/nix.h
index 53cdfbb142..2c1487a105 100644
--- a/drivers/common/cnxk/hw/nix.h
+++ b/drivers/common/cnxk/hw/nix.h
@@ -2112,6 +2112,55 @@ struct nix_lso_format {
 #define NIX_RPM_MAX_HW_FRS  16380UL
 #define NIX_MIN_HW_FRS	    60UL
 
+/** NIX policer rate limits */
+#define NIX_BPF_MAX_RATE_DIV_EXP  12
+#define NIX_BPF_MAX_RATE_EXPONENT 0xf
+#define NIX_BPF_MAX_RATE_MANTISSA 0xff
+
+#define NIX_BPF_RATE_CONST 2000000ULL
+
+/* NIX rate calculation in Bits/Sec
+ *	PIR_ADD = ((256 + NIX_*_PIR[RATE_MANTISSA])
+ *		<< NIX_*_PIR[RATE_EXPONENT]) / 256
+ *	PIR = (2E6 * PIR_ADD / (1 << NIX_*_PIR[RATE_DIVIDER_EXPONENT]))
+ *
+ *	CIR_ADD = ((256 + NIX_*_CIR[RATE_MANTISSA])
+ *		<< NIX_*_CIR[RATE_EXPONENT]) / 256
+ *	CIR = (2E6 * CIR_ADD / (CCLK_TICKS << NIX_*_CIR[RATE_DIVIDER_EXPONENT]))
+ */
+#define NIX_BPF_RATE(exponent, mantissa, div_exp)                              \
+	((NIX_BPF_RATE_CONST * ((256 + (mantissa)) << (exponent))) /           \
+	 (((1ull << (div_exp)) * 256)))
+
+/* Meter rate limits in Bits/Sec */
+#define NIX_BPF_RATE_MIN NIX_BPF_RATE(0, 0, NIX_BPF_MAX_RATE_DIV_EXP)
+#define NIX_BPF_RATE_MAX                                                       \
+	NIX_BPF_RATE(NIX_BPF_MAX_RATE_EXPONENT, NIX_BPF_MAX_RATE_MANTISSA, 0)
+
+#define NIX_BPF_DEFAULT_ADJUST_MANTISSA 511
+#define NIX_BPF_DEFAULT_ADJUST_EXPONENT 0
+
+/** NIX burst limits */
+#define NIX_BPF_MAX_BURST_EXPONENT 0xf
+#define NIX_BPF_MAX_BURST_MANTISSA 0xff
+
+/* NIX burst calculation
+ *	PIR_BURST = ((256 + NIX_*_PIR[BURST_MANTISSA])
+ *		<< (NIX_*_PIR[BURST_EXPONENT] + 1))
+ *			/ 256
+ *
+ *	CIR_BURST = ((256 + NIX_*_CIR[BURST_MANTISSA])
+ *		<< (NIX_*_CIR[BURST_EXPONENT] + 1))
+ *			/ 256
+ */
+#define NIX_BPF_BURST(exponent, mantissa)                                      \
+	(((256 + (mantissa)) << ((exponent) + 1)) / 256)
+
+/** Meter burst limits */
+#define NIX_BPF_BURST_MIN NIX_BPF_BURST(0, 0)
+#define NIX_BPF_BURST_MAX                                                      \
+	NIX_BPF_BURST(NIX_BPF_MAX_BURST_EXPONENT, NIX_BPF_MAX_BURST_MANTISSA)
+
 /* NIX rate limits */
 #define NIX_TM_MAX_RATE_DIV_EXP	 12
 #define NIX_TM_MAX_RATE_EXPONENT 0xf
diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index bf451ecdbc..42af66ccde 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -39,6 +39,62 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+enum roc_nix_bpf_color {
+	ROC_NIX_BPF_COLOR_GREEN,
+	ROC_NIX_BPF_COLOR_YELLOW,
+	ROC_NIX_BPF_COLOR_RED,
+	ROC_NIX_BPF_COLOR_MAX
+};
+
+enum roc_nix_bpf_algo {
+	ROC_NIX_BPF_ALGO_NONE,
+	ROC_NIX_BPF_ALGO_2698,
+	ROC_NIX_BPF_ALGO_4115,
+	ROC_NIX_BPF_ALGO_2697
+};
+
+enum roc_nix_bpf_lmode { ROC_NIX_BPF_LMODE_BYTE, ROC_NIX_BPF_LMODE_PACKET };
+
+enum roc_nix_bpf_action {
+	ROC_NIX_BPF_ACTION_PASS,
+	ROC_NIX_BPF_ACTION_DROP,
+	ROC_NIX_BPF_ACTION_RED
+};
+
+struct roc_nix_bpf_cfg {
+	enum roc_nix_bpf_algo alg;
+	enum roc_nix_bpf_lmode lmode;
+	union {
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2697. */
+		struct {
+			uint64_t cir;
+			uint64_t cbs;
+			uint64_t ebs;
+		} algo2697;
+
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2698. */
+		struct {
+			uint64_t cir;
+			uint64_t pir;
+			uint64_t cbs;
+			uint64_t pbs;
+		} algo2698;
+
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_4115. */
+		struct {
+			uint64_t cir;
+			uint64_t eir;
+			uint64_t cbs;
+			uint64_t ebs;
+		} algo4115;
+	};
+
+	enum roc_nix_bpf_action action[ROC_NIX_BPF_COLOR_MAX];
+
+	/* Reserved for future config*/
+	uint32_t rsvd[3];
+};
+
 struct roc_nix_bpf_objs {
 	uint16_t level;
 	uint16_t count;
@@ -499,6 +555,10 @@ int __roc_api roc_nix_bpf_free(struct roc_nix *roc_nix,
 
 int __roc_api roc_nix_bpf_free_all(struct roc_nix *roc_nix);
 
+int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+				 enum roc_nix_bpf_level_flag lvl_flag,
+				 struct roc_nix_bpf_cfg *cfg);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 41d31bc6cd..37631c134c 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -26,6 +26,105 @@ get_mbox(struct roc_nix *roc_nix)
 	return dev->mbox;
 }
 
+static inline uint64_t
+meter_rate_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p,
+		  uint64_t *div_exp_p)
+{
+	uint64_t div_exp, exponent, mantissa;
+
+	/* Boundary checks */
+	if (value < NIX_BPF_RATE_MIN || value > NIX_BPF_RATE_MAX)
+		return 0;
+
+	if (value <= NIX_BPF_RATE(0, 0, 0)) {
+		/* Calculate rate div_exp and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * (256 + mantissa)
+		 *              / ((1 << div_exp) * 256))
+		 */
+		div_exp = 0;
+		exponent = 0;
+		mantissa = NIX_BPF_MAX_RATE_MANTISSA;
+
+		while (value < (NIX_BPF_RATE_CONST / (1 << div_exp)))
+			div_exp += 1;
+
+		while (value < ((NIX_BPF_RATE_CONST * (256 + mantissa)) /
+				((1 << div_exp) * 256)))
+			mantissa -= 1;
+	} else {
+		/* Calculate rate exponent and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * ((256 + mantissa) << exponent)) / 256
+		 *
+		 */
+		div_exp = 0;
+		exponent = NIX_BPF_MAX_RATE_EXPONENT;
+		mantissa = NIX_BPF_MAX_RATE_MANTISSA;
+
+		while (value < (NIX_BPF_RATE_CONST * (1 << exponent)))
+			exponent -= 1;
+
+		while (value <
+		       ((NIX_BPF_RATE_CONST * ((256 + mantissa) << exponent)) /
+			256))
+			mantissa -= 1;
+	}
+
+	if (div_exp > NIX_BPF_MAX_RATE_DIV_EXP ||
+	    exponent > NIX_BPF_MAX_RATE_EXPONENT ||
+	    mantissa > NIX_BPF_MAX_RATE_MANTISSA)
+		return 0;
+
+	if (div_exp_p)
+		*div_exp_p = div_exp;
+	if (exponent_p)
+		*exponent_p = exponent;
+	if (mantissa_p)
+		*mantissa_p = mantissa;
+
+	/* Calculate real rate value */
+	return NIX_BPF_RATE(exponent, mantissa, div_exp);
+}
+
+static inline uint64_t
+meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
+{
+	uint64_t exponent, mantissa;
+
+	if (value < NIX_BPF_BURST_MIN || value > NIX_BPF_BURST_MAX)
+		return 0;
+
+	/* Calculate burst exponent and mantissa using
+	 * the following formula:
+	 *
+	 * value = (((256 + mantissa) << (exponent + 1)
+	 / 256)
+	 *
+	 */
+	exponent = NIX_BPF_MAX_BURST_EXPONENT;
+	mantissa = NIX_BPF_MAX_BURST_MANTISSA;
+
+	while (value < (1ull << (exponent + 1)))
+		exponent -= 1;
+
+	while (value < ((256 + mantissa) << (exponent + 1)) / 256)
+		mantissa -= 1;
+
+	if (exponent > NIX_BPF_MAX_BURST_EXPONENT ||
+	    mantissa > NIX_BPF_MAX_BURST_MANTISSA)
+		return 0;
+
+	if (exponent_p)
+		*exponent_p = exponent;
+	if (mantissa_p)
+		*mantissa_p = mantissa;
+
+	return NIX_BPF_BURST(exponent, mantissa);
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -210,3 +309,137 @@ roc_nix_bpf_free_all(struct roc_nix *roc_nix)
 	req->free_all = true;
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+		   enum roc_nix_bpf_level_flag lvl_flag,
+		   struct roc_nix_bpf_cfg *cfg)
+{
+	uint64_t exponent_p = 0, mantissa_p = 0, div_exp_p = 0;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!cfg)
+		return NIX_ERR_PARAM;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	aq->prof.adjust_exponent = NIX_BPF_DEFAULT_ADJUST_EXPONENT;
+	aq->prof.adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA;
+	if (cfg->lmode == ROC_NIX_BPF_LMODE_BYTE)
+		aq->prof.adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA / 2;
+
+	aq->prof_mask.adjust_exponent = ~(aq->prof_mask.adjust_exponent);
+	aq->prof_mask.adjust_mantissa = ~(aq->prof_mask.adjust_mantissa);
+
+	switch (cfg->alg) {
+	case ROC_NIX_BPF_ALGO_2697:
+		meter_rate_to_nix(cfg->algo2697.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2697.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2697.ebs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	case ROC_NIX_BPF_ALGO_2698:
+		meter_rate_to_nix(cfg->algo2698.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_rate_to_nix(cfg->algo2698.pir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.peir_mantissa = mantissa_p;
+		aq->prof.peir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2698.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2698.pbs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	case ROC_NIX_BPF_ALGO_4115:
+		meter_rate_to_nix(cfg->algo4115.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_rate_to_nix(cfg->algo4115.eir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.peir_mantissa = mantissa_p;
+		aq->prof.peir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo4115.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo4115.ebs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	default:
+		return NIX_ERR_PARAM;
+	}
+
+	aq->prof.lmode = cfg->lmode;
+	aq->prof.gc_action = cfg->action[ROC_NIX_BPF_COLOR_GREEN];
+	aq->prof.yc_action = cfg->action[ROC_NIX_BPF_COLOR_YELLOW];
+	aq->prof.rc_action = cfg->action[ROC_NIX_BPF_COLOR_RED];
+
+	aq->prof_mask.lmode = ~(aq->prof_mask.lmode);
+	aq->prof_mask.gc_action = ~(aq->prof_mask.gc_action);
+	aq->prof_mask.yc_action = ~(aq->prof_mask.yc_action);
+	aq->prof_mask.rc_action = ~(aq->prof_mask.rc_action);
+
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index c45d524d65..6a009eaf35 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -78,6 +78,7 @@ INTERNAL {
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
+	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 07/27] common/cnxk: support RoC API to toggle profile state
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (4 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 06/27] common/cnxk: support RoC API to configure bandwidth profile skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 08/27] common/cnxk: support RoC API to dump bandwidth profile skori
                     ` (21 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to enable or disable HW bandwidth profiles
on CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  4 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 39 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 44 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 42af66ccde..2576e938be 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -214,6 +214,7 @@ struct roc_nix_stats_queue {
 struct roc_nix_rq {
 	/* Input parameters */
 	uint16_t qid;
+	uint16_t bpf_id;
 	uint64_t aura_handle;
 	bool ipsech_ena;
 	uint16_t first_skip;
@@ -559,6 +560,9 @@ int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 				 enum roc_nix_bpf_level_flag lvl_flag,
 				 struct roc_nix_bpf_cfg *cfg);
 
+int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
+				  struct roc_nix_rq *rq, bool enable);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 37631c134c..557b6279e6 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -443,3 +443,42 @@ roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id, struct roc_nix_rq *rq,
+		    bool enable)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (rq->qid >= nix->nb_rx_queues)
+		return NIX_ERR_QUEUE_INVALID_RANGE;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = rq->qid;
+	aq->ctype = NIX_AQ_CTYPE_RQ;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	aq->rq.policer_ena = enable;
+	aq->rq_mask.policer_ena = ~(aq->rq_mask.policer_ena);
+	if (enable) {
+		aq->rq.band_prof_id = id;
+		aq->rq_mask.band_prof_id = ~(aq->rq_mask.band_prof_id);
+	}
+
+	rc = mbox_process(mbox);
+	if (rc)
+		goto exit;
+
+	rq->bpf_id = id;
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 6a009eaf35..4c5adb8212 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -80,6 +80,7 @@ INTERNAL {
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_ena_dis;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 08/27] common/cnxk: support RoC API to dump bandwidth profile
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (5 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 07/27] common/cnxk: support RoC API to toggle profile state skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 09/27] common/cnxk: support RoC API to setup precolor table skori
                     ` (20 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to dump bandwidth profile on CN10K
platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h      |  3 ++
 drivers/common/cnxk/roc_nix_bpf.c  | 86 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_platform.h |  1 +
 drivers/common/cnxk/version.map    |  1 +
 4 files changed, 91 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 2576e938be..15df1e593f 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -563,6 +563,9 @@ int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
 				  struct roc_nix_rq *rq, bool enable);
 
+int __roc_api roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
+			       enum roc_nix_bpf_level_flag lvl_flag);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 557b6279e6..970c960186 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -125,6 +125,60 @@ meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
 	return NIX_BPF_BURST(exponent, mantissa);
 }
 
+static inline void
+nix_lf_bpf_dump(__io struct nix_band_prof_s *bpf)
+{
+	plt_dump("W0: cir_mantissa  \t\t\t%d\nW0: pebs_mantissa \t\t\t0x%03x",
+		 bpf->cir_mantissa, bpf->pebs_mantissa);
+	plt_dump("W0: peir_matissa \t\t\t\t%d\nW0: cbs_exponent \t\t\t%d",
+		 bpf->peir_mantissa, bpf->cbs_exponent);
+	plt_dump("W0: cir_exponent \t\t\t%d\nW0: pebs_exponent \t\t\t%d",
+		 bpf->cir_exponent, bpf->pebs_exponent);
+	plt_dump("W0: peir_exponent \t\t\t%d\n", bpf->peir_exponent);
+	plt_dump("W0: tnl_ena \t\t\t%d\n", bpf->tnl_ena);
+	plt_dump("W0: icolor \t\t\t%d\n", bpf->icolor);
+	plt_dump("W0: pc_mode \t\t\t%d\n", bpf->pc_mode);
+	plt_dump("W1: hl_en \t\t%d\nW1: band_prof_id \t\t%d", bpf->hl_en,
+		 bpf->band_prof_id);
+	plt_dump("W1: meter_algo \t\t%d\nW1: rc_action \t\t%d", bpf->meter_algo,
+		 bpf->rc_action);
+	plt_dump("W1: yc_action \t\t\t%d\nW1: gc_action \t\t\t%d",
+		 bpf->yc_action, bpf->gc_action);
+	plt_dump("W1: adjust_mantissa\t\t\t%d\nW1: adjust_exponent \t\t\t%d",
+		 bpf->adjust_mantissa, bpf->adjust_exponent);
+	plt_dump("W1: rdiv \t\t\t%d\n", bpf->rdiv);
+	plt_dump("W1: l_select \t\t%d\nW2: lmode \t\t%d", bpf->l_sellect,
+		 bpf->lmode);
+	plt_dump("W1: cbs_mantissa \t\t\t%d\n", bpf->cbs_mantissa);
+	plt_dump("W2: tsa \t\t\t0x%" PRIx64 "\n", (uint64_t)bpf->ts);
+	plt_dump("W3: c_accum \t\t%d\nW3: pe_accum \t\t%d", bpf->c_accum,
+		 bpf->pe_accum);
+	plt_dump("W4: green_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_pkt_pass);
+	plt_dump("W5: yellow_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_pkt_pass);
+	plt_dump("W6: red_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_pkt_pass);
+	plt_dump("W7: green_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_octs_pass);
+	plt_dump("W8: yellow_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_octs_pass);
+	plt_dump("W9: red_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_octs_pass);
+	plt_dump("W10: green_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_pkt_drop);
+	plt_dump("W11: yellow_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_pkt_drop);
+	plt_dump("W12: red_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_pkt_drop);
+	plt_dump("W13: green_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_octs_drop);
+	plt_dump("W14: yellow_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_octs_drop);
+	plt_dump("W15: red_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_octs_drop);
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -482,3 +536,35 @@ roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id, struct roc_nix_rq *rq,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
+		 enum roc_nix_bpf_level_flag lvl_flag)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_rsp *rsp;
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_READ;
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (!rc) {
+		plt_dump("============= band prof id =%d ===============", id);
+		nix_lf_bpf_dump(&rsp->prof);
+	}
+
+	return rc;
+}
diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h
index 285b24b82d..69b7c49d8b 100644
--- a/drivers/common/cnxk/roc_platform.h
+++ b/drivers/common/cnxk/roc_platform.h
@@ -155,6 +155,7 @@ extern int cnxk_logtype_tm;
 #define plt_info(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
 #define plt_warn(fmt, args...) RTE_LOG(WARNING, PMD, fmt "\n", ##args)
 #define plt_print(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
+#define plt_dump(fmt, ...)      fprintf(stderr, fmt "\n", ##__VA_ARGS__)
 
 /**
  * Log debug message if given subsystem logging is enabled.
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 4c5adb8212..97386ef273 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -80,6 +80,7 @@ INTERNAL {
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_dump;
 	roc_nix_bpf_ena_dis;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 09/27] common/cnxk: support RoC API to setup precolor table
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (6 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 08/27] common/cnxk: support RoC API to dump bandwidth profile skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 10/27] common/cnxk: support RoC API to connect bandwidth profiles skori
                     ` (19 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

For initial coloring of input packet, CN10K platform maintains
precolor table for VLAN, DSCP and Generic. Implement RoC
interface to setup pre color table.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  20 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 193 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 3 files changed, 214 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 15df1e593f..6d17d46388 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -39,6 +39,15 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+enum roc_nix_bpf_pc_mode {
+	ROC_NIX_BPF_PC_MODE_VLAN_INNER,
+	ROC_NIX_BPF_PC_MODE_VLAN_OUTER,
+	ROC_NIX_BPF_PC_MODE_DSCP_INNER,
+	ROC_NIX_BPF_PC_MODE_DSCP_OUTER,
+	ROC_NIX_BPF_PC_MODE_GEN_INNER,
+	ROC_NIX_BPF_PC_MODE_GEN_OUTER
+};
+
 enum roc_nix_bpf_color {
 	ROC_NIX_BPF_COLOR_GREEN,
 	ROC_NIX_BPF_COLOR_YELLOW,
@@ -101,6 +110,13 @@ struct roc_nix_bpf_objs {
 	uint16_t ids[ROC_NIX_BPF_PER_PFFUNC];
 };
 
+struct roc_nix_bpf_precolor {
+#define ROC_NIX_BPF_PRE_COLOR_MAX 64
+	uint8_t count;
+	enum roc_nix_bpf_pc_mode mode;
+	enum roc_nix_bpf_color color[ROC_NIX_BPF_PRE_COLOR_MAX];
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -566,6 +582,10 @@ int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
 int __roc_api roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
 			       enum roc_nix_bpf_level_flag lvl_flag);
 
+int __roc_api roc_nix_bpf_pre_color_tbl_setup(
+	struct roc_nix *roc_nix, uint16_t id,
+	enum roc_nix_bpf_level_flag lvl_flag, struct roc_nix_bpf_precolor *tbl);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 970c960186..b5a1c484a9 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -9,6 +9,10 @@
 #define NIX_MAX_BPF_COUNT_MID_LAYER  8
 #define NIX_MAX_BPF_COUNT_TOP_LAYER  1
 
+#define NIX_BPF_PRECOLOR_GEN_TABLE_SIZE	 16
+#define NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE 16
+#define NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE 64
+
 #define NIX_BPF_LEVEL_F_MASK                                                   \
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
@@ -179,6 +183,107 @@ nix_lf_bpf_dump(__io struct nix_band_prof_s *bpf)
 		 (uint64_t)bpf->red_octs_drop);
 }
 
+static inline void
+nix_precolor_conv_table_write(struct roc_nix *roc_nix, uint64_t val,
+			      uint32_t off)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	int64_t *addr;
+
+	addr = PLT_PTR_ADD(nix->base, off);
+	/* FIXME: Currently writing to this register throwing kernel dump.
+	 * plt_write64(val, addr);
+	 */
+	PLT_SET_USED(val);
+	PLT_SET_USED(addr);
+}
+
+static uint8_t
+nix_precolor_vlan_table_update(struct roc_nix *roc_nix,
+			       struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val = 0, i;
+	uint8_t tn_ena;
+	uint32_t off;
+
+	for (i = 0; i < tbl->count; i++)
+		val |= (((uint64_t)tbl->color[i]) << (2 * i));
+
+	if (tbl->mode == ROC_NIX_BPF_PC_MODE_VLAN_INNER) {
+		off = NIX_LF_RX_VLAN1_COLOR_CONV;
+		tn_ena = true;
+	} else {
+		off = NIX_LF_RX_VLAN0_COLOR_CONV;
+		tn_ena = false;
+	}
+
+	nix_precolor_conv_table_write(roc_nix, val, off);
+	return tn_ena;
+}
+
+static uint8_t
+nix_precolor_inner_dscp_table_update(struct roc_nix *roc_nix,
+				     struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val_lo = 0, val_hi = 0, i, j;
+
+	for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
+		val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	for (j = 0; i < tbl->count; i++, j++)
+		val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	nix_precolor_conv_table_write(roc_nix, val_lo,
+				      NIX_LF_RX_IIP_COLOR_CONV_LO);
+	nix_precolor_conv_table_write(roc_nix, val_hi,
+				      NIX_LF_RX_IIP_COLOR_CONV_HI);
+
+	return true;
+}
+
+static uint8_t
+nix_precolor_outer_dscp_table_update(struct roc_nix *roc_nix,
+				     struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val_lo = 0, val_hi = 0, i, j;
+
+	for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
+		val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	for (j = 0; i < tbl->count; i++, j++)
+		val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	nix_precolor_conv_table_write(roc_nix, val_lo,
+				      NIX_LF_RX_OIP_COLOR_CONV_LO);
+	nix_precolor_conv_table_write(roc_nix, val_hi,
+				      NIX_LF_RX_OIP_COLOR_CONV_HI);
+
+	return false;
+}
+
+static uint8_t
+nix_precolor_gen_table_update(struct roc_nix *roc_nix,
+			      struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val = 0, i;
+	uint8_t tn_ena;
+	uint32_t off;
+
+	for (i = 0; i < tbl->count; i++)
+		val |= (((uint64_t)tbl->color[i]) << (2 * i));
+
+	if (tbl->mode == ROC_NIX_BPF_PC_MODE_GEN_INNER) {
+		off = NIX_LF_RX_GEN_COLOR_CONVX(1);
+		tn_ena = true;
+	} else {
+		off = NIX_LF_RX_GEN_COLOR_CONVX(0);
+		tn_ena = false;
+	}
+
+	nix_precolor_conv_table_write(roc_nix, val, off);
+	return tn_ena;
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -568,3 +673,91 @@ roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
 
 	return rc;
 }
+
+int
+roc_nix_bpf_pre_color_tbl_setup(struct roc_nix *roc_nix, uint16_t id,
+				enum roc_nix_bpf_level_flag lvl_flag,
+				struct roc_nix_bpf_precolor *tbl)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t pc_mode, tn_ena;
+	uint8_t level_idx;
+	int rc;
+
+	if (!tbl || !tbl->count)
+		return NIX_ERR_PARAM;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	switch (tbl->mode) {
+	case ROC_NIX_BPF_PC_MODE_VLAN_INNER:
+	case ROC_NIX_BPF_PC_MODE_VLAN_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_vlan_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_VLAN;
+		break;
+	case ROC_NIX_BPF_PC_MODE_DSCP_INNER:
+		if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_inner_dscp_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
+		break;
+	case ROC_NIX_BPF_PC_MODE_DSCP_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_outer_dscp_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
+		break;
+	case ROC_NIX_BPF_PC_MODE_GEN_INNER:
+	case ROC_NIX_BPF_PC_MODE_GEN_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_GEN_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_GEN_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+
+		tn_ena = nix_precolor_gen_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_GEN;
+		break;
+	default:
+		rc = NIX_ERR_PARAM;
+		goto exit;
+	}
+
+	/* Update corresponding bandwidth profile too */
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+	aq->prof.pc_mode = pc_mode;
+	aq->prof.tnl_ena = tn_ena;
+	aq->prof_mask.pc_mode = ~(aq->prof_mask.pc_mode);
+	aq->prof_mask.tnl_ena = ~(aq->prof_mask.tnl_ena);
+
+	return mbox_process(mbox);
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 97386ef273..a08fbe6013 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -85,6 +85,7 @@ INTERNAL {
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
+	roc_nix_bpf_pre_color_tbl_setup;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 10/27] common/cnxk: support RoC API to connect bandwidth profiles
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (7 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 09/27] common/cnxk: support RoC API to setup precolor table skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 11/27] common/cnxk: support RoC API to get stats to index skori
                     ` (18 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

To maintain chain of bandwidth profiles, they needs to be
connected. Implement RoC API to connect two bandwidth profiles
at different levels.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  6 ++++++
 drivers/common/cnxk/roc_nix_bpf.c | 36 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 43 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 6d17d46388..af76068030 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -7,6 +7,7 @@
 
 /* Constants */
 #define ROC_NIX_BPF_PER_PFFUNC	      64
+#define ROC_NIX_BPF_ID_INVALID	      0xFFFF
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
 
@@ -586,6 +587,11 @@ int __roc_api roc_nix_bpf_pre_color_tbl_setup(
 	struct roc_nix *roc_nix, uint16_t id,
 	enum roc_nix_bpf_level_flag lvl_flag, struct roc_nix_bpf_precolor *tbl);
 
+/* Use ROC_NIX_BPF_ID_INVALID as dst_id to disconnect */
+int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
+				  enum roc_nix_bpf_level_flag lvl_flag,
+				  uint16_t src_id, uint16_t dst_id);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index b5a1c484a9..f5822136d1 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -761,3 +761,39 @@ roc_nix_bpf_pre_color_tbl_setup(struct roc_nix *roc_nix, uint16_t id,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_connect(struct roc_nix *roc_nix,
+		    enum roc_nix_bpf_level_flag lvl_flag, uint16_t src_id,
+		    uint16_t dst_id)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | src_id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	if (dst_id == ROC_NIX_BPF_ID_INVALID) {
+		aq->prof.hl_en = false;
+		aq->prof_mask.hl_en = ~(aq->prof_mask.hl_en);
+	} else {
+		aq->prof.hl_en = true;
+		aq->prof.band_prof_id = dst_id;
+		aq->prof_mask.hl_en = ~(aq->prof_mask.hl_en);
+		aq->prof_mask.band_prof_id = ~(aq->prof_mask.band_prof_id);
+	}
+
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index a08fbe6013..c04a8ca9da 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -79,6 +79,7 @@ INTERNAL {
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
+	roc_nix_bpf_connect;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_dump;
 	roc_nix_bpf_ena_dis;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 11/27] common/cnxk: support RoC API to get stats to index
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (8 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 10/27] common/cnxk: support RoC API to connect bandwidth profiles skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 12/27] common/cnxk: support RoC API to read profile statistics skori
                     ` (17 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform supports different stats for HW bandwidth profiles.
Implement RoC API to get index for given stats type.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     | 18 ++++++++++++++++
 drivers/common/cnxk/roc_nix_bpf.c | 34 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 53 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index af76068030..7bff69d39f 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -10,6 +10,7 @@
 #define ROC_NIX_BPF_ID_INVALID	      0xFFFF
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
+#define ROC_NIX_BPF_STATS_MAX	      12
 
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
@@ -71,6 +72,21 @@ enum roc_nix_bpf_action {
 	ROC_NIX_BPF_ACTION_RED
 };
 
+enum roc_nix_bpf_stats {
+	ROC_NIX_BPF_GREEN_PKT_F_PASS = BIT_ULL(0),
+	ROC_NIX_BPF_GREEN_OCTS_F_PASS = BIT_ULL(1),
+	ROC_NIX_BPF_GREEN_PKT_F_DROP = BIT_ULL(2),
+	ROC_NIX_BPF_GREEN_OCTS_F_DROP = BIT_ULL(3),
+	ROC_NIX_BPF_YELLOW_PKT_F_PASS = BIT_ULL(4),
+	ROC_NIX_BPF_YELLOW_OCTS_F_PASS = BIT_ULL(5),
+	ROC_NIX_BPF_YELLOW_PKT_F_DROP = BIT_ULL(6),
+	ROC_NIX_BPF_YELLOW_OCTS_F_DROP = BIT_ULL(7),
+	ROC_NIX_BPF_RED_PKT_F_PASS = BIT_ULL(8),
+	ROC_NIX_BPF_RED_OCTS_F_PASS = BIT_ULL(9),
+	ROC_NIX_BPF_RED_PKT_F_DROP = BIT_ULL(10),
+	ROC_NIX_BPF_RED_OCTS_F_DROP = BIT_ULL(11),
+};
+
 struct roc_nix_bpf_cfg {
 	enum roc_nix_bpf_algo alg;
 	enum roc_nix_bpf_lmode lmode;
@@ -595,6 +611,8 @@ int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
+uint8_t __roc_api roc_nix_bpf_stats_to_idx(enum roc_nix_bpf_stats lvl_flag);
+
 /* MAC */
 int __roc_api roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start);
 int __roc_api roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix,
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index f5822136d1..8f45650d18 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -300,6 +300,40 @@ roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 	return idx;
 }
 
+uint8_t
+roc_nix_bpf_stats_to_idx(enum roc_nix_bpf_stats level_f)
+{
+	uint8_t idx;
+
+	if (level_f & ROC_NIX_BPF_GREEN_PKT_F_PASS)
+		idx = 0;
+	else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
+		idx = 1;
+	else if (level_f & ROC_NIX_BPF_GREEN_PKT_F_DROP)
+		idx = 2;
+	else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
+		idx = 3;
+	else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
+		idx = 4;
+	else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
+		idx = 5;
+	else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
+		idx = 6;
+	else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
+		idx = 7;
+	else if (level_f & ROC_NIX_BPF_RED_PKT_F_PASS)
+		idx = 8;
+	else if (level_f & ROC_NIX_BPF_RED_OCTS_F_PASS)
+		idx = 9;
+	else if (level_f & ROC_NIX_BPF_RED_PKT_F_DROP)
+		idx = 10;
+	else if (level_f & ROC_NIX_BPF_RED_OCTS_F_DROP)
+		idx = 11;
+	else
+		idx = ROC_NIX_BPF_STATS_MAX;
+	return idx;
+}
+
 int
 roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index c04a8ca9da..5d4bdd57a9 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -87,6 +87,7 @@ INTERNAL {
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_bpf_pre_color_tbl_setup;
+	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 12/27] common/cnxk: support RoC API to read profile statistics
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (9 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 11/27] common/cnxk: support RoC API to get stats to index skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 13/27] common/cnxk: support RoC API to reset profile stats skori
                     ` (16 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform provides statistics per bandwidth profile and
per nixlf. Implement RoC API to read stats for given bandwidth
profile.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |   9 ++
 drivers/common/cnxk/roc_nix_bpf.c | 197 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   2 +
 3 files changed, 208 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 7bff69d39f..0081ccc9ee 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -608,6 +608,15 @@ int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
 				  enum roc_nix_bpf_level_flag lvl_flag,
 				  uint16_t src_id, uint16_t dst_id);
 
+int __roc_api
+roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+		       enum roc_nix_bpf_level_flag lvl_flag,
+		       uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
+
+int __roc_api
+roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
+			  uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 8f45650d18..2169164d9c 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -17,6 +17,9 @@
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
 
+#define NIX_RD_STATS(val)  plt_read64(nix->base + NIX_LF_RX_STATX(val))
+#define NIX_RST_STATS(val) plt_write64(0, nix->base + NIX_LF_RX_STATX(val))
+
 static uint8_t sw_to_hw_lvl_map[] = {NIX_RX_BAND_PROF_LAYER_LEAF,
 				     NIX_RX_BAND_PROF_LAYER_MIDDLE,
 				     NIX_RX_BAND_PROF_LAYER_TOP};
@@ -831,3 +834,197 @@ roc_nix_bpf_connect(struct roc_nix *roc_nix,
 
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+		       enum roc_nix_bpf_level_flag lvl_flag,
+		       uint64_t stats[ROC_NIX_BPF_STATS_MAX])
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_rsp *rsp;
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_READ;
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		return rc;
+
+	green_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[green_pkt_pass] = rsp->prof.green_pkt_pass;
+
+	if (green_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[green_octs_pass] = rsp->prof.green_octs_pass;
+
+	if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[green_pkt_drop] = rsp->prof.green_pkt_drop;
+
+	if (green_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[green_octs_drop] = rsp->prof.green_octs_pass;
+
+	if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_pkt_pass] = rsp->prof.yellow_pkt_pass;
+
+	if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_octs_pass] = rsp->prof.yellow_octs_pass;
+
+	if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_pkt_drop] = rsp->prof.yellow_pkt_drop;
+
+	if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_octs_drop] = rsp->prof.yellow_octs_drop;
+
+	if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[red_pkt_pass] = rsp->prof.red_pkt_pass;
+
+	if (red_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[red_octs_pass] = rsp->prof.red_octs_pass;
+
+	if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[red_pkt_drop] = rsp->prof.red_pkt_drop;
+
+	if (red_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[red_octs_drop] = rsp->prof.red_octs_drop;
+
+	return 0;
+}
+
+int
+roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
+			  uint64_t stats[ROC_NIX_BPF_STATS_MAX])
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+
+	green_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_PASSED);
+	}
+
+	if (green_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_PASSED);
+	}
+
+	if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_DROP);
+	}
+
+	if (green_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_DROP);
+	}
+
+	if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_PASSED);
+	}
+
+	if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_PASSED);
+	}
+
+	if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_DROP);
+	}
+
+	if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_DROP);
+	}
+
+	if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_PASSED);
+	}
+
+	if (red_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_PASSED);
+	}
+
+	if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_DROP);
+	}
+
+	if (red_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_DROP);
+	}
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 5d4bdd57a9..52e7fa1e89 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -86,7 +86,9 @@ INTERNAL {
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
+	roc_nix_bpf_lf_stats_read;
 	roc_nix_bpf_pre_color_tbl_setup;
+	roc_nix_bpf_stats_read;
 	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 13/27] common/cnxk: support RoC API to reset profile stats
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (10 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 12/27] common/cnxk: support RoC API to read profile statistics skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 14/27] common/cnxk: support meter in action list skori
                     ` (15 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to reset stats per bandwidth profile
or per nixlf.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |   7 ++
 drivers/common/cnxk/roc_nix_bpf.c | 113 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   2 +
 3 files changed, 122 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 0081ccc9ee..b6715ef2ed 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -613,10 +613,17 @@ roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
 		       enum roc_nix_bpf_level_flag lvl_flag,
 		       uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_stats_reset(struct roc_nix *roc_nix, uint16_t id,
+				      uint64_t mask,
+				      enum roc_nix_bpf_level_flag lvl_flag);
+
 int __roc_api
 roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 			  uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_lf_stats_reset(struct roc_nix *roc_nix,
+					 uint64_t mask);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 2169164d9c..bba906a59b 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -931,6 +931,86 @@ roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
 	return 0;
 }
 
+int
+roc_nix_bpf_stats_reset(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+			enum roc_nix_bpf_level_flag lvl_flag)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS) {
+		aq->prof.green_pkt_pass = 0;
+		aq->prof_mask.green_pkt_pass = ~(aq->prof_mask.green_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS) {
+		aq->prof.green_octs_pass = 0;
+		aq->prof_mask.green_octs_pass =
+			~(aq->prof_mask.green_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP) {
+		aq->prof.green_pkt_drop = 0;
+		aq->prof_mask.green_pkt_drop = ~(aq->prof_mask.green_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP) {
+		aq->prof.green_octs_drop = 0;
+		aq->prof_mask.green_octs_drop =
+			~(aq->prof_mask.green_octs_drop);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS) {
+		aq->prof.yellow_pkt_pass = 0;
+		aq->prof_mask.yellow_pkt_pass =
+			~(aq->prof_mask.yellow_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS) {
+		aq->prof.yellow_octs_pass = 0;
+		aq->prof_mask.yellow_octs_pass =
+			~(aq->prof_mask.yellow_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP) {
+		aq->prof.yellow_pkt_drop = 0;
+		aq->prof_mask.yellow_pkt_drop =
+			~(aq->prof_mask.yellow_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP) {
+		aq->prof.yellow_octs_drop = 0;
+		aq->prof_mask.yellow_octs_drop =
+			~(aq->prof_mask.yellow_octs_drop);
+	}
+	if (mask & ROC_NIX_BPF_RED_PKT_F_PASS) {
+		aq->prof.red_pkt_pass = 0;
+		aq->prof_mask.red_pkt_pass = ~(aq->prof_mask.red_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS) {
+		aq->prof.red_octs_pass = 0;
+		aq->prof_mask.red_octs_pass = ~(aq->prof_mask.red_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_RED_PKT_F_DROP) {
+		aq->prof.red_pkt_drop = 0;
+		aq->prof_mask.red_pkt_drop = ~(aq->prof_mask.red_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP) {
+		aq->prof.red_octs_drop = 0;
+		aq->prof_mask.red_octs_drop = ~(aq->prof_mask.red_octs_drop);
+	}
+
+	return mbox_process(mbox);
+}
+
 int
 roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 			  uint64_t stats[ROC_NIX_BPF_STATS_MAX])
@@ -1028,3 +1108,36 @@ roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 
 	return 0;
 }
+
+int
+roc_nix_bpf_lf_stats_reset(struct roc_nix *roc_nix, uint64_t mask)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	if (mask & ROC_NIX_BPF_RED_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_RED_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 52e7fa1e89..3b08fb0025 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -87,8 +87,10 @@ INTERNAL {
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_bpf_lf_stats_read;
+	roc_nix_bpf_lf_stats_reset;
 	roc_nix_bpf_pre_color_tbl_setup;
 	roc_nix_bpf_stats_read;
+	roc_nix_bpf_stats_reset;
 	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 14/27] common/cnxk: support meter in action list
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (11 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 13/27] common/cnxk: support RoC API to reset profile stats skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 15/27] net/cnxk: support meter ops get API skori
                     ` (14 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao; +Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Meter action is added in supported action list.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_npc.c | 3 +++
 drivers/common/cnxk/roc_npc.h | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/common/cnxk/roc_npc.c b/drivers/common/cnxk/roc_npc.c
index 52a54b3990..8f88e254b3 100644
--- a/drivers/common/cnxk/roc_npc.c
+++ b/drivers/common/cnxk/roc_npc.c
@@ -447,6 +447,9 @@ npc_parse_actions(struct npc *npc, const struct roc_npc_attr *attr,
 		case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
 			req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
 			break;
+		case ROC_NPC_ACTION_TYPE_METER:
+			req_act |= ROC_NPC_ACTION_TYPE_METER;
+			break;
 		default:
 			errcode = NPC_ERR_ACTION_NOTSUP;
 			goto err_exit;
diff --git a/drivers/common/cnxk/roc_npc.h b/drivers/common/cnxk/roc_npc.h
index 4d6f8f8cd9..86365df754 100644
--- a/drivers/common/cnxk/roc_npc.h
+++ b/drivers/common/cnxk/roc_npc.h
@@ -58,7 +58,7 @@ struct roc_npc_flow_item_raw {
 	const uint8_t *pattern; /**< Byte string to look for. */
 };
 
-#define ROC_NPC_MAX_ACTION_COUNT 12
+#define ROC_NPC_MAX_ACTION_COUNT 17
 
 enum roc_npc_action_type {
 	ROC_NPC_ACTION_TYPE_END = (1 << 0),
@@ -77,6 +77,7 @@ enum roc_npc_action_type {
 	ROC_NPC_ACTION_TYPE_VLAN_INSERT = (1 << 13),
 	ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT = (1 << 14),
 	ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT = (1 << 15),
+	ROC_NPC_ACTION_TYPE_METER = (1 << 16),
 };
 
 struct roc_npc_action {
@@ -110,6 +111,10 @@ struct roc_npc_action_of_set_vlan_pcp {
 	uint8_t vlan_pcp; /**< VLAN priority. */
 };
 
+struct roc_npc_action_meter {
+	uint32_t mtr_id; /**< Meter id to be applied. > */
+};
+
 struct roc_npc_attr {
 	uint32_t priority;	/**< Rule priority level within group. */
 	uint32_t ingress : 1;	/**< Rule applies to ingress traffic. */
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 15/27] net/cnxk: support meter ops get API
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (12 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 14/27] common/cnxk: support meter in action list skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 16/27] net/cnxk: support ops to get meter capabilities skori
                     ` (13 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

To enable support for ingress meter, supported operations
are exposed for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev.c     |  1 +
 drivers/net/cnxk/cn10k_ethdev.h     |  2 ++
 drivers/net/cnxk/cn10k_ethdev_mtr.c | 18 ++++++++++++++++++
 drivers/net/cnxk/meson.build        |  1 +
 4 files changed, 22 insertions(+)
 create mode 100644 drivers/net/cnxk/cn10k_ethdev_mtr.c

diff --git a/drivers/net/cnxk/cn10k_ethdev.c b/drivers/net/cnxk/cn10k_ethdev.c
index 7caec6cf14..8c1f6a4408 100644
--- a/drivers/net/cnxk/cn10k_ethdev.c
+++ b/drivers/net/cnxk/cn10k_ethdev.c
@@ -457,6 +457,7 @@ nix_eth_dev_ops_override(void)
 	cnxk_eth_dev_ops.dev_ptypes_set = cn10k_nix_ptypes_set;
 	cnxk_eth_dev_ops.timesync_enable = cn10k_nix_timesync_enable;
 	cnxk_eth_dev_ops.timesync_disable = cn10k_nix_timesync_disable;
+	cnxk_eth_dev_ops.mtr_ops_get = cn10k_nix_mtr_ops_get;
 }
 
 static void
diff --git a/drivers/net/cnxk/cn10k_ethdev.h b/drivers/net/cnxk/cn10k_ethdev.h
index 8b6e0f2b3f..117aa2a62d 100644
--- a/drivers/net/cnxk/cn10k_ethdev.h
+++ b/drivers/net/cnxk/cn10k_ethdev.h
@@ -38,4 +38,6 @@ struct cn10k_eth_rxq {
 void cn10k_eth_set_rx_function(struct rte_eth_dev *eth_dev);
 void cn10k_eth_set_tx_function(struct rte_eth_dev *eth_dev);
 
+/* MTR */
+int cn10k_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops);
 #endif /* __CN10K_ETHDEV_H__ */
diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
new file mode 100644
index 0000000000..9b46032858
--- /dev/null
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell.
+ */
+
+#include "cn10k_ethdev.h"
+#include <rte_mtr_driver.h>
+
+const struct rte_mtr_ops nix_mtr_ops = {
+};
+
+int
+cn10k_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops)
+{
+	RTE_SET_USED(dev);
+
+	*(const void **)ops = &nix_mtr_ops;
+	return 0;
+}
diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build
index d4cdd1744a..91afc1de4c 100644
--- a/drivers/net/cnxk/meson.build
+++ b/drivers/net/cnxk/meson.build
@@ -35,6 +35,7 @@ sources += files(
 # CN10K
 sources += files(
         'cn10k_ethdev.c',
+        'cn10k_ethdev_mtr.c',
         'cn10k_rte_flow.c',
         'cn10k_rx.c',
         'cn10k_rx_mseg.c',
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 16/27] net/cnxk: support ops to get meter capabilities
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (13 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 15/27] net/cnxk: support meter ops get API skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 17/27] net/cnxk: support ops to create meter profile skori
                     ` (12 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement ethdev operation to get meter capabilities for
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 48 +++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 9b46032858..a1b42831a5 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -5,7 +5,55 @@
 #include "cn10k_ethdev.h"
 #include <rte_mtr_driver.h>
 
+#define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
+#define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
+
+static struct rte_mtr_capabilities mtr_capa = {
+	.n_max = NIX_MTR_COUNT_MAX,
+	.n_shared_max = NIX_MTR_COUNT_PER_FLOW,
+	/* .identical = , */
+	.shared_identical = true,
+	/* .shared_n_flows_per_mtr_max = ,*/
+	.chaining_n_mtrs_per_flow_max = NIX_MTR_COUNT_PER_FLOW,
+	.chaining_use_prev_mtr_color_supported = true,
+	.chaining_use_prev_mtr_color_enforced = true,
+	.meter_srtcm_rfc2697_n_max = NIX_MTR_COUNT_MAX,
+	.meter_trtcm_rfc2698_n_max = NIX_MTR_COUNT_MAX,
+	.meter_trtcm_rfc4115_n_max = NIX_MTR_COUNT_MAX,
+	.meter_rate_max = NIX_BPF_RATE_MAX / 8, /* Bytes per second */
+	.meter_policy_n_max = NIX_MTR_COUNT_MAX,
+	.color_aware_srtcm_rfc2697_supported = true,
+	.color_aware_trtcm_rfc2698_supported = true,
+	.color_aware_trtcm_rfc4115_supported = true,
+	.srtcm_rfc2697_byte_mode_supported = true,
+	.srtcm_rfc2697_packet_mode_supported = true,
+	.trtcm_rfc2698_byte_mode_supported = true,
+	.trtcm_rfc2698_packet_mode_supported = true,
+	.trtcm_rfc4115_byte_mode_supported = true,
+	.trtcm_rfc4115_packet_mode_supported = true,
+	.stats_mask = RTE_MTR_STATS_N_PKTS_GREEN | RTE_MTR_STATS_N_PKTS_YELLOW |
+		      RTE_MTR_STATS_N_PKTS_RED | RTE_MTR_STATS_N_PKTS_DROPPED |
+		      RTE_MTR_STATS_N_BYTES_GREEN |
+		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
+		      RTE_MTR_STATS_N_BYTES_DROPPED};
+
+static int
+cn10k_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
+			       struct rte_mtr_capabilities *capa,
+			       struct rte_mtr_error *error)
+{
+	RTE_SET_USED(dev);
+
+	if (!capa)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "NULL input parameter");
+	*capa = mtr_capa;
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
+	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 17/27] net/cnxk: support ops to create meter profile
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (14 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 16/27] net/cnxk: support ops to get meter capabilities skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 18/27] net/cnxk: support ops to delete " skori
                     ` (11 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to add meter profile for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 138 ++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev.c      |  14 +++
 drivers/net/cnxk/cnxk_ethdev.h      |  13 +++
 3 files changed, 165 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index a1b42831a5..69efe395b5 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -37,6 +37,106 @@ static struct rte_mtr_capabilities mtr_capa = {
 		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
 		      RTE_MTR_STATS_N_BYTES_DROPPED};
 
+static struct cnxk_mtr_profile_node *
+nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
+{
+	struct cnxk_mtr_profiles *fmps = &dev->mtr_profiles;
+	struct cnxk_mtr_profile_node *fmp;
+
+	TAILQ_FOREACH(fmp, fmps, next)
+		if (profile_id == fmp->id)
+			return fmp;
+
+	return NULL;
+}
+
+static int
+nix_mtr_profile_validate(struct cnxk_eth_dev *dev, uint32_t profile_id,
+			 struct rte_mtr_meter_profile *profile,
+			 struct rte_mtr_error *error)
+{
+	int rc = 0;
+
+	PLT_SET_USED(dev);
+
+	if (profile == NULL)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE,
+					  NULL, "Meter profile is null.");
+
+	if (profile_id == UINT32_MAX)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile id not valid.");
+
+	switch (profile->alg) {
+	case RTE_MTR_SRTCM_RFC2697:
+		if (profile->srtcm_rfc2697.cir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CIR exceeds max meter rate");
+
+		if (profile->srtcm_rfc2697.cbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->srtcm_rfc2697.ebs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"EBS exceeds max meter burst size");
+		break;
+
+	case RTE_MTR_TRTCM_RFC2698:
+		if (profile->trtcm_rfc2698.cir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CIR exceeds max meter rate");
+
+		if (profile->trtcm_rfc2698.pir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PIR exceeds max meter rate");
+
+		if (profile->trtcm_rfc2698.cbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->trtcm_rfc2698.pbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PBS exceeds max meter burst size");
+		break;
+
+	case RTE_MTR_TRTCM_RFC4115:
+		if ((profile->trtcm_rfc4115.cir + profile->trtcm_rfc4115.eir) >
+		    mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PIR + EIR exceeds max rate");
+
+		if (profile->trtcm_rfc4115.cbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->trtcm_rfc4115.ebs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PBS exceeds max meter burst size");
+		break;
+
+	default:
+		rc = -rte_mtr_error_set(error, EINVAL,
+					RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+					"alg is invalid");
+		break;
+	}
+
+	return rc;
+}
+
 static int
 cn10k_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
 			       struct rte_mtr_capabilities *capa,
@@ -52,8 +152,46 @@ cn10k_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_profile_add(struct rte_eth_dev *eth_dev, uint32_t profile_id,
+			  struct rte_mtr_meter_profile *profile,
+			  struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profiles *fmps = &dev->mtr_profiles;
+	struct cnxk_mtr_profile_node *fmp;
+	int ret;
+
+	/* Check input params. */
+	ret = nix_mtr_profile_validate(dev, profile_id, profile, error);
+	if (ret)
+		return ret;
+
+	fmp = nix_mtr_profile_find(dev, profile_id);
+	if (fmp) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Profile already exist");
+	}
+
+	fmp = plt_zmalloc(sizeof(struct cnxk_mtr_profile_node), ROC_ALIGN);
+	if (fmp == NULL)
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Meter profile memory "
+					  "alloc failed.");
+
+	fmp->id = profile_id;
+	fmp->profile = *profile;
+
+	TAILQ_INSERT_TAIL(fmps, fmp, next);
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
+	.meter_profile_add = cn10k_nix_mtr_profile_add,
 };
 
 int
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index 7152dcd002..e952aa5ec5 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -504,6 +504,14 @@ nix_free_queue_mem(struct cnxk_eth_dev *dev)
 	dev->sqs = NULL;
 }
 
+static int
+nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
+{
+	TAILQ_INIT(&dev->mtr_profiles);
+
+	return 0;
+}
+
 static int
 nix_rss_default_setup(struct cnxk_eth_dev *dev)
 {
@@ -901,6 +909,12 @@ cnxk_nix_configure(struct rte_eth_dev *eth_dev)
 		goto free_nix_lf;
 	}
 
+	rc = nix_ingress_policer_setup(dev);
+	if (rc) {
+		plt_err("Failed to setup ingress policer rc=%d", rc);
+		goto free_nix_lf;
+	}
+
 	rc = roc_nix_tm_hierarchy_enable(nix, ROC_NIX_TM_DEFAULT, false);
 	if (rc) {
 		plt_err("Failed to enable default tm hierarchy, rc=%d", rc);
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 27920c84f2..2b9b5beb83 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -13,6 +13,7 @@
 #include <rte_mbuf.h>
 #include <rte_mbuf_pool_ops.h>
 #include <rte_mempool.h>
+#include <rte_mtr_driver.h>
 #include <rte_time.h>
 
 #include "roc_api.h"
@@ -144,6 +145,15 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct cnxk_mtr_profile_node {
+	TAILQ_ENTRY(cnxk_mtr_profile_node) next;
+	struct rte_mtr_meter_profile profile; /**< Profile detail. */
+	uint32_t ref_cnt;		      /**< Use count. */
+	uint32_t id;			      /**< Profile id. */
+};
+
+TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
+
 struct cnxk_eth_dev {
 	/* ROC NIX */
 	struct roc_nix nix;
@@ -211,6 +221,9 @@ struct cnxk_eth_dev {
 	double clk_freq_mult;
 	uint64_t clk_delta;
 
+	/* Ingress policer */
+	struct cnxk_mtr_profiles mtr_profiles;
+
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
 
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 18/27] net/cnxk: support ops to delete meter profile
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (15 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 17/27] net/cnxk: support ops to create meter profile skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 19/27] net/cnxk: support ops to validate meter policy skori
                     ` (10 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter profile for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 30 +++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 69efe395b5..ea4d898cd7 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -189,9 +189,39 @@ cn10k_nix_mtr_profile_add(struct rte_eth_dev *eth_dev, uint32_t profile_id,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,
+			     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *fmp;
+
+	if (profile_id == UINT32_MAX)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile id not valid.");
+
+	fmp = nix_mtr_profile_find(dev, profile_id);
+	if (fmp == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  &profile_id,
+					  "Meter profile is invalid.");
+
+	if (fmp->ref_cnt)
+		return -rte_mtr_error_set(error, EBUSY,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile is in use.");
+
+	TAILQ_REMOVE(&dev->mtr_profiles, fmp, next);
+	plt_free(fmp);
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
+	.meter_profile_delete = cn10k_nix_mtr_profile_delete,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 19/27] net/cnxk: support ops to validate meter policy
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (16 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 18/27] net/cnxk: support ops to delete " skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 20/27] net/cnxk: support ops to create " skori
                     ` (9 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to validate meter policy for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 49 +++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index ea4d898cd7..4cf4ebd6fd 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -218,10 +218,59 @@ cn10k_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_policy_validate(struct rte_eth_dev *dev,
+			      struct rte_mtr_meter_policy_params *policy,
+			      struct rte_mtr_error *error)
+{
+	static const char *const action_color[] = {"Green", "Yellow", "Red"};
+	bool supported[RTE_COLORS] = {false, false, false};
+	const struct rte_flow_action *action;
+	char message[1024];
+	uint32_t i;
+
+	RTE_SET_USED(dev);
+
+	if (!policy)
+		return 0; /* Nothing to be validated */
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		if (policy->actions[i]) {
+			for (action = policy->actions[i];
+			     action->type != RTE_FLOW_ACTION_TYPE_END;
+			     action++) {
+				if (action->type == RTE_FLOW_ACTION_TYPE_METER)
+					supported[i] = true;
+
+				if (action->type == RTE_FLOW_ACTION_TYPE_DROP)
+					supported[i] = true;
+
+				if (!supported[i]) {
+					sprintf(message,
+						"%s action is not valid",
+						action_color[i]);
+					return -rte_mtr_error_set(error,
+					  ENOTSUP,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+					  message);
+				}
+			}
+		} else {
+			sprintf(message, "%s action is null", action_color[i]);
+			return -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+				message);
+		}
+	}
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
 	.meter_profile_delete = cn10k_nix_mtr_profile_delete,
+	.meter_policy_validate = cn10k_nix_mtr_policy_validate,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 20/27] net/cnxk: support ops to create meter policy
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (17 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 19/27] net/cnxk: support ops to validate meter policy skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 21/27] net/cnxk: support ops to delete " skori
                     ` (8 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to add meter policy for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 84 +++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev.c      |  1 +
 drivers/net/cnxk/cnxk_ethdev.h      | 31 +++++++++++
 3 files changed, 116 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 4cf4ebd6fd..bb191666c4 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -50,6 +50,18 @@ nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
 	return NULL;
 }
 
+static struct cnxk_mtr_policy_node *
+nix_mtr_policy_find(struct cnxk_eth_dev *dev, uint32_t meter_policy_id)
+{
+	struct cnxk_mtr_policy *fmps = &dev->mtr_policy;
+	struct cnxk_mtr_policy_node *fmp;
+
+	TAILQ_FOREACH(fmp, fmps, next)
+		if (meter_policy_id == fmp->id)
+			return fmp;
+	return NULL;
+}
+
 static int
 nix_mtr_profile_validate(struct cnxk_eth_dev *dev, uint32_t profile_id,
 			 struct rte_mtr_meter_profile *profile,
@@ -266,11 +278,83 @@ cn10k_nix_mtr_policy_validate(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static void
+cn10k_fill_policy_actions(struct cnxk_mtr_policy_node *fmp,
+			  struct rte_mtr_meter_policy_params *policy)
+
+{
+	const struct rte_flow_action_meter *mtr;
+	const struct rte_flow_action *action;
+	int i;
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		if (policy->actions[i]) {
+			for (action = policy->actions[i];
+			     action->type != RTE_FLOW_ACTION_TYPE_END;
+			     action++) {
+				if (action->type ==
+				    RTE_FLOW_ACTION_TYPE_METER) {
+					fmp->actions[i].action_fate =
+						action->type;
+					mtr = (const struct
+					       rte_flow_action_meter *)
+						      action->conf;
+					fmp->actions[i].mtr_id = mtr->mtr_id;
+				}
+
+				if (action->type == RTE_FLOW_ACTION_TYPE_DROP) {
+					fmp->actions[i].action_fate =
+						action->type;
+				}
+			}
+		}
+	}
+}
+
+static int
+cn10k_nix_mtr_policy_add(struct rte_eth_dev *eth_dev, uint32_t policy_id,
+			 struct rte_mtr_meter_policy_params *policy,
+			 struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy *fmps = &dev->mtr_policy;
+	struct cnxk_mtr_policy_node *fmp;
+	int rc;
+
+	fmp = nix_mtr_policy_find(dev, policy_id);
+	if (fmp) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "Policy already exist");
+	}
+
+	fmp = plt_zmalloc(sizeof(struct cnxk_mtr_policy_node), ROC_ALIGN);
+	if (fmp == NULL) {
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Memory allocation failure");
+	} else {
+		rc = cn10k_nix_mtr_policy_validate(eth_dev, policy, error);
+		if (rc)
+			goto exit;
+	}
+
+	fmp->id = policy_id;
+	cn10k_fill_policy_actions(fmp, policy);
+	TAILQ_INSERT_TAIL(fmps, fmp, next);
+	return 0;
+
+exit:
+	plt_free(fmp);
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
 	.meter_profile_delete = cn10k_nix_mtr_profile_delete,
 	.meter_policy_validate = cn10k_nix_mtr_policy_validate,
+	.meter_policy_add = cn10k_nix_mtr_policy_add,
 };
 
 int
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index e952aa5ec5..9e75060513 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -508,6 +508,7 @@ static int
 nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
 	TAILQ_INIT(&dev->mtr_profiles);
+	TAILQ_INIT(&dev->mtr_policy);
 
 	return 0;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 2b9b5beb83..4e45061c86 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -145,6 +145,35 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct action_rss {
+	enum rte_eth_hash_function func;
+	uint32_t level;
+	uint64_t types;
+	uint32_t key_len;
+	uint32_t queue_num;
+	uint8_t *key;
+	uint16_t *queue;
+};
+
+struct policy_actions {
+	uint32_t action_fate;
+	union {
+		uint16_t queue;
+		uint32_t mtr_id;
+		struct action_rss *rss_desc;
+	};
+};
+
+struct cnxk_mtr_policy_node {
+	TAILQ_ENTRY(cnxk_mtr_policy_node) next;
+	/**< Pointer to the next flow meter structure. */
+	uint32_t id;	 /**< Policy id */
+	uint32_t mtr_id; /** Meter id */
+	struct rte_mtr_meter_policy_params policy;
+	struct policy_actions actions[RTE_COLORS];
+	uint32_t ref_cnt;
+};
+
 struct cnxk_mtr_profile_node {
 	TAILQ_ENTRY(cnxk_mtr_profile_node) next;
 	struct rte_mtr_meter_profile profile; /**< Profile detail. */
@@ -153,6 +182,7 @@ struct cnxk_mtr_profile_node {
 };
 
 TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
+TAILQ_HEAD(cnxk_mtr_policy, cnxk_mtr_policy_node);
 
 struct cnxk_eth_dev {
 	/* ROC NIX */
@@ -223,6 +253,7 @@ struct cnxk_eth_dev {
 
 	/* Ingress policer */
 	struct cnxk_mtr_profiles mtr_profiles;
+	struct cnxk_mtr_policy mtr_policy;
 
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 21/27] net/cnxk: support ops to delete meter policy
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (18 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 20/27] net/cnxk: support ops to create " skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 22/27] net/cnxk: support ops to create meter skori
                     ` (7 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter policy for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index bb191666c4..ff865b8fa6 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -349,12 +349,38 @@ cn10k_nix_mtr_policy_add(struct rte_eth_dev *eth_dev, uint32_t policy_id,
 	return rc;
 }
 
+static int
+cn10k_nix_mtr_policy_delete(struct rte_eth_dev *eth_dev, uint32_t policy_id,
+			    struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy_node *fmp;
+
+	fmp = nix_mtr_policy_find(dev, policy_id);
+	if (fmp == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "No policy found");
+	}
+
+	if (fmp->ref_cnt)
+		return -rte_mtr_error_set(error, EBUSY,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "Meter policy is in use.");
+
+	TAILQ_REMOVE(&dev->mtr_policy, fmp, next);
+	plt_free(fmp);
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
 	.meter_profile_delete = cn10k_nix_mtr_profile_delete,
 	.meter_policy_validate = cn10k_nix_mtr_policy_validate,
 	.meter_policy_add = cn10k_nix_mtr_policy_add,
+	.meter_policy_delete = cn10k_nix_mtr_policy_delete,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 22/27] net/cnxk: support ops to create meter
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (19 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 21/27] net/cnxk: support ops to delete " skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 23/27] net/cnxk: support ops to delete meter skori
                     ` (6 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to create meter instance for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 97 +++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev.c      |  1 +
 drivers/net/cnxk/cnxk_ethdev.h      | 25 ++++++++
 3 files changed, 123 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index ff865b8fa6..8916dc329f 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -37,6 +37,18 @@ static struct rte_mtr_capabilities mtr_capa = {
 		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
 		      RTE_MTR_STATS_N_BYTES_DROPPED};
 
+static struct cnxk_meter_node *
+nix_mtr_find(struct cnxk_eth_dev *dev, uint32_t meter_id)
+{
+	struct cnxk_mtr *fms = &dev->mtr;
+	struct cnxk_meter_node *fm;
+
+	TAILQ_FOREACH(fm, fms, next)
+		if (meter_id == fm->id)
+			return fm;
+	return NULL;
+}
+
 static struct cnxk_mtr_profile_node *
 nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
 {
@@ -374,6 +386,90 @@ cn10k_nix_mtr_policy_delete(struct rte_eth_dev *eth_dev, uint32_t policy_id,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_create(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		     struct rte_mtr_params *params, int shared,
+		     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_mtr *fm = &dev->mtr;
+	struct cnxk_meter_node *mtr;
+	int i;
+
+	RTE_SET_USED(shared);
+
+	if (params == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "Meter params are invalid.");
+
+	profile = nix_mtr_profile_find(dev, params->meter_profile_id);
+	if (profile == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  &params->meter_profile_id,
+					  "Meter profile is invalid.");
+
+	policy = nix_mtr_policy_find(dev, params->meter_policy_id);
+	if (policy == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  &params->meter_policy_id,
+					  "Meter policy is invalid.");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		mtr = plt_zmalloc(sizeof(struct cnxk_meter_node), ROC_ALIGN);
+		if (mtr == NULL) {
+			return -rte_mtr_error_set(error, ENOMEM,
+				RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+				"Meter memory alloc failed.");
+		} else {
+			mtr->id = mtr_id;
+			mtr->profile = profile;
+			mtr->policy = policy;
+			mtr->params = *params;
+			mtr->bpf_id = ROC_NIX_BPF_ID_INVALID;
+			mtr->prev_cnt = 0;
+			for (i = 0; i < MAX_PRV_MTR_NODES; i++)
+				mtr->prev_id[i] = ROC_NIX_BPF_ID_INVALID;
+			mtr->next_id = ROC_NIX_BPF_ID_INVALID;
+			mtr->is_prev = false;
+			mtr->is_next = false;
+			mtr->level = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+
+			if (params->dscp_table) {
+				mtr->params.dscp_table =
+					plt_zmalloc(ROC_NIX_BPF_PRE_COLOR_MAX,
+						    ROC_ALIGN);
+				if (mtr->params.dscp_table == NULL) {
+					plt_free(mtr);
+					return -rte_mtr_error_set(error, ENOMEM,
+						RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+						NULL, "Memory alloc failed.");
+				}
+
+				for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX;
+				     i++) {
+					mtr->params.dscp_table[i] =
+						params->dscp_table[i];
+				}
+			}
+		}
+	} else {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter already exist");
+	}
+
+	profile->ref_cnt++;
+	policy->ref_cnt++;
+	TAILQ_INSERT_TAIL(fm, mtr, next);
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -381,6 +477,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_validate = cn10k_nix_mtr_policy_validate,
 	.meter_policy_add = cn10k_nix_mtr_policy_add,
 	.meter_policy_delete = cn10k_nix_mtr_policy_delete,
+	.create = cn10k_nix_mtr_create,
 };
 
 int
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index 9e75060513..4c12715756 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -509,6 +509,7 @@ nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
 	TAILQ_INIT(&dev->mtr_profiles);
 	TAILQ_INIT(&dev->mtr_policy);
+	TAILQ_INIT(&dev->mtr);
 
 	return 0;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 4e45061c86..8d94d873bb 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -145,6 +145,28 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct cnxk_meter_node {
+#define MAX_PRV_MTR_NODES 10
+	TAILQ_ENTRY(cnxk_meter_node) next;
+	/**< Pointer to the next flow meter structure. */
+	uint32_t id; /**< Usr mtr id. */
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	uint32_t bpf_id; /**< Hw mtr id. */
+	uint32_t rq_num;
+	uint32_t *rq_id;
+	uint16_t level;
+	uint32_t prev_id[MAX_PRV_MTR_NODES]; /**< Prev mtr id for chaining */
+	uint32_t prev_cnt;
+	uint32_t next_id; /**< Next mtr id for chaining */
+	bool is_prev;
+	bool is_next;
+	struct rte_mtr_params params;
+	struct roc_nix_bpf_objs profs;
+	bool is_used;
+	uint32_t ref_cnt;
+};
+
 struct action_rss {
 	enum rte_eth_hash_function func;
 	uint32_t level;
@@ -183,6 +205,7 @@ struct cnxk_mtr_profile_node {
 
 TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
 TAILQ_HEAD(cnxk_mtr_policy, cnxk_mtr_policy_node);
+TAILQ_HEAD(cnxk_mtr, cnxk_meter_node);
 
 struct cnxk_eth_dev {
 	/* ROC NIX */
@@ -252,8 +275,10 @@ struct cnxk_eth_dev {
 	uint64_t clk_delta;
 
 	/* Ingress policer */
+	enum roc_nix_bpf_color precolor_tbl[ROC_NIX_BPF_PRE_COLOR_MAX];
 	struct cnxk_mtr_profiles mtr_profiles;
 	struct cnxk_mtr_policy mtr_policy;
+	struct cnxk_mtr mtr;
 
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 23/27] net/cnxk: support ops to delete meter
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (20 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 22/27] net/cnxk: support ops to create meter skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 24/27] net/cnxk: support ops to enable/disable meter skori
                     ` (5 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter instance for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 82 +++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 8916dc329f..6d48680c19 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -8,6 +8,10 @@
 #define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
 #define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
 
+static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
+						      ROC_NIX_BPF_LEVEL_F_MID,
+						      ROC_NIX_BPF_LEVEL_F_TOP};
+
 static struct rte_mtr_capabilities mtr_capa = {
 	.n_max = NIX_MTR_COUNT_MAX,
 	.n_shared_max = NIX_MTR_COUNT_PER_FLOW,
@@ -470,6 +474,83 @@ cn10k_nix_mtr_create(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return 0;
 }
 
+static int
+cn10k_nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		      struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_objs profs = {0};
+	struct cnxk_mtr *fm = &dev->mtr;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, &mtr_id,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->ref_cnt) {
+		return -rte_mtr_error_set(error, EADDRINUSE,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, &mtr_id,
+					  "Meter id in use.");
+	}
+
+	switch (lvl_map[mtr->level]) {
+	case ROC_NIX_BPF_LEVEL_F_LEAF:
+		if (mtr->is_next) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_LEAF,
+						 mtr_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		break;
+	case ROC_NIX_BPF_LEVEL_F_MID:
+		while (mtr->prev_cnt) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_LEAF,
+						 mtr->prev_id[mtr->prev_cnt],
+						 ROC_NIX_BPF_ID_INVALID);
+			mtr->prev_cnt--;
+		}
+		if (mtr->is_next) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_MID,
+						 mtr_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		break;
+	case ROC_NIX_BPF_LEVEL_F_TOP:
+		while (mtr->prev_cnt) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_MID,
+						 mtr->prev_id[mtr->prev_cnt],
+						 ROC_NIX_BPF_ID_INVALID);
+			mtr->prev_cnt--;
+		}
+		break;
+	default:
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Invalid meter level");
+	}
+
+	if (rc)
+		goto exit;
+
+	profs.level = mtr->level;
+	profs.count = 1;
+	profs.ids[0] = mtr->bpf_id;
+	rc = roc_nix_bpf_free(nix, &profs, 1);
+	if (rc)
+		goto exit;
+
+	TAILQ_REMOVE(fm, mtr, next);
+	plt_free(mtr->params.dscp_table);
+	plt_free(mtr);
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -478,6 +559,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_add = cn10k_nix_mtr_policy_add,
 	.meter_policy_delete = cn10k_nix_mtr_policy_delete,
 	.create = cn10k_nix_mtr_create,
+	.destroy = cn10k_nix_mtr_destroy,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 24/27] net/cnxk: support ops to enable/disable meter
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (21 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 23/27] net/cnxk: support ops to delete meter skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 25/27] net/cnxk: support ops to update precolor DSCP table skori
                     ` (4 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to enable or disable meter instance for
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 60 +++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 6d48680c19..88153563c2 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -551,6 +551,64 @@ cn10k_nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cn10k_nix_mtr_enable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->level != 0)
+		return 0;
+
+	for (i = 0; i < mtr->rq_num; i++) {
+		rq = &dev->rqs[mtr->rq_id[i]];
+		rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, true);
+	}
+
+	return rc;
+}
+
+static int
+cn10k_nix_mtr_disable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		      struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->level != 0)
+		return 0;
+
+	for (i = 0; i < mtr->rq_num; i++) {
+		rq = &dev->rqs[mtr->rq_id[i]];
+		rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, false);
+	}
+
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -560,6 +618,8 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_delete = cn10k_nix_mtr_policy_delete,
 	.create = cn10k_nix_mtr_create,
 	.destroy = cn10k_nix_mtr_destroy,
+	.meter_enable = cn10k_nix_mtr_enable,
+	.meter_disable = cn10k_nix_mtr_disable,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 25/27] net/cnxk: support ops to update precolor DSCP table
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (22 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 24/27] net/cnxk: support ops to enable/disable meter skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 26/27] net/cnxk: support ops to read/update meter stats skori
                     ` (3 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to update DSCP table for pre-coloring for
incoming packet per nixlf for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 43 +++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 88153563c2..55485601fb 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -609,6 +609,48 @@ cn10k_nix_mtr_disable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cn10k_nix_mtr_dscp_table_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+				enum rte_color *dscp_table,
+				struct rte_mtr_error *error)
+{
+	enum roc_nix_bpf_color nix_dscp_tbl[ROC_NIX_BPF_PRE_COLOR_MAX];
+	enum roc_nix_bpf_color color_map[] = {ROC_NIX_BPF_COLOR_GREEN,
+					      ROC_NIX_BPF_COLOR_YELLOW,
+					      ROC_NIX_BPF_COLOR_RED};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint8_t lvl_flag = ROC_NIX_BPF_LEVEL_F_LEAF;
+	struct roc_nix_bpf_precolor table;
+	struct roc_nix *nix = &dev->nix;
+	int rc, i;
+
+	if (!dscp_table) {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			nix_dscp_tbl[i] = ROC_NIX_BPF_COLOR_GREEN;
+	} else {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			nix_dscp_tbl[i] = color_map[dscp_table[i]];
+	}
+
+	table.count = ROC_NIX_BPF_PRE_COLOR_MAX;
+	table.mode = ROC_NIX_BPF_PC_MODE_DSCP_OUTER;
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		table.color[i] = nix_dscp_tbl[i];
+
+	rc = roc_nix_bpf_pre_color_tbl_setup(nix, mtr_id, lvl_flag, &table);
+	if (rc) {
+		rte_mtr_error_set(error, rc, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+				  NULL, NULL);
+		goto exit;
+	}
+
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		dev->precolor_tbl[i] = nix_dscp_tbl[i];
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -620,6 +662,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.destroy = cn10k_nix_mtr_destroy,
 	.meter_enable = cn10k_nix_mtr_enable,
 	.meter_disable = cn10k_nix_mtr_disable,
+	.meter_dscp_table_update = cn10k_nix_mtr_dscp_table_update,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 26/27] net/cnxk: support ops to read/update meter stats
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (23 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 25/27] net/cnxk: support ops to update precolor DSCP table skori
@ 2021-09-30  9:08   ` skori
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 27/27] net/cnxk: support meter action to flow create skori
                     ` (2 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to read and update stats corresponding to
given meter instance for CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_ethdev_mtr.c | 141 ++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)

diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 55485601fb..62f48c534f 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -8,6 +8,21 @@
 #define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
 #define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
 
+#define NIX_BPF_STATS_MASK_ALL                                                 \
+	{                                                                      \
+		ROC_NIX_BPF_GREEN_PKT_F_PASS | ROC_NIX_BPF_GREEN_OCTS_F_PASS | \
+			ROC_NIX_BPF_GREEN_PKT_F_DROP |                         \
+			ROC_NIX_BPF_GREEN_OCTS_F_DROP |                        \
+			ROC_NIX_BPF_YELLOW_PKT_F_PASS |                        \
+			ROC_NIX_BPF_YELLOW_OCTS_F_PASS |                       \
+			ROC_NIX_BPF_YELLOW_PKT_F_DROP |                        \
+			ROC_NIX_BPF_YELLOW_OCTS_F_DROP |                       \
+			ROC_NIX_BPF_RED_PKT_F_PASS |                           \
+			ROC_NIX_BPF_RED_OCTS_F_PASS |                          \
+			ROC_NIX_BPF_RED_PKT_F_DROP |                           \
+			ROC_NIX_BPF_RED_OCTS_F_DROP                            \
+	}
+
 static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
 						      ROC_NIX_BPF_LEVEL_F_MID,
 						      ROC_NIX_BPF_LEVEL_F_TOP};
@@ -651,6 +666,130 @@ cn10k_nix_mtr_dscp_table_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cn10k_nix_mtr_stats_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+			   uint64_t stats_mask, struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	if (!stats_mask)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "no bit is set to stats mask");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	mtr->params.stats_mask = stats_mask;
+	return 0;
+}
+
+static int
+cn10k_nix_mtr_stats_read(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+			 struct rte_mtr_stats *stats, uint64_t *stats_mask,
+			 int clear, struct rte_mtr_error *error)
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	uint64_t bpf_stats[ROC_NIX_BPF_STATS_MAX] = {0};
+	uint8_t lvl_flag = ROC_NIX_BPF_LEVEL_F_LEAF;
+	uint64_t mask = NIX_BPF_STATS_MASK_ALL;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	int rc;
+
+	if (!stats)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "stats pointer is NULL");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	rc = roc_nix_bpf_stats_read(nix, mtr->bpf_id, mask, lvl_flag,
+				    bpf_stats);
+	if (rc) {
+		rte_mtr_error_set(error, rc, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+				  NULL, NULL);
+		goto exit;
+	}
+
+	green_pkt_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
+		stats->n_pkts[RTE_COLOR_GREEN] = bpf_stats[green_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
+		stats->n_pkts[RTE_COLOR_YELLOW] = bpf_stats[yellow_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_RED)
+		stats->n_pkts[RTE_COLOR_RED] = bpf_stats[red_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
+		stats->n_bytes[RTE_COLOR_GREEN] = bpf_stats[green_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
+		stats->n_bytes[RTE_COLOR_YELLOW] = bpf_stats[yellow_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_RED)
+		stats->n_bytes[RTE_COLOR_RED] = bpf_stats[red_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
+		stats->n_pkts_dropped = bpf_stats[green_pkt_drop] +
+					bpf_stats[yellow_pkt_drop] +
+					bpf_stats[red_pkt_drop];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
+		stats->n_bytes_dropped = bpf_stats[green_octs_drop] +
+					 bpf_stats[yellow_octs_drop] +
+					 bpf_stats[red_octs_drop];
+
+	if (stats_mask)
+		*stats_mask = mtr->params.stats_mask;
+
+	if (clear) {
+		rc = roc_nix_bpf_stats_reset(nix, mtr->bpf_id, mask, lvl_flag);
+		if (rc) {
+			rte_mtr_error_set(error, rc,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  NULL);
+			goto exit;
+		}
+	}
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cn10k_nix_mtr_capabilities_get,
 	.meter_profile_add = cn10k_nix_mtr_profile_add,
@@ -663,6 +802,8 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_enable = cn10k_nix_mtr_enable,
 	.meter_disable = cn10k_nix_mtr_disable,
 	.meter_dscp_table_update = cn10k_nix_mtr_dscp_table_update,
+	.stats_update = cn10k_nix_mtr_stats_update,
+	.stats_read = cn10k_nix_mtr_stats_read,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v3 27/27] net/cnxk: support meter action to flow create
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (24 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 26/27] net/cnxk: support ops to read/update meter stats skori
@ 2021-09-30  9:08   ` skori
  2021-09-30 10:00   ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions Kinsella, Ray
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-09-30  9:08 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Meters are configured per flow using rte_flow_create API.
Implement support for meter action applied on the flow.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 doc/guides/nics/features/cnxk.ini    |   1 +
 doc/guides/nics/features/cnxk_vf.ini |   1 +
 drivers/net/cnxk/cn10k_ethdev_mtr.c  | 514 +++++++++++++++++++++++++++
 drivers/net/cnxk/cn10k_rte_flow.c    | 171 ++++++++-
 drivers/net/cnxk/cnxk_ethdev.h       |  18 +
 drivers/net/cnxk/cnxk_rte_flow.c     |   4 +
 6 files changed, 708 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/cnxk.ini b/doc/guides/nics/features/cnxk.ini
index 5d456257bd..7bbce7dafc 100644
--- a/doc/guides/nics/features/cnxk.ini
+++ b/doc/guides/nics/features/cnxk.ini
@@ -78,6 +78,7 @@ count                = Y
 drop                 = Y
 flag                 = Y
 mark                 = Y
+meter                = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
 of_set_vlan_pcp      = Y
diff --git a/doc/guides/nics/features/cnxk_vf.ini b/doc/guides/nics/features/cnxk_vf.ini
index 7b4299f0be..89802a27f9 100644
--- a/doc/guides/nics/features/cnxk_vf.ini
+++ b/doc/guides/nics/features/cnxk_vf.ini
@@ -70,6 +70,7 @@ count                = Y
 drop                 = Y
 flag                 = Y
 mark                 = Y
+meter                = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
 of_set_vlan_pcp      = Y
diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c
index 62f48c534f..0b98489dee 100644
--- a/drivers/net/cnxk/cn10k_ethdev_mtr.c
+++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c
@@ -814,3 +814,517 @@ cn10k_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops)
 	*(const void **)ops = &nix_mtr_ops;
 	return 0;
 }
+
+int
+nix_mtr_validate(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	profile = nix_mtr_profile_find(dev, mtr->params.meter_profile_id);
+	if (profile == NULL)
+		return -EINVAL;
+
+	policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id);
+	if (policy == NULL)
+		return -EINVAL;
+
+	return 0;
+}
+
+int
+nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id,
+		       struct cnxk_mtr_policy_node **policy_act)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id);
+	if (policy == NULL)
+		return -EINVAL;
+
+	*policy_act = policy;
+
+	return 0;
+}
+
+int
+nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t queue_num,
+		  const uint16_t *queue)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+	uint32_t i;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	mtr->rq_id = plt_zmalloc(queue_num * sizeof(uint32_t), ROC_ALIGN);
+	if (mtr->rq_id == NULL)
+		return -ENOMEM;
+
+	mtr->rq_num = queue_num;
+	for (i = 0; i < queue_num; i++)
+		mtr->rq_id[i] = queue[i];
+
+	return 0;
+}
+
+int
+nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id)
+{
+	struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint32_t mtr_id = cur_id;
+	int i = 0, j = 0;
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		mtr[i] = nix_mtr_find(dev, mtr_id);
+		if (mtr[i])
+			mtr_id = mtr[i]->next_id;
+	}
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		if (mtr[i]) {
+			for (j = 0; j < MAX_PRV_MTR_NODES; j++)
+				mtr[i]->prev_id[i] = ROC_NIX_BPF_ID_INVALID;
+			mtr[i]->level = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+			mtr[i]->next_id = ROC_NIX_BPF_ID_INVALID;
+			mtr[i]->is_prev = false;
+			mtr[i]->is_next = false;
+			mtr[i]->prev_cnt = 0;
+		}
+	}
+	return 0;
+}
+
+int
+nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id,
+		     uint32_t prev_id, uint32_t next_id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, cur_id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	switch (lvl_map[mtr->level]) {
+	case ROC_NIX_BPF_LEVEL_F_LEAF:
+		mtr->prev_id[mtr->prev_cnt] = ROC_NIX_BPF_ID_INVALID;
+		mtr->next_id = next_id;
+		mtr->is_prev = false;
+		mtr->is_next = true;
+		break;
+	case ROC_NIX_BPF_LEVEL_F_MID:
+		mtr->prev_id[mtr->prev_cnt] = prev_id;
+		mtr->next_id = next_id;
+		mtr->is_prev = true;
+		mtr->is_next = true;
+		break;
+	case ROC_NIX_BPF_LEVEL_F_TOP:
+		mtr->prev_id[mtr->prev_cnt] = prev_id;
+		mtr->next_id = ROC_NIX_BPF_ID_INVALID;
+		mtr->is_prev = true;
+		mtr->is_next = false;
+		break;
+	default:
+		plt_err("Invalid meter level");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+struct cnxk_meter_node *
+nix_get_mtr(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return NULL;
+
+	return mtr;
+}
+
+int
+nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t level)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	mtr->level = level;
+	return 0;
+}
+
+static void
+nix_mtr_config_map(struct cnxk_meter_node *mtr, struct roc_nix_bpf_cfg *cfg)
+{
+	enum roc_nix_bpf_algo alg_map[] = {
+		ROC_NIX_BPF_ALGO_NONE, ROC_NIX_BPF_ALGO_2697,
+		ROC_NIX_BPF_ALGO_2698, ROC_NIX_BPF_ALGO_4115};
+	struct cnxk_mtr_profile_node *profile = mtr->profile;
+	struct cnxk_mtr_policy_node *policy = mtr->policy;
+
+	cfg->alg = alg_map[profile->profile.alg];
+	cfg->lmode = profile->profile.packet_mode;
+
+	switch (cfg->alg) {
+	case ROC_NIX_BPF_ALGO_2697:
+		cfg->algo2697.cir = profile->profile.srtcm_rfc2697.cir * 8;
+		cfg->algo2697.cbs = profile->profile.srtcm_rfc2697.cbs;
+		cfg->algo2697.ebs = profile->profile.srtcm_rfc2697.ebs;
+		break;
+	case ROC_NIX_BPF_ALGO_2698:
+		cfg->algo2698.cir = profile->profile.trtcm_rfc2698.cir * 8;
+		cfg->algo2698.pir = profile->profile.trtcm_rfc2698.pir * 8;
+		cfg->algo2698.cbs = profile->profile.trtcm_rfc2698.cbs;
+		cfg->algo2698.pbs = profile->profile.trtcm_rfc2698.pbs;
+		break;
+	case ROC_NIX_BPF_ALGO_4115:
+		cfg->algo4115.cir = profile->profile.trtcm_rfc4115.cir * 8;
+		cfg->algo4115.eir = profile->profile.trtcm_rfc4115.eir * 8;
+		cfg->algo4115.cbs = profile->profile.trtcm_rfc4115.cbs;
+		cfg->algo4115.ebs = profile->profile.trtcm_rfc4115.ebs;
+		break;
+	default:
+		break;
+	}
+
+	cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_PASS;
+	cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_PASS;
+	cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_PASS;
+
+	if (policy->actions[RTE_COLOR_GREEN].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_DROP;
+
+	if (policy->actions[RTE_COLOR_YELLOW].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_DROP;
+
+	if (policy->actions[RTE_COLOR_RED].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_DROP;
+}
+
+static void
+nix_dscp_table_map(struct cnxk_meter_node *mtr,
+		   struct roc_nix_bpf_precolor *tbl)
+{
+	enum roc_nix_bpf_color color_map[] = {ROC_NIX_BPF_COLOR_GREEN,
+					      ROC_NIX_BPF_COLOR_YELLOW,
+					      ROC_NIX_BPF_COLOR_RED};
+	int i;
+
+	tbl->count = ROC_NIX_BPF_PRE_COLOR_MAX;
+	tbl->mode = ROC_NIX_BPF_PC_MODE_DSCP_OUTER;
+
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		tbl->color[i] = ROC_NIX_BPF_COLOR_GREEN;
+
+	if (mtr->params.dscp_table) {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			tbl->color[i] = color_map[mtr->params.dscp_table[i]];
+	}
+}
+
+int
+nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	enum roc_nix_bpf_level_flag lvl_flag = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *base_mtr, *next_mtr;
+	struct roc_nix *nix = &dev->nix;
+	uint32_t cur_mtr_id = id;
+	int rc, i;
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		base_mtr = nix_mtr_find(dev, cur_mtr_id);
+		if (base_mtr) {
+			if (base_mtr->level == 0)
+				lvl_flag = ROC_NIX_BPF_LEVEL_F_LEAF;
+			if (base_mtr->level == 1)
+				lvl_flag = ROC_NIX_BPF_LEVEL_F_MID;
+
+			if (base_mtr->is_next) {
+				next_mtr = nix_mtr_find(dev, base_mtr->next_id);
+				if (next_mtr) {
+					if (!base_mtr->is_used) {
+						rc = roc_nix_bpf_connect(nix,
+							lvl_flag,
+							base_mtr->bpf_id,
+							next_mtr->bpf_id);
+						if (rc)
+							return rc;
+					}
+				}
+				cur_mtr_id = base_mtr->next_id;
+			}
+		}
+	}
+	return 0;
+}
+
+int
+nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_objs profs[ROC_NIX_BPF_LEVEL_MAX];
+	uint8_t idx0 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint8_t idx1 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint8_t idx2 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX];
+	int num_mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct roc_nix *nix = &dev->nix;
+	struct roc_nix_bpf_precolor tbl;
+	struct roc_nix_bpf_cfg cfg;
+	struct roc_nix_rq *rq;
+	uint8_t lvl_mask;
+	uint32_t i;
+	uint32_t j;
+	int rc;
+
+	mtr[0] = nix_mtr_find(dev, id);
+	if (mtr[0] == NULL)
+		return -EINVAL;
+
+	num_mtr[0] = 1;
+	idx0 = roc_nix_bpf_level_to_idx(lvl_map[mtr[0]->level]);
+	if (idx0 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return -EINVAL;
+
+	lvl_mask = ROC_NIX_BPF_LEVEL_F_LEAF;
+	if (mtr[0]->is_used)
+		per_lvl_cnt[idx0] = 0;
+	else
+		per_lvl_cnt[idx0] = 1;
+
+	if (mtr[0]->is_next) {
+		mtr[1] = nix_mtr_find(dev, mtr[0]->next_id);
+		if (mtr[1] == NULL)
+			return -EINVAL;
+		num_mtr[1] = 1;
+		idx1 = roc_nix_bpf_level_to_idx(lvl_map[mtr[1]->level]);
+		if (idx1 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			return -EINVAL;
+
+		lvl_mask |= ROC_NIX_BPF_LEVEL_F_MID;
+		if (mtr[1]->is_used)
+			per_lvl_cnt[idx1] = 0;
+		else
+			per_lvl_cnt[idx1] = 1;
+	}
+
+	if (mtr[1] && mtr[1]->is_next) {
+		mtr[2] = nix_mtr_find(dev, mtr[1]->next_id);
+		if (mtr[2] == NULL)
+			return -EINVAL;
+
+		num_mtr[2] = 1;
+		idx2 = roc_nix_bpf_level_to_idx(lvl_map[mtr[2]->level]);
+		if (idx2 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			return -EINVAL;
+
+		lvl_mask |= ROC_NIX_BPF_LEVEL_F_TOP;
+		if (mtr[2]->is_used)
+			per_lvl_cnt[idx2] = 0;
+		else
+			per_lvl_cnt[idx2] = 1;
+	}
+
+	rc = roc_nix_bpf_alloc(nix, lvl_mask, per_lvl_cnt, profs);
+	if (rc)
+		return rc;
+	if (mtr[0]->bpf_id == ROC_NIX_BPF_ID_INVALID)
+		mtr[0]->bpf_id = profs[idx0].ids[0];
+
+	if (num_mtr[0])
+		if (mtr[0]->is_next && idx1 != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			if (mtr[1]->bpf_id == ROC_NIX_BPF_ID_INVALID)
+				mtr[1]->bpf_id = profs[idx1].ids[0];
+
+	if (num_mtr[1])
+		if (mtr[1]->is_next && idx2 != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			if (mtr[2]->bpf_id == ROC_NIX_BPF_ID_INVALID)
+				mtr[2]->bpf_id = profs[idx2].ids[0];
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		if (num_mtr[i]) {
+			if (!mtr[i]->is_used) {
+				memset(&cfg, 0, sizeof(struct roc_nix_bpf_cfg));
+				nix_mtr_config_map(mtr[i], &cfg);
+				rc = roc_nix_bpf_config(nix, mtr[i]->bpf_id,
+							lvl_map[mtr[i]->level],
+							&cfg);
+
+				memset(&tbl, 0,
+				       sizeof(struct roc_nix_bpf_precolor));
+				nix_dscp_table_map(mtr[i], &tbl);
+				rc = roc_nix_bpf_pre_color_tbl_setup(nix,
+					mtr[i]->bpf_id, lvl_map[mtr[i]->level],
+					&tbl);
+
+				if (mtr[i]->params.meter_enable) {
+					for (j = 0; j < mtr[i]->rq_num; j++) {
+						rq = &dev->rqs[mtr[i]->rq_id
+								       [j]];
+						rc = roc_nix_bpf_ena_dis(nix,
+							mtr[i]->bpf_id, rq,
+							true);
+					}
+				}
+			}
+		}
+	}
+
+	return rc;
+}
+
+int
+nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
+			      uint32_t *prev_id, uint32_t *next_id,
+			      struct cnxk_mtr_policy_node *policy,
+			      int *tree_level)
+{
+	uint32_t action_fate_red = policy->actions[RTE_COLOR_RED].action_fate;
+	uint32_t action_fate_green =
+		policy->actions[RTE_COLOR_GREEN].action_fate;
+	uint32_t action_fate_yellow =
+		policy->actions[RTE_COLOR_YELLOW].action_fate;
+	uint32_t cur_mtr_id = *next_id;
+	uint32_t next_mtr_id = 0xffff;
+	uint32_t prev_mtr_id = 0xffff;
+	struct cnxk_meter_node *mtr;
+
+	if (action_fate_green == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_GREEN].mtr_id;
+
+	if (action_fate_yellow == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_YELLOW].mtr_id;
+
+	if (action_fate_red == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_RED].mtr_id;
+
+	if (next_mtr_id != 0xffff) {
+		switch (*tree_level) {
+		case 0:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 0);
+				nix_mtr_chain_update(eth_dev, cur_mtr_id, -1,
+						     next_mtr_id);
+			} else {
+				if (mtr->level == 0)
+					mtr->is_used = true;
+				else
+					return -EINVAL;
+			}
+			(*tree_level)++;
+			*next_id = next_mtr_id;
+			break;
+		case 1:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 1);
+				prev_mtr_id = id;
+				nix_mtr_chain_update(eth_dev, cur_mtr_id,
+						     prev_mtr_id, next_mtr_id);
+			} else {
+				if (mtr->level == 1) {
+					mtr->prev_cnt++;
+					prev_mtr_id = id;
+					nix_mtr_chain_update(eth_dev,
+						cur_mtr_id, prev_mtr_id,
+						next_mtr_id);
+
+					mtr->is_used = true;
+				} else {
+					return -EINVAL;
+				}
+			}
+			(*tree_level)++;
+			*next_id = next_mtr_id;
+			*prev_id = cur_mtr_id;
+			break;
+		case 2:
+			nix_mtr_chain_reset(eth_dev, id);
+			return -EINVAL;
+		}
+	} else {
+		switch (*tree_level) {
+		case 0:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 0);
+			} else {
+				if (mtr->level == 0)
+					mtr->is_used = true;
+				else
+					return -EINVAL;
+			}
+			break;
+		case 1:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 1);
+				prev_mtr_id = id;
+				nix_mtr_chain_update(eth_dev, cur_mtr_id,
+						     prev_mtr_id, -1);
+			} else {
+				if (mtr->level == 1) {
+					mtr->prev_cnt++;
+					prev_mtr_id = id;
+					nix_mtr_chain_update(eth_dev,
+							     cur_mtr_id,
+							     prev_mtr_id, -1);
+					mtr->is_used = true;
+				} else {
+					return -EINVAL;
+				}
+			}
+			break;
+		case 2:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 2);
+				prev_mtr_id = *prev_id;
+				nix_mtr_chain_update(eth_dev, cur_mtr_id,
+						     prev_mtr_id, -1);
+			} else {
+				if (mtr->level == 2) {
+					mtr->prev_cnt++;
+					prev_mtr_id = *prev_id;
+					nix_mtr_chain_update(eth_dev,
+							     cur_mtr_id,
+							     prev_mtr_id, -1);
+					mtr->is_used = true;
+				} else {
+					return -EINVAL;
+				}
+			}
+			break;
+		}
+		*next_id = 0xffff;
+	}
+
+	return 0;
+}
diff --git a/drivers/net/cnxk/cn10k_rte_flow.c b/drivers/net/cnxk/cn10k_rte_flow.c
index b04de6a7e6..8fa0856c77 100644
--- a/drivers/net/cnxk/cn10k_rte_flow.c
+++ b/drivers/net/cnxk/cn10k_rte_flow.c
@@ -6,6 +6,113 @@
 #include "cn10k_ethdev.h"
 #include "cn10k_rx.h"
 
+static int
+cn10k_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t mtr_id)
+{
+	return nix_mtr_connect(eth_dev, mtr_id);
+}
+
+static int
+cn10k_mtr_configure(struct rte_eth_dev *eth_dev,
+		    const struct rte_flow_action actions[])
+{
+	uint32_t mtr_id = 0xffff, prev_mtr_id = 0xffff, next_mtr_id = 0xffff;
+	const struct rte_flow_action_meter *mtr_conf;
+	const struct rte_flow_action_queue *q_conf;
+	const struct rte_flow_action_rss *rss_conf;
+	struct cnxk_mtr_policy_node *policy;
+	bool is_mtr_act = false;
+	int tree_level = 0;
+	int rc = -EINVAL, i;
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) {
+			mtr_conf = (const struct rte_flow_action_meter
+					    *)(actions->conf);
+			mtr_id = mtr_conf->mtr_id;
+			is_mtr_act = true;
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE) {
+			q_conf = (const struct rte_flow_action_queue
+					  *)(actions->conf);
+			if (is_mtr_act)
+				nix_mtr_rq_update(eth_dev, mtr_id, 1,
+						  &q_conf->index);
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
+			rss_conf = (const struct rte_flow_action_rss
+					    *)(actions->conf);
+			if (is_mtr_act)
+				nix_mtr_rq_update(eth_dev, mtr_id,
+						  rss_conf->queue_num,
+						  rss_conf->queue);
+		}
+	}
+
+	if (!is_mtr_act)
+		return rc;
+
+	prev_mtr_id = mtr_id;
+	next_mtr_id = mtr_id;
+	while (next_mtr_id != 0xffff) {
+		rc = nix_mtr_validate(eth_dev, next_mtr_id);
+		if (rc)
+			return rc;
+
+		rc = nix_mtr_policy_act_get(eth_dev, next_mtr_id, &policy);
+		if (rc)
+			return rc;
+
+		rc = nix_mtr_color_action_validate(eth_dev, mtr_id,
+						   &prev_mtr_id, &next_mtr_id,
+						   policy, &tree_level);
+		if (rc)
+			return rc;
+	}
+
+	return nix_mtr_configure(eth_dev, mtr_id);
+}
+
+static int
+cn10k_rss_action_validate(struct rte_eth_dev *eth_dev,
+			  const struct rte_flow_attr *attr,
+			  const struct rte_flow_action *act)
+{
+	const struct rte_flow_action_rss *rss;
+
+	if (act == NULL)
+		return -EINVAL;
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (attr->egress) {
+		plt_err("No support of RSS in egress");
+		return -EINVAL;
+	}
+
+	if (eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
+		plt_err("multi-queue mode is disabled");
+		return -ENOTSUP;
+	}
+
+	if (!rss || !rss->queue_num) {
+		plt_err("no valid queues");
+		return -EINVAL;
+	}
+
+	if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
+		plt_err("non-default RSS hash functions are not supported");
+		return -ENOTSUP;
+	}
+
+	if (rss->key_len && rss->key_len > ROC_NIX_RSS_KEY_LEN) {
+		plt_err("RSS hash key too large");
+		return -ENOTSUP;
+	}
+
+	return 0;
+}
+
 struct rte_flow *
 cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		  const struct rte_flow_item pattern[],
@@ -13,13 +120,75 @@ cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		  struct rte_flow_error *error)
 {
 	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	const struct rte_flow_action *action_rss = NULL;
+	const struct rte_flow_action_meter *mtr = NULL;
+	const struct rte_flow_action *act_q = NULL;
 	int mark_actions = 0, vtag_actions = 0;
 	struct roc_npc *npc = &dev->npc;
 	struct roc_npc_flow *flow;
+	uint32_t req_act = 0;
+	int i, rc;
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER)
+			req_act |= ROC_NPC_ACTION_TYPE_METER;
+
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE) {
+			req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
+			act_q = &actions[i];
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
+			req_act |= ROC_NPC_ACTION_TYPE_RSS;
+			action_rss = &actions[i];
+		}
+	}
+
+	if (req_act & ROC_NPC_ACTION_TYPE_METER) {
+		if ((req_act & ROC_NPC_ACTION_TYPE_RSS) &&
+		    ((req_act & ROC_NPC_ACTION_TYPE_QUEUE))) {
+			return NULL;
+		}
+		if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
+			rc = cn10k_rss_action_validate(eth_dev, attr,
+						       action_rss);
+			if (rc)
+				return NULL;
+		} else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
+			const struct rte_flow_action_queue *act_queue;
+			act_queue = (const struct rte_flow_action_queue *)
+					    act_q->conf;
+			if (act_queue->index > eth_dev->data->nb_rx_queues)
+				return NULL;
+		} else {
+			return NULL;
+		}
+	}
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) {
+			mtr = (const struct rte_flow_action_meter *)actions[i]
+				      .conf;
+			rc = cn10k_mtr_configure(eth_dev, actions);
+			if (rc) {
+				rte_flow_error_set(error, 0,
+					RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+					"Failed to configure mtr ");
+				return NULL;
+			}
+			break;
+		}
+	}
 
 	flow = cnxk_flow_create(eth_dev, attr, pattern, actions, error);
-	if (!flow)
+	if (!flow) {
+		if (mtr)
+			nix_mtr_chain_reset(eth_dev, mtr->mtr_id);
+
 		return NULL;
+	} else {
+		if (mtr)
+			cn10k_mtr_connect(eth_dev, mtr->mtr_id);
+	}
 
 	mark_actions = roc_npc_mark_actions_get(npc);
 
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 8d94d873bb..aee83b5abb 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -457,6 +457,24 @@ int cnxk_nix_dev_get_reg(struct rte_eth_dev *eth_dev,
 
 /* Other private functions */
 int nix_recalc_mtu(struct rte_eth_dev *eth_dev);
+int nix_mtr_validate(struct rte_eth_dev *dev, uint32_t id);
+int nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id,
+			   struct cnxk_mtr_policy_node **policy);
+int nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id,
+		      uint32_t queue_num, const uint16_t *queue);
+int nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id,
+			 uint32_t prev_id, uint32_t next_id);
+int nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id);
+struct cnxk_meter_node *nix_get_mtr(struct rte_eth_dev *eth_dev,
+				    uint32_t cur_id);
+int nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id,
+			 uint32_t level);
+int nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id);
+int nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id);
+int nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
+				  uint32_t *prev_id, uint32_t *next_id,
+				  struct cnxk_mtr_policy_node *policy,
+				  int *tree_level);
 
 /* Inlines */
 static __rte_always_inline uint64_t
diff --git a/drivers/net/cnxk/cnxk_rte_flow.c b/drivers/net/cnxk/cnxk_rte_flow.c
index 32c1b5dee5..56dcd36c61 100644
--- a/drivers/net/cnxk/cnxk_rte_flow.c
+++ b/drivers/net/cnxk/cnxk_rte_flow.c
@@ -195,6 +195,10 @@ cnxk_map_actions(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 				ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
 			in_actions[i].conf = actions->conf;
 			break;
+		case RTE_FLOW_ACTION_TYPE_METER:
+			in_actions[i].type = ROC_NPC_ACTION_TYPE_METER;
+			in_actions[i].conf = actions->conf;
+			break;
 		default:
 			plt_npc_dbg("Action is not supported = %d",
 				    actions->type);
-- 
2.25.1


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

* Re: [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (25 preceding siblings ...)
  2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 27/27] net/cnxk: support meter action to flow create skori
@ 2021-09-30 10:00   ` Kinsella, Ray
  2021-10-02 13:56     ` Jerin Jacob
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
  27 siblings, 1 reply; 116+ messages in thread
From: Kinsella, Ray @ 2021-09-30 10:00 UTC (permalink / raw)
  To: skori, Nithin Dabilpuram, Kiran Kumar K, Satha Rao; +Cc: dev



On 30/09/2021 10:08, skori@marvell.com wrote:
> From: Sunil Kumar Kori <skori@marvell.com>
> 
> To support ingress policer on CN10K, MBOX interfaces and HW
> definitions are synced.
> 
> Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
> ---
> v3:
>  - Rebase support on latest DPDK
>  - Handled multilevel chaining for tree hierarchy
>  - Fix naming convention
> v2:
>  - Rebase support on latest DPDK
>  - Handled multilevel chaining for linear hierarchy
>  - Review comments incorporated
> 
>  drivers/common/cnxk/hw/nix.h   | 13 ++++++++++---
>  drivers/common/cnxk/roc_mbox.h | 34 +++++++++++++++++++++++++++++++++-
>  2 files changed, 43 insertions(+), 4 deletions(-)
> 
Acked-by: Ray Kinsella <mdr@ashroe.eu>
(for the series).

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

* Re: [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions
  2021-09-30 10:00   ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions Kinsella, Ray
@ 2021-10-02 13:56     ` Jerin Jacob
  0 siblings, 0 replies; 116+ messages in thread
From: Jerin Jacob @ 2021-10-02 13:56 UTC (permalink / raw)
  To: Kinsella, Ray
  Cc: Sunil Kumar Kori, Nithin Dabilpuram, Kiran Kumar K, Satha Rao, dpdk-dev

On Thu, Sep 30, 2021 at 3:31 PM Kinsella, Ray <mdr@ashroe.eu> wrote:
>
>
>
> On 30/09/2021 10:08, skori@marvell.com wrote:
> > From: Sunil Kumar Kori <skori@marvell.com>
> >
> > To support ingress policer on CN10K, MBOX interfaces and HW
> > definitions are synced.
> >
> > Signed-off-by: Sunil Kumar Kori <skori@marvell.com>

# Please add cover letter
# Please update the release notes for this feature
# Please rebase to next-net-mrvl and fix following issues
[for-next-net]dell[dpdk-next-net-mrvl] $ git pw series apply 19286 &&
rm -rf /tmp/k/* && git format-patch HEAD~27 -o /tmp/k/ && git reset
--hard HEAD~27
Applying: common/cnxk: update policer MBOX APIs and HW definitions
Applying: common/cnxk: support RoC API to get level to index
Using index info to reconstruct a base tree...
M       drivers/common/cnxk/meson.build
M       drivers/common/cnxk/roc_nix.h
M       drivers/common/cnxk/roc_nix_priv.h
M       drivers/common/cnxk/roc_utils.c
M       drivers/common/cnxk/version.map
Falling back to patching base and 3-way merge...
Auto-merging drivers/common/cnxk/version.map
Auto-merging drivers/common/cnxk/roc_utils.c
Auto-merging drivers/common/cnxk/roc_nix_priv.h
Auto-merging drivers/common/cnxk/roc_nix.h
CONFLICT (content): Merge conflict in drivers/common/cnxk/roc_nix.h
Auto-merging drivers/common/cnxk/meson.build
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 common/cnxk: support RoC API to get level to index
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".


> > ---
> > v3:
> >  - Rebase support on latest DPDK
> >  - Handled multilevel chaining for tree hierarchy
> >  - Fix naming convention
> > v2:
> >  - Rebase support on latest DPDK
> >  - Handled multilevel chaining for linear hierarchy
> >  - Review comments incorporated
> >
> >  drivers/common/cnxk/hw/nix.h   | 13 ++++++++++---
> >  drivers/common/cnxk/roc_mbox.h | 34 +++++++++++++++++++++++++++++++++-
> >  2 files changed, 43 insertions(+), 4 deletions(-)
> >
> Acked-by: Ray Kinsella <mdr@ashroe.eu>
> (for the series).

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

* [dpdk-dev] [PATCH v4 00/28] Support ingress policer
  2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
                     ` (26 preceding siblings ...)
  2021-09-30 10:00   ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions Kinsella, Ray
@ 2021-10-11 15:50   ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 01/28] common/cnxk: update policer MBOX APIs and HW definitions skori
                       ` (28 more replies)
  27 siblings, 29 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  Cc: dev, Sunil Kumar Kori

From: Sunil Kumar Kori <skori@marvell.com>

Series adds support for ingress meter for CN10K platform. Series is divided
in following two logical implementation:

 - common/cnxk: It implements RoC APIs over MBOX interfaces which are by network drivers.

	common/cnxk: update policer MBOX APIs and HW definitions
	common/cnxk: support RoC API to get level to index
	common/cnxk: support RoC API to get profile count
	common/cnxk: support RoC API to alloc bandwidth profiles
	common/cnxk: support RoC API to free bandwidth profiles
	common/cnxk: support RoC API to configure bandwidth profile
	common/cnxk: support RoC API to toggle profile state
	common/cnxk: support RoC API to dump bandwidth profile
	common/cnxk: support RoC API to setup precolor table
	common/cnxk: support RoC API to connect bandwidth profiles
	common/cnxk: support RoC API to get stats to index
	common/cnxk: support RoC API to read profile statistics
	common/cnxk: support RoC API to reset profile stats
	common/cnxk: support meter in action list

 - net/cnxk: It implenets ethdev ops for various metering operations.
	For cn9k platform, ops are registerded as NULL because cn9k does
	not support metering.

	net/cnxk: support meter ops get API
	net/cnxk: support ops to get meter capabilities
	net/cnxk: support ops to create meter profile
	net/cnxk: support ops to delete meter profile
	net/cnxk: support ops to validate meter policy
	net/cnxk: support ops to create meter policy
	net/cnxk: support ops to delete meter policy
	net/cnxk: support ops to create meter
	net/cnxk: support ops to delete meter
	net/cnxk: support ops to enable/disable meter
	net/cnxk: support ops to update precolor DSCP table
	net/cnxk: support ops to read/update meter stats
	net/cnxk: support meter action to flow create
	net/cnxk: support meter action to flow destroy

 doc/guides/nics/features/cnxk.ini      |    1 +
 doc/guides/nics/features/cnxk_vf.ini   |    1 +
 doc/guides/rel_notes/release_21_11.rst |    1 +
 drivers/common/cnxk/hw/nix.h           |   62 +-
 drivers/common/cnxk/meson.build        |    1 +
 drivers/common/cnxk/roc_mbox.h         |   34 +-
 drivers/common/cnxk/roc_nix.h          |  164 +++
 drivers/common/cnxk/roc_nix_bpf.c      | 1149 ++++++++++++++++++++
 drivers/common/cnxk/roc_nix_priv.h     |    1 +
 drivers/common/cnxk/roc_npc.c          |    7 +
 drivers/common/cnxk/roc_npc.h          |    8 +-
 drivers/common/cnxk/roc_platform.h     |    1 +
 drivers/common/cnxk/roc_utils.c        |    3 +
 drivers/common/cnxk/version.map        |   15 +
 drivers/net/cnxk/cn10k_rte_flow.c      |  193 +++-
 drivers/net/cnxk/cnxk_ethdev.c         |   57 +
 drivers/net/cnxk/cnxk_ethdev.h         |   92 ++
 drivers/net/cnxk/cnxk_ethdev_mtr.c     | 1341 ++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_rte_flow.c       |    4 +
 drivers/net/cnxk/meson.build           |    1 +
 20 files changed, 3129 insertions(+), 7 deletions(-)
 create mode 100644 drivers/common/cnxk/roc_nix_bpf.c
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mtr.c

-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 01/28] common/cnxk: update policer MBOX APIs and HW definitions
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
@ 2021-10-11 15:50     ` skori
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 02/28] common/cnxk: support RoC API to get level to index skori
                       ` (27 subsequent siblings)
  28 siblings, 1 reply; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Ray Kinsella

From: Sunil Kumar Kori <skori@marvell.com>

To support ingress policer on CN10K, MBOX interfaces and HW
definitions are synced.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Acked-by: Ray Kinsella <mdr@ashroe.eu>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/hw/nix.h   | 13 ++++++++++---
 drivers/common/cnxk/roc_mbox.h | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/common/cnxk/hw/nix.h b/drivers/common/cnxk/hw/nix.h
index 6a0eb019ac..7685b7dc1b 100644
--- a/drivers/common/cnxk/hw/nix.h
+++ b/drivers/common/cnxk/hw/nix.h
@@ -692,9 +692,16 @@
 #define NIX_RX_BAND_PROF_ACTIONRESULT_DROP (0x1ull) /* [CN10K, .) */
 #define NIX_RX_BAND_PROF_ACTIONRESULT_RED  (0x2ull) /* [CN10K, .) */
 
-#define NIX_RX_BAND_PROF_LAYER_LEAF   (0x0ull) /* [CN10K, .) */
-#define NIX_RX_BAND_PROF_LAYER_MIDDLE (0x1ull) /* [CN10K, .) */
-#define NIX_RX_BAND_PROF_LAYER_TOP    (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_LEAF    (0x0ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_INVALID (0x1ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_MIDDLE  (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_TOP     (0x3ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_MAX     (0x4ull) /* [CN10K, .) */
+
+#define NIX_RX_BAND_PROF_PC_MODE_VLAN (0x0ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_DSCP (0x1ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_GEN  (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_RSVD (0x3ull) /* [CN10K, .) */
 
 #define NIX_RX_COLORRESULT_GREEN  (0x0ull) /* [CN10K, .) */
 #define NIX_RX_COLORRESULT_YELLOW (0x1ull) /* [CN10K, .) */
diff --git a/drivers/common/cnxk/roc_mbox.h b/drivers/common/cnxk/roc_mbox.h
index 75d1ff1ef3..bc40848450 100644
--- a/drivers/common/cnxk/roc_mbox.h
+++ b/drivers/common/cnxk/roc_mbox.h
@@ -234,7 +234,11 @@ struct mbox_msghdr {
 	  nix_inline_ipsec_lf_cfg, msg_rsp)                                    \
 	M(NIX_CN10K_AQ_ENQ, 0x801b, nix_cn10k_aq_enq, nix_cn10k_aq_enq_req,    \
 	  nix_cn10k_aq_enq_rsp)                                                \
-	M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info)
+	M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info)      \
+	M(NIX_BANDPROF_ALLOC, 0x801d, nix_bandprof_alloc,                      \
+	  nix_bandprof_alloc_req, nix_bandprof_alloc_rsp)                      \
+	M(NIX_BANDPROF_FREE, 0x801e, nix_bandprof_free, nix_bandprof_free_req, \
+	  msg_rsp)
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES                                                   \
@@ -772,6 +776,10 @@ struct nix_cn10k_aq_enq_req {
 		__io struct nix_rsse_s rss;
 		/* Valid when op == WRITE/INIT and ctype == NIX_AQ_CTYPE_MCE */
 		__io struct nix_rx_mce_s mce;
+		/* Valid when op == WRITE/INIT and
+		 * ctype == NIX_AQ_CTYPE_BAND_PROF
+		 */
+		__io struct nix_band_prof_s prof;
 	};
 	/* Mask data when op == WRITE (1=write, 0=don't write) */
 	union {
@@ -785,6 +793,8 @@ struct nix_cn10k_aq_enq_req {
 		__io struct nix_rsse_s rss_mask;
 		/* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_MCE */
 		__io struct nix_rx_mce_s mce_mask;
+		/* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_BAND_PROF */
+		__io struct nix_band_prof_s prof_mask;
 	};
 };
 
@@ -796,6 +806,7 @@ struct nix_cn10k_aq_enq_rsp {
 		struct nix_cq_ctx_s cq;
 		struct nix_rsse_s rss;
 		struct nix_rx_mce_s mce;
+		struct nix_band_prof_s prof;
 	};
 };
 
@@ -1130,6 +1141,27 @@ struct nix_hw_info {
 	uint16_t __io rsvd[15];
 };
 
+struct nix_bandprof_alloc_req {
+	struct mbox_msghdr hdr;
+	/* Count of profiles needed per layer */
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+};
+
+struct nix_bandprof_alloc_rsp {
+	struct mbox_msghdr hdr;
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+
+#define BANDPROF_PER_PFFUNC 64
+	uint16_t __io prof_idx[NIX_RX_BAND_PROF_LAYER_MAX][BANDPROF_PER_PFFUNC];
+};
+
+struct nix_bandprof_free_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io free_all;
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+	uint16_t __io prof_idx[NIX_RX_BAND_PROF_LAYER_MAX][BANDPROF_PER_PFFUNC];
+};
+
 /* SSO mailbox error codes
  * Range 501 - 600.
  */
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 02/28] common/cnxk: support RoC API to get level to index
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 01/28] common/cnxk: update policer MBOX APIs and HW definitions skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 03/28] common/cnxk: support RoC API to get profile count skori
                       ` (26 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform supports policer up to 3 level of hierarchy.
Implement RoC API to get corresponding index for given level.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/meson.build    |  1 +
 drivers/common/cnxk/roc_nix.h      | 12 ++++++++++++
 drivers/common/cnxk/roc_nix_bpf.c  | 22 ++++++++++++++++++++++
 drivers/common/cnxk/roc_nix_priv.h |  1 +
 drivers/common/cnxk/roc_utils.c    |  3 +++
 drivers/common/cnxk/version.map    |  1 +
 6 files changed, 40 insertions(+)
 create mode 100644 drivers/common/cnxk/roc_nix_bpf.c

diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build
index 97db5f087b..32d3ad5087 100644
--- a/drivers/common/cnxk/meson.build
+++ b/drivers/common/cnxk/meson.build
@@ -25,6 +25,7 @@ sources = files(
         'roc_mbox.c',
         'roc_model.c',
         'roc_nix.c',
+        'roc_nix_bpf.c',
         'roc_nix_debug.c',
         'roc_nix_fc.c',
         'roc_nix_irq.c',
diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index b06895a565..bf4fd2f208 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -6,6 +6,8 @@
 #define _ROC_NIX_H_
 
 /* Constants */
+#define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
+
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
 	ROC_NIX_RSS_RETA_SZ_128 = 128,
@@ -29,6 +31,12 @@ enum roc_nix_vlan_type {
 	ROC_NIX_VLAN_TYPE_OUTER = 0x02,
 };
 
+enum roc_nix_bpf_level_flag {
+	ROC_NIX_BPF_LEVEL_F_LEAF = BIT(0),
+	ROC_NIX_BPF_LEVEL_F_MID = BIT(1),
+	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -508,6 +516,10 @@ int __roc_api roc_nix_tm_prepare_rate_limited_tree(struct roc_nix *roc_nix);
 bool __roc_api roc_nix_tm_is_user_hierarchy_enabled(struct roc_nix *nix);
 int __roc_api roc_nix_tm_tree_type_get(struct roc_nix *nix);
 
+/* Ingress Policer API */
+uint8_t __roc_api
+roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
+
 /* MAC */
 int __roc_api roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start);
 int __roc_api roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix,
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
new file mode 100644
index 0000000000..b588cc16e4
--- /dev/null
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell.
+ */
+
+#include "roc_api.h"
+#include "roc_priv.h"
+
+uint8_t
+roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
+{
+	uint8_t idx;
+
+	if (level_f & ROC_NIX_BPF_LEVEL_F_LEAF)
+		idx = 0;
+	else if (level_f & ROC_NIX_BPF_LEVEL_F_MID)
+		idx = 1;
+	else if (level_f & ROC_NIX_BPF_LEVEL_F_TOP)
+		idx = 2;
+	else
+		idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	return idx;
+}
diff --git a/drivers/common/cnxk/roc_nix_priv.h b/drivers/common/cnxk/roc_nix_priv.h
index 7653c5a328..02b1be852d 100644
--- a/drivers/common/cnxk/roc_nix_priv.h
+++ b/drivers/common/cnxk/roc_nix_priv.h
@@ -187,6 +187,7 @@ enum nix_err_status {
 	NIX_ERR_INVALID_RANGE,
 	NIX_ERR_INTERNAL,
 	NIX_ERR_OP_NOTSUP,
+	NIX_ERR_HW_NOTSUP,
 	NIX_ERR_QUEUE_INVALID_RANGE,
 	NIX_ERR_AQ_READ_FAILED,
 	NIX_ERR_AQ_WRITE_FAILED,
diff --git a/drivers/common/cnxk/roc_utils.c b/drivers/common/cnxk/roc_utils.c
index 751486f503..f1b5ef3b70 100644
--- a/drivers/common/cnxk/roc_utils.c
+++ b/drivers/common/cnxk/roc_utils.c
@@ -34,6 +34,9 @@ roc_error_msg_get(int errorcode)
 	case NIX_ERR_OP_NOTSUP:
 		err_msg = "Operation not supported";
 		break;
+	case NIX_ERR_HW_NOTSUP:
+		err_msg = "Hardware does not support";
+		break;
 	case NIX_ERR_QUEUE_INVALID_RANGE:
 		err_msg = "Invalid Queue range";
 		break;
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index ccf8ec157e..c84c229938 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -82,6 +82,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 03/28] common/cnxk: support RoC API to get profile count
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 01/28] common/cnxk: update policer MBOX APIs and HW definitions skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 02/28] common/cnxk: support RoC API to get level to index skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 04/28] common/cnxk: support RoC API to alloc bandwidth profiles skori
                       ` (25 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement interface to get available profile count for given
nixlf.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  5 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 46 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 52 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index bf4fd2f208..4fef6d44e7 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -7,6 +7,7 @@
 
 /* Constants */
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
+#define ROC_NIX_BPF_LEVEL_MAX	      3
 
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
@@ -517,6 +518,10 @@ bool __roc_api roc_nix_tm_is_user_hierarchy_enabled(struct roc_nix *nix);
 int __roc_api roc_nix_tm_tree_type_get(struct roc_nix *nix);
 
 /* Ingress Policer API */
+int __roc_api
+roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX] /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index b588cc16e4..af9dffa90c 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -5,6 +5,14 @@
 #include "roc_api.h"
 #include "roc_priv.h"
 
+#define NIX_MAX_BPF_COUNT_LEAF_LAYER 64
+#define NIX_MAX_BPF_COUNT_MID_LAYER  8
+#define NIX_MAX_BPF_COUNT_TOP_LAYER  1
+
+#define NIX_BPF_LEVEL_F_MASK                                                   \
+	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
+	 ROC_NIX_BPF_LEVEL_F_TOP)
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -20,3 +28,41 @@ roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 		idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
 	return idx;
 }
+
+int
+roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
+{
+	uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
+	uint8_t leaf_idx, mid_idx, top_idx;
+
+	PLT_SET_USED(roc_nix);
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!mask)
+		return NIX_ERR_PARAM;
+
+	/* Currently No MBOX interface is available to get number
+	 * of bandwidth profiles. So numbers per level are hard coded,
+	 * considering 3 RPM blocks and each block has 4 LMAC's.
+	 * So total 12 physical interfaces are in system. Each interface
+	 * supports following bandwidth profiles.
+	 */
+
+	leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
+	mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
+	top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[leaf_idx] = NIX_MAX_BPF_COUNT_LEAF_LAYER;
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[mid_idx] = NIX_MAX_BPF_COUNT_MID_LAYER;
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[top_idx] = NIX_MAX_BPF_COUNT_TOP_LAYER;
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index c84c229938..6990c1f084 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -82,6 +82,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_count_get;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 04/28] common/cnxk: support RoC API to alloc bandwidth profiles
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (2 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 03/28] common/cnxk: support RoC API to get profile count skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 05/28] common/cnxk: support RoC API to free " skori
                       ` (24 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to allocate HW resources i.e. bandwidth
profiles for policer processing on CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  11 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 104 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 3 files changed, 116 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 4fef6d44e7..b192a2b217 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -6,6 +6,7 @@
 #define _ROC_NIX_H_
 
 /* Constants */
+#define ROC_NIX_BPF_PER_PFFUNC	      64
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
 
@@ -38,6 +39,12 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+struct roc_nix_bpf_objs {
+	uint16_t level;
+	uint16_t count;
+	uint16_t ids[ROC_NIX_BPF_PER_PFFUNC];
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -522,6 +529,10 @@ int __roc_api
 roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
+				uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
+				struct roc_nix_bpf_objs *profs /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index af9dffa90c..06394bda07 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -13,6 +13,19 @@
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
 
+static uint8_t sw_to_hw_lvl_map[] = {NIX_RX_BAND_PROF_LAYER_LEAF,
+				     NIX_RX_BAND_PROF_LAYER_MIDDLE,
+				     NIX_RX_BAND_PROF_LAYER_TOP};
+
+static inline struct mbox *
+get_mbox(struct roc_nix *roc_nix)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct dev *dev = &nix->dev;
+
+	return dev->mbox;
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -66,3 +79,94 @@ roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 
 	return 0;
 }
+
+int
+roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		  uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
+		  struct roc_nix_bpf_objs *profs)
+{
+	uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_alloc_req *req;
+	struct nix_bandprof_alloc_rsp *rsp;
+	uint8_t leaf_idx, mid_idx, top_idx;
+	int rc = -ENOSPC, i;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!mask)
+		return NIX_ERR_PARAM;
+
+	leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
+	mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
+	top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
+
+	if ((leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[leaf_idx] > NIX_MAX_BPF_COUNT_LEAF_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	if ((mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[mid_idx] > NIX_MAX_BPF_COUNT_MID_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	if ((top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[top_idx] > NIX_MAX_BPF_COUNT_TOP_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	req = mbox_alloc_msg_nix_bandprof_alloc(mbox);
+	if (req == NULL)
+		goto exit;
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[leaf_idx]] =
+			per_lvl_cnt[leaf_idx];
+	}
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[mid_idx]] =
+			per_lvl_cnt[mid_idx];
+	}
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[top_idx]] =
+			per_lvl_cnt[top_idx];
+	}
+
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		goto exit;
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[leaf_idx].level = leaf_idx;
+		profs[leaf_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[leaf_idx]];
+		for (i = 0; i < profs[leaf_idx].count; i++) {
+			profs[leaf_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[leaf_idx]][i];
+		}
+	}
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[mid_idx].level = mid_idx;
+		profs[mid_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[mid_idx]];
+		for (i = 0; i < profs[mid_idx].count; i++) {
+			profs[mid_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[mid_idx]][i];
+		}
+	}
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[top_idx].level = top_idx;
+		profs[top_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[top_idx]];
+		for (i = 0; i < profs[top_idx].count; i++) {
+			profs[top_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[top_idx]][i];
+		}
+	}
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 6990c1f084..b8863a1155 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -82,6 +82,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_alloc;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 05/28] common/cnxk: support RoC API to free bandwidth profiles
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (3 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 04/28] common/cnxk: support RoC API to alloc bandwidth profiles skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 06/28] common/cnxk: support RoC API to configure bandwidth profile skori
                       ` (23 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC interface to free HW bandwidth profiles on
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  6 +++++
 drivers/common/cnxk/roc_nix_bpf.c | 40 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  2 ++
 3 files changed, 48 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index b192a2b217..a5642337b2 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -533,6 +533,12 @@ int __roc_api roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
 				uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
 				struct roc_nix_bpf_objs *profs /* Out */);
 
+int __roc_api roc_nix_bpf_free(struct roc_nix *roc_nix,
+			       struct roc_nix_bpf_objs *profs,
+			       uint8_t num_prof);
+
+int __roc_api roc_nix_bpf_free_all(struct roc_nix *roc_nix);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 06394bda07..41d31bc6cd 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -170,3 +170,43 @@ roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_free(struct roc_nix *roc_nix, struct roc_nix_bpf_objs *profs,
+		 uint8_t num_prof)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_free_req *req;
+	uint8_t level;
+	int i, j;
+
+	if (num_prof >= NIX_RX_BAND_PROF_LAYER_MAX)
+		return NIX_ERR_INVALID_RANGE;
+
+	req = mbox_alloc_msg_nix_bandprof_free(mbox);
+	if (req == NULL)
+		return -ENOSPC;
+
+	for (i = 0; i < num_prof; i++) {
+		level = sw_to_hw_lvl_map[profs[i].level];
+		req->prof_count[level] = profs[i].count;
+		for (j = 0; j < profs[i].count; j++)
+			req->prof_idx[level][j] = profs[i].ids[j];
+	}
+
+	return mbox_process(mbox);
+}
+
+int
+roc_nix_bpf_free_all(struct roc_nix *roc_nix)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_free_req *req;
+
+	req = mbox_alloc_msg_nix_bandprof_free(mbox);
+	if (req == NULL)
+		return -ENOSPC;
+
+	req->free_all = true;
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index b8863a1155..3d474f8a96 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -84,6 +84,8 @@ INTERNAL {
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_free;
+	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 06/28] common/cnxk: support RoC API to configure bandwidth profile
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (4 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 05/28] common/cnxk: support RoC API to free " skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 07/28] common/cnxk: support RoC API to toggle profile state skori
                       ` (22 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to configure HW bandwidth profile for
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/hw/nix.h      |  49 ++++++
 drivers/common/cnxk/roc_nix.h     |  63 ++++++++
 drivers/common/cnxk/roc_nix_bpf.c | 239 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 4 files changed, 352 insertions(+)

diff --git a/drivers/common/cnxk/hw/nix.h b/drivers/common/cnxk/hw/nix.h
index 7685b7dc1b..b9e65c942f 100644
--- a/drivers/common/cnxk/hw/nix.h
+++ b/drivers/common/cnxk/hw/nix.h
@@ -2113,6 +2113,55 @@ struct nix_lso_format {
 #define NIX_RPM_MAX_HW_FRS  16380UL
 #define NIX_MIN_HW_FRS	    60UL
 
+/** NIX policer rate limits */
+#define NIX_BPF_MAX_RATE_DIV_EXP  12
+#define NIX_BPF_MAX_RATE_EXPONENT 0xf
+#define NIX_BPF_MAX_RATE_MANTISSA 0xff
+
+#define NIX_BPF_RATE_CONST 2000000ULL
+
+/* NIX rate calculation in Bits/Sec
+ *	PIR_ADD = ((256 + NIX_*_PIR[RATE_MANTISSA])
+ *		<< NIX_*_PIR[RATE_EXPONENT]) / 256
+ *	PIR = (2E6 * PIR_ADD / (1 << NIX_*_PIR[RATE_DIVIDER_EXPONENT]))
+ *
+ *	CIR_ADD = ((256 + NIX_*_CIR[RATE_MANTISSA])
+ *		<< NIX_*_CIR[RATE_EXPONENT]) / 256
+ *	CIR = (2E6 * CIR_ADD / (CCLK_TICKS << NIX_*_CIR[RATE_DIVIDER_EXPONENT]))
+ */
+#define NIX_BPF_RATE(exponent, mantissa, div_exp)                              \
+	((NIX_BPF_RATE_CONST * ((256 + (mantissa)) << (exponent))) /           \
+	 (((1ull << (div_exp)) * 256)))
+
+/* Meter rate limits in Bits/Sec */
+#define NIX_BPF_RATE_MIN NIX_BPF_RATE(0, 0, NIX_BPF_MAX_RATE_DIV_EXP)
+#define NIX_BPF_RATE_MAX                                                       \
+	NIX_BPF_RATE(NIX_BPF_MAX_RATE_EXPONENT, NIX_BPF_MAX_RATE_MANTISSA, 0)
+
+#define NIX_BPF_DEFAULT_ADJUST_MANTISSA 511
+#define NIX_BPF_DEFAULT_ADJUST_EXPONENT 0
+
+/** NIX burst limits */
+#define NIX_BPF_MAX_BURST_EXPONENT 0xf
+#define NIX_BPF_MAX_BURST_MANTISSA 0xff
+
+/* NIX burst calculation
+ *	PIR_BURST = ((256 + NIX_*_PIR[BURST_MANTISSA])
+ *		<< (NIX_*_PIR[BURST_EXPONENT] + 1))
+ *			/ 256
+ *
+ *	CIR_BURST = ((256 + NIX_*_CIR[BURST_MANTISSA])
+ *		<< (NIX_*_CIR[BURST_EXPONENT] + 1))
+ *			/ 256
+ */
+#define NIX_BPF_BURST(exponent, mantissa)                                      \
+	(((256 + (mantissa)) << ((exponent) + 1)) / 256)
+
+/** Meter burst limits */
+#define NIX_BPF_BURST_MIN NIX_BPF_BURST(0, 0)
+#define NIX_BPF_BURST_MAX                                                      \
+	NIX_BPF_BURST(NIX_BPF_MAX_BURST_EXPONENT, NIX_BPF_MAX_BURST_MANTISSA)
+
 /* NIX rate limits */
 #define NIX_TM_MAX_RATE_DIV_EXP	 12
 #define NIX_TM_MAX_RATE_EXPONENT 0xf
diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index a5642337b2..c2cc823516 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -39,6 +39,65 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+enum roc_nix_bpf_color {
+	ROC_NIX_BPF_COLOR_GREEN,
+	ROC_NIX_BPF_COLOR_YELLOW,
+	ROC_NIX_BPF_COLOR_RED,
+	ROC_NIX_BPF_COLOR_MAX
+};
+
+enum roc_nix_bpf_algo {
+	ROC_NIX_BPF_ALGO_NONE,
+	ROC_NIX_BPF_ALGO_2698,
+	ROC_NIX_BPF_ALGO_4115,
+	ROC_NIX_BPF_ALGO_2697
+};
+
+enum roc_nix_bpf_lmode { ROC_NIX_BPF_LMODE_BYTE, ROC_NIX_BPF_LMODE_PACKET };
+
+enum roc_nix_bpf_action {
+	ROC_NIX_BPF_ACTION_PASS,
+	ROC_NIX_BPF_ACTION_DROP,
+	ROC_NIX_BPF_ACTION_RED
+};
+
+struct roc_nix_bpf_cfg {
+	enum roc_nix_bpf_algo alg;
+	enum roc_nix_bpf_lmode lmode;
+	enum roc_nix_bpf_color icolor;
+	enum roc_nix_bpf_pc_mode pc_mode;
+	bool tnl_ena;
+	union {
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2697. */
+		struct {
+			uint64_t cir;
+			uint64_t cbs;
+			uint64_t ebs;
+		} algo2697;
+
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2698. */
+		struct {
+			uint64_t cir;
+			uint64_t pir;
+			uint64_t cbs;
+			uint64_t pbs;
+		} algo2698;
+
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_4115. */
+		struct {
+			uint64_t cir;
+			uint64_t eir;
+			uint64_t cbs;
+			uint64_t ebs;
+		} algo4115;
+	};
+
+	enum roc_nix_bpf_action action[ROC_NIX_BPF_COLOR_MAX];
+
+	/* Reserved for future config*/
+	uint32_t rsvd[3];
+};
+
 struct roc_nix_bpf_objs {
 	uint16_t level;
 	uint16_t count;
@@ -539,6 +598,10 @@ int __roc_api roc_nix_bpf_free(struct roc_nix *roc_nix,
 
 int __roc_api roc_nix_bpf_free_all(struct roc_nix *roc_nix);
 
+int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+				 enum roc_nix_bpf_level_flag lvl_flag,
+				 struct roc_nix_bpf_cfg *cfg);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 41d31bc6cd..aa5829ee42 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -26,6 +26,105 @@ get_mbox(struct roc_nix *roc_nix)
 	return dev->mbox;
 }
 
+static inline uint64_t
+meter_rate_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p,
+		  uint64_t *div_exp_p)
+{
+	uint64_t div_exp, exponent, mantissa;
+
+	/* Boundary checks */
+	if (value < NIX_BPF_RATE_MIN || value > NIX_BPF_RATE_MAX)
+		return 0;
+
+	if (value <= NIX_BPF_RATE(0, 0, 0)) {
+		/* Calculate rate div_exp and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * (256 + mantissa)
+		 *              / ((1 << div_exp) * 256))
+		 */
+		div_exp = 0;
+		exponent = 0;
+		mantissa = NIX_BPF_MAX_RATE_MANTISSA;
+
+		while (value < (NIX_BPF_RATE_CONST / (1 << div_exp)))
+			div_exp += 1;
+
+		while (value < ((NIX_BPF_RATE_CONST * (256 + mantissa)) /
+				((1 << div_exp) * 256)))
+			mantissa -= 1;
+	} else {
+		/* Calculate rate exponent and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * ((256 + mantissa) << exponent)) / 256
+		 *
+		 */
+		div_exp = 0;
+		exponent = NIX_BPF_MAX_RATE_EXPONENT;
+		mantissa = NIX_BPF_MAX_RATE_MANTISSA;
+
+		while (value < (NIX_BPF_RATE_CONST * (1 << exponent)))
+			exponent -= 1;
+
+		while (value <
+		       ((NIX_BPF_RATE_CONST * ((256 + mantissa) << exponent)) /
+			256))
+			mantissa -= 1;
+	}
+
+	if (div_exp > NIX_BPF_MAX_RATE_DIV_EXP ||
+	    exponent > NIX_BPF_MAX_RATE_EXPONENT ||
+	    mantissa > NIX_BPF_MAX_RATE_MANTISSA)
+		return 0;
+
+	if (div_exp_p)
+		*div_exp_p = div_exp;
+	if (exponent_p)
+		*exponent_p = exponent;
+	if (mantissa_p)
+		*mantissa_p = mantissa;
+
+	/* Calculate real rate value */
+	return NIX_BPF_RATE(exponent, mantissa, div_exp);
+}
+
+static inline uint64_t
+meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
+{
+	uint64_t exponent, mantissa;
+
+	if (value < NIX_BPF_BURST_MIN || value > NIX_BPF_BURST_MAX)
+		return 0;
+
+	/* Calculate burst exponent and mantissa using
+	 * the following formula:
+	 *
+	 * value = (((256 + mantissa) << (exponent + 1)
+	 / 256)
+	 *
+	 */
+	exponent = NIX_BPF_MAX_BURST_EXPONENT;
+	mantissa = NIX_BPF_MAX_BURST_MANTISSA;
+
+	while (value < (1ull << (exponent + 1)))
+		exponent -= 1;
+
+	while (value < ((256 + mantissa) << (exponent + 1)) / 256)
+		mantissa -= 1;
+
+	if (exponent > NIX_BPF_MAX_BURST_EXPONENT ||
+	    mantissa > NIX_BPF_MAX_BURST_MANTISSA)
+		return 0;
+
+	if (exponent_p)
+		*exponent_p = exponent;
+	if (mantissa_p)
+		*mantissa_p = mantissa;
+
+	return NIX_BPF_BURST(exponent, mantissa);
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -210,3 +309,143 @@ roc_nix_bpf_free_all(struct roc_nix *roc_nix)
 	req->free_all = true;
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+		   enum roc_nix_bpf_level_flag lvl_flag,
+		   struct roc_nix_bpf_cfg *cfg)
+{
+	uint64_t exponent_p = 0, mantissa_p = 0, div_exp_p = 0;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!cfg)
+		return NIX_ERR_PARAM;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	aq->prof.adjust_exponent = NIX_BPF_DEFAULT_ADJUST_EXPONENT;
+	aq->prof.adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA;
+	if (cfg->lmode == ROC_NIX_BPF_LMODE_BYTE)
+		aq->prof.adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA / 2;
+
+	aq->prof_mask.adjust_exponent = ~(aq->prof_mask.adjust_exponent);
+	aq->prof_mask.adjust_mantissa = ~(aq->prof_mask.adjust_mantissa);
+
+	switch (cfg->alg) {
+	case ROC_NIX_BPF_ALGO_2697:
+		meter_rate_to_nix(cfg->algo2697.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2697.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2697.ebs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	case ROC_NIX_BPF_ALGO_2698:
+		meter_rate_to_nix(cfg->algo2698.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_rate_to_nix(cfg->algo2698.pir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.peir_mantissa = mantissa_p;
+		aq->prof.peir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2698.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2698.pbs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	case ROC_NIX_BPF_ALGO_4115:
+		meter_rate_to_nix(cfg->algo4115.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_rate_to_nix(cfg->algo4115.eir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.peir_mantissa = mantissa_p;
+		aq->prof.peir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo4115.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo4115.ebs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	default:
+		return NIX_ERR_PARAM;
+	}
+
+	aq->prof.lmode = cfg->lmode;
+	aq->prof.icolor = cfg->icolor;
+	aq->prof.pc_mode = cfg->pc_mode;
+	aq->prof.tnl_ena = cfg->tnl_ena;
+	aq->prof.gc_action = cfg->action[ROC_NIX_BPF_COLOR_GREEN];
+	aq->prof.yc_action = cfg->action[ROC_NIX_BPF_COLOR_YELLOW];
+	aq->prof.rc_action = cfg->action[ROC_NIX_BPF_COLOR_RED];
+
+	aq->prof_mask.lmode = ~(aq->prof_mask.lmode);
+	aq->prof_mask.icolor = ~(aq->prof_mask.icolor);
+	aq->prof_mask.pc_mode = ~(aq->prof_mask.pc_mode);
+	aq->prof_mask.tnl_ena = ~(aq->prof_mask.tnl_ena);
+	aq->prof_mask.gc_action = ~(aq->prof_mask.gc_action);
+	aq->prof_mask.yc_action = ~(aq->prof_mask.yc_action);
+	aq->prof_mask.rc_action = ~(aq->prof_mask.rc_action);
+
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 3d474f8a96..f34fd3b4a4 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -83,6 +83,7 @@ INTERNAL {
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
+	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 07/28] common/cnxk: support RoC API to toggle profile state
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (5 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 06/28] common/cnxk: support RoC API to configure bandwidth profile skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 08/28] common/cnxk: support RoC API to dump bandwidth profile skori
                       ` (21 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to enable or disable HW bandwidth profiles
on CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  4 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 39 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 44 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index c2cc823516..5b3bf38a82 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -217,6 +217,7 @@ struct roc_nix_stats_queue {
 struct roc_nix_rq {
 	/* Input parameters */
 	uint16_t qid;
+	uint16_t bpf_id;
 	uint64_t aura_handle;
 	bool ipsech_ena;
 	uint16_t first_skip;
@@ -602,6 +603,9 @@ int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 				 enum roc_nix_bpf_level_flag lvl_flag,
 				 struct roc_nix_bpf_cfg *cfg);
 
+int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
+				  struct roc_nix_rq *rq, bool enable);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index aa5829ee42..c61a697f1a 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -449,3 +449,42 @@ roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id, struct roc_nix_rq *rq,
+		    bool enable)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (rq->qid >= nix->nb_rx_queues)
+		return NIX_ERR_QUEUE_INVALID_RANGE;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = rq->qid;
+	aq->ctype = NIX_AQ_CTYPE_RQ;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	aq->rq.policer_ena = enable;
+	aq->rq_mask.policer_ena = ~(aq->rq_mask.policer_ena);
+	if (enable) {
+		aq->rq.band_prof_id = id;
+		aq->rq_mask.band_prof_id = ~(aq->rq_mask.band_prof_id);
+	}
+
+	rc = mbox_process(mbox);
+	if (rc)
+		goto exit;
+
+	rq->bpf_id = id;
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index f34fd3b4a4..05b19beaa2 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -85,6 +85,7 @@ INTERNAL {
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_ena_dis;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 08/28] common/cnxk: support RoC API to dump bandwidth profile
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (6 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 07/28] common/cnxk: support RoC API to toggle profile state skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 09/28] common/cnxk: support RoC API to setup precolor table skori
                       ` (20 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to dump bandwidth profile on CN10K
platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h      |  3 ++
 drivers/common/cnxk/roc_nix_bpf.c  | 86 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_platform.h |  1 +
 drivers/common/cnxk/version.map    |  1 +
 4 files changed, 91 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 5b3bf38a82..d7e8dd94e3 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -606,6 +606,9 @@ int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
 				  struct roc_nix_rq *rq, bool enable);
 
+int __roc_api roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
+			       enum roc_nix_bpf_level_flag lvl_flag);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index c61a697f1a..8181753220 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -125,6 +125,60 @@ meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
 	return NIX_BPF_BURST(exponent, mantissa);
 }
 
+static inline void
+nix_lf_bpf_dump(__io struct nix_band_prof_s *bpf)
+{
+	plt_dump("W0: cir_mantissa  \t\t\t%d\nW0: pebs_mantissa \t\t\t0x%03x",
+		 bpf->cir_mantissa, bpf->pebs_mantissa);
+	plt_dump("W0: peir_matissa \t\t\t\t%d\nW0: cbs_exponent \t\t\t%d",
+		 bpf->peir_mantissa, bpf->cbs_exponent);
+	plt_dump("W0: cir_exponent \t\t\t%d\nW0: pebs_exponent \t\t\t%d",
+		 bpf->cir_exponent, bpf->pebs_exponent);
+	plt_dump("W0: peir_exponent \t\t\t%d\n", bpf->peir_exponent);
+	plt_dump("W0: tnl_ena \t\t\t%d\n", bpf->tnl_ena);
+	plt_dump("W0: icolor \t\t\t%d\n", bpf->icolor);
+	plt_dump("W0: pc_mode \t\t\t%d\n", bpf->pc_mode);
+	plt_dump("W1: hl_en \t\t%d\nW1: band_prof_id \t\t%d", bpf->hl_en,
+		 bpf->band_prof_id);
+	plt_dump("W1: meter_algo \t\t%d\nW1: rc_action \t\t%d", bpf->meter_algo,
+		 bpf->rc_action);
+	plt_dump("W1: yc_action \t\t\t%d\nW1: gc_action \t\t\t%d",
+		 bpf->yc_action, bpf->gc_action);
+	plt_dump("W1: adjust_mantissa\t\t\t%d\nW1: adjust_exponent \t\t\t%d",
+		 bpf->adjust_mantissa, bpf->adjust_exponent);
+	plt_dump("W1: rdiv \t\t\t%d\n", bpf->rdiv);
+	plt_dump("W1: l_select \t\t%d\nW2: lmode \t\t%d", bpf->l_sellect,
+		 bpf->lmode);
+	plt_dump("W1: cbs_mantissa \t\t\t%d\n", bpf->cbs_mantissa);
+	plt_dump("W2: tsa \t\t\t0x%" PRIx64 "\n", (uint64_t)bpf->ts);
+	plt_dump("W3: c_accum \t\t%d\nW3: pe_accum \t\t%d", bpf->c_accum,
+		 bpf->pe_accum);
+	plt_dump("W4: green_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_pkt_pass);
+	plt_dump("W5: yellow_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_pkt_pass);
+	plt_dump("W6: red_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_pkt_pass);
+	plt_dump("W7: green_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_octs_pass);
+	plt_dump("W8: yellow_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_octs_pass);
+	plt_dump("W9: red_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_octs_pass);
+	plt_dump("W10: green_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_pkt_drop);
+	plt_dump("W11: yellow_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_pkt_drop);
+	plt_dump("W12: red_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_pkt_drop);
+	plt_dump("W13: green_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_octs_drop);
+	plt_dump("W14: yellow_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_octs_drop);
+	plt_dump("W15: red_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_octs_drop);
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -488,3 +542,35 @@ roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id, struct roc_nix_rq *rq,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
+		 enum roc_nix_bpf_level_flag lvl_flag)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_rsp *rsp;
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_READ;
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (!rc) {
+		plt_dump("============= band prof id =%d ===============", id);
+		nix_lf_bpf_dump(&rsp->prof);
+	}
+
+	return rc;
+}
diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h
index 241655b334..3a586d3617 100644
--- a/drivers/common/cnxk/roc_platform.h
+++ b/drivers/common/cnxk/roc_platform.h
@@ -158,6 +158,7 @@ extern int cnxk_logtype_tm;
 #define plt_info(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
 #define plt_warn(fmt, args...) RTE_LOG(WARNING, PMD, fmt "\n", ##args)
 #define plt_print(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
+#define plt_dump(fmt, ...)      fprintf(stderr, fmt "\n", ##__VA_ARGS__)
 
 /**
  * Log debug message if given subsystem logging is enabled.
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 05b19beaa2..959250ea8e 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -85,6 +85,7 @@ INTERNAL {
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_dump;
 	roc_nix_bpf_ena_dis;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 09/28] common/cnxk: support RoC API to setup precolor table
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (7 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 08/28] common/cnxk: support RoC API to dump bandwidth profile skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 10/28] common/cnxk: support RoC API to connect bandwidth profiles skori
                       ` (19 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

For initial coloring of input packet, CN10K platform maintains
precolor table for VLAN, DSCP and Generic. Implement RoC
interface to setup pre color table.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  20 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 193 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 3 files changed, 214 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index d7e8dd94e3..d125941c5c 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -39,6 +39,15 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+enum roc_nix_bpf_pc_mode {
+	ROC_NIX_BPF_PC_MODE_VLAN_INNER,
+	ROC_NIX_BPF_PC_MODE_VLAN_OUTER,
+	ROC_NIX_BPF_PC_MODE_DSCP_INNER,
+	ROC_NIX_BPF_PC_MODE_DSCP_OUTER,
+	ROC_NIX_BPF_PC_MODE_GEN_INNER,
+	ROC_NIX_BPF_PC_MODE_GEN_OUTER
+};
+
 enum roc_nix_bpf_color {
 	ROC_NIX_BPF_COLOR_GREEN,
 	ROC_NIX_BPF_COLOR_YELLOW,
@@ -104,6 +113,13 @@ struct roc_nix_bpf_objs {
 	uint16_t ids[ROC_NIX_BPF_PER_PFFUNC];
 };
 
+struct roc_nix_bpf_precolor {
+#define ROC_NIX_BPF_PRE_COLOR_MAX 64
+	uint8_t count;
+	enum roc_nix_bpf_pc_mode mode;
+	enum roc_nix_bpf_color color[ROC_NIX_BPF_PRE_COLOR_MAX];
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -609,6 +625,10 @@ int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
 int __roc_api roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
 			       enum roc_nix_bpf_level_flag lvl_flag);
 
+int __roc_api roc_nix_bpf_pre_color_tbl_setup(
+	struct roc_nix *roc_nix, uint16_t id,
+	enum roc_nix_bpf_level_flag lvl_flag, struct roc_nix_bpf_precolor *tbl);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 8181753220..8c84bbb656 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -9,6 +9,10 @@
 #define NIX_MAX_BPF_COUNT_MID_LAYER  8
 #define NIX_MAX_BPF_COUNT_TOP_LAYER  1
 
+#define NIX_BPF_PRECOLOR_GEN_TABLE_SIZE	 16
+#define NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE 16
+#define NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE 64
+
 #define NIX_BPF_LEVEL_F_MASK                                                   \
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
@@ -179,6 +183,107 @@ nix_lf_bpf_dump(__io struct nix_band_prof_s *bpf)
 		 (uint64_t)bpf->red_octs_drop);
 }
 
+static inline void
+nix_precolor_conv_table_write(struct roc_nix *roc_nix, uint64_t val,
+			      uint32_t off)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	int64_t *addr;
+
+	addr = PLT_PTR_ADD(nix->base, off);
+	/* FIXME: Currently writing to this register throwing kernel dump.
+	 * plt_write64(val, addr);
+	 */
+	PLT_SET_USED(val);
+	PLT_SET_USED(addr);
+}
+
+static uint8_t
+nix_precolor_vlan_table_update(struct roc_nix *roc_nix,
+			       struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val = 0, i;
+	uint8_t tn_ena;
+	uint32_t off;
+
+	for (i = 0; i < tbl->count; i++)
+		val |= (((uint64_t)tbl->color[i]) << (2 * i));
+
+	if (tbl->mode == ROC_NIX_BPF_PC_MODE_VLAN_INNER) {
+		off = NIX_LF_RX_VLAN1_COLOR_CONV;
+		tn_ena = true;
+	} else {
+		off = NIX_LF_RX_VLAN0_COLOR_CONV;
+		tn_ena = false;
+	}
+
+	nix_precolor_conv_table_write(roc_nix, val, off);
+	return tn_ena;
+}
+
+static uint8_t
+nix_precolor_inner_dscp_table_update(struct roc_nix *roc_nix,
+				     struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val_lo = 0, val_hi = 0, i, j;
+
+	for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
+		val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	for (j = 0; i < tbl->count; i++, j++)
+		val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	nix_precolor_conv_table_write(roc_nix, val_lo,
+				      NIX_LF_RX_IIP_COLOR_CONV_LO);
+	nix_precolor_conv_table_write(roc_nix, val_hi,
+				      NIX_LF_RX_IIP_COLOR_CONV_HI);
+
+	return true;
+}
+
+static uint8_t
+nix_precolor_outer_dscp_table_update(struct roc_nix *roc_nix,
+				     struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val_lo = 0, val_hi = 0, i, j;
+
+	for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
+		val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	for (j = 0; i < tbl->count; i++, j++)
+		val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	nix_precolor_conv_table_write(roc_nix, val_lo,
+				      NIX_LF_RX_OIP_COLOR_CONV_LO);
+	nix_precolor_conv_table_write(roc_nix, val_hi,
+				      NIX_LF_RX_OIP_COLOR_CONV_HI);
+
+	return false;
+}
+
+static uint8_t
+nix_precolor_gen_table_update(struct roc_nix *roc_nix,
+			      struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val = 0, i;
+	uint8_t tn_ena;
+	uint32_t off;
+
+	for (i = 0; i < tbl->count; i++)
+		val |= (((uint64_t)tbl->color[i]) << (2 * i));
+
+	if (tbl->mode == ROC_NIX_BPF_PC_MODE_GEN_INNER) {
+		off = NIX_LF_RX_GEN_COLOR_CONVX(1);
+		tn_ena = true;
+	} else {
+		off = NIX_LF_RX_GEN_COLOR_CONVX(0);
+		tn_ena = false;
+	}
+
+	nix_precolor_conv_table_write(roc_nix, val, off);
+	return tn_ena;
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -574,3 +679,91 @@ roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
 
 	return rc;
 }
+
+int
+roc_nix_bpf_pre_color_tbl_setup(struct roc_nix *roc_nix, uint16_t id,
+				enum roc_nix_bpf_level_flag lvl_flag,
+				struct roc_nix_bpf_precolor *tbl)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t pc_mode, tn_ena;
+	uint8_t level_idx;
+	int rc;
+
+	if (!tbl || !tbl->count)
+		return NIX_ERR_PARAM;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	switch (tbl->mode) {
+	case ROC_NIX_BPF_PC_MODE_VLAN_INNER:
+	case ROC_NIX_BPF_PC_MODE_VLAN_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_vlan_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_VLAN;
+		break;
+	case ROC_NIX_BPF_PC_MODE_DSCP_INNER:
+		if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_inner_dscp_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
+		break;
+	case ROC_NIX_BPF_PC_MODE_DSCP_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_outer_dscp_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
+		break;
+	case ROC_NIX_BPF_PC_MODE_GEN_INNER:
+	case ROC_NIX_BPF_PC_MODE_GEN_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_GEN_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_GEN_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+
+		tn_ena = nix_precolor_gen_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_GEN;
+		break;
+	default:
+		rc = NIX_ERR_PARAM;
+		goto exit;
+	}
+
+	/* Update corresponding bandwidth profile too */
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+	aq->prof.pc_mode = pc_mode;
+	aq->prof.tnl_ena = tn_ena;
+	aq->prof_mask.pc_mode = ~(aq->prof_mask.pc_mode);
+	aq->prof_mask.tnl_ena = ~(aq->prof_mask.tnl_ena);
+
+	return mbox_process(mbox);
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 959250ea8e..836cbec4dc 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -90,6 +90,7 @@ INTERNAL {
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
+	roc_nix_bpf_pre_color_tbl_setup;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 10/28] common/cnxk: support RoC API to connect bandwidth profiles
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (8 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 09/28] common/cnxk: support RoC API to setup precolor table skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 11/28] common/cnxk: support RoC API to get stats to index skori
                       ` (18 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

To maintain chain of bandwidth profiles, they needs to be
connected. Implement RoC API to connect two bandwidth profiles
at different levels.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  6 ++++++
 drivers/common/cnxk/roc_nix_bpf.c | 36 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 43 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index d125941c5c..be24d20462 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -7,6 +7,7 @@
 
 /* Constants */
 #define ROC_NIX_BPF_PER_PFFUNC	      64
+#define ROC_NIX_BPF_ID_INVALID	      0xFFFF
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
 
@@ -629,6 +630,11 @@ int __roc_api roc_nix_bpf_pre_color_tbl_setup(
 	struct roc_nix *roc_nix, uint16_t id,
 	enum roc_nix_bpf_level_flag lvl_flag, struct roc_nix_bpf_precolor *tbl);
 
+/* Use ROC_NIX_BPF_ID_INVALID as dst_id to disconnect */
+int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
+				  enum roc_nix_bpf_level_flag lvl_flag,
+				  uint16_t src_id, uint16_t dst_id);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 8c84bbb656..807723f7b7 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -767,3 +767,39 @@ roc_nix_bpf_pre_color_tbl_setup(struct roc_nix *roc_nix, uint16_t id,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_connect(struct roc_nix *roc_nix,
+		    enum roc_nix_bpf_level_flag lvl_flag, uint16_t src_id,
+		    uint16_t dst_id)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | src_id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	if (dst_id == ROC_NIX_BPF_ID_INVALID) {
+		aq->prof.hl_en = false;
+		aq->prof_mask.hl_en = ~(aq->prof_mask.hl_en);
+	} else {
+		aq->prof.hl_en = true;
+		aq->prof.band_prof_id = dst_id;
+		aq->prof_mask.hl_en = ~(aq->prof_mask.hl_en);
+		aq->prof_mask.band_prof_id = ~(aq->prof_mask.band_prof_id);
+	}
+
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 836cbec4dc..dfd2cdc287 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -84,6 +84,7 @@ INTERNAL {
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
+	roc_nix_bpf_connect;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_dump;
 	roc_nix_bpf_ena_dis;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 11/28] common/cnxk: support RoC API to get stats to index
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (9 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 10/28] common/cnxk: support RoC API to connect bandwidth profiles skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 12/28] common/cnxk: support RoC API to read profile statistics skori
                       ` (17 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform supports different stats for HW bandwidth profiles.
Implement RoC API to get index for given stats type.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     | 18 ++++++++++++++++
 drivers/common/cnxk/roc_nix_bpf.c | 34 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 53 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index be24d20462..c6cf42e8f4 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -10,6 +10,7 @@
 #define ROC_NIX_BPF_ID_INVALID	      0xFFFF
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
+#define ROC_NIX_BPF_STATS_MAX	      12
 
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
@@ -71,6 +72,21 @@ enum roc_nix_bpf_action {
 	ROC_NIX_BPF_ACTION_RED
 };
 
+enum roc_nix_bpf_stats {
+	ROC_NIX_BPF_GREEN_PKT_F_PASS = BIT_ULL(0),
+	ROC_NIX_BPF_GREEN_OCTS_F_PASS = BIT_ULL(1),
+	ROC_NIX_BPF_GREEN_PKT_F_DROP = BIT_ULL(2),
+	ROC_NIX_BPF_GREEN_OCTS_F_DROP = BIT_ULL(3),
+	ROC_NIX_BPF_YELLOW_PKT_F_PASS = BIT_ULL(4),
+	ROC_NIX_BPF_YELLOW_OCTS_F_PASS = BIT_ULL(5),
+	ROC_NIX_BPF_YELLOW_PKT_F_DROP = BIT_ULL(6),
+	ROC_NIX_BPF_YELLOW_OCTS_F_DROP = BIT_ULL(7),
+	ROC_NIX_BPF_RED_PKT_F_PASS = BIT_ULL(8),
+	ROC_NIX_BPF_RED_OCTS_F_PASS = BIT_ULL(9),
+	ROC_NIX_BPF_RED_PKT_F_DROP = BIT_ULL(10),
+	ROC_NIX_BPF_RED_OCTS_F_DROP = BIT_ULL(11),
+};
+
 struct roc_nix_bpf_cfg {
 	enum roc_nix_bpf_algo alg;
 	enum roc_nix_bpf_lmode lmode;
@@ -638,6 +654,8 @@ int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
+uint8_t __roc_api roc_nix_bpf_stats_to_idx(enum roc_nix_bpf_stats lvl_flag);
+
 /* MAC */
 int __roc_api roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start);
 int __roc_api roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix,
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 807723f7b7..7c1ac9d728 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -300,6 +300,40 @@ roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 	return idx;
 }
 
+uint8_t
+roc_nix_bpf_stats_to_idx(enum roc_nix_bpf_stats level_f)
+{
+	uint8_t idx;
+
+	if (level_f & ROC_NIX_BPF_GREEN_PKT_F_PASS)
+		idx = 0;
+	else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
+		idx = 1;
+	else if (level_f & ROC_NIX_BPF_GREEN_PKT_F_DROP)
+		idx = 2;
+	else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
+		idx = 3;
+	else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
+		idx = 4;
+	else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
+		idx = 5;
+	else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
+		idx = 6;
+	else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
+		idx = 7;
+	else if (level_f & ROC_NIX_BPF_RED_PKT_F_PASS)
+		idx = 8;
+	else if (level_f & ROC_NIX_BPF_RED_OCTS_F_PASS)
+		idx = 9;
+	else if (level_f & ROC_NIX_BPF_RED_PKT_F_DROP)
+		idx = 10;
+	else if (level_f & ROC_NIX_BPF_RED_OCTS_F_DROP)
+		idx = 11;
+	else
+		idx = ROC_NIX_BPF_STATS_MAX;
+	return idx;
+}
+
 int
 roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index dfd2cdc287..e9643f7469 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -92,6 +92,7 @@ INTERNAL {
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_bpf_pre_color_tbl_setup;
+	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 12/28] common/cnxk: support RoC API to read profile statistics
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (10 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 11/28] common/cnxk: support RoC API to get stats to index skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 13/28] common/cnxk: support RoC API to reset profile stats skori
                       ` (16 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform provides statistics per bandwidth profile and
per nixlf. Implement RoC API to read stats for given bandwidth
profile.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |   9 ++
 drivers/common/cnxk/roc_nix_bpf.c | 197 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   2 +
 3 files changed, 208 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index c6cf42e8f4..0416778c11 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -651,6 +651,15 @@ int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
 				  enum roc_nix_bpf_level_flag lvl_flag,
 				  uint16_t src_id, uint16_t dst_id);
 
+int __roc_api
+roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+		       enum roc_nix_bpf_level_flag lvl_flag,
+		       uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
+
+int __roc_api
+roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
+			  uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 7c1ac9d728..a5e3575404 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -17,6 +17,9 @@
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
 
+#define NIX_RD_STATS(val)  plt_read64(nix->base + NIX_LF_RX_STATX(val))
+#define NIX_RST_STATS(val) plt_write64(0, nix->base + NIX_LF_RX_STATX(val))
+
 static uint8_t sw_to_hw_lvl_map[] = {NIX_RX_BAND_PROF_LAYER_LEAF,
 				     NIX_RX_BAND_PROF_LAYER_MIDDLE,
 				     NIX_RX_BAND_PROF_LAYER_TOP};
@@ -837,3 +840,197 @@ roc_nix_bpf_connect(struct roc_nix *roc_nix,
 
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+		       enum roc_nix_bpf_level_flag lvl_flag,
+		       uint64_t stats[ROC_NIX_BPF_STATS_MAX])
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_rsp *rsp;
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_READ;
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		return rc;
+
+	green_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[green_pkt_pass] = rsp->prof.green_pkt_pass;
+
+	if (green_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[green_octs_pass] = rsp->prof.green_octs_pass;
+
+	if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[green_pkt_drop] = rsp->prof.green_pkt_drop;
+
+	if (green_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[green_octs_drop] = rsp->prof.green_octs_pass;
+
+	if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_pkt_pass] = rsp->prof.yellow_pkt_pass;
+
+	if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_octs_pass] = rsp->prof.yellow_octs_pass;
+
+	if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_pkt_drop] = rsp->prof.yellow_pkt_drop;
+
+	if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_octs_drop] = rsp->prof.yellow_octs_drop;
+
+	if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[red_pkt_pass] = rsp->prof.red_pkt_pass;
+
+	if (red_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[red_octs_pass] = rsp->prof.red_octs_pass;
+
+	if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[red_pkt_drop] = rsp->prof.red_pkt_drop;
+
+	if (red_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[red_octs_drop] = rsp->prof.red_octs_drop;
+
+	return 0;
+}
+
+int
+roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
+			  uint64_t stats[ROC_NIX_BPF_STATS_MAX])
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+
+	green_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_PASSED);
+	}
+
+	if (green_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_PASSED);
+	}
+
+	if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_DROP);
+	}
+
+	if (green_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_DROP);
+	}
+
+	if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_PASSED);
+	}
+
+	if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_PASSED);
+	}
+
+	if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_DROP);
+	}
+
+	if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_DROP);
+	}
+
+	if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_PASSED);
+	}
+
+	if (red_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_PASSED);
+	}
+
+	if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_DROP);
+	}
+
+	if (red_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_DROP);
+	}
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index e9643f7469..94a25d58ef 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -91,7 +91,9 @@ INTERNAL {
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
+	roc_nix_bpf_lf_stats_read;
 	roc_nix_bpf_pre_color_tbl_setup;
+	roc_nix_bpf_stats_read;
 	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 13/28] common/cnxk: support RoC API to reset profile stats
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (11 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 12/28] common/cnxk: support RoC API to read profile statistics skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 14/28] common/cnxk: support meter in action list skori
                       ` (15 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to reset stats per bandwidth profile
or per nixlf.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |   7 ++
 drivers/common/cnxk/roc_nix_bpf.c | 113 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   2 +
 3 files changed, 122 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 0416778c11..343bb2f8b7 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -656,10 +656,17 @@ roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
 		       enum roc_nix_bpf_level_flag lvl_flag,
 		       uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_stats_reset(struct roc_nix *roc_nix, uint16_t id,
+				      uint64_t mask,
+				      enum roc_nix_bpf_level_flag lvl_flag);
+
 int __roc_api
 roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 			  uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_lf_stats_reset(struct roc_nix *roc_nix,
+					 uint64_t mask);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index a5e3575404..df57958683 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -937,6 +937,86 @@ roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
 	return 0;
 }
 
+int
+roc_nix_bpf_stats_reset(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+			enum roc_nix_bpf_level_flag lvl_flag)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS) {
+		aq->prof.green_pkt_pass = 0;
+		aq->prof_mask.green_pkt_pass = ~(aq->prof_mask.green_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS) {
+		aq->prof.green_octs_pass = 0;
+		aq->prof_mask.green_octs_pass =
+			~(aq->prof_mask.green_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP) {
+		aq->prof.green_pkt_drop = 0;
+		aq->prof_mask.green_pkt_drop = ~(aq->prof_mask.green_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP) {
+		aq->prof.green_octs_drop = 0;
+		aq->prof_mask.green_octs_drop =
+			~(aq->prof_mask.green_octs_drop);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS) {
+		aq->prof.yellow_pkt_pass = 0;
+		aq->prof_mask.yellow_pkt_pass =
+			~(aq->prof_mask.yellow_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS) {
+		aq->prof.yellow_octs_pass = 0;
+		aq->prof_mask.yellow_octs_pass =
+			~(aq->prof_mask.yellow_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP) {
+		aq->prof.yellow_pkt_drop = 0;
+		aq->prof_mask.yellow_pkt_drop =
+			~(aq->prof_mask.yellow_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP) {
+		aq->prof.yellow_octs_drop = 0;
+		aq->prof_mask.yellow_octs_drop =
+			~(aq->prof_mask.yellow_octs_drop);
+	}
+	if (mask & ROC_NIX_BPF_RED_PKT_F_PASS) {
+		aq->prof.red_pkt_pass = 0;
+		aq->prof_mask.red_pkt_pass = ~(aq->prof_mask.red_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS) {
+		aq->prof.red_octs_pass = 0;
+		aq->prof_mask.red_octs_pass = ~(aq->prof_mask.red_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_RED_PKT_F_DROP) {
+		aq->prof.red_pkt_drop = 0;
+		aq->prof_mask.red_pkt_drop = ~(aq->prof_mask.red_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP) {
+		aq->prof.red_octs_drop = 0;
+		aq->prof_mask.red_octs_drop = ~(aq->prof_mask.red_octs_drop);
+	}
+
+	return mbox_process(mbox);
+}
+
 int
 roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 			  uint64_t stats[ROC_NIX_BPF_STATS_MAX])
@@ -1034,3 +1114,36 @@ roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 
 	return 0;
 }
+
+int
+roc_nix_bpf_lf_stats_reset(struct roc_nix *roc_nix, uint64_t mask)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	if (mask & ROC_NIX_BPF_RED_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_RED_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 94a25d58ef..f5de985224 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -92,8 +92,10 @@ INTERNAL {
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_bpf_lf_stats_read;
+	roc_nix_bpf_lf_stats_reset;
 	roc_nix_bpf_pre_color_tbl_setup;
 	roc_nix_bpf_stats_read;
+	roc_nix_bpf_stats_reset;
 	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 14/28] common/cnxk: support meter in action list
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (12 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 13/28] common/cnxk: support RoC API to reset profile stats skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 15/28] net/cnxk: support meter ops get API skori
                       ` (14 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao; +Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Meter action is added in supported action list.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_npc.c | 7 +++++++
 drivers/common/cnxk/roc_npc.h | 8 +++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/common/cnxk/roc_npc.c b/drivers/common/cnxk/roc_npc.c
index b724ff9401..5a78d9652c 100644
--- a/drivers/common/cnxk/roc_npc.c
+++ b/drivers/common/cnxk/roc_npc.c
@@ -348,6 +348,7 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
 {
 	struct npc *npc = roc_npc_to_npc_priv(roc_npc);
 	const struct roc_npc_action_mark *act_mark;
+	const struct roc_npc_action_meter *act_mtr;
 	const struct roc_npc_action_queue *act_q;
 	const struct roc_npc_action_vf *vf_act;
 	bool vlan_insert_action = false;
@@ -451,6 +452,12 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
 		case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
 			req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
 			break;
+		case ROC_NPC_ACTION_TYPE_METER:
+			act_mtr = (const struct roc_npc_action_meter *)
+					  actions->conf;
+			flow->mtr_id = act_mtr->mtr_id;
+			req_act |= ROC_NPC_ACTION_TYPE_METER;
+			break;
 		default:
 			errcode = NPC_ERR_ACTION_NOTSUP;
 			goto err_exit;
diff --git a/drivers/common/cnxk/roc_npc.h b/drivers/common/cnxk/roc_npc.h
index 65d4bd6edc..10d1ac82a4 100644
--- a/drivers/common/cnxk/roc_npc.h
+++ b/drivers/common/cnxk/roc_npc.h
@@ -58,7 +58,7 @@ struct roc_npc_flow_item_raw {
 	const uint8_t *pattern; /**< Byte string to look for. */
 };
 
-#define ROC_NPC_MAX_ACTION_COUNT 12
+#define ROC_NPC_MAX_ACTION_COUNT 19
 
 enum roc_npc_action_type {
 	ROC_NPC_ACTION_TYPE_END = (1 << 0),
@@ -77,6 +77,7 @@ enum roc_npc_action_type {
 	ROC_NPC_ACTION_TYPE_VLAN_INSERT = (1 << 13),
 	ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT = (1 << 14),
 	ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT = (1 << 15),
+	ROC_NPC_ACTION_TYPE_METER = (1 << 17),
 };
 
 struct roc_npc_action {
@@ -110,6 +111,10 @@ struct roc_npc_action_of_set_vlan_pcp {
 	uint8_t vlan_pcp; /**< VLAN priority. */
 };
 
+struct roc_npc_action_meter {
+	uint32_t mtr_id; /**< Meter id to be applied. > */
+};
+
 struct roc_npc_attr {
 	uint32_t priority;	/**< Rule priority level within group. */
 	uint32_t ingress : 1;	/**< Rule applies to ingress traffic. */
@@ -128,6 +133,7 @@ struct roc_npc_flow {
 	uint32_t mcam_id;
 	int32_t ctr_id;
 	uint32_t priority;
+	uint32_t mtr_id;
 #define ROC_NPC_MAX_MCAM_WIDTH_DWORDS 7
 	/* Contiguous match string */
 	uint64_t mcam_data[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 15/28] net/cnxk: support meter ops get API
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (13 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 14/28] common/cnxk: support meter in action list skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 16/28] net/cnxk: support ops to get meter capabilities skori
                       ` (13 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

To enable support for ingress meter, supported operations
are exposed for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev.c     |  1 +
 drivers/net/cnxk/cnxk_ethdev.h     |  3 +++
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 18 ++++++++++++++++++
 drivers/net/cnxk/meson.build       |  1 +
 4 files changed, 23 insertions(+)
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mtr.c

diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index ec00e620eb..f694abd71d 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -1498,6 +1498,7 @@ struct eth_dev_ops cnxk_eth_dev_ops = {
 	.set_mc_addr_list = cnxk_nix_mc_addr_list_configure,
 	.set_queue_rate_limit = cnxk_nix_tm_set_queue_rate_limit,
 	.tm_ops_get = cnxk_nix_tm_ops_get,
+	.mtr_ops_get = cnxk_nix_mtr_ops_get,
 };
 
 static int
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index ff21b977b7..7a585b9dcf 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -433,6 +433,9 @@ int cnxk_nix_tm_ops_get(struct rte_eth_dev *eth_dev, void *ops);
 int cnxk_nix_tm_set_queue_rate_limit(struct rte_eth_dev *eth_dev,
 				     uint16_t queue_idx, uint16_t tx_rate);
 
+/* MTR */
+int cnxk_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops);
+
 /* RSS */
 uint32_t cnxk_rss_ethdev_to_nix(struct cnxk_eth_dev *dev, uint64_t ethdev_rss,
 				uint8_t rss_level);
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
new file mode 100644
index 0000000000..fdb493a4b9
--- /dev/null
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell.
+ */
+
+#include "cnxk_ethdev.h"
+#include <rte_mtr_driver.h>
+
+const struct rte_mtr_ops nix_mtr_ops = {
+};
+
+int
+cnxk_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops)
+{
+	RTE_SET_USED(dev);
+
+	*(const void **)ops = &nix_mtr_ops;
+	return 0;
+}
diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build
index d86188fed7..5dac078b2c 100644
--- a/drivers/net/cnxk/meson.build
+++ b/drivers/net/cnxk/meson.build
@@ -11,6 +11,7 @@ endif
 sources = files(
         'cnxk_ethdev.c',
         'cnxk_ethdev_devargs.c',
+        'cnxk_ethdev_mtr.c',
         'cnxk_ethdev_ops.c',
         'cnxk_ethdev_sec.c',
         'cnxk_link.c',
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 16/28] net/cnxk: support ops to get meter capabilities
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (14 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 15/28] net/cnxk: support meter ops get API skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 17/28] net/cnxk: support ops to create meter profile skori
                       ` (12 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement ethdev operation to get meter capabilities for
CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 48 ++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index fdb493a4b9..12013f26c2 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -5,7 +5,55 @@
 #include "cnxk_ethdev.h"
 #include <rte_mtr_driver.h>
 
+#define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
+#define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
+
+static struct rte_mtr_capabilities mtr_capa = {
+	.n_max = NIX_MTR_COUNT_MAX,
+	.n_shared_max = NIX_MTR_COUNT_PER_FLOW,
+	/* .identical = , */
+	.shared_identical = true,
+	/* .shared_n_flows_per_mtr_max = ,*/
+	.chaining_n_mtrs_per_flow_max = NIX_MTR_COUNT_PER_FLOW,
+	.chaining_use_prev_mtr_color_supported = true,
+	.chaining_use_prev_mtr_color_enforced = true,
+	.meter_srtcm_rfc2697_n_max = NIX_MTR_COUNT_MAX,
+	.meter_trtcm_rfc2698_n_max = NIX_MTR_COUNT_MAX,
+	.meter_trtcm_rfc4115_n_max = NIX_MTR_COUNT_MAX,
+	.meter_rate_max = NIX_BPF_RATE_MAX / 8, /* Bytes per second */
+	.meter_policy_n_max = NIX_MTR_COUNT_MAX,
+	.color_aware_srtcm_rfc2697_supported = true,
+	.color_aware_trtcm_rfc2698_supported = true,
+	.color_aware_trtcm_rfc4115_supported = true,
+	.srtcm_rfc2697_byte_mode_supported = true,
+	.srtcm_rfc2697_packet_mode_supported = true,
+	.trtcm_rfc2698_byte_mode_supported = true,
+	.trtcm_rfc2698_packet_mode_supported = true,
+	.trtcm_rfc4115_byte_mode_supported = true,
+	.trtcm_rfc4115_packet_mode_supported = true,
+	.stats_mask = RTE_MTR_STATS_N_PKTS_GREEN | RTE_MTR_STATS_N_PKTS_YELLOW |
+		      RTE_MTR_STATS_N_PKTS_RED | RTE_MTR_STATS_N_PKTS_DROPPED |
+		      RTE_MTR_STATS_N_BYTES_GREEN |
+		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
+		      RTE_MTR_STATS_N_BYTES_DROPPED};
+
+static int
+cnxk_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
+			       struct rte_mtr_capabilities *capa,
+			       struct rte_mtr_error *error)
+{
+	RTE_SET_USED(dev);
+
+	if (!capa)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "NULL input parameter");
+	*capa = mtr_capa;
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
+	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 17/28] net/cnxk: support ops to create meter profile
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (15 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 16/28] net/cnxk: support ops to get meter capabilities skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 18/28] net/cnxk: support ops to delete " skori
                       ` (11 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to add meter profile for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev.c     |  14 +++
 drivers/net/cnxk/cnxk_ethdev.h     |  13 +++
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 138 +++++++++++++++++++++++++++++
 3 files changed, 165 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index f694abd71d..d748d5da04 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -701,6 +701,14 @@ nix_free_queue_mem(struct cnxk_eth_dev *dev)
 	dev->sqs = NULL;
 }
 
+static int
+nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
+{
+	TAILQ_INIT(&dev->mtr_profiles);
+
+	return 0;
+}
+
 static int
 nix_rss_default_setup(struct cnxk_eth_dev *dev)
 {
@@ -1113,6 +1121,12 @@ cnxk_nix_configure(struct rte_eth_dev *eth_dev)
 		goto free_nix_lf;
 	}
 
+	rc = nix_ingress_policer_setup(dev);
+	if (rc) {
+		plt_err("Failed to setup ingress policer rc=%d", rc);
+		goto free_nix_lf;
+	}
+
 	rc = roc_nix_tm_hierarchy_enable(nix, ROC_NIX_TM_DEFAULT, false);
 	if (rc) {
 		plt_err("Failed to enable default tm hierarchy, rc=%d", rc);
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 7a585b9dcf..c076208d77 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -13,6 +13,7 @@
 #include <rte_mbuf.h>
 #include <rte_mbuf_pool_ops.h>
 #include <rte_mempool.h>
+#include <rte_mtr_driver.h>
 #include <rte_security.h>
 #include <rte_security_driver.h>
 #include <rte_tailq.h>
@@ -158,6 +159,15 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct cnxk_mtr_profile_node {
+	TAILQ_ENTRY(cnxk_mtr_profile_node) next;
+	struct rte_mtr_meter_profile profile; /**< Profile detail. */
+	uint32_t ref_cnt;		      /**< Use count. */
+	uint32_t id;			      /**< Profile id. */
+};
+
+TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
+
 /* Security session private data */
 struct cnxk_eth_sec_sess {
 	/* List entry */
@@ -303,6 +313,9 @@ struct cnxk_eth_dev {
 	double clk_freq_mult;
 	uint64_t clk_delta;
 
+	/* Ingress policer */
+	struct cnxk_mtr_profiles mtr_profiles;
+
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
 
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 12013f26c2..bab03ebe95 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -37,6 +37,106 @@ static struct rte_mtr_capabilities mtr_capa = {
 		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
 		      RTE_MTR_STATS_N_BYTES_DROPPED};
 
+static struct cnxk_mtr_profile_node *
+nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
+{
+	struct cnxk_mtr_profiles *fmps = &dev->mtr_profiles;
+	struct cnxk_mtr_profile_node *fmp;
+
+	TAILQ_FOREACH(fmp, fmps, next)
+		if (profile_id == fmp->id)
+			return fmp;
+
+	return NULL;
+}
+
+static int
+nix_mtr_profile_validate(struct cnxk_eth_dev *dev, uint32_t profile_id,
+			 struct rte_mtr_meter_profile *profile,
+			 struct rte_mtr_error *error)
+{
+	int rc = 0;
+
+	PLT_SET_USED(dev);
+
+	if (profile == NULL)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE,
+					  NULL, "Meter profile is null.");
+
+	if (profile_id == UINT32_MAX)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile id not valid.");
+
+	switch (profile->alg) {
+	case RTE_MTR_SRTCM_RFC2697:
+		if (profile->srtcm_rfc2697.cir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CIR exceeds max meter rate");
+
+		if (profile->srtcm_rfc2697.cbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->srtcm_rfc2697.ebs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"EBS exceeds max meter burst size");
+		break;
+
+	case RTE_MTR_TRTCM_RFC2698:
+		if (profile->trtcm_rfc2698.cir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CIR exceeds max meter rate");
+
+		if (profile->trtcm_rfc2698.pir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PIR exceeds max meter rate");
+
+		if (profile->trtcm_rfc2698.cbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->trtcm_rfc2698.pbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PBS exceeds max meter burst size");
+		break;
+
+	case RTE_MTR_TRTCM_RFC4115:
+		if ((profile->trtcm_rfc4115.cir + profile->trtcm_rfc4115.eir) >
+		    mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PIR + EIR exceeds max rate");
+
+		if (profile->trtcm_rfc4115.cbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->trtcm_rfc4115.ebs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PBS exceeds max meter burst size");
+		break;
+
+	default:
+		rc = -rte_mtr_error_set(error, EINVAL,
+					RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+					"alg is invalid");
+		break;
+	}
+
+	return rc;
+}
+
 static int
 cnxk_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
 			       struct rte_mtr_capabilities *capa,
@@ -52,8 +152,46 @@ cnxk_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_profile_add(struct rte_eth_dev *eth_dev, uint32_t profile_id,
+			  struct rte_mtr_meter_profile *profile,
+			  struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profiles *fmps = &dev->mtr_profiles;
+	struct cnxk_mtr_profile_node *fmp;
+	int ret;
+
+	/* Check input params. */
+	ret = nix_mtr_profile_validate(dev, profile_id, profile, error);
+	if (ret)
+		return ret;
+
+	fmp = nix_mtr_profile_find(dev, profile_id);
+	if (fmp) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Profile already exist");
+	}
+
+	fmp = plt_zmalloc(sizeof(struct cnxk_mtr_profile_node), ROC_ALIGN);
+	if (fmp == NULL)
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Meter profile memory "
+					  "alloc failed.");
+
+	fmp->id = profile_id;
+	fmp->profile = *profile;
+
+	TAILQ_INSERT_TAIL(fmps, fmp, next);
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
+	.meter_profile_add = cnxk_nix_mtr_profile_add,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 18/28] net/cnxk: support ops to delete meter profile
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (16 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 17/28] net/cnxk: support ops to create meter profile skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 19/28] net/cnxk: support ops to validate meter policy skori
                       ` (10 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter profile for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index bab03ebe95..f5e2c19480 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -189,9 +189,39 @@ cnxk_nix_mtr_profile_add(struct rte_eth_dev *eth_dev, uint32_t profile_id,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,
+			     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *fmp;
+
+	if (profile_id == UINT32_MAX)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile id not valid.");
+
+	fmp = nix_mtr_profile_find(dev, profile_id);
+	if (fmp == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  &profile_id,
+					  "Meter profile is invalid.");
+
+	if (fmp->ref_cnt)
+		return -rte_mtr_error_set(error, EBUSY,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile is in use.");
+
+	TAILQ_REMOVE(&dev->mtr_profiles, fmp, next);
+	plt_free(fmp);
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
+	.meter_profile_delete = cnxk_nix_mtr_profile_delete,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 19/28] net/cnxk: support ops to validate meter policy
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (17 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 18/28] net/cnxk: support ops to delete " skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 20/28] net/cnxk: support ops to create " skori
                       ` (9 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to validate meter policy for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 49 ++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index f5e2c19480..ec34327756 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -218,10 +218,59 @@ cnxk_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,
+			      struct rte_mtr_meter_policy_params *policy,
+			      struct rte_mtr_error *error)
+{
+	static const char *const action_color[] = {"Green", "Yellow", "Red"};
+	bool supported[RTE_COLORS] = {false, false, false};
+	const struct rte_flow_action *action;
+	char message[1024];
+	uint32_t i;
+
+	RTE_SET_USED(dev);
+
+	if (!policy)
+		return 0; /* Nothing to be validated */
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		if (policy->actions[i]) {
+			for (action = policy->actions[i];
+			     action->type != RTE_FLOW_ACTION_TYPE_END;
+			     action++) {
+				if (action->type == RTE_FLOW_ACTION_TYPE_METER)
+					supported[i] = true;
+
+				if (action->type == RTE_FLOW_ACTION_TYPE_DROP)
+					supported[i] = true;
+
+				if (!supported[i]) {
+					sprintf(message,
+						"%s action is not valid",
+						action_color[i]);
+					return -rte_mtr_error_set(error,
+					  ENOTSUP,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+					  message);
+				}
+			}
+		} else {
+			sprintf(message, "%s action is null", action_color[i]);
+			return -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+				message);
+		}
+	}
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
 	.meter_profile_delete = cnxk_nix_mtr_profile_delete,
+	.meter_policy_validate = cnxk_nix_mtr_policy_validate,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 20/28] net/cnxk: support ops to create meter policy
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (18 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 19/28] net/cnxk: support ops to validate meter policy skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 21/28] net/cnxk: support ops to delete " skori
                       ` (8 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to add meter policy for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev.c     |  1 +
 drivers/net/cnxk/cnxk_ethdev.h     | 31 +++++++++++
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 84 ++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index d748d5da04..6295fa0557 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -705,6 +705,7 @@ static int
 nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
 	TAILQ_INIT(&dev->mtr_profiles);
+	TAILQ_INIT(&dev->mtr_policy);
 
 	return 0;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index c076208d77..4cdce5dfd0 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -159,6 +159,35 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct action_rss {
+	enum rte_eth_hash_function func;
+	uint32_t level;
+	uint64_t types;
+	uint32_t key_len;
+	uint32_t queue_num;
+	uint8_t *key;
+	uint16_t *queue;
+};
+
+struct policy_actions {
+	uint32_t action_fate;
+	union {
+		uint16_t queue;
+		uint32_t mtr_id;
+		struct action_rss *rss_desc;
+	};
+};
+
+struct cnxk_mtr_policy_node {
+	TAILQ_ENTRY(cnxk_mtr_policy_node) next;
+	/**< Pointer to the next flow meter structure. */
+	uint32_t id;	 /**< Policy id */
+	uint32_t mtr_id; /** Meter id */
+	struct rte_mtr_meter_policy_params policy;
+	struct policy_actions actions[RTE_COLORS];
+	uint32_t ref_cnt;
+};
+
 struct cnxk_mtr_profile_node {
 	TAILQ_ENTRY(cnxk_mtr_profile_node) next;
 	struct rte_mtr_meter_profile profile; /**< Profile detail. */
@@ -167,6 +196,7 @@ struct cnxk_mtr_profile_node {
 };
 
 TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
+TAILQ_HEAD(cnxk_mtr_policy, cnxk_mtr_policy_node);
 
 /* Security session private data */
 struct cnxk_eth_sec_sess {
@@ -315,6 +345,7 @@ struct cnxk_eth_dev {
 
 	/* Ingress policer */
 	struct cnxk_mtr_profiles mtr_profiles;
+	struct cnxk_mtr_policy mtr_policy;
 
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index ec34327756..187a0b90b2 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -50,6 +50,18 @@ nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
 	return NULL;
 }
 
+static struct cnxk_mtr_policy_node *
+nix_mtr_policy_find(struct cnxk_eth_dev *dev, uint32_t meter_policy_id)
+{
+	struct cnxk_mtr_policy *fmps = &dev->mtr_policy;
+	struct cnxk_mtr_policy_node *fmp;
+
+	TAILQ_FOREACH(fmp, fmps, next)
+		if (meter_policy_id == fmp->id)
+			return fmp;
+	return NULL;
+}
+
 static int
 nix_mtr_profile_validate(struct cnxk_eth_dev *dev, uint32_t profile_id,
 			 struct rte_mtr_meter_profile *profile,
@@ -266,11 +278,83 @@ cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static void
+cnxk_fill_policy_actions(struct cnxk_mtr_policy_node *fmp,
+			  struct rte_mtr_meter_policy_params *policy)
+
+{
+	const struct rte_flow_action_meter *mtr;
+	const struct rte_flow_action *action;
+	int i;
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		if (policy->actions[i]) {
+			for (action = policy->actions[i];
+			     action->type != RTE_FLOW_ACTION_TYPE_END;
+			     action++) {
+				if (action->type ==
+				    RTE_FLOW_ACTION_TYPE_METER) {
+					fmp->actions[i].action_fate =
+						action->type;
+					mtr = (const struct
+					       rte_flow_action_meter *)
+						      action->conf;
+					fmp->actions[i].mtr_id = mtr->mtr_id;
+				}
+
+				if (action->type == RTE_FLOW_ACTION_TYPE_DROP) {
+					fmp->actions[i].action_fate =
+						action->type;
+				}
+			}
+		}
+	}
+}
+
+static int
+cnxk_nix_mtr_policy_add(struct rte_eth_dev *eth_dev, uint32_t policy_id,
+			 struct rte_mtr_meter_policy_params *policy,
+			 struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy *fmps = &dev->mtr_policy;
+	struct cnxk_mtr_policy_node *fmp;
+	int rc;
+
+	fmp = nix_mtr_policy_find(dev, policy_id);
+	if (fmp) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "Policy already exist");
+	}
+
+	fmp = plt_zmalloc(sizeof(struct cnxk_mtr_policy_node), ROC_ALIGN);
+	if (fmp == NULL) {
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Memory allocation failure");
+	} else {
+		rc = cnxk_nix_mtr_policy_validate(eth_dev, policy, error);
+		if (rc)
+			goto exit;
+	}
+
+	fmp->id = policy_id;
+	cnxk_fill_policy_actions(fmp, policy);
+	TAILQ_INSERT_TAIL(fmps, fmp, next);
+	return 0;
+
+exit:
+	plt_free(fmp);
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
 	.meter_profile_delete = cnxk_nix_mtr_profile_delete,
 	.meter_policy_validate = cnxk_nix_mtr_policy_validate,
+	.meter_policy_add = cnxk_nix_mtr_policy_add,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 21/28] net/cnxk: support ops to delete meter policy
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (19 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 20/28] net/cnxk: support ops to create " skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 22/28] net/cnxk: support ops to create meter skori
                       ` (7 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter policy for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 187a0b90b2..c3739749fc 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -349,12 +349,38 @@ cnxk_nix_mtr_policy_add(struct rte_eth_dev *eth_dev, uint32_t policy_id,
 	return rc;
 }
 
+static int
+cnxk_nix_mtr_policy_delete(struct rte_eth_dev *eth_dev, uint32_t policy_id,
+			    struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy_node *fmp;
+
+	fmp = nix_mtr_policy_find(dev, policy_id);
+	if (fmp == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "No policy found");
+	}
+
+	if (fmp->ref_cnt)
+		return -rte_mtr_error_set(error, EBUSY,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "Meter policy is in use.");
+
+	TAILQ_REMOVE(&dev->mtr_policy, fmp, next);
+	plt_free(fmp);
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
 	.meter_profile_delete = cnxk_nix_mtr_profile_delete,
 	.meter_policy_validate = cnxk_nix_mtr_policy_validate,
 	.meter_policy_add = cnxk_nix_mtr_policy_add,
+	.meter_policy_delete = cnxk_nix_mtr_policy_delete,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 22/28] net/cnxk: support ops to create meter
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (20 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 21/28] net/cnxk: support ops to delete " skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 23/28] net/cnxk: support ops to delete meter skori
                       ` (6 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to create meter instance for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev.c     |  1 +
 drivers/net/cnxk/cnxk_ethdev.h     | 25 ++++++++
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 93 ++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index 6295fa0557..2bb33d8f2d 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -706,6 +706,7 @@ nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
 	TAILQ_INIT(&dev->mtr_profiles);
 	TAILQ_INIT(&dev->mtr_policy);
+	TAILQ_INIT(&dev->mtr);
 
 	return 0;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 4cdce5dfd0..10adeeec82 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -159,6 +159,28 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct cnxk_meter_node {
+#define MAX_PRV_MTR_NODES 10
+	TAILQ_ENTRY(cnxk_meter_node) next;
+	/**< Pointer to the next flow meter structure. */
+	uint32_t id; /**< Usr mtr id. */
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	uint32_t bpf_id; /**< Hw mtr id. */
+	uint32_t rq_num;
+	uint32_t *rq_id;
+	uint16_t level;
+	uint32_t prev_id[MAX_PRV_MTR_NODES]; /**< Prev mtr id for chaining */
+	uint32_t prev_cnt;
+	uint32_t next_id; /**< Next mtr id for chaining */
+	bool is_prev;
+	bool is_next;
+	struct rte_mtr_params params;
+	struct roc_nix_bpf_objs profs;
+	bool is_used;
+	uint32_t ref_cnt;
+};
+
 struct action_rss {
 	enum rte_eth_hash_function func;
 	uint32_t level;
@@ -197,6 +219,7 @@ struct cnxk_mtr_profile_node {
 
 TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
 TAILQ_HEAD(cnxk_mtr_policy, cnxk_mtr_policy_node);
+TAILQ_HEAD(cnxk_mtr, cnxk_meter_node);
 
 /* Security session private data */
 struct cnxk_eth_sec_sess {
@@ -344,8 +367,10 @@ struct cnxk_eth_dev {
 	uint64_t clk_delta;
 
 	/* Ingress policer */
+	enum roc_nix_bpf_color precolor_tbl[ROC_NIX_BPF_PRE_COLOR_MAX];
 	struct cnxk_mtr_profiles mtr_profiles;
 	struct cnxk_mtr_policy mtr_policy;
+	struct cnxk_mtr mtr;
 
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index c3739749fc..b258de0253 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -37,6 +37,18 @@ static struct rte_mtr_capabilities mtr_capa = {
 		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
 		      RTE_MTR_STATS_N_BYTES_DROPPED};
 
+static struct cnxk_meter_node *
+nix_mtr_find(struct cnxk_eth_dev *dev, uint32_t meter_id)
+{
+	struct cnxk_mtr *fms = &dev->mtr;
+	struct cnxk_meter_node *fm;
+
+	TAILQ_FOREACH(fm, fms, next)
+		if (meter_id == fm->id)
+			return fm;
+	return NULL;
+}
+
 static struct cnxk_mtr_profile_node *
 nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
 {
@@ -374,6 +386,86 @@ cnxk_nix_mtr_policy_delete(struct rte_eth_dev *eth_dev, uint32_t policy_id,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_create(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		     struct rte_mtr_params *params, int shared,
+		     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_mtr *fm = &dev->mtr;
+	struct cnxk_meter_node *mtr;
+	int i;
+
+	RTE_SET_USED(shared);
+
+	if (params == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "Meter params are invalid.");
+
+	profile = nix_mtr_profile_find(dev, params->meter_profile_id);
+	if (profile == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  &params->meter_profile_id,
+					  "Meter profile is invalid.");
+
+	policy = nix_mtr_policy_find(dev, params->meter_policy_id);
+	if (policy == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  &params->meter_policy_id,
+					  "Meter policy is invalid.");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter already exist");
+	}
+
+	mtr = plt_zmalloc(sizeof(struct cnxk_meter_node), ROC_ALIGN);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Meter memory alloc failed.");
+	}
+
+	mtr->id = mtr_id;
+	mtr->profile = profile;
+	mtr->policy = policy;
+	mtr->params = *params;
+	mtr->bpf_id = ROC_NIX_BPF_ID_INVALID;
+	mtr->prev_cnt = 0;
+	for (i = 0; i < MAX_PRV_MTR_NODES; i++)
+		mtr->prev_id[i] = ROC_NIX_BPF_ID_INVALID;
+
+	mtr->next_id = ROC_NIX_BPF_ID_INVALID;
+	mtr->is_next = false;
+	mtr->level = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+
+	if (params->dscp_table) {
+		mtr->params.dscp_table = plt_zmalloc(ROC_NIX_BPF_PRE_COLOR_MAX,
+						     ROC_ALIGN);
+		if (mtr->params.dscp_table == NULL) {
+			plt_free(mtr);
+			return -rte_mtr_error_set(error, ENOMEM,
+					RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+					NULL, "Memory alloc failed.");
+		}
+
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			mtr->params.dscp_table[i] = params->dscp_table[i];
+	}
+
+	profile->ref_cnt++;
+	policy->ref_cnt++;
+	TAILQ_INSERT_TAIL(fm, mtr, next);
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -381,6 +473,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_validate = cnxk_nix_mtr_policy_validate,
 	.meter_policy_add = cnxk_nix_mtr_policy_add,
 	.meter_policy_delete = cnxk_nix_mtr_policy_delete,
+	.create = cnxk_nix_mtr_create,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 23/28] net/cnxk: support ops to delete meter
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (21 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 22/28] net/cnxk: support ops to create meter skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 24/28] net/cnxk: support ops to enable/disable meter skori
                       ` (5 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter instance for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 90 ++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index b258de0253..28eba29f0a 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -8,6 +8,10 @@
 #define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
 #define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
 
+static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
+						      ROC_NIX_BPF_LEVEL_F_MID,
+						      ROC_NIX_BPF_LEVEL_F_TOP};
+
 static struct rte_mtr_capabilities mtr_capa = {
 	.n_max = NIX_MTR_COUNT_MAX,
 	.n_shared_max = NIX_MTR_COUNT_PER_FLOW,
@@ -466,6 +470,91 @@ cnxk_nix_mtr_create(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		      struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_objs profs = {0};
+	struct cnxk_mtr *fm = &dev->mtr;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct cnxk_meter_node *mid_mtr;
+	struct cnxk_meter_node *top_mtr;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, &mtr_id,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->ref_cnt) {
+		return -rte_mtr_error_set(error, EADDRINUSE,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, &mtr_id,
+					  "Meter id in use.");
+	}
+
+	switch (lvl_map[mtr->level]) {
+	case ROC_NIX_BPF_LEVEL_F_LEAF:
+		if (mtr->is_next) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_LEAF,
+						 mtr->bpf_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		break;
+	case ROC_NIX_BPF_LEVEL_F_MID:
+		while ((mtr->prev_cnt) + 1) {
+			mid_mtr =
+				nix_mtr_find(dev, mtr->prev_id[mtr->prev_cnt]);
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_LEAF,
+						 mid_mtr->bpf_id,
+						 ROC_NIX_BPF_ID_INVALID);
+			mtr->prev_cnt--;
+		}
+		if (mtr->is_next) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_MID,
+						 mtr->bpf_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		break;
+	case ROC_NIX_BPF_LEVEL_F_TOP:
+		while (mtr->prev_cnt) {
+			top_mtr =
+				nix_mtr_find(dev, mtr->prev_id[mtr->prev_cnt]);
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_MID,
+						 top_mtr->bpf_id,
+						 ROC_NIX_BPF_ID_INVALID);
+			mtr->prev_cnt--;
+		}
+		break;
+	default:
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Invalid meter level");
+	}
+
+	if (rc)
+		goto exit;
+
+	profs.level = mtr->level;
+	profs.count = 1;
+	profs.ids[0] = mtr->bpf_id;
+	rc = roc_nix_bpf_free(nix, &profs, 1);
+	if (rc)
+		goto exit;
+
+	mtr->policy->ref_cnt--;
+	mtr->profile->ref_cnt--;
+	TAILQ_REMOVE(fm, mtr, next);
+	plt_free(mtr->params.dscp_table);
+	plt_free(mtr);
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -474,6 +563,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_add = cnxk_nix_mtr_policy_add,
 	.meter_policy_delete = cnxk_nix_mtr_policy_delete,
 	.create = cnxk_nix_mtr_create,
+	.destroy = cnxk_nix_mtr_destroy,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 24/28] net/cnxk: support ops to enable/disable meter
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (22 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 23/28] net/cnxk: support ops to delete meter skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 25/28] net/cnxk: support ops to update precolor DSCP table skori
                       ` (4 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to enable or disable meter instance for
CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 60 ++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 28eba29f0a..b9359c185d 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -555,6 +555,64 @@ cnxk_nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cnxk_nix_mtr_enable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->level != 0)
+		return 0;
+
+	for (i = 0; i < mtr->rq_num; i++) {
+		rq = &dev->rqs[mtr->rq_id[i]];
+		rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, true);
+	}
+
+	return rc;
+}
+
+static int
+cnxk_nix_mtr_disable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		      struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->level != 0)
+		return 0;
+
+	for (i = 0; i < mtr->rq_num; i++) {
+		rq = &dev->rqs[mtr->rq_id[i]];
+		rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, false);
+	}
+
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -564,6 +622,8 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_delete = cnxk_nix_mtr_policy_delete,
 	.create = cnxk_nix_mtr_create,
 	.destroy = cnxk_nix_mtr_destroy,
+	.meter_enable = cnxk_nix_mtr_enable,
+	.meter_disable = cnxk_nix_mtr_disable,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 25/28] net/cnxk: support ops to update precolor DSCP table
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (23 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 24/28] net/cnxk: support ops to enable/disable meter skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 26/28] net/cnxk: support ops to read/update meter stats skori
                       ` (3 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to update DSCP table for pre-coloring for
incoming packet per nixlf for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 51 ++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index b9359c185d..be902ad47d 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -613,6 +613,56 @@ cnxk_nix_mtr_disable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cnxk_nix_mtr_dscp_table_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+				enum rte_color *dscp_table,
+				struct rte_mtr_error *error)
+{
+	enum roc_nix_bpf_color nix_dscp_tbl[ROC_NIX_BPF_PRE_COLOR_MAX];
+	enum roc_nix_bpf_color color_map[] = {ROC_NIX_BPF_COLOR_GREEN,
+					      ROC_NIX_BPF_COLOR_YELLOW,
+					      ROC_NIX_BPF_COLOR_RED};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_precolor table;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	int rc, i;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	if (!dscp_table) {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			nix_dscp_tbl[i] = ROC_NIX_BPF_COLOR_GREEN;
+	} else {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			nix_dscp_tbl[i] = color_map[dscp_table[i]];
+	}
+
+	table.count = ROC_NIX_BPF_PRE_COLOR_MAX;
+	table.mode = ROC_NIX_BPF_PC_MODE_DSCP_OUTER;
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		table.color[i] = nix_dscp_tbl[i];
+
+	rc = roc_nix_bpf_pre_color_tbl_setup(nix, mtr->bpf_id,
+					     lvl_map[mtr->level], &table);
+	if (rc) {
+		rte_mtr_error_set(error, rc, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+				  NULL, NULL);
+		goto exit;
+	}
+
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		dev->precolor_tbl[i] = nix_dscp_tbl[i];
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -624,6 +674,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.destroy = cnxk_nix_mtr_destroy,
 	.meter_enable = cnxk_nix_mtr_enable,
 	.meter_disable = cnxk_nix_mtr_disable,
+	.meter_dscp_table_update = cnxk_nix_mtr_dscp_table_update,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 26/28] net/cnxk: support ops to read/update meter stats
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (24 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 25/28] net/cnxk: support ops to update precolor DSCP table skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 27/28] net/cnxk: support meter action to flow create skori
                       ` (2 subsequent siblings)
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to read and update stats corresponding to
given meter instance for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 141 +++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index be902ad47d..08af3f628a 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -8,6 +8,21 @@
 #define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
 #define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
 
+#define NIX_BPF_STATS_MASK_ALL                                                 \
+	{                                                                      \
+		ROC_NIX_BPF_GREEN_PKT_F_PASS | ROC_NIX_BPF_GREEN_OCTS_F_PASS | \
+			ROC_NIX_BPF_GREEN_PKT_F_DROP |                         \
+			ROC_NIX_BPF_GREEN_OCTS_F_DROP |                        \
+			ROC_NIX_BPF_YELLOW_PKT_F_PASS |                        \
+			ROC_NIX_BPF_YELLOW_OCTS_F_PASS |                       \
+			ROC_NIX_BPF_YELLOW_PKT_F_DROP |                        \
+			ROC_NIX_BPF_YELLOW_OCTS_F_DROP |                       \
+			ROC_NIX_BPF_RED_PKT_F_PASS |                           \
+			ROC_NIX_BPF_RED_OCTS_F_PASS |                          \
+			ROC_NIX_BPF_RED_PKT_F_DROP |                           \
+			ROC_NIX_BPF_RED_OCTS_F_DROP                            \
+	}
+
 static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
 						      ROC_NIX_BPF_LEVEL_F_MID,
 						      ROC_NIX_BPF_LEVEL_F_TOP};
@@ -663,6 +678,130 @@ cnxk_nix_mtr_dscp_table_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cnxk_nix_mtr_stats_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+			   uint64_t stats_mask, struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	if (!stats_mask)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "no bit is set to stats mask");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	mtr->params.stats_mask = stats_mask;
+	return 0;
+}
+
+static int
+cnxk_nix_mtr_stats_read(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+			 struct rte_mtr_stats *stats, uint64_t *stats_mask,
+			 int clear, struct rte_mtr_error *error)
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	uint64_t bpf_stats[ROC_NIX_BPF_STATS_MAX] = {0};
+	uint64_t mask = NIX_BPF_STATS_MASK_ALL;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	int rc;
+
+	if (!stats)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "stats pointer is NULL");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	rc = roc_nix_bpf_stats_read(nix, mtr->bpf_id, mask, lvl_map[mtr->level],
+				    bpf_stats);
+	if (rc) {
+		rte_mtr_error_set(error, rc, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+				  NULL, NULL);
+		goto exit;
+	}
+
+	green_pkt_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
+		stats->n_pkts[RTE_COLOR_GREEN] = bpf_stats[green_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
+		stats->n_pkts[RTE_COLOR_YELLOW] = bpf_stats[yellow_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_RED)
+		stats->n_pkts[RTE_COLOR_RED] = bpf_stats[red_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
+		stats->n_bytes[RTE_COLOR_GREEN] = bpf_stats[green_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
+		stats->n_bytes[RTE_COLOR_YELLOW] = bpf_stats[yellow_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_RED)
+		stats->n_bytes[RTE_COLOR_RED] = bpf_stats[red_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
+		stats->n_pkts_dropped = bpf_stats[green_pkt_drop] +
+					bpf_stats[yellow_pkt_drop] +
+					bpf_stats[red_pkt_drop];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
+		stats->n_bytes_dropped = bpf_stats[green_octs_drop] +
+					 bpf_stats[yellow_octs_drop] +
+					 bpf_stats[red_octs_drop];
+
+	if (stats_mask)
+		*stats_mask = mtr->params.stats_mask;
+
+	if (clear) {
+		rc = roc_nix_bpf_stats_reset(nix, mtr->bpf_id, mask,
+					     lvl_map[mtr->level]);
+		if (rc) {
+			rte_mtr_error_set(error, rc,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  NULL);
+			goto exit;
+		}
+	}
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -675,6 +814,8 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_enable = cnxk_nix_mtr_enable,
 	.meter_disable = cnxk_nix_mtr_disable,
 	.meter_dscp_table_update = cnxk_nix_mtr_dscp_table_update,
+	.stats_update = cnxk_nix_mtr_stats_update,
+	.stats_read = cnxk_nix_mtr_stats_read,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 27/28] net/cnxk: support meter action to flow create
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (25 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 26/28] net/cnxk: support ops to read/update meter stats skori
@ 2021-10-11 15:50     ` skori
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 28/28] net/cnxk: support meter action to flow destroy skori
  2021-10-19 14:30     ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer Jerin Jacob
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Meters are configured per flow using rte_flow_create API.
Implement support for meter action applied on the flow.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 doc/guides/nics/features/cnxk.ini      |   1 +
 doc/guides/nics/features/cnxk_vf.ini   |   1 +
 doc/guides/rel_notes/release_21_11.rst |   1 +
 drivers/net/cnxk/cn10k_rte_flow.c      | 171 ++++++++-
 drivers/net/cnxk/cnxk_ethdev.h         |  18 +
 drivers/net/cnxk/cnxk_ethdev_mtr.c     | 506 +++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_rte_flow.c       |   4 +
 7 files changed, 701 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/cnxk.ini b/doc/guides/nics/features/cnxk.ini
index 1ced3ee903..f0586457ca 100644
--- a/doc/guides/nics/features/cnxk.ini
+++ b/doc/guides/nics/features/cnxk.ini
@@ -79,6 +79,7 @@ count                = Y
 drop                 = Y
 flag                 = Y
 mark                 = Y
+meter                = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
 of_set_vlan_pcp      = Y
diff --git a/doc/guides/nics/features/cnxk_vf.ini b/doc/guides/nics/features/cnxk_vf.ini
index 139d9b9892..f3d9f23f17 100644
--- a/doc/guides/nics/features/cnxk_vf.ini
+++ b/doc/guides/nics/features/cnxk_vf.ini
@@ -71,6 +71,7 @@ count                = Y
 drop                 = Y
 flag                 = Y
 mark                 = Y
+meter                = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
 of_set_vlan_pcp      = Y
diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst
index 16c48d54a1..5ec80377ee 100644
--- a/doc/guides/rel_notes/release_21_11.rst
+++ b/doc/guides/rel_notes/release_21_11.rst
@@ -91,6 +91,7 @@ New Features
   * Added rte_tm support.
   * Added support for Inline IPsec for CN9K event mode and CN10K
     poll mode and event mode.
+  * Added support for ingress meter for CN10K platform.
 
 * **Updated af_packet ethdev driver.**
 
diff --git a/drivers/net/cnxk/cn10k_rte_flow.c b/drivers/net/cnxk/cn10k_rte_flow.c
index b04de6a7e6..00c0b172e4 100644
--- a/drivers/net/cnxk/cn10k_rte_flow.c
+++ b/drivers/net/cnxk/cn10k_rte_flow.c
@@ -6,6 +6,113 @@
 #include "cn10k_ethdev.h"
 #include "cn10k_rx.h"
 
+static int
+cn10k_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t mtr_id)
+{
+	return nix_mtr_connect(eth_dev, mtr_id);
+}
+
+static int
+cn10k_mtr_configure(struct rte_eth_dev *eth_dev,
+		    const struct rte_flow_action actions[])
+{
+	uint32_t mtr_id = 0xffff, prev_mtr_id = 0xffff, next_mtr_id = 0xffff;
+	const struct rte_flow_action_meter *mtr_conf;
+	const struct rte_flow_action_queue *q_conf;
+	const struct rte_flow_action_rss *rss_conf;
+	struct cnxk_mtr_policy_node *policy;
+	bool is_mtr_act = false;
+	int tree_level = 0;
+	int rc = -EINVAL, i;
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) {
+			mtr_conf = (const struct rte_flow_action_meter
+					    *)(actions->conf);
+			mtr_id = mtr_conf->mtr_id;
+			is_mtr_act = true;
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE) {
+			q_conf = (const struct rte_flow_action_queue
+					  *)(actions->conf);
+			if (is_mtr_act)
+				nix_mtr_rq_update(eth_dev, mtr_id, 1,
+						  &q_conf->index);
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
+			rss_conf = (const struct rte_flow_action_rss
+					    *)(actions->conf);
+			if (is_mtr_act)
+				nix_mtr_rq_update(eth_dev, mtr_id,
+						  rss_conf->queue_num,
+						  rss_conf->queue);
+		}
+	}
+
+	if (!is_mtr_act)
+		return rc;
+
+	prev_mtr_id = mtr_id;
+	next_mtr_id = mtr_id;
+	while (next_mtr_id != 0xffff) {
+		rc = nix_mtr_validate(eth_dev, next_mtr_id);
+		if (rc)
+			return rc;
+
+		rc = nix_mtr_policy_act_get(eth_dev, next_mtr_id, &policy);
+		if (rc)
+			return rc;
+
+		rc = nix_mtr_color_action_validate(eth_dev, mtr_id,
+						   &prev_mtr_id, &next_mtr_id,
+						   policy, &tree_level);
+		if (rc)
+			return rc;
+	}
+
+	return nix_mtr_configure(eth_dev, mtr_id);
+}
+
+static int
+cn10k_rss_action_validate(struct rte_eth_dev *eth_dev,
+			  const struct rte_flow_attr *attr,
+			  const struct rte_flow_action *act)
+{
+	const struct rte_flow_action_rss *rss;
+
+	if (act == NULL)
+		return -EINVAL;
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (attr->egress) {
+		plt_err("No support of RSS in egress");
+		return -EINVAL;
+	}
+
+	if (eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
+		plt_err("multi-queue mode is disabled");
+		return -ENOTSUP;
+	}
+
+	if (!rss || !rss->queue_num) {
+		plt_err("no valid queues");
+		return -EINVAL;
+	}
+
+	if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
+		plt_err("non-default RSS hash functions are not supported");
+		return -ENOTSUP;
+	}
+
+	if (rss->key_len && rss->key_len > ROC_NIX_RSS_KEY_LEN) {
+		plt_err("RSS hash key too large");
+		return -ENOTSUP;
+	}
+
+	return 0;
+}
+
 struct rte_flow *
 cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		  const struct rte_flow_item pattern[],
@@ -13,13 +120,75 @@ cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		  struct rte_flow_error *error)
 {
 	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	const struct rte_flow_action *action_rss = NULL;
+	const struct rte_flow_action_meter *mtr = NULL;
+	const struct rte_flow_action *act_q = NULL;
 	int mark_actions = 0, vtag_actions = 0;
 	struct roc_npc *npc = &dev->npc;
 	struct roc_npc_flow *flow;
+	uint32_t req_act = 0;
+	int i, rc;
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER)
+			req_act |= ROC_NPC_ACTION_TYPE_METER;
+
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE) {
+			req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
+			act_q = &actions[i];
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
+			req_act |= ROC_NPC_ACTION_TYPE_RSS;
+			action_rss = &actions[i];
+		}
+	}
+
+	if (req_act & ROC_NPC_ACTION_TYPE_METER) {
+		if ((req_act & ROC_NPC_ACTION_TYPE_RSS) &&
+		    ((req_act & ROC_NPC_ACTION_TYPE_QUEUE))) {
+			return NULL;
+		}
+		if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
+			rc = cn10k_rss_action_validate(eth_dev, attr,
+						       action_rss);
+			if (rc)
+				return NULL;
+		} else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
+			const struct rte_flow_action_queue *act_queue;
+			act_queue = (const struct rte_flow_action_queue *)
+					    act_q->conf;
+			if (act_queue->index > eth_dev->data->nb_rx_queues)
+				return NULL;
+		} else {
+			return NULL;
+		}
+	}
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) {
+			mtr = (const struct rte_flow_action_meter *)actions[i]
+				      .conf;
+			rc = cn10k_mtr_configure(eth_dev, actions);
+			if (rc) {
+				rte_flow_error_set(error, rc,
+					RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+					"Failed to configure mtr ");
+				return NULL;
+			}
+			break;
+		}
+	}
 
 	flow = cnxk_flow_create(eth_dev, attr, pattern, actions, error);
-	if (!flow)
+	if (!flow) {
+		if (mtr)
+			nix_mtr_chain_reset(eth_dev, mtr->mtr_id);
+
 		return NULL;
+	} else {
+		if (mtr)
+			cn10k_mtr_connect(eth_dev, mtr->mtr_id);
+	}
 
 	mark_actions = roc_npc_mark_actions_get(npc);
 
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 10adeeec82..7e13956572 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -575,6 +575,24 @@ cnxk_eth_sec_sess_get_by_sess(struct cnxk_eth_dev *dev,
 
 /* Other private functions */
 int nix_recalc_mtu(struct rte_eth_dev *eth_dev);
+int nix_mtr_validate(struct rte_eth_dev *dev, uint32_t id);
+int nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id,
+			   struct cnxk_mtr_policy_node **policy);
+int nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id,
+		      uint32_t queue_num, const uint16_t *queue);
+int nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id,
+			 uint32_t prev_id, uint32_t next_id);
+int nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id);
+struct cnxk_meter_node *nix_get_mtr(struct rte_eth_dev *eth_dev,
+				    uint32_t cur_id);
+int nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id,
+			 uint32_t level);
+int nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id);
+int nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id);
+int nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
+				  uint32_t *prev_id, uint32_t *next_id,
+				  struct cnxk_mtr_policy_node *policy,
+				  int *tree_level);
 
 /* Inlines */
 static __rte_always_inline uint64_t
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 08af3f628a..7fde992d0f 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -826,3 +826,509 @@ cnxk_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops)
 	*(const void **)ops = &nix_mtr_ops;
 	return 0;
 }
+
+int
+nix_mtr_validate(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	profile = nix_mtr_profile_find(dev, mtr->params.meter_profile_id);
+	if (profile == NULL)
+		return -EINVAL;
+
+	policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id);
+	if (policy == NULL)
+		return -EINVAL;
+
+	return 0;
+}
+
+int
+nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id,
+		       struct cnxk_mtr_policy_node **policy_act)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id);
+	if (policy == NULL)
+		return -EINVAL;
+
+	*policy_act = policy;
+
+	return 0;
+}
+
+int
+nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t queue_num,
+		  const uint16_t *queue)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+	uint32_t i;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	mtr->rq_id = plt_zmalloc(queue_num * sizeof(uint32_t), ROC_ALIGN);
+	if (mtr->rq_id == NULL)
+		return -ENOMEM;
+
+	mtr->rq_num = queue_num;
+	for (i = 0; i < queue_num; i++)
+		mtr->rq_id[i] = queue[i];
+
+	return 0;
+}
+
+int
+nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id)
+{
+	struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint32_t mtr_id = cur_id;
+	int i = 0, j = 0;
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		mtr[i] = nix_mtr_find(dev, mtr_id);
+		if (mtr[i])
+			mtr_id = mtr[i]->next_id;
+	}
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		if (mtr[i]) {
+			for (j = 0; j < MAX_PRV_MTR_NODES; j++)
+				mtr[i]->prev_id[i] = ROC_NIX_BPF_ID_INVALID;
+			mtr[i]->level = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+			mtr[i]->next_id = ROC_NIX_BPF_ID_INVALID;
+			mtr[i]->is_next = false;
+			mtr[i]->prev_cnt = 0;
+		}
+	}
+	return 0;
+}
+
+int
+nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id,
+		     uint32_t prev_id, uint32_t next_id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, cur_id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	switch (lvl_map[mtr->level]) {
+	case ROC_NIX_BPF_LEVEL_F_LEAF:
+		mtr->prev_id[mtr->prev_cnt] = ROC_NIX_BPF_ID_INVALID;
+		mtr->next_id = next_id;
+		mtr->is_next = true;
+		break;
+	case ROC_NIX_BPF_LEVEL_F_MID:
+		mtr->prev_id[mtr->prev_cnt] = prev_id;
+		mtr->next_id = next_id;
+		mtr->is_next = true;
+		break;
+	case ROC_NIX_BPF_LEVEL_F_TOP:
+		mtr->prev_id[mtr->prev_cnt] = prev_id;
+		mtr->next_id = ROC_NIX_BPF_ID_INVALID;
+		mtr->is_next = false;
+		break;
+	default:
+		plt_err("Invalid meter level");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+struct cnxk_meter_node *
+nix_get_mtr(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return NULL;
+
+	return mtr;
+}
+
+int
+nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t level)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	mtr->level = level;
+	return 0;
+}
+
+static void
+nix_mtr_config_map(struct cnxk_meter_node *mtr, struct roc_nix_bpf_cfg *cfg)
+{
+	enum roc_nix_bpf_algo alg_map[] = {
+		ROC_NIX_BPF_ALGO_NONE, ROC_NIX_BPF_ALGO_2697,
+		ROC_NIX_BPF_ALGO_2698, ROC_NIX_BPF_ALGO_4115};
+	struct cnxk_mtr_profile_node *profile = mtr->profile;
+	struct cnxk_mtr_policy_node *policy = mtr->policy;
+
+	cfg->alg = alg_map[profile->profile.alg];
+	cfg->lmode = profile->profile.packet_mode;
+
+	switch (cfg->alg) {
+	case ROC_NIX_BPF_ALGO_2697:
+		cfg->algo2697.cir = profile->profile.srtcm_rfc2697.cir * 8;
+		cfg->algo2697.cbs = profile->profile.srtcm_rfc2697.cbs;
+		cfg->algo2697.ebs = profile->profile.srtcm_rfc2697.ebs;
+		break;
+	case ROC_NIX_BPF_ALGO_2698:
+		cfg->algo2698.cir = profile->profile.trtcm_rfc2698.cir * 8;
+		cfg->algo2698.pir = profile->profile.trtcm_rfc2698.pir * 8;
+		cfg->algo2698.cbs = profile->profile.trtcm_rfc2698.cbs;
+		cfg->algo2698.pbs = profile->profile.trtcm_rfc2698.pbs;
+		break;
+	case ROC_NIX_BPF_ALGO_4115:
+		cfg->algo4115.cir = profile->profile.trtcm_rfc4115.cir * 8;
+		cfg->algo4115.eir = profile->profile.trtcm_rfc4115.eir * 8;
+		cfg->algo4115.cbs = profile->profile.trtcm_rfc4115.cbs;
+		cfg->algo4115.ebs = profile->profile.trtcm_rfc4115.ebs;
+		break;
+	default:
+		break;
+	}
+
+	cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_PASS;
+	cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_PASS;
+	cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_PASS;
+
+	if (policy->actions[RTE_COLOR_GREEN].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_DROP;
+
+	if (policy->actions[RTE_COLOR_YELLOW].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_DROP;
+
+	if (policy->actions[RTE_COLOR_RED].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_DROP;
+}
+
+static void
+nix_dscp_table_map(struct cnxk_meter_node *mtr,
+		   struct roc_nix_bpf_precolor *tbl)
+{
+	enum roc_nix_bpf_color color_map[] = {ROC_NIX_BPF_COLOR_GREEN,
+					      ROC_NIX_BPF_COLOR_YELLOW,
+					      ROC_NIX_BPF_COLOR_RED};
+	int i;
+
+	tbl->count = ROC_NIX_BPF_PRE_COLOR_MAX;
+	tbl->mode = ROC_NIX_BPF_PC_MODE_DSCP_OUTER;
+
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		tbl->color[i] = ROC_NIX_BPF_COLOR_GREEN;
+
+	if (mtr->params.dscp_table) {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			tbl->color[i] = color_map[mtr->params.dscp_table[i]];
+	}
+}
+
+int
+nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	enum roc_nix_bpf_level_flag lvl_flag = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *base_mtr, *next_mtr;
+	struct roc_nix *nix = &dev->nix;
+	uint32_t cur_mtr_id = id;
+	int rc, i;
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		base_mtr = nix_mtr_find(dev, cur_mtr_id);
+		if (base_mtr) {
+			lvl_flag = lvl_map[base_mtr->level];
+			if (base_mtr->is_next) {
+				next_mtr = nix_mtr_find(dev, base_mtr->next_id);
+				if (next_mtr) {
+					if (!base_mtr->is_used) {
+						rc = roc_nix_bpf_connect(nix,
+							lvl_flag,
+							base_mtr->bpf_id,
+							next_mtr->bpf_id);
+						if (rc)
+							return rc;
+					}
+				}
+				cur_mtr_id = base_mtr->next_id;
+			}
+		}
+	}
+	return 0;
+}
+
+int
+nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_objs profs[ROC_NIX_BPF_LEVEL_MAX];
+	uint8_t idx0 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint8_t idx1 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint8_t idx2 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX];
+	int num_mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct roc_nix *nix = &dev->nix;
+	struct roc_nix_bpf_precolor tbl;
+	struct roc_nix_bpf_cfg cfg;
+	struct roc_nix_rq *rq;
+	uint8_t lvl_mask;
+	uint32_t i;
+	uint32_t j;
+	int rc;
+
+	mtr[0] = nix_mtr_find(dev, id);
+	if (mtr[0] == NULL)
+		return -EINVAL;
+
+	num_mtr[0] = 1;
+	idx0 = roc_nix_bpf_level_to_idx(lvl_map[mtr[0]->level]);
+	if (idx0 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return -EINVAL;
+
+	lvl_mask = ROC_NIX_BPF_LEVEL_F_LEAF;
+	if (mtr[0]->is_used)
+		per_lvl_cnt[idx0] = 0;
+	else
+		per_lvl_cnt[idx0] = 1;
+
+	if (mtr[0]->is_next) {
+		mtr[1] = nix_mtr_find(dev, mtr[0]->next_id);
+		if (mtr[1] == NULL)
+			return -EINVAL;
+		num_mtr[1] = 1;
+		idx1 = roc_nix_bpf_level_to_idx(lvl_map[mtr[1]->level]);
+		if (idx1 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			return -EINVAL;
+
+		lvl_mask |= ROC_NIX_BPF_LEVEL_F_MID;
+		if (mtr[1]->is_used)
+			per_lvl_cnt[idx1] = 0;
+		else
+			per_lvl_cnt[idx1] = 1;
+	}
+
+	if (mtr[1] && mtr[1]->is_next) {
+		mtr[2] = nix_mtr_find(dev, mtr[1]->next_id);
+		if (mtr[2] == NULL)
+			return -EINVAL;
+
+		num_mtr[2] = 1;
+		idx2 = roc_nix_bpf_level_to_idx(lvl_map[mtr[2]->level]);
+		if (idx2 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			return -EINVAL;
+
+		lvl_mask |= ROC_NIX_BPF_LEVEL_F_TOP;
+		if (mtr[2]->is_used)
+			per_lvl_cnt[idx2] = 0;
+		else
+			per_lvl_cnt[idx2] = 1;
+	}
+
+	rc = roc_nix_bpf_alloc(nix, lvl_mask, per_lvl_cnt, profs);
+	if (rc)
+		return rc;
+	if (mtr[0]->bpf_id == ROC_NIX_BPF_ID_INVALID)
+		mtr[0]->bpf_id = profs[idx0].ids[0];
+
+	if (num_mtr[0])
+		if (mtr[0]->is_next && idx1 != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			if (mtr[1]->bpf_id == ROC_NIX_BPF_ID_INVALID)
+				mtr[1]->bpf_id = profs[idx1].ids[0];
+
+	if (num_mtr[1])
+		if (mtr[1]->is_next && idx2 != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			if (mtr[2]->bpf_id == ROC_NIX_BPF_ID_INVALID)
+				mtr[2]->bpf_id = profs[idx2].ids[0];
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		if (num_mtr[i]) {
+			if (!mtr[i]->is_used) {
+				memset(&cfg, 0, sizeof(struct roc_nix_bpf_cfg));
+				nix_mtr_config_map(mtr[i], &cfg);
+				rc = roc_nix_bpf_config(nix, mtr[i]->bpf_id,
+							lvl_map[mtr[i]->level],
+							&cfg);
+
+				memset(&tbl, 0,
+				       sizeof(struct roc_nix_bpf_precolor));
+				nix_dscp_table_map(mtr[i], &tbl);
+				rc = roc_nix_bpf_pre_color_tbl_setup(nix,
+					mtr[i]->bpf_id, lvl_map[mtr[i]->level],
+					&tbl);
+
+				if (mtr[i]->params.meter_enable) {
+					for (j = 0; j < mtr[i]->rq_num; j++) {
+						rq = &dev->rqs[mtr[i]->rq_id
+								       [j]];
+						rc = roc_nix_bpf_ena_dis(nix,
+							mtr[i]->bpf_id, rq,
+							true);
+					}
+				}
+			}
+		}
+	}
+
+	return rc;
+}
+
+int
+nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
+			      uint32_t *prev_id, uint32_t *next_id,
+			      struct cnxk_mtr_policy_node *policy,
+			      int *tree_level)
+{
+	uint32_t action_fate_red = policy->actions[RTE_COLOR_RED].action_fate;
+	uint32_t action_fate_green =
+		policy->actions[RTE_COLOR_GREEN].action_fate;
+	uint32_t action_fate_yellow =
+		policy->actions[RTE_COLOR_YELLOW].action_fate;
+	uint32_t cur_mtr_id = *next_id;
+	uint32_t next_mtr_id = 0xffff;
+	uint32_t prev_mtr_id = 0xffff;
+	struct cnxk_meter_node *mtr;
+
+	if (action_fate_green == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_GREEN].mtr_id;
+
+	if (action_fate_yellow == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_YELLOW].mtr_id;
+
+	if (action_fate_red == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_RED].mtr_id;
+
+	if (next_mtr_id != 0xffff) {
+		switch (*tree_level) {
+		case 0:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 0);
+				nix_mtr_chain_update(eth_dev, cur_mtr_id, -1,
+						     next_mtr_id);
+			} else {
+				if (mtr->level == 0)
+					mtr->is_used = true;
+				else
+					return -EINVAL;
+			}
+			(*tree_level)++;
+			*next_id = next_mtr_id;
+			break;
+		case 1:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 1);
+				prev_mtr_id = id;
+				nix_mtr_chain_update(eth_dev, cur_mtr_id,
+						     prev_mtr_id, next_mtr_id);
+			} else {
+				if (mtr->level == 1) {
+					mtr->prev_cnt++;
+					prev_mtr_id = id;
+					nix_mtr_chain_update(eth_dev,
+						cur_mtr_id, prev_mtr_id,
+						next_mtr_id);
+
+					mtr->is_used = true;
+				} else {
+					return -EINVAL;
+				}
+			}
+			(*tree_level)++;
+			*next_id = next_mtr_id;
+			*prev_id = cur_mtr_id;
+			break;
+		case 2:
+			nix_mtr_chain_reset(eth_dev, id);
+			return -EINVAL;
+		}
+	} else {
+		switch (*tree_level) {
+		case 0:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 0);
+			} else {
+				if (mtr->level == 0)
+					mtr->is_used = true;
+				else
+					return -EINVAL;
+			}
+			break;
+		case 1:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 1);
+				prev_mtr_id = id;
+				nix_mtr_chain_update(eth_dev, cur_mtr_id,
+						     prev_mtr_id, -1);
+			} else {
+				if (mtr->level == 1) {
+					mtr->prev_cnt++;
+					prev_mtr_id = id;
+					nix_mtr_chain_update(eth_dev,
+							     cur_mtr_id,
+							     prev_mtr_id, -1);
+					mtr->is_used = true;
+				} else {
+					return -EINVAL;
+				}
+			}
+			break;
+		case 2:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 2);
+				prev_mtr_id = *prev_id;
+				nix_mtr_chain_update(eth_dev, cur_mtr_id,
+						     prev_mtr_id, -1);
+			} else {
+				if (mtr->level == 2) {
+					mtr->prev_cnt++;
+					prev_mtr_id = *prev_id;
+					nix_mtr_chain_update(eth_dev,
+							     cur_mtr_id,
+							     prev_mtr_id, -1);
+					mtr->is_used = true;
+				} else {
+					return -EINVAL;
+				}
+			}
+			break;
+		}
+		*next_id = 0xffff;
+	}
+
+	return 0;
+}
diff --git a/drivers/net/cnxk/cnxk_rte_flow.c b/drivers/net/cnxk/cnxk_rte_flow.c
index 32c1b5dee5..56dcd36c61 100644
--- a/drivers/net/cnxk/cnxk_rte_flow.c
+++ b/drivers/net/cnxk/cnxk_rte_flow.c
@@ -195,6 +195,10 @@ cnxk_map_actions(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 				ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
 			in_actions[i].conf = actions->conf;
 			break;
+		case RTE_FLOW_ACTION_TYPE_METER:
+			in_actions[i].type = ROC_NPC_ACTION_TYPE_METER;
+			in_actions[i].conf = actions->conf;
+			break;
 		default:
 			plt_npc_dbg("Action is not supported = %d",
 				    actions->type);
-- 
2.25.1


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

* [dpdk-dev] [PATCH v4 28/28] net/cnxk: support meter action to flow destroy
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (26 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 27/28] net/cnxk: support meter action to flow create skori
@ 2021-10-11 15:50     ` skori
  2021-10-19 14:30     ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer Jerin Jacob
  28 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-11 15:50 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Meters are configured per flow using rte_flow_create API.
Patch adds support for destroy operation for meter action
applied on the flow.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention
v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_rte_flow.c  | 22 +++++++++++++++-
 drivers/net/cnxk/cnxk_ethdev.c     | 40 ++++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev.h     |  2 ++
 drivers/net/cnxk/cnxk_ethdev_mtr.c |  7 ++++++
 4 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/drivers/net/cnxk/cn10k_rte_flow.c b/drivers/net/cnxk/cn10k_rte_flow.c
index 00c0b172e4..8c87452934 100644
--- a/drivers/net/cnxk/cn10k_rte_flow.c
+++ b/drivers/net/cnxk/cn10k_rte_flow.c
@@ -12,6 +12,14 @@ cn10k_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t mtr_id)
 	return nix_mtr_connect(eth_dev, mtr_id);
 }
 
+static int
+cn10k_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id)
+{
+	struct rte_mtr_error mtr_error;
+
+	return nix_mtr_destroy(eth_dev, mtr_id, &mtr_error);
+}
+
 static int
 cn10k_mtr_configure(struct rte_eth_dev *eth_dev,
 		    const struct rte_flow_action actions[])
@@ -215,6 +223,8 @@ cn10k_flow_destroy(struct rte_eth_dev *eth_dev, struct rte_flow *rte_flow,
 	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
 	int mark_actions = 0, vtag_actions = 0;
 	struct roc_npc *npc = &dev->npc;
+	uint32_t mtr_id;
+	int rc;
 
 	mark_actions = roc_npc_mark_actions_get(npc);
 	if (mark_actions) {
@@ -237,5 +247,15 @@ cn10k_flow_destroy(struct rte_eth_dev *eth_dev, struct rte_flow *rte_flow,
 		}
 	}
 
-	return cnxk_flow_destroy(eth_dev, flow, error);
+	mtr_id = flow->mtr_id;
+	rc = cnxk_flow_destroy(eth_dev, flow, error);
+	if (!rc) {
+		rc = cn10k_mtr_destroy(eth_dev, mtr_id);
+		if (rc) {
+			rte_flow_error_set(error, ENXIO,
+				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				"Meter attached to this flow does not exist");
+		}
+	}
+	return rc;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index 2bb33d8f2d..69bd58ae45 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -141,6 +141,38 @@ nix_security_setup(struct cnxk_eth_dev *dev)
 	return rc;
 }
 
+static int
+nix_meter_fini(struct cnxk_eth_dev *dev)
+{
+	struct cnxk_meter_node *next_mtr = NULL;
+	struct roc_nix_bpf_objs profs = {0};
+	struct cnxk_meter_node *mtr = NULL;
+	struct cnxk_mtr *fms = &dev->mtr;
+	struct roc_nix *nix = &dev->nix;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc;
+
+	RTE_TAILQ_FOREACH_SAFE(mtr, fms, next, next_mtr) {
+		for (i = 0; i < mtr->rq_num; i++) {
+			rq = &dev->rqs[mtr->rq_id[i]];
+			rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, false);
+		}
+
+		profs.level = mtr->level;
+		profs.count = 1;
+		profs.ids[0] = mtr->bpf_id;
+		rc = roc_nix_bpf_free(nix, &profs, 1);
+
+		if (rc)
+			return rc;
+
+		TAILQ_REMOVE(fms, mtr, next);
+		plt_free(mtr);
+	}
+	return 0;
+}
+
 static int
 nix_security_release(struct cnxk_eth_dev *dev)
 {
@@ -1012,6 +1044,11 @@ cnxk_nix_configure(struct rte_eth_dev *eth_dev)
 		if (rc)
 			goto fail_configure;
 
+		/* Disable and free rte_meter entries */
+		rc = nix_meter_fini(dev);
+		if (rc)
+			goto fail_configure;
+
 		/* Cleanup security support */
 		rc = nix_security_release(dev);
 		if (rc)
@@ -1668,6 +1705,9 @@ cnxk_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool reset)
 
 	roc_nix_npc_rx_ena_dis(nix, false);
 
+	/* Disable and free rte_meter entries */
+	nix_meter_fini(dev);
+
 	/* Disable and free rte_flow entries */
 	roc_npc_fini(&dev->npc);
 
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 7e13956572..2d4b073985 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -589,6 +589,8 @@ int nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id,
 			 uint32_t level);
 int nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id);
 int nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id);
+int nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t id,
+		    struct rte_mtr_error *error);
 int nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
 				  uint32_t *prev_id, uint32_t *next_id,
 				  struct cnxk_mtr_policy_node *policy,
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 7fde992d0f..bfae145f7c 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -1054,6 +1054,13 @@ nix_dscp_table_map(struct cnxk_meter_node *mtr,
 	}
 }
 
+int
+nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t id,
+		struct rte_mtr_error *error)
+{
+	return cnxk_nix_mtr_destroy(eth_dev, id, error);
+}
+
 int
 nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id)
 {
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 00/28] Support ingress policer
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 01/28] common/cnxk: update policer MBOX APIs and HW definitions skori
@ 2021-10-12  7:05       ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 01/28] common/cnxk: update policer MBOX APIs and HW definitions skori
                           ` (27 more replies)
  0 siblings, 28 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  Cc: dev, Sunil Kumar Kori

From: Sunil Kumar Kori <skori@marvell.com>

Series adds support for ingress meter for CN10K platform. Series is divided
in following two logical implementation:

 - common/cnxk: It implements RoC APIs over MBOX interfaces which are by network drivers.

	common/cnxk: update policer MBOX APIs and HW definitions
	common/cnxk: support RoC API to get level to index
	common/cnxk: support RoC API to get profile count
	common/cnxk: support RoC API to alloc bandwidth profiles
	common/cnxk: support RoC API to free bandwidth profiles
	common/cnxk: support RoC API to configure bandwidth profile
	common/cnxk: support RoC API to toggle profile state
	common/cnxk: support RoC API to dump bandwidth profile
	common/cnxk: support RoC API to setup precolor table
	common/cnxk: support RoC API to connect bandwidth profiles
	common/cnxk: support RoC API to get stats to index
	common/cnxk: support RoC API to read profile statistics
	common/cnxk: support RoC API to reset profile stats
	common/cnxk: support meter in action list

 - net/cnxk: It implenets ethdev ops for various metering operations.
	For cn9k platform, ops are registerded as NULL because cn9k does
	not support metering.

	net/cnxk: support meter ops get API
	net/cnxk: support ops to get meter capabilities
	net/cnxk: support ops to create meter profile
	net/cnxk: support ops to delete meter profile
	net/cnxk: support ops to validate meter policy
	net/cnxk: support ops to create meter policy
	net/cnxk: support ops to delete meter policy
	net/cnxk: support ops to create meter
	net/cnxk: support ops to delete meter
	net/cnxk: support ops to enable/disable meter
	net/cnxk: support ops to update precolor DSCP table
	net/cnxk: support ops to read/update meter stats
	net/cnxk: support meter action to flow create
	net/cnxk: support meter action to flow destroy

 doc/guides/nics/features/cnxk.ini      |    1 +
 doc/guides/nics/features/cnxk_vf.ini   |    1 +
 doc/guides/rel_notes/release_21_11.rst |    1 +
 drivers/common/cnxk/hw/nix.h           |   62 +-
 drivers/common/cnxk/meson.build        |    1 +
 drivers/common/cnxk/roc_mbox.h         |   34 +-
 drivers/common/cnxk/roc_nix.h          |  164 +++
 drivers/common/cnxk/roc_nix_bpf.c      | 1149 ++++++++++++++++++++
 drivers/common/cnxk/roc_nix_priv.h     |    1 +
 drivers/common/cnxk/roc_npc.c          |    7 +
 drivers/common/cnxk/roc_npc.h          |    8 +-
 drivers/common/cnxk/roc_platform.h     |    1 +
 drivers/common/cnxk/roc_utils.c        |    3 +
 drivers/common/cnxk/version.map        |   15 +
 drivers/net/cnxk/cn10k_rte_flow.c      |  193 +++-
 drivers/net/cnxk/cnxk_ethdev.c         |   57 +
 drivers/net/cnxk/cnxk_ethdev.h         |   92 ++
 drivers/net/cnxk/cnxk_ethdev_mtr.c     | 1341 ++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_rte_flow.c       |    4 +
 drivers/net/cnxk/meson.build           |    1 +
 20 files changed, 3129 insertions(+), 7 deletions(-)
 create mode 100644 drivers/common/cnxk/roc_nix_bpf.c
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mtr.c

-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 01/28] common/cnxk: update policer MBOX APIs and HW definitions
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 02/28] common/cnxk: support RoC API to get level to index skori
                           ` (26 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Ray Kinsella

From: Sunil Kumar Kori <skori@marvell.com>

To support ingress policer on CN10K, MBOX interfaces and HW
definitions are synced.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Acked-by: Ray Kinsella <mdr@ashroe.eu>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/hw/nix.h   | 13 ++++++++++---
 drivers/common/cnxk/roc_mbox.h | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/common/cnxk/hw/nix.h b/drivers/common/cnxk/hw/nix.h
index 6a0eb019ac..7685b7dc1b 100644
--- a/drivers/common/cnxk/hw/nix.h
+++ b/drivers/common/cnxk/hw/nix.h
@@ -692,9 +692,16 @@
 #define NIX_RX_BAND_PROF_ACTIONRESULT_DROP (0x1ull) /* [CN10K, .) */
 #define NIX_RX_BAND_PROF_ACTIONRESULT_RED  (0x2ull) /* [CN10K, .) */
 
-#define NIX_RX_BAND_PROF_LAYER_LEAF   (0x0ull) /* [CN10K, .) */
-#define NIX_RX_BAND_PROF_LAYER_MIDDLE (0x1ull) /* [CN10K, .) */
-#define NIX_RX_BAND_PROF_LAYER_TOP    (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_LEAF    (0x0ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_INVALID (0x1ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_MIDDLE  (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_TOP     (0x3ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_LAYER_MAX     (0x4ull) /* [CN10K, .) */
+
+#define NIX_RX_BAND_PROF_PC_MODE_VLAN (0x0ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_DSCP (0x1ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_GEN  (0x2ull) /* [CN10K, .) */
+#define NIX_RX_BAND_PROF_PC_MODE_RSVD (0x3ull) /* [CN10K, .) */
 
 #define NIX_RX_COLORRESULT_GREEN  (0x0ull) /* [CN10K, .) */
 #define NIX_RX_COLORRESULT_YELLOW (0x1ull) /* [CN10K, .) */
diff --git a/drivers/common/cnxk/roc_mbox.h b/drivers/common/cnxk/roc_mbox.h
index 75d1ff1ef3..bc40848450 100644
--- a/drivers/common/cnxk/roc_mbox.h
+++ b/drivers/common/cnxk/roc_mbox.h
@@ -234,7 +234,11 @@ struct mbox_msghdr {
 	  nix_inline_ipsec_lf_cfg, msg_rsp)                                    \
 	M(NIX_CN10K_AQ_ENQ, 0x801b, nix_cn10k_aq_enq, nix_cn10k_aq_enq_req,    \
 	  nix_cn10k_aq_enq_rsp)                                                \
-	M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info)
+	M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info)      \
+	M(NIX_BANDPROF_ALLOC, 0x801d, nix_bandprof_alloc,                      \
+	  nix_bandprof_alloc_req, nix_bandprof_alloc_rsp)                      \
+	M(NIX_BANDPROF_FREE, 0x801e, nix_bandprof_free, nix_bandprof_free_req, \
+	  msg_rsp)
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES                                                   \
@@ -772,6 +776,10 @@ struct nix_cn10k_aq_enq_req {
 		__io struct nix_rsse_s rss;
 		/* Valid when op == WRITE/INIT and ctype == NIX_AQ_CTYPE_MCE */
 		__io struct nix_rx_mce_s mce;
+		/* Valid when op == WRITE/INIT and
+		 * ctype == NIX_AQ_CTYPE_BAND_PROF
+		 */
+		__io struct nix_band_prof_s prof;
 	};
 	/* Mask data when op == WRITE (1=write, 0=don't write) */
 	union {
@@ -785,6 +793,8 @@ struct nix_cn10k_aq_enq_req {
 		__io struct nix_rsse_s rss_mask;
 		/* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_MCE */
 		__io struct nix_rx_mce_s mce_mask;
+		/* Valid when op == WRITE and ctype == NIX_AQ_CTYPE_BAND_PROF */
+		__io struct nix_band_prof_s prof_mask;
 	};
 };
 
@@ -796,6 +806,7 @@ struct nix_cn10k_aq_enq_rsp {
 		struct nix_cq_ctx_s cq;
 		struct nix_rsse_s rss;
 		struct nix_rx_mce_s mce;
+		struct nix_band_prof_s prof;
 	};
 };
 
@@ -1130,6 +1141,27 @@ struct nix_hw_info {
 	uint16_t __io rsvd[15];
 };
 
+struct nix_bandprof_alloc_req {
+	struct mbox_msghdr hdr;
+	/* Count of profiles needed per layer */
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+};
+
+struct nix_bandprof_alloc_rsp {
+	struct mbox_msghdr hdr;
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+
+#define BANDPROF_PER_PFFUNC 64
+	uint16_t __io prof_idx[NIX_RX_BAND_PROF_LAYER_MAX][BANDPROF_PER_PFFUNC];
+};
+
+struct nix_bandprof_free_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io free_all;
+	uint16_t __io prof_count[NIX_RX_BAND_PROF_LAYER_MAX];
+	uint16_t __io prof_idx[NIX_RX_BAND_PROF_LAYER_MAX][BANDPROF_PER_PFFUNC];
+};
+
 /* SSO mailbox error codes
  * Range 501 - 600.
  */
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 02/28] common/cnxk: support RoC API to get level to index
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 01/28] common/cnxk: update policer MBOX APIs and HW definitions skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 03/28] common/cnxk: support RoC API to get profile count skori
                           ` (25 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform supports policer up to 3 level of hierarchy.
Implement RoC API to get corresponding index for given level.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/meson.build    |  1 +
 drivers/common/cnxk/roc_nix.h      | 12 ++++++++++++
 drivers/common/cnxk/roc_nix_bpf.c  | 22 ++++++++++++++++++++++
 drivers/common/cnxk/roc_nix_priv.h |  1 +
 drivers/common/cnxk/roc_utils.c    |  3 +++
 drivers/common/cnxk/version.map    |  1 +
 6 files changed, 40 insertions(+)
 create mode 100644 drivers/common/cnxk/roc_nix_bpf.c

diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build
index 97db5f087b..32d3ad5087 100644
--- a/drivers/common/cnxk/meson.build
+++ b/drivers/common/cnxk/meson.build
@@ -25,6 +25,7 @@ sources = files(
         'roc_mbox.c',
         'roc_model.c',
         'roc_nix.c',
+        'roc_nix_bpf.c',
         'roc_nix_debug.c',
         'roc_nix_fc.c',
         'roc_nix_irq.c',
diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index b06895a565..bf4fd2f208 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -6,6 +6,8 @@
 #define _ROC_NIX_H_
 
 /* Constants */
+#define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
+
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
 	ROC_NIX_RSS_RETA_SZ_128 = 128,
@@ -29,6 +31,12 @@ enum roc_nix_vlan_type {
 	ROC_NIX_VLAN_TYPE_OUTER = 0x02,
 };
 
+enum roc_nix_bpf_level_flag {
+	ROC_NIX_BPF_LEVEL_F_LEAF = BIT(0),
+	ROC_NIX_BPF_LEVEL_F_MID = BIT(1),
+	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -508,6 +516,10 @@ int __roc_api roc_nix_tm_prepare_rate_limited_tree(struct roc_nix *roc_nix);
 bool __roc_api roc_nix_tm_is_user_hierarchy_enabled(struct roc_nix *nix);
 int __roc_api roc_nix_tm_tree_type_get(struct roc_nix *nix);
 
+/* Ingress Policer API */
+uint8_t __roc_api
+roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
+
 /* MAC */
 int __roc_api roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start);
 int __roc_api roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix,
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
new file mode 100644
index 0000000000..b588cc16e4
--- /dev/null
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell.
+ */
+
+#include "roc_api.h"
+#include "roc_priv.h"
+
+uint8_t
+roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
+{
+	uint8_t idx;
+
+	if (level_f & ROC_NIX_BPF_LEVEL_F_LEAF)
+		idx = 0;
+	else if (level_f & ROC_NIX_BPF_LEVEL_F_MID)
+		idx = 1;
+	else if (level_f & ROC_NIX_BPF_LEVEL_F_TOP)
+		idx = 2;
+	else
+		idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	return idx;
+}
diff --git a/drivers/common/cnxk/roc_nix_priv.h b/drivers/common/cnxk/roc_nix_priv.h
index 7653c5a328..02b1be852d 100644
--- a/drivers/common/cnxk/roc_nix_priv.h
+++ b/drivers/common/cnxk/roc_nix_priv.h
@@ -187,6 +187,7 @@ enum nix_err_status {
 	NIX_ERR_INVALID_RANGE,
 	NIX_ERR_INTERNAL,
 	NIX_ERR_OP_NOTSUP,
+	NIX_ERR_HW_NOTSUP,
 	NIX_ERR_QUEUE_INVALID_RANGE,
 	NIX_ERR_AQ_READ_FAILED,
 	NIX_ERR_AQ_WRITE_FAILED,
diff --git a/drivers/common/cnxk/roc_utils.c b/drivers/common/cnxk/roc_utils.c
index 751486f503..f1b5ef3b70 100644
--- a/drivers/common/cnxk/roc_utils.c
+++ b/drivers/common/cnxk/roc_utils.c
@@ -34,6 +34,9 @@ roc_error_msg_get(int errorcode)
 	case NIX_ERR_OP_NOTSUP:
 		err_msg = "Operation not supported";
 		break;
+	case NIX_ERR_HW_NOTSUP:
+		err_msg = "Hardware does not support";
+		break;
 	case NIX_ERR_QUEUE_INVALID_RANGE:
 		err_msg = "Invalid Queue range";
 		break;
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index ccf8ec157e..c84c229938 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -82,6 +82,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 03/28] common/cnxk: support RoC API to get profile count
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 01/28] common/cnxk: update policer MBOX APIs and HW definitions skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 02/28] common/cnxk: support RoC API to get level to index skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 04/28] common/cnxk: support RoC API to alloc bandwidth profiles skori
                           ` (24 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement interface to get available profile count for given
nixlf.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  5 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 46 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 52 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index bf4fd2f208..4fef6d44e7 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -7,6 +7,7 @@
 
 /* Constants */
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
+#define ROC_NIX_BPF_LEVEL_MAX	      3
 
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
@@ -517,6 +518,10 @@ bool __roc_api roc_nix_tm_is_user_hierarchy_enabled(struct roc_nix *nix);
 int __roc_api roc_nix_tm_tree_type_get(struct roc_nix *nix);
 
 /* Ingress Policer API */
+int __roc_api
+roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX] /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index b588cc16e4..af9dffa90c 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -5,6 +5,14 @@
 #include "roc_api.h"
 #include "roc_priv.h"
 
+#define NIX_MAX_BPF_COUNT_LEAF_LAYER 64
+#define NIX_MAX_BPF_COUNT_MID_LAYER  8
+#define NIX_MAX_BPF_COUNT_TOP_LAYER  1
+
+#define NIX_BPF_LEVEL_F_MASK                                                   \
+	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
+	 ROC_NIX_BPF_LEVEL_F_TOP)
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -20,3 +28,41 @@ roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 		idx = ROC_NIX_BPF_LEVEL_IDX_INVALID;
 	return idx;
 }
+
+int
+roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
+{
+	uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
+	uint8_t leaf_idx, mid_idx, top_idx;
+
+	PLT_SET_USED(roc_nix);
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!mask)
+		return NIX_ERR_PARAM;
+
+	/* Currently No MBOX interface is available to get number
+	 * of bandwidth profiles. So numbers per level are hard coded,
+	 * considering 3 RPM blocks and each block has 4 LMAC's.
+	 * So total 12 physical interfaces are in system. Each interface
+	 * supports following bandwidth profiles.
+	 */
+
+	leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
+	mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
+	top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[leaf_idx] = NIX_MAX_BPF_COUNT_LEAF_LAYER;
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[mid_idx] = NIX_MAX_BPF_COUNT_MID_LAYER;
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		count[top_idx] = NIX_MAX_BPF_COUNT_TOP_LAYER;
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index c84c229938..6990c1f084 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -82,6 +82,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_count_get;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 04/28] common/cnxk: support RoC API to alloc bandwidth profiles
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (2 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 03/28] common/cnxk: support RoC API to get profile count skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 05/28] common/cnxk: support RoC API to free " skori
                           ` (23 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to allocate HW resources i.e. bandwidth
profiles for policer processing on CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  11 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 104 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 3 files changed, 116 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 4fef6d44e7..b192a2b217 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -6,6 +6,7 @@
 #define _ROC_NIX_H_
 
 /* Constants */
+#define ROC_NIX_BPF_PER_PFFUNC	      64
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
 
@@ -38,6 +39,12 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+struct roc_nix_bpf_objs {
+	uint16_t level;
+	uint16_t count;
+	uint16_t ids[ROC_NIX_BPF_PER_PFFUNC];
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -522,6 +529,10 @@ int __roc_api
 roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
+				uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
+				struct roc_nix_bpf_objs *profs /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index af9dffa90c..06394bda07 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -13,6 +13,19 @@
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
 
+static uint8_t sw_to_hw_lvl_map[] = {NIX_RX_BAND_PROF_LAYER_LEAF,
+				     NIX_RX_BAND_PROF_LAYER_MIDDLE,
+				     NIX_RX_BAND_PROF_LAYER_TOP};
+
+static inline struct mbox *
+get_mbox(struct roc_nix *roc_nix)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct dev *dev = &nix->dev;
+
+	return dev->mbox;
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -66,3 +79,94 @@ roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 
 	return 0;
 }
+
+int
+roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
+		  uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
+		  struct roc_nix_bpf_objs *profs)
+{
+	uint8_t mask = lvl_mask & NIX_BPF_LEVEL_F_MASK;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_alloc_req *req;
+	struct nix_bandprof_alloc_rsp *rsp;
+	uint8_t leaf_idx, mid_idx, top_idx;
+	int rc = -ENOSPC, i;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!mask)
+		return NIX_ERR_PARAM;
+
+	leaf_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_LEAF);
+	mid_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_MID);
+	top_idx = roc_nix_bpf_level_to_idx(mask & ROC_NIX_BPF_LEVEL_F_TOP);
+
+	if ((leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[leaf_idx] > NIX_MAX_BPF_COUNT_LEAF_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	if ((mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[mid_idx] > NIX_MAX_BPF_COUNT_MID_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	if ((top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) &&
+	    (per_lvl_cnt[top_idx] > NIX_MAX_BPF_COUNT_TOP_LAYER))
+		return NIX_ERR_INVALID_RANGE;
+
+	req = mbox_alloc_msg_nix_bandprof_alloc(mbox);
+	if (req == NULL)
+		goto exit;
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[leaf_idx]] =
+			per_lvl_cnt[leaf_idx];
+	}
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[mid_idx]] =
+			per_lvl_cnt[mid_idx];
+	}
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		req->prof_count[sw_to_hw_lvl_map[top_idx]] =
+			per_lvl_cnt[top_idx];
+	}
+
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		goto exit;
+
+	if (leaf_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[leaf_idx].level = leaf_idx;
+		profs[leaf_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[leaf_idx]];
+		for (i = 0; i < profs[leaf_idx].count; i++) {
+			profs[leaf_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[leaf_idx]][i];
+		}
+	}
+
+	if (mid_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[mid_idx].level = mid_idx;
+		profs[mid_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[mid_idx]];
+		for (i = 0; i < profs[mid_idx].count; i++) {
+			profs[mid_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[mid_idx]][i];
+		}
+	}
+
+	if (top_idx != ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+		profs[top_idx].level = top_idx;
+		profs[top_idx].count =
+			rsp->prof_count[sw_to_hw_lvl_map[top_idx]];
+		for (i = 0; i < profs[top_idx].count; i++) {
+			profs[top_idx].ids[i] =
+				rsp->prof_idx[sw_to_hw_lvl_map[top_idx]][i];
+		}
+	}
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 6990c1f084..b8863a1155 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -82,6 +82,7 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_nix_bpf_alloc;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 05/28] common/cnxk: support RoC API to free bandwidth profiles
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (3 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 04/28] common/cnxk: support RoC API to alloc bandwidth profiles skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 06/28] common/cnxk: support RoC API to configure bandwidth profile skori
                           ` (22 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC interface to free HW bandwidth profiles on
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  6 +++++
 drivers/common/cnxk/roc_nix_bpf.c | 40 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  2 ++
 3 files changed, 48 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index b192a2b217..a5642337b2 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -533,6 +533,12 @@ int __roc_api roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
 				uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX],
 				struct roc_nix_bpf_objs *profs /* Out */);
 
+int __roc_api roc_nix_bpf_free(struct roc_nix *roc_nix,
+			       struct roc_nix_bpf_objs *profs,
+			       uint8_t num_prof);
+
+int __roc_api roc_nix_bpf_free_all(struct roc_nix *roc_nix);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 06394bda07..41d31bc6cd 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -170,3 +170,43 @@ roc_nix_bpf_alloc(struct roc_nix *roc_nix, uint8_t lvl_mask,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_free(struct roc_nix *roc_nix, struct roc_nix_bpf_objs *profs,
+		 uint8_t num_prof)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_free_req *req;
+	uint8_t level;
+	int i, j;
+
+	if (num_prof >= NIX_RX_BAND_PROF_LAYER_MAX)
+		return NIX_ERR_INVALID_RANGE;
+
+	req = mbox_alloc_msg_nix_bandprof_free(mbox);
+	if (req == NULL)
+		return -ENOSPC;
+
+	for (i = 0; i < num_prof; i++) {
+		level = sw_to_hw_lvl_map[profs[i].level];
+		req->prof_count[level] = profs[i].count;
+		for (j = 0; j < profs[i].count; j++)
+			req->prof_idx[level][j] = profs[i].ids[j];
+	}
+
+	return mbox_process(mbox);
+}
+
+int
+roc_nix_bpf_free_all(struct roc_nix *roc_nix)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_bandprof_free_req *req;
+
+	req = mbox_alloc_msg_nix_bandprof_free(mbox);
+	if (req == NULL)
+		return -ENOSPC;
+
+	req->free_all = true;
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index b8863a1155..3d474f8a96 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -84,6 +84,8 @@ INTERNAL {
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_free;
+	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 06/28] common/cnxk: support RoC API to configure bandwidth profile
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (4 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 05/28] common/cnxk: support RoC API to free " skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 07/28] common/cnxk: support RoC API to toggle profile state skori
                           ` (21 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to configure HW bandwidth profile for
CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/hw/nix.h      |  49 ++++++
 drivers/common/cnxk/roc_nix.h     |  63 ++++++++
 drivers/common/cnxk/roc_nix_bpf.c | 239 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 4 files changed, 352 insertions(+)

diff --git a/drivers/common/cnxk/hw/nix.h b/drivers/common/cnxk/hw/nix.h
index 7685b7dc1b..b9e65c942f 100644
--- a/drivers/common/cnxk/hw/nix.h
+++ b/drivers/common/cnxk/hw/nix.h
@@ -2113,6 +2113,55 @@ struct nix_lso_format {
 #define NIX_RPM_MAX_HW_FRS  16380UL
 #define NIX_MIN_HW_FRS	    60UL
 
+/** NIX policer rate limits */
+#define NIX_BPF_MAX_RATE_DIV_EXP  12
+#define NIX_BPF_MAX_RATE_EXPONENT 0xf
+#define NIX_BPF_MAX_RATE_MANTISSA 0xff
+
+#define NIX_BPF_RATE_CONST 2000000ULL
+
+/* NIX rate calculation in Bits/Sec
+ *	PIR_ADD = ((256 + NIX_*_PIR[RATE_MANTISSA])
+ *		<< NIX_*_PIR[RATE_EXPONENT]) / 256
+ *	PIR = (2E6 * PIR_ADD / (1 << NIX_*_PIR[RATE_DIVIDER_EXPONENT]))
+ *
+ *	CIR_ADD = ((256 + NIX_*_CIR[RATE_MANTISSA])
+ *		<< NIX_*_CIR[RATE_EXPONENT]) / 256
+ *	CIR = (2E6 * CIR_ADD / (CCLK_TICKS << NIX_*_CIR[RATE_DIVIDER_EXPONENT]))
+ */
+#define NIX_BPF_RATE(exponent, mantissa, div_exp)                              \
+	((NIX_BPF_RATE_CONST * ((256 + (mantissa)) << (exponent))) /           \
+	 (((1ull << (div_exp)) * 256)))
+
+/* Meter rate limits in Bits/Sec */
+#define NIX_BPF_RATE_MIN NIX_BPF_RATE(0, 0, NIX_BPF_MAX_RATE_DIV_EXP)
+#define NIX_BPF_RATE_MAX                                                       \
+	NIX_BPF_RATE(NIX_BPF_MAX_RATE_EXPONENT, NIX_BPF_MAX_RATE_MANTISSA, 0)
+
+#define NIX_BPF_DEFAULT_ADJUST_MANTISSA 511
+#define NIX_BPF_DEFAULT_ADJUST_EXPONENT 0
+
+/** NIX burst limits */
+#define NIX_BPF_MAX_BURST_EXPONENT 0xf
+#define NIX_BPF_MAX_BURST_MANTISSA 0xff
+
+/* NIX burst calculation
+ *	PIR_BURST = ((256 + NIX_*_PIR[BURST_MANTISSA])
+ *		<< (NIX_*_PIR[BURST_EXPONENT] + 1))
+ *			/ 256
+ *
+ *	CIR_BURST = ((256 + NIX_*_CIR[BURST_MANTISSA])
+ *		<< (NIX_*_CIR[BURST_EXPONENT] + 1))
+ *			/ 256
+ */
+#define NIX_BPF_BURST(exponent, mantissa)                                      \
+	(((256 + (mantissa)) << ((exponent) + 1)) / 256)
+
+/** Meter burst limits */
+#define NIX_BPF_BURST_MIN NIX_BPF_BURST(0, 0)
+#define NIX_BPF_BURST_MAX                                                      \
+	NIX_BPF_BURST(NIX_BPF_MAX_BURST_EXPONENT, NIX_BPF_MAX_BURST_MANTISSA)
+
 /* NIX rate limits */
 #define NIX_TM_MAX_RATE_DIV_EXP	 12
 #define NIX_TM_MAX_RATE_EXPONENT 0xf
diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index a5642337b2..c2cc823516 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -39,6 +39,65 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+enum roc_nix_bpf_color {
+	ROC_NIX_BPF_COLOR_GREEN,
+	ROC_NIX_BPF_COLOR_YELLOW,
+	ROC_NIX_BPF_COLOR_RED,
+	ROC_NIX_BPF_COLOR_MAX
+};
+
+enum roc_nix_bpf_algo {
+	ROC_NIX_BPF_ALGO_NONE,
+	ROC_NIX_BPF_ALGO_2698,
+	ROC_NIX_BPF_ALGO_4115,
+	ROC_NIX_BPF_ALGO_2697
+};
+
+enum roc_nix_bpf_lmode { ROC_NIX_BPF_LMODE_BYTE, ROC_NIX_BPF_LMODE_PACKET };
+
+enum roc_nix_bpf_action {
+	ROC_NIX_BPF_ACTION_PASS,
+	ROC_NIX_BPF_ACTION_DROP,
+	ROC_NIX_BPF_ACTION_RED
+};
+
+struct roc_nix_bpf_cfg {
+	enum roc_nix_bpf_algo alg;
+	enum roc_nix_bpf_lmode lmode;
+	enum roc_nix_bpf_color icolor;
+	enum roc_nix_bpf_pc_mode pc_mode;
+	bool tnl_ena;
+	union {
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2697. */
+		struct {
+			uint64_t cir;
+			uint64_t cbs;
+			uint64_t ebs;
+		} algo2697;
+
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_2698. */
+		struct {
+			uint64_t cir;
+			uint64_t pir;
+			uint64_t cbs;
+			uint64_t pbs;
+		} algo2698;
+
+		/* Valid when *alg* is set to ROC_NIX_BPF_ALGO_4115. */
+		struct {
+			uint64_t cir;
+			uint64_t eir;
+			uint64_t cbs;
+			uint64_t ebs;
+		} algo4115;
+	};
+
+	enum roc_nix_bpf_action action[ROC_NIX_BPF_COLOR_MAX];
+
+	/* Reserved for future config*/
+	uint32_t rsvd[3];
+};
+
 struct roc_nix_bpf_objs {
 	uint16_t level;
 	uint16_t count;
@@ -539,6 +598,10 @@ int __roc_api roc_nix_bpf_free(struct roc_nix *roc_nix,
 
 int __roc_api roc_nix_bpf_free_all(struct roc_nix *roc_nix);
 
+int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+				 enum roc_nix_bpf_level_flag lvl_flag,
+				 struct roc_nix_bpf_cfg *cfg);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 41d31bc6cd..aa5829ee42 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -26,6 +26,105 @@ get_mbox(struct roc_nix *roc_nix)
 	return dev->mbox;
 }
 
+static inline uint64_t
+meter_rate_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p,
+		  uint64_t *div_exp_p)
+{
+	uint64_t div_exp, exponent, mantissa;
+
+	/* Boundary checks */
+	if (value < NIX_BPF_RATE_MIN || value > NIX_BPF_RATE_MAX)
+		return 0;
+
+	if (value <= NIX_BPF_RATE(0, 0, 0)) {
+		/* Calculate rate div_exp and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * (256 + mantissa)
+		 *              / ((1 << div_exp) * 256))
+		 */
+		div_exp = 0;
+		exponent = 0;
+		mantissa = NIX_BPF_MAX_RATE_MANTISSA;
+
+		while (value < (NIX_BPF_RATE_CONST / (1 << div_exp)))
+			div_exp += 1;
+
+		while (value < ((NIX_BPF_RATE_CONST * (256 + mantissa)) /
+				((1 << div_exp) * 256)))
+			mantissa -= 1;
+	} else {
+		/* Calculate rate exponent and mantissa using
+		 * the following formula:
+		 *
+		 * value = (2E6 * ((256 + mantissa) << exponent)) / 256
+		 *
+		 */
+		div_exp = 0;
+		exponent = NIX_BPF_MAX_RATE_EXPONENT;
+		mantissa = NIX_BPF_MAX_RATE_MANTISSA;
+
+		while (value < (NIX_BPF_RATE_CONST * (1 << exponent)))
+			exponent -= 1;
+
+		while (value <
+		       ((NIX_BPF_RATE_CONST * ((256 + mantissa) << exponent)) /
+			256))
+			mantissa -= 1;
+	}
+
+	if (div_exp > NIX_BPF_MAX_RATE_DIV_EXP ||
+	    exponent > NIX_BPF_MAX_RATE_EXPONENT ||
+	    mantissa > NIX_BPF_MAX_RATE_MANTISSA)
+		return 0;
+
+	if (div_exp_p)
+		*div_exp_p = div_exp;
+	if (exponent_p)
+		*exponent_p = exponent;
+	if (mantissa_p)
+		*mantissa_p = mantissa;
+
+	/* Calculate real rate value */
+	return NIX_BPF_RATE(exponent, mantissa, div_exp);
+}
+
+static inline uint64_t
+meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
+{
+	uint64_t exponent, mantissa;
+
+	if (value < NIX_BPF_BURST_MIN || value > NIX_BPF_BURST_MAX)
+		return 0;
+
+	/* Calculate burst exponent and mantissa using
+	 * the following formula:
+	 *
+	 * value = (((256 + mantissa) << (exponent + 1)
+	 / 256)
+	 *
+	 */
+	exponent = NIX_BPF_MAX_BURST_EXPONENT;
+	mantissa = NIX_BPF_MAX_BURST_MANTISSA;
+
+	while (value < (1ull << (exponent + 1)))
+		exponent -= 1;
+
+	while (value < ((256 + mantissa) << (exponent + 1)) / 256)
+		mantissa -= 1;
+
+	if (exponent > NIX_BPF_MAX_BURST_EXPONENT ||
+	    mantissa > NIX_BPF_MAX_BURST_MANTISSA)
+		return 0;
+
+	if (exponent_p)
+		*exponent_p = exponent;
+	if (mantissa_p)
+		*mantissa_p = mantissa;
+
+	return NIX_BPF_BURST(exponent, mantissa);
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -210,3 +309,143 @@ roc_nix_bpf_free_all(struct roc_nix *roc_nix)
 	req->free_all = true;
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
+		   enum roc_nix_bpf_level_flag lvl_flag,
+		   struct roc_nix_bpf_cfg *cfg)
+{
+	uint64_t exponent_p = 0, mantissa_p = 0, div_exp_p = 0;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (!cfg)
+		return NIX_ERR_PARAM;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	aq->prof.adjust_exponent = NIX_BPF_DEFAULT_ADJUST_EXPONENT;
+	aq->prof.adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA;
+	if (cfg->lmode == ROC_NIX_BPF_LMODE_BYTE)
+		aq->prof.adjust_mantissa = NIX_BPF_DEFAULT_ADJUST_MANTISSA / 2;
+
+	aq->prof_mask.adjust_exponent = ~(aq->prof_mask.adjust_exponent);
+	aq->prof_mask.adjust_mantissa = ~(aq->prof_mask.adjust_mantissa);
+
+	switch (cfg->alg) {
+	case ROC_NIX_BPF_ALGO_2697:
+		meter_rate_to_nix(cfg->algo2697.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2697.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2697.ebs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	case ROC_NIX_BPF_ALGO_2698:
+		meter_rate_to_nix(cfg->algo2698.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_rate_to_nix(cfg->algo2698.pir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.peir_mantissa = mantissa_p;
+		aq->prof.peir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2698.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo2698.pbs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	case ROC_NIX_BPF_ALGO_4115:
+		meter_rate_to_nix(cfg->algo4115.cir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.cir_mantissa = mantissa_p;
+		aq->prof.cir_exponent = exponent_p;
+
+		meter_rate_to_nix(cfg->algo4115.eir, &exponent_p, &mantissa_p,
+				  &div_exp_p);
+		aq->prof.peir_mantissa = mantissa_p;
+		aq->prof.peir_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo4115.cbs, &exponent_p, &mantissa_p);
+		aq->prof.cbs_mantissa = mantissa_p;
+		aq->prof.cbs_exponent = exponent_p;
+
+		meter_burst_to_nix(cfg->algo4115.ebs, &exponent_p, &mantissa_p);
+		aq->prof.pebs_mantissa = mantissa_p;
+		aq->prof.pebs_exponent = exponent_p;
+
+		aq->prof_mask.cir_mantissa = ~(aq->prof_mask.cir_mantissa);
+		aq->prof_mask.peir_mantissa = ~(aq->prof_mask.peir_mantissa);
+		aq->prof_mask.cbs_mantissa = ~(aq->prof_mask.cbs_mantissa);
+		aq->prof_mask.pebs_mantissa = ~(aq->prof_mask.pebs_mantissa);
+
+		aq->prof_mask.cir_exponent = ~(aq->prof_mask.cir_exponent);
+		aq->prof_mask.peir_exponent = ~(aq->prof_mask.peir_exponent);
+		aq->prof_mask.cbs_exponent = ~(aq->prof_mask.cbs_exponent);
+		aq->prof_mask.pebs_exponent = ~(aq->prof_mask.pebs_exponent);
+		break;
+
+	default:
+		return NIX_ERR_PARAM;
+	}
+
+	aq->prof.lmode = cfg->lmode;
+	aq->prof.icolor = cfg->icolor;
+	aq->prof.pc_mode = cfg->pc_mode;
+	aq->prof.tnl_ena = cfg->tnl_ena;
+	aq->prof.gc_action = cfg->action[ROC_NIX_BPF_COLOR_GREEN];
+	aq->prof.yc_action = cfg->action[ROC_NIX_BPF_COLOR_YELLOW];
+	aq->prof.rc_action = cfg->action[ROC_NIX_BPF_COLOR_RED];
+
+	aq->prof_mask.lmode = ~(aq->prof_mask.lmode);
+	aq->prof_mask.icolor = ~(aq->prof_mask.icolor);
+	aq->prof_mask.pc_mode = ~(aq->prof_mask.pc_mode);
+	aq->prof_mask.tnl_ena = ~(aq->prof_mask.tnl_ena);
+	aq->prof_mask.gc_action = ~(aq->prof_mask.gc_action);
+	aq->prof_mask.yc_action = ~(aq->prof_mask.yc_action);
+	aq->prof_mask.rc_action = ~(aq->prof_mask.rc_action);
+
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 3d474f8a96..f34fd3b4a4 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -83,6 +83,7 @@ INTERNAL {
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
+	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 07/28] common/cnxk: support RoC API to toggle profile state
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (5 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 06/28] common/cnxk: support RoC API to configure bandwidth profile skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 08/28] common/cnxk: support RoC API to dump bandwidth profile skori
                           ` (20 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to enable or disable HW bandwidth profiles
on CN10K platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  4 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 39 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 44 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index c2cc823516..5b3bf38a82 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -217,6 +217,7 @@ struct roc_nix_stats_queue {
 struct roc_nix_rq {
 	/* Input parameters */
 	uint16_t qid;
+	uint16_t bpf_id;
 	uint64_t aura_handle;
 	bool ipsech_ena;
 	uint16_t first_skip;
@@ -602,6 +603,9 @@ int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 				 enum roc_nix_bpf_level_flag lvl_flag,
 				 struct roc_nix_bpf_cfg *cfg);
 
+int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
+				  struct roc_nix_rq *rq, bool enable);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index aa5829ee42..c61a697f1a 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -449,3 +449,42 @@ roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id, struct roc_nix_rq *rq,
+		    bool enable)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	if (rq->qid >= nix->nb_rx_queues)
+		return NIX_ERR_QUEUE_INVALID_RANGE;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = rq->qid;
+	aq->ctype = NIX_AQ_CTYPE_RQ;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	aq->rq.policer_ena = enable;
+	aq->rq_mask.policer_ena = ~(aq->rq_mask.policer_ena);
+	if (enable) {
+		aq->rq.band_prof_id = id;
+		aq->rq_mask.band_prof_id = ~(aq->rq_mask.band_prof_id);
+	}
+
+	rc = mbox_process(mbox);
+	if (rc)
+		goto exit;
+
+	rq->bpf_id = id;
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index f34fd3b4a4..05b19beaa2 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -85,6 +85,7 @@ INTERNAL {
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_ena_dis;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 08/28] common/cnxk: support RoC API to dump bandwidth profile
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (6 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 07/28] common/cnxk: support RoC API to toggle profile state skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 09/28] common/cnxk: support RoC API to setup precolor table skori
                           ` (19 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to dump bandwidth profile on CN10K
platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h      |  3 ++
 drivers/common/cnxk/roc_nix_bpf.c  | 86 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_platform.h |  1 +
 drivers/common/cnxk/version.map    |  1 +
 4 files changed, 91 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 5b3bf38a82..d7e8dd94e3 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -606,6 +606,9 @@ int __roc_api roc_nix_bpf_config(struct roc_nix *roc_nix, uint16_t id,
 int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
 				  struct roc_nix_rq *rq, bool enable);
 
+int __roc_api roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
+			       enum roc_nix_bpf_level_flag lvl_flag);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index c61a697f1a..8181753220 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -125,6 +125,60 @@ meter_burst_to_nix(uint64_t value, uint64_t *exponent_p, uint64_t *mantissa_p)
 	return NIX_BPF_BURST(exponent, mantissa);
 }
 
+static inline void
+nix_lf_bpf_dump(__io struct nix_band_prof_s *bpf)
+{
+	plt_dump("W0: cir_mantissa  \t\t\t%d\nW0: pebs_mantissa \t\t\t0x%03x",
+		 bpf->cir_mantissa, bpf->pebs_mantissa);
+	plt_dump("W0: peir_matissa \t\t\t\t%d\nW0: cbs_exponent \t\t\t%d",
+		 bpf->peir_mantissa, bpf->cbs_exponent);
+	plt_dump("W0: cir_exponent \t\t\t%d\nW0: pebs_exponent \t\t\t%d",
+		 bpf->cir_exponent, bpf->pebs_exponent);
+	plt_dump("W0: peir_exponent \t\t\t%d\n", bpf->peir_exponent);
+	plt_dump("W0: tnl_ena \t\t\t%d\n", bpf->tnl_ena);
+	plt_dump("W0: icolor \t\t\t%d\n", bpf->icolor);
+	plt_dump("W0: pc_mode \t\t\t%d\n", bpf->pc_mode);
+	plt_dump("W1: hl_en \t\t%d\nW1: band_prof_id \t\t%d", bpf->hl_en,
+		 bpf->band_prof_id);
+	plt_dump("W1: meter_algo \t\t%d\nW1: rc_action \t\t%d", bpf->meter_algo,
+		 bpf->rc_action);
+	plt_dump("W1: yc_action \t\t\t%d\nW1: gc_action \t\t\t%d",
+		 bpf->yc_action, bpf->gc_action);
+	plt_dump("W1: adjust_mantissa\t\t\t%d\nW1: adjust_exponent \t\t\t%d",
+		 bpf->adjust_mantissa, bpf->adjust_exponent);
+	plt_dump("W1: rdiv \t\t\t%d\n", bpf->rdiv);
+	plt_dump("W1: l_select \t\t%d\nW2: lmode \t\t%d", bpf->l_sellect,
+		 bpf->lmode);
+	plt_dump("W1: cbs_mantissa \t\t\t%d\n", bpf->cbs_mantissa);
+	plt_dump("W2: tsa \t\t\t0x%" PRIx64 "\n", (uint64_t)bpf->ts);
+	plt_dump("W3: c_accum \t\t%d\nW3: pe_accum \t\t%d", bpf->c_accum,
+		 bpf->pe_accum);
+	plt_dump("W4: green_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_pkt_pass);
+	plt_dump("W5: yellow_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_pkt_pass);
+	plt_dump("W6: red_pkt_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_pkt_pass);
+	plt_dump("W7: green_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_octs_pass);
+	plt_dump("W8: yellow_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_octs_pass);
+	plt_dump("W9: red_octs_pass \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_octs_pass);
+	plt_dump("W10: green_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_pkt_drop);
+	plt_dump("W11: yellow_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_pkt_drop);
+	plt_dump("W12: red_pkt_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_pkt_drop);
+	plt_dump("W13: green_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->green_octs_drop);
+	plt_dump("W14: yellow_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->yellow_octs_drop);
+	plt_dump("W15: red_octs_drop \t\t\t0x%" PRIx64 "",
+		 (uint64_t)bpf->red_octs_drop);
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -488,3 +542,35 @@ roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id, struct roc_nix_rq *rq,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
+		 enum roc_nix_bpf_level_flag lvl_flag)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_rsp *rsp;
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_READ;
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (!rc) {
+		plt_dump("============= band prof id =%d ===============", id);
+		nix_lf_bpf_dump(&rsp->prof);
+	}
+
+	return rc;
+}
diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h
index 241655b334..3a586d3617 100644
--- a/drivers/common/cnxk/roc_platform.h
+++ b/drivers/common/cnxk/roc_platform.h
@@ -158,6 +158,7 @@ extern int cnxk_logtype_tm;
 #define plt_info(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
 #define plt_warn(fmt, args...) RTE_LOG(WARNING, PMD, fmt "\n", ##args)
 #define plt_print(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
+#define plt_dump(fmt, ...)      fprintf(stderr, fmt "\n", ##__VA_ARGS__)
 
 /**
  * Log debug message if given subsystem logging is enabled.
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 05b19beaa2..959250ea8e 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -85,6 +85,7 @@ INTERNAL {
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_count_get;
+	roc_nix_bpf_dump;
 	roc_nix_bpf_ena_dis;
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 09/28] common/cnxk: support RoC API to setup precolor table
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (7 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 08/28] common/cnxk: support RoC API to dump bandwidth profile skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 10/28] common/cnxk: support RoC API to connect bandwidth profiles skori
                           ` (18 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

For initial coloring of input packet, CN10K platform maintains
precolor table for VLAN, DSCP and Generic. Implement RoC
interface to setup pre color table.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  20 ++++
 drivers/common/cnxk/roc_nix_bpf.c | 193 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   1 +
 3 files changed, 214 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index d7e8dd94e3..d125941c5c 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -39,6 +39,15 @@ enum roc_nix_bpf_level_flag {
 	ROC_NIX_BPF_LEVEL_F_TOP = BIT(2),
 };
 
+enum roc_nix_bpf_pc_mode {
+	ROC_NIX_BPF_PC_MODE_VLAN_INNER,
+	ROC_NIX_BPF_PC_MODE_VLAN_OUTER,
+	ROC_NIX_BPF_PC_MODE_DSCP_INNER,
+	ROC_NIX_BPF_PC_MODE_DSCP_OUTER,
+	ROC_NIX_BPF_PC_MODE_GEN_INNER,
+	ROC_NIX_BPF_PC_MODE_GEN_OUTER
+};
+
 enum roc_nix_bpf_color {
 	ROC_NIX_BPF_COLOR_GREEN,
 	ROC_NIX_BPF_COLOR_YELLOW,
@@ -104,6 +113,13 @@ struct roc_nix_bpf_objs {
 	uint16_t ids[ROC_NIX_BPF_PER_PFFUNC];
 };
 
+struct roc_nix_bpf_precolor {
+#define ROC_NIX_BPF_PRE_COLOR_MAX 64
+	uint8_t count;
+	enum roc_nix_bpf_pc_mode mode;
+	enum roc_nix_bpf_color color[ROC_NIX_BPF_PRE_COLOR_MAX];
+};
+
 struct roc_nix_vlan_config {
 	uint32_t type;
 	union {
@@ -609,6 +625,10 @@ int __roc_api roc_nix_bpf_ena_dis(struct roc_nix *roc_nix, uint16_t id,
 int __roc_api roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
 			       enum roc_nix_bpf_level_flag lvl_flag);
 
+int __roc_api roc_nix_bpf_pre_color_tbl_setup(
+	struct roc_nix *roc_nix, uint16_t id,
+	enum roc_nix_bpf_level_flag lvl_flag, struct roc_nix_bpf_precolor *tbl);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 8181753220..8c84bbb656 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -9,6 +9,10 @@
 #define NIX_MAX_BPF_COUNT_MID_LAYER  8
 #define NIX_MAX_BPF_COUNT_TOP_LAYER  1
 
+#define NIX_BPF_PRECOLOR_GEN_TABLE_SIZE	 16
+#define NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE 16
+#define NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE 64
+
 #define NIX_BPF_LEVEL_F_MASK                                                   \
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
@@ -179,6 +183,107 @@ nix_lf_bpf_dump(__io struct nix_band_prof_s *bpf)
 		 (uint64_t)bpf->red_octs_drop);
 }
 
+static inline void
+nix_precolor_conv_table_write(struct roc_nix *roc_nix, uint64_t val,
+			      uint32_t off)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	int64_t *addr;
+
+	addr = PLT_PTR_ADD(nix->base, off);
+	/* FIXME: Currently writing to this register throwing kernel dump.
+	 * plt_write64(val, addr);
+	 */
+	PLT_SET_USED(val);
+	PLT_SET_USED(addr);
+}
+
+static uint8_t
+nix_precolor_vlan_table_update(struct roc_nix *roc_nix,
+			       struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val = 0, i;
+	uint8_t tn_ena;
+	uint32_t off;
+
+	for (i = 0; i < tbl->count; i++)
+		val |= (((uint64_t)tbl->color[i]) << (2 * i));
+
+	if (tbl->mode == ROC_NIX_BPF_PC_MODE_VLAN_INNER) {
+		off = NIX_LF_RX_VLAN1_COLOR_CONV;
+		tn_ena = true;
+	} else {
+		off = NIX_LF_RX_VLAN0_COLOR_CONV;
+		tn_ena = false;
+	}
+
+	nix_precolor_conv_table_write(roc_nix, val, off);
+	return tn_ena;
+}
+
+static uint8_t
+nix_precolor_inner_dscp_table_update(struct roc_nix *roc_nix,
+				     struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val_lo = 0, val_hi = 0, i, j;
+
+	for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
+		val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	for (j = 0; i < tbl->count; i++, j++)
+		val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	nix_precolor_conv_table_write(roc_nix, val_lo,
+				      NIX_LF_RX_IIP_COLOR_CONV_LO);
+	nix_precolor_conv_table_write(roc_nix, val_hi,
+				      NIX_LF_RX_IIP_COLOR_CONV_HI);
+
+	return true;
+}
+
+static uint8_t
+nix_precolor_outer_dscp_table_update(struct roc_nix *roc_nix,
+				     struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val_lo = 0, val_hi = 0, i, j;
+
+	for (i = 0, j = 0; i < (tbl->count / 2); i++, j++)
+		val_lo |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	for (j = 0; i < tbl->count; i++, j++)
+		val_hi |= (((uint64_t)tbl->color[i]) << (2 * j));
+
+	nix_precolor_conv_table_write(roc_nix, val_lo,
+				      NIX_LF_RX_OIP_COLOR_CONV_LO);
+	nix_precolor_conv_table_write(roc_nix, val_hi,
+				      NIX_LF_RX_OIP_COLOR_CONV_HI);
+
+	return false;
+}
+
+static uint8_t
+nix_precolor_gen_table_update(struct roc_nix *roc_nix,
+			      struct roc_nix_bpf_precolor *tbl)
+{
+	uint64_t val = 0, i;
+	uint8_t tn_ena;
+	uint32_t off;
+
+	for (i = 0; i < tbl->count; i++)
+		val |= (((uint64_t)tbl->color[i]) << (2 * i));
+
+	if (tbl->mode == ROC_NIX_BPF_PC_MODE_GEN_INNER) {
+		off = NIX_LF_RX_GEN_COLOR_CONVX(1);
+		tn_ena = true;
+	} else {
+		off = NIX_LF_RX_GEN_COLOR_CONVX(0);
+		tn_ena = false;
+	}
+
+	nix_precolor_conv_table_write(roc_nix, val, off);
+	return tn_ena;
+}
+
 uint8_t
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 {
@@ -574,3 +679,91 @@ roc_nix_bpf_dump(struct roc_nix *roc_nix, uint16_t id,
 
 	return rc;
 }
+
+int
+roc_nix_bpf_pre_color_tbl_setup(struct roc_nix *roc_nix, uint16_t id,
+				enum roc_nix_bpf_level_flag lvl_flag,
+				struct roc_nix_bpf_precolor *tbl)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t pc_mode, tn_ena;
+	uint8_t level_idx;
+	int rc;
+
+	if (!tbl || !tbl->count)
+		return NIX_ERR_PARAM;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	switch (tbl->mode) {
+	case ROC_NIX_BPF_PC_MODE_VLAN_INNER:
+	case ROC_NIX_BPF_PC_MODE_VLAN_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_VLAN_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_vlan_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_VLAN;
+		break;
+	case ROC_NIX_BPF_PC_MODE_DSCP_INNER:
+		if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_inner_dscp_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
+		break;
+	case ROC_NIX_BPF_PC_MODE_DSCP_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_DSCP_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+		tn_ena = nix_precolor_outer_dscp_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_DSCP;
+		break;
+	case ROC_NIX_BPF_PC_MODE_GEN_INNER:
+	case ROC_NIX_BPF_PC_MODE_GEN_OUTER:
+		if (tbl->count != NIX_BPF_PRECOLOR_GEN_TABLE_SIZE) {
+			plt_err("Table size must be %d",
+				NIX_BPF_PRECOLOR_GEN_TABLE_SIZE);
+			rc = NIX_ERR_PARAM;
+			goto exit;
+		}
+
+		tn_ena = nix_precolor_gen_table_update(roc_nix, tbl);
+		pc_mode = NIX_RX_BAND_PROF_PC_MODE_GEN;
+		break;
+	default:
+		rc = NIX_ERR_PARAM;
+		goto exit;
+	}
+
+	/* Update corresponding bandwidth profile too */
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+	aq->prof.pc_mode = pc_mode;
+	aq->prof.tnl_ena = tn_ena;
+	aq->prof_mask.pc_mode = ~(aq->prof_mask.pc_mode);
+	aq->prof_mask.tnl_ena = ~(aq->prof_mask.tnl_ena);
+
+	return mbox_process(mbox);
+
+exit:
+	return rc;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 959250ea8e..836cbec4dc 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -90,6 +90,7 @@ INTERNAL {
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
+	roc_nix_bpf_pre_color_tbl_setup;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 10/28] common/cnxk: support RoC API to connect bandwidth profiles
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (8 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 09/28] common/cnxk: support RoC API to setup precolor table skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 11/28] common/cnxk: support RoC API to get stats to index skori
                           ` (17 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

To maintain chain of bandwidth profiles, they needs to be
connected. Implement RoC API to connect two bandwidth profiles
at different levels.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |  6 ++++++
 drivers/common/cnxk/roc_nix_bpf.c | 36 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 43 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index d125941c5c..be24d20462 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -7,6 +7,7 @@
 
 /* Constants */
 #define ROC_NIX_BPF_PER_PFFUNC	      64
+#define ROC_NIX_BPF_ID_INVALID	      0xFFFF
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
 
@@ -629,6 +630,11 @@ int __roc_api roc_nix_bpf_pre_color_tbl_setup(
 	struct roc_nix *roc_nix, uint16_t id,
 	enum roc_nix_bpf_level_flag lvl_flag, struct roc_nix_bpf_precolor *tbl);
 
+/* Use ROC_NIX_BPF_ID_INVALID as dst_id to disconnect */
+int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
+				  enum roc_nix_bpf_level_flag lvl_flag,
+				  uint16_t src_id, uint16_t dst_id);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 8c84bbb656..807723f7b7 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -767,3 +767,39 @@ roc_nix_bpf_pre_color_tbl_setup(struct roc_nix *roc_nix, uint16_t id,
 exit:
 	return rc;
 }
+
+int
+roc_nix_bpf_connect(struct roc_nix *roc_nix,
+		    enum roc_nix_bpf_level_flag lvl_flag, uint16_t src_id,
+		    uint16_t dst_id)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14) | src_id;
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	if (dst_id == ROC_NIX_BPF_ID_INVALID) {
+		aq->prof.hl_en = false;
+		aq->prof_mask.hl_en = ~(aq->prof_mask.hl_en);
+	} else {
+		aq->prof.hl_en = true;
+		aq->prof.band_prof_id = dst_id;
+		aq->prof_mask.hl_en = ~(aq->prof_mask.hl_en);
+		aq->prof_mask.band_prof_id = ~(aq->prof_mask.band_prof_id);
+	}
+
+	return mbox_process(mbox);
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 836cbec4dc..dfd2cdc287 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -84,6 +84,7 @@ INTERNAL {
 	roc_se_ciph_key_set;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
+	roc_nix_bpf_connect;
 	roc_nix_bpf_count_get;
 	roc_nix_bpf_dump;
 	roc_nix_bpf_ena_dis;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 11/28] common/cnxk: support RoC API to get stats to index
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (9 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 10/28] common/cnxk: support RoC API to connect bandwidth profiles skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 12/28] common/cnxk: support RoC API to read profile statistics skori
                           ` (16 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform supports different stats for HW bandwidth profiles.
Implement RoC API to get index for given stats type.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     | 18 ++++++++++++++++
 drivers/common/cnxk/roc_nix_bpf.c | 34 +++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |  1 +
 3 files changed, 53 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index be24d20462..c6cf42e8f4 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -10,6 +10,7 @@
 #define ROC_NIX_BPF_ID_INVALID	      0xFFFF
 #define ROC_NIX_BPF_LEVEL_IDX_INVALID 0xFF
 #define ROC_NIX_BPF_LEVEL_MAX	      3
+#define ROC_NIX_BPF_STATS_MAX	      12
 
 enum roc_nix_rss_reta_sz {
 	ROC_NIX_RSS_RETA_SZ_64 = 64,
@@ -71,6 +72,21 @@ enum roc_nix_bpf_action {
 	ROC_NIX_BPF_ACTION_RED
 };
 
+enum roc_nix_bpf_stats {
+	ROC_NIX_BPF_GREEN_PKT_F_PASS = BIT_ULL(0),
+	ROC_NIX_BPF_GREEN_OCTS_F_PASS = BIT_ULL(1),
+	ROC_NIX_BPF_GREEN_PKT_F_DROP = BIT_ULL(2),
+	ROC_NIX_BPF_GREEN_OCTS_F_DROP = BIT_ULL(3),
+	ROC_NIX_BPF_YELLOW_PKT_F_PASS = BIT_ULL(4),
+	ROC_NIX_BPF_YELLOW_OCTS_F_PASS = BIT_ULL(5),
+	ROC_NIX_BPF_YELLOW_PKT_F_DROP = BIT_ULL(6),
+	ROC_NIX_BPF_YELLOW_OCTS_F_DROP = BIT_ULL(7),
+	ROC_NIX_BPF_RED_PKT_F_PASS = BIT_ULL(8),
+	ROC_NIX_BPF_RED_OCTS_F_PASS = BIT_ULL(9),
+	ROC_NIX_BPF_RED_PKT_F_DROP = BIT_ULL(10),
+	ROC_NIX_BPF_RED_OCTS_F_DROP = BIT_ULL(11),
+};
+
 struct roc_nix_bpf_cfg {
 	enum roc_nix_bpf_algo alg;
 	enum roc_nix_bpf_lmode lmode;
@@ -638,6 +654,8 @@ int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
+uint8_t __roc_api roc_nix_bpf_stats_to_idx(enum roc_nix_bpf_stats lvl_flag);
+
 /* MAC */
 int __roc_api roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start);
 int __roc_api roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix,
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 807723f7b7..7c1ac9d728 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -300,6 +300,40 @@ roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag level_f)
 	return idx;
 }
 
+uint8_t
+roc_nix_bpf_stats_to_idx(enum roc_nix_bpf_stats level_f)
+{
+	uint8_t idx;
+
+	if (level_f & ROC_NIX_BPF_GREEN_PKT_F_PASS)
+		idx = 0;
+	else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
+		idx = 1;
+	else if (level_f & ROC_NIX_BPF_GREEN_PKT_F_DROP)
+		idx = 2;
+	else if (level_f & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
+		idx = 3;
+	else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
+		idx = 4;
+	else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
+		idx = 5;
+	else if (level_f & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
+		idx = 6;
+	else if (level_f & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
+		idx = 7;
+	else if (level_f & ROC_NIX_BPF_RED_PKT_F_PASS)
+		idx = 8;
+	else if (level_f & ROC_NIX_BPF_RED_OCTS_F_PASS)
+		idx = 9;
+	else if (level_f & ROC_NIX_BPF_RED_PKT_F_DROP)
+		idx = 10;
+	else if (level_f & ROC_NIX_BPF_RED_OCTS_F_DROP)
+		idx = 11;
+	else
+		idx = ROC_NIX_BPF_STATS_MAX;
+	return idx;
+}
+
 int
 roc_nix_bpf_count_get(struct roc_nix *roc_nix, uint8_t lvl_mask,
 		      uint16_t count[ROC_NIX_BPF_LEVEL_MAX])
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index dfd2cdc287..e9643f7469 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -92,6 +92,7 @@ INTERNAL {
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_bpf_pre_color_tbl_setup;
+	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
 	roc_nix_cq_init;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 12/28] common/cnxk: support RoC API to read profile statistics
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (10 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 11/28] common/cnxk: support RoC API to get stats to index skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 13/28] common/cnxk: support RoC API to reset profile stats skori
                           ` (15 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

CN10K platform provides statistics per bandwidth profile and
per nixlf. Implement RoC API to read stats for given bandwidth
profile.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |   9 ++
 drivers/common/cnxk/roc_nix_bpf.c | 197 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   2 +
 3 files changed, 208 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index c6cf42e8f4..0416778c11 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -651,6 +651,15 @@ int __roc_api roc_nix_bpf_connect(struct roc_nix *roc_nix,
 				  enum roc_nix_bpf_level_flag lvl_flag,
 				  uint16_t src_id, uint16_t dst_id);
 
+int __roc_api
+roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+		       enum roc_nix_bpf_level_flag lvl_flag,
+		       uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
+
+int __roc_api
+roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
+			  uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index 7c1ac9d728..a5e3575404 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -17,6 +17,9 @@
 	(ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |                  \
 	 ROC_NIX_BPF_LEVEL_F_TOP)
 
+#define NIX_RD_STATS(val)  plt_read64(nix->base + NIX_LF_RX_STATX(val))
+#define NIX_RST_STATS(val) plt_write64(0, nix->base + NIX_LF_RX_STATX(val))
+
 static uint8_t sw_to_hw_lvl_map[] = {NIX_RX_BAND_PROF_LAYER_LEAF,
 				     NIX_RX_BAND_PROF_LAYER_MIDDLE,
 				     NIX_RX_BAND_PROF_LAYER_TOP};
@@ -837,3 +840,197 @@ roc_nix_bpf_connect(struct roc_nix *roc_nix,
 
 	return mbox_process(mbox);
 }
+
+int
+roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+		       enum roc_nix_bpf_level_flag lvl_flag,
+		       uint64_t stats[ROC_NIX_BPF_STATS_MAX])
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_rsp *rsp;
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+	int rc;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_READ;
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		return rc;
+
+	green_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[green_pkt_pass] = rsp->prof.green_pkt_pass;
+
+	if (green_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[green_octs_pass] = rsp->prof.green_octs_pass;
+
+	if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[green_pkt_drop] = rsp->prof.green_pkt_drop;
+
+	if (green_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[green_octs_drop] = rsp->prof.green_octs_pass;
+
+	if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_pkt_pass] = rsp->prof.yellow_pkt_pass;
+
+	if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_octs_pass] = rsp->prof.yellow_octs_pass;
+
+	if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_pkt_drop] = rsp->prof.yellow_pkt_drop;
+
+	if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[yellow_octs_drop] = rsp->prof.yellow_octs_drop;
+
+	if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[red_pkt_pass] = rsp->prof.red_pkt_pass;
+
+	if (red_octs_pass != ROC_NIX_BPF_STATS_MAX)
+		stats[red_octs_pass] = rsp->prof.red_octs_pass;
+
+	if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[red_pkt_drop] = rsp->prof.red_pkt_drop;
+
+	if (red_octs_drop != ROC_NIX_BPF_STATS_MAX)
+		stats[red_octs_drop] = rsp->prof.red_octs_drop;
+
+	return 0;
+}
+
+int
+roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
+			  uint64_t stats[ROC_NIX_BPF_STATS_MAX])
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+
+	green_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop =
+		roc_nix_bpf_stats_to_idx(mask & ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (green_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_PASSED);
+	}
+
+	if (green_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_PASSED);
+	}
+
+	if (green_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_OCTS_DROP);
+	}
+
+	if (green_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[green_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_PKTS_DROP);
+	}
+
+	if (yellow_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_PASSED);
+	}
+
+	if (yellow_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_PASSED);
+	}
+
+	if (yellow_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_GC_PKTS_DROP);
+	}
+
+	if (yellow_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[yellow_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_OCTS_DROP);
+	}
+
+	if (red_pkt_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_pkt_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_PASSED);
+	}
+
+	if (red_octs_pass != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_octs_pass] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_PASSED);
+	}
+
+	if (red_pkt_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_pkt_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_YC_OCTS_DROP);
+	}
+
+	if (red_octs_drop != ROC_NIX_BPF_STATS_MAX) {
+		stats[red_octs_drop] =
+			NIX_RD_STATS(NIX_STAT_LF_RX_RX_RC_PKTS_DROP);
+	}
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index e9643f7469..94a25d58ef 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -91,7 +91,9 @@ INTERNAL {
 	roc_nix_bpf_free;
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
+	roc_nix_bpf_lf_stats_read;
 	roc_nix_bpf_pre_color_tbl_setup;
+	roc_nix_bpf_stats_read;
 	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 13/28] common/cnxk: support RoC API to reset profile stats
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (11 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 12/28] common/cnxk: support RoC API to read profile statistics skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 14/28] common/cnxk: support meter in action list skori
                           ` (14 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	Ray Kinsella
  Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Implement RoC API to reset stats per bandwidth profile
or per nixlf.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_nix.h     |   7 ++
 drivers/common/cnxk/roc_nix_bpf.c | 113 ++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   2 +
 3 files changed, 122 insertions(+)

diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 0416778c11..343bb2f8b7 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -656,10 +656,17 @@ roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
 		       enum roc_nix_bpf_level_flag lvl_flag,
 		       uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_stats_reset(struct roc_nix *roc_nix, uint16_t id,
+				      uint64_t mask,
+				      enum roc_nix_bpf_level_flag lvl_flag);
+
 int __roc_api
 roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 			  uint64_t stats[ROC_NIX_BPF_STATS_MAX] /* Out */);
 
+int __roc_api roc_nix_bpf_lf_stats_reset(struct roc_nix *roc_nix,
+					 uint64_t mask);
+
 uint8_t __roc_api
 roc_nix_bpf_level_to_idx(enum roc_nix_bpf_level_flag lvl_flag);
 
diff --git a/drivers/common/cnxk/roc_nix_bpf.c b/drivers/common/cnxk/roc_nix_bpf.c
index a5e3575404..df57958683 100644
--- a/drivers/common/cnxk/roc_nix_bpf.c
+++ b/drivers/common/cnxk/roc_nix_bpf.c
@@ -937,6 +937,86 @@ roc_nix_bpf_stats_read(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
 	return 0;
 }
 
+int
+roc_nix_bpf_stats_reset(struct roc_nix *roc_nix, uint16_t id, uint64_t mask,
+			enum roc_nix_bpf_level_flag lvl_flag)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct nix_cn10k_aq_enq_req *aq;
+	uint8_t level_idx;
+
+	if (roc_model_is_cn9k())
+		return NIX_ERR_HW_NOTSUP;
+
+	level_idx = roc_nix_bpf_level_to_idx(lvl_flag);
+	if (level_idx == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return NIX_ERR_PARAM;
+
+	aq = mbox_alloc_msg_nix_cn10k_aq_enq(mbox);
+	if (aq == NULL)
+		return -ENOSPC;
+	aq->qidx = (sw_to_hw_lvl_map[level_idx] << 14 | id);
+	aq->ctype = NIX_AQ_CTYPE_BAND_PROF;
+	aq->op = NIX_AQ_INSTOP_WRITE;
+
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS) {
+		aq->prof.green_pkt_pass = 0;
+		aq->prof_mask.green_pkt_pass = ~(aq->prof_mask.green_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS) {
+		aq->prof.green_octs_pass = 0;
+		aq->prof_mask.green_octs_pass =
+			~(aq->prof_mask.green_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP) {
+		aq->prof.green_pkt_drop = 0;
+		aq->prof_mask.green_pkt_drop = ~(aq->prof_mask.green_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP) {
+		aq->prof.green_octs_drop = 0;
+		aq->prof_mask.green_octs_drop =
+			~(aq->prof_mask.green_octs_drop);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS) {
+		aq->prof.yellow_pkt_pass = 0;
+		aq->prof_mask.yellow_pkt_pass =
+			~(aq->prof_mask.yellow_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS) {
+		aq->prof.yellow_octs_pass = 0;
+		aq->prof_mask.yellow_octs_pass =
+			~(aq->prof_mask.yellow_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP) {
+		aq->prof.yellow_pkt_drop = 0;
+		aq->prof_mask.yellow_pkt_drop =
+			~(aq->prof_mask.yellow_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP) {
+		aq->prof.yellow_octs_drop = 0;
+		aq->prof_mask.yellow_octs_drop =
+			~(aq->prof_mask.yellow_octs_drop);
+	}
+	if (mask & ROC_NIX_BPF_RED_PKT_F_PASS) {
+		aq->prof.red_pkt_pass = 0;
+		aq->prof_mask.red_pkt_pass = ~(aq->prof_mask.red_pkt_pass);
+	}
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS) {
+		aq->prof.red_octs_pass = 0;
+		aq->prof_mask.red_octs_pass = ~(aq->prof_mask.red_octs_pass);
+	}
+	if (mask & ROC_NIX_BPF_RED_PKT_F_DROP) {
+		aq->prof.red_pkt_drop = 0;
+		aq->prof_mask.red_pkt_drop = ~(aq->prof_mask.red_pkt_drop);
+	}
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP) {
+		aq->prof.red_octs_drop = 0;
+		aq->prof_mask.red_octs_drop = ~(aq->prof_mask.red_octs_drop);
+	}
+
+	return mbox_process(mbox);
+}
+
 int
 roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 			  uint64_t stats[ROC_NIX_BPF_STATS_MAX])
@@ -1034,3 +1114,36 @@ roc_nix_bpf_lf_stats_read(struct roc_nix *roc_nix, uint64_t mask,
 
 	return 0;
 }
+
+int
+roc_nix_bpf_lf_stats_reset(struct roc_nix *roc_nix, uint64_t mask)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_GREEN_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_GREEN_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_YELLOW_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_YELLOW_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	if (mask & ROC_NIX_BPF_RED_PKT_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_PASS);
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_PASS)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_PASS);
+	if (mask & ROC_NIX_BPF_RED_PKT_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_PKT_F_DROP);
+	if (mask & ROC_NIX_BPF_RED_OCTS_F_DROP)
+		NIX_RST_STATS(ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	return 0;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 94a25d58ef..f5de985224 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -92,8 +92,10 @@ INTERNAL {
 	roc_nix_bpf_free_all;
 	roc_nix_bpf_level_to_idx;
 	roc_nix_bpf_lf_stats_read;
+	roc_nix_bpf_lf_stats_reset;
 	roc_nix_bpf_pre_color_tbl_setup;
 	roc_nix_bpf_stats_read;
+	roc_nix_bpf_stats_reset;
 	roc_nix_bpf_stats_to_idx;
 	roc_nix_cq_dump;
 	roc_nix_cq_fini;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 14/28] common/cnxk: support meter in action list
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (12 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 13/28] common/cnxk: support RoC API to reset profile stats skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 15/28] net/cnxk: support meter ops get API skori
                           ` (13 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao; +Cc: dev

From: Sunil Kumar Kori <skori@marvell.com>

Meter action is added in supported action list.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/common/cnxk/roc_npc.c | 7 +++++++
 drivers/common/cnxk/roc_npc.h | 8 +++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/common/cnxk/roc_npc.c b/drivers/common/cnxk/roc_npc.c
index b724ff9401..5a78d9652c 100644
--- a/drivers/common/cnxk/roc_npc.c
+++ b/drivers/common/cnxk/roc_npc.c
@@ -348,6 +348,7 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
 {
 	struct npc *npc = roc_npc_to_npc_priv(roc_npc);
 	const struct roc_npc_action_mark *act_mark;
+	const struct roc_npc_action_meter *act_mtr;
 	const struct roc_npc_action_queue *act_q;
 	const struct roc_npc_action_vf *vf_act;
 	bool vlan_insert_action = false;
@@ -451,6 +452,12 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
 		case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
 			req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
 			break;
+		case ROC_NPC_ACTION_TYPE_METER:
+			act_mtr = (const struct roc_npc_action_meter *)
+					  actions->conf;
+			flow->mtr_id = act_mtr->mtr_id;
+			req_act |= ROC_NPC_ACTION_TYPE_METER;
+			break;
 		default:
 			errcode = NPC_ERR_ACTION_NOTSUP;
 			goto err_exit;
diff --git a/drivers/common/cnxk/roc_npc.h b/drivers/common/cnxk/roc_npc.h
index 65d4bd6edc..10d1ac82a4 100644
--- a/drivers/common/cnxk/roc_npc.h
+++ b/drivers/common/cnxk/roc_npc.h
@@ -58,7 +58,7 @@ struct roc_npc_flow_item_raw {
 	const uint8_t *pattern; /**< Byte string to look for. */
 };
 
-#define ROC_NPC_MAX_ACTION_COUNT 12
+#define ROC_NPC_MAX_ACTION_COUNT 19
 
 enum roc_npc_action_type {
 	ROC_NPC_ACTION_TYPE_END = (1 << 0),
@@ -77,6 +77,7 @@ enum roc_npc_action_type {
 	ROC_NPC_ACTION_TYPE_VLAN_INSERT = (1 << 13),
 	ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT = (1 << 14),
 	ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT = (1 << 15),
+	ROC_NPC_ACTION_TYPE_METER = (1 << 17),
 };
 
 struct roc_npc_action {
@@ -110,6 +111,10 @@ struct roc_npc_action_of_set_vlan_pcp {
 	uint8_t vlan_pcp; /**< VLAN priority. */
 };
 
+struct roc_npc_action_meter {
+	uint32_t mtr_id; /**< Meter id to be applied. > */
+};
+
 struct roc_npc_attr {
 	uint32_t priority;	/**< Rule priority level within group. */
 	uint32_t ingress : 1;	/**< Rule applies to ingress traffic. */
@@ -128,6 +133,7 @@ struct roc_npc_flow {
 	uint32_t mcam_id;
 	int32_t ctr_id;
 	uint32_t priority;
+	uint32_t mtr_id;
 #define ROC_NPC_MAX_MCAM_WIDTH_DWORDS 7
 	/* Contiguous match string */
 	uint64_t mcam_data[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 15/28] net/cnxk: support meter ops get API
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (13 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 14/28] common/cnxk: support meter in action list skori
@ 2021-10-12  7:05         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 16/28] net/cnxk: support ops to get meter capabilities skori
                           ` (12 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:05 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

To enable support for ingress meter, supported operations
are exposed for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev.c     |  1 +
 drivers/net/cnxk/cnxk_ethdev.h     |  3 +++
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 18 ++++++++++++++++++
 drivers/net/cnxk/meson.build       |  1 +
 4 files changed, 23 insertions(+)
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mtr.c

diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index ec00e620eb..f694abd71d 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -1498,6 +1498,7 @@ struct eth_dev_ops cnxk_eth_dev_ops = {
 	.set_mc_addr_list = cnxk_nix_mc_addr_list_configure,
 	.set_queue_rate_limit = cnxk_nix_tm_set_queue_rate_limit,
 	.tm_ops_get = cnxk_nix_tm_ops_get,
+	.mtr_ops_get = cnxk_nix_mtr_ops_get,
 };
 
 static int
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index ff21b977b7..7a585b9dcf 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -433,6 +433,9 @@ int cnxk_nix_tm_ops_get(struct rte_eth_dev *eth_dev, void *ops);
 int cnxk_nix_tm_set_queue_rate_limit(struct rte_eth_dev *eth_dev,
 				     uint16_t queue_idx, uint16_t tx_rate);
 
+/* MTR */
+int cnxk_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops);
+
 /* RSS */
 uint32_t cnxk_rss_ethdev_to_nix(struct cnxk_eth_dev *dev, uint64_t ethdev_rss,
 				uint8_t rss_level);
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
new file mode 100644
index 0000000000..fdb493a4b9
--- /dev/null
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell.
+ */
+
+#include "cnxk_ethdev.h"
+#include <rte_mtr_driver.h>
+
+const struct rte_mtr_ops nix_mtr_ops = {
+};
+
+int
+cnxk_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops)
+{
+	RTE_SET_USED(dev);
+
+	*(const void **)ops = &nix_mtr_ops;
+	return 0;
+}
diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build
index d86188fed7..5dac078b2c 100644
--- a/drivers/net/cnxk/meson.build
+++ b/drivers/net/cnxk/meson.build
@@ -11,6 +11,7 @@ endif
 sources = files(
         'cnxk_ethdev.c',
         'cnxk_ethdev_devargs.c',
+        'cnxk_ethdev_mtr.c',
         'cnxk_ethdev_ops.c',
         'cnxk_ethdev_sec.c',
         'cnxk_link.c',
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 16/28] net/cnxk: support ops to get meter capabilities
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (14 preceding siblings ...)
  2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 15/28] net/cnxk: support meter ops get API skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 17/28] net/cnxk: support ops to create meter profile skori
                           ` (11 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement ethdev operation to get meter capabilities for
CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 48 ++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index fdb493a4b9..43dc3406af 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -5,7 +5,55 @@
 #include "cnxk_ethdev.h"
 #include <rte_mtr_driver.h>
 
+#define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
+#define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
+
+static struct rte_mtr_capabilities mtr_capa = {
+	.n_max = NIX_MTR_COUNT_MAX,
+	.n_shared_max = NIX_MTR_COUNT_PER_FLOW,
+	/* .identical = , */
+	.shared_identical = true,
+	/* .shared_n_flows_per_mtr_max = ,*/
+	.chaining_n_mtrs_per_flow_max = NIX_MTR_COUNT_PER_FLOW,
+	.chaining_use_prev_mtr_color_supported = true,
+	.chaining_use_prev_mtr_color_enforced = true,
+	.meter_srtcm_rfc2697_n_max = NIX_MTR_COUNT_MAX,
+	.meter_trtcm_rfc2698_n_max = NIX_MTR_COUNT_MAX,
+	.meter_trtcm_rfc4115_n_max = NIX_MTR_COUNT_MAX,
+	.meter_rate_max = NIX_BPF_RATE_MAX / 8, /* Bytes per second */
+	.meter_policy_n_max = NIX_MTR_COUNT_MAX,
+	.color_aware_srtcm_rfc2697_supported = true,
+	.color_aware_trtcm_rfc2698_supported = true,
+	.color_aware_trtcm_rfc4115_supported = true,
+	.srtcm_rfc2697_byte_mode_supported = true,
+	.srtcm_rfc2697_packet_mode_supported = true,
+	.trtcm_rfc2698_byte_mode_supported = true,
+	.trtcm_rfc2698_packet_mode_supported = true,
+	.trtcm_rfc4115_byte_mode_supported = true,
+	.trtcm_rfc4115_packet_mode_supported = true,
+	.stats_mask = RTE_MTR_STATS_N_PKTS_GREEN | RTE_MTR_STATS_N_PKTS_YELLOW |
+		      RTE_MTR_STATS_N_PKTS_RED | RTE_MTR_STATS_N_PKTS_DROPPED |
+		      RTE_MTR_STATS_N_BYTES_GREEN |
+		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
+		      RTE_MTR_STATS_N_BYTES_DROPPED};
+
+static int
+cnxk_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
+			      struct rte_mtr_capabilities *capa,
+			      struct rte_mtr_error *error)
+{
+	RTE_SET_USED(dev);
+
+	if (!capa)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "NULL input parameter");
+	*capa = mtr_capa;
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
+	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 17/28] net/cnxk: support ops to create meter profile
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (15 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 16/28] net/cnxk: support ops to get meter capabilities skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 18/28] net/cnxk: support ops to delete " skori
                           ` (10 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to add meter profile for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev.c     |  14 +++
 drivers/net/cnxk/cnxk_ethdev.h     |  13 +++
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 138 +++++++++++++++++++++++++++++
 3 files changed, 165 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index f694abd71d..d748d5da04 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -701,6 +701,14 @@ nix_free_queue_mem(struct cnxk_eth_dev *dev)
 	dev->sqs = NULL;
 }
 
+static int
+nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
+{
+	TAILQ_INIT(&dev->mtr_profiles);
+
+	return 0;
+}
+
 static int
 nix_rss_default_setup(struct cnxk_eth_dev *dev)
 {
@@ -1113,6 +1121,12 @@ cnxk_nix_configure(struct rte_eth_dev *eth_dev)
 		goto free_nix_lf;
 	}
 
+	rc = nix_ingress_policer_setup(dev);
+	if (rc) {
+		plt_err("Failed to setup ingress policer rc=%d", rc);
+		goto free_nix_lf;
+	}
+
 	rc = roc_nix_tm_hierarchy_enable(nix, ROC_NIX_TM_DEFAULT, false);
 	if (rc) {
 		plt_err("Failed to enable default tm hierarchy, rc=%d", rc);
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 7a585b9dcf..c076208d77 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -13,6 +13,7 @@
 #include <rte_mbuf.h>
 #include <rte_mbuf_pool_ops.h>
 #include <rte_mempool.h>
+#include <rte_mtr_driver.h>
 #include <rte_security.h>
 #include <rte_security_driver.h>
 #include <rte_tailq.h>
@@ -158,6 +159,15 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct cnxk_mtr_profile_node {
+	TAILQ_ENTRY(cnxk_mtr_profile_node) next;
+	struct rte_mtr_meter_profile profile; /**< Profile detail. */
+	uint32_t ref_cnt;		      /**< Use count. */
+	uint32_t id;			      /**< Profile id. */
+};
+
+TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
+
 /* Security session private data */
 struct cnxk_eth_sec_sess {
 	/* List entry */
@@ -303,6 +313,9 @@ struct cnxk_eth_dev {
 	double clk_freq_mult;
 	uint64_t clk_delta;
 
+	/* Ingress policer */
+	struct cnxk_mtr_profiles mtr_profiles;
+
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
 
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 43dc3406af..9127d9a888 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -37,6 +37,106 @@ static struct rte_mtr_capabilities mtr_capa = {
 		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
 		      RTE_MTR_STATS_N_BYTES_DROPPED};
 
+static struct cnxk_mtr_profile_node *
+nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
+{
+	struct cnxk_mtr_profiles *fmps = &dev->mtr_profiles;
+	struct cnxk_mtr_profile_node *fmp;
+
+	TAILQ_FOREACH(fmp, fmps, next)
+		if (profile_id == fmp->id)
+			return fmp;
+
+	return NULL;
+}
+
+static int
+nix_mtr_profile_validate(struct cnxk_eth_dev *dev, uint32_t profile_id,
+			 struct rte_mtr_meter_profile *profile,
+			 struct rte_mtr_error *error)
+{
+	int rc = 0;
+
+	PLT_SET_USED(dev);
+
+	if (profile == NULL)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE,
+					  NULL, "Meter profile is null.");
+
+	if (profile_id == UINT32_MAX)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile id not valid.");
+
+	switch (profile->alg) {
+	case RTE_MTR_SRTCM_RFC2697:
+		if (profile->srtcm_rfc2697.cir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CIR exceeds max meter rate");
+
+		if (profile->srtcm_rfc2697.cbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->srtcm_rfc2697.ebs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"EBS exceeds max meter burst size");
+		break;
+
+	case RTE_MTR_TRTCM_RFC2698:
+		if (profile->trtcm_rfc2698.cir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CIR exceeds max meter rate");
+
+		if (profile->trtcm_rfc2698.pir > mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PIR exceeds max meter rate");
+
+		if (profile->trtcm_rfc2698.cbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->trtcm_rfc2698.pbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PBS exceeds max meter burst size");
+		break;
+
+	case RTE_MTR_TRTCM_RFC4115:
+		if ((profile->trtcm_rfc4115.cir + profile->trtcm_rfc4115.eir) >
+		    mtr_capa.meter_rate_max)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PIR + EIR exceeds max rate");
+
+		if (profile->trtcm_rfc4115.cbs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"CBS exceeds max meter burst size");
+
+		if (profile->trtcm_rfc4115.ebs > NIX_BPF_BURST_MAX)
+			rc = -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"PBS exceeds max meter burst size");
+		break;
+
+	default:
+		rc = -rte_mtr_error_set(error, EINVAL,
+					RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+					"alg is invalid");
+		break;
+	}
+
+	return rc;
+}
+
 static int
 cnxk_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
 			      struct rte_mtr_capabilities *capa,
@@ -52,8 +152,46 @@ cnxk_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_profile_add(struct rte_eth_dev *eth_dev, uint32_t profile_id,
+			 struct rte_mtr_meter_profile *profile,
+			 struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profiles *fmps = &dev->mtr_profiles;
+	struct cnxk_mtr_profile_node *fmp;
+	int ret;
+
+	/* Check input params. */
+	ret = nix_mtr_profile_validate(dev, profile_id, profile, error);
+	if (ret)
+		return ret;
+
+	fmp = nix_mtr_profile_find(dev, profile_id);
+	if (fmp) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Profile already exist");
+	}
+
+	fmp = plt_zmalloc(sizeof(struct cnxk_mtr_profile_node), ROC_ALIGN);
+	if (fmp == NULL)
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Meter profile memory "
+					  "alloc failed.");
+
+	fmp->id = profile_id;
+	fmp->profile = *profile;
+
+	TAILQ_INSERT_TAIL(fmps, fmp, next);
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
+	.meter_profile_add = cnxk_nix_mtr_profile_add,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 18/28] net/cnxk: support ops to delete meter profile
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (16 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 17/28] net/cnxk: support ops to create meter profile skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 19/28] net/cnxk: support ops to validate meter policy skori
                           ` (9 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter profile for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 9127d9a888..9106cb14ac 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -189,9 +189,39 @@ cnxk_nix_mtr_profile_add(struct rte_eth_dev *eth_dev, uint32_t profile_id,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,
+			    struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *fmp;
+
+	if (profile_id == UINT32_MAX)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile id not valid.");
+
+	fmp = nix_mtr_profile_find(dev, profile_id);
+	if (fmp == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  &profile_id,
+					  "Meter profile is invalid.");
+
+	if (fmp->ref_cnt)
+		return -rte_mtr_error_set(error, EBUSY,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  NULL, "Meter profile is in use.");
+
+	TAILQ_REMOVE(&dev->mtr_profiles, fmp, next);
+	plt_free(fmp);
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
+	.meter_profile_delete = cnxk_nix_mtr_profile_delete,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 19/28] net/cnxk: support ops to validate meter policy
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (17 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 18/28] net/cnxk: support ops to delete " skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 20/28] net/cnxk: support ops to create " skori
                           ` (8 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to validate meter policy for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 49 ++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 9106cb14ac..c042da6fa5 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -218,10 +218,59 @@ cnxk_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,
+			     struct rte_mtr_meter_policy_params *policy,
+			     struct rte_mtr_error *error)
+{
+	static const char *const action_color[] = {"Green", "Yellow", "Red"};
+	bool supported[RTE_COLORS] = {false, false, false};
+	const struct rte_flow_action *action;
+	char message[1024];
+	uint32_t i;
+
+	RTE_SET_USED(dev);
+
+	if (!policy)
+		return 0; /* Nothing to be validated */
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		if (policy->actions[i]) {
+			for (action = policy->actions[i];
+			     action->type != RTE_FLOW_ACTION_TYPE_END;
+			     action++) {
+				if (action->type == RTE_FLOW_ACTION_TYPE_METER)
+					supported[i] = true;
+
+				if (action->type == RTE_FLOW_ACTION_TYPE_DROP)
+					supported[i] = true;
+
+				if (!supported[i]) {
+					sprintf(message,
+						"%s action is not valid",
+						action_color[i]);
+					return -rte_mtr_error_set(error,
+					  ENOTSUP,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+					  message);
+				}
+			}
+		} else {
+			sprintf(message, "%s action is null", action_color[i]);
+			return -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+				message);
+		}
+	}
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
 	.meter_profile_delete = cnxk_nix_mtr_profile_delete,
+	.meter_policy_validate = cnxk_nix_mtr_policy_validate,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 20/28] net/cnxk: support ops to create meter policy
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (18 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 19/28] net/cnxk: support ops to validate meter policy skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 21/28] net/cnxk: support ops to delete " skori
                           ` (7 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to add meter policy for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev.c     |  1 +
 drivers/net/cnxk/cnxk_ethdev.h     | 31 +++++++++++
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 84 ++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index d748d5da04..6295fa0557 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -705,6 +705,7 @@ static int
 nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
 	TAILQ_INIT(&dev->mtr_profiles);
+	TAILQ_INIT(&dev->mtr_policy);
 
 	return 0;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index c076208d77..4cdce5dfd0 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -159,6 +159,35 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct action_rss {
+	enum rte_eth_hash_function func;
+	uint32_t level;
+	uint64_t types;
+	uint32_t key_len;
+	uint32_t queue_num;
+	uint8_t *key;
+	uint16_t *queue;
+};
+
+struct policy_actions {
+	uint32_t action_fate;
+	union {
+		uint16_t queue;
+		uint32_t mtr_id;
+		struct action_rss *rss_desc;
+	};
+};
+
+struct cnxk_mtr_policy_node {
+	TAILQ_ENTRY(cnxk_mtr_policy_node) next;
+	/**< Pointer to the next flow meter structure. */
+	uint32_t id;	 /**< Policy id */
+	uint32_t mtr_id; /** Meter id */
+	struct rte_mtr_meter_policy_params policy;
+	struct policy_actions actions[RTE_COLORS];
+	uint32_t ref_cnt;
+};
+
 struct cnxk_mtr_profile_node {
 	TAILQ_ENTRY(cnxk_mtr_profile_node) next;
 	struct rte_mtr_meter_profile profile; /**< Profile detail. */
@@ -167,6 +196,7 @@ struct cnxk_mtr_profile_node {
 };
 
 TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
+TAILQ_HEAD(cnxk_mtr_policy, cnxk_mtr_policy_node);
 
 /* Security session private data */
 struct cnxk_eth_sec_sess {
@@ -315,6 +345,7 @@ struct cnxk_eth_dev {
 
 	/* Ingress policer */
 	struct cnxk_mtr_profiles mtr_profiles;
+	struct cnxk_mtr_policy mtr_policy;
 
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index c042da6fa5..91b9f618ce 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -50,6 +50,18 @@ nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
 	return NULL;
 }
 
+static struct cnxk_mtr_policy_node *
+nix_mtr_policy_find(struct cnxk_eth_dev *dev, uint32_t meter_policy_id)
+{
+	struct cnxk_mtr_policy *fmps = &dev->mtr_policy;
+	struct cnxk_mtr_policy_node *fmp;
+
+	TAILQ_FOREACH(fmp, fmps, next)
+		if (meter_policy_id == fmp->id)
+			return fmp;
+	return NULL;
+}
+
 static int
 nix_mtr_profile_validate(struct cnxk_eth_dev *dev, uint32_t profile_id,
 			 struct rte_mtr_meter_profile *profile,
@@ -266,11 +278,83 @@ cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static void
+cnxk_fill_policy_actions(struct cnxk_mtr_policy_node *fmp,
+			 struct rte_mtr_meter_policy_params *policy)
+
+{
+	const struct rte_flow_action_meter *mtr;
+	const struct rte_flow_action *action;
+	int i;
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		if (policy->actions[i]) {
+			for (action = policy->actions[i];
+			     action->type != RTE_FLOW_ACTION_TYPE_END;
+			     action++) {
+				if (action->type ==
+				    RTE_FLOW_ACTION_TYPE_METER) {
+					fmp->actions[i].action_fate =
+						action->type;
+					mtr = (const struct
+					       rte_flow_action_meter *)
+						      action->conf;
+					fmp->actions[i].mtr_id = mtr->mtr_id;
+				}
+
+				if (action->type == RTE_FLOW_ACTION_TYPE_DROP) {
+					fmp->actions[i].action_fate =
+						action->type;
+				}
+			}
+		}
+	}
+}
+
+static int
+cnxk_nix_mtr_policy_add(struct rte_eth_dev *eth_dev, uint32_t policy_id,
+			struct rte_mtr_meter_policy_params *policy,
+			struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy *fmps = &dev->mtr_policy;
+	struct cnxk_mtr_policy_node *fmp;
+	int rc;
+
+	fmp = nix_mtr_policy_find(dev, policy_id);
+	if (fmp) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "Policy already exist");
+	}
+
+	fmp = plt_zmalloc(sizeof(struct cnxk_mtr_policy_node), ROC_ALIGN);
+	if (fmp == NULL) {
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Memory allocation failure");
+	} else {
+		rc = cnxk_nix_mtr_policy_validate(eth_dev, policy, error);
+		if (rc)
+			goto exit;
+	}
+
+	fmp->id = policy_id;
+	cnxk_fill_policy_actions(fmp, policy);
+	TAILQ_INSERT_TAIL(fmps, fmp, next);
+	return 0;
+
+exit:
+	plt_free(fmp);
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
 	.meter_profile_delete = cnxk_nix_mtr_profile_delete,
 	.meter_policy_validate = cnxk_nix_mtr_policy_validate,
+	.meter_policy_add = cnxk_nix_mtr_policy_add,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 21/28] net/cnxk: support ops to delete meter policy
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (19 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 20/28] net/cnxk: support ops to create " skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 22/28] net/cnxk: support ops to create meter skori
                           ` (6 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter policy for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 91b9f618ce..b5be7c587a 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -349,12 +349,38 @@ cnxk_nix_mtr_policy_add(struct rte_eth_dev *eth_dev, uint32_t policy_id,
 	return rc;
 }
 
+static int
+cnxk_nix_mtr_policy_delete(struct rte_eth_dev *eth_dev, uint32_t policy_id,
+			   struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy_node *fmp;
+
+	fmp = nix_mtr_policy_find(dev, policy_id);
+	if (fmp == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "No policy found");
+	}
+
+	if (fmp->ref_cnt)
+		return -rte_mtr_error_set(error, EBUSY,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  NULL, "Meter policy is in use.");
+
+	TAILQ_REMOVE(&dev->mtr_policy, fmp, next);
+	plt_free(fmp);
+
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
 	.meter_profile_delete = cnxk_nix_mtr_profile_delete,
 	.meter_policy_validate = cnxk_nix_mtr_policy_validate,
 	.meter_policy_add = cnxk_nix_mtr_policy_add,
+	.meter_policy_delete = cnxk_nix_mtr_policy_delete,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 22/28] net/cnxk: support ops to create meter
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (20 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 21/28] net/cnxk: support ops to delete " skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 23/28] net/cnxk: support ops to delete meter skori
                           ` (5 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to create meter instance for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev.c     |  1 +
 drivers/net/cnxk/cnxk_ethdev.h     | 25 ++++++++
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 93 ++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index 6295fa0557..2bb33d8f2d 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -706,6 +706,7 @@ nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
 	TAILQ_INIT(&dev->mtr_profiles);
 	TAILQ_INIT(&dev->mtr_policy);
+	TAILQ_INIT(&dev->mtr);
 
 	return 0;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 4cdce5dfd0..10adeeec82 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -159,6 +159,28 @@ struct cnxk_timesync_info {
 	uint64_t *tx_tstamp;
 } __plt_cache_aligned;
 
+struct cnxk_meter_node {
+#define MAX_PRV_MTR_NODES 10
+	TAILQ_ENTRY(cnxk_meter_node) next;
+	/**< Pointer to the next flow meter structure. */
+	uint32_t id; /**< Usr mtr id. */
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	uint32_t bpf_id; /**< Hw mtr id. */
+	uint32_t rq_num;
+	uint32_t *rq_id;
+	uint16_t level;
+	uint32_t prev_id[MAX_PRV_MTR_NODES]; /**< Prev mtr id for chaining */
+	uint32_t prev_cnt;
+	uint32_t next_id; /**< Next mtr id for chaining */
+	bool is_prev;
+	bool is_next;
+	struct rte_mtr_params params;
+	struct roc_nix_bpf_objs profs;
+	bool is_used;
+	uint32_t ref_cnt;
+};
+
 struct action_rss {
 	enum rte_eth_hash_function func;
 	uint32_t level;
@@ -197,6 +219,7 @@ struct cnxk_mtr_profile_node {
 
 TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
 TAILQ_HEAD(cnxk_mtr_policy, cnxk_mtr_policy_node);
+TAILQ_HEAD(cnxk_mtr, cnxk_meter_node);
 
 /* Security session private data */
 struct cnxk_eth_sec_sess {
@@ -344,8 +367,10 @@ struct cnxk_eth_dev {
 	uint64_t clk_delta;
 
 	/* Ingress policer */
+	enum roc_nix_bpf_color precolor_tbl[ROC_NIX_BPF_PRE_COLOR_MAX];
 	struct cnxk_mtr_profiles mtr_profiles;
 	struct cnxk_mtr_policy mtr_policy;
+	struct cnxk_mtr mtr;
 
 	/* Rx burst for cleanup(Only Primary) */
 	eth_rx_burst_t rx_pkt_burst_no_offload;
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index b5be7c587a..96f2a334a9 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -37,6 +37,18 @@ static struct rte_mtr_capabilities mtr_capa = {
 		      RTE_MTR_STATS_N_BYTES_YELLOW | RTE_MTR_STATS_N_BYTES_RED |
 		      RTE_MTR_STATS_N_BYTES_DROPPED};
 
+static struct cnxk_meter_node *
+nix_mtr_find(struct cnxk_eth_dev *dev, uint32_t meter_id)
+{
+	struct cnxk_mtr *fms = &dev->mtr;
+	struct cnxk_meter_node *fm;
+
+	TAILQ_FOREACH(fm, fms, next)
+		if (meter_id == fm->id)
+			return fm;
+	return NULL;
+}
+
 static struct cnxk_mtr_profile_node *
 nix_mtr_profile_find(struct cnxk_eth_dev *dev, uint32_t profile_id)
 {
@@ -374,6 +386,86 @@ cnxk_nix_mtr_policy_delete(struct rte_eth_dev *eth_dev, uint32_t policy_id,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_create(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		    struct rte_mtr_params *params, int shared,
+		    struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_mtr *fm = &dev->mtr;
+	struct cnxk_meter_node *mtr;
+	int i;
+
+	RTE_SET_USED(shared);
+
+	if (params == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "Meter params are invalid.");
+
+	profile = nix_mtr_profile_find(dev, params->meter_profile_id);
+	if (profile == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
+					  &params->meter_profile_id,
+					  "Meter profile is invalid.");
+
+	policy = nix_mtr_policy_find(dev, params->meter_policy_id);
+	if (policy == NULL)
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
+					  &params->meter_policy_id,
+					  "Meter policy is invalid.");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr) {
+		return -rte_mtr_error_set(error, EEXIST,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter already exist");
+	}
+
+	mtr = plt_zmalloc(sizeof(struct cnxk_meter_node), ROC_ALIGN);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOMEM,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "Meter memory alloc failed.");
+	}
+
+	mtr->id = mtr_id;
+	mtr->profile = profile;
+	mtr->policy = policy;
+	mtr->params = *params;
+	mtr->bpf_id = ROC_NIX_BPF_ID_INVALID;
+	mtr->prev_cnt = 0;
+	for (i = 0; i < MAX_PRV_MTR_NODES; i++)
+		mtr->prev_id[i] = ROC_NIX_BPF_ID_INVALID;
+
+	mtr->next_id = ROC_NIX_BPF_ID_INVALID;
+	mtr->is_next = false;
+	mtr->level = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+
+	if (params->dscp_table) {
+		mtr->params.dscp_table =
+			plt_zmalloc(ROC_NIX_BPF_PRE_COLOR_MAX, ROC_ALIGN);
+		if (mtr->params.dscp_table == NULL) {
+			plt_free(mtr);
+			return -rte_mtr_error_set(error, ENOMEM,
+					RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+					NULL, "Memory alloc failed.");
+		}
+
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			mtr->params.dscp_table[i] = params->dscp_table[i];
+	}
+
+	profile->ref_cnt++;
+	policy->ref_cnt++;
+	TAILQ_INSERT_TAIL(fm, mtr, next);
+	return 0;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -381,6 +473,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_validate = cnxk_nix_mtr_policy_validate,
 	.meter_policy_add = cnxk_nix_mtr_policy_add,
 	.meter_policy_delete = cnxk_nix_mtr_policy_delete,
+	.create = cnxk_nix_mtr_create,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 23/28] net/cnxk: support ops to delete meter
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (21 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 22/28] net/cnxk: support ops to create meter skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 24/28] net/cnxk: support ops to enable/disable meter skori
                           ` (4 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to delete meter instance for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 90 ++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 96f2a334a9..6d950fd177 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -8,6 +8,10 @@
 #define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
 #define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
 
+static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
+						      ROC_NIX_BPF_LEVEL_F_MID,
+						      ROC_NIX_BPF_LEVEL_F_TOP};
+
 static struct rte_mtr_capabilities mtr_capa = {
 	.n_max = NIX_MTR_COUNT_MAX,
 	.n_shared_max = NIX_MTR_COUNT_PER_FLOW,
@@ -466,6 +470,91 @@ cnxk_nix_mtr_create(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return 0;
 }
 
+static int
+cnxk_nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_objs profs = {0};
+	struct cnxk_mtr *fm = &dev->mtr;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct cnxk_meter_node *mid_mtr;
+	struct cnxk_meter_node *top_mtr;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, &mtr_id,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->ref_cnt) {
+		return -rte_mtr_error_set(error, EADDRINUSE,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, &mtr_id,
+					  "Meter id in use.");
+	}
+
+	switch (lvl_map[mtr->level]) {
+	case ROC_NIX_BPF_LEVEL_F_LEAF:
+		if (mtr->is_next) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_LEAF,
+						 mtr->bpf_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		break;
+	case ROC_NIX_BPF_LEVEL_F_MID:
+		while ((mtr->prev_cnt) + 1) {
+			mid_mtr =
+				nix_mtr_find(dev, mtr->prev_id[mtr->prev_cnt]);
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_LEAF,
+						 mid_mtr->bpf_id,
+						 ROC_NIX_BPF_ID_INVALID);
+			mtr->prev_cnt--;
+		}
+		if (mtr->is_next) {
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_MID,
+						 mtr->bpf_id,
+						 ROC_NIX_BPF_ID_INVALID);
+		}
+		break;
+	case ROC_NIX_BPF_LEVEL_F_TOP:
+		while (mtr->prev_cnt) {
+			top_mtr =
+				nix_mtr_find(dev, mtr->prev_id[mtr->prev_cnt]);
+			rc = roc_nix_bpf_connect(nix, ROC_NIX_BPF_LEVEL_F_MID,
+						 top_mtr->bpf_id,
+						 ROC_NIX_BPF_ID_INVALID);
+			mtr->prev_cnt--;
+		}
+		break;
+	default:
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Invalid meter level");
+	}
+
+	if (rc)
+		goto exit;
+
+	profs.level = mtr->level;
+	profs.count = 1;
+	profs.ids[0] = mtr->bpf_id;
+	rc = roc_nix_bpf_free(nix, &profs, 1);
+	if (rc)
+		goto exit;
+
+	mtr->policy->ref_cnt--;
+	mtr->profile->ref_cnt--;
+	TAILQ_REMOVE(fm, mtr, next);
+	plt_free(mtr->params.dscp_table);
+	plt_free(mtr);
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -474,6 +563,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_add = cnxk_nix_mtr_policy_add,
 	.meter_policy_delete = cnxk_nix_mtr_policy_delete,
 	.create = cnxk_nix_mtr_create,
+	.destroy = cnxk_nix_mtr_destroy,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 24/28] net/cnxk: support ops to enable/disable meter
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (22 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 23/28] net/cnxk: support ops to delete meter skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 25/28] net/cnxk: support ops to update precolor DSCP table skori
                           ` (3 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to enable or disable meter instance for
CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 60 ++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 6d950fd177..6c19b90e10 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -555,6 +555,64 @@ cnxk_nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cnxk_nix_mtr_enable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		    struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->level != 0)
+		return 0;
+
+	for (i = 0; i < mtr->rq_num; i++) {
+		rq = &dev->rqs[mtr->rq_id[i]];
+		rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, true);
+	}
+
+	return rc;
+}
+
+static int
+cnxk_nix_mtr_disable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+		     struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc = 0;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter id is invalid.");
+	}
+
+	if (mtr->level != 0)
+		return 0;
+
+	for (i = 0; i < mtr->rq_num; i++) {
+		rq = &dev->rqs[mtr->rq_id[i]];
+		rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, false);
+	}
+
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -564,6 +622,8 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_policy_delete = cnxk_nix_mtr_policy_delete,
 	.create = cnxk_nix_mtr_create,
 	.destroy = cnxk_nix_mtr_destroy,
+	.meter_enable = cnxk_nix_mtr_enable,
+	.meter_disable = cnxk_nix_mtr_disable,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 25/28] net/cnxk: support ops to update precolor DSCP table
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (23 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 24/28] net/cnxk: support ops to enable/disable meter skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 26/28] net/cnxk: support ops to read/update meter stats skori
                           ` (2 subsequent siblings)
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to update DSCP table for pre-coloring for
incoming packet per nixlf for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 51 ++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 6c19b90e10..d14de95907 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -613,6 +613,56 @@ cnxk_nix_mtr_disable(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cnxk_nix_mtr_dscp_table_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+			       enum rte_color *dscp_table,
+			       struct rte_mtr_error *error)
+{
+	enum roc_nix_bpf_color nix_dscp_tbl[ROC_NIX_BPF_PRE_COLOR_MAX];
+	enum roc_nix_bpf_color color_map[] = {ROC_NIX_BPF_COLOR_GREEN,
+					      ROC_NIX_BPF_COLOR_YELLOW,
+					      ROC_NIX_BPF_COLOR_RED};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_precolor table;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	int rc, i;
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	if (!dscp_table) {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			nix_dscp_tbl[i] = ROC_NIX_BPF_COLOR_GREEN;
+	} else {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			nix_dscp_tbl[i] = color_map[dscp_table[i]];
+	}
+
+	table.count = ROC_NIX_BPF_PRE_COLOR_MAX;
+	table.mode = ROC_NIX_BPF_PC_MODE_DSCP_OUTER;
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		table.color[i] = nix_dscp_tbl[i];
+
+	rc = roc_nix_bpf_pre_color_tbl_setup(nix, mtr->bpf_id,
+					     lvl_map[mtr->level], &table);
+	if (rc) {
+		rte_mtr_error_set(error, rc, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+				  NULL, NULL);
+		goto exit;
+	}
+
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		dev->precolor_tbl[i] = nix_dscp_tbl[i];
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -624,6 +674,7 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.destroy = cnxk_nix_mtr_destroy,
 	.meter_enable = cnxk_nix_mtr_enable,
 	.meter_disable = cnxk_nix_mtr_disable,
+	.meter_dscp_table_update = cnxk_nix_mtr_dscp_table_update,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 26/28] net/cnxk: support ops to read/update meter stats
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (24 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 25/28] net/cnxk: support ops to update precolor DSCP table skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 27/28] net/cnxk: support meter action to flow create skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 28/28] net/cnxk: support meter action to flow destroy skori
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Implement API to read and update stats corresponding to
given meter instance for CNXK platform.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cnxk_ethdev_mtr.c | 141 +++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index d14de95907..e5fcdda5e2 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -8,6 +8,21 @@
 #define NIX_MTR_COUNT_MAX      73 /* 64(leaf) + 8(mid) + 1(top) */
 #define NIX_MTR_COUNT_PER_FLOW 3  /* 1(leaf) + 1(mid) + 1(top) */
 
+#define NIX_BPF_STATS_MASK_ALL                                                 \
+	{                                                                      \
+		ROC_NIX_BPF_GREEN_PKT_F_PASS | ROC_NIX_BPF_GREEN_OCTS_F_PASS | \
+			ROC_NIX_BPF_GREEN_PKT_F_DROP |                         \
+			ROC_NIX_BPF_GREEN_OCTS_F_DROP |                        \
+			ROC_NIX_BPF_YELLOW_PKT_F_PASS |                        \
+			ROC_NIX_BPF_YELLOW_OCTS_F_PASS |                       \
+			ROC_NIX_BPF_YELLOW_PKT_F_DROP |                        \
+			ROC_NIX_BPF_YELLOW_OCTS_F_DROP |                       \
+			ROC_NIX_BPF_RED_PKT_F_PASS |                           \
+			ROC_NIX_BPF_RED_OCTS_F_PASS |                          \
+			ROC_NIX_BPF_RED_PKT_F_DROP |                           \
+			ROC_NIX_BPF_RED_OCTS_F_DROP                            \
+	}
+
 static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
 						      ROC_NIX_BPF_LEVEL_F_MID,
 						      ROC_NIX_BPF_LEVEL_F_TOP};
@@ -663,6 +678,130 @@ cnxk_nix_mtr_dscp_table_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
 	return rc;
 }
 
+static int
+cnxk_nix_mtr_stats_update(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+			  uint64_t stats_mask, struct rte_mtr_error *error)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	if (!stats_mask)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "no bit is set to stats mask");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	mtr->params.stats_mask = stats_mask;
+	return 0;
+}
+
+static int
+cnxk_nix_mtr_stats_read(struct rte_eth_dev *eth_dev, uint32_t mtr_id,
+			struct rte_mtr_stats *stats, uint64_t *stats_mask,
+			int clear, struct rte_mtr_error *error)
+{
+	uint8_t yellow_pkt_pass, yellow_octs_pass, yellow_pkt_drop;
+	uint8_t green_octs_drop, yellow_octs_drop, red_octs_drop;
+	uint8_t green_pkt_pass, green_octs_pass, green_pkt_drop;
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint8_t red_pkt_pass, red_octs_pass, red_pkt_drop;
+	uint64_t bpf_stats[ROC_NIX_BPF_STATS_MAX] = {0};
+	uint64_t mask = NIX_BPF_STATS_MASK_ALL;
+	struct roc_nix *nix = &dev->nix;
+	struct cnxk_meter_node *mtr;
+	int rc;
+
+	if (!stats)
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+					  "stats pointer is NULL");
+
+	mtr = nix_mtr_find(dev, mtr_id);
+	if (mtr == NULL) {
+		return -rte_mtr_error_set(error, ENOENT,
+					  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
+					  "Meter object not found");
+	}
+
+	rc = roc_nix_bpf_stats_read(nix, mtr->bpf_id, mask, lvl_map[mtr->level],
+				    bpf_stats);
+	if (rc) {
+		rte_mtr_error_set(error, rc, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+				  NULL, NULL);
+		goto exit;
+	}
+
+	green_pkt_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_PKT_F_PASS);
+	green_octs_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_OCTS_F_PASS);
+	green_pkt_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_PKT_F_DROP);
+	green_octs_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_GREEN_OCTS_F_DROP);
+	yellow_pkt_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_PKT_F_PASS);
+	yellow_octs_pass =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_OCTS_F_PASS);
+	yellow_pkt_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_PKT_F_DROP);
+	yellow_octs_drop =
+		roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_YELLOW_OCTS_F_DROP);
+	red_pkt_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_PKT_F_PASS);
+	red_octs_pass = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_OCTS_F_PASS);
+	red_pkt_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_PKT_F_DROP);
+	red_octs_drop = roc_nix_bpf_stats_to_idx(ROC_NIX_BPF_RED_OCTS_F_DROP);
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_GREEN)
+		stats->n_pkts[RTE_COLOR_GREEN] = bpf_stats[green_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW)
+		stats->n_pkts[RTE_COLOR_YELLOW] = bpf_stats[yellow_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_RED)
+		stats->n_pkts[RTE_COLOR_RED] = bpf_stats[red_pkt_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_GREEN)
+		stats->n_bytes[RTE_COLOR_GREEN] = bpf_stats[green_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW)
+		stats->n_bytes[RTE_COLOR_YELLOW] = bpf_stats[yellow_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_RED)
+		stats->n_bytes[RTE_COLOR_RED] = bpf_stats[red_octs_pass];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED)
+		stats->n_pkts_dropped = bpf_stats[green_pkt_drop] +
+					bpf_stats[yellow_pkt_drop] +
+					bpf_stats[red_pkt_drop];
+
+	if (mtr->params.stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED)
+		stats->n_bytes_dropped = bpf_stats[green_octs_drop] +
+					 bpf_stats[yellow_octs_drop] +
+					 bpf_stats[red_octs_drop];
+
+	if (stats_mask)
+		*stats_mask = mtr->params.stats_mask;
+
+	if (clear) {
+		rc = roc_nix_bpf_stats_reset(nix, mtr->bpf_id, mask,
+					     lvl_map[mtr->level]);
+		if (rc) {
+			rte_mtr_error_set(error, rc,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  NULL);
+			goto exit;
+		}
+	}
+
+exit:
+	return rc;
+}
+
 const struct rte_mtr_ops nix_mtr_ops = {
 	.capabilities_get = cnxk_nix_mtr_capabilities_get,
 	.meter_profile_add = cnxk_nix_mtr_profile_add,
@@ -675,6 +814,8 @@ const struct rte_mtr_ops nix_mtr_ops = {
 	.meter_enable = cnxk_nix_mtr_enable,
 	.meter_disable = cnxk_nix_mtr_disable,
 	.meter_dscp_table_update = cnxk_nix_mtr_dscp_table_update,
+	.stats_update = cnxk_nix_mtr_stats_update,
+	.stats_read = cnxk_nix_mtr_stats_read,
 };
 
 int
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 27/28] net/cnxk: support meter action to flow create
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (25 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 26/28] net/cnxk: support ops to read/update meter stats skori
@ 2021-10-12  7:06         ` skori
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 28/28] net/cnxk: support meter action to flow destroy skori
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Meters are configured per flow using rte_flow_create API.
Implement support for meter action applied on the flow.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 doc/guides/nics/features/cnxk.ini      |   1 +
 doc/guides/nics/features/cnxk_vf.ini   |   1 +
 doc/guides/rel_notes/release_21_11.rst |   1 +
 drivers/net/cnxk/cn10k_rte_flow.c      | 171 ++++++++-
 drivers/net/cnxk/cnxk_ethdev.h         |  18 +
 drivers/net/cnxk/cnxk_ethdev_mtr.c     | 506 +++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_rte_flow.c       |   4 +
 7 files changed, 701 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/cnxk.ini b/doc/guides/nics/features/cnxk.ini
index 1ced3ee903..f0586457ca 100644
--- a/doc/guides/nics/features/cnxk.ini
+++ b/doc/guides/nics/features/cnxk.ini
@@ -79,6 +79,7 @@ count                = Y
 drop                 = Y
 flag                 = Y
 mark                 = Y
+meter                = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
 of_set_vlan_pcp      = Y
diff --git a/doc/guides/nics/features/cnxk_vf.ini b/doc/guides/nics/features/cnxk_vf.ini
index 139d9b9892..f3d9f23f17 100644
--- a/doc/guides/nics/features/cnxk_vf.ini
+++ b/doc/guides/nics/features/cnxk_vf.ini
@@ -71,6 +71,7 @@ count                = Y
 drop                 = Y
 flag                 = Y
 mark                 = Y
+meter                = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
 of_set_vlan_pcp      = Y
diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst
index 16c48d54a1..5ec80377ee 100644
--- a/doc/guides/rel_notes/release_21_11.rst
+++ b/doc/guides/rel_notes/release_21_11.rst
@@ -91,6 +91,7 @@ New Features
   * Added rte_tm support.
   * Added support for Inline IPsec for CN9K event mode and CN10K
     poll mode and event mode.
+  * Added support for ingress meter for CN10K platform.
 
 * **Updated af_packet ethdev driver.**
 
diff --git a/drivers/net/cnxk/cn10k_rte_flow.c b/drivers/net/cnxk/cn10k_rte_flow.c
index b04de6a7e6..00c0b172e4 100644
--- a/drivers/net/cnxk/cn10k_rte_flow.c
+++ b/drivers/net/cnxk/cn10k_rte_flow.c
@@ -6,6 +6,113 @@
 #include "cn10k_ethdev.h"
 #include "cn10k_rx.h"
 
+static int
+cn10k_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t mtr_id)
+{
+	return nix_mtr_connect(eth_dev, mtr_id);
+}
+
+static int
+cn10k_mtr_configure(struct rte_eth_dev *eth_dev,
+		    const struct rte_flow_action actions[])
+{
+	uint32_t mtr_id = 0xffff, prev_mtr_id = 0xffff, next_mtr_id = 0xffff;
+	const struct rte_flow_action_meter *mtr_conf;
+	const struct rte_flow_action_queue *q_conf;
+	const struct rte_flow_action_rss *rss_conf;
+	struct cnxk_mtr_policy_node *policy;
+	bool is_mtr_act = false;
+	int tree_level = 0;
+	int rc = -EINVAL, i;
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) {
+			mtr_conf = (const struct rte_flow_action_meter
+					    *)(actions->conf);
+			mtr_id = mtr_conf->mtr_id;
+			is_mtr_act = true;
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE) {
+			q_conf = (const struct rte_flow_action_queue
+					  *)(actions->conf);
+			if (is_mtr_act)
+				nix_mtr_rq_update(eth_dev, mtr_id, 1,
+						  &q_conf->index);
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
+			rss_conf = (const struct rte_flow_action_rss
+					    *)(actions->conf);
+			if (is_mtr_act)
+				nix_mtr_rq_update(eth_dev, mtr_id,
+						  rss_conf->queue_num,
+						  rss_conf->queue);
+		}
+	}
+
+	if (!is_mtr_act)
+		return rc;
+
+	prev_mtr_id = mtr_id;
+	next_mtr_id = mtr_id;
+	while (next_mtr_id != 0xffff) {
+		rc = nix_mtr_validate(eth_dev, next_mtr_id);
+		if (rc)
+			return rc;
+
+		rc = nix_mtr_policy_act_get(eth_dev, next_mtr_id, &policy);
+		if (rc)
+			return rc;
+
+		rc = nix_mtr_color_action_validate(eth_dev, mtr_id,
+						   &prev_mtr_id, &next_mtr_id,
+						   policy, &tree_level);
+		if (rc)
+			return rc;
+	}
+
+	return nix_mtr_configure(eth_dev, mtr_id);
+}
+
+static int
+cn10k_rss_action_validate(struct rte_eth_dev *eth_dev,
+			  const struct rte_flow_attr *attr,
+			  const struct rte_flow_action *act)
+{
+	const struct rte_flow_action_rss *rss;
+
+	if (act == NULL)
+		return -EINVAL;
+
+	rss = (const struct rte_flow_action_rss *)act->conf;
+
+	if (attr->egress) {
+		plt_err("No support of RSS in egress");
+		return -EINVAL;
+	}
+
+	if (eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
+		plt_err("multi-queue mode is disabled");
+		return -ENOTSUP;
+	}
+
+	if (!rss || !rss->queue_num) {
+		plt_err("no valid queues");
+		return -EINVAL;
+	}
+
+	if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
+		plt_err("non-default RSS hash functions are not supported");
+		return -ENOTSUP;
+	}
+
+	if (rss->key_len && rss->key_len > ROC_NIX_RSS_KEY_LEN) {
+		plt_err("RSS hash key too large");
+		return -ENOTSUP;
+	}
+
+	return 0;
+}
+
 struct rte_flow *
 cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		  const struct rte_flow_item pattern[],
@@ -13,13 +120,75 @@ cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		  struct rte_flow_error *error)
 {
 	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	const struct rte_flow_action *action_rss = NULL;
+	const struct rte_flow_action_meter *mtr = NULL;
+	const struct rte_flow_action *act_q = NULL;
 	int mark_actions = 0, vtag_actions = 0;
 	struct roc_npc *npc = &dev->npc;
 	struct roc_npc_flow *flow;
+	uint32_t req_act = 0;
+	int i, rc;
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER)
+			req_act |= ROC_NPC_ACTION_TYPE_METER;
+
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE) {
+			req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
+			act_q = &actions[i];
+		}
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) {
+			req_act |= ROC_NPC_ACTION_TYPE_RSS;
+			action_rss = &actions[i];
+		}
+	}
+
+	if (req_act & ROC_NPC_ACTION_TYPE_METER) {
+		if ((req_act & ROC_NPC_ACTION_TYPE_RSS) &&
+		    ((req_act & ROC_NPC_ACTION_TYPE_QUEUE))) {
+			return NULL;
+		}
+		if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
+			rc = cn10k_rss_action_validate(eth_dev, attr,
+						       action_rss);
+			if (rc)
+				return NULL;
+		} else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
+			const struct rte_flow_action_queue *act_queue;
+			act_queue = (const struct rte_flow_action_queue *)
+					    act_q->conf;
+			if (act_queue->index > eth_dev->data->nb_rx_queues)
+				return NULL;
+		} else {
+			return NULL;
+		}
+	}
+
+	for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+		if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) {
+			mtr = (const struct rte_flow_action_meter *)actions[i]
+				      .conf;
+			rc = cn10k_mtr_configure(eth_dev, actions);
+			if (rc) {
+				rte_flow_error_set(error, rc,
+					RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+					"Failed to configure mtr ");
+				return NULL;
+			}
+			break;
+		}
+	}
 
 	flow = cnxk_flow_create(eth_dev, attr, pattern, actions, error);
-	if (!flow)
+	if (!flow) {
+		if (mtr)
+			nix_mtr_chain_reset(eth_dev, mtr->mtr_id);
+
 		return NULL;
+	} else {
+		if (mtr)
+			cn10k_mtr_connect(eth_dev, mtr->mtr_id);
+	}
 
 	mark_actions = roc_npc_mark_actions_get(npc);
 
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 10adeeec82..7e13956572 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -575,6 +575,24 @@ cnxk_eth_sec_sess_get_by_sess(struct cnxk_eth_dev *dev,
 
 /* Other private functions */
 int nix_recalc_mtu(struct rte_eth_dev *eth_dev);
+int nix_mtr_validate(struct rte_eth_dev *dev, uint32_t id);
+int nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id,
+			   struct cnxk_mtr_policy_node **policy);
+int nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id,
+		      uint32_t queue_num, const uint16_t *queue);
+int nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id,
+			 uint32_t prev_id, uint32_t next_id);
+int nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id);
+struct cnxk_meter_node *nix_get_mtr(struct rte_eth_dev *eth_dev,
+				    uint32_t cur_id);
+int nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id,
+			 uint32_t level);
+int nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id);
+int nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id);
+int nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
+				  uint32_t *prev_id, uint32_t *next_id,
+				  struct cnxk_mtr_policy_node *policy,
+				  int *tree_level);
 
 /* Inlines */
 static __rte_always_inline uint64_t
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index e5fcdda5e2..c29a7ec47b 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -826,3 +826,509 @@ cnxk_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops)
 	*(const void **)ops = &nix_mtr_ops;
 	return 0;
 }
+
+int
+nix_mtr_validate(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_profile_node *profile;
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	profile = nix_mtr_profile_find(dev, mtr->params.meter_profile_id);
+	if (profile == NULL)
+		return -EINVAL;
+
+	policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id);
+	if (policy == NULL)
+		return -EINVAL;
+
+	return 0;
+}
+
+int
+nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id,
+		       struct cnxk_mtr_policy_node **policy_act)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mtr_policy_node *policy;
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id);
+	if (policy == NULL)
+		return -EINVAL;
+
+	*policy_act = policy;
+
+	return 0;
+}
+
+int
+nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t queue_num,
+		  const uint16_t *queue)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+	uint32_t i;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	mtr->rq_id = plt_zmalloc(queue_num * sizeof(uint32_t), ROC_ALIGN);
+	if (mtr->rq_id == NULL)
+		return -ENOMEM;
+
+	mtr->rq_num = queue_num;
+	for (i = 0; i < queue_num; i++)
+		mtr->rq_id[i] = queue[i];
+
+	return 0;
+}
+
+int
+nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id)
+{
+	struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	uint32_t mtr_id = cur_id;
+	int i = 0, j = 0;
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		mtr[i] = nix_mtr_find(dev, mtr_id);
+		if (mtr[i])
+			mtr_id = mtr[i]->next_id;
+	}
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		if (mtr[i]) {
+			for (j = 0; j < MAX_PRV_MTR_NODES; j++)
+				mtr[i]->prev_id[i] = ROC_NIX_BPF_ID_INVALID;
+			mtr[i]->level = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+			mtr[i]->next_id = ROC_NIX_BPF_ID_INVALID;
+			mtr[i]->is_next = false;
+			mtr[i]->prev_cnt = 0;
+		}
+	}
+	return 0;
+}
+
+int
+nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id,
+		     uint32_t prev_id, uint32_t next_id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, cur_id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	switch (lvl_map[mtr->level]) {
+	case ROC_NIX_BPF_LEVEL_F_LEAF:
+		mtr->prev_id[mtr->prev_cnt] = ROC_NIX_BPF_ID_INVALID;
+		mtr->next_id = next_id;
+		mtr->is_next = true;
+		break;
+	case ROC_NIX_BPF_LEVEL_F_MID:
+		mtr->prev_id[mtr->prev_cnt] = prev_id;
+		mtr->next_id = next_id;
+		mtr->is_next = true;
+		break;
+	case ROC_NIX_BPF_LEVEL_F_TOP:
+		mtr->prev_id[mtr->prev_cnt] = prev_id;
+		mtr->next_id = ROC_NIX_BPF_ID_INVALID;
+		mtr->is_next = false;
+		break;
+	default:
+		plt_err("Invalid meter level");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+struct cnxk_meter_node *
+nix_get_mtr(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return NULL;
+
+	return mtr;
+}
+
+int
+nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t level)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *mtr;
+
+	mtr = nix_mtr_find(dev, id);
+	if (mtr == NULL)
+		return -EINVAL;
+
+	mtr->level = level;
+	return 0;
+}
+
+static void
+nix_mtr_config_map(struct cnxk_meter_node *mtr, struct roc_nix_bpf_cfg *cfg)
+{
+	enum roc_nix_bpf_algo alg_map[] = {
+		ROC_NIX_BPF_ALGO_NONE, ROC_NIX_BPF_ALGO_2697,
+		ROC_NIX_BPF_ALGO_2698, ROC_NIX_BPF_ALGO_4115};
+	struct cnxk_mtr_profile_node *profile = mtr->profile;
+	struct cnxk_mtr_policy_node *policy = mtr->policy;
+
+	cfg->alg = alg_map[profile->profile.alg];
+	cfg->lmode = profile->profile.packet_mode;
+
+	switch (cfg->alg) {
+	case ROC_NIX_BPF_ALGO_2697:
+		cfg->algo2697.cir = profile->profile.srtcm_rfc2697.cir * 8;
+		cfg->algo2697.cbs = profile->profile.srtcm_rfc2697.cbs;
+		cfg->algo2697.ebs = profile->profile.srtcm_rfc2697.ebs;
+		break;
+	case ROC_NIX_BPF_ALGO_2698:
+		cfg->algo2698.cir = profile->profile.trtcm_rfc2698.cir * 8;
+		cfg->algo2698.pir = profile->profile.trtcm_rfc2698.pir * 8;
+		cfg->algo2698.cbs = profile->profile.trtcm_rfc2698.cbs;
+		cfg->algo2698.pbs = profile->profile.trtcm_rfc2698.pbs;
+		break;
+	case ROC_NIX_BPF_ALGO_4115:
+		cfg->algo4115.cir = profile->profile.trtcm_rfc4115.cir * 8;
+		cfg->algo4115.eir = profile->profile.trtcm_rfc4115.eir * 8;
+		cfg->algo4115.cbs = profile->profile.trtcm_rfc4115.cbs;
+		cfg->algo4115.ebs = profile->profile.trtcm_rfc4115.ebs;
+		break;
+	default:
+		break;
+	}
+
+	cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_PASS;
+	cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_PASS;
+	cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_PASS;
+
+	if (policy->actions[RTE_COLOR_GREEN].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_DROP;
+
+	if (policy->actions[RTE_COLOR_YELLOW].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_DROP;
+
+	if (policy->actions[RTE_COLOR_RED].action_fate ==
+	    RTE_FLOW_ACTION_TYPE_DROP)
+		cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_DROP;
+}
+
+static void
+nix_dscp_table_map(struct cnxk_meter_node *mtr,
+		   struct roc_nix_bpf_precolor *tbl)
+{
+	enum roc_nix_bpf_color color_map[] = {ROC_NIX_BPF_COLOR_GREEN,
+					      ROC_NIX_BPF_COLOR_YELLOW,
+					      ROC_NIX_BPF_COLOR_RED};
+	int i;
+
+	tbl->count = ROC_NIX_BPF_PRE_COLOR_MAX;
+	tbl->mode = ROC_NIX_BPF_PC_MODE_DSCP_OUTER;
+
+	for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+		tbl->color[i] = ROC_NIX_BPF_COLOR_GREEN;
+
+	if (mtr->params.dscp_table) {
+		for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++)
+			tbl->color[i] = color_map[mtr->params.dscp_table[i]];
+	}
+}
+
+int
+nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	enum roc_nix_bpf_level_flag lvl_flag = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_meter_node *base_mtr, *next_mtr;
+	struct roc_nix *nix = &dev->nix;
+	uint32_t cur_mtr_id = id;
+	int rc, i;
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		base_mtr = nix_mtr_find(dev, cur_mtr_id);
+		if (base_mtr) {
+			lvl_flag = lvl_map[base_mtr->level];
+			if (base_mtr->is_next) {
+				next_mtr = nix_mtr_find(dev, base_mtr->next_id);
+				if (next_mtr) {
+					if (!base_mtr->is_used) {
+						rc = roc_nix_bpf_connect(nix,
+							lvl_flag,
+							base_mtr->bpf_id,
+							next_mtr->bpf_id);
+						if (rc)
+							return rc;
+					}
+				}
+				cur_mtr_id = base_mtr->next_id;
+			}
+		}
+	}
+	return 0;
+}
+
+int
+nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id)
+{
+	struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_nix_bpf_objs profs[ROC_NIX_BPF_LEVEL_MAX];
+	uint8_t idx0 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint8_t idx1 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint8_t idx2 = ROC_NIX_BPF_LEVEL_IDX_INVALID;
+	uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX];
+	int num_mtr[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	struct roc_nix *nix = &dev->nix;
+	struct roc_nix_bpf_precolor tbl;
+	struct roc_nix_bpf_cfg cfg;
+	struct roc_nix_rq *rq;
+	uint8_t lvl_mask;
+	uint32_t i;
+	uint32_t j;
+	int rc;
+
+	mtr[0] = nix_mtr_find(dev, id);
+	if (mtr[0] == NULL)
+		return -EINVAL;
+
+	num_mtr[0] = 1;
+	idx0 = roc_nix_bpf_level_to_idx(lvl_map[mtr[0]->level]);
+	if (idx0 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+		return -EINVAL;
+
+	lvl_mask = ROC_NIX_BPF_LEVEL_F_LEAF;
+	if (mtr[0]->is_used)
+		per_lvl_cnt[idx0] = 0;
+	else
+		per_lvl_cnt[idx0] = 1;
+
+	if (mtr[0]->is_next) {
+		mtr[1] = nix_mtr_find(dev, mtr[0]->next_id);
+		if (mtr[1] == NULL)
+			return -EINVAL;
+		num_mtr[1] = 1;
+		idx1 = roc_nix_bpf_level_to_idx(lvl_map[mtr[1]->level]);
+		if (idx1 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			return -EINVAL;
+
+		lvl_mask |= ROC_NIX_BPF_LEVEL_F_MID;
+		if (mtr[1]->is_used)
+			per_lvl_cnt[idx1] = 0;
+		else
+			per_lvl_cnt[idx1] = 1;
+	}
+
+	if (mtr[1] && mtr[1]->is_next) {
+		mtr[2] = nix_mtr_find(dev, mtr[1]->next_id);
+		if (mtr[2] == NULL)
+			return -EINVAL;
+
+		num_mtr[2] = 1;
+		idx2 = roc_nix_bpf_level_to_idx(lvl_map[mtr[2]->level]);
+		if (idx2 == ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			return -EINVAL;
+
+		lvl_mask |= ROC_NIX_BPF_LEVEL_F_TOP;
+		if (mtr[2]->is_used)
+			per_lvl_cnt[idx2] = 0;
+		else
+			per_lvl_cnt[idx2] = 1;
+	}
+
+	rc = roc_nix_bpf_alloc(nix, lvl_mask, per_lvl_cnt, profs);
+	if (rc)
+		return rc;
+	if (mtr[0]->bpf_id == ROC_NIX_BPF_ID_INVALID)
+		mtr[0]->bpf_id = profs[idx0].ids[0];
+
+	if (num_mtr[0])
+		if (mtr[0]->is_next && idx1 != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			if (mtr[1]->bpf_id == ROC_NIX_BPF_ID_INVALID)
+				mtr[1]->bpf_id = profs[idx1].ids[0];
+
+	if (num_mtr[1])
+		if (mtr[1]->is_next && idx2 != ROC_NIX_BPF_LEVEL_IDX_INVALID)
+			if (mtr[2]->bpf_id == ROC_NIX_BPF_ID_INVALID)
+				mtr[2]->bpf_id = profs[idx2].ids[0];
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) {
+		if (num_mtr[i]) {
+			if (!mtr[i]->is_used) {
+				memset(&cfg, 0, sizeof(struct roc_nix_bpf_cfg));
+				nix_mtr_config_map(mtr[i], &cfg);
+				rc = roc_nix_bpf_config(nix, mtr[i]->bpf_id,
+							lvl_map[mtr[i]->level],
+							&cfg);
+
+				memset(&tbl, 0,
+				       sizeof(struct roc_nix_bpf_precolor));
+				nix_dscp_table_map(mtr[i], &tbl);
+				rc = roc_nix_bpf_pre_color_tbl_setup(nix,
+					mtr[i]->bpf_id, lvl_map[mtr[i]->level],
+					&tbl);
+
+				if (mtr[i]->params.meter_enable) {
+					for (j = 0; j < mtr[i]->rq_num; j++) {
+						rq = &dev->rqs[mtr[i]->rq_id
+								       [j]];
+						rc = roc_nix_bpf_ena_dis(nix,
+							mtr[i]->bpf_id, rq,
+							true);
+					}
+				}
+			}
+		}
+	}
+
+	return rc;
+}
+
+int
+nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
+			      uint32_t *prev_id, uint32_t *next_id,
+			      struct cnxk_mtr_policy_node *policy,
+			      int *tree_level)
+{
+	uint32_t action_fate_red = policy->actions[RTE_COLOR_RED].action_fate;
+	uint32_t action_fate_green =
+		policy->actions[RTE_COLOR_GREEN].action_fate;
+	uint32_t action_fate_yellow =
+		policy->actions[RTE_COLOR_YELLOW].action_fate;
+	uint32_t cur_mtr_id = *next_id;
+	uint32_t next_mtr_id = 0xffff;
+	uint32_t prev_mtr_id = 0xffff;
+	struct cnxk_meter_node *mtr;
+
+	if (action_fate_green == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_GREEN].mtr_id;
+
+	if (action_fate_yellow == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_YELLOW].mtr_id;
+
+	if (action_fate_red == RTE_FLOW_ACTION_TYPE_METER)
+		next_mtr_id = policy->actions[RTE_COLOR_RED].mtr_id;
+
+	if (next_mtr_id != 0xffff) {
+		switch (*tree_level) {
+		case 0:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 0);
+				nix_mtr_chain_update(eth_dev, cur_mtr_id, -1,
+						     next_mtr_id);
+			} else {
+				if (mtr->level == 0)
+					mtr->is_used = true;
+				else
+					return -EINVAL;
+			}
+			(*tree_level)++;
+			*next_id = next_mtr_id;
+			break;
+		case 1:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 1);
+				prev_mtr_id = id;
+				nix_mtr_chain_update(eth_dev, cur_mtr_id,
+						     prev_mtr_id, next_mtr_id);
+			} else {
+				if (mtr->level == 1) {
+					mtr->prev_cnt++;
+					prev_mtr_id = id;
+					nix_mtr_chain_update(eth_dev,
+						cur_mtr_id, prev_mtr_id,
+						next_mtr_id);
+
+					mtr->is_used = true;
+				} else {
+					return -EINVAL;
+				}
+			}
+			(*tree_level)++;
+			*next_id = next_mtr_id;
+			*prev_id = cur_mtr_id;
+			break;
+		case 2:
+			nix_mtr_chain_reset(eth_dev, id);
+			return -EINVAL;
+		}
+	} else {
+		switch (*tree_level) {
+		case 0:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 0);
+			} else {
+				if (mtr->level == 0)
+					mtr->is_used = true;
+				else
+					return -EINVAL;
+			}
+			break;
+		case 1:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 1);
+				prev_mtr_id = id;
+				nix_mtr_chain_update(eth_dev, cur_mtr_id,
+						     prev_mtr_id, -1);
+			} else {
+				if (mtr->level == 1) {
+					mtr->prev_cnt++;
+					prev_mtr_id = id;
+					nix_mtr_chain_update(eth_dev,
+							     cur_mtr_id,
+							     prev_mtr_id, -1);
+					mtr->is_used = true;
+				} else {
+					return -EINVAL;
+				}
+			}
+			break;
+		case 2:
+			mtr = nix_get_mtr(eth_dev, cur_mtr_id);
+			if (mtr->level == ROC_NIX_BPF_LEVEL_IDX_INVALID) {
+				nix_mtr_level_update(eth_dev, cur_mtr_id, 2);
+				prev_mtr_id = *prev_id;
+				nix_mtr_chain_update(eth_dev, cur_mtr_id,
+						     prev_mtr_id, -1);
+			} else {
+				if (mtr->level == 2) {
+					mtr->prev_cnt++;
+					prev_mtr_id = *prev_id;
+					nix_mtr_chain_update(eth_dev,
+							     cur_mtr_id,
+							     prev_mtr_id, -1);
+					mtr->is_used = true;
+				} else {
+					return -EINVAL;
+				}
+			}
+			break;
+		}
+		*next_id = 0xffff;
+	}
+
+	return 0;
+}
diff --git a/drivers/net/cnxk/cnxk_rte_flow.c b/drivers/net/cnxk/cnxk_rte_flow.c
index 32c1b5dee5..56dcd36c61 100644
--- a/drivers/net/cnxk/cnxk_rte_flow.c
+++ b/drivers/net/cnxk/cnxk_rte_flow.c
@@ -195,6 +195,10 @@ cnxk_map_actions(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 				ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
 			in_actions[i].conf = actions->conf;
 			break;
+		case RTE_FLOW_ACTION_TYPE_METER:
+			in_actions[i].type = ROC_NPC_ACTION_TYPE_METER;
+			in_actions[i].conf = actions->conf;
+			break;
 		default:
 			plt_npc_dbg("Action is not supported = %d",
 				    actions->type);
-- 
2.25.1


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

* [dpdk-dev] [PATCH v5 28/28] net/cnxk: support meter action to flow destroy
  2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
                           ` (26 preceding siblings ...)
  2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 27/28] net/cnxk: support meter action to flow create skori
@ 2021-10-12  7:06         ` skori
  27 siblings, 0 replies; 116+ messages in thread
From: skori @ 2021-10-12  7:06 UTC (permalink / raw)
  To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao
  Cc: dev, Rakesh Kudurumalla

From: Sunil Kumar Kori <skori@marvell.com>

Meters are configured per flow using rte_flow_create API.
Patch adds support for destroy operation for meter action
applied on the flow.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v5:
 - Fix checkpatch errors
 - Fix patch apply errors

v4:
 - Rebase support on dpdk-next-net-mrvl branch
 - Handled meter action during flow destroy
 - Handled meter cleanup during port shutdown
 
v3:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for tree hierarchy
 - Fix naming convention

v2:
 - Rebase support on latest DPDK
 - Handled multilevel chaining for linear hierarchy
 - Review comments incorporated

 drivers/net/cnxk/cn10k_rte_flow.c  | 22 +++++++++++++++-
 drivers/net/cnxk/cnxk_ethdev.c     | 40 ++++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev.h     |  2 ++
 drivers/net/cnxk/cnxk_ethdev_mtr.c |  7 ++++++
 4 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/drivers/net/cnxk/cn10k_rte_flow.c b/drivers/net/cnxk/cn10k_rte_flow.c
index 00c0b172e4..8c87452934 100644
--- a/drivers/net/cnxk/cn10k_rte_flow.c
+++ b/drivers/net/cnxk/cn10k_rte_flow.c
@@ -12,6 +12,14 @@ cn10k_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t mtr_id)
 	return nix_mtr_connect(eth_dev, mtr_id);
 }
 
+static int
+cn10k_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t mtr_id)
+{
+	struct rte_mtr_error mtr_error;
+
+	return nix_mtr_destroy(eth_dev, mtr_id, &mtr_error);
+}
+
 static int
 cn10k_mtr_configure(struct rte_eth_dev *eth_dev,
 		    const struct rte_flow_action actions[])
@@ -215,6 +223,8 @@ cn10k_flow_destroy(struct rte_eth_dev *eth_dev, struct rte_flow *rte_flow,
 	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
 	int mark_actions = 0, vtag_actions = 0;
 	struct roc_npc *npc = &dev->npc;
+	uint32_t mtr_id;
+	int rc;
 
 	mark_actions = roc_npc_mark_actions_get(npc);
 	if (mark_actions) {
@@ -237,5 +247,15 @@ cn10k_flow_destroy(struct rte_eth_dev *eth_dev, struct rte_flow *rte_flow,
 		}
 	}
 
-	return cnxk_flow_destroy(eth_dev, flow, error);
+	mtr_id = flow->mtr_id;
+	rc = cnxk_flow_destroy(eth_dev, flow, error);
+	if (!rc) {
+		rc = cn10k_mtr_destroy(eth_dev, mtr_id);
+		if (rc) {
+			rte_flow_error_set(error, ENXIO,
+				RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				"Meter attached to this flow does not exist");
+		}
+	}
+	return rc;
 }
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index 2bb33d8f2d..69bd58ae45 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -141,6 +141,38 @@ nix_security_setup(struct cnxk_eth_dev *dev)
 	return rc;
 }
 
+static int
+nix_meter_fini(struct cnxk_eth_dev *dev)
+{
+	struct cnxk_meter_node *next_mtr = NULL;
+	struct roc_nix_bpf_objs profs = {0};
+	struct cnxk_meter_node *mtr = NULL;
+	struct cnxk_mtr *fms = &dev->mtr;
+	struct roc_nix *nix = &dev->nix;
+	struct roc_nix_rq *rq;
+	uint32_t i;
+	int rc;
+
+	RTE_TAILQ_FOREACH_SAFE(mtr, fms, next, next_mtr) {
+		for (i = 0; i < mtr->rq_num; i++) {
+			rq = &dev->rqs[mtr->rq_id[i]];
+			rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, false);
+		}
+
+		profs.level = mtr->level;
+		profs.count = 1;
+		profs.ids[0] = mtr->bpf_id;
+		rc = roc_nix_bpf_free(nix, &profs, 1);
+
+		if (rc)
+			return rc;
+
+		TAILQ_REMOVE(fms, mtr, next);
+		plt_free(mtr);
+	}
+	return 0;
+}
+
 static int
 nix_security_release(struct cnxk_eth_dev *dev)
 {
@@ -1012,6 +1044,11 @@ cnxk_nix_configure(struct rte_eth_dev *eth_dev)
 		if (rc)
 			goto fail_configure;
 
+		/* Disable and free rte_meter entries */
+		rc = nix_meter_fini(dev);
+		if (rc)
+			goto fail_configure;
+
 		/* Cleanup security support */
 		rc = nix_security_release(dev);
 		if (rc)
@@ -1668,6 +1705,9 @@ cnxk_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool reset)
 
 	roc_nix_npc_rx_ena_dis(nix, false);
 
+	/* Disable and free rte_meter entries */
+	nix_meter_fini(dev);
+
 	/* Disable and free rte_flow entries */
 	roc_npc_fini(&dev->npc);
 
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 7e13956572..2d4b073985 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -589,6 +589,8 @@ int nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id,
 			 uint32_t level);
 int nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id);
 int nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id);
+int nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t id,
+		    struct rte_mtr_error *error);
 int nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
 				  uint32_t *prev_id, uint32_t *next_id,
 				  struct cnxk_mtr_policy_node *policy,
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index c29a7ec47b..22c85336d9 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -1054,6 +1054,13 @@ nix_dscp_table_map(struct cnxk_meter_node *mtr,
 	}
 }
 
+int
+nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t id,
+		struct rte_mtr_error *error)
+{
+	return cnxk_nix_mtr_destroy(eth_dev, id, error);
+}
+
 int
 nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id)
 {
-- 
2.25.1


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

* Re: [dpdk-dev] [PATCH v4 00/28] Support ingress policer
  2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
                       ` (27 preceding siblings ...)
  2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 28/28] net/cnxk: support meter action to flow destroy skori
@ 2021-10-19 14:30     ` Jerin Jacob
  2021-10-20 13:28       ` Ferruh Yigit
  28 siblings, 1 reply; 116+ messages in thread
From: Jerin Jacob @ 2021-10-19 14:30 UTC (permalink / raw)
  To: Sunil Kumar Kori, Ferruh Yigit; +Cc: dpdk-dev

On Mon, Oct 11, 2021 at 9:21 PM <skori@marvell.com> wrote:
>
> From: Sunil Kumar Kori <skori@marvell.com>
>


Series Acked-by: Jerin Jacob <jerinj@marvell.com>
Series applied to dpdk-next-net-mrvl/for-dpdk-main. Thanks.

> Series adds support for ingress meter for CN10K platform. Series is divided
> in following two logical implementation:
>
>  - common/cnxk: It implements RoC APIs over MBOX interfaces which are by network drivers.
>
>         common/cnxk: update policer MBOX APIs and HW definitions
>         common/cnxk: support RoC API to get level to index
>         common/cnxk: support RoC API to get profile count
>         common/cnxk: support RoC API to alloc bandwidth profiles
>         common/cnxk: support RoC API to free bandwidth profiles
>         common/cnxk: support RoC API to configure bandwidth profile
>         common/cnxk: support RoC API to toggle profile state
>         common/cnxk: support RoC API to dump bandwidth profile
>         common/cnxk: support RoC API to setup precolor table
>         common/cnxk: support RoC API to connect bandwidth profiles
>         common/cnxk: support RoC API to get stats to index
>         common/cnxk: support RoC API to read profile statistics
>         common/cnxk: support RoC API to reset profile stats
>         common/cnxk: support meter in action list
>
>  - net/cnxk: It implenets ethdev ops for various metering operations.
>         For cn9k platform, ops are registerded as NULL because cn9k does
>         not support metering.
>
>         net/cnxk: support meter ops get API
>         net/cnxk: support ops to get meter capabilities
>         net/cnxk: support ops to create meter profile
>         net/cnxk: support ops to delete meter profile
>         net/cnxk: support ops to validate meter policy
>         net/cnxk: support ops to create meter policy
>         net/cnxk: support ops to delete meter policy
>         net/cnxk: support ops to create meter
>         net/cnxk: support ops to delete meter
>         net/cnxk: support ops to enable/disable meter
>         net/cnxk: support ops to update precolor DSCP table
>         net/cnxk: support ops to read/update meter stats
>         net/cnxk: support meter action to flow create
>         net/cnxk: support meter action to flow destroy
>
>  doc/guides/nics/features/cnxk.ini      |    1 +
>  doc/guides/nics/features/cnxk_vf.ini   |    1 +
>  doc/guides/rel_notes/release_21_11.rst |    1 +
>  drivers/common/cnxk/hw/nix.h           |   62 +-
>  drivers/common/cnxk/meson.build        |    1 +
>  drivers/common/cnxk/roc_mbox.h         |   34 +-
>  drivers/common/cnxk/roc_nix.h          |  164 +++
>  drivers/common/cnxk/roc_nix_bpf.c      | 1149 ++++++++++++++++++++
>  drivers/common/cnxk/roc_nix_priv.h     |    1 +
>  drivers/common/cnxk/roc_npc.c          |    7 +
>  drivers/common/cnxk/roc_npc.h          |    8 +-
>  drivers/common/cnxk/roc_platform.h     |    1 +
>  drivers/common/cnxk/roc_utils.c        |    3 +
>  drivers/common/cnxk/version.map        |   15 +
>  drivers/net/cnxk/cn10k_rte_flow.c      |  193 +++-
>  drivers/net/cnxk/cnxk_ethdev.c         |   57 +
>  drivers/net/cnxk/cnxk_ethdev.h         |   92 ++
>  drivers/net/cnxk/cnxk_ethdev_mtr.c     | 1341 ++++++++++++++++++++++++
>  drivers/net/cnxk/cnxk_rte_flow.c       |    4 +
>  drivers/net/cnxk/meson.build           |    1 +
>  20 files changed, 3129 insertions(+), 7 deletions(-)
>  create mode 100644 drivers/common/cnxk/roc_nix_bpf.c
>  create mode 100644 drivers/net/cnxk/cnxk_ethdev_mtr.c
>
> --
> 2.25.1
>

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

* Re: [dpdk-dev] [PATCH v4 00/28] Support ingress policer
  2021-10-19 14:30     ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer Jerin Jacob
@ 2021-10-20 13:28       ` Ferruh Yigit
  0 siblings, 0 replies; 116+ messages in thread
From: Ferruh Yigit @ 2021-10-20 13:28 UTC (permalink / raw)
  To: Jerin Jacob, Sunil Kumar Kori; +Cc: dpdk-dev

On 10/19/2021 3:30 PM, Jerin Jacob wrote:
> On Mon, Oct 11, 2021 at 9:21 PM <skori@marvell.com> wrote:
>>
>> From: Sunil Kumar Kori <skori@marvell.com>
>>
> 
> 
> Series Acked-by: Jerin Jacob <jerinj@marvell.com>
> Series applied to dpdk-next-net-mrvl/for-dpdk-main. Thanks.
> 

For record, v5 of this patch seems merged according patchwork:
https://patches.dpdk.org/project/dpdk/list/?series=19543&state=*

>> Series adds support for ingress meter for CN10K platform. Series is divided
>> in following two logical implementation:
>>
>>   - common/cnxk: It implements RoC APIs over MBOX interfaces which are by network drivers.
>>
>>          common/cnxk: update policer MBOX APIs and HW definitions
>>          common/cnxk: support RoC API to get level to index
>>          common/cnxk: support RoC API to get profile count
>>          common/cnxk: support RoC API to alloc bandwidth profiles
>>          common/cnxk: support RoC API to free bandwidth profiles
>>          common/cnxk: support RoC API to configure bandwidth profile
>>          common/cnxk: support RoC API to toggle profile state
>>          common/cnxk: support RoC API to dump bandwidth profile
>>          common/cnxk: support RoC API to setup precolor table
>>          common/cnxk: support RoC API to connect bandwidth profiles
>>          common/cnxk: support RoC API to get stats to index
>>          common/cnxk: support RoC API to read profile statistics
>>          common/cnxk: support RoC API to reset profile stats
>>          common/cnxk: support meter in action list
>>
>>   - net/cnxk: It implenets ethdev ops for various metering operations.
>>          For cn9k platform, ops are registerded as NULL because cn9k does
>>          not support metering.
>>
>>          net/cnxk: support meter ops get API
>>          net/cnxk: support ops to get meter capabilities
>>          net/cnxk: support ops to create meter profile
>>          net/cnxk: support ops to delete meter profile
>>          net/cnxk: support ops to validate meter policy
>>          net/cnxk: support ops to create meter policy
>>          net/cnxk: support ops to delete meter policy
>>          net/cnxk: support ops to create meter
>>          net/cnxk: support ops to delete meter
>>          net/cnxk: support ops to enable/disable meter
>>          net/cnxk: support ops to update precolor DSCP table
>>          net/cnxk: support ops to read/update meter stats
>>          net/cnxk: support meter action to flow create
>>          net/cnxk: support meter action to flow destroy
>>
>>   doc/guides/nics/features/cnxk.ini      |    1 +
>>   doc/guides/nics/features/cnxk_vf.ini   |    1 +
>>   doc/guides/rel_notes/release_21_11.rst |    1 +
>>   drivers/common/cnxk/hw/nix.h           |   62 +-
>>   drivers/common/cnxk/meson.build        |    1 +
>>   drivers/common/cnxk/roc_mbox.h         |   34 +-
>>   drivers/common/cnxk/roc_nix.h          |  164 +++
>>   drivers/common/cnxk/roc_nix_bpf.c      | 1149 ++++++++++++++++++++
>>   drivers/common/cnxk/roc_nix_priv.h     |    1 +
>>   drivers/common/cnxk/roc_npc.c          |    7 +
>>   drivers/common/cnxk/roc_npc.h          |    8 +-
>>   drivers/common/cnxk/roc_platform.h     |    1 +
>>   drivers/common/cnxk/roc_utils.c        |    3 +
>>   drivers/common/cnxk/version.map        |   15 +
>>   drivers/net/cnxk/cn10k_rte_flow.c      |  193 +++-
>>   drivers/net/cnxk/cnxk_ethdev.c         |   57 +
>>   drivers/net/cnxk/cnxk_ethdev.h         |   92 ++
>>   drivers/net/cnxk/cnxk_ethdev_mtr.c     | 1341 ++++++++++++++++++++++++
>>   drivers/net/cnxk/cnxk_rte_flow.c       |    4 +
>>   drivers/net/cnxk/meson.build           |    1 +
>>   20 files changed, 3129 insertions(+), 7 deletions(-)
>>   create mode 100644 drivers/common/cnxk/roc_nix_bpf.c
>>   create mode 100644 drivers/net/cnxk/cnxk_ethdev_mtr.c
>>
>> --
>> 2.25.1
>>


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

end of thread, other threads:[~2021-10-20 13:28 UTC | newest]

Thread overview: 116+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27  8:21 [dpdk-dev] [PATCH v2 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
2021-09-27  8:21 ` [dpdk-dev] [PATCH v2 02/27] common/cnxk: support RoC API to get level to index skori
2021-09-27  8:21 ` [dpdk-dev] [PATCH v2 03/27] common/cnxk: support RoC API to get profile count skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 04/27] common/cnxk: support RoC API to alloc bandwidth profiles skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 05/27] common/cnxk: support RoC API to free " skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 06/27] common/cnxk: support RoC API to configure bandwidth profile skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 07/27] common/cnxk: support RoC API to toggle profile state skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 08/27] common/cnxk: support RoC API to dump bandwidth profile skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 09/27] common/cnxk: support RoC API to setup precolor table skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 10/27] common/cnxk: support RoC API to connect bandwidth profiles skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 11/27] common/cnxk: support RoC API to get stats to index skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 12/27] common/cnxk: support RoC API to read profile statistics skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 13/27] common/cnxk: support RoC API to reset profile stats skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 14/27] common/cnxk: support meter in action list skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 15/27] net/cnxk: support meter ops get API skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 16/27] net/cnxk: support ops to get meter capabilities skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 17/27] net/cnxk: support ops to create meter profile skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 18/27] net/cnxk: support ops to delete " skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 19/27] net/cnxk: support ops to validate meter policy skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 20/27] net/cnxk: support ops to create " skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 21/27] net/cnxk: support ops to delete " skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 22/27] net/cnxk: support ops to create meter skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 23/27] net/cnxk: support ops to delete meter skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 24/27] net/cnxk: support ops to enable/disable meter skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 25/27] net/cnxk: support ops to update precolor DSCP table skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 26/27] net/cnxk: support ops to read/update meter stats skori
2021-09-27  8:22 ` [dpdk-dev] [PATCH v2 27/27] net/cnxk: support meter action to flow create skori
2021-09-30  9:08 ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 02/27] common/cnxk: support RoC API to get level to index skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 03/27] common/cnxk: support RoC API to get profile count skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 04/27] common/cnxk: support RoC API to alloc bandwidth profiles skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 05/27] common/cnxk: support RoC API to free " skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 06/27] common/cnxk: support RoC API to configure bandwidth profile skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 07/27] common/cnxk: support RoC API to toggle profile state skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 08/27] common/cnxk: support RoC API to dump bandwidth profile skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 09/27] common/cnxk: support RoC API to setup precolor table skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 10/27] common/cnxk: support RoC API to connect bandwidth profiles skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 11/27] common/cnxk: support RoC API to get stats to index skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 12/27] common/cnxk: support RoC API to read profile statistics skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 13/27] common/cnxk: support RoC API to reset profile stats skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 14/27] common/cnxk: support meter in action list skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 15/27] net/cnxk: support meter ops get API skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 16/27] net/cnxk: support ops to get meter capabilities skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 17/27] net/cnxk: support ops to create meter profile skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 18/27] net/cnxk: support ops to delete " skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 19/27] net/cnxk: support ops to validate meter policy skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 20/27] net/cnxk: support ops to create " skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 21/27] net/cnxk: support ops to delete " skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 22/27] net/cnxk: support ops to create meter skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 23/27] net/cnxk: support ops to delete meter skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 24/27] net/cnxk: support ops to enable/disable meter skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 25/27] net/cnxk: support ops to update precolor DSCP table skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 26/27] net/cnxk: support ops to read/update meter stats skori
2021-09-30  9:08   ` [dpdk-dev] [PATCH v3 27/27] net/cnxk: support meter action to flow create skori
2021-09-30 10:00   ` [dpdk-dev] [PATCH v3 01/27] common/cnxk: update policer MBOX APIs and HW definitions Kinsella, Ray
2021-10-02 13:56     ` Jerin Jacob
2021-10-11 15:50   ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 01/28] common/cnxk: update policer MBOX APIs and HW definitions skori
2021-10-12  7:05       ` [dpdk-dev] [PATCH v5 00/28] Support ingress policer skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 01/28] common/cnxk: update policer MBOX APIs and HW definitions skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 02/28] common/cnxk: support RoC API to get level to index skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 03/28] common/cnxk: support RoC API to get profile count skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 04/28] common/cnxk: support RoC API to alloc bandwidth profiles skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 05/28] common/cnxk: support RoC API to free " skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 06/28] common/cnxk: support RoC API to configure bandwidth profile skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 07/28] common/cnxk: support RoC API to toggle profile state skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 08/28] common/cnxk: support RoC API to dump bandwidth profile skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 09/28] common/cnxk: support RoC API to setup precolor table skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 10/28] common/cnxk: support RoC API to connect bandwidth profiles skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 11/28] common/cnxk: support RoC API to get stats to index skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 12/28] common/cnxk: support RoC API to read profile statistics skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 13/28] common/cnxk: support RoC API to reset profile stats skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 14/28] common/cnxk: support meter in action list skori
2021-10-12  7:05         ` [dpdk-dev] [PATCH v5 15/28] net/cnxk: support meter ops get API skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 16/28] net/cnxk: support ops to get meter capabilities skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 17/28] net/cnxk: support ops to create meter profile skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 18/28] net/cnxk: support ops to delete " skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 19/28] net/cnxk: support ops to validate meter policy skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 20/28] net/cnxk: support ops to create " skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 21/28] net/cnxk: support ops to delete " skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 22/28] net/cnxk: support ops to create meter skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 23/28] net/cnxk: support ops to delete meter skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 24/28] net/cnxk: support ops to enable/disable meter skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 25/28] net/cnxk: support ops to update precolor DSCP table skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 26/28] net/cnxk: support ops to read/update meter stats skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 27/28] net/cnxk: support meter action to flow create skori
2021-10-12  7:06         ` [dpdk-dev] [PATCH v5 28/28] net/cnxk: support meter action to flow destroy skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 02/28] common/cnxk: support RoC API to get level to index skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 03/28] common/cnxk: support RoC API to get profile count skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 04/28] common/cnxk: support RoC API to alloc bandwidth profiles skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 05/28] common/cnxk: support RoC API to free " skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 06/28] common/cnxk: support RoC API to configure bandwidth profile skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 07/28] common/cnxk: support RoC API to toggle profile state skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 08/28] common/cnxk: support RoC API to dump bandwidth profile skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 09/28] common/cnxk: support RoC API to setup precolor table skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 10/28] common/cnxk: support RoC API to connect bandwidth profiles skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 11/28] common/cnxk: support RoC API to get stats to index skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 12/28] common/cnxk: support RoC API to read profile statistics skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 13/28] common/cnxk: support RoC API to reset profile stats skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 14/28] common/cnxk: support meter in action list skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 15/28] net/cnxk: support meter ops get API skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 16/28] net/cnxk: support ops to get meter capabilities skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 17/28] net/cnxk: support ops to create meter profile skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 18/28] net/cnxk: support ops to delete " skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 19/28] net/cnxk: support ops to validate meter policy skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 20/28] net/cnxk: support ops to create " skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 21/28] net/cnxk: support ops to delete " skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 22/28] net/cnxk: support ops to create meter skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 23/28] net/cnxk: support ops to delete meter skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 24/28] net/cnxk: support ops to enable/disable meter skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 25/28] net/cnxk: support ops to update precolor DSCP table skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 26/28] net/cnxk: support ops to read/update meter stats skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 27/28] net/cnxk: support meter action to flow create skori
2021-10-11 15:50     ` [dpdk-dev] [PATCH v4 28/28] net/cnxk: support meter action to flow destroy skori
2021-10-19 14:30     ` [dpdk-dev] [PATCH v4 00/28] Support ingress policer Jerin Jacob
2021-10-20 13:28       ` Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).