Skip to contentSkip to conversation

crypto: Add Keem Bay OCS HCU driver

PATCH In review Daniele Alessandrelli 3 participants 8 messages Dec 16, 2020 – Jan 4, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover crypto: Add Keem Bay OCS HCU driver

The Intel Keem Bay SoC has an Offload Crypto Subsystem (OCS) featuring a Hashing Control Unit (HCU) for accelerating hashing operations.

This driver adds support for such hardware thus enabling hardware-accelerated hashing on the Keem Bay SoC for the following algorithms:
- sha224 and hmac(sha224)
- sha256 and hmac(sha256)
- sha384 and hmac(sha384)
- sha512 and hmac(sha512)
- sm3 and hmac(sm3)

The driver is passing crypto manager self-tests, including the extra tests (CRYPTO_MANAGER_EXTRA_TESTS=y).

v3 -> v4:
- Addressed comments from Mark Gross.
- Added Reviewed-by-tag from Rob Herring to DT binding patch.
- Driver reworked to better separate the code interacting with the hardware from the code implementing the crypto ahash API.
- Main patch split into 3 different patches to simplify review (patch series is now composed of 5 patches)

v2 -> v3:
- Fixed more issues with dt-bindings (removed useless descriptions for reg, interrupts, and clocks)

v1 -> v2:
- Fixed issues with dt-bindings

Daniele Alessandrelli (3):
crypto: keembay-ocs-hcu - Add HMAC support
crypto: keembay-ocs-hcu - Add optional support for sha224
MAINTAINERS: Add maintainers for Keem Bay OCS HCU driver

Declan Murphy (2):
dt-bindings: crypto: Add Keem Bay OCS HCU bindings
crypto: keembay - Add Keem Bay OCS HCU driver

 .../crypto/intel,keembay-ocs-hcu.yaml         |   46 +
 MAINTAINERS                                   |   11 +
 drivers/crypto/keembay/Kconfig                |   29 +
 drivers/crypto/keembay/Makefile               |    3 +
 drivers/crypto/keembay/keembay-ocs-hcu-core.c | 1264 +++++++++++++++++
 drivers/crypto/keembay/ocs-hcu.c              |  840 +++++++++++
 drivers/crypto/keembay/ocs-hcu.h              |  106 ++
 7 files changed, 2299 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/intel,keembay-ocs-hcu.yaml
 create mode 100644 drivers/crypto/keembay/keembay-ocs-hcu-core.c
 create mode 100644 drivers/crypto/keembay/ocs-hcu.c
 create mode 100644 drivers/crypto/keembay/ocs-hcu.h

base-commit: 7bba37a1591369e2e506d599b8f5d7d0516b2dbc

Signature · 1 line
2.26.2
#1 lore raw

PATCH v4 1/5 dt-bindings: crypto: Add Keem Bay OCS HCU bindings

From: Declan Murphy <[email protected]>

Add device-tree bindings for the Intel Keem Bay Offload Crypto Subsystem (OCS) Hashing Control Unit (HCU) crypto driver.

---
 .../crypto/intel,keembay-ocs-hcu.yaml         | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/intel,keembay-ocs-hcu.yaml
Documentation/devicetree/bindings/crypto/intel,keembay-ocs-hcu.yaml new file +46 -0
new file mode 100644
index 000000000000..acb92706d280
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/crypto/intel,keembay-ocs-hcu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Intel Keem Bay OCS HCU Device Tree Bindings
+
+maintainers:
+  - Declan Murphy <[email protected]>
+  - Daniele Alessandrelli <[email protected]>
+
+description:
+  The Intel Keem Bay Offload and Crypto Subsystem (OCS) Hash Control Unit (HCU)
+  provides hardware-accelerated hashing and HMAC.
+
+properties:
+  compatible:
+    const: intel,keembay-ocs-hcu
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    crypto@3000b000 {
+      compatible = "intel,keembay-ocs-hcu";
+      reg = <0x3000b000 0x1000>;
+      interrupts = <GIC_SPI 121 IRQ_TYPE_LEVEL_HIGH>;
+      clocks = <&scmi_clk 94>;
+    };
Signature · 1 line
2.26.2
#2 lore raw

