X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fcnxk%2Fcnxk_ethdev_mtr.c;h=02803bdf7540185b85cfc1df6f45d66d4710d6c5;hb=3c100e0e6b9c7865193cc07236ac347927660ff2;hp=c29a7ec47bd2bc8246bcdbcec1696a51b4b51294;hpb=58397fedc63b7d0e56574eb1ca521b81cffea5e8;p=dpdk.git diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c index c29a7ec47b..02803bdf75 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,6 @@ 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 +179,42 @@ cnxk_nix_mtr_capabilities_get(struct rte_eth_dev *dev, struct rte_mtr_capabilities *capa, struct rte_mtr_error *error) { + uint8_t lvl_mask = ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID | + ROC_NIX_BPF_LEVEL_F_TOP; + struct cnxk_eth_dev *eth_dev = cnxk_eth_pmd_priv(dev); + uint16_t count[ROC_NIX_BPF_LEVEL_MAX] = {0}; + struct roc_nix *nix = ð_dev->nix; + uint32_t time_unit; + int rc, 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; + + rc = roc_nix_bpf_timeunit_get(nix, &time_unit); + if (rc) + return rc; + + mtr_capa.meter_rate_max = + NIX_BPF_RATE(time_unit, NIX_BPF_MAX_RATE_EXPONENT, + NIX_BPF_MAX_RATE_MANTISSA, 0) / + 8; + *capa = mtr_capa; return 0; } @@ -261,15 +285,54 @@ cnxk_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id, return 0; } +static int +update_mtr_err(uint32_t act_color, struct rte_mtr_error *error, bool action) +{ + const char *str = NULL; + switch (act_color) { + case RTE_COLOR_GREEN: + if (action) { + str = "Green action is not valid"; + goto notsup; + } else { + str = "Green action is null"; + goto notvalid; + } + break; + case RTE_COLOR_YELLOW: + if (action) { + str = "Yellow action is not valid"; + goto notsup; + } else { + str = "Yellow action is null"; + goto notvalid; + } + break; + case RTE_COLOR_RED: + if (action) { + str = "Red action is not valid"; + goto notsup; + } else { + str = "Red action is null"; + goto notvalid; + } + break; + } +notsup: + return -rte_mtr_error_set(error, ENOTSUP, + RTE_MTR_ERROR_TYPE_METER_POLICY, NULL, str); +notvalid: + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_METER_POLICY, NULL, str); +} + 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); @@ -288,21 +351,14 @@ cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev, 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); - } + if (action->type == RTE_FLOW_ACTION_TYPE_VOID) + supported[i] = true; + + if (!supported[i]) + return update_mtr_err(i, error, true); } } 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 update_mtr_err(i, error, false); } } @@ -1054,6 +1110,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) { @@ -1332,3 +1395,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); +}