From 26b034f78ca7d9a8c5dbf9e25bcac5aa24261c08 Mon Sep 17 00:00:00 2001 From: Sunil Kumar Kori Date: Tue, 12 Oct 2021 12:36:03 +0530 Subject: [PATCH] net/cnxk: support to validate meter policy Implement API to validate meter policy for CNXK platform. Signed-off-by: Sunil Kumar Kori Signed-off-by: Rakesh Kudurumalla Acked-by: Jerin Jacob --- doc/guides/nics/features/cnxk.ini | 1 + doc/guides/nics/features/cnxk_vf.ini | 1 + drivers/net/cnxk/cnxk_ethdev_mtr.c | 49 ++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) 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/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.20.1