diff mbox series

[v2,2/2] net/cnxk: integrate bpfcount get MBOX interface

Message ID 20211102064137.1802537-2-rkudurumalla@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers show
Series [v2,1/2] common/cnxk: change policer timeuint to configured value | expand

Checks

Context Check Description
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/checkpatch success coding style OK

Commit Message

Rakesh Kudurumalla Nov. 2, 2021, 6:41 a.m. UTC
Bpf count is updated in meter capabilities during device
initialization using mbox interface

Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
---
v2:
- resolve nix configure error in cn9k
 drivers/net/cnxk/cn10k_rte_flow.c  |  2 +-
 drivers/net/cnxk/cn9k_ethdev.c     |  1 +
 drivers/net/cnxk/cnxk_ethdev.c     |  8 +++++-
 drivers/net/cnxk/cnxk_ethdev.h     |  1 +
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 39 ++++++++++++++++++++++++------
 5 files changed, 42 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/cnxk/cn10k_rte_flow.c b/drivers/net/cnxk/cn10k_rte_flow.c
index dff4c7746c..b830abe63e 100644
--- a/drivers/net/cnxk/cn10k_rte_flow.c
+++ b/drivers/net/cnxk/cn10k_rte_flow.c
@@ -249,7 +249,7 @@  cn10k_flow_destroy(struct rte_eth_dev *eth_dev, struct rte_flow *rte_flow,
 
 	mtr_id = flow->mtr_id;
 	rc = cnxk_flow_destroy(eth_dev, flow, error);
-	if (!rc) {
+	if (!rc && mtr_id != ROC_NIX_MTR_ID_INVALID) {
 		rc = cn10k_mtr_destroy(eth_dev, mtr_id);
 		if (rc) {
 			rte_flow_error_set(error, ENXIO,
diff --git a/drivers/net/cnxk/cn9k_ethdev.c b/drivers/net/cnxk/cn9k_ethdev.c
index 2fdc10a2c9..f8f3d3895e 100644
--- a/drivers/net/cnxk/cn9k_ethdev.c
+++ b/drivers/net/cnxk/cn9k_ethdev.c
@@ -486,6 +486,7 @@  nix_eth_dev_ops_override(void)
 	cnxk_eth_dev_ops.dev_ptypes_set = cn9k_nix_ptypes_set;
 	cnxk_eth_dev_ops.timesync_enable = cn9k_nix_timesync_enable;
 	cnxk_eth_dev_ops.timesync_disable = cn9k_nix_timesync_disable;
+	cnxk_eth_dev_ops.mtr_ops_get = NULL;
 }
 
 static void
diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c
index db54468dbc..942177f2c5 100644
--- a/drivers/net/cnxk/cnxk_ethdev.c
+++ b/drivers/net/cnxk/cnxk_ethdev.c
@@ -730,11 +730,17 @@  nix_free_queue_mem(struct cnxk_eth_dev *dev)
 static int
 nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
+	struct rte_eth_dev *eth_dev = dev->eth_dev;
+	int rc = 0;
+
 	TAILQ_INIT(&dev->mtr_profiles);
 	TAILQ_INIT(&dev->mtr_policy);
 	TAILQ_INIT(&dev->mtr);
 
-	return 0;
+	if (eth_dev->dev_ops->mtr_ops_get == NULL)
+		return rc;
+
+	return nix_mtr_capabilities_init(eth_dev);
 }
 
 static int
diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h
index 7e4939f0b9..d7c4b3e319 100644
--- a/drivers/net/cnxk/cnxk_ethdev.h
+++ b/drivers/net/cnxk/cnxk_ethdev.h
@@ -590,6 +590,7 @@  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_capabilities_init(struct rte_eth_dev *eth_dev);
 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,
diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 22c85336d9..39d8563826 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -28,7 +28,6 @@  static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
 						      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,
 	/* .identical = , */
 	.shared_identical = true,
@@ -36,11 +35,7 @@  static struct rte_mtr_capabilities mtr_capa = {
 	.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,
@@ -185,12 +180,33 @@  cnxk_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
 			      struct rte_mtr_capabilities *capa,
 			      struct rte_mtr_error *error)
 {
+	struct cnxk_eth_dev *eth_dev = cnxk_eth_pmd_priv(dev);
+	uint16_t count[ROC_NIX_BPF_LEVEL_MAX] = {0};
+	uint8_t lvl_mask = ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |
+			   ROC_NIX_BPF_LEVEL_F_TOP;
+	struct roc_nix *nix = &eth_dev->nix;
+	int rc;
+	int i;
+
 	RTE_SET_USED(dev);
 
 	if (!capa)
 		return -rte_mtr_error_set(error, EINVAL,
-					  RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
-					  "NULL input parameter");
+				RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+				"NULL input parameter");
+
+	rc = roc_nix_bpf_count_get(nix, lvl_mask, count);
+	if (rc)
+		return rc;
+
+	for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++)
+		mtr_capa.n_max += count[i];
+
+	mtr_capa.meter_srtcm_rfc2697_n_max = mtr_capa.n_max;
+	mtr_capa.meter_trtcm_rfc2698_n_max = mtr_capa.n_max;
+	mtr_capa.meter_trtcm_rfc4115_n_max = mtr_capa.n_max;
+	mtr_capa.meter_policy_n_max = mtr_capa.n_max;
+
 	*capa = mtr_capa;
 	return 0;
 }
@@ -1339,3 +1355,12 @@  nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
 
 	return 0;
 }
+
+int
+nix_mtr_capabilities_init(struct rte_eth_dev *eth_dev)
+{
+	struct rte_mtr_capabilities capa;
+	struct rte_mtr_error error;
+
+	return cnxk_nix_mtr_capabilities_get(eth_dev, &capa, &error);
+}