From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 218CB45BC0;
	Tue, 29 Oct 2024 18:17:41 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 06B134326C;
	Tue, 29 Oct 2024 18:17:02 +0100 (CET)
Received: from egress-ip42b.ess.de.barracuda.com
 (egress-ip42b.ess.de.barracuda.com [18.185.115.246])
 by mails.dpdk.org (Postfix) with ESMTP id 1FC5B43264
 for <dev@dpdk.org>; Tue, 29 Oct 2024 18:16:55 +0100 (CET)
Received: from EUR03-DBA-obe.outbound.protection.outlook.com
 (mail-dbaeur03lp2172.outbound.protection.outlook.com [104.47.51.172]) by
 mx-outbound17-86.eu-central-1b.ess.aws.cudaops.com (version=TLSv1.2
 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO);
 Tue, 29 Oct 2024 17:16:51 +0000
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=jatm89kZLk8gXHy5+fgz3/YT1dd73r8YDY12w3INOKhJ+TK/uwmWcpQce+bsf8AtsDBsC6HZKS0n3E0EPVmRzzZQ8j8Or/K9kNM8LeJqUw+1vJ3DP9UJrPL8p2kgSf1QwSkVNOHNd5zGb98c3LlVYtA+7PzmXXOOPf6GZxOSXpmXAThYah72++dW2Cm7SlfvzExnjXiLnspA3QwZKHglPWpmCK12IK8Tn5HsLXgehKrx4WNQ4L0DUXJHjiNq15A5odN7vT696rjk0JNRGkuGVw9adcZ92myMHttrNi8Oo3KQnMpw5iZfNqopzsmXXY7xojoJBHr3dPwjIo/bLbUz8Q==
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=UIo6VpgdH6v8fU9JcOIfb0TH7V2pfACyEMCtmC/3GW0=;
 b=o5QtGa8qX2zA9dbWrBsJtLgOqF0AoyzUuEt+yXIRS2ow2b4JonpA0Ro1MnNRJwoPbcPW+EYi3pGVHIDMGChnGy2fgj6DOh8nWqojWAu2yJoMFeMawQQTpUQ1rJoE+u1ehoDNWL+iWIQ7VJ5IuEHLDX+Y8rMugH0tl877i749dui0xJ5HfDa7MCizsZkmkYeIhMAPUP8izO4AW5+1k9TsWy5Z/32ytnyozzqKK6GXBx+styjk1UGQhZrUIDgbwmSDIE2rMadxhwgM0EPi4fYf04OvQ3LRNWc9Qq845xZXJGZX1f3Oh+DqxIMxSiV4mpzAosgtqhFGoOzv2j3UmNaQgA==
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=UIo6VpgdH6v8fU9JcOIfb0TH7V2pfACyEMCtmC/3GW0=;
 b=hC4X3ebVWBef6w7cNzj10VAJTPLBCZXfbJs8HlrNI1RSybOT9jXhbSJc1caIAdlAfzTR7hHDNJlT4wh0z4xwuNh7Y8f8v+ZsJbBP8iSM2IXmYpOklIKOAKFsHShUK1o1w3lGju3hivCr1aEl5qMvu9nJt6TFLrUDJyYc5uvQKIc=
Received: from DUZPR01CA0197.eurprd01.prod.exchangelabs.com
 (2603:10a6:10:4b6::11) by GVXP190MB2230.EURP190.PROD.OUTLOOK.COM
 (2603:10a6:150:223::18) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Tue, 29 Oct
 2024 16:44:04 +0000
Received: from DU2PEPF00028D06.eurprd03.prod.outlook.com
 (2603:10a6:10:4b6:cafe::ea) by DUZPR01CA0197.outlook.office365.com
 (2603:10a6:10:4b6::11) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.29 via Frontend
 Transport; Tue, 29 Oct 2024 16:44:04 +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
 DU2PEPF00028D06.mail.protection.outlook.com (10.167.242.166) with Microsoft
 SMTP Server id 15.20.8114.16 via Frontend Transport; Tue, 29 Oct 2024
 16:44:04 +0000
From: Serhii Iliushyk <sil-plv@napatech.com>
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, Danylo Vodopianov <dvo-plv@napatech.com>
Subject: [PATCH v4 72/86] net/ntnic: add meter module
Date: Tue, 29 Oct 2024 17:42:16 +0100
Message-ID: <20241029164243.1648775-73-sil-plv@napatech.com>
X-Mailer: git-send-email 2.45.0
In-Reply-To: <20241029164243.1648775-1-sil-plv@napatech.com>
References: <20241021210527.2075431-1-sil-plv@napatech.com>
 <20241029164243.1648775-1-sil-plv@napatech.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: DU2PEPF00028D06:EE_|GVXP190MB2230:EE_
