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 1A30E41DE6; Mon, 6 Mar 2023 13:05:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EE5A740E50; Mon, 6 Mar 2023 13:05:58 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2080.outbound.protection.outlook.com [40.107.244.80]) by mails.dpdk.org (Postfix) with ESMTP id 8055740A8A; Mon, 6 Mar 2023 13:05:55 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QiTHX0/hVAPG07D44TPk1DLSQvpxEEcYUhdrOwUeCEx0ny5SPdMdgGHetdV/IyXGuQRe0ytdzasxhE7YMjHa+MNlo7J36O+v2kLp7zIqF8xkZ/+JE2gET/Ojuhz+kUhHOp0VKBCovopjKQicE7k+TIgzeGcw/NdiiMO9/VHhQCjYwcAG6d96pxwsD8G6t8Kc+AbhaDfcCVw92mGQ0/BY4x78b5cwyUrBg85S6IBEheXP2ZIje0y/DxRskBANBDrFy39KoKirPf96IHzfddVlbNCTvttYLSBH26gs5xQG4xqYusOoq9F5WvEDqvYyNIdhwQhFE+TscrYC6LxQO2Ly9Q== 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=JXB0r4HqvQaa7R55q/4S5f1+5BeC/0cPLbwlTbA5now=; b=GC9wv1j1rqu32fwDU/6u19d2oXBVMXt//4LtNqUiNx4U8zWCVleZjBrQtyHawIEZTqRl67INwDkr7PI27YllsGlQwsqfk+jzmPvtRhF1T9mPjmgihSqpVBSa8cOCBhQfv/TBDniA6aoi1X3i2ZxvRTpcQBfT4UFKL9uCIAfOUu96WVEaNvVrikSh1uIZ/rE++SGYLItMJGwrpdOcIkZ7di3uTJltkJJuhfO1pdc0Vz3JDjIssQxV9mmWGB6GG5RhtbjHQp23ID4BHADE6R1nryNeUPJAulgo+VmAHyYBeDXfS6Q1Jo1lxajg1dDp0ep1ExiS7oukYpLMkDm4vNoU2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JXB0r4HqvQaa7R55q/4S5f1+5BeC/0cPLbwlTbA5now=; b=Vc5qMiigvOZLhgkKQqrNoqi50hGH37p/6UrTN8olCDsIjPA6/3kXpuqyMbmLvqboDcVtfxdNymXD1fCvroy1wPAwUhQyGc16mepv4fq58htwqmw2alco4V36Sd6FbPB52mXNMtDucHcPV1e1WJzwUJze37PD7G3tq2NEiyNXTZY= Received: from PH7PR12MB6694.namprd12.prod.outlook.com (2603:10b6:510:1b1::8) by DM6PR12MB4281.namprd12.prod.outlook.com (2603:10b6:5:21e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.27; Mon, 6 Mar 2023 12:05:52 +0000 Received: from PH7PR12MB6694.namprd12.prod.outlook.com ([fe80::5faa:be04:9c30:1c06]) by PH7PR12MB6694.namprd12.prod.outlook.com ([fe80::5faa:be04:9c30:1c06%6]) with mapi id 15.20.6156.027; Mon, 6 Mar 2023 12:05:52 +0000 From: "Uttarwar, Sunil Prakashrao" To: David Marchand , "dev@dpdk.org" CC: "stable@dpdk.org" , "Somalapuram, Amaranath" , "Sebastian, Selwin" Subject: RE: [PATCH v2] crypto/ccp: fix PCI probing Thread-Topic: [PATCH v2] crypto/ccp: fix PCI probing Thread-Index: AQHZTPxKPM+ZDS2GtEuThHdvqZadc67tmTYw Date: Mon, 6 Mar 2023 12:05:52 +0000 Message-ID: References: <20220909150411.3702860-1-david.marchand@redhat.com> <20230302114342.1638086-1-david.marchand@redhat.com> In-Reply-To: <20230302114342.1638086-1-david.marchand@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_Enabled=true; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_SetDate=2023-03-06T12:05:49Z; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_Method=Privileged; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_Name=Public-AIP 2.0; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_ActionId=ebe28cd5-c323-492b-865e-b4d95e219a9a; MSIP_Label_d4243a53-6221-4f75-8154-e4b33a5707a1_ContentBits=1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH7PR12MB6694:EE_|DM6PR12MB4281:EE_ x-ms-office365-filtering-correlation-id: 45de9f07-b59f-44f5-b953-08db1e3b21c5 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: FqCd6PRBVgGSnHl9/q05dfI6hoMabuPcJrjQD9F3bREAJfRzINn7rzvHbuT2La/qlfXA5IGFz3VAyaibpA4SvhLFkwxjeGTzKXENSKoUEXmF3TNrUkDn3JHwXSVzl8gtKwAofPwDBdcQduepeSf6KKx04FB/4pNdvl9Ik+5dw/R93EopMGP+9EaKCwk7n/CAUiGKNTSNxLn5jGYEBpv5Qe8kMmDVWn9H/GCKBd7BfcA+/mGybe1DFbhRpcZor1MlLbiQmhjNu1lb/3QdqGIwCEBRdcvZ5weqPyk4lK59gMXITNkF5gZbApmcCzgFcyC61HJXNnam3C9Ad1xN5ocldWGZom2pWBjb032oivLZ0WCcUPYRPlHOA8qaD5x8G1yVVCPQ4m98sZSu0kcAlCb66Xc+tQkLr+PU6m0BUZCPW8luRbbGtvayP3H9k9zW2GtSuo+CjI8/moYbuK7OSZ2p75jod9/mIcJCfXwjT9UCcpPTfxqZ08c6O4Wh+57jXuWHwrPhOF5bsAOyWvgkTCfVB+Ohuoo0HId+h8KHP7u3nx/mF91PyR+/iKWodvvXNsFQ813bk0by5eHjbxUby94tOubTKA5bb0pE7jgiWn18DZgDiqUYiSabL08wvnZH7iSbyyijjZnvMw3RixeqZJZnqtRop1S9JXwoHvTmvfhbtdrLqYKNFtPzL6qMrCkushinXFR5AGsAK8lQrbZ9UYGwLw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH7PR12MB6694.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(39860400002)(366004)(346002)(136003)(376002)(396003)(451199018)(316002)(54906003)(110136005)(66446008)(55016003)(83380400001)(86362001)(33656002)(186003)(9686003)(2906002)(30864003)(5660300002)(76116006)(8936002)(66556008)(66946007)(8676002)(64756008)(4326008)(41300700001)(478600001)(6506007)(26005)(66476007)(53546011)(71200400001)(7696005)(122000001)(52536014)(38100700002)(38070700005); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?35AOph7kTnjHFZ+Q0N4lh6bVNqp315q+oRstRWjEDvQnWIVIAYhLz+avcN2y?= =?us-ascii?Q?j2zptUmTSNthxpYbvHzxbgojk7T34dx+8kKlXbfhtaezi8usCv/D+VgFWAeV?= =?us-ascii?Q?tqEUgv+9rlaj0jmHPtrPuEK2ie2M9XgqRl9M9UIcLwF5I+L2x+WscWTLnCcH?= =?us-ascii?Q?cnLrWUGgM1glN0U7sKRVTWzuLupSmFNEqrFXvWPKaqIu7DCYWx7vdTcGIAnW?= =?us-ascii?Q?svbLUTZTLq+BZCdA3ufHhsPmHOCAaMECraeCYotvZjAq5uXI7FB2TBU4nBxK?= =?us-ascii?Q?C7F8/fbdXVR2wZtglhMymqAgQGu+cZmJ2ntQ373HA2R9wYZEHueSVv5X9TJ6?= =?us-ascii?Q?M3LpNteazq2w7T+kNjDnA84PbtZYawAhVLpmvGp7DzDfd2gZuV3xDco2YkJU?= =?us-ascii?Q?cEm2SJPs4RzD5ZchQp6GLZzv90w33RwSr8OgZCt7eRJUOcpsoHHNABiIpoC/?= =?us-ascii?Q?otKHb4z+EM/11JjGBd/yfjSmOi+iiu17AKVXeWdfgBw2FBEUTeK2GKsrhY0g?= =?us-ascii?Q?R6qKF9c5LT8iSH3UQFAsW9/ONxc39mWZeiAOggttrt815dWHMO3spUQIPh+Q?= =?us-ascii?Q?EOogqqLca0pZd1L7ERsrUGhJqo50XlUlvl8BtJvhIOpOgOq9E/Ca2W839yUU?= =?us-ascii?Q?9jndJ2F3607xdS6eD5hkFk+niCFfZ9SVDQVTVd2gEW8hoGru93n4+nB1yJeT?= =?us-ascii?Q?ZMi3sK8Lm7hWLu1MD1QGcdbPkIV6iqAiRSHkPHxBPaI3nnrzNIMJGoURYR4L?= =?us-ascii?Q?95UPs4I6bqwWEq/5aNUtxdpxRUSdUqtlkVHGsZ5GatO5dBlCS52aCN3yo/ky?= =?us-ascii?Q?XiqZxukrfgo+mIoW+Jpifl6NMwssYqiU6Kaxjo/RqwmlKIK1BSpef+7d2kgR?= =?us-ascii?Q?UnWyxiuWM75LdFItyWDsWQC98wpJ7x87w02WBmmsLMNDAJgJ6Sr9qo6p+DBd?= =?us-ascii?Q?c242Zgt71d130n61EHrEdtWy8lVebWmCSR25F9W/HJZiJnSB5LKKcIpBbZ7E?= =?us-ascii?Q?ExgR47Y/UfF0dameqOJVTogjRVzCsELf4zS9RLxvmx8Y02+rqPMh6tdGDvmz?= =?us-ascii?Q?C31iJm7lE7aOMiOmcQ0JhMDpoDZ5lbVDUleiod7TIvr5PJ13UEPf7JN9XL+o?= =?us-ascii?Q?3hqqBY7Z/RAQxsuT4hhlfTVSP0TMxrGNjGWE9L2KL0hy3ZWJsak4oWcR3gYy?= =?us-ascii?Q?aiNDOKpazZn4j1116Viy56cg2Vu8hGU6WbPvDtYSrWEDwXM+CaaqBy5mbZhO?= =?us-ascii?Q?YeHpz3WYfEbFTYfUfvrcudAizXS45r22jhh8eaPFsQlql9OUNdQzwq4IqMJf?= =?us-ascii?Q?ZxhcP2NzqB8Q07N3jDinK5+2YfFfkWZ6edUpmSuHzbOJK8ad/wGIiqizybiX?= =?us-ascii?Q?Xk8+4uqKfoObsbjk0P+sZlQJrCblpN7LcUG+ZVpSwXGvtGivoaDO/Mtq/vI5?= =?us-ascii?Q?5pRcWd8O67fGzdw4iuAHMji22M5MstRLsqxW+Ag8qQLYLeRnOYGWPuwUJP8I?= =?us-ascii?Q?fBYI7b1WaphGhT5oy9fgx2OFvvXs/SG1x5L4JTd+ct8wHDx31OOR5Jx6pMUL?= =?us-ascii?Q?g9v878RG7vtkM3L2O8mqcmV/O11JVgyFh3rw7m8o?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB6694.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45de9f07-b59f-44f5-b953-08db1e3b21c5 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Mar 2023 12:05:52.0942 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 1tltEOMJL8IjKqlqQo4TDThadoh0m4vMPJNQGn8f69Uy0pzkpX7EUxZbiyeqcaG74Xy8dj9KuVpv4IY5pxymqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4281 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 [Public] Acked-by: Sunil Uttarwar -----Original Message----- From: David Marchand =20 Sent: Thursday, March 2, 2023 5:14 PM To: dev@dpdk.org Cc: stable@dpdk.org; Uttarwar, Sunil Prakashrao ; Somalapuram, Amaranath Subject: [PATCH v2] crypto/ccp: fix PCI probing Caution: This message originated from an External Source. Use proper cautio= n when opening attachments, clicking links, or responding. 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 presen= t 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") Cc: stable@dpdk.org Signed-off-by: David Marchand --- Changes since v2: - restored cryptodev_cnt update, --- 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 dr= ivers/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_crypt= o.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 in= dex 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 =3D TAILQ_HEAD_INITIALIZER(ccp_list); +static TAILQ_HEAD(, ccp_device) ccp_list =3D=20 +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 =3D (void *)(dev->pci.mem_resource[2].addr); + void *vaddr =3D (void *)(dev->pci->mem_resource[2].addr); while (dev->hwrng_retries++ < CCP_MAX_TRNG_RETRIES) { *value =3D CCP_READ_REG(vaddr, TRNG_OUT_REG); @@ -4= 80,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; @@ -4= 94,9 +493,9 @@ ccp_add_device(struct ccp_device *dev, int type) dev->id =3D ccp_dev_id++; dev->qidx =3D 0; - vaddr =3D (void *)(dev->pci.mem_resource[2].addr); + vaddr =3D (void *)(dev->pci->mem_resource[2].addr); - if (type =3D=3D CCP_VERSION_5B) { + if (dev->pci->id.device_id =3D=3D AMD_PCI_CCP_5B) { CCP_WRITE_REG(vaddr, CMD_TRNG_CTL_OFFSET, 0x00012D57); CCP_WRITE_REG(vaddr, CMD_CONFIG_0_OFFSET, 0x00000003); for (i =3D 0; i < 12; i++) { @@ -615,41 +614,8 @@ ccp_remov= e_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 =3D (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 =3D (uint16_t)tmp; - - for (id =3D ccp_id, i =3D 0; id->vendor_id !=3D 0; id++, i++) { - if (vendor =3D=3D id->vendor_id && - device_id =3D=3D id->device_id) { - *type =3D 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 =3D=3D NULL) goto fail; - ccp_dev->pci =3D *pci_dev; + ccp_dev->pci =3D 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 @@ ccp_probe_device(int ccp_type, struct rte_pci_device *= pci_dev) 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 =3D 0; - int ccp_type =3D 0; - struct dirent *d; - DIR *dir; - int ret =3D 0; - uint16_t domain; - uint8_t bus, devid, function; - char dirname[PATH_MAX]; - - TAILQ_INIT(&ccp_list); - dir =3D opendir(SYSFS_PCI_DEVICES); - if (dir =3D=3D NULL) - return -1; - while ((d =3D readdir(dir)) !=3D NULL) { - if (d->d_name[0] =3D=3D '.') - continue; - if (ccp_parse_pci_addr_format(d->d_name, sizeof(d->d_name), - &domain, &bus, &devid, &function) != =3D 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 =3D = 0x%x\n", - ccp_id[ccp_type].device_id); - ret =3D ccp_probe_device(ccp_type, pci_dev); - if (ret =3D=3D 0) - dev_cnt++; - } - } - closedir(dir); - return dev_cnt; -} diff --git a/drivers/crypto/ccp/ccp_dev.h b/drivers/crypto/ccp/ccp_dev.h in= dex 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, in= t 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 =3D 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(s= truct 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 de= leted 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 =3D strndup(buf, bufsize); - - if (buf_copy =3D=3D NULL) - return -1; - - if (rte_strsplit(buf_copy, bufsize, splitaddr.str, PCI_FMT_NVAL, ':= ') - !=3D PCI_FMT_NVAL - 1) - goto error; - /* final split is on '.' between devid and function */ - splitaddr.function =3D strchr(splitaddr.devid, '.'); - if (splitaddr.function =3D=3D NULL) - goto error; - *splitaddr.function++ =3D '\0'; - - /* now convert to int values */ - errno =3D 0; - *domain =3D (uint8_t)strtoul(splitaddr.domain, NULL, 16); - *bus =3D (uint8_t)strtoul(splitaddr.bus, NULL, 16); - *devid =3D (uint8_t)strtoul(splitaddr.devid, NULL, 16); - *function =3D (uint8_t)strtoul(splitaddr.function, NULL, 10); - if (errno !=3D 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 =3D NULL; - - f =3D fopen(filename, "r"); - if (f =3D=3D NULL) - return -1; - if (fgets(buf, sizeof(buf), f) =3D=3D NULL) { - fclose(f); - return -1; - } - *val =3D strtoul(buf, &end, 0); - if ((buf[0] =3D=3D '\0') || (end =3D=3D NULL) || (*end !=3D '\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_ad= dr, - 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, ' ') !=3D 3) - return -1; - errno =3D 0; - *phys_addr =3D strtoull(res_info.phys_addr, NULL, 16); - *end_addr =3D strtoull(res_info.end_addr, NULL, 16); - *flags =3D strtoull(res_info.flags, NULL, 16); - if (errno !=3D 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 =3D fopen(filename, "r"); - if (fp =3D=3D NULL) - return -1; - - for (i =3D 0; i < PCI_MAX_RESOURCE; i++) { - if (fgets(buf, sizeof(buf), fp) =3D=3D 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 =3D phys_addr; - dev->mem_resource[i].len =3D end_addr - phys_addr += 1; - /* not mapped for now */ - dev->mem_resource[i].addr =3D 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 =3D -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 =3D opendir(dirname_uio); - if (dir =3D=3D NULL) { - /* retry with the parent directory might be different kernel versio= n*/ - dir =3D opendir(dirname); - if (dir =3D=3D NULL) - return -1; - } - - /* take the first file starting with "uio" */ - while ((e =3D readdir(dir)) !=3D NULL) { - /* format could be uio%d ...*/ - int shortprefix_len =3D sizeof("uio") - 1; - /* ... or uio:uio%d */ - int longprefix_len =3D sizeof("uio:uio") - 1; - char *endptr; - - if (strncmp(e->d_name, "uio", 3) !=3D 0) - continue; - - /* first try uio%d */ - errno =3D 0; - uio_num =3D strtoull(e->d_name + shortprefix_len, &endptr, = 10); - if (errno =3D=3D 0 && endptr !=3D (e->d_name + shortprefix_= len)) { - ret =3D uio_num; - break; - } - - /* then try uio:uio%d */ - errno =3D 0; - uio_num =3D strtoull(e->d_name + longprefix_len, &endptr, 1= 0); - if (errno =3D=3D 0 && endptr !=3D (e->d_name + longprefix_l= en)) { - ret =3D uio_num; - break; - } - } - closedir(dir); - return ret; - - -} diff --git a/drivers/crypto/ccp/ccp_pci.h b/drivers/crypto/ccp/ccp_pci.h de= leted 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 *doma= in, - uint8_t *bus, uint8_t *devid, uint8_t *functi= on); - -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.buil= d index a4f3406009..a9abaa4da0 100644 --- a/drivers/crypto/ccp/meson.build +++ b/drivers/crypto/ccp/meson.build @@ -18,7 +18,6 @@ sources =3D 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_cry= pto_op **ops, * The set of PCI devices this driver supports */ static struct rte_pci_id ccp_pci_id[] =3D { - { - 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 =3D 0}, }; @@ -228,12 +222,11 @@ cryptodev_ccp_create(const char *name, goto init_error; } - cryptodev_cnt =3D ccp_probe_devices(pci_dev, ccp_pci_id); - - if (cryptodev_cnt =3D=3D 0) { + if (ccp_probe_device(pci_dev) !=3D 0) { CCP_LOG_ERR("failed to detect CCP crypto device"); goto init_error; } + cryptodev_cnt++; CCP_LOG_DBG("CCP : Crypto device count =3D %d\n", cryptodev_cnt); dev->device =3D &pci_dev->device; -- 2.39.2