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 C64A245BCC; Thu, 31 Oct 2024 00:14:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2799F4352D; Thu, 31 Oct 2024 00:13:42 +0100 (CET) Received: from egress-ip42a.ess.de.barracuda.com (egress-ip42a.ess.de.barracuda.com [18.185.115.201]) by mails.dpdk.org (Postfix) with ESMTP id 7613B434BF for ; Thu, 31 Oct 2024 00:13:26 +0100 (CET) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2110.outbound.protection.outlook.com [104.47.18.110]) by mx-outbound47-144.eu-central-1c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 30 Oct 2024 23:13:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JQr7B08qyVGFMbpdrEgHchuYQ6EmcmLsc0FM+GrgjygkqjX/N++svpYFhgSJrYVoZ1hsdK5nDXsilKWymO+tqfZfH4RLEdDBkq5TVTfee40imYUfTSR+b8z7rF6ipDy/sTNtdbPLRbs+K8TXHDPSYiCiGTf+IvyO4MXYIKJwsUJNb9p80wGPhLDbidv+9krrBY4HT/wKQY39qy92NB85y2xofb2KBZPSzVLJZ1TaiHgpJoa/ZDZKyvw8WhUtDz9kt0Cy1mnFceOP0JV8e27VxsabEpOaTB+dtbhR0c715sEPfaWPUMME3WM474BsbOfMqElDYK7wcxiFocJNvsQ3CA== 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=ysMVolJyrgcBTu+pp8uOu+766DpV9nGgJtLBW2l9xyk=; b=RCj+6BlkKC60227vt4SwPpEeqKNynRwRECdO0wPsmvLNUf1MK0YvnjR+pIU7l/Y8QJPCOB6Sd+I1AFv0goqc4wT+dTgiYCmFltB0CkV/Gy6USI1gU2JmLdRqkvKCxr2ucWwvxGJRitRyAKqhNr6/FZEi5mgd1BPQMLP1IzgksT+CKNs43Vh3aOSqVWeG04I3Z4cIZ/wM1rdeAmtW2DNLfX8udxlJVhQD2mPu1mG7nsBp26YEv1IZduJPfjFTR6uXpUMoYNQy3pTKjOk2h79c7PVzppGSPCew/KIHSiHA1IIGa2R6SvcNPd23IX/dQqREDLPIgbT9vWu5VfsvCicp7A== 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=ysMVolJyrgcBTu+pp8uOu+766DpV9nGgJtLBW2l9xyk=; b=ZllDFXUtMVuhcXNne6z2tc+0Im+MrwTUu6BM69EmUvTw0d8NEUtcHrtuFtKu3kLQoXO6cX0mjf8PithEDy/Dwk9WG6jEFpDYL0xLhRvOkOWEscZEdSSDT4GH1InKoy6hfXGyyKHNW03EEidM7HJuYnqf28vqI6kQIsgZ++J6hhc= Received: from DUZPR01CA0006.eurprd01.prod.exchangelabs.com (2603:10a6:10:3c3::13) by GV1P190MB1946.EURP190.PROD.OUTLOOK.COM (2603:10a6:150:55::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21; Wed, 30 Oct 2024 21:40:52 +0000 Received: from DU2PEPF00028D13.eurprd03.prod.outlook.com (2603:10a6:10:3c3:cafe::eb) by DUZPR01CA0006.outlook.office365.com (2603:10a6:10:3c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20 via Frontend Transport; Wed, 30 Oct 2024 21:40:52 +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 DU2PEPF00028D13.mail.protection.outlook.com (10.167.242.27) with Microsoft SMTP Server id 15.20.8114.16 via Frontend Transport; Wed, 30 Oct 2024 21:40:52 +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, Danylo Vodopianov Subject: [PATCH v5 61/80] net/ntnic: add xStats Date: Wed, 30 Oct 2024 22:39:08 +0100 Message-ID: <20241030213940.3470062-62-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241030213940.3470062-1-sil-plv@napatech.com> References: <20241021210527.2075431-1-sil-plv@napatech.com> <20241030213940.3470062-1-sil-plv@napatech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D13:EE_|GV1P190MB1946:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: f1f696e9-c59c-4589-1253-08dcf92b8703 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?GyuHR3KpNv5QvU+ESOhcviHz2FW4eRL0Sv38AlbiAa/e4Zgbh65qeP3H5Yqo?= =?us-ascii?Q?x3gGmfn3+nGKpaN70pRFF5yQgwTeFyehQ5rvzXTsHG5hQQZE/eA3iogN70hk?= =?us-ascii?Q?uslU6MW4TB5g3algoKTJsyS87BZD9mmG3uiGcoljsnzjTVjb7iMfVtcMbk1Q?= =?us-ascii?Q?adcdAuxjvNahAmckt6r0ZisyZd9LMTKsxBBuNHBpuc1LqZfC3c3R2qbII2mY?= =?us-ascii?Q?jnHI5sE9+u9c0LwBz/wR1ZZqQlTunm4TK0XSpPKrqtUYujU8f1UBBst+xrm9?= =?us-ascii?Q?/ZHIqwjGFwiGJPcjmyYmoy38LNxrR1tLtQbJCfYa5MC9Qc1nKBTVOokeopFV?= =?us-ascii?Q?vhSmWC4h7d/sKzdDd7DmlWUj4/4xQCzsrO1qSl5kkvjdYEnzBk21SmVnFwld?= =?us-ascii?Q?6rt8N1YVes8uFJr/GY6goev9fOMkUSO+WrV+TGjeeT6A/0y+Q5LsI3B0eKl/?= =?us-ascii?Q?t+D14eef4w/949wFX59RkLHdxUioXNaUECQGS6MzmSL4apv7SUWrrcDueH6+?= =?us-ascii?Q?GBOk0EKft0fOuDhqreTdxPcRzt7hJcnvSwILrO8DwYSdRLgajoxJ645H2Xiw?= =?us-ascii?Q?HFCSfH3sSPsS9oqdoD+GkmlVqmLsKRcbktu/EOGOZbis8mE4oZrRJvjrZEuf?= =?us-ascii?Q?BOyZdtAf2iRa5osE7wj7nHzyKQMNrKPbdqQwRqEAzzMXKKqmI37luhy4hRMF?= =?us-ascii?Q?b6Zwpb/30ncYDdjSL+B6QhOKd10hBCDNcyeroVmvek6YUOg85AISzNdYnWwB?= =?us-ascii?Q?vBr3v7AQO1yDg0NcqYRNDRWApU/wasEgcq5zsjE75cWoKWwjGXSoNTmoG8/+?= =?us-ascii?Q?8pA1SvPpU5NildJYasr1YrahgvAD8t7/a6LMEIgLYNccDAGbEaygGu7LgTyY?= =?us-ascii?Q?KSn+StDkTvVFrRbb4OJroRzlER8pvUeaYlleQTDgZWVCsi618Yn7RQYHVDKn?= =?us-ascii?Q?X3Va6JYsAJsKLnSfnaCnRWEO6ChC0c+k4tnkMsqTP60TlY9Zw1O2sjqpV+E0?= =?us-ascii?Q?lY7dpJ78U7woniyBN9DPxLtXNmyIXQP0YoYBo2jCJfje7VWwZfHL3FE48VG9?= =?us-ascii?Q?S+A79VJl7GFULZbbkjtzDgggmc4Zcins9HMjkc8k5Tsb9+vy2ZtCgi4K3r8B?= =?us-ascii?Q?qFyiuMy6OCTWVZyOJftO3Pg7+jc3l4kZZYcOWw4BeqfEWX8ucWTK9RuhcHEI?= =?us-ascii?Q?y32L2f9YC5wPoD72fuhPh0oNWNCkF4x42nrxwSvJ4unPIZPiRyBVzJn6GWuY?= =?us-ascii?Q?ii4UYAcy2NNgIHyuD0wnCiHOJuZ0M1zEomzC4XecXvw0h9q/Bw1Ef2oVRDSY?= =?us-ascii?Q?h6AXxDgV5C94VtV50ZY6+ZRV8kUi4mIc7+0A3IELllDEvLZf/lAvepiXoXWJ?= =?us-ascii?Q?E2cikUW/uLSaJ1wToqYik7oWGERiT7RLYlnAGQCa14onTfWq3A=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: gej+Sv5RLTsWUueImXVwy+FmJgZUIAcL08/CfUHjqeuJNomN/aqyDRCLqnpcVR66u4+WxZCMS18LI6xs6iExVk8rHO3yxwl8LZJ0bvsYngob2rxrdB47lyVGcM4jFYiDCYGfnOm9m/2mEUVPUaPqWyiFD1J3T2IoG4+FcVDjgOY6HOxhcLRM9B5gyzITBMhNtU9TTKBptausEkshyZz8MmKUvolnCsjRy1KvcpjmKHA/saIPXSGmd6DKPTtXjj2PncM9LSpllXRebfqQ5NatElqKX9iQfrThN+EKcKZox2+xQdB9b2wRjVGBnt9S5vOXdMMIoSaBgRj0SzWdCnXrlcaOCOfHYuF/oox9sjUsVv8Q941equG1JnurjHK9n03AW4X0ZRr/GNSTnf/HBjWpOUMmcB2lejpCAmMoJaMKkAdmqWgkofJhQ9gG1/5jqsaf9DXHhJaTEHmR6nRD6uTsKtaXiObJKzqtXzGf2Mttz1lp7mVmqc5D1Rq6+CdkQtNJrAj3Tsda6Fh2XC/Vt4YQ/Rp2MJ7JkjSgeQYMJdflnPRXjdusBbyjnIdygZd8Ql7zEhiHdomuOCp3Ei1KinLvN8zMROvtfjwIocK7HV6RLT40Ci5DWu9HCm4QAjgdatjkC1LJAR6wFxal1VJdBlL4o5U9CNj0pJGTzA2ABVHxtj4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 21:40:52.0834 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f1f696e9-c59c-4589-1253-08dcf92b8703 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: DU2PEPF00028D13.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1P190MB1946 X-OriginatorOrg: napatech.com X-BESS-ID: 1730330001-312176-12708-43869-1 X-BESS-VER: 2019.1_20241018.1852 X-BESS-Apparent-Source-IP: 104.47.18.110 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVsaW5qYWQGYGUNQwKTnVyMAsxc jUwCItMS3JxDDF3NIgLdUyNck42SDVQqk2FgCzCjExQgAAAA== X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.260092 [from cloudscan15-25.eu-central-1a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS113687 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, 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 From: Danylo Vodopianov Extended statistics implementation and initialization were added. Extended set of operations for eth dev with xstats support. Signed-off-by: Danylo Vodopianov --- doc/guides/nics/features/ntnic.ini | 1 + doc/guides/nics/ntnic.rst | 2 + drivers/net/ntnic/include/ntnic_stat.h | 36 + drivers/net/ntnic/meson.build | 1 + drivers/net/ntnic/ntnic_ethdev.c | 112 +++ drivers/net/ntnic/ntnic_mod_reg.c | 15 + drivers/net/ntnic/ntnic_mod_reg.h | 28 + drivers/net/ntnic/ntnic_xstats/ntnic_xstats.c | 829 ++++++++++++++++++ 8 files changed, 1024 insertions(+) create mode 100644 drivers/net/ntnic/ntnic_xstats/ntnic_xstats.c diff --git a/doc/guides/nics/features/ntnic.ini b/doc/guides/nics/features/ntnic.ini index 64351bcdc7..947c7ba3a1 100644 --- a/doc/guides/nics/features/ntnic.ini +++ b/doc/guides/nics/features/ntnic.ini @@ -13,6 +13,7 @@ Multicast MAC filter = Y RSS hash = Y RSS key update = Y Basic stats = Y +Extended stats = Y Linux = Y x86-64 = Y diff --git a/doc/guides/nics/ntnic.rst b/doc/guides/nics/ntnic.rst index 6e3a290a5c..bae27ce1ce 100644 --- a/doc/guides/nics/ntnic.rst +++ b/doc/guides/nics/ntnic.rst @@ -64,6 +64,8 @@ Features - Several RSS hash keys, one for each flow type. - Default RSS operation with no hash key specification. - Port and queue statistics. +- RMON statistics in extended stats. +- Link state information. Limitations ~~~~~~~~~~~ diff --git a/drivers/net/ntnic/include/ntnic_stat.h b/drivers/net/ntnic/include/ntnic_stat.h index 0735dbc085..4d4affa3cf 100644 --- a/drivers/net/ntnic/include/ntnic_stat.h +++ b/drivers/net/ntnic/include/ntnic_stat.h @@ -169,6 +169,39 @@ struct port_counters_v2 { }; struct flm_counters_v1 { + /* FLM 0.17 */ + uint64_t current; + uint64_t learn_done; + uint64_t learn_ignore; + uint64_t learn_fail; + uint64_t unlearn_done; + uint64_t unlearn_ignore; + uint64_t auto_unlearn_done; + uint64_t auto_unlearn_ignore; + uint64_t auto_unlearn_fail; + uint64_t timeout_unlearn_done; + uint64_t rel_done; + uint64_t rel_ignore; + /* FLM 0.20 */ + uint64_t prb_done; + uint64_t prb_ignore; + uint64_t sta_done; + uint64_t inf_done; + uint64_t inf_skip; + uint64_t pck_hit; + uint64_t pck_miss; + uint64_t pck_unh; + uint64_t pck_dis; + uint64_t csh_hit; + uint64_t csh_miss; + uint64_t csh_unh; + uint64_t cuc_start; + uint64_t cuc_move; + /* FLM 0.17 Load */ + uint64_t load_lps; + uint64_t load_aps; + uint64_t max_lps; + uint64_t max_aps; }; struct nt4ga_stat_s { @@ -200,6 +233,9 @@ struct nt4ga_stat_s { struct host_buffer_counters *mp_stat_structs_hb; struct port_load_counters *mp_port_load; + int flm_stat_ver; + struct flm_counters_v1 *mp_stat_structs_flm; + /* Rx/Tx totals: */ uint64_t n_totals_reset_timestamp; /* timestamp for last totals reset */ diff --git a/drivers/net/ntnic/meson.build b/drivers/net/ntnic/meson.build index a6c4fec0be..e59ac5bdb3 100644 --- a/drivers/net/ntnic/meson.build +++ b/drivers/net/ntnic/meson.build @@ -31,6 +31,7 @@ sources = files( 'link_mgmt/nt4ga_link.c', 'nim/i2c_nim.c', 'ntnic_filter/ntnic_filter.c', + 'ntnic_xstats/ntnic_xstats.c', 'nthw/dbs/nthw_dbs.c', 'nthw/supported/nthw_fpga_9563_055_049_0000.c', 'nthw/supported/nthw_fpga_instances.c', diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c index 8a9ca2c03d..5635bd3b42 100644 --- a/drivers/net/ntnic/ntnic_ethdev.c +++ b/drivers/net/ntnic/ntnic_ethdev.c @@ -1496,6 +1496,113 @@ static int dev_flow_ops_get(struct rte_eth_dev *dev __rte_unused, const struct r return 0; } +static int eth_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *stats, unsigned int n) +{ + struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private; + struct drv_s *p_drv = internals->p_drv; + ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv; + nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat; + int if_index = internals->n_intf_no; + int nb_xstats; + + const struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops(); + + if (ntnic_xstats_ops == NULL) { + NT_LOG(INF, NTNIC, "ntnic_xstats module not included"); + return -1; + } + + pthread_mutex_lock(&p_nt_drv->stat_lck); + nb_xstats = ntnic_xstats_ops->nthw_xstats_get(p_nt4ga_stat, stats, n, if_index); + pthread_mutex_unlock(&p_nt_drv->stat_lck); + return nb_xstats; +} + +static int eth_xstats_get_by_id(struct rte_eth_dev *eth_dev, + const uint64_t *ids, + uint64_t *values, + unsigned int n) +{ + struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private; + struct drv_s *p_drv = internals->p_drv; + ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv; + nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat; + int if_index = internals->n_intf_no; + int nb_xstats; + + const struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops(); + + if (ntnic_xstats_ops == NULL) { + NT_LOG(INF, NTNIC, "ntnic_xstats module not included"); + return -1; + } + + pthread_mutex_lock(&p_nt_drv->stat_lck); + nb_xstats = + ntnic_xstats_ops->nthw_xstats_get_by_id(p_nt4ga_stat, ids, values, n, if_index); + pthread_mutex_unlock(&p_nt_drv->stat_lck); + return nb_xstats; +} + +static int eth_xstats_reset(struct rte_eth_dev *eth_dev) +{ + struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private; + struct drv_s *p_drv = internals->p_drv; + ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv; + nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat; + int if_index = internals->n_intf_no; + + struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops(); + + if (ntnic_xstats_ops == NULL) { + NT_LOG(INF, NTNIC, "ntnic_xstats module not included"); + return -1; + } + + pthread_mutex_lock(&p_nt_drv->stat_lck); + ntnic_xstats_ops->nthw_xstats_reset(p_nt4ga_stat, if_index); + pthread_mutex_unlock(&p_nt_drv->stat_lck); + return dpdk_stats_reset(internals, p_nt_drv, if_index); +} + +static int eth_xstats_get_names(struct rte_eth_dev *eth_dev, + struct rte_eth_xstat_name *xstats_names, unsigned int size) +{ + struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private; + struct drv_s *p_drv = internals->p_drv; + ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv; + nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat; + + const struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops(); + + if (ntnic_xstats_ops == NULL) { + NT_LOG(INF, NTNIC, "ntnic_xstats module not included"); + return -1; + } + + return ntnic_xstats_ops->nthw_xstats_get_names(p_nt4ga_stat, xstats_names, size); +} + +static int eth_xstats_get_names_by_id(struct rte_eth_dev *eth_dev, + const uint64_t *ids, + struct rte_eth_xstat_name *xstats_names, + unsigned int size) +{ + struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private; + struct drv_s *p_drv = internals->p_drv; + ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv; + nt4ga_stat_t *p_nt4ga_stat = &p_nt_drv->adapter_info.nt4ga_stat; + const struct ntnic_xstats_ops *ntnic_xstats_ops = get_ntnic_xstats_ops(); + + if (ntnic_xstats_ops == NULL) { + NT_LOG(INF, NTNIC, "ntnic_xstats module not included"); + return -1; + } + + return ntnic_xstats_ops->nthw_xstats_get_names_by_id(p_nt4ga_stat, xstats_names, ids, + size); +} + static int promiscuous_enable(struct rte_eth_dev __rte_unused(*dev)) { @@ -1592,6 +1699,11 @@ static const struct eth_dev_ops nthw_eth_dev_ops = { .mac_addr_set = eth_mac_addr_set, .set_mc_addr_list = eth_set_mc_addr_list, .flow_ops_get = dev_flow_ops_get, + .xstats_get = eth_xstats_get, + .xstats_get_names = eth_xstats_get_names, + .xstats_reset = eth_xstats_reset, + .xstats_get_by_id = eth_xstats_get_by_id, + .xstats_get_names_by_id = eth_xstats_get_names_by_id, .promiscuous_enable = promiscuous_enable, .rss_hash_update = eth_dev_rss_hash_update, .rss_hash_conf_get = rss_hash_conf_get, diff --git a/drivers/net/ntnic/ntnic_mod_reg.c b/drivers/net/ntnic/ntnic_mod_reg.c index 355e2032b1..6737d18a6f 100644 --- a/drivers/net/ntnic/ntnic_mod_reg.c +++ b/drivers/net/ntnic/ntnic_mod_reg.c @@ -192,3 +192,18 @@ const struct rte_flow_ops *get_dev_flow_ops(void) return dev_flow_ops; } + +static struct ntnic_xstats_ops *ntnic_xstats_ops; + +void register_ntnic_xstats_ops(struct ntnic_xstats_ops *ops) +{ + ntnic_xstats_ops = ops; +} + +struct ntnic_xstats_ops *get_ntnic_xstats_ops(void) +{ + if (ntnic_xstats_ops == NULL) + ntnic_xstats_ops_init(); + + return ntnic_xstats_ops; +} diff --git a/drivers/net/ntnic/ntnic_mod_reg.h b/drivers/net/ntnic/ntnic_mod_reg.h index 8703d478b6..65e7972c68 100644 --- a/drivers/net/ntnic/ntnic_mod_reg.h +++ b/drivers/net/ntnic/ntnic_mod_reg.h @@ -7,6 +7,10 @@ #define __NTNIC_MOD_REG_H__ #include + +#include "rte_ethdev.h" +#include "rte_flow_driver.h" + #include "flow_api.h" #include "stream_binary_flow_api.h" #include "nthw_fpga_model.h" @@ -354,4 +358,28 @@ void register_flow_filter_ops(const struct flow_filter_ops *ops); const struct flow_filter_ops *get_flow_filter_ops(void); void init_flow_filter(void); +struct ntnic_xstats_ops { + int (*nthw_xstats_get_names)(nt4ga_stat_t *p_nt4ga_stat, + struct rte_eth_xstat_name *xstats_names, + unsigned int size); + int (*nthw_xstats_get)(nt4ga_stat_t *p_nt4ga_stat, + struct rte_eth_xstat *stats, + unsigned int n, + uint8_t port); + void (*nthw_xstats_reset)(nt4ga_stat_t *p_nt4ga_stat, uint8_t port); + int (*nthw_xstats_get_names_by_id)(nt4ga_stat_t *p_nt4ga_stat, + struct rte_eth_xstat_name *xstats_names, + const uint64_t *ids, + unsigned int size); + int (*nthw_xstats_get_by_id)(nt4ga_stat_t *p_nt4ga_stat, + const uint64_t *ids, + uint64_t *values, + unsigned int n, + uint8_t port); +}; + +void register_ntnic_xstats_ops(struct ntnic_xstats_ops *ops); +struct ntnic_xstats_ops *get_ntnic_xstats_ops(void); +void ntnic_xstats_ops_init(void); + #endif /* __NTNIC_MOD_REG_H__ */ diff --git a/drivers/net/ntnic/ntnic_xstats/ntnic_xstats.c b/drivers/net/ntnic/ntnic_xstats/ntnic_xstats.c new file mode 100644 index 0000000000..7604afe6a0 --- /dev/null +++ b/drivers/net/ntnic/ntnic_xstats/ntnic_xstats.c @@ -0,0 +1,829 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#include + +#include "include/ntdrv_4ga.h" +#include "ntlog.h" +#include "nthw_drv.h" +#include "nthw_fpga.h" +#include "stream_binary_flow_api.h" +#include "ntnic_mod_reg.h" + +struct rte_nthw_xstats_names_s { + char name[RTE_ETH_XSTATS_NAME_SIZE]; + uint8_t source; + unsigned int offset; +}; + +/* + * Extended stat for Capture/Inline - implements RMON + * FLM 0.17 + */ +static struct rte_nthw_xstats_names_s nthw_cap_xstats_names_v1[] = { + { "rx_drop_events", 1, offsetof(struct port_counters_v2, drop_events) }, + { "rx_octets", 1, offsetof(struct port_counters_v2, octets) }, + { "rx_packets", 1, offsetof(struct port_counters_v2, pkts) }, + { "rx_broadcast_packets", 1, offsetof(struct port_counters_v2, broadcast_pkts) }, + { "rx_multicast_packets", 1, offsetof(struct port_counters_v2, multicast_pkts) }, + { "rx_unicast_packets", 1, offsetof(struct port_counters_v2, unicast_pkts) }, + { "rx_align_errors", 1, offsetof(struct port_counters_v2, pkts_alignment) }, + { "rx_code_violation_errors", 1, offsetof(struct port_counters_v2, pkts_code_violation) }, + { "rx_crc_errors", 1, offsetof(struct port_counters_v2, pkts_crc) }, + { "rx_undersize_packets", 1, offsetof(struct port_counters_v2, undersize_pkts) }, + { "rx_oversize_packets", 1, offsetof(struct port_counters_v2, oversize_pkts) }, + { "rx_fragments", 1, offsetof(struct port_counters_v2, fragments) }, + { + "rx_jabbers_not_truncated", 1, + offsetof(struct port_counters_v2, jabbers_not_truncated) + }, + { "rx_jabbers_truncated", 1, offsetof(struct port_counters_v2, jabbers_truncated) }, + { "rx_size_64_packets", 1, offsetof(struct port_counters_v2, pkts_64_octets) }, + { + "rx_size_65_to_127_packets", 1, + offsetof(struct port_counters_v2, pkts_65_to_127_octets) + }, + { + "rx_size_128_to_255_packets", 1, + offsetof(struct port_counters_v2, pkts_128_to_255_octets) + }, + { + "rx_size_256_to_511_packets", 1, + offsetof(struct port_counters_v2, pkts_256_to_511_octets) + }, + { + "rx_size_512_to_1023_packets", 1, + offsetof(struct port_counters_v2, pkts_512_to_1023_octets) + }, + { + "rx_size_1024_to_1518_packets", 1, + offsetof(struct port_counters_v2, pkts_1024_to_1518_octets) + }, + { + "rx_size_1519_to_2047_packets", 1, + offsetof(struct port_counters_v2, pkts_1519_to_2047_octets) + }, + { + "rx_size_2048_to_4095_packets", 1, + offsetof(struct port_counters_v2, pkts_2048_to_4095_octets) + }, + { + "rx_size_4096_to_8191_packets", 1, + offsetof(struct port_counters_v2, pkts_4096_to_8191_octets) + }, + { + "rx_size_8192_to_max_packets", 1, + offsetof(struct port_counters_v2, pkts_8192_to_max_octets) + }, + { "rx_ip_checksum_error", 1, offsetof(struct port_counters_v2, pkts_ip_chksum_error) }, + { "rx_udp_checksum_error", 1, offsetof(struct port_counters_v2, pkts_udp_chksum_error) }, + { "rx_tcp_checksum_error", 1, offsetof(struct port_counters_v2, pkts_tcp_chksum_error) }, + + { "tx_drop_events", 2, offsetof(struct port_counters_v2, drop_events) }, + { "tx_octets", 2, offsetof(struct port_counters_v2, octets) }, + { "tx_packets", 2, offsetof(struct port_counters_v2, pkts) }, + { "tx_broadcast_packets", 2, offsetof(struct port_counters_v2, broadcast_pkts) }, + { "tx_multicast_packets", 2, offsetof(struct port_counters_v2, multicast_pkts) }, + { "tx_unicast_packets", 2, offsetof(struct port_counters_v2, unicast_pkts) }, + { "tx_align_errors", 2, offsetof(struct port_counters_v2, pkts_alignment) }, + { "tx_code_violation_errors", 2, offsetof(struct port_counters_v2, pkts_code_violation) }, + { "tx_crc_errors", 2, offsetof(struct port_counters_v2, pkts_crc) }, + { "tx_undersize_packets", 2, offsetof(struct port_counters_v2, undersize_pkts) }, + { "tx_oversize_packets", 2, offsetof(struct port_counters_v2, oversize_pkts) }, + { "tx_fragments", 2, offsetof(struct port_counters_v2, fragments) }, + { + "tx_jabbers_not_truncated", 2, + offsetof(struct port_counters_v2, jabbers_not_truncated) + }, + { "tx_jabbers_truncated", 2, offsetof(struct port_counters_v2, jabbers_truncated) }, + { "tx_size_64_packets", 2, offsetof(struct port_counters_v2, pkts_64_octets) }, + { + "tx_size_65_to_127_packets", 2, + offsetof(struct port_counters_v2, pkts_65_to_127_octets) + }, + { + "tx_size_128_to_255_packets", 2, + offsetof(struct port_counters_v2, pkts_128_to_255_octets) + }, + { + "tx_size_256_to_511_packets", 2, + offsetof(struct port_counters_v2, pkts_256_to_511_octets) + }, + { + "tx_size_512_to_1023_packets", 2, + offsetof(struct port_counters_v2, pkts_512_to_1023_octets) + }, + { + "tx_size_1024_to_1518_packets", 2, + offsetof(struct port_counters_v2, pkts_1024_to_1518_octets) + }, + { + "tx_size_1519_to_2047_packets", 2, + offsetof(struct port_counters_v2, pkts_1519_to_2047_octets) + }, + { + "tx_size_2048_to_4095_packets", 2, + offsetof(struct port_counters_v2, pkts_2048_to_4095_octets) + }, + { + "tx_size_4096_to_8191_packets", 2, + offsetof(struct port_counters_v2, pkts_4096_to_8191_octets) + }, + { + "tx_size_8192_to_max_packets", 2, + offsetof(struct port_counters_v2, pkts_8192_to_max_octets) + }, + + /* FLM 0.17 */ + { "flm_count_current", 3, offsetof(struct flm_counters_v1, current) }, + { "flm_count_learn_done", 3, offsetof(struct flm_counters_v1, learn_done) }, + { "flm_count_learn_ignore", 3, offsetof(struct flm_counters_v1, learn_ignore) }, + { "flm_count_learn_fail", 3, offsetof(struct flm_counters_v1, learn_fail) }, + { "flm_count_unlearn_done", 3, offsetof(struct flm_counters_v1, unlearn_done) }, + { "flm_count_unlearn_ignore", 3, offsetof(struct flm_counters_v1, unlearn_ignore) }, + { "flm_count_auto_unlearn_done", 3, offsetof(struct flm_counters_v1, auto_unlearn_done) }, + { + "flm_count_auto_unlearn_ignore", 3, + offsetof(struct flm_counters_v1, auto_unlearn_ignore) + }, + { "flm_count_auto_unlearn_fail", 3, offsetof(struct flm_counters_v1, auto_unlearn_fail) }, + { + "flm_count_timeout_unlearn_done", 3, + offsetof(struct flm_counters_v1, timeout_unlearn_done) + }, + { "flm_count_rel_done", 3, offsetof(struct flm_counters_v1, rel_done) }, + { "flm_count_rel_ignore", 3, offsetof(struct flm_counters_v1, rel_ignore) }, + { "flm_count_prb_done", 3, offsetof(struct flm_counters_v1, prb_done) }, + { "flm_count_prb_ignore", 3, offsetof(struct flm_counters_v1, prb_ignore) } +}; + +/* + * Extended stat for Capture/Inline - implements RMON + * FLM 0.18 + */ +static struct rte_nthw_xstats_names_s nthw_cap_xstats_names_v2[] = { + { "rx_drop_events", 1, offsetof(struct port_counters_v2, drop_events) }, + { "rx_octets", 1, offsetof(struct port_counters_v2, octets) }, + { "rx_packets", 1, offsetof(struct port_counters_v2, pkts) }, + { "rx_broadcast_packets", 1, offsetof(struct port_counters_v2, broadcast_pkts) }, + { "rx_multicast_packets", 1, offsetof(struct port_counters_v2, multicast_pkts) }, + { "rx_unicast_packets", 1, offsetof(struct port_counters_v2, unicast_pkts) }, + { "rx_align_errors", 1, offsetof(struct port_counters_v2, pkts_alignment) }, + { "rx_code_violation_errors", 1, offsetof(struct port_counters_v2, pkts_code_violation) }, + { "rx_crc_errors", 1, offsetof(struct port_counters_v2, pkts_crc) }, + { "rx_undersize_packets", 1, offsetof(struct port_counters_v2, undersize_pkts) }, + { "rx_oversize_packets", 1, offsetof(struct port_counters_v2, oversize_pkts) }, + { "rx_fragments", 1, offsetof(struct port_counters_v2, fragments) }, + { + "rx_jabbers_not_truncated", 1, + offsetof(struct port_counters_v2, jabbers_not_truncated) + }, + { "rx_jabbers_truncated", 1, offsetof(struct port_counters_v2, jabbers_truncated) }, + { "rx_size_64_packets", 1, offsetof(struct port_counters_v2, pkts_64_octets) }, + { + "rx_size_65_to_127_packets", 1, + offsetof(struct port_counters_v2, pkts_65_to_127_octets) + }, + { + "rx_size_128_to_255_packets", 1, + offsetof(struct port_counters_v2, pkts_128_to_255_octets) + }, + { + "rx_size_256_to_511_packets", 1, + offsetof(struct port_counters_v2, pkts_256_to_511_octets) + }, + { + "rx_size_512_to_1023_packets", 1, + offsetof(struct port_counters_v2, pkts_512_to_1023_octets) + }, + { + "rx_size_1024_to_1518_packets", 1, + offsetof(struct port_counters_v2, pkts_1024_to_1518_octets) + }, + { + "rx_size_1519_to_2047_packets", 1, + offsetof(struct port_counters_v2, pkts_1519_to_2047_octets) + }, + { + "rx_size_2048_to_4095_packets", 1, + offsetof(struct port_counters_v2, pkts_2048_to_4095_octets) + }, + { + "rx_size_4096_to_8191_packets", 1, + offsetof(struct port_counters_v2, pkts_4096_to_8191_octets) + }, + { + "rx_size_8192_to_max_packets", 1, + offsetof(struct port_counters_v2, pkts_8192_to_max_octets) + }, + { "rx_ip_checksum_error", 1, offsetof(struct port_counters_v2, pkts_ip_chksum_error) }, + { "rx_udp_checksum_error", 1, offsetof(struct port_counters_v2, pkts_udp_chksum_error) }, + { "rx_tcp_checksum_error", 1, offsetof(struct port_counters_v2, pkts_tcp_chksum_error) }, + + { "tx_drop_events", 2, offsetof(struct port_counters_v2, drop_events) }, + { "tx_octets", 2, offsetof(struct port_counters_v2, octets) }, + { "tx_packets", 2, offsetof(struct port_counters_v2, pkts) }, + { "tx_broadcast_packets", 2, offsetof(struct port_counters_v2, broadcast_pkts) }, + { "tx_multicast_packets", 2, offsetof(struct port_counters_v2, multicast_pkts) }, + { "tx_unicast_packets", 2, offsetof(struct port_counters_v2, unicast_pkts) }, + { "tx_align_errors", 2, offsetof(struct port_counters_v2, pkts_alignment) }, + { "tx_code_violation_errors", 2, offsetof(struct port_counters_v2, pkts_code_violation) }, + { "tx_crc_errors", 2, offsetof(struct port_counters_v2, pkts_crc) }, + { "tx_undersize_packets", 2, offsetof(struct port_counters_v2, undersize_pkts) }, + { "tx_oversize_packets", 2, offsetof(struct port_counters_v2, oversize_pkts) }, + { "tx_fragments", 2, offsetof(struct port_counters_v2, fragments) }, + { + "tx_jabbers_not_truncated", 2, + offsetof(struct port_counters_v2, jabbers_not_truncated) + }, + { "tx_jabbers_truncated", 2, offsetof(struct port_counters_v2, jabbers_truncated) }, + { "tx_size_64_packets", 2, offsetof(struct port_counters_v2, pkts_64_octets) }, + { + "tx_size_65_to_127_packets", 2, + offsetof(struct port_counters_v2, pkts_65_to_127_octets) + }, + { + "tx_size_128_to_255_packets", 2, + offsetof(struct port_counters_v2, pkts_128_to_255_octets) + }, + { + "tx_size_256_to_511_packets", 2, + offsetof(struct port_counters_v2, pkts_256_to_511_octets) + }, + { + "tx_size_512_to_1023_packets", 2, + offsetof(struct port_counters_v2, pkts_512_to_1023_octets) + }, + { + "tx_size_1024_to_1518_packets", 2, + offsetof(struct port_counters_v2, pkts_1024_to_1518_octets) + }, + { + "tx_size_1519_to_2047_packets", 2, + offsetof(struct port_counters_v2, pkts_1519_to_2047_octets) + }, + { + "tx_size_2048_to_4095_packets", 2, + offsetof(struct port_counters_v2, pkts_2048_to_4095_octets) + }, + { + "tx_size_4096_to_8191_packets", 2, + offsetof(struct port_counters_v2, pkts_4096_to_8191_octets) + }, + { + "tx_size_8192_to_max_packets", 2, + offsetof(struct port_counters_v2, pkts_8192_to_max_octets) + }, + + /* FLM 0.17 */ + { "flm_count_current", 3, offsetof(struct flm_counters_v1, current) }, + { "flm_count_learn_done", 3, offsetof(struct flm_counters_v1, learn_done) }, + { "flm_count_learn_ignore", 3, offsetof(struct flm_counters_v1, learn_ignore) }, + { "flm_count_learn_fail", 3, offsetof(struct flm_counters_v1, learn_fail) }, + { "flm_count_unlearn_done", 3, offsetof(struct flm_counters_v1, unlearn_done) }, + { "flm_count_unlearn_ignore", 3, offsetof(struct flm_counters_v1, unlearn_ignore) }, + { "flm_count_auto_unlearn_done", 3, offsetof(struct flm_counters_v1, auto_unlearn_done) }, + { + "flm_count_auto_unlearn_ignore", 3, + offsetof(struct flm_counters_v1, auto_unlearn_ignore) + }, + { "flm_count_auto_unlearn_fail", 3, offsetof(struct flm_counters_v1, auto_unlearn_fail) }, + { + "flm_count_timeout_unlearn_done", 3, + offsetof(struct flm_counters_v1, timeout_unlearn_done) + }, + { "flm_count_rel_done", 3, offsetof(struct flm_counters_v1, rel_done) }, + { "flm_count_rel_ignore", 3, offsetof(struct flm_counters_v1, rel_ignore) }, + { "flm_count_prb_done", 3, offsetof(struct flm_counters_v1, prb_done) }, + { "flm_count_prb_ignore", 3, offsetof(struct flm_counters_v1, prb_ignore) }, + + /* FLM 0.20 */ + { "flm_count_sta_done", 3, offsetof(struct flm_counters_v1, sta_done) }, + { "flm_count_inf_done", 3, offsetof(struct flm_counters_v1, inf_done) }, + { "flm_count_inf_skip", 3, offsetof(struct flm_counters_v1, inf_skip) }, + { "flm_count_pck_hit", 3, offsetof(struct flm_counters_v1, pck_hit) }, + { "flm_count_pck_miss", 3, offsetof(struct flm_counters_v1, pck_miss) }, + { "flm_count_pck_unh", 3, offsetof(struct flm_counters_v1, pck_unh) }, + { "flm_count_pck_dis", 3, offsetof(struct flm_counters_v1, pck_dis) }, + { "flm_count_csh_hit", 3, offsetof(struct flm_counters_v1, csh_hit) }, + { "flm_count_csh_miss", 3, offsetof(struct flm_counters_v1, csh_miss) }, + { "flm_count_csh_unh", 3, offsetof(struct flm_counters_v1, csh_unh) }, + { "flm_count_cuc_start", 3, offsetof(struct flm_counters_v1, cuc_start) }, + { "flm_count_cuc_move", 3, offsetof(struct flm_counters_v1, cuc_move) } +}; + +/* + * Extended stat for Capture/Inline - implements RMON + * STA 0.9 + */ + +static struct rte_nthw_xstats_names_s nthw_cap_xstats_names_v3[] = { + { "rx_drop_events", 1, offsetof(struct port_counters_v2, drop_events) }, + { "rx_octets", 1, offsetof(struct port_counters_v2, octets) }, + { "rx_packets", 1, offsetof(struct port_counters_v2, pkts) }, + { "rx_broadcast_packets", 1, offsetof(struct port_counters_v2, broadcast_pkts) }, + { "rx_multicast_packets", 1, offsetof(struct port_counters_v2, multicast_pkts) }, + { "rx_unicast_packets", 1, offsetof(struct port_counters_v2, unicast_pkts) }, + { "rx_align_errors", 1, offsetof(struct port_counters_v2, pkts_alignment) }, + { "rx_code_violation_errors", 1, offsetof(struct port_counters_v2, pkts_code_violation) }, + { "rx_crc_errors", 1, offsetof(struct port_counters_v2, pkts_crc) }, + { "rx_undersize_packets", 1, offsetof(struct port_counters_v2, undersize_pkts) }, + { "rx_oversize_packets", 1, offsetof(struct port_counters_v2, oversize_pkts) }, + { "rx_fragments", 1, offsetof(struct port_counters_v2, fragments) }, + { + "rx_jabbers_not_truncated", 1, + offsetof(struct port_counters_v2, jabbers_not_truncated) + }, + { "rx_jabbers_truncated", 1, offsetof(struct port_counters_v2, jabbers_truncated) }, + { "rx_size_64_packets", 1, offsetof(struct port_counters_v2, pkts_64_octets) }, + { + "rx_size_65_to_127_packets", 1, + offsetof(struct port_counters_v2, pkts_65_to_127_octets) + }, + { + "rx_size_128_to_255_packets", 1, + offsetof(struct port_counters_v2, pkts_128_to_255_octets) + }, + { + "rx_size_256_to_511_packets", 1, + offsetof(struct port_counters_v2, pkts_256_to_511_octets) + }, + { + "rx_size_512_to_1023_packets", 1, + offsetof(struct port_counters_v2, pkts_512_to_1023_octets) + }, + { + "rx_size_1024_to_1518_packets", 1, + offsetof(struct port_counters_v2, pkts_1024_to_1518_octets) + }, + { + "rx_size_1519_to_2047_packets", 1, + offsetof(struct port_counters_v2, pkts_1519_to_2047_octets) + }, + { + "rx_size_2048_to_4095_packets", 1, + offsetof(struct port_counters_v2, pkts_2048_to_4095_octets) + }, + { + "rx_size_4096_to_8191_packets", 1, + offsetof(struct port_counters_v2, pkts_4096_to_8191_octets) + }, + { + "rx_size_8192_to_max_packets", 1, + offsetof(struct port_counters_v2, pkts_8192_to_max_octets) + }, + { "rx_ip_checksum_error", 1, offsetof(struct port_counters_v2, pkts_ip_chksum_error) }, + { "rx_udp_checksum_error", 1, offsetof(struct port_counters_v2, pkts_udp_chksum_error) }, + { "rx_tcp_checksum_error", 1, offsetof(struct port_counters_v2, pkts_tcp_chksum_error) }, + + { "tx_drop_events", 2, offsetof(struct port_counters_v2, drop_events) }, + { "tx_octets", 2, offsetof(struct port_counters_v2, octets) }, + { "tx_packets", 2, offsetof(struct port_counters_v2, pkts) }, + { "tx_broadcast_packets", 2, offsetof(struct port_counters_v2, broadcast_pkts) }, + { "tx_multicast_packets", 2, offsetof(struct port_counters_v2, multicast_pkts) }, + { "tx_unicast_packets", 2, offsetof(struct port_counters_v2, unicast_pkts) }, + { "tx_align_errors", 2, offsetof(struct port_counters_v2, pkts_alignment) }, + { "tx_code_violation_errors", 2, offsetof(struct port_counters_v2, pkts_code_violation) }, + { "tx_crc_errors", 2, offsetof(struct port_counters_v2, pkts_crc) }, + { "tx_undersize_packets", 2, offsetof(struct port_counters_v2, undersize_pkts) }, + { "tx_oversize_packets", 2, offsetof(struct port_counters_v2, oversize_pkts) }, + { "tx_fragments", 2, offsetof(struct port_counters_v2, fragments) }, + { + "tx_jabbers_not_truncated", 2, + offsetof(struct port_counters_v2, jabbers_not_truncated) + }, + { "tx_jabbers_truncated", 2, offsetof(struct port_counters_v2, jabbers_truncated) }, + { "tx_size_64_packets", 2, offsetof(struct port_counters_v2, pkts_64_octets) }, + { + "tx_size_65_to_127_packets", 2, + offsetof(struct port_counters_v2, pkts_65_to_127_octets) + }, + { + "tx_size_128_to_255_packets", 2, + offsetof(struct port_counters_v2, pkts_128_to_255_octets) + }, + { + "tx_size_256_to_511_packets", 2, + offsetof(struct port_counters_v2, pkts_256_to_511_octets) + }, + { + "tx_size_512_to_1023_packets", 2, + offsetof(struct port_counters_v2, pkts_512_to_1023_octets) + }, + { + "tx_size_1024_to_1518_packets", 2, + offsetof(struct port_counters_v2, pkts_1024_to_1518_octets) + }, + { + "tx_size_1519_to_2047_packets", 2, + offsetof(struct port_counters_v2, pkts_1519_to_2047_octets) + }, + { + "tx_size_2048_to_4095_packets", 2, + offsetof(struct port_counters_v2, pkts_2048_to_4095_octets) + }, + { + "tx_size_4096_to_8191_packets", 2, + offsetof(struct port_counters_v2, pkts_4096_to_8191_octets) + }, + { + "tx_size_8192_to_max_packets", 2, + offsetof(struct port_counters_v2, pkts_8192_to_max_octets) + }, + + /* FLM 0.17 */ + { "flm_count_current", 3, offsetof(struct flm_counters_v1, current) }, + { "flm_count_learn_done", 3, offsetof(struct flm_counters_v1, learn_done) }, + { "flm_count_learn_ignore", 3, offsetof(struct flm_counters_v1, learn_ignore) }, + { "flm_count_learn_fail", 3, offsetof(struct flm_counters_v1, learn_fail) }, + { "flm_count_unlearn_done", 3, offsetof(struct flm_counters_v1, unlearn_done) }, + { "flm_count_unlearn_ignore", 3, offsetof(struct flm_counters_v1, unlearn_ignore) }, + { "flm_count_auto_unlearn_done", 3, offsetof(struct flm_counters_v1, auto_unlearn_done) }, + { + "flm_count_auto_unlearn_ignore", 3, + offsetof(struct flm_counters_v1, auto_unlearn_ignore) + }, + { "flm_count_auto_unlearn_fail", 3, offsetof(struct flm_counters_v1, auto_unlearn_fail) }, + { + "flm_count_timeout_unlearn_done", 3, + offsetof(struct flm_counters_v1, timeout_unlearn_done) + }, + { "flm_count_rel_done", 3, offsetof(struct flm_counters_v1, rel_done) }, + { "flm_count_rel_ignore", 3, offsetof(struct flm_counters_v1, rel_ignore) }, + { "flm_count_prb_done", 3, offsetof(struct flm_counters_v1, prb_done) }, + { "flm_count_prb_ignore", 3, offsetof(struct flm_counters_v1, prb_ignore) }, + + /* FLM 0.20 */ + { "flm_count_sta_done", 3, offsetof(struct flm_counters_v1, sta_done) }, + { "flm_count_inf_done", 3, offsetof(struct flm_counters_v1, inf_done) }, + { "flm_count_inf_skip", 3, offsetof(struct flm_counters_v1, inf_skip) }, + { "flm_count_pck_hit", 3, offsetof(struct flm_counters_v1, pck_hit) }, + { "flm_count_pck_miss", 3, offsetof(struct flm_counters_v1, pck_miss) }, + { "flm_count_pck_unh", 3, offsetof(struct flm_counters_v1, pck_unh) }, + { "flm_count_pck_dis", 3, offsetof(struct flm_counters_v1, pck_dis) }, + { "flm_count_csh_hit", 3, offsetof(struct flm_counters_v1, csh_hit) }, + { "flm_count_csh_miss", 3, offsetof(struct flm_counters_v1, csh_miss) }, + { "flm_count_csh_unh", 3, offsetof(struct flm_counters_v1, csh_unh) }, + { "flm_count_cuc_start", 3, offsetof(struct flm_counters_v1, cuc_start) }, + { "flm_count_cuc_move", 3, offsetof(struct flm_counters_v1, cuc_move) }, + + /* FLM 0.17 */ + { "flm_count_load_lps", 3, offsetof(struct flm_counters_v1, load_lps) }, + { "flm_count_load_aps", 3, offsetof(struct flm_counters_v1, load_aps) }, + { "flm_count_max_lps", 3, offsetof(struct flm_counters_v1, max_lps) }, + { "flm_count_max_aps", 3, offsetof(struct flm_counters_v1, max_aps) }, + + { "rx_packet_per_second", 4, offsetof(struct port_load_counters, rx_pps) }, + { "rx_max_packet_per_second", 4, offsetof(struct port_load_counters, rx_pps_max) }, + { "rx_bits_per_second", 4, offsetof(struct port_load_counters, rx_bps) }, + { "rx_max_bits_per_second", 4, offsetof(struct port_load_counters, rx_bps_max) }, + { "tx_packet_per_second", 4, offsetof(struct port_load_counters, tx_pps) }, + { "tx_max_packet_per_second", 4, offsetof(struct port_load_counters, tx_pps_max) }, + { "tx_bits_per_second", 4, offsetof(struct port_load_counters, tx_bps) }, + { "tx_max_bits_per_second", 4, offsetof(struct port_load_counters, tx_bps_max) } +}; + +#define NTHW_CAP_XSTATS_NAMES_V1 RTE_DIM(nthw_cap_xstats_names_v1) +#define NTHW_CAP_XSTATS_NAMES_V2 RTE_DIM(nthw_cap_xstats_names_v2) +#define NTHW_CAP_XSTATS_NAMES_V3 RTE_DIM(nthw_cap_xstats_names_v3) + +/* + * Container for the reset values + */ +#define NTHW_XSTATS_SIZE NTHW_CAP_XSTATS_NAMES_V3 + +static uint64_t nthw_xstats_reset_val[NUM_ADAPTER_PORTS_MAX][NTHW_XSTATS_SIZE] = { 0 }; + +/* + * These functions must only be called with stat mutex locked + */ +static int nthw_xstats_get(nt4ga_stat_t *p_nt4ga_stat, + struct rte_eth_xstat *stats, + unsigned int n, + uint8_t port) +{ + unsigned int i; + uint8_t *pld_ptr; + uint8_t *flm_ptr; + uint8_t *rx_ptr; + uint8_t *tx_ptr; + uint32_t nb_names; + struct rte_nthw_xstats_names_s *names; + + pld_ptr = (uint8_t *)&p_nt4ga_stat->mp_port_load[port]; + flm_ptr = (uint8_t *)p_nt4ga_stat->mp_stat_structs_flm; + rx_ptr = (uint8_t *)&p_nt4ga_stat->cap.mp_stat_structs_port_rx[port]; + tx_ptr = (uint8_t *)&p_nt4ga_stat->cap.mp_stat_structs_port_tx[port]; + + if (p_nt4ga_stat->flm_stat_ver < 18) { + names = nthw_cap_xstats_names_v1; + nb_names = NTHW_CAP_XSTATS_NAMES_V1; + + } else if (p_nt4ga_stat->mp_nthw_stat->mn_stat_layout_version < 7 || + p_nt4ga_stat->flm_stat_ver < 23) { + names = nthw_cap_xstats_names_v2; + nb_names = NTHW_CAP_XSTATS_NAMES_V2; + + } else { + names = nthw_cap_xstats_names_v3; + nb_names = NTHW_CAP_XSTATS_NAMES_V3; + } + + for (i = 0; i < n && i < nb_names; i++) { + stats[i].id = i; + + switch (names[i].source) { + case 1: + /* RX stat */ + stats[i].value = *((uint64_t *)&rx_ptr[names[i].offset]) - + nthw_xstats_reset_val[port][i]; + break; + + case 2: + /* TX stat */ + stats[i].value = *((uint64_t *)&tx_ptr[names[i].offset]) - + nthw_xstats_reset_val[port][i]; + break; + + case 3: + + /* FLM stat */ + if (flm_ptr) { + stats[i].value = *((uint64_t *)&flm_ptr[names[i].offset]) - + nthw_xstats_reset_val[0][i]; + + } else { + stats[i].value = 0; + } + + break; + + case 4: + + /* Port Load stat */ + if (pld_ptr) { + /* No reset */ + stats[i].value = *((uint64_t *)&pld_ptr[names[i].offset]); + + } else { + stats[i].value = 0; + } + + break; + + default: + stats[i].value = 0; + break; + } + } + + return i; +} + +static int nthw_xstats_get_by_id(nt4ga_stat_t *p_nt4ga_stat, + const uint64_t *ids, + uint64_t *values, + unsigned int n, + uint8_t port) +{ + unsigned int i; + uint8_t *pld_ptr; + uint8_t *flm_ptr; + uint8_t *rx_ptr; + uint8_t *tx_ptr; + uint32_t nb_names; + struct rte_nthw_xstats_names_s *names; + int count = 0; + + pld_ptr = (uint8_t *)&p_nt4ga_stat->mp_port_load[port]; + flm_ptr = (uint8_t *)p_nt4ga_stat->mp_stat_structs_flm; + rx_ptr = (uint8_t *)&p_nt4ga_stat->cap.mp_stat_structs_port_rx[port]; + tx_ptr = (uint8_t *)&p_nt4ga_stat->cap.mp_stat_structs_port_tx[port]; + + if (p_nt4ga_stat->flm_stat_ver < 18) { + names = nthw_cap_xstats_names_v1; + nb_names = NTHW_CAP_XSTATS_NAMES_V1; + + } else if (p_nt4ga_stat->mp_nthw_stat->mn_stat_layout_version < 7 || + p_nt4ga_stat->flm_stat_ver < 23) { + names = nthw_cap_xstats_names_v2; + nb_names = NTHW_CAP_XSTATS_NAMES_V2; + + } else { + names = nthw_cap_xstats_names_v3; + nb_names = NTHW_CAP_XSTATS_NAMES_V3; + } + + for (i = 0; i < n; i++) { + if (ids[i] < nb_names) { + switch (names[ids[i]].source) { + case 1: + /* RX stat */ + values[i] = *((uint64_t *)&rx_ptr[names[ids[i]].offset]) - + nthw_xstats_reset_val[port][ids[i]]; + break; + + case 2: + /* TX stat */ + values[i] = *((uint64_t *)&tx_ptr[names[ids[i]].offset]) - + nthw_xstats_reset_val[port][ids[i]]; + break; + + case 3: + + /* FLM stat */ + if (flm_ptr) { + values[i] = *((uint64_t *)&flm_ptr[names[ids[i]].offset]) - + nthw_xstats_reset_val[0][ids[i]]; + + } else { + values[i] = 0; + } + + break; + + case 4: + + /* Port Load stat */ + if (pld_ptr) { + /* No reset */ + values[i] = *((uint64_t *)&pld_ptr[names[i].offset]); + + } else { + values[i] = 0; + } + + break; + + default: + values[i] = 0; + break; + } + + count++; + } + } + + return count; +} + +static void nthw_xstats_reset(nt4ga_stat_t *p_nt4ga_stat, uint8_t port) +{ + unsigned int i; + uint8_t *flm_ptr; + uint8_t *rx_ptr; + uint8_t *tx_ptr; + uint32_t nb_names; + struct rte_nthw_xstats_names_s *names; + + flm_ptr = (uint8_t *)p_nt4ga_stat->mp_stat_structs_flm; + rx_ptr = (uint8_t *)&p_nt4ga_stat->cap.mp_stat_structs_port_rx[port]; + tx_ptr = (uint8_t *)&p_nt4ga_stat->cap.mp_stat_structs_port_tx[port]; + + if (p_nt4ga_stat->flm_stat_ver < 18) { + names = nthw_cap_xstats_names_v1; + nb_names = NTHW_CAP_XSTATS_NAMES_V1; + + } else if (p_nt4ga_stat->mp_nthw_stat->mn_stat_layout_version < 7 || + p_nt4ga_stat->flm_stat_ver < 23) { + names = nthw_cap_xstats_names_v2; + nb_names = NTHW_CAP_XSTATS_NAMES_V2; + + } else { + names = nthw_cap_xstats_names_v3; + nb_names = NTHW_CAP_XSTATS_NAMES_V3; + } + + for (i = 0; i < nb_names; i++) { + switch (names[i].source) { + case 1: + /* RX stat */ + nthw_xstats_reset_val[port][i] = *((uint64_t *)&rx_ptr[names[i].offset]); + break; + + case 2: + /* TX stat */ + nthw_xstats_reset_val[port][i] = *((uint64_t *)&tx_ptr[names[i].offset]); + break; + + case 3: + + /* FLM stat */ + /* Reset makes no sense for flm_count_current */ + /* Reset can't be used for load_lps, load_aps, max_lps and max_aps */ + if (flm_ptr && + (strcmp(names[i].name, "flm_count_current") != 0 && + strcmp(names[i].name, "flm_count_load_lps") != 0 && + strcmp(names[i].name, "flm_count_load_aps") != 0 && + strcmp(names[i].name, "flm_count_max_lps") != 0 && + strcmp(names[i].name, "flm_count_max_aps") != 0)) { + nthw_xstats_reset_val[0][i] = + *((uint64_t *)&flm_ptr[names[i].offset]); + } + + break; + + case 4: + /* Port load stat*/ + /* No reset */ + break; + + default: + break; + } + } +} + +/* + * These functions does not require stat mutex locked + */ +static int nthw_xstats_get_names(nt4ga_stat_t *p_nt4ga_stat, + struct rte_eth_xstat_name *xstats_names, + unsigned int size) +{ + int count = 0; + unsigned int i; + uint32_t nb_names; + struct rte_nthw_xstats_names_s *names; + + if (p_nt4ga_stat->flm_stat_ver < 18) { + names = nthw_cap_xstats_names_v1; + nb_names = NTHW_CAP_XSTATS_NAMES_V1; + + } else if (p_nt4ga_stat->mp_nthw_stat->mn_stat_layout_version < 7 || + p_nt4ga_stat->flm_stat_ver < 23) { + names = nthw_cap_xstats_names_v2; + nb_names = NTHW_CAP_XSTATS_NAMES_V2; + + } else { + names = nthw_cap_xstats_names_v3; + nb_names = NTHW_CAP_XSTATS_NAMES_V3; + } + + if (!xstats_names) + return nb_names; + + for (i = 0; i < size && i < nb_names; i++) { + strlcpy(xstats_names[i].name, names[i].name, sizeof(xstats_names[i].name)); + count++; + } + + return count; +} + +static int nthw_xstats_get_names_by_id(nt4ga_stat_t *p_nt4ga_stat, + struct rte_eth_xstat_name *xstats_names, + const uint64_t *ids, + unsigned int size) +{ + int count = 0; + unsigned int i; + + uint32_t nb_names; + struct rte_nthw_xstats_names_s *names; + + if (p_nt4ga_stat->flm_stat_ver < 18) { + names = nthw_cap_xstats_names_v1; + nb_names = NTHW_CAP_XSTATS_NAMES_V1; + + } else if (p_nt4ga_stat->mp_nthw_stat->mn_stat_layout_version < 7 || + p_nt4ga_stat->flm_stat_ver < 23) { + names = nthw_cap_xstats_names_v2; + nb_names = NTHW_CAP_XSTATS_NAMES_V2; + + } else { + names = nthw_cap_xstats_names_v3; + nb_names = NTHW_CAP_XSTATS_NAMES_V3; + } + + if (!xstats_names) + return nb_names; + + for (i = 0; i < size; i++) { + if (ids[i] < nb_names) { + strlcpy(xstats_names[i].name, + names[ids[i]].name, + RTE_ETH_XSTATS_NAME_SIZE); + } + + count++; + } + + return count; +} + +static struct ntnic_xstats_ops ops = { + .nthw_xstats_get_names = nthw_xstats_get_names, + .nthw_xstats_get = nthw_xstats_get, + .nthw_xstats_reset = nthw_xstats_reset, + .nthw_xstats_get_names_by_id = nthw_xstats_get_names_by_id, + .nthw_xstats_get_by_id = nthw_xstats_get_by_id +}; + +void ntnic_xstats_ops_init(void) +{ + NT_LOG_DBGX(DBG, NTNIC, "xstats module was initialized"); + register_ntnic_xstats_ops(&ops); +} -- 2.45.0