From patchwork Fri Nov 8 03:49:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suanming Mou X-Patchwork-Id: 62719 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C325DA04AB; Fri, 8 Nov 2019 04:50:43 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 544DD1BFB5; Fri, 8 Nov 2019 04:49:50 +0100 (CET) Received: from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130]) by dpdk.org (Postfix) with ESMTP id 22FDB1BF53 for ; Fri, 8 Nov 2019 04:49:33 +0100 (CET) From: Suanming Mou To: viacheslavo@mellanox.com, matan@mellanox.com Cc: orika@mellanox.com, rasland@mellanox.com, dev@dpdk.org Date: Fri, 8 Nov 2019 05:49:11 +0200 Message-Id: <1573184965-49691-6-git-send-email-suanmingm@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573184965-49691-1-git-send-email-suanmingm@mellanox.com> References: <1573053090-179521-1-git-send-email-suanmingm@mellanox.com> <1573184965-49691-1-git-send-email-suanmingm@mellanox.com> Subject: [dpdk-dev] [PATCH v2 05/19] net/mlx5: validate meter profile X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The add meter profile should be validated if it is valid or has been add to the list. Invalid and exist profile should not be add to the list. Signed-off-by: Suanming Mou --- drivers/net/mlx5/mlx5_flow_meter.c | 70 ++++++++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_prm.h | 5 +++ 2 files changed, 75 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c index b11962f..5ad5e14 100644 --- a/drivers/net/mlx5/mlx5_flow_meter.c +++ b/drivers/net/mlx5/mlx5_flow_meter.c @@ -35,6 +35,71 @@ } /** + * Validate the MTR profile. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[in] meter_profile_id + * Meter profile id. + * @param[in] profile + * Pointer to meter profile detail. + * @param[out] error + * Pointer to the error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev, + uint32_t meter_profile_id, + struct rte_mtr_meter_profile *profile, + struct rte_mtr_error *error) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_flow_meter_profile *fmp; + + /* Profile must not be NULL. */ + if (profile == NULL) + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE, + NULL, "Meter profile is null."); + /* Meter profile ID must be valid. */ + if (meter_profile_id == UINT32_MAX) + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, "Meter profile id not valid."); + /* Meter profile must not exist. */ + fmp = mlx5_flow_meter_profile_find(priv, meter_profile_id); + if (fmp) + return -rte_mtr_error_set(error, EEXIST, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "Meter profile already exists."); + if (profile->alg == RTE_MTR_SRTCM_RFC2697) { + if (priv->config.hca_attr.qos.srtcm_sup) { + /* Verify support for flow meter parameters. */ + if (profile->srtcm_rfc2697.cir > 0 && + profile->srtcm_rfc2697.cir <= MLX5_SRTCM_CIR_MAX && + profile->srtcm_rfc2697.cbs > 0 && + profile->srtcm_rfc2697.cbs <= MLX5_SRTCM_CBS_MAX && + profile->srtcm_rfc2697.ebs <= MLX5_SRTCM_EBS_MAX) + return 0; + else + return -rte_mtr_error_set + (error, ENOTSUP, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, + NULL, + profile->srtcm_rfc2697.ebs ? + "Metering value ebs must be 0." : + "Invalid metering parameters."); + } + } + return -rte_mtr_error_set(error, ENOTSUP, + RTE_MTR_ERROR_TYPE_METER_PROFILE, + NULL, "Metering algorithm not supported."); +} + +/** * Calculate mantissa and exponent for cir. * * @param[in] cir @@ -226,6 +291,11 @@ return -rte_mtr_error_set(error, ENOTSUP, RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL, "Meter is not support"); + /* Check input params. */ + ret = mlx5_flow_meter_profile_validate(dev, meter_profile_id, + profile, error); + if (ret) + return ret; /* Meter profile memory allocation. */ fmp = rte_calloc(__func__, 1, sizeof(struct mlx5_flow_meter_profile), RTE_CACHE_LINE_SIZE); diff --git a/drivers/net/mlx5/mlx5_prm.h b/drivers/net/mlx5/mlx5_prm.h index a0c37c8..3ebf191 100644 --- a/drivers/net/mlx5/mlx5_prm.h +++ b/drivers/net/mlx5/mlx5_prm.h @@ -1768,6 +1768,11 @@ struct mlx5_mini_cqe8 { uint32_t byte_cnt; }; +/* Maximum value of srTCM metering parameters. */ +#define MLX5_SRTCM_CBS_MAX (0xFF * (1ULL << 0x1F)) +#define MLX5_SRTCM_CIR_MAX (8 * (1ULL << 30) * 0xFF) +#define MLX5_SRTCM_EBS_MAX 0 + /** * Convert a user mark to flow mark. *