Skip to contentSkip to conversation

Add MediaTek crypto acclelrator driver

PATCH In review Ryder Lee 2 participants 6 messages Dec 2, 2016

Subsystems (3)
lore
Share & tools
lore

Ryder Lee

author
#0 lore raw

cover Add MediaTek crypto acclelrator driver

This adds support for the MediaTek hardware accelerator on mt7623 SoC.

This driver currently implement:
- SHA1 and SHA2 family(HMAC) hash alogrithms.
- AES block cipher in CBC/ECB mode with 128/196/256 bits keys.

Ryder Lee (2):
Add crypto driver support for some MediaTek chips
crypto: mediatek - add DT bindings documentation

 .../devicetree/bindings/crypto/mediatek-crypto.txt |   32 +
 drivers/crypto/Kconfig                             |   17 +
 drivers/crypto/Makefile                            |    1 +
 drivers/crypto/mediatek/Makefile                   |    2 +
 drivers/crypto/mediatek/mtk-aes.c                  |  734 +++++++++++
 drivers/crypto/mediatek/mtk-platform.c             |  575 ++++++++
 drivers/crypto/mediatek/mtk-platform.h             |  230 ++++
 drivers/crypto/mediatek/mtk-regs.h                 |  194 +++
 drivers/crypto/mediatek/mtk-sha.c                  | 1384 ++++++++++++++++++++
 9 files changed, 3169 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/mediatek-crypto.txt
 create mode 100644 drivers/crypto/mediatek/Makefile
 create mode 100644 drivers/crypto/mediatek/mtk-aes.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.h
 create mode 100644 drivers/crypto/mediatek/mtk-regs.h
 create mode 100644 drivers/crypto/mediatek/mtk-sha.c
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/2 Add crypto driver support for some MediaTek chips

This adds support for the MediaTek hardware accelerator on mt7623/mt2701/mt8521p SoC.

This driver currently implement:
- SHA1 and SHA2 family(HMAC) hash alogrithms.
- AES block cipher in CBC/ECB mode with 128/196/256 bits keys.

---
 drivers/crypto/Kconfig                 |   17 +
 drivers/crypto/Makefile                |    1 +
 drivers/crypto/mediatek/Makefile       |    2 +
 drivers/crypto/mediatek/mtk-aes.c      |  734 +++++++++++++++++
 drivers/crypto/mediatek/mtk-platform.c |  575 +++++++++++++
 drivers/crypto/mediatek/mtk-platform.h |  230 ++++++
 drivers/crypto/mediatek/mtk-regs.h     |  194 +++++
 drivers/crypto/mediatek/mtk-sha.c      | 1384 ++++++++++++++++++++++++++++++++
 8 files changed, 3137 insertions(+)
 create mode 100644 drivers/crypto/mediatek/Makefile
 create mode 100644 drivers/crypto/mediatek/mtk-aes.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.h
 create mode 100644 drivers/crypto/mediatek/mtk-regs.h
 create mode 100644 drivers/crypto/mediatek/mtk-sha.c
drivers/crypto/Kconfig +17 -0
index 4d2b81f..5d9c803 100644
@@ -553,6 +553,23 @@ config CRYPTO_DEV_ROCKCHIP
 	  This driver interfaces with the hardware crypto accelerator.
 	  Supporting cbc/ecb chainmode, and aes/des/des3_ede cipher mode.
 
+config CRYPTO_DEV_MEDIATEK
+	tristate "MediaTek's Cryptographic Engine driver"
+	depends on ARM && ARCH_MEDIATEK
+	select NEON
+	select KERNEL_MODE_NEON
+	select ARM_CRYPTO
+	select CRYPTO_AES
+	select CRYPTO_BLKCIPHER
+	select CRYPTO_SHA1_ARM_NEON
+	select CRYPTO_SHA256_ARM
+	select CRYPTO_SHA512_ARM
+	select CRYPTO_HMAC
+	help
+	  This driver allows you to utilize the hardware crypto accelerator
+	  which can be found on the MT7623 MT2701, MT8521p, etc ....
+	  Select this if you want to use it for AES/SHA1/SHA2 algorithms.
+
 source "drivers/crypto/chelsio/Kconfig"
 
 endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
