Linux-Renesas-SoC Archive on lore.kernel.org
 help / color / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Gilad Ben-Yossef <gilad@benyossef.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	linux-crypto@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH v2 22/34] crypto: ccree - extract cc_init_copy_sram()
Date: Tue, 11 Feb 2020 19:19:16 +0100
Message-ID: <20200211181928.15178-23-geert+renesas@glider.be> (raw)
In-Reply-To: <20200211181928.15178-1-geert+renesas@glider.be>

Extract the copy to SRAM of the initial values for a hash algorithm into
its own function, to improve readability and ease maintenance.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - New.

 drivers/crypto/ccree/cc_hash.c | 91 ++++++++++++++--------------------
 1 file changed, 36 insertions(+), 55 deletions(-)

diff --git a/drivers/crypto/ccree/cc_hash.c b/drivers/crypto/ccree/cc_hash.c
index 0b179aafd484738b..f3adc1ab0e01abec 100644
--- a/drivers/crypto/ccree/cc_hash.c
+++ b/drivers/crypto/ccree/cc_hash.c
@@ -1865,104 +1865,85 @@ static struct cc_hash_alg *cc_alloc_hash_alg(struct cc_hash_template *template,
 	return t_crypto_alg;
 }
 
+static int cc_init_copy_sram(struct cc_drvdata *drvdata, const u32 *data,
+			     unsigned int size, u32 *sram_buff_ofs)
+{
+	struct cc_hw_desc larval_seq[CC_DIGEST_SIZE_MAX / sizeof(u32)];
+	unsigned int larval_seq_len = 0;
+	int rc;
+
+	cc_set_sram_desc(data, *sram_buff_ofs, size / sizeof(*data),
+			 larval_seq, &larval_seq_len);
+	rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+	if (rc)
+		return rc;
+
+	*sram_buff_ofs += size;
+	return 0;
+}
+
 int cc_init_hash_sram(struct cc_drvdata *drvdata)
 {
 	struct cc_hash_handle *hash_handle = drvdata->hash_handle;
 	u32 sram_buff_ofs = hash_handle->digest_len_sram_addr;
-	unsigned int larval_seq_len = 0;
-	struct cc_hw_desc larval_seq[CC_DIGEST_SIZE_MAX / sizeof(u32)];
 	bool large_sha_supported = (drvdata->hw_rev >= CC_HW_REV_712);
 	bool sm3_supported = (drvdata->hw_rev >= CC_HW_REV_713);
 	int rc = 0;
 
 	/* Copy-to-sram digest-len */
-	cc_set_sram_desc(cc_digest_len_init, sram_buff_ofs,
-			 ARRAY_SIZE(cc_digest_len_init), larval_seq,
-			 &larval_seq_len);
-	rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+	rc = cc_init_copy_sram(drvdata, cc_digest_len_init,
+			       sizeof(cc_digest_len_init), &sram_buff_ofs);
 	if (rc)
 		goto init_digest_const_err;
 
-	sram_buff_ofs += sizeof(cc_digest_len_init);
-	larval_seq_len = 0;
-
 	if (large_sha_supported) {
 		/* Copy-to-sram digest-len for sha384/512 */
-		cc_set_sram_desc(cc_digest_len_sha512_init, sram_buff_ofs,
-				 ARRAY_SIZE(cc_digest_len_sha512_init),
-				 larval_seq, &larval_seq_len);
-		rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+		rc = cc_init_copy_sram(drvdata, cc_digest_len_sha512_init,
+				       sizeof(cc_digest_len_sha512_init),
+				       &sram_buff_ofs);
 		if (rc)
 			goto init_digest_const_err;
-
-		sram_buff_ofs += sizeof(cc_digest_len_sha512_init);
-		larval_seq_len = 0;
 	}
 
 	/* The initial digests offset */
 	hash_handle->larval_digest_sram_addr = sram_buff_ofs;
 
 	/* Copy-to-sram initial SHA* digests */
-	cc_set_sram_desc(cc_md5_init, sram_buff_ofs, ARRAY_SIZE(cc_md5_init),
-			 larval_seq, &larval_seq_len);
-	rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+	rc = cc_init_copy_sram(drvdata, cc_md5_init, sizeof(cc_md5_init),
+			       &sram_buff_ofs);
 	if (rc)
 		goto init_digest_const_err;
-	sram_buff_ofs += sizeof(cc_md5_init);
-	larval_seq_len = 0;
 
-	cc_set_sram_desc(cc_sha1_init, sram_buff_ofs,
-			 ARRAY_SIZE(cc_sha1_init), larval_seq,
-			 &larval_seq_len);
-	rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+	rc = cc_init_copy_sram(drvdata, cc_sha1_init, sizeof(cc_sha1_init),
+			       &sram_buff_ofs);
 	if (rc)
 		goto init_digest_const_err;
-	sram_buff_ofs += sizeof(cc_sha1_init);
-	larval_seq_len = 0;
 
-	cc_set_sram_desc(cc_sha224_init, sram_buff_ofs,
-			 ARRAY_SIZE(cc_sha224_init), larval_seq,
-			 &larval_seq_len);
-	rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+	rc = cc_init_copy_sram(drvdata, cc_sha224_init, sizeof(cc_sha224_init),
+			       &sram_buff_ofs);
 	if (rc)
 		goto init_digest_const_err;
-	sram_buff_ofs += sizeof(cc_sha224_init);
-	larval_seq_len = 0;
 
-	cc_set_sram_desc(cc_sha256_init, sram_buff_ofs,
-			 ARRAY_SIZE(cc_sha256_init), larval_seq,
-			 &larval_seq_len);
-	rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+	rc = cc_init_copy_sram(drvdata, cc_sha256_init, sizeof(cc_sha256_init),
+			       &sram_buff_ofs);
 	if (rc)
 		goto init_digest_const_err;
-	sram_buff_ofs += sizeof(cc_sha256_init);
-	larval_seq_len = 0;
 
 	if (sm3_supported) {
-		cc_set_sram_desc(cc_sm3_init, sram_buff_ofs,
-				 ARRAY_SIZE(cc_sm3_init), larval_seq,
-				 &larval_seq_len);
-		rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+		rc = cc_init_copy_sram(drvdata, cc_sm3_init,
+				       sizeof(cc_sm3_init), &sram_buff_ofs);
 		if (rc)
 			goto init_digest_const_err;
-		sram_buff_ofs += sizeof(cc_sm3_init);
-		larval_seq_len = 0;
 	}
 
 	if (large_sha_supported) {
-		cc_set_sram_desc(cc_sha384_init, sram_buff_ofs,
-				 ARRAY_SIZE(cc_sha384_init), larval_seq,
-				 &larval_seq_len);
-		rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+		rc = cc_init_copy_sram(drvdata, cc_sha384_init,
+				       sizeof(cc_sha384_init), &sram_buff_ofs);
 		if (rc)
 			goto init_digest_const_err;
-		sram_buff_ofs += sizeof(cc_sha384_init);
-		larval_seq_len = 0;
 
-		cc_set_sram_desc(cc_sha512_init, sram_buff_ofs,
-				 ARRAY_SIZE(cc_sha512_init), larval_seq,
-				 &larval_seq_len);
-		rc = send_request_init(drvdata, larval_seq, larval_seq_len);
+		rc = cc_init_copy_sram(drvdata, cc_sha512_init,
+				       sizeof(cc_sha512_init), &sram_buff_ofs);
 		if (rc)
 			goto init_digest_const_err;
 	}
-- 
2.17.1


  parent reply index

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 18:18 [PATCH v2 00/34] crypto: ccree - miscellaneous fixes and improvements Geert Uytterhoeven
2020-02-11 18:18 ` [PATCH v2 01/34] debugfs: regset32: Add Runtime PM support Geert Uytterhoeven
2020-02-11 18:18 ` [PATCH v2 02/34] crypto: ccree - fix debugfs register access while suspended Geert Uytterhoeven
2020-02-11 18:18 ` [PATCH v2 03/34] crypto: ccree - fix retry handling in cc_send_sync_request() Geert Uytterhoeven
2020-02-11 18:18 ` [PATCH v2 04/34] crypto: ccree - remove unneeded casts Geert Uytterhoeven
2020-02-11 18:18 ` [PATCH v2 05/34] crypto: ccree - swap SHA384 and SHA512 larval hashes at build time Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 06/34] crypto: ccree - drop duplicated error message on SRAM exhaustion Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 07/34] crypto: ccree - remove empty cc_sram_mgr_fini() Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 08/34] crypto: ccree - clean up clock handling Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 09/34] crypto: ccree - make mlli_params.mlli_virt_addr void * Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 10/34] crypto: ccree - use existing helpers to split 64-bit addresses Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 11/34] crypto: ccree - defer larval_digest_addr init until needed Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 12/34] crypto: ccree - remove bogus paragraph about freeing SRAM Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 13/34] crypto: ccree - use u32 for SRAM addresses Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 14/34] crypto: ccree - simplify Runtime PM handling Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 15/34] crypto: ccree - use of_device_get_match_data() Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 16/34] crypto: ccree - remove cc_pm_is_dev_suspended() wrapper Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 17/34] crypto: ccree - make cc_pm_{suspend,resume}() static Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 18/34] crypto: ccree - remove struct cc_sram_ctx Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 19/34] crypto: ccree - remove struct cc_debugfs_ctx Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 20/34] crypto: ccree - remove struct buff_mgr_handle Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 21/34] crypto: ccree - remove struct cc_cipher_handle Geert Uytterhoeven
2020-02-11 18:19 ` Geert Uytterhoeven [this message]
2020-02-11 18:19 ` [PATCH v2 23/34] crypto: ccree - remove bogus kerneldoc markers Geert Uytterhoeven
2020-02-11 18:44   ` Sergei Shtylyov
2020-02-11 18:19 ` [PATCH v2 24/34] crypto: ccree - improve kerneldoc in cc_hw_queue_defs.h Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 25/34] crypto: ccree - improve kerneldoc in cc_buffer_mgr.c Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 26/34] crypto: ccree - improve kerneldoc in cc_hash.[ch] Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 27/34] crypto: ccree - improve kerneldoc in cc_request_mgr.[ch] Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 28/34] crypto: ccree - improve kerneldoc in cc_sram_mgr.[ch] Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 29/34] crypto: ccree - spelling s/Crytpcell/Cryptocell/ Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 30/34] crypto: ccree - grammar s/not room/no room/ Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 31/34] crypto: ccree - use existing dev helper in init_cc_resources() Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 32/34] crypto: ccree - use devm_k[mz]alloc() for AEAD data Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 33/34] crypto: ccree - use devm_k[mz]alloc() for cipher data Geert Uytterhoeven
2020-02-11 18:19 ` [PATCH v2 34/34] crypto: ccree - use devm_kzalloc() for hash data Geert Uytterhoeven
     [not found] ` <CAOtvUMfs84VXAecVNShoEg-CU6APjyiVTUBkogpFq_c3fbaX+Q@mail.gmail.com>
2020-02-13  7:47   ` [PATCH v2 00/34] crypto: ccree - miscellaneous fixes and improvements Geert Uytterhoeven
2020-02-19 15:41     ` Gilad Ben-Yossef
2020-02-20 12:29 ` Gilad Ben-Yossef
2020-02-22  1:42 ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200211181928.15178-23-geert+renesas@glider.be \
    --to=geert+renesas@glider.be \
    --cc=davem@davemloft.net \
    --cc=gilad@benyossef.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Renesas-SoC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-renesas-soc/0 linux-renesas-soc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-renesas-soc linux-renesas-soc/ https://lore.kernel.org/linux-renesas-soc \
		linux-renesas-soc@vger.kernel.org
	public-inbox-index linux-renesas-soc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-renesas-soc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git