Add SA2UL Public Key Accelerator driver
cover Add SA2UL Public Key Accelerator driver
The PKA is a subdevice of the SA2UL that provides hardware acceleration for asymmetric cryptography algorithms. RSA and Diffie-Hellman are enabled in this patch series.
Tested using these configurations:
- CONFIG_CRYPTO_MANAGER_DISABLE_TESTS=n
- CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y
These patches are RFC for now because we're waiting for legal to clear us to release the firmware.
The dts patches depend on [1] and [2], respectively, to apply without fuzz.
[1]: https://www.spinics.net/lists/devicetree/msg523234.html
[2]: https://www.spinics.net/lists/devicetree/msg523233.html
Daniel Parks (6):
dt-bindings: crypto: ti,sa2ul: add pka subdevice
dt-bindings: crypto: add binding for eip29t2 public key accelerator
(PKA)
arm64: dts: ti: k3-am64-main: add SA2UL public key accelerator
subdevice
arm64: dts: ti: k3-j721e-main: add SA2UL public key accelerator
subdevice
crypto: sa2ul: turn on PKA engine
crypto: sa2ul_pka: Add SA2UL PKA driver
.../inside-secure,safexcel-eip29t2.yaml | 49 ++ .../devicetree/bindings/crypto/ti,sa2ul.yaml | 6 + arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 8 + arch/arm64/boot/dts/ti/k3-j721e-main.dtsi | 7 + drivers/crypto/Kconfig | 2 + drivers/crypto/Makefile | 1 + drivers/crypto/sa2ul.c | 2 +- drivers/crypto/sa2ul_pka/Kconfig | 26 + drivers/crypto/sa2ul_pka/Makefile | 3 + drivers/crypto/sa2ul_pka/sa2ul_pka.h | 135 +++++ drivers/crypto/sa2ul_pka/sa2ul_pka_base.c | 564 ++++++++++++++++++ drivers/crypto/sa2ul_pka/sa2ul_pka_dh.c | 150 +++++ drivers/crypto/sa2ul_pka/sa2ul_pka_op.c | 205 +++++++ drivers/crypto/sa2ul_pka/sa2ul_pka_op.h | 28 + drivers/crypto/sa2ul_pka/sa2ul_pka_rsa.c | 193 ++++++ drivers/crypto/sa2ul_pka/sa2ul_pka_sg.c | 316 ++++++++++ 16 files changed, 1694 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml create mode 100644 drivers/crypto/sa2ul_pka/Kconfig create mode 100644 drivers/crypto/sa2ul_pka/Makefile create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka.h create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_base.c create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_dh.c create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_op.c create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_op.h create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_rsa.c create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_sg.c
Signature · 1 line
2.17.1
RFC PATCH 1/6 dt-bindings: crypto: ti,sa2ul: add pka subdevice
The PKA (aka eip29t2) is a subdevice of the SA2UL on k3.
--- Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml +6 -0
@@ -64,8 +64,14 @@ patternProperties: type: object description: Child RNG node for SA2UL +patternProperties: + "^pka@[a-f0-9]+$": + type: object + description: + Child PKA node for SA2UL + required: - compatible - reg - power-domains
Signature · 1 line
2.17.1
Re: [RFC PATCH 1/6] dt-bindings: crypto: ti,sa2ul: add pka subdevice
Quoted 12 lines · Daniel Parks
The PKA (aka eip29t2) is a subdevice of the SA2UL on k3.
Signed-off-by Daniel Parks <[email protected]>--- Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml +0
-0
Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml patternProperties: · line 72
Quoted 9 lines
Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml +5
-0@@ -64,8 +64,14 @@ patternProperties: type: object description: Child RNG node for SA2UL +patternProperties: + "^pka@[a-f0-9]+$": + type: object + description: + Child PKA node for SA2UL
If PKA is from "Public Key Accelerator", could you include here full name of the abbreviation?
Anyway you need here reference to schema for your node or describe the contents.
Best regards,
Krzysztof
Rob Herring
maintainerRe: [RFC PATCH 1/6] dt-bindings: crypto: ti,sa2ul: add pka subdevice
In reply to Daniel ParksQuoted 7 lines · Daniel Parks
The PKA (aka eip29t2) is a subdevice of the SA2UL on k3.
Signed-off-by Daniel Parks <[email protected]>--- Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:./Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml:68:1: [error] duplication of key "patternProperties" in mapping (key-duplicates)
dtschema/dtc warnings/errors:
make[1]: *** Deleting file 'Documentation/devicetree/bindings/crypto/ti,sa2ul.example.dts' Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml:68:1: found duplicate key "patternProperties" with value "{}" (original value: "{}") make[1]: *** [Documentation/devicetree/bindings/Makefile:26: Documentation/devicetree/bindings/crypto/ti,sa2ul.example.dts] Error 1 make[1]: *** Waiting for unfinished jobs...../Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml:68:1: found duplicate key "patternProperties" with value "{}" (original value: "{}") /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml: ignoring, error parsing file
make: *** [Makefile:1404: dt_binding_check] Error 2
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/patch/
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit.
RFC PATCH 2/6 dt-bindings: crypto: add binding for eip29t2 public key accelerator (PKA)
In reply to Daniel ParksThe PKA is a mmio-only asymmetric crypto accelerator available on certain K3 devices.
--- .../inside-secure,safexcel-eip29t2.yaml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml
Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml new file +49 -0
@@ -0,0 +1,49 @@ +# SPDX-License-Identifier: (GPL-2.0-only or BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/inside-secure,safexcel-eip29t2.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: K3 SoC SA2UL PKA crypto module + +maintainers: + - Daniel Parks <[email protected]> + +description: | + Asymmetric crypto accelerator + +properties: + compatible: + const: inside-secure,safexcel-eip29t2 + + reg: + items: + - description: control registers + - description: mapped memory + + interrupts: + items: + - description: PKA interrupt + + clocks: + items: + - description: PKA in clock + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + pka: pka@40920000 { + compatible = "inside-secure,safexcel-eip29t2"; + reg = <0x00 0x40920000 0x00 0x2000>, + <0x00 0x40924000 0x00 0x8000>; + interrupts = <GIC_SPI 167 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&k3_clks 133 0>; + };
Signature · 1 line
2.17.1
Re: [RFC PATCH 2/6] dt-bindings: crypto: add binding for eip29t2 public key accelerator (PKA)
Quoted 15 lines · Daniel Parks
The PKA is a mmio-only asymmetric crypto accelerator available on certain K3 devices.
Signed-off-by Daniel Parks <[email protected]>--- .../inside-secure,safexcel-eip29t2.yaml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yamlDocumentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml new file +0
-0
Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml line 7
Quoted 7 lines
Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml new file +7
-0@@ -0,0 +1,49 @@ +# SPDX-License-Identifier: (GPL-2.0-only or BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/inside-secure,safexcel-eip29t2.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: K3 SoC SA2UL PKA crypto module
If this is the child mentioned in patch #1, then this should be first patch and your next one should reference it.
Quoted 9 lines
Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml new file +9
-0+ +maintainers: + - Daniel Parks <[email protected]> + +description: | + Asymmetric crypto accelerator + +properties: + compatible:
Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml line 26
Quoted 10 lines
Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml new file +10
-0+ const: inside-secure,safexcel-eip29t2 + + reg: + items: + - description: control registers + - description: mapped memory + + interrupts: + items: + - description: PKA interrupt
This could be "maxItems:1" because your description actually does not bring anything new, but current choice is also OK.
Best regards,
Krzysztof
Rob Herring
maintainerRe: [RFC PATCH 2/6] dt-bindings: crypto: add binding for eip29t2 public key accelerator (PKA)
In reply to Daniel ParksQuoted 9 lines · Daniel Parks
The PKA is a mmio-only asymmetric crypto accelerator available on certain K3 devices.
Signed-off-by Daniel Parks <[email protected]>--- .../inside-secure,safexcel-eip29t2.yaml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.example.dtb: pka@40920000: reg: [[0, 1083310080], [0, 8192], [0, 1083326464], [0, 32768]] is too long
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip29t2.yaml
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/patch/
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit.
RFC PATCH 3/6 arm64: dts: ti: k3-am64-main: add SA2UL public key accelerator subdevice
In reply to Daniel ParksThe PKA on am64 will eventually be accessible from the A53, so add it as a (disabled) subdevice alongside the RNG module.
This patch depends on "[PATCH v2 0/2] Enable SA2UL support on AM64X" [1]
[1]: https://lore.kernel.org/linux-arm-kernel/[email protected]/
--- arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/ti/k3-am64-main.dtsi +8 -0
@@ -1326,6 +1326,14 @@ interrupts = <GIC_SPI 168 IRQ_TYPE_LEVEL_HIGH>; clocks = <&k3_clks 133 1>; status = "disabled"; /* Used by OP-TEE */ }; + + pka: pka@40920000 { + compatible = "inside-secure,safexcel-eip29t2"; + reg = <0x00 0x40920000 0x00 0x2000>, + <0x00 0x40924000 0x00 0x8000>; + interrupts = <GIC_SPI 167 IRQ_TYPE_LEVEL_HIGH>; + status = "disabled"; /* handoff from sysfw not yet implemented */ + }; }; };
Signature · 1 line
2.17.1
RFC PATCH 4/6 arm64: dts: ti: k3-j721e-main: add SA2UL public key accelerator subdevice
In reply to Daniel Parksj721e contains two SA2ULs, and the PKA in the main domain is accessible, so add it as a subdevice alongside the RNG module.
--- arch/arm64/boot/dts/ti/k3-j721e-main.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/boot/dts/ti/k3-j721e-main.dtsi +7 -0
@@ -344,8 +344,15 @@ reg = <0x0 0x4e10000 0x0 0x7d>; interrupts = <GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>; clocks = <&k3_clks 264 2>; }; + + pka: pka@4e20000 { + compatible = "inside-secure,safexcel-eip29t2"; + reg = <0x00 0x4e20000 0x00 0x2000>, + <0x00 0x4e24000 0x00 0x8000>; + interrupts = <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>; + }; }; main_pmx0: pinctrl@11c000 { compatible = "pinctrl-single";
Signature · 1 line
2.17.1
RFC PATCH 5/6 crypto: sa2ul: turn on PKA engine
In reply to Daniel ParksThe SA2UL driver is responsible for enabling power to its subdevices before enumerating them. In order to enable the PKA driver, we need to turn on the power to it here.
--- drivers/crypto/sa2ul.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/sa2ul.c +1 -1
@@ -2428,9 +2428,9 @@ static int sa_ul_probe(struct platform_device *pdev)if (!dev_data->match_data->skip_engine_control) {u32 val =SA_EEC_ENCSS_EN |SA_EEC_AUTHSS_EN |SA_EEC_CTXCACH_EN |SA_EEC_CPPI_PORT_IN_EN |SA_EEC_CPPI_PORT_OUT_EN | -SA_EEC_TRNG_EN ; +SA_EEC_TRNG_EN |SA_EEC_PKA_EN ;writel_relaxed (val, saul_base +SA_ENGINE_ENABLE_CONTROL ); }
Signature · 1 line
2.17.1
RFC PATCH 6/6 crypto: sa2ul_pka: Add SA2UL PKA driver
In reply to Daniel ParksThis device exposes asymmetric crypto primitives rather than complete operations, and it only supports memory-mapped I/O, and its memory is only addressable one 32-bit word at a time. As a result, some of the code might look a little different from other crypto accelerator drivers.
--- drivers/crypto/Kconfig | 2 + drivers/crypto/Makefile | 1 + drivers/crypto/sa2ul_pka/Kconfig | 26 + drivers/crypto/sa2ul_pka/Makefile | 3 + drivers/crypto/sa2ul_pka/sa2ul_pka.h | 135 ++++++ drivers/crypto/sa2ul_pka/sa2ul_pka_base.c | 564 ++++++++++++++++++++++ drivers/crypto/sa2ul_pka/sa2ul_pka_dh.c | 150 ++++++ drivers/crypto/sa2ul_pka/sa2ul_pka_op.c | 205 ++++++++ drivers/crypto/sa2ul_pka/sa2ul_pka_op.h | 28 ++ drivers/crypto/sa2ul_pka/sa2ul_pka_rsa.c | 193 ++++++++ drivers/crypto/sa2ul_pka/sa2ul_pka_sg.c | 316 ++++++++++++ 11 files changed, 1623 insertions(+) create mode 100644 drivers/crypto/sa2ul_pka/Kconfig create mode 100644 drivers/crypto/sa2ul_pka/Makefile create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka.h create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_base.c create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_dh.c create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_op.c create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_op.h create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_rsa.c create mode 100644 drivers/crypto/sa2ul_pka/sa2ul_pka_sg.c
drivers/crypto/Kconfig +2 -0
@@ -816,7 +816,9 @@ config CRYPTO_DEV_SA2UL K3 devices include a security accelerator engine that may be used for crypto offload. Select this if you want to use hardware acceleration for cryptographic algorithms on these devices. +source "drivers/crypto/sa2ul_pka/Kconfig" + source "drivers/crypto/keembay/Kconfig" endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
@@ -37,8 +37,9 @@ obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/ obj-$(CONFIG_CRYPTO_DEV_QCOM_RNG) += qcom-rng.o obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/ obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o obj-$(CONFIG_CRYPTO_DEV_SA2UL) += sa2ul.o +obj-$(CONFIG_CRYPTO_DEV_SA2UL_PKA) += sa2ul_pka/ obj-$(CONFIG_CRYPTO_DEV_SAHARA) += sahara.o obj-$(CONFIG_CRYPTO_DEV_SL3516) += gemini/ obj-$(CONFIG_ARCH_STM32) += stm32/ obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o
drivers/crypto/sa2ul_pka/Kconfig new file +26 -0
@@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config CRYPTO_DEV_SA2UL_PKA + tristate "Support for TI security accelerator public-key module" + depends on CRYPTO_DEV_SA2UL || COMPILE_TEST + select ARM64_CRYPTO + select CRYPTO_AKCIPHER + select CRYPTO_RSA + select PACKING + select CRYPTO_DH + help + The K3 security accelerator engine contains a public-key + cryptography module. Select this if you want to use hardware + acceleration for asymmetric cryptography on these devices. This + engine is not available to the Linux cores on most devices; check + your device tree if unsure. + +config CRYPTO_DEV_SA2UL_PKA_DEBUG + bool "Debugging options for TI security accelerator public-key module" + depends on CRYPTO_DEV_SA2UL_PKA + default n + help + Enables the module options 'snapshot' and 'poison_mem' to assist + in debugging the PKA driver. Choosing "y" will allow the root user + to extract cryptographic keys from the driver, so do not enable in + a production build.
drivers/crypto/sa2ul_pka/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_CRYPTO_DEV_SA2UL_PKA) += sa2ul_pka.o +sa2ul_pka-objs := sa2ul_pka_base.o sa2ul_pka_sg.o sa2ul_pka_op.o sa2ul_pka_rsa.o sa2ul_pka_dh.o
drivers/crypto/sa2ul_pka/sa2ul_pka.h new file +135 -0
135 lines not on this page · raw message
drivers/crypto/sa2ul_pka/sa2ul_pka_base.c new file +564 -0
564 lines not on this page · raw message
drivers/crypto/sa2ul_pka/sa2ul_pka_dh.c new file +150 -0
150 lines not on this page · raw message
drivers/crypto/sa2ul_pka/sa2ul_pka_op.c new file +205 -0
205 lines not on this page · raw message
drivers/crypto/sa2ul_pka/sa2ul_pka_op.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* K3 SA2UL Public Key Accelerator driver +* +* Copyright (c) 2022 Texas Instruments Incorporated - https://www.ti.com +* +* Author: Daniel Parks <[email protected]> +*/ + +#ifndef PKA_OP_H +#define PKA_OP_H + +#include <linux/scatterlist.h> + +#include "sa2ul_pka.h" + +int pka_modexp (struct pka_data *data,struct scatterlist *src,uint slen, +const u8 *exponent,size_t elen,const u8 *modulus,size_t mlen, +struct scatterlist *dst,uint *dlen,u32 shift, +bool check_base); + +size_t pka_sg_copy_in (void __iomem *dst,struct scatterlist *src,size_t len, +bool big); +size_t pka_sg_copy_out (void __iomem *src,struct scatterlist *dst,size_t skip, +size_t len,bool big); +void *reverse_memcpy (void *dest,const void *src,size_t count); + +#endif /* PKA_OP_H */
drivers/crypto/sa2ul_pka/sa2ul_pka_rsa.c new file +193 -0
193 lines not on this page · raw message
drivers/crypto/sa2ul_pka/sa2ul_pka_sg.c new file +316 -0
316 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [RFC PATCH 6/6] crypto: sa2ul_pka: Add SA2UL PKA driver
Hi--
Quoted 22 lines · Daniel Parks
drivers/crypto/sa2ul_pka/Kconfig new file +16
-0@@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config CRYPTO_DEV_SA2UL_PKA + tristate "Support for TI security accelerator public-key module" + depends on CRYPTO_DEV_SA2UL || COMPILE_TEST + select ARM64_CRYPTO + select CRYPTO_AKCIPHER + select CRYPTO_RSA + select PACKING + select CRYPTO_DH + help + The K3 security accelerator engine contains a public-key + cryptography module. Select this if you want to use hardware + acceleration for asymmetric cryptography on these devices. This + engine is not available to the Linux cores on most devices; check + your device tree if unsure.
drivers/crypto/sa2ul_pka/Kconfig line 26
Quoted 10 lines
drivers/crypto/sa2ul_pka/Kconfig new file +10
-0+ +config CRYPTO_DEV_SA2UL_PKA_DEBUG + bool "Debugging options for TI security accelerator public-key module" + depends on CRYPTO_DEV_SA2UL_PKA + default n + help + Enables the module options 'snapshot' and 'poison_mem' to assist + in debugging the PKA driver. Choosing "y" will allow the root user + to extract cryptographic keys from the driver, so do not enable in + a production build.
Too much help text indentation.
from Documentation/process/coding-style.rst:
For all of the Kconfig* configuration files throughout the source tree, the indentation is somewhat different. Lines under a ``config`` definition are indented with one tab, while help text is indented an additional two spaces.
Signature · 1 line
~Randy