index ad7250f..272b51a 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_CRYPTO_DEV_IMGTEC_HASH) += img-hash.o
 obj-$(CONFIG_CRYPTO_DEV_IXP4XX) += ixp4xx_crypto.o
 obj-$(CONFIG_CRYPTO_DEV_MV_CESA) += mv_cesa.o
 obj-$(CONFIG_CRYPTO_DEV_MARVELL_CESA) += marvell/
+obj-$(CONFIG_CRYPTO_DEV_MEDIATEK) += mediatek/
 obj-$(CONFIG_CRYPTO_DEV_MXS_DCP) += mxs-dcp.o
 obj-$(CONFIG_CRYPTO_DEV_NIAGARA2) += n2_crypto.o
 n2_crypto-y := n2_core.o n2_asm.o
drivers/crypto/mediatek/Makefile new file +2 -0
new file mode 100644
index 0000000..187be79
@@ -0,0 +1,2 @@
+obj-$(CONFIG_CRYPTO_DEV_MEDIATEK) += mtk-crypto.o
+mtk-crypto-objs:= mtk-platform.o mtk-aes.o mtk-sha.o
drivers/crypto/mediatek/mtk-aes.c new file +734 -0

734 lines not on this page · raw message

drivers/crypto/mediatek/mtk-platform.c new file +575 -0

575 lines not on this page · raw message

drivers/crypto/mediatek/mtk-platform.h new file +230 -0

230 lines not on this page · raw message

drivers/crypto/mediatek/mtk-regs.h new file +194 -0

194 lines not on this page · raw message

drivers/crypto/mediatek/mtk-sha.c new file +1384 -0

1,235 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.9.1

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [PATCH 1/2] Add crypto driver support for some MediaTek chips

Hello

I have some minor comment inline

Quoted 6 lines · Ryder Lee

This adds support for the MediaTek hardware accelerator on mt7623/mt2701/mt8521p SoC.

This driver currently implement:
- SHA1 and SHA2 family(HMAC) hash alogrithms.
- AES block cipher in CBC/ECB mode with 128/196/256 bits keys.

I see also a PRNG but is seems not really used.

Quoted 29 lines
---
 drivers/crypto/Kconfig                 |   17 +
 drivers/crypto/Makefile                |    1 +
 drivers/crypto/mediatek/Makefile       |    2 +
 drivers/crypto/mediatek/mtk-aes.c      |  734 +++++++++++++++++
 drivers/crypto/mediatek/mtk-platform.c |  575 +++++++++++++
 drivers/crypto/mediatek/mtk-platform.h |  230 ++++++
 drivers/crypto/mediatek/mtk-regs.h     |  194 +++++
 drivers/crypto/mediatek/mtk-sha.c      | 1384 ++++++++++++++++++++++++++++++++
 8 files changed, 3137 insertions(+)
 create mode 100644 drivers/crypto/mediatek/Makefile
 create mode 100644 drivers/crypto/mediatek/mtk-aes.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.h
 create mode 100644 drivers/crypto/mediatek/mtk-regs.h
 create mode 100644 drivers/crypto/mediatek/mtk-sha.c
drivers/crypto/Kconfig +2 -0
index 4d2b81f..5d9c803 100644
@@ -553,6 +553,23 @@ config CRYPTO_DEV_ROCKCHIP
 	  This driver interfaces with the hardware crypto accelerator.
 	  Supporting cbc/ecb chainmode, and aes/des/des3_ede cipher mode.
 
+config CRYPTO_DEV_MEDIATEK
+	tristate "MediaTek's Cryptographic Engine driver"

drivers/crypto/Kconfig config CRYPTO_DEV_ROCKCHIP · line 567

Quoted 10 lines
drivers/crypto/Kconfig +10 -0
+	depends on ARM && ARCH_MEDIATEK
+	select NEON
+	select KERNEL_MODE_NEON
+	select ARM_CRYPTO
+	select CRYPTO_AES
+	select CRYPTO_BLKCIPHER
+	select CRYPTO_SHA1_ARM_NEON
+	select CRYPTO_SHA256_ARM
+	select CRYPTO_SHA512_ARM
+	select CRYPTO_HMAC

