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 E9A16430EF; Thu, 24 Aug 2023 13:14:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9D80243283; Thu, 24 Aug 2023 13:11:38 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2112.outbound.protection.outlook.com [40.107.93.112]) by mails.dpdk.org (Postfix) with ESMTP id A4B6643278 for ; Thu, 24 Aug 2023 13:11:34 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c5m29Rx/YUhYzX04I1moGsUHOLXn5gMRn56XoSm1V5L9+0BVl97A61SfZj3vuhl/qZw1PB+2vYlTTlDq5UDRlYo/IMcrwzmT1yB9TMLltuGfHBknuknapAxBqNe4l1IEYCzOetcO8HArL/HH048eS+rbatP82LiiWtcFhcrSNRUWkOMsmOYPKzSfbV/oZ/hwXT/vezGW50V8XWArtSfxxM6KwW0VLia4wAW9gheHN7Fjv5tcTDleHpKNYUpZEElcMHnrWTq5y6ptT+vtjnqKqH63mwP5MMpOdoc0H8w0V3heN4Fv6fml8l98/Xz1yLlRl14EKaBDZ8A6JKzZFNvc9A== 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=XMjgKZTRd8XatilF6/detPwzXJfEL1F/kYVLaxcCguI=; b=DeIt8cPFlLRBbvePxZFsVIN3pkEPWhLUoAcJslaycnGqSgsDo6QWUgZLi0RYYuHL/fABOoY/XGzFWKeDZBiJOl8t+K443FR+kDLHeIOjFU37rtgVg2GLZMJKNEL+lLfUoHXd3+WAl33NmFvT8stTrFKAQ2DeP6Ws0L6rqZ9Hg66DACu9FMs2ip9WW7XcfalpSohQr+qCkRC5GT5vZGAz5UW2LwbGZmXnX8826++nobuZr21LYfblZ44Hx+OR16QXvklT1JJn1CjQ0PV2cL9LSZpZbn3mhwVii7EinpYDtNIsK8WcI57WI+XuX1M9GtmTOGtXmxccyjrtjVRAjG++9Q== 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=XMjgKZTRd8XatilF6/detPwzXJfEL1F/kYVLaxcCguI=; b=WE3g8zyzUKpDiYeKVYQ5JAFZ5y+auEkWuNj1XNraTmdKUkw4DanPk/uRoJh6JTltbaQ+mCDdRows1DEQ6rQ+dcouFcWqUBOpV18VdyCKI9JktflPgbPhQH/XchrhlhutKMUj7ylxZ65kK9lYl0cL/jgy1Axgqi+m20xixwC/9Z4= 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 PH7PR13MB6116.namprd13.prod.outlook.com (2603:10b6:510:2b7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Thu, 24 Aug 2023 11:11:33 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::51fe:5846:af8b:bace]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::51fe:5846:af8b:bace%3]) with mapi id 15.20.6699.020; Thu, 24 Aug 2023 11:11:33 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com, Chaoyong He Subject: [PATCH 26/27] net/nfp: refact the cppcore and PCIe module Date: Thu, 24 Aug 2023 19:09:55 +0800 Message-Id: <20230824110956.1943559-27-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230824110956.1943559-1-chaoyong.he@corigine.com> References: <20230824110956.1943559-1-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SJ0PR05CA0005.namprd05.prod.outlook.com (2603:10b6:a03:33b::10) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH7PR13MB6116:EE_ X-MS-Office365-Filtering-Correlation-Id: 02162124-c0ef-4670-510a-08dba492dfb2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rS9q89N7Ujy4OxQIGhB4oGnSNe3nbar7F5CWHN8Mygn+Cp4dxroPVuUwqmHOrQYcGe08dEFu5Ez2GEyTOpgCzUv+T4hv0WR4sJ+tkglvmV7aEf7M3A9SH0rYkDMfVed8IEYiBUqH83vM/UUl0T+vSkIdiEs5CaDWJigQB2cQmanejWJGSDivkqRy20of89uML91qo7EJog5k1UER8yF7gO8vMPToFI3IkJt4AQhQrCQS218jSE1nWcPnHmcu7V94cAyVRAki3O7jHFh/DzImMQtjN8llehobWBVQoWzyzxeoN143NGOYBRkqHunciqI9pUhe/XbUxFbtwHwd77c3yMOLYkkGH45IEIcZDCWj1x2JAw/MbJ1JxRvIeZqfeJZpnQ0lsHtaFQO4vA4H7L2n1rYMH3t2lsZyks26jEpaXXF8atFy+XuU+QOK4zBLjDVTOLnOhOrBdRUsgLY4cpijX5HFHEpfy3SejQByIW7uaFc057Nv7uztlO9QlUSAOvG0YqVe2Dnw+ahTd6n1E6hf4kZplxDimuSNwriyMk3y3Uq9pzpI6XZDB4mAgehLfHZor+8IuPbcWpMYUcQh6e/fQ4fDpqxdwKqry32gk+Y7m8D/c61JW/E0vhV4pFSb1Rm2j6C0zKwfH5uOCU/82WKg65NnCJo4f1w+vkb/3xxu4o5I2LyONRo62qXzHM36vKpX1IiRVcPfMKamZbVyF8MGaw== 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)(39830400003)(346002)(396003)(136003)(376002)(1800799009)(186009)(451199024)(6506007)(26005)(1076003)(2616005)(107886003)(52116002)(12101799020)(6512007)(66574015)(6486002)(83380400001)(38100700002)(8676002)(8936002)(36756003)(316002)(4326008)(41300700001)(30864003)(2906002)(86362001)(5660300002)(44832011)(38350700002)(6666004)(6916009)(478600001)(66476007)(66946007)(66556008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cW1IM1hxUXJqSWVoOXJ6SW80c0FieUt1ZlkvblZFMHdreGJ5OVdmWGo2Szdo?= =?utf-8?B?dXB3d0xkZU5SU0VvVTZJZ3ZoTjhaU2F5TTExMFI3WVVwWDhRMVpSdXYrc1Bi?= =?utf-8?B?NFpsNHo2RjMwSm4waXcrYi9WUXkzZHhwenV4RmV5ai9zaWU2aTRhQmlnTngy?= =?utf-8?B?K1YrZUc5ODBUYld0RWFmWGFYclJYWk9ka1EvTm9uNEdZczdFb3Q3dCtPZit0?= =?utf-8?B?bkE5QWJwMElySkJBK0V2S2lqbXBQRitRRVFDam9VeURPVjNRNlhsVjhnMnFV?= =?utf-8?B?dkFOYjFCTGlzS0s3WnJRem5oV1hxTzFBa2d3d2QvbmZ5Zm9GOEVrekdER2kv?= =?utf-8?B?Q0ZTM291L0ZNaFBtU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SnBE?= =?utf-8?B?OVE9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02162124-c0ef-4670-510a-08dba492dfb2 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2023 11:11:33.1754 (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: jJ1lyGY5MLhBXTSWjwesAcV3R/exhSAOMsbughZACmwFEXR18jgIXSRMdFLU9FvBGzp2pCQDLj/VFGL6Y58jTrM/2TEYB9fbWLcHNrSi0o0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB6116 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 eb03571f99..a3bc7a14c4 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; + uint16_t interface; + struct nfp_cpp *cpp; + 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); } /** -- 2.39.1