PATCH v4 2/5 crypto: keembay - Add Keem Bay OCS HCU driver

In reply to Daniele Alessandrelli

From: Declan Murphy <[email protected]>

Add support for the Hashing Control Unit (HCU) included in the Offload Crypto Subsystem (OCS) of the Intel Keem Bay SoC, thus enabling hardware-accelerated hashing on the Keem Bay SoC for the following algorithms:
- sha256
- sha384
- sha512
- sm3

The driver is composed of two files:

- 'ocs-hcu.c' which interacts with the hardware and abstracts it by providing an API following the usual paradigm used in hashing drivers / libraries (e.g., hash_init(), hash_update(), hash_final(), etc.).
NOTE: this API can block and sleep, since completions are used to wait for the HW to complete the hashing.

- 'keembay-ocs-hcu-core.c' which exports the functionality provided by 'ocs-hcu.c' as a ahash crypto driver. The crypto engine is used to provide asynchronous behavior. 'keembay-ocs-hcu-core.c' also takes care of the DMA mapping of the input sg list.

The driver passes crypto manager self-tests, including the extra tests (CRYPTO_MANAGER_EXTRA_TESTS=y).

---
 drivers/crypto/keembay/Kconfig                |  17 +
 drivers/crypto/keembay/Makefile               |   3 +
 drivers/crypto/keembay/keembay-ocs-hcu-core.c | 830 ++++++++++++++++++
 drivers/crypto/keembay/ocs-hcu.c              | 684 +++++++++++++++
 drivers/crypto/keembay/ocs-hcu.h              |  98 +++
 5 files changed, 1632 insertions(+)
 create mode 100644 drivers/crypto/keembay/keembay-ocs-hcu-core.c
 create mode 100644 drivers/crypto/keembay/ocs-hcu.c
 create mode 100644 drivers/crypto/keembay/ocs-hcu.h
drivers/crypto/keembay/Kconfig +17 -0
index 3c16797b25b9..d207a4511b7e 100644
@@ -37,3 +37,20 @@ config CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS
 	  Provides OCS version of cts(cbc(aes)) and cts(cbc(sm4)).
 
 	  Intel does not recommend use of CTS mode with AES/SM4.
+
+config CRYPTO_DEV_KEEMBAY_OCS_HCU
+	tristate "Support for Intel Keem Bay OCS HCU HW acceleration"
+	select CRYPTO_HASH
+	select CRYPTO_ENGINE
+	depends on OF || COMPILE_TEST
+	help
+	  Support for Intel Keem Bay Offload and Crypto Subsystem (OCS) Hash
+	  Control Unit (HCU) hardware acceleration for use with Crypto API.
+
+	  Provides OCS HCU hardware acceleration of sha256, sha384, sha512, and
+	  sm3.
+
+	  Say Y or M if you're building for the Intel Keem Bay SoC. If compiled
+	  as a module, the module will be called keembay-ocs-hcu.
+
+	  If unsure, say N.
drivers/crypto/keembay/Makefile +3 -0
index f21e2c4ab3b3..aea03d4432c4 100644
@@ -3,3 +3,6 @@
 #
 obj-$(CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4) += keembay-ocs-aes.o
 keembay-ocs-aes-objs := keembay-ocs-aes-core.o ocs-aes.o
+
+obj-$(CONFIG_CRYPTO_DEV_KEEMBAY_OCS_HCU) += keembay-ocs-hcu.o
+keembay-ocs-hcu-objs := keembay-ocs-hcu-core.o ocs-hcu.o
drivers/crypto/keembay/keembay-ocs-hcu-core.c new file +830 -0

830 lines not on this page · raw message

drivers/crypto/keembay/ocs-hcu.c new file +684 -0

