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 C5B1CA00C3; Wed, 7 Dec 2022 03:18:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CAFDB42BC9; Wed, 7 Dec 2022 03:18:29 +0100 (CET) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2097.outbound.protection.outlook.com [40.107.92.97]) by mails.dpdk.org (Postfix) with ESMTP id 6AF1C4161A for ; Wed, 7 Dec 2022 03:18:26 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JKFDR4FU5sHG1NrPeLZUEMkOhPDp9OxD+FvjkWPqkPwwAdRyVGnMQryhGLOajCf2fFExRp0m+Sdih4kE8lgK7QRrYpGvywnORQ40ULXEgKb86kuKf+pB+up0Lp54fsI/RmInwjK4iPn1vAqjltvh2/AzUMEgAoQAFYaqaVqrXyaMgscEi4K3U6OlC+LUXc+un0kPOoTsUbxoUfyaVdFX//L2NdINbkRI2ZiBg1GXMsm0Um34D0Y/wiu5y8FyNgz7bB0bNMQBf1Ad1xWjWzB9wrSQKhB6tvBOwvLCzUnuQweJXKX4oECL7gV6aNylcKlBl0sdX+CZDsp+FXU5l+y0Wg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UEvSihUkFDf2D1u75b9ci4y50nzj7eQ6uR4Jxk1XYb0=; b=QNvD9ksYBy8xpiM5Hcgl2m3JwtkQiUbsL/bS2quoAepe+1OVkfNqe9Is6Unj8lb6DaeqFHmMx4bswXGMW+f9uTZTE95c+LgNlxZCPccA9B4xABohd86LBY3VaTeK7ecgP5jv0QBOOwK8NTtEJImVT2qxAumI/4P/CqrFn21Gua+SUBqe30N7EQQ1UMh1Nh31UOuQJJBA73s+JikWt7rx1XA8xvtbx8l7qYhLrhUsX7ersEc6TgQDmDVMXb3Me5nbMDpKqaRAPFmZxBD4uPkXYdrrJBn1ZBLe4kvul3nEleQ6do8sBJfiIFgKzIL4FRVEufoPVuw3xV8aD/G6/O3SyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UEvSihUkFDf2D1u75b9ci4y50nzj7eQ6uR4Jxk1XYb0=; b=WBlBCIimndh89ASCIu4N08rOAdFSWnRCYxDbVNZM0QOG2mGsjtwIM6r3/JubRoEGdc7X/IfzRjKsQgj0WqYqt4WFfnz8Gi98fxagYPihmnY0UTkWbt5coIuvlr1kqgJzEnJzoxHDtoJDYjLcR7edjx2yh2rDcws4Z3hhND+lfXk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by DM6PR13MB3785.namprd13.prod.outlook.com (2603:10b6:5:244::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 02:18:24 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::5122:8c31:51f3:4ee7]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::5122:8c31:51f3:4ee7%4]) with mapi id 15.20.5880.014; Wed, 7 Dec 2022 02:18:24 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com, Jin Liu , Peng Zhang , Chaoyong He Subject: [PATCH 4/6] net/nfp: add meter options Date: Wed, 7 Dec 2022 10:17:46 +0800 Message-Id: <20221207021748.40143-5-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20221207021748.40143-1-chaoyong.he@corigine.com> References: <20221207021748.40143-1-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: LO6P265CA0021.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2ff::14) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|DM6PR13MB3785:EE_ X-MS-Office365-Filtering-Correlation-Id: af746cb4-bfac-4446-f69c-08dad7f95193 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ojopnGii9hy9MR4VYJgZETzkxGYeclEt14Zh+jW6CWmo3E2RiTQbYi+lUOqqBRgC7DgYQh1KOh7AZA9Bx6WreU4Lny86lcruwAaWXYoXRa97MnIg4EbJXXDMmc3YXBZeasfcvJBPNJTdSb45FaDcmisQ84+kwUpiYY5Gulm47ADWXKlgQnD75FsvbIBLZdUOhFknjZdnqZ+H1+7w8KrqGvOhN8DdEcGvSi4CH/tS4U+5nWcDw1j7j79XJT4tP667yTr+xx8iXReqm4agVD5YFSWOPHJqawpGfJPDWvQGkvoxjf93N+KnDYLwF1h5Yf25Ihdv0eOWxrT5xeQtBef2ksOHSwIJ88bDl4L/94g4kDANEphUZznwMUK/xD1XAu5Q7VxBKttMO0Ey8Z67FOZSoShmGuNQtXAd1ijOmy9Vx8OHhqtiGvMHb7ekcMnJ4Nmg6ctJrNhJtmJ+GUPJmz6FAOEa/iPXQkRXVUy2819fVhG7wnF924MwBq/0sGxAHxwGUhvz15KG+eLtC4RK+F7km9vlyWWqQHE6xMMevkid22KzORBlGf+K4O2oZ8Nw0p2xm8HCMA2PJz0Alb6FpKdJzBdr6pqweTz093Sr0F/VEiOJNrAWlFMMecuw+Sew7G6Sttf8KlvR4jUJSHDObnOhzulMtkmXHMJhg3cIuY5JewSk+RmKpEsAPQoZkqpg8n4bM1c1tSjq8fMSG8uyCbjYDw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39830400003)(396003)(376002)(136003)(366004)(346002)(451199015)(66574015)(6486002)(478600001)(52116002)(6506007)(36756003)(86362001)(2616005)(26005)(83380400001)(186003)(1076003)(38100700002)(5660300002)(30864003)(41300700001)(8676002)(38350700002)(6512007)(107886003)(8936002)(6666004)(44832011)(66946007)(66556008)(4326008)(316002)(54906003)(66476007)(6916009)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Mm95My9pNzRwbW9yeUF5ZFhUeGMzWklYam1OK2w2VU1Ca0J6VnM1U3cvRWM1?= =?utf-8?B?aUVnSHFuMG80QnRJckVIWkZuTFRYNVFtbUZkM0szMmtnTVBvSm1ZN0ZlUkpr?= =?utf-8?B?dFJXeXNhWU05YVhtQUNZOUI5YS94b2Q0SHZlMElYcWdsMFR2QlhJZUh2U3BE?= =?utf-8?B?b240aFJ1b20yWGhNUUltNlN4SXpMTnJCbVBDd3M2Vkc3eUpBdDhMM1hZY3NI?= =?utf-8?B?RlR4djVOVHRCMU1nQ3JOR3V6cStlallOZkFmRzdVUU1CQ2JUeWtDbEo0M2Zr?= =?utf-8?B?S29TUWU5UjVqTlBybGg4cHU1UXZ0VTFrNEtGc2dUMjIz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WWZ1YmFCMHllTjZFVnpwclhFRkVSOGlWTlo3aG5uYkMycStVMWhR?= =?utf-8?B?aWc9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: af746cb4-bfac-4446-f69c-08dad7f95193 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 02:18:24.7138 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WV/c3+k72TxT1ud/aHA+rXgOSwyR5vp3/2X1nlC3O2QI59oWap8eL00YQ74PAJc9fGH7xqXBc07syHaRliyUnsDT5WaI1uXzIWrSeDBeE2o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR13MB3785 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 From: Jin Liu Add function of meter options, a meter include a profile and a policy. Meter options include add a new meter object and destroy a exist meter object, enable meter object and disable meter object, update profile that been used by meter object to another. Signed-off-by: Jin Liu Signed-off-by: Peng Zhang Reviewed-by: Chaoyong He Reviewed-by: Niklas Söderlund --- drivers/net/nfp/nfp_mtr.c | 357 ++++++++++++++++++++++++++++++++++++++ drivers/net/nfp/nfp_mtr.h | 24 +++ 2 files changed, 381 insertions(+) diff --git a/drivers/net/nfp/nfp_mtr.c b/drivers/net/nfp/nfp_mtr.c index c8caf97262..1df7103417 100644 --- a/drivers/net/nfp/nfp_mtr.c +++ b/drivers/net/nfp/nfp_mtr.c @@ -541,12 +541,362 @@ nfp_mtr_policy_delete(struct rte_eth_dev *dev, return 0; } +struct nfp_mtr * +nfp_mtr_find_by_mtr_id(struct nfp_mtr_priv *priv, uint32_t mtr_id) +{ + struct nfp_mtr *mtr; + + LIST_FOREACH(mtr, &priv->mtrs, next) + if (mtr->mtr_id == mtr_id) + break; + + return mtr; +} + +static int +nfp_mtr_validate(uint32_t meter_id, + struct rte_mtr_params *params, + struct rte_mtr_error *error) +{ + /* Params must not be NULL */ + if (params == NULL) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, + NULL, "Meter params is null."); + } + + /* Meter policy ID must be valid. */ + if (meter_id >= NFP_MAX_MTR_CNT) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Meter id not valid."); + } + + if (params->use_prev_mtr_color != 0) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, + NULL, "Feature use_prev_mtr_color not support"); + } + + return 0; +} + +static void +nfp_mtr_config(uint32_t mtr_id, + int shared, + struct rte_mtr_params *params, + struct nfp_mtr_profile *mtr_profile, + struct nfp_mtr_policy *mtr_policy, + struct nfp_mtr *mtr) +{ + mtr->mtr_id = mtr_id; + + if (shared != 0) + mtr->shared = true; + + if (params->meter_enable != 0) + mtr->enable = true; + + mtr->mtr_profile = mtr_profile; + mtr->mtr_policy = mtr_policy; +} + +/** + * Create meter rules. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[in] mtr_id + * Meter id. + * @param[in] params + * Pointer to rte meter parameters. + * @param[in] shared + * Meter shared with other flow or not. + * @param[out] error + * Pointer to rte meter error structure. + * + * @return + * 0 on success, a negative value otherwise and rte_errno is set. + */ +static int +nfp_mtr_create(struct rte_eth_dev *dev, + uint32_t mtr_id, + struct rte_mtr_params *params, + int shared, + struct rte_mtr_error *error) +{ + int ret; + struct nfp_mtr *mtr; + struct nfp_mtr_priv *priv; + struct nfp_mtr_policy *mtr_policy; + struct nfp_mtr_profile *mtr_profile; + struct nfp_flower_representor *representor; + + representor = dev->data->dev_private; + priv = representor->app_fw_flower->mtr_priv; + + /* Check if meter id exist */ + mtr = nfp_mtr_find_by_mtr_id(priv, mtr_id); + if (mtr != NULL) { + return -rte_mtr_error_set(error, EEXIST, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Meter already exist"); + } + + /* Check input meter params */ + ret = nfp_mtr_validate(mtr_id, params, error); + if (ret != 0) + return ret; + + mtr_profile = nfp_mtr_profile_search(priv, params->meter_profile_id); + if (mtr_profile == NULL) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, "Request meter profile not exist"); + } + + if (mtr_profile->in_use) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, "Request meter profile is been used"); + } + + mtr_policy = nfp_mtr_policy_search(priv, params->meter_policy_id); + if (mtr_policy == NULL) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_METER_POLICY_ID, + NULL, "Request meter policy not exist"); + } + + /* Meter param memory alloc */ + mtr = rte_zmalloc(NULL, sizeof(struct nfp_mtr), 0); + if (mtr == NULL) { + return -rte_mtr_error_set(error, ENOMEM, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, "Meter param alloc failed"); + } + + nfp_mtr_config(mtr_id, shared, params, mtr_profile, mtr_policy, mtr); + + /* Update profile/policy status */ + mtr->mtr_policy->ref_cnt++; + mtr->mtr_profile->in_use = true; + + /* Insert mtr into mtr list */ + LIST_INSERT_HEAD(&priv->mtrs, mtr, next); + + return 0; +} + +/** + * Destroy meter rules. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[in] mtr_id + * Meter id. + * @param[out] error + * Pointer to rte meter error structure. + * + * @return + * 0 on success, a negative value otherwise and rte_errno is set. + */ +static int +nfp_mtr_destroy(struct rte_eth_dev *dev, + uint32_t mtr_id, + struct rte_mtr_error *error) +{ + struct nfp_mtr *mtr; + struct nfp_mtr_priv *priv; + struct nfp_flower_representor *representor; + + representor = dev->data->dev_private; + priv = representor->app_fw_flower->mtr_priv; + + /* Check if meter id exist */ + mtr = nfp_mtr_find_by_mtr_id(priv, mtr_id); + if (mtr == NULL) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Request meter not exist"); + } + + if (mtr->ref_cnt > 0) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Meter object is being used"); + } + + /* Update profile/policy status */ + mtr->mtr_policy->ref_cnt--; + mtr->mtr_profile->in_use = false; + + /* Remove mtr from mtr list */ + LIST_REMOVE(mtr, next); + rte_free(mtr); + + return 0; +} + +/** + * Enable meter object. + * + * @param[in] dev + * Pointer to the device. + * @param[in] mtr_id + * Id of the meter. + * @param[out] error + * Pointer to the error. + * + * @returns + * 0 in success, negative value otherwise and rte_errno is set.. + */ +static int +nfp_mtr_enable(struct rte_eth_dev *dev, + uint32_t mtr_id, + struct rte_mtr_error *error) +{ + struct nfp_mtr *mtr; + struct nfp_mtr_priv *priv; + struct nfp_flower_representor *representor; + + representor = dev->data->dev_private; + priv = representor->app_fw_flower->mtr_priv; + + /* Check if meter id exist */ + mtr = nfp_mtr_find_by_mtr_id(priv, mtr_id); + if (mtr == NULL) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Request meter not exist"); + } + + mtr->enable = true; + + return 0; +} + +/** + * Disable meter object. + * + * @param[in] dev + * Pointer to the device. + * @param[in] mtr_id + * Id of the meter. + * @param[out] error + * Pointer to the error. + * + * @returns + * 0 on success, negative value otherwise and rte_errno is set.. + */ +static int +nfp_mtr_disable(struct rte_eth_dev *dev, + uint32_t mtr_id, + struct rte_mtr_error *error) +{ + struct nfp_mtr *mtr; + struct nfp_mtr_priv *priv; + struct nfp_flower_representor *representor; + + representor = dev->data->dev_private; + priv = representor->app_fw_flower->mtr_priv; + + /* Check if meter id exist */ + mtr = nfp_mtr_find_by_mtr_id(priv, mtr_id); + if (mtr == NULL) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Request meter not exist"); + } + + if (mtr->ref_cnt > 0) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Can't disable a used meter"); + } + + mtr->enable = false; + + return 0; +} + +/** + * Callback to update meter profile. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[in] mtr_id + * Meter id. + * @param[in] mtr_profile_id + * To be updated meter profile id. + * @param[out] error + * Pointer to rte meter error structure. + * + * @return + * 0 on success, a negative value otherwise and rte_errno is set. + */ +static int +nfp_mtr_profile_update(struct rte_eth_dev *dev, + uint32_t mtr_id, + uint32_t mtr_profile_id, + struct rte_mtr_error *error) +{ + struct nfp_mtr *mtr; + struct nfp_mtr_priv *priv; + struct nfp_mtr_profile *mtr_profile; + struct nfp_flower_representor *representor; + + representor = dev->data->dev_private; + priv = representor->app_fw_flower->mtr_priv; + + /* Check if meter id exist */ + mtr = nfp_mtr_find_by_mtr_id(priv, mtr_id); + if (mtr == NULL) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Request meter not exist"); + } + + if (mtr->ref_cnt > 0) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Request meter is been used"); + } + + if (mtr->mtr_profile->profile_id == mtr_profile_id) + return 0; + + mtr_profile = nfp_mtr_profile_search(priv, mtr_profile_id); + if (mtr_profile == NULL) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, "Request meter profile not exist"); + } + + if (mtr_profile->in_use) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, "Request meter profile is been used"); + } + + mtr_profile->in_use = true; + mtr->mtr_profile->in_use = false; + mtr->mtr_profile = mtr_profile; + + return 0; +} + static const struct rte_mtr_ops nfp_mtr_ops = { .capabilities_get = nfp_mtr_cap_get, .meter_profile_add = nfp_mtr_profile_add, .meter_profile_delete = nfp_mtr_profile_delete, .meter_policy_add = nfp_mtr_policy_add, .meter_policy_delete = nfp_mtr_policy_delete, + .create = nfp_mtr_create, + .destroy = nfp_mtr_destroy, + .meter_enable = nfp_mtr_enable, + .meter_disable = nfp_mtr_disable, + .meter_profile_update = nfp_mtr_profile_update, }; int @@ -577,6 +927,7 @@ nfp_mtr_priv_init(struct nfp_pf_dev *pf_dev) app_fw_flower = NFP_PRIV_TO_APP_FW_FLOWER(pf_dev->app_fw_priv); app_fw_flower->mtr_priv = priv; + LIST_INIT(&priv->mtrs); LIST_INIT(&priv->profiles); LIST_INIT(&priv->policies); @@ -586,6 +937,7 @@ nfp_mtr_priv_init(struct nfp_pf_dev *pf_dev) void nfp_mtr_priv_uninit(struct nfp_pf_dev *pf_dev) { + struct nfp_mtr *mtr; struct nfp_mtr_priv *priv; struct nfp_mtr_policy *mtr_policy; struct nfp_mtr_profile *mtr_profile; @@ -594,6 +946,11 @@ nfp_mtr_priv_uninit(struct nfp_pf_dev *pf_dev) app_fw_flower = NFP_PRIV_TO_APP_FW_FLOWER(pf_dev->app_fw_priv); priv = app_fw_flower->mtr_priv; + LIST_FOREACH(mtr, &priv->mtrs, next) { + LIST_REMOVE(mtr, next); + rte_free(mtr); + } + LIST_FOREACH(mtr_profile, &priv->profiles, next) { LIST_REMOVE(mtr_profile, next); rte_free(mtr_profile); diff --git a/drivers/net/nfp/nfp_mtr.h b/drivers/net/nfp/nfp_mtr.h index 4fea0cf926..1f74e39e17 100644 --- a/drivers/net/nfp/nfp_mtr.h +++ b/drivers/net/nfp/nfp_mtr.h @@ -95,18 +95,42 @@ struct nfp_mtr_policy { struct rte_mtr_meter_policy_params policy; }; +/** + * Struct nfp_mtr - meter object information + * @next: next meter object + * @mtr_id: meter id + * @ref_cnt: reference count by flow + * @shared: if meter can be used by multiple flows + * @enable: if meter is enable to use + * @mtr_profile: the pointer of profile + * @mtr_policy: the pointer of policy + */ +struct nfp_mtr { + LIST_ENTRY(nfp_mtr) next; + uint32_t mtr_id; + uint32_t ref_cnt; + bool shared; + bool enable; + struct nfp_mtr_profile *mtr_profile; + struct nfp_mtr_policy *mtr_policy; +}; + /** * Struct nfp_mtr_priv - meter private data * @profiles: the head node of profile list * @policies: the head node of policy list + * @mtrs: the head node of mtrs list */ struct nfp_mtr_priv { LIST_HEAD(, nfp_mtr_profile) profiles; LIST_HEAD(, nfp_mtr_policy) policies; + LIST_HEAD(, nfp_mtr) mtrs; }; int nfp_net_mtr_ops_get(struct rte_eth_dev *dev, void *arg); int nfp_mtr_priv_init(struct nfp_pf_dev *pf_dev); void nfp_mtr_priv_uninit(struct nfp_pf_dev *pf_dev); +struct nfp_mtr *nfp_mtr_find_by_mtr_id(struct nfp_mtr_priv *priv, + uint32_t mtr_id); #endif /* __NFP_MTR_H__ */ -- 2.29.3