From patchwork Thu Jun 19 12:23: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: 1615 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 C1AAB23B603 for ; Thu, 19 Jun 2025 12:24:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335855; cv=none; b=Rk7YmH4achnIeURm/UxnvjgYxqdQR+P7189LLvKi3PDk2V6PEC5060b8gsQp/hs1j6W6gMX7UiR6t+h7JG90e01xV89dFSxzFCutMyz+0gok/CF9Wc10dC24KDh+IUL38J621s//CP2kr4Z4+sYDYnKuf61rFRgUGzdmHSp4kTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335855; c=relaxed/simple; bh=V+HFJ3mcjgzB1Gr3bIDT3f6dj+Z5XsFbLbUNii2zGtc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PAAiOTNUGMe6TWlnB6ZZhajbHs7ZKnmTnAK/OeysvI88rHVrfh6kVk6VCbXkOSKucjT4hKoBCZ4Tbpw6xR9/jdqc8iVBGe3k08tl/zIWSbM1Vr8BHvv/Bmd+Whbg1HDwQaVmyQFUxJq7X8yUwOC5lCPjny4lvy97DZMvOh4xMsM= 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=X1CoKRnU; arc=none smtp.client-ip=209.85.218.42 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="X1CoKRnU" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-adfb562266cso132534866b.0 for ; Thu, 19 Jun 2025 05:24:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335852; x=1750940652; 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=X1CoKRnUd2Ga1gghtUq0qQ6/6WVPIFmOAEza78Qcu1O8IB+XjFVVXEX/mwY+qhLqvB TlZw9SUroAcqEAkjWQ6XlWV1ULUI/tDJuh0Fkr56dsyn2IgqesO2AfmAhS3xnWh9Jlyb nmLu//rUqkMuHOdiSF03o+dtTMDttFQMeRqyXbHEr4WKdxDKD4tnrSOiWfQ8+qJkN7QD KeNujkAKaNI0iTHaiqBKH8fvmE1WwP5bheUh5kALa9orqfyebHn4UUWugyApCYjlqK9M jN3GNstqKaVRWRyu/KQAUtbew4hBKeErCW5BhQQabrqhPM82mRand7tCyw9Qe9FVVvvq JcYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335852; x=1750940652; 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=VfsVYWb0sVcBn9S56DnDgZTKGqw5axq5C29QxD1s3D8kimU4G9W4iqYvjIL6jUjFAG 7SrhBBnqz2C+HPPUtrIHJI9HwUFOHK6MLw9OQpO9QGv2TF+EvNaLBKxl6Sk7/vJIvHpp i4tdjP60CyFA1huV7xI6tF5hAYhswx8B6UqTReDXaLjtIuME+kH1uz5a67o2dlZiOJAj 4Wi3f15GlcJqWmCn/Tjo/EwJMS1BR9eGjrSwVOO0uDxoK6ahvXvx/IPeb+6YfhA5JLNL Ppkz5yKZzKKPhFsAfGssUG4cY0bjZ6JGKDoN2ILG8ex0LOpm98KAs1/N6XhvwrBdWK3s Qsqw== X-Forwarded-Encrypted: i=1; AJvYcCW2N6Gl4dd8fg4h4tMKx75yfZyB2xEBEuhJArt6VL9rGLlJqwi6z91PrwkL07yg3n6NnXDlCdspOtOxww==@lists.linux.dev X-Gm-Message-State: AOJu0YwDK2TuzGHxLtCLLMAavaOW7JJty9VUbU8Aq8u0x0iytD77saY2 zuAM7XHrGkclbhP7NKSVguHKlRJJ3gCLHtMdLlBPugnaJKV+3+5miCQq X-Gm-Gg: ASbGncuPL7tER7QLqDVvAE3/cIcYGwrfs2i86vLfXr8S7/UeM4C1Fky5xFskJWlv/KS oayUOiPYOhNk2P0huExDov7Eijx7J9XOch2lXU7Eyt+D9rL17pc8oqMhD59fN5UQsuUsJ3WssJH qEb2j4Cb405Z+awYpRBGwaZEK9b1hdbVWeDOnk1Am7mZEipbJwmnG/nGSz+P3Fb/bk+qqiKPQBS lK4Vyu+0mDrI44BIWeHvUqmZ5jNNeU4cQEIoEicgoTZUh0az7bt0jBFUXpZgx2b6WoCzRhcXgcY Dh5cQt7Piv6Z2KZXmXoZRELXPqe1bIjqsbRsBlv3PF/R7bsTrFUQxTTX/BnKA9QbUVOd3phlXBD uUJU9ucrSWY/4NQ== X-Google-Smtp-Source: AGHT+IHxZ6KyDVZH+/AWtxZdICZOs1YlDPZ1ZpE6Nu/jpvdE/3Ii2DDUvVsNbEbPVhvCkr3A2LmzwA== X-Received: by 2002:a17:907:d86:b0:ad8:8d89:bbec with SMTP id a640c23a62f3a-adfad4123a2mr2149991966b.28.1750335851736; Thu, 19 Jun 2025 05:24:11 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24:11 -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 01/10] crypto: sun8i-ce - remove channel timeout field Date: Thu, 19 Jun 2025 15:23:07 +0300 Message-ID: <20250619122316.2587236-2-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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 19 12:23: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: 1614 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 BAAFF23E35B for ; Thu, 19 Jun 2025 12:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335856; cv=none; b=UvUNoKxecAKVoYhYC0s+IuxziPPwLnmW3lVnRjb8XbwwsptZivVFgTX/Go27yDlPBLQna/yMN3yAEWrPGm8ly6ex1prNhqcbvwrTCIT3jKIbZ1QZfSWLR50dIrg0F7hwWSJ0hJiVAF9gMMt2YU7H0qwG9mO4BLeb4PqUhMOcQ6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335856; c=relaxed/simple; bh=D3Fpyml+Pwh/ot9LUtEAJrW9x78rJDQPnjdfBz8Z7cI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=He/YaDgGg4z9K17mtADPHXwvRnGUwsYPyAdWPtYhRK9xxSJgzjgVcud3/7Pc7XfgQWQbkFaFCDuiIJ54ZXVRQh9X8xuwWQciRl92xOOE3Dlo1pz2anWM+wGfvMULA/XvCa86DzJaVL9IssnkjIRl/91yTqAtZCxsAtwwTjGu1d0= 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=nPVVQMUn; arc=none smtp.client-ip=209.85.218.54 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="nPVVQMUn" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-ade4679fba7so144139566b.2 for ; Thu, 19 Jun 2025 05:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335853; x=1750940653; 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=nPVVQMUnMdfYRFFcMlzPLUSbDGhbkizr7FnQJSEycOkWmgbV7A85n9CdQ14Q8/yBSd brpkek5Z9pCuGeJ652/jynDy4mD2OCVfzw4wareIfFJeEa33lJqKl1Nja7GTO8GLXrpH CrAJREkHLv3xe/9jrIaO6CtrjvjSNQ4SzRMp9WEss9d2mPkbQQ+Evl460Pb5X5ETEILV jwg6rGnjwhyQPsUxPI1P97zm81xz/COrS7tiC81LbNhp92HlMGT64p198jvXvjDn9H+F nkTOzkmMC37d8v8X9nR0icrEJwfbXVEfFgE6pUWiuub2WpAmHXx3qv7S0uqeJ6etGfjH f7gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335853; x=1750940653; 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=AmDvyMM5DgtrwnXp5n0NpLmwVEsNGdn0eXJ/CWIrTxgIo7quP5roS9IZ8lKQBwm93P hfKD3cnQ40LQGddA61SQUuR8w8+HTGJaawsgb9EwoVAfE2AdJL4c5whOK4/Q1C5c9bMt NZgDRI8qr48V/M+VQuwwWZumQ86BjYkp2nImljrqseYfVxiCWCBsGqiW4gpugBYOuIpS tmK5WB04RJ2McIksxGPDAGmtND7fkyqUFDc624ULbZT84IjNOv2ZUYSflvCZCu6fVmUS 0wmJPq6WRAVtv7UQBFxAqpQXxdLBe9OUXXJLYQ/S9ItIFBVm9E6TWu3TchbDb2+QkEOL S7jg== X-Forwarded-Encrypted: i=1; AJvYcCXMvjZb3ZRsLRARjzXFE2B8CbNm7LCBbMCLXrJi8qT/5nGRjbs4OYMY17zsKjBnAOhX/+kkS7nlUJelQg==@lists.linux.dev X-Gm-Message-State: AOJu0Yx4H0YSmQmG0m6Fh3puhwlvvOQ25wmp7OkHsOpyLAkDoXzINKly DeN5GK66wzcaedhTsjiUOJ9ykOHxWdSN+HN971Zcv5NGop1pKSb289b1 X-Gm-Gg: ASbGncsrEG7VeA2B5XdyCKE0xCkcKJBY3Ke/E98Su3C4WkpHO4re8wgS3AzIO3OOhAt UtIxUOvqEMAqYwU8XjAsAXbOOF/qMcn3/6rQbqFfp38HteJBe7hJkgtLlEaKxAJ6s9hFS3HmWDd 6OmaxPGQuSW3MM7CYg6XWHoT86NtEtFjM7hat+PA0uMR7UJ0COms7lolv0xLrm0d7k9OdujmTMt 6HsridECHerI1LzzVkBL8aAkO5B3K+Alxx7MnYRjYowtNwkNh6sM+M6snOFEUsLr+p6MlBYDlDr OtDN8OfO1n1WGNEGlwpUn40LzdXFVKEbacSA7bqWYwlJpQMXGEim1CcQSD2ejS4vlnQlIobcJmF TEs/zQbOgwu9/Uw== X-Google-Smtp-Source: AGHT+IFHuWqBozXH71wulrFP//Y6OM4S5v5aSjrSOQKgs/LL1p2at57xIwfuaUeDkpt3vFS1Udqh+Q== X-Received: by 2002:a17:907:3f1a:b0:ad8:8e56:3c5c with SMTP id a640c23a62f3a-adfad363d82mr1948037266b.11.1750335852861; Thu, 19 Jun 2025 05:24:12 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24:12 -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 02/10] crypto: sun8i-ce - remove boilerplate in sun8i_ce_hash_digest() Date: Thu, 19 Jun 2025 15:23:08 +0300 Message-ID: <20250619122316.2587236-3-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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 19 12:23: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: 1613 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 0BCDD2459E6 for ; Thu, 19 Jun 2025 12:24:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335857; cv=none; b=ShT+Z8a4GSNIV9N2I8Qzu9er6v6QLkPkCHTlsf+Pnxo3TtkbBkEyVp4Kd/+ZgwkzSb4stkZLcylUdXpZHXsM9g/X71JDWUaYBwWftzOy88iGelZjZYNsInVQ8Q018XjIC1f78LEP8Af7oCUIADt9Q9dQuREIyBzdFJV80t6ehYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335857; c=relaxed/simple; bh=pRmnLFjBJ2dWkN+uiG3G+4366k2+/zNV3iQ7dsrr+ws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nd2yqrhtK3vnsgXrfGnAi174WE0pEHynuTj2Y7fAvxDrBFykyiOkcL8OwP3qJKEqr4WyjCsKsgvA+SZZRgX11lUCKeuHoew+fAtyI/AmhQ+GIvRLNAVcEGCUxXLV82GxMx+y4D1Nd9yQMJ2bp6lRB+oxnSGidnxgw7x+9o2hOZI= 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=RBdQsGXR; arc=none smtp.client-ip=209.85.218.51 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="RBdQsGXR" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-ade48b24c97so115178266b.2 for ; Thu, 19 Jun 2025 05:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335854; x=1750940654; 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=RBdQsGXRSa0bnm8O3uTZqaI0MB4R6g6Svsdi94TwjQbExn/wbJCRjoACeIyhVR5ufm gopl4SpmBkf4rlTLsESVJpCcNgybXcwG5rAgA3gq8lgzgSAK+W3Bzz1HxNkcE2FJ0rWh JOAfdkUr0V50lXp8MUOk4x0riCpllHN4wkR4M5zs1LiTiv/mZQjse6OneQJd/ks7+9ly nSPw3Xhqp/nDp2zyx6M6EZf+IOIJJmtCohLl/5xxifgDUf3Z6BpRSu3cDUHSm8RNp51g CFWxzl6Re8nEFmN/paBnETmXXAGHx1haavLlEZnEeOySU5c1m+0EGtr/4htNu/GajbTF BXCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335854; x=1750940654; 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=viUTwRxDl9ppxE6f2M36dA6QrDECD89Vw/ElZm2g+4EhVMNiCJxk0r2/qhDOjpgha+ hh+ZDDRfsIlGiO5w4MVMJhbzwin9D8KRbS6v6QmPyaywvoE8Act6poaBEOqvC3SjDRPU MFor16rh9rBPg8wWNmLFXj+u6xDyD3Ne8gxR4qgsfK4eOGwBZKiMnPBX3I7W6oWymC2h dFuGC5nrGYGEKgiIhnNAB3Qr3aWIlmWbRBbjvRev7Cqa8sOPKQFxSbvrePbQYx3iIeNr S9lkfpEcAmaMyQZ1U6M6EcHOBoNi4c08I6UZj3mERx7Y1hweqJi51GX/mpqof24GkaBj U2Ug== X-Forwarded-Encrypted: i=1; AJvYcCV/Ma+2ObuYz69IEQc56y4jaVujB03BScrWYv2X+DafzXN9fZPmU0q90p/uMR8CwWY+Qh7HH+OYbHnmLg==@lists.linux.dev X-Gm-Message-State: AOJu0YwzlMGyCQMG419iAswdPgmVrFdNai2mOukCNYEPLhDs6PW7StQE XuvTj22/9FskmZTfl55XSgKIS6EkiFM/geR6ZiNa++v6WcU+YmGYP7U8hdsoTw== X-Gm-Gg: ASbGncvNonptfAtxJz6vQ9OnzJMqwJ0S6WWPTh3UV2Txh/Nct2CuDQ7zvlCBOZcDDhT cLhtOgNp7mKC8wIATGcOyge9o3DBp6+gZwb9jxu8bgasGMNyIJSCV8qBLGAxlUEm+GSaj3N5BWr D7Ka/6J/m3XmeZx9g4qjGDYb8j4Si+Xhqn5IdxZE+asnkjh1a94Rt4t/MAdIeh2+suuMyGdrKyH LevQIsLuQp3LOENzQm2q6sdncDc4L08OEN1zSHzcJt8y7WGcvpthonnotQk9qTIYj+zujmCbGYt 5CAgIYwju1jmFahCXnzDu7lRHziZrI1p1QEf3BKnR3GkFo96dZVpK/hhDIwhzD2IxRHbuLEhBTB o2M+ob7tQLnrJTw== X-Google-Smtp-Source: AGHT+IHjXBuVHBHVzGX7KJawSoi/MaD0OIMw0TPwOstgtvFQbFHnqwQM6253a1WMLNA8WmktvzgJrw== X-Received: by 2002:a17:907:7fa6:b0:ae0:3f20:68f8 with SMTP id a640c23a62f3a-ae03f207cdamr188465966b.39.1750335854011; Thu, 19 Jun 2025 05:24:14 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24:13 -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 03/10] crypto: sun8i-ce - move bounce_iv and backup_iv to request context Date: Thu, 19 Jun 2025 15:23:09 +0300 Message-ID: <20250619122316.2587236-4-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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 19 12:23: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: 1612 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.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 163BB248F47 for ; Thu, 19 Jun 2025 12:24:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335859; cv=none; b=X3ejcMiKOhlt4nay11nF2s9i9IaxLrW80r6Ioj+RY3z1z27vozh79vOnBm+3jGw4YHw0uN76zNCmHzy4qEy1zaafpkJfbl/HPf4spkv1iiuA9C7QUy2srN+gb3IW///09+BQd/++iWoR9vMfmXNQBlfl8hWxYKKnuhNYIcWqifI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335859; c=relaxed/simple; bh=C/gJk2ObWTENdNN8gXRsiciv6hvj3wk+copliiqlW8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tNnUmNQYML6rQyUAEkDkJbQFaNfxZNvFXmdeCqSLw98onfejXL97SXAoSuRUpKcA2XMMlVIEa/TgG1DkYuSf/S3B2r3X4CsTfQLLpoA+QM4sZ3lqYBNXll/1qxgdnbKpnhS5FCpv/yDF67S92orReOWEXL/Y1hDp12jyJw5Wlo0= 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=k2VkR6Ln; arc=none smtp.client-ip=209.85.218.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="k2VkR6Ln" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-ade4679fba7so144146166b.2 for ; Thu, 19 Jun 2025 05:24:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335855; x=1750940655; 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=k2VkR6LncHyovtNfzCjN1k0azTOnMH7/GlFNYpuYYRe3dll/KjHOrd3Qd6TChQF3// /h+epIUAj+/clarROinI1ruGnm87UtNAtC1/c9nps+tMnGG/n4HTG8fQOLxcJMBSz62h dVJ7O/2R+yZVazD6OkHPItcVQ6tmwZbMBBAhWgt9N7rYRH2BEDc5z+RBy6mSnYWUtS46 ZTRN3/2/E3EWibHkk32iR/KSIDb6vN2tSvffOpy6a1XuilKrLyfJjaUSoZvu6VDRPwoO wieDB+qIzY2leVJAS/ZMLzVWz7Q6imSH2OpPydbW9kGAC7Naj//lFXi/SZ4mLBmN6Ndf Pj/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335855; x=1750940655; 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=vwzQzFF6mkgE+B+tOq9zpSUddNjgKBnnhcmi4TPVtQRBb5jMr/r4SgamFvxLFPAHGv Dt8DR8ul3xVPhFLROIkCFfM6XjUwLu1BxBUxWMMIUfnmBKeVnNCCoNyTvGzMc3bxH+rT mwxhtvYLo1bZUwReOnzOGkGpIGOwZ3dXbgBLR4zTz1EcAXtq5HH5J2+9nF+IgocQAQfS 5WEQKx6r/bQTpEPE/WLpD88tquZXcXWzXlqSZyKNOxgC169BaSFv1FV+PTbcdII8w4iM G2W2E/jHyzy4+/2eNz0qunLFwi0xD8wXhBpFmZTtkI6PT91QSialfGMtyh5WeYVx8Qxe 4AOw== X-Forwarded-Encrypted: i=1; AJvYcCVvjaK1fZvwXNPEMgjJ7jXwu/1GUchdBtQ/wXLBLkYZJj4FlAZJ/N64FyhKDsmUBuL95sHwM6X7DNEINA==@lists.linux.dev X-Gm-Message-State: AOJu0YwpuZ8LtOprPaTEzPMG1io+eKnEVqtSOd+1MZp8wpOEd+zBYhsF IJqKgyoiuzEqn9Aj3G0fPvukzSSgx3GsbsfJ/ONvfk7w3C9+u2PL3e6a X-Gm-Gg: ASbGnctmmbnSN9hEqJfavqC7+/k2VW0b0PULz3Nhh2BVNg2C0PVTr4lpQkDtW+T/qFJ kU+xJ3DOChOWwkgCNQ5ZSnqh2j8qlo5Pzqn87fInthyfbeTJKgzuco2cIYwNjd9R6skzxPAdTHy e498eUfEx0twxMqPw5lJ5KhpAlxEipMKDqL6GMlaAES6bLQT9AhFF2phC8ttNWeVUmIuP1nJjHi e5D7qVkP1C9KZ4CB2S6BhL7JyPWJMvAXoYN4+Avx2CzFuHLxaZREcNmbHbiSwbtd1hUEkb/0SMe JyjzH3YZ+NhoD/izlKiozZGsVrSvZkLwYiGkntD/R0KeRCiM/MkhnI7yZwdpr8+71/0xZvmBdjR fBpDJbj1nudVHqQ== X-Google-Smtp-Source: AGHT+IEqkd21piHtgzZrKyYzEgGCeUARprhDQ5f8PJdOXO/FUR4X0Sb+5gSgjLC8tCZKpkV/N0CMLw== X-Received: by 2002:a17:907:1c9e:b0:ad8:8529:4f86 with SMTP id a640c23a62f3a-adfad5e2b12mr2149539166b.58.1750335855186; Thu, 19 Jun 2025 05:24:15 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24:14 -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 04/10] crypto: sun8i-ce - save hash buffers and dma info to request context Date: Thu, 19 Jun 2025 15:23:10 +0300 Message-ID: <20250619122316.2587236-5-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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 19 12:23: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: 1611 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 36C1024E4BD for ; Thu, 19 Jun 2025 12:24:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335861; cv=none; b=d2XLddUFuBNuBPls3Ewqp3GCBRXbuEPr/N8zUSAruZkVxRSxmOEVAVURhRN7LUK3j279QT6T3T6fMYftq59Pi7FoQRP/Vi3QuUWFgFMt02ztRRHLz5ENNh0F77tsanr83q6vixqWVit7j3qAL6CRQkcjhy0LIB2tjLtu9fwuHQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335861; c=relaxed/simple; bh=ThK72kzM3/NAb5q4kYO3GzKkml/jXobH2nqcwRen8oE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g7JHyUcNcrXdX7GjKaDSXw605rrviOZTVD/cQn1yuCsyVE/Y8CqGsT+l4KnuyazN2iGvZFJPUBtBX0EdMyksyar1BOKTjepiYYZ908jCRlMCn60/fmtGpS+/bo2JMfVnIsFRdh4eqUkzC3MeV+Wf73IbalwWOUGMrpZhzMgHLU0= 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=jc7xSQpM; arc=none smtp.client-ip=209.85.218.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="jc7xSQpM" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-adb47e0644dso130615266b.0 for ; Thu, 19 Jun 2025 05:24:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335856; x=1750940656; 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=jc7xSQpMQS6uW80rdF7CtHe6GTK1ZbfB9XVJ38W9DqNTtR25GS7jjNSXno+Ut542QY BQxdUNfvZeKqXgmyLdbicCtYEVlit2JhL4h1X7GBLBLQzYxtrDaBZXCqt+qTkJsKMmo7 nwD6GVv2ZyyY2z4ROJ5FKHJOwQ5Xkb7+MqVPHbVXLjLmMr8Z/pe3UWj2fsNHPVPBjRti LuCT6UYk5UiC1vHwKSsAFl7xTV2PfXIcI9YE0Hm1W8mBUTZEGfj0LjdkAWdS6A+BmCc/ rRu4cJPwkJWGsYU1X2eG3aMHPzXthLVSCQbLKKctBgqvWf4HfriZDILbzSfVFlHNyoaV JHuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335856; x=1750940656; 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=PY1T99zzBJh3EwGfhUmXjkeI9T4rEQktUUN+suiGiRDBovzK/B+M1W+/A6MaPT33UN pC7WPvcZgWO6T8b285mzAvbQiZgcWTVw3ea0OaAWizSTH+QwBSqs2gkxzKhlvA8fuGPK LO0PyPCDaZBc/8zgePisOsJqwiQs5AcMp2w2bT0WjJcKur57nOXivpEgLz1JcsonWmVw T4mvedsR2reOVHXnRziSTKd8G+r2w8dHtpjkcNmvVfap7e9FwvLS1qyblJSwBYA0Sb7/ EMfa23uNWIZQzGQ6KokHQyGoxWAQ64325KPfMDPh2eLlndz0JeVBiWjlslbEKChRVdAC BUuw== X-Forwarded-Encrypted: i=1; AJvYcCXaIEeZF5uyZgk+KsNrVX1/mRlkObkBtklK3YJOkA8+vhapqTUIanwRntLpBqdPcvzzJBbgI3NjoLU9yQ==@lists.linux.dev X-Gm-Message-State: AOJu0YzmQoFvP8qtAc8VDBP5lyykpHo+6KoIz+7EjI9flIVMI//nE+1K cECe69SU5rLTEyM+ekcCXVv6HdzWUsNmUMF0wibS2d0LpKTfTcMH/4vB X-Gm-Gg: ASbGnctH40xGJnWYOl3MfaFzAKraDfHi6p8gVElaW9DqZgRG1+Z+NWs5kdW635ZwhOK EsRn6LdMmC3cRhCervJ7X1kpOdYFvSNe23oQoyaW37gO/mBXG9al6/RNbcOGGGY/UAIiUiwWrnT LNz0OQdcZvstWkRfzCV2eNPqz1/ZRLvB2D7iaQ6SDYr6t8ShJ8fzBpf60YHzcnFzPhmV+z9PZCi NEBubQ0mvgS7OaBqiBAPfaQcdeDrNcs5Wnfx/+gY5ewoDhYmt1yKvN+Ktka3LcUwQOYGBzW0Wsp oHXbru+yWsx9u5GpSJtpuJLkkyE1mpOaTeNr4+umggMkUY2ats8Lf5gywCE/07G0h1vHf4GinmN BXqZFe7mV6BV9Rg== X-Google-Smtp-Source: AGHT+IGp2TBBgU3kBXSIIbngsVXxutaDLHe7ezjC9aFjh5AHU1t7NJo73l09wb2AvdA+UM11p80C2g== X-Received: by 2002:a17:907:e897:b0:ade:31eb:66df with SMTP id a640c23a62f3a-ae035285491mr322808566b.11.1750335856287; Thu, 19 Jun 2025 05:24:16 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24:16 -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 05/10] crypto: sun8i-ce - factor out prepare/unprepare code from ahash do_one_request Date: Thu, 19 Jun 2025 15:23:11 +0300 Message-ID: <20250619122316.2587236-6-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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 19 12:23: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: 1610 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 6146E24EAA3 for ; Thu, 19 Jun 2025 12:24:19 +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=1750335861; cv=none; b=FHJZlMNxoN1EDnwobTORkLgo7VXZv551qJ+Rg0bd3W9OAonvb2TXXb6WSdkhzfzmaMN1nAoFJZOdViVIzItQ8zb1sGKXo5m9zPRBmwUtpfqmFlE5RJ4xtO61lqC+B6vYq87c0osE/Y1cZRNsyJImOsT2vH3hgCYJ7xJclDwQwR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335861; c=relaxed/simple; bh=MVmmWlPksmaiBVibi00qDI48RIUv844ifSFHgrjus/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VSq21hVmYGRc90ikTLSxvGk7bqYRrTyPYI7zNKbl5EcjZFYq0FKIuw6QtVz2AEfXUrpYJUZJmo8B88onqmR9jEsb+7U+J7jjhe8deH2QQhoxyW0pfYbjX3M8HREFGQQlsHmPw3DOuaajEX5UCAj8Komi+vDq5IdL/JWSAg8MtYA= 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=mfzFT1ie; 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="mfzFT1ie" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-adeaa4f3d07so144217766b.0 for ; Thu, 19 Jun 2025 05:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335858; x=1750940658; 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=mfzFT1iecTL9CosduTb2vNGJaZ9XcQ+trbK8Gl6Z6i7hWNQsYZk/Bw7HvPmMPNy+hX Icv87txb35rOH/VskBYEB8ntqU68j/gKvlOB8h637ZgwnwORz66AvC7Cr/F5u9KfzacT FuA3kibZWKPUVWCMJZWUMU5e6gmMSMUHikipJNBggyKSNyljzY2NzssS4YAtDvLvg4fj a46t/io4L9zy8hYKZfLTGccSx9aAK+dgEZx/SD+/2QCfhegvQ9Z/IHPT17bkCVNUx3EL hgPnSeJ7GkSo06sKPmcK+H7XKPqt6doRvM+YZkZIneNCRFnz+F+At6JAW8be1t4oJdvN pbWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335858; x=1750940658; 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=iW6DuO86E5MfMb0Xpu2mogCXLdcEFbLDeCkL07FablB81Yu3pVW8IY4RVcDU2R2Zo4 kmelBxb4mUL0SLBSsOQ4WRbn1NS5Cl+Rsx7kBG5Ytacn/VmIkvOxazf62LOJEVXf91TW 5e32K50bojKZ24pioSrENgAoIyW0Ws5wChJCluNM0pZBt0iZgtrI+/BGih7lqOFffahw I+OZpQ3wlwCDl1wuf1uC+wsNGcpgyojZ+HsVSzlil4MIij9Ysj9dDmV65OfriMFfICiY PCAVk207xZweVYQ3Nw7ogTaQnvQX/YaFf6617GxVrggyrkKoLLdy+GoqCXcZzCwRLwXF VE/w== X-Forwarded-Encrypted: i=1; AJvYcCVR0hR3EVrzHm673SQYEflmCT4TJQU6kOx717WghEIilbTVbz92Na1fRmEFLJZHOq0iAg50PTyya/ghNA==@lists.linux.dev X-Gm-Message-State: AOJu0Yy0AWlwPqZ3n4039sOGHA1a5wpFTPMg8FmNvppcCChUDTXD5VOo Oddvxs3zPdWYrNPs9jO3KqfSz8fDMclEuNwsRTjd3tEIw3ry2WzArPNWwC7I0Q== X-Gm-Gg: ASbGncsSfFeNHzocjUskWaDQj2YYpZb7y5OtSjRcjBIzhlGpk0iPAZgDVFHF4JF1Q5u cMmNZk5Pt6Q91O9J5Ae/n+7JlVlZ7EaEPKRkU6VAKdGsYL9QJNfqOv7LXF5iDmwA7poZWGkSy84 YQBTdxRhFFSyFdsH1EtVSwskxZEgHqsdDAq9fpS5xBzkaspBdfrHPP2tArbxNmDmpdEyjeFCkQe GUoIyyQa0XIrNY6d16gBoQj2Zi4iHG4Eb7CGvLdbmmTIzrJRrbnXiJwSF7uNaXwaXhybXoK0y+P WTCFRuOeChNUh6X3x50dpAEQARoChf69MC6LgRn16H3y/oqXo4ng1dji4lZyt/1RwzDEJlY2qYh plYVVuP3FkPHJLw== X-Google-Smtp-Source: AGHT+IE+a44JiT4pmaQaCPgiF4SiL6W/ZMs6YLvucyMriX+08QeWg5qDOEHlRbDj5alSx6vbOGHqPA== X-Received: by 2002:a17:906:9fcb:b0:ad8:9e5b:9217 with SMTP id a640c23a62f3a-adfad60cb3bmr2167795566b.45.1750335857453; Thu, 19 Jun 2025 05:24:17 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24:17 -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 06/10] crypto: sun8i-ce - fold sun8i_ce_cipher_run() into sun8i_ce_cipher_do_one() Date: Thu, 19 Jun 2025 15:23:12 +0300 Message-ID: <20250619122316.2587236-7-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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 19 12:23: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: 1609 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 85A04242D96 for ; Thu, 19 Jun 2025 12:24:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335862; cv=none; b=uFhcYcODA5Oh9FtZH6D0y33fuE2hYcxsjsCQu2gGnNdPiqEGag3kDYez78X6zJSkX3x+hphPnVpDjL26C/7P/fEZKXxiq9R9fdz0HbSxjU2TlGcizyQHySoT2B52C61StwcQlCIjPtUd2DgGbYnRQlhC3Pd2+fFg7VYxH04c+fQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335862; c=relaxed/simple; bh=kINjivbB1+ylLn7tV9af00mOK273H9HJI0nMG3aaa1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WlPUTnkRued/pK8DmBlPCTPGXdyDje/rSlHX68ePlYV84/Z5aPGcTB8Pxdm1mZ9mX7UqwfYuZGrfg/+PdYyTjByteI73Zq7blJwO0CQFDEBtz7y0MVlgtDWEvI3qAt2d/JDpTvyGVeAJ9PlttMjXe0biWwkv0YCUq+Yq9kfy0H8= 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=DKtSM7S3; arc=none smtp.client-ip=209.85.218.48 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="DKtSM7S3" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-addda47ebeaso145459866b.1 for ; Thu, 19 Jun 2025 05:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335859; x=1750940659; 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=DKtSM7S3mgaxW93QAU2jApcUd1+mMEqGbs9mnR5O4TwNGL6abfKx3hzS+j5qKkXmRT CUyN8uyuOANnp990fRM1v/LgMfGcwouk8EbDzLUpeN4zHUv5m8rrqlC6//0E0pKmpGI2 GRLy32RJAoU7XLsiXqcLqEDB0S9wnUsLxMz4iy1QmjwKMN2ZSKwwloav3/N0RzrfElwe vQ7baGJQD6pbYEE/clFq/WEz+pIBFIcHzkrWdVAvUsNg0Ds1rspwmqPOvCQ9sYlnemRW PfL5/+loypu8SB7dgAlOSjDDdCnzYg4zvXfiQFToDGBAa6JpIU6s0soV6eQU8EB+eHPU cLug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335859; x=1750940659; 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=ke0ajxKW9rnMkvkfiVUJHkAJTZZ91r7iucgJ9c3Uhuiwl6Xeq/vf/PTiQcHnFOjZWm va9Gmpnj6HxreO1CQc9LFiYgdOnMIQR7YcWW5Pxwx2mnFQbTGm1zZopd9lgLl5Wa/52s eMtOHDeQJUy2d6Crs81hQ4SSMpeMMNkA6vSlsfO3KzN97QfgiO5HW+zC2cZG9vo0Qvpu uzEFPNW8kcDGH7aEktHR1QVxcB+Y0ffcRFSnKHgQ+sUzR8d/hdBwue3PZbsoHAg4PsS/ aYF45OgjC3PuiYAGcjOeCcPy/tuTAQJxSXIJgGWdzeCe1c94uxrw23UDDQL9ypV7W9xs uqig== X-Forwarded-Encrypted: i=1; AJvYcCVVXHuCYj3Gt+pjz9LbFmzRdy3C/TpBQq8ZD0qwbFmy54VhwmvNYnoznYYsLHCjBXMwA1oAYWeItaRe2A==@lists.linux.dev X-Gm-Message-State: AOJu0Yy5W44XOZAKknPb39Mo8338R/68bQAs9iDIDY3WuxDu1VogrNlV oiT8Q/ei0mRoH3sW8cH9g4WYhl/dLErHWzRS4hehJzVh1lfg91vAowf+ X-Gm-Gg: ASbGncsgRNoaI/izpWxPQCaMxgcfWLi3FSIIuiKPI/naVDGUWz6beUVmxnaPGy2WF+N fhOrpcMP9Sf5mD1wXj/fSlJu6GZYTtvFSm6rSOV0ycus759qQnbJuy+UhO4R8HyPmkJFC4CmXgd 9h1A9+iCCOwxP8DVOs6QDdnS1pdZchstIMBVEMGS3W0g8NbjqMcxM76VuErFd/kpjnKAGTA44qb 3qbHMV6UQzDh8HfYTiCGrubGY678/K9MGOM0QraNgF1TUs5oHcQZ6IfM2s/UmEmp6MSintmXrqS IlP4oplbyN7/gW2ZN7fovrwdqp1lydDZrPFEhRbmc1qPQsCXgB26WwUJa9O7YfqCpXLuRloyCuV AQeAUpIvuNyWeWw== X-Google-Smtp-Source: AGHT+IGEPeo5IOklcxib13+gmY/mAxR132u//d0bSaTarIv0yq4bk3Wfepb86FCqZ57HZAhqV1/TKw== X-Received: by 2002:a17:906:c10f:b0:adb:3345:7594 with SMTP id a640c23a62f3a-adfad31e10cmr1852773366b.9.1750335858569; Thu, 19 Jun 2025 05:24:18 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24: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 07/10] crypto: sun8i-ce - pass task descriptor to cipher prepare/unprepare Date: Thu, 19 Jun 2025 15:23:13 +0300 Message-ID: <20250619122316.2587236-8-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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 19 12:23:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1608 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 D5F90253F1A for ; Thu, 19 Jun 2025 12:24:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335864; cv=none; b=RNM89zt5Vyli0MoS1RxfnmyRaweMAyIdjS7i2VMtedEI1+CyqqvCJ9MuZIYGJ1L539i7sEYVi3jqWa7fb+y7IQ3KxL/T2mP/PYpELhgJB1Vhr354DNMdxJvlMQMQFYuMqZrwURQ7hfAJcLzeuf4jelmKppKsVfCIwhQR3S6NV9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335864; c=relaxed/simple; bh=SV17SgqAFM/CwgJKb43KYYELjIo00ELjwm2XuaeiHoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uBUDgl7PV0Ii1aYmmhumo1Vn6wFbSDy4V5LR8YEL4SjQlRyIl6uIIIjC6G52iiRjumaielg4Wl9muQeFKXpFQ5/hVVwlLZmaLiXw3euRMxbI1krgLntVOR/Cm98TPG/GqEd/Rdrm7BZ5O3BkAvEqyUwASRlqsPLyb+UtYrqQrpg= 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=CVyQSHPj; arc=none smtp.client-ip=209.85.218.54 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="CVyQSHPj" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-ad8a6c202ffso137412766b.3 for ; Thu, 19 Jun 2025 05:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335860; x=1750940660; 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=CVyQSHPjdb1tVWkjykIC7us3XbQUOA++Btbpsz0NepJB663FVR8Znwn2zeZk+JB2+Y g3f0NS1fpdfCvmGsC9G9dWBc6EX3OfL3+a7TcWqvVh2HuVXyyrOZENhk0f771ma3Zy7/ q2UN1O4KO/N4fiBLEfrdEM07/MlxbsSqd/Wk0DvspYw6D4FbrI3BBQyBicXtm/gvA+QV BIzr2jZoFFZjzE7SqGO0NwFZKPdJiLujhfhuUo3+6dzAxangYIsXNOEh+PZsEQhd+5NP 3gUH5Bp+62NJ1utaDSt5zzjnLFe0E8hvqlrhzcyhAQzElakQguZaHkYtpujoFtkC6OXD 0BZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335860; x=1750940660; 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=a9cX2ay5UQkk1+kLgyvYsTUT7qSJ/2FCBEdZiKbnAHh7w2Ff9bfH1yeVf9DfbmGKDz 3htKBNxFvD6L3uUI65XGTa7NmofR3Z2eUZ3u8RkiU65ywNdoZTjwsWQoKIw4MPdYGSzR 1mOYEDhcG0fL5hyVMVYMqlEkX1TON4eHmqAT+ZwQgtysRObc/Z7ewJk6NHamFt6L4HHE gAimCJr7I3FDRtmbyo0TKlQhwKtoXVoG7YiflB9hQdLCAIUwSejyy/Gh/y+ibFewaUpp k2hJIXZmihaGyeJBVlA6uAu2/1GxB27Q10SzUkMK+rYGw7It4Aed0lizkYyhgO8SYd1a rsEA== X-Forwarded-Encrypted: i=1; AJvYcCXnCpqNXSl3R2OuAO5cPb6DtN5kqFB29iZdOSoqwkcuA10QBkVBqXrnpGC1oDbZ7Bf/htNRmBUlCBOs8Q==@lists.linux.dev X-Gm-Message-State: AOJu0YyEEmlmF46y/19zCqCa2bUAffdN/nSA3Cg8DA9UWs4k+ytMmZHW gBTLUuUWXfYL6wMbUT4ZZ0EILAmd5UBv94wl0/qOJ5uXCFIqROvcme5J X-Gm-Gg: ASbGncuSgdpS9f33qZeYG2GbLaS71RBDiXO6vSBvF+/cABafVxNKwwqsgn2YFetFYx4 J6hFoklp5JKf1Jc584zOSiXoxOAg2zmfVUYA8gI60E3XrAqIhZXFP196nchZZkuXF0y9mR7M+KZ xjMriWfTQf1sGPjq4b8RKBVX2YFDwHh2w9Xl0l6yEf5W8s3Wcl5Sf4XuVXAl9dQd/n7B+7HCSof u2lXNQl4fTi74VXiajM4N8sGwAZW3fBy96JKvnaWTzMlGmAMqzbkiyFxlvhoDRniUgR7reVWzYE 6hFvEb9QvVnvQaYU5coScz9dboKRdBCxJhYMoqCAB+OE2jOwaJXaXJTQeEBw7Aqs5zpX4aUjpPh K185VbEFQNMBjcA== X-Google-Smtp-Source: AGHT+IHwGI3VAdkps/w875TI+PTeKjZsVrfn6fAKJdMQGXVhrfDL7CIBgagxHkyrj9BPDgk2ITeRzw== X-Received: by 2002:a17:907:3fa9:b0:ad8:89f8:3f51 with SMTP id a640c23a62f3a-adfad28d0e8mr2120856066b.6.1750335859832; Thu, 19 Jun 2025 05:24:19 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24: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 08/10] crypto: sun8i-ce - factor out public versions of finalize request Date: Thu, 19 Jun 2025 15:23:14 +0300 Message-ID: <20250619122316.2587236-9-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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 19 12:23:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1607 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 AFB45254864 for ; Thu, 19 Jun 2025 12:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335864; cv=none; b=pd6rHO7SRY5jTcD4nSDDMSnkfvpeCTBtyYDSelk/qqlWx7SmrSQjUSVixgWdsHNRHhdERPqLtoenjslEMHQwcy1TnNeBPTi0ArePyIUnc7hq6lCG65BsNkg25BoWUVKVqb/rsIb737tFqHfA/Cgkee4/gA7HQ9CNytuIMSOrHQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335864; c=relaxed/simple; bh=dsS+p6UvQk8Xwg+WgyOGAas3d5MTBbJN2FAK8gI6CFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZPG44GknfSAck2uKo2coyyN9b+ZN5DNHC9LKD0ARYuTX7YjGU95RLys0nSfSAKwaNop4/F6pkjl27QxFzVByPfU1RFRs8GIOcxlZMBCBZIG2G0alCSBW0oheGV2NfAu+BOzjqh+gU+f2PksvYGAvExnAguSXPlssWV6C3J/WDIQ= 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=HNjgagv/; arc=none smtp.client-ip=209.85.218.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="HNjgagv/" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-ad93ff9f714so135262066b.2 for ; Thu, 19 Jun 2025 05:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335861; x=1750940661; 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=HNjgagv/dr/iDH5FBCTbh/dP3nWqbx+gLC1SDTW8SadICGk411v5wiAoD+8e2ppkdK tEEoCFJR/F7XCKn8njTx4NjsWid7sKjOs7eQ5BAxsjrDMm2EHJewr8FkRnc0TQ3F0Eeg PebAldTxQpjSwrFyoZhP/8bveOdsnTwTExhMAEYayaZfBtjTnCtgARB/DcfrBkk+wZOK f3ZwTZwhk+a+/I1Z5jYy9rec5E6kC+pGkJ4QeJl09qL+3PtsFTc57kgLsSSuy8Y/akXg 2pCLoKF+W2SKJ7e3XbrqFSbrjFY25iU21J/Y9n41Xv+Xe4yiYnqBlh7OP8hzO52EHCbx B+xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335861; x=1750940661; 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=w69sQdW7xiqCvDVgwzFFU4gZuvTe+u2OoO/zcmc1GSJgcp/Y3zFa+WnyTD7lJ1K+Hy QZk0Qhb1OE08m6hO65nZkh5dSS8hy8rKqF1sUk37ymjDYt8KM/D8nlcjIsizdOIfASaD ESwpVsfR9T+YVYT6u2y4DRX9zbPqrXyJXhZAPE00Ji7J6na2PxO/F4S1OAfNn5z0VaX3 R8qYtnqIJlvSVGQ5J/TdfrxHYv6IoUhvkQbdLHKGMHhUaazCreoZBtaNz236nQ4GGIiH oqcqHlvMpnsZjR+tzhLPc8IN7UOlpSS1LLFyzTYaNvwrVT0kIhuJAq+ql/yodJyiCO+M SSgA== X-Forwarded-Encrypted: i=1; AJvYcCU+ns1C38EEHvVryOvA9zbFkaRhphGW3gEHiMDFjWPEaLUIPQhmAd/V0GqKHmsJyQfMcjEom69J0abooA==@lists.linux.dev X-Gm-Message-State: AOJu0YzWxNWhWX3bOk+BAqFS08AC1B8dHmRvWQLSMwXSzZ4XCQmrptjj 9zFCY5f0Omgjj9LZxAdGhnJZy34zhHSfq1IodXAjDz9H6oEnWqGggF9P X-Gm-Gg: ASbGncsU8wc5xngy59+lEUyoRqFLAq1q8s24S5pEgHHCHVr22He8xK4hwBAA658Qcpd VhNUR2n3NtGb16KBhHjGvGH3QZJrjGmOBkeQuIqX6bAN3o3NUVHFsauO/vg3KPXBOB5EcAP6O67 KK0tIXrZGh0/LumBIPQeKlWvzDQ8xVfNfwqFlavUnAvARtIYanw0fhgvCpQ1lAaVid1Q8vTg5+G zCti01QJAfvtPmm5aLe+M9b56WJbwNJxzXxJju3SQiknHKhjP0Vhryg2HKsjQQLzJ2fCxHtjaSc 31YjyzVgFl5d5z2IxJr0NwH7WhdLfI5NpfzCvBmfhfgCQNbJEFPRXzxM9G4kv9yQ1uz5aR44oqI Cojz7qNQB+Nh13g== X-Google-Smtp-Source: AGHT+IHH6DFXlW3XSv30gN9W1MaxFbV4Xi7gLnQBbzesKqNPz0MrTZ8hdE2KCDgVxH4xeRlqT8acsw== X-Received: by 2002:a17:907:9694:b0:ad5:4a43:5ae8 with SMTP id a640c23a62f3a-adfad31cd15mr2245682266b.12.1750335860965; Thu, 19 Jun 2025 05:24:20 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24: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 09/10] crypto: sun8i-ce - add a new function for dumping task descriptors Date: Thu, 19 Jun 2025 15:23:15 +0300 Message-ID: <20250619122316.2587236-10-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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 19 12:23:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1606 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 19BBE255240 for ; Thu, 19 Jun 2025 12:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335866; cv=none; b=tOI2R66/c+l1VtPhHsxX7ZR3wX3Z/HWfC/LKIkbbZRkzyegRtb9WpuIbXKEDESqET6brf/LzZNIelP6sp8EWpkfqVzRQ2ds117vkYRv6NV72hnXUIs9hr7QQe2w6YumsVgjDlFkXNrO2FL6IytS78F4Q/+KxSelWo+NheepxkEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335866; c=relaxed/simple; bh=uvn/CbjR0iHC1Gzqj3IMoegYKQaMERPstoXduBNPa1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=siVUYT/a8/iJV8/gq8Ozy9L9cHKFzAlaNwmBOGD0tmEKkxhBQenrIAO3nwbWVy+HifTEH7sf/c9XK7szOqIm4fSgmxBoxHRzlp8ArKKPTBausYELiGmyfmbr+zC8xlcYFQFi0E5UCZ0VGQoOrb9+eyNVjlKC9NemGbYVBZGrVg4= 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=Il5+BYBY; arc=none smtp.client-ip=209.85.218.51 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="Il5+BYBY" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-addda47ebeaso145469066b.1 for ; Thu, 19 Jun 2025 05:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750335862; x=1750940662; 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=g5Gpu+13nPGCVHqZg30hcatcad880Sim9iFcp3f23U4=; b=Il5+BYBYiNuea0hrOIYcCYJ76kX+24VaNDhxJCEMjSDieicVsaWPd9oQJdp9L4sMWO hqb5yPagbtBN+AKjoCvcwYSrG/f8K9wTSSC2c2RxjQlkowDOw+Fo+VBDZmvo57hUSjO+ GvBAJ5KXokMUOBkFBLKKwpTFAm9UaGV8IOZckt68TVrTCNSrrCyVPi12VUduH9Z1mXem u33pxcFtiVx6qTWGIFeD1qjPxsiDlJD/flBPTlj2x4IxSXxlnC1qEkime87LDIVMwXEn s5wiP9LrvJbDWXXMKCAMOs51jYaWNmsvaTlINRtyRpwcJJwwP2wF8mm1e/cDhyb5i7wt O8bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750335862; x=1750940662; 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=g5Gpu+13nPGCVHqZg30hcatcad880Sim9iFcp3f23U4=; b=NKNtepRruzO/fRYpR1x39ibiprxqu7SHHPAf809wQQhyq8FVxV7adAU6T1TcTCmuv3 8m6/U3f6hCU3PI2xeWsKKfikCkV8oOq5cZqBew8iVYMZO/IPBs/PDlFngvR2xLbZkGhX 1A7zahrNfMAFu4+zBgWYqSHLldm+6sCM/PoYs+PS1eKiiQ7KjtvieBUlWASEhGx3DTpk KE7j6A8Xyq6cvGucpzhi1QPbMoAH5dHoCFd2TRxbw/fpBW9Ipp9OIXVO4eMAM/SDrENJ XhQ1wd/7knWXhw6XLKPbNKgcEZ69JEdepA/yVAE1+duRSvfwCQueIETvL4LzPjfKBYA+ Y4oA== X-Forwarded-Encrypted: i=1; AJvYcCU+xAeMQ6McuoNmC6+u7hCM7JzWzgjzNjcWaRPXrwv90bL573p2b8/TuL4Xu9aT9KfEVAlKMHpWpvFIIw==@lists.linux.dev X-Gm-Message-State: AOJu0YyUkLK+7klNMI8pT9zzCsWAZHzVDTmgy/JvKrJ9ItBUXg4LEZ7r wFNP9tpVZochldtYJP0jRBbhdyJK/AWwMnSa1RwhvaIxCguT5PcY+YGt X-Gm-Gg: ASbGncuaN4g2C6DAvaHKRqeKl+s+26P3FOIVy4dIFSzZRBiy8IiY+fXFk5Yh5yl0XDm 6ZW/bymnYnCD+ZFfXi6xPJxqkFY1xS51IhQtfm8Tf4LqrhTkYxAvXykIMGOm6JfLA/fOuo6Lh9/ gtGnNAVPQdnKX/Dxtp0506eWCxfIll0Fi6y6VlQ6y+vmx9sKmaImM+Tr4UGUXrB6csWYkKKmkeH TD7WFpXEhsHdmhpIB543ydRyP+mFnRhONSu6B1BrHevBBbqNiJ40j1SlmkPPnKcr37Cqw5ZRZKa KTxwha6E8xvJr9I4NTlJYoOhnO/U+DCv5G4STh0RzNrranJN1DXZKkI3myefXfUPz3+Tro5kaIy 7M0ApJMQGL4Hzqg== X-Google-Smtp-Source: AGHT+IF962CYjlLZtvg9eHBjvU8GUucSlYDpx3mPu8LwlDHj4xeOOn/8jtcAmRLBHe5JeNQW4grErg== X-Received: by 2002:a17:907:3c86:b0:ad8:a329:b490 with SMTP id a640c23a62f3a-adfad396ef2mr1987587166b.23.1750335862153; Thu, 19 Jun 2025 05:24:22 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f0e:c51b:8900:a03f:12cb:72f7:9069]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae000b02bd3sm504688066b.3.2025.06.19.05.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 05:24:21 -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 10/10] crypto: sun8i-ce - implement request batching Date: Thu, 19 Jun 2025 15:23:16 +0300 Message-ID: <20250619122316.2587236-11-ovidiu.panait.oss@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250619122316.2587236-1-ovidiu.panait.oss@gmail.com> References: <20250619122316.2587236-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..424deea18453 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 12 +#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,