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 DAF7E425C9; Mon, 18 Sep 2023 04:50:11 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4AB6642D87; Mon, 18 Sep 2023 04:47:57 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2122.outbound.protection.outlook.com [40.107.244.122]) by mails.dpdk.org (Postfix) with ESMTP id 135EA427E9 for ; Mon, 18 Sep 2023 04:47:55 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q+SuMn6agM4zUPEo4ctJEYye9oOqAExPInKRIIDAATdhicKwIFcAQX1rYl9fhroJex8w1rDaIuTpl2bvOpuuw0nYo4I9pURTcA0tm/VrCd8a/odRM/M3ELWDRen9d64ZVzS3GpN881V9Gz0w6eRUVgXJ6o0QD25xyU1lsBILaqzxl8JrBxGodSLocSV/+fqGt6RfpT0nGiC+4GckML06zAFgu7y/sgzUpx8K3JYs11RUtUwXsubARbXq9cGZOJ1BmuGBY3yzoSLMR3CBIyQQo6CbBkrPDuWUekOKTSOjLHA7bUNlc0BEwP3xjUU+HT1beuY0JviLzK2uKUA/35J8UA== 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=e/8aeLVLMVTDcuNqDNkKXYdCRfzmvR365YWr5EAApwg=; b=ZZn8Iw4lBphT2XvoPHAk2CBv7uVnPRDradcSjnvgxB0xdgyif8sOqX2EVL8HsWLvrXdZPJ0OPvi4DJICvJazabvedFrPwK2+gRqMNTgbrIa8MIS46eH44PEzlwkIP26zYt+lWr7JVgmJsg0W+ae/SNMkE1h08li85QZgEOKKxP6/0i796SLN711a4lywi3PDfvwsrBC9bM+7DAP/tSouiCBNfDx7L1SEnkOx0eKRA4MldE/5MOd0+4aEHWvAq9qqjORQ+YIl519kW9EIbPpgRWVjyp8bNrua4lB1vzkRq8deF4cQAHRPym/5eMkzLKJpW80q4N2KGfAj48IAbjIAqw== 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=e/8aeLVLMVTDcuNqDNkKXYdCRfzmvR365YWr5EAApwg=; b=lwGetzxDdiX9fZFUp76mn74QufRhzv0i3vGqLfXcpxoNj/DD6h37f239YQuea2Jwyi4uylMI2TfZp9cMBmqhCsiKUWDVsrSxEUdGIxtlEInuIGWxdan/Geb46F5E6zNliupxRrx6QCjgg1eZxsKBZ7Cemlm1RNuqMlvaUfxWGVE= 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:52 +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:52 +0000 From: Chaoyong He To: dev@dpdk.org Cc: Chaoyong He , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v4 24/26] net/nfp: refact the PCIe module Date: Mon, 18 Sep 2023 10:46:10 +0800 Message-Id: <20230918024612.1600536-25-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: e430aa88-a77d-4e58-ded7-08dbb7f1a779 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Po5aAG3CZnuhDbLF/qgncB0rnvHw1Q+HvU1Jvcz9gErAVJVW7su3DT0IBUt7eezAYZ5CVh4v81/+HV7KyxtccK/R4eZl5UHPE4IKMhTFuhUoA659tWh9eRWfv/43bCNkUrHOjCdVlkgn+dVymmVGSUhYTwzhXrtMDe+ZszmlcmWd+izAUozYDn0tnXg1wl4m00PpzhBLfuJ8usZcMkAZcYS88Z9fR6DNzTRciPj+J8GIEP2QzohaWvtfpVE2o4f80bMvKvftiK9JXIZrBV/QTGtP2YqbPb82Lb6rlmcvgDF1+R0UwgzhS00S1V9imogKcSEaJxf6u/JfUJeVP0JdtPh9fPepEQjU2sHvMh/1N02v2FtQPWfOm4QCssS236qRghs+6boJvla+YjDnkPArrYbT43yj7j0RBY0cMqFCMZMsIRH2p6VP+KqYy5haEk1JrE2Ay0zUqad4ngAsnLA9KJHxAcuoAUbFEBBo5ye/E9Cu5EgMJSCjQQbr+RGuv1KHkpnTdNEMRn0oOuSwQ3NZCPw7uPRlNg/uF8MRuw5XmPxLlcJo7GjuKx3Cx+ctTb5ldyMQ2a2CKENds0v3kayHbmbItL+i2SMSws+75bKw9EmigioPnS9toquARMLk3a8VfQOH1TF+dtsvi/FzjLHmDPZ0s4os6RXu8mVobPgeZrw= 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)(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?bDdZdmhoeFZxMlFpTUFhUnpkaWJpdHNycmZMZFBQNjM1TVI4dmZiUUoyUEJV?= =?utf-8?B?ZWMyTHFZVkxtRElNditmWU1FbXhpVjlwM3hoN1YwbXE4a09aRlJUcE4zMW1n?= =?utf-8?B?TFNtNDNtSGN1YU5WVjBBQWNVOUhHTlpBT1VSeXMrcHZlUXVpd3JoV3FFY3ox?= =?utf-8?B?dllia2kzc3I2M1M4LzVxYkVVaSs5Q0pQVTJhZG0wWjUvZWZtWUFxWmpCMFJE?= =?utf-8?B?cnJzMFJEYzJ3dDFKQzJOVm0rT0VXV2pOd2UxcmwzRE5NMWVtMWJSV2RvbkJN?= =?utf-8?B?a1BwTHcySGs5WlZwd3YzUmE3SHh4M2d1K09WeUZoQkxLTkxEYTF3bjBrclNo?= =?utf-8?B?ZWxoNnJGSkNRQWlHd082TXI4a2hM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rg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: e430aa88-a77d-4e58-ded7-08dbb7f1a779 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:52.8464 (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: +A17sGXAsliLAM4bWihUTY1mhSoAiPt8TRZqtgrTlpOG1/xF/3GlnbCylDGqrs23Nkbl0V5sKA7NqnQJh+0Aft3cRYum1TcQvk2SmFixFpk= 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 and remove the unneeded header file include statements. Signed-off-by: Chaoyong He Reviewed-by: Niklas Söderlund --- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 211 +++++++++++++++++-------- drivers/net/nfp/nfpcore/nfp_cpp.h | 9 ++ 2 files changed, 150 insertions(+), 70 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 45645e04f8..4f453f19a9 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -16,23 +16,8 @@ #include "nfp6000_pcie.h" -#include -#include -#include #include -#include -#include #include -#include -#include -#include -#include - -#include -#include -#include - -#include #include "nfp_cpp.h" #include "nfp_logs.h" @@ -43,8 +28,11 @@ #define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) +#define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(_x) (((_x) >> 16) & 0x1f) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) +#define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS_OF(_x) (((_x) >> 0) & 0xffff) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT(_x) (((_x) & 0x3) << 27) +#define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(_x) (((_x) >> 27) & 0x3) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT 0 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT 1 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE 3 @@ -55,7 +43,9 @@ #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET 2 #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL 3 #define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(_x) (((_x) & 0xf) << 23) +#define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(_x) (((_x) >> 23) & 0xf) #define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(_x) (((_x) & 0x3) << 21) +#define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(_x) (((_x) >> 21) & 0x3) /* * Minimal size of the PCIe cfg memory we depend on being mapped, @@ -132,7 +122,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (target >= 16) + if (target >= NFP_CPP_NUM_TARGETS) return -EINVAL; switch (width) { @@ -182,10 +172,6 @@ nfp_compute_bar(const struct nfp_bar *bar, offset &= mask; bitsize = 40 - 21; } - - if (bar->bitsize < bitsize) - return -EINVAL; - newcfg |= offset >> bitsize; if (bar_base != NULL) @@ -434,7 +420,7 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Must have been too big. Sub-allocate. */ if (priv->bar->iomem == NULL) - return (-ENOMEM); + return -ENOMEM; priv->iomem = priv->bar->iomem + priv->bar_offset; @@ -464,9 +450,9 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32 = address; uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; @@ -484,47 +470,54 @@ nfp6000_area_read(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } - is_64 = width == TARGET_WIDTH_64; - - /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { - is_64 = false; - } + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; + ret = n; + break; + default: + return -EINVAL; + } + + return ret; } static int @@ -533,9 +526,9 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; @@ -553,47 +546,53 @@ nfp6000_area_write(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; - is_64 = width == TARGET_WIDTH_64; - - /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) - is_64 = false; + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; -} + ret = n; + break; + default: + return -EINVAL; + } -#define PCI_DEVICES "/sys/bus/pci/devices" + return ret; +} static int nfp_acquire_process_lock(struct nfp_pcie_user *desc) @@ -706,6 +705,74 @@ nfp6000_set_serial(struct rte_pci_device *dev, return 0; } +static int +nfp6000_get_dsn(struct rte_pci_device *pci_dev, + uint64_t *dsn) +{ + off_t pos; + size_t len; + uint64_t tmp = 0; + + pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN); + if (pos <= 0) { + PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found"); + return -ENODEV; + } + + pos += 4; + len = sizeof(tmp); + + if (rte_pci_read_config(pci_dev, &tmp, len, pos) < 0) { + PMD_DRV_LOG(ERR, "nfp get device serial number failed"); + return -ENOENT; + } + + *dsn = tmp; + + return 0; +} + +static int +nfp6000_get_interface(struct rte_pci_device *dev, + uint16_t *interface) +{ + int ret; + uint64_t dsn = 0; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + *interface = dsn & 0xffff; + + return 0; +} + +static int +nfp6000_get_serial(struct rte_pci_device *dev, + uint8_t *serial, + size_t length) +{ + int ret; + uint64_t dsn = 0; + + if (length < NFP_SERIAL_LEN) + return -ENOMEM; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + serial[0] = (dsn >> 56) & 0xff; + serial[1] = (dsn >> 48) & 0xff; + serial[2] = (dsn >> 40) & 0xff; + serial[3] = (dsn >> 32) & 0xff; + serial[4] = (dsn >> 24) & 0xff; + serial[5] = (dsn >> 16) & 0xff; + + return 0; +} + static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) @@ -789,6 +856,10 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .free = nfp6000_free, .area_priv_size = sizeof(struct nfp6000_area_priv), + + .get_interface = nfp6000_get_interface, + .get_serial = nfp6000_get_serial, + .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 34ed50ceca..0f36ba0b50 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -16,6 +16,8 @@ struct nfp_cpp_area; #define NFP_SERIAL_LEN 6 +#define NFP_CPP_NUM_TARGETS 16 + /* * NFP CPP operations structure */ @@ -33,6 +35,13 @@ struct nfp_cpp_operations { */ void (*free)(struct nfp_cpp *cpp); + int (*get_interface)(struct rte_pci_device *dev, + uint16_t *interface); + + int (*get_serial)(struct rte_pci_device *dev, + uint8_t *serial, + size_t length); + /* * Initialize a new NFP CPP area * NOTE: This is _not_ serialized -- 2.39.1