684 lines not on this page · raw message

drivers/crypto/keembay/ocs-hcu.h new file +98 -0

98 lines not on this page · raw message

Signature · 1 line
2.26.2
#3 lore raw

PATCH v4 3/5 crypto: keembay-ocs-hcu - Add HMAC support

In reply to Daniele Alessandrelli

From: Daniele Alessandrelli <[email protected]>

Add HMAC support to the Keem Bay OCS HCU driver, thus making it provide the following additional transformations:
- hmac(sha256)
- hmac(sha384)
- hmac(sha512)
- hmac(sm3)

The Keem Bay OCS HCU hardware does not allow "context-switch" for HMAC operations, i.e., it does not support computing a partial HMAC, save its state and then continue it later. Therefore, full hardware acceleration is provided only when possible (e.g., when crypto_ahash_digest() is called); in all other cases hardware acceleration is only partial (OPAD and IPAD calculation is done in software, while hashing is hardware accelerated).

---
 drivers/crypto/keembay/Kconfig                |   2 +-
 drivers/crypto/keembay/keembay-ocs-hcu-core.c | 387 +++++++++++++++++-
 drivers/crypto/keembay/ocs-hcu.c              | 156 +++++++
 drivers/crypto/keembay/ocs-hcu.h              |   8 +
 4 files changed, 544 insertions(+), 9 deletions(-)
drivers/crypto/keembay/Kconfig +1 -1
index d207a4511b7e..a4e7a1626cef 100644
@@ -48,7 +48,7 @@ config CRYPTO_DEV_KEEMBAY_OCS_HCU
 	  Control Unit (HCU) hardware acceleration for use with Crypto API.
 
 	  Provides OCS HCU hardware acceleration of sha256, sha384, sha512, and
-	  sm3.
+	  sm3, as well as the HMAC variant of these algorithms.
 
 	  Say Y or M if you're building for the Intel Keem Bay SoC. If compiled
 	  as a module, the module will be called keembay-ocs-hcu.
drivers/crypto/keembay/keembay-ocs-hcu-core.c +379 -8

519 lines not on this page · raw message

drivers/crypto/keembay/ocs-hcu.c +156 -0

168 lines not on this page · raw message

drivers/crypto/keembay/ocs-hcu.h +8 -0
index 6a467dcaf99c..fbbbb92a0592 100644
@@ -95,4 +95,12 @@ int ocs_hcu_hash_final(struct ocs_hcu_dev *hcu_dev,
 		       const struct ocs_hcu_hash_ctx *ctx, u8 *dgst,
 		       size_t dgst_len);
 
+int ocs_hcu_digest(struct ocs_hcu_dev *hcu_dev, enum ocs_hcu_algo algo,
+		   void *data, size_t data_len, u8 *dgst, size_t dgst_len);
+
+int ocs_hcu_hmac(struct ocs_hcu_dev *hcu_dev, enum ocs_hcu_algo algo,
+		 const u8 *key, size_t key_len,
+		 const struct ocs_hcu_dma_list *dma_list,
+		 u8 *dgst, size_t dgst_len);
+
 #endif /* _CRYPTO_OCS_HCU_H */
Signature · 1 line
2.26.2
#4 lore raw

PATCH v4 4/5 crypto: keembay-ocs-hcu - Add optional support for sha224

In reply to Daniele Alessandrelli

From: Daniele Alessandrelli <[email protected]>

Add optional support of sha224 and hmac(sha224).

---
 drivers/crypto/keembay/Kconfig                | 12 ++++
 drivers/crypto/keembay/keembay-ocs-hcu-core.c | 63 +++++++++++++++++++
 2 files changed, 75 insertions(+)
drivers/crypto/keembay/Kconfig +12 -0
index a4e7a1626cef..2b2f514f116b 100644
@@ -54,3 +54,15 @@ config CRYPTO_DEV_KEEMBAY_OCS_HCU
 	  as a module, the module will be called keembay-ocs-hcu.
 
 	  If unsure, say N.
