crypto: Add EIP-93 crypto engine support
Subsystems (5)
Christian Marangi
maintainerv11 cover crypto: Add EIP-93 crypto engine support
This small series add support for the Inside Secure EIP-93. This is a predecessor of the current supported EIP197. It doesn't require a firmware but instead it's embedded in the SoC.
First patch extend guard for spinlock_bh.
The other actually implement Documentation and Driver.
The Driver pass all the normal selft test for the supported algo and also pass the EXTRA test with fuzz_iterations set to 10000.
Changes v11:
- Drop any mtk variable reference and use eip93 instead
- Mute smatch warning for context unbalance by using scoped_guard instead of guard cleanup API
Changes v10:
- Use CRYPTO_ALG_ASYNC for eip93_hmac_setkey
Changes v9:
- Rework hash code to alloc DMA only when needed
- Rework hash code to only alloc needed blocks and use
local struct in req for everything else
- Rework hash code to use GFP_ATOMIC
- Simplify hash update function
- Generalize hmac key set function
Changes v8:
- Rework export and update to not sleep on exporting state (consume pending packet in update and return -EINPROGRESS)
Changes v7:
- Fix copypaste error in __eip93_hash_init
- Rework import/export to actually export the partial hash (we actually unmap DMA on export)
- Rename no_finalize variable to better partial_hash
- Rename 3rd commit title and drop Mediatek from title.
- Add Cover Letter
- Add Reviewed-by to DT commit
(cumulative changes from old series that had changelog in each patch) Changes v6:
- Add SoC specific compatible
- Add now supported entry for compatible with no user
Changes v5:
- Add Ack tag to guard patch
- Comment out compatible with no current user
- Fix smatch warning (reported by Dan Carpenter)
Changes v4:
- Out of RFC
- Add missing bitfield.h
- Drop useless header
Changes v3:
- Mute warning from Clang about C23
- Fix not inizialized err
- Drop unused variable
- Add SoC compatible with generic one
Changes v2:
- Rename all variables from mtk to eip93
- Move to inside-secure directory
- Check DMA map errors
- Use guard API for spinlock
- Minor improvements to code
- Add guard patch
- Change to better compatible
- Add description for EIP93 models
Christian Marangi (3):
spinlock: extend guard with spinlock_bh variants
dt-bindings: crypto: Add Inside Secure SafeXcel EIP-93 crypto engine
crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
.../crypto/inside-secure,safexcel-eip93.yaml | 67 ++ MAINTAINERS | 7 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/inside-secure/eip93/Kconfig | 20 + drivers/crypto/inside-secure/eip93/Makefile | 5 + .../crypto/inside-secure/eip93/eip93-aead.c | 711 ++++++++++++++ .../crypto/inside-secure/eip93/eip93-aead.h | 38 + .../crypto/inside-secure/eip93/eip93-aes.h | 16 + .../crypto/inside-secure/eip93/eip93-cipher.c | 413 +++++++++ .../crypto/inside-secure/eip93/eip93-cipher.h | 60 ++ .../crypto/inside-secure/eip93/eip93-common.c | 809 ++++++++++++++++ .../crypto/inside-secure/eip93/eip93-common.h | 24 + .../crypto/inside-secure/eip93/eip93-des.h | 16 + .../crypto/inside-secure/eip93/eip93-hash.c | 866 ++++++++++++++++++ .../crypto/inside-secure/eip93/eip93-hash.h | 82 ++ .../crypto/inside-secure/eip93/eip93-main.c | 501 ++++++++++ .../crypto/inside-secure/eip93/eip93-main.h | 151 +++ .../crypto/inside-secure/eip93/eip93-regs.h | 335 +++++++ include/linux/spinlock.h | 13 + 20 files changed, 4136 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip93.yaml create mode 100644 drivers/crypto/inside-secure/eip93/Kconfig create mode 100644 drivers/crypto/inside-secure/eip93/Makefile create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aes.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-des.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-regs.h
Signature · 1 line
2.45.2
Christian Marangi
maintainerPATCH v11 1/3 spinlock: extend guard with spinlock_bh variants
Extend guard APIs with missing raw/spinlock_bh variants.
--- include/linux/spinlock.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/spinlock.h +13 -0
@@ -548,6 +548,12 @@ DEFINE_LOCK_GUARD_1(raw_spinlock_irq, raw_spinlock_t, DEFINE_LOCK_GUARD_1_COND(raw_spinlock_irq, _try, raw_spin_trylock_irq(_T->lock)) +DEFINE_LOCK_GUARD_1 (raw_spinlock_bh, raw_spinlock_t, +raw_spin_lock_bh (_T->lock), + raw_spin_unlock_bh(_T->lock)) + +DEFINE_LOCK_GUARD_1_COND(raw_spinlock_bh, _try, raw_spin_trylock_bh(_T->lock)) + DEFINE_LOCK_GUARD_1(raw_spinlock_irqsave, raw_spinlock_t, raw_spin_lock_irqsave(_T->lock, _T->flags), raw_spin_unlock_irqrestore(_T->lock, _T->flags),
@@ -569,6 +575,13 @@ DEFINE_LOCK_GUARD_1(spinlock_irq, spinlock_t,DEFINE_LOCK_GUARD_1_COND (spinlock_irq, _try, spin_trylock_irq(_T->lock)) +DEFINE_LOCK_GUARD_1 (spinlock_bh, spinlock_t, +spin_lock_bh (_T->lock), + spin_unlock_bh(_T->lock)) + +DEFINE_LOCK_GUARD_1_COND (spinlock_bh, _try, + spin_trylock_bh(_T->lock)) + DEFINE_LOCK_GUARD_1(spinlock_irqsave, spinlock_t, spin_lock_irqsave(_T->lock, _T->flags), spin_unlock_irqrestore(_T->lock, _T->flags),
Signature · 1 line
2.45.2
Christian Marangi
maintainerPATCH v11 2/3 dt-bindings: crypto: Add Inside Secure SafeXcel EIP-93 crypto engine
In reply to Christian MarangiAdd bindings for the Inside Secure SafeXcel EIP-93 crypto engine.
The IP is present on Airoha SoC and on various Mediatek devices and other SoC under different names like mtk-eip93 or PKTE.
All the compatible that currently doesn't have any user are defined but rejected waiting for an actual device that makes use of them.
--- .../crypto/inside-secure,safexcel-eip93.yaml | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip93.yaml
Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip93.yaml new file +67 -0
@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/inside-secure,safexcel-eip93.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Inside Secure SafeXcel EIP-93 cryptographic engine + +maintainers: + - Christian Marangi <[email protected]> + +description: | + The Inside Secure SafeXcel EIP-93 is a cryptographic engine IP block + integrated in varios devices with very different and generic name from + PKTE to simply vendor+EIP93. The real IP under the hood is actually + developed by Inside Secure and given to license to vendors. + + The IP block is sold with different model based on what feature are + needed and are identified with the final letter. Each letter correspond + to a specific set of feature and multiple letter reflect the sum of the + feature set. + + EIP-93 models: + - EIP-93i: (basic) DES/Triple DES, AES, PRNG, IPsec ESP, SRTP, SHA1 + - EIP-93ie: i + SHA224/256, AES-192/256 + - EIP-93is: i + SSL/DTLS/DTLS, MD5, ARC4 + - EIP-93ies: i + e + s + - EIP-93iw: i + AES-XCB-MAC, AES-CCM + +properties: + compatible: + oneOf: + - items: + - const: airoha,en7581-eip93 + - const: inside-secure,safexcel-eip93ies + - items: + - not: {} + description: Need a SoC specific compatible + - enum: + - inside-secure,safexcel-eip93i + - inside-secure,safexcel-eip93ie + - inside-secure,safexcel-eip93is + - inside-secure,safexcel-eip93iw + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + crypto@1e004000 { + compatible = "airoha,en7581-eip93", "inside-secure,safexcel-eip93ies"; + reg = <0x1fb70000 0x1000>; + + interrupts = <GIC_SPI 44 IRQ_TYPE_LEVEL_HIGH>; + };
Signature · 1 line
2.45.2
Christian Marangi
maintainerPATCH v11 3/3 crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
In reply to Christian MarangiAdd support for the Inside Secure SafeXcel EIP-93 Crypto Engine used on Mediatek MT7621 SoC and new Airoha SoC.
EIP-93 IP supports AES/DES/3DES ciphers in ECB/CBC and CTR modes as well as authenc(HMAC(x), cipher(y)) using HMAC MD5, SHA1, SHA224 and SHA256.
EIP-93 provide regs to signal support for specific chipers and the driver dynamically register only the supported one by the chip.
--- MAINTAINERS | 7 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/inside-secure/eip93/Kconfig | 20 + drivers/crypto/inside-secure/eip93/Makefile | 5 + .../crypto/inside-secure/eip93/eip93-aead.c | 711 ++++++++++++++ .../crypto/inside-secure/eip93/eip93-aead.h | 38 + .../crypto/inside-secure/eip93/eip93-aes.h | 16 + .../crypto/inside-secure/eip93/eip93-cipher.c | 413 +++++++++ .../crypto/inside-secure/eip93/eip93-cipher.h | 60 ++ .../crypto/inside-secure/eip93/eip93-common.c | 809 ++++++++++++++++ .../crypto/inside-secure/eip93/eip93-common.h | 24 + .../crypto/inside-secure/eip93/eip93-des.h | 16 + .../crypto/inside-secure/eip93/eip93-hash.c | 866 ++++++++++++++++++ .../crypto/inside-secure/eip93/eip93-hash.h | 82 ++ .../crypto/inside-secure/eip93/eip93-main.c | 501 ++++++++++ .../crypto/inside-secure/eip93/eip93-main.h | 151 +++ .../crypto/inside-secure/eip93/eip93-regs.h | 335 +++++++ 18 files changed, 4056 insertions(+) create mode 100644 drivers/crypto/inside-secure/eip93/Kconfig create mode 100644 drivers/crypto/inside-secure/eip93/Makefile create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aes.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-des.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-regs.h
MAINTAINERS +7 -0
@@ -11322,6 +11322,13 @@ L: [email protected] S: Maintained F: drivers/crypto/inside-secure/ +INSIDE SECURE EIP93 CRYPTO DRIVER +M: Christian Marangi <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip93.yaml +F: drivers/crypto/inside-secure/eip93/ + INTEGRITY MEASUREMENT ARCHITECTURE (IMA) M: Mimi Zohar <[email protected]> M: Roberto Sassu <[email protected]>
drivers/crypto/Kconfig +1 -0
@@ -851,5 +851,6 @@ config CRYPTO_DEV_SA2UL source "drivers/crypto/aspeed/Kconfig" source "drivers/crypto/starfive/Kconfig" +source "drivers/crypto/inside-secure/eip93/Kconfig" endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
@@ -52,3 +52,4 @@ obj-y += hisilicon/ obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic/ obj-y += intel/ obj-y += starfive/ +obj-y += inside-secure/eip93/
drivers/crypto/inside-secure/eip93/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0 +config CRYPTO_DEV_EIP93 + tristate "Support for EIP93 crypto HW accelerators" + depends on SOC_MT7621 || ARCH_AIROHA ||COMPILE_TEST + select CRYPTO_LIB_AES + select CRYPTO_LIB_DES + select CRYPTO_SKCIPHER + select CRYPTO_AEAD + select CRYPTO_AUTHENC + select CRYPTO_MD5 + select CRYPTO_SHA1 + select CRYPTO_SHA256 + help + EIP93 have various crypto HW accelerators. Select this if + you want to use the EIP93 modules for any of the crypto algorithms. + + If the IP supports it, this provide offload for AES - ECB, CBC and + CTR crypto. Also provide DES and 3DES ECB and CBC. + + Also provide AEAD authenc(hmac(x), cipher(y)) for supported algo.
drivers/crypto/inside-secure/eip93/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +obj-$(CONFIG_CRYPTO_DEV_EIP93) += crypto-hw-eip93.o + +crypto-hw-eip93-y += eip93-main.o eip93-common.o +crypto-hw-eip93-y += eip93-cipher.o eip93-aead.o +crypto-hw-eip93-y += eip93-hash.o
drivers/crypto/inside-secure/eip93/eip93-aead.c new file +711 -0
711 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-aead.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2019 - 2021 +* +* Richard van Schagen <[email protected]> +* Christian Marangi <[email protected] +*/ +#ifndef _EIP93_AEAD_H_ +#define _EIP93_AEAD_H_ + +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_cbc_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_cbc_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_cbc_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_cbc_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_ctr_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_ctr_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_ctr_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_ctr_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_rfc3686_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_rfc3686_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_rfc3686_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_rfc3686_aes; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_cbc_des; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_cbc_des; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_cbc_des; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_cbc_des; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_cbc_des3_ede; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_cbc_des3_ede; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_cbc_des3_ede; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_cbc_des3_ede; +extern struct eip93_alg_template eip93_alg_authenc_hmac_md5_ecb_null; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha1_ecb_null; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha224_ecb_null; +extern struct eip93_alg_template eip93_alg_authenc_hmac_sha256_ecb_null; + +void eip93_aead_handle_result (struct crypto_async_request *async,int err); + +#endif /* _EIP93_AEAD_H_ */
drivers/crypto/inside-secure/eip93/eip93-aes.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2019 - 2021 +* +* Richard van Schagen <[email protected]> +* Christian Marangi <[email protected] +*/ +#ifndef _EIP93_AES_H_ +#define _EIP93_AES_H_ + +extern struct eip93_alg_template eip93_alg_ecb_aes; +extern struct eip93_alg_template eip93_alg_cbc_aes; +extern struct eip93_alg_template eip93_alg_ctr_aes; +extern struct eip93_alg_template eip93_alg_rfc3686_aes; + +#endif /* _EIP93_AES_H_ */
drivers/crypto/inside-secure/eip93/eip93-cipher.c new file +413 -0
413 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-cipher.h new file +60 -0
60 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-common.c new file +809 -0
809 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-common.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2019 - 2021 +* +* Richard van Schagen <[email protected]> +* Christian Marangi <[email protected] +*/ + +#ifndef _EIP93_COMMON_H_ +#define _EIP93_COMMON_H_ + +void *eip93_get_descriptor (struct eip93_device *eip93); +int eip93_put_descriptor (struct eip93_device *eip93,struct eip93_descriptor *desc); + +void eip93_set_sa_record (struct sa_record *sa_record,const unsigned int keylen, +const u32 flags); + +int eip93_parse_ctrl_stat_err (struct eip93_device *eip93,int err); + +int eip93_hmac_setkey (u32 ctx_flags,const u8 *key,unsigned int keylen, +unsigned int hashlen,u8 *ipad,u8 *opad, +bool skip_ipad); + +#endif /* _EIP93_COMMON_H_ */
drivers/crypto/inside-secure/eip93/eip93-des.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2019 - 2021 +* +* Richard van Schagen <[email protected]> +* Christian Marangi <[email protected] +*/ +#ifndef _EIP93_DES_H_ +#define _EIP93_DES_H_ + +extern struct eip93_alg_template eip93_alg_ecb_des; +extern struct eip93_alg_template eip93_alg_cbc_des; +extern struct eip93_alg_template eip93_alg_ecb_des3_ede; +extern struct eip93_alg_template eip93_alg_cbc_des3_ede; + +#endif /* _EIP93_DES_H_ */
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +866 -0
865 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-hash.h new file +82 -0
82 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-main.c new file +501 -0
501 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-main.h new file +151 -0
151 lines not on this page · raw message
drivers/crypto/inside-secure/eip93/eip93-regs.h new file +335 -0
335 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.45.2
Part of the diff is not shown here. View the raw message.
Herbert Xu
maintainerRe: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Quoted 4 lines · Christian Marangi
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +3
-0+static int eip93_send_hash_req (struct crypto_async_request *async,u8 *data, +dma_addr_t *data_dma,u32 len,bool last) +{
...
drivers/crypto/inside-secure/eip93/eip93-hash.c line 271
Quoted 10 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +10
-0+again: + ret =eip93_put_descriptor (eip93, &cdesc); +if (ret) { +usleep_range (EIP93_RING_BUSY_DELAY , +EIP93_RING_BUSY_DELAY *2 ); + goto again; + } + +/* Writing new descriptor count starts DMA action */ +writel (1 , eip93->base +EIP93_REG_PE_CD_COUNT );
Why is there no locking here? Shouldn't this be under ring->write_lock?
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
Christian Marangi (Ansuel)
maintainerRe: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Il giorno mar 1 apr 2025 alle ore 12:08 Herbert Xu <[email protected]> ha scritto:
Quoted 9 lines · Christian Marangi
Quoted 4 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +3
-0+static int eip93_send_hash_req (struct crypto_async_request *async,u8 *data, +dma_addr_t *data_dma,u32 len,bool last) +{...
Quoted 13 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c line 271
Quoted 10 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +10
-0+again: + ret =eip93_put_descriptor (eip93, &cdesc); +if (ret) { +usleep_range (EIP93_RING_BUSY_DELAY , +EIP93_RING_BUSY_DELAY *2 ); + goto again; + } + +/* Writing new descriptor count starts DMA action */ +writel (1 , eip93->base +EIP93_REG_PE_CD_COUNT );Why is there no locking here? Shouldn't this be under
ring->write_lock?
Hi Herbert,
this is really to tell DMA that there is new packet to process and gets decreased instantly.
The lock is used to track what descriptor index should be used in the ring in the put and get
functions.
Herbert Xu
maintainerRe: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Quoted 25 lines · Christian Marangi (Ansuel)
Il giorno mar 1 apr 2025 alle ore 12:08 Herbert Xu <[email protected]> ha scritto:
Quoted 9 lines · Christian Marangi
Quoted 4 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +3
-0+static int eip93_send_hash_req (struct crypto_async_request *async,u8 *data, +dma_addr_t *data_dma,u32 len,bool last) +{...
Quoted 13 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c line 271
Quoted 10 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +10
-0+again: + ret =eip93_put_descriptor (eip93, &cdesc); +if (ret) { +usleep_range (EIP93_RING_BUSY_DELAY , +EIP93_RING_BUSY_DELAY *2 ); + goto again; + } + +/* Writing new descriptor count starts DMA action */ +writel (1 , eip93->base +EIP93_REG_PE_CD_COUNT );Why is there no locking here? Shouldn't this be under
ring->write_lock?
Quoted 6 lines
Hi Herbert,
this is really to tell DMA that there is new packet to process and gets decreased instantly.
The lock is used to track what descriptor index should be used in the ring in the put and get
functions.
AFAICS it's not safe to call eip93_put_descriptor simultaneously since it doesn't use atomics. Without locking in eip93_send_hash_req two threads hashing into two separate eip93 requests will be calling eip93_put_descriptor at the same time.
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
Christian Marangi (Ansuel)
maintainerRe: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Il giorno mar 1 apr 2025 alle ore 12:57 Herbert Xu <[email protected]> ha scritto:
Quoted 34 lines · Christian Marangi (Ansuel)
Quoted 25 lines
Il giorno mar 1 apr 2025 alle ore 12:08 Herbert Xu <[email protected]> ha scritto:
Quoted 9 lines · Christian Marangi
Quoted 4 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +3
-0+static int eip93_send_hash_req (struct crypto_async_request *async,u8 *data, +dma_addr_t *data_dma,u32 len,bool last) +{...
Quoted 13 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c line 271
Quoted 10 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +10
-0+again: + ret =eip93_put_descriptor (eip93, &cdesc); +if (ret) { +usleep_range (EIP93_RING_BUSY_DELAY , +EIP93_RING_BUSY_DELAY *2 ); + goto again; + } + +/* Writing new descriptor count starts DMA action */ +writel (1 , eip93->base +EIP93_REG_PE_CD_COUNT );Why is there no locking here? Shouldn't this be under
ring->write_lock?Quoted 6 lines
Hi Herbert,
this is really to tell DMA that there is new packet to process and gets decreased instantly.
The lock is used to track what descriptor index should be used in the ring in the put and get
functions.
Quoted 5 lines
AFAICS it's not safe to call
eip93_put_descriptorsimultaneously since it doesn't use atomics. Without locking ineip93_send_hash_reqtwo threads hashing into two separate eip93 requests will be callingeip93_put_descriptorat the same time.
Sorry but isn't it enough to acquire lock before eip93_put_descriptor to prevent 2 thread?
Or you are suggesting that also
writel(1, eip93->base + EIP93_REG_PE_CD_COUNT);
should be done atomically?
Maybe I can better handle that writel(1) by using atomic_t value and atomic_inc/dec?
Herbert Xu
maintainerRe: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Quoted 3 lines · Christian Marangi (Ansuel)
Sorry but isn't it enough to acquire lock before
eip93_put_descriptorto prevent 2 thread?
It would be, but where is the lock? In the other places where the same function is used you take the ring write lock. But not here in the hash function.
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
Christian Marangi (Ansuel)
maintainerRe: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Il giorno mar 1 apr 2025 alle ore 13:33 Herbert Xu <[email protected]> ha scritto:
Quoted 10 lines · Christian Marangi (Ansuel)
Quoted 3 lines
Sorry but isn't it enough to acquire lock before
eip93_put_descriptorto prevent 2 thread?It would be, but where is the lock? In the other places where the same function is used you take the ring write lock. But not here in the hash function.
Oh god! You are right, now I'm noticing... The scoped guard is missing!
Let me quickly send a fix-up patch!
Herbert Xu
maintainerRe: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
In reply to Christian MarangiQuoted 6 lines · Christian Marangi
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +5
-0+static void eip93_hash_export_sa_state (struct ahash_request *req, +struct eip93_hash_export_state *state) +{ +struct eip93_hash_reqctx *rctx =ahash_request_ctx_dma (req); +struct sa_state *sa_state = &rctx->sa_state;
drivers/crypto/inside-secure/eip93/eip93-hash.c line 140
Quoted 10 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +10
-0+ +/* +* EIP93 have special handling for state_byte_cnt in sa_state. +* Even if a zero packet is passed (and a BADMSG is returned), +* state_byte_cnt is incremented to the digest handled (with the hash +* primitive). This is problematic with export/import as EIP93 +* expect 0 state_byte_cnt for the very first iteration. +*/ +if (!rctx->len) +memset (state->state_len,0 ,sizeof (u32) *2 );
I don't understand when this can occur. As far as I can see, zero-length packets are never passed to the hardware for hashing.
drivers/crypto/inside-secure/eip93/eip93-hash.c line 143
Quoted 3 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +3
-0+else +memcpy (state->state_len, sa_state->state_byte_cnt, +sizeof (u32) *2 );
I need to know the endianness of state_byte_cnt, which I presume is the number of bytes that have been hashed into the partial hash state.
I need this because I'm changing the export format of all ahash algorithms to match that of the generic implementation. This is so that you can seamlessly switch between an async ahash and its sync fallback.
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
Christian Marangi (Ansuel)
maintainerRe: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Il giorno mar 1 apr 2025 alle ore 12:53 Herbert Xu <[email protected]> ha scritto:
Quoted 13 lines · Christian Marangi
Quoted 11 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +10
-0+static void eip93_hash_export_sa_state (struct ahash_request *req, +struct eip93_hash_export_state *state) +{ +struct eip93_hash_reqctx *rctx =ahash_request_ctx_dma (req); +struct sa_state *sa_state = &rctx->sa_state; + +/* +* EIP93 have special handling for state_byte_cnt in sa_state. +* Even if a zero packet is passed (and a BADMSG is returned), +* state_byte_cnt is incremented to the digest handled (with the hash
Quoted 9 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c line 140
Quoted 5 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +5
-0+* primitive). This is problematic with export/import as EIP93 +* expect 0 state_byte_cnt for the very first iteration. +*/ +if (!rctx->len) +memset (state->state_len,0 ,sizeof (u32) *2 );I don't understand when this can occur. As far as I can see, zero-length packets are never passed to the hardware for hashing.
I did some extra check on this and you are right. This was a leftover (and discovery) when we were discussing on how to correctly implement import/export.
My initial idea was to send a zero packet on export to sync and wait for DMA to finish. But this was scrapped in favor of -EINPROGRESS in the update function (that wasn't aware of possible)
If you are ok I can send a patch to drop this (and maybe leave the comment just to document this strange finding)
What do you think?
Quoted 7 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c line 143
Quoted 3 lines
drivers/crypto/inside-secure/eip93/eip93-hash.c new file +3
-0+else +memcpy (state->state_len, sa_state->state_byte_cnt, +sizeof (u32) *2 );I need to know the endianness of
state_byte_cnt, which I presume is the number of bytes that have been hashed into the partial hash state.
It's LE.
Quoted 6 lines
I need this because I'm changing the export format of all ahash algorithms to match that of the generic implementation. This is so that you can seamlessly switch between an async ahash and its sync fallback.
Herbert Xu
maintainerRe: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
Quoted 5 lines · Christian Marangi (Ansuel)
If you are ok I can send a patch to drop this (and maybe leave the comment just to document this strange finding)
What do you think?
Thanks for checking. There is no need to send a patch for this since I can just remove it when changing the export/import format.
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
Herbert Xu
maintainerQuoted 96 lines · Christian Marangi
This small series add support for the Inside Secure EIP-93. This is a predecessor of the current supported EIP197. It doesn't require a firmware but instead it's embedded in the SoC.
First patch extend guard for
spinlock_bh.The other actually implement Documentation and Driver.
The Driver pass all the normal selft test for the supported algo and also pass the EXTRA test with
fuzz_iterationsset to 10000.Changes v11:
- Drop any mtk variable reference and use eip93 instead
- Mute smatch warning for context unbalance by usingscoped_guardinstead of guard cleanup API
Changes v10:
- UseCRYPTO_ALG_ASYNCforeip93_hmac_setkey
Changes v9:
- Rework hash code to alloc DMA only when needed
- Rework hash code to only alloc needed blocks and use
local struct in req for everything else
- Rework hash code to useGFP_ATOMIC
- Simplify hash update function
- Generalize hmac key set function
Changes v8:
- Rework export and update to not sleep on exporting state (consume pending packet in update and return-EINPROGRESS)
Changes v7:
- Fix copypaste error in__eip93_hash_init
- Rework import/export to actually export the partial hash (we actually unmap DMA on export)
- Renameno_finalizevariable to betterpartial_hash
- Rename 3rd commit title and drop Mediatek from title.
- Add Cover Letter
- Add Reviewed-by to DT commit
(cumulative changes from old series that had changelog in each patch) Changes v6:
- Add SoC specific compatible
- Add now supported entry for compatible with no user
Changes v5:
- Add Ack tag to guard patch
- Comment out compatible with no current user
- Fix smatch warning (reported by Dan Carpenter)
Changes v4:
- Out of RFC
- Add missingbitfield.h
- Drop useless header
Changes v3:
- Mute warning from Clang about C23
- Fix not inizialized err
- Drop unused variable
- Add SoC compatible with generic one
Changes v2:
- Rename all variables from mtk to eip93
- Move to inside-secure directory
- Check DMA map errors
- Use guard API for spinlock
- Minor improvements to code
- Add guard patch
- Change to better compatible
- Add description for EIP93 modelsChristian Marangi (3):
spinlock: extend guard withspinlock_bhvariants
dt-bindings: crypto: Add Inside Secure SafeXcel EIP-93 crypto engine
crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support.../crypto/inside-secure,safexcel-eip93.yaml | 67 ++ MAINTAINERS | 7 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/inside-secure/eip93/Kconfig | 20 + drivers/crypto/inside-secure/eip93/Makefile | 5 + .../crypto/inside-secure/eip93/eip93-aead.c | 711 ++++++++++++++ .../crypto/inside-secure/eip93/eip93-aead.h | 38 + .../crypto/inside-secure/eip93/eip93-aes.h | 16 + .../crypto/inside-secure/eip93/eip93-cipher.c | 413 +++++++++ .../crypto/inside-secure/eip93/eip93-cipher.h | 60 ++ .../crypto/inside-secure/eip93/eip93-common.c | 809 ++++++++++++++++ .../crypto/inside-secure/eip93/eip93-common.h | 24 + .../crypto/inside-secure/eip93/eip93-des.h | 16 + .../crypto/inside-secure/eip93/eip93-hash.c | 866 ++++++++++++++++++ .../crypto/inside-secure/eip93/eip93-hash.h | 82 ++ .../crypto/inside-secure/eip93/eip93-main.c | 501 ++++++++++ .../crypto/inside-secure/eip93/eip93-main.h | 151 +++ .../crypto/inside-secure/eip93/eip93-regs.h | 335 +++++++ include/linux/spinlock.h | 13 + 20 files changed, 4136 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/inside-secure,safexcel-eip93.yaml create mode 100644 drivers/crypto/inside-secure/eip93/Kconfig create mode 100644 drivers/crypto/inside-secure/eip93/Makefile create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aead.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-aes.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-cipher.h
Quoted 11 lines
create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-common.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-des.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-hash.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.c create mode 100644 drivers/crypto/inside-secure/eip93/eip93-main.h create mode 100644 drivers/crypto/inside-secure/eip93/eip93-regs.hSignature · 1 line
2.45.2
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