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 7B50E45614; Fri, 12 Jul 2024 17:48:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0D3C742FD5; Fri, 12 Jul 2024 17:48:00 +0200 (CEST) Received: from egress-ip11b.ess.de.barracuda.com (egress-ip11b.ess.de.barracuda.com [18.185.115.215]) by mails.dpdk.org (Postfix) with ESMTP id 59C3942EA9 for ; Fri, 12 Jul 2024 17:47:55 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2107.outbound.protection.outlook.com [104.47.18.107]) by mx-outbound45-239.eu-central-1c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 12 Jul 2024 15:47:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dUqHizkdY5Iabg2ib5wtoSdfv+jSz4Fv5GdcSSUmRBzue8GghD9aOLwDf5RLmxcGnSb8o3YIQBTBX+Xxi2f2vw6qzva0PJ6UDqCgCYdlJ2uKBzAidLUzCxLOtSCN2LF1g3GYQCHvC4AzkxNfTeJKJtCQwcjAEy0Dnj1k0H/lvOg8UmVDfIsqbtLfW5f/nYw1GX4ipFMEvR+dSGXMQ/N6U4hd3jaZAD8ee0HOHjM+UW69e8oHwdlKr2VdFmHVkWLWIzQQtfpDDEgZuENC7Tm6GPFBCXqr9Q9Y4N79pihu7e7adiSf26Rj8m59dm0d0JICeTqLN4Z9+6sPMBrTXroBWA== 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=0dVEHveiVKhx9PCIMjMaMNHhvGX9aiIW4NnW5GTMqNA=; b=rwDmFM95JfnSIOvG2xnBBl9FUsoufkERRGvXnRpg7ywjmMtW1gQKbM3nwafzl3XbkvGiAnwEfnxYxPx4oJ4w2fWx6vJUW0l6acuyRZPX9N+9s4sRySfNfkmj6QZ/nPc2G6iy5JTYcHTmbzN+dfkY1s3zsZj6JKSk2jsDqVduZVVfCCASHgI3klbBMkPh9495QRSzmcflz3n9NwKvJzVW0lUOeB8/QEN6Nb9Nc8hhBWG/Q0dNdl71vgsYG3EW6hZ5YLce1m296rvBs7N2li+VTUxeWwxr5W6h6RB6xRXIE+wtQddSXPWXYlTyWopVEwo5iMGI9TVr7E404/pXz94XBg== 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=0dVEHveiVKhx9PCIMjMaMNHhvGX9aiIW4NnW5GTMqNA=; b=kboxsBJc22DbqLXzyByVjwtzuJZrvGI/i520K/+ZJ1Pvgx/VhiUPVpJ8YQ7zcRVxPuvCA/El3BP8WX8M9rmjNXSQRCOWU3O+f/Y++yYk9sC8+HLJF4eKO3yTWh007WyE+3fEaoW3DRMa98YtsauS/2CsN63o/CJ2PvU5fHeqLFo= Received: from DU7PR01CA0020.eurprd01.prod.exchangelabs.com (2603:10a6:10:50f::25) by PA4P190MB1199.EURP190.PROD.OUTLOOK.COM (2603:10a6:102:10a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.23; Fri, 12 Jul 2024 15:47:52 +0000 Received: from DU2PEPF00028D0C.eurprd03.prod.outlook.com (2603:10a6:10:50f:cafe::d5) by DU7PR01CA0020.outlook.office365.com (2603:10a6:10:50f::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.23 via Frontend Transport; Fri, 12 Jul 2024 15:47: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 DU2PEPF00028D0C.mail.protection.outlook.com (10.167.242.20) with Microsoft SMTP Server id 15.20.7762.17 via Frontend Transport; Fri, 12 Jul 2024 15:47: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 Subject: [PATCH v8 08/21] net/ntnic: add adapter initialization Date: Fri, 12 Jul 2024 17:47:18 +0200 Message-ID: <20240712154737.1339646-8-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240712154737.1339646-1-sil-plv@napatech.com> References: <20240530144929.4127931-1-sil-plv@napatech.com> <20240712154737.1339646-1-sil-plv@napatech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D0C:EE_|PA4P190MB1199:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 4e6e1ae7-88f8-47b3-13d1-08dca289fd75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?KJEnKPTgTuOytJDjqYWquAhNc6ouO0nDDW5Eng3Unal15qnEgHpPo1fP74Wa?= =?us-ascii?Q?nF2c8Mr34NLG1MdrIiWPRelAQnb9ZR4uHNO00Gyv9rggOx/8GHIOS/Pb+B21?= =?us-ascii?Q?clJrh6/IlNFyEkPsoGTNQs99x688Xeq99CBGNJaXCuHoT/i83FTuNKSPgFWz?= =?us-ascii?Q?vrLzFyOKpHzJwh7GLWKOd0ywgT2+AyW+n+gylAMV3YUQU7C+NzRiAnnOlFE5?= =?us-ascii?Q?rpbaX10v1sBW6jSi6qdXzbznWWaTFvd/DETcoh0tvAIgc0ByJ53xtDC95w8r?= =?us-ascii?Q?NxiPnC+0CY2edhnqgDZCIwb51xQdG5Rpf1n4vpshVqD8wB5AuXFeW/8JuzLp?= =?us-ascii?Q?5JRmmDGPWZ9Qbx/WVjsQUCzaqhOTeOzr+vNHSrtvcURZ7tX3W2LTfwwf82Oe?= =?us-ascii?Q?aLdGuOWSnp3HoBGlSSe7/nwZUFMIRp2cJtqKr4w6jL5p1ltv67xNaJFiMEF7?= =?us-ascii?Q?+TfyxvW/UhWSmjV67WbnTzxQyD6z8gNSvPQhZhcTKtDYlVsRXslabBpelsk0?= =?us-ascii?Q?BKxWVlru7tzyclcJzP1chgnAKVESxWTBTIhXVBgcSQPRT/lAHyYSAsxgqTIC?= =?us-ascii?Q?dMsZo0TUGWk1ZaQxHchVpZFxF0lEvzA1pfTSb6afeiDbkkshXIKibA6/JJvd?= =?us-ascii?Q?vboWOxkgRULiaQgSSa5PdLjyjEy9yn3okfEJ1c8QOdoGcsOKyagRrC/8n51c?= =?us-ascii?Q?56LngnSND9rzaL2cTqOFQ7WgWCKEr/P6Ve4lRmWjIvtY0e7WlC2djat9N3KE?= =?us-ascii?Q?sqlKVLuh3SbHp0GdL2YJ1JLmIL/UM0J2vyjgBIj3PS07nJnHtK4X7pHYyTOx?= =?us-ascii?Q?TAHlij2IZViQJgXUBTAuA7C2pk9cAmSINumtm5Yu0ZhTUG9Kt3reWxLb4gI8?= =?us-ascii?Q?v3T+cdGCj1Hg/v8pCbD99vTQhQp5OZTc9RY4nSiP3knKlH60VNIPLXUiznf0?= =?us-ascii?Q?jGN+H+nOYAn6qXulTZuW3ZFSWzQHgCSxnQJ0f/AQ0M3l4NygX/PHUnk8CPUQ?= =?us-ascii?Q?8wtLpidMba+zdA60PX6OxWxFLOpoQJxjDtzA0Qdl/XyKY3RJxuDa9oN1mwGG?= =?us-ascii?Q?lnh3itFIArMh5PtCSPpVxv3SYtDc4Mn13IlM5y+dwrwRDAx9TivwXaIlgO2s?= =?us-ascii?Q?QaVrFuMDIFIvvfg9kxK4eyv85RYfMlZJ2v345IoyKFDIiOcHKux6/ucLRuuE?= =?us-ascii?Q?1FOKa+jDxNry+deILfNS+itWyyKO0YD13neQYJ/VoqP4FtPzGVtanBwccHlw?= =?us-ascii?Q?UPH3EREAOZHtu/1fAcYzkv0nunYpQkRad9T5KlgeyW948x0dlcVhPSwlQ0dy?= =?us-ascii?Q?RgHcUvO9eLS8bEV/2fh6fkfU3EsKKjTQEAO/rKA6GciReoRIG5vjZYidxpVV?= =?us-ascii?Q?R6sv3DFC0POQUhgQs0kBJkc/ztlbmVyL58D6NuiVo/qyxk4WXCwQnrw1iMnU?= =?us-ascii?Q?Hp9C//F8uo+tDkNUWpTnHE4qdFjJiBYs?= 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)(82310400026)(1800799024)(376014)(36860700013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: pFnHUbAr3HugsCcvWvEymBoxabDlfRdob9eme4tJeNP4iFDYUfiT99Q6jx4lZ6zGobm9F2o7QQs/teIThNGrzMzv9nGHhBl8vJS2uHiiqSGcPuDXFAJv0y/T06mU3Z+FH9hdkk02xCQCGMZgIIXg8rjMCvNpLKwoNv3ktHZFWBQRsLUoi/pGKT6S/z+tEmSwh//i0sijDn992JyL/uMWCB9/v5s/L6elJaMpIyDR147Hu3LrG4CsonxLfVpYsJYSNFovk88imyE6IY2SgTI3kpXNNSdtCLPDy2yIqKp5ZNxVeAYYODhTHIJALBjhxQkq6yzyWUoLniAoBbINevmyP6BfGWDolfsbjmke6Fw4ghiZIHlZxH4r5/7mOPb4xXdW8qrKWX+UwC0ouRld3mMpdg7ruIpaEj7ZOFFj6QBjd3vtyIhkO2uGI6edNbWLD0euuLQq1p18bblw4PNoVKnJLEphfvNx4+hE5rhJIac8isDpFoWevUJrV8gYJ/tAagP9yYrIssjZDzv7Ip1ol7FXMhOSvdf4qdz04IvHxd9Me3i89jpIwEMLpDKAu26YrsMwgXabYFUHSQRg0XNjGIK2hK85Ao/F+yB7C/Cuo6vJ4J+bbmm0XaM04BKx7S49MuRpaYQuuPFPYUNu24FVXKmpFw== X-OriginatorOrg: napatech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2024 15:47:52.3482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e6e1ae7-88f8-47b3-13d1-08dca289fd75 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: DU2PEPF00028D0C.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4P190MB1199 X-BESS-ID: 1720799274-311759-12661-32379-1 X-BESS-VER: 2019.1_20240702.1505 X-BESS-Apparent-Source-IP: 104.47.18.107 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoYmRiYmQGYGUNQ4JTnV2DzNJN EiydjA1NLCzDLRPCXVItE0KdncwtgiTak2FgDCRGuiQgAAAA== X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.257575 [from cloudscan15-209.eu-central-1a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS113687 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add interfaces for initialize the adapter Signed-off-by: Serhii Iliushyk --- v6 * Function for global var clearing was removed --- drivers/net/ntnic/adapter/nt4ga_adapter.c | 148 ++++++++++++++++++++++ drivers/net/ntnic/include/nt4ga_adapter.h | 40 ++++++ drivers/net/ntnic/include/ntdrv_4ga.h | 2 + drivers/net/ntnic/meson.build | 2 + drivers/net/ntnic/ntnic_ethdev.c | 89 ++++++++++--- drivers/net/ntnic/ntnic_mod_reg.c | 20 +++ drivers/net/ntnic/ntnic_mod_reg.h | 27 ++++ 7 files changed, 310 insertions(+), 18 deletions(-) create mode 100644 drivers/net/ntnic/adapter/nt4ga_adapter.c create mode 100644 drivers/net/ntnic/include/nt4ga_adapter.h create mode 100644 drivers/net/ntnic/ntnic_mod_reg.c create mode 100644 drivers/net/ntnic/ntnic_mod_reg.h diff --git a/drivers/net/ntnic/adapter/nt4ga_adapter.c b/drivers/net/ntnic/adapter/nt4ga_adapter.c new file mode 100644 index 0000000000..7cc3841ecf --- /dev/null +++ b/drivers/net/ntnic/adapter/nt4ga_adapter.c @@ -0,0 +1,148 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#include + +#include "ntlog.h" +#include "nt_util.h" +#include "ntnic_mod_reg.h" + +static int nt4ga_adapter_show_info(struct adapter_info_s *p_adapter_info, FILE *pfh) +{ + const char *const p_dev_name = p_adapter_info->p_dev_name; + const char *const p_adapter_id_str = p_adapter_info->mp_adapter_id_str; + fpga_info_t *p_fpga_info = &p_adapter_info->fpga_info; + hw_info_t *p_hw_info = &p_adapter_info->hw_info; + char a_pci_ident_str[32]; + + snprintf(a_pci_ident_str, sizeof(a_pci_ident_str), PCIIDENT_PRINT_STR, + PCIIDENT_TO_DOMAIN(p_fpga_info->pciident), + PCIIDENT_TO_BUSNR(p_fpga_info->pciident), + PCIIDENT_TO_DEVNR(p_fpga_info->pciident), + PCIIDENT_TO_FUNCNR(p_fpga_info->pciident)); + + fprintf(pfh, "%s: DeviceName: %s\n", p_adapter_id_str, (p_dev_name ? p_dev_name : "NA")); + fprintf(pfh, "%s: PCI Details:\n", p_adapter_id_str); + fprintf(pfh, "%s: %s: %08X: %04X:%04X %04X:%04X\n", p_adapter_id_str, a_pci_ident_str, + p_fpga_info->pciident, p_hw_info->pci_vendor_id, p_hw_info->pci_device_id, + p_hw_info->pci_sub_vendor_id, p_hw_info->pci_sub_device_id); + fprintf(pfh, "%s: FPGA Details:\n", p_adapter_id_str); + fprintf(pfh, "%s: %03d-%04d-%02d-%02d [%016" PRIX64 "] (%08X)\n", p_adapter_id_str, + p_fpga_info->n_fpga_type_id, p_fpga_info->n_fpga_prod_id, + p_fpga_info->n_fpga_ver_id, p_fpga_info->n_fpga_rev_id, p_fpga_info->n_fpga_ident, + p_fpga_info->n_fpga_build_time); + fprintf(pfh, "%s: FpgaDebugMode=0x%x\n", p_adapter_id_str, p_fpga_info->n_fpga_debug_mode); + fprintf(pfh, "%s: Hw=0x%02X_rev%d: %s\n", p_adapter_id_str, p_hw_info->hw_platform_id, + p_fpga_info->nthw_hw_info.hw_id, p_fpga_info->nthw_hw_info.hw_plat_id_str); + fprintf(pfh, "%s: MCU Details:\n", p_adapter_id_str); + + + return 0; +} + +static int nt4ga_adapter_init(struct adapter_info_s *p_adapter_info) +{ + char *const p_dev_name = malloc(24); + char *const p_adapter_id_str = malloc(24); + fpga_info_t *fpga_info = &p_adapter_info->fpga_info; + hw_info_t *p_hw_info = &p_adapter_info->hw_info; + + + p_hw_info->n_nthw_adapter_id = nthw_platform_get_nthw_adapter_id(p_hw_info->pci_device_id); + + fpga_info->n_nthw_adapter_id = p_hw_info->n_nthw_adapter_id; + /* ref: DN-0060 section 9 */ + p_hw_info->hw_product_type = p_hw_info->pci_device_id & 0x000f; + /* ref: DN-0060 section 9 */ + p_hw_info->hw_platform_id = (p_hw_info->pci_device_id >> 4) & 0x00ff; + /* ref: DN-0060 section 9 */ + p_hw_info->hw_reserved1 = (p_hw_info->pci_device_id >> 12) & 0x000f; + + /* mp_dev_name */ + p_adapter_info->p_dev_name = p_dev_name; + + if (p_dev_name) { + snprintf(p_dev_name, 24, PCIIDENT_PRINT_STR, + PCIIDENT_TO_DOMAIN(p_adapter_info->fpga_info.pciident), + PCIIDENT_TO_BUSNR(p_adapter_info->fpga_info.pciident), + PCIIDENT_TO_DEVNR(p_adapter_info->fpga_info.pciident), + PCIIDENT_TO_FUNCNR(p_adapter_info->fpga_info.pciident)); + NT_LOG(DBG, NTNIC, "%s: (0x%08X)\n", p_dev_name, + p_adapter_info->fpga_info.pciident); + } + + /* mp_adapter_id_str */ + p_adapter_info->mp_adapter_id_str = p_adapter_id_str; + + p_adapter_info->fpga_info.mp_adapter_id_str = p_adapter_id_str; + + if (p_adapter_id_str) { + snprintf(p_adapter_id_str, 24, "PCI:" PCIIDENT_PRINT_STR, + PCIIDENT_TO_DOMAIN(p_adapter_info->fpga_info.pciident), + PCIIDENT_TO_BUSNR(p_adapter_info->fpga_info.pciident), + PCIIDENT_TO_DEVNR(p_adapter_info->fpga_info.pciident), + PCIIDENT_TO_FUNCNR(p_adapter_info->fpga_info.pciident)); + NT_LOG(DBG, NTNIC, "%s: %s\n", p_adapter_id_str, p_dev_name); + } + + { + int i; + + for (i = 0; i < (int)ARRAY_SIZE(p_adapter_info->mp_port_id_str); i++) { + char *p = malloc(32); + + if (p) { + snprintf(p, 32, "%s:intf_%d", + (p_adapter_id_str ? p_adapter_id_str : "NA"), i); + } + + p_adapter_info->mp_port_id_str[i] = p; + } + } + + return 0; +} + +static int nt4ga_adapter_deinit(struct adapter_info_s *p_adapter_info) +{ + fpga_info_t *fpga_info = &p_adapter_info->fpga_info; + int i; + int res = -1; + + + /* Free adapter port ident strings */ + for (i = 0; i < fpga_info->n_phy_ports; i++) { + if (p_adapter_info->mp_port_id_str[i]) { + free(p_adapter_info->mp_port_id_str[i]); + p_adapter_info->mp_port_id_str[i] = NULL; + } + } + + /* Free adapter ident string */ + if (p_adapter_info->mp_adapter_id_str) { + free(p_adapter_info->mp_adapter_id_str); + p_adapter_info->mp_adapter_id_str = NULL; + } + + /* Free devname ident string */ + if (p_adapter_info->p_dev_name) { + free(p_adapter_info->p_dev_name); + p_adapter_info->p_dev_name = NULL; + } + + return res; +} + +static const struct adapter_ops ops = { + .init = nt4ga_adapter_init, + .deinit = nt4ga_adapter_deinit, + + .show_info = nt4ga_adapter_show_info, +}; + +void adapter_init(void) +{ + register_adapter_ops(&ops); +} diff --git a/drivers/net/ntnic/include/nt4ga_adapter.h b/drivers/net/ntnic/include/nt4ga_adapter.h new file mode 100644 index 0000000000..2c72583caf --- /dev/null +++ b/drivers/net/ntnic/include/nt4ga_adapter.h @@ -0,0 +1,40 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#ifndef _NT4GA_ADAPTER_H_ +#define _NT4GA_ADAPTER_H_ + +#include "ntos_drv.h" +typedef struct hw_info_s { + /* pciids */ + uint16_t pci_vendor_id; + uint16_t pci_device_id; + uint16_t pci_sub_vendor_id; + uint16_t pci_sub_device_id; + uint16_t pci_class_id; + + /* Derived from pciid */ + nthw_adapter_id_t n_nthw_adapter_id; + int hw_platform_id; + int hw_product_type; + int hw_reserved1; +} hw_info_t; + +typedef struct adapter_info_s { + struct hw_info_s hw_info; + struct fpga_info_s fpga_info; + + char *mp_port_id_str[NUM_ADAPTER_PORTS_MAX]; + char *mp_adapter_id_str; + char *p_dev_name; + volatile bool *pb_shutdown; + + int adapter_no; + int n_rx_host_buffers; + int n_tx_host_buffers; +} adapter_info_t; + + +#endif /* _NT4GA_ADAPTER_H_ */ diff --git a/drivers/net/ntnic/include/ntdrv_4ga.h b/drivers/net/ntnic/include/ntdrv_4ga.h index bcb7ddc242..8017aa4fc3 100644 --- a/drivers/net/ntnic/include/ntdrv_4ga.h +++ b/drivers/net/ntnic/include/ntdrv_4ga.h @@ -6,9 +6,11 @@ #ifndef __NTDRV_4GA_H__ #define __NTDRV_4GA_H__ +#include "nt4ga_adapter.h" typedef struct ntdrv_4ga_s { uint32_t pciident; + struct adapter_info_s adapter_info; char *p_drv_name; volatile bool b_shutdown; diff --git a/drivers/net/ntnic/meson.build b/drivers/net/ntnic/meson.build index 73c4188da0..94f24e09e3 100644 --- a/drivers/net/ntnic/meson.build +++ b/drivers/net/ntnic/meson.build @@ -18,9 +18,11 @@ includes = [ # all sources sources = files( + 'adapter/nt4ga_adapter.c', 'nthw/nthw_platform.c', 'ntlog/ntlog.c', 'ntutil/nt_util.c', + 'ntnic_mod_reg.c', 'ntnic_vfio.c', 'ntnic_ethdev.c', ) diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c index 2a73162d6c..c84321ed91 100644 --- a/drivers/net/ntnic/ntnic_ethdev.c +++ b/drivers/net/ntnic/ntnic_ethdev.c @@ -19,6 +19,7 @@ #include "ntos_drv.h" #include "ntos_system.h" #include "ntnic_vfio.h" +#include "ntnic_mod_reg.h" #include "nt_util.h" #define EXCEPTION_PATH_HID 0 @@ -66,17 +67,6 @@ store_pdrv(struct drv_s *p_drv) rte_spinlock_unlock(&hwlock); } -static void -clear_pdrv(struct drv_s *p_drv) -{ - if (p_drv->adapter_no > NUM_ADAPTER_MAX) - return; - - rte_spinlock_lock(&hwlock); - _g_p_drv[p_drv->adapter_no] = NULL; - rte_spinlock_unlock(&hwlock); -} - static struct drv_s * get_pdrv_from_pci(struct rte_pci_addr addr) { @@ -144,14 +134,20 @@ eth_dev_stop(struct rte_eth_dev *eth_dev) static void drv_deinit(struct drv_s *p_drv) { + const struct adapter_ops *adapter_ops = get_adapter_ops(); + + if (adapter_ops == NULL) { + NT_LOG(ERR, NTNIC, "Adapter module uninitialized\n"); + return; + } + if (p_drv == NULL) return; - /* - * Mark the global pdrv for cleared. Used by some threads to terminate. - * 1 second to give the threads a chance to see the termination. - */ - clear_pdrv(p_drv); - nt_os_wait_usec(1000000); + + ntdrv_4ga_t *p_nt_drv = &p_drv->ntdrv; + + /* stop adapter */ + adapter_ops->deinit(&p_nt_drv->adapter_info); /* clean memory */ rte_free(p_drv); @@ -194,8 +190,17 @@ nthw_pci_dev_init(struct rte_pci_device *pci_dev) { nt_vfio_init(); + const struct adapter_ops *adapter_ops = get_adapter_ops(); + + if (adapter_ops == NULL) { + NT_LOG(ERR, NTNIC, "Adapter module uninitialized\n"); + return -1; + } + struct drv_s *p_drv; ntdrv_4ga_t *p_nt_drv; + hw_info_t *p_hw_info; + (void)p_hw_info; uint32_t n_port_mask = -1; /* All ports enabled by default */ uint32_t nb_rx_queues = 1; uint32_t nb_tx_queues = 1; @@ -227,30 +232,78 @@ nthw_pci_dev_init(struct rte_pci_device *pci_dev) /* context */ p_nt_drv = &p_drv->ntdrv; + p_hw_info = &p_nt_drv->adapter_info.hw_info; p_drv->p_dev = pci_dev; /* Set context for NtDrv */ p_nt_drv->pciident = BDF_TO_PCIIDENT(pci_dev->addr.domain, pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function); + p_nt_drv->adapter_info.n_rx_host_buffers = nb_rx_queues; + p_nt_drv->adapter_info.n_tx_host_buffers = nb_tx_queues; + p_nt_drv->adapter_info.hw_info.pci_class_id = pci_dev->id.class_id; + p_nt_drv->adapter_info.hw_info.pci_vendor_id = pci_dev->id.vendor_id; + p_nt_drv->adapter_info.hw_info.pci_device_id = pci_dev->id.device_id; + p_nt_drv->adapter_info.hw_info.pci_sub_vendor_id = pci_dev->id.subsystem_vendor_id; + p_nt_drv->adapter_info.hw_info.pci_sub_device_id = pci_dev->id.subsystem_device_id; + + NT_LOG(DBG, NTNIC, "%s: " PCIIDENT_PRINT_STR " %04X:%04X: %04X:%04X:\n", + p_nt_drv->adapter_info.mp_adapter_id_str, 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), + p_nt_drv->adapter_info.hw_info.pci_vendor_id, + p_nt_drv->adapter_info.hw_info.pci_device_id, + p_nt_drv->adapter_info.hw_info.pci_sub_vendor_id, + p_nt_drv->adapter_info.hw_info.pci_sub_device_id); + p_nt_drv->b_shutdown = false; + p_nt_drv->adapter_info.pb_shutdown = &p_nt_drv->b_shutdown; /* store context */ store_pdrv(p_drv); + /* initialize nt4ga nthw fpga module instance in drv */ + int err = adapter_ops->init(&p_nt_drv->adapter_info); + + if (err != 0) { + NT_LOG(ERR, NTNIC, "%s: Cannot initialize the adapter instance\n", + p_nt_drv->adapter_info.mp_adapter_id_str); + return -1; + } + + /* Start ctrl, monitor, stat thread only for primary process. */ + if (err == 0) { + /* mp_adapter_id_str is initialized after nt4ga_adapter_init(p_nt_drv) */ + const char *const p_adapter_id_str = p_nt_drv->adapter_info.mp_adapter_id_str; + (void)p_adapter_id_str; + + } else { + NT_LOG_DBGX(ERR, NTNIC, "%s: error=%d\n", + (pci_dev->name[0] ? pci_dev->name : "NA"), err); + return -1; + } + n_phy_ports = 0; for (int n_intf_no = 0; n_intf_no < n_phy_ports; n_intf_no++) { + const char *const p_port_id_str = p_nt_drv->adapter_info.mp_port_id_str[n_intf_no]; + (void)p_port_id_str; struct pmd_internals *internals = NULL; struct rte_eth_dev *eth_dev = NULL; char name[32]; - if ((1 << n_intf_no) & ~n_port_mask) + if ((1 << n_intf_no) & ~n_port_mask) { + NT_LOG_DBGX(DEBUG, NTNIC, + "%s: interface #%d: skipping due to portmask 0x%02X\n", + p_port_id_str, n_intf_no, n_port_mask); continue; + } snprintf(name, sizeof(name), "ntnic%d", n_intf_no); + NT_LOG_DBGX(DEBUG, NTNIC, "%s: interface #%d: %s: '%s'\n", p_port_id_str, + n_intf_no, (pci_dev->name[0] ? pci_dev->name : "NA"), name); internals = rte_zmalloc_socket(name, sizeof(struct pmd_internals), RTE_CACHE_LINE_SIZE, pci_dev->device.numa_node); diff --git a/drivers/net/ntnic/ntnic_mod_reg.c b/drivers/net/ntnic/ntnic_mod_reg.c new file mode 100644 index 0000000000..006221bbe3 --- /dev/null +++ b/drivers/net/ntnic/ntnic_mod_reg.c @@ -0,0 +1,20 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#include "ntnic_mod_reg.h" + +static const struct adapter_ops *adapter_ops; + +void register_adapter_ops(const struct adapter_ops *ops) +{ + adapter_ops = ops; +} + +const struct adapter_ops *get_adapter_ops(void) +{ + if (adapter_ops == NULL) + adapter_init(); + return adapter_ops; +} diff --git a/drivers/net/ntnic/ntnic_mod_reg.h b/drivers/net/ntnic/ntnic_mod_reg.h new file mode 100644 index 0000000000..48a9f8f7b9 --- /dev/null +++ b/drivers/net/ntnic/ntnic_mod_reg.h @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#ifndef __NTNIC_MOD_REG_H__ +#define __NTNIC_MOD_REG_H__ + +#include +#include "nthw_platform_drv.h" +#include "nthw_drv.h" +#include "nt4ga_adapter.h" +#include "ntos_drv.h" + +struct adapter_ops { + int (*init)(struct adapter_info_s *p_adapter_info); + int (*deinit)(struct adapter_info_s *p_adapter_info); + + int (*show_info)(struct adapter_info_s *p_adapter_info, FILE *pfh); +}; + +void register_adapter_ops(const struct adapter_ops *ops); +const struct adapter_ops *get_adapter_ops(void); +void adapter_init(void); + + +#endif /* __NTNIC_MOD_REG_H__ */ -- 2.45.0