crypto: starfive - Add drivers for crypto engine
Subsystems (5)
Jia Jie Ho
maintainerv8 cover crypto: starfive - Add drivers for crypto engine
This patch series adds kernel driver support for StarFive JH7110 crypto engine. The first patch adds Documentations for the device and Patch 2 adds device probe and DMA init for the module. Patch 3 adds crypto and DMA dts node for VisionFive 2 board. Patch 4 adds hash/hmac support to the module.
Patch 3 needs to be applied on top of:
https://lore.kernel.org/lkml/[email protected]/
Patch 4 needs to be applied on top of:
https://lore.kernel.org/linux-crypto/[email protected]/T/#u
Changes v7->v8
- Enable COMPILE_TEST in Kconfig (Herbert)
- Fix compile_test warning on 'long unsigned int' to 'unsigned int' conversion (Herbert)
Changes v6->v7
- Remove NULL assignment as struct is kzalloc()-ed (Christophe)
- Do clk_disable_unprepare and assert reset if probe failed (Christophe)
- Remove unnecessary null pointer check (Christophe)
- Update module name in Kconfig description (Christophe)
Changes v5->v6
- Remove set_crypt in export as request will have been created by init/updated calls (Herbert)
- Use new helper to set statesize of crypto_ahash (Herbert)
- Use crypto_ahash_blocksize instead of crypto_ahash_tfm (Herbert)
- Switch to init_tfm/exit_tfm instead of cra_init/cra_exit (Herbert)
Changes v4->v5
- Schedule tasklet from IRQ handler instead of using completion to sync events (Herbert)
Changes v3->v4:
- Use fallback for non-aligned cases as hardware doesn't support hashing piece-meal (Herbert)
- Use ahash_request_set_* helpers to update members of ahash_request (Herbert)
- Set callbacks for async fallback (Herbert)
- Remove completion variable and use dma_callback to do the rest of processing instead. (Herbert)
Changes v2->v3:
- Only implement digest and use fallback for other ops (Herbert)
- Use interrupt instead of polling for hash complete (Herbert)
- Remove manual data copy from out-of-bound memory location as it will be handled by DMA API. (Christoph & Herbert)
Changes v1->v2:
- Fixed yaml filename and format (Krzysztof)
- Removed unnecessary property names in yaml (Krzysztof)
- Moved of_device_id table close to usage (Krzysztof)
- Use dev_err_probe for error returns (Krzysztof)
- Dropped redundant readl and writel wrappers (Krzysztof)
- Updated commit signed offs (Conor)
- Dropped redundant node in dts, module set to on in dtsi (Conor)
Jia Jie Ho (4):
dt-bindings: crypto: Add StarFive crypto module
crypto: starfive - Add crypto engine support
riscv: dts: starfive: Add crypto and DMA node for VisionFive 2
crypto: starfive - Add hash and HMAC support
.../crypto/starfive,jh7110-crypto.yaml | 70 ++ MAINTAINERS | 7 + arch/riscv/boot/dts/starfive/jh7110.dtsi | 28 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/starfive/Kconfig | 21 + drivers/crypto/starfive/Makefile | 4 + drivers/crypto/starfive/jh7110-cryp.c | 240 +++++ drivers/crypto/starfive/jh7110-cryp.h | 127 +++ drivers/crypto/starfive/jh7110-hash.c | 892 ++++++++++++++++++ 10 files changed, 1391 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/starfive,jh7110-crypto.yaml create mode 100644 drivers/crypto/starfive/Kconfig create mode 100644 drivers/crypto/starfive/Makefile create mode 100644 drivers/crypto/starfive/jh7110-cryp.c create mode 100644 drivers/crypto/starfive/jh7110-cryp.h create mode 100644 drivers/crypto/starfive/jh7110-hash.c
Signature · 1 line
2.25.1
Jia Jie Ho
maintainerPATCH v8 1/4 dt-bindings: crypto: Add StarFive crypto module
Add documentation to describe StarFive cryptographic engine.
--- .../crypto/starfive,jh7110-crypto.yaml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/starfive,jh7110-crypto.yaml
Documentation/devicetree/bindings/crypto/starfive,jh7110-crypto.yaml new file +70 -0
@@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/starfive,jh7110-crypto.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive Cryptographic Module + +maintainers: + - Jia Jie Ho <[email protected]> + - William Qiu <[email protected]> + +properties: + compatible: + const: starfive,jh7110-crypto + + reg: + maxItems: 1 + + clocks: + items: + - description: Hardware reference clock + - description: AHB reference clock + + clock-names: + items: + - const: hclk + - const: ahb + + interrupts: + maxItems: 1 + + resets: + maxItems: 1 + + dmas: + items: + - description: TX DMA channel + - description: RX DMA channel + + dma-names: + items: + - const: tx + - const: rx + +required: + - compatible + - reg + - clocks + - clock-names + - resets + - dmas + - dma-names + +additionalProperties: false + +examples: + - | + crypto: crypto@16000000 { + compatible = "starfive,jh7110-crypto"; + reg = <0x16000000 0x4000>; + clocks = <&clk 15>, <&clk 16>; + clock-names = "hclk", "ahb"; + interrupts = <28>; + resets = <&reset 3>; + dmas = <&dma 1 2>, + <&dma 0 2>; + dma-names = "tx", "rx"; + }; +...
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Jia Jie Ho
maintainerPATCH v8 2/4 crypto: starfive - Add crypto engine support
In reply to Jia Jie HoAdding device probe and DMA init for StarFive cryptographic module.
--- MAINTAINERS | 7 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/starfive/Kconfig | 17 +++ drivers/crypto/starfive/Makefile | 4 + drivers/crypto/starfive/jh7110-cryp.c | 201 ++++++++++++++++++++++++++ drivers/crypto/starfive/jh7110-cryp.h | 63 ++++++++ 7 files changed, 294 insertions(+) create mode 100644 drivers/crypto/starfive/Kconfig create mode 100644 drivers/crypto/starfive/Makefile create mode 100644 drivers/crypto/starfive/jh7110-cryp.c create mode 100644 drivers/crypto/starfive/jh7110-cryp.h
MAINTAINERS +7 -0
@@ -19920,6 +19920,13 @@ F: Documentation/devicetree/bindings/clock/starfive,jh71*.yaml F: drivers/clk/starfive/clk-starfive-jh71* F: include/dt-bindings/clock/starfive?jh71*.h +STARFIVE CRYPTO DRIVER +M: Jia Jie Ho <[email protected]> +M: William Qiu <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/crypto/starfive* +F: drivers/crypto/starfive/ + STARFIVE JH71X0 PINCTRL DRIVERS M: Emil Renner Berthing <[email protected]> M: Jianlong Huang <[email protected]>
drivers/crypto/Kconfig +1 -0
@@ -822,5 +822,6 @@ config CRYPTO_DEV_SA2UL source "drivers/crypto/keembay/Kconfig" source "drivers/crypto/aspeed/Kconfig" +source "drivers/crypto/starfive/Kconfig" endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
@@ -52,3 +52,4 @@ obj-y += xilinx/ obj-y += hisilicon/ obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic/ obj-y += keembay/ +obj-y += starfive/
drivers/crypto/starfive/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# +# StarFive crypto drivers configuration +# + +config CRYPTO_DEV_JH7110 + tristate "StarFive JH7110 cryptographic engine driver" + depends on SOC_STARFIVE || COMPILE_TEST + select CRYPTO_ENGINE + select ARM_AMBA + select DMADEVICES + select AMBA_PL08X + help + Support for StarFive JH7110 crypto hardware acceleration engine. + This module provides acceleration for public key algo, + skciphers, AEAD and hash functions. + + If you choose 'M' here, this module will be called jh7110-crypto.
drivers/crypto/starfive/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_CRYPTO_DEV_JH7110) += jh7110-crypto.o +jh7110-crypto-objs := jh7110-cryp.o
drivers/crypto/starfive/jh7110-cryp.c new file +201 -0
201 lines not on this page · raw message
drivers/crypto/starfive/jh7110-cryp.h new file +63 -0
63 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v8 2/4] crypto: starfive - Add crypto engine support
drivers/crypto/starfive/Kconfig line 9
Quoted 5 lines · Jia Jie Ho
drivers/crypto/starfive/Kconfig new file +5
-0+config CRYPTO_DEV_JH7110 + tristate "StarFive JH7110 cryptographic engine driver" + depends on SOC_STARFIVE || COMPILE_TEST + select CRYPTO_ENGINE + select ARM_AMBA
I have yet to bisect, but I think this has broken the build on RISC-V:drivers/dma/pl330.c:1053:13: error: redefinition of '_start' as different kind of symbol static bool _start(struct pl330_thread *thrd)
^
arch/riscv/include/asm/sections.h:11:13: note: previous definition is here
extern char _start[];
^
drivers/dma/pl330.c:1705:10: error: called object type 'char[]' is not a function or function pointer
_start(thrd);
~~~~~~^
drivers/dma/pl330.c:2092:9: error: called object type 'char[]' is not a function or function pointer
_start(pch->thread);
~~~~~~^
drivers/dma/pl330.c:2110:11: error: called object type 'char[]' is not a function or function pointer
_start(pch->thread);
~~~~~~^4 errors generated.
The pl330 dma driver depends on ARM_AMBA.
Cheers,
Conor.
Jia Jie Ho
maintainerPATCH v8 3/4 riscv: dts: starfive: Add crypto and DMA node for VisionFive 2
In reply to Jia Jie HoAdd StarFive cryptographic module and dedicated DMA controller node to VisionFive 2 SoCs.
--- arch/riscv/boot/dts/starfive/jh7110.dtsi | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
arch/riscv/boot/dts/starfive/jh7110.dtsi +28 -0
@@ -570,5 +570,33 @@ voutcrg: clock-controller@295c0000 { #reset-cells = <1>; power-domains = <&pwrc JH7110_PD_VOUT>; }; + + sdma: dma@16008000 { + compatible = "arm,pl080", "arm,primecell"; + arm,primecell-periphid = <0x00041080>; + reg = <0x0 0x16008000 0x0 0x4000>; + interrupts = <29>; + clocks = <&stgcrg JH7110_STGCLK_SEC_AHB>, + <&stgcrg JH7110_STGCLK_SEC_MISC_AHB>; + clock-names = "hclk", "apb_pclk"; + resets = <&stgcrg JH7110_STGRST_SEC_AHB>; + lli-bus-interface-ahb1; + mem-bus-interface-ahb1; + memcpy-burst-size = <256>; + memcpy-bus-width = <32>; + #dma-cells = <2>; + }; + + crypto: crypto@16000000 { + compatible = "starfive,jh7110-crypto"; + reg = <0x0 0x16000000 0x0 0x4000>; + clocks = <&stgcrg JH7110_STGCLK_SEC_AHB>, + <&stgcrg JH7110_STGCLK_SEC_MISC_AHB>; + clock-names = "hclk", "ahb"; + interrupts = <28>; + resets = <&stgcrg JH7110_STGRST_SEC_AHB>; + dmas = <&sdma 1 2>, <&sdma 0 2>; + dma-names = "tx", "rx"; + }; }; };
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Jia Jie Ho
maintainerPATCH v8 4/4 crypto: starfive - Add hash and HMAC support
In reply to Jia Jie HoAdding hash/HMAC support for SHA-2 and SM3 to StarFive cryptographic module.
--- drivers/crypto/starfive/Kconfig | 4 + drivers/crypto/starfive/Makefile | 2 +- drivers/crypto/starfive/jh7110-cryp.c | 39 ++ drivers/crypto/starfive/jh7110-cryp.h | 70 +- drivers/crypto/starfive/jh7110-hash.c | 892 ++++++++++++++++++++++++++ 5 files changed, 1003 insertions(+), 4 deletions(-) create mode 100644 drivers/crypto/starfive/jh7110-hash.c
drivers/crypto/starfive/Kconfig +4 -0
@@ -6,6 +6,10 @@ config CRYPTO_DEV_JH7110 tristate "StarFive JH7110 cryptographic engine driver" depends on SOC_STARFIVE || COMPILE_TEST select CRYPTO_ENGINE + select CRYPTO_HMAC + select CRYPTO_SHA256 + select CRYPTO_SHA512 + select CRYPTO_SM3_GENERIC select ARM_AMBA select DMADEVICES select AMBA_PL08X
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-crypto-objs := jh7110-cryp.o jh7110-hash.o
drivers/crypto/starfive/jh7110-cryp.c +39 -0
@@ -79,10 +79,25 @@ static void starfive_dma_cleanup(struct starfive_cryp_dev *cryp)dma_release_channel (cryp->rx); } +static irqreturn_t starfive_cryp_irq (int irq,void *priv) +{ +u32 status; +struct starfive_cryp_dev *cryp = (struct starfive_cryp_dev *)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 ); +tasklet_schedule (&cryp->hash_done); + } + +return IRQ_HANDLED ; +} +static int starfive_cryp_probe (struct platform_device *pdev) {struct starfive_cryp_dev *cryp;struct resource *res; +int irq;int ret; cryp =devm_kzalloc (&pdev->dev,sizeof (*cryp),GFP_KERNEL );
@@ -97,6 +112,8 @@ static int starfive_cryp_probe(struct platform_device *pdev)return dev_err_probe (&pdev->dev,PTR_ERR (cryp->base),"Error remapping memory for platform device\n" ); +tasklet_init (&cryp->hash_done, starfive_hash_done_task, (unsigned long )cryp); + cryp->phys_base = res->start; cryp->dma_maxburst =32 ;
@@ -115,6 +132,16 @@ 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" ); + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + ret =devm_request_irq (&pdev->dev, irq, starfive_cryp_irq,0 , pdev->name, + (void *)cryp); +if (ret) +return dev_err_probe (&pdev->dev, irq, +"Failed to register interrupt handler\n" ); +clk_prepare_enable (cryp->hclk);clk_prepare_enable (cryp->ahb);reset_control_deassert (cryp->rst);
@@ -142,8 +169,14 @@ static int starfive_cryp_probe(struct platform_device *pdev)if (ret) goto err_engine_start; + ret =starfive_hash_register_algs (); +if (ret) + goto err_algs_hash; +return 0 ; +err_algs_hash: +crypto_engine_stop (cryp->engine); err_engine_start:crypto_engine_exit (cryp->engine); err_engine:
@@ -156,6 +189,8 @@ static int starfive_cryp_probe(struct platform_device *pdev)clk_disable_unprepare (cryp->hclk);clk_disable_unprepare (cryp->ahb);reset_control_assert (cryp->rst); + +tasklet_kill (&cryp->hash_done); err_probe_defer:return ret; }
@@ -164,6 +199,10 @@ static int starfive_cryp_remove(struct platform_device *pdev) {struct starfive_cryp_dev *cryp =platform_get_drvdata (pdev); +starfive_hash_unregister_algs (); + +tasklet_kill (&cryp->hash_done); +crypto_engine_stop (cryp->engine);crypto_engine_exit (cryp->engine);
drivers/crypto/starfive/jh7110-cryp.h +67 -3
104 lines not on this page · raw message
drivers/crypto/starfive/jh7110-hash.c new file +892 -0
892 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Herbert Xu
maintainerQuoted 73 lines · Jia Jie Ho
This patch series adds kernel driver support for StarFive JH7110 crypto engine. The first patch adds Documentations for the device and Patch 2 adds device probe and DMA init for the module. Patch 3 adds crypto and DMA dts node for VisionFive 2 board. Patch 4 adds hash/hmac support to the module.
Patch 3 needs to be applied on top of:
https://lore.kernel.org/lkml/[email protected]/Patch 4 needs to be applied on top of:
https://lore.kernel.org/linux-crypto/[email protected]/T/#uChanges
v7->v8
- EnableCOMPILE_TESTinKconfig(Herbert)
- Fixcompile_testwarning on 'long unsigned int' to 'unsigned int' conversion (Herbert)Changes
v6->v7
- Remove NULL assignment as struct is kzalloc()-ed (Christophe)
- Doclk_disable_unprepareand assert reset if probe failed (Christophe)
- Remove unnecessary null pointer check (Christophe)
- Update module name inKconfigdescription (Christophe)Changes
v5->v6
- Removeset_cryptin export as request will have been created by init/updated calls (Herbert)
- Use new helper to set statesize ofcrypto_ahash(Herbert)
- Usecrypto_ahash_blocksizeinstead ofcrypto_ahash_tfm(Herbert)
- Switch to init_tfm/exit_tfm instead of cra_init/cra_exit (Herbert)Changes
v4->v5
- Schedule tasklet from IRQ handler instead of using completion to sync events (Herbert)Changes
v3->v4:
- Use fallback for non-aligned cases as hardware doesn't support hashing piece-meal (Herbert)
- Use ahash_request_set_* helpers to update members ofahash_request(Herbert)
- Set callbacks for async fallback (Herbert)
- Remove completion variable and usedma_callbackto do the rest of processing instead. (Herbert)Changes
v2->v3:
- Only implement digest and use fallback for other ops (Herbert)
- Use interrupt instead of polling for hash complete (Herbert)
- Remove manual data copy from out-of-bound memory location as it will be handled by DMA API. (Christoph & Herbert)Changes
v1->v2:
- Fixed yaml filename and format (Krzysztof)
- Removed unnecessary property names in yaml (Krzysztof)
- Movedof_device_idtable close to usage (Krzysztof)
- Usedev_err_probefor error returns (Krzysztof)
- Dropped redundant readl and writel wrappers (Krzysztof)
- Updated commit signed offs (Conor)
- Dropped redundant node in dts, module set to on in dtsi (Conor)Jia Jie Ho (4):
dt-bindings: crypto: Add StarFive crypto module
crypto: starfive - Add crypto engine support
riscv: dts: starfive: Add crypto and DMA node for VisionFive 2
crypto: starfive - Add hash and HMAC support.../crypto/starfive,jh7110-crypto.yaml | 70 ++ MAINTAINERS | 7 + arch/riscv/boot/dts/starfive/jh7110.dtsi | 28 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/starfive/Kconfig | 21 + drivers/crypto/starfive/Makefile | 4 + drivers/crypto/starfive/jh7110-cryp.c | 240 +++++ drivers/crypto/starfive/jh7110-cryp.h | 127 +++
Quoted 11 lines
drivers/crypto/starfive/jh7110-hash.c | 892 ++++++++++++++++++ 10 files changed, 1391 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/starfive,jh7110-crypto.yaml create mode 100644 drivers/crypto/starfive/Kconfig create mode 100644 drivers/crypto/starfive/Makefile create mode 100644 drivers/crypto/starfive/jh7110-cryp.c create mode 100644 drivers/crypto/starfive/jh7110-cryp.h create mode 100644 drivers/crypto/starfive/jh7110-hash.cSignature · 1 line
2.25.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
Hey Herbert,
Quoted 8 lines · Herbert Xu
Quoted 5 lines · Jia Jie Ho
Jia Jie Ho (4):
dt-bindings: crypto: Add StarFive crypto module
crypto: starfive - Add crypto engine support
riscv: dts: starfive: Add crypto and DMA node for VisionFive 2
crypto: starfive - Add hash and HMAC supportAll applied. Thanks.
Can you drop the ea1aeba1b2e07b82f9eb7cce5cb169263a77d046 ("riscv: dts:
starfive: Add crypto and DMA node for VisionFive 2") please? It depends on a clock node that has not been added to the dts yet, and will break the dtb build:
Error: arch/riscv/boot/dts/starfive/jh7110.dtsi:505.22-23 syntax error FATAL ERROR: Unable to parse input tree
Thanks,
Conor.
Herbert Xu
maintainerQuoted 8 lines · Conor Dooley
Can you drop the
ea1aeba1b2e07b82f9eb7cce5cb169263a77d046("riscv: dts:
starfive: Add crypto and DMA node for VisionFive 2") please? It depends on a clock node that has not been added to the dts yet, and will break the dtb build:Error: arch/riscv/boot/dts/starfive/jh7110.dtsi:505.22-23 syntax error FATAL ERROR: Unable to parse input tree
OK, I've dropped it.
Cheers,
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