Why do you select accelerated algos ?
Adding COMPILE_TEST could be helpfull also.

[...]

drivers/crypto/Kconfig config CRYPTO_DEV_ROCKCHIP

Quoted 9 lines
drivers/crypto/Kconfig +9 -0
+
+#include <linux/dma-mapping.h>
+#include <linux/scatterlist.h>
+#include <crypto/scatterwalk.h>
+#include <crypto/algapi.h>
+#include <crypto/aes.h>
+#include "mtk-platform.h"
+#include "mtk-regs.h"
+

Sort headers in alphabetical order

[...]

drivers/crypto/Kconfig

Quoted 5 lines
drivers/crypto/Kconfig +5 -0
+
+	mtk_aes_unregister_algs();
+	mtk_aes_record_free(cryp);
+}
+EXPORT_SYMBOL(mtk_cipher_alg_release);

Why not EXPORT_SYMBOL_GPL ?
Furthermore do you really need it to be exported ?

[...]

drivers/crypto/Kconfig

Quoted 11 lines
drivers/crypto/Kconfig +11 -0
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/mfd/syscon.h>
+#include <linux/pm_runtime.h>
+#include <linux/clk.h>
+#include <linux/platform_device.h>
+#include "mtk-platform.h"
+#include "mtk-regs.h"
+

Sort headers in alphabetical order

[...]

drivers/crypto/Kconfig

