2024-01-10 20:21:15

by Alexey Romanov

[permalink] [raw]
Subject: [PATCH v1 00/24] Support more Amlogic SoC families in crypto driver

Hello!

This patchset expand the funcionality of the Amlogic
crypto driver by adding support for more SoC families:
AXG, G12A, G12B, SM1, A1, S4.

Also specify and enable crypto node in device tree
for reference Amlogic devices.

Tested on AXG, G12A/B, SM1, A1 and S4 devices via
custom tests and trcypt module.

Alexey Romanov (17):
drivers: crypto: meson: don't hardcode IRQ count
drivers: crypto: meson: make CLK controller optional
drviers: crypto: meson: add platform data
drivers: crypto: meson: add MMIO helpers
drivers: crypto: meson: move get_engine_number()
drivers: crypto: meson: use fallback for 192-bit keys
drivers: crypto: meson: add support for G12-series
drivers: crypto: meson: add support for AXG-series
dt-bindings: crypto: meson: add new compatibles
arch: arm64: dts: meson: a1: add crypto node
arch: arm64: dts: meson: s4: add crypto node
arch: arm64: dts: meson: g12: add crypto node
arch: arm64: dts: meson: axg: add crypto node
arch: arm64: dts: meson: s4-s805x2-aq222: enable crypto node
arch: arm64: dts: meson: a1-ad401: enable crypto node
arch: arm64: dts: meson: axg-s400: enable crypto node
arch: arm64: dts: meson: g12a-u200: enable crypto node

Jan Dakinevich (7):
drivers: crypto: meson: drop status field from meson_flow
drivers: crypto: meson: move algs definition and cipher API to
cipher.c
drivers: crypto: meson: cleanup defines
drivers: crypto: meson: process more than MAXDESCS descriptors
drivers: crypto: meson: avoid kzalloc in engine thread
drivers: crypto: meson: introduce hasher
drivers: crypto: meson: add support for AES-CTR

.../bindings/crypto/amlogic,gxl-crypto.yaml | 2 +
.../arm64/boot/dts/amlogic/meson-a1-ad401.dts | 4 +
arch/arm64/boot/dts/amlogic/meson-a1.dtsi | 8 +
.../arm64/boot/dts/amlogic/meson-axg-s400.dts | 4 +
arch/arm64/boot/dts/amlogic/meson-axg.dtsi | 7 +
.../boot/dts/amlogic/meson-g12-common.dtsi | 7 +
.../boot/dts/amlogic/meson-g12a-u200.dts | 4 +
.../dts/amlogic/meson-s4-s805x2-aq222.dts | 4 +
arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 7 +
drivers/crypto/amlogic/Makefile | 2 +-
drivers/crypto/amlogic/amlogic-gxl-cipher.c | 591 ++++++++++++------
drivers/crypto/amlogic/amlogic-gxl-core.c | 260 ++++----
drivers/crypto/amlogic/amlogic-gxl-hasher.c | 448 +++++++++++++
drivers/crypto/amlogic/amlogic-gxl.h | 116 +++-
14 files changed, 1135 insertions(+), 329 deletions(-)
create mode 100644 drivers/crypto/amlogic/amlogic-gxl-hasher.c

--
2.30.1



2024-01-10 20:22:13

by Alexey Romanov

[permalink] [raw]
Subject: [PATCH v1 06/24] drivers: crypto: meson: drop status field from meson_flow

From: Jan Dakinevich <[email protected]>

This field is used only to check for timeout. But there is more
convenient way to achive the same goal.

Signed-off-by: Jan Dakinevich <[email protected]>
Signed-off-by: Alexey Romanov <[email protected]>
---
drivers/crypto/amlogic/amlogic-gxl-cipher.c | 13 +++++++++----
drivers/crypto/amlogic/amlogic-gxl-core.c | 1 -
drivers/crypto/amlogic/amlogic-gxl.h | 2 --
3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
index eb64dc0c0654..f9a86a11cd70 100644
--- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
+++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
@@ -219,13 +219,18 @@ static int meson_cipher(struct skcipher_request *areq)
}

reinit_completion(&mc->chanlist[flow].complete);
- mc->chanlist[flow].status = 0;
meson_dma_start(mc, flow);
- wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete,
- msecs_to_jiffies(500));
- if (mc->chanlist[flow].status == 0) {
+
+ err = wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete,
+ msecs_to_jiffies(500));
+ if (err == 0) {
dev_err(mc->dev, "DMA timeout for flow %d\n", flow);
err = -EINVAL;
+ } else if (err < 0) {
+ dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err);
+ } else {
+ /* No error */
+ err = 0;
}

