From patchwork Tue Oct 4 09:51:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 117295 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B131EA0543; Tue, 4 Oct 2022 11:51:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A497242685; Tue, 4 Oct 2022 11:51:53 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id D832540DDC for ; Tue, 4 Oct 2022 11:51:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664877111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hq9X973YpqwKfFDZ+JAxgM6jUH9gsoIi+s0znsUAPYQ=; b=EdGaHqCqKqwQfrCa4eV0/RKiAlR5c05frtaxxYrP1mfX+oBiHv6e1SWOCKjhd0dMwjFYTu gDXREQYZZy6TOeVWnkFcIYiSKL4te1Porv33AbvH83q96cwuX/W5dzjd69dCZROq4oCw+9 cLFtcCM9ysQQEEOsEg/c5aNDwNb5RTs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-465-dNVGwF8vPIyGcKzjoL8DhA-1; Tue, 04 Oct 2022 05:51:47 -0400 X-MC-Unique: dNVGwF8vPIyGcKzjoL8DhA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B21F91C07544; Tue, 4 Oct 2022 09:51:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C35CC15BA4; Tue, 4 Oct 2022 09:51:45 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: gakhil@marvell.com, sunilprakashrao.uttarwar@amd.com, stable@dpdk.org, Ravi Kumar Subject: [PATCH v2 1/4] crypto/ccp: remove some printf Date: Tue, 4 Oct 2022 11:51:29 +0200 Message-Id: <20221004095132.198777-2-david.marchand@redhat.com> In-Reply-To: <20221004095132.198777-1-david.marchand@redhat.com> References: <20220909150411.3702860-1-david.marchand@redhat.com> <20221004095132.198777-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 A DPDK application must _not_ use printf. Use log framework. Fixes: ef4b04f87fa6 ("crypto/ccp: support device init") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Sunil Uttarwar Signed-off-by: David Marchand --- drivers/crypto/ccp/ccp_dev.c | 4 ++-- drivers/crypto/ccp/ccp_pci.c | 3 ++- drivers/crypto/ccp/rte_ccp_pmd.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/ccp/ccp_dev.c b/drivers/crypto/ccp/ccp_dev.c index 424ead82c3..9c9cb81236 100644 --- a/drivers/crypto/ccp/ccp_dev.c +++ b/drivers/crypto/ccp/ccp_dev.c @@ -362,7 +362,7 @@ ccp_find_lsb_regions(struct ccp_queue *cmd_q, uint64_t status) if (ccp_get_bit(&cmd_q->lsbmask, j)) weight++; - printf("Queue %d can access %d LSB regions of mask %lu\n", + CCP_LOG_DBG("Queue %d can access %d LSB regions of mask %lu\n", (int)cmd_q->id, weight, cmd_q->lsbmask); return weight ? 0 : -EINVAL; @@ -709,7 +709,7 @@ ccp_probe_devices(struct rte_pci_device *pci_dev, snprintf(dirname, sizeof(dirname), "%s/%s", SYSFS_PCI_DEVICES, d->d_name); if (is_ccp_device(dirname, ccp_id, &ccp_type)) { - printf("CCP : Detected CCP device with ID = 0x%x\n", + 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) diff --git a/drivers/crypto/ccp/ccp_pci.c b/drivers/crypto/ccp/ccp_pci.c index 38029a9081..c941e222c7 100644 --- a/drivers/crypto/ccp/ccp_pci.c +++ b/drivers/crypto/ccp/ccp_pci.c @@ -11,6 +11,7 @@ #include #include "ccp_pci.h" +#include "ccp_pmd_private.h" static const char * const uio_module_names[] = { "igb_uio", @@ -41,7 +42,7 @@ ccp_check_pci_uio_module(void) rewind(fp); } fclose(fp); - printf("Insert igb_uio or uio_pci_generic kernel module(s)"); + CCP_LOG_DBG("Insert igb_uio or uio_pci_generic kernel module(s)"); return -1;/* uio not inserted */ } diff --git a/drivers/crypto/ccp/rte_ccp_pmd.c b/drivers/crypto/ccp/rte_ccp_pmd.c index 013f3be1e6..7338ef0ae8 100644 --- a/drivers/crypto/ccp/rte_ccp_pmd.c +++ b/drivers/crypto/ccp/rte_ccp_pmd.c @@ -250,7 +250,7 @@ cryptodev_ccp_create(const char *name, goto init_error; } - printf("CCP : Crypto device count = %d\n", cryptodev_cnt); + CCP_LOG_DBG("CCP : Crypto device count = %d\n", cryptodev_cnt); dev->device = &pci_dev->device; dev->device->driver = &pci_drv->driver; dev->driver_id = ccp_cryptodev_driver_id; From patchwork Tue Oct 4 09:51:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 117296 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0231AA0544; Tue, 4 Oct 2022 11:51:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AD3854281E; Tue, 4 Oct 2022 11:51:57 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 2A717427F7 for ; Tue, 4 Oct 2022 11:51:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664877115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kAoWJ2/5Mi8hApPB/LXeaex44gQi7p75hh7kZD2oGQ0=; b=akfMSwUIHvA1jrH6EHVLD/NIRL8t1tznAYaJOLxChbTzuRA9GTz8C0ifQyi4064dmlvVez PgyFnGaF+7Drs5x9QK/jvRUkPPlK0cz6YamaKcXjIS1oIner3xXlnhQU7ZlILuI+9Uw8iS cFeeqFUsGLMZqwPptWuFpLDiSTALLsc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-Babqh54cPDudzsFlqjgarw-1; Tue, 04 Oct 2022 05:51:50 -0400 X-MC-Unique: Babqh54cPDudzsFlqjgarw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DEEDC85A5A6; Tue, 4 Oct 2022 09:51:49 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD1D8492B04; Tue, 4 Oct 2022 09:51:48 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: gakhil@marvell.com, sunilprakashrao.uttarwar@amd.com, stable@dpdk.org, Amaranath Somalapuram Subject: [PATCH v2 2/4] crypto/ccp: remove some dead code for UIO Date: Tue, 4 Oct 2022 11:51:30 +0200 Message-Id: <20221004095132.198777-3-david.marchand@redhat.com> In-Reply-To: <20221004095132.198777-1-david.marchand@redhat.com> References: <20220909150411.3702860-1-david.marchand@redhat.com> <20221004095132.198777-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 uio_fd is unused. Fixes: 09a0fd736a08 ("crypto/ccp: enable IOMMU") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Sunil Uttarwar Signed-off-by: David Marchand --- drivers/crypto/ccp/ccp_dev.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/crypto/ccp/ccp_dev.c b/drivers/crypto/ccp/ccp_dev.c index 9c9cb81236..410e62121e 100644 --- a/drivers/crypto/ccp/ccp_dev.c +++ b/drivers/crypto/ccp/ccp_dev.c @@ -653,7 +653,6 @@ static int ccp_probe_device(int ccp_type, struct rte_pci_device *pci_dev) { struct ccp_device *ccp_dev = NULL; - int uio_fd = -1; ccp_dev = rte_zmalloc("ccp_device", sizeof(*ccp_dev), RTE_CACHE_LINE_SIZE); @@ -671,8 +670,6 @@ ccp_probe_device(int ccp_type, struct rte_pci_device *pci_dev) return 0; fail: CCP_LOG_ERR("CCP Device probe failed"); - if (uio_fd >= 0) - close(uio_fd); rte_free(ccp_dev); return -1; } From patchwork Tue Oct 4 09:51:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 117297 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8CD7AA0543; Tue, 4 Oct 2022 11:52:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B7058427F5; Tue, 4 Oct 2022 11:51:59 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 1896142836 for ; Tue, 4 Oct 2022 11:51:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664877117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1wniGjHYe9uOz2RLoGQT0xVbk2qDPBd0/1X2K8ThGMk=; b=O6B7rYChpetr/utDEEoxVFoNv16t27wTUjDBnVy5IrAtQwl/4HHi5E6Wtb7uub0qHxQfcR R0Pyf06aGePjHCilxNHe3kZzNtrDUS+0MEYA3JT2u7Wm2Mi0tZlWrs+sRm7b+JFs91NEpM /GQ2gNAlgmcYAJmJGkD5NbcuALPXmqQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-170-OqOWaDfTNm6tti1UL4fDiA-1; Tue, 04 Oct 2022 05:51:53 -0400 X-MC-Unique: OqOWaDfTNm6tti1UL4fDiA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 33C50101A528; Tue, 4 Oct 2022 09:51:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7F5E4099B53; Tue, 4 Oct 2022 09:51:51 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: gakhil@marvell.com, sunilprakashrao.uttarwar@amd.com, stable@dpdk.org, Amaranath Somalapuram Subject: [PATCH v2 3/4] crypto/ccp: fix IOVA handling Date: Tue, 4 Oct 2022 11:51:31 +0200 Message-Id: <20221004095132.198777-4-david.marchand@redhat.com> In-Reply-To: <20221004095132.198777-1-david.marchand@redhat.com> References: <20220909150411.3702860-1-david.marchand@redhat.com> <20221004095132.198777-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 Using IOVA or physical addresses is something that the user (via --iova-mode=) or the bus code decides. The crypto/ccp PCI driver should only use rte_mem_virt2iova. It should not try to decide what to use solely based on the kmod the PCI device is bound to. While at it, the global variable sha_ctx looks unsafe and unneeded. Remove it. Fixes: 09a0fd736a08 ("crypto/ccp: enable IOMMU") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Sunil Uttarwar Signed-off-by: David Marchand --- drivers/crypto/ccp/ccp_crypto.c | 105 ++++++------------------------- drivers/crypto/ccp/ccp_dev.c | 9 +-- drivers/crypto/ccp/ccp_pci.c | 34 ---------- drivers/crypto/ccp/ccp_pci.h | 3 - drivers/crypto/ccp/rte_ccp_pmd.c | 3 - 5 files changed, 19 insertions(+), 135 deletions(-) diff --git a/drivers/crypto/ccp/ccp_crypto.c b/drivers/crypto/ccp/ccp_crypto.c index 4bab18323b..351d8ac63e 100644 --- a/drivers/crypto/ccp/ccp_crypto.c +++ b/drivers/crypto/ccp/ccp_crypto.c @@ -33,8 +33,6 @@ #include #include -extern int iommu_mode; -void *sha_ctx; /* SHA initial context values */ uint32_t ccp_sha1_init[SHA_COMMON_DIGEST_SIZE / sizeof(uint32_t)] = { SHA1_H4, SHA1_H3, @@ -748,13 +746,8 @@ ccp_configure_session_cipher(struct ccp_session *sess, CCP_LOG_ERR("Invalid CCP Engine"); return -ENOTSUP; } - if (iommu_mode == 2) { - sess->cipher.nonce_phys = rte_mem_virt2iova(sess->cipher.nonce); - sess->cipher.key_phys = rte_mem_virt2iova(sess->cipher.key_ccp); - } else { - sess->cipher.nonce_phys = rte_mem_virt2phy(sess->cipher.nonce); - sess->cipher.key_phys = rte_mem_virt2phy(sess->cipher.key_ccp); - } + sess->cipher.nonce_phys = rte_mem_virt2iova(sess->cipher.nonce); + sess->cipher.key_phys = rte_mem_virt2iova(sess->cipher.key_ccp); return 0; } @@ -793,7 +786,6 @@ ccp_configure_session_auth(struct ccp_session *sess, sess->auth.ctx = (void *)ccp_sha1_init; sess->auth.ctx_len = CCP_SB_BYTES; sess->auth.offset = CCP_SB_BYTES - SHA1_DIGEST_SIZE; - rte_memcpy(sha_ctx, sess->auth.ctx, SHA_COMMON_DIGEST_SIZE); break; case RTE_CRYPTO_AUTH_SHA1_HMAC: if (sess->auth_opt) { @@ -832,7 +824,6 @@ ccp_configure_session_auth(struct ccp_session *sess, sess->auth.ctx = (void *)ccp_sha224_init; sess->auth.ctx_len = CCP_SB_BYTES; sess->auth.offset = CCP_SB_BYTES - SHA224_DIGEST_SIZE; - rte_memcpy(sha_ctx, sess->auth.ctx, SHA256_DIGEST_SIZE); break; case RTE_CRYPTO_AUTH_SHA224_HMAC: if (sess->auth_opt) { @@ -895,7 +886,6 @@ ccp_configure_session_auth(struct ccp_session *sess, sess->auth.ctx = (void *)ccp_sha256_init; sess->auth.ctx_len = CCP_SB_BYTES; sess->auth.offset = CCP_SB_BYTES - SHA256_DIGEST_SIZE; - rte_memcpy(sha_ctx, sess->auth.ctx, SHA256_DIGEST_SIZE); break; case RTE_CRYPTO_AUTH_SHA256_HMAC: if (sess->auth_opt) { @@ -958,7 +948,6 @@ ccp_configure_session_auth(struct ccp_session *sess, sess->auth.ctx = (void *)ccp_sha384_init; sess->auth.ctx_len = CCP_SB_BYTES << 1; sess->auth.offset = (CCP_SB_BYTES << 1) - SHA384_DIGEST_SIZE; - rte_memcpy(sha_ctx, sess->auth.ctx, SHA512_DIGEST_SIZE); break; case RTE_CRYPTO_AUTH_SHA384_HMAC: if (sess->auth_opt) { @@ -1023,7 +1012,6 @@ ccp_configure_session_auth(struct ccp_session *sess, sess->auth.ctx = (void *)ccp_sha512_init; sess->auth.ctx_len = CCP_SB_BYTES << 1; sess->auth.offset = (CCP_SB_BYTES << 1) - SHA512_DIGEST_SIZE; - rte_memcpy(sha_ctx, sess->auth.ctx, SHA512_DIGEST_SIZE); break; case RTE_CRYPTO_AUTH_SHA512_HMAC: if (sess->auth_opt) { @@ -1173,13 +1161,8 @@ ccp_configure_session_aead(struct ccp_session *sess, CCP_LOG_ERR("Unsupported aead algo"); return -ENOTSUP; } - if (iommu_mode == 2) { - sess->cipher.nonce_phys = rte_mem_virt2iova(sess->cipher.nonce); - sess->cipher.key_phys = rte_mem_virt2iova(sess->cipher.key_ccp); - } else { - sess->cipher.nonce_phys = rte_mem_virt2phy(sess->cipher.nonce); - sess->cipher.key_phys = rte_mem_virt2phy(sess->cipher.key_ccp); - } + sess->cipher.nonce_phys = rte_mem_virt2iova(sess->cipher.nonce); + sess->cipher.key_phys = rte_mem_virt2iova(sess->cipher.key_ccp); return 0; } @@ -1594,14 +1577,8 @@ ccp_perform_hmac(struct rte_crypto_op *op, op->sym->auth.data.offset); append_ptr = (void *)rte_pktmbuf_append(op->sym->m_src, session->auth.ctx_len); - if (iommu_mode == 2) { - dest_addr = (phys_addr_t)rte_mem_virt2iova(append_ptr); - pst.src_addr = (phys_addr_t)rte_mem_virt2iova((void *)addr); - } else { - dest_addr = (phys_addr_t)rte_mem_virt2phy(append_ptr); - pst.src_addr = (phys_addr_t)rte_mem_virt2phy((void *)addr); - } - dest_addr_t = dest_addr; + dest_addr_t = dest_addr = (phys_addr_t)rte_mem_virt2iova(append_ptr); + pst.src_addr = (phys_addr_t)rte_mem_virt2iova((void *)addr); /** Load PHash1 to LSB*/ pst.dest_addr = (phys_addr_t)(cmd_q->sb_sha * CCP_SB_BYTES); @@ -1683,10 +1660,7 @@ ccp_perform_hmac(struct rte_crypto_op *op, /** Load PHash2 to LSB*/ addr += session->auth.ctx_len; - if (iommu_mode == 2) - pst.src_addr = (phys_addr_t)rte_mem_virt2iova((void *)addr); - else - pst.src_addr = (phys_addr_t)rte_mem_virt2phy((void *)addr); + pst.src_addr = (phys_addr_t)rte_mem_virt2iova((void *)addr); pst.dest_addr = (phys_addr_t)(cmd_q->sb_sha * CCP_SB_BYTES); pst.len = session->auth.ctx_len; pst.dir = 1; @@ -1774,14 +1748,8 @@ ccp_perform_sha(struct rte_crypto_op *op, op->sym->auth.data.offset); append_ptr = (void *)rte_pktmbuf_append(op->sym->m_src, session->auth.ctx_len); - if (iommu_mode == 2) { - dest_addr = (phys_addr_t)rte_mem_virt2iova(append_ptr); - pst.src_addr = (phys_addr_t)sha_ctx; - } else { - dest_addr = (phys_addr_t)rte_mem_virt2phy(append_ptr); - pst.src_addr = (phys_addr_t)rte_mem_virt2phy((void *) - session->auth.ctx); - } + pst.src_addr = (phys_addr_t)rte_mem_virt2iova((void *)session->auth.ctx); + dest_addr = (phys_addr_t)rte_mem_virt2iova(append_ptr); /** Passthru sha context*/ @@ -1871,15 +1839,8 @@ ccp_perform_sha3_hmac(struct rte_crypto_op *op, CCP_LOG_ERR("CCP MBUF append failed\n"); return -1; } - if (iommu_mode == 2) { - dest_addr = (phys_addr_t)rte_mem_virt2iova((void *)append_ptr); - ctx_paddr = (phys_addr_t)rte_mem_virt2iova( - session->auth.pre_compute); - } else { - dest_addr = (phys_addr_t)rte_mem_virt2phy((void *)append_ptr); - ctx_paddr = (phys_addr_t)rte_mem_virt2phy( - session->auth.pre_compute); - } + dest_addr = (phys_addr_t)rte_mem_virt2iova((void *)append_ptr); + ctx_paddr = (phys_addr_t)rte_mem_virt2iova(session->auth.pre_compute); dest_addr_t = dest_addr + (session->auth.ctx_len / 2); desc = &cmd_q->qbase_desc[cmd_q->qidx]; memset(desc, 0, Q_DESC_SIZE); @@ -2017,13 +1978,8 @@ ccp_perform_sha3(struct rte_crypto_op *op, CCP_LOG_ERR("CCP MBUF append failed\n"); return -1; } - if (iommu_mode == 2) { - dest_addr = (phys_addr_t)rte_mem_virt2iova((void *)append_ptr); - ctx_paddr = (phys_addr_t)rte_mem_virt2iova((void *)ctx_addr); - } else { - dest_addr = (phys_addr_t)rte_mem_virt2phy((void *)append_ptr); - ctx_paddr = (phys_addr_t)rte_mem_virt2phy((void *)ctx_addr); - } + dest_addr = (phys_addr_t)rte_mem_virt2iova((void *)append_ptr); + ctx_paddr = (phys_addr_t)rte_mem_virt2iova((void *)ctx_addr); ctx_addr = session->auth.sha3_ctx; @@ -2099,13 +2055,7 @@ ccp_perform_aes_cmac(struct rte_crypto_op *op, ctx_addr = session->auth.pre_compute; memset(ctx_addr, 0, AES_BLOCK_SIZE); - if (iommu_mode == 2) - pst.src_addr = (phys_addr_t)rte_mem_virt2iova( - (void *)ctx_addr); - else - pst.src_addr = (phys_addr_t)rte_mem_virt2phy( - (void *)ctx_addr); - + pst.src_addr = (phys_addr_t)rte_mem_virt2iova((void *)ctx_addr); pst.dest_addr = (phys_addr_t)(cmd_q->sb_iv * CCP_SB_BYTES); pst.len = CCP_SB_BYTES; pst.dir = 1; @@ -2143,12 +2093,7 @@ ccp_perform_aes_cmac(struct rte_crypto_op *op, } else { ctx_addr = session->auth.pre_compute + CCP_SB_BYTES; memset(ctx_addr, 0, AES_BLOCK_SIZE); - if (iommu_mode == 2) - pst.src_addr = (phys_addr_t)rte_mem_virt2iova( - (void *)ctx_addr); - else - pst.src_addr = (phys_addr_t)rte_mem_virt2phy( - (void *)ctx_addr); + pst.src_addr = (phys_addr_t)rte_mem_virt2iova((void *)ctx_addr); pst.dest_addr = (phys_addr_t)(cmd_q->sb_iv * CCP_SB_BYTES); pst.len = CCP_SB_BYTES; pst.dir = 1; @@ -2342,12 +2287,7 @@ ccp_perform_3des(struct rte_crypto_op *op, rte_memcpy(lsb_buf + (CCP_SB_BYTES - session->iv.length), iv, session->iv.length); - if (iommu_mode == 2) - pst.src_addr = (phys_addr_t)rte_mem_virt2iova( - (void *) lsb_buf); - else - pst.src_addr = (phys_addr_t)rte_mem_virt2phy( - (void *) lsb_buf); + pst.src_addr = (phys_addr_t)rte_mem_virt2iova((void *) lsb_buf); pst.dest_addr = (phys_addr_t)(cmd_q->sb_iv * CCP_SB_BYTES); pst.len = CCP_SB_BYTES; pst.dir = 1; @@ -2370,11 +2310,7 @@ ccp_perform_3des(struct rte_crypto_op *op, else dest_addr = src_addr; - if (iommu_mode == 2) - key_addr = rte_mem_virt2iova(session->cipher.key_ccp); - else - key_addr = rte_mem_virt2phy(session->cipher.key_ccp); - + key_addr = rte_mem_virt2iova(session->cipher.key_ccp); desc = &cmd_q->qbase_desc[cmd_q->qidx]; memset(desc, 0, Q_DESC_SIZE); @@ -2768,12 +2704,7 @@ process_ops_to_enqueue(struct ccp_qp *qp, b_info->lsb_buf_idx = 0; b_info->desccnt = 0; b_info->cmd_q = cmd_q; - if (iommu_mode == 2) - b_info->lsb_buf_phys = - (phys_addr_t)rte_mem_virt2iova((void *)b_info->lsb_buf); - else - b_info->lsb_buf_phys = - (phys_addr_t)rte_mem_virt2phy((void *)b_info->lsb_buf); + b_info->lsb_buf_phys = (phys_addr_t)rte_mem_virt2iova((void *)b_info->lsb_buf); rte_atomic64_sub(&b_info->cmd_q->free_slots, slots_req); diff --git a/drivers/crypto/ccp/ccp_dev.c b/drivers/crypto/ccp/ccp_dev.c index 410e62121e..14c54929c4 100644 --- a/drivers/crypto/ccp/ccp_dev.c +++ b/drivers/crypto/ccp/ccp_dev.c @@ -23,7 +23,6 @@ #include "ccp_pci.h" #include "ccp_pmd_private.h" -int iommu_mode; struct ccp_list ccp_list = TAILQ_HEAD_INITIALIZER(ccp_list); static int ccp_dev_id; @@ -652,7 +651,7 @@ is_ccp_device(const char *dirname, static int ccp_probe_device(int ccp_type, struct rte_pci_device *pci_dev) { - struct ccp_device *ccp_dev = NULL; + struct ccp_device *ccp_dev; ccp_dev = rte_zmalloc("ccp_device", sizeof(*ccp_dev), RTE_CACHE_LINE_SIZE); @@ -683,16 +682,10 @@ ccp_probe_devices(struct rte_pci_device *pci_dev, struct dirent *d; DIR *dir; int ret = 0; - int module_idx = 0; uint16_t domain; uint8_t bus, devid, function; char dirname[PATH_MAX]; - module_idx = ccp_check_pci_uio_module(); - if (module_idx < 0) - return -1; - - iommu_mode = module_idx; TAILQ_INIT(&ccp_list); dir = opendir(SYSFS_PCI_DEVICES); if (dir == NULL) diff --git a/drivers/crypto/ccp/ccp_pci.c b/drivers/crypto/ccp/ccp_pci.c index c941e222c7..bd1a037f76 100644 --- a/drivers/crypto/ccp/ccp_pci.c +++ b/drivers/crypto/ccp/ccp_pci.c @@ -11,40 +11,6 @@ #include #include "ccp_pci.h" -#include "ccp_pmd_private.h" - -static const char * const uio_module_names[] = { - "igb_uio", - "uio_pci_generic", - "vfio_pci" -}; - -int -ccp_check_pci_uio_module(void) -{ - FILE *fp; - int i; - char buf[BUFSIZ]; - - fp = fopen(PROC_MODULES, "r"); - if (fp == NULL) - return -1; - i = 0; - while (uio_module_names[i] != NULL) { - while (fgets(buf, sizeof(buf), fp) != NULL) { - if (!strncmp(buf, uio_module_names[i], - strlen(uio_module_names[i]))) { - fclose(fp); - return i; - } - } - i++; - rewind(fp); - } - fclose(fp); - CCP_LOG_DBG("Insert igb_uio or uio_pci_generic kernel module(s)"); - return -1;/* uio not inserted */ -} /* * split up a pci address into its constituent parts. diff --git a/drivers/crypto/ccp/ccp_pci.h b/drivers/crypto/ccp/ccp_pci.h index 6736bf8ad3..d9a8b9dcc6 100644 --- a/drivers/crypto/ccp/ccp_pci.h +++ b/drivers/crypto/ccp/ccp_pci.h @@ -10,9 +10,6 @@ #include #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices" -#define PROC_MODULES "/proc/modules" - -int ccp_check_pci_uio_module(void); int ccp_parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain, uint8_t *bus, uint8_t *devid, uint8_t *function); diff --git a/drivers/crypto/ccp/rte_ccp_pmd.c b/drivers/crypto/ccp/rte_ccp_pmd.c index 7338ef0ae8..8b3a5a304b 100644 --- a/drivers/crypto/ccp/rte_ccp_pmd.c +++ b/drivers/crypto/ccp/rte_ccp_pmd.c @@ -22,7 +22,6 @@ static unsigned int ccp_pmd_init_done; uint8_t ccp_cryptodev_driver_id; uint8_t cryptodev_cnt; -extern void *sha_ctx; struct ccp_pmd_init_params { struct rte_cryptodev_pmd_init_params def_p; @@ -213,7 +212,6 @@ cryptodev_ccp_remove(struct rte_pci_device *pci_dev) return -ENODEV; ccp_pmd_init_done = 0; - rte_free(sha_ctx); RTE_LOG(INFO, PMD, "Closing ccp device %s on numa socket %u\n", name, rte_socket_id()); @@ -300,7 +298,6 @@ cryptodev_ccp_probe(struct rte_pci_driver *pci_drv __rte_unused, .auth_opt = CCP_PMD_AUTH_OPT_CCP, }; - sha_ctx = (void *)rte_malloc(NULL, SHA512_DIGEST_SIZE, 64); if (ccp_pmd_init_done) { RTE_LOG(INFO, PMD, "CCP PMD already initialized\n"); return -EFAULT; From patchwork Tue Oct 4 09:51:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 117298 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E1D6AA0543; Tue, 4 Oct 2022 11:52:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 14DE042847; Tue, 4 Oct 2022 11:52:01 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 7820240DDC for ; Tue, 4 Oct 2022 11:52:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664877120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W+WQ0Ym4ZPpyGk48cXwLy+OxHGPukEznQYv3uy+dgJQ=; b=gEmN1mR/xS2zxgFptfLJR5zoyY17Bbw5R6VXZUxQGrTbTuTNvhW8cmGE90F7DlmDu8nUuD l0YDIwGmNmUUgvdY2VEJ4e94rPmhyHFehSq7TiWss/C3Ez8rywSLF/FEGdekZmCdSWrfI9 5t2S0nWRdUo5Ha/kSUN+PnH2dCJhZ/k= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-548-JvVWZ2RlP0-hMmCDekzkLg-1; Tue, 04 Oct 2022 05:51:57 -0400 X-MC-Unique: JvVWZ2RlP0-hMmCDekzkLg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 948843C0D189; Tue, 4 Oct 2022 09:51:56 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56A1139DB3; Tue, 4 Oct 2022 09:51:55 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: gakhil@marvell.com, sunilprakashrao.uttarwar@amd.com, stable@dpdk.org, Amaranath Somalapuram Subject: [PATCH v2 4/4] crypto/ccp: fix PCI probing Date: Tue, 4 Oct 2022 11:51:32 +0200 Message-Id: <20221004095132.198777-5-david.marchand@redhat.com> In-Reply-To: <20221004095132.198777-1-david.marchand@redhat.com> References: <20220909150411.3702860-1-david.marchand@redhat.com> <20221004095132.198777-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 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") Cc: stable@dpdk.org Signed-off-by: David Marchand --- 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 | 18 +-- 7 files changed, 26 insertions(+), 345 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 351d8ac63e..461f18ca2e 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 @@ 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 = 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 8b3a5a304b..ac05d63ade 100644 --- a/drivers/crypto/ccp/rte_ccp_pmd.c +++ b/drivers/crypto/ccp/rte_ccp_pmd.c @@ -180,15 +180,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}, }; @@ -241,9 +235,7 @@ 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; } @@ -267,7 +259,7 @@ cryptodev_ccp_create(const char *name, internals->max_nb_qpairs = init_params->def_p.max_nb_queue_pairs; internals->auth_opt = init_params->auth_opt; - internals->crypto_num_dev = cryptodev_cnt; + internals->crypto_num_dev = 1; rte_cryptodev_pmd_probing_finish(dev);