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 BB6D8425A3; Fri, 15 Sep 2023 11:19:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BC7ED42DB6; Fri, 15 Sep 2023 11:17:09 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2121.outbound.protection.outlook.com [40.107.237.121]) by mails.dpdk.org (Postfix) with ESMTP id B5A4842D97 for ; Fri, 15 Sep 2023 11:17:07 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KGV+0ZkaIjU3VIDMCNJdJfLjp6rw4RVaDPQ4kWnbyrqalIv1rKoUlObjuH/Xx0DsFQauw00QLi+BlRc7lXcyCgEj0mcxXnstWrtapMIV4wC8pZd/3g8z8cKn9wKIE4vsmgCPR3anZkWrBtzkwwzBQFv8MKKMkq5izpK7peDQFh+EW9QogbBafXX1MQXtNQOxRml9S7GDWjW8V40l3lxCy0ZWunAUuZipoXgsPCZJ8XH2rYdDvgqlzZ1hqmzvhbtgkecSn1oRWMcVsbKeggHQlWitwlL+Ger+tai15exIauEEBeGrcmZspxF+/p68iYm+TUgSmgOTRZbRtYH+gQQsZQ== 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=4SeL/sNh1CDUKzg/ZBL4DYY8ZkmF0oGPND3swf6fxL8=; b=ib2rHr6OXkxqLnluhxUa47F2+LIGRT3r8SAc6LKO6paeqQSmFCO6bCV5LuZm3bHln0Oh8mVnteBWcGGYlies+ZuE8NYxKtjnXg4dJU/nsltZNfQVf+s+eRF67bGw1sj+V2igXtrTABwWrUciV4UZxWu/emqOR9mGqUQ2Z/fLiZskxlUoJRpeisoUNBdQRZOITw9fLL04Jl9EZryVfeq2rYn3URCiXscoGf2Tr7NtjHXj05gdvSqycz0qSPW6fE69hFzoCM5ZkO2XnMN35gsoAaPkaeublOql9MFHcP0EhSECwfWUwjgmYfadjNIJmWkmEtA6dGyyfHESdxF4BY2Kpg== 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=4SeL/sNh1CDUKzg/ZBL4DYY8ZkmF0oGPND3swf6fxL8=; b=c/MM6iTR7aPI6hHwSoq3n/Ce2t2ZPwFWoQEmTsW/Y0Va+CVvauhGMAe7U4N4oKEILZ+TEXX53vgCnYOqagz8biq1LbggRUadIWOCzj4ikSTLkWCsB4ZarGceH669aJzBKnBBc2xslT8t9iKMhyUOAEbyB7Vfn21CKswG75y+TmA= 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 CO1PR13MB4773.namprd13.prod.outlook.com (2603:10b6:303:fb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21; Fri, 15 Sep 2023 09:17:06 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::c05c:6915:1628:70c4]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::c05c:6915:1628:70c4%7]) with mapi id 15.20.6768.029; Fri, 15 Sep 2023 09:17:06 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v3 24/27] net/nfp: refact the cppcore module Date: Fri, 15 Sep 2023 17:15:48 +0800 Message-Id: <20230915091551.1459606-25-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230915091551.1459606-1-chaoyong.he@corigine.com> References: <20230830021457.2064750-1-chaoyong.he@corigine.com> <20230915091551.1459606-1-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: PH7PR10CA0017.namprd10.prod.outlook.com (2603:10b6:510:23d::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_|CO1PR13MB4773:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b5b005a-d0c6-44ae-45d1-08dbb5cc87b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hrY2RMMvk2CX2i769G/GdURYbIwE4OfMq3CfKzzdGY5Xy4vfdNJ0NXQZhLqXllUv4kfxb05hVBcHZ4lyV9LEl3bbQ9p5xso4XGIiHfQAiNb25U8ngRcnZjgethO63+4G1SoWo6mJTxP9Gej33KXvsSUur8sQbJSFMAgwRElN4aQTgQ8zdCjjLGHulSMi/pDFkTMLnwkh3EGT8N8WqOGcyIf0cZsmkrVFCvaHmPWwjXIspQFF1j2vzHhgsEvlfI9ot0N5jiFHlLwldeXvnw5JqOKnwKJe6vpA/xxxkYnNR2w9UNnt80AuyxtuNZkDOjWxCvC/H89yYOle/5Qy00i6E1rUD9UFmLERdMW6KpwVa2JdCNe56OEWwIBD03nl2ZeN41T2rvdmifj7upKXLZ232kD3smlGybyZV6MmMN4AChP14ln33B9vgiS/vhP59SlBiTJwuXaZBCGY/YMDjnFL/u36/p9Ic/3boBTKNHqjjDTzFEZrrMkcYvnoekq2wUdMHylKXJbYoCU1AO4Jjl2oNYflqLTyPVGMgOGfifOnMKIMcfa2jgnw6U0TuwTt2eXDwxMWI2hZvdciadHirsPewCN6CdpRoGYu+1F0bCOgF0u2/Jilx3CdhBKw0hE7uBuc51UUm4tKJN2lEz3+MAIx13kUCs9C+ltx2415v7hec68= 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)(39840400004)(346002)(136003)(376002)(396003)(366004)(451199024)(186009)(1800799009)(6512007)(107886003)(1076003)(2616005)(6666004)(52116002)(6506007)(6486002)(66946007)(26005)(316002)(41300700001)(66476007)(66556008)(6916009)(54906003)(5660300002)(4326008)(8676002)(38350700002)(8936002)(38100700002)(478600001)(66574015)(83380400001)(36756003)(44832011)(30864003)(86362001)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bFZVQ1hSMXdwSlErcHQ1MG9STUF2dXBGS21OemhGT3N4dDBMWW5OTlgwYXhQ?= =?utf-8?B?SC9EY20xZnZ5cVBRc0VoYW8wSlpZSXlvU25Sa1EvSkU5Rkdjb2pyZ1ppVFJj?= =?utf-8?B?aW9KY3RJSVR0RnAwNWdYY1JFZG9ONkZIOEZFUjkvVkxFcU5JZUxYUVpiTXdK?= =?utf-8?B?NTJ0MGY0QmU1MXk5OUlWa1hUY1ViVmE0RkV2MHRVbTRIWC9tczB1eGp5d21o?= =?utf-8?B?ZzNtajhzMGM4RUFCNEhwT0JSUENUZkU4QzJrWndkRnFoVkt4Njg2bjJMMGdL?= =?utf-8?B?dWpLS2EyVnY2QzlQVDFWTThyN0krQXhXMEx1UTRYbGhMZmxzSC9NTlp2M2hE?= =?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WkxMnpNU1N6VGE3M1c1OEFLbkZKR0pCam4yeUd6?= =?utf-8?B?U0E9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b5b005a-d0c6-44ae-45d1-08dbb5cc87b5 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 09:17:06.0593 (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: En5a6h8akh3hrccPrGVPP6DgefBYm6ixDLXhVDXE4cizgv2GPUCNpyGzylLjvC2U5qt96aaZZbz9ulD2EGpBolYxmppdyzVNvfN/15DJ5D4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR13MB4773 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 Modify the comment and standard the coding style. Move the definition of data structure into the implement file to make the API small. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He Reviewed-by: Niklas Söderlund --- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 14 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 40 ++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 186 ++++++++++++++++--------- 5 files changed, 143 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c index 88cd1aa572..a9998f3c08 100644 --- a/drivers/net/nfp/nfp_cpp_bridge.c +++ b/drivers/net/nfp/nfp_cpp_bridge.c @@ -344,7 +344,7 @@ nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp) return -EIO; } - tmp = cpp->interface; + tmp = nfp_cpp_interface(cpp); PMD_CPP_LOG(DEBUG, "%s: sending NFP interface %08x\n", __func__, tmp); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index c37d8a1449..5d129d0ad3 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -654,15 +654,23 @@ nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) char fw_name[125]; char serial[40]; size_t fsize; + uint16_t interface; + uint32_t cpp_serial_len; + const uint8_t *cpp_serial; + + cpp_serial_len = nfp_cpp_serial(cpp, &cpp_serial); + if (cpp_serial_len != NFP_SERIAL_LEN) + return -ERANGE; + + interface = nfp_cpp_interface(cpp); /* Looking for firmware file in order of priority */ /* First try to find a firmware image specific for this device */ snprintf(serial, sizeof(serial), "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", - cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3], - cpp->serial[4], cpp->serial[5], cpp->interface >> 8, - cpp->interface & 0xff); + cpp_serial[0], cpp_serial[1], cpp_serial[2], cpp_serial[3], + cpp_serial[4], cpp_serial[5], interface >> 8, interface & 0xff); snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH, serial); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index abee584f85..45645e04f8 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -739,7 +739,7 @@ nfp6000_init(struct nfp_cpp *cpp, strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; @@ -778,7 +778,7 @@ nfp6000_free(struct nfp_cpp *cpp) struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); nfp_disable_bars(desc); - if (cpp->driver_lock_needed) + if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); free(desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0df97552cb..34ed50ceca 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -9,38 +9,12 @@ #include /* NFP CPP handle */ -struct nfp_cpp { - uint32_t model; - uint32_t interface; - uint8_t *serial; - int serial_len; - void *priv; - - /* Mutex cache */ - struct nfp_cpp_mutex *mutex_cache; - const struct nfp_cpp_operations *op; - - /* - * NFP-6xxx originating island IMB CPP Address Translation. CPP Target - * ID is index into array. Values are obtained at runtime from local - * island XPB CSRs. - */ - uint32_t imb_cat_table[16]; - - /* MU access type bit offset */ - uint32_t mu_locality_lsb; - - int driver_lock_needed; -}; +struct nfp_cpp; /* NFP CPP device area handle */ -struct nfp_cpp_area { - struct nfp_cpp *cpp; - char *name; - unsigned long long offset; - unsigned long size; - /* Here follows the 'priv' part of nfp_cpp_area. */ -}; +struct nfp_cpp_area; + +#define NFP_SERIAL_LEN 6 /* * NFP CPP operations structure @@ -230,7 +204,7 @@ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); @@ -349,7 +323,9 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); + +bool nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp); struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 965b7a3428..0c1a03b0ab 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -3,30 +3,56 @@ * All rights reserved. */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include +#include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_platform.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" -#include "nfp_nffw.h" #include "nfp6000_pcie.h" +#define NFP_PL_DEVICE_PART_NFP6000 0x6200 #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff #define NFP_PL_DEVICE_PART_MASK 0xffff0000 #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/* NFP CPP handle */ +struct nfp_cpp { + void *priv; /**< Private data of the low-level implementation */ + + uint32_t model; /**< Chip model */ + uint16_t interface; /**< Chip interface id */ + uint8_t serial[NFP_SERIAL_LEN]; /**< Chip serial number */ + + /** Low-level implementation ops */ + const struct nfp_cpp_operations *op; + + /* + * NFP-6xxx originating island IMB CPP Address Translation. CPP Target + * ID is index into array. Values are obtained at runtime from local + * island XPB CSRs. + */ + uint32_t imb_cat_table[16]; + + /**< MU access type bit offset */ + uint32_t mu_locality_lsb; + + bool driver_lock_needed; +}; + +/* NFP CPP device area handle */ +struct nfp_cpp_area { + struct nfp_cpp *cpp; + char *name; + uint64_t offset; + uint32_t size; + /* Here follows the 'priv' part of nfp_cpp_area. */ + /* Here follows the ASCII name, pointed by @name */ +}; + /** * Set the private data of the nfp_cpp instance * @@ -125,12 +151,13 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, * @return * Length of NFP serial number */ -int +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) { - *serial = cpp->serial; - return cpp->serial_len; + *serial = &cpp->serial[0]; + + return sizeof(cpp->serial); } /** @@ -143,22 +170,12 @@ nfp_cpp_serial(struct nfp_cpp *cpp, * @param serial_len * Length of the serial byte array */ -int +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len) { - if (cpp->serial_len) - free(cpp->serial); - - cpp->serial = malloc(serial_len); - if (cpp->serial == NULL) - return -1; - memcpy(cpp->serial, serial, serial_len); - cpp->serial_len = serial_len; - - return 0; } /** @@ -179,6 +196,21 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Retrieve the driver need lock flag + * + * @param cpp + * NFP CPP handle + * + * @return + * The driver need lock flag + */ +bool +nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp) +{ + return cpp->driver_lock_needed; +} + /** * Get the privately allocated portion of a NFP CPP area handle * @@ -283,39 +315,40 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t size) { int err; + size_t name_len; + uint32_t target_id; + uint64_t target_addr; struct nfp_cpp_area *area; - uint64_t tmp64 = (uint64_t)address; if (cpp == NULL) return NULL; /* Remap from cpp_island to cpp_target */ - err = nfp_target_cpp(dest, tmp64, &dest, &tmp64, cpp->imb_cat_table); + err = nfp_target_cpp(dest, address, &target_id, &target_addr, + cpp->imb_cat_table); if (err < 0) return NULL; - address = tmp64; - if (name == NULL) - name = ""; + name = "(reserved)"; - area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + name_len = strlen(name) + 1; + area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + name_len); if (area == NULL) return NULL; area->cpp = cpp; area->name = ((char *)area) + sizeof(*area) + cpp->op->area_priv_size; - memcpy(area->name, name, strlen(name) + 1); + memcpy(area->name, name, name_len); - err = cpp->op->area_init(area, dest, address, size); + err = cpp->op->area_init(area, target_id, target_addr, size); if (err < 0) { PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } - area->offset = address; + area->offset = target_addr; area->size = size; return area; @@ -555,26 +588,28 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, * Ensure that non-local XPB accesses go out through the * global XPBM bus. */ - island = ((*xpb_addr) >> 24) & 0x3f; + island = (*xpb_addr >> 24) & 0x3f; if (island == 0) return xpb; - if (island == 1) { - /* - * Accesses to the ARM Island overlay uses Island 0 - * Global Bit - */ - (*xpb_addr) &= ~0x7f000000; - if (*xpb_addr < 0x60000) - *xpb_addr |= (1 << 30); - else - /* And only non-ARM interfaces use island id = 1 */ - if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) - *xpb_addr |= (1 << 24); + if (island != 1) { + *xpb_addr |= (1 << 30); + return xpb; + } + + /* + * Accesses to the ARM Island overlay uses Island 0 + * Global Bit + */ + *xpb_addr &= ~0x7f000000; + if (*xpb_addr < 0x60000) { + *xpb_addr |= (1 << 30); } else { - (*xpb_addr) |= (1 << 30); + /* And only non-ARM interfaces use island id = 1 */ + if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != + NFP_CPP_INTERFACE_TYPE_ARM) + *xpb_addr |= (1 << 24); } return xpb; @@ -602,9 +637,12 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -629,7 +667,10 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, value = rte_cpu_to_le_32(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - return (sz == sizeof(value)) ? 0 : -1; + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; + + return 0; } /** @@ -654,9 +695,12 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, uint64_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_64(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -681,8 +725,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, value = rte_cpu_to_le_64(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -710,9 +756,12 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t tmp; sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -740,8 +789,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, value = rte_cpu_to_le_32(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -770,8 +821,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); *value = rte_le_to_cpu_64(tmp); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -799,8 +852,10 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, value = rte_cpu_to_le_64(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -918,9 +973,6 @@ nfp_cpp_free(struct nfp_cpp *cpp) if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len != 0) - free(cpp->serial); - rte_free(cpp); } @@ -974,7 +1026,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); - return -1; + return -EACCES; } err = nfp_cpp_area_read(area, 0, address, length); @@ -1013,7 +1065,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); - return -1; + return -EACCES; } err = nfp_cpp_area_write(area, 0, address, length); @@ -1039,8 +1091,12 @@ nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return err; *model = reg & NFP_PL_DEVICE_MODEL_MASK; - if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) - *model -= 0x10; + /* Disambiguate the NFP4000/NFP5000/NFP6000 chips */ + if (FIELD_GET(NFP_PL_DEVICE_PART_MASK, reg) == + NFP_PL_DEVICE_PART_NFP6000) { + if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) + *model -= 0x10; + } return 0; } -- 2.39.1