Content-Type: text/plain
X-MS-Office365-Filtering-Correlation-Id: 0dd89830-54c1-4807-92e5-08dcf838e64a
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
 ARA:13230040|1800799024|376014|36860700013|82310400026; 
X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?3yLKusLnCwwK3BoMbha+mVSpfkQ6HUp3NTqJvn8CqGWSpypYkSmIzxg04Qzf?=
 =?us-ascii?Q?biw1kbsgcYKeaVZ+M+OD9gOD2vnfRJMgsBCCOlD0G7tclaLCouCaJwfqpgGM?=
 =?us-ascii?Q?ie2sGO9mutVHU40r1/hcLUURBcjk3QSqtghFBFNOCBL7x/QAO7BjjGdnE9B+?=
 =?us-ascii?Q?aWh0Sy80DXKfIVWWJ72ejfn25HkDCE4BdmLMPuOZn7E95Ra0dt+uwCZC9xCT?=
 =?us-ascii?Q?lBm6mLzD+SFQUPvkJ6ijeaN8cw4vJb2iw7Pp/QGHx00En7dD9uc+tOb8eEE7?=
 =?us-ascii?Q?CywQvW5zVilZBzQt2SsyBOTTHfGlEfjJVfFYDfV08/eQcuodC5HoW3fi62gv?=
 =?us-ascii?Q?uZ0BQCfY0AwXYFZYsW+NCaRje3c+HLr7cmXoDuRMm1rnnQa3bwL9dd1WXZBQ?=
 =?us-ascii?Q?fPD3fVKZ/r/umm1egTw0RvAXlKhqBUFvtZqFyCLLGO73OPlo2mEmseB4mP4v?=
 =?us-ascii?Q?ji4DNAiTWG4r2TfcU7dsZCkLTk8fKc5VhkzBXvMN0qGzx7q/FCPzSqSFbg7v?=
 =?us-ascii?Q?EFC6aQVr/gIvLVEGWkt2NCxmbJZZ7VrCBK3la23UwVibESDmTbbhXnfwjoyw?=
 =?us-ascii?Q?wsqkf4DRYjk+B9rAogoydQHq4iyYMPilYQe6wgSWa43nnIpehYx7K+/EDY/x?=
 =?us-ascii?Q?zvcL+d4CMF4usEBgK81kPuszrxvasIGvcY+U647DIIOwAwfEhGx6Y0jXI3FK?=
 =?us-ascii?Q?lJU+qeWUh+RNoUD4T3YXWaWwdNENxspX58CB6cbguLhzxVKmT2jggvsqS7ZU?=
 =?us-ascii?Q?cxtjVoG1zSZioHIM9u0alPWOlB0bmS0LgjSxbuVksufg6+OuWGX+q7elDOFZ?=
 =?us-ascii?Q?RkIyEkTMaDOINzaHmX7GWB+yY21n7Azb++1Mm4zieo30xs3tESExqd/VBroO?=
 =?us-ascii?Q?bb+QizlGN/8hE31hqdGB73TirYe+bl+CnJIH7aaufNUx6qx+99i0aqNHOmyt?=
 =?us-ascii?Q?Jg3ktAFUcXmWtYKhhhHFoh1sQ3JeuFhRXC3zZtwxmGZHgovYmcPICQOuZk87?=
 =?us-ascii?Q?n7Z4UPI0zZ7FDTVX14g7nvpX/TEPRcO3gD8X6/yBSjPHsl3GGPIRhaLS9WTP?=
 =?us-ascii?Q?SKe267TZ32qfFJRBTfCqtSHCJ0W0Yb826M6wkAjl+CnqmnXoYwCac1vqC/EH?=
 =?us-ascii?Q?rsQR98jZlaVX4BdGQzRHYC9Nf7ENGG/pK6Ge6vydynUeftPcRxHcABvbT/Ng?=
 =?us-ascii?Q?CT6xp2HtmDrLnuk+3zf6WLsk+G6Gcq73WSGAxKIRAl3oc2bi/0DNVT5rS+Zh?=
 =?us-ascii?Q?uCSW1GU1ct+Ayximsn8jwn7RLragX1Q05gxcSTnExIri2l1SDX5nwZIKuD8c?=
 =?us-ascii?Q?ZFQ1Ks/By9plh0Qbyfpax5GiPmGC1GM8+ZYXEc7ggjau15L10w+7NotlMhTo?=
 =?us-ascii?Q?usDytUDybmf590jXVB2jNdOWRRfJSbhT6KpGbo/p3u89OWSr0A=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)(1800799024)(376014)(36860700013)(82310400026);
 DIR:OUT; SFP:1102; 
