Skip to content

kernel: replace eip93 patch with upstream - #20130

Open
aiamadeus wants to merge 3 commits into
openwrt:mainfrom
aiamadeus:eip
Open

aiamadeus wants to merge 3 commits into
openwrt:mainfrom
aiamadeus:eip

Conversation

@aiamadeus

Copy link
Copy Markdown
Contributor
  • Replace the eip93 patch with upstream version
  • Update the kmod-crypto-hw-eip93 package
  • Remove the downstream version in ramips

@github-actions github-actions Bot added kernel pull request/issue with Linux kernel related changes core packages pull request/issue for core (in-tree) packages target/ramips pull request/issue for ramips target target/airoha pull request/issue for airoha target labels Sep 22, 2025
@Linaro1985

Copy link
Copy Markdown
Contributor

Hi @aiamadeus. Is this tested on mt7621?

@aiamadeus

Copy link
Copy Markdown
Contributor Author

Hi. Is this tested on mt7621?

Not yet, I'm waiting for @libiunc 's test results.

@Linaro1985

Copy link
Copy Markdown
Contributor

@aiamadeus what about fallback mode for mt7621? See #10042 (comment)

@abajk

abajk commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

The upstream version of EIP93 creashes under load. This is fixed now?

@aiamadeus

Copy link
Copy Markdown
Contributor Author

The upstream version of EIP93 creashes under load. This is fixed now?

Looks like it works fine on an7581 and mt7621 with kernel 6.12.

@abajk

abajk commented Sep 24, 2025 •

Copy link
Copy Markdown
Contributor

The upstream driver lacks software fallback for small data chunks. It would be best not to lose this feature.

@abajk abajk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build fails on 6.6:

o_hw_eip93 -c -o drivers/crypto/inside-secure/eip93/eip93-main.o drivers/crypto/inside-secure/eip93/eip93-main.c  
drivers/crypto/inside-secure/eip93/eip93-main.c:490:19: error: initialization of 'int (*)(struct platform_device *)' from incompatible pointer type 'void (*)(struct platform_device *)' [-Wincompatible-pointer-types]
  490 |         .remove = eip93_crypto_remove,
      |                   ^~~~~~~~~~~~~~~~~~~
drivers/crypto/inside-secure/eip93/eip93-main.c:490:19: note: (near initialization for 'eip93_crypto_driver.remove')

@aiamadeus

Copy link
Copy Markdown
Contributor Author

The upstream driver lacks software fallback for small data chunks. It would be best not to lose this feature.

The patches involved may need to be placed in the hack directory.
@Ansuel What do you think of software fallback mode?

@Ansuel

Ansuel commented Sep 26, 2025

Copy link
Copy Markdown
Member

@abajk just change remove to remove_new.

@aiamadeus I would revaluate that and check the performance improvement. But it's ok to have that in hack as a dedicated patch or also pending since it can be upstreamed.

@abajk

abajk commented Oct 5, 2025

Copy link
Copy Markdown
Contributor

@aiamadeus I would revaluate that and check the performance improvement. But it's ok to have that in hack as a dedicated patch or also pending since it can be upstreamed.

I have tested EIP93 on AN7581 with kernel 6.12. The driver works correctly. However, the software crypto is significantly faster for data blocks smaller than 1024.

@gingernut1978

Copy link
Copy Markdown
Contributor

@aiamadeus please rebase

@aiamadeus
aiamadeus force-pushed the eip branch 3 times, most recently from b06502a to 0f9dd3d Compare November 30, 2025 14:05
@aiamadeus
aiamadeus requested a review from abajk November 30, 2025 14:20
@aiamadeus
aiamadeus marked this pull request as ready for review November 30, 2025 14:28
@aiamadeus

Copy link
Copy Markdown
Contributor Author

@Ansuel @Linaro1985 The software fallback mode has been
split into a separate patch and placed in the hack directory.

@Ansuel

Ansuel commented Nov 30, 2025 via email

Copy link
Copy Markdown
Member

@abajk

abajk commented Nov 30, 2025

Copy link
Copy Markdown
Contributor

