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 DD9F645635; Wed, 17 Jul 2024 15:33:46 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C14DA40A89; Wed, 17 Jul 2024 15:33:27 +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 3B1CA40674 for ; Wed, 17 Jul 2024 15:33:23 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2104.outbound.protection.outlook.com [104.47.18.104]) by mx-outbound23-33.eu-central-1b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 17 Jul 2024 13:33:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rxbkB97uDq0xkMG93qJNq0jOf+a8+HSzG5BzT5qNEqwPNXUKGeVOu5Xi7gEGdoivP1jrZowaHa5zfqWiyIsq8SfmxJOHNmqgV4gU0brRTWm7zY+QAiE8TAMlvjpo5GktKFfMEMsUjrotNwoesrWcc1FO5dmHnIDXSuXmKBEZTQGsnpK3qlMMSUjOsBKPgWTJBDnG2LgwVt/7DVo9shHgjdNKmQxzrEQ4hF5FP17QhYzp0ap7PYtH2k+ld/2r9a8Js35z9NLjArCH7sCFfV10yYTDs+XwgsPd6eb/iLsTlrrEcoH2SEONY2pqP0/aUK7scFrggidyrsz8JfTex3h3Rw== 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=uwGLMd/CCxbOjU8yoOP/T93peGdWVDi3msa38YqnnSE=; b=bwhIW91v+y/oy+8JneLviTDEwjViR3RUVbVgh851yyrbRniogxJ8OZ0Xf1OD9o4x8mTNWPpE+qcE3MGdpEcKnvx8UhZ4nq78d6SXZDj6GcYGgW2wULA67vhOBkUdcMaxB3ezM/UZLiWd1VmNnZwb1ZlqYCVVggIsX0OUlNF+oLaXSmALElaGltJecrdix/XrA57KnwEGW2jcWxggbUzYZypCdV/xB7u2ArBub2bfHnjkGbr3i/iuXD0hjh17BDdTxKvR7gRjaTYB1Nkg6z0ebmCMT1HJBLGgepXl5CVV3sBatAb3kreUPopyMB6PmojfZGf2fJ21PhnkdrogGknjnw== 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=uwGLMd/CCxbOjU8yoOP/T93peGdWVDi3msa38YqnnSE=; b=gsqLCUahx3aF0Wuv7jhWdVbfcDo6augLbOJi6jUrt2JEBbIVCFtsUfMcT0pjN/0Sk/JyxfH2V6acdH/MqkZ7Bq1OuvE4DhLZIMAJms0HpuVWgeC5HBjsvSRM4NubLKPbHwcrOm62fA0XdC11AoqIgFGDFQw6ZeiWmkjCAnZRbL4= Received: from AM0PR04CA0100.eurprd04.prod.outlook.com (2603:10a6:208:be::41) by DBAP190MB0888.EURP190.PROD.OUTLOOK.COM (2603:10a6:10:1a4::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Wed, 17 Jul 2024 13:33:20 +0000 Received: from AM3PEPF0000A799.eurprd04.prod.outlook.com (2603:10a6:208:be:cafe::d4) by AM0PR04CA0100.outlook.office365.com (2603:10a6:208:be::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16 via Frontend Transport; Wed, 17 Jul 2024 13:33:20 +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 AM3PEPF0000A799.mail.protection.outlook.com (10.167.16.104) with Microsoft SMTP Server id 15.20.7784.11 via Frontend Transport; Wed, 17 Jul 2024 13:33:20 +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 v10 06/21] net/ntnic: add basic eth dev ops Date: Wed, 17 Jul 2024 15:32:53 +0200 Message-ID: <20240717133313.3104239-6-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240717133313.3104239-1-sil-plv@napatech.com> References: <20240530144929.4127931-1-sil-plv@napatech.com> <20240717133313.3104239-1-sil-plv@napatech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF0000A799:EE_|DBAP190MB0888:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: bbc184ca-3a93-4455-d49e-08dca665060d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?latw5lYprnifaXAaLkjQRcgz7vCBbxjPsQ9IS7PEkVU4VtlM3H2sVLQNHciA?= =?us-ascii?Q?pWh5hRUVI7BINBaQQ9+I5jaVSiU/UlW7A4Twj6nnyGHI3SkhemFXRaQeXn1u?= =?us-ascii?Q?kdK0JLmdY+Ly3NM9aDUUnyTh7MLxaYlbOqSro33u5a5sU2ue6xQ3gnq8YGzX?= =?us-ascii?Q?tM9zomOKHKR2iPfBQGEsA0P4BQMeyUM3krcfLGmfNs8QNdLnKDJ4bppG5rDt?= =?us-ascii?Q?q/SQzaLnjwbGY+KKbCYVQ7LqEgcieEjG1Q5VgoTZait2vlGoQ6KhgPczMV9O?= =?us-ascii?Q?oAo42W3KV8XRajP7kzVkeg67sN7g9tkIKX2F/uMfdtEHuQsmQZe/0dFT8y7Z?= =?us-ascii?Q?2N2LRAa6ubv6By1IOSM1c1uujJOVFRSCZ+akKq300WniT7ikxpuIZlqu8fbE?= =?us-ascii?Q?xaol1o/A5wp44cJ/8FKJlwvOMUFXQbH+tcnwCtdI1n96UGRrEJE/B4j9LK9G?= =?us-ascii?Q?dS1lPAgOkZXYm3o7KaMntqm4V+wQv7sQAhSdiSJKdc9z/9Gao9MaB8cWjosV?= =?us-ascii?Q?U4AwkDtIpX3hmOpRtW9dDvMsmByZLcIESQznci5sAvX0KRB2eNJ1NAYv89wB?= =?us-ascii?Q?aoehA82liEwgs/TyCfqqep1r/Bv9QpTnGOydYLUJal7PXBV9YO4TSnox5KVJ?= =?us-ascii?Q?qU8plS3/hLVugl73vtSbo+MNnjcWxodmAA778HyUG63iyP7yImQmIokU59EJ?= =?us-ascii?Q?2YpxvvBZ81TalTbWFvkLWflW/VYIkkuEzNW8jMavz0d5vAETe3fzlkPXlAWg?= =?us-ascii?Q?EyCJNL5SkCGOWz0seeo10OE3ubGCxy9I27BmtfmKpflpxruszQHXehT+45o5?= =?us-ascii?Q?7CIZA8avasR2/h28kIJgGIq03TiIobjrGs5wcwDo1XGFQ+8iB//p5FEZWZ1P?= =?us-ascii?Q?sdBPPV/dx7+k4YSjll2MSAJwa7bK7QwUUFa7zHbMPFvNEFEjL+Ce8sbp5sS9?= =?us-ascii?Q?Zj1kfZpI44z57csptPDaL3WeqcKRdVeIkbhJbjbUGDavePeyF+0eZ7TRp4sP?= =?us-ascii?Q?984a1EajypCICAtveGOQDdmaUwqo3A9fO3pfgwdPVQbxbCt72Pw8KoFTQVZ+?= =?us-ascii?Q?Z057Z5cQ4j72m/VhdqwHeYUvHvQhhox4Sy6aBE7oHgNUwsNd+3xr3TyatQbC?= =?us-ascii?Q?qcazrz6EYUmgdsAdj++OWHy5MU88nHLEg5tv7UsH/IsPTjQeleYwI71a8uJR?= =?us-ascii?Q?7S54tHGGsYknj6iGn1BTmqA90Q+S8BYCMU1toJcWOXmEdQSIYU+n/mfaOjoo?= =?us-ascii?Q?dKhAtog9m2p3Plrp88n7HHeeUPaljHW0dvRepv7Q67HdVexjBD6WMP8++1wD?= =?us-ascii?Q?fU5yNTszBKWRVz/PIOrUukJ2npkGXGRMvgMyHAHz0Y/suiCkQSuajHrZQjAa?= =?us-ascii?Q?UXoiX3itDW2dPBW8uPCq5qnls1zetCrwq9dFo7IZAtU2W1cN0LQlMJt6Wnx5?= =?us-ascii?Q?X9eK7XcyIhJE9qILTzVsrO96hmSZdk//?= 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)(36860700013)(376014)(82310400026)(1800799024); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 5fSmn1uz7cLy9V9SOnPg95J7nLS56puX2yfikT4fIpvI3aLjdYNKRCpbLMWmM5DOW+Gpw5fHr1NNnZJWH2BZZwLX6Bf2VeVKvJFMCLGAYfzwApIPa3syhnhRDIrCPjySJKvmZOUOkRE5N52udrHczsJqgKWebBG0HaB93E5MhwduX0lggyBcTsne8Cto1LsF4I2CgcFJipErmdW5Lg+CNVcQ6EFcP0eSjyIzfDoIL9jt221pFYzz2H/0b6h+5FGodI+LEdUcbnZwFT9Qb9JIWQCBpYamxoQfGVZK11+HcaPokQe9lvGXBHjlGuPBEmiICQlJLlZ5LaSg5exc8AgaRP4DXgSg5dX/qDjdFokeuygwbYtTTutizT90xKK/J3Yr/rBGrtQjMVDeuC1hyv+URNsMo2PTX/0a/rflTIWwupe4VX1szc322hsZjBf3QD1iM6FBZ4rzyojhTn7DER+cBMXCx5J28UVimR+JZdKm7Lll/NVxPYbqdFqltxd1vLbcRBkqEYXoAZoID3mk5kV+sgwDz/Qc6MiyWTu87LWPgGsY7JQ/1pIK02Am7IzP3zhPuwLLnU84H8hPPl857ps7VfEBLHOCihIvtVXq0JlPJoLW2HfwFS+sj5xQZsLbckuOQ0Y6przwLUVEJtUD8WBEYw== X-OriginatorOrg: napatech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 13:33:20.1682 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbc184ca-3a93-4455-d49e-08dca665060d 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: AM3PEPF0000A799.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAP190MB0888 X-BESS-ID: 1721223202-305921-12777-14949-1 X-BESS-VER: 2019.1_20240716.1757 X-BESS-Apparent-Source-IP: 104.47.18.104 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoYGJobGQGYGUNTQzNLA2DIpMd UoNSnF0sTE0MTcJNXcMNXSIDElLc3UTKk2FgDYV5zIQgAAAA== X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.257687 [from cloudscan21-11.eu-central-1b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS113687 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Adds support for eth_dev configure, start, stop, close, and infos_get. The internal structs of ntnic is also added and initialized. Signed-off-by: Serhii Iliushyk --- v6 * Replace if_index with n_intf_no * Unnecessry resources free was fixed * Fix typo * Useless vars were removed v9 * Remove if_index usage to n_intf_no * Make ops structure as const * Fix logs * Cleaup struct pmd_internals * Move back dev init count increasing v10 * Remove "to ntnic" from the commit message title * Use 8 spaces as indentation in meson --- drivers/net/ntnic/include/ntdrv_4ga.h | 17 ++ drivers/net/ntnic/include/ntos_drv.h | 30 ++++ drivers/net/ntnic/include/ntos_system.h | 19 +++ drivers/net/ntnic/meson.build | 1 + drivers/net/ntnic/ntnic_ethdev.c | 207 +++++++++++++++++++++++- 5 files changed, 273 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ntnic/include/ntdrv_4ga.h create mode 100644 drivers/net/ntnic/include/ntos_drv.h create mode 100644 drivers/net/ntnic/include/ntos_system.h diff --git a/drivers/net/ntnic/include/ntdrv_4ga.h b/drivers/net/ntnic/include/ntdrv_4ga.h new file mode 100644 index 0000000000..bcb7ddc242 --- /dev/null +++ b/drivers/net/ntnic/include/ntdrv_4ga.h @@ -0,0 +1,17 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#ifndef __NTDRV_4GA_H__ +#define __NTDRV_4GA_H__ + + +typedef struct ntdrv_4ga_s { + uint32_t pciident; + char *p_drv_name; + + volatile bool b_shutdown; +} ntdrv_4ga_t; + +#endif /* __NTDRV_4GA_H__ */ diff --git a/drivers/net/ntnic/include/ntos_drv.h b/drivers/net/ntnic/include/ntos_drv.h new file mode 100644 index 0000000000..3c0a62cc85 --- /dev/null +++ b/drivers/net/ntnic/include/ntos_drv.h @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#ifndef __NTOS_DRV_H__ +#define __NTOS_DRV_H__ + +#include +#include +#include +#include + +#include + +#define NUM_MAC_ADDRS_PER_PORT (16U) +#define NUM_MULTICAST_ADDRS_PER_PORT (16U) + +#define NUM_ADAPTER_MAX (8) +#define NUM_ADAPTER_PORTS_MAX (128) + +struct pmd_internals { + const struct rte_pci_device *pci_dev; + char name[20]; + int n_intf_no; + struct drv_s *p_drv; + struct pmd_internals *next; +}; + +#endif /* __NTOS_DRV_H__ */ diff --git a/drivers/net/ntnic/include/ntos_system.h b/drivers/net/ntnic/include/ntos_system.h new file mode 100644 index 0000000000..01f1dc65f4 --- /dev/null +++ b/drivers/net/ntnic/include/ntos_system.h @@ -0,0 +1,19 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Napatech A/S + */ + +#ifndef __NTOS_SYSTEM_H__ +#define __NTOS_SYSTEM_H__ + +#include "ntdrv_4ga.h" + +struct drv_s { + int adapter_no; + struct rte_pci_device *p_dev; + struct ntdrv_4ga_s ntdrv; + + int n_eth_dev_init_count; +}; + +#endif /* __NTOS_SYSTEM_H__ */ diff --git a/drivers/net/ntnic/meson.build b/drivers/net/ntnic/meson.build index deeb0aca09..47c4b6357a 100644 --- a/drivers/net/ntnic/meson.build +++ b/drivers/net/ntnic/meson.build @@ -10,6 +10,7 @@ endif # includes includes = [ include_directories('.'), + include_directories('include'), include_directories('ntlog'), include_directories('ntutil'), ] diff --git a/drivers/net/ntnic/ntnic_ethdev.c b/drivers/net/ntnic/ntnic_ethdev.c index b838eb4d7a..504d6c6bcd 100644 --- a/drivers/net/ntnic/ntnic_ethdev.c +++ b/drivers/net/ntnic/ntnic_ethdev.c @@ -14,6 +14,9 @@ #include "ntlog.h" +#include "ntdrv_4ga.h" +#include "ntos_drv.h" +#include "ntos_system.h" #include "ntnic_vfio.h" #include "nt_util.h" @@ -25,30 +28,201 @@ static const struct rte_pci_id nthw_pci_id_map[] = { }, /* sentinel */ }; +static rte_spinlock_t hwlock = RTE_SPINLOCK_INITIALIZER; + +/* + * Store and get adapter info + */ + +static struct drv_s *_g_p_drv[NUM_ADAPTER_MAX] = { NULL }; + +static void +store_pdrv(struct drv_s *p_drv) +{ + if (p_drv->adapter_no > NUM_ADAPTER_MAX) { + NT_LOG(ERR, NTNIC, + "Internal error adapter number %u out of range. Max number of adapters: %u\n", + p_drv->adapter_no, NUM_ADAPTER_MAX); + return; + } + + if (_g_p_drv[p_drv->adapter_no] != 0) { + NT_LOG(WRN, NTNIC, + "Overwriting adapter structure for PCI " PCIIDENT_PRINT_STR + " with adapter structure for PCI " PCIIDENT_PRINT_STR "\n", + PCIIDENT_TO_DOMAIN(_g_p_drv[p_drv->adapter_no]->ntdrv.pciident), + PCIIDENT_TO_BUSNR(_g_p_drv[p_drv->adapter_no]->ntdrv.pciident), + PCIIDENT_TO_DEVNR(_g_p_drv[p_drv->adapter_no]->ntdrv.pciident), + PCIIDENT_TO_FUNCNR(_g_p_drv[p_drv->adapter_no]->ntdrv.pciident), + PCIIDENT_TO_DOMAIN(p_drv->ntdrv.pciident), + PCIIDENT_TO_BUSNR(p_drv->ntdrv.pciident), + PCIIDENT_TO_DEVNR(p_drv->ntdrv.pciident), + PCIIDENT_TO_FUNCNR(p_drv->ntdrv.pciident)); + } + + rte_spinlock_lock(&hwlock); + _g_p_drv[p_drv->adapter_no] = p_drv; + rte_spinlock_unlock(&hwlock); +} + +static struct drv_s * +get_pdrv_from_pci(struct rte_pci_addr addr) +{ + int i; + struct drv_s *p_drv = NULL; + rte_spinlock_lock(&hwlock); + + for (i = 0; i < NUM_ADAPTER_MAX; i++) { + if (_g_p_drv[i]) { + if (PCIIDENT_TO_DOMAIN(_g_p_drv[i]->ntdrv.pciident) == addr.domain && + PCIIDENT_TO_BUSNR(_g_p_drv[i]->ntdrv.pciident) == addr.bus) { + p_drv = _g_p_drv[i]; + break; + } + } + } + + rte_spinlock_unlock(&hwlock); + return p_drv; +} + +static int +eth_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *dev_info) +{ + struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private; + + dev_info->driver_name = internals->name; + + return 0; +} + +static int +eth_dev_configure(struct rte_eth_dev *eth_dev) +{ + NT_LOG_DBGX(DEBUG, NTNIC, "Called for eth_dev %p\n", eth_dev); + + /* The device is ALWAYS running promiscuous mode. */ + eth_dev->data->promiscuous ^= ~eth_dev->data->promiscuous; + return 0; +} + +static int +eth_dev_start(struct rte_eth_dev *eth_dev) +{ + struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private; + + NT_LOG_DBGX(DEBUG, NTNIC, "Port %u\n", internals->n_intf_no); + + return 0; +} + +static int +eth_dev_stop(struct rte_eth_dev *eth_dev) +{ + struct pmd_internals *internals = (struct pmd_internals *)eth_dev->data->dev_private; + + NT_LOG_DBGX(DEBUG, NTNIC, "Port %u\n", internals->n_intf_no); + + eth_dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN; + return 0; +} + +static void +drv_deinit(struct drv_s *p_drv) +{ + if (p_drv == NULL) + return; + + /* clean memory */ + rte_free(p_drv); + p_drv = NULL; +} + +static int +eth_dev_close(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; + + internals->p_drv = NULL; + + rte_eth_dev_release_port(eth_dev); + + /* decrease initialized ethernet devices */ + p_drv->n_eth_dev_init_count--; + + /* + * rte_pci_dev has no private member for p_drv + * wait until all rte_eth_dev's are closed - then close adapters via p_drv + */ + if (!p_drv->n_eth_dev_init_count && p_drv) + drv_deinit(p_drv); + + return 0; +} + +static const struct eth_dev_ops nthw_eth_dev_ops = { + .dev_configure = eth_dev_configure, + .dev_start = eth_dev_start, + .dev_stop = eth_dev_stop, + .dev_close = eth_dev_close, + .dev_infos_get = eth_dev_infos_get, +}; + static int nthw_pci_dev_init(struct rte_pci_device *pci_dev) { nt_vfio_init(); + struct drv_s *p_drv; + ntdrv_4ga_t *p_nt_drv; uint32_t n_port_mask = -1; /* All ports enabled by default */ + uint32_t nb_rx_queues = 1; + uint32_t nb_tx_queues = 1; int n_phy_ports; NT_LOG_DBGX(DEBUG, NTNIC, "Dev %s PF #%i Init : %02x:%02x:%i\n", pci_dev->name, pci_dev->addr.function, pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function); + /* alloc */ + p_drv = rte_zmalloc_socket(pci_dev->name, sizeof(struct drv_s), RTE_CACHE_LINE_SIZE, + pci_dev->device.numa_node); + + if (!p_drv) { + NT_LOG_DBGX(ERR, NTNIC, "%s: error %d\n", + (pci_dev->name[0] ? pci_dev->name : "NA"), -1); + return -1; + } + /* Setup VFIO context */ int vfio = nt_vfio_setup(pci_dev); if (vfio < 0) { NT_LOG_DBGX(ERR, TNIC, "%s: vfio_setup error %d\n", (pci_dev->name[0] ? pci_dev->name : "NA"), -1); + rte_free(p_drv); return -1; } + /* context */ + p_nt_drv = &p_drv->ntdrv; + + 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->b_shutdown = false; + + /* store context */ + store_pdrv(p_drv); + n_phy_ports = 0; for (int n_intf_no = 0; n_intf_no < n_phy_ports; n_intf_no++) { + struct pmd_internals *internals = NULL; struct rte_eth_dev *eth_dev = NULL; char name[32]; @@ -57,6 +231,31 @@ nthw_pci_dev_init(struct rte_pci_device *pci_dev) snprintf(name, sizeof(name), "ntnic%d", n_intf_no); + internals = rte_zmalloc_socket(name, sizeof(struct pmd_internals), + RTE_CACHE_LINE_SIZE, pci_dev->device.numa_node); + + if (!internals) { + NT_LOG_DBGX(ERR, NTNIC, "%s: %s: error=%d\n", + (pci_dev->name[0] ? pci_dev->name : "NA"), name, -1); + return -1; + } + + internals->pci_dev = pci_dev; + internals->n_intf_no = n_intf_no; + + /* Setup queue_ids */ + if (nb_rx_queues > 1) { + NT_LOG(DBG, NTNIC, + "(%i) NTNIC configured with Rx multi queues. %i queues\n", + internals->n_intf_no, nb_rx_queues); + } + + if (nb_tx_queues > 1) { + NT_LOG(DBG, NTNIC, + "(%i) NTNIC configured with Tx multi queues. %i queues\n", + internals->n_intf_no, nb_tx_queues); + } + eth_dev = rte_eth_dev_allocate(name); if (!eth_dev) { @@ -73,10 +272,13 @@ nthw_pci_dev_init(struct rte_pci_device *pci_dev) eth_dev->device = &pci_dev->device; eth_dev->data->dev_link = pmd_link; - eth_dev->dev_ops = NULL; + eth_dev->dev_ops = &nthw_eth_dev_ops; eth_dev_pci_specific_init(eth_dev, pci_dev); rte_eth_dev_probing_finish(eth_dev); + + /* increase initialized ethernet devices - PF */ + p_drv->n_eth_dev_init_count++; } return 0; @@ -142,6 +344,9 @@ nthw_pci_remove(struct rte_pci_device *pci_dev) { NT_LOG_DBGX(DEBUG, NTNIC); + struct drv_s *p_drv = get_pdrv_from_pci(pci_dev->addr); + drv_deinit(p_drv); + return rte_eth_dev_pci_generic_remove(pci_dev, nthw_pci_dev_deinit); } -- 2.43.0