+
+config CRYPTO_DEV_KEEMBAY_OCS_HCU_HMAC_SHA224
+	bool "Enable sha224 and hmac(sha224) support in Intel Keem Bay OCS HCU"
+	depends on CRYPTO_DEV_KEEMBAY_OCS_HCU
+	help
+	  Enables support for sha224 and hmac(sha224) algorithms in the Intel
+	  Keem Bay OCS HCU driver. Intel recommends not to use these
+	  algorithms.
+
+	  Provides OCS HCU hardware acceleration of sha224 and hmac(224).
+
+	  If unsure, say N.
drivers/crypto/keembay/keembay-ocs-hcu-core.c +63 -0

81 lines not on this page · raw message

Signature · 1 line
2.26.2
#5 lore raw

PATCH v4 5/5 MAINTAINERS: Add maintainers for Keem Bay OCS HCU driver

In reply to Daniele Alessandrelli

From: Daniele Alessandrelli <[email protected]>

Add maintainers for the Intel Keem Bay Offload Crypto Subsystem (OCS) Hash Control Unit (HCU) crypto driver.

---
 MAINTAINERS | 11 +++++++++++
 1 file changed, 11 insertions(+)
MAINTAINERS +11 -0
index c9e221929961..a610b78fc4a2 100644
@@ -9068,6 +9068,17 @@ F:	drivers/crypto/keembay/keembay-ocs-aes-core.c
 F:	drivers/crypto/keembay/ocs-aes.c
 F:	drivers/crypto/keembay/ocs-aes.h
 
+INTEL KEEM BAY OCS HCU CRYPTO DRIVER
+M:	Daniele Alessandrelli <[email protected]>
+M:	Declan Murphy <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/crypto/intel,keembay-ocs-hcu.yaml
+F:	drivers/crypto/keembay/Kconfig
+F:	drivers/crypto/keembay/Makefile
+F:	drivers/crypto/keembay/keembay-ocs-hcu-core.c
+F:	drivers/crypto/keembay/ocs-hcu.c
+F:	drivers/crypto/keembay/ocs-hcu.h
+
 INTEL MANAGEMENT ENGINE (mei)
 M:	Tomas Winkler <[email protected]>
 L:	[email protected]
Signature · 1 line
2.26.2
maintainer
#6 lore raw
In reply to Daniele Alessandrelli
Quoted 38 lines · Daniele Alessandrelli

The Intel Keem Bay SoC has an Offload Crypto Subsystem (OCS) featuring a Hashing Control Unit (HCU) for accelerating hashing operations.

This driver adds support for such hardware thus enabling hardware-accelerated hashing on the Keem Bay SoC for the following algorithms:
- sha224 and hmac(sha224)
- sha256 and hmac(sha256)
- sha384 and hmac(sha384)
- sha512 and hmac(sha512)
- sm3 and hmac(sm3)

The driver is passing crypto manager self-tests, including the extra tests (CRYPTO_MANAGER_EXTRA_TESTS=y).

v3 -> v4:
- Addressed comments from Mark Gross.
- Added Reviewed-by-tag from Rob Herring to DT binding patch.
- Driver reworked to better separate the code interacting with the hardware from the code implementing the crypto ahash API.
- Main patch split into 3 different patches to simplify review (patch series is now composed of 5 patches)

v2 -> v3:
- Fixed more issues with dt-bindings (removed useless descriptions for reg, interrupts, and clocks)

v1 -> v2:
- Fixed issues with dt-bindings

Daniele Alessandrelli (3):
crypto: keembay-ocs-hcu - Add HMAC support
crypto: keembay-ocs-hcu - Add optional support for sha224
MAINTAINERS: Add maintainers for Keem Bay OCS HCU driver

Declan Murphy (2):
dt-bindings: crypto: Add Keem Bay OCS HCU bindings
crypto: keembay - Add Keem Bay OCS HCU driver

