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 3404345628; Tue, 16 Jul 2024 14:03:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A0EC943308; Tue, 16 Jul 2024 14:02:33 +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 21C22427E6 for ; Tue, 16 Jul 2024 14:02:29 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03lp2169.outbound.protection.outlook.com [104.47.51.169]) by mx-outbound46-60.eu-central-1c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 16 Jul 2024 12:02:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e5oeX85vL4TfavvjRXvnELYBkYr7wYPnE6i3VlGul+C+LwMUlvLjrekCuQx+rUIUUkbuWAZieQQRz0d1ftRNQOXQpobV+yOr4yTk8ASX8or/Seqh7N9TjvT14capN4CZIq05Xr7y0RMeVHpAYUvM4e7Nc49sMm8otTrHk/7fHNsToaDBIeQf3Xy6IZ+R2PdHmPZcTG84j8WFD3f5Ejb7z47OrgVZJfoIji99iLVgnsCmSezrR/0vuqWE0n2i6KhS7pEGRxOJE06acSwsZEn/Mj3hioyP16PcPu/BkFhG5YsNJbHZ5mY1BU9lWnPN3zxRrFTeqoV2pNp4oRd4kvhFKg== 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=45Zr120GHvWJv3RFjmW5YESVKokS5QPn9lCwQibgXSI=; b=dngs7Xbr1wKIG5lBiNJMgTCoI1sQOVdynmU0toZTBR26emPn0sl6a12YTW7+BvWWB50fUtFIn9+NYhPO5HE0aAaHQ1EqhOcedZJqLBVL2rsKdw8rQqhK6R3AE+lX6hNqgvWdYaN22vPM/Tt6e6C/ee4gisZAwIITrYI6bHEntcQCqI/7OIPY6/5kyFXKboB9GApvV37vlCIrjssobZOx8UzcHS7gs9frA49Uhk+N7jy6u6oXMEb7CnaEso90MIg7snk7cnApcMeVkrH62gvrUo9Hcyze23pxBAChY1w5pyNRGkirMsKUbLNkYXDFhXA2JdpPWtdagPGBsNApj0tr9Q== 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=45Zr120GHvWJv3RFjmW5YESVKokS5QPn9lCwQibgXSI=; b=qA2O+VaT5O95fTjSxrTP9OLCKvzEI06Z59UV3lqQqwUhFmaicA79T1hT7p2OE4lhRfsy9UA3lB09DPc0pCN4DcUCIdDIuk4rXw+m3U3uzsk9bqWVIkh4a+PSJAoRN/tdqGONuUDKQN6LQHYrjrdrFiv55vx35t9ttKVZdkn2pP8= Received: from DU7P195CA0001.EURP195.PROD.OUTLOOK.COM (2603:10a6:10:54d::15) by AS4P190MB1928.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:514::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29; Tue, 16 Jul 2024 12:02:24 +0000 Received: from DU6PEPF0000A7DD.eurprd02.prod.outlook.com (2603:10a6:10:54d:cafe::f3) by DU7P195CA0001.outlook.office365.com (2603:10a6:10:54d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29 via Frontend Transport; Tue, 16 Jul 2024 12:02:24 +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 DU6PEPF0000A7DD.mail.protection.outlook.com (10.167.8.37) with Microsoft SMTP Server id 15.20.7784.11 via Frontend Transport; Tue, 16 Jul 2024 12:02:24 +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 v9 06/21] net/ntnic: add basic eth dev ops to ntnic Date: Tue, 16 Jul 2024 14:01:55 +0200 Message-ID: <20240716120216.3032484-6-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240716120216.3032484-1-sil-plv@napatech.com> References: <20240530144929.4127931-1-sil-plv@napatech.com> <20240716120216.3032484-1-sil-plv@napatech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU6PEPF0000A7DD:EE_|AS4P190MB1928:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 23d2bcd4-cf12-4a3a-01f3-08dca58f279c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?n8fcjdZH0ny1mhabOPTtvBEJzBwgqTFQdjx4Rsfa6UNSmG9WT/KSucD0FSzG?= =?us-ascii?Q?uGwNAoz69U2YNsXrvdpoEB8kx6Nby34Q0yfsJUFg5Q7AcYn1/Y827N5o4Vpv?= =?us-ascii?Q?JXjfaYnQ3bR5VjQL9Q/UzVWWH+Epf4WXcfIazHkW6pvnuK/H4fZXxLcuOd5T?= =?us-ascii?Q?tUGF6g2hDt3Kr8jWLlcaIfkWqP25fk/9AmbMkht1qxruyHgzEunpy0G6JJbG?= =?us-ascii?Q?vn+D/iTgp6/BE6amuXEEaBSEWkrItGcxu3Ml9YElbe0E7iAUU//XRvTsYxsW?= =?us-ascii?Q?qnUgXkDKK8R+Fa53nPREwgqk1IRSE1gXopxvGhd/1IjbgoIsnKqaOJVqywDK?= =?us-ascii?Q?Ln528a5ns2WHwCgymtBBGNE/zMhFtP+1oIOq0gB2jE767XMx5LFtjxNT85FM?= =?us-ascii?Q?5Sbag4bb+y5oMxdpYNjUalNJhhy6Z2bZkSle9+9W5N11IDSwa2xWkEkHeopc?= =?us-ascii?Q?2R6bUNJf8qQ0oG8FNE1xH3o0gKtzmUOuqorG2chEeGiWiTYLjsigUWm/LaPt?= =?us-ascii?Q?xiPM0fe8nSCIr3tAARTFv5ndLP7XizonOnqiNenYjgpNhL1p9b7L5QYr05t2?= =?us-ascii?Q?+UEyGxVZLm2uQNmEGNAkW4cB/a1YVzb3pbpos4ne7jznuNu4EM8PE+vvThkW?= =?us-ascii?Q?TolaDz4RZdAfQCXwdC5ckV6XM4Ni1jbd6Hc+dQ/LDqJo6eW0c4zZHVSLo6uY?= =?us-ascii?Q?hrbtZDosPU1bjTKj4g5O+G4PCOYgPw3IMHnMVKTmrmzxL1RchWKfTyUSkRta?= =?us-ascii?Q?3GaaLMesC6TlS7m3Ybuut/aUq/BYieGwwwW7eID4TjGba2CC9a3NiwrFckX7?= =?us-ascii?Q?hY1G5ftYLO8LKZ+9vqbeT/rrFihDsx2UHSXuh1N08OZLsEPbjhiYZvoRy652?= =?us-ascii?Q?8ApHW65CeRv9jgh5TByyWUr4kncj5eu+z8N6PAHKYXYJMB97rE2REjzkcREb?= =?us-ascii?Q?uhLr6vgmecS0pyLe/2uX+0+SeOd05SBpjBCRjugxpm2HT8921HDvYzfR6xS5?= =?us-ascii?Q?wyH/cgXFrQEkOIHZGsxmp+iCnnVJusLRmV/4fC4FOnkfxpiBZOe5s4zJ5u+Q?= =?us-ascii?Q?tCLOSUdvqLKMDdym5+4uXX5zL6vkvqocUZLaZAy6dLUU/nGdpo5wmbZWPUrm?= =?us-ascii?Q?HNi2MOoY3j439j5AaRqQbb4nydZZrvLnFz+pEP/5t/lzy9P4zQ8PoxgcuxfY?= =?us-ascii?Q?p55PgqBkAkJAHDNO6i5u9us5IHvMbhzfLf9rWPsEPxUbrarqmGLU6vOc1Sju?= =?us-ascii?Q?A4Ic+KLXD9yVtYTY1tIuv0nh3eU7o/CXSDNpH2dXRbkUiopE2x0NSRJmfjwX?= =?us-ascii?Q?IBmBdW9wZVwb/g36et1IV3quqlJz2vIufy65rdcJHq3tjySct9YrJ6b2AGi+?= =?us-ascii?Q?ESE0B1kRo9LLS8G3Mo60JXQmQLu/yvH6RAp/w9VNuk2m5y4uHvs7N8W0iXrY?= =?us-ascii?Q?0jnWwG0MsFx40cpSJaOVokEzJGrpJ0j6?= 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)(1800799024)(82310400026)(36860700013); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: +zPI9f/xauGRk0lIx8+iuBgIa3cIbHbBouZh6Ccr7WbsWXLUWc5pSM/bEA9CVJUkJ+Sow1wbCEG0ri33MLIy+q/w+CmyOAGU+ECdnDDcAtJGe0FYBLHf/l0ZmfVMkgsSU5RAmocSukdtfi0oxnzoc04gfwTQFsCP/AiCeEuFodmzp26/g4UbvWwfy6FX7oSNWun8MCXRufpw/M2hm1O1KqmgHWPyBNzHqJ/cD/XWkemepeUJuXPX0+SAV7vyIoezGMayen+Ib7aP3AeR5hhSHmoyP95q3KmnJ3D33Ul7jUh3tqsbBdMYTVayj5eZUtvjnl+D5KUYTtt0vbRLjsBFawdKpDnZtc7UO/XtT/CQqW+lBuuKPOKzuwTH5tY5YZ3ELtRGP8A6EYCLE2QkgALOwgR88cvDp++wRiqmz9QIBLiLerxlZWn5b0nfhmP1mRcan7vgoFL6zwds9afG6Nl365SHwiOur66LOe4bo6PTu4ulTFb64+3JGFjUo5je+vwz9oop4J7q1GRkTwSfk6H1iWUMiNZm3A/eCIFP8fGjxMnYPeN2WJjB3LH27GQNO6xSM5YNlcqt26KXq+houGbn4KTw0aOaZXR1adVJ6dyBmcE/kxPyOMdu//AhArjtyD/nsVnlws/ArgpKJvkK2nUaP2V6zcpA+nh0XFnblkX1OEY= X-OriginatorOrg: napatech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2024 12:02:24.0397 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23d2bcd4-cf12-4a3a-01f3-08dca58f279c 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: DU6PEPF0000A7DD.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4P190MB1928 X-BESS-ID: 1721131347-311836-12657-23657-1 X-BESS-VER: 2019.1_20240702.1505 X-BESS-Apparent-Source-IP: 104.47.51.169 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoYGxgYmQGYGUNTMMiUxLckoLc XE3NjIwizV0MA0zTTJ0NjUwswiMc0gVak2FgDd/HjwQgAAAA== X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.257662 [from cloudscan13-139.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 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 --- 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 bf86a0a098..f372b0c3cf 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.45.0