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 58A5A45A68; Tue, 22 Oct 2024 20:30:42 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4B4D540614; Tue, 22 Oct 2024 20:30:42 +0200 (CEST) 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 A8D3B40272 for ; Tue, 22 Oct 2024 20:30:38 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2175.outbound.protection.outlook.com [104.47.17.175]) 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 18:30:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iqaWF7IYr4FAYpLcWCa9EO/V25t+8P9ksWJ2aeq5/1+s1JiDafMPx5TDQjBWQBIYUMuSodAF9UZELJN05iDaJc1YeJeW8qzJM4MFaGWhbL0y25xgrKpB2tsYl2tDxltwDtgg008/OnbCPrtrWSPZO26EtlkALbcxcHjEpVPIEP59eLyEsNqO246HkxDTVcqg/IE4x5G8zk/UHvxHQkyi1m7WMGsKm6P3acGTqzaoNYTAwE1asTsHqrY2RQfSY/6c/2IxZFr2znDeNm5TxMdSPsT0hCMMB8Z+XmaZ2sEMXH31j4uGNvproYKiEMtlehQ2YQkRtfnWAIML11cpbd949Q== 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=9Yd1Kxpm2FQGfJkJIKC0R+vE2pzJGrUe34Z2STxG4Zc=; b=ENNXWGa3SlFdRxN66PPkZNK0PuDzsUnRO0UqVDcSav6DcM3NxjZc13SYTRWsY776f2AlN2JHRGYxpXDSFW4TYT32Li2BpxYPjCNleUgcl+R+9EvuxEu86KEmb0nKAbYgtK0y71Yr4uQobeFDm/MjX6Jw/OXq7Lm5p0l3JKIsFxfXIAvbIFFpY6i2A8hqsT4r+5fIiwimmX4ux9ZnL7nx6uqyZCadJ6l9mEsyATdEHysWBkAos/z/6RsNlRBA9SZpGhH47E8pjID9EcxDv7tTKRsV3aGcgWpN+143Fhyny36sM1OV4hq8b0IuuRF3I7b7okTAu8D3mZJkXP5GJl4w4Q== 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=9Yd1Kxpm2FQGfJkJIKC0R+vE2pzJGrUe34Z2STxG4Zc=; b=i1jJkpfw7TPtP+/pXjsrSzK9Re78MW6lBbBAcPGySlbM6DeCm25wWs+2pW8YNjgcWQYiBkIjmpVoG/ocEHjItuDheRL7wJMs6KteueXb7UpXLkmKq+z/YhoksJyJawq8aBs8JubOpA17oogvbziWtbpJyNdPstkrkjPJghjkrvc= Received: from DB9PR06CA0018.eurprd06.prod.outlook.com (2603:10a6:10:1db::23) by AM9P190MB1076.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:263::8) 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:07 +0000 Received: from DU2PEPF0001E9C2.eurprd03.prod.outlook.com (2603:10a6:10:1db:cafe::72) by DB9PR06CA0018.outlook.office365.com (2603:10a6:10:1db::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16 via Frontend Transport; Tue, 22 Oct 2024 16:57:07 +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:07 +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 v2 58/73] net/ntnic: add tsm module Date: Tue, 22 Oct 2024 18:55:15 +0200 Message-ID: <20241022165541.3186140-59-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_|AM9P190MB1076:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: f1617076-77b6-4084-1be5-08dcf2ba9016 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?ucVky3+zzg5F/3tduu764NhF5EddnSjqBO9QY1sSwN492NKQMUbb/xFyx2uw?= =?us-ascii?Q?FxiaA+9Slt1r7yenPBKEWJao9fffCZdbeLKTl4Xgvj4SQIs081n+OJeN9vQ8?= =?us-ascii?Q?AQvZ8EDrhN+LwCtTXmU8LikCZQM0YgTfSpnh/dzn9RVQlPYnWJzEEyLOV3J4?= =?us-ascii?Q?IEnr1Ci/vFW1+GE0jRsWG2WGOWXGEJ6blNLnMeWA7fXfj+g8Kt5ysK4uc7+k?= =?us-ascii?Q?rEFTN26Mp7NSXrC3/mwAFSYhI42IaZGKG1EVeXkDctjLUxNR2rCb4kaFMEol?= =?us-ascii?Q?vvwXsVdODEmgTV9mzNBdyAXvFWdsldd06S6KNz06Gf1jcBL0KkHsbCIBEo7C?= =?us-ascii?Q?PkcfajyZj+mCg8h8i65DlOYoeu2q1T2DO5gPhh18cgbAprtfzBYd8hjLwRZM?= =?us-ascii?Q?MkvauuNGLXgL0ZHT05BFiHeSHzQVm3RHqhEo+WOh7aCySO+DzhhrixCw3RYV?= =?us-ascii?Q?rgwkmymLW4QExuPk2+q17aLVc9YiAzzjRMMX/O6/Y8PRJVwKL/LDul4ogt1J?= =?us-ascii?Q?unPLRQftOUF+U/2hvbhpZI0F5gR+jfQIIj2OvIvP/qnPCaupsggln/fErPrJ?= =?us-ascii?Q?bQP9kJ9Xt9/Bdlk4DQyrSd4msLCUuqGBq4bpD4xSaIFsH6YSbNrF+wY14zpp?= =?us-ascii?Q?q6ROLTYLc2LavpWUyKgEu9NGCEqm2gQs/FvLS4d3OA62LLmp7Rh0hetrXHd+?= =?us-ascii?Q?Pe8ZosP3kih76YQ3CTwX2WMqh2I+B4aAb30CTDu4o86d30euDvpbnE5kMEw9?= =?us-ascii?Q?4GzdWCVgu/is4tZ1X8mqGiX9+xouqYw6zqk+3KwJLHHAE0Ih0WysrX9ZPrue?= =?us-ascii?Q?FG5RfqK2mgBQNQf5myAYRDk0SIecXPqwA8a8BYh1lGgl9r6XOEGqpiA98VHC?= =?us-ascii?Q?azJgXiWMazwh728COWJKCklpEbV3q3f88E285rmKLch8K94hqJUEX2SyC00S?= =?us-ascii?Q?XSQhdOxq59+y47opwylgt5zsW5Cj4YB3ialMLR2vhVn4GfHJ6+CTZRIVjN27?= =?us-ascii?Q?bHOKNMnVtFBrptVTEATexX8wjr3tUiy0fTbEaEwbE0exbl1UKOTCMzb0wqO9?= =?us-ascii?Q?rfnnzECtaGlgeJ8fyX+RPvD9h4sgWulTaXjLXVyRmvuDted431Jc3VOGClFD?= =?us-ascii?Q?G8cwDsQRfquAZf4X49QcjtJa9ctRrdm1XV7XPSaoCFbM5CdSfWdmVtMdmw5N?= =?us-ascii?Q?8TxgDCPjnuSVeuBtKJijht8ujDV12SjJzCi6+OVRZekw327bDdOe3Zg1hz57?= =?us-ascii?Q?C7FmQFYU91dxgQLLAHdd/uc1fgr9lqjanOdWNFu2W1FHU6wVwH6zJUqaSrix?= =?us-ascii?Q?PG56Iu/bKbIeiP1/TdYKJz/398ypUKdsJ6kSTGbyRfv3y8gIOIrq07B12Wmj?= =?us-ascii?Q?AidHFaY98YTwa+CDDFpWalaK+sNk/J+tr5i3Q+kVIxCE7p6I2g=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: YGEo0KLQ3ki7t3G72/DdlQwY76jlnEed4WCUIQ7V8kBdfgdi9aAHYHd+5ezMBqGfY/CdA0YGy/aDIPGxidojcXeeXFRatX2IrwRW65BxIqIhom+rV5v33hhDgv7UG2mJH0flL3EsrTWBHUeroVV5AJMv5c6dixeopqXXaPIS09gEb7qO8u5tTc4dMmiYL7FkHcMxIDbTAGzghlw2/IxfnVniyNjPUXO1Yr2CfC6oM3hj119Qr4MPrxtBWXqEegdWCNKViVgxtBtRjrdZ00lgW0XL88sZd4DZa5xWKJ0ThPOBojCLYAT2JFxYDv+Mf9QT2UgJ1Q9mKL2num5uOa5OERUi2vNZdar46Xi03UPwkANtnXIeiGGIpTjGPrwl2y1vO684JWHI7dgFXCxdoMeUwLtAgurI1dP0EQAZap7BfM6Qse5t0wMRcwXwDtKXjvLD3PzdG16hiU5kJkxGJG9xbY0wzYukOIlTzhFZO5lSJOfw60dbmMO2u3H68nB9AdSUyZgYwcGi5J0dy9STRssUCNYXG/2+klDz4+0XMmOwW67opSAR/jqKBu42+OYtnb3v6zFbo3LKSDVLQluF321XsjCzkgUegokeLdi7wtdpMVzXJfQ3hP2OhPR9sh9icbilH32QTPfU3JYcQIkwWMwkChSGthzQ9EgleUq0WvaoA6A= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 16:57:07.1693 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f1617076-77b6-4084-1be5-08dcf2ba9016 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: AM9P190MB1076 X-OriginatorOrg: napatech.com X-BESS-ID: 1729621837-310266-12661-16897-1 X-BESS-VER: 2019.1_20241018.1852 X-BESS-Apparent-Source-IP: 104.47.17.175 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoZGxgZmQGYGUNQgxcTIzCjVLM XIyNwwMSUx2dDQxMTSxNg0zSw1xdLcXKk2FgBa47plQgAAAA== X-BESS-Outbound-Spam-Score: 1.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.259903 [from cloudscan23-115.eu-central-1b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.50 BSF_RULE_7582B META: Custom Rule 7582B 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=1.00 using account:ESS113687 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, BSF_RULE_7582B, 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 tsm module which operate with timers in the physical nic was added. Necessary defines and implementation were added. The Time Stamp Module controls every aspect of packet timestamping, including time synchronization, time stamp format, PTP protocol, etc. Signed-off-by: Danylo Vodopianov --- drivers/net/ntnic/meson.build | 1 + .../net/ntnic/nthw/core/include/nthw_tsm.h | 56 ++++++ drivers/net/ntnic/nthw/core/nthw_fpga.c | 47 +++++ drivers/net/ntnic/nthw/core/nthw_tsm.c | 167 ++++++++++++++++++ .../ntnic/nthw/supported/nthw_fpga_mod_defs.h | 1 + .../ntnic/nthw/supported/nthw_fpga_reg_defs.h | 1 + .../nthw/supported/nthw_fpga_reg_defs_tsm.h | 28 +++ 7 files changed, 301 insertions(+) create mode 100644 drivers/net/ntnic/nthw/core/include/nthw_tsm.h create mode 100644 drivers/net/ntnic/nthw/core/nthw_tsm.c create mode 100644 drivers/net/ntnic/nthw/supported/nthw_fpga_reg_defs_tsm.h diff --git a/drivers/net/ntnic/meson.build b/drivers/net/ntnic/meson.build index ed5a201fd5..a6c4fec0be 100644 --- a/drivers/net/ntnic/meson.build +++ b/drivers/net/ntnic/meson.build @@ -41,6 +41,7 @@ sources = files( 'nthw/core/nt200a0x/reset/nthw_fpga_rst_nt200a0x.c', 'nthw/core/nthw_fpga.c', 'nthw/core/nthw_gmf.c', + 'nthw/core/nthw_tsm.c', 'nthw/core/nthw_gpio_phy.c', 'nthw/core/nthw_hif.c', 'nthw/core/nthw_i2cm.c', diff --git a/drivers/net/ntnic/nthw/core/include/nthw_tsm.h b/drivers/net/ntnic/nthw/core/include/nthw_tsm.h new file mode 100644 index 0000000000..0a3bcdcaf5 --- /dev/null +++ b/drivers/net/ntnic/nthw/core/include/nthw_tsm.h @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#ifndef __NTHW_TSM_H__ +#define __NTHW_TSM_H__ + +#include "stdint.h" + +#include "nthw_fpga_model.h" + +struct nthw_tsm { + nthw_fpga_t *mp_fpga; + nthw_module_t *mp_mod_tsm; + int mn_instance; + + nthw_field_t *mp_fld_config_ts_format; + + nthw_field_t *mp_fld_timer_ctrl_timer_en_t0; + nthw_field_t *mp_fld_timer_ctrl_timer_en_t1; + + nthw_field_t *mp_fld_timer_timer_t0_max_count; + + nthw_field_t *mp_fld_timer_timer_t1_max_count; + + nthw_register_t *mp_reg_ts_lo; + nthw_field_t *mp_fld_ts_lo; + + nthw_register_t *mp_reg_ts_hi; + nthw_field_t *mp_fld_ts_hi; + + nthw_register_t *mp_reg_time_lo; + nthw_field_t *mp_fld_time_lo; + + nthw_register_t *mp_reg_time_hi; + nthw_field_t *mp_fld_time_hi; +}; + +typedef struct nthw_tsm nthw_tsm_t; +typedef struct nthw_tsm nthw_tsm; + +nthw_tsm_t *nthw_tsm_new(void); +int nthw_tsm_init(nthw_tsm_t *p, nthw_fpga_t *p_fpga, int n_instance); + +int nthw_tsm_get_ts(nthw_tsm_t *p, uint64_t *p_ts); +int nthw_tsm_get_time(nthw_tsm_t *p, uint64_t *p_time); + +int nthw_tsm_set_timer_t0_enable(nthw_tsm_t *p, bool b_enable); +int nthw_tsm_set_timer_t0_max_count(nthw_tsm_t *p, uint32_t n_timer_val); +int nthw_tsm_set_timer_t1_enable(nthw_tsm_t *p, bool b_enable); +int nthw_tsm_set_timer_t1_max_count(nthw_tsm_t *p, uint32_t n_timer_val); + +int nthw_tsm_set_config_ts_format(nthw_tsm_t *p, uint32_t n_val); + +#endif /* __NTHW_TSM_H__ */ diff --git a/drivers/net/ntnic/nthw/core/nthw_fpga.c b/drivers/net/ntnic/nthw/core/nthw_fpga.c index 9448c29de1..ca69a9d5b1 100644 --- a/drivers/net/ntnic/nthw/core/nthw_fpga.c +++ b/drivers/net/ntnic/nthw/core/nthw_fpga.c @@ -13,6 +13,8 @@ #include "nthw_fpga_instances.h" #include "nthw_fpga_mod_str_map.h" +#include "nthw_tsm.h" + #include int nthw_fpga_get_param_info(struct fpga_info_s *p_fpga_info, nthw_fpga_t *p_fpga) @@ -179,6 +181,7 @@ int nthw_fpga_init(struct fpga_info_s *p_fpga_info) nthw_hif_t *p_nthw_hif = NULL; nthw_pcie3_t *p_nthw_pcie3 = NULL; nthw_rac_t *p_nthw_rac = NULL; + nthw_tsm_t *p_nthw_tsm = NULL; mcu_info_t *p_mcu_info = &p_fpga_info->mcu_info; uint64_t n_fpga_ident = 0; @@ -331,6 +334,50 @@ int nthw_fpga_init(struct fpga_info_s *p_fpga_info) p_fpga_info->mp_nthw_hif = p_nthw_hif; + p_nthw_tsm = nthw_tsm_new(); + + if (p_nthw_tsm) { + nthw_tsm_init(p_nthw_tsm, p_fpga, 0); + + nthw_tsm_set_config_ts_format(p_nthw_tsm, 1); /* 1 = TSM: TS format native */ + + /* Timer T0 - stat toggle timer */ + nthw_tsm_set_timer_t0_enable(p_nthw_tsm, false); + nthw_tsm_set_timer_t0_max_count(p_nthw_tsm, 50 * 1000 * 1000); /* ns */ + nthw_tsm_set_timer_t0_enable(p_nthw_tsm, true); + + /* Timer T1 - keep alive timer */ + nthw_tsm_set_timer_t1_enable(p_nthw_tsm, false); + nthw_tsm_set_timer_t1_max_count(p_nthw_tsm, 100 * 1000 * 1000); /* ns */ + nthw_tsm_set_timer_t1_enable(p_nthw_tsm, true); + } + + p_fpga_info->mp_nthw_tsm = p_nthw_tsm; + + /* TSM sample triggering: test validation... */ +#if defined(DEBUG) && (1) + { + uint64_t n_time, n_ts; + int i; + + for (i = 0; i < 4; i++) { + if (p_nthw_hif) + nthw_hif_trigger_sample_time(p_nthw_hif); + + else if (p_nthw_pcie3) + nthw_pcie3_trigger_sample_time(p_nthw_pcie3); + + nthw_tsm_get_time(p_nthw_tsm, &n_time); + nthw_tsm_get_ts(p_nthw_tsm, &n_ts); + + NT_LOG(DBG, NTHW, "%s: TSM time: %016" PRIX64 " %016" PRIX64 "\n", + p_adapter_id_str, n_time, n_ts); + + nt_os_wait_usec(1000); + } + } +#endif + return res; } diff --git a/drivers/net/ntnic/nthw/core/nthw_tsm.c b/drivers/net/ntnic/nthw/core/nthw_tsm.c new file mode 100644 index 0000000000..b88dcb9b0b --- /dev/null +++ b/drivers/net/ntnic/nthw/core/nthw_tsm.c @@ -0,0 +1,167 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#include "ntlog.h" + +#include "nthw_drv.h" +#include "nthw_register.h" + +#include "nthw_tsm.h" + +nthw_tsm_t *nthw_tsm_new(void) +{ + nthw_tsm_t *p = malloc(sizeof(nthw_tsm_t)); + + if (p) + memset(p, 0, sizeof(nthw_tsm_t)); + + return p; +} + +int nthw_tsm_init(nthw_tsm_t *p, nthw_fpga_t *p_fpga, int n_instance) +{ + const char *const p_adapter_id_str = p_fpga->p_fpga_info->mp_adapter_id_str; + nthw_module_t *mod = nthw_fpga_query_module(p_fpga, MOD_TSM, n_instance); + + if (p == NULL) + return mod == NULL ? -1 : 0; + + if (mod == NULL) { + NT_LOG(ERR, NTHW, "%s: TSM %d: no such instance", p_adapter_id_str, n_instance); + return -1; + } + + p->mp_fpga = p_fpga; + p->mn_instance = n_instance; + p->mp_mod_tsm = mod; + + { + nthw_register_t *p_reg; + + p_reg = nthw_module_get_register(p->mp_mod_tsm, TSM_CONFIG); + p->mp_fld_config_ts_format = nthw_register_get_field(p_reg, TSM_CONFIG_TS_FORMAT); + + p_reg = nthw_module_get_register(p->mp_mod_tsm, TSM_TIMER_CTRL); + p->mp_fld_timer_ctrl_timer_en_t0 = + nthw_register_get_field(p_reg, TSM_TIMER_CTRL_TIMER_EN_T0); + p->mp_fld_timer_ctrl_timer_en_t1 = + nthw_register_get_field(p_reg, TSM_TIMER_CTRL_TIMER_EN_T1); + + p_reg = nthw_module_get_register(p->mp_mod_tsm, TSM_TIMER_T0); + p->mp_fld_timer_timer_t0_max_count = + nthw_register_get_field(p_reg, TSM_TIMER_T0_MAX_COUNT); + + p_reg = nthw_module_get_register(p->mp_mod_tsm, TSM_TIMER_T1); + p->mp_fld_timer_timer_t1_max_count = + nthw_register_get_field(p_reg, TSM_TIMER_T1_MAX_COUNT); + + p->mp_reg_time_lo = nthw_module_get_register(p->mp_mod_tsm, TSM_TIME_LO); + p_reg = p->mp_reg_time_lo; + p->mp_fld_time_lo = nthw_register_get_field(p_reg, TSM_TIME_LO_NS); + + p->mp_reg_time_hi = nthw_module_get_register(p->mp_mod_tsm, TSM_TIME_HI); + p_reg = p->mp_reg_time_hi; + p->mp_fld_time_hi = nthw_register_get_field(p_reg, TSM_TIME_HI_SEC); + + p->mp_reg_ts_lo = nthw_module_get_register(p->mp_mod_tsm, TSM_TS_LO); + p_reg = p->mp_reg_ts_lo; + p->mp_fld_ts_lo = nthw_register_get_field(p_reg, TSM_TS_LO_TIME); + + p->mp_reg_ts_hi = nthw_module_get_register(p->mp_mod_tsm, TSM_TS_HI); + p_reg = p->mp_reg_ts_hi; + p->mp_fld_ts_hi = nthw_register_get_field(p_reg, TSM_TS_HI_TIME); + } + return 0; +} + +int nthw_tsm_get_ts(nthw_tsm_t *p, uint64_t *p_ts) +{ + uint32_t n_ts_lo, n_ts_hi; + uint64_t val; + + if (!p_ts) + return -1; + + n_ts_lo = nthw_field_get_updated(p->mp_fld_ts_lo); + n_ts_hi = nthw_field_get_updated(p->mp_fld_ts_hi); + + val = ((((uint64_t)n_ts_hi) << 32UL) | n_ts_lo); + + if (p_ts) + *p_ts = val; + + return 0; +} + +int nthw_tsm_get_time(nthw_tsm_t *p, uint64_t *p_time) +{ + uint32_t n_time_lo, n_time_hi; + uint64_t val; + + if (!p_time) + return -1; + + n_time_lo = nthw_field_get_updated(p->mp_fld_time_lo); + n_time_hi = nthw_field_get_updated(p->mp_fld_time_hi); + + val = ((((uint64_t)n_time_hi) << 32UL) | n_time_lo); + + if (p_time) + *p_time = val; + + return 0; +} + +int nthw_tsm_set_timer_t0_enable(nthw_tsm_t *p, bool b_enable) +{ + nthw_field_update_register(p->mp_fld_timer_ctrl_timer_en_t0); + + if (b_enable) + nthw_field_set_flush(p->mp_fld_timer_ctrl_timer_en_t0); + + else + nthw_field_clr_flush(p->mp_fld_timer_ctrl_timer_en_t0); + + return 0; +} + +int nthw_tsm_set_timer_t0_max_count(nthw_tsm_t *p, uint32_t n_timer_val) +{ + /* Timer T0 - stat toggle timer */ + nthw_field_update_register(p->mp_fld_timer_timer_t0_max_count); + nthw_field_set_val_flush32(p->mp_fld_timer_timer_t0_max_count, + n_timer_val); /* ns (50*1000*1000) */ + return 0; +} + +int nthw_tsm_set_timer_t1_enable(nthw_tsm_t *p, bool b_enable) +{ + nthw_field_update_register(p->mp_fld_timer_ctrl_timer_en_t1); + + if (b_enable) + nthw_field_set_flush(p->mp_fld_timer_ctrl_timer_en_t1); + + else + nthw_field_clr_flush(p->mp_fld_timer_ctrl_timer_en_t1); + + return 0; +} + +int nthw_tsm_set_timer_t1_max_count(nthw_tsm_t *p, uint32_t n_timer_val) +{ + /* Timer T1 - keep alive timer */ + nthw_field_update_register(p->mp_fld_timer_timer_t1_max_count); + nthw_field_set_val_flush32(p->mp_fld_timer_timer_t1_max_count, + n_timer_val); /* ns (100*1000*1000) */ + return 0; +} + +int nthw_tsm_set_config_ts_format(nthw_tsm_t *p, uint32_t n_val) +{ + nthw_field_update_register(p->mp_fld_config_ts_format); + /* 0x1: Native - 10ns units, start date: 1970-01-01. */ + nthw_field_set_val_flush32(p->mp_fld_config_ts_format, n_val); + return 0; +} diff --git a/drivers/net/ntnic/nthw/supported/nthw_fpga_mod_defs.h b/drivers/net/ntnic/nthw/supported/nthw_fpga_mod_defs.h index 03122acaf5..e6ed9e714b 100644 --- a/drivers/net/ntnic/nthw/supported/nthw_fpga_mod_defs.h +++ b/drivers/net/ntnic/nthw/supported/nthw_fpga_mod_defs.h @@ -48,6 +48,7 @@ #define MOD_SLC (0x1aef1f38UL) #define MOD_SLC_LR (0x969fc50bUL) #define MOD_STA (0x76fae64dUL) +#define MOD_TSM (0x35422a24UL) #define MOD_TX_CPY (0x60acf217UL) #define MOD_TX_INS (0x59afa100UL) #define MOD_TX_RPL (0x1095dfbbUL) diff --git a/drivers/net/ntnic/nthw/supported/nthw_fpga_reg_defs.h b/drivers/net/ntnic/nthw/supported/nthw_fpga_reg_defs.h index 7067f4b1d0..4d299c6aa8 100644 --- a/drivers/net/ntnic/nthw/supported/nthw_fpga_reg_defs.h +++ b/drivers/net/ntnic/nthw/supported/nthw_fpga_reg_defs.h @@ -44,6 +44,7 @@ #include "nthw_fpga_reg_defs_rpp_lr.h" #include "nthw_fpga_reg_defs_rst9563.h" #include "nthw_fpga_reg_defs_sdc.h" +#include "nthw_fpga_reg_defs_tsm.h" #include "nthw_fpga_reg_defs_slc.h" #include "nthw_fpga_reg_defs_slc_lr.h" #include "nthw_fpga_reg_defs_sta.h" diff --git a/drivers/net/ntnic/nthw/supported/nthw_fpga_reg_defs_tsm.h b/drivers/net/ntnic/nthw/supported/nthw_fpga_reg_defs_tsm.h new file mode 100644 index 0000000000..a087850aa4 --- /dev/null +++ b/drivers/net/ntnic/nthw/supported/nthw_fpga_reg_defs_tsm.h @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Napatech A/S + */ + +#ifndef _NTHW_FPGA_REG_DEFS_TSM_ +#define _NTHW_FPGA_REG_DEFS_TSM_ + +/* TSM */ +#define TSM_CONFIG (0xef5dec83UL) +#define TSM_CONFIG_TS_FORMAT (0xe6efc2faUL) +#define TSM_TIMER_CTRL (0x648da051UL) +#define TSM_TIMER_CTRL_TIMER_EN_T0 (0x17cee154UL) +#define TSM_TIMER_CTRL_TIMER_EN_T1 (0x60c9d1c2UL) +#define TSM_TIMER_T0 (0x417217a5UL) +#define TSM_TIMER_T0_MAX_COUNT (0xaa601706UL) +#define TSM_TIMER_T1 (0x36752733UL) +#define TSM_TIMER_T1_MAX_COUNT (0x6beec8c6UL) +#define TSM_TIME_HI (0x175acea1UL) +#define TSM_TIME_HI_SEC (0xc0e9c9a1UL) +#define TSM_TIME_LO (0x9a55ae90UL) +#define TSM_TIME_LO_NS (0x879c5c4bUL) +#define TSM_TS_HI (0xccfe9e5eUL) +#define TSM_TS_HI_TIME (0xc23fed30UL) +#define TSM_TS_LO (0x41f1fe6fUL) +#define TSM_TS_LO_TIME (0xe0292a3eUL) + +#endif /* _NTHW_FPGA_REG_DEFS_TSM_ */ -- 2.45.0