dma_unmap_single(mc->dev, phykeyiv, keyivlen, DMA_TO_DEVICE);
diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c
index 06330706e49f..ae50ea51c8a0 100644
--- a/drivers/crypto/amlogic/amlogic-gxl-core.c
+++ b/drivers/crypto/amlogic/amlogic-gxl-core.c
@@ -51,7 +51,6 @@ static irqreturn_t meson_irq_handler(int irq, void *data)
for (flow = 0; flow < mc->flow_cnt; flow++) {
if (mc->chanlist[flow].irq == irq) {
if (meson_dma_ready(mc, flow)) {
- mc->chanlist[flow].status = 1;
complete(&mc->chanlist[flow].complete);
return IRQ_HANDLED;
}
diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h
index 46cc85afb74e..80ce6cb9baef 100644
--- a/drivers/crypto/amlogic/amlogic-gxl.h
+++ b/drivers/crypto/amlogic/amlogic-gxl.h
@@ -59,7 +59,6 @@ struct meson_desc {
* @engine: ptr to the crypto_engine for this flow
* @keylen: keylen for this flow operation
* @complete: completion for the current task on this flow
- * @status: set to 1 by interrupt if task is done
* @irq: IRQ number for amlogic-crypto
* @t_phy: Physical address of task
* @tl: pointer to the current ce_task for this flow
@@ -68,7 +67,6 @@ struct meson_desc {
struct meson_flow {
struct crypto_engine *engine;
struct completion complete;
- int status;
int irq;
unsigned int keylen;
dma_addr_t t_phy;
--
2.30.1


2024-01-10 20:22:22

by Alexey Romanov

[permalink] [raw]
Subject: [PATCH v1 04/24] drivers: crypto: meson: add MMIO helpers

Add MMIO access helpers: meson_dma_start() and meson_dma_ready().

Signed-off-by: Alexey Romanov <[email protected]>
Signed-off-by: Jan Dakinevich <[email protected]>
---
drivers/crypto/amlogic/amlogic-gxl-cipher.c | 2 +-
drivers/crypto/amlogic/amlogic-gxl-core.c | 24 ++++++++++++++++-----
drivers/crypto/amlogic/amlogic-gxl.h | 2 ++
3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
index 58de925caae7..7ea88a9f78a5 100644
--- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
+++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
@@ -225,7 +225,7 @@ static int meson_cipher(struct skcipher_request *areq)

reinit_completion(&mc->chanlist[flow].complete);
mc->chanlist[flow].status = 0;
- writel(mc->chanlist[flow].t_phy | 2, mc->base + ((mc->pdata->descs_reg + flow) << 2));
+ meson_dma_start(mc, flow);
wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete,
msecs_to_jiffies(500));
if (mc->chanlist[flow].status == 0) {
diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c
index a83c00922b48..78b70c17862d 100644
--- a/drivers/crypto/amlogic/amlogic-gxl-core.c
+++ b/drivers/crypto/amlogic/amlogic-gxl-core.c
@@ -20,18 +20,32 @@

#include "amlogic-gxl.h"

+void meson_dma_start(struct meson_dev *mc, int flow)
+{
+ u32 offset = (mc->pdata->descs_reg + flow) << 2;
+
+ writel(mc->chanlist[flow].t_phy | 2, mc->base + offset);
+}
+
+static bool meson_dma_ready(struct meson_dev *mc, int flow)
+{
+ u32 offset = (mc->pdata->status_reg + flow) << 2;
+ u32 data = readl(mc->base + offset);
+
+ if (data)
+ writel_relaxed(0xF, mc->base + offset);
+
+ return data;
+}
+
static irqreturn_t meson_irq_handler(int irq, void *data)
{
struct meson_dev *mc = (struct meson_dev *)data;
int flow;
- u32 p;

for (flow = 0; flow < mc->flow_cnt; flow++) {
if (mc->chanlist[flow].irq == irq) {
- p = readl(mc->base + ((mc->pdata->status_reg + flow) << 2));
- if (p) {
- writel_relaxed(0xF, mc->base +
- ((mc->pdata->status_reg + flow) << 2));
+ if (meson_dma_ready(mc, flow)) {
mc->chanlist[flow].status = 1;
complete(&mc->chanlist[flow].complete);
return IRQ_HANDLED;
diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h
index c8ba726ccc8b..80b7a2492168 100644
--- a/drivers/crypto/amlogic/amlogic-gxl.h
+++ b/drivers/crypto/amlogic/amlogic-gxl.h
@@ -163,6 +163,8 @@ struct meson_alg_template {
#endif
};

+void meson_dma_start(struct meson_dev *mc, int flow);
+
int meson_enqueue(struct crypto_async_request *areq, u32 type);

int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
--
2.30.1


2024-01-10 20:26:49

by Alexey Romanov

[permalink] [raw]
Subject: [PATCH v1 23/24] arch: arm64: dts: meson: axg-s400: enable crypto node

AXG has hardware support of crypto algos: SHA1/224/256 and AES.

Signed-off-by: Alexey Romanov <[email protected]>
---
arch/arm64/boot/dts/amlogic/meson-axg-s400.dts | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/arch/arm64/boot/dts/amlogic/meson-axg-s400.dts b/arch/arm64/boot/dts/amlogic/meson-axg-s400.dts
index 359589d1dfa9..d8f2289d7452 100644
--- a/arch/arm64/boot/dts/amlogic/meson-axg-s400.dts
+++ b/arch/arm64/boot/dts/amlogic/meson-axg-s400.dts
@@ -600,3 +600,7 @@ &usb {
dr_mode = "otg";
vbus-supply = <&usb_pwr>;
};
+
+&crypto {
+ status = "okay";
+};
--
2.30.1


2024-01-10 21:08:48

by Corentin Labbe

[permalink] [raw]
Subject: Re: [PATCH v1 00/24] Support more Amlogic SoC families in crypto driver

Le Wed, Jan 10, 2024 at 11:11:16PM +0300, Alexey Romanov a ?crit :
> Hello!
>
> This patchset expand the funcionality of the Amlogic
> crypto driver by adding support for more SoC families:
> AXG, G12A, G12B, SM1, A1, S4.
>
> Also specify and enable crypto node in device tree
> for reference Amlogic devices.
>
> Tested on AXG, G12A/B, SM1, A1 and S4 devices via
> custom tests and trcypt module.

Hello

Thanks for your patch series.
Unfortunatly, I fail to apply it for testing on top of linux-next.
On top of which tree did you have tested ?
According to patch 01, you used a tree based before "crypto: amlogic - Use new crypto_engine_op interface" so too old.

Regards

2024-01-11 09:19:19

by Alexey Romanov

[permalink] [raw]
Subject: Re: [PATCH v1 00/24] Support more Amlogic SoC families in crypto driver

Hello!

On Wed, Jan 10, 2024 at 10:08:15PM +0100, Corentin Labbe wrote:
> Le Wed, Jan 10, 2024 at 11:11:16PM +0300, Alexey Romanov a 'ecrit :
> > Hello!
> >
> > This patchset expand the funcionality of the Amlogic
> > crypto driver by adding support for more SoC families:
> > AXG, G12A, G12B, SM1, A1, S4.
> >
> > Also specify and enable crypto node in device tree
> > for reference Amlogic devices.
> >
> > Tested on AXG, G12A/B, SM1, A1 and S4 devices via
> > custom tests and trcypt module.
>
> Hello
>
> Thanks for your patch series.
> Unfortunatly, I fail to apply it for testing on top of linux-next.
> On top of which tree did you have tested ?

We use 6.5-rc3.

> According to patch 01, you used a tree based before "crypto: amlogic - Use new crypto_engine_op interface" so too old.

Will rebase over linux-next in v2.

>
> Regards

--
Thank you,
Alexey

2024-01-11 09:32:15

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v1 00/24] Support more Amlogic SoC families in crypto driver

On 11/01/2024 10:29, Krzysztof Kozlowski wrote:
> On 11/01/2024 10:18, Alexey Romanov wrote:
>> Hello!
>>
>> On Wed, Jan 10, 2024 at 10:08:15PM +0100, Corentin Labbe wrote:
>>> Le Wed, Jan 10, 2024 at 11:11:16PM +0300, Alexey Romanov a 'ecrit :
>>>> Hello!
>>>>
>>>> This patchset expand the funcionality of the Amlogic
>>>> crypto driver by adding support for more SoC families:
>>>> AXG, G12A, G12B, SM1, A1, S4.
>>>>
>>>> Also specify and enable crypto node in device tree
>>>> for reference Amlogic devices.
>>>>
>>>> Tested on AXG, G12A/B, SM1, A1 and S4 devices via
>>>> custom tests and trcypt module.
>>>
>>> Hello
>>>
>>> Thanks for your patch series.
>>> Unfortunatly, I fail to apply it for testing on top of linux-next.
>>> On top of which tree did you have tested ?
>>
>> We use 6.5-rc3.
>
> Don't develop on old trees... I mean, internally you can do whatever you
> wish, but don't work upstream on such trees.

Number of email bounces also prove the point: you did not Cc right
people due to work on some ancient files.

Best regards,
Krzysztof


2024-01-11 09:35:12

by Alexey Romanov

[permalink] [raw]
Subject: Re: [PATCH v1 00/24] Support more Amlogic SoC families in crypto driver


Hi Neil,

On Thu, Jan 11, 2024 at 09:19:11AM +0100, [email protected] wrote:
> Hi !
>
> On 10/01/2024 21:11, Alexey Romanov wrote:
> > Hello!
> >
> > This patchset expand the funcionality of the Amlogic
> > crypto driver by adding support for more SoC families:
> > AXG, G12A, G12B, SM1, A1, S4.
> >
> > Also specify and enable crypto node in device tree
> > for reference Amlogic devices.
> >
> > Tested on AXG, G12A/B, SM1, A1 and S4 devices via
> > custom tests and trcypt module.
>
> Thanks a lot for the patchset, it's very welcome!
>
> Could you provide some procedure used to test and test dumps for all the platforms, like `cryptsetup benchmark` or a summary of tcrypt tests output ?

We use the following kernel module:

https://gist.github.com/mRrvz/8d9277d57abb4d21568725785ec9e939

and don't forget to define reserved memory region in device tree.

>
> Thanks,
> Neil
>
> >
> > Alexey Romanov (17):
> > drivers: crypto: meson: don't hardcode IRQ count
> > drivers: crypto: meson: make CLK controller optional
> > drviers: crypto: meson: add platform data
> > drivers: crypto: meson: add MMIO helpers
> > drivers: crypto: meson: move get_engine_number()
> > drivers: crypto: meson: use fallback for 192-bit keys
> > drivers: crypto: meson: add support for G12-series
> > drivers: crypto: meson: add support for AXG-series
> > dt-bindings: crypto: meson: add new compatibles
> > arch: arm64: dts: meson: a1: add crypto node
> > arch: arm64: dts: meson: s4: add crypto node
> > arch: arm64: dts: meson: g12: add crypto node
> > arch: arm64: dts: meson: axg: add crypto node
> > arch: arm64: dts: meson: s4-s805x2-aq222: enable crypto node
> > arch: arm64: dts: meson: a1-ad401: enable crypto node
> > arch: arm64: dts: meson: axg-s400: enable crypto node
> > arch: arm64: dts: meson: g12a-u200: enable crypto node
> >
> > Jan Dakinevich (7):
> > drivers: crypto: meson: drop status field from meson_flow
> > drivers: crypto: meson: move algs definition and cipher API to
> > cipher.c
> > drivers: crypto: meson: cleanup defines
> > drivers: crypto: meson: process more than MAXDESCS descriptors
> > drivers: crypto: meson: avoid kzalloc in engine thread
> > drivers: crypto: meson: introduce hasher
> > drivers: crypto: meson: add support for AES-CTR
> >
> > .../bindings/crypto/amlogic,gxl-crypto.yaml | 2 +
> > .../arm64/boot/dts/amlogic/meson-a1-ad401.dts | 4 +
> > arch/arm64/boot/dts/amlogic/meson-a1.dtsi | 8 +
> > .../arm64/boot/dts/amlogic/meson-axg-s400.dts | 4 +
> > arch/arm64/boot/dts/amlogic/meson-axg.dtsi | 7 +
> > .../boot/dts/amlogic/meson-g12-common.dtsi | 7 +
> > .../boot/dts/amlogic/meson-g12a-u200.dts | 4 +
> > .../dts/amlogic/meson-s4-s805x2-aq222.dts | 4 +
> > arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 7 +
> > drivers/crypto/amlogic/Makefile | 2 +-
> > drivers/crypto/amlogic/amlogic-gxl-cipher.c | 591 ++++++++++++------
> > drivers/crypto/amlogic/amlogic-gxl-core.c | 260 ++++----
> > drivers/crypto/amlogic/amlogic-gxl-hasher.c | 448 +++++++++++++
> > drivers/crypto/amlogic/amlogic-gxl.h | 116 +++-
> > 14 files changed, 1135 insertions(+), 329 deletions(-)
> > create mode 100644 drivers/crypto/amlogic/amlogic-gxl-hasher.c
> >
>

--
Thank you,
Alexey