Very nice now we need to test mt7530

You mean the mt7621?

@Ansuel

Ansuel commented Nov 30, 2025 via email

Copy link
Copy Markdown
Member

Comment on lines +6 to +7
Mediatek EIP93 Crypto engine is a crypto accelerator which
is available in the Mediatek MT7621 SoC.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message does not really describe the patch. I think it would be good to mention the why of the patch, i.e. show some performance numbers showing that this patch improves performance.

@abajk

abajk commented May 15, 2026

Copy link
Copy Markdown
Contributor

@abajk doesnt seem like that. But there are like 3 different DMA engines that could be used maybe one of them works properly. Can you elaborate how the current buffer io works?

That's sad. In the ZynqMP SoC, there was a bit that allowed certain peripherals to be rerouted via a different coherent AXI bus. The eip93 has its own DMA engine. Are those 3 others generic DMA engines, or DMA engines from other peripherals like Ethernet?

@abajk

abajk commented May 15, 2026

Copy link
Copy Markdown
Contributor

Cache synchronization consumes a lot of CPU cycles. On the Marvell platform, the coherent EIP97 delivers three times as many IOPS.

@merbanan

Copy link
Copy Markdown

Ok, I kinda understand the how it works now.

Can you validate this reg?
#define EIP93_PE_CONFIG_RST_RING BIT(2)

@merbanan

Copy link
Copy Markdown

Are those 3 others generic DMA engines, or DMA engines from other peripherals like Ethernet?

The AN7581 have 2 generic DMA engines. GDMA and HS-DMA, then we have the packet processing DMA, TDMA(AKA PDMA) and QDMA.

@abajk

abajk commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Can you validate this reg?
#define EIP93_PE_CONFIG_RST_RING BIT(2)

The point is, the specification says it should be BIT(1), right?

obraz

Old driver also use BIT(1): https://github.com/openwrt/openwrt/blob/openwrt-25.12/target/linux/ramips/patches-6.12/860-ramips-add-eip93-driver.patch#L3081.

@merbanan

Copy link
Copy Markdown

The point is, the specification says it should be BIT(1), right?

Correct. Does that fix the crash though?

Where can I find the document you are referring to? I looked in the MT7621 documentation and it does not look like this.

@abajk

abajk commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

The point is, the specification says it should be BIT(1), right?

Correct. Does that fix the crash though?

Where can I find the document you are referring to? I looked in the MT7621 documentation and it does not look like this.

vschagen/mtk-eip93#5

My research shows that EIP93 is integrated into Econet/Airoha SoCs, the MT7621, Analog Devices' Blackgin series, and Renesas SoCs. Only Analog publishes documentation for this IP core. Some registers are missing in the Analog documentation. This may be due to the fact that this IP core is in a different revision. All Airoha, MediaTek, and Econet SoCs use EIP93 revision 3.0p1.

@merbanan

Copy link
Copy Markdown

For the record MT7621 ProgrammingGuide DMA containes documentation for this part.

@abajk

abajk commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Correct. Does that fix the crash though?

The crash still exists when multiple operations are running in parallel (insmod tcrypt mode=602 sec=1 num_mb=1024).

