diff mbox series

[v3,19/27] net/cnxk: support ops to validate meter policy

Message ID 20210930090844.1059326-19-skori@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Jerin Jacob
Headers show
Series [v3,01/27] common/cnxk: update policer MBOX APIs and HW definitions | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Sunil Kumar Kori Sept. 30, 2021, 9:08 a.m. UTC
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 mbox series

Patch

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