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 A3CDEA00C3; Wed, 7 Dec 2022 03:18:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0464A42D38; Wed, 7 Dec 2022 03:18:32 +0100 (CET) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2132.outbound.protection.outlook.com [40.107.92.132]) by mails.dpdk.org (Postfix) with ESMTP id 6BF6C42D38 for ; Wed, 7 Dec 2022 03:18:30 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=llbBsfBpiftX0SxnMhMNFIz2GoYx3c5Xy3fQgw1MEXYpCD7K5khUioIH8HuKX8n0LxTdlvRwxn0jeahjCa3VsEtfpab4DQoNsvT6+wWRlYHci2dY68JUamu+z+44aZ3tMPrReXccNN2vptLj6qPOnZNwIC3p76QRhJoZKyn1Q+Mkc3P5ghyGT9hTkc1Huu6sX7Bvg837YB6DuuTKWNYbP8jpF4bNQrK/A5Zd05+fIwXZ3uQsiawGpUBx6ne0ViI2rLsafG0Fs9idxDN9Tny2sDiDexNUJqW3lu0wbHulR7HeBhBwwhmk5MX1sHUbDoLnRdQFhIIq+BSZwkUDD9HcQA== 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=BrBrUEd+JA0mmr2DCgZidW/CGDz8ycU0eQfCvgWrO1k=; b=GX/0C+e9tXy2i9BRIkYml4laHCGlmBC/m7szDL5fz9Ttq+TX/rlcbo34cmWmmZS5MyE64LBPgPpn3cQyAnNJq7HeItWLboDNWcF90dxU5lPv93iDlQZyAEGs6W1NafDysuIiH8wSYnKMsjiPstE0LEzU30NwzWuBaaVby0Cf9yLvxShPxdOWLqcsM+7WLxnSU6jTbuONDFVUq8TcNpUOYNoHw3EmHzyDBIXJ77WkyKm7rdMfqfbkBKqnlftYy2y4sMgHgYLxus/t3lDwrRFuOoBnWrHeQEymmxkMo3DtcfM2+pjgd1fxQuCa4/+BGIwJgHFfjfzpeXk3qwSPkoCJ6A== 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=BrBrUEd+JA0mmr2DCgZidW/CGDz8ycU0eQfCvgWrO1k=; b=VbvEE/w1LYs6Q7B/UZA1L9Qpr8jNTMwqlVBzVx4AT4etTVkglV1693bTYsA7urtDWamLhux/tv4FnFZMFntkssy2/yLtH95HKjHlC/afYHNVVnBprQgbw9UwAoZAO5KQJ4qMUcvgObGhP41560CWsZjBZT5RcEh1gb3r8+s0pQ4= 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:28 +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:28 +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 5/6] net/nfp: add meter stats options Date: Wed, 7 Dec 2022 10:17:47 +0800 Message-Id: <20221207021748.40143-6-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: 40dc8583-248c-459f-98bf-08dad7f953d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sNXM7Lee/BSyIJlrENMXs5/0zQAIL1e/opa5AQMudMznZUEcGYHI5X0rKqYruDPhPpEjD7kchUirvZqpevKiBYHHFVdU30vok4q29/LHsM7Ywa+DCQ92MMZeBsalbvAOx5at4KITY1bEpj4wzYimUsEq9QPUSmMFAuJYgjZpLFvbUpWFhr7MiXFWewbh16eyMLCQxjLR5DcJQIaW8nAzwgi3uD6O7BFCYQrj0qvMSd8zt6x0dAMQNchg+B39Z+0OkrVifjUCjdvbGsaCRLgZeEy7zcz229W0zV5uv+Yg61w57Y/8x08uCkefnN662JHhJK2jOrT1UeoM+vE3oASHQiN67+SvdgcE+o0f4dqk/g/pNwmRK2YtnA1bmvBmZRdfm2ni8rLoF9N0ap9Kb05WU0ZoNRWa7KZIaXfuuDTzmDHHuCvWK+bCF1CKmGVV7PeYGZCXsDT6r3sCWJEyCZhwA3hSSKBvHwMx2D0DQXRnlG9d7f+YqatjOlgES8VVLN/82fXumUB17/toiIpH2EphJZnX4ok/P6Vu0rcvAmp9xz0KS9B1fIIqTKQ40fuaS/YXdsluWcaegz+mtC76ZckkktWYI6OA+n95JTDA0PNnVsJQRI5p14Pt6859GDp3KHrA4VTSbPZ4TnO92rwbP93oOGXYhxNUjFmCv5pQ7MKsS3l8TsbDVarWZPBCRMOiDH8lQO2AViSK3d+5EJsAFo50EA== 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)(66899015)(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?Q2dreFJRakZNKy9UTnNZNUhQZ0swT2JZVWdIdlBFdUYwOFFWdlhXMWNxM0Jz?= =?utf-8?B?RDdDWGgyTXl6UUxqZFE0N2JEaGVUelA3K1IwZFJuWHA3Tnh1UE5leG9kY1Nw?= =?utf-8?B?WmpleGxNOTcvWlhnTW16eSs4QWVLVDg0TGMzdWZScjI4TWVGVTZWVHRjcjNw?= =?utf-8?B?eVQra1hqU3dBK0FMYkpuRURWVU9rQlV6U2N5eEZQamZESGlKOEczd1pFOTBT?= =?utf-8?B?b3JpQ1RraUhhL0Evb2g1NXdJTmMySjRmSWtaZ1ZEaUhYRnZLaTRtSG44dHdP?= =?utf-8?B?emZUYkM3OTRhdHdyK0lmWUswd2haQTMrRCtkbW1najBwNjk2YTU0Uz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c5d3R3NUc5VzRtM1Q1S0VkNi9odWFXbXoySnovVmYvT2lHN2NFTjVI?= =?utf-8?B?eFE9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40dc8583-248c-459f-98bf-08dad7f953d7 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:28.5137 (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: QAsiZhRtYxettKHN9Mm6JFKI40b0t3EKgNEzjSc3a8jpvZF3+8bKaU8lHQyAOdJuCam+fpqEgHPBgfXCoIDxglaITRKgOxrMv1AzQcae8XM= 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 support for meter stats mask feature, it indicate what type meter stats that NFP card support. Add function of update meter stats mask, it will change the stats mask used by the meter to another. Add function of read meter stats, get the meter stats that stored in driver. Signed-off-by: Jin Liu Signed-off-by: Peng Zhang Reviewed-by: Chaoyong He Reviewed-by: Niklas Söderlund --- doc/guides/rel_notes/release_23_03.rst | 3 + drivers/net/nfp/flower/nfp_flower_cmsg.c | 29 ++++ drivers/net/nfp/flower/nfp_flower_cmsg.h | 2 + drivers/net/nfp/flower/nfp_flower_ctrl.c | 57 +++++++- drivers/net/nfp/nfp_mtr.c | 164 ++++++++++++++++++++++- drivers/net/nfp/nfp_mtr.h | 44 ++++++ 6 files changed, 296 insertions(+), 3 deletions(-) diff --git a/doc/guides/rel_notes/release_23_03.rst b/doc/guides/rel_notes/release_23_03.rst index b8c5b68d6c..0ce6fbf8ee 100644 --- a/doc/guides/rel_notes/release_23_03.rst +++ b/doc/guides/rel_notes/release_23_03.rst @@ -55,6 +55,9 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Updated Corigine nfp driver.** + + * Added support for meter options. Removed Items ------------- diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.c b/drivers/net/nfp/flower/nfp_flower_cmsg.c index eaddd6c52c..430dd9c316 100644 --- a/drivers/net/nfp/flower/nfp_flower_cmsg.c +++ b/drivers/net/nfp/flower/nfp_flower_cmsg.c @@ -525,3 +525,32 @@ nfp_flower_cmsg_qos_delete(struct nfp_app_fw_flower *app_fw_flower, return 0; } + +int +nfp_flower_cmsg_qos_stats(struct nfp_app_fw_flower *app_fw_flower, + struct nfp_cfg_head *head) +{ + char *msg; + uint16_t cnt; + uint32_t len; + struct rte_mbuf *mbuf; + + mbuf = rte_pktmbuf_alloc(app_fw_flower->ctrl_pktmbuf_pool); + if (mbuf == NULL) { + PMD_DRV_LOG(DEBUG, "Failed to alloc mbuf for qos stats"); + return -ENOMEM; + } + + len = sizeof(struct nfp_cfg_head); + msg = nfp_flower_cmsg_init(mbuf, NFP_FLOWER_CMSG_TYPE_QOS_STATS, len); + rte_memcpy(msg, head, len); + + cnt = nfp_flower_ctrl_vnic_xmit(app_fw_flower, mbuf); + if (cnt == 0) { + PMD_DRV_LOG(ERR, "Send cmsg through ctrl vnic failed."); + rte_pktmbuf_free(mbuf); + return -EIO; + } + + return 0; +} diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.h b/drivers/net/nfp/flower/nfp_flower_cmsg.h index 1894c454d3..2f4cd68730 100644 --- a/drivers/net/nfp/flower/nfp_flower_cmsg.h +++ b/drivers/net/nfp/flower/nfp_flower_cmsg.h @@ -928,5 +928,7 @@ int nfp_flower_cmsg_qos_add(struct nfp_app_fw_flower *app_fw_flower, struct nfp_profile_conf *conf); int nfp_flower_cmsg_qos_delete(struct nfp_app_fw_flower *app_fw_flower, struct nfp_profile_conf *conf); +int nfp_flower_cmsg_qos_stats(struct nfp_app_fw_flower *app_fw_flower, + struct nfp_cfg_head *head); #endif /* _NFP_CMSG_H_ */ diff --git a/drivers/net/nfp/flower/nfp_flower_ctrl.c b/drivers/net/nfp/flower/nfp_flower_ctrl.c index c545007d0c..03a2e2e622 100644 --- a/drivers/net/nfp/flower/nfp_flower_ctrl.c +++ b/drivers/net/nfp/flower/nfp_flower_ctrl.c @@ -249,7 +249,32 @@ nfp_flower_cmsg_rx_stats(struct nfp_flow_priv *flow_priv, } static void -nfp_flower_cmsg_rx(struct nfp_flow_priv *flow_priv, +nfp_flower_cmsg_rx_qos_stats(struct nfp_mtr_priv *mtr_priv, + struct rte_mbuf *mbuf) +{ + char *msg; + uint32_t profile_id; + struct nfp_mtr *mtr; + struct nfp_mtr_stats_reply *mtr_stats; + + msg = rte_pktmbuf_mtod(mbuf, char *) + NFP_FLOWER_CMSG_HLEN; + + mtr_stats = (struct nfp_mtr_stats_reply *)msg; + profile_id = rte_be_to_cpu_32(mtr_stats->head.profile_id); + mtr = nfp_mtr_find_by_profile_id(mtr_priv, profile_id); + if (mtr == NULL) + return; + + rte_spinlock_lock(&mtr_priv->mtr_stats_lock); + mtr->mtr_stats.curr.pass_bytes = rte_be_to_cpu_64(mtr_stats->pass_bytes); + mtr->mtr_stats.curr.pass_pkts = rte_be_to_cpu_64(mtr_stats->pass_pkts); + mtr->mtr_stats.curr.drop_bytes = rte_be_to_cpu_64(mtr_stats->drop_bytes); + mtr->mtr_stats.curr.drop_pkts = rte_be_to_cpu_64(mtr_stats->drop_pkts); + rte_spinlock_unlock(&mtr_priv->mtr_stats_lock); +} + +static void +nfp_flower_cmsg_rx(struct nfp_app_fw_flower *app_fw_flower, struct rte_mbuf **pkts_burst, uint16_t count) { @@ -257,8 +282,13 @@ nfp_flower_cmsg_rx(struct nfp_flow_priv *flow_priv, char *meta; uint32_t meta_type; uint32_t meta_info; + struct nfp_mtr_priv *mtr_priv; + struct nfp_flow_priv *flow_priv; struct nfp_flower_cmsg_hdr *cmsg_hdr; + mtr_priv = app_fw_flower->mtr_priv; + flow_priv = app_fw_flower->flow_priv; + for (i = 0; i < count; i++) { meta = rte_pktmbuf_mtod(pkts_burst[i], char *); @@ -282,21 +312,38 @@ nfp_flower_cmsg_rx(struct nfp_flow_priv *flow_priv, if (cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_FLOW_STATS) { /* We need to deal with stats updates from HW asap */ nfp_flower_cmsg_rx_stats(flow_priv, pkts_burst[i]); + } else if (cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_QOS_STATS) { + /* Handle meter stats */ + nfp_flower_cmsg_rx_qos_stats(mtr_priv, pkts_burst[i]); } rte_pktmbuf_free(pkts_burst[i]); } } +static void +nfp_mtr_stats_request(struct nfp_app_fw_flower *app_fw_flower) +{ + struct nfp_mtr *mtr; + + LIST_FOREACH(mtr, &app_fw_flower->mtr_priv->mtrs, next) + (void)nfp_flower_cmsg_qos_stats(app_fw_flower, &mtr->mtr_profile->conf.head); +} + void nfp_flower_ctrl_vnic_poll(struct nfp_app_fw_flower *app_fw_flower) { uint16_t count; + uint64_t cur_tsc; + uint64_t drain_tsc; + uint64_t pre_tsc = 0; struct nfp_net_rxq *rxq; struct nfp_net_hw *ctrl_hw; struct rte_eth_dev *ctrl_eth_dev; struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; + drain_tsc = app_fw_flower->mtr_priv->drain_tsc; + ctrl_hw = app_fw_flower->ctrl_hw; ctrl_eth_dev = ctrl_hw->eth_dev; @@ -308,7 +355,13 @@ nfp_flower_ctrl_vnic_poll(struct nfp_app_fw_flower *app_fw_flower) if (count != 0) { app_fw_flower->ctrl_vnic_rx_count += count; /* Process cmsgs here */ - nfp_flower_cmsg_rx(app_fw_flower->flow_priv, pkts_burst, count); + nfp_flower_cmsg_rx(app_fw_flower, pkts_burst, count); + } + + cur_tsc = rte_rdtsc(); + if (unlikely(cur_tsc - pre_tsc > drain_tsc)) { + nfp_mtr_stats_request(app_fw_flower); + pre_tsc = cur_tsc; } } } diff --git a/drivers/net/nfp/nfp_mtr.c b/drivers/net/nfp/nfp_mtr.c index 1df7103417..f77381dcb3 100644 --- a/drivers/net/nfp/nfp_mtr.c +++ b/drivers/net/nfp/nfp_mtr.c @@ -553,6 +553,48 @@ nfp_mtr_find_by_mtr_id(struct nfp_mtr_priv *priv, uint32_t mtr_id) return mtr; } +struct nfp_mtr * +nfp_mtr_find_by_profile_id(struct nfp_mtr_priv *priv, uint32_t profile_id) +{ + struct nfp_mtr *mtr; + + LIST_FOREACH(mtr, &priv->mtrs, next) + if (mtr->mtr_profile->profile_id == profile_id) + break; + + return mtr; +} + +static int +nfp_mtr_stats_mask_validate(uint64_t stats_mask, struct rte_mtr_error *error) +{ + if ((stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW) != 0) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, + NULL, "RTE_MTR_STATS_N_PKTS_YELLOW not support"); + } + + if ((stats_mask & RTE_MTR_STATS_N_PKTS_RED) != 0) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, + NULL, "RTE_MTR_STATS_N_PKTS_RED not support"); + } + + if ((stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW) != 0) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, + NULL, "RTE_MTR_STATS_N_BYTES_YELLOW not support"); + } + + if ((stats_mask & RTE_MTR_STATS_N_BYTES_RED) != 0) { + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, + NULL, "RTE_MTR_STATS_N_BYTES_RED not support"); + } + + return 0; +} + static int nfp_mtr_validate(uint32_t meter_id, struct rte_mtr_params *params, @@ -578,7 +620,7 @@ nfp_mtr_validate(uint32_t meter_id, NULL, "Feature use_prev_mtr_color not support"); } - return 0; + return nfp_mtr_stats_mask_validate(params->stats_mask, error); } static void @@ -599,6 +641,7 @@ nfp_mtr_config(uint32_t mtr_id, mtr->mtr_profile = mtr_profile; mtr->mtr_policy = mtr_policy; + mtr->stats_mask = params->stats_mask; } /** @@ -886,6 +929,119 @@ nfp_mtr_profile_update(struct rte_eth_dev *dev, return 0; } +/** + * Callback to update meter stats mask. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[in] mtr_id + * Meter id. + * @param[in] stats_mask + * To be updated stats_mask. + * @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_stats_update(struct rte_eth_dev *dev, + uint32_t mtr_id, + uint64_t stats_mask, + struct rte_mtr_error *error) +{ + int ret; + 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, EEXIST, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, "Request meter id not exist"); + } + + ret = nfp_mtr_stats_mask_validate(stats_mask, error); + if (ret != 0) + return ret; + + mtr->stats_mask = stats_mask; + + return 0; +} + +/** + * Callback to read meter statistics. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[in] mtr_id + * Meter id. + * @param[out] stats + * Pointer to store the statistics. + * @param[out] stats_mask + * Pointer to store the stats_mask. + * @param[in] clear + * Statistic to be cleared after read 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_stats_read(struct rte_eth_dev *dev, + uint32_t mtr_id, + struct rte_mtr_stats *stats, + uint64_t *stats_mask, + int clear, + struct rte_mtr_error *error) +{ + struct nfp_mtr *mtr; + struct nfp_mtr_priv *priv; + struct nfp_mtr_stats curr; + struct nfp_mtr_stats *prev; + 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"); + } + + *stats_mask = mtr->stats_mask; + + rte_spinlock_lock(&priv->mtr_stats_lock); + rte_memcpy(&curr, &mtr->mtr_stats.curr, sizeof(curr)); + rte_spinlock_unlock(&priv->mtr_stats_lock); + + prev = &mtr->mtr_stats.prev; + + stats->n_pkts[RTE_COLOR_GREEN] = curr.pass_pkts - prev->pass_pkts; + stats->n_bytes[RTE_COLOR_GREEN] = curr.pass_bytes - prev->pass_bytes; + stats->n_pkts_dropped = curr.drop_pkts - prev->drop_pkts; + stats->n_bytes_dropped = curr.drop_bytes - prev->drop_bytes; + + if (clear != 0) { + prev->pass_pkts = curr.pass_pkts; + prev->pass_bytes = curr.pass_bytes; + prev->drop_pkts = curr.drop_pkts; + prev->drop_bytes = curr.drop_bytes; + } + + return 0; +} + static const struct rte_mtr_ops nfp_mtr_ops = { .capabilities_get = nfp_mtr_cap_get, .meter_profile_add = nfp_mtr_profile_add, @@ -897,6 +1053,8 @@ static const struct rte_mtr_ops nfp_mtr_ops = { .meter_enable = nfp_mtr_enable, .meter_disable = nfp_mtr_disable, .meter_profile_update = nfp_mtr_profile_update, + .stats_update = nfp_mtr_stats_update, + .stats_read = nfp_mtr_stats_read, }; int @@ -927,10 +1085,14 @@ 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; + priv->drain_tsc = rte_get_tsc_hz(); + LIST_INIT(&priv->mtrs); LIST_INIT(&priv->profiles); LIST_INIT(&priv->policies); + rte_spinlock_init(&priv->mtr_stats_lock); + return 0; } diff --git a/drivers/net/nfp/nfp_mtr.h b/drivers/net/nfp/nfp_mtr.h index 1f74e39e17..7bfc935e7d 100644 --- a/drivers/net/nfp/nfp_mtr.h +++ b/drivers/net/nfp/nfp_mtr.h @@ -66,6 +66,22 @@ struct nfp_profile_conf { rte_be32_t cir; }; +/** + * Struct nfp_mtr_stats_reply - meter stats, read from firmware + * @head: config head information + * @pass_bytes: count of passed bytes + * @pass_pkts: count of passed packets + * @drop_bytes: count of dropped bytes + * @drop_pkts: count of dropped packets + */ +struct nfp_mtr_stats_reply { + struct nfp_cfg_head head; + rte_be64_t pass_bytes; + rte_be64_t pass_pkts; + rte_be64_t drop_bytes; + rte_be64_t drop_pkts; +}; + /** * Struct nfp_mtr_profile - meter profile, stored in driver * Can only be used by one meter @@ -95,6 +111,20 @@ struct nfp_mtr_policy { struct rte_mtr_meter_policy_params policy; }; +/** + * Struct nfp_mtr_stats - meter stats information + * @pass_bytes: count of passed bytes for meter + * @pass_pkts: count of passed packets for meter + * @drop_bytes: count of dropped bytes for meter + * @drop_pkts: count of dropped packets for meter + */ +struct nfp_mtr_stats { + uint64_t pass_bytes; + uint64_t pass_pkts; + uint64_t drop_bytes; + uint64_t drop_pkts; +}; + /** * Struct nfp_mtr - meter object information * @next: next meter object @@ -104,6 +134,9 @@ struct nfp_mtr_policy { * @enable: if meter is enable to use * @mtr_profile: the pointer of profile * @mtr_policy: the pointer of policy + * @stats_mask: supported meter stats mask + * @curr: current meter stats + * @prev: previous meter stats */ struct nfp_mtr { LIST_ENTRY(nfp_mtr) next; @@ -113,6 +146,11 @@ struct nfp_mtr { bool enable; struct nfp_mtr_profile *mtr_profile; struct nfp_mtr_policy *mtr_policy; + uint64_t stats_mask; + struct { + struct nfp_mtr_stats curr; + struct nfp_mtr_stats prev; + } mtr_stats; }; /** @@ -120,11 +158,15 @@ struct nfp_mtr { * @profiles: the head node of profile list * @policies: the head node of policy list * @mtrs: the head node of mtrs list + * @mtr_stats_lock: spinlock for meter stats + * @drain_tsc: clock period */ struct nfp_mtr_priv { LIST_HEAD(, nfp_mtr_profile) profiles; LIST_HEAD(, nfp_mtr_policy) policies; LIST_HEAD(, nfp_mtr) mtrs; + rte_spinlock_t mtr_stats_lock; + uint64_t drain_tsc; }; int nfp_net_mtr_ops_get(struct rte_eth_dev *dev, void *arg); @@ -132,5 +174,7 @@ 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); +struct nfp_mtr *nfp_mtr_find_by_profile_id(struct nfp_mtr_priv *priv, + uint32_t profile_id); #endif /* __NFP_MTR_H__ */ -- 2.29.3