Add Tegra Security Engine driver
Subsystems (6)
Akhil R
maintainerv4 cover Add Tegra Security Engine driver
Add support for Tegra Security Engine which can accelerates various crypto algorithms. The Engine has two separate instances within for AES and HASH algorithms respectively.
The driver registers two crypto engines - one for AES and another for HASH algorithms and these operate independently and both uses the host1x bus. Additionally, it provides hardware-assisted key protection for up to 15 symmetric keys which it can use for the cipher operations.
v3->v4:
* Remove unused header in bindings doc.
* Update commit message in host1x change.
* Fix test bot warning.v2->v3:
* Update compatible in driver and device trees.
* Remove extra new lines and symbols in binding doc. v1->v2:
* Update probe errors with 'dev_err_probe'.
* Clean up function prototypes and redundant prints.
* Remove readl/writel wrappers.
* Fix test bot warnings.
Akhil R (5):
dt-bindings: crypto: Add Tegra Security Engine
gpu: host1x: Add Tegra SE to SID table
crypto: tegra: Add Tegra Security Engine driver
arm64: defconfig: Enable Tegra Security Engine
arm64: tegra: Add Tegra Security Engine DT nodes
.../crypto/nvidia,tegra234-se-aes.yaml | 52 + .../crypto/nvidia,tegra234-se-hash.yaml | 52 + MAINTAINERS | 5 + arch/arm64/boot/dts/nvidia/tegra234.dtsi | 16 + arch/arm64/configs/defconfig | 1 + drivers/crypto/Kconfig | 8 + drivers/crypto/Makefile | 1 + drivers/crypto/tegra/Makefile | 9 + drivers/crypto/tegra/tegra-se-aes.c | 1932 +++++++++++++++++ drivers/crypto/tegra/tegra-se-hash.c | 1022 +++++++++ drivers/crypto/tegra/tegra-se-key.c | 156 ++ drivers/crypto/tegra/tegra-se-main.c | 439 ++++ drivers/crypto/tegra/tegra-se.h | 569 +++++ drivers/gpu/host1x/dev.c | 24 + 14 files changed, 4286 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/nvidia,tegra234-se-aes.yaml create mode 100644 Documentation/devicetree/bindings/crypto/nvidia,tegra234-se-hash.yaml create mode 100644 drivers/crypto/tegra/Makefile create mode 100644 drivers/crypto/tegra/tegra-se-aes.c create mode 100644 drivers/crypto/tegra/tegra-se-hash.c create mode 100644 drivers/crypto/tegra/tegra-se-key.c create mode 100644 drivers/crypto/tegra/tegra-se-main.c create mode 100644 drivers/crypto/tegra/tegra-se.h
Signature · 1 line
2.17.1
Akhil R
maintainerPATCH v4 1/5 dt-bindings: crypto: Add Tegra Security Engine
Add DT binding document for Tegra Security Engine.
The AES and HASH algorithms are handled independently by separate engines within the Security Engine. These engines are registered as two separate crypto engine drivers.
--- .../crypto/nvidia,tegra234-se-aes.yaml | 52 +++++++++++++++++++ .../crypto/nvidia,tegra234-se-hash.yaml | 52 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/nvidia,tegra234-se-aes.yaml create mode 100644 Documentation/devicetree/bindings/crypto/nvidia,tegra234-se-hash.yaml
Documentation/devicetree/bindings/crypto/nvidia,tegra234-se-aes.yaml new file +52 -0
@@ -0,0 +1,52 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/nvidia,tegra234-se-aes.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NVIDIA Tegra Security Engine for AES algorithms + +description: + The Tegra Security Engine accelerates the following AES encryption/decryption + algorithms - AES-ECB, AES-CBC, AES-OFB, AES-XTS, AES-CTR, AES-GCM, AES-CCM, + AES-CMAC + +maintainers: + - Akhil R <[email protected]> + +properties: + compatible: + const: nvidia,tegra234-se-aes + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + iommus: + maxItems: 1 + + dma-coherent: true + +required: + - compatible + - reg + - clocks + - iommus + +additionalProperties: false + +examples: + - | + #include <dt-bindings/memory/tegra234-mc.h> + #include <dt-bindings/clock/tegra234-clock.h> + + crypto@15820000 { + compatible = "nvidia,tegra234-se-aes"; + reg = <0x15820000 0x10000>; + clocks = <&bpmp TEGRA234_CLK_SE>; + iommus = <&smmu TEGRA234_SID_SES_SE1>; + dma-coherent; + }; +...
Documentation/devicetree/bindings/crypto/nvidia,tegra234-se-hash.yaml new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.17.1
Akhil R
maintainerPATCH v4 2/5 gpu: host1x: Add Tegra SE to SID table
In reply to Akhil RAdd Tegra Security Engine details to the SID table in host1x driver. These entries are required to be in place to configure the stream ID for SE. Register writes to stream ID registers fail otherwise.
--- drivers/gpu/host1x/dev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/gpu/host1x/dev.c +24 -0
@@ -214,6 +214,30 @@ static const struct host1x_info host1x07_info = {* and firmware stream ID in the MMIO path table. */ static const struct host1x_sid_entry tegra234_sid_table[] = { + { +/* SE2 MMIO */ + .base =0x1658 , + .offset =0x90 , + .limit =0x90 + }, + { +/* SE4 MMIO */ + .base =0x1660 , + .offset =0x90 , + .limit =0x90 + }, + { +/* SE2 channel */ + .base =0x1738 , + .offset =0x90 , + .limit =0x90 + }, + { +/* SE4 channel */ + .base =0x1740 , + .offset =0x90 , + .limit =0x90 + }, {/* VIC channel */ .base =0x17b8 ,
Signature · 1 line
2.17.1
Akhil R
maintainerPATCH v4 3/5 crypto: tegra: Add Tegra Security Engine driver
In reply to Akhil RAdd support for Tegra Security Engine which can accelerate various crypto algorithms. The Engine has two separate instances within for AES and HASH algorithms respectively.
The driver registers two crypto engines - one for AES and another for HASH algorithms and these operate independently and both uses the host1x bus. Additionally, it provides hardware-assisted key protection for up to 15 symmetric keys which it can use for the cipher operations.
--- MAINTAINERS | 5 + drivers/crypto/Kconfig | 8 + drivers/crypto/Makefile | 1 + drivers/crypto/tegra/Makefile | 9 + drivers/crypto/tegra/tegra-se-aes.c | 1932 ++++++++++++++++++++++++++ drivers/crypto/tegra/tegra-se-hash.c | 1022 ++++++++++++++ drivers/crypto/tegra/tegra-se-key.c | 156 +++ drivers/crypto/tegra/tegra-se-main.c | 439 ++++++ drivers/crypto/tegra/tegra-se.h | 569 ++++++++ 9 files changed, 4141 insertions(+) create mode 100644 drivers/crypto/tegra/Makefile create mode 100644 drivers/crypto/tegra/tegra-se-aes.c create mode 100644 drivers/crypto/tegra/tegra-se-hash.c create mode 100644 drivers/crypto/tegra/tegra-se-key.c create mode 100644 drivers/crypto/tegra/tegra-se-main.c create mode 100644 drivers/crypto/tegra/tegra-se.h
MAINTAINERS +5 -0
@@ -21462,6 +21462,11 @@ M: Prashant Gaikwad <[email protected]> S: Supported F: drivers/clk/tegra/ +TEGRA CRYPTO DRIVERS +M: Akhil R <[email protected]> +S: Supported +F: drivers/crypto/tegra/* + TEGRA DMA DRIVERS M: Laxman Dewangan <[email protected]> M: Jon Hunter <[email protected]>
drivers/crypto/Kconfig +8 -0
@@ -659,6 +659,14 @@ config CRYPTO_DEV_ROCKCHIP_DEBUG This will create /sys/kernel/debug/rk3288_crypto/stats for displaying the number of requests per algorithm and other internal stats. +config CRYPTO_DEV_TEGRA + tristate "Enable Tegra Security Engine" + depends on TEGRA_HOST1X + select CRYPTO_ENGINE + + help + Select this to enable Tegra Security Engine which accelerates various + AES encryption/decryption and HASH algorithms. config CRYPTO_DEV_ZYNQMP_AES tristate "Support for Xilinx ZynqMP AES hw accelerator"
drivers/crypto/Makefile +1 -0
@@ -41,6 +41,7 @@ obj-$(CONFIG_CRYPTO_DEV_SAHARA) += sahara.o obj-$(CONFIG_CRYPTO_DEV_SL3516) += gemini/ obj-y += stm32/ obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o +obj-$(CONFIG_CRYPTO_DEV_TEGRA) += tegra/ obj-$(CONFIG_CRYPTO_DEV_VIRTIO) += virtio/ obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/ obj-$(CONFIG_CRYPTO_DEV_BCM_SPU) += bcm/
drivers/crypto/tegra/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +tegra-se-objs := tegra-se-key.o tegra-se-main.o + +tegra-se-y += tegra-se-aes.o +tegra-se-y += tegra-se-hash.o + +obj-$(CONFIG_CRYPTO_DEV_TEGRA) += tegra-se.o
drivers/crypto/tegra/tegra-se-aes.c new file +1932 -0
1,932 lines not on this page · raw message
drivers/crypto/tegra/tegra-se-hash.c new file +1022 -0
1,022 lines not on this page · raw message
drivers/crypto/tegra/tegra-se-key.c new file +156 -0
5 lines not on this page · raw message
drivers/crypto/tegra/tegra-se-main.c new file +439 -0
439 lines not on this page · raw message
drivers/crypto/tegra/tegra-se.h new file +569 -0
569 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Herbert Xu
maintainerRe: [PATCH v4 3/5] crypto: tegra: Add Tegra Security Engine driver
drivers/crypto/tegra/tegra-se-hash.c line 407
Quoted 12 lines · Akhil R
drivers/crypto/tegra/tegra-se-hash.c new file +11
-0+static void tegra_sha_init_fallback (struct tegra_sha_ctx *ctx,const char *algname) +{ + ctx->fallback_tfm =crypto_alloc_ahash (algname,0 ,CRYPTO_ALG_ASYNC | +CRYPTO_ALG_NEED_FALLBACK ); + +if (IS_ERR (ctx->fallback_tfm)) { +dev_warn (ctx->se->dev,"failed to allocate fallback for %s %ld\n" , + algname,PTR_ERR (ctx->fallback_tfm)); + ctx->fallback_tfm =NULL ; + } +}
This should check that the fallback state size is smaller than that of tegra. As otherwise the fallback export/import will break.
Quoted 6 lines
drivers/crypto/tegra/tegra-se-hash.c new file +6
-0+static int tegra_sha_import (struct ahash_request *req,const void *in) +{ +struct tegra_sha_reqctx *rctx =ahash_request_ctx (req); +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); +struct tegra_sha_ctx *ctx =crypto_ahash_ctx (tfm); +int i;
drivers/crypto/tegra/tegra-se-hash.c line 613
Quoted 10 lines
drivers/crypto/tegra/tegra-se-hash.c new file +10
-0+ +if (ctx->fallback) +return tegra_sha_fallback_import (req, in); + +memcpy (rctx, in,sizeof (*rctx)); + +/* Paste all intermediate results */ +for (i =0 ; i <HASH_RESULT_REG_COUNT ; i++) +writel (rctx->result[i], + ctx->se->base + ctx->se->hw->regs->result + (i *4 ));
What happens when multiple requests of the same tfm import at the same time? Normally we don't actually touch the hardware in the import function. Instead, all the hard work happens at the end of the update function, which moves hardware state into the request object.
The import/export function then simply copies the request object state to the in/out buffer.
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
Akhil R
maintainerRE: [PATCH v4 3/5] crypto: tegra: Add Tegra Security Engine driver
Quoted 17 lines · Akhil R
Quoted 2 lines
+static void tegra_sha_init_fallback(struct
tegra_sha_ctx*ctx, const char*algname)
drivers/crypto/tegra/tegra-se-hash.c line 407
Quoted 10 lines
drivers/crypto/tegra/tegra-se-hash.c new file +10
-0+{ + ctx->fallback_tfm =crypto_alloc_ahash (algname,0 ,CRYPTO_ALG_ASYNC | +CRYPTO_ALG_NEED_FALLBACK ); + +if (IS_ERR (ctx->fallback_tfm)) { +dev_warn (ctx->se->dev,"failed to allocate fallback for %s %ld\n" , + algname,PTR_ERR (ctx->fallback_tfm)); + ctx->fallback_tfm =NULL ; + } +}This should check that the fallback state size is smaller than that of tegra. As otherwise the fallback export/import will break.
Okay. Got it. Will update.
Quoted 23 lines
Quoted 6 lines
drivers/crypto/tegra/tegra-se-hash.c new file +6
-0+static int tegra_sha_import (struct ahash_request *req,const void *in) +{ +struct tegra_sha_reqctx *rctx =ahash_request_ctx (req); +struct crypto_ahash *tfm =crypto_ahash_reqtfm (req); +struct tegra_sha_ctx *ctx =crypto_ahash_ctx (tfm); +int i;drivers/crypto/tegra/tegra-se-hash.c line 613
Quoted 10 lines
drivers/crypto/tegra/tegra-se-hash.c new file +10
-0+ +if (ctx->fallback) +return tegra_sha_fallback_import (req, in); + +memcpy (rctx, in,sizeof (*rctx)); + +/* Paste all intermediate results */ +for (i =0 ; i <HASH_RESULT_REG_COUNT ; i++) +writel (rctx->result[i], + ctx->se->base + ctx->se->hw->regs->result + (i *4 ));What happens when multiple requests of the same tfm import at the same time? Normally we don't actually touch the hardware in the import function. Instead, all the hard work happens at the end of the update function, which moves hardware state into the request object.
Quoted 2 lines
The import/export function then simply copies the request object state to the in/out buffer.
Understood the issue. But I feel it will be a bit overburden for the update() to copy/paste these for every call. Let me explore more on the hardware and come back with a better approach.
Thanks for the comments.
Regards,
Akhil
Herbert Xu
maintainerRe: [PATCH v4 3/5] crypto: tegra: Add Tegra Security Engine driver
Quoted 4 lines · Akhil R
Understood the issue. But I feel it will be a bit overburden for the
update()to copy/paste these for every call. Let me explore more on the hardware and come back with a better approach.
Of course it's a burden to copy it in and out on every update, that is why we generally use digest and finup instead of update.
As a driver you don't need to worry about this cost.
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
Akhil R
maintainerRE: [PATCH v4 3/5] crypto: tegra: Add Tegra Security Engine driver
Quoted 11 lines · Akhil R
Quoted 4 lines
Understood the issue. But I feel it will be a bit overburden for the
update()to copy/paste these for every call. Let me explore more on the hardware and come back with a better approach.Of course it's a burden to copy it in and out on every update, that is why we generally use digest and finup instead of update.
As a driver you don't need to worry about this cost.
Hmm. Makes sense. Thanks. Will update and post a new version.
Regards,
Akhil
Akhil R
maintainerPATCH v4 4/5 arm64: defconfig: Enable Tegra Security Engine
In reply to Akhil REnable Tegra Security Engine which can accelerate various AES and HASH algorithms on supported hardware.
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -1602,6 +1602,7 @@ CONFIG_CRYPTO_DEV_FSL_CAAM=m CONFIG_CRYPTO_DEV_FSL_DPAA2_CAAM=m CONFIG_CRYPTO_DEV_QCE=m CONFIG_CRYPTO_DEV_QCOM_RNG=m +CONFIG_CRYPTO_DEV_TEGRA=m CONFIG_CRYPTO_DEV_CCREE=m CONFIG_CRYPTO_DEV_HISI_SEC2=m CONFIG_CRYPTO_DEV_HISI_ZIP=m
Signature · 1 line
2.17.1
Akhil R
maintainerPATCH v4 5/5 arm64: tegra: Add Tegra Security Engine DT nodes
In reply to Akhil RAdd device tree nodes for Tegra AES and HASH engines.
--- arch/arm64/boot/dts/nvidia/tegra234.dtsi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/arm64/boot/dts/nvidia/tegra234.dtsi +16 -0
@@ -2304,6 +2304,22 @@ */ status = "disabled"; }; + + crypto@15820000 { + compatible = "nvidia,tegra234-se-aes"; + reg = <0x00 0x15820000 0x00 0x10000>; + clocks = <&bpmp TEGRA234_CLK_SE>; + iommus = <&smmu_niso1 TEGRA234_SID_SES_SE1>; + dma-coherent; + }; + + crypto@15840000 { + compatible = "nvidia,tegra234-se-hash"; + reg = <0x00 0x15840000 0x00 0x10000>; + clocks = <&bpmp TEGRA234_CLK_SE>; + iommus = <&smmu_niso1 TEGRA234_SID_SES_SE1>; + dma-coherent; + }; }; pcie@140a0000 {
Signature · 1 line
2.17.1