Quoted 9 lines
drivers/crypto/Kconfig +9 -0
+
+static void mtk_prng_reseed(struct mtk_cryp *cryp)
+{
+	/* 8 words to seed the PRNG to provide IVs */
+	void __iomem *base = cryp->base;
+	const u32 prng_key[8] = {0x48c24cfd, 0x6c07f742,
+				0xaee75681, 0x0f27c239,
+				0x79947198, 0xe2991275,
+				0x21ac3c7c, 0xd008c4b4};

Why do you seed with thoses constant ?

[...]

drivers/crypto/Kconfig

Quoted 7 lines
drivers/crypto/Kconfig +7 -0
+
+static int mtk_accelerator_init(struct mtk_cryp *cryp)
+{
+	int i, err;
+
+	/* Initialize advanced interrupt controller(AIC) */
+	for (i = 0; i < 5; i++) {

I see this 5 for interrupt away, so perhaps a define could be used

[...]

here

Quoted 7 lines
drivers/crypto/Kconfig +7 -0
+	for (i = 0; i < 5; i++) {
+		cryp->irq[i] = platform_get_irq(pdev, i);
+		if (cryp->irq[i] < 0) {
+			dev_err(cryp->dev, "no IRQ:%d resource info\n", i);
+			return -ENXIO;
+		}
+	}

[...]

drivers/crypto/Kconfig

Quoted 6 lines
drivers/crypto/Kconfig +6 -0
+#ifndef __MTK_PLATFORM_H_
+#define __MTK_PLATFORM_H_
+
+#include <linux/crypto.h>
+#include <crypto/internal/hash.h>
+#include <linux/interrupt.h>

Sort headers in alphabetical order

[...]

drivers/crypto/Kconfig

Quoted 5 lines
drivers/crypto/Kconfig +5 -0
+#define MTK_DESC_FIRST		BIT(23)
+#define MTK_DESC_BUF_LEN(x)	((x) & 0x1ffff)
+#define MTK_DESC_CT_LEN(x)	(((x) & 0xff) << 24)
+
+#define WORD(x)			((x) >> 2)

dangerous and ambigous define

[...]

drivers/crypto/Kconfig

Quoted 8 lines
drivers/crypto/Kconfig +8 -0
+
+#include <linux/dma-mapping.h>
+#include <linux/scatterlist.h>
+#include <linux/crypto.h>
+#include <crypto/scatterwalk.h>
+#include <crypto/algapi.h>
+#include <crypto/sha.h>
+#include <crypto/internal/hash.h>

Sort headers in alphabetical order
[...]

Generally more function comment could be helpfull.

Regards

author
#3 lore raw

Re: [PATCH 1/2] Add crypto driver support for some MediaTek chips

Hello,

Quoted 5 lines · Corentin Labbe

Hello

I have some minor comment inline

On Fri, Dec 02, 2016 at 11:26:44AM +0800, Ryder Lee wrote:

Quoted 8 lines
Quoted 6 lines

This adds support for the MediaTek hardware accelerator on mt7623/mt2701/mt8521p SoC.

This driver currently implement:
- SHA1 and SHA2 family(HMAC) hash alogrithms.
- AES block cipher in CBC/ECB mode with 128/196/256 bits keys.

I see also a PRNG but is seems not really used.

Yes, PRNG is not implemented yet, i will remove it temporarily.

Quoted 27 lines
Quoted 27 lines
---
 drivers/crypto/Kconfig                 |   17 +
 drivers/crypto/Makefile                |    1 +
 drivers/crypto/mediatek/Makefile       |    2 +
 drivers/crypto/mediatek/mtk-aes.c      |  734 +++++++++++++++++
 drivers/crypto/mediatek/mtk-platform.c |  575 +++++++++++++
 drivers/crypto/mediatek/mtk-platform.h |  230 ++++++
 drivers/crypto/mediatek/mtk-regs.h     |  194 +++++
 drivers/crypto/mediatek/mtk-sha.c      | 1384 ++++++++++++++++++++++++++++++++
 8 files changed, 3137 insertions(+)
 create mode 100644 drivers/crypto/mediatek/Makefile
 create mode 100644 drivers/crypto/mediatek/mtk-aes.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.h
 create mode 100644 drivers/crypto/mediatek/mtk-regs.h
 create mode 100644 drivers/crypto/mediatek/mtk-sha.c
drivers/crypto/Kconfig +0 -0
index 4d2b81f..5d9c803 100644
@@ -553,6 +553,23 @@ config CRYPTO_DEV_ROCKCHIP
 	  This driver interfaces with the hardware crypto accelerator.
 	  Supporting cbc/ecb chainmode, and aes/des/des3_ede cipher mode.
 
Quoted 15 lines

drivers/crypto/Kconfig config CRYPTO_DEV_ROCKCHIP · line 567

Quoted 12 lines
drivers/crypto/Kconfig +12 -0
+config CRYPTO_DEV_MEDIATEK
+	tristate "MediaTek's Cryptographic Engine driver"
+	depends on ARM && ARCH_MEDIATEK
+	select NEON
+	select KERNEL_MODE_NEON
+	select ARM_CRYPTO
+	select CRYPTO_AES
+	select CRYPTO_BLKCIPHER
+	select CRYPTO_SHA1_ARM_NEON
+	select CRYPTO_SHA256_ARM
+	select CRYPTO_SHA512_ARM
+	select CRYPTO_HMAC

Why do you select accelerated algos ?
Adding COMPILE_TEST could be helpfull also.

Our Hardware has complex procedure on calculate HMAC, and it get a bad performance.... So i decide to use ARM NEON instruction as fallback to speedup it.
I will add COMPILE_TEST.

Quoted 14 lines

[...]

drivers/crypto/Kconfig

Quoted 9 lines
drivers/crypto/Kconfig +9 -0
+
+#include <linux/dma-mapping.h>
+#include <linux/scatterlist.h>
+#include <crypto/scatterwalk.h>
+#include <crypto/algapi.h>
+#include <crypto/aes.h>
+#include "mtk-platform.h"
+#include "mtk-regs.h"
+

Sort headers in alphabetical order

[...]

Quoted 8 lines

drivers/crypto/Kconfig

Quoted 5 lines
drivers/crypto/Kconfig +5 -0
+
+	mtk_aes_unregister_algs();
+	mtk_aes_record_free(cryp);
+}
+EXPORT_SYMBOL(mtk_cipher_alg_release);

Why not EXPORT_SYMBOL_GPL ?
Furthermore do you really need it to be exported ?

My mistake. I will remove it.

Quoted 61 lines

[...]

drivers/crypto/Kconfig

Quoted 11 lines
drivers/crypto/Kconfig +11 -0
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/mfd/syscon.h>
+#include <linux/pm_runtime.h>
+#include <linux/clk.h>
+#include <linux/platform_device.h>
+#include "mtk-platform.h"
+#include "mtk-regs.h"
+

Sort headers in alphabetical order

[...]

drivers/crypto/Kconfig

Quoted 9 lines
drivers/crypto/Kconfig +9 -0
+
+static void mtk_prng_reseed(struct mtk_cryp *cryp)
+{
+	/* 8 words to seed the PRNG to provide IVs */
+	void __iomem *base = cryp->base;
+	const u32 prng_key[8] = {0x48c24cfd, 0x6c07f742,
+				0xaee75681, 0x0f27c239,
+				0x79947198, 0xe2991275,
+				0x21ac3c7c, 0xd008c4b4};

Why do you seed with thoses constant ?

[...]

drivers/crypto/Kconfig

Quoted 7 lines
drivers/crypto/Kconfig +7 -0
+
+static int mtk_accelerator_init(struct mtk_cryp *cryp)
+{
+	int i, err;
+
+	/* Initialize advanced interrupt controller(AIC) */
+	for (i = 0; i < 5; i++) {

I see this 5 for interrupt away, so perhaps a define could be used

[...]

here

Quoted 7 lines
drivers/crypto/Kconfig +7 -0
+	for (i = 0; i < 5; i++) {
+		cryp->irq[i] = platform_get_irq(pdev, i);
+		if (cryp->irq[i] < 0) {
+			dev_err(cryp->dev, "no IRQ:%d resource info\n", i);
+			return -ENXIO;
+		}
+	}

[...]

drivers/crypto/Kconfig

Quoted 6 lines
drivers/crypto/Kconfig +6 -0
+#ifndef __MTK_PLATFORM_H_
+#define __MTK_PLATFORM_H_
+
+#include <linux/crypto.h>
+#include <crypto/internal/hash.h>
+#include <linux/interrupt.h>

Sort headers in alphabetical order

Quoted 8 lines

[...]

drivers/crypto/Kconfig

Quoted 5 lines
drivers/crypto/Kconfig +5 -0
+#define MTK_DESC_FIRST		BIT(23)
+#define MTK_DESC_BUF_LEN(x)	((x) & 0x1ffff)
+#define MTK_DESC_CT_LEN(x)	(((x) & 0xff) << 24)
+
+#define WORD(x)			((x) >> 2)

dangerous and ambigous define

I will define a IRQ_NUM and modify ambiguous definition.

Quoted 13 lines

[...]

drivers/crypto/Kconfig

Quoted 8 lines
drivers/crypto/Kconfig +8 -0
+
+#include <linux/dma-mapping.h>
+#include <linux/scatterlist.h>
+#include <linux/crypto.h>
+#include <crypto/scatterwalk.h>
+#include <crypto/algapi.h>
+#include <crypto/sha.h>
+#include <crypto/internal/hash.h>

Sort headers in alphabetical order
[...]
Generally more function comment could be helpfull.

I will sort all header and add more function comment. Thanks for your review.

Quoted 1 line

Regards

author
#4 lore raw

Re: [PATCH 1/2] Add crypto driver support for some MediaTek chips

In reply to Corentin Labbe

Hello,

Quoted 5 lines · Corentin Labbe

Hello

I have some minor comment inline

On Fri, Dec 02, 2016 at 11:26:44AM +0800, Ryder Lee wrote:

Quoted 8 lines
Quoted 6 lines

This adds support for the MediaTek hardware accelerator on mt7623/mt2701/mt8521p SoC.

This driver currently implement:
- SHA1 and SHA2 family(HMAC) hash alogrithms.
- AES block cipher in CBC/ECB mode with 128/196/256 bits keys.

I see also a PRNG but is seems not really used.

Yes, PRNG is not implemented yet, i will remove it temporarily.

Quoted 11 lines
Quoted 11 lines
---
 drivers/crypto/Kconfig                 |   17 +
 drivers/crypto/Makefile                |    1 +
 drivers/crypto/mediatek/Makefile       |    2 +
 drivers/crypto/mediatek/mtk-aes.c      |  734 +++++++++++++++++
 drivers/crypto/mediatek/mtk-platform.c |  575 +++++++++++++
 drivers/crypto/mediatek/mtk-platform.h |  230 ++++++
 drivers/crypto/mediatek/mtk-regs.h     |  194 +++++
 drivers/crypto/mediatek/mtk-sha.c      | 1384

++++++++++++++++++++++++++++++++

Quoted 8 lines
Quoted 8 lines
 8 files changed, 3137 insertions(+)
 create mode 100644 drivers/crypto/mediatek/Makefile
 create mode 100644 drivers/crypto/mediatek/mtk-aes.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.c
 create mode 100644 drivers/crypto/mediatek/mtk-platform.h
 create mode 100644 drivers/crypto/mediatek/mtk-regs.h
 create mode 100644 drivers/crypto/mediatek/mtk-sha.c
Quoted 7 lines

drivers/crypto/Kconfig config CRYPTO_DEV_ROCKCHIP · line 554

Quoted 7 lines
drivers/crypto/Kconfig +0 -0
index 4d2b81f..5d9c803 100644
@@ -553,6 +553,23 @@ config CRYPTO_DEV_ROCKCHIP
      This driver interfaces with the hardware crypto accelerator.
      Supporting cbc/ecb chainmode, and aes/des/des3_ede cipher

mode.

Quoted 14 lines

drivers/crypto/Kconfig config CRYPTO_DEV_ROCKCHIP · line 567

Quoted 13 lines
drivers/crypto/Kconfig +12 -0
+config CRYPTO_DEV_MEDIATEK
+   tristate "MediaTek's Cryptographic Engine driver"
+   depends on ARM && ARCH_MEDIATEK
+   select NEON
+   select KERNEL_MODE_NEON
+   select ARM_CRYPTO
+   select CRYPTO_AES
+   select CRYPTO_BLKCIPHER
+   select CRYPTO_SHA1_ARM_NEON
+   select CRYPTO_SHA256_ARM
+   select CRYPTO_SHA512_ARM
+   select CRYPTO_HMAC
Quoted 2 lines

Why do you select accelerated algos ?
Adding COMPILE_TEST could be helpfull also.

Our Hardware has complex procedure on calculate HMAC, and it get a bad performance.... So i decide to use ARM NEON instruction as fallback to speedup it.
I will add COMPILE_TEST.

Quoted 14 lines

[...]

drivers/crypto/Kconfig

Quoted 9 lines
drivers/crypto/Kconfig +9 -0
+
+#include <linux/dma-mapping.h>
+#include <linux/scatterlist.h>
+#include <crypto/scatterwalk.h>
+#include <crypto/algapi.h>
+#include <crypto/aes.h>
+#include "mtk-platform.h"
+#include "mtk-regs.h"
+

Sort headers in alphabetical order

[...]

Quoted 8 lines

drivers/crypto/Kconfig

Quoted 5 lines
drivers/crypto/Kconfig +5 -0
+
+   mtk_aes_unregister_algs();
+   mtk_aes_record_free(cryp);
+}
+EXPORT_SYMBOL(mtk_cipher_alg_release);

Why not EXPORT_SYMBOL_GPL ?
Furthermore do you really need it to be exported ?

My mistake. I will remove it.

Quoted 39 lines

[...]

drivers/crypto/Kconfig

Quoted 11 lines
drivers/crypto/Kconfig +11 -0
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/mfd/syscon.h>
+#include <linux/pm_runtime.h>
+#include <linux/clk.h>
+#include <linux/platform_device.h>
+#include "mtk-platform.h"
+#include "mtk-regs.h"
+

Sort headers in alphabetical order

[...]

drivers/crypto/Kconfig

Quoted 9 lines
drivers/crypto/Kconfig +9 -0
+
+static void mtk_prng_reseed(struct mtk_cryp *cryp)
+{
+   /* 8 words to seed the PRNG to provide IVs */
+   void __iomem *base = cryp->base;
+   const u32 prng_key[8] = {0x48c24cfd, 0x6c07f742,
+                           0xaee75681, 0x0f27c239,
+                           0x79947198, 0xe2991275,
+                           0x21ac3c7c, 0xd008c4b4};

Why do you seed with thoses constant ?

[...]

drivers/crypto/Kconfig

Quoted 7 lines
drivers/crypto/Kconfig +7 -0
+
+static int mtk_accelerator_init(struct mtk_cryp *cryp)
+{
+   int i, err;
+
+   /* Initialize advanced interrupt controller(AIC) */
+   for (i = 0; i < 5; i++) {

I see this 5 for interrupt away, so perhaps a define could be used

Quoted 8 lines

[...]

here

Quoted 4 lines
drivers/crypto/Kconfig +4 -0
+   for (i = 0; i < 5; i++) {
+           cryp->irq[i] = platform_get_irq(pdev, i);
+           if (cryp->irq[i] < 0) {
+                   dev_err(cryp->dev, "no IRQ:%d resource info\n",

i);

Quoted 14 lines
Quoted 3 lines
drivers/crypto/Kconfig +3 -0
+                   return -ENXIO;
+           }
+   }

[...]

drivers/crypto/Kconfig

Quoted 6 lines
drivers/crypto/Kconfig +6 -0
+#ifndef __MTK_PLATFORM_H_
+#define __MTK_PLATFORM_H_
+
+#include <linux/crypto.h>
+#include <crypto/internal/hash.h>
+#include <linux/interrupt.h>

Sort headers in alphabetical order

Quoted 8 lines

[...]

drivers/crypto/Kconfig

Quoted 5 lines
drivers/crypto/Kconfig +5 -0
+#define MTK_DESC_FIRST             BIT(23)
+#define MTK_DESC_BUF_LEN(x)        ((x) & 0x1ffff)
+#define MTK_DESC_CT_LEN(x) (((x) & 0xff) << 24)
+
+#define WORD(x)                    ((x) >> 2)

dangerous and ambigous define

I will define a IRQ_NUM and modify ambiguous definition.

Quoted 13 lines

[...]

drivers/crypto/Kconfig

Quoted 8 lines
drivers/crypto/Kconfig +8 -0
+
+#include <linux/dma-mapping.h>
+#include <linux/scatterlist.h>
+#include <linux/crypto.h>
+#include <crypto/scatterwalk.h>
+#include <crypto/algapi.h>
+#include <crypto/sha.h>
+#include <crypto/internal/hash.h>

Sort headers in alphabetical order
[...]
Generally more function comment could be helpfull.

I will sort all header and add more function comment. Thanks for your review.

Quoted 1 line

Regards

author
#5 lore raw

PATCH 2/2 crypto: mediatek - add DT bindings documentation

In reply to Ryder Lee

Add DT bindings documentation for the crypto driver

---
 .../devicetree/bindings/crypto/mediatek-crypto.txt | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/mediatek-crypto.txt
Documentation/devicetree/bindings/crypto/mediatek-crypto.txt new file +32 -0
new file mode 100644
index 0000000..8b1db08
@@ -0,0 +1,32 @@
+MediaTek cryptographic accelerators
+
+Required properties:
+- compatible: Should be "mediatek,mt7623-crypto"
+- reg: Address and length of the register set for the device
+- interrupts: Should contain the five crypto engines interrupts in numeric
+	order. These are global system and four descriptor rings.
+- clocks: the clock used by the core
+- clock-names: the names of the clock listed in the clocks property. These are
+	"ethif", "cryp"
+- power-domains: Must contain a reference to the PM domain.
+
+
+Optional properties:
+- interrupt-parent: Should be the phandle for the interrupt controller
+  that services interrupts for this device
+
+
+Example:
+	crypto: crypto at 1b240000 {
+		compatible = "mediatek,mt7623-crypto";
+		reg = <0 0x1b240000 0 0x20000>;
+		interrupts = <GIC_SPI 82 IRQ_TYPE_LEVEL_LOW>,
+			     <GIC_SPI 83 IRQ_TYPE_LEVEL_LOW>,
+			     <GIC_SPI 84 IRQ_TYPE_LEVEL_LOW>,
+			     <GIC_SPI 91 IRQ_TYPE_LEVEL_LOW>,
+			     <GIC_SPI 97 IRQ_TYPE_LEVEL_LOW>;
+		clocks = <&topckgen CLK_TOP_ETHIF_SEL>,
+			 <&ethsys CLK_ETHSYS_CRYPTO>;
+		clock-names = "ethif","cryp";
+		power-domains = <&scpsys MT2701_POWER_DOMAIN_ETH>;
+	};
Signature · 1 line
1.9.1