[PATCH v2 24/30] crypto: sa2ul - calculate DMA metadata length from the command label

From: Manorit Chawdhry

Date: Wed Nov 04 2026 - 00:55:35 EST


Request type and subtype are software bookkeeping, not command-label
data. Remove that trailer and calculate the DMA metadata length from
the EPIB, protocol-specific header and actual command-label size.

With those extra bytes no longer sent through DMA, update the 3DES
IV index from 6 to 4 to match the new offsets.

Fixes: 7694b6ca649f ("crypto: sa2ul - Add crypto driver")
Fixes: d2c8ac187fc9 ("crypto: sa2ul - Add AEAD algorithm support")
Signed-off-by: Manorit Chawdhry <m-chawdhry@xxxxxx>
---
drivers/crypto/sa2ul.c | 25 +++++++------------------
drivers/crypto/sa2ul.h | 23 +----------------------
2 files changed, 8 insertions(+), 40 deletions(-)

diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index 18a69c890ee2..e34c52de5ec4 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -905,7 +905,7 @@ static int sa_3des_cbc_setkey(struct crypto_skcipher *tfm, const u8 *key,

ad.mci_enc = mci_cbc_3des_enc_array;
ad.mci_dec = mci_cbc_3des_dec_array;
- ad.iv_idx = 6;
+ ad.iv_idx = 4;
ad.iv_out_size = 8;

return sa_cipher_setkey(tfm, key, keylen, &ad);
@@ -980,7 +980,7 @@ static void sa_aes_dma_in_callback(void *data,
skcipher_request_complete(req, err);
}

-static void
+static int
sa_prepare_tx_desc(u32 *mdptr, u32 pslen, u32 *psdata, u32 epiblen, u32 *epib)
{
u32 *out, *in;
@@ -993,6 +993,8 @@ sa_prepare_tx_desc(u32 *mdptr, u32 pslen, u32 *psdata, u32 epiblen, u32 *epib)
for (out = &mdptr[5], in = psdata, i = 0;
i < pslen / sizeof(u32); i++)
*out++ = *in++;
+
+ return epiblen + sizeof(u32) + pslen;
}

static int sa_run(struct sa_req *req)
@@ -1054,16 +1056,6 @@ static int sa_run(struct sa_req *req)

sa_update_cmdl(req, cmdl, &cmdl_upd_info);

- if (req->type != CRYPTO_ALG_TYPE_AHASH) {
- if (req->enc)
- req->type |=
- (SA_REQ_SUBTYPE_ENC << SA_REQ_SUBTYPE_SHIFT);
- else
- req->type |=
- (SA_REQ_SUBTYPE_DEC << SA_REQ_SUBTYPE_SHIFT);
- }
-
- cmdl[sa_ctx->cmdl_size / sizeof(u32)] = req->type;

/*
* Map the packets, first we check if the data fits into a single
@@ -1200,9 +1192,9 @@ static int sa_run(struct sa_req *req)
*/
mdptr = (u32 *)dmaengine_desc_get_metadata_ptr(tx_out, &pl, &ml);

- sa_prepare_tx_desc(mdptr, (sa_ctx->cmdl_size + (SA_PSDATA_CTX_WORDS *
- sizeof(u32))), cmdl, sizeof(sa_ctx->epib),
- sa_ctx->epib);
+ req->mdata_size = sa_prepare_tx_desc(mdptr, cmdl_size,
+ cmdl, sizeof(sa_ctx->epib),
+ sa_ctx->epib);

dmaengine_desc_set_metadata_len(tx_out, req->mdata_size);

@@ -1259,7 +1251,6 @@ static int sa_cipher_run(struct skcipher_request *req, u8 *iv, int enc)
sa_req.type = CRYPTO_ALG_TYPE_SKCIPHER;
sa_req.enc = enc;
sa_req.callback = sa_aes_dma_in_callback;
- sa_req.mdata_size = 44;
sa_req.base = &req->base;
sa_req.ctx = ctx;

@@ -1364,7 +1355,6 @@ static int sa_sha_run(struct ahash_request *req)
sa_req.enc = true;
sa_req.type = CRYPTO_ALG_TYPE_AHASH;
sa_req.callback = sa_sha_dma_in_callback;
- sa_req.mdata_size = 28;
sa_req.ctx = ctx;
sa_req.base = &req->base;

@@ -1841,7 +1831,6 @@ static int sa_aead_run(struct aead_request *req, u8 *iv, int enc)
sa_req.type = CRYPTO_ALG_TYPE_AEAD;
sa_req.enc = enc;
sa_req.callback = sa_aead_dma_in_callback;
- sa_req.mdata_size = 52;
sa_req.base = &req->base;
sa_req.ctx = ctx;
sa_req.src = req->src;
diff --git a/drivers/crypto/sa2ul.h b/drivers/crypto/sa2ul.h
index ea86199b6231..67bc722a1170 100644
--- a/drivers/crypto/sa2ul.h
+++ b/drivers/crypto/sa2ul.h
@@ -31,22 +31,9 @@ struct sa_tfm_ctx;
#define SA_EEC_CPPI_PORT_IN_EN 0x00000200
#define SA_EEC_CPPI_PORT_OUT_EN 0x00000800

-/*
- * Encoding used to identify the typo of crypto operation
- * performed on the packet when the packet is returned
- * by SA
- */
-#define SA_REQ_SUBTYPE_ENC 0x0001
-#define SA_REQ_SUBTYPE_DEC 0x0002
-#define SA_REQ_SUBTYPE_SHIFT 16
-#define SA_REQ_SUBTYPE_MASK 0xffff
-
/* Number of 32 bit words in EPIB */
#define SA_DMA_NUM_EPIB_WORDS 4

-/* Number of 32 bit words in PS data */
-#define SA_DMA_NUM_PS_WORDS 16
-
/*
* Maximum number of simultaeneous security contexts
* supported by the driver
@@ -216,16 +203,8 @@ struct sa_cmdl_upd_info {
struct sa_cmdl_param_info auth_offset;
};

-/*
- * Number of 32bit words appended after the command label
- * in PSDATA to identify the crypto request context.
- * word-0: Request type
- * word-1: pointer to request
- */
-#define SA_PSDATA_CTX_WORDS 4
-
/* Maximum size of Command label in 32 words */
-#define SA_MAX_CMDL_WORDS (SA_DMA_NUM_PS_WORDS - SA_PSDATA_CTX_WORDS)
+#define SA_MAX_CMDL_WORDS 24

/**
* struct sa_ctx_info: SA context information

--
2.43.0