X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: neLp86NXBlTNBtKJVi13yVaac9ObIWjad0P/tc2jNDYj/ZG9cEqnCxg+OePS7E+Gma4MdBCDlpdqwRB+KRupjx4uU4pTM0i/QYR4hOv1ww1dNjgp3+H/k9u2GZZirDnXisnxUer0L4QI5ZFb2iPbg8Elk9rDSSGjQB7Jk7kNgVMeIReJNwMI0QI7ZclPSqS8NyTuwK8ENdJ59jXtLMrKEMfQu2FyIKmX1xM1ep//pCGCqbr/5u8QulaPMpZxDrzZLW37t/enPXWrzfoD3d1LgfHOZwKBpyyV3YVjQW/Ygk1KnYg2qM1j0thJZyu+MkCkUCYbA+Q0u0y6DQQVPR9guCNvGotTSzclNnrHd8e46qLLmBGZFJFc3gHNQblmEUkpY3Q7nYXmcmtp/XdxMJqA9+QacR4IOKkCCJkxiup38Ajq9hnrV5H5kVI+8FjSDSXIfKOxuLgFGtr+xiiSvbmsgu9yE5238LDUc2VgzyxeU0oYqeueKa+nKOsjty8LX1PdbQVKkj9FxEXJ4uoFtWjbtH7xVkoiSddtbDl/LweKCzyASXGruHRK0kDSzuGjDutmaqbf7afzVT3BWtN8XUP510OxBS582E5+p9MxXPL1N9QIPrdDfYxhbbSXmC1Kn/1WacPPRwDU3J4ZrtqfvFtkgKLumPoJL3HlfKOmiiTNgyM=
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 16:44:04.2303 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 0dd89830-54c1-4807-92e5-08dcf838e64a
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: DU2PEPF00028D06.eurprd03.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXP190MB2230
X-OriginatorOrg: napatech.com
X-BESS-ID: 1730222211-304438-12709-31898-1
X-BESS-VER: 2019.1_20241018.1852
X-BESS-Apparent-Source-IP: 104.47.51.172
X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVkYG5uZGQGYGUDQtycgs2dTAwD
 DZxCjJwtAk2cjAKCXFLNUwzSAlKcU4Wak2FgA3c+18QgAAAA==
