NULL,
"Meter profile already exists.");
if (profile->alg == RTE_MTR_SRTCM_RFC2697) {
- if (priv->config.hca_attr.qos.srtcm_sup) {
+ if (priv->config.hca_attr.qos.flow_meter_old) {
/* Verify support for flow meter parameters. */
if (profile->srtcm_rfc2697.cir > 0 &&
profile->srtcm_rfc2697.cir <= MLX5_SRTCM_CIR_MAX &&
cap->shared_n_flows_per_mtr_max = 4 << 20;
/* 2M flows can share the same meter. */
cap->chaining_n_mtrs_per_flow_max = 1; /* Chaining is not supported. */
- cap->meter_srtcm_rfc2697_n_max = qattr->srtcm_sup ? cap->n_max : 0;
+ cap->meter_srtcm_rfc2697_n_max = qattr->flow_meter_old ? cap->n_max : 0;
cap->meter_rate_max = 1ULL << 40; /* 1 Tera tokens per sec. */
cap->policer_action_drop_supported = 1;
cap->stats_mask = RTE_MTR_STATS_N_BYTES_DROPPED |
MTR_POLICER_ACTION_COLOR_RED };
int i;
+ /* Meter must use global drop action. */
+ if (!priv->sh->dr_drop_action)
+ return -rte_mtr_error_set(error, ENOTSUP,
+ RTE_MTR_ERROR_TYPE_MTR_PARAMS,
+ NULL,
+ "No drop action ready for meter.");
/* Meter params must not be NULL. */
if (params == NULL)
return -rte_mtr_error_set(error, EINVAL,
.egress = 1,
.transfer = priv->config.dv_esw_en ? 1 : 0,
};
+ struct mlx5_indexed_pool_config flow_ipool_cfg = {
+ .size = 0,
+ .trunk_size = 64,
+ .need_lock = 1,
+ .type = "mlx5_flow_mtr_flow_id_pool",
+ };
int ret;
unsigned int i;
uint32_t idx = 0;
+ uint8_t mtr_id_bits;
+ uint8_t mtr_reg_bits = priv->mtr_reg_share ?
+ MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
if (!priv->mtr_en)
return -rte_mtr_error_set(error, ENOTSUP,
return -rte_mtr_error_set(error, ENOMEM,
RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
"Memory alloc failed for meter.");
+ mtr_id_bits = MLX5_REG_BITS - __builtin_clz(idx);
+ if ((mtr_id_bits + priv->max_mtr_flow_bits) > mtr_reg_bits) {
+ DRV_LOG(ERR, "Meter number exceeds max limit.");
+ goto error;
+ }
+ if (mtr_id_bits > priv->max_mtr_bits)
+ priv->max_mtr_bits = mtr_id_bits;
fm->idx = idx;
/* Fill the flow meter parameters. */
fm->meter_id = meter_id;
if (!fm->policer_stats.cnt[i])
goto error;
}
- fm->mfts = mlx5_flow_create_mtr_tbls(dev, fm);
+ fm->mfts = mlx5_flow_create_mtr_tbls(dev);
if (!fm->mfts)
goto error;
- ret = mlx5_flow_create_policer_rules(dev, fm, &attr);
+ ret = mlx5_flow_prepare_policer_rules(dev, fm, &attr);
if (ret)
goto error;
/* Add to the flow meter list. */
fm->shared = !!shared;
fm->policer_stats.stats_mask = params->stats_mask;
fm->profile->ref_cnt++;
+ fm->flow_ipool = mlx5_ipool_create(&flow_ipool_cfg);
+ if (!fm->flow_ipool)
+ goto error;
+ rte_spinlock_init(&fm->sl);
return 0;
error:
mlx5_flow_destroy_policer_rules(dev, fm, &attr);
if (fm->policer_stats.cnt[i])
mlx5_counter_free(dev, fm->policer_stats.cnt[i]);
/* Free meter flow table */
+ if (fm->flow_ipool)
+ mlx5_ipool_destroy(fm->flow_ipool);
mlx5_flow_destroy_policer_rules(dev, fm, &attr);
mlx5_flow_destroy_mtr_tbls(dev, fm->mfts);
mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR], fm->idx);
*
* @param [in] priv
* Pointer to mlx5 private data.
- * @param [in] meter_id
- * Flow meter id.
+ * @param[in] fm
+ * Pointer to flow meter.
* @param [in] attr
* Pointer to flow attributes.
* @param [out] error
* Pointer to error structure.
*
- * @return the flow meter pointer, NULL otherwise.
+ * @return
+ * 0 on success, a negative errno value otherwise and rte_errno is set.
*/
-struct mlx5_flow_meter *
-mlx5_flow_meter_attach(struct mlx5_priv *priv, uint32_t meter_id,
+int
+mlx5_flow_meter_attach(struct mlx5_priv *priv,
+ struct mlx5_flow_meter *fm,
const struct rte_flow_attr *attr,
struct rte_flow_error *error)
{
- struct mlx5_flow_meter *fm;
+ int ret = 0;
- fm = mlx5_flow_meter_find(priv, meter_id);
- if (fm == NULL) {
- rte_flow_error_set(error, ENOENT,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
- "Meter object id not valid");
- goto error;
- }
- if (!fm->shared && fm->ref_cnt) {
- DRV_LOG(ERR, "Cannot share a non-shared meter.");
- rte_flow_error_set(error, EINVAL,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
- "Meter can't be shared");
- goto error;
- }
- if (!fm->ref_cnt++) {
- MLX5_ASSERT(!fm->mfts->meter_action);
+ rte_spinlock_lock(&fm->sl);
+ if (fm->mfts->meter_action) {
+ if (fm->shared &&
+ attr->transfer == fm->transfer &&
+ attr->ingress == fm->ingress &&
+ attr->egress == fm->egress)
+ fm->ref_cnt++;
+ else
+ ret = -1;
+ } else {
fm->ingress = attr->ingress;
fm->egress = attr->egress;
fm->transfer = attr->transfer;
+ fm->ref_cnt = 1;
/* This also creates the meter object. */
fm->mfts->meter_action = mlx5_flow_meter_action_create(priv,
fm);
- if (!fm->mfts->meter_action)
- goto error_detach;
- } else {
- MLX5_ASSERT(fm->mfts->meter_action);
- if (attr->transfer != fm->transfer ||
- attr->ingress != fm->ingress ||
- attr->egress != fm->egress) {
- DRV_LOG(ERR, "meter I/O attributes do not "
- "match flow I/O attributes.");
- goto error_detach;
+ if (!fm->mfts->meter_action) {
+ fm->ref_cnt = 0;
+ fm->ingress = 0;
+ fm->egress = 0;
+ fm->transfer = 0;
+ ret = -1;
+ DRV_LOG(ERR, "Meter action create failed.");
}
}
- return fm;
-error_detach:
- mlx5_flow_meter_detach(fm);
- rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
- fm->mfts->meter_action ? "Meter attr not match" :
- "Meter action create failed");
-error:
- return NULL;
+ rte_spinlock_unlock(&fm->sl);
+ if (ret)
+ rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+ fm->mfts->meter_action ?
+ "Meter attr not match" :
+ "Meter action create failed");
+ return ret ? -rte_errno : 0;
}
/**
void
mlx5_flow_meter_detach(struct mlx5_flow_meter *fm)
{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER
+ rte_spinlock_lock(&fm->sl);
MLX5_ASSERT(fm->ref_cnt);
- if (--fm->ref_cnt)
- return;
- if (fm->mfts->meter_action)
+ if (--fm->ref_cnt == 0) {
mlx5_glue->destroy_flow_action(fm->mfts->meter_action);
- fm->mfts->meter_action = NULL;
- fm->ingress = 0;
- fm->egress = 0;
- fm->transfer = 0;
+ fm->mfts->meter_action = NULL;
+ fm->ingress = 0;
+ fm->egress = 0;
+ fm->transfer = 0;
+ }
+ rte_spinlock_unlock(&fm->sl);
+#else
+ (void)fm;
+#endif
}
/**