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 CCA39425A3; Fri, 15 Sep 2023 11:19:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 054DD42DBD; Fri, 15 Sep 2023 11:17:11 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2128.outbound.protection.outlook.com [40.107.237.128]) by mails.dpdk.org (Postfix) with ESMTP id 728AB42D9D for ; Fri, 15 Sep 2023 11:17:09 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ixt03OfDcVcigVH4tENeYCRVPKsKBt5ZTek4NjAoHXYIUOupvqacfHhMT/P5mVd7+SWQwIj76IAg66MZw6UGsscOp2LywYfjG96koNYmu8EtqeEJTlyQ4AlQLBUTEFjWpnBmmrMMCvj/VoCp9mxNdFQWnHu2m7ZMs25c2bUFB4RiwvsmPI5FTXoMGBqWRTIH8CKXE6wwJrvI977e0/y3YGnfV9qeR9Zt8t+UMddEnrxm/qRg2oU61hWofeQGadMWk1cQl9jcQXch1/pTtAnFQ5fcP6OamAVsEOyWugkheb0e33DgQBtBD7v4SIq+KHyBz5Y+mbEfaYC6F/klGa8eGQ== 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=kzauFyHNsnV0UiFWQ3dynngiGpVWHI+Eg4JZ3CruQXEwUEQKedio4rPhih0v1rIjhkp9SUOi6XewmN4AAoENWOw3JEr+jU6VuY1W8yBjM8ZONq0EROUclDWCy0CMgpBnFqGIqIGSgIQQ46XuUXF5RFHUs7N9cdI3K+m1k39ZaEVKloSmBVdbEX0zCmFVAdx0/HM2TmRiOg4DYgcTns50N1fArKe4py72Jz0NriCgDyVSW7WXU/sCSGgacIS13JSfXr/U/wbxEWyHTWqhyxEg28dHks5nRFgs+PUrUvTqgT5P5W3wheqkUTmZImhwkEX7lXjHcEp9gwImDfdcRj9+YA== 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=oxAm04Z2IBBx2SQMhMJpR3yd6Hm1B7slTiwyYP7NId/N+LZV8W1skoJE+8Dsc1Fs6RSGnZb+VP33gK0oUHB0WzKQuoSbwt+37XtG+2MYnC8HN0ewXAKp7DuuZP7nWTKKU1XE06G3N9AKaZyBAGfqcXxtz+PBdZYwOVSbWnTjuFs= 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:08 +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:07 +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 25/27] net/nfp: refact the PCIe module Date: Fri, 15 Sep 2023 17:15:49 +0800 Message-Id: <20230915091551.1459606-26-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: 1b7fc23c-c35b-4550-ef8a-08dbb5cc88d0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: STtiCHxuYWLpAT13wKUGtU7pTDlZBO02dK/5F2e66OGEX9Ej6BHLZHsbjCiVfoWOkRYYSCJloD83tRByfeM7qWBatu/aO1zCe1aHLPTW3i6hOq2TS9c+RZgJR+jOqxeY2EMSEGLHf8vKlHGcd3yUJZZXWvvhYJRHa+ERrfTyt283JhpMIA0yJ2I/tW9uWZLy9aTsd27u7St5bY/ZsCNVvE5qDtmo83cbhKnfV4W3ZWxSi/97mfAxbDwD2QHZuc1JdYpI4qkZaI1u0Cg4w5967oHtgytMguJKVIyq/osohZ2/EEXKVQjAe/aItofKfVKwx3Z/fZEUkwOMUcQ5U7F8OdkAI2wnGWl+AdNseMNvDCidd9wrR0YFGLZYj9A+kAKMaG58wt4TWZ0trvRb1qIvP//GfjDEGvCZk1hGtwgJsZUZWnEy0byoG55rWkKhj4XZWCzRbv7EMcRJqy93gEIJkDbVTJm9IphsA9Tz9fVJdtymhtiiGYXDcSR8kzrjV3icjQ3DymI/Kiwz4vV9SgZANim6EiQzhTGDwrPVeaMAU4Ym58WMUFccPJdfSQpRYeFznO/QkQzf/gpNp+SAr6c5UNPC4oeP4XxsYmom/aZlOn36+D74UPUwXS5s4c5cWIrJXxls1r5ODuWaTLgp3UhB+u+SXPnsaVsNkuZtjGvLP8k= 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)(86362001)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eDhYWm1tTTlkYnkyTlFsbVdEM1NBK1o0VXBiMzJINWp6WXpOSS9BeXZOVnU1?= =?utf-8?B?T1ZLdXpvWE1FV0F0MDBwUDF1M1l3ei9zZmdGZjB6TFFlQ2Ezb1hXbUozQXhL?= =?utf-8?B?VFFBYlU4U1pLVHJxdSt0U3FYYk5XZHZoY1Z2bDZWZW42Nk1OT0kybGs4RUQz?= =?utf-8?B?ZFNNQzh3WFVPT3dZeVlzY3NodFFDaWtmdXQ4MDNURUR2b3gyMm0wa3QwUUth?= =?utf-8?B?UmpjSHZSM0wzOGZmK3o3M3FQNTFWV1A4ODFCYWZZZHg3Z3BRZkZSWWhEd2xl?= =?utf-8?B?bGdqdWRoeTFsQnFzOGZRY1RQZ1NGcnRFdzVMdVBpUXFiMEM2Wm1P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kSnZZV1lvbTVRcmZHcnhwd1F0MHJaY1lyVkRMQnJZcTlj?= =?utf-8?B?a3c9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b7fc23c-c35b-4550-ef8a-08dbb5cc88d0 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:07.9167 (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: FyOKnK68qYLw6u97b/WN129CsA0ilrZQHLJ4D5nr+jBePyxWqlAOfJ8IGjBQM+IEYnDlUdKshVR6g+vi0esktbdL4pii6oAFd/WG5pOaDrQ= 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 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