X-BESS-Outbound-Spam-Score: 0.00
X-BESS-Outbound-Spam-Report: Code version 3.2,
 rules version 3.2.2.260064 [from 
 cloudscan22-120.eu-central-1b.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 <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

From: Danylo Vodopianov <dvo-plv@napatech.com>

Meter module was added:
1. add/remove profile
2. create/destroy flow
3. add/remove meter policy
4. read/update stats

eth_dev_ops struct was extended with ops above.

Signed-off-by: Danylo Vodopianov <dvo-plv@napatech.com>
---
 drivers/net/ntnic/include/ntos_drv.h          |  14 +
 drivers/net/ntnic/meson.build                 |   2 +
 .../net/ntnic/nthw/ntnic_meter/ntnic_meter.c  | 483 ++++++++++++++++++
 drivers/net/ntnic/ntnic_ethdev.c              |  11 +-
 drivers/net/ntnic/ntnic_mod_reg.c             |  21 +
 drivers/net/ntnic/ntnic_mod_reg.h             |  12 +
 6 files changed, 542 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ntnic/nthw/ntnic_meter/ntnic_meter.c

diff --git a/drivers/net/ntnic/include/ntos_drv.h b/drivers/net/ntnic/include/ntos_drv.h
index 7b3c8ff3d6..f6ce442d17 100644
--- a/drivers/net/ntnic/include/ntos_drv.h
+++ b/drivers/net/ntnic/include/ntos_drv.h
@@ -12,6 +12,7 @@
 #include <inttypes.h>
 
 #include <rte_ether.h>
+#include "rte_mtr.h"
 
 #include "stream_binary_flow_api.h"
 #include "nthw_drv.h"
@@ -90,6 +91,19 @@ struct __rte_cache_aligned ntnic_tx_queue {
 	enum fpga_info_profile profile;  /* Inline / Capture */
 };
 
+struct nt_mtr_profile {
+	LIST_ENTRY(nt_mtr_profile) next;
+	uint32_t profile_id;
+	struct rte_mtr_meter_profile profile;
+};
+
+struct nt_mtr {
+	LIST_ENTRY(nt_mtr) next;
+	uint32_t mtr_id;
+	int shared;
+	struct nt_mtr_profile *profile;
+};
+
 struct pmd_internals {
 	const struct rte_pci_device *pci_dev;
 	struct flow_eth_dev *flw_dev;
diff --git a/drivers/net/ntnic/meson.build b/drivers/net/ntnic/meson.build
index 8c6d02a5ec..ca46541ef3 100644
--- a/drivers/net/ntnic/meson.build
+++ b/drivers/net/ntnic/meson.build
@@ -17,6 +17,7 @@ includes = [
         include_directories('nthw'),
         include_directories('nthw/supported'),
         include_directories('nthw/model'),
+        include_directories('nthw/ntnic_meter'),
         include_directories('nthw/flow_filter'),
         include_directories('nthw/flow_api'),
         include_directories('nim/'),
@@ -92,6 +93,7 @@ sources = files(
         'nthw/flow_filter/flow_nthw_tx_cpy.c',
         'nthw/flow_filter/flow_nthw_tx_ins.c',
         'nthw/flow_filter/flow_nthw_tx_rpl.c',
+        'nthw/ntnic_meter/ntnic_meter.c',
         'nthw/model/nthw_fpga_model.c',
         'nthw/nthw_platform.c',
         'nthw/nthw_rac.c',
diff --git a/drivers/net/ntnic/nthw/ntnic_meter/ntnic_meter.c b/drivers/net/ntnic/nthw/ntnic_meter/ntnic_meter.c
new file mode 100644
index 0000000000..e4e8fe0c7d
--- /dev/null
+++ b/drivers/net/ntnic/nthw/ntnic_meter/ntnic_meter.c
@@ -0,0 +1,483 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Napatech A/S
+ */
+
+#include <stdint.h>
+
+#include <rte_common.h>
+#include <rte_meter.h>
+#include <rte_mtr.h>
+#include <rte_mtr_driver.h>
+#include <rte_malloc.h>
+
+#include "ntos_drv.h"
+#include "ntlog.h"
+#include "nt_util.h"
+#include "ntos_system.h"
+#include "ntnic_mod_reg.h"
+
+static inline uint8_t get_caller_id(uint16_t port)
+{
+	return MAX_VDPA_PORTS + (uint8_t)(port & 0x7f) + 1;
+}
+
+struct qos_integer_fractional {
+	uint32_t integer;
+	uint32_t fractional;	/* 1/1024 */
+};
+
+/*
+ * Inline FLM metering
+ */
+
+static int eth_mtr_capabilities_get_inline(struct rte_eth_dev *eth_dev,
+	struct rte_mtr_capabilities *cap,
+	struct rte_mtr_error *error)
+{
+	const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
+
+	if (profile_inline_ops == NULL) {
+		NT_LOG(ERR, NTHW, "profile_inline module uninitialized");
+		return -1;
+	}
+
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+
+	uint8_t caller_id = get_caller_id(eth_dev->data->port_id);
+
+	if (!profile_inline_ops->flow_mtr_supported(internals->flw_dev)) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+				"Ethernet device does not support metering");
+	}
+
+	memset(cap, 0x0, sizeof(struct rte_mtr_capabilities));
+
+	/* MBR records use 28-bit integers */
+	cap->n_max = profile_inline_ops->flow_mtr_meters_supported(internals->flw_dev,
+		caller_id);
+	cap->n_shared_max = cap->n_max;
+
+	cap->identical = 0;
+	cap->shared_identical = 0;
+
+	cap->shared_n_flows_per_mtr_max = UINT32_MAX;
+
+	/* Limited by number of MBR record ids per FLM learn record */
+	cap->chaining_n_mtrs_per_flow_max = 4;
+
+	cap->chaining_use_prev_mtr_color_supported = 0;
+	cap->chaining_use_prev_mtr_color_enforced = 0;
+
+	cap->meter_rate_max = (uint64_t)(0xfff << 0xf) * 1099;
+
+	cap->stats_mask = RTE_MTR_STATS_N_PKTS_GREEN | RTE_MTR_STATS_N_BYTES_GREEN;
+
+	/* Only color-blind mode is supported */
+	cap->color_aware_srtcm_rfc2697_supported = 0;
+	cap->color_aware_trtcm_rfc2698_supported = 0;
+	cap->color_aware_trtcm_rfc4115_supported = 0;
+
+	/* Focused on RFC2698 for now */
+	cap->meter_srtcm_rfc2697_n_max = 0;
+	cap->meter_trtcm_rfc2698_n_max = cap->n_max;
+	cap->meter_trtcm_rfc4115_n_max = 0;
+
+	cap->meter_policy_n_max = profile_inline_ops->flow_mtr_meter_policy_n_max();
+
+	/* Byte mode is supported */
+	cap->srtcm_rfc2697_byte_mode_supported = 0;
+	cap->trtcm_rfc2698_byte_mode_supported = 1;
+	cap->trtcm_rfc4115_byte_mode_supported = 0;
+
+	/* Packet mode not supported */
+	cap->srtcm_rfc2697_packet_mode_supported = 0;
+	cap->trtcm_rfc2698_packet_mode_supported = 0;
+	cap->trtcm_rfc4115_packet_mode_supported = 0;
+
+	return 0;
+}
+
+static int eth_mtr_meter_profile_add_inline(struct rte_eth_dev *eth_dev,
+	uint32_t meter_profile_id,
+	struct rte_mtr_meter_profile *profile,
+	struct rte_mtr_error *error __rte_unused)
+{
+	const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
+
+	if (profile_inline_ops == NULL) {
+		NT_LOG(ERR, NTHW, "profile_inline module uninitialized");
+		return -1;
+	}
+
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+
+	if (meter_profile_id >= profile_inline_ops->flow_mtr_meter_policy_n_max())
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, NULL,
+				"Profile id out of range");
+
+	if (profile->packet_mode != 0) {
+		return -rte_mtr_error_set(error, EINVAL,
+				RTE_MTR_ERROR_TYPE_METER_PROFILE_PACKET_MODE, NULL,
+				"Profile packet mode not supported");
+	}
+
+	if (profile->alg == RTE_MTR_SRTCM_RFC2697) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"RFC 2697 not supported");
+	}
+
+	if (profile->alg == RTE_MTR_TRTCM_RFC4115) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"RFC 4115 not supported");
+	}
+
+	if (profile->trtcm_rfc2698.cir != profile->trtcm_rfc2698.pir ||
+		profile->trtcm_rfc2698.cbs != profile->trtcm_rfc2698.pbs) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"Profile committed and peak rates must be equal");
+	}
+
+	int res = profile_inline_ops->flow_mtr_set_profile(internals->flw_dev, meter_profile_id,
+			profile->trtcm_rfc2698.cir,
+			profile->trtcm_rfc2698.cbs, 0, 0);
+
+	if (res) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_PROFILE, NULL,
+				"Profile could not be added.");
+	}
+
+	return 0;
+}
+
+static int eth_mtr_meter_profile_delete_inline(struct rte_eth_dev *eth_dev,
+	uint32_t meter_profile_id,
+	struct rte_mtr_error *error __rte_unused)
+{
+	const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
+
+	if (profile_inline_ops == NULL) {
+		NT_LOG(ERR, NTHW, "profile_inline module uninitialized");
+		return -1;
+	}
+
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+
+	if (meter_profile_id >= profile_inline_ops->flow_mtr_meter_policy_n_max())
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, NULL,
+				"Profile id out of range");
+
+	profile_inline_ops->flow_mtr_set_profile(internals->flw_dev, meter_profile_id, 0, 0, 0, 0);
+
+	return 0;
+}
+
+static int eth_mtr_meter_policy_add_inline(struct rte_eth_dev *eth_dev,
+	uint32_t policy_id,
+	struct rte_mtr_meter_policy_params *policy,
+	struct rte_mtr_error *error)
+{
+	const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
+
+	if (profile_inline_ops == NULL) {
+		NT_LOG(ERR, NTHW, "profile_inline module uninitialized");
+		return -1;
+	}
+
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+
+	if (policy_id >= profile_inline_ops->flow_mtr_meter_policy_n_max())
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY_ID, NULL,
+				"Policy id out of range");
+
+	const struct rte_flow_action *actions = policy->actions[RTE_COLOR_GREEN];
+	int green_action_supported = (actions[0].type == RTE_FLOW_ACTION_TYPE_END) ||
+		(actions[0].type == RTE_FLOW_ACTION_TYPE_VOID &&
+			actions[1].type == RTE_FLOW_ACTION_TYPE_END) ||
+		(actions[0].type == RTE_FLOW_ACTION_TYPE_PASSTHRU &&
+			actions[1].type == RTE_FLOW_ACTION_TYPE_END);
+
+	actions = policy->actions[RTE_COLOR_YELLOW];
+	int yellow_action_supported = actions[0].type == RTE_FLOW_ACTION_TYPE_DROP &&
+		actions[1].type == RTE_FLOW_ACTION_TYPE_END;
+
+	actions = policy->actions[RTE_COLOR_RED];
+	int red_action_supported = actions[0].type == RTE_FLOW_ACTION_TYPE_DROP &&
+		actions[1].type == RTE_FLOW_ACTION_TYPE_END;
+
+	if (green_action_supported == 0 || yellow_action_supported == 0 ||
+		red_action_supported == 0) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+				"Unsupported meter policy actions");
+	}
+
+	if (profile_inline_ops->flow_mtr_set_policy(internals->flw_dev, policy_id, 1)) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
+				"Policy could not be added");
+	}
+
+	return 0;
+}
+
+static int eth_mtr_meter_policy_delete_inline(struct rte_eth_dev *eth_dev __rte_unused,
+	uint32_t policy_id,
+	struct rte_mtr_error *error __rte_unused)
+{
+	const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
+
+	if (profile_inline_ops == NULL) {
+		NT_LOG(ERR, NTHW, "profile_inline module uninitialized");
+		return -1;
+	}
+
+	if (policy_id >= profile_inline_ops->flow_mtr_meter_policy_n_max())
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY_ID, NULL,
+				"Policy id out of range");
+
+	return 0;
+}
+
+static int eth_mtr_create_inline(struct rte_eth_dev *eth_dev,
+	uint32_t mtr_id,
+	struct rte_mtr_params *params,
+	int shared,
+	struct rte_mtr_error *error)
+{
+	const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
+
+	if (profile_inline_ops == NULL) {
+		NT_LOG(ERR, NTHW, "profile_inline module uninitialized");
+		return -1;
+	}
+
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+
+	uint8_t caller_id = get_caller_id(eth_dev->data->port_id);
+
+	if (params->use_prev_mtr_color != 0 || params->dscp_table != NULL) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+				"Only color blind mode is supported");
+	}
+
+	uint64_t allowed_stats_mask = RTE_MTR_STATS_N_PKTS_GREEN | RTE_MTR_STATS_N_BYTES_GREEN;
+
+	if ((params->stats_mask & ~allowed_stats_mask) != 0) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+				"Requested color stats not supported");
+	}
+
+	if (params->meter_enable == 0) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+				"Disabled meters not supported");
+	}
+
+	if (shared == 0) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+				"Only shared mtrs are supported");
+	}
+
+	if (params->meter_profile_id >= profile_inline_ops->flow_mtr_meter_policy_n_max())
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, NULL,
+				"Profile id out of range");
+
+	if (params->meter_policy_id >= profile_inline_ops->flow_mtr_meter_policy_n_max())
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY_ID, NULL,
+				"Policy id out of range");
+
+	if (mtr_id >=
+		profile_inline_ops->flow_mtr_meters_supported(internals->flw_dev, caller_id)) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+				"MTR id is out of range");
+	}
+
+	int res = profile_inline_ops->flow_mtr_create_meter(internals->flw_dev,
+			caller_id,
+			mtr_id,
+			params->meter_profile_id,
+			params->meter_policy_id,
+			params->stats_mask);
+
+	if (res) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+				"Failed to offload to hardware");
+	}
+
+	return 0;
+}
+
+static int eth_mtr_destroy_inline(struct rte_eth_dev *eth_dev,
+	uint32_t mtr_id,
+	struct rte_mtr_error *error __rte_unused)
+{
+	const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
+
+	if (profile_inline_ops == NULL) {
+		NT_LOG(ERR, NTHW, "profile_inline module uninitialized");
+		return -1;
+	}
+
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+
+	uint8_t caller_id = get_caller_id(eth_dev->data->port_id);
+
+	if (mtr_id >=
+		profile_inline_ops->flow_mtr_meters_supported(internals->flw_dev, caller_id)) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+				"MTR id is out of range");
+	}
+
+	if (profile_inline_ops->flow_mtr_destroy_meter(internals->flw_dev, caller_id, mtr_id)) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+				"Failed to offload to hardware");
+	}
+
+	return 0;
+}
+
+static int eth_mtr_stats_adjust_inline(struct rte_eth_dev *eth_dev,
+	uint32_t mtr_id,
+	uint64_t adjust_value,
+	struct rte_mtr_error *error)
+{
+	const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
+
+	if (profile_inline_ops == NULL) {
+		NT_LOG(ERR, NTHW, "profile_inline module uninitialized");
+		return -1;
+	}
+
+	const uint64_t adjust_bit = 1ULL << 63;
+	const uint64_t probe_bit = 1ULL << 62;
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+	uint8_t caller_id = get_caller_id(eth_dev->data->port_id);
+
+	if (mtr_id >=
+		profile_inline_ops->flow_mtr_meters_supported(internals->flw_dev, caller_id)) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+				"MTR id is out of range");
+	}
+
+	if (adjust_value & adjust_bit) {
+		adjust_value &= adjust_bit - 1;
+
+		if (adjust_value > (uint64_t)UINT32_MAX) {
+			return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS,
+					NULL, "Adjust value is out of range");
+		}
+
+		if (profile_inline_ops->flm_mtr_adjust_stats(internals->flw_dev, caller_id, mtr_id,
+				(uint32_t)adjust_value)) {
+			return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+					NULL, "Failed to adjust offloaded MTR");
+		}
+
+		return 0;
+	}
+
+	if (adjust_value & probe_bit) {
+		if (mtr_id >=
+			profile_inline_ops->flow_mtr_meters_supported(internals->flw_dev,
+				caller_id)) {
+			return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS,
+					NULL, "MTR id is out of range");
+		}
+
+		if (profile_inline_ops->flow_mtr_probe_meter(internals->flw_dev, caller_id,
+				mtr_id)) {
+			return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
+					NULL, "Failed to offload to hardware");
+		}
+
+		return 0;
+	}
+
+	return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+			"Use of meter stats update requires bit 63 or bit 62 of \"stats_mask\" must be 1.");
+}
+
+static int eth_mtr_stats_read_inline(struct rte_eth_dev *eth_dev,
+	uint32_t mtr_id,
+	struct rte_mtr_stats *stats,
+	uint64_t *stats_mask,
+	int clear,
+	struct rte_mtr_error *error)
+{
+	const struct profile_inline_ops *profile_inline_ops = get_profile_inline_ops();
+
+	if (profile_inline_ops == NULL) {
+		NT_LOG(ERR, NTHW, "profile_inline module uninitialized");
+		return -1;
+	}
+
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+
+	uint8_t caller_id = get_caller_id(eth_dev->data->port_id);
+
+	if (mtr_id >=
+		profile_inline_ops->flow_mtr_meters_supported(internals->flw_dev, caller_id)) {
+		return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+				"MTR id is out of range");
+	}
+
+	memset(stats, 0x0, sizeof(struct rte_mtr_stats));
+	profile_inline_ops->flm_mtr_read_stats(internals->flw_dev, caller_id, mtr_id, stats_mask,
+		&stats->n_pkts[RTE_COLOR_GREEN],
+		&stats->n_bytes[RTE_COLOR_GREEN], clear);
+
+	return 0;
+}
+
+/*
+ * Ops setup
+ */
+
+static const struct rte_mtr_ops mtr_ops_inline = {
+	.capabilities_get = eth_mtr_capabilities_get_inline,
+	.meter_profile_add = eth_mtr_meter_profile_add_inline,
+	.meter_profile_delete = eth_mtr_meter_profile_delete_inline,
+	.create = eth_mtr_create_inline,
+	.destroy = eth_mtr_destroy_inline,
+	.meter_policy_add = eth_mtr_meter_policy_add_inline,
+	.meter_policy_delete = eth_mtr_meter_policy_delete_inline,
+	.stats_update = eth_mtr_stats_adjust_inline,
+	.stats_read = eth_mtr_stats_read_inline,
+};
+
+static int eth_mtr_ops_get(struct rte_eth_dev *eth_dev, void *ops)
+{
+	struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private;
+	ntdrv_4ga_t *p_nt_drv = &internals->p_drv->ntdrv;
+	enum fpga_info_profile profile = p_nt_drv->adapter_info.fpga_info.profile;
+
+	switch (profile) {
+	case FPGA_INFO_PROFILE_INLINE:
+		*(const struct rte_mtr_ops **)ops = &mtr_ops_inline;
+		break;
+
+	case FPGA_INFO_PROFILE_UNKNOWN:
+
+	/* fallthrough */
+	case FPGA_INFO_PROFILE_CAPTURE:
+
+	/* fallthrough */
+	default:
+		NT_LOG(ERR, NTHW, "" PCIIDENT_PRINT_STR ": fpga profile not supported",
+			PCIIDENT_TO_DOMAIN(p_nt_drv->pciident),
+			PCIIDENT_TO_BUSNR(p_nt_drv->pciident),
+			PCIIDENT_TO_DEVNR(p_nt_drv->pciident),
+			PCIIDENT_TO_FUNCNR(p_nt_drv->pciident));
+		return -1;
+	}
+
+	return 0;
+}
+
+static struct meter_ops_s meter_ops = {
+	.eth_mtr_ops_get = eth_mtr_ops_get,
+};
+
+void meter_init(void)
+{
+	NT_LOG(DBG, NTNIC, "Meter ops initialized");
+	register_meter_ops(&meter_ops);
+}
diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c
index cdf5c346b7..df9ee77e06 100644
--- a/drivers/net/ntnic/ntnic_ethdev.c
+++ b/drivers/net/ntnic/ntnic_ethdev.c
@@ -1682,7 +1682,7 @@ static int rss_hash_conf_get(struct rte_eth_dev *eth_dev, struct rte_eth_rss_con
 	return 0;
 }
 
