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,
.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,
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;
}
return 0;
}
+static int
+update_mtr_err(uint32_t act_color, struct rte_mtr_error *error, bool action)
+{
+ const char *str;
+ 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);
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);
}
}
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);
+}