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 190224320F; Fri, 27 Oct 2023 05:00:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2F05740E68; Fri, 27 Oct 2023 05:00:31 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2121.outbound.protection.outlook.com [40.107.243.121]) by mails.dpdk.org (Postfix) with ESMTP id 6D58540DF6 for ; Fri, 27 Oct 2023 05:00:27 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pc8TElO2K4ZRu9JMW2aR8vDLfq4CQPC1s9OM8PcjOu2VnvXD7WQMofXg3QNnsxIPn3S9khV3nYBo14OswfsLmx9+ithPKiompqD3oZPO2Ab1CN31POe5LoU4pLdz6x/JXIrOR0SkmCXYRARDXUiTHl91JSdN0UZh4Wq+jL4hSSQQzVGXWGOTlUIU0PPFcwYXYkKVgctQLwnuDJzb/Qx1tWylID8RAFwe/+/vsUFQGU0i7iGW8g8wJ7lfnQt+BfzlCwoj84lvJ0bB1t/KXBK34B+El2RxNuZ2m0KsgzuGSn5TDQiR4QC7e4bH9FSY+M1nOmHvNvaduH6dvYyNkEV1uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=4Q9QnKwYORzPcV269h57iRczxLtSD5GDi7BNAf/pqww=; b=RzooYzf9ECptuQnz/mH7s8sVOik9ewr664onnr7NzFfEilf/GYDEObFIs8Nc6EZv0HYOK4t3FfmpJndde/NAQKkYpMV/YAXgUrhYVLp6WiNwRjS9gAPC6JrNv6LSLvzp+FbhjVVk3hTV+mGCNJ0eoe74oiEywT5uyN+1k5vHr5DwZzM9paqoIdgNg679udLwNTk4AhNMJeoaxEEw9eLUyWWMZ63dy1NnXf+L0zj+NkPjberbdOW/2qDLaB08e8VJ2LHqaXaUWtugfo2KcbH6rOotGN9o7e4N3EjTl/s2icSrGatURVuh2tvHrgihrtkqzzA17wprLqSA4/052UTLkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4Q9QnKwYORzPcV269h57iRczxLtSD5GDi7BNAf/pqww=; b=trTsunXCE976g9yRLnyuRtnbkVOctRBCNZRgTMntUOztvge3MRTBKO2/qZ9FMGzmCvtEP5L8MNoAuIlTEWP8IM3ryf9Ou9GzRnQEQydd6ucPJ/UWnhEn5/g4HFBPHINbC54FoSACBFO6VUiz5LIIAAgbfkC9cGK8zA1XVu4bkbo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by SA0PR13MB4048.namprd13.prod.outlook.com (2603:10b6:806:97::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.24; Fri, 27 Oct 2023 03:00:25 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::45b3:d83c:cff2:4a1b]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::45b3:d83c:cff2:4a1b%6]) with mapi id 15.20.6933.022; Fri, 27 Oct 2023 03:00:25 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He , Shujing Dong , Long Wu , Peng Zhang Subject: [PATCH v4 01/24] common/nfp: introduce driver Date: Fri, 27 Oct 2023 10:59:38 +0800 Message-Id: <20231027030001.602639-2-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20231027030001.602639-1-chaoyong.he@corigine.com> References: <20231026064324.177531-1-chaoyong.he@corigine.com> <20231027030001.602639-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BYAPR08CA0065.namprd08.prod.outlook.com (2603:10b6:a03:117::42) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|SA0PR13MB4048:EE_ X-MS-Office365-Filtering-Correlation-Id: c49970ca-c119-4d60-7d6f-08dbd698de27 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jwI4PAXXwlQF18fhLBv/GvmGl4lKCXcvRHo3VHA5s93AoCKlx1ZwjGYvBKWHIn6FULO0k5SO4k5bJ5kJcd1waK+NlqHpndAGV+bwlG+hvdIGFS2+qYQawdKjRfexNaBrBovE9mcaYdVJaKymlWEIB2v9UidqBoti9HX7puk7E6GvJ/bognw7+Pxzjz7EKFpZEqWQGyebnRD5l4RGLOpb6Sb3jXMOVOa0WTLKQmk3+k358mpMDVEKHQFR5avdXbqseRVJUmpn4uFo68N/uoEQPU9gSbZNrjnwihNEqT/uGD1CV4gxfp+8K+S5zvBb3AlyiSbedyLBz2JlaAzvgJhNbsQEUHRjkdyy5V+Zr1Inrz6edBcJlaBmzSZ9589/zyYy1EnRl+Q+ZoS7sFmXK33Pfero4IEyXjWfDwSLkloGD9V/6BipOF1tCOa/18gxRDjNXhYj1zWFbnTOVq5GV43bmyLQi2uSTFojJDLq13t2tf4NCONq66VBhRQyx1UVY95QHxJ8ZcxjAxZNd3wUunZoXJByKdmlzgPwCVE7zxpyyROvUuWf7Ws4VKjzM5MF/VR1/ku2LEqeY1tCyE9R4N3DgM0PXzbLtM/HeyMYjths9WPOFU9oNQq7QqUo4ThAI4l9rHUiBl5ZjE8n8b9aBSXbW2V5ApNy5vRTqPbaJ5/qgJM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376002)(396003)(39840400004)(366004)(346002)(136003)(230922051799003)(64100799003)(186009)(1800799009)(451199024)(6512007)(6666004)(52116002)(6506007)(6486002)(86362001)(36756003)(478600001)(38100700002)(30864003)(2906002)(6916009)(41300700001)(83380400001)(1076003)(107886003)(26005)(2616005)(38350700005)(66946007)(316002)(66556008)(66476007)(4326008)(8936002)(8676002)(44832011)(5660300002)(54906003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?YshQtnNzyLDJPml91uGnZ2dLph/m87S0Cb+SdtdCOhDbi8gpkn4pZZQLG6RV?= =?us-ascii?Q?PW99/Ywa3VkjAFZaIXsuLEdwfpoNeKbQ0T/tA2VTakJbm1c7K38ppvkGkOBL?= =?us-ascii?Q?RyH56neT/aSQm2xCt8DDa7MlS7q0UacQG6OJX84uoQBRnrM2Frxovp77C35O?= =?us-ascii?Q?r3aKuvWnjabVI50qRompx1LTy+KQEhCFjXs9zlA14QCLlABeDqd0TMv7VT+b?= =?us-ascii?Q?CFq5b+L0CQ1WI7Hrk4JjRgsxNoshGZvhXPRFHHeJ50yr1+30WsofzFaM/6ga?= =?us-ascii?Q?6iAUZPxUsFpqjeWk4jGnJ2OQS9Oo+8XjdFL5dc3t7qbjT1iXw/RUSWSyhA8W?= =?us-ascii?Q?ZMNUatejtykBkC4m+aUjI6RUHtO7PwIQmxj/1LsRBxymHxklW033zgNRZjms?= =?us-ascii?Q?SqUdRQKPkHR2/ukTi2crDcoYjEIVkLN5/oBogzQnl2AOAwAOV2i9KdlcKNgy?= =?us-ascii?Q?oxbZeqIEk3lVGY11/rCz4/qdvnnI9ynFhbIOwrsLw1gvR6SiO7Avd+ZbBgI6?= =?us-ascii?Q?3AKV5ntSO8zkUbY0X6ZbdRQHQW4T2rT7MbuMvotX0tyxz+AOp23ijOKkoM03?= =?us-ascii?Q?61Jf2Y9TExJIkMurg0dKgeG3FDz4e45LcklDXOL0f4S8vTlBM2CPKFQ0PUh1?= =?us-ascii?Q?gIqvTKXqQGs5+JrUkL2oKNbu8Hbkzlc4AB+oByfNS+4gulfvLhIROxyXNbAL?= =?us-ascii?Q?77eflClZzka4slYuSmAbg7dUZOFXctWBtfwRYVedSLWJZiu64meb7kxFJlyv?= =?us-ascii?Q?Y1sPXzsqhmLXR7ZbWZNt8yvOUtwt+9j6Q1pgantpKhRakGq/eSQGOnK5tCx8?= =?us-ascii?Q?CydMAzqNv1herqjnETvdrKRaGhYP6Ty/GzSPPwxrl6LRRgNaVylfCFjG1uAF?= =?us-ascii?Q?a4UsmJ2KiVt8jbyP+y+i93AfAwnH2jinjvH0ke9vm9srmVnmStaUYDR26ns7?= =?us-ascii?Q?d8HznAalesz4ac/uBZjX42k0mZoJk29HETTPg8zh1BgHOVN+fM98PfWmL6/H?= =?us-ascii?Q?23V5T71VLgexsPKYU9CNA2NnD9D5LQMbOr1vZpZj3uZSzs6B8fcyzXduIDgN?= =?us-ascii?Q?POkY+oya2+/In9xDAeH/YSprTBkRHFl6wMtZl65+b0hRdqypgBXomgIPl0Lz?= =?us-ascii?Q?P2k/FxbbagDzwqBzhntoEuTc1JogbA3vRuOcoI91a9GpMJ1+ztPElL9ExHK3?= =?us-ascii?Q?cTueShhZy/AAnny/ZFcKqCEHO3XrMcBmRW3dxVt6GJXFgLx1TzTDP/c8YCsq?= =?us-ascii?Q?VGtYM1LSUAu4J9beMcIhSVxVisA+TTmxKFJ97lpuZZnv55sR0+XIS7yNg1NU?= =?us-ascii?Q?3w4n4nFBLsZzZbuDv7uzcbcdXCOC8YewaLqRoXnGBwZc+MVmuC0oqQKqOkde?= =?us-ascii?Q?B2krBogrDI5W/OI/qO9qLFThNQJz4EQYFw+CHnKx21AUu1kyTyJ3e3c4A0+y?= =?us-ascii?Q?Dnnvg+xEYJlo3cjufC9a+ZI8fTK9+JucnbAfzEGOHyuT9UZxTYyS3Hbz4sqd?= =?us-ascii?Q?qsKkVbxS61f+XLaH2MlYbguVgqFNts3eAMUCR5+5SFnh9gqLsusgp8bSC4oL?= =?us-ascii?Q?pDd9rEERDswWGQdfHEkp337igd4OVzCi2vNw0i63I6msLKuvrqywE241gQ8T?= =?us-ascii?Q?rA=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: c49970ca-c119-4d60-7d6f-08dbd698de27 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2023 03:00:25.7227 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UYPzYnsncaP1hzXeGOnbMJqirziFoah/d08Uao+DhnESbny6XRohj3UeGKq8oMfb7FqoTcWLtx6I9ZPyUGEJuN2KzUPIm4mWHkcTGiSg3fE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR13MB4048 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 A new NFP vdpa PMD will be added to support vdpa operations by NFP adapters. This vdpa PMD share some logic with the net/nfp PMD. So create a new common library in drivers/common for NFP PMDs. We import a 'nfp_class_driver' layer and which can support various device type in addition to the ethernet device. The shared logic will move into this common library in the following commits. Signed-off-by: Chaoyong He Signed-off-by: Shujing Dong Reviewed-by: Long Wu Reviewed-by: Peng Zhang --- .mailmap | 1 + MAINTAINERS | 1 + drivers/common/nfp/meson.build | 14 ++ drivers/common/nfp/nfp_common_log.c | 8 + drivers/common/nfp/nfp_common_log.h | 16 ++ drivers/common/nfp/nfp_common_pci.c | 274 ++++++++++++++++++++++++++++ drivers/common/nfp/nfp_common_pci.h | 44 +++++ drivers/common/nfp/version.map | 7 + drivers/meson.build | 1 + 9 files changed, 366 insertions(+) create mode 100644 drivers/common/nfp/meson.build create mode 100644 drivers/common/nfp/nfp_common_log.c create mode 100644 drivers/common/nfp/nfp_common_log.h create mode 100644 drivers/common/nfp/nfp_common_pci.c create mode 100644 drivers/common/nfp/nfp_common_pci.h create mode 100644 drivers/common/nfp/version.map diff --git a/.mailmap b/.mailmap index 3f5bab26a8..9d9e015607 100644 --- a/.mailmap +++ b/.mailmap @@ -1299,6 +1299,7 @@ Shuanglin Wang Shuki Katzenelson Shun Hao Shu Shen +Shujing Dong Shweta Choudaha Shyam Kumar Shrivastav Shy Shyman diff --git a/MAINTAINERS b/MAINTAINERS index 4083658697..5273ab9812 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -900,6 +900,7 @@ F: doc/guides/nics/features/nfb.ini Netronome nfp M: Chaoyong He +F: drivers/common/nfp/ F: drivers/net/nfp/ F: doc/guides/nics/nfp.rst F: doc/guides/nics/features/nfp*.ini diff --git a/drivers/common/nfp/meson.build b/drivers/common/nfp/meson.build new file mode 100644 index 0000000000..cda5a930c7 --- /dev/null +++ b/drivers/common/nfp/meson.build @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2023 Corigine, Inc. + +if not is_linux or not dpdk_conf.get('RTE_ARCH_64') + build = false + reason = 'only supported on 64-bit Linux' +endif + +sources = files( + 'nfp_common_log.c', + 'nfp_common_pci.c', +) + +deps += ['bus_pci'] diff --git a/drivers/common/nfp/nfp_common_log.c b/drivers/common/nfp/nfp_common_log.c new file mode 100644 index 0000000000..e69e608eb9 --- /dev/null +++ b/drivers/common/nfp/nfp_common_log.c @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#include "nfp_common_log.h" + +RTE_LOG_REGISTER_SUFFIX(nfp_logtype_common, common, NOTICE); diff --git a/drivers/common/nfp/nfp_common_log.h b/drivers/common/nfp/nfp_common_log.h new file mode 100644 index 0000000000..066e38e688 --- /dev/null +++ b/drivers/common/nfp/nfp_common_log.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_COMMON_LOG_H__ +#define __NFP_COMMON_LOG_H__ + +#include + +extern int nfp_logtype_common; +#define PMD_DRV_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, nfp_logtype_common, \ + "%s(): " fmt "\n", __func__, ## args) + +#endif/* __NFP_COMMON_LOG_H__ */ diff --git a/drivers/common/nfp/nfp_common_pci.c b/drivers/common/nfp/nfp_common_pci.c new file mode 100644 index 0000000000..65f189b05e --- /dev/null +++ b/drivers/common/nfp/nfp_common_pci.c @@ -0,0 +1,274 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#include "nfp_common_pci.h" + +#include + +#include +#include +#include + +#include "nfp_common_log.h" + +/* Reported driver name. */ +#define NFP_PCI_DRIVER_NAME "nfp_common_pci" + +static struct rte_pci_driver nfp_common_pci_driver; + +/* PCI ID table is build dynamically based on registered nfp drivers. */ +static struct rte_pci_id *nfp_pci_id_table; + +/* Head of list of drivers. */ +static TAILQ_HEAD(nfp_drivers, nfp_class_driver) nfp_drivers_list = + TAILQ_HEAD_INITIALIZER(nfp_drivers_list); + +static bool nfp_common_initialized; + +static const struct { + const char *name; + enum nfp_class drv_class; +} nfp_classes[] = { + { .name = "eth", .drv_class = NFP_CLASS_ETH }, +}; + +static enum nfp_class +nfp_class_name_to_value(const char *class_name) +{ + uint32_t i; + + for (i = 0; i < RTE_DIM(nfp_classes); i++) { + if (strcmp(class_name, nfp_classes[i].name) == 0) + return nfp_classes[i].drv_class; + } + + return NFP_CLASS_INVALID; +} + +static uint32_t +nfp_pci_id_table_size_get(const struct rte_pci_id *id_table) +{ + uint32_t table_size; + + if (id_table == NULL) + return 0; + + for (table_size = 0; id_table->vendor_id != 0; id_table++) + table_size++; + + return table_size; +} + +static bool +nfp_pci_id_exists(const struct rte_pci_id *id, + const struct rte_pci_id *table, + uint32_t next_idx) +{ + uint32_t i; + + if (next_idx == 0) + return false; + + for (i = 0; i < next_idx; i++) { + if (id->device_id == table[i].device_id && + id->vendor_id == table[i].vendor_id && + id->subsystem_vendor_id == table[i].subsystem_vendor_id && + id->subsystem_device_id == table[i].subsystem_device_id) + return true; + } + + return false; +} + +static void +nfp_pci_id_insert(struct rte_pci_id *new_table, + uint32_t *next_idx, + const struct rte_pci_id *id_table) +{ + if (id_table == NULL) + return; + + /* Add non duplicate entries to new table. */ + for (; id_table->vendor_id != 0; id_table++) { + if (!nfp_pci_id_exists(id_table, new_table, *next_idx)) { + new_table[*next_idx] = *id_table; + (*next_idx)++; + } + } +} + +static int +nfp_pci_id_table_update(const struct rte_pci_id *driver_id_table) +{ + uint32_t i = 0; + uint32_t num_ids = 0; + struct rte_pci_id *old_table; + const struct rte_pci_id *id_iter; + struct rte_pci_id *updated_table; + + old_table = nfp_pci_id_table; + if (old_table != NULL) + num_ids = nfp_pci_id_table_size_get(old_table); + num_ids += nfp_pci_id_table_size_get(driver_id_table); + + /* Increase size by one for the termination entry of vendor_id = 0. */ + num_ids += 1; + updated_table = calloc(num_ids, sizeof(struct rte_pci_id)); + if (updated_table == NULL) + return -ENOMEM; + + if (old_table == NULL) { + /* Copy the first driver's ID table. */ + for (id_iter = driver_id_table; id_iter[i].vendor_id != 0; i++) + updated_table[i] = id_iter[i]; + } else { + /* First copy existing table entries. */ + for (id_iter = old_table; id_iter[i].vendor_id != 0; i++) + updated_table[i] = id_iter[i]; + /* New id to be added at the end of current ID table. */ + nfp_pci_id_insert(updated_table, &i, driver_id_table); + + free(old_table); + } + + /* Terminate table with empty entry. */ + updated_table[i].vendor_id = 0; + nfp_pci_id_table = updated_table; + nfp_common_pci_driver.id_table = nfp_pci_id_table; + + return 0; +} + +static int +nfp_kvarg_dev_class_handler(__rte_unused const char *key, + const char *class_str, + void *opaque) +{ + enum nfp_class *dev_class = opaque; + + if (class_str == NULL) + return *dev_class; + + *dev_class = nfp_class_name_to_value(class_str); + + return 0; +} + +static enum nfp_class +nfp_parse_class_options(const struct rte_devargs *devargs) +{ + struct rte_kvargs *kvargs; + enum nfp_class dev_class = NFP_CLASS_ETH; + + if (devargs == NULL) + return dev_class; + + kvargs = rte_kvargs_parse(devargs->args, NULL); + if (kvargs == NULL) + return dev_class; + + if (rte_kvargs_count(kvargs, RTE_DEVARGS_KEY_CLASS) != 0) { + rte_kvargs_process(kvargs, RTE_DEVARGS_KEY_CLASS, + nfp_kvarg_dev_class_handler, &dev_class); + } + + rte_kvargs_free(kvargs); + + return dev_class; +} + +static int +nfp_drivers_probe(struct rte_pci_device *pci_dev, + enum nfp_class class) +{ + int32_t ret = 0; + struct nfp_class_driver *driver; + + TAILQ_FOREACH(driver, &nfp_drivers_list, next) { + if (driver->drv_class != class) + continue; + + ret = driver->probe(pci_dev); + if (ret < 0) { + PMD_DRV_LOG(ERR, "Failed to load driver %s", driver->name); + return ret; + } + } + + return 0; +} + +static int +nfp_common_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev) +{ + enum nfp_class class; + struct rte_device *eal_dev = &pci_dev->device; + + PMD_DRV_LOG(INFO, "probe device %s.", eal_dev->name); + + class = nfp_parse_class_options(eal_dev->devargs); + if (class == NFP_CLASS_INVALID) { + PMD_DRV_LOG(ERR, "Unsupported nfp class type: %s", + eal_dev->devargs->args); + return -ENOTSUP; + } + + return nfp_drivers_probe(pci_dev, class); +} + +static int +nfp_common_pci_remove(__rte_unused struct rte_pci_device *pci_dev) +{ + return 0; +} + +static struct rte_pci_driver nfp_common_pci_driver = { + .driver = { + .name = NFP_PCI_DRIVER_NAME, + }, + .probe = nfp_common_pci_probe, + .remove = nfp_common_pci_remove, +}; + +static void +nfp_common_init(void) +{ + const struct rte_pci_id empty_table[] = { + { + .vendor_id = 0 + }, + }; + + if (nfp_common_initialized) + return; + + /* + * All the constructor of NFP PMDs run at same priority. So any of the PMD + * including this one can register the PCI table first. If any other + * PMD(s) have registered the PCI ID table, no need to register an empty + * default one. + */ + if (nfp_pci_id_table == NULL && nfp_pci_id_table_update(empty_table) != 0) + return; + + rte_pci_register(&nfp_common_pci_driver); + nfp_common_initialized = true; +} + +void +nfp_class_driver_register(struct nfp_class_driver *driver) +{ + nfp_common_init(); + + if (driver->id_table != NULL) { + if (nfp_pci_id_table_update(driver->id_table) != 0) + return; + } + + nfp_common_pci_driver.drv_flags |= driver->drv_flags; + + TAILQ_INSERT_TAIL(&nfp_drivers_list, driver, next); +} diff --git a/drivers/common/nfp/nfp_common_pci.h b/drivers/common/nfp/nfp_common_pci.h new file mode 100644 index 0000000000..21465fca68 --- /dev/null +++ b/drivers/common/nfp/nfp_common_pci.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_COMMON_PCI_H__ +#define __NFP_COMMON_PCI_H__ + +#include + +/* Initialization function for the driver called during device probing. */ +typedef int (nfp_class_driver_probe_t)(struct rte_pci_device *dev); + +/* Uninitialization function for the driver called during hot-unplugging. */ +typedef int (nfp_class_driver_remove_t)(struct rte_pci_device *dev); + +enum nfp_class { + NFP_CLASS_ETH, + NFP_CLASS_INVALID, +}; + +/* Describing a nfp common class driver. */ +struct nfp_class_driver { + TAILQ_ENTRY(nfp_class_driver) next; + enum nfp_class drv_class; /**< Class of this driver. */ + const char *name; /**< Driver name. */ + const struct rte_pci_id *id_table; /**< ID table, NULL terminated. */ + uint32_t drv_flags; /**< Flags RTE_PCI_DRV_*. */ + nfp_class_driver_probe_t *probe; /**< Device probe function. */ + nfp_class_driver_remove_t *remove; /**< Device remove function. */ +}; + +/** + * Register a nfp device driver. + * + * @param driver + * A pointer to a nfp_driver structure describing the driver + * to be registered. + */ +__rte_internal +void +nfp_class_driver_register(struct nfp_class_driver *driver); + +#endif /* __NFP_COMMON_PCI_H__ */ diff --git a/drivers/common/nfp/version.map b/drivers/common/nfp/version.map new file mode 100644 index 0000000000..25e48c39d6 --- /dev/null +++ b/drivers/common/nfp/version.map @@ -0,0 +1,7 @@ +INTERNAL { + global: + + nfp_class_driver_register; + + local: *; +}; diff --git a/drivers/meson.build b/drivers/meson.build index 8c775bbe62..af70ed322c 100644 --- a/drivers/meson.build +++ b/drivers/meson.build @@ -15,6 +15,7 @@ subdirs = [ 'common/mlx5', # depends on bus. 'common/qat', # depends on bus. 'common/sfc_efx', # depends on bus. + 'common/nfp', # depends on bus. 'mempool', # depends on common and bus. 'dma', # depends on common and bus. 'net', # depends on common, bus, mempool -- 2.39.1