crypto: starfive - Add RSA algo to drivers
Subsystems (2)
Jia Jie Ho
maintainerv3 cover crypto: starfive - Add RSA algo to drivers
This patch series adds RSA support to VisionFive 2 SoCs. Patch 1 updates current irq handling of hash module to prevent conflict among other crypto modules. Patch 2 adds RSA algo to crypto engine drivers.
Changes v2 -> v3:
- Rearranged irq mask clear sequence to prevent spurious interrupt from completing pka_done prematurely (Herbert)
Changes v1 -> v2:
- Removed ASYNC flag (Herbert)
Jia Jie Ho (2):
crypto: starfive - Update hash module irq handling
crypto: starfive - Add RSA algo support
drivers/crypto/starfive/Kconfig | 1 + drivers/crypto/starfive/Makefile | 2 +- drivers/crypto/starfive/jh7110-cryp.c | 20 +- drivers/crypto/starfive/jh7110-cryp.h | 45 ++ drivers/crypto/starfive/jh7110-hash.c | 9 +- drivers/crypto/starfive/jh7110-rsa.c | 617 ++++++++++++++++++++++++++ 6 files changed, 691 insertions(+), 3 deletions(-) create mode 100644 drivers/crypto/starfive/jh7110-rsa.c
Signature · 1 line
2.34.1
Jia Jie Ho
maintainerPATCH v3 1/2 crypto: starfive - Update hash module irq handling
Hash driver needs to check the value of irq mask register before writing as it will mask irq of other modules.
--- drivers/crypto/starfive/jh7110-hash.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/crypto/starfive/jh7110-hash.c +8 -1
@@ -39,6 +39,7 @@#define STARFIVE_HASH_SHAWKLEN (STARFIVE_HASH_REGS_OFFSET + 0x24)#define STARFIVE_HASH_BUFLEN SHA512_BLOCK_SIZE +#define STARFIVE_HASH_RESET 0x2static inline int starfive_hash_wait_busy (struct starfive_cryp_ctx *ctx) {
@@ -95,6 +96,7 @@ static void starfive_hash_start(void *param)struct starfive_cryp_dev *cryp = ctx->cryp;union starfive_alg_cr alg_cr;union starfive_hash_csr csr; +u32 stat;dma_unmap_sg (cryp->dev, rctx->in_sg, rctx->in_sg_len,DMA_TO_DEVICE );
@@ -107,7 +109,9 @@ static void starfive_hash_start(void *param) csr.firstb =0 ; csr.final =1 ; -writel (~STARFIVE_IE_MASK_HASH_DONE , cryp->base +STARFIVE_IE_MASK_OFFSET ); + stat =readl (cryp->base +STARFIVE_IE_MASK_OFFSET ); + stat &= ~STARFIVE_IE_MASK_HASH_DONE ; +writel (stat, cryp->base +STARFIVE_IE_MASK_OFFSET );writel (csr.v, cryp->base +STARFIVE_HASH_SHACSR ); }
@@ -223,6 +227,9 @@ void starfive_hash_done_task(unsigned long param)if (!err) err =starfive_hash_copy_hash (cryp->req.hreq); +/* Reset to clear hash_done in irq register*/ +writel (STARFIVE_HASH_RESET , cryp->base +STARFIVE_HASH_SHACSR ); +crypto_finalize_hash_request (cryp->engine, cryp->req.hreq, err); }
Signature · 1 line
2.34.1
Jia Jie Ho
maintainerPATCH v3 2/2 crypto: starfive - Add RSA algo support
In reply to Jia Jie HoAdding RSA enc/dec and sign/verify feature for StarFive cryptographic module. The module only supports mod sizes up to 2048, therefore calculations more than that will use fallback algo.
--- drivers/crypto/starfive/Kconfig | 1 + drivers/crypto/starfive/Makefile | 2 +- drivers/crypto/starfive/jh7110-cryp.c | 20 +- drivers/crypto/starfive/jh7110-cryp.h | 45 ++ drivers/crypto/starfive/jh7110-rsa.c | 617 ++++++++++++++++++++++++++ 5 files changed, 683 insertions(+), 2 deletions(-) create mode 100644 drivers/crypto/starfive/jh7110-rsa.c
drivers/crypto/starfive/Kconfig +1 -0
@@ -11,6 +11,7 @@ config CRYPTO_DEV_JH7110 select CRYPTO_SHA256 select CRYPTO_SHA512 select CRYPTO_SM3_GENERIC + select CRYPTO_RSA help Support for StarFive JH7110 crypto hardware acceleration engine. This module provides acceleration for public key algo,
drivers/crypto/starfive/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_CRYPTO_DEV_JH7110) += jh7110-crypto.o -jh7110-crypto-objs := jh7110-cryp.o jh7110-hash.o +jh7110-crypto-objs := jh7110-cryp.o jh7110-hash.o jh7110-rsa.o
drivers/crypto/starfive/jh7110-cryp.c +19 -1
@@ -86,10 +86,19 @@ static irqreturn_t starfive_cryp_irq(int irq, void *priv) status =readl (cryp->base +STARFIVE_IE_FLAG_OFFSET );if (status &STARFIVE_IE_FLAG_HASH_DONE ) { -writel (STARFIVE_IE_MASK_HASH_DONE , cryp->base +STARFIVE_IE_MASK_OFFSET ); + status =readl (cryp->base +STARFIVE_IE_MASK_OFFSET ); + status |=STARFIVE_IE_MASK_HASH_DONE ; +writel (status, cryp->base +STARFIVE_IE_MASK_OFFSET );tasklet_schedule (&cryp->hash_done); } +if (status &STARFIVE_IE_FLAG_PKA_DONE ) { + status =readl (cryp->base +STARFIVE_IE_MASK_OFFSET ); + status |=STARFIVE_IE_MASK_PKA_DONE ; +writel (status, cryp->base +STARFIVE_IE_MASK_OFFSET ); +complete (&cryp->pka_done); + } +return IRQ_HANDLED ; }
@@ -132,6 +141,8 @@ static int starfive_cryp_probe(struct platform_device *pdev)return dev_err_probe (&pdev->dev,PTR_ERR (cryp->rst),"Error getting hardware reset line\n" ); +init_completion (&cryp->pka_done); + irq =platform_get_irq (pdev,0 );if (irq <0 )return irq;
@@ -173,8 +184,14 @@ static int starfive_cryp_probe(struct platform_device *pdev)if (ret) goto err_algs_hash; + ret =starfive_rsa_register_algs (); +if (ret) + goto err_algs_rsa; +return 0 ; +err_algs_rsa: +starfive_hash_unregister_algs (); err_algs_hash:crypto_engine_stop (cryp->engine); err_engine_start:
@@ -200,6 +217,7 @@ static int starfive_cryp_remove(struct platform_device *pdev)struct starfive_cryp_dev *cryp =platform_get_drvdata (pdev);starfive_hash_unregister_algs (); +starfive_rsa_unregister_algs ();tasklet_kill (&cryp->hash_done);
drivers/crypto/starfive/jh7110-cryp.h +45 -0
89 lines not on this page · raw message
drivers/crypto/starfive/jh7110-rsa.c new file +617 -0
617 lines not on this page · raw message
Signature · 1 line
2.34.1
Herbert Xu
maintainerQuoted 15 lines · Jia Jie Ho
This patch series adds RSA support to VisionFive 2 SoCs. Patch 1 updates current irq handling of hash module to prevent conflict among other crypto modules. Patch 2 adds RSA algo to crypto engine drivers.
Changes v2 -> v3:
- Rearranged irq mask clear sequence to prevent spurious interrupt from completingpka_doneprematurely (Herbert)Changes v1 -> v2:
- Removed ASYNC flag (Herbert)Jia Jie Ho (2):
crypto: starfive - Update hash module irq handling
crypto: starfive - Add RSA algo support
Quoted 11 lines
drivers/crypto/starfive/Kconfig | 1 + drivers/crypto/starfive/Makefile | 2 +- drivers/crypto/starfive/jh7110-cryp.c | 20 +- drivers/crypto/starfive/jh7110-cryp.h | 45 ++ drivers/crypto/starfive/jh7110-hash.c | 9 +- drivers/crypto/starfive/jh7110-rsa.c | 617 ++++++++++++++++++++++++++ 6 files changed, 691 insertions(+), 3 deletions(-) create mode 100644 drivers/crypto/starfive/jh7110-rsa.cSignature · 1 line
2.34.1
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt