Add Tegra Security Engine driver
Subsystems (6)
Akhil R
maintainerv6 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.
v5->v6:
* Move copy/pase of intermediate results in export()/import() to 'update()' callback for CMAC as well.
* Check for rctx size when using fallback alg.
* Updated blocksizes to align with generic implementation
* Combined GCM and CCM init into aead_cra_init
* Updates to handle invalid cases better
* Reduce log levels for invalid cases to dev_dbg v4->v5:
* Move copy/paste of intermediate results in export()/import() to 'update()' callbackv3->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 | 1960 +++++++++++++++++ drivers/crypto/tegra/tegra-se-hash.c | 1055 +++++++++ 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, 4347 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.43.2
Akhil R
maintainerPATCH v6 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.43.2
Akhil R
maintainerPATCH v6 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
@@ -215,6 +215,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.43.2
Akhil R
maintainerPATCH v6 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 | 1960 ++++++++++++++++++++++++++ drivers/crypto/tegra/tegra-se-hash.c | 1055 ++++++++++++++ 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, 4202 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
@@ -21702,6 +21702,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
@@ -660,6 +660,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 +1960 -0
1,960 lines not on this page · raw message
drivers/crypto/tegra/tegra-se-hash.c new file +1055 -0
999 lines not on this page · raw message
drivers/crypto/tegra/tegra-se-key.c new file +156 -0
156 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.43.2
Part of the diff is not shown here. View the raw message.
Herbert Xu
maintainerRe: [PATCH v6 3/5] crypto: tegra: Add Tegra Security Engine driver
Quoted 13 lines · Akhil R
drivers/crypto/tegra/tegra-se-aes.c new file +12
-0+ .alg.skcipher.op.do_one_request = tegra_aes_do_one_req, + .alg.skcipher.base = { + .init = tegra_aes_cra_init, + .exit = tegra_aes_cra_exit, + .setkey = tegra_aes_setkey, + .encrypt = tegra_aes_encrypt, + .decrypt = tegra_aes_decrypt, + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .ivsize = AES_BLOCK_SIZE, + .base = { + .cra_name = "ofb(aes)",
drivers/crypto/tegra/tegra-se-aes.c line 559
Quoted 10 lines
drivers/crypto/tegra/tegra-se-aes.c new file +10
-0+ .cra_driver_name = "ofb-aes-tegra", + .cra_priority = 500, + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_ASYNC, + .cra_blocksize = AES_BLOCK_SIZE, + .cra_ctxsize = sizeof(struct tegra_aes_ctx), + .cra_alignmask = 0xf, + .cra_module = THIS_MODULE, + }, + } + }, {
OFB no longer exists in the kernel. Please remove all traces of it from your driver.
Also please ensure that yuor driver passes the extra fuzz tests.
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
Akhil R
maintainerRE: [PATCH v6 3/5] crypto: tegra: Add Tegra Security Engine driver
Quoted 25 lines
Quoted 6 lines
drivers/crypto/tegra/tegra-se-aes.c new file +5
-0+ .alg.skcipher.op.do_one_request = tegra_aes_do_one_req, + .alg.skcipher.base = { + .init = tegra_aes_cra_init, + .exit = tegra_aes_cra_exit, + .setkey = tegra_aes_setkey,drivers/crypto/tegra/tegra-se-aes.c
Quoted 10 lines
drivers/crypto/tegra/tegra-se-aes.c new file +10
-0+ .encrypt = tegra_aes_encrypt, + .decrypt = tegra_aes_decrypt, + .min_keysize = AES_MIN_KEY_SIZE, + .max_keysize = AES_MAX_KEY_SIZE, + .ivsize = AES_BLOCK_SIZE, + .base = { + .cra_name = "ofb(aes)", + .cra_driver_name = "ofb-aes-tegra", + .cra_priority = 500, + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER |
CRYPTO_ALG_ASYNC,drivers/crypto/tegra/tegra-se-aes.c line 494
Quoted 7 lines
drivers/crypto/tegra/tegra-se-aes.c new file +7
-0+ .cra_blocksize = AES_BLOCK_SIZE, + .cra_ctxsize = sizeof(struct tegra_aes_ctx), + .cra_alignmask = 0xf, + .cra_module = THIS_MODULE, + }, + } + }, {
Quoted 1 line
OFB no longer exists in the kernel. Please remove all traces of it from your driver.
Okay. Will remove and post a new version.
Quoted 2 lines
Also please ensure that yuor driver passes the extra fuzz tests.
Yes. It does pass the extra fuzz tests.
Regards,
Akhil
Herbert Xu
maintainerRe: [PATCH v6 3/5] crypto: tegra: Add Tegra Security Engine driver
In reply to Akhil Rdrivers/crypto/tegra/tegra-se-hash.c line 33
Quoted 3 lines · Akhil R
drivers/crypto/tegra/tegra-se-hash.c new file +2
-0+struct tegra_sha_reqctx { +struct ahash_request fallback_req;
This doesn't work because ahash_request is dynamically sized. So you'll end up clobbering the rest of the struct if a fallback ends up being used.
You should place the fallback_req at the end of the reqctx and set the reqsize based on the fallback reqsize.
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 v6 3/5] crypto: tegra: Add Tegra Security Engine driver
Quoted 11 lines · Akhil R
drivers/crypto/tegra/tegra-se-hash.c line 33
Quoted 3 lines
drivers/crypto/tegra/tegra-se-hash.c new file +2
-0+struct tegra_sha_reqctx { +struct ahash_request fallback_req;This doesn't work because
ahash_requestis dynamically sized.
So you'll end up clobbering the rest of the struct if a fallback ends up being used.You should place the
fallback_reqat the end of the reqctx and set the reqsize based on the fallback reqsize.
Should I set the reqsize as below in sha_cra_init()? Seeing this in other crypto drivers.
crypto_ahash_set_reqsize(ahash_tfm,
sizeof(struct tegra_sha_reqctx) + crypto_ahash_reqsize(ctx->fallback_tfm));
Regards,
Akhil
Herbert Xu
maintainerRe: [PATCH v6 3/5] crypto: tegra: Add Tegra Security Engine driver
Quoted 6 lines · Akhil R
Should I set the reqsize as below in
sha_cra_init()? Seeing this in other crypto drivers.crypto_ahash_set_reqsize(ahash_tfm,
sizeof(struct tegra_sha_reqctx)+crypto_ahash_reqsize(ctx->fallback_tfm));
Yes if you places the fallback request at the end of reqctx then this is the correct reqsize.
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
maintainerPATCH v6 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
@@ -1647,6 +1647,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.43.2
Akhil R
maintainerPATCH v6 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
@@ -4406,6 +4406,22 @@ nvdec@15480000 { */ 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_SE2>; + dma-coherent; + }; }; pcie@140a0000 {
Signature · 1 line
2.43.2