From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 08EDFA034F; Thu, 29 Jul 2021 18:04:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C58B640687; Thu, 29 Jul 2021 18:04:42 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2059.outbound.protection.outlook.com [40.107.92.59]) by mails.dpdk.org (Postfix) with ESMTP id 2FE474067A for ; Thu, 29 Jul 2021 18:04:42 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TnTdfeFG9E8Nw7w4FXscDe0armTD+/7qZ2ZTExu3xb22FNjK4r+UyUMO31RUsOxn/hy7qEaEfg7mBWpbCxOEBbjFiw00m+rKaOr2+BcooTBE4I35kFmt9ON3RIr3qkpUQPh1zxYrHxCU+bygs8qOuGL3yxAiYPkRkvcnJljHw+k9uHJULQo+F6XpcHK3Pnc0wSAdDrok9meWxRQi2EPqV4/rqwrCvvqvUBL43F2BM9ss6dPJs2ffwHtFtgsysWQeSj/I7WvZBKVq0l4KjLrBSlK0fZsore0j0uAfEAhrGeGYHJND3UxaVIDX7b4BcAtclEr9oVxElZ/c5VsqfXeBsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YtmH422gfzF5MwXC1EJhIIIeUj+HKdSk0TCUURwnIPI=; b=kK62Gkx9VFD8AZHeEQPEXCDDPQBrD6aVp8xAcPu5I2An23xJVRSQv8tfS0kgz9juYycecXW8oqudgmIoGvJZ2CFVXnYLA2LtUSJk1PwNCJHFaRNAscOpQqzeC6WI3OleZ0BXNGnVAuaMTIiYCsbXHZRa9/aLIrBFTxK77kfb0z8tybIyleq4iBBlMnJQg4HA+q0pZb/ED/wQisZFg+99tloMjzPZ2EsXTsUe/IvFUXFIVJBDDqAIpRM+a0T8+nhcttjNY0ctnq4H19g+hsONg2Pxridsw72mtQrVe5/S7zIyQmhXnUtu7dawsnmw8LZ/UQYUocNrawjLSXSNw19JoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=monjalon.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YtmH422gfzF5MwXC1EJhIIIeUj+HKdSk0TCUURwnIPI=; b=IQJ7oJSsZ/WKNZriOglseCnn2wAHW2uFrCpTFo9E3SUmX+JpBxSKFoUevS13VAvY64fYjSmrCxjNIq135idf+qZKoD5SkTTx8aA9mLyzO+2diMi8x8dmCIF+1r6m5SFUxyxtM0MeJnp+2W/otfPUJ/d87zGWFBsqbBTTwa2dC9yCktzl79cac64Ag8RJRZQ8yCZra7UXrRuJsj8osIoi8YGXLJ1bWTu+ujIcQ+BQk4dhd/JBVjYWCqvypwPGm60n6FVSiAJTywI1Jihf1HghheEPuNkUOxJtWTG57q7OmgAoFPWxiv2x6+zsLZMWeaafXBRy7d20URrv3lfAyd7uQw== Received: from BN6PR22CA0060.namprd22.prod.outlook.com (2603:10b6:404:ca::22) by DM6PR12MB2764.namprd12.prod.outlook.com (2603:10b6:5:4a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.26; Thu, 29 Jul 2021 16:04:40 +0000 Received: from BN8NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:404:ca:cafe::9a) by BN6PR22CA0060.outlook.office365.com (2603:10b6:404:ca::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.17 via Frontend Transport; Thu, 29 Jul 2021 16:04:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; monjalon.net; dkim=none (message not signed) header.d=none;monjalon.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT022.mail.protection.outlook.com (10.13.176.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4373.18 via Frontend Transport; Thu, 29 Jul 2021 16:04:40 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 29 Jul 2021 16:04:38 +0000 From: Bing Zhao To: , CC: , , , Date: Thu, 29 Jul 2021 19:04:02 +0300 Message-ID: <20210729160405.161982-1-bingz@nvidia.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e233116d-d298-4209-7720-08d952aa9280 X-MS-TrafficTypeDiagnostic: DM6PR12MB2764: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NSiwTbp9f2YL5rNPwXmLG/vn84aU2q12jNENvcORds3ZWQa5m9xksG95/tUNAm/FEhILFBOyJW8Z5L6+j6Cc13UiH2cCA5XUI7tSWoKl2N0RZL/P7uNsVSvhdO3gqWC33XYsWQdZWWc8g3srqMPMhpnEe/aY9kmWk4droqwlqfb9CFKDyS0CR7Egd1bnVlWkvJQI0pzuMhbYT+qjyZNJZ/tkIUKblaFvTClUfpQ6eobFzKZ6xSgBsdXSeFaJxC8EE+mkT9M59ReH66izktZkFrNmuG2yX6rbtj9YXg9Tr6alKIE45wnp5SdUNywdHCaDlaeqk3GWduGezwtiMWw7IngbcH+nCTJy6Cu4FxJbwLJJHiRfUM5DC3CZhA7oB82YM1i1ORF1xGbnj978ypHmagpMjz2oViOH/Tx5wODSxyVeK1GvaqxOqNcjweXliBJ8e/AT+FXJe4lvq8egq7Frkl1/csKd9j1L0UpR3xg2EDI4lTKwe+OCgzspuxmM1JlowA6CGf6zxZ8eIXZkI6pHWcFbvi/sFcz++B60GYhFjzhXrIUF3Uxr21RPRphS5054+NW4hH7C1qYfV7Hr/D3au6Wz4eWNI2gnpUsywf9nCBlmgnzO3X6JFVHOrp4RI/BD3fSPc/SAd843BMBq2FgZumgZ6r701wL7zSmb18PRrtH/fJOTrYQc9P/tF6XiVwlEJolz3YYAd0C8lO8SqqEM0A== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(136003)(376002)(346002)(396003)(36840700001)(46966006)(426003)(316002)(54906003)(4326008)(6286002)(36906005)(55016002)(7696005)(8676002)(2906002)(26005)(83380400001)(36756003)(186003)(6666004)(86362001)(5660300002)(16526019)(336012)(82310400003)(7636003)(47076005)(36860700001)(478600001)(1076003)(82740400003)(70206006)(110136005)(356005)(6636002)(2616005)(8936002)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 16:04:40.3857 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e233116d-d298-4209-7720-08d952aa9280 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2764 Subject: [dpdk-dev] [PATCH] net/mlx5: fix meter profile validation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" After the support for yellow color and RFC2698 & RFC4115 were added, the profile validation adjustment was missed. With this fix, the validation is like below: 1. Legacy metering only supports RFC2697 without EBS. 2. ASO metering can support all the three profiles. 3. For backward compatibility, none EBS with RFC2697 profile is still supported and the checking is done in the meter creation stage. In the meanwhile, some checking which was done in the parameters calculation stage is moved in the validation in order to skip the useless checking. Fixes: 33a7493c8df8 ("net/mlx5: support meter for trTCM profiles") Signed-off-by: Bing Zhao Acked-by: Matan Azrad --- drivers/common/mlx5/mlx5_prm.h | 7 +- drivers/net/mlx5/mlx5_flow_meter.c | 139 ++++++++++++++++++----------- 2 files changed, 88 insertions(+), 58 deletions(-) diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h index 5b73a193ee..fdb20f5d49 100644 --- a/drivers/common/mlx5/mlx5_prm.h +++ b/drivers/common/mlx5/mlx5_prm.h @@ -3849,10 +3849,9 @@ enum { MLX5_FLOW_COLOR_UNDEFINED, }; -/* 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 +/* Maximum value of srTCM & trTCM metering parameters. */ +#define MLX5_SRTCM_XBS_MAX (0xFF * (1ULL << 0x1F)) +#define MLX5_SRTCM_XIR_MAX (8 * (1ULL << 30) * 0xFF) /* The bits meter color use. */ #define MLX5_MTR_COLOR_BITS 8 diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c index 2d91a6fcf0..0f51710907 100644 --- a/drivers/net/mlx5/mlx5_flow_meter.c +++ b/drivers/net/mlx5/mlx5_flow_meter.c @@ -130,6 +130,11 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev, { struct mlx5_priv *priv = dev->data->dev_private; struct mlx5_flow_meter_profile *fmp; + uint32_t ls_factor; + int ret; + uint64_t cir, cbs; + uint64_t eir, ebs; + uint64_t pir, pbs; /* Profile must not be NULL. */ if (profile == NULL) @@ -148,50 +153,83 @@ mlx5_flow_meter_profile_validate(struct rte_eth_dev *dev, 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.flow_meter_old) { - /* Verify support for flow meter parameters. */ - if (priv->sh->meter_aso_en && profile->packet_mode) { - if (profile->srtcm_rfc2697.cir > 0 && - (profile->srtcm_rfc2697.cir << - MLX5_MTRS_PPS_MAP_BPS_SHIFT) - <= MLX5_SRTCM_CIR_MAX && - profile->srtcm_rfc2697.cbs > 0 && - (profile->srtcm_rfc2697.cbs << - MLX5_MTRS_PPS_MAP_BPS_SHIFT) - <= MLX5_SRTCM_CBS_MAX && - (profile->srtcm_rfc2697.ebs << - MLX5_MTRS_PPS_MAP_BPS_SHIFT) - <= MLX5_SRTCM_EBS_MAX) - return 0; - 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."); - } - 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; + if (!priv->sh->meter_aso_en) { + /* Old version is even not supported. */ + if (!priv->config.hca_attr.qos.flow_meter_old) 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."); + RTE_MTR_ERROR_TYPE_METER_PROFILE, + NULL, "Metering is not supported."); + /* Old FW metering only supports srTCM. */ + if (profile->alg != RTE_MTR_SRTCM_RFC2697) { + return -rte_mtr_error_set(error, ENOTSUP, + RTE_MTR_ERROR_TYPE_METER_PROFILE, + NULL, "Metering algorithm is not supported."); + } else if (profile->srtcm_rfc2697.ebs) { + /* EBS is not supported for old metering. */ + return -rte_mtr_error_set(error, ENOTSUP, + RTE_MTR_ERROR_TYPE_METER_PROFILE, + NULL, "EBS is not supported."); } + if (profile->packet_mode) + return -rte_mtr_error_set(error, ENOTSUP, + RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL, + "Metering algorithm packet mode is not supported."); } - return -rte_mtr_error_set(error, ENOTSUP, - RTE_MTR_ERROR_TYPE_METER_PROFILE, - NULL, "Metering algorithm not supported."); + ls_factor = profile->packet_mode ? MLX5_MTRS_PPS_MAP_BPS_SHIFT : 0; + switch (profile->alg) { + case RTE_MTR_SRTCM_RFC2697: + cir = profile->srtcm_rfc2697.cir << ls_factor; + cbs = profile->srtcm_rfc2697.cbs << ls_factor; + ebs = profile->srtcm_rfc2697.ebs << ls_factor; + /* EBS could be zero for old metering. */ + if (cir > 0 && cir <= MLX5_SRTCM_XIR_MAX && + cbs > 0 && cbs <= MLX5_SRTCM_XBS_MAX && + ebs <= MLX5_SRTCM_XBS_MAX) { + ret = 0; + } else { + ret = -rte_mtr_error_set(error, ENOTSUP, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL, + "Profile values out of range."); + } + break; + case RTE_MTR_TRTCM_RFC2698: + cir = profile->trtcm_rfc2698.cir << ls_factor; + cbs = profile->trtcm_rfc2698.cbs << ls_factor; + pir = profile->trtcm_rfc2698.pir << ls_factor; + pbs = profile->trtcm_rfc2698.pbs << ls_factor; + if (cir > 0 && cir <= MLX5_SRTCM_XIR_MAX && + cbs > 0 && cbs <= MLX5_SRTCM_XBS_MAX && + pir >= cir && pir <= (MLX5_SRTCM_XIR_MAX * 2) && + pbs >= cbs && pbs <= (MLX5_SRTCM_XBS_MAX * 2)) { + ret = 0; + } else { + ret = -rte_mtr_error_set(error, ENOTSUP, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL, + "Profile values out of range."); + } + break; + case RTE_MTR_TRTCM_RFC4115: + cir = profile->trtcm_rfc4115.cir << ls_factor; + cbs = profile->trtcm_rfc4115.cbs << ls_factor; + eir = profile->trtcm_rfc4115.eir << ls_factor; + ebs = profile->trtcm_rfc4115.ebs << ls_factor; + if (cir > 0 && cir <= MLX5_SRTCM_XIR_MAX && + cbs > 0 && cbs <= MLX5_SRTCM_XBS_MAX && + eir <= MLX5_SRTCM_XIR_MAX && ebs <= MLX5_SRTCM_XBS_MAX) { + ret = 0; + } else { + ret = -rte_mtr_error_set(error, ENOTSUP, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL, + "Profile values out of range."); + } + break; + default: + ret = -rte_mtr_error_set(error, ENOTSUP, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL, + "Unknown metering algorithm."); + break; + } + return ret; } /* @@ -270,7 +308,7 @@ mlx5_flow_meter_xbs_man_exp_calc(uint64_t xbs, uint8_t *man, uint8_t *exp) */ static int mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, - struct mlx5_priv *priv, struct rte_mtr_error *error) + struct rte_mtr_error *error) { struct mlx5_flow_meter_srtcm_rfc2697_prm *srtcm = &fmp->srtcm_prm; uint8_t man, exp; @@ -278,17 +316,6 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, uint32_t eir_exp, eir_man, ebs_exp, ebs_man; uint64_t cir, cbs, eir, ebs; - if (!priv->sh->meter_aso_en) { - /* Legacy FW metering will only support srTCM. */ - if (fmp->profile.alg != RTE_MTR_SRTCM_RFC2697) - return -rte_mtr_error_set(error, ENOTSUP, - RTE_MTR_ERROR_TYPE_METER_PROFILE, - NULL, "Metering algorithm is not supported."); - if (fmp->profile.packet_mode) - return -rte_mtr_error_set(error, ENOTSUP, - RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL, - "Metering algorithm packet mode is not supported."); - } switch (fmp->profile.alg) { case RTE_MTR_SRTCM_RFC2697: cir = fmp->profile.srtcm_rfc2697.cir; @@ -469,7 +496,7 @@ mlx5_flow_meter_profile_add(struct rte_eth_dev *dev, fmp->id = meter_profile_id; fmp->profile = *profile; /* Fill the flow meter parameters for the PRM. */ - ret = mlx5_flow_meter_param_fill(fmp, priv, error); + ret = mlx5_flow_meter_param_fill(fmp, error); if (ret) goto error; data.ptr = fmp; @@ -1210,6 +1237,10 @@ mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id, aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx); fm = &aso_mtr->fm; } else { + if (fmp->y_support) + return -rte_mtr_error_set(error, ENOMEM, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL, + "Unsupported profile with yellow."); legacy_fm = mlx5_ipool_zmalloc (priv->sh->ipool[MLX5_IPOOL_MTR], &mtr_idx); if (legacy_fm == NULL) -- 2.27.0