Quoted 12 lines
 .../crypto/intel,keembay-ocs-hcu.yaml         |   46 +
 MAINTAINERS                                   |   11 +
 drivers/crypto/keembay/Kconfig                |   29 +
 drivers/crypto/keembay/Makefile               |    3 +
 drivers/crypto/keembay/keembay-ocs-hcu-core.c | 1264 +++++++++++++++++
 drivers/crypto/keembay/ocs-hcu.c              |  840 +++++++++++
 drivers/crypto/keembay/ocs-hcu.h              |  106 ++
 7 files changed, 2299 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/intel,keembay-ocs-hcu.yaml
 create mode 100644 drivers/crypto/keembay/keembay-ocs-hcu-core.c
 create mode 100644 drivers/crypto/keembay/ocs-hcu.c
 create mode 100644 drivers/crypto/keembay/ocs-hcu.h

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
#7 lore raw
Quoted 61 lines · Herbert Xu
Quoted 44 lines · Daniele Alessandrelli

The Intel Keem Bay SoC has an Offload Crypto Subsystem (OCS) featuring a
Hashing Control Unit (HCU) for accelerating hashing operations.

This driver adds support for such hardware thus enabling hardware- accelerated
hashing on the Keem Bay SoC for the following algorithms:
- sha224 and hmac(sha224)
- sha256 and hmac(sha256)
- sha384 and hmac(sha384)
- sha512 and hmac(sha512)
- sm3 and hmac(sm3)

The driver is passing crypto manager self-tests, including the extra tests
(CRYPTO_MANAGER_EXTRA_TESTS=y).

v3 -> v4:
- Addressed comments from Mark Gross.
- Added Reviewed-by-tag from Rob Herring to DT binding patch.
- Driver reworked to better separate the code interacting with the hardware
from the code implementing the crypto ahash API.
- Main patch split into 3 different patches to simplify review (patch series is
now composed of 5 patches)

v2 -> v3:
- Fixed more issues with dt-bindings (removed useless descriptions for reg,
interrupts, and clocks)

v1 -> v2:
- Fixed issues with dt-bindings

Daniele Alessandrelli (3):
crypto: keembay-ocs-hcu - Add HMAC support
crypto: keembay-ocs-hcu - Add optional support for sha224
MAINTAINERS: Add maintainers for Keem Bay OCS HCU driver

Declan Murphy (2):
dt-bindings: crypto: Add Keem Bay OCS HCU bindings
crypto: keembay - Add Keem Bay OCS HCU driver

Quoted 14 lines
 .../crypto/intel,keembay-ocs-hcu.yaml         |   46 +
 MAINTAINERS                                   |   11 +
 drivers/crypto/keembay/Kconfig                |   29 +
 drivers/crypto/keembay/Makefile               |    3 +
 drivers/crypto/keembay/keembay-ocs-hcu-core.c | 1264
+++++++++++++++++
 drivers/crypto/keembay/ocs-hcu.c              |  840 +++++++++++
 drivers/crypto/keembay/ocs-hcu.h              |  106 ++
 7 files changed, 2299 insertions(+)
 create mode 100644
Documentation/devicetree/bindings/crypto/intel,keembay-ocs-hcu.yaml
 create mode 100644 drivers/crypto/keembay/keembay-ocs-hcu-core.c
 create mode 100644 drivers/crypto/keembay/ocs-hcu.c
 create mode 100644 drivers/crypto/keembay/ocs-hcu.h
Quoted 1 line

All applied. Thanks.

Thanks Herbert.

Just a note, this patch series was sent before the following two issues about the Keem Bay AES driver were reported:
1. https://lore.kernel.org/linux-crypto/[email protected]/
2. https://lore.kernel.org/lkml/[email protected]/

I think that this patch set has the same issues, but, due to the Christmas / New Year holidays, I wasn't able to double check that and send an updated series.

I will now look into it and send a new patch to fix the issues soon (if confirmed).

Regards,
Daniele