From patchwork Wed Aug 30 02:14:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chaoyong He X-Patchwork-Id: 130864 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C327A41FC8; Wed, 30 Aug 2023 04:19:06 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 80BA240ED6; Wed, 30 Aug 2023 04:16:18 +0200 (CEST) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2126.outbound.protection.outlook.com [40.107.212.126]) by mails.dpdk.org (Postfix) with ESMTP id D7F1C40E72 for ; Wed, 30 Aug 2023 04:16:15 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LBe5d8Qd51V8qF9+sKtOvD6mrVQY/FTGM9s9IcjaEHtjueiQXcWurRJuSLyDuSn8wE6Iz12u6RrLm3Ye2YR9KigcdNlPVIAMMLqgNquOrCgMk8z878KrJBEXMEplyGnhJL4rFbhN369qhlL7UqVlRfVmmTN73bjd/wqlAY/Ow11CBNhw1dbDajDu5aLIZn7lQ0x2Jbtnor8I82mPIX+XfKgHhTjwY9t1j4SM0Wcc/wlVFKBkXfDUjJRLHKw0pKOdEIwTb1L8EJKWLEZPzYMR7BtrB+X5E3qCTM+jkGDRYf5jgsINW5pByMv0bw+199SFqmwjC/1LjRNXw6TdH4sNoA== 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=O0eui1uCQQGt2N38CMW96vEtZmFfy2Bvr+QxFbQDJtg=; b=RY+JfDQMz1q6UnlyQ1lo6usVhhdoBBocyleTzBdbh2J6EslC+LaBReQByCv50MB9VSYaN2AVbNsBLjSu7GRJx2RpZ544UbA1gfhzLyErQ/0C/Tk+vkIqOccsw0cj9Zob1i78lMGhKAZIxFKqsE3+45MpOB8IhaxkpegaHkJ2elnH/OKBDyoPrFc9c4NAxvy37CsqL0Yt7BFNdxP0eEqK9BxqQwfrrVf4U2xCZAtAXfKa0ZfqrEEytgSJmOzu5SskwzDoNGakTrY4VJtk/P/eHehQe4ex4H5ahh3j6DyaCoQVuG9UAhVQlo7MzWho1ph3Jt/8uhIcvyufZJkXp4QJ7Q== 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=O0eui1uCQQGt2N38CMW96vEtZmFfy2Bvr+QxFbQDJtg=; b=GH2o1a3Ligo7OwbLrTb7bCzRsWVJr7lMWeEPRUj0Skh687IkUA2pJ6z5XLTHjrdzsPAM4XWH99xv/no6I+vnsPgXQzNC9uwyUSeuxH8iLocQxL7tuxRMVV3xb6T/Ia2HFldm5tfmqaTt7iK4qfoHzDkTHTRMSy6RSC6RaHtETRY= 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 DM6PR13MB3786.namprd13.prod.outlook.com (2603:10b6:5:229::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.18; Wed, 30 Aug 2023 02:16:13 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::c0f3:c2cc:b5bb:4192]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::c0f3:c2cc:b5bb:4192%4]) with mapi id 15.20.6699.034; Wed, 30 Aug 2023 02:16:13 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com, Chaoyong He Subject: [PATCH v2 26/27] net/nfp: refact the cppcore and PCIe module Date: Wed, 30 Aug 2023 10:14:56 +0800 Message-Id: <20230830021457.2064750-27-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230830021457.2064750-1-chaoyong.he@corigine.com> References: <20230824110956.1943559-1-chaoyong.he@corigine.com> <20230830021457.2064750-1-chaoyong.he@corigine.com> X-ClientProxiedBy: PH0PR07CA0113.namprd07.prod.outlook.com (2603:10b6:510:4::28) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|DM6PR13MB3786:EE_ X-MS-Office365-Filtering-Correlation-Id: d62049b4-9d7e-45a9-652f-08dba8ff1594 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qPFYYemXmogl2U3B1Cdodsjy7WzROCmhQh7B18WgBTPIKOs6w9f3rosZYRYz/XDH5xsO+kXqtHyBQq3hG1cNzOmWdiFntrallqHUYg9zgbxZv7bMn43U38xNDJuzL5tOsfqR2NdJaGPUv4KIUL1GRKsj2WtW9q/1K676PnNxNI4zp0yEf7Ioy3GAky7ju1XyQJzgrr7m3PR49FrJapu5kpNBjmwUIQL+K1vIc/pWSoPzpzftu1KN6TmZAQx3u+PctlCbcSrC51ndIuFjJsDQ5Aj5ujFeBrzYN906J15RMLfvCMgnJj3qt2cCLyBSceW5dtvBdRXEwRN0bAnbtBGEeJiaBC8KpMPpW35DqtsjkZ+UQ1OsTD8E88Tlg747Nq3Ym2r60bL/IR0CwDjAcUrjO4Tmh0+xb2kd16OoX3Sx/P17BMVCd1Q7cQiJhwgvk9kJvQ7ZN8su62iUaYAgTu0qpLRmVNZ2ulj5yVR2xX6yiqg2QlCkv6GKVBErVvuCjpCSv2MQhqUa9aqALPITYJHjnNfGqQ0SBoc/1MMgCt6XotycJlWNj59lRm1jjkmPCKMqsMwLJYJ/eVffBJYDsJCt3+g16H9pDnmIGHqfUE1Z65OVOsikSdSkGlfk41Qx92yJfGd0XB3QUMP3sb7O3amMVneYuOFSieHIySolgnBvf5M= 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)(136003)(366004)(376002)(346002)(396003)(39830400003)(451199024)(186009)(1800799009)(6512007)(6916009)(316002)(38100700002)(41300700001)(38350700002)(2906002)(4326008)(66574015)(30864003)(83380400001)(2616005)(86362001)(44832011)(26005)(36756003)(1076003)(8676002)(5660300002)(107886003)(8936002)(6666004)(6506007)(6486002)(66556008)(66946007)(66476007)(52116002)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?psQ9GRHct9JrGM5LCYYJj1fBy8fr?= =?utf-8?q?nuBKqXUUF2kkmU7o8hS3aAG8ddv3FpCF5Sg0+qL7z+HSx4jpmHqwmR1S9j5SqCtDv?= =?utf-8?q?h914G2r1FYvvW+xsCk2LiDhAe+lpjYx632Xt9uTcIR6ZOANEt90IonsXjxeBcDPB6?= =?utf-8?q?XcCT+LGLAiCiA/pz2JPDdma5svwhVbrJUUjbA6yeSaSkdf19BLFWaEY3uB2FjeFTX?= =?utf-8?q?t+xyld72ptBs+mFBb4UbsYcoq2nJVz5taQv0MCmWmMgi8YUp1vwJW8zbg4yWjZKO5?= =?utf-8?q?1CqhFrxRjpCFYRtnpm0vdh0SEU/agDagFPDCUOrYjnqA75nrWlBQ40z9x12lAHLco?= =?utf-8?q?ths0Q1EtrqT3iXMfi4SJiLICzo3SpFos8evzieO+me2DYrtcVD+f6LpDfoeee1/E0?= =?utf-8?q?Jrg/z57IooEjzB/4U1XzpLwjZb51fLkoBX3rZnX+GyzAWOuJrWwkMmDP2pzDYqG6p?= =?utf-8?q?T9Cd4L8plbKCKjmydB7QEDI7Zt/x4LNg6HbeDpPP5rluu77pexUy9lvGs7rE3+Tjt?= =?utf-8?q?VWDsRnuoDDXZ4Frpc92tWr3PBZ5a6zxUG2m79vBzlhZyN+4p+I+mf8/XZfRBdeUYJ?= =?utf-8?q?3i6oBpTc30NKty0Qpgj6ujvaJsxTf0MqRWectLh6s2e6SrF+st4YTcexZLPqWBAxX?= =?utf-8?q?SI4G0ccRbu+Ts6iTWx5BCJ9ig7ocXjWW8BiF/rieh1xlXlIN5dAgh2Tn0Ih9N0B+Y?= =?utf-8?q?jTTp0aV5t32R30/rNKo3CvuL8saF481izVpiOO4R3LxIzmYtvR7IT+txkzqBIJgeg?= =?utf-8?q?PeNIXxua5V6TJanA6IK+PBVDQsgTK3I79QO5ixQEQ/oYEbVY9+gdk8IRe1vB701Ku?= =?utf-8?q?ERp52eOrFcgU84Q1vv0FGD7OZW8vX2yLBRiQ3hOIZ5GM8/fBZj7TqkyTQ9qQNsQPL?= =?utf-8?q?Q2kdvmIx47ZvVZrvVWo239iRLXl8zM49LpDFQFo0VEa4NJGt7KRPUfBPVPZtQW/7D?= =?utf-8?q?OpYT4dP7fqwC2B+vchpkmzB4GD/uDE/1Odb+oCK4rQN4SCGkvDgn3uNO4vzGr03HN?= =?utf-8?q?tUT9Jh2JPxSvkxaOY7Glk3HFve4oywJe/6g2fuOMF3YHuRbtxSleoPUbyNzvyJDeD?= =?utf-8?q?qPo2xkMWLjrBstaFofP9BhGK/36EA/2l3zEKoRfjE7vS1DWkpv0eoRyjrfztZa5Qw?= =?utf-8?q?xEM981Nvgwpk/MdtXmyf5msM9q9X63BWe5XYexf1BVrvg7x32ZMIIIaVwT5zdYDt6?= =?utf-8?q?uvfdGNr+Vb/NJIeUai3mI6suaHvvq0wuw/R66xBpI8U4i4XJ64KcKGO7wdUYugTiQ?= =?utf-8?q?NucYIhC9m5/NZk8tlGeweONxSGANbtfvNT2g9uOMETAXszbafMhGrUujLjx6rkYMJ?= =?utf-8?q?s+iLzStF/Ni+PwjkBZE8ZeC+p31LFwIwGEld53IHvl+OKrX2E1vJ7TGJ3XTE9nph8?= =?utf-8?q?nXW+2L1c3n+ehbRx7wmgKhqCRG9epMMHH4c6XAhy/ik0qBNdtxfUfKBiAHq2YDEde?= =?utf-8?q?D070KQm9J5e9H+McZbdzsFrDjw5lqzDXq3+7HbSIZPpQKd3gyynKwpt/eog518oPu?= =?utf-8?q?hppY7Kq2/wC1nfI/CwoO7Nci02HHVfrnzg=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: d62049b4-9d7e-45a9-652f-08dba8ff1594 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2023 02:16:13.8594 (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: yhV1fR2E/m4cnBHAW7lGYZdqxXvAqqpWtUoRcwFiC+Ojxc98+cM5VSklouW/TDie/MchVTlbd6UcNpVWGItHSxpjILX1ca6o+TLMbzBYWAo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR13MB3786 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 Reviewed-by: Niklas Söderlund --- 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, 141 insertions(+), 175 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 5d129d0ad3..6eefec3836 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" @@ -917,9 +918,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..e32ac1107c 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 @@ -848,7 +750,7 @@ nfp6000_free(struct nfp_cpp *cpp) if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); - free(desc); + rte_free(desc); } static const struct nfp_cpp_operations nfp6000_pcie_ops = { @@ -873,3 +775,58 @@ 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 = rte_zmalloc(NULL, sizeof(*nfp), 0); + if (nfp == NULL) + return NULL; + + ret = nfp6000_get_interface(pci_dev, &interface); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Get interface failed."); + rte_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."); + rte_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"); + rte_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"); + rte_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 209d0b5160..6f46dbf5b7 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) { + rte_free(cpp); + return NULL; + } + + err = ops->get_serial(pci_dev, cpp->serial, NFP_SERIAL_LEN); + if (err != 0) { + rte_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"); + rte_free(cpp); + return NULL; + } + + err = nfp_cpp_model_autodetect(cpp, &cpp->model); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP model detection failed"); + rte_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"); rte_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) { - rte_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); } /**