From patchwork Thu Jun 26 09:58:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1530 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 967662BF009 for ; Thu, 26 Jun 2025 09:59:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931962; cv=none; b=VlxT2hP9LXxv4YTP+VJeiRjGO6r6/iESmAqxZkwsYQNT6FwsBmx+PC5PsEM+Vjy3gJuXeyX9yOB4NT3L7Sh9j38c3sDLNpeCSfF9auwgCrUm9gucYkHJLC9clo09vR1AEGVRxcTI2SQg3p4AEeWvE0pnkI2FbB4XuVTlAl65oos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931962; c=relaxed/simple; bh=V+HFJ3mcjgzB1Gr3bIDT3f6dj+Z5XsFbLbUNii2zGtc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mzXTEXK7ytxd/HhvjCGSq0O/jAeJJkJyRGGHex77adYO0ypJa56Plqvn8kHAWCZCcDN0hOxUggx1xKc/LRKlXJJhdxwrfWha7v1OYSvhZI1DPefuicFAkswGJwsmK/xFbox0bIel0B5/gft5zT+75LlZLA4yo6f1lhfQZ2qymaE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PdxU76tL; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PdxU76tL" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-ae0bde4d5c9so153965766b.3 for ; Thu, 26 Jun 2025 02:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931959; x=1751536759; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XbU44eJvfJDBcTZ+xWKQo+1cPwZ/TlkyCXqSjcDCqLQ=; b=PdxU76tL/1/AFnrEdOtYNytvyXlXYNk0wvBV1K4bu4GXS+XmuDvP0+0U56YwFNji7Z dBMnC/hNAZORjqpevXw65w2YY1COep7W3+UT1EGEVQmQvhHGYKr4VnhWX1DXqJDpM4ri NJx4Eo6PQXI55Kh7+Y8CQ74VNczHvNk8NziLHogU37fGyYCjy2arZ9G12xzwBlM3i+MA PZtMIpkpHtw4uABVrMMqZbs9QJRWhZwkoKj1SKAb0V5sFu2zrQHns6orLo6aDmkdAAT/ n1m1uo762kxO2wSo6ABPpH9p1B1Bt8LjsCfVDOCl7oQ5QMjmhQFdwzGyLypWXf7DxgI9 jOWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931959; x=1751536759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XbU44eJvfJDBcTZ+xWKQo+1cPwZ/TlkyCXqSjcDCqLQ=; b=vGy6RHvR11yUwA/5aSNvvabN+wUnZH+uHaytMRxKR96CRt1Yu2wsKec+MSE+a/I+Mf sQyr18/tnk1It9pU5rojVNTmtIpIdY3mKnAZ1KOimSHoOEFw1mrlP2wPkyucHk/+zuRz FnQqJFRCksRaFolJhIlFBRWKcFFAKQQUf5uvtGep4S8H8+80umbjXWDvgpxnNir0SjKe aIK1rEfomisA4Uxd68Dg/AtbpHw7N8G5wdmUgFOhTALOgfAHG+2gSosRUCoA6BTPjaZM 3aPweLwJaJ//yO5ZQveFZwZ8ceFxNyxNIIAHoum61AJ4A73JGcF+eC6VDCrvGwYLsH6U aJzQ== X-Forwarded-Encrypted: i=1; AJvYcCVbyUiP2dqHKRUGK7FnAwiSzlhPlBjXWQdOMf+ppXZILCV21gqOqREfJzsImAXREQTTIf6+uSwWH2Wz0A==@lists.linux.dev X-Gm-Message-State: AOJu0YwAhcf7l71ORQKRXo8iHvxFAnEQ8ueBgUE4aFPx+dOSsx7Jqkq/ /qtoinVDWDCtrjX1bjxu14d19Puv93R5DUqNcFi/I1cXeZdrTYMR9kq1 X-Gm-Gg: ASbGncuIKeRWCn5lsu+P6YszLV36VHg9YSN2XitlBBPJ7qRTMi+F8noT55Vix2hOeEp b7wbEkqQ2hf2WSd/mqydNk+qLyFbDws0xO12DE+thXIK/2dkHDbdK1xPgTzKRfAME6eBh0C5L9d 1OFVcRGYKgq4l0qjQiCswU3AycEIo4N1zjf2JY1Z+oqHss24VDfI2D342ttpCRk5zKRjifZ5c9v 8udHgKKmgIL0eK4tlua4Fi/kCR74vEyuHHrvSajOeDPfkhaoMQra+wZEIz9qcDgYrELfkxEaVbt q0BerTRBoSSZolPF713SW10o0IRcMH9gV3cApdcgvs1ujlBE5/qWk5kb45GWZRXMguKUMATx4mC I0g5pT4lyTlUVTA== X-Google-Smtp-Source: AGHT+IEaMXp6A7i8DWJAL63v7SwwWZbY3qhE9qWDgXfE0g+LUPmTke+IYpv3zr+vGVl6rNn5ZDE3ag== X-Received: by 2002:a17:906:360f:b0:ae0:bc2b:61cc with SMTP id a640c23a62f3a-ae0be84e3e8mr577634666b.14.1750931958448; Thu, 26 Jun 2025 02:59:18 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:18 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 01/10] crypto: sun8i-ce - remove channel timeout field Date: Thu, 26 Jun 2025 12:58:04 +0300 Message-ID: <20250626095813.83963-2-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Using the number of bytes in the request as DMA timeout is really inconsistent, as large requests could possibly set a timeout of hundreds of seconds. Remove the per-channel timeout field and use a single, static DMA timeout of 3 seconds for all requests. Signed-off-by: Ovidiu Panait --- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 1 - drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 5 ++--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 2 -- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 1 - drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c | 1 - drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 2 +- 6 files changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 5663df49dd81..113a1100f2ae 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -276,7 +276,6 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req goto theend_sgs; } - chan->timeout = areq->cryptlen; rctx->nr_sgs = ns; rctx->nr_sgd = nd; return 0; diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index 658f520cee0c..79ec172e5c99 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -210,11 +210,10 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) mutex_unlock(&ce->mlock); wait_for_completion_interruptible_timeout(&ce->chanlist[flow].complete, - msecs_to_jiffies(ce->chanlist[flow].timeout)); + msecs_to_jiffies(CE_DMA_TIMEOUT_MS)); if (ce->chanlist[flow].status == 0) { - dev_err(ce->dev, "DMA timeout for %s (tm=%d) on flow %d\n", name, - ce->chanlist[flow].timeout, flow); + dev_err(ce->dev, "DMA timeout for %s on flow %d\n", name, flow); err = -EFAULT; } /* No need to lock for this read, the channel is locked so diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c index 13bdfb8a2c62..b26f5427c1e0 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c @@ -446,8 +446,6 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) else cet->t_dlen = cpu_to_le32(areq->nbytes / 4 + j); - chan->timeout = areq->nbytes; - err = sun8i_ce_run_task(ce, flow, crypto_ahash_alg_name(tfm)); dma_unmap_single(ce->dev, addr_pad, j * 4, DMA_TO_DEVICE); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c index 762459867b6c..d0a1ac66738b 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c @@ -137,7 +137,6 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src, cet->t_dst[0].addr = desc_addr_val_le32(ce, dma_dst); cet->t_dst[0].len = cpu_to_le32(todo / 4); - ce->chanlist[flow].timeout = 2000; err = sun8i_ce_run_task(ce, 3, "PRNG"); mutex_unlock(&ce->rnglock); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c index e1e8bc15202e..244529bf0616 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c @@ -79,7 +79,6 @@ static int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wa cet->t_dst[0].addr = desc_addr_val_le32(ce, dma_dst); cet->t_dst[0].len = cpu_to_le32(todo / 4); - ce->chanlist[flow].timeout = todo; err = sun8i_ce_run_task(ce, 3, "TRNG"); mutex_unlock(&ce->rnglock); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 0f9a89067016..f12c32d1843f 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -106,6 +106,7 @@ #define MAX_SG 8 #define CE_MAX_CLOCKS 4 +#define CE_DMA_TIMEOUT_MS 3000 #define MAXFLOW 4 @@ -196,7 +197,6 @@ struct sun8i_ce_flow { struct completion complete; int status; dma_addr_t t_phy; - int timeout; struct ce_task *tl; void *backup_iv; void *bounce_iv; From patchwork Thu Jun 26 09:58:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1529 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC3A12C032B for ; Thu, 26 Jun 2025 09:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931963; cv=none; b=P+hgXXEfA/GaI8aRePWqodNEzhtLt2kLhgwwxwV4oLXszu2gf4eSyNzqBFK3z/84/6siPxPX6eLubnP7VGtyCGkJ4wMNCQJhVgbCEuMnV0d1PmEBJZsgZNSPTOa8k1XhW9WmtPjzaqPSKneL3FmGeizKsb1JJ6Q8pXupAcsHmNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931963; c=relaxed/simple; bh=D3Fpyml+Pwh/ot9LUtEAJrW9x78rJDQPnjdfBz8Z7cI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bt94gvEVHFwI/r8A3HKBfaadfNXI16CdBXKeEupif5cZD0D6IG3JUDgvMkuW1xS+2y3lcu5XP4SVL9TuyWZivnfZefGQyir64VwkR85910OgJ2bbgwUuyEfOj6wGRc069Nzr1SxjfyycB1OHNTTLCeCEZcoPAIkPK5B+hPjGYqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D8dxDJbc; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D8dxDJbc" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-ade5b8aab41so169083366b.0 for ; Thu, 26 Jun 2025 02:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931960; x=1751536760; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0HrsFLSEEMdhGLUzZIYXTdJy0VycwWTY4NZmzeB9UZg=; b=D8dxDJbcxvirp2TYjdwVRuZUVIii1/d2pgzLMyrFs/1mgX3e35n/OXzPqfEhYTR29v 7epJL4jbvfYDUleNX6/yKVJUIUNphSIMel1N5yknbM/RW7g5hDWKlUvxEvG9WhONLQhU 7Vdr7nY7MCC2s6YHL4HcDEgjcc4McD60NogZgKIr1WUft9JlEacAgEeWoKHs46Ub+KMh 9+myUTcWU5szFT40HUrg96r4FTWgbGzsICueaEAvu0RmbvWLvAfRHkrs0QvkJdPOTNSg uIXJRQ/E2+3p37CguGtLsFcRuySNyAuNqN1F2UKTDIHSLI0ScuP5KoL2hJtIvId1FISc DUvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931960; x=1751536760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0HrsFLSEEMdhGLUzZIYXTdJy0VycwWTY4NZmzeB9UZg=; b=tqcKqI3WDt/IjFByIjRW5UyR+ontkSInzsShNj1Rfq5raScxZRnZhWEiNZH2dJCPfj 5+3+QRRcRgAgq7hFFyM3uJObmWgf0YIEoTpWbQ/glOAogvCAmQrSiEycbUuUPSeungd1 glLv74T+2evFRRj+x6aB8C2IoZmYC5mWD/avY3iCnRYYAfYjd5AQ5sJFrTl/oCO5cL8A vJ9fdiDxhs81ms2kfzCpsi4Uj+/ZF+N/dDRzouTQBxk3DS56VSLLWblkuC7+3lPJbMlz GYBqiDg3eJBh9RJutlU1lqHH4HcvUNg29gA49XpqdcK/Z+xx4ibfkGdI9EfH1jTWzvJL 21mA== X-Forwarded-Encrypted: i=1; AJvYcCWT6i6n7G1JkVaVMy3vEUob/gzcwHquBlOiWjhvrrhJCS+IjNXndCLrhojis4G9XD4wAqaMylv6j8A+KA==@lists.linux.dev X-Gm-Message-State: AOJu0YwK45w2fn4pAJXqq6pd8UZuvgXoGoF1NuLmXfiQutiXFURsQeyW yA7ugeudqce6U3PWHv82ZrwPsu1OlL4VFMfVmaY4ZgqiYlnwHmUVdy3VsKSyFQ== X-Gm-Gg: ASbGncuNZcm5BEp/vhn6QALFcoZ+PkXu+NIUZjN9XfUB+cfLB1Tq23tiCoivfTgmLiB PP1/BEIhdMJNySSqVUNxCAgKjPIs5UBsfaTm05+TnrYrNcb0nWozt5OF+30pta7buBxB0JkUlKJ fZwc9vN/G2Es37ndTqBGJHksdNKdV3QuiM/c+xFhspAM4XrB6QtFYMqDvtvUaoxtL9ENYnBsnjs TbZdzL0mZiLN9eSKbuecUP3KYRFLPW4CKh4+tTTBXw2b//vGpZ/c46oI40uqYCwSrz+uvhcAcx5 yQQCi+m/JDK41X5G8QH1f19rFismI9N5L0ZLx7Cvru9XqsWMa37by//qa43hk2Dhp5OZwnJLbU0 T7mUKD+FrF8USPe3i1U9DnEGd X-Google-Smtp-Source: AGHT+IGcHkgMnqpZF93lLxs84Oee/gXcIKO2zDueULt6PM5LIPG4njAWAD+IiAyNDCajyksrQT6oWA== X-Received: by 2002:a17:906:6ac1:b0:ae0:9fdf:25e8 with SMTP id a640c23a62f3a-ae0bee52de0mr552743566b.47.1750931959733; Thu, 26 Jun 2025 02:59:19 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:19 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 02/10] crypto: sun8i-ce - remove boilerplate in sun8i_ce_hash_digest() Date: Thu, 26 Jun 2025 12:58:05 +0300 Message-ID: <20250626095813.83963-3-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Retrieve the dev pointer from tfm context to eliminate some boilerplate code in sun8i_ce_hash_digest(). Signed-off-by: Ovidiu Panait --- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c index b26f5427c1e0..61e8d968fdcc 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c @@ -238,19 +238,15 @@ static bool sun8i_ce_hash_need_fallback(struct ahash_request *areq) int sun8i_ce_hash_digest(struct ahash_request *areq) { struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); - struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg); + struct sun8i_ce_hash_tfm_ctx *ctx = crypto_ahash_ctx(tfm); struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq); - struct sun8i_ce_alg_template *algt; - struct sun8i_ce_dev *ce; + struct sun8i_ce_dev *ce = ctx->ce; struct crypto_engine *engine; int e; if (sun8i_ce_hash_need_fallback(areq)) return sun8i_ce_hash_digest_fb(areq); - algt = container_of(alg, struct sun8i_ce_alg_template, alg.hash.base); - ce = algt->ce; - e = sun8i_ce_get_engine_number(ce); rctx->flow = e; engine = ce->chanlist[e].engine; From patchwork Thu Jun 26 09:58:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1528 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 152892D12E3 for ; Thu, 26 Jun 2025 09:59:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931964; cv=none; b=PoumlPY+Q2Jlx4fqJRnDE/EVCYzggkiI0VN7tSNBxFdvXhLeKAWTv+JyI1MI3ZD1dldzNTkgSJAMlOAcn8M4qgIBomPnDSlGgkV0LYacCucdTrUxvb2wAhn3P6u5AnPcujcjdcdp68kbVv3q5F3XVkdh21Qiju8FVXYyxZPuHsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931964; c=relaxed/simple; bh=pRmnLFjBJ2dWkN+uiG3G+4366k2+/zNV3iQ7dsrr+ws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qSuvAYIrQULa7y+tcMBPJX67J/Qa2DyYtTG9pdoV5oV8F6alZsYwhks9Fhvoc2MRCu2PKASnX0Q4/MGtnQmmws9euIYqoK0+M2+zrCfsRdTnzfJUhLVlGlMIj7kikaI8ocMLdqemV881UnYsOE7hDJzuG2C5OVELNr44SjY1jRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RTyHkjak; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RTyHkjak" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-60c4f796446so1275044a12.1 for ; Thu, 26 Jun 2025 02:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931961; x=1751536761; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t10wxuAUiB4KyOt9zeZgZ/9RxJrj16+YdQHln4bOH7s=; b=RTyHkjakQY4F/YV2LF8FVKDjo14jsG8s0HzkzOHrHI0OFGEjBjleRiJsRZaLI3RWoz YucEdDdvCgvsw6ijN07Df5FBZkbEEUPlwA3JhhLIoUHurqVfzn1PXctTp5vDgso+IUa5 GwNCnXzz9mKPWlOn/Im0+aVxrWXP1soLqB3/JZCzEeqRT90mMlHVf+B94UlyjMO7+DPA G8C1tbA0D6YJ/Ry9qhLYJ8NoAWRovqsiXwlsYjXgANquwYvjsB9AP8LohYAxhRf6//R8 LxRCdcu63Eg1oAaBzBx9ZxwkV4Ww4bg3BQWusCjzjCopoaRMZf8vDnB9jAaDgCcBT8DQ kL8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931961; x=1751536761; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t10wxuAUiB4KyOt9zeZgZ/9RxJrj16+YdQHln4bOH7s=; b=L2C87VGJj33cVyaZSqnUd8mCX9wylKvVwcYEKh1KmQIaKG0R+9wZdTExvr6fvvqtG1 KSLuj8UNKA4m5BP7KhDoJ8tOIWA6+l9HL7sQfKX1rtHAETS8goO73yFWRDvOhv6wB645 seMnOhUe7WtpSjstQO+bI7XLsC4w82itK1B1ZFiyNRjkX//b05VMJo9Ro7E8aoLBHiTO ZpYBR8GdafMvarTjit/nUtJJW9u2zuippGhGuW2XA40Un7X2NFmqzh40vjDwSrbiVEyP mWpdC5yfiqfjgKiTrrmxVjijYu1lB0vu2aIrbnuOw9QjQtV4W3iiPhP7auoune1BGs8o ko6g== X-Forwarded-Encrypted: i=1; AJvYcCWZMo8i4dZLErxBet+ssY4fBc1gbsfTJifc9J/QRk3cAU9jWY/XobPUkZZ+tHt01wlhETrIWACVDGEOYQ==@lists.linux.dev X-Gm-Message-State: AOJu0YxaYoUhl8cFHsuR/HkFeoCturhhPHjY6kJJmilPHtOzgBedYNgl EkeqVeuVItjC2Yct+SmQ23RVwUJet4Db0aEyI27sjBSTZTyTFbqjTGmp X-Gm-Gg: ASbGncvk8a0yW71ozNJLIgpO1ZidG/uXmZ/GE1S87x16r/v0VXQ8guPSKxFaFSMpqOW bFC1e1fd6QvFXZVOk88LAYNbh00Cm1fG2lOrWIXQWsled7FQQW/RK3QEb1mNcfpzBLF6wnGER2H 5E9ZXyftVi1rzBvxf0EQBw0jCFgpVEKbjCf9lHKys+SWSHyQM8w5dsVdpBoVrNCbNlmNk0eu8DL FLEBznf/UkB9W7PvRZAkQUjycLSDlQ4Jt1+VrvqTPfPqNX3d/JCA+XvkgnFDYdnbqKgPO5P16pL 8uvpmStzcdktFeWM5aimubo5+cb6BNZTYBaQ3/hsgDlge31bp1rzepyomjgMTklfeDmv7ndH4pz w1QlUIfdih9y9OA== X-Google-Smtp-Source: AGHT+IF88aeRCVtH1nDToQx7qH4JEcc3ZSBCfS0kNyW1PJ4UHQE1SJGsErLVbTOdPYpSRcUEg4t7Mg== X-Received: by 2002:a17:907:fd01:b0:ae0:b33d:2a4a with SMTP id a640c23a62f3a-ae0bee50370mr591341566b.35.1750931961147; Thu, 26 Jun 2025 02:59:21 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:20 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 03/10] crypto: sun8i-ce - move bounce_iv and backup_iv to request context Date: Thu, 26 Jun 2025 12:58:06 +0300 Message-ID: <20250626095813.83963-4-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Currently, the iv buffers are allocated once per flow during driver probe. Having a single iv buffer for all requests works with the current setup where requests are processed one by one, but it wouldn't work if multiple requests are chained together and processed in one go. In preparation for introducing request batching, allocate iv buffers per request, rather than per flow. Signed-off-by: Ovidiu Panait --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 18 +++++++++--------- .../crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 12 ------------ drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 8 ++++---- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 113a1100f2ae..9963e5962551 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -209,11 +209,11 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req if (areq->iv && ivsize > 0) { if (rctx->op_dir & CE_DECRYPTION) { offset = areq->cryptlen - ivsize; - scatterwalk_map_and_copy(chan->backup_iv, areq->src, + scatterwalk_map_and_copy(rctx->backup_iv, areq->src, offset, ivsize, 0); } - memcpy(chan->bounce_iv, areq->iv, ivsize); - rctx->addr_iv = dma_map_single(ce->dev, chan->bounce_iv, ivsize, + memcpy(rctx->bounce_iv, areq->iv, ivsize); + rctx->addr_iv = dma_map_single(ce->dev, rctx->bounce_iv, ivsize, DMA_TO_DEVICE); if (dma_mapping_error(ce->dev, rctx->addr_iv)) { dev_err(ce->dev, "Cannot DMA MAP IV\n"); @@ -299,13 +299,13 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req offset = areq->cryptlen - ivsize; if (rctx->op_dir & CE_DECRYPTION) { - memcpy(areq->iv, chan->backup_iv, ivsize); - memzero_explicit(chan->backup_iv, ivsize); + memcpy(areq->iv, rctx->backup_iv, ivsize); + memzero_explicit(rctx->backup_iv, ivsize); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset, ivsize, 0); } - memzero_explicit(chan->bounce_iv, ivsize); + memzero_explicit(rctx->bounce_iv, ivsize); } dma_unmap_single(ce->dev, rctx->addr_key, op->keylen, DMA_TO_DEVICE); @@ -348,13 +348,13 @@ static void sun8i_ce_cipher_unprepare(struct crypto_engine *engine, DMA_TO_DEVICE); offset = areq->cryptlen - ivsize; if (rctx->op_dir & CE_DECRYPTION) { - memcpy(areq->iv, chan->backup_iv, ivsize); - memzero_explicit(chan->backup_iv, ivsize); + memcpy(areq->iv, rctx->backup_iv, ivsize); + memzero_explicit(rctx->backup_iv, ivsize); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset, ivsize, 0); } - memzero_explicit(chan->bounce_iv, ivsize); + memzero_explicit(rctx->bounce_iv, ivsize); } dma_unmap_single(ce->dev, rctx->addr_key, op->keylen, DMA_TO_DEVICE); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index 79ec172e5c99..930a6579d853 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -757,18 +757,6 @@ static int sun8i_ce_allocate_chanlist(struct sun8i_ce_dev *ce) err = -ENOMEM; goto error_engine; } - ce->chanlist[i].bounce_iv = devm_kmalloc(ce->dev, AES_BLOCK_SIZE, - GFP_KERNEL | GFP_DMA); - if (!ce->chanlist[i].bounce_iv) { - err = -ENOMEM; - goto error_engine; - } - ce->chanlist[i].backup_iv = devm_kmalloc(ce->dev, AES_BLOCK_SIZE, - GFP_KERNEL); - if (!ce->chanlist[i].backup_iv) { - err = -ENOMEM; - goto error_engine; - } } return 0; error_engine: diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index f12c32d1843f..0d46531c475c 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -188,8 +188,6 @@ struct ce_task { * @status: set to 1 by interrupt if task is done * @t_phy: Physical address of task * @tl: pointer to the current ce_task for this flow - * @backup_iv: buffer which contain the next IV to store - * @bounce_iv: buffer which contain the IV * @stat_req: number of request done by this flow */ struct sun8i_ce_flow { @@ -198,8 +196,6 @@ struct sun8i_ce_flow { int status; dma_addr_t t_phy; struct ce_task *tl; - void *backup_iv; - void *bounce_iv; #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG unsigned long stat_req; #endif @@ -264,6 +260,8 @@ static inline __le32 desc_addr_val_le32(struct sun8i_ce_dev *dev, * @nr_sgd: The number of destination SG (as given by dma_map_sg()) * @addr_iv: The IV addr returned by dma_map_single, need to unmap later * @addr_key: The key addr returned by dma_map_single, need to unmap later + * @bounce_iv: Current IV buffer + * @backup_iv: Next IV buffer * @fallback_req: request struct for invoking the fallback skcipher TFM */ struct sun8i_cipher_req_ctx { @@ -273,6 +271,8 @@ struct sun8i_cipher_req_ctx { int nr_sgd; dma_addr_t addr_iv; dma_addr_t addr_key; + u8 bounce_iv[AES_BLOCK_SIZE] ____cacheline_aligned; + u8 backup_iv[AES_BLOCK_SIZE] ____cacheline_aligned; struct skcipher_request fallback_req; // keep at the end }; From patchwork Thu Jun 26 09:58:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1527 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B61B2D3EC9 for ; Thu, 26 Jun 2025 09:59:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931966; cv=none; b=fKVL3jYIrfNCXlmta+9gdphROJ/lvBguhk8kQ8S+sprI7rkkzMmgEWKGIZd2FVwlXPL0pCGkGrn7Gd58wtnl/AlAcxRveJz8IxVjyJdPE/F/q3/OQM7IH36FtF59oWwZ8ajYfejjZRdATy/GqlW5hYm34zyxUnT+s7Jb4GORobs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931966; c=relaxed/simple; bh=C/gJk2ObWTENdNN8gXRsiciv6hvj3wk+copliiqlW8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YyO4mtWAYhUzQaPaJ8dB048pDOibf+GftwqfBvbdSSIEp9dvudVMGqpGKeaeXIkyFFwWYTDzgct4fdMTg3TWqFa/+2CMq2CoWgPd9/dDoAq1eZV5dOnw8XkLzHZddaKL7XPAqneGfGYjX61sTUvG1O8ajGfFm6Zw6eMAnOK/RKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RHnqNbGj; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RHnqNbGj" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-adb2bb25105so121055466b.0 for ; Thu, 26 Jun 2025 02:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931963; x=1751536763; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n4FE/m8CCQWWX6zEjUZSa1AuebcPVAo/kb1WN2hI258=; b=RHnqNbGjeNTOkkAkXfdRXmyCd83ZEI2RuEYWgm2wo1aG2wgBgMB79rtOr//wfoxCK8 17gEq1eFdPgfr1aayWS9bB6GmAgdehXdi/NwdKb9bar06SDN1pAu3CdHm2vFuai6mGCu JKTy6/kwnd/n2OsZJEDi4KsCfszlvclN+Fu+4fV0z/KjsuPC35715PqZtxmO8QP6m0z5 3qzI/AhyhDEsx/Efx+j/yS+eZV2v2nm/NA2Tbwg71M6IzrH/LJwbDlKmCr/Zd7psZ50t LiB/itkKN29ScNN5HmpO+Q/vH3v7qOjZl1oXrgiFrsSiqVPKg03U53IfOk5flvX145Ez BpIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931963; x=1751536763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n4FE/m8CCQWWX6zEjUZSa1AuebcPVAo/kb1WN2hI258=; b=NwZG0s1ADW6BoRlFeG0ovUxOhQKVW9sXOBJPSQJ+XCMOQiU+gJ6I6CVcGFPSkkkgNN NIzs8gpu3U59qsQBiyUJjPHPEYqTTAFXmTn5umTIrkkCyD9DrsiSpDKef2K+psmaBfPN oaZUlZynRkcUWoU5YYMCV/S8zyuWa4rDYI3yrVZVmAQftBPXxfpU7RoslZJk+gZuSP/n UHC2jHpA9i1hOpAq80SMHIXnG69Rdk0MknIWF1SBRrp0kOURmxKSzhcYDPFhzrGZ1TDl 5aCjKTpv8e1QJurus3T3P2bJsGpSiaP0RseEARtRAJVJ4eYIs1GQGdNJmCj1hhwGI5Bn Au+g== X-Forwarded-Encrypted: i=1; AJvYcCUwdoqFGYSu1KC6q1UKo9rnS584z4w/Ilk2fk1pNfOWqcrbl4OdSSP64yBPqDaRfSKHTRwwz/EfI0jrUw==@lists.linux.dev X-Gm-Message-State: AOJu0YwFLMAV5Z+mf/1o8zgkWuto40jhUzf+AB6oZ5fqoiQDx91T9Gqk P6spoFsTcVKaIRC7S8eOCu/opweZaGa/4P/OWG3Y7W6V3JCJRr9TI6RF X-Gm-Gg: ASbGncvnWg+dA0zFOfWOpDY76HnQmElr6PVVFezvH3/slLwdMrESA7HtUegqzwyhd4W MgcURKHDLL/XOVjwVoEkPewfrjP+Da2YmeFOoSWZ5CxtMhju6GXmEyE67+WIVWRWBVX+wm/WYb3 XT8jwa4Z2HDx5wNQAAQBGSSgLSDW+fPqkTqEX4aICTHz7vbsM3xHegEPRZAyACHJF/GYrSyEbTY p97uOj0Suj83rSTPGLN+4R33lmLFqSZk97QXbpOIhrMVCsu3+B6vJaL6kPrqUfsMaM5+m2Gf1Kg GeSV9dwNysO9u1fnbCf64YaKeIIy8m6hmf0PEi5xMqm0rtO2PvQ3yuYyp4JHKxz1w2lfCrfMZb1 rylTUaHiIDzu1stEb2FGn+X3X X-Google-Smtp-Source: AGHT+IFTZlskgagUQmsCBIaQcTzLFQ/L/bhoraExJkrhCa/vRJ39QMtLqAaw8cYJYMf4uvVB6AQrMw== X-Received: by 2002:a17:907:d26:b0:ad8:9e80:6baf with SMTP id a640c23a62f3a-ae0be95d15amr719826166b.13.1750931962452; Thu, 26 Jun 2025 02:59:22 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:22 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 04/10] crypto: sun8i-ce - save hash buffers and dma info to request context Date: Thu, 26 Jun 2025 12:58:07 +0300 Message-ID: <20250626095813.83963-5-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Currently, all hash processing (buffer allocation/deallocation, dma mapping/unmapping) is done inside do_one_request() callback. In order to implement request batching, the hash buffers and dma info associated with each request need to be saved inside request context, for later use (during do_batch_requests() callback). Signed-off-by: Ovidiu Panait --- .../crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 56 +++++++------------ drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 17 ++++++ 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c index 61e8d968fdcc..3ee0c65ef600 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c @@ -328,12 +328,9 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) u32 common; u64 byte_count; __le32 *bf; - void *buf, *result; int j, i, todo; u64 bs; int digestsize; - dma_addr_t addr_res, addr_pad; - int ns = sg_nents_for_len(areq->src, areq->nbytes); algt = container_of(alg, struct sun8i_ce_alg_template, alg.hash.base); ce = algt->ce; @@ -345,19 +342,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) if (digestsize == SHA384_DIGEST_SIZE) digestsize = SHA512_DIGEST_SIZE; - /* the padding could be up to two block. */ - buf = kcalloc(2, bs, GFP_KERNEL | GFP_DMA); - if (!buf) { - err = -ENOMEM; - goto err_out; - } - bf = (__le32 *)buf; - - result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA); - if (!result) { - err = -ENOMEM; - goto err_free_buf; - } + bf = (__le32 *)rctx->pad; flow = rctx->flow; chan = &ce->chanlist[flow]; @@ -378,11 +363,12 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) cet->t_sym_ctl = 0; cet->t_asym_ctl = 0; - nr_sgs = dma_map_sg(ce->dev, areq->src, ns, DMA_TO_DEVICE); + rctx->nr_sgs = sg_nents_for_len(areq->src, areq->nbytes); + nr_sgs = dma_map_sg(ce->dev, areq->src, rctx->nr_sgs, DMA_TO_DEVICE); if (nr_sgs <= 0 || nr_sgs > MAX_SG) { dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs); err = -EINVAL; - goto err_free_result; + goto err_out; } len = areq->nbytes; @@ -397,10 +383,13 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) err = -EINVAL; goto err_unmap_src; } - addr_res = dma_map_single(ce->dev, result, digestsize, DMA_FROM_DEVICE); - cet->t_dst[0].addr = desc_addr_val_le32(ce, addr_res); - cet->t_dst[0].len = cpu_to_le32(digestsize / 4); - if (dma_mapping_error(ce->dev, addr_res)) { + + rctx->result_len = digestsize; + rctx->addr_res = dma_map_single(ce->dev, rctx->result, rctx->result_len, + DMA_FROM_DEVICE); + cet->t_dst[0].addr = desc_addr_val_le32(ce, rctx->addr_res); + cet->t_dst[0].len = cpu_to_le32(rctx->result_len / 4); + if (dma_mapping_error(ce->dev, rctx->addr_res)) { dev_err(ce->dev, "DMA map dest\n"); err = -EINVAL; goto err_unmap_src; @@ -428,10 +417,12 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) goto err_unmap_result; } - addr_pad = dma_map_single(ce->dev, buf, j * 4, DMA_TO_DEVICE); - cet->t_src[i].addr = desc_addr_val_le32(ce, addr_pad); + rctx->pad_len = j * 4; + rctx->addr_pad = dma_map_single(ce->dev, rctx->pad, rctx->pad_len, + DMA_TO_DEVICE); + cet->t_src[i].addr = desc_addr_val_le32(ce, rctx->addr_pad); cet->t_src[i].len = cpu_to_le32(j); - if (dma_mapping_error(ce->dev, addr_pad)) { + if (dma_mapping_error(ce->dev, rctx->addr_pad)) { dev_err(ce->dev, "DMA error on padding SG\n"); err = -EINVAL; goto err_unmap_result; @@ -444,21 +435,16 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) err = sun8i_ce_run_task(ce, flow, crypto_ahash_alg_name(tfm)); - dma_unmap_single(ce->dev, addr_pad, j * 4, DMA_TO_DEVICE); + dma_unmap_single(ce->dev, rctx->addr_pad, rctx->pad_len, DMA_TO_DEVICE); err_unmap_result: - dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE); + dma_unmap_single(ce->dev, rctx->addr_res, rctx->result_len, + DMA_FROM_DEVICE); if (!err) - memcpy(areq->result, result, crypto_ahash_digestsize(tfm)); + memcpy(areq->result, rctx->result, crypto_ahash_digestsize(tfm)); err_unmap_src: - dma_unmap_sg(ce->dev, areq->src, ns, DMA_TO_DEVICE); - -err_free_result: - kfree(result); - -err_free_buf: - kfree(buf); + dma_unmap_sg(ce->dev, areq->src, rctx->nr_sgs, DMA_TO_DEVICE); err_out: local_bh_disable(); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 0d46531c475c..90b955787d37 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -110,6 +110,9 @@ #define MAXFLOW 4 +#define CE_MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE +#define CE_MAX_HASH_BLOCK_SIZE SHA512_BLOCK_SIZE + /* * struct ce_clock - Describe clocks used by sun8i-ce * @name: Name of clock needed by this variant @@ -304,9 +307,23 @@ struct sun8i_ce_hash_tfm_ctx { * struct sun8i_ce_hash_reqctx - context for an ahash request * @fallback_req: pre-allocated fallback request * @flow: the flow to use for this request + * @nr_sgs: number of entries in the source scatterlist + * @result_len: result length in bytes + * @pad_len: padding length in bytes + * @addr_res: DMA address of the result buffer, returned by dma_map_single() + * @addr_pad: DMA address of the padding buffer, returned by dma_map_single() + * @result: per-request result buffer + * @pad: per-request padding buffer (up to 2 blocks) */ struct sun8i_ce_hash_reqctx { int flow; + int nr_sgs; + size_t result_len; + size_t pad_len; + dma_addr_t addr_res; + dma_addr_t addr_pad; + u8 result[CE_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned; + u8 pad[2 * CE_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned; struct ahash_request fallback_req; // keep at the end }; From patchwork Thu Jun 26 09:58:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1526 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 917702BF01C for ; Thu, 26 Jun 2025 09:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931967; cv=none; b=J9owZpOFnGJXTPa+BQacdKmhdNTI+DE9463uXLY1iAgwLKGdBOaf+rVIBJIk6hQ4/hIIvxQGZOwybQGg/C7PEtv08P1LlUWTCv1PjGHBjOESgIeSOs9znQlNLapgKCMM9JIsZJhczBHvSEBqqXqTJjerEi/xdPcrxDJlfW32SqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931967; c=relaxed/simple; bh=ThK72kzM3/NAb5q4kYO3GzKkml/jXobH2nqcwRen8oE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MHc7YwHmIjiaIIukXL9gUwQyDwJVlyc6QP+h18j5eFWC8bmxPZWmIa1ZEzXvX6xyc3okqocxHBBF1fFpiq/D9YngqvauFJRaof/GGFDlfyBlOZqiLDbQ6l3ecxjzbe3wX1Ivlop2fRxlfgElfP2Knehe/VNIHjWwMBfGsXN9nS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gouJ4oXK; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gouJ4oXK" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-ae0dd62f2adso53201366b.2 for ; Thu, 26 Jun 2025 02:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931964; x=1751536764; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rgIbzVPscBuyqUEBsClRFHHr0kmYa9s+xoX+40DNp18=; b=gouJ4oXKkJb4vO5i4Rg+itbNF22mQkl9PaqbLlS133U8g909gmzVM2W941oriEztjI /MCMef/TJqrmxjlgKGja22dH0Z1J18sjVeIEAmcttA1DYvtAVp3OhBxHoE2ngdX5JrzY jfzGHfeh2eTBeHFEWWzf2EPUlQiTlMiAC+nYK1UY6dyLXAUth7XVcXOiVjL4HW2p1Oh4 4QNNUHb6W35z5Ij41XOODzaxdIHpfnUPyeL7LsZ72A31a/zY3efe9onerluTGpH0Z0J3 YUOUbL5u8K0973R5mIjnrdD0ltnKS4c6c9lX+F3O4v6GxblL/NLlDchy/5ls0LXtlXgx B7+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931964; x=1751536764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rgIbzVPscBuyqUEBsClRFHHr0kmYa9s+xoX+40DNp18=; b=rk3BuIjCZwjKopy3ybbWyf7aLXo1IRe3AdgcMqWQvUKFfsxIJwEwkKEHxoWzqMeHLp tHIb0rifEF7p1EOpI2il64jv60X+11LsEZ8HNZ+qk3SNlxbXpj/8GBhlKxYSI/S2wqEy ugxCanOkItakfR86CODm33rzVmGl0Eud0SlqohdEFO9g9C77YnhPr1mA/MblHxb5O7jl VQ8ejNSwTxPdE3aJDBr6263Z2C+nKdTzcoHlhRXP4zuhrrfOjCYn76Z+L50gr5Uep2Lp uSJX+F9828KSKdGe7kPBvPpPz38PRGfeKPJtVFheoZsPx9zM3/l6IChIsMNNNVSxWFm7 0gHA== X-Forwarded-Encrypted: i=1; AJvYcCURmAC4NegRgHUSREMVqRLGmRNIMyw2mWMK1L7n6+7hrucPnQB7G3sNYu/t1XWZZ2OeJZ53ZiQLSjAHwg==@lists.linux.dev X-Gm-Message-State: AOJu0YzsRTk2ntnvNbS4cZ5ngdg+ovPUwhfKfoJbSU3vo+hQbXVchtIb HQpBUU+iCHQg10OFZO6eonSg8kha0coD7hIX/+scHpoPfX68T2gYSVoq X-Gm-Gg: ASbGncvDIG4wZXrfu1woUEHp9i974NyXqeoQWJUUQYZ3grG6yZHPlleb5J6bdoVta2B 7rP6n6TgasXgqWcNEdnspeG67AO2ZJ+HPIdMkadubEhxYtAthH+Qki+RhqTstRbjLbGNGqEGpnr 1ktjNJ7mMpTHBxakT8kc1/FMW3IDDb6/ymCs3gJmMNSjiebiHcrOAWAXQIJjta6/3IVWh/y1CyZ dcoEIaE7LwiXN153Ucb2pxqmxGZXW82RahgkvpLrE/hqf6NAGAyBVfUbJ6W4cDLtZO4Pj+gfa9P u9geLRJGBruMRbK4223gi+24j9vmw2ro59Ecw/cameiO2B+aw5jVJglgPKncLTQPp9Wdu7Rm3MH cg4uiTYEVWyafew== X-Google-Smtp-Source: AGHT+IHJfX+7ivm4fdZr8aEC60S1v6KlfF4DtnJ6WAAHM60+ZeTeCtoGepFQRb/ZdyWtPXc8/FAGAQ== X-Received: by 2002:a17:907:94c7:b0:ade:bf32:b05a with SMTP id a640c23a62f3a-ae0be53a92cmr665540566b.0.1750931963697; Thu, 26 Jun 2025 02:59:23 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:23 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 05/10] crytpo: sun8i-ce - factor out prepare/unprepare code from ahash do_one_request Date: Thu, 26 Jun 2025 12:58:08 +0300 Message-ID: <20250626095813.83963-6-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O The crypto engine workflow for batching requests requires the driver to chain the requests in do_one_request() and then send the batch for processing in do_batch_requests(). Split the monolithic ahash do_one_request() callback into two parts, prepare and unprepare, so they can be used in batch processing. Signed-off-by: Ovidiu Panait --- .../crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 64 ++++++++++++++----- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c index 3ee0c65ef600..7811fa17388c 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c @@ -312,18 +312,15 @@ static u64 hash_pad(__le32 *buf, unsigned int bufsize, u64 padi, u64 byte_count, return j; } -int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) +static int sun8i_ce_hash_prepare(struct ahash_request *areq, struct ce_task *cet) { - struct ahash_request *areq = container_of(breq, struct ahash_request, base); struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg); struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq); struct sun8i_ce_alg_template *algt; struct sun8i_ce_dev *ce; - struct sun8i_ce_flow *chan; - struct ce_task *cet; struct scatterlist *sg; - int nr_sgs, flow, err; + int nr_sgs, err; unsigned int len; u32 common; u64 byte_count; @@ -344,18 +341,14 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) bf = (__le32 *)rctx->pad; - flow = rctx->flow; - chan = &ce->chanlist[flow]; - if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) algt->stat_req++; dev_dbg(ce->dev, "%s %s len=%d\n", __func__, crypto_tfm_alg_name(areq->base.tfm), areq->nbytes); - cet = chan->tl; memset(cet, 0, sizeof(struct ce_task)); - cet->t_id = cpu_to_le32(flow); + cet->t_id = cpu_to_le32(rctx->flow); common = ce->variant->alg_hash[algt->ce_algo_id]; common |= CE_COMM_INT; cet->t_common_ctl = cpu_to_le32(common); @@ -433,22 +426,61 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) else cet->t_dlen = cpu_to_le32(areq->nbytes / 4 + j); - err = sun8i_ce_run_task(ce, flow, crypto_ahash_alg_name(tfm)); - - dma_unmap_single(ce->dev, rctx->addr_pad, rctx->pad_len, DMA_TO_DEVICE); + return 0; err_unmap_result: dma_unmap_single(ce->dev, rctx->addr_res, rctx->result_len, DMA_FROM_DEVICE); - if (!err) - memcpy(areq->result, rctx->result, crypto_ahash_digestsize(tfm)); err_unmap_src: dma_unmap_sg(ce->dev, areq->src, rctx->nr_sgs, DMA_TO_DEVICE); err_out: + return err; +} + +static void sun8i_ce_hash_unprepare(struct ahash_request *areq, + struct ce_task *cet) +{ + struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); + struct sun8i_ce_hash_tfm_ctx *ctx = crypto_ahash_ctx(tfm); + struct sun8i_ce_dev *ce = ctx->ce; + + dma_unmap_single(ce->dev, rctx->addr_pad, rctx->pad_len, DMA_TO_DEVICE); + dma_unmap_single(ce->dev, rctx->addr_res, rctx->result_len, + DMA_FROM_DEVICE); + dma_unmap_sg(ce->dev, areq->src, rctx->nr_sgs, DMA_TO_DEVICE); +} + +int sun8i_ce_hash_run(struct crypto_engine *engine, void *async_req) +{ + struct ahash_request *areq = ahash_request_cast(async_req); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); + struct sun8i_ce_hash_tfm_ctx *ctx = crypto_ahash_ctx(tfm); + struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq); + struct sun8i_ce_dev *ce = ctx->ce; + struct sun8i_ce_flow *chan; + struct ce_task *cet; + int err; + + chan = &ce->chanlist[rctx->flow]; + cet = chan->tl; + + err = sun8i_ce_hash_prepare(areq, cet); + if (err) + return err; + + err = sun8i_ce_run_task(ce, rctx->flow, crypto_ahash_alg_name(tfm)); + + sun8i_ce_hash_unprepare(areq, cet); + + if (!err) + memcpy(areq->result, rctx->result, + crypto_ahash_digestsize(tfm)); + local_bh_disable(); - crypto_finalize_hash_request(engine, breq, err); + crypto_finalize_hash_request(engine, async_req, err); local_bh_enable(); return 0; From patchwork Thu Jun 26 09:58:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1525 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDE782D663A for ; Thu, 26 Jun 2025 09:59:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931968; cv=none; b=DRbSQCc3/xSxTz6DLEBL6/g6KqAWrP3Es7kQC7kVg3GvTqSzBCY+hz30c/+Wrf+fRiDa0TR+Qxn3qCHhUSxZ2uIP4uV7dOk8oN5EZh9jE/SkqCTkkTgGQKdHnTlDBlDY59LPLnuC2hrIr8yNDNVjGeHKX4KGZ/BLUVxo5QRFWXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931968; c=relaxed/simple; bh=MVmmWlPksmaiBVibi00qDI48RIUv844ifSFHgrjus/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jFDi6iWOeej488pcUgjPM/r8PdHLdX671pQF8QYtYJwYMm0LJW4yAB0PX4VIp0fzfHu1SbUl2S1BgTpJvjMUebLyz81w9cBx5Quu5SCIuAkpNmf6oqHzCDAz0520H24G5yl+SoXHL3VoOL/SQhH5mtUsW8simW1FYhpk6U1A7jo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BkGQJndt; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BkGQJndt" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-6070293103cso1285327a12.0 for ; Thu, 26 Jun 2025 02:59:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931965; x=1751536765; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nOCWgCxa5TuHqEzs7P/Xd0Uu+UeKSk+lfEEEEay9BLo=; b=BkGQJndtxURBipUMovRKpAO+rTHR12X1KkWohjRtKZyiKFdMIZs8Hs5PPhVgcQL0th ouIRDAGABJNSH0emjVuFXYN6ydPRtErBmYPZOxboBnzDdiLlBw7ERiVTp36crvRLb0/P SfW5LVCNzXOaNfkbtrUBJILYrOeNk20n61LmUjVztIkt7sOliv43/p1kuRoojvk6Ss+w VXbxhcPxFKtZ6yTJdado5qURpYJq0SYHx5xqS4YipNlK6RindZdLBY9XyvL79rtTK5Rh yxXFT/VOxbgUnDWXMMyKrWcbHzUx9jTGQFAgCrTirF3usF7h7+E5DShqqkxCrahoh7Ho vOHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931965; x=1751536765; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nOCWgCxa5TuHqEzs7P/Xd0Uu+UeKSk+lfEEEEay9BLo=; b=LL/+JihQSB+4pNmI6cwBs9u+mxv+Offiu1D/zuX+sXslR1/W2SsYcryB1lVgajbxQ3 Tu6/Z24Uh85QcMfLBuMLhEnWJCXqRjAvgQQVo+XGxJla4qVX1DMHTNdYbmlfzkjOTLVH HciH02eJy6vUbXj+wnaLKkeoUUgLMKviHVajXgEh1bSCQm4WutNhN8Qs6mpPJ96YwJdp mSZYNVZaXIIfQ4wDuOXaiKWdvr6zuI2G6OV/dAY3m0sn474HfzBWHhXGxq0pnsNoPPm/ yOmTGOZeFomCblipOFcOt0JbW/VCzaiiHrGvFfnkVQSZ5LiDnci8Qm1RiteQf7VYTFLO qHOA== X-Forwarded-Encrypted: i=1; AJvYcCUmRlO2PZGTGwXHJqRMgpPm5KCmwq3ishmlZcMs56IoSVRzu0Ec/bfOyEZqLP+Tt1k1EKRrXFQ3ZPhx1Q==@lists.linux.dev X-Gm-Message-State: AOJu0YxuublnSgC8ckBcNX2GQ1iZJlXB9qUULpBIUrLGWERjKszwBJEN UUvjYauURM1ruZEBK9G1phEldq9AB0pwZPtt2VnD/dYB/tOmt69/zJWloOFutg== X-Gm-Gg: ASbGncumOc1b76dudj3mJyFzWedMXJgW9fudDepUBDk21G8nh15fRVI/S/Z3+BdTAqA J7csee0b5uT8b3naQ/BmkFV1pqhxRDCU2nduUp+PcHeISOQjikKLier0khhOfGx5V411nhGg1uw Q5s93SIckUvlTkz7mRxDaVaaa4VOpZRqjbV6ymyy/+/CSRlC5oFrmiRYJ6AdGZehYSYIG1+0yjC 7+vHgaU+PKxR2Zi3JQ8XIRRw4ajHp3/EBeenQxNfbOJtYPqU1Kj3k7inWVCk4ZEn93fwMottUIO iJDoXcinoTeHgBDyy5cszRTJopwoHjbtru9lFuaTlPpQpMmzHzYQzIQEZHQyQtLFCSOdfV0HH2p 7dgDCLQopzaUPTw== X-Google-Smtp-Source: AGHT+IFXLtDWsVLMRJFKSM7ZfKEbTxaY7obk208Kuz4qR9WlO3f5+snTWFaRNwrAjl6SXIyIm+JgZw== X-Received: by 2002:a17:906:33d5:b0:ade:cdec:7085 with SMTP id a640c23a62f3a-ae0be893190mr488892666b.26.1750931964994; Thu, 26 Jun 2025 02:59:24 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:24 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 06/10] crypto: sun8i-ce - fold sun8i_ce_cipher_run() into sun8i_ce_cipher_do_one() Date: Thu, 26 Jun 2025 12:58:09 +0300 Message-ID: <20250626095813.83963-7-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Fold sun8i_ce_cipher_run() into it's only caller, sun8i_ce_cipher_do_one(), to eliminate a bit of boilerplate. This will also make it a bit more clear that the skcipher do_one_request() callback follows the usual prepare -> run -> unprepare pattern. Signed-off-by: Ovidiu Panait --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 9963e5962551..5fdb6a986b1f 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -360,31 +360,27 @@ static void sun8i_ce_cipher_unprepare(struct crypto_engine *engine, dma_unmap_single(ce->dev, rctx->addr_key, op->keylen, DMA_TO_DEVICE); } -static void sun8i_ce_cipher_run(struct crypto_engine *engine, void *areq) -{ - struct skcipher_request *breq = container_of(areq, struct skcipher_request, base); - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(breq); - struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); - struct sun8i_ce_dev *ce = op->ce; - struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(breq); - int flow, err; - - flow = rctx->flow; - err = sun8i_ce_run_task(ce, flow, crypto_tfm_alg_name(breq->base.tfm)); - sun8i_ce_cipher_unprepare(engine, areq); - local_bh_disable(); - crypto_finalize_skcipher_request(engine, breq, err); - local_bh_enable(); -} - int sun8i_ce_cipher_do_one(struct crypto_engine *engine, void *areq) { - int err = sun8i_ce_cipher_prepare(engine, areq); + struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(areq); + struct skcipher_request *req = skcipher_request_cast(areq); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); + struct sun8i_cipher_tfm_ctx *ctx = crypto_skcipher_ctx(tfm); + struct sun8i_ce_dev *ce = ctx->ce; + int err; + err = sun8i_ce_cipher_prepare(engine, areq); if (err) return err; - sun8i_ce_cipher_run(engine, areq); + err = sun8i_ce_run_task(ce, rctx->flow, + crypto_tfm_alg_name(req->base.tfm)); + sun8i_ce_cipher_unprepare(engine, areq); + + local_bh_disable(); + crypto_finalize_skcipher_request(engine, req, err); + local_bh_enable(); + return 0; } From patchwork Thu Jun 26 09:58:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1524 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 432022D979B for ; Thu, 26 Jun 2025 09:59:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931970; cv=none; b=Mj5aFElHoLG8H4T9CQinrhi66yvChohZeEe767Isjz2nFKCBrTzWdURrIrhOo2ADOq0nsmKl02vHRsG8XG2h8XQ/PFo1l10OlpdyAG3vV3XWkYheKaflFiNRXhp4TO60HL9MvKA/z6O4lpnfF5D8TuclwGpbw8upRjnNywj6OF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931970; c=relaxed/simple; bh=kINjivbB1+ylLn7tV9af00mOK273H9HJI0nMG3aaa1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oKS0bryux0eawA1yFkeyPn05fbmF5vL4aaqFCx4HvMI+csrJnYDhYsHks3C1Gp0hvSMAZFL0QGFRXfEaHr9cygyvKn4Ooha5UBVMnGnzC6sCF3plHV+BvOYJPjl4E3fwH5qY+G7rbbhOIWL4JzfTWKU/BT5fvGAyQh9yjLXvtxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g40cgvpi; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g40cgvpi" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-addda47ebeaso168774966b.1 for ; Thu, 26 Jun 2025 02:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931966; x=1751536766; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SfOFmSReN1wX8YEf6gXPwdHyf/C+wiQacKthqWE/o4Y=; b=g40cgvpiiYSrNMcHjIztfbVI3wkL5isNrNWMArSatHMoV8WJ52r6tziW06P2hzegfS iXhH7jVbdP7OnLpZWJLYziHcK0X9j9nsFIUGm3CdLdR5bPUjRT77rhKMLU+R/owPSIva qD7oVvVAgKUh4pgSMjgORMoyaNDrneeGfRh0Nu4IZ8riH5evkAddOfNDVlPJ8Bee+0cI M4xtJept2rmNOhj/J8W/tHyhQBUmanPejjMdz4o0Bdm7L/+MizOQF88TXlREVZ6rANQ+ Pq/v9dysOWoDqoNbTcl04MIw0l9NDeoOq5zkrIrAMmMG9LzWo/644v14mT7krk2DfbTr fHzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931966; x=1751536766; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SfOFmSReN1wX8YEf6gXPwdHyf/C+wiQacKthqWE/o4Y=; b=qXjdH8LwbWaxRuhm9+JxmBQmvKn9BZZFwpTsySAIJpRupZ0F0dHUob1WFO2x5r1r19 51RY7t7WO2PaNSxi4/hG66SOAiHucqcj8QILr4BIQdgxHpE2SH8aXa1AS2CIB31J9sya poSFrsckvcxV3hwgGvGzKO0UZjflGopLrWuUcFi6kNvspou+oYZJpPGKvqGUOOoyztzz h5ZZbJSECwIZfmKcVFvU2vsMx6hUDfjGyLpwVwEEUV39VIpBNDoG2TfpESX3dhx3zdpq SV8O6VXQN9iZlVhMiqXPsKdnQYVzpvtrnoe5syPsv2i39afA0puuOaqe9GQ/vA4h/PDy Gikg== X-Forwarded-Encrypted: i=1; AJvYcCU6tflcZKkLR1fnVfwxMbn0JzszaLeMiRLpcZokcT3T+yGuwy9y49CVZn0+2/Jl2pZzkMpQi9oU3SYNyA==@lists.linux.dev X-Gm-Message-State: AOJu0YyqVZUyLDUT1pNwlwn8sX2AwGtsOKjhTMyi1JpJDKRgxZkvzB4U bTR3+F9ITE/xOyNuJdG154OeH+El954Uk9S4kUdzXz70AIk4JeM+SorR X-Gm-Gg: ASbGnctbHpmcsBXjgdijiQxpCm6qt/DTxRMUBeKr5E7BvRSsmP5QHk/ONCsqG8dxgcF lHRWlkkOYnCZl+1wzB1ARN8xVqTxkLzbgS+7jA0Uw3f3J/d7sjzsakZ4zrNkCWkEtIEo1bsEvY8 SMtVBlQQSxpUYMAOOSfyD0nluXQFwx7FfEISibCTVqJ4y5TpCCDP03v4C7GOvKCk62NrVYgJazr MKIBeJJmv6ZxWJYpaJ7BseUDkxjQMfWtIWxHq/OTH9JwjH+1F+9J8OkNBorqe1ek8HDx3w1jHn8 T3OPOTz8IE0pdLiTNUa45QkGdMspguRn7T+pDGSdVqg+6a+mhtjsmYxufK3dzvJSLyhO/q63GuS IrxFEAD7YoWuN7PqReHLC//3s X-Google-Smtp-Source: AGHT+IHpLn6aCPnOPWyRWC4lX3V76l2fWHzGHcZP/K3tw1wy0XjyFByxeww30mlPPfNzoaWZ+4XQ7Q== X-Received: by 2002:a17:906:390e:b0:acf:15d:2385 with SMTP id a640c23a62f3a-ae0be84ee1amr611692566b.16.1750931966229; Thu, 26 Jun 2025 02:59:26 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:25 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 07/10] crypto: sun8i-ce - pass task descriptor to cipher prepare/unprepare Date: Thu, 26 Jun 2025 12:58:10 +0300 Message-ID: <20250626095813.83963-8-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Rework sun8i_ce_cipher_prepare() and sun8i_ce_cipher_unprepare() to take a task descriptor pointer as a parameter. Move common flow setup code to sun8i_ce_cipher_do_one() and also remove the crypto_engine parameter, as it was not used anyway. Signed-off-by: Ovidiu Panait --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 5fdb6a986b1f..d206b4fb5084 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -131,21 +131,19 @@ static int sun8i_ce_cipher_fallback(struct skcipher_request *areq) return err; } -static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req) +static int sun8i_ce_cipher_prepare(struct skcipher_request *areq, + struct ce_task *cet) { - struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); struct sun8i_ce_dev *ce = op->ce; struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(areq); struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct sun8i_ce_alg_template *algt; - struct sun8i_ce_flow *chan; - struct ce_task *cet; struct scatterlist *sg; unsigned int todo, len, offset, ivsize; u32 common, sym; - int flow, i; + int i; int nr_sgs = 0; int nr_sgd = 0; int err = 0; @@ -163,14 +161,9 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) algt->stat_req++; - flow = rctx->flow; - - chan = &ce->chanlist[flow]; - - cet = chan->tl; memset(cet, 0, sizeof(struct ce_task)); - cet->t_id = cpu_to_le32(flow); + cet->t_id = cpu_to_le32(rctx->flow); common = ce->variant->alg_cipher[algt->ce_algo_id]; common |= rctx->op_dir | CE_COMM_INT; cet->t_common_ctl = cpu_to_le32(common); @@ -314,24 +307,17 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req return err; } -static void sun8i_ce_cipher_unprepare(struct crypto_engine *engine, - void *async_req) +static void sun8i_ce_cipher_unprepare(struct skcipher_request *areq, + struct ce_task *cet) { - struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); struct sun8i_ce_dev *ce = op->ce; struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(areq); - struct sun8i_ce_flow *chan; - struct ce_task *cet; unsigned int ivsize, offset; int nr_sgs = rctx->nr_sgs; int nr_sgd = rctx->nr_sgd; - int flow; - flow = rctx->flow; - chan = &ce->chanlist[flow]; - cet = chan->tl; ivsize = crypto_skcipher_ivsize(tfm); if (areq->src == areq->dst) { @@ -362,20 +348,25 @@ static void sun8i_ce_cipher_unprepare(struct crypto_engine *engine, int sun8i_ce_cipher_do_one(struct crypto_engine *engine, void *areq) { - struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(areq); struct skcipher_request *req = skcipher_request_cast(areq); + struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(req); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct sun8i_cipher_tfm_ctx *ctx = crypto_skcipher_ctx(tfm); struct sun8i_ce_dev *ce = ctx->ce; + struct sun8i_ce_flow *chan; + struct ce_task *cet; int err; - err = sun8i_ce_cipher_prepare(engine, areq); + chan = &ce->chanlist[rctx->flow]; + cet = chan->tl; + + err = sun8i_ce_cipher_prepare(req, cet); if (err) return err; err = sun8i_ce_run_task(ce, rctx->flow, crypto_tfm_alg_name(req->base.tfm)); - sun8i_ce_cipher_unprepare(engine, areq); + sun8i_ce_cipher_unprepare(req, cet); local_bh_disable(); crypto_finalize_skcipher_request(engine, req, err); From patchwork Thu Jun 26 09:58:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1523 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 777372D97BC for ; Thu, 26 Jun 2025 09:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931971; cv=none; b=GXVly7bcX52CNpuwaY4sfJCJFDJ2p2I1THvakfTFuFB78GAGK4mObf0sb8Wy3Kc8LJ/4GkrZ2Yw1JsTmPuDJsuDGyK6IUMeHoBSXcT8kZUJJpzv9QXXzAqhSik1ZiVaF7VwNJcwuK6xa9DBu64s3l4JtRnijZYCx8xvNb3OJVG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931971; c=relaxed/simple; bh=SV17SgqAFM/CwgJKb43KYYELjIo00ELjwm2XuaeiHoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kT2dur1UI8gOgDPTW/hEzKlTaa32DYQRzk0XpfOX6MHK5stzpDp8a9VKKYvr+U9hFrHggqQjqrf2pVV71oO2dZJjJ4ySFTQgY1FzyE17Pa8PsA2ftK9zrhUpPc1L9JtqpRRnc1nFR5HmMS0kFGewoq6kQoQlUqBcKVIassBAqLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZX2zs+Vs; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZX2zs+Vs" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-ae0e0271d82so22473766b.3 for ; Thu, 26 Jun 2025 02:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931968; x=1751536768; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TntJfTNuRfw8H9ywL1n4IQi1UH/CB2DPSoGeEkzsKwc=; b=ZX2zs+VsN+dojHTTeVGcNTw23aqk5wHpHIHUAnTBruE1T7iziiwRn0Cwk3oeQeCXEy ukXcmlySYT7dRpRZIvm9kRUo1Ra1GzJWz62gEv3XRig8uWftI5J/BLB4+cNiq+t1mXQj 9hUDLxRN7DZgjBST8DibkmQy+/oZJinaORf1ufcx2qr+xlOgjOV4NYzXhr2AR9URqEhu 7SZb0Zm9OKjxQ6pyAZA38Eq6UH1tK94qkw9HzDr0JR0eat5rhSXpWL8U8MfsnxMtuWR4 k9kN3H8XxDIz7CgLfPaN5TMNeASMOGfyOMByQjbjRCS/5EZg/kBYhnKe7cyNMpdJBhTa h7fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931968; x=1751536768; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TntJfTNuRfw8H9ywL1n4IQi1UH/CB2DPSoGeEkzsKwc=; b=M/VYbAGOvq9auNLLEIhpzwPyLUQEuBIh3B6tWfjjhTo7bJUT41HhUvQyYfQoFXul4N e9hy1kDi+M1FHEE4CIibM7iLrB9f9HjEAofJAH+jMI/mVUsl5atdYKu6weZZofMbx0as Z7kfkk5gvLBS8E/KXuHdOvYEea4aWN884/fWH/Tyb7VA2ICCw1aMUq3tLyv4rAa18qZj pl1EnZ9xIlIrHaUrFDPSa+JejJpBMaR0LbZGUN+jgkIa/Ezk45lvdlDUrPm4YHVjzl2+ c0GmZBoVVaQbhVSQv+slrdEZe8VlEN6+/Sw+8hHzbdSGdsPvHn39xsLo6HmmhGhPybOV C/GQ== X-Forwarded-Encrypted: i=1; AJvYcCVzJfGRPQwdYtDuz5nq4+FF5793roiRFC7np91CTj54OioaNzHqzCFaUuzy2wC/vAQtYIG+z7Zjh0CWSg==@lists.linux.dev X-Gm-Message-State: AOJu0YyzuenHCcsgrGpoZ9PRAk6JlsrTVqzy5/Haz7h4sj1uMZSs1tCg 1N9H/fs//xADSJi8q5BBpOMClh1f7zVsKErDtiunAd8SF6SJ/R3R3LXN X-Gm-Gg: ASbGncu5AFDCBQd8JdU4IM2dqq5/UPP1wHhSL3oXDcebFnA22h8FDsRGuMi+sUTVr3p joYws7IiSpz+PwWNcC9I6AUkIX+lVjFg86nUhtjcoTRlPEHhHND54xwjgBRP/b/rgefcwUfv2mG waGvqeu6lEmxpOd6YkgrT+JbWSuEgpwCFRd9NqijyDv8sbnZAdE5trgAZVWxK49O39ikLVEFGrB cX2+0VNSovM4SMsTWsDJF2YRsB8OMHNLJrJ8O+dGgiWQe5QX7yl9okRYbN0mWiwQ+plk3TF2wpl kktt++nRVUpJ82JWId5N/1h7vVvg072iiLhtI1T0qacxwok1RrQJo6oh6KJol2jam5Is20A8v9k S1J/5cFulm/+rlA== X-Google-Smtp-Source: AGHT+IFyb5bPq7coEij2ylBbwkujWU2PveIvkYkjw2FajzUHkMcuMAgQb7EBUOsbFoZBWzMPaDgZYA== X-Received: by 2002:a17:906:7308:b0:ade:9fb:b07d with SMTP id a640c23a62f3a-ae0be7fe523mr687847466b.4.1750931967528; Thu, 26 Jun 2025 02:59:27 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:27 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 08/10] crypto: sun8i-ce - factor out public versions of finalize request Date: Thu, 26 Jun 2025 12:58:11 +0300 Message-ID: <20250626095813.83963-9-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Factor out hash and cipher finalize routines so that they can be used in the next commits during do_batch_requests() callback. Signed-off-by: Ovidiu Panait --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 23 ++++++++++--- .../crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 33 ++++++++++++++----- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 26 +++++++++++++++ 3 files changed, 69 insertions(+), 13 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index d206b4fb5084..22b1fe72aa71 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -346,6 +346,24 @@ static void sun8i_ce_cipher_unprepare(struct skcipher_request *areq, dma_unmap_single(ce->dev, rctx->addr_key, op->keylen, DMA_TO_DEVICE); } +void sun8i_ce_cipher_finalize_req(struct crypto_async_request *async_req, + struct ce_task *cet, int err) +{ + struct skcipher_request *req = skcipher_request_cast(async_req); + struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(req); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); + struct sun8i_cipher_tfm_ctx *ctx = crypto_skcipher_ctx(tfm); + struct sun8i_ce_flow *chan; + + chan = &ctx->ce->chanlist[rctx->flow]; + + sun8i_ce_cipher_unprepare(req, cet); + + local_bh_disable(); + crypto_finalize_skcipher_request(chan->engine, req, err); + local_bh_enable(); +} + int sun8i_ce_cipher_do_one(struct crypto_engine *engine, void *areq) { struct skcipher_request *req = skcipher_request_cast(areq); @@ -366,11 +384,8 @@ int sun8i_ce_cipher_do_one(struct crypto_engine *engine, void *areq) err = sun8i_ce_run_task(ce, rctx->flow, crypto_tfm_alg_name(req->base.tfm)); - sun8i_ce_cipher_unprepare(req, cet); - local_bh_disable(); - crypto_finalize_skcipher_request(engine, req, err); - local_bh_enable(); + sun8i_ce_cipher_finalize_req(areq, cet, err); return 0; } diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c index 7811fa17388c..5d8ac1394c0c 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c @@ -453,6 +453,29 @@ static void sun8i_ce_hash_unprepare(struct ahash_request *areq, dma_unmap_sg(ce->dev, areq->src, rctx->nr_sgs, DMA_TO_DEVICE); } +void sun8i_ce_hash_finalize_req(struct crypto_async_request *async_req, + struct ce_task *cet, + int err) +{ + struct ahash_request *areq = ahash_request_cast(async_req); + struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); + struct sun8i_ce_hash_tfm_ctx *ctx = crypto_ahash_ctx(tfm); + struct sun8i_ce_flow *chan; + + chan = &ctx->ce->chanlist[rctx->flow]; + + sun8i_ce_hash_unprepare(areq, cet); + + if (!err) + memcpy(areq->result, rctx->result, + crypto_ahash_digestsize(tfm)); + + local_bh_disable(); + crypto_finalize_hash_request(chan->engine, areq, err); + local_bh_enable(); +} + int sun8i_ce_hash_run(struct crypto_engine *engine, void *async_req) { struct ahash_request *areq = ahash_request_cast(async_req); @@ -473,15 +496,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *async_req) err = sun8i_ce_run_task(ce, rctx->flow, crypto_ahash_alg_name(tfm)); - sun8i_ce_hash_unprepare(areq, cet); - - if (!err) - memcpy(areq->result, rctx->result, - crypto_ahash_digestsize(tfm)); - - local_bh_disable(); - crypto_finalize_hash_request(engine, async_req, err); - local_bh_enable(); + sun8i_ce_hash_finalize_req(async_req, cet, err); return 0; } diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 90b955787d37..1022fd590256 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -383,6 +383,19 @@ int sun8i_ce_cipher_do_one(struct crypto_engine *engine, void *areq); int sun8i_ce_skdecrypt(struct skcipher_request *areq); int sun8i_ce_skencrypt(struct skcipher_request *areq); +/** + * sun8i_ce_cipher_finalize_req - finalize cipher request + * @async_req: request to be finalized + * @cet: task descriptor associated with @async_req + * @err: error code indicating if request was executed successfully + * + * This function does the final cleanups for request @async_req and + * finalizes the request. + */ +void sun8i_ce_cipher_finalize_req(struct crypto_async_request *async_req, + struct ce_task *cet, + int err); + int sun8i_ce_get_engine_number(struct sun8i_ce_dev *ce); int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name); @@ -398,6 +411,19 @@ int sun8i_ce_hash_finup(struct ahash_request *areq); int sun8i_ce_hash_digest(struct ahash_request *areq); int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq); +/** + * sun8i_ce_hash_finalize_req - finalize hash request + * @async_req: request to be finalized + * @cet: task descriptor associated with @async_req + * @err: error code indicating if request was executed successfully + * + * This function does the final cleanups for request @async_req and + * finalizes the request. + */ +void sun8i_ce_hash_finalize_req(struct crypto_async_request *async_req, + struct ce_task *cet, + int err); + int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src, unsigned int slen, u8 *dst, unsigned int dlen); int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed, unsigned int slen); From patchwork Thu Jun 26 09:58:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1522 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B646F2C08CF for ; Thu, 26 Jun 2025 09:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931972; cv=none; b=RR2aob4NgHdatBu6rPx+hnZLkotZayKF985njXAlekeotjwubFDzqxd2v91mQgY5pLtoylxPzgB2ksa1q+rfz5BWNKLiOENUXOIVFXJEAWNDskn1zPI7nWbR+LfNQYyzevSy45BCDZH15LzZpl2bm1wiwaWm9P8Bo9+B1akA6fU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931972; c=relaxed/simple; bh=dsS+p6UvQk8Xwg+WgyOGAas3d5MTBbJN2FAK8gI6CFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RRpgfo9AVBQZuhldoDKNbHA7ugCMdA/Fm/N6cO3AhCCQe40/MREUH0UbjpatBPg8L5l3chx6xgj/6xQbYIzY91YANDr7N5wpP/fdDDK58KkwazQDyFHwFUY/QI0GJifR9P41UcCHv1don6M51POeZH3NwhL3ottn6npINlK1ybQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d+R0VjOF; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d+R0VjOF" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-ae0a0cd709bso379053766b.0 for ; Thu, 26 Jun 2025 02:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931969; x=1751536769; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=579Q1QhHC2sKl8ad1uJdu4XVU+r2uSj185NnGxhlUu0=; b=d+R0VjOFSCwp2tiJCK/TuMHlAcW6qaW5OD0x6ImlObN+Vpj8JEsfeiD5VPjePSjctX Vhy0wlG0gKqkONahGEgDG2vNi1rjWvG8HMnM9iqYce+8RBuUT1BGyJFuRgezQJoPc9FX x3lHC3fNx8CLJ72K3PmD0iDuYMIeBLPTubXGx6eKBtBaX4gGiTF3xk4OyO4wNNDRwBvZ RAxr497PekE7p405osCS6kNA03EIyFVt8r3vzNKVz2NwniuxGw4/hrXReYz9fQvhRx2E mdQzgbYiPifM3DXO7X0yPHpGQsKitMencmOz9xvGmf9JSS5E5Ep24Uc6yo7spDZnMOVZ nBCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931969; x=1751536769; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=579Q1QhHC2sKl8ad1uJdu4XVU+r2uSj185NnGxhlUu0=; b=iI1rmQ5bkiHso+9/XUluVc7k2dNA1q/ES33UlTSu5v2cPU+GKRLbPnmsdl+FOYXvWx iHHSQFAhOw//VFfi8thOu8QWI4MUSyRa5rIZKiR1YB5D3VAXfsgYbeRmlNGMeLjg4ur4 35w4zQJ4NuQSzTGLjfY3vFLwoAmjRue6FEfrVOHYALTIOuGiRZHQQWKH0VhR9HvZGqho qfYILn8u42AsFVfc+DkV3vETfLNY3dpef3b5/89PSWD7XIcYeQ7Bc7/hWmgWzyaJgiIh YkudqD/IV3x+x6k4OTCKcy3NgGOFL2dF6umN9WkZB0glwHx6RhpmKDf5zfQLZiHqcU+d 3tpQ== X-Forwarded-Encrypted: i=1; AJvYcCWBtaQI8UBC4mGH6cwbeyk+71KDIWnszkhtATzbxBYUMzcAaQSmTe20Zvw+dnpUKU5dZCuZoFLvPe1RHQ==@lists.linux.dev X-Gm-Message-State: AOJu0YyUqJX29zSMmaP5ZfoMOGKO/1Pdks1SatVyao5SRUmSUiplFi8z bPQju4xpWEiwR4ry4Vi2NVB113Y9w5XvwBXQjYiUMmtHSa8CmDJtA69N X-Gm-Gg: ASbGncuT1yInAIH15+EadG3Qw3S5Ugh00tM/NDHipipTMuNghDYjzVOZqEZMglQNm5y s6IViA7bh4SHV1JBSDTbftTmVuaAYeTRONe0m2q6l/9vv9vce3PzxkObIU0mcvSPW8PmqBvlWp2 deY1QJpAEOMNpctR0/3O7fTyCN4NJ15mvoPMGt1U3HAAuVqTSyLyfmJsB5j7Sgp0gzf+29eEJeY EjFN/l9bdHvk+K0mjD0516zXKKWvtpN7rymUiw9MXjYP6orfoDKAVLWLV1/IzouFsfAc6Zv2JYP 2m+bNTNNYhAZdfgJG79vzGKKNJPwvFPZdzMudYKftGcBcuZiZ/+ym7YZ7AFmURxvfNxbl9C6o2P XQoWZLG48h8t6Jw== X-Google-Smtp-Source: AGHT+IGVv+Hw7jSjoixa1/E7zQmSwh1p6WVQXmOD2Loe5VSlhlnuizOR3ugGTm+11YiJ3z+bTMozvg== X-Received: by 2002:a17:906:d553:b0:ae0:c4e3:e2e8 with SMTP id a640c23a62f3a-ae0d26f80f4mr322465866b.28.1750931968753; Thu, 26 Jun 2025 02:59:28 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:28 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 09/10] crypto: sun8i-ce - add a new function for dumping task descriptors Date: Thu, 26 Jun 2025 12:58:12 +0300 Message-ID: <20250626095813.83963-10-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O In order to remove code duplication, factor out task descriptor dumping to a new function sun8i_ce_dump_task_descriptors(). Signed-off-by: Ovidiu Panait --- .../crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index 930a6579d853..b6cfc6758a5a 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -169,6 +169,12 @@ static const struct ce_variant ce_r40_variant = { .trng = CE_ID_NOTSUPP, }; +static void sun8i_ce_dump_task_descriptors(struct sun8i_ce_flow *chan) +{ + print_hex_dump(KERN_INFO, "TASK: ", DUMP_PREFIX_NONE, 16, 4, + chan->tl, sizeof(struct ce_task), false); +} + /* * sun8i_ce_get_engine_number() get the next channel slot * This is a simple round-robin way of getting the next channel @@ -183,7 +189,6 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) { u32 v; int err = 0; - struct ce_task *cet = ce->chanlist[flow].tl; #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG ce->chanlist[flow].stat_req++; @@ -225,9 +230,8 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) /* Sadly, the error bit is not per flow */ if (v) { dev_err(ce->dev, "CE ERROR: %x for flow %x\n", v, flow); + sun8i_ce_dump_task_descriptors(&ce->chanlist[flow]); err = -EFAULT; - print_hex_dump(KERN_INFO, "TASK: ", DUMP_PREFIX_NONE, 16, 4, - cet, sizeof(struct ce_task), false); } if (v & CE_ERR_ALGO_NOTSUP) dev_err(ce->dev, "CE ERROR: algorithm not supported\n"); @@ -244,9 +248,8 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) v &= 0xF; if (v) { dev_err(ce->dev, "CE ERROR: %x for flow %x\n", v, flow); + sun8i_ce_dump_task_descriptors(&ce->chanlist[flow]); err = -EFAULT; - print_hex_dump(KERN_INFO, "TASK: ", DUMP_PREFIX_NONE, 16, 4, - cet, sizeof(struct ce_task), false); } if (v & CE_ERR_ALGO_NOTSUP) dev_err(ce->dev, "CE ERROR: algorithm not supported\n"); @@ -260,9 +263,8 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) v &= 0xFF; if (v) { dev_err(ce->dev, "CE ERROR: %x for flow %x\n", v, flow); + sun8i_ce_dump_task_descriptors(&ce->chanlist[flow]); err = -EFAULT; - print_hex_dump(KERN_INFO, "TASK: ", DUMP_PREFIX_NONE, 16, 4, - cet, sizeof(struct ce_task), false); } if (v & CE_ERR_ALGO_NOTSUP) dev_err(ce->dev, "CE ERROR: algorithm not supported\n"); From patchwork Thu Jun 26 09:58:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1521 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEF1F2DBF73 for ; Thu, 26 Jun 2025 09:59:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931973; cv=none; b=BMhzQcn4Au5O1DotP49H7tAlMpFFZy0aN5SWgUp4jQ1atm4L/tzC/udOMKYW/1d5sO5Eih5xl0qeZXtyI+8EK+Kz8d3/YX4vmmQwYa0GKRquLqOvJJDQ2Vmi1bjR3KmnU9bWgf/f97PnXYwYn3BBgC0HWwh99YhRUkwtzB5xsHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750931973; c=relaxed/simple; bh=tbTFzNCpLJSVFhQmpoJbNfx1TQTTaya8gz6bH1S/uso=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fC005zxkHhqNCfpdz1n+pPQNxs45oKuctTWSwsTRj/lh3RLOqnC+qk4VxuGe0iIE4ysKV1NCmXowX+2oU2Ne2SxcoHQboNUs6hQzTFTazp5GWFhAXF6RqisythWFdFr6yUl1xQuCS2OQfPYOKm/Oe+R+ypuXKo7t3xNK1qhzx2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=N9h+dBUO; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N9h+dBUO" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-ae0d758c3a2so95895566b.2 for ; Thu, 26 Jun 2025 02:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750931970; x=1751536770; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P/fE/0yl8M/v8XV3CKxXJaDNwhg5S07FYLicaloeOKU=; b=N9h+dBUO/aF/jRL7B9U9YfIutjxD79nw8ZT6q4k2JR6qoS4ZKe5sFpB2OhHpVHa/Ed 2v77fG5wOqt0VHjG05bG3JJU7OTh0QII8hp6pDx07TO8hH2jOshKjinxoHkp5f3D5pTk 3OdifdBLVlY8r1nqxG4RS/zW3/ArJ4cDZVkRYI3obIidzhe2W7sEu+hsPtN0XdCG9rX/ jGLaU6DTXqCohbll5/u6Jz9T4scRSZCIknjGn/H2vfJQZ1VrZPLouWBZKanYgtkxLApC yzRXODrRUSnrLzJ35vdWATeRVqFOXSKNm1cLNZUS5dgenxlKY2GjJbatHBXM0GAQjhEu ymGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750931970; x=1751536770; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P/fE/0yl8M/v8XV3CKxXJaDNwhg5S07FYLicaloeOKU=; b=H7jQGkw+n4WNgWRrCweu/poXpNw/Za7O5Hj9MLIKPT8uBJ/3sa7yqq9M/e20jetRuj tviTAMR1Vt+42LnA1fe+kNLeJ8OQk0jbz1J7vNoDbyGoSxh7nU4kwAkUpuHC8TZ9un2J q0Iz/DYty5jtNuZo9R8yQ78/6gcU+bEEHo8Bj2/5i1MfMYwX0T35UcBD/IniPeFfyO6T pgrD3qw4+qq4rALJCXElP9onnVc8qkJ1H4XMLFiw8gL3iILI3TRz8cLRowFdwawrnWBj JEOsDB4Jpzvo4pQ+EIJjopvFX9yMSBvgeQGf92dtvD1b9Tb/MIiVCpVdzg44uIX3yuCA dcSw== X-Forwarded-Encrypted: i=1; AJvYcCVfF4/assRMD+Su7fXMsIisi/0ZsTlLORfQBBTiEcdJyGGqmo+lHdBnZsX+kqIcgE0vTKf1rdgtkVHOnA==@lists.linux.dev X-Gm-Message-State: AOJu0Yzj188OsWhUtHbl8x3vikoKtKMg3TIwl64ZcpzT+Dg5JOLNz0tl 2OIfFn8X4IunUIQjHNqPoKLcb52oCHnl2zR5gkE4fFXd606P/67RxQ5x X-Gm-Gg: ASbGncv1UoxF27qt+oYveagUp4F37eKo3WX29dpiPYFELIENBad3wkLgaP30U5ZdiXm cqcNv1wHysBCn0VX2g0sz0knz8iqESNAYPfK+UKlW42vYCdZbDwO7HqwHvGfiRHJejdnyM+UaCx 3LRhwhHX3l2aYNP7ot66JpBEv8/zadebIYWxxMoA0sdeoIplOEcD8J/kBtKipyi0mvXN+ZfOfR/ 9ea9vh9O+XxGQepqYsP6c8iPrxUPV1oMm4HB+HOPJjmoXzfGgmvUURr6VWV9BL3ss077/v6YjY3 /H3Am5oPnw131zkmu1TalFqWQz7FXXDT/Jd9LMudBkNfCozJwmqE642m2xZ/ZAj1Nu7oMo/HfqJ tAOD1dsBb2fs90g== X-Google-Smtp-Source: AGHT+IEPjb/8uofV4csnmULxi9nDFlRA8uvr4c7ZG+YY8cHUXk7++SxrX5pnt1HPos1h1UHIsCu5pg== X-Received: by 2002:a17:907:9615:b0:ad5:3055:784d with SMTP id a640c23a62f3a-ae0d0ccbe63mr317427366b.34.1750931970075; Thu, 26 Jun 2025 02:59:30 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae06aa5ff34sm1014106166b.40.2025.06.26.02.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jun 2025 02:59:29 -0700 (PDT) From: Ovidiu Panait To: clabbe.montjoie@gmail.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ovidiu Panait Subject: [PATCH v2 10/10] crypto: sun8i-ce - implement request batching Date: Thu, 26 Jun 2025 12:58:13 +0300 Message-ID: <20250626095813.83963-11-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> References: <20250626095813.83963-1-ovidiu.panait.oss@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O The Allwinner crypto engine can process multiple requests at a time, if they are chained together using the task descriptor's 'next' field. Having multiple requests processed in one go can reduce the number of interrupts generated and also improve throughput. This commit introduces batching support in the sun8i-ce driver by enabling the retry mechanism in the crypto_engine and implementing the do_batch_requests() callback. Only requests of the same type (hash, skcipher, etc) are batched together, as the hardware doesn't seem to support processing multiple types of requests in the same batch. The existing do_one_request() handlers are adjusted to only fill a per-flow queue and set up the dma mappings. Once the queue is full or a different kind of request is received, -ENOSPC is returned to signal the crypto engine that the batch is ready to be processed. Next, do_batch_requests() chains the requests, sets the interrupt flag, sends the batch to hardware for processing and performs the cleanup. With request batching, the tcrypt multibuffer benchmark shows an increase in throughput of ~85% for 16 byte AES blocks (when testing with 8 data streams on the OrangePi Zero2 board). Signed-off-by: Ovidiu Panait --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 15 +-- .../crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 123 ++++++++++++++++-- .../crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 13 +- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 31 +++++ 4 files changed, 155 insertions(+), 27 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 22b1fe72aa71..5a3fd5848fd1 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -165,7 +165,7 @@ static int sun8i_ce_cipher_prepare(struct skcipher_request *areq, cet->t_id = cpu_to_le32(rctx->flow); common = ce->variant->alg_cipher[algt->ce_algo_id]; - common |= rctx->op_dir | CE_COMM_INT; + common |= rctx->op_dir; cet->t_common_ctl = cpu_to_le32(common); /* CTS and recent CE (H6) need length in bytes, in word otherwise */ if (ce->variant->cipher_t_dlen_in_bytes) @@ -376,16 +376,15 @@ int sun8i_ce_cipher_do_one(struct crypto_engine *engine, void *areq) int err; chan = &ce->chanlist[rctx->flow]; - cet = chan->tl; + cet = sun8i_ce_enqueue_one(chan, areq); + if (IS_ERR(cet)) + return PTR_ERR(cet); err = sun8i_ce_cipher_prepare(req, cet); - if (err) + if (err) { + sun8i_ce_dequeue_one(chan); return err; - - err = sun8i_ce_run_task(ce, rctx->flow, - crypto_tfm_alg_name(req->base.tfm)); - - sun8i_ce_cipher_finalize_req(areq, cet, err); + } return 0; } diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index b6cfc6758a5a..a2addc9f64d9 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -10,7 +10,7 @@ * You could find a link for the datasheet in Documentation/arch/arm/sunxi.rst */ -#include +#include #include #include #include @@ -171,8 +171,14 @@ static const struct ce_variant ce_r40_variant = { static void sun8i_ce_dump_task_descriptors(struct sun8i_ce_flow *chan) { - print_hex_dump(KERN_INFO, "TASK: ", DUMP_PREFIX_NONE, 16, 4, - chan->tl, sizeof(struct ce_task), false); + for (int i = 0; i < chan->reqs_no; ++i) { + struct ce_task *cet = &chan->tl[i]; + char task[CE_MAX_TASK_DESCR_DUMP_MSG_SIZE]; + + snprintf(task, sizeof(task), "TASK %d:", i); + print_hex_dump(KERN_INFO, task, DUMP_PREFIX_NONE, 16, 4, + cet, sizeof(struct ce_task), false); + } } /* @@ -190,10 +196,6 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) u32 v; int err = 0; -#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG - ce->chanlist[flow].stat_req++; -#endif - mutex_lock(&ce->mlock); v = readl(ce->base + CE_ICR); @@ -710,12 +712,107 @@ static int sun8i_ce_debugfs_show(struct seq_file *seq, void *v) DEFINE_SHOW_ATTRIBUTE(sun8i_ce_debugfs); +static int sun8i_ce_get_flow_from_engine(struct sun8i_ce_dev *ce, + struct crypto_engine *engine) +{ + for (int i = 0; i < MAXFLOW; ++i) + if (ce->chanlist[i].engine == engine) + return i; + + return -ENODEV; +} + +static int sun8i_ce_do_batch(struct crypto_engine *engine) +{ + struct sun8i_ce_dev *ce; + struct sun8i_ce_flow *chan; + int err, flow; + + ce = dev_get_drvdata(engine->dev); + flow = sun8i_ce_get_flow_from_engine(ce, engine); + if (flow < 0) + return flow; + + chan = &ce->chanlist[flow]; + + if (!chan->reqs_no) + return 0; + +#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG + ce->chanlist[flow].stat_req += chan->reqs_no; +#endif + + for (int i = 0; i < chan->reqs_no - 1; ++i) { + struct ce_task *task = &chan->tl[i]; + dma_addr_t next = chan->t_phy + (i + 1) * sizeof(struct ce_task); + + task->next = desc_addr_val_le32(ce, next); + } + chan->tl[chan->reqs_no - 1].next = 0; + chan->tl[chan->reqs_no - 1].t_common_ctl |= cpu_to_le32(CE_COMM_INT); + + err = sun8i_ce_run_task(ce, flow, "BATCH"); + + for (int i = 0; i < chan->reqs_no; ++i) { + struct crypto_async_request *areq = chan->reqs[i]; + u32 req_type = crypto_tfm_alg_type(areq->tfm); + + if (req_type == CRYPTO_ALG_TYPE_SKCIPHER) + sun8i_ce_cipher_finalize_req(areq, &chan->tl[i], err); + + if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_HASH) && + (req_type == CRYPTO_ALG_TYPE_AHASH)) + sun8i_ce_hash_finalize_req(areq, &chan->tl[i], err); + + chan->reqs[i] = NULL; + } + + chan->reqs_no = 0; + + return err; +} + +struct ce_task *sun8i_ce_enqueue_one(struct sun8i_ce_flow *chan, + struct crypto_async_request *areq) +{ + struct ce_task *cet; + struct crypto_async_request *prev; + u32 alg_type, prev_alg_type; + + if (chan->reqs_no == CE_MAX_REQS_PER_BATCH) + return ERR_PTR(-ENOSPC); + + if (chan->reqs_no) { + prev = chan->reqs[chan->reqs_no - 1]; + prev_alg_type = crypto_tfm_alg_type(prev->tfm); + alg_type = crypto_tfm_alg_type(areq->tfm); + + if (alg_type != prev_alg_type) + return ERR_PTR(-ENOSPC); + } + + cet = chan->tl + chan->reqs_no; + chan->reqs[chan->reqs_no] = areq; + chan->reqs_no++; + + return cet; +} + +void sun8i_ce_dequeue_one(struct sun8i_ce_flow *chan) +{ + if (chan->reqs_no) { + chan->reqs_no--; + chan->reqs[chan->reqs_no] = NULL; + } +} + static void sun8i_ce_free_chanlist(struct sun8i_ce_dev *ce, int i) { while (i >= 0) { crypto_engine_exit(ce->chanlist[i].engine); if (ce->chanlist[i].tl) - dma_free_coherent(ce->dev, sizeof(struct ce_task), + dma_free_coherent(ce->dev, + CE_DMA_TASK_DESCR_ALLOC_SIZE, ce->chanlist[i].tl, ce->chanlist[i].t_phy); i--; @@ -737,7 +834,9 @@ static int sun8i_ce_allocate_chanlist(struct sun8i_ce_dev *ce) for (i = 0; i < MAXFLOW; i++) { init_completion(&ce->chanlist[i].complete); - ce->chanlist[i].engine = crypto_engine_alloc_init(ce->dev, true); + ce->chanlist[i].engine = crypto_engine_alloc_init_and_set( + ce->dev, true, sun8i_ce_do_batch, true, + CE_MAX_REQS_PER_BATCH); if (!ce->chanlist[i].engine) { dev_err(ce->dev, "Cannot allocate engine\n"); i--; @@ -750,9 +849,9 @@ static int sun8i_ce_allocate_chanlist(struct sun8i_ce_dev *ce) goto error_engine; } ce->chanlist[i].tl = dma_alloc_coherent(ce->dev, - sizeof(struct ce_task), - &ce->chanlist[i].t_phy, - GFP_KERNEL); + CE_DMA_TASK_DESCR_ALLOC_SIZE, + &ce->chanlist[i].t_phy, + GFP_KERNEL); if (!ce->chanlist[i].tl) { dev_err(ce->dev, "Cannot get DMA memory for task %d\n", i); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c index 5d8ac1394c0c..73cfcdb2b951 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c @@ -350,7 +350,6 @@ static int sun8i_ce_hash_prepare(struct ahash_request *areq, struct ce_task *cet cet->t_id = cpu_to_le32(rctx->flow); common = ce->variant->alg_hash[algt->ce_algo_id]; - common |= CE_COMM_INT; cet->t_common_ctl = cpu_to_le32(common); cet->t_sym_ctl = 0; @@ -488,15 +487,15 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *async_req) int err; chan = &ce->chanlist[rctx->flow]; - cet = chan->tl; + cet = sun8i_ce_enqueue_one(chan, async_req); + if (IS_ERR(cet)) + return PTR_ERR(cet); err = sun8i_ce_hash_prepare(areq, cet); - if (err) + if (err) { + sun8i_ce_dequeue_one(chan); return err; - - err = sun8i_ce_run_task(ce, rctx->flow, crypto_ahash_alg_name(tfm)); - - sun8i_ce_hash_finalize_req(async_req, cet, err); + } return 0; } diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 1022fd590256..53f31fff1a71 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -104,6 +104,10 @@ #define CE_DIE_ID_MASK 0x07 #define MAX_SG 8 +#define CE_MAX_REQS_PER_BATCH 10 +#define CE_MAX_TASK_DESCR_DUMP_MSG_SIZE 18 +#define CE_DMA_TASK_DESCR_ALLOC_SIZE \ + (CE_MAX_REQS_PER_BATCH * sizeof(struct ce_task)) #define CE_MAX_CLOCKS 4 #define CE_DMA_TIMEOUT_MS 3000 @@ -191,6 +195,8 @@ struct ce_task { * @status: set to 1 by interrupt if task is done * @t_phy: Physical address of task * @tl: pointer to the current ce_task for this flow + * @reqs: array of requests to be processed in batch + * @reqs_no: current number of requests in @reqs * @stat_req: number of request done by this flow */ struct sun8i_ce_flow { @@ -199,6 +205,8 @@ struct sun8i_ce_flow { int status; dma_addr_t t_phy; struct ce_task *tl; + struct crypto_async_request *reqs[CE_MAX_REQS_PER_BATCH]; + int reqs_no; #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG unsigned long stat_req; #endif @@ -373,6 +381,29 @@ struct sun8i_ce_alg_template { char fbname[CRYPTO_MAX_ALG_NAME]; }; +/** + * sun8i_ce_enqueue_one - add a request to the per-flow batch queue + * @chan: engine flow to enqueue the request + * @areq: request to be added to the batch queue + * + * This function adds request @areq to the batch queue in @chan. Should be + * called during do_one_request() crypto engine handler. + * + * @return - on success, task descriptor associated with the request + * - on failure, ERR_PTR(-ENOSPC) if the queue was full or if the + * request type is different from the requests already queued up + */ +struct ce_task *sun8i_ce_enqueue_one(struct sun8i_ce_flow *chan, + struct crypto_async_request *areq); + +/** + * sun8i_ce_dequeue_one - remove head request from the per-flow batch queue + * @chan: engine flow to remove the request from + * + * This function removes the head request from the batch queue in @chan. + */ +void sun8i_ce_dequeue_one(struct sun8i_ce_flow *chan); + int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen); int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,