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 19637425C9; Mon, 18 Sep 2023 04:50:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B0E8B427DF; Mon, 18 Sep 2023 04:47:59 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2110.outbound.protection.outlook.com [40.107.244.110]) by mails.dpdk.org (Postfix) with ESMTP id 593D642D87 for ; Mon, 18 Sep 2023 04:47:56 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Erg8Lih0GGWJvxNd8yCsG8GHbZsLksKhudxKtv0Z1tTnTTitGb2WpRtnZPKbBB/BZMJYTNHT0g5jA6ybqcGN6xcjmONkUKirgp5ZivUOS8T/k8nYHdCQjFmyjTV5gTW/WyYVkHoMoyphFan7TP2hzzAW/b2tRURMYJq1CVm5Z1yqccwgyE/M4Kv6oj2qRV8jGQ76UHXNOVDHIqWKgONmXgqrtpgOvrHEGo3XO5oATiKXOX0qNOMOy4+7Mg3U+fJJ7BEIS0si7VpB80PmXmi/WC3W1kWg4nYPdvp9F8LEYcSJ+ceiAvDkIgH7+mK/+jUeyUvb4a37svSd+2wnBANGyg== 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=5NlXw4M7J7zpbb+Sg9Ni2bV1678sjBiLqB6Dd847ZO4=; b=kWy7ccQ537xj5WAoxJURhbJFuD7g/cSliHMs18TgTreesYp7L6s9n2mHlQ9k2jqZGz7CZJXDDUu4BlwI9Wo6sAND8pxlun5qEdNykZ8+dzeOIJxWzYLQTwAAmaCssZFcB6NR6imw8T+4S7ReB3ZJdfpgbQrbZqizY5h3C+LsOzuDIlW9DuEiZpwYJD3IIi3/rFY1V4FMy9ThKAFuiTWeBmiY8H6Iv43nhi5iQIXlUD4O/xawMxoSO68QQNDDyxO1ZrQIdNZ/C8dZhYjSIJno/Ltt5D30XEU1DEZh6upZwDg3ZbBce6zJ4jB8wShYahRzvmB50FJRwKe0TvnOIUKMeg== 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=5NlXw4M7J7zpbb+Sg9Ni2bV1678sjBiLqB6Dd847ZO4=; b=QjyQahRqv0Dkd/8OiMMZth49Suu+3Q+CYLqmbtAKs+RyZZlyRU5uKqLYt4Hcz+Pn3dUDMtan0RM9wE4EqgUQ6HuvvUjuQ1q4Tv8wJWbCrDsgBies7l3OZyk8LtBS3+odFJFiLJXV0Zzq0ldTGjXxGSwduNcsJ3jep0Kz70AlmT8= 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 BL0PR13MB4401.namprd13.prod.outlook.com (2603:10b6:208:1c3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.24; Mon, 18 Sep 2023 02:47:54 +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; Mon, 18 Sep 2023 02:47:54 +0000 From: Chaoyong He To: dev@dpdk.org Cc: Chaoyong He , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v4 25/26] net/nfp: refact the cppcore and PCIe module Date: Mon, 18 Sep 2023 10:46:11 +0800 Message-Id: <20230918024612.1600536-26-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230918024612.1600536-1-chaoyong.he@corigine.com> References: <20230915091551.1459606-1-chaoyong.he@corigine.com> <20230918024612.1600536-1-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SE2P216CA0016.KORP216.PROD.OUTLOOK.COM (2603:1096:101:114::20) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|BL0PR13MB4401:EE_ X-MS-Office365-Filtering-Correlation-Id: f7173fa1-d40f-4d68-52e8-08dbb7f1a85c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /1K1RObWpWGt4/Fffpuuwu8W77NPPkYjgO2UdcgX1gbWKn3ttESZGT89ESPTHykIQ9znegNDianZtR0jDi+5teFVvNX6NONqjc7Ooi1zXCRqFM3plaK9m5xtFymO/zMlgK7lCdQbjjW7t+FWWNT8rv0fyyabqo9arycCUvTF9aqPm6FsEa8dn+BxUZBKoTlWVXtJrEb6Xzk+pmCqSaZfYjIImAXC6qbQYJKQR/m53XQtcj452fPgxKqWf1vcr5uMcxACZNZ/FHZUYZELAoGQtb3WCExMxiYo3wTLc3/Zv4UH+7Sj2kuh1Vl3shs1GVdrTztOLU7gaibt+/hV7gLzjIBdENzf3VvZlpuZKzlKimRwI4NKV1/Qzsglkz5ygT2HOLgC0sP99um7I7+30gg+iy8ZrFLEE/ya6KDnl7UuZKKjrEPjiGclpxDbLiu7rGLKk0pjQ0lauRI39gybqh4vSfxcs+FUPdxk31tQN7doLl7yB4Rm8X8C1jEJouEq/f7nTrtNf838P/PMoHeoyfxLJweBJmCl8Muy1Wk8+f3JrL4WtQ/mGig9O2fhwsaIdvNmc2U1xv7JR7a/sOoiP1eeviy9v0uCoQWUfSrJplDT25EeQKsSufaJr6iwB3pi0lzJvguzhI2UAz6VwKqVbxN6iZmQzwPUzFcniRgEtSYVFZ4= 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)(136003)(376002)(346002)(39830400003)(396003)(186009)(1800799009)(451199024)(5660300002)(26005)(107886003)(1076003)(8936002)(4326008)(8676002)(2616005)(2906002)(30864003)(86362001)(38350700002)(38100700002)(36756003)(83380400001)(66574015)(44832011)(66946007)(6506007)(6486002)(52116002)(66476007)(66556008)(54906003)(6666004)(478600001)(6512007)(41300700001)(316002)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cXFyZi9uQnZnWlYrY3B5L2ZIYmdleGQ0K2J3eFRmWlMyWjhRaHFiY2ZXZ3VU?= =?utf-8?B?di9TOWlLR1JiT0RCYnhaUDlpKy9Sb2l5RWtNT3VBVHI2QVl3b1VXcmFkSUJX?= =?utf-8?B?T04wODlvOVFCTFRDVUlWK1o2VHI3TnQyNEdiajdlUVJYbVBud3pCSTIzY2ZY?= =?utf-8?B?WU1QQ1pJL3UxeWtmWTRON0FwSUxsOW40WmRZVGgvQi9aODZPbThidnA1clpW?= =?utf-8?B?QWFVN2NIZWNFckMySzA1VHRmRW93K1YvRWtmbGZiRkVOdXBmQ3pOeVVoeWF5?= =?utf-8?B?cUJGSCs0R3NFdnVEbDhMdXJTUlJmSXlsQzBmM0ZaaHZV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?YmYzQlhycTRLR3dQU25EaXBheVNKa2w2ZVNWZVZCamRmYUdXQkI1UDZDNGht?= =?utf-8?B?aUE9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: f7173fa1-d40f-4d68-52e8-08dbb7f1a85c X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 02:47:54.4984 (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: pdwiEIjRY07z5otOhOXn+UY8ceP8dRxDIra8HPPOND2xgXSM9FFU2hkSae2hTSrA9Wi2WtBP8JLdzf0EirWfSW+cx3FMBsIiquDGKAq8qPo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR13MB4401 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, 142 insertions(+), 174 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 921fa167dd..a645e23a4d 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..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