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 AE241425CD; Wed, 20 Sep 2023 03:29:17 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 357F840278; Wed, 20 Sep 2023 03:29:17 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2134.outbound.protection.outlook.com [40.107.92.134]) by mails.dpdk.org (Postfix) with ESMTP id 1290B40277 for ; Wed, 20 Sep 2023 03:29:16 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VTL8NtQoAR4/uqDHfkKZOAsX3SqMy4BPf/B+jEza0Fcvv2gKDEn54lNAI6smNKIxq31Hhc+Ut3UVyIBkB7NGO04EyrC8vs1STljcujoSD7IA4y3+0Se7ME5GYMsjXd5YVkvh3KRzysusXsX5DkGRqhjMWZTs9EmmzoQeLH7tcn9xVyAS2l4WGYAM1k7WFgllaMQcro6r/91mSqXgwz8dd0SANm9pVFcfJQaJUU+mpQWgB2B+prLgcBI21fAw8fMAEAgiTz7ecuWgIibY+ykxcX+oO10K9KaAzjziuNH4k/7mw6VZDfVXPP6OoXbA1YUcxGQ0IgOIsjrzLJkFs7n3Jg== 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=ITlXIlMZCya8FSM9aZ/4trxAuaPbIrmC4qzuTJB55NI=; b=Wexdrlh8bssiMYAPIyT4I73rVSY/couQjbnmtDOa4SU+qtuR9LoR8ckxnD5MJhnGh/ispwFnZIKt2iCzroTYcaRXlvKnj/hGj2IVFqCakYinrrGrZoXH9CMx6adWIf5X4lsOGPfyYn64w7m87/Q34P5Q8LVNANBgHjFbesKILMzClNgZslIQ9DRGlJboubJ7qOGtfkrscGAYxU2q99u84vLusoBqnYwaqxIK51mGjmfPxC0tHL5YuL3hXvSufpu9YtQVMZ4XPpUJ/9sXvH8UoViw1ZkV2eLaMMEfa+5xH6WWOvCAwifsq74zfpJoPfzXOMKuXLGVz0a2TuKiQBQMUg== 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=ITlXIlMZCya8FSM9aZ/4trxAuaPbIrmC4qzuTJB55NI=; b=Ms/E2QA7qNjKT5FxC3zzn451XyYmbzJSNtI9OK1xowDIOZokmfOz5ZkkK2CZvjEqtQPKKlknGvueT8XuztJ+s/SJqyhpYB4B+6ZOjT7AxXzH20pjeFc2sFTte1PhCAkiHuIETxodSeJLKytOMQgnKPfSuUXJe9MpHWH6qh7b7vk= 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 CH2PR13MB3623.namprd13.prod.outlook.com (2603:10b6:610:98::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.19; Wed, 20 Sep 2023 01:29:07 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7a1c:2887:348a:84bd]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7a1c:2887:348a:84bd%6]) with mapi id 15.20.6792.026; Wed, 20 Sep 2023 01:29:06 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He Subject: [PATCH v5 25/26] net/nfp: refact the cppcore and PCIe module Date: Wed, 20 Sep 2023 09:28:46 +0800 Message-Id: <20230920012846.46379-1-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230918024612.1600536-1-chaoyong.he@corigine.com> References: <20230918024612.1600536-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: PH7PR17CA0060.namprd17.prod.outlook.com (2603:10b6:510:325::24) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|CH2PR13MB3623:EE_ X-MS-Office365-Filtering-Correlation-Id: 969a1389-f772-432d-2634-08dbb978fa78 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 73oimSa/DBySpUW38VgO8fxRcBVEv6OIenKUvVMKwrLHvLR/QMiNy9EHVeEq5ALsNYXkFRi6rdDQpYr0UgPeZqF6gp8MYwV3o00Klb92UPGwn8p87AcT6ulgtJXo8eDH6upRFwBKoWMyBIFgGQ8d+k7wHc/KyeEAoB98P4BqOaz/nm/ji4AGm8aDTGYaf+suCRGAhot4qKJkdUvsqCZM+0tEFk1Yv0QfLst2M3waxkfOhBIQlioLCFBEVdIUKqY/h9XxBlb0xr2KKJjWlbYZoKxOc3etVkdFP8UX6IWE9Trpti4IraaIM81UbU9Is+rJSAtNaoFsHw7xFUBy3/KgLAhnaFd3u0Oj0Y1mDkAcQmYFxbF4+xSqjSdHqpMuuXmbT24GvBtP9tzNx2tmMlB8YPYIy1vYoj4Vdn/JzBaZkhviJ/2AKqp+wEhP9tTwsLBASNe3+d9E+PdQG0z1zDZFWCFHyMsCm8fBDHyAQpnpkHApAwDo1bsayEoPSPUFAVQ/ooPYZ1dIKBzsf1fcwnLdVXEMJyRmrJBVPyJR6vzJ/zIvvXLSGz4msNka4p+A/3gi8mHCs2PTvCbbzMosSHckLvK7TrJx9Py6d6Yib+GO1evadkXilQZS4lgWfExQE4PcjWvSsIJE4H5W0vH+p/LDTUcgJIbS8y4+oSGb93oDrYY= 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)(366004)(396003)(376002)(136003)(39830400003)(346002)(1800799009)(186009)(451199024)(478600001)(6486002)(6666004)(6512007)(6506007)(52116002)(8936002)(8676002)(44832011)(83380400001)(66946007)(66476007)(66556008)(6916009)(316002)(5660300002)(107886003)(2616005)(36756003)(38100700002)(38350700002)(86362001)(4326008)(26005)(2906002)(1076003)(41300700001)(30864003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?l6dsWUhtTNOtSGhjG1G0ZZGEPOTv/GhxhfnoRRmAAMOhsUl5AuCgZrXVk9MN?= =?us-ascii?Q?BzQ3YKAmlnjJcXDu+g6QSNhQaPSU1sIfiwpFvrxfWXKJ2UYtLh5Qw5sdO+ik?= =?us-ascii?Q?aFif3zY2ENP5is7m/bbWCamjIIq7v0hIzxexSm2f+baZ0cQd+ff94R+xbhvs?= =?us-ascii?Q?5Ykn+V28kEg/VcKJSkN6nquS/ggyCMCqz+sgm7ixM1+/4NNqbPZTlx2Zx9fI?= =?us-ascii?Q?mwWoWb/QMVB/P2LKzAM91Bcz7PyFF3dBGzMgNSS5ROQ0UxxSVkovYCTb91NA?= =?us-ascii?Q?O2AxOlz5Kz4kYMFJly5MmLIJR3tlcNZRhAl/8GpiHu4xA1csgMqN+7t4azGN?= =?us-ascii?Q?e5ce2/eFfZ1QF3TptLnyjOux6sTT91XuR4r+bZRQHl1KX3uzXElN41ntNZLk?= =?us-ascii?Q?0WwyQ4smgMiJm0DK/CkUuKYZgBmMGbuSf6UHoLaTrA/wPGDeFKKFQOYMLSnf?= =?us-ascii?Q?sHD12lEB7fxtD0RRsVeBFyVVo+f6A9px6yAPP7NZZQuBbrZdZv3pbT/DJKyV?= =?us-ascii?Q?tnTOb85ZovmekzCVW6dvz0NkEpKf4vQ0HFoxwg9Hqa0Pq6KSahrGdh0vI88M?= =?us-ascii?Q?5FnprUS2Fz0JWrcx6xRjD9CagUgJfxtiOYt7INJbnl3ZHxFokJlXAR8S+8Cb?= =?us-ascii?Q?hdviWAL1D+e9iCGznkaVIYNQqDiBsCThjpRhtypacFakvSzS4BZ+/cYZi9oa?= =?us-ascii?Q?3mhsV2DZqe+ve8YQQ/Rn/11gR2+El1IDu86LpWtofQ7flUsODoITW6tq9/UY?= =?us-ascii?Q?t23a6jv3r1G7/dFQ8OR/XG+B2tDlUBz4wacL0oxQHzrvQARQT0TWmQ/pj/gc?= =?us-ascii?Q?pJ8MJl1h8+6YWJtD7O0lDQH+SaG8p70aWs5hCBWvapJUUNHNB4m4A6jjFy7c?= =?us-ascii?Q?C54ouXSX186LhehFyrOIsnBAhBezr82EGzYQLQOR6v6kUaNuEmAtFvQeEitq?= =?us-ascii?Q?OMVnSzJqX9yUxt5RyXoutxDpFHSl6qZaG0VusqPxg2IGsAqHsiliUke3no4r?= =?us-ascii?Q?JPdNQTktMecNhAfyLGLfS4vM/PxrzMj1GlZwTqzoRmCRKF74PQH/73JMTXVx?= =?us-ascii?Q?sZC0ILH0nhNKxB3xDVmjcZO3gX4ot1pJiISRvZuz0rcSKKzIRas5kf8WHDAM?= =?us-ascii?Q?vzHJnf5Nk8+BZok6KTRiSpFQNziJC3WlBSRMDUF4J6qv6njF1NzxP7XW2Xxo?= =?us-ascii?Q?P05bx5/krQfqo+DTb83YoaYwD0L+e+y55ICA/Q1kmNc7RssQs1m4r317cRUI?= =?us-ascii?Q?M1jmVxGb4TyNR78+HBHbQEECDSzO8548ZmLuHV4jHUDbGUIy6E1XeZFRDmSs?= =?us-ascii?Q?gUkHNKIMVR6uZm5hhXVQMctQFdt1DHmi4ZSlVGO49EW/vZgZFfarU7aCAZGX?= =?us-ascii?Q?vWq8vpcHtGkmtk6qNPHbtQSVfPO6eyLhjjCBqbFNhiISn3CvgZSzg26eqwfb?= =?us-ascii?Q?8psNilx9J/TH6NW0Nz6d4rmdTVjntJx64ft7f/Q5wp/6J5yTYfnjlo8S1SnX?= =?us-ascii?Q?85ZDmClg/2v6cfMdLKQnh+SuPdfctwIKvs9l/I47gm20hJviokwzSHzKaEIh?= =?us-ascii?Q?+1LfMdyn660U8ltQK55fsfBi13xbCAkEZljZFNkYDTNFdGrEZXcyFO358/pR?= =?us-ascii?Q?Qg=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 969a1389-f772-432d-2634-08dbb978fa78 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 01:29:06.5084 (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: /+38v2hW2FxL37iOrjxGw2j9AhW9grwRFEu5730Xva10JYoKtYU4OZl+X0iB9fNg/c4FMzXUSIOeHQxWnomTIE60EvJZhS9cs0Ytm8kmuig= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR13MB3623 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 Sync the logic from kernel driver, use the new entry function from the PCIe module instead of the cppcore module. Signed-off-by: Chaoyong He --- drivers/net/nfp/nfp_ethdev.c | 9 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 197 ++++++++++--------------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 6 + drivers/net/nfp/nfpcore/nfp_cpp.h | 36 +---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 68 ++++++--- 5 files changed, 142 insertions(+), 174 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 04244c4e08..673bb06d00 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -23,6 +23,7 @@ #include "nfpcore/nfp_mip.h" #include "nfpcore/nfp_rtsym.h" #include "nfpcore/nfp_nsp.h" +#include "nfpcore/nfp6000_pcie.h" #include "nfp_common.h" #include "nfp_ctrl.h" @@ -919,9 +920,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1120,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 4f453f19a9..40076cdc11 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -98,6 +98,24 @@ struct nfp_pcie_user { char *cfg; }; +/* Generic CPP bus access interface. */ +struct nfp6000_area_priv { + struct nfp_bar *bar; + uint32_t bar_offset; + + int target; + int action; + int token; + uint64_t offset; + struct { + int read; + int write; + int bar; + } width; + size_t size; + char *iomem; +}; + static uint32_t nfp_bar_maptype(struct nfp_bar *bar) { @@ -334,24 +352,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* Generic CPP bus access interface. */ -struct nfp6000_area_priv { - struct nfp_bar *bar; - uint32_t bar_offset; - - uint32_t target; - uint32_t action; - uint32_t token; - uint64_t offset; - struct { - int read; - int write; - int bar; - } width; - size_t size; - char *iomem; -}; - static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, @@ -624,87 +624,6 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) return 0; } -static int -nfp6000_set_model(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint32_t model; - - if (rte_pci_read_config(dev, &model, 4, 0x2e) < 0) { - PMD_DRV_LOG(ERR, "nfp set model failed"); - return -1; - } - - model = model << 16; - nfp_cpp_model_set(cpp, model); - - return 0; -} - -static int -nfp6000_set_interface(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint16_t interface; - - if (rte_pci_read_config(dev, &interface, 2, 0x154) < 0) { - PMD_DRV_LOG(ERR, "nfp set interface failed"); - return -1; - } - - nfp_cpp_interface_set(cpp, interface); - - return 0; -} - -static int -nfp6000_set_serial(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - off_t pos; - uint16_t tmp; - uint8_t serial[6]; - int serial_len = 6; - - pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); - if (pos <= 0) { - PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found. nfp set serial failed"); - return -1; - } else { - pos += 6; - } - - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[4] = (uint8_t)((tmp >> 8) & 0xff); - serial[5] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[2] = (uint8_t)((tmp >> 8) & 0xff); - serial[3] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[0] = (uint8_t)((tmp >> 8) & 0xff); - serial[1] = (uint8_t)(tmp & 0xff); - - nfp_cpp_serial_set(cpp, serial, serial_len); - - return 0; -} - static int nfp6000_get_dsn(struct rte_pci_device *pci_dev, uint64_t *dsn) @@ -795,12 +714,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) { int ret = 0; - struct nfp_pcie_user *desc; - - desc = malloc(sizeof(*desc)); - if (desc == NULL) - return -1; - + struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); memset(desc->busdev, 0, BUSDEV_SZ); strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); @@ -809,17 +723,11 @@ nfp6000_init(struct nfp_cpp *cpp, nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) - goto error; + return -1; } - if (nfp6000_set_model(dev, cpp) < 0) - goto error; - if (nfp6000_set_interface(dev, cpp) < 0) - goto error; - if (nfp6000_set_serial(dev, cpp) < 0) - goto error; if (nfp6000_set_barsz(dev, desc) < 0) - goto error; + return -1; desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; @@ -830,13 +738,7 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - nfp_cpp_priv_set(cpp, desc); - return 0; - -error: - free(desc); - return -1; } static void @@ -873,3 +775,60 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) { return &nfp6000_pcie_ops; } + +/** + * Build a NFP CPP bus from a NFP6000 PCI device + * + * @param pdev + * NFP6000 PCI device + * @param driver_lock_needed + * driver lock flag + * + * @return + * NFP CPP handle or NULL + */ +struct nfp_cpp * +nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed) +{ + int ret; + struct nfp_cpp *cpp; + uint16_t interface = 0; + struct nfp_pcie_user *nfp; + + nfp = malloc(sizeof(*nfp)); + if (nfp == NULL) + return NULL; + + memset(nfp, 0, sizeof(*nfp)); + + ret = nfp6000_get_interface(pci_dev, &interface); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Get interface failed."); + free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_TYPE_of(interface) != NFP_CPP_INTERFACE_TYPE_PCI) { + PMD_DRV_LOG(ERR, "Interface type is not right."); + free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_CHANNEL_of(interface) != + NFP_CPP_INTERFACE_CHANNEL_PEROPENER) { + PMD_DRV_LOG(ERR, "Interface channel is not right"); + free(nfp); + return NULL; + } + + /* Probe for all the common NFP devices */ + cpp = nfp_cpp_from_device_name(pci_dev, nfp, driver_lock_needed); + if (cpp == NULL) { + PMD_DRV_LOG(ERR, "Get cpp from operation failed"); + free(nfp); + return NULL; + } + + return cpp; +} diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index e126457d45..8847f6f946 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -6,8 +6,14 @@ #ifndef __NFP6000_PCIE_H__ #define __NFP6000_PCIE_H__ +#include + #include "nfp_cpp.h" +#include "nfp_dev.h" const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); +struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed); + #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0f36ba0b50..e879c7c920 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,40 +226,12 @@ uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + void *priv, bool driver_lock_needed); void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/** - * Retrieve the chip ID from the model ID - * - * The chip ID is a 16-bit BCD+A-F encoding for the chip type. - * - * @param model - * NFP CPP model id - * - * @return - * NFP CPP chip id - */ -#define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) - -/** - * Check for the NFP6000 family of devices - * - * NOTE: The NFP4000 series is considered as a NFP6000 series variant. - * - * @param model - * NFP CPP model id - * - * @return - * true if model is in the NFP6000 family, false otherwise. - */ -#define NFP_CPP_MODEL_IS_6000(model) \ - ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ - (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) - uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,6 +302,12 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) +/* + * Use this channel ID for multiple virtual channel interfaces + * (ie ARM and PCIe) when setting up the interface field. + */ +#define NFP_CPP_INTERFACE_CHANNEL_PEROPENER 255 + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index bbf2eaa448..8b2d00a6a1 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -909,10 +909,13 @@ nfp_xpb_readl(struct nfp_cpp *cpp, } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, - int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *pci_dev, + void *priv, + bool driver_lock_needed) { int err; + size_t target; + uint32_t xpb_addr; struct nfp_cpp *cpp; const struct nfp_cpp_operations *ops; @@ -925,32 +928,50 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return NULL; cpp->op = ops; + cpp->priv = priv; cpp->driver_lock_needed = driver_lock_needed; - if (cpp->op->init) { - err = cpp->op->init(cpp, dev); + err = ops->get_interface(pci_dev, &cpp->interface); + if (err != 0) { + free(cpp); + return NULL; + } + + err = ops->get_serial(pci_dev, cpp->serial, NFP_SERIAL_LEN); + if (err != 0) { + free(cpp); + return NULL; + } + + /* + * NOTE: cpp_lock is NOT locked for op->init, + * since it may call NFP CPP API operations + */ + err = cpp->op->init(cpp, pci_dev); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP interface initialization failed"); + free(cpp); + return NULL; + } + + err = nfp_cpp_model_autodetect(cpp, &cpp->model); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP model detection failed"); + free(cpp); + return NULL; + } + + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { + /* Hardcoded XPB IMB Base, island 0 */ + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, &cpp->imb_cat_table[target]); if (err < 0) { + PMD_DRV_LOG(ERR, "Can't read CPP mapping from device"); free(cpp); return NULL; } } - if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpb_addr; - size_t target; - - for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { - /* Hardcoded XPB IMB Base, island 0 */ - xpb_addr = 0x000a0000 + (target * 4); - err = nfp_xpb_readl(cpp, xpb_addr, - (uint32_t *)&cpp->imb_cat_table[target]); - if (err < 0) { - free(cpp); - return NULL; - } - } - } - err = nfp_cpp_set_mu_locality_lsb(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "Can't calculate MU locality bit offset"); @@ -981,6 +1002,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) * * @param dev * PCI device + * @param priv + * Private data of low-level implementation * @param driver_lock_needed * Driver lock flag * @@ -991,9 +1014,10 @@ nfp_cpp_free(struct nfp_cpp *cpp) */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed) + void *priv, + bool driver_lock_needed) { - return nfp_cpp_alloc(dev, driver_lock_needed); + return nfp_cpp_alloc(dev, priv, driver_lock_needed); } /** -- 2.39.1