-static const struct eth_dev_ops nthw_eth_dev_ops = {
+static struct eth_dev_ops nthw_eth_dev_ops = {
 	.dev_configure = eth_dev_configure,
 	.dev_start = eth_dev_start,
 	.dev_stop = eth_dev_stop,
@@ -1705,6 +1705,7 @@ static const struct eth_dev_ops nthw_eth_dev_ops = {
 	.mac_addr_add = eth_mac_addr_add,
 	.mac_addr_set = eth_mac_addr_set,
 	.set_mc_addr_list = eth_set_mc_addr_list,
+	.mtr_ops_get = NULL,
 	.flow_ops_get = dev_flow_ops_get,
 	.xstats_get = eth_xstats_get,
 	.xstats_get_names = eth_xstats_get_names,
@@ -2168,6 +2169,14 @@ nthw_pci_dev_init(struct rte_pci_device *pci_dev)
 		return -1;
 	}
 
+	const struct meter_ops_s *meter_ops = get_meter_ops();
+
+	if (meter_ops != NULL)
+		nthw_eth_dev_ops.mtr_ops_get = meter_ops->eth_mtr_ops_get;
+
+	else
+		NT_LOG(DBG, NTNIC, "Meter module is not initialized");
+
 	/* Initialize the queue system */
 	if (err == 0) {
 		sg_ops = get_sg_ops();
diff --git a/drivers/net/ntnic/ntnic_mod_reg.c b/drivers/net/ntnic/ntnic_mod_reg.c
index 6737d18a6f..10aa778a57 100644
--- a/drivers/net/ntnic/ntnic_mod_reg.c
+++ b/drivers/net/ntnic/ntnic_mod_reg.c
@@ -19,6 +19,27 @@ const struct sg_ops_s *get_sg_ops(void)
 	return sg_ops;
 }
 
+/*
+ *
+ */
+static struct meter_ops_s *meter_ops;
+
+void register_meter_ops(struct meter_ops_s *ops)
+{
+	meter_ops = ops;
+}
+
+const struct meter_ops_s *get_meter_ops(void)
+{
+	if (meter_ops == NULL)
+		meter_init();
+
+	return meter_ops;
+}
+
+/*
+ *
+ */
 static const struct ntnic_filter_ops *ntnic_filter_ops;
 
 void register_ntnic_filter_ops(const struct ntnic_filter_ops *ops)
diff --git a/drivers/net/ntnic/ntnic_mod_reg.h b/drivers/net/ntnic/ntnic_mod_reg.h
index 1e9dcd549f..3fbbee6490 100644
--- a/drivers/net/ntnic/ntnic_mod_reg.h
+++ b/drivers/net/ntnic/ntnic_mod_reg.h
@@ -115,6 +115,18 @@ void register_sg_ops(struct sg_ops_s *ops);
 const struct sg_ops_s *get_sg_ops(void);
 void sg_init(void);
 
+/* Meter ops section */
+struct meter_ops_s {
+	int (*eth_mtr_ops_get)(struct rte_eth_dev *eth_dev, void *ops);
+};
+
+void register_meter_ops(struct meter_ops_s *ops);
+const struct meter_ops_s *get_meter_ops(void);
+void meter_init(void);
+
+/*
+ *
+ */
 struct ntnic_filter_ops {
 	int (*poll_statistics)(struct pmd_internals *internals);
 };
-- 
2.45.0