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 678B0428F8 for ; Sun, 9 Apr 2023 17:33:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5E29440A80; Sun, 9 Apr 2023 17:33:15 +0200 (CEST) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2047.outbound.protection.outlook.com [40.107.96.47]) by mails.dpdk.org (Postfix) with ESMTP id C74AC40A80 for ; Sun, 9 Apr 2023 17:33:13 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MCySlpeqClCiZsjNgq3iLfGU9vCtrVbUXind2FwSLksa5um3ttIWwcIjDgMXzJJN6MtpFpssIBcBgVy7HI53USfSmHlVu6BmcIcgJvTOYZrwMDblUMa9oMG7cPOeEHloHCY+0VIk6U0Rrr9yvYGIaNQZpOARTfMs9YxvJSDQ/yvwjQMCd2EJke6TR0DwKWA3Z9hyOH4uojxFqA6XaSH0wb98TVafXzzciJvSVUgqrEVUUDhyXENViBqLJwLICwckDp1VCbSkpCdIpvukrpvCGyhBB48r0Hk3Xm4U8P2GqfiFu8ahHt5pBQgSRCHw+m+gUsIblzAcOB0Zqd9fnLlYTQ== 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=KO3mltS/c+c/qIdRGk60TFDwaLVsyDbcryCEu3RuDGY=; b=nUtN6O6vVbCxAUCV415B8q0TdKR7u+yJjkT+5dNMDiVXSsTvM6Tj6W/Hk1U6f4c+8CbCbixOlHVHkfg2mjBOaqDNrU3tRY7SNK/y8Z/dXA5b2cfZFNXCtcq4CfPjyMGsMVQQ6OblLOBS2282qR2GgffvDo21i0AARXrrz0RamNetJBQvQLoI28hxrNKB25ObDlztFfKxDMdWm4A79vkfh3+qhwEEPztFbfCIyBc4tUzYT1GSM3DKnyw1HxaluYom9ZhybMbDZHGdzPGPgvPE9BLeqfjqNlsG9XSA+w9H+6bJq8+ssk22LUITeCQCmjN1KkB0BhugMFv3I9zlKjPb6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KO3mltS/c+c/qIdRGk60TFDwaLVsyDbcryCEu3RuDGY=; b=h368I+cy/2K9SSG6x7YBKrqqbsxzwxHZgT7lABvK43NJvcCsNshDw1Jz9GcJsWAIP1Z0u51b+KH864YC+IiTPawB03+GvcTfCcAgxAP5LRdUQg1uNAX3PpVXzBUD15rO3buJBjnwdKRJwgJhbp869/L1E5rQsQccSDhZ/mLsE/T/KMpI7cgC8cpDzGOTgm/y9gpfZCHmTvO3NGeMwRl/2CzjeU3f87RwnxXXlBuk+vAbgcZlSNhNeDhl/EER98WE+XhSPlvar5Bzw+0PfKI9x9HU2k78kQUkdoPiuu0/kEX1cFz/PsZJikFzEUEhYS/9/0x4ij6GkHzDHcNNWWW4zA== Received: from MW4PR04CA0373.namprd04.prod.outlook.com (2603:10b6:303:81::18) by CY8PR12MB7515.namprd12.prod.outlook.com (2603:10b6:930:93::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.34; Sun, 9 Apr 2023 15:33:10 +0000 Received: from CO1NAM11FT053.eop-nam11.prod.protection.outlook.com (2603:10b6:303:81:cafe::d3) by MW4PR04CA0373.outlook.office365.com (2603:10b6:303:81::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38 via Frontend Transport; Sun, 9 Apr 2023 15:33:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CO1NAM11FT053.mail.protection.outlook.com (10.13.175.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.25 via Frontend Transport; Sun, 9 Apr 2023 15:33:09 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Sun, 9 Apr 2023 08:33:06 -0700 Received: from nvidia.com (10.126.230.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 9 Apr 2023 08:33:05 -0700 From: Xueming Li To: David Marchand CC: Sunil Uttarwar , dpdk stable Subject: patch 'crypto/ccp: fix PCI probing' has been queued to stable release 22.11.2 Date: Sun, 9 Apr 2023 23:24:37 +0800 Message-ID: <20230409152529.5308-90-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230409152529.5308-1-xuemingl@nvidia.com> References: <20230227062349.13764-1-xuemingl@nvidia.com> <20230409152529.5308-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT053:EE_|CY8PR12MB7515:EE_ X-MS-Office365-Filtering-Correlation-Id: b30a2460-a798-4b75-383e-08db390fb951 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6e9QICLmobXBN2MoU8gS9YkU+zwnM4hTXOX4HUzI4SAoyXf+t763nIxlwyXCq1m8/BYoFd9JyLMdkowTNZJeyE5GcdSm8nW9CRvIzqZYtbtol9BUeXemv6XpIw3ZUU5Kz4xluTm2TnS6obRIqkKEDw3uUnlf7LDlsj/4a8wH9L39LrISHrW9lfuj2J1FnwwU5i5LR2Z2k/oXcIsSmdy5wVO55zNQO7Ijjv+rSU1WhpSl1NY3zIynCfFeNFEi8I1gUh+Knl92dNLWlduHni6zqnYf4oOfiM/kBBFWEeVe0eyx5AJ9VlZcDMOyAUWk2HVB5TMDXJ9B0DigqXHXiLOBxhLQllE5aIeJ9CloGgid3aIBMck50/kUfz2AjtINlyzDYXu/ZwBX878NApx3fFuZbyKQsjMbVCKNBDaBUs4cuVZ+vGsphYxnIroVYtsEQqVwuyhlFcR1B3GfwGZwDvzaK1sihYU03gZ0n5EpI3Ggx5fBbt/SnLD1oE77Zb4DAecOgmHQpxu5OMsJqe5l3cWpVsEsaZg5Vt3baS3Z+03Bf48TTMJ26HpH0DCw7MB+DOp2YWPcuaAGirbq1P0X7KvQDY/6udmaUEHF21P1CMTsIWfjPKoRhrRhAFOoNc9XpoGo4H0YZBt5Ay/JOwpgdD8GI1GsgNB7Jg8oftrDK6eeiVlidVWgsH8vxnH5ko/CSXrzPba7EAAwKFLI9RLNC+rpwPcFTSwge2c4WULvGkoSZPwysTkebny8JpLFLwwooJShJAo93XITY2fCn96UW08ZNyyG4EJAuk8YhSSwN7EyDFQY28jjyiqlHmA0yuTGb0ZrPOjdNzlwgsnllxMoO5U7hg== X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(376002)(396003)(346002)(136003)(451199021)(40470700004)(46966006)(36840700001)(83380400001)(316002)(54906003)(478600001)(186003)(1076003)(36756003)(53546011)(16526019)(6286002)(55016003)(26005)(40480700001)(36860700001)(40460700003)(2616005)(47076005)(426003)(966005)(336012)(6666004)(7696005)(82740400003)(2906002)(70206006)(70586007)(4326008)(6916009)(30864003)(8676002)(8936002)(86362001)(41300700001)(5660300002)(356005)(82310400005)(7636003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2023 15:33:09.8516 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b30a2460-a798-4b75-383e-08db390fb951 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT053.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7515 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 22.11.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 04/11/23. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging This queued commit can be viewed at: https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging/commit/eba4eee77bf216ac308482cc5887128b05d30773 Thanks. Xueming Li --- >From eba4eee77bf216ac308482cc5887128b05d30773 Mon Sep 17 00:00:00 2001 From: David Marchand Date: Thu, 2 Mar 2023 12:43:42 +0100 Subject: [PATCH] crypto/ccp: fix PCI probing Cc: Xueming Li [ upstream commit e849b88fff2d3875e815a5749110241140a4512a ] This driver has been converted from a vdev driver to a pci driver some time ago. This conversion is buggy as it tries to probe any pci devices present on a system for *each* probe request from the PCI bus. Rely on the passed PCI device and only probe what is requested. While at it: - stop copying the pci device object content into a local private copy, - rely on the PCI identifier and remove internal ccp_device_version identifier, - ccp_list can be made static, With this done, all the code parsing Linux sysfs can be dropped. Fixes: 889317b7ecb3 ("crypto/ccp: convert driver from vdev to PCI") Signed-off-by: David Marchand Acked-by: Sunil Uttarwar --- drivers/crypto/ccp/ccp_crypto.c | 1 - drivers/crypto/ccp/ccp_dev.c | 89 ++----------- drivers/crypto/ccp/ccp_dev.h | 31 ++--- drivers/crypto/ccp/ccp_pci.c | 207 ------------------------------- drivers/crypto/ccp/ccp_pci.h | 24 ---- drivers/crypto/ccp/meson.build | 1 - drivers/crypto/ccp/rte_ccp_pmd.c | 17 +-- 7 files changed, 26 insertions(+), 344 deletions(-) delete mode 100644 drivers/crypto/ccp/ccp_pci.c delete mode 100644 drivers/crypto/ccp/ccp_pci.h diff --git a/drivers/crypto/ccp/ccp_crypto.c b/drivers/crypto/ccp/ccp_crypto.c index 2758187d93..4b84b3303e 100644 --- a/drivers/crypto/ccp/ccp_crypto.c +++ b/drivers/crypto/ccp/ccp_crypto.c @@ -26,7 +26,6 @@ #include "ccp_dev.h" #include "ccp_crypto.h" -#include "ccp_pci.h" #include "ccp_pmd_private.h" #include diff --git a/drivers/crypto/ccp/ccp_dev.c b/drivers/crypto/ccp/ccp_dev.c index 14c54929c4..ee30f5ac30 100644 --- a/drivers/crypto/ccp/ccp_dev.c +++ b/drivers/crypto/ccp/ccp_dev.c @@ -20,10 +20,9 @@ #include #include "ccp_dev.h" -#include "ccp_pci.h" #include "ccp_pmd_private.h" -struct ccp_list ccp_list = TAILQ_HEAD_INITIALIZER(ccp_list); +static TAILQ_HEAD(, ccp_device) ccp_list = TAILQ_HEAD_INITIALIZER(ccp_list); static int ccp_dev_id; int @@ -68,7 +67,7 @@ ccp_read_hwrng(uint32_t *value) struct ccp_device *dev; TAILQ_FOREACH(dev, &ccp_list, next) { - void *vaddr = (void *)(dev->pci.mem_resource[2].addr); + void *vaddr = (void *)(dev->pci->mem_resource[2].addr); while (dev->hwrng_retries++ < CCP_MAX_TRNG_RETRIES) { *value = CCP_READ_REG(vaddr, TRNG_OUT_REG); @@ -480,7 +479,7 @@ ccp_assign_lsbs(struct ccp_device *ccp) } static int -ccp_add_device(struct ccp_device *dev, int type) +ccp_add_device(struct ccp_device *dev) { int i; uint32_t qmr, status_lo, status_hi, dma_addr_lo, dma_addr_hi; @@ -494,9 +493,9 @@ ccp_add_device(struct ccp_device *dev, int type) dev->id = ccp_dev_id++; dev->qidx = 0; - vaddr = (void *)(dev->pci.mem_resource[2].addr); + vaddr = (void *)(dev->pci->mem_resource[2].addr); - if (type == CCP_VERSION_5B) { + if (dev->pci->id.device_id == AMD_PCI_CCP_5B) { CCP_WRITE_REG(vaddr, CMD_TRNG_CTL_OFFSET, 0x00012D57); CCP_WRITE_REG(vaddr, CMD_CONFIG_0_OFFSET, 0x00000003); for (i = 0; i < 12; i++) { @@ -615,41 +614,8 @@ ccp_remove_device(struct ccp_device *dev) TAILQ_REMOVE(&ccp_list, dev, next); } -static int -is_ccp_device(const char *dirname, - const struct rte_pci_id *ccp_id, - int *type) -{ - char filename[PATH_MAX]; - const struct rte_pci_id *id; - uint16_t vendor, device_id; - int i; - unsigned long tmp; - - /* get vendor id */ - snprintf(filename, sizeof(filename), "%s/vendor", dirname); - if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0) - return 0; - vendor = (uint16_t)tmp; - - /* get device id */ - snprintf(filename, sizeof(filename), "%s/device", dirname); - if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0) - return 0; - device_id = (uint16_t)tmp; - - for (id = ccp_id, i = 0; id->vendor_id != 0; id++, i++) { - if (vendor == id->vendor_id && - device_id == id->device_id) { - *type = i; - return 1; /* Matched device */ - } - } - return 0; -} - -static int -ccp_probe_device(int ccp_type, struct rte_pci_device *pci_dev) +int +ccp_probe_device(struct rte_pci_device *pci_dev) { struct ccp_device *ccp_dev; @@ -658,10 +624,10 @@ ccp_probe_device(int ccp_type, struct rte_pci_device *pci_dev) if (ccp_dev == NULL) goto fail; - ccp_dev->pci = *pci_dev; + ccp_dev->pci = pci_dev; /* device is valid, add in list */ - if (ccp_add_device(ccp_dev, ccp_type)) { + if (ccp_add_device(ccp_dev)) { ccp_remove_device(ccp_dev); goto fail; } @@ -672,40 +638,3 @@ fail: rte_free(ccp_dev); return -1; } - -int -ccp_probe_devices(struct rte_pci_device *pci_dev, - const struct rte_pci_id *ccp_id) -{ - int dev_cnt = 0; - int ccp_type = 0; - struct dirent *d; - DIR *dir; - int ret = 0; - uint16_t domain; - uint8_t bus, devid, function; - char dirname[PATH_MAX]; - - TAILQ_INIT(&ccp_list); - dir = opendir(SYSFS_PCI_DEVICES); - if (dir == NULL) - return -1; - while ((d = readdir(dir)) != NULL) { - if (d->d_name[0] == '.') - continue; - if (ccp_parse_pci_addr_format(d->d_name, sizeof(d->d_name), - &domain, &bus, &devid, &function) != 0) - continue; - snprintf(dirname, sizeof(dirname), "%s/%s", - SYSFS_PCI_DEVICES, d->d_name); - if (is_ccp_device(dirname, ccp_id, &ccp_type)) { - CCP_LOG_DBG("CCP : Detected CCP device with ID = 0x%x\n", - ccp_id[ccp_type].device_id); - ret = ccp_probe_device(ccp_type, pci_dev); - if (ret == 0) - dev_cnt++; - } - } - closedir(dir); - return dev_cnt; -} diff --git a/drivers/crypto/ccp/ccp_dev.h b/drivers/crypto/ccp/ccp_dev.h index 9deaae7980..e3ec481dd3 100644 --- a/drivers/crypto/ccp/ccp_dev.h +++ b/drivers/crypto/ccp/ccp_dev.h @@ -19,6 +19,12 @@ #include #include +/* CCP PCI device identifiers */ +#define AMD_PCI_VENDOR_ID 0x1022 +#define AMD_PCI_CCP_5A 0x1456 +#define AMD_PCI_CCP_5B 0x1468 +#define AMD_PCI_CCP_RV 0x15df + /**< CCP specific */ #define MAX_HW_QUEUES 5 #define CCP_MAX_TRNG_RETRIES 10 @@ -169,18 +175,6 @@ static inline uint32_t ccp_pci_reg_read(void *base, int offset) #define CCP_WRITE_REG(hw_addr, reg_offset, value) \ ccp_pci_reg_write(hw_addr, reg_offset, value) -TAILQ_HEAD(ccp_list, ccp_device); - -extern struct ccp_list ccp_list; - -/** - * CCP device version - */ -enum ccp_device_version { - CCP_VERSION_5A = 0, - CCP_VERSION_5B, -}; - /** * A structure describing a CCP command queue. */ @@ -233,8 +227,8 @@ struct ccp_device { /**< ccp queue */ int cmd_q_count; /**< no. of ccp Queues */ - struct rte_pci_device pci; - /**< ccp pci identifier */ + struct rte_pci_device *pci; + /**< ccp pci device */ unsigned long lsbmap[CCP_BITMAP_SIZE(SLSB_MAP_SIZE)]; /**< shared lsb mask of ccp */ rte_spinlock_t lsb_lock; @@ -468,13 +462,12 @@ high32_value(unsigned long addr) int ccp_dev_start(struct rte_cryptodev *dev); /** - * Detect ccp platform and initialize all ccp devices + * Initialize one ccp device * - * @param ccp_id rte_pci_id list for supported CCP devices - * @return no. of successfully initialized CCP devices + * @dev rte pci device + * @return 0 on success otherwise -1 */ -int ccp_probe_devices(struct rte_pci_device *pci_dev, - const struct rte_pci_id *ccp_id); +int ccp_probe_device(struct rte_pci_device *pci_dev); /** * allocate a ccp command queue diff --git a/drivers/crypto/ccp/ccp_pci.c b/drivers/crypto/ccp/ccp_pci.c deleted file mode 100644 index bd1a037f76..0000000000 --- a/drivers/crypto/ccp/ccp_pci.c +++ /dev/null @@ -1,207 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved. - */ - -#include -#include -#include -#include -#include - -#include - -#include "ccp_pci.h" - -/* - * split up a pci address into its constituent parts. - */ -int -ccp_parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain, - uint8_t *bus, uint8_t *devid, uint8_t *function) -{ - /* first split on ':' */ - union splitaddr { - struct { - char *domain; - char *bus; - char *devid; - char *function; - }; - char *str[PCI_FMT_NVAL]; - /* last element-separator is "." not ":" */ - } splitaddr; - - char *buf_copy = strndup(buf, bufsize); - - if (buf_copy == NULL) - return -1; - - if (rte_strsplit(buf_copy, bufsize, splitaddr.str, PCI_FMT_NVAL, ':') - != PCI_FMT_NVAL - 1) - goto error; - /* final split is on '.' between devid and function */ - splitaddr.function = strchr(splitaddr.devid, '.'); - if (splitaddr.function == NULL) - goto error; - *splitaddr.function++ = '\0'; - - /* now convert to int values */ - errno = 0; - *domain = (uint8_t)strtoul(splitaddr.domain, NULL, 16); - *bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16); - *devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16); - *function = (uint8_t)strtoul(splitaddr.function, NULL, 10); - if (errno != 0) - goto error; - - free(buf_copy); /* free the copy made with strdup */ - return 0; -error: - free(buf_copy); - return -1; -} - -int -ccp_pci_parse_sysfs_value(const char *filename, unsigned long *val) -{ - FILE *f; - char buf[BUFSIZ]; - char *end = NULL; - - f = fopen(filename, "r"); - if (f == NULL) - return -1; - if (fgets(buf, sizeof(buf), f) == NULL) { - fclose(f); - return -1; - } - *val = strtoul(buf, &end, 0); - if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) { - fclose(f); - return -1; - } - fclose(f); - return 0; -} - -/** IO resource type: */ -#define IORESOURCE_IO 0x00000100 -#define IORESOURCE_MEM 0x00000200 - -/* parse one line of the "resource" sysfs file (note that the 'line' - * string is modified) - */ -static int -ccp_pci_parse_one_sysfs_resource(char *line, size_t len, uint64_t *phys_addr, - uint64_t *end_addr, uint64_t *flags) -{ - union pci_resource_info { - struct { - char *phys_addr; - char *end_addr; - char *flags; - }; - char *ptrs[PCI_RESOURCE_FMT_NVAL]; - } res_info; - - if (rte_strsplit(line, len, res_info.ptrs, 3, ' ') != 3) - return -1; - errno = 0; - *phys_addr = strtoull(res_info.phys_addr, NULL, 16); - *end_addr = strtoull(res_info.end_addr, NULL, 16); - *flags = strtoull(res_info.flags, NULL, 16); - if (errno != 0) - return -1; - - return 0; -} - -/* parse the "resource" sysfs file */ -int -ccp_pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev) -{ - FILE *fp; - char buf[BUFSIZ]; - int i; - uint64_t phys_addr, end_addr, flags; - - fp = fopen(filename, "r"); - if (fp == NULL) - return -1; - - for (i = 0; i < PCI_MAX_RESOURCE; i++) { - if (fgets(buf, sizeof(buf), fp) == NULL) - goto error; - if (ccp_pci_parse_one_sysfs_resource(buf, sizeof(buf), - &phys_addr, &end_addr, &flags) < 0) - goto error; - - if (flags & IORESOURCE_MEM) { - dev->mem_resource[i].phys_addr = phys_addr; - dev->mem_resource[i].len = end_addr - phys_addr + 1; - /* not mapped for now */ - dev->mem_resource[i].addr = NULL; - } - } - fclose(fp); - return 0; - -error: - fclose(fp); - return -1; -} - -int -ccp_find_uio_devname(const char *dirname) -{ - - DIR *dir; - struct dirent *e; - char dirname_uio[PATH_MAX]; - unsigned int uio_num; - int ret = -1; - - /* depending on kernel version, uio can be located in uio/uioX - * or uio:uioX - */ - snprintf(dirname_uio, sizeof(dirname_uio), "%s/uio", dirname); - dir = opendir(dirname_uio); - if (dir == NULL) { - /* retry with the parent directory might be different kernel version*/ - dir = opendir(dirname); - if (dir == NULL) - return -1; - } - - /* take the first file starting with "uio" */ - while ((e = readdir(dir)) != NULL) { - /* format could be uio%d ...*/ - int shortprefix_len = sizeof("uio") - 1; - /* ... or uio:uio%d */ - int longprefix_len = sizeof("uio:uio") - 1; - char *endptr; - - if (strncmp(e->d_name, "uio", 3) != 0) - continue; - - /* first try uio%d */ - errno = 0; - uio_num = strtoull(e->d_name + shortprefix_len, &endptr, 10); - if (errno == 0 && endptr != (e->d_name + shortprefix_len)) { - ret = uio_num; - break; - } - - /* then try uio:uio%d */ - errno = 0; - uio_num = strtoull(e->d_name + longprefix_len, &endptr, 10); - if (errno == 0 && endptr != (e->d_name + longprefix_len)) { - ret = uio_num; - break; - } - } - closedir(dir); - return ret; - - -} diff --git a/drivers/crypto/ccp/ccp_pci.h b/drivers/crypto/ccp/ccp_pci.h deleted file mode 100644 index d9a8b9dcc6..0000000000 --- a/drivers/crypto/ccp/ccp_pci.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved. - */ - -#ifndef _CCP_PCI_H_ -#define _CCP_PCI_H_ - -#include - -#include - -#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices" - -int ccp_parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain, - uint8_t *bus, uint8_t *devid, uint8_t *function); - -int ccp_pci_parse_sysfs_value(const char *filename, unsigned long *val); - -int ccp_pci_parse_sysfs_resource(const char *filename, - struct rte_pci_device *dev); - -int ccp_find_uio_devname(const char *dirname); - -#endif /* _CCP_PCI_H_ */ diff --git a/drivers/crypto/ccp/meson.build b/drivers/crypto/ccp/meson.build index a4f3406009..a9abaa4da0 100644 --- a/drivers/crypto/ccp/meson.build +++ b/drivers/crypto/ccp/meson.build @@ -18,7 +18,6 @@ sources = files( 'rte_ccp_pmd.c', 'ccp_crypto.c', 'ccp_dev.c', - 'ccp_pci.c', 'ccp_pmd_ops.c', ) diff --git a/drivers/crypto/ccp/rte_ccp_pmd.c b/drivers/crypto/ccp/rte_ccp_pmd.c index 661a796116..a5271d7227 100644 --- a/drivers/crypto/ccp/rte_ccp_pmd.c +++ b/drivers/crypto/ccp/rte_ccp_pmd.c @@ -167,15 +167,9 @@ ccp_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops, * The set of PCI devices this driver supports */ static struct rte_pci_id ccp_pci_id[] = { - { - RTE_PCI_DEVICE(0x1022, 0x1456), /* AMD CCP-5a */ - }, - { - RTE_PCI_DEVICE(0x1022, 0x1468), /* AMD CCP-5b */ - }, - { - RTE_PCI_DEVICE(0x1022, 0x15df), /* AMD CCP RV */ - }, + { RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_CCP_5A), }, + { RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_CCP_5B), }, + { RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_CCP_RV), }, {.device_id = 0}, }; @@ -228,12 +222,11 @@ cryptodev_ccp_create(const char *name, goto init_error; } - cryptodev_cnt = ccp_probe_devices(pci_dev, ccp_pci_id); - - if (cryptodev_cnt == 0) { + if (ccp_probe_device(pci_dev) != 0) { CCP_LOG_ERR("failed to detect CCP crypto device"); goto init_error; } + cryptodev_cnt++; CCP_LOG_DBG("CCP : Crypto device count = %d\n", cryptodev_cnt); dev->device = &pci_dev->device; -- 2.25.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2023-04-09 21:45:41.047088900 +0800 +++ 0089-crypto-ccp-fix-PCI-probing.patch 2023-04-09 21:45:38.709042200 +0800 @@ -1 +1 @@ -From e849b88fff2d3875e815a5749110241140a4512a Mon Sep 17 00:00:00 2001 +From eba4eee77bf216ac308482cc5887128b05d30773 Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Xueming Li + +[ upstream commit e849b88fff2d3875e815a5749110241140a4512a ] @@ -21 +23,0 @@ -Cc: stable@dpdk.org