2. Stall after driver detach/attach (kernel: replace eip93 patch with upstream #20130 (comment)),

But this regression is fixed. I've sent patch upstream.

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 new commits; no new issues found. The PR commits are identical (byte-for-byte same diffs and commit messages) to the previously reviewed revision — only the base has advanced.


Generated by Claude Code

@merbanan

Copy link
Copy Markdown

Lots of models (even local Qwen) think the issue is that "idr_alloc can fail and return a negative error code, which gets silently converted to (u16) in cdesc."

"This bug manifests under heavy load (multibuffer mode with large num_mb) because the IDR runs out of available IDs when many concurrent requests are in flight, causing idr_alloc to return -ENOSPC."

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes since the last review. Only the third commit ("kernel: backport eip93 driver fixes") was rebased; the other two commits are byte-for-byte identical (verified via patch-id). The rebase adds two new patches — backport-6.12/837-v7.2-... and backport-6.18/832-v7.2-crypto-eip93-fix-reset-ring-register-definition.patch — which are identical to each other and apply a single EIP93_PE_CONFIG_RST_RING BIT(2) → BIT(1) fix. Context and patch numbering match the in-tree eip93-regs.h (confirmed against the v6.18.33 reference tree), and the commit message accurately describes the change. No new issues found.


Generated by Claude Code

aiamadeus added 2 commits May 30, 2026 16:10
Replace the eip93 patch in the airoha target with upstream
version. Also move it to generic for use by other targets.

Signed-off-by: Chukun Pan <[email protected]>
Split the fallback mode from ramips target into a separate
patch. Also update the path of crypto-hw-eip93 package.

Signed-off-by: Chukun Pan <[email protected]>
Backport minor fixes for the eip93 driver from upstream.

Signed-off-by: Aleksander Jan Bajkowski <[email protected]>

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes since the last review. The first two commits ("kernel: replace eip93 patch with upstream", "kernel: update crypto-hw-eip93 driver") are byte-for-byte identical to the previously reviewed revision (verified via patch-id). Only the third commit ("kernel: backport eip93 driver fixes") changed.

The rebased third commit reworks the 6.18 backports:

  • Drops backport-6.18/831-v7.1-crypto-eip93-fix-hmac-setkey-algo-selection.patch. Confirmed against the v6.18.33 reference tree that this fix is already upstream there — eip93-common.c calls crypto_alloc_ahash(alg_name, 0, 0) (mask 0, no CRYPTO_ALG_ASYNC), which is exactly what that patch applies. Correct to drop for 6.18 (still needed for 6.12 as 836, since 6.12 mainline has no eip93 driver).
  • Renumbers the 6.18 make-it-selectable patch 829 → 831; no collision (830 is the emc2305 patch).
  • Adds backport-6.18/832-v7.2-crypto-eip93-fix-reset-ring-register-definition.patch, identical to the 6.12 837 counterpart. v6.18.33 still has EIP93_PE_CONFIG_RST_RING BIT(2), so this BIT(2)→BIT(1) fix is still required there; context lines match the in-tree header.

The make-it-selectable (ECONET) patch is also still needed for 6.18 — the v6.18.33 Kconfig depends line lacks ECONET. No dangling references to the old pending-6.18/928 patch remain, and no patch-number collisions in either backport directory. The commit message still accurately describes the change. No new issues found.


Generated by Claude Code

@libiunc libiunc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's time to merge. It tested successfully on my device, and EIP93 works correctly.

@abajk

abajk commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

For those tracking the thread. Known remaining issues:

  1. Panic in stress test (kernel: replace eip93 patch with upstream #20130 (comment)),
    Pending fix: https://patchwork.kernel.org/project/linux-crypto/patch/[email protected]/
  2. Reduced performance by 20-25% on MT7621 (crypto: eip93: add SafeXcel EIP-93 crypto engine support #21499 (comment)).
  3. Crash on big endian platforms (kernel: replace eip93 patch with upstream #20130 (comment))
    WiP: kernel: replace eip93 patch with upstream #20130 (comment).

The first issue seems to be the most critical. The big endian panic can be fixed later and should not block this PR.

@naseef

naseef commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Here is claude's analysis on the Big endian crash ( Claude has access to live device, all the verification and finding are by claude, I did not review or check anything, Also the testing was on main, not with any commits on this PR)

Big-endian bring-up on EcoNet EN751221 (MIPS 34Kc, BE)

I brought the in-tree driver up on a big-endian EN75xx SoC (Genexis
Platinum 4410, crypto@1fb70000, IRQ 28). As expected it hung immediately —
this is the first big-endian user of the driver. Answering @abajk 's
suggestion about the endian-config register, here is what I found.

The crash

eip93_handle_result_descriptor() spins forever waiting for PE_READY,
because the result-descriptor words are read byte-swapped → RCU stall on the
first request:

raw ctrl_stat = 0x02001800  -> swab32 -> 0x00180002  bits[1:0]  = 2 (PE_READY)
raw length    = 0x00008008  -> swab32 -> 0x08800000  bits[23:22]= 2 (PE_READY)

The endian register (the combinations you asked about)

EN751221 implements only the Airoha variant at 0x1d0
(EIP93_AIROHA_REG_PE_ENDIAN_CONFIG); the standard 0x1cc reads back 0.
Reset default of 0x1d0 is 0x00e400e4 (TARGET=0xe4, MASTER=0xe4, i.e.
identity / little-endian).

What I tried and the outcome:

Attempt Result
0x1cc T+M = 0x1b no-op (register not implemented) → still hangs
0x1d0 MASTER=0x1b after reset no effect → still hangs
0x1d0 T+M=0x1b before reset + PE_CONFIG.SWAP_CDRD works
add PE_CONFIG.SWAP_DATA breaks the cipher payload (byte-swaps the data stream)
add PE_CONFIG.SWAP_SA redundant (the 0x1d0 master swap already covers the SA)

So on big-endian the register must be written with a full byte-lane reversal
(0x1b in both TARGET_BYTE_SWAP and MASTER_BYTE_SWAP) before the PE
reset so it is latched
, plus the CDR/RDR descriptor swap:

if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
    writel(FIELD_PREP(EIP93_PE_ENDIAN_TARGET_BYTE_SWAP, 0x1b) |
           FIELD_PREP(EIP93_PE_ENDIAN_MASTER_BYTE_SWAP, 0x1b),
           eip93->base + EIP93_AIROHA_REG_PE_ENDIAN_CONFIG);

/* ... in the PE_CONFIG reset write: */
if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
    val |= EIP93_PE_CONFIG_SWAP_CDRD;

What works now (crypto manager self-tests, big-endian)

  • skcipher: ecb/cbc/ctr/rfc3686(aes), ecb/cbc(des), ecb/cbc(des3_ede) — pass
  • ahash single-shot: md5, sha1, sha224, sha256 — pass

Still broken on big-endian — help appreciated

Any hash op without HASH_FINAL hangs: HMAC ipad/opad pre-compute,
multi-block hashing, and the AF_ALG hash interface (init→update→final). The
engine produces no result descriptor for the non-final command
(PE_RD_COUNT stays 0, eip93_done_task returns immediately, the requester
blocks forever — the box stays alive, no RCU stall). The ipad/opad blocks
handed to the engine are correct, so it is not the key/block prep; it looks
like the sa_state intermediate-state / result-generation side of the
non-HASH_FINAL path in eip93_send_hash_req().

Repro (self-tests off, CONFIG_CRYPTO_USER_API_HASH=y), via AF_ALG:

hmac(sha256-eip93)  -> hangs (D-state), no result descriptor
sha256-eip93        -> also hangs (AF_ALG uses update/final)

@abajk

abajk commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

So on big-endian the register must be written with a full byte-lane reversal
(0x1b in both TARGET_BYTE_SWAP and MASTER_BYTE_SWAP) before the PE reset so it is latched, plus the CDR/RDR descriptor swap:

The reset doesn't work on the openWRT main branch yet. The patch is in the upstream backport queue. The backport should land in 6.18.41 landed in 6.18.40. Can you run some tests with the reset working correctly?

@@ -0,0 +1,27 @@
From 09e6b79b8ce388993aec9ac91b1cb2c181c27bd9 Mon Sep 17 00:00:00 2001

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterwillcn

Copy link
Copy Markdown
Contributor

ping @hauke

@abajk

abajk commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

For the record MT7621 ProgrammingGuide DMA containes documentation for this part.

Hi @merbanan. I compared the rest of the bit macros between the old and new drivers. EIP93_SA_CMD_SSL_MAC doesn't match either. This bit isn't described in the Analog Devices documentation. Does the MT7621 Programming Guide mention whether it's 11 or 12 bit? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core packages pull request/issue for core (in-tree) packages kernel pull request/issue with Linux kernel related changes target/airoha pull request/issue for airoha target target/ramips pull request/issue for ramips target

Projects

None yet

Development

Successfully merging this pull request may close these issues.