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 E71CA45BA3; Tue, 22 Oct 2024 19:30:47 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BE5AB40BA0; Tue, 22 Oct 2024 19:30:30 +0200 (CEST) Received: from egress-ip11a.ess.de.barracuda.com (egress-ip11a.ess.de.barracuda.com [18.184.203.234]) by mails.dpdk.org (Postfix) with ESMTP id E83AB40B8D for ; Tue, 22 Oct 2024 19:30:27 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2105.outbound.protection.outlook.com [104.47.17.105]) by mx-outbound40-26.eu-central-1c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 22 Oct 2024 17:30:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sVJ27r+bg7ehJHafW9sa390kl4wlSq0uQ1wlnWDBZFFAjazNQC4dNROmbQYtogzswgCPSww1xCN0eHUKAhSs0ghLCeRETCG/p2MDd6+xtK34IhFpLS4MxI47TMWFyZr1u+nDeIO1xnMiZ58naY22hx3BxrSERdKB5d8z2ioCmVMimdisfPxkAjklona2JabVxBdkRZ29Ltb+mPwbH37ig7IEQ/vhdXiMmrWsGkSlM7WkCoAHVlijPRzhKI11PSppXy15aaQ0kc31c7yw9fvnxrQt35nigM5u26AAE1KBrkHYK35veAF2Wn+ZpBNK/HrPW4olB1o4SMOeofpa4MaOMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=kFVST8ru/wCkSHFkiAFIpehm/gq1iANHjcFZ9VSXoIc=; b=oDuMrTQVsfM1A7v68yCK2gwOS3n/TX4qAwvD2SqwKuQdjmWToIuJQr5E4N9aIN+hb7eaOnc5ILG+ChOe+TIrw1fbQkuBMGznWLwS0vpI1l4zLIduVDzdrakB+ckLSVMewHUO5Fs/BUPcp7u1QWAEbijgYfx1VKdTSYlDsnkGp0jdSkMfqJGogunWQLjTPRnB/6Gql1xxI5Ah/r30iWmszJGt/ZvH7Owy5E0dvZzFr1vD0OUQFnYpjISJxRHhwLwVGz5RmcLsbxBsiBHnypAKAGQPIv8yiT6xillwSc1GmxKhJo6iEZ7kQ/Ul8sV39o1KqXmGPYU1ZiETJg5lDNQ/IA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 178.72.21.4) smtp.rcpttodomain=dpdk.org smtp.mailfrom=napatech.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=napatech.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=napatech.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kFVST8ru/wCkSHFkiAFIpehm/gq1iANHjcFZ9VSXoIc=; b=psCRT6xRFHveHZW8SwCArikavLEok9WWZzQzgVR+fLISXyFGEnUdXs8WqqxLL3SYleAgASzKKvK6wlgwXiqEgpnV7hlwNGNqH/YiIPwyCaVjLDpSdQqyhmZw6lMvgDMo8XrE1lM4lum4UcFCgdhZV9vL4LgS7GzIG3VN11WFoz8= Received: from DB9PR06CA0029.eurprd06.prod.outlook.com (2603:10a6:10:1db::34) by AS8P190MB1239.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:2e4::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Tue, 22 Oct 2024 16:57:19 +0000 Received: from DU2PEPF0001E9C2.eurprd03.prod.outlook.com (2603:10a6:10:1db:cafe::94) by DB9PR06CA0029.outlook.office365.com (2603:10a6:10:1db::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.29 via Frontend Transport; Tue, 22 Oct 2024 16:57:19 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 178.72.21.4) smtp.mailfrom=napatech.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=napatech.com; Received-SPF: Fail (protection.outlook.com: domain of napatech.com does not designate 178.72.21.4 as permitted sender) receiver=protection.outlook.com; client-ip=178.72.21.4; helo=localhost.localdomain; Received: from localhost.localdomain (178.72.21.4) by DU2PEPF0001E9C2.mail.protection.outlook.com (10.167.8.71) with Microsoft SMTP Server id 15.20.8093.14 via Frontend Transport; Tue, 22 Oct 2024 16:57:19 +0000 From: Serhii Iliushyk To: dev@dpdk.org Cc: mko-plv@napatech.com, sil-plv@napatech.com, ckm@napatech.com, andrew.rybchenko@oktetlabs.ru, ferruh.yigit@amd.com, stephen@networkplumber.org Subject: [PATCH v2 71/73] net/ntnic: add meter API Date: Tue, 22 Oct 2024 18:55:28 +0200 Message-ID: <20241022165541.3186140-72-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241022165541.3186140-1-sil-plv@napatech.com> References: <20241021210527.2075431-1-sil-plv@napatech.com> <20241022165541.3186140-1-sil-plv@napatech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF0001E9C2:EE_|AS8P190MB1239:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 3ce64c6e-7800-4caa-a385-08dcf2ba9752 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Ip+E8LHwa02ZfStGEcnOyp3AOEzXKw4CxnoIELIlFvaeeNpzpRRkehI4rcoo?= =?us-ascii?Q?UC6uEuwyB6zk4aQ2AmQSXFpax6v0A3finM7RarFSfQqYrmnLfNRGaRxhvo9y?= =?us-ascii?Q?wHA1Uo+T0b+CqVb4zd8XIdK69lqsku0Py6AFCt52p4xVA/gaBTwX5SRBIGum?= =?us-ascii?Q?F29DxA1M+rcab6uU/8tzyNiCrt3Dc0JwiRL/XhyOoyED36tCV/XixpYH6M7P?= =?us-ascii?Q?GpF+TfAsueD3AxkJ1+/iiAjxtOq8XcfUp3wOqRs+qexrUD5RM9iQe6rwoFzo?= =?us-ascii?Q?+Oq50FObILV8g23X4pwLtyeV/ErRUsJBCq/E+ALHeg1sEE2xMGqk/5/ktr2P?= =?us-ascii?Q?90mFCiccFGsfd5pSqOMoIsV+9RNEEN12vtMhKGkblO/JjQ/WXDqIiqmgC9q1?= =?us-ascii?Q?vJ+sF5CW+2MAMndfeAtBQL3JQ6YhIT+oeTdpZXeUhv5jDitSRhbiR3ieBlJ4?= =?us-ascii?Q?Wr4HboXHT1bNrjOPbpJyjW2JHz5uGw4ed8nWSnSUpFV0iiWl/yuV3SRNiGhH?= =?us-ascii?Q?gsIV1HZ/VNleJ6nbgqhKH0wA2vwtgBfJzEzRthZVIpELYbwPiO5OM8K/kjiZ?= =?us-ascii?Q?jNyH/YX7x8D+55N6MMNE9v/m+gl5hFdnR72TxBCfwCPE1GmgSH34rICEoGqd?= =?us-ascii?Q?caTmH/CJ5KG4+Hyf+cOc2r9n7UU5HoTu+uv1/yFSITFcAvwh5Xw3EXWNpdun?= =?us-ascii?Q?ssRFGhjGQHNn824ppbvNf5TICsUdKKqu/ysqz9+vZPC9e8ryJ+ax7WmqA/zI?= =?us-ascii?Q?TMEU+9yvFfNq6bH1Lwf5AxzOngak57vae44Jx9vBCBhnLUZxPqYcDf2AmEex?= =?us-ascii?Q?l7jFo9/9uq0Ify3JYsPfTUqwlaF3w63F/MxSVT0nQNvsDaOvqKlHSk2BKbiU?= =?us-ascii?Q?1GFxAlgNmfZz/CeGi9MKeNzHFgMj8vG6l9nHJqdKVZGKwstqhcd+56uaSFo1?= =?us-ascii?Q?s+7H5Avjr4JRaOat/WqIeUl+ZUbVZuluTi+kke9UpwAPzV9+vgLqaGr6wazC?= =?us-ascii?Q?oyz5p3c6bLdK7HltpeHEewVNi301hHVrx++QfWslxb86SKpgFqtaGvBoXEew?= =?us-ascii?Q?o6OH+FKnqkIyStldTmMQMLihp2zxdHIp4V7PK/s01ADYn5/Q4/SbeFHmK/1M?= =?us-ascii?Q?66fd6e9/S2TTCvA45mp9An+ZTcQRIpNYj9tQy2ZrJoEH6OjMY+O4LwjXEDuF?= =?us-ascii?Q?Tf33lFTe9FTQVwOFKCcAp2m36D1m+0tfWJAgCRd1uZ88o45hUcqQZkFtPMwD?= =?us-ascii?Q?1+lWuXL3HJwzBMLbfFc2HNpf/DhjBf9CdHwnb02ivzUZXYLdobkgDxN7kcTG?= =?us-ascii?Q?/9MajM1U+BHkSWVoYgXOOpCb0d2UKp5QEZPqf/vRlsqAQf4TgiVJeDiSdGsN?= =?us-ascii?Q?2Jm4ofFO6tmx0wt9hwvCAvf387L+OXy3WBIkxE8QeNR8Fi6hYw=3D=3D?= X-Forefront-Antispam-Report: CIP:178.72.21.4; CTRY:DK; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:localhost.localdomain; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Y+GIlHqzu7H06P8Z3lpgvpgoMBWADn54iZC6nq+nkNv2QtRtGse/2XjwRs5CQ5jEmpASNXFHSibPcxA2anjGdR2QIexa3ktx97LEwF/D5jepEbFvj93Tjng4QZrMfBuP+0dLsY93+MKPOFkIX+Bx+DuyOCCJ713J4pGSWLZ7+oh3EEW775Yfisr3DDAx5/iqfhM1ABlg+7IHQBtTgiu21Hw9z8fxN/9CuZqk/FmUNV1q+1y8LbK5x8ZdFUl6NG2/QOqP5jiJNGgkMobTbhTZE10OZirDcSDSKFGrFzK2D9qg9zRl+1Kc307ReXo1/6SL3ckW78eDIOi/RJQL1X2iGQfUqbU8fDr+t9v89tTggGw/6M1oXbXBLx4/mhohOQaC99X2Z9jDCgdD4A8JZqCpHRIowxamdPkoHcID0WW/eXmbxM5Nn6ujaFLPz9XgdofzWA3QNQAg5tkem+dHvYdzjbZaLGgT+tuGWYHx4VnOa1W4JA7ii1zmtKtZcOpaQM+NP/kNde63Js0updFdlazXJjC1X1EVMY0RRA85DvHy3sgEkaASBpkG3I1AiTsAf6ErsFyCLpYGbyFbrnkdHWBNqqTOnsN4WuIjTDnsMTdR474n/hIXu2dBexuRtvct7VXMRQilEWX5RWZP7NZ9J/j0g8zRrb9CUEVnoDbjMv9eP10= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 16:57:19.2788 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ce64c6e-7800-4caa-a385-08dcf2ba9752 X-MS-Exchange-CrossTenant-Id: c4540d0b-728a-4233-9da5-9ea30c7ec3ed X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=c4540d0b-728a-4233-9da5-9ea30c7ec3ed; Ip=[178.72.21.4]; Helo=[localhost.localdomain] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF0001E9C2.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P190MB1239 X-OriginatorOrg: napatech.com X-BESS-ID: 1729618226-310266-12660-14389-1 X-BESS-VER: 2019.1_20241018.1852 X-BESS-Apparent-Source-IP: 104.47.17.105 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVkbGpiaWQGYGUDTZzNTSNNUkJd nc0sTU3DQp2TjV1MjMxDApNcXcyDQpRak2FgC5dlHmQgAAAA== X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.259902 [from cloudscan12-62.eu-central-1a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS113687 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 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 Add meter API and implementation to the profile inline. management functions were extended with meter flow support. Signed-off-by: Serhii Iliushyk --- drivers/net/ntnic/include/flow_api.h | 1 + drivers/net/ntnic/include/flow_api_engine.h | 5 + .../flow_api/profile_inline/flm_evt_queue.c | 21 + .../flow_api/profile_inline/flm_evt_queue.h | 1 + .../profile_inline/flow_api_profile_inline.c | 534 +++++++++++++++++- drivers/net/ntnic/ntnic_mod_reg.h | 34 ++ 6 files changed, 578 insertions(+), 18 deletions(-) diff --git a/drivers/net/ntnic/include/flow_api.h b/drivers/net/ntnic/include/flow_api.h index 89f071d982..032063712a 100644 --- a/drivers/net/ntnic/include/flow_api.h +++ b/drivers/net/ntnic/include/flow_api.h @@ -100,6 +100,7 @@ struct flow_nic_dev { void *km_res_handle; void *kcc_res_handle; + void *flm_mtr_handle; void *group_handle; void *hw_db_handle; void *id_table_handle; diff --git a/drivers/net/ntnic/include/flow_api_engine.h b/drivers/net/ntnic/include/flow_api_engine.h index 155a9e1fd6..8f1a6419f3 100644 --- a/drivers/net/ntnic/include/flow_api_engine.h +++ b/drivers/net/ntnic/include/flow_api_engine.h @@ -57,6 +57,7 @@ enum res_type_e { #define MAX_TCAM_START_OFFSETS 4 +#define MAX_FLM_MTRS_SUPPORTED 4 #define MAX_CPY_WRITERS_SUPPORTED 8 #define MAX_MATCH_FIELDS 16 @@ -215,6 +216,8 @@ struct nic_flow_def { uint32_t jump_to_group; + uint32_t mtr_ids[MAX_FLM_MTRS_SUPPORTED]; + int full_offload; /* @@ -307,6 +310,8 @@ struct flow_handle { uint32_t flm_db_idx_counter; uint32_t flm_db_idxs[RES_COUNT]; + uint32_t flm_mtr_ids[MAX_FLM_MTRS_SUPPORTED]; + uint32_t flm_data[10]; uint8_t flm_prot; uint8_t flm_kid; diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c index 761609a0ea..d76c7da568 100644 --- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c +++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c @@ -234,6 +234,27 @@ int flm_sta_queue_put(uint8_t port, bool remote, struct flm_status_event_s *obj) return 0; } +void flm_inf_queue_put(uint8_t port, bool remote, struct flm_info_event_s *obj) +{ + int ret; + + /* If queues is not created, then ignore and return */ + if (!remote) { + if (port < MAX_INFO_LCL_QUEUES && info_q_local[port] != NULL) { + ret = rte_ring_sp_enqueue_elem(info_q_local[port], obj, FLM_EVT_ELEM_SIZE); + + if (ret != 0) + NT_LOG(DBG, FILTER, "FLM local info queue full"); + } + + } else if (port < MAX_INFO_RMT_QUEUES && info_q_remote[port] != NULL) { + ret = rte_ring_sp_enqueue_elem(info_q_remote[port], obj, FLM_EVT_ELEM_SIZE); + + if (ret != 0) + NT_LOG(DBG, FILTER, "FLM remote info queue full"); + } +} + int flm_inf_queue_get(uint8_t port, bool remote, struct flm_info_event_s *obj) { int ret; diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.h b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.h index d61b282472..ee8175cf25 100644 --- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.h +++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.h @@ -48,6 +48,7 @@ enum { #define FLM_STAT_ELEM_SIZE sizeof(struct flm_status_event_s) void flm_inf_sta_queue_free_all(uint8_t caller); +void flm_inf_queue_put(uint8_t port, bool remote, struct flm_info_event_s *obj); int flm_inf_queue_get(uint8_t port, bool remote, struct flm_info_event_s *obj); int flm_sta_queue_put(uint8_t port, bool remote, struct flm_status_event_s *obj); diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c index 21d8ed4ca9..2c55a7c9c2 100644 --- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c +++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c @@ -21,6 +21,10 @@ #include "ntnic_mod_reg.h" #include +#define FLM_MTR_PROFILE_SIZE 0x100000 +#define FLM_MTR_STAT_SIZE 0x1000000 +#define UINT64_MSB ((uint64_t)1 << 63) + #define DMA_BLOCK_SIZE 256 #define DMA_OVERHEAD 20 #define WORDS_PER_STA_DATA (sizeof(struct flm_v25_sta_data_s) / sizeof(uint32_t)) @@ -46,8 +50,336 @@ #define NT_FLM_OP_UNLEARN 0 #define NT_FLM_OP_LEARN 1 +#define NT_FLM_MISS_FLOW_TYPE 0 +#define NT_FLM_UNHANDLED_FLOW_TYPE 1 +#define NT_FLM_VIOLATING_MBR_FLOW_TYPE 15 + +#define NT_VIOLATING_MBR_CFN 0 +#define NT_VIOLATING_MBR_QSL 1 + +#define POLICING_PARAMETER_OFFSET 4096 +#define SIZE_CONVERTER 1099.511627776 + +struct flm_mtr_stat_s { + struct dual_buckets_s *buckets; + atomic_uint_fast64_t n_pkt; + atomic_uint_fast64_t n_bytes; + uint64_t n_pkt_base; + uint64_t n_bytes_base; + atomic_uint_fast64_t stats_mask; + uint32_t flm_id; +}; + +struct flm_mtr_shared_stats_s { + struct flm_mtr_stat_s *stats; + uint32_t size; + int shared; +}; + +struct flm_flow_mtr_handle_s { + struct dual_buckets_s { + uint16_t rate_a; + uint16_t rate_b; + uint16_t size_a; + uint16_t size_b; + } dual_buckets[FLM_MTR_PROFILE_SIZE]; + + struct flm_mtr_shared_stats_s *port_stats[UINT8_MAX]; +}; + static void *flm_lrn_queue_arr; +static int flow_mtr_supported(struct flow_eth_dev *dev) +{ + return hw_mod_flm_present(&dev->ndev->be) && dev->ndev->be.flm.nb_variant == 2; +} + +static uint64_t flow_mtr_meter_policy_n_max(void) +{ + return FLM_MTR_PROFILE_SIZE; +} + +static inline uint64_t convert_policing_parameter(uint64_t value) +{ + uint64_t limit = POLICING_PARAMETER_OFFSET; + uint64_t shift = 0; + uint64_t res = value; + + while (shift < 15 && value >= limit) { + limit <<= 1; + ++shift; + } + + if (shift != 0) { + uint64_t tmp = POLICING_PARAMETER_OFFSET * (1 << (shift - 1)); + + if (tmp > value) { + res = 0; + + } else { + tmp = value - tmp; + res = tmp >> (shift - 1); + } + + if (res >= POLICING_PARAMETER_OFFSET) + res = POLICING_PARAMETER_OFFSET - 1; + + res = res | (shift << 12); + } + + return res; +} + +static int flow_mtr_set_profile(struct flow_eth_dev *dev, uint32_t profile_id, + uint64_t bucket_rate_a, uint64_t bucket_size_a, uint64_t bucket_rate_b, + uint64_t bucket_size_b) +{ + struct flow_nic_dev *ndev = dev->ndev; + struct flm_flow_mtr_handle_s *handle = + (struct flm_flow_mtr_handle_s *)ndev->flm_mtr_handle; + struct dual_buckets_s *buckets = &handle->dual_buckets[profile_id]; + + /* Round rates up to nearest 128 bytes/sec and shift to 128 bytes/sec units */ + bucket_rate_a = (bucket_rate_a + 127) >> 7; + bucket_rate_b = (bucket_rate_b + 127) >> 7; + + buckets->rate_a = convert_policing_parameter(bucket_rate_a); + buckets->rate_b = convert_policing_parameter(bucket_rate_b); + + /* Round size down to 38-bit int */ + if (bucket_size_a > 0x3fffffffff) + bucket_size_a = 0x3fffffffff; + + if (bucket_size_b > 0x3fffffffff) + bucket_size_b = 0x3fffffffff; + + /* Convert size to units of 2^40 / 10^9. Output is a 28-bit int. */ + bucket_size_a = bucket_size_a / SIZE_CONVERTER; + bucket_size_b = bucket_size_b / SIZE_CONVERTER; + + buckets->size_a = convert_policing_parameter(bucket_size_a); + buckets->size_b = convert_policing_parameter(bucket_size_b); + + return 0; +} + +static int flow_mtr_set_policy(struct flow_eth_dev *dev, uint32_t policy_id, int drop) +{ + (void)dev; + (void)policy_id; + (void)drop; + return 0; +} + +static uint32_t flow_mtr_meters_supported(struct flow_eth_dev *dev, uint8_t caller_id) +{ + struct flm_flow_mtr_handle_s *handle = dev->ndev->flm_mtr_handle; + return handle->port_stats[caller_id]->size; +} + +static int flow_mtr_create_meter(struct flow_eth_dev *dev, + uint8_t caller_id, + uint32_t mtr_id, + uint32_t profile_id, + uint32_t policy_id, + uint64_t stats_mask) +{ + (void)policy_id; + struct flm_v25_lrn_data_s *learn_record = NULL; + + pthread_mutex_lock(&dev->ndev->mtx); + + learn_record = + (struct flm_v25_lrn_data_s *) + flm_lrn_queue_get_write_buffer(flm_lrn_queue_arr); + + while (learn_record == NULL) { + nt_os_wait_usec(1); + learn_record = + (struct flm_v25_lrn_data_s *) + flm_lrn_queue_get_write_buffer(flm_lrn_queue_arr); + } + + struct flm_flow_mtr_handle_s *handle = dev->ndev->flm_mtr_handle; + + struct dual_buckets_s *buckets = &handle->dual_buckets[profile_id]; + + memset(learn_record, 0x0, sizeof(struct flm_v25_lrn_data_s)); + + union flm_handles flm_h; + flm_h.idx = mtr_id; + uint32_t flm_id = ntnic_id_table_get_id(dev->ndev->id_table_handle, flm_h, caller_id, 2); + + learn_record->sw9 = flm_id; + learn_record->kid = 1; + + learn_record->rate = buckets->rate_a; + learn_record->size = buckets->size_a; + learn_record->fill = buckets->size_a; + + learn_record->ft_mbr = + NT_FLM_VIOLATING_MBR_FLOW_TYPE; /* FT to assign if MBR has been exceeded */ + + learn_record->ent = 1; + learn_record->op = 1; + learn_record->eor = 1; + + learn_record->id = flm_id; + + if (stats_mask) + learn_record->vol_idx = 1; + + flm_lrn_queue_release_write_buffer(flm_lrn_queue_arr); + + struct flm_mtr_stat_s *mtr_stat = handle->port_stats[caller_id]->stats; + mtr_stat[mtr_id].buckets = buckets; + mtr_stat[mtr_id].flm_id = flm_id; + atomic_store(&mtr_stat[mtr_id].stats_mask, stats_mask); + + pthread_mutex_unlock(&dev->ndev->mtx); + + return 0; +} + +static int flow_mtr_probe_meter(struct flow_eth_dev *dev, uint8_t caller_id, uint32_t mtr_id) +{ + struct flm_v25_lrn_data_s *learn_record = NULL; + + pthread_mutex_lock(&dev->ndev->mtx); + + learn_record = + (struct flm_v25_lrn_data_s *) + flm_lrn_queue_get_write_buffer(flm_lrn_queue_arr); + + while (learn_record == NULL) { + nt_os_wait_usec(1); + learn_record = + (struct flm_v25_lrn_data_s *) + flm_lrn_queue_get_write_buffer(flm_lrn_queue_arr); + } + + struct flm_flow_mtr_handle_s *handle = dev->ndev->flm_mtr_handle; + + struct flm_mtr_stat_s *mtr_stat = handle->port_stats[caller_id]->stats; + uint32_t flm_id = mtr_stat[mtr_id].flm_id; + + memset(learn_record, 0x0, sizeof(struct flm_v25_lrn_data_s)); + + learn_record->sw9 = flm_id; + learn_record->kid = 1; + + learn_record->ent = 1; + learn_record->op = 3; + learn_record->eor = 1; + + learn_record->id = flm_id; + + flm_lrn_queue_release_write_buffer(flm_lrn_queue_arr); + + pthread_mutex_unlock(&dev->ndev->mtx); + + return 0; +} + +static int flow_mtr_destroy_meter(struct flow_eth_dev *dev, uint8_t caller_id, uint32_t mtr_id) +{ + struct flm_v25_lrn_data_s *learn_record = NULL; + + pthread_mutex_lock(&dev->ndev->mtx); + + learn_record = + (struct flm_v25_lrn_data_s *) + flm_lrn_queue_get_write_buffer(flm_lrn_queue_arr); + + while (learn_record == NULL) { + nt_os_wait_usec(1); + learn_record = + (struct flm_v25_lrn_data_s *) + flm_lrn_queue_get_write_buffer(flm_lrn_queue_arr); + } + + struct flm_flow_mtr_handle_s *handle = dev->ndev->flm_mtr_handle; + + struct flm_mtr_stat_s *mtr_stat = handle->port_stats[caller_id]->stats; + uint32_t flm_id = mtr_stat[mtr_id].flm_id; + + memset(learn_record, 0x0, sizeof(struct flm_v25_lrn_data_s)); + + learn_record->sw9 = flm_id; + learn_record->kid = 1; + + learn_record->ent = 1; + learn_record->op = 0; + /* Suppress generation of statistics INF_DATA */ + learn_record->nofi = 1; + learn_record->eor = 1; + + learn_record->id = flm_id; + + /* Clear statistics so stats_mask prevents updates of counters on deleted meters */ + atomic_store(&mtr_stat[mtr_id].stats_mask, 0); + atomic_store(&mtr_stat[mtr_id].n_bytes, 0); + atomic_store(&mtr_stat[mtr_id].n_pkt, 0); + mtr_stat[mtr_id].n_bytes_base = 0; + mtr_stat[mtr_id].n_pkt_base = 0; + mtr_stat[mtr_id].buckets = NULL; + + ntnic_id_table_free_id(dev->ndev->id_table_handle, flm_id); + + flm_lrn_queue_release_write_buffer(flm_lrn_queue_arr); + + pthread_mutex_unlock(&dev->ndev->mtx); + + return 0; +} + +static int flm_mtr_adjust_stats(struct flow_eth_dev *dev, uint8_t caller_id, uint32_t mtr_id, + uint32_t adjust_value) +{ + struct flm_v25_lrn_data_s *learn_record = NULL; + + pthread_mutex_lock(&dev->ndev->mtx); + + learn_record = + (struct flm_v25_lrn_data_s *) + flm_lrn_queue_get_write_buffer(flm_lrn_queue_arr); + + while (learn_record == NULL) { + nt_os_wait_usec(1); + learn_record = + (struct flm_v25_lrn_data_s *) + flm_lrn_queue_get_write_buffer(flm_lrn_queue_arr); + } + + struct flm_flow_mtr_handle_s *handle = dev->ndev->flm_mtr_handle; + + struct flm_mtr_stat_s *mtr_stat = &handle->port_stats[caller_id]->stats[mtr_id]; + + memset(learn_record, 0x0, sizeof(struct flm_v25_lrn_data_s)); + + learn_record->sw9 = mtr_stat->flm_id; + learn_record->kid = 1; + + learn_record->rate = mtr_stat->buckets->rate_a; + learn_record->size = mtr_stat->buckets->size_a; + learn_record->adj = adjust_value; + + learn_record->ft_mbr = NT_FLM_VIOLATING_MBR_FLOW_TYPE; + + learn_record->ent = 1; + learn_record->op = 2; + learn_record->eor = 1; + + if (atomic_load(&mtr_stat->stats_mask)) + learn_record->vol_idx = 1; + + flm_lrn_queue_release_write_buffer(flm_lrn_queue_arr); + + pthread_mutex_unlock(&dev->ndev->mtx); + + return 0; +} + static void flm_setup_queues(void) { flm_lrn_queue_arr = flm_lrn_queue_create(); @@ -92,6 +424,8 @@ static inline bool is_remote_caller(uint8_t caller_id, uint8_t *port) static void flm_mtr_read_inf_records(struct flow_eth_dev *dev, uint32_t *data, uint32_t records) { + struct flm_flow_mtr_handle_s *handle = dev->ndev->flm_mtr_handle; + for (uint32_t i = 0; i < records; ++i) { struct flm_v25_inf_data_s *inf_data = (struct flm_v25_inf_data_s *)&data[i * WORDS_PER_INF_DATA]; @@ -102,29 +436,62 @@ static void flm_mtr_read_inf_records(struct flow_eth_dev *dev, uint32_t *data, u &type); /* Check that received record hold valid meter statistics */ - if (type == 1) { - switch (inf_data->cause) { - case INF_DATA_CAUSE_TIMEOUT_FLOW_DELETED: - case INF_DATA_CAUSE_TIMEOUT_FLOW_KEPT: { - struct flow_handle *fh = (struct flow_handle *)flm_h.p; - struct flm_age_event_s age_event; - uint8_t port; + if (type == 2) { + uint64_t mtr_id = flm_h.idx; + + if (mtr_id < handle->port_stats[caller_id]->size) { + struct flm_mtr_stat_s *mtr_stat = + handle->port_stats[caller_id]->stats; + + /* Don't update a deleted meter */ + uint64_t stats_mask = atomic_load(&mtr_stat[mtr_id].stats_mask); + + if (stats_mask) { + atomic_store(&mtr_stat[mtr_id].n_pkt, + inf_data->packets | UINT64_MSB); + atomic_store(&mtr_stat[mtr_id].n_bytes, inf_data->bytes); + atomic_store(&mtr_stat[mtr_id].n_pkt, inf_data->packets); + struct flm_info_event_s stat_data; + bool remote_caller; + uint8_t port; + + remote_caller = is_remote_caller(caller_id, &port); + + /* Save stat data to flm stat queue */ + stat_data.bytes = inf_data->bytes; + stat_data.packets = inf_data->packets; + stat_data.id = mtr_id; + stat_data.timestamp = inf_data->ts; + stat_data.cause = inf_data->cause; + flm_inf_queue_put(port, remote_caller, &stat_data); + } + } - age_event.context = fh->context; + /* Check that received record hold valid flow data */ - is_remote_caller(caller_id, &port); + } else if (type == 1) { + switch (inf_data->cause) { + case INF_DATA_CAUSE_TIMEOUT_FLOW_DELETED: + case INF_DATA_CAUSE_TIMEOUT_FLOW_KEPT: { + struct flow_handle *fh = (struct flow_handle *)flm_h.p; + struct flm_age_event_s age_event; + uint8_t port; - flm_age_queue_put(caller_id, &age_event); - flm_age_event_set(port); - } - break; + age_event.context = fh->context; - case INF_DATA_CAUSE_SW_UNLEARN: - case INF_DATA_CAUSE_NA: - case INF_DATA_CAUSE_PERIODIC_FLOW_INFO: - case INF_DATA_CAUSE_SW_PROBE: - default: + is_remote_caller(caller_id, &port); + + flm_age_queue_put(caller_id, &age_event); + flm_age_event_set(port); + } break; + + case INF_DATA_CAUSE_SW_UNLEARN: + case INF_DATA_CAUSE_NA: + case INF_DATA_CAUSE_PERIODIC_FLOW_INFO: + case INF_DATA_CAUSE_SW_PROBE: + default: + break; } } } @@ -203,6 +570,42 @@ static uint32_t flm_update(struct flow_eth_dev *dev) return inf_word_cnt + sta_word_cnt; } +static void flm_mtr_read_stats(struct flow_eth_dev *dev, + uint8_t caller_id, + uint32_t id, + uint64_t *stats_mask, + uint64_t *green_pkt, + uint64_t *green_bytes, + int clear) +{ + struct flm_flow_mtr_handle_s *handle = dev->ndev->flm_mtr_handle; + struct flm_mtr_stat_s *mtr_stat = handle->port_stats[caller_id]->stats; + *stats_mask = atomic_load(&mtr_stat[id].stats_mask); + + if (*stats_mask) { + uint64_t pkt_1; + uint64_t pkt_2; + uint64_t nb; + + do { + do { + pkt_1 = atomic_load(&mtr_stat[id].n_pkt); + } while (pkt_1 & UINT64_MSB); + + nb = atomic_load(&mtr_stat[id].n_bytes); + pkt_2 = atomic_load(&mtr_stat[id].n_pkt); + } while (pkt_1 != pkt_2); + + *green_pkt = pkt_1 - mtr_stat[id].n_pkt_base; + *green_bytes = nb - mtr_stat[id].n_bytes_base; + + if (clear) { + mtr_stat[id].n_pkt_base = pkt_1; + mtr_stat[id].n_bytes_base = nb; + } + } +} + static int rx_queue_idx_to_hw_id(const struct flow_eth_dev *dev, int id) { for (int i = 0; i < dev->num_queues; ++i) @@ -2511,6 +2914,13 @@ static void copy_fd_to_fh_flm(struct flow_handle *fh, const struct nic_flow_def const uint32_t *packet_data, uint32_t flm_key_id, uint32_t flm_ft, uint16_t rpl_ext_ptr, uint32_t flm_scrub __rte_unused, uint32_t priority) { + for (int i = 0; i < MAX_FLM_MTRS_SUPPORTED; ++i) { + struct flm_flow_mtr_handle_s *handle = fh->dev->ndev->flm_mtr_handle; + struct flm_mtr_stat_s *mtr_stat = handle->port_stats[fh->caller_id]->stats; + fh->flm_mtr_ids[i] = + fd->mtr_ids[i] == UINT32_MAX ? 0 : mtr_stat[fd->mtr_ids[i]].flm_id; + } + switch (fd->l4_prot) { case PROT_L4_TCP: fh->flm_prot = 6; @@ -3540,6 +3950,29 @@ int initialize_flow_management_of_ndev_profile_inline(struct flow_nic_dev *ndev) if (ndev->id_table_handle == NULL) goto err_exit0; + ndev->flm_mtr_handle = calloc(1, sizeof(struct flm_flow_mtr_handle_s)); + struct flm_mtr_shared_stats_s *flm_shared_stats = + calloc(1, sizeof(struct flm_mtr_shared_stats_s)); + struct flm_mtr_stat_s *flm_stats = + calloc(FLM_MTR_STAT_SIZE, sizeof(struct flm_mtr_stat_s)); + + if (ndev->flm_mtr_handle == NULL || flm_shared_stats == NULL || + flm_stats == NULL) { + free(ndev->flm_mtr_handle); + free(flm_shared_stats); + free(flm_stats); + goto err_exit0; + } + + for (uint32_t i = 0; i < UINT8_MAX; ++i) { + ((struct flm_flow_mtr_handle_s *)ndev->flm_mtr_handle)->port_stats[i] = + flm_shared_stats; + } + + flm_shared_stats->stats = flm_stats; + flm_shared_stats->size = FLM_MTR_STAT_SIZE; + flm_shared_stats->shared = UINT8_MAX; + if (flow_group_handle_create(&ndev->group_handle, ndev->be.flm.nb_categories)) goto err_exit0; @@ -3574,6 +4007,27 @@ int done_flow_management_of_ndev_profile_inline(struct flow_nic_dev *ndev) flow_nic_free_resource(ndev, RES_FLM_FLOW_TYPE, 1); flow_nic_free_resource(ndev, RES_FLM_RCP, 0); + for (uint32_t i = 0; i < UINT8_MAX; ++i) { + struct flm_flow_mtr_handle_s *handle = ndev->flm_mtr_handle; + handle->port_stats[i]->shared -= 1; + + if (handle->port_stats[i]->shared == 0) { + free(handle->port_stats[i]->stats); + free(handle->port_stats[i]); + } + } + + for (uint32_t i = 0; i < UINT8_MAX; ++i) { + struct flm_flow_mtr_handle_s *handle = ndev->flm_mtr_handle; + handle->port_stats[i]->shared -= 1; + + if (handle->port_stats[i]->shared == 0) { + free(handle->port_stats[i]->stats); + free(handle->port_stats[i]); + } + } + + free(ndev->flm_mtr_handle); flow_group_handle_destroy(&ndev->group_handle); ntnic_id_table_destroy(ndev->id_table_handle); @@ -4693,6 +5147,11 @@ int flow_info_get_profile_inline(struct flow_eth_dev *dev, uint8_t caller_id, port_info->max_nb_aging_objects = dev->nb_aging_objects; + struct flm_flow_mtr_handle_s *mtr_handle = dev->ndev->flm_mtr_handle; + + if (mtr_handle) + port_info->max_nb_meters = mtr_handle->port_stats[caller_id]->size; + return res; } @@ -4724,6 +5183,35 @@ int flow_configure_profile_inline(struct flow_eth_dev *dev, uint8_t caller_id, dev->nb_aging_objects = port_attr->nb_aging_objects; } + if (port_attr->nb_meters > 0) { + struct flm_flow_mtr_handle_s *mtr_handle = dev->ndev->flm_mtr_handle; + + if (mtr_handle->port_stats[caller_id]->shared == 1) { + res = realloc(mtr_handle->port_stats[caller_id]->stats, + port_attr->nb_meters) == NULL + ? -1 + : 0; + mtr_handle->port_stats[caller_id]->size = port_attr->nb_meters; + + } else { + mtr_handle->port_stats[caller_id] = + calloc(1, sizeof(struct flm_mtr_shared_stats_s)); + struct flm_mtr_stat_s *stats = + calloc(port_attr->nb_meters, sizeof(struct flm_mtr_stat_s)); + + if (mtr_handle->port_stats[caller_id] == NULL || stats == NULL) { + free(mtr_handle->port_stats[caller_id]); + free(stats); + error->message = "Failed to allocate meter actions"; + goto error_out; + } + + mtr_handle->port_stats[caller_id]->stats = stats; + mtr_handle->port_stats[caller_id]->size = port_attr->nb_meters; + mtr_handle->port_stats[caller_id]->shared = 1; + } + } + return res; error_out: @@ -4763,8 +5251,18 @@ static const struct profile_inline_ops ops = { /* * NT Flow FLM Meter API */ + .flow_mtr_supported = flow_mtr_supported, + .flow_mtr_meter_policy_n_max = flow_mtr_meter_policy_n_max, + .flow_mtr_set_profile = flow_mtr_set_profile, + .flow_mtr_set_policy = flow_mtr_set_policy, + .flow_mtr_create_meter = flow_mtr_create_meter, + .flow_mtr_probe_meter = flow_mtr_probe_meter, + .flow_mtr_destroy_meter = flow_mtr_destroy_meter, + .flm_mtr_adjust_stats = flm_mtr_adjust_stats, + .flow_mtr_meters_supported = flow_mtr_meters_supported, .flm_setup_queues = flm_setup_queues, .flm_free_queues = flm_free_queues, + .flm_mtr_read_stats = flm_mtr_read_stats, .flm_update = flm_update, }; diff --git a/drivers/net/ntnic/ntnic_mod_reg.h b/drivers/net/ntnic/ntnic_mod_reg.h index 029b0ac4eb..503674f4a4 100644 --- a/drivers/net/ntnic/ntnic_mod_reg.h +++ b/drivers/net/ntnic/ntnic_mod_reg.h @@ -303,10 +303,44 @@ struct profile_inline_ops { uint64_t *data, uint64_t size); + /* + * NT Flow FLM Meter API + */ + int (*flow_mtr_supported)(struct flow_eth_dev *dev); + + uint64_t (*flow_mtr_meter_policy_n_max)(void); + + int (*flow_mtr_set_profile)(struct flow_eth_dev *dev, uint32_t profile_id, + uint64_t bucket_rate_a, uint64_t bucket_size_a, + uint64_t bucket_rate_b, uint64_t bucket_size_b); + + int (*flow_mtr_set_policy)(struct flow_eth_dev *dev, uint32_t policy_id, int drop); + + int (*flow_mtr_create_meter)(struct flow_eth_dev *dev, uint8_t caller_id, uint32_t mtr_id, + uint32_t profile_id, uint32_t policy_id, uint64_t stats_mask); + + int (*flow_mtr_probe_meter)(struct flow_eth_dev *dev, uint8_t caller_id, uint32_t mtr_id); + + int (*flow_mtr_destroy_meter)(struct flow_eth_dev *dev, uint8_t caller_id, + uint32_t mtr_id); + + int (*flm_mtr_adjust_stats)(struct flow_eth_dev *dev, uint8_t caller_id, uint32_t mtr_id, + uint32_t adjust_value); + + uint32_t (*flow_mtr_meters_supported)(struct flow_eth_dev *dev, uint8_t caller_id); + /* * NT Flow FLM queue API */ void (*flm_setup_queues)(void); + void (*flm_mtr_read_stats)(struct flow_eth_dev *dev, + uint8_t caller_id, + uint32_t id, + uint64_t *stats_mask, + uint64_t *green_pkt, + uint64_t *green_bytes, + int clear); + void (*flm_free_queues)(void); uint32_t (*flm_update)(struct flow_eth_dev *dev); -- 2.45.0