Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] crypto: caam - Use bounce buffer for unaligned RSA destination buffers
@ 2026-08-05  4:19 Changwei Zou
  2026-08-15  1:00 ` Herbert Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Changwei Zou @ 2026-08-05  4:19 UTC (permalink / raw)
  To: horia.geanta, pankaj.gupta, gaurav.jain, herbert, davem
  Cc: linux-crypto, linux-kernel, lukas, changwei.zou

The CAAM RSA driver directly DMA-maps the destination buffer supplied by
the caller via req->dst without checking whether it meets the cacheline
alignment requirements of DMA-incoherent hardware such as i.MX8.

On CPUs with non-coherent DMA caches, if the destination buffer shares a
cacheline with other data (i.e. it is not cacheline-aligned), cache
writeback/invalidation during DMA can corrupt adjacent memory or cause
stale data to be read back. This manifests as intermittent -EKEYREJECTED
errors when loading signed kernel modules.

When any segment of req->dst is not cacheline-aligned, allocate a
single contiguous aligned bounce buffer covering the full dst_len,
redirect the operation to it, and scatter-copy the result back to the
original destination once the hardware has completed the operation.

The intermittent error 'Key was rejected by service' on i.MX8 with CAAM
can be triggered when loading signed kernel modules:

    for i in $(seq 1 100); do
        sudo modprobe xfs 2>&1 && echo "SUCCESS on attempt $i" \
        && sudo rmmod xfs || echo "FAILED on attempt $i"
    done

Signed-off-by: Changwei Zou <changwei.zou@canonical.com>
Assisted-by: OpenCode:claude-sonnet-4.6
---
 drivers/crypto/caam/caampkc.c | 66 ++++++++++++++++++++++++++++++++++-
 drivers/crypto/caam/caampkc.h |  6 ++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index cb001aa1de66..70300182f2ad 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -59,6 +59,37 @@ static void rsa_io_unmap(struct device *dev, struct rsa_edesc *edesc,
 				 DMA_TO_DEVICE);
 }
 
+static int do_rsa_bounce_buf(struct akcipher_request *req)
+{
+	struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
+	int nents, err = 0;
+
+	if (!req_ctx->bounce_buf)
+		return 0;
+
+	/* Copy from aligned bounce buffer back to the original destination */
+	nents = sg_nents_for_len(req_ctx->orig_dst, req->dst_len);
+	if (nents < 0)
+		err = nents;
+	else if (sg_copy_from_buffer(req_ctx->orig_dst, nents,
+				     req_ctx->bounce_buf, req->dst_len) != req->dst_len)
+		err = -EFAULT;
+
+	kfree(req_ctx->bounce_buf);
+	req_ctx->bounce_buf = NULL;
+	req->dst = req_ctx->orig_dst;
+
+	return err;
+}
+
+static inline void rsa_bounce_buf_done(struct akcipher_request *req, int *err)
+{
+	int cperr = do_rsa_bounce_buf(req);
+
+	if (!*err)
+		*err = cperr;
+}
+
 static void rsa_pub_unmap(struct device *dev, struct rsa_edesc *edesc,
 			  struct akcipher_request *req)
 {
@@ -138,6 +169,7 @@ static void rsa_pub_done(struct device *dev, u32 *desc, u32 err, void *context)
 	rsa_pub_unmap(dev, edesc, req);
 	rsa_io_unmap(dev, edesc, req);
 	kfree(edesc);
+	rsa_bounce_buf_done(req, &ecode);
 
 	/*
 	 * If no backlog flag, the completion of the request is done
@@ -181,6 +213,7 @@ static void rsa_priv_f_done(struct device *dev, u32 *desc, u32 err,
 
 	rsa_io_unmap(dev, edesc, req);
 	kfree(edesc);
+	rsa_bounce_buf_done(req, &ecode);
 
 	/*
 	 * If no backlog flag, the completion of the request is done
@@ -291,11 +324,32 @@ static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req,
 				     req_ctx->fixup_src_len);
 	dst_nents = sg_nents_for_len(req->dst, req->dst_len);
 
+	req_ctx->bounce_buf = NULL;
+	req_ctx->orig_dst = req->dst;
+	if (req->dst_len > 0) {
+		struct scatterlist *sg;
+		int i;
+
+		for_each_sg(req->dst, sg, dst_nents, i) {
+			if (!IS_ALIGNED((unsigned long)sg_virt(sg),
+					dma_get_cache_alignment())) {
+				req_ctx->bounce_buf = kmalloc(req->dst_len, flags);
+				if (!req_ctx->bounce_buf)
+					return ERR_PTR(-ENOMEM);
+				sg_init_one(&req_ctx->dst, req_ctx->bounce_buf,
+					    req->dst_len);
+				req->dst = &req_ctx->dst;
+				dst_nents = 1;
+				break;
+			}
+		}
+	}
+
 	mapped_src_nents = dma_map_sg(dev, req_ctx->fixup_src, src_nents,
 				      DMA_TO_DEVICE);
 	if (unlikely(!mapped_src_nents)) {
 		dev_err(dev, "unable to map source\n");
-		return ERR_PTR(-ENOMEM);
+		goto bounce_fail;
 	}
 	mapped_dst_nents = dma_map_sg(dev, req->dst, dst_nents,
 				      DMA_FROM_DEVICE);
@@ -368,6 +422,10 @@ static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req,
 	dma_unmap_sg(dev, req->dst, dst_nents, DMA_FROM_DEVICE);
 src_fail:
 	dma_unmap_sg(dev, req_ctx->fixup_src, src_nents, DMA_TO_DEVICE);
+bounce_fail:
+	kfree(req_ctx->bounce_buf);
+	req_ctx->bounce_buf = NULL;
+	req->dst = req_ctx->orig_dst;
 	return ERR_PTR(-ENOMEM);
 }
 
@@ -394,6 +452,7 @@ static int akcipher_do_one_req(struct crypto_engine *engine, void *areq)
 		rsa_pub_unmap(jrdev, req_ctx->edesc, req);
 		rsa_io_unmap(jrdev, req_ctx->edesc, req);
 		kfree(req_ctx->edesc);
+		rsa_bounce_buf_done(req, &ret);
 	} else {
 		ret = 0;
 	}
@@ -706,6 +765,7 @@ static int akcipher_enqueue_req(struct device *jrdev,
 		}
 		rsa_io_unmap(jrdev, edesc, req);
 		kfree(edesc);
+		rsa_bounce_buf_done(req, &ret);
 	}
 
 	return ret;
@@ -747,6 +807,7 @@ static int caam_rsa_enc(struct akcipher_request *req)
 init_fail:
 	rsa_io_unmap(jrdev, edesc, req);
 	kfree(edesc);
+	rsa_bounce_buf_done(req, &ret);
 	return ret;
 }
 
@@ -776,6 +837,7 @@ static int caam_rsa_dec_priv_f1(struct akcipher_request *req)
 init_fail:
 	rsa_io_unmap(jrdev, edesc, req);
 	kfree(edesc);
+	rsa_bounce_buf_done(req, &ret);
 	return ret;
 }
 
@@ -805,6 +867,7 @@ static int caam_rsa_dec_priv_f2(struct akcipher_request *req)
 init_fail:
 	rsa_io_unmap(jrdev, edesc, req);
 	kfree(edesc);
+	rsa_bounce_buf_done(req, &ret);
 	return ret;
 }
 
@@ -834,6 +897,7 @@ static int caam_rsa_dec_priv_f3(struct akcipher_request *req)
 init_fail:
 	rsa_io_unmap(jrdev, edesc, req);
 	kfree(edesc);
+	rsa_bounce_buf_done(req, &ret);
 	return ret;
 }
 
diff --git a/drivers/crypto/caam/caampkc.h b/drivers/crypto/caam/caampkc.h
index 96d03704c9be..efad91d6058f 100644
--- a/drivers/crypto/caam/caampkc.h
+++ b/drivers/crypto/caam/caampkc.h
@@ -103,6 +103,9 @@ struct caam_rsa_ctx {
  * @src           : input scatterlist (stripped of leading zeros)
  * @fixup_src     : input scatterlist (that might be stripped of leading zeros)
  * @fixup_src_len : length of the fixup_src input scatterlist
+ * @dst           : destination scatterlist backed by bounce buffer (if needed)
+ * @bounce_buf    : DMA-aligned bounce buffer for destination (or NULL)
+ * @orig_dst      : original destination scatterlist (before bounce substitution)
  * @edesc         : s/w-extended rsa descriptor
  * @akcipher_op_done : callback used when operation is done
  */
@@ -110,6 +113,9 @@ struct caam_rsa_req_ctx {
 	struct scatterlist src[2];
 	struct scatterlist *fixup_src;
 	unsigned int fixup_src_len;
+	struct scatterlist dst;
+	u8 *bounce_buf;
+	struct scatterlist *orig_dst;
 	struct rsa_edesc *edesc;
 	void (*akcipher_op_done)(struct device *jrdev, u32 *desc, u32 err,
 				 void *context);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: caam - Use bounce buffer for unaligned RSA destination buffers
  2026-08-05  4:19 [PATCH] crypto: caam - Use bounce buffer for unaligned RSA destination buffers Changwei Zou
@ 2026-08-15  1:00 ` Herbert Xu
  2026-08-21  5:18   ` Changwei Zou
  0 siblings, 1 reply; 5+ messages in thread
From: Herbert Xu @ 2026-08-15  1:00 UTC (permalink / raw)
  To: Changwei Zou
  Cc: horia.geanta, pankaj.gupta, gaurav.jain, davem, linux-crypto,
	linux-kernel, lukas

On Wed, Aug 05, 2026 at 02:19:02PM +1000, Changwei Zou wrote:
> The CAAM RSA driver directly DMA-maps the destination buffer supplied by
> the caller via req->dst without checking whether it meets the cacheline
> alignment requirements of DMA-incoherent hardware such as i.MX8.
> 
> On CPUs with non-coherent DMA caches, if the destination buffer shares a
> cacheline with other data (i.e. it is not cacheline-aligned), cache
> writeback/invalidation during DMA can corrupt adjacent memory or cause
> stale data to be read back. This manifests as intermittent -EKEYREJECTED
> errors when loading signed kernel modules.
> 
> When any segment of req->dst is not cacheline-aligned, allocate a
> single contiguous aligned bounce buffer covering the full dst_len,
> redirect the operation to it, and scatter-copy the result back to the
> original destination once the hardware has completed the operation.
> 
> The intermittent error 'Key was rejected by service' on i.MX8 with CAAM
> can be triggered when loading signed kernel modules:
> 
>     for i in $(seq 1 100); do
>         sudo modprobe xfs 2>&1 && echo "SUCCESS on attempt $i" \
>         && sudo rmmod xfs || echo "FAILED on attempt $i"
>     done
> 
> Signed-off-by: Changwei Zou <changwei.zou@canonical.com>
> Assisted-by: OpenCode:claude-sonnet-4.6
> ---
>  drivers/crypto/caam/caampkc.c | 66 ++++++++++++++++++++++++++++++++++-
>  drivers/crypto/caam/caampkc.h |  6 ++++
>  2 files changed, 71 insertions(+), 1 deletion(-)

Please take a look at the Sashiko reviews:

https://sashiko.dev/#/patchset/20260805041902.1575170-1-changwei.zou%40canonical.com

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: caam - Use bounce buffer for unaligned RSA destination buffers
  2026-08-15  1:00 ` Herbert Xu
@ 2026-08-21  5:18   ` Changwei Zou
  2026-09-04  5:37     ` [PATCH] crypto: caam - Remove public key support Herbert Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Changwei Zou @ 2026-08-21  5:18 UTC (permalink / raw)
  To: herbert
  Cc: changwei.zou, davem, gaurav.jain, horia.geanta, linux-crypto,
	linux-kernel, lukas, pankaj.gupta

Hi Herbert,

A new version with two patches and a cover letter is available at the following link.

https://lore.kernel.org/all/20260821045555.806471-1-changwei.zou@canonical.com/

Thank you very much.

Kind regards,
Changwei


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] crypto: caam - Remove public key support
  2026-08-21  5:18   ` Changwei Zou
@ 2026-09-04  5:37     ` Herbert Xu
  2026-09-09  7:23       ` [EXT] " Varun Sethi
  0 siblings, 1 reply; 5+ messages in thread
From: Herbert Xu @ 2026-09-04  5:37 UTC (permalink / raw)
  To: Changwei Zou
  Cc: davem, gaurav.jain, horia.geanta, linux-crypto, linux-kernel,
	lukas, pankaj.gupta

On Fri, Aug 21, 2026 at 03:18:24PM +1000, Changwei Zou wrote:
> 
> A new version with two patches and a cover letter is available at the following link.

This driver hasn't been actively maintained for years.

Let's just remove it:

---8<---
Remove the public key part of the caam driver because it has been
unmaintained and there are serious bugs in it.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
deleted file mode 100644
index cb001aa1de66..000000000000
--- a/drivers/crypto/caam/caampkc.c
+++ /dev/null
@@ -1,1230 +0,0 @@
-// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
-/*
- * caam - Freescale FSL CAAM support for Public Key Cryptography
- *
- * Copyright 2016 Freescale Semiconductor, Inc.
- * Copyright 2018-2019, 2023 NXP
- *
- * There is no Shared Descriptor for PKC so that the Job Descriptor must carry
- * all the desired key parameters, input and output pointers.
- */
-#include "compat.h"
-#include "regs.h"
-#include "intern.h"
-#include "jr.h"
-#include "error.h"
-#include "desc_constr.h"
-#include "sg_sw_sec4.h"
-#include "caampkc.h"
-#include <crypto/internal/engine.h>
-#include <linux/dma-mapping.h>
-#include <linux/err.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/string.h>
-
-#define DESC_RSA_PUB_LEN	(2 * CAAM_CMD_SZ + SIZEOF_RSA_PUB_PDB)
-#define DESC_RSA_PRIV_F1_LEN	(2 * CAAM_CMD_SZ + \
-				 SIZEOF_RSA_PRIV_F1_PDB)
-#define DESC_RSA_PRIV_F2_LEN	(2 * CAAM_CMD_SZ + \
-				 SIZEOF_RSA_PRIV_F2_PDB)
-#define DESC_RSA_PRIV_F3_LEN	(2 * CAAM_CMD_SZ + \
-				 SIZEOF_RSA_PRIV_F3_PDB)
-#define CAAM_RSA_MAX_INPUT_SIZE	512 /* for a 4096-bit modulus */
-
-/* buffer filled with zeros, used for padding */
-static u8 *zero_buffer;
-
-/*
- * variable used to avoid double free of resources in case
- * algorithm registration was unsuccessful
- */
-static bool init_done;
-
-struct caam_akcipher_alg {
-	struct akcipher_engine_alg akcipher;
-	bool registered;
-};
-
-static void rsa_io_unmap(struct device *dev, struct rsa_edesc *edesc,
-			 struct akcipher_request *req)
-{
-	struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-
-	dma_unmap_sg(dev, req->dst, edesc->dst_nents, DMA_FROM_DEVICE);
-	dma_unmap_sg(dev, req_ctx->fixup_src, edesc->src_nents, DMA_TO_DEVICE);
-
-	if (edesc->sec4_sg_bytes)
-		dma_unmap_single(dev, edesc->sec4_sg_dma, edesc->sec4_sg_bytes,
-				 DMA_TO_DEVICE);
-}
-
-static void rsa_pub_unmap(struct device *dev, struct rsa_edesc *edesc,
-			  struct akcipher_request *req)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct rsa_pub_pdb *pdb = &edesc->pdb.pub;
-
-	dma_unmap_single(dev, pdb->n_dma, key->n_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->e_dma, key->e_sz, DMA_TO_DEVICE);
-}
-
-static void rsa_priv_f1_unmap(struct device *dev, struct rsa_edesc *edesc,
-			      struct akcipher_request *req)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct rsa_priv_f1_pdb *pdb = &edesc->pdb.priv_f1;
-
-	dma_unmap_single(dev, pdb->n_dma, key->n_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
-}
-
-static void rsa_priv_f2_unmap(struct device *dev, struct rsa_edesc *edesc,
-			      struct akcipher_request *req)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2;
-	size_t p_sz = key->p_sz;
-	size_t q_sz = key->q_sz;
-
-	dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
-	dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_BIDIRECTIONAL);
-}
-
-static void rsa_priv_f3_unmap(struct device *dev, struct rsa_edesc *edesc,
-			      struct akcipher_request *req)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3;
-	size_t p_sz = key->p_sz;
-	size_t q_sz = key->q_sz;
-
-	dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->dp_dma, p_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->dq_dma, q_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE);
-	dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
-	dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_BIDIRECTIONAL);
-}
-
-/* RSA Job Completion handler */
-static void rsa_pub_done(struct device *dev, u32 *desc, u32 err, void *context)
-{
-	struct akcipher_request *req = context;
-	struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-	struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
-	struct rsa_edesc *edesc;
-	int ecode = 0;
-	bool has_bklog;
-
-	if (err)
-		ecode = caam_jr_strstatus(dev, err);
-
-	edesc = req_ctx->edesc;
-	has_bklog = edesc->bklog;
-
-	rsa_pub_unmap(dev, edesc, req);
-	rsa_io_unmap(dev, edesc, req);
-	kfree(edesc);
-
-	/*
-	 * If no backlog flag, the completion of the request is done
-	 * by CAAM, not crypto engine.
-	 */
-	if (!has_bklog)
-		akcipher_request_complete(req, ecode);
-	else
-		crypto_finalize_akcipher_request(jrp->engine, req, ecode);
-}
-
-static void rsa_priv_f_done(struct device *dev, u32 *desc, u32 err,
-			    void *context)
-{
-	struct akcipher_request *req = context;
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-	struct rsa_edesc *edesc;
-	int ecode = 0;
-	bool has_bklog;
-
-	if (err)
-		ecode = caam_jr_strstatus(dev, err);
-
-	edesc = req_ctx->edesc;
-	has_bklog = edesc->bklog;
-
-	switch (key->priv_form) {
-	case FORM1:
-		rsa_priv_f1_unmap(dev, edesc, req);
-		break;
-	case FORM2:
-		rsa_priv_f2_unmap(dev, edesc, req);
-		break;
-	case FORM3:
-		rsa_priv_f3_unmap(dev, edesc, req);
-	}
-
-	rsa_io_unmap(dev, edesc, req);
-	kfree(edesc);
-
-	/*
-	 * If no backlog flag, the completion of the request is done
-	 * by CAAM, not crypto engine.
-	 */
-	if (!has_bklog)
-		akcipher_request_complete(req, ecode);
-	else
-		crypto_finalize_akcipher_request(jrp->engine, req, ecode);
-}
-
-/**
- * caam_rsa_count_leading_zeros - Count leading zeros, need it to strip,
- *                                from a given scatterlist
- *
- * @sgl   : scatterlist to count zeros from
- * @nbytes: number of zeros, in bytes, to strip
- * @flags : operation flags
- */
-static int caam_rsa_count_leading_zeros(struct scatterlist *sgl,
-					unsigned int nbytes,
-					unsigned int flags)
-{
-	struct sg_mapping_iter miter;
-	int lzeros, ents;
-	unsigned int len;
-	unsigned int tbytes = nbytes;
-	const u8 *buff;
-
-	ents = sg_nents_for_len(sgl, nbytes);
-	if (ents < 0)
-		return ents;
-
-	sg_miter_start(&miter, sgl, ents, SG_MITER_FROM_SG | flags);
-
-	lzeros = 0;
-	len = 0;
-	while (nbytes > 0) {
-		/* do not strip more than given bytes */
-		while (len && !*buff && lzeros < nbytes) {
-			lzeros++;
-			len--;
-			buff++;
-		}
-
-		if (len && *buff)
-			break;
-
-		if (!sg_miter_next(&miter))
-			break;
-
-		buff = miter.addr;
-		len = miter.length;
-
-		nbytes -= lzeros;
-		lzeros = 0;
-	}
-
-	miter.consumed = lzeros;
-	sg_miter_stop(&miter);
-	nbytes -= lzeros;
-
-	return tbytes - nbytes;
-}
-
-static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req,
-					 size_t desclen)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct device *dev = ctx->dev;
-	struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-	struct caam_rsa_key *key = &ctx->key;
-	struct rsa_edesc *edesc;
-	gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
-		       GFP_KERNEL : GFP_ATOMIC;
-	int sg_flags = (flags == GFP_ATOMIC) ? SG_MITER_ATOMIC : 0;
-	int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes;
-	int src_nents, dst_nents;
-	int mapped_src_nents, mapped_dst_nents;
-	unsigned int diff_size = 0;
-	int lzeros;
-
-	if (req->src_len > key->n_sz) {
-		/*
-		 * strip leading zeros and
-		 * return the number of zeros to skip
-		 */
-		lzeros = caam_rsa_count_leading_zeros(req->src, req->src_len -
-						      key->n_sz, sg_flags);
-		if (lzeros < 0)
-			return ERR_PTR(lzeros);
-
-		req_ctx->fixup_src = scatterwalk_ffwd(req_ctx->src, req->src,
-						      lzeros);
-		req_ctx->fixup_src_len = req->src_len - lzeros;
-	} else {
-		/*
-		 * input src is less then n key modulus,
-		 * so there will be zero padding
-		 */
-		diff_size = key->n_sz - req->src_len;
-		req_ctx->fixup_src = req->src;
-		req_ctx->fixup_src_len = req->src_len;
-	}
-
-	src_nents = sg_nents_for_len(req_ctx->fixup_src,
-				     req_ctx->fixup_src_len);
-	dst_nents = sg_nents_for_len(req->dst, req->dst_len);
-
-	mapped_src_nents = dma_map_sg(dev, req_ctx->fixup_src, src_nents,
-				      DMA_TO_DEVICE);
-	if (unlikely(!mapped_src_nents)) {
-		dev_err(dev, "unable to map source\n");
-		return ERR_PTR(-ENOMEM);
-	}
-	mapped_dst_nents = dma_map_sg(dev, req->dst, dst_nents,
-				      DMA_FROM_DEVICE);
-	if (unlikely(!mapped_dst_nents)) {
-		dev_err(dev, "unable to map destination\n");
-		goto src_fail;
-	}
-
-	if (!diff_size && mapped_src_nents == 1)
-		sec4_sg_len = 0; /* no need for an input hw s/g table */
-	else
-		sec4_sg_len = mapped_src_nents + !!diff_size;
-	sec4_sg_index = sec4_sg_len;
-
-	if (mapped_dst_nents > 1)
-		sec4_sg_len += pad_sg_nents(mapped_dst_nents);
-	else
-		sec4_sg_len = pad_sg_nents(sec4_sg_len);
-
-	sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
-
-	/* allocate space for base edesc, hw desc commands and link tables */
-	edesc = kzalloc(sizeof(*edesc) + desclen + sec4_sg_bytes, flags);
-	if (!edesc)
-		goto dst_fail;
-
-	edesc->sec4_sg = (void *)edesc + sizeof(*edesc) + desclen;
-	if (diff_size)
-		dma_to_sec4_sg_one(edesc->sec4_sg, ctx->padding_dma, diff_size,
-				   0);
-
-	if (sec4_sg_index)
-		sg_to_sec4_sg_last(req_ctx->fixup_src, req_ctx->fixup_src_len,
-				   edesc->sec4_sg + !!diff_size, 0);
-
-	if (mapped_dst_nents > 1)
-		sg_to_sec4_sg_last(req->dst, req->dst_len,
-				   edesc->sec4_sg + sec4_sg_index, 0);
-
-	/* Save nents for later use in Job Descriptor */
-	edesc->src_nents = src_nents;
-	edesc->dst_nents = dst_nents;
-
-	req_ctx->edesc = edesc;
-
-	if (!sec4_sg_bytes)
-		return edesc;
-
-	edesc->mapped_src_nents = mapped_src_nents;
-	edesc->mapped_dst_nents = mapped_dst_nents;
-
-	edesc->sec4_sg_dma = dma_map_single(dev, edesc->sec4_sg,
-					    sec4_sg_bytes, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, edesc->sec4_sg_dma)) {
-		dev_err(dev, "unable to map S/G table\n");
-		goto sec4_sg_fail;
-	}
-
-	edesc->sec4_sg_bytes = sec4_sg_bytes;
-
-	print_hex_dump_debug("caampkc sec4_sg@" __stringify(__LINE__) ": ",
-			     DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
-			     edesc->sec4_sg_bytes, 1);
-
-	return edesc;
-
-sec4_sg_fail:
-	kfree(edesc);
-dst_fail:
-	dma_unmap_sg(dev, req->dst, dst_nents, DMA_FROM_DEVICE);
-src_fail:
-	dma_unmap_sg(dev, req_ctx->fixup_src, src_nents, DMA_TO_DEVICE);
-	return ERR_PTR(-ENOMEM);
-}
-
-static int akcipher_do_one_req(struct crypto_engine *engine, void *areq)
-{
-	struct akcipher_request *req = container_of(areq,
-						    struct akcipher_request,
-						    base);
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct device *jrdev = ctx->dev;
-	u32 *desc = req_ctx->edesc->hw_desc;
-	int ret;
-
-	req_ctx->edesc->bklog = true;
-
-	ret = caam_jr_enqueue(jrdev, desc, req_ctx->akcipher_op_done, req);
-
-	if (ret == -ENOSPC && engine->retry_support)
-		return ret;
-
-	if (ret != -EINPROGRESS) {
-		rsa_pub_unmap(jrdev, req_ctx->edesc, req);
-		rsa_io_unmap(jrdev, req_ctx->edesc, req);
-		kfree(req_ctx->edesc);
-	} else {
-		ret = 0;
-	}
-
-	return ret;
-}
-
-static int set_rsa_pub_pdb(struct akcipher_request *req,
-			   struct rsa_edesc *edesc)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct device *dev = ctx->dev;
-	struct rsa_pub_pdb *pdb = &edesc->pdb.pub;
-	int sec4_sg_index = 0;
-
-	pdb->n_dma = dma_map_single(dev, key->n, key->n_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->n_dma)) {
-		dev_err(dev, "Unable to map RSA modulus memory\n");
-		return -ENOMEM;
-	}
-
-	pdb->e_dma = dma_map_single(dev, key->e, key->e_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->e_dma)) {
-		dev_err(dev, "Unable to map RSA public exponent memory\n");
-		dma_unmap_single(dev, pdb->n_dma, key->n_sz, DMA_TO_DEVICE);
-		return -ENOMEM;
-	}
-
-	if (edesc->mapped_src_nents > 1) {
-		pdb->sgf |= RSA_PDB_SGF_F;
-		pdb->f_dma = edesc->sec4_sg_dma;
-		sec4_sg_index += edesc->mapped_src_nents;
-	} else {
-		pdb->f_dma = sg_dma_address(req_ctx->fixup_src);
-	}
-
-	if (edesc->mapped_dst_nents > 1) {
-		pdb->sgf |= RSA_PDB_SGF_G;
-		pdb->g_dma = edesc->sec4_sg_dma +
-			     sec4_sg_index * sizeof(struct sec4_sg_entry);
-	} else {
-		pdb->g_dma = sg_dma_address(req->dst);
-	}
-
-	pdb->sgf |= (key->e_sz << RSA_PDB_E_SHIFT) | key->n_sz;
-	pdb->f_len = req_ctx->fixup_src_len;
-
-	return 0;
-}
-
-static int set_rsa_priv_f1_pdb(struct akcipher_request *req,
-			       struct rsa_edesc *edesc)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct device *dev = ctx->dev;
-	struct rsa_priv_f1_pdb *pdb = &edesc->pdb.priv_f1;
-	int sec4_sg_index = 0;
-
-	pdb->n_dma = dma_map_single(dev, key->n, key->n_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->n_dma)) {
-		dev_err(dev, "Unable to map modulus memory\n");
-		return -ENOMEM;
-	}
-
-	pdb->d_dma = dma_map_single(dev, key->d, key->d_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->d_dma)) {
-		dev_err(dev, "Unable to map RSA private exponent memory\n");
-		dma_unmap_single(dev, pdb->n_dma, key->n_sz, DMA_TO_DEVICE);
-		return -ENOMEM;
-	}
-
-	if (edesc->mapped_src_nents > 1) {
-		pdb->sgf |= RSA_PRIV_PDB_SGF_G;
-		pdb->g_dma = edesc->sec4_sg_dma;
-		sec4_sg_index += edesc->mapped_src_nents;
-
-	} else {
-		struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-
-		pdb->g_dma = sg_dma_address(req_ctx->fixup_src);
-	}
-
-	if (edesc->mapped_dst_nents > 1) {
-		pdb->sgf |= RSA_PRIV_PDB_SGF_F;
-		pdb->f_dma = edesc->sec4_sg_dma +
-			     sec4_sg_index * sizeof(struct sec4_sg_entry);
-	} else {
-		pdb->f_dma = sg_dma_address(req->dst);
-	}
-
-	pdb->sgf |= (key->d_sz << RSA_PDB_D_SHIFT) | key->n_sz;
-
-	return 0;
-}
-
-static int set_rsa_priv_f2_pdb(struct akcipher_request *req,
-			       struct rsa_edesc *edesc)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct device *dev = ctx->dev;
-	struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2;
-	int sec4_sg_index = 0;
-	size_t p_sz = key->p_sz;
-	size_t q_sz = key->q_sz;
-
-	pdb->d_dma = dma_map_single(dev, key->d, key->d_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->d_dma)) {
-		dev_err(dev, "Unable to map RSA private exponent memory\n");
-		return -ENOMEM;
-	}
-
-	pdb->p_dma = dma_map_single(dev, key->p, p_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->p_dma)) {
-		dev_err(dev, "Unable to map RSA prime factor p memory\n");
-		goto unmap_d;
-	}
-
-	pdb->q_dma = dma_map_single(dev, key->q, q_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->q_dma)) {
-		dev_err(dev, "Unable to map RSA prime factor q memory\n");
-		goto unmap_p;
-	}
-
-	pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz, DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(dev, pdb->tmp1_dma)) {
-		dev_err(dev, "Unable to map RSA tmp1 memory\n");
-		goto unmap_q;
-	}
-
-	pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz, DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(dev, pdb->tmp2_dma)) {
-		dev_err(dev, "Unable to map RSA tmp2 memory\n");
-		goto unmap_tmp1;
-	}
-
-	if (edesc->mapped_src_nents > 1) {
-		pdb->sgf |= RSA_PRIV_PDB_SGF_G;
-		pdb->g_dma = edesc->sec4_sg_dma;
-		sec4_sg_index += edesc->mapped_src_nents;
-	} else {
-		struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-
-		pdb->g_dma = sg_dma_address(req_ctx->fixup_src);
-	}
-
-	if (edesc->mapped_dst_nents > 1) {
-		pdb->sgf |= RSA_PRIV_PDB_SGF_F;
-		pdb->f_dma = edesc->sec4_sg_dma +
-			     sec4_sg_index * sizeof(struct sec4_sg_entry);
-	} else {
-		pdb->f_dma = sg_dma_address(req->dst);
-	}
-
-	pdb->sgf |= (key->d_sz << RSA_PDB_D_SHIFT) | key->n_sz;
-	pdb->p_q_len = (q_sz << RSA_PDB_Q_SHIFT) | p_sz;
-
-	return 0;
-
-unmap_tmp1:
-	dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
-unmap_q:
-	dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
-unmap_p:
-	dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
-unmap_d:
-	dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
-
-	return -ENOMEM;
-}
-
-static int set_rsa_priv_f3_pdb(struct akcipher_request *req,
-			       struct rsa_edesc *edesc)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct device *dev = ctx->dev;
-	struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3;
-	int sec4_sg_index = 0;
-	size_t p_sz = key->p_sz;
-	size_t q_sz = key->q_sz;
-
-	pdb->p_dma = dma_map_single(dev, key->p, p_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->p_dma)) {
-		dev_err(dev, "Unable to map RSA prime factor p memory\n");
-		return -ENOMEM;
-	}
-
-	pdb->q_dma = dma_map_single(dev, key->q, q_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->q_dma)) {
-		dev_err(dev, "Unable to map RSA prime factor q memory\n");
-		goto unmap_p;
-	}
-
-	pdb->dp_dma = dma_map_single(dev, key->dp, p_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->dp_dma)) {
-		dev_err(dev, "Unable to map RSA exponent dp memory\n");
-		goto unmap_q;
-	}
-
-	pdb->dq_dma = dma_map_single(dev, key->dq, q_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->dq_dma)) {
-		dev_err(dev, "Unable to map RSA exponent dq memory\n");
-		goto unmap_dp;
-	}
-
-	pdb->c_dma = dma_map_single(dev, key->qinv, p_sz, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, pdb->c_dma)) {
-		dev_err(dev, "Unable to map RSA CRT coefficient qinv memory\n");
-		goto unmap_dq;
-	}
-
-	pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz, DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(dev, pdb->tmp1_dma)) {
-		dev_err(dev, "Unable to map RSA tmp1 memory\n");
-		goto unmap_qinv;
-	}
-
-	pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz, DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(dev, pdb->tmp2_dma)) {
-		dev_err(dev, "Unable to map RSA tmp2 memory\n");
-		goto unmap_tmp1;
-	}
-
-	if (edesc->mapped_src_nents > 1) {
-		pdb->sgf |= RSA_PRIV_PDB_SGF_G;
-		pdb->g_dma = edesc->sec4_sg_dma;
-		sec4_sg_index += edesc->mapped_src_nents;
-	} else {
-		struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-
-		pdb->g_dma = sg_dma_address(req_ctx->fixup_src);
-	}
-
-	if (edesc->mapped_dst_nents > 1) {
-		pdb->sgf |= RSA_PRIV_PDB_SGF_F;
-		pdb->f_dma = edesc->sec4_sg_dma +
-			     sec4_sg_index * sizeof(struct sec4_sg_entry);
-	} else {
-		pdb->f_dma = sg_dma_address(req->dst);
-	}
-
-	pdb->sgf |= key->n_sz;
-	pdb->p_q_len = (q_sz << RSA_PDB_Q_SHIFT) | p_sz;
-
-	return 0;
-
-unmap_tmp1:
-	dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
-unmap_qinv:
-	dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE);
-unmap_dq:
-	dma_unmap_single(dev, pdb->dq_dma, q_sz, DMA_TO_DEVICE);
-unmap_dp:
-	dma_unmap_single(dev, pdb->dp_dma, p_sz, DMA_TO_DEVICE);
-unmap_q:
-	dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
-unmap_p:
-	dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
-
-	return -ENOMEM;
-}
-
-static int akcipher_enqueue_req(struct device *jrdev,
-				void (*cbk)(struct device *jrdev, u32 *desc,
-					    u32 err, void *context),
-				struct akcipher_request *req)
-{
-	struct caam_drv_private_jr *jrpriv = dev_get_drvdata(jrdev);
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
-	struct rsa_edesc *edesc = req_ctx->edesc;
-	u32 *desc = edesc->hw_desc;
-	int ret;
-
-	req_ctx->akcipher_op_done = cbk;
-	/*
-	 * Only the backlog request are sent to crypto-engine since the others
-	 * can be handled by CAAM, if free, especially since JR has up to 1024
-	 * entries (more than the 10 entries from crypto-engine).
-	 */
-	if (req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)
-		ret = crypto_transfer_akcipher_request_to_engine(jrpriv->engine,
-								 req);
-	else
-		ret = caam_jr_enqueue(jrdev, desc, cbk, req);
-
-	if ((ret != -EINPROGRESS) && (ret != -EBUSY)) {
-		switch (key->priv_form) {
-		case FORM1:
-			rsa_priv_f1_unmap(jrdev, edesc, req);
-			break;
-		case FORM2:
-			rsa_priv_f2_unmap(jrdev, edesc, req);
-			break;
-		case FORM3:
-			rsa_priv_f3_unmap(jrdev, edesc, req);
-			break;
-		default:
-			rsa_pub_unmap(jrdev, edesc, req);
-		}
-		rsa_io_unmap(jrdev, edesc, req);
-		kfree(edesc);
-	}
-
-	return ret;
-}
-
-static int caam_rsa_enc(struct akcipher_request *req)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	struct device *jrdev = ctx->dev;
-	struct rsa_edesc *edesc;
-	int ret;
-
-	if (unlikely(!key->n || !key->e))
-		return -EINVAL;
-
-	if (req->dst_len < key->n_sz) {
-		req->dst_len = key->n_sz;
-		dev_err(jrdev, "Output buffer length less than parameter n\n");
-		return -EOVERFLOW;
-	}
-
-	/* Allocate extended descriptor */
-	edesc = rsa_edesc_alloc(req, DESC_RSA_PUB_LEN);
-	if (IS_ERR(edesc))
-		return PTR_ERR(edesc);
-
-	/* Set RSA Encrypt Protocol Data Block */
-	ret = set_rsa_pub_pdb(req, edesc);
-	if (ret)
-		goto init_fail;
-
-	/* Initialize Job Descriptor */
-	init_rsa_pub_desc(edesc->hw_desc, &edesc->pdb.pub);
-
-	return akcipher_enqueue_req(jrdev, rsa_pub_done, req);
-
-init_fail:
-	rsa_io_unmap(jrdev, edesc, req);
-	kfree(edesc);
-	return ret;
-}
-
-static int caam_rsa_dec_priv_f1(struct akcipher_request *req)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct device *jrdev = ctx->dev;
-	struct rsa_edesc *edesc;
-	int ret;
-
-	/* Allocate extended descriptor */
-	edesc = rsa_edesc_alloc(req, DESC_RSA_PRIV_F1_LEN);
-	if (IS_ERR(edesc))
-		return PTR_ERR(edesc);
-
-	/* Set RSA Decrypt Protocol Data Block - Private Key Form #1 */
-	ret = set_rsa_priv_f1_pdb(req, edesc);
-	if (ret)
-		goto init_fail;
-
-	/* Initialize Job Descriptor */
-	init_rsa_priv_f1_desc(edesc->hw_desc, &edesc->pdb.priv_f1);
-
-	return akcipher_enqueue_req(jrdev, rsa_priv_f_done, req);
-
-init_fail:
-	rsa_io_unmap(jrdev, edesc, req);
-	kfree(edesc);
-	return ret;
-}
-
-static int caam_rsa_dec_priv_f2(struct akcipher_request *req)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct device *jrdev = ctx->dev;
-	struct rsa_edesc *edesc;
-	int ret;
-
-	/* Allocate extended descriptor */
-	edesc = rsa_edesc_alloc(req, DESC_RSA_PRIV_F2_LEN);
-	if (IS_ERR(edesc))
-		return PTR_ERR(edesc);
-
-	/* Set RSA Decrypt Protocol Data Block - Private Key Form #2 */
-	ret = set_rsa_priv_f2_pdb(req, edesc);
-	if (ret)
-		goto init_fail;
-
-	/* Initialize Job Descriptor */
-	init_rsa_priv_f2_desc(edesc->hw_desc, &edesc->pdb.priv_f2);
-
-	return akcipher_enqueue_req(jrdev, rsa_priv_f_done, req);
-
-init_fail:
-	rsa_io_unmap(jrdev, edesc, req);
-	kfree(edesc);
-	return ret;
-}
-
-static int caam_rsa_dec_priv_f3(struct akcipher_request *req)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct device *jrdev = ctx->dev;
-	struct rsa_edesc *edesc;
-	int ret;
-
-	/* Allocate extended descriptor */
-	edesc = rsa_edesc_alloc(req, DESC_RSA_PRIV_F3_LEN);
-	if (IS_ERR(edesc))
-		return PTR_ERR(edesc);
-
-	/* Set RSA Decrypt Protocol Data Block - Private Key Form #3 */
-	ret = set_rsa_priv_f3_pdb(req, edesc);
-	if (ret)
-		goto init_fail;
-
-	/* Initialize Job Descriptor */
-	init_rsa_priv_f3_desc(edesc->hw_desc, &edesc->pdb.priv_f3);
-
-	return akcipher_enqueue_req(jrdev, rsa_priv_f_done, req);
-
-init_fail:
-	rsa_io_unmap(jrdev, edesc, req);
-	kfree(edesc);
-	return ret;
-}
-
-static int caam_rsa_dec(struct akcipher_request *req)
-{
-	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-	int ret;
-
-	if (unlikely(!key->n || !key->d))
-		return -EINVAL;
-
-	if (req->dst_len < key->n_sz) {
-		req->dst_len = key->n_sz;
-		dev_err(ctx->dev, "Output buffer length less than parameter n\n");
-		return -EOVERFLOW;
-	}
-
-	if (key->priv_form == FORM3)
-		ret = caam_rsa_dec_priv_f3(req);
-	else if (key->priv_form == FORM2)
-		ret = caam_rsa_dec_priv_f2(req);
-	else
-		ret = caam_rsa_dec_priv_f1(req);
-
-	return ret;
-}
-
-static void caam_rsa_free_key(struct caam_rsa_key *key)
-{
-	kfree_sensitive(key->d);
-	kfree_sensitive(key->p);
-	kfree_sensitive(key->q);
-	kfree_sensitive(key->dp);
-	kfree_sensitive(key->dq);
-	kfree_sensitive(key->qinv);
-	kfree_sensitive(key->tmp1);
-	kfree_sensitive(key->tmp2);
-	kfree(key->e);
-	kfree(key->n);
-	memset(key, 0, sizeof(*key));
-}
-
-static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes)
-{
-	while (!**ptr && *nbytes) {
-		(*ptr)++;
-		(*nbytes)--;
-	}
-}
-
-/**
- * caam_read_rsa_crt - Used for reading dP, dQ, qInv CRT members.
- * dP, dQ and qInv could decode to less than corresponding p, q length, as the
- * BER-encoding requires that the minimum number of bytes be used to encode the
- * integer. dP, dQ, qInv decoded values have to be zero-padded to appropriate
- * length.
- *
- * @ptr   : pointer to {dP, dQ, qInv} CRT member
- * @nbytes: length in bytes of {dP, dQ, qInv} CRT member
- * @dstlen: length in bytes of corresponding p or q prime factor
- */
-static u8 *caam_read_rsa_crt(const u8 *ptr, size_t nbytes, size_t dstlen)
-{
-	u8 *dst;
-
-	caam_rsa_drop_leading_zeros(&ptr, &nbytes);
-	if (!nbytes)
-		return NULL;
-
-	dst = kzalloc(dstlen, GFP_KERNEL);
-	if (!dst)
-		return NULL;
-
-	memcpy(dst + (dstlen - nbytes), ptr, nbytes);
-
-	return dst;
-}
-
-/**
- * caam_read_raw_data - Read a raw byte stream as a positive integer.
- * The function skips buffer's leading zeros, copies the remained data
- * to a buffer allocated in the GFP_KERNEL zone and returns
- * the address of the new buffer.
- *
- * @buf   : The data to read
- * @nbytes: The amount of data to read
- */
-static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes)
-{
-
-	caam_rsa_drop_leading_zeros(&buf, nbytes);
-	if (!*nbytes)
-		return NULL;
-
-	return kmemdup(buf, *nbytes, GFP_KERNEL);
-}
-
-static int caam_rsa_check_key_length(unsigned int len)
-{
-	if (len > 4096)
-		return -EINVAL;
-	return 0;
-}
-
-static int caam_rsa_set_pub_key(struct crypto_akcipher *tfm, const void *key,
-				unsigned int keylen)
-{
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct rsa_key raw_key = {NULL};
-	struct caam_rsa_key *rsa_key = &ctx->key;
-	int ret;
-
-	/* Free the old RSA key if any */
-	caam_rsa_free_key(rsa_key);
-
-	ret = rsa_parse_pub_key(&raw_key, key, keylen);
-	if (ret)
-		return ret;
-
-	/* Copy key in DMA zone */
-	rsa_key->e = kmemdup(raw_key.e, raw_key.e_sz, GFP_KERNEL);
-	if (!rsa_key->e)
-		goto err;
-
-	/*
-	 * Skip leading zeros and copy the positive integer to a buffer
-	 * allocated in the GFP_KERNEL zone. The decryption descriptor
-	 * expects a positive integer for the RSA modulus and uses its length as
-	 * decryption output length.
-	 */
-	rsa_key->n = caam_read_raw_data(raw_key.n, &raw_key.n_sz);
-	if (!rsa_key->n)
-		goto err;
-
-	if (caam_rsa_check_key_length(raw_key.n_sz << 3)) {
-		caam_rsa_free_key(rsa_key);
-		return -EINVAL;
-	}
-
-	rsa_key->e_sz = raw_key.e_sz;
-	rsa_key->n_sz = raw_key.n_sz;
-
-	return 0;
-err:
-	caam_rsa_free_key(rsa_key);
-	return -ENOMEM;
-}
-
-static int caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
-				       struct rsa_key *raw_key)
-{
-	struct caam_rsa_key *rsa_key = &ctx->key;
-	size_t p_sz = raw_key->p_sz;
-	size_t q_sz = raw_key->q_sz;
-	unsigned aligned_size;
-
-	rsa_key->p = caam_read_raw_data(raw_key->p, &p_sz);
-	if (!rsa_key->p)
-		return -ENOMEM;
-	rsa_key->p_sz = p_sz;
-
-	rsa_key->q = caam_read_raw_data(raw_key->q, &q_sz);
-	if (!rsa_key->q)
-		goto free_p;
-	rsa_key->q_sz = q_sz;
-
-	aligned_size = ALIGN(raw_key->p_sz, dma_get_cache_alignment());
-	rsa_key->tmp1 = kzalloc(aligned_size, GFP_KERNEL);
-	if (!rsa_key->tmp1)
-		goto free_q;
-
-	aligned_size = ALIGN(raw_key->q_sz, dma_get_cache_alignment());
-	rsa_key->tmp2 = kzalloc(aligned_size, GFP_KERNEL);
-	if (!rsa_key->tmp2)
-		goto free_tmp1;
-
-	rsa_key->priv_form = FORM2;
-
-	rsa_key->dp = caam_read_rsa_crt(raw_key->dp, raw_key->dp_sz, p_sz);
-	if (!rsa_key->dp)
-		goto free_tmp2;
-
-	rsa_key->dq = caam_read_rsa_crt(raw_key->dq, raw_key->dq_sz, q_sz);
-	if (!rsa_key->dq)
-		goto free_dp;
-
-	rsa_key->qinv = caam_read_rsa_crt(raw_key->qinv, raw_key->qinv_sz,
-					  q_sz);
-	if (!rsa_key->qinv)
-		goto free_dq;
-
-	rsa_key->priv_form = FORM3;
-
-	return 0;
-
-free_dq:
-	kfree_sensitive(rsa_key->dq);
-free_dp:
-	kfree_sensitive(rsa_key->dp);
-free_tmp2:
-	kfree_sensitive(rsa_key->tmp2);
-free_tmp1:
-	kfree_sensitive(rsa_key->tmp1);
-free_q:
-	kfree_sensitive(rsa_key->q);
-free_p:
-	kfree_sensitive(rsa_key->p);
-	return -ENOMEM;
-}
-
-static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
-				 unsigned int keylen)
-{
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct rsa_key raw_key = {NULL};
-	struct caam_rsa_key *rsa_key = &ctx->key;
-	int ret;
-
-	/* Free the old RSA key if any */
-	caam_rsa_free_key(rsa_key);
-
-	ret = rsa_parse_priv_key(&raw_key, key, keylen);
-	if (ret)
-		return ret;
-
-	/* Copy key in DMA zone */
-	rsa_key->d = kmemdup(raw_key.d, raw_key.d_sz, GFP_KERNEL);
-	if (!rsa_key->d)
-		goto err;
-
-	rsa_key->e = kmemdup(raw_key.e, raw_key.e_sz, GFP_KERNEL);
-	if (!rsa_key->e)
-		goto err;
-
-	/*
-	 * Skip leading zeros and copy the positive integer to a buffer
-	 * allocated in the GFP_KERNEL zone. The decryption descriptor
-	 * expects a positive integer for the RSA modulus and uses its length as
-	 * decryption output length.
-	 */
-	rsa_key->n = caam_read_raw_data(raw_key.n, &raw_key.n_sz);
-	if (!rsa_key->n)
-		goto err;
-
-	if (caam_rsa_check_key_length(raw_key.n_sz << 3)) {
-		caam_rsa_free_key(rsa_key);
-		return -EINVAL;
-	}
-
-	rsa_key->d_sz = raw_key.d_sz;
-	rsa_key->e_sz = raw_key.e_sz;
-	rsa_key->n_sz = raw_key.n_sz;
-
-	ret = caam_rsa_set_priv_key_form(ctx, &raw_key);
-	if (ret)
-		goto err;
-
-	return 0;
-
-err:
-	caam_rsa_free_key(rsa_key);
-	return -ENOMEM;
-}
-
-static unsigned int caam_rsa_max_size(struct crypto_akcipher *tfm)
-{
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-
-	return ctx->key.n_sz;
-}
-
-/* Per session pkc's driver context creation function */
-static int caam_rsa_init_tfm(struct crypto_akcipher *tfm)
-{
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-
-	akcipher_set_reqsize(tfm, sizeof(struct caam_rsa_req_ctx));
-
-	ctx->dev = caam_jr_alloc();
-
-	if (IS_ERR(ctx->dev)) {
-		pr_err("Job Ring Device allocation for transform failed\n");
-		return PTR_ERR(ctx->dev);
-	}
-
-	ctx->padding_dma = dma_map_single(ctx->dev, zero_buffer,
-					  CAAM_RSA_MAX_INPUT_SIZE - 1,
-					  DMA_TO_DEVICE);
-	if (dma_mapping_error(ctx->dev, ctx->padding_dma)) {
-		dev_err(ctx->dev, "unable to map padding\n");
-		caam_jr_free(ctx->dev);
-		return -ENOMEM;
-	}
-
-	return 0;
-}
-
-/* Per session pkc's driver context cleanup function */
-static void caam_rsa_exit_tfm(struct crypto_akcipher *tfm)
-{
-	struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
-	struct caam_rsa_key *key = &ctx->key;
-
-	dma_unmap_single(ctx->dev, ctx->padding_dma, CAAM_RSA_MAX_INPUT_SIZE -
-			 1, DMA_TO_DEVICE);
-	caam_rsa_free_key(key);
-	caam_jr_free(ctx->dev);
-}
-
-static struct caam_akcipher_alg caam_rsa = {
-	.akcipher.base = {
-		.encrypt = caam_rsa_enc,
-		.decrypt = caam_rsa_dec,
-		.set_pub_key = caam_rsa_set_pub_key,
-		.set_priv_key = caam_rsa_set_priv_key,
-		.max_size = caam_rsa_max_size,
-		.init = caam_rsa_init_tfm,
-		.exit = caam_rsa_exit_tfm,
-		.base = {
-			.cra_name = "rsa",
-			.cra_driver_name = "rsa-caam",
-			.cra_priority = 3000,
-			.cra_module = THIS_MODULE,
-			.cra_ctxsize = sizeof(struct caam_rsa_ctx) +
-				       CRYPTO_DMA_PADDING,
-		},
-	},
-	.akcipher.op = {
-		.do_one_request = akcipher_do_one_req,
-	},
-};
-
-/* Public Key Cryptography module initialization handler */
-int caam_pkc_init(struct device *ctrldev)
-{
-	struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
-	u32 pk_inst, pkha;
-	int err;
-	init_done = false;
-
-	/* Determine public key hardware accelerator presence. */
-	if (priv->era < 10) {
-		pk_inst = (rd_reg32(&priv->jr[0]->perfmon.cha_num_ls) &
-			   CHA_ID_LS_PK_MASK) >> CHA_ID_LS_PK_SHIFT;
-	} else {
-		pkha = rd_reg32(&priv->jr[0]->vreg.pkha);
-		pk_inst = pkha & CHA_VER_NUM_MASK;
-
-		/*
-		 * Newer CAAMs support partially disabled functionality. If this is the
-		 * case, the number is non-zero, but this bit is set to indicate that
-		 * no encryption or decryption is supported. Only signing and verifying
-		 * is supported.
-		 */
-		if (pkha & CHA_VER_MISC_PKHA_NO_CRYPT)
-			pk_inst = 0;
-	}
-
-	/* Do not register algorithms if PKHA is not present. */
-	if (!pk_inst)
-		return 0;
-
-	/* allocate zero buffer, used for padding input */
-	zero_buffer = kzalloc(CAAM_RSA_MAX_INPUT_SIZE - 1, GFP_KERNEL);
-	if (!zero_buffer)
-		return -ENOMEM;
-
-	err = crypto_engine_register_akcipher(&caam_rsa.akcipher);
-
-	if (err) {
-		kfree(zero_buffer);
-		dev_warn(ctrldev, "%s alg registration failed\n",
-			 caam_rsa.akcipher.base.base.cra_driver_name);
-	} else {
-		init_done = true;
-		caam_rsa.registered = true;
-		dev_info(ctrldev, "caam pkc algorithms registered in /proc/crypto\n");
-	}
-
-	return err;
-}
-
-void caam_pkc_exit(void)
-{
-	if (!init_done)
-		return;
-
-	if (caam_rsa.registered)
-		crypto_engine_unregister_akcipher(&caam_rsa.akcipher);
-
-	kfree(zero_buffer);
-}
diff --git a/drivers/crypto/caam/caampkc.h b/drivers/crypto/caam/caampkc.h
deleted file mode 100644
index 96d03704c9be..000000000000
--- a/drivers/crypto/caam/caampkc.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * caam - Freescale FSL CAAM support for Public Key Cryptography descriptors
- *
- * Copyright 2016 Freescale Semiconductor, Inc.
- *
- * There is no Shared Descriptor for PKC so that the Job Descriptor must carry
- * all the desired key parameters, input and output pointers.
- */
-
-#ifndef _PKC_DESC_H_
-#define _PKC_DESC_H_
-#include "compat.h"
-#include "pdb.h"
-
-/**
- * caam_priv_key_form - CAAM RSA private key representation
- * CAAM RSA private key may have either of three forms.
- *
- * 1. The first representation consists of the pair (n, d), where the
- *    components have the following meanings:
- *        n      the RSA modulus
- *        d      the RSA private exponent
- *
- * 2. The second representation consists of the triplet (p, q, d), where the
- *    components have the following meanings:
- *        p      the first prime factor of the RSA modulus n
- *        q      the second prime factor of the RSA modulus n
- *        d      the RSA private exponent
- *
- * 3. The third representation consists of the quintuple (p, q, dP, dQ, qInv),
- *    where the components have the following meanings:
- *        p      the first prime factor of the RSA modulus n
- *        q      the second prime factor of the RSA modulus n
- *        dP     the first factors's CRT exponent
- *        dQ     the second factors's CRT exponent
- *        qInv   the (first) CRT coefficient
- *
- * The benefit of using the third or the second key form is lower computational
- * cost for the decryption and signature operations.
- */
-enum caam_priv_key_form {
-	FORM1,
-	FORM2,
-	FORM3
-};
-
-/**
- * caam_rsa_key - CAAM RSA key structure. Keys are allocated in DMA zone.
- * @n           : RSA modulus raw byte stream
- * @e           : RSA public exponent raw byte stream
- * @d           : RSA private exponent raw byte stream
- * @p           : RSA prime factor p of RSA modulus n
- * @q           : RSA prime factor q of RSA modulus n
- * @dp          : RSA CRT exponent of p
- * @dp          : RSA CRT exponent of q
- * @qinv        : RSA CRT coefficient
- * @tmp1        : CAAM uses this temporary buffer as internal state buffer.
- *                It is assumed to be as long as p.
- * @tmp2        : CAAM uses this temporary buffer as internal state buffer.
- *                It is assumed to be as long as q.
- * @n_sz        : length in bytes of RSA modulus n
- * @e_sz        : length in bytes of RSA public exponent
- * @d_sz        : length in bytes of RSA private exponent
- * @p_sz        : length in bytes of RSA prime factor p of RSA modulus n
- * @q_sz        : length in bytes of RSA prime factor q of RSA modulus n
- * @priv_form   : CAAM RSA private key representation
- */
-struct caam_rsa_key {
-	u8 *n;
-	u8 *e;
-	u8 *d;
-	u8 *p;
-	u8 *q;
-	u8 *dp;
-	u8 *dq;
-	u8 *qinv;
-	u8 *tmp1;
-	u8 *tmp2;
-	size_t n_sz;
-	size_t e_sz;
-	size_t d_sz;
-	size_t p_sz;
-	size_t q_sz;
-	enum caam_priv_key_form priv_form;
-};
-
-/**
- * caam_rsa_ctx - per session context.
- * @key         : RSA key in DMA zone
- * @dev         : device structure
- * @padding_dma : dma address of padding, for adding it to the input
- */
-struct caam_rsa_ctx {
-	struct caam_rsa_key key;
-	struct device *dev;
-	dma_addr_t padding_dma;
-
-};
-
-/**
- * caam_rsa_req_ctx - per request context.
- * @src           : input scatterlist (stripped of leading zeros)
- * @fixup_src     : input scatterlist (that might be stripped of leading zeros)
- * @fixup_src_len : length of the fixup_src input scatterlist
- * @edesc         : s/w-extended rsa descriptor
- * @akcipher_op_done : callback used when operation is done
- */
-struct caam_rsa_req_ctx {
-	struct scatterlist src[2];
-	struct scatterlist *fixup_src;
-	unsigned int fixup_src_len;
-	struct rsa_edesc *edesc;
-	void (*akcipher_op_done)(struct device *jrdev, u32 *desc, u32 err,
-				 void *context);
-};
-
-/**
- * rsa_edesc - s/w-extended rsa descriptor
- * @src_nents     : number of segments in input s/w scatterlist
- * @dst_nents     : number of segments in output s/w scatterlist
- * @mapped_src_nents: number of segments in input h/w link table
- * @mapped_dst_nents: number of segments in output h/w link table
- * @sec4_sg_bytes : length of h/w link table
- * @bklog         : stored to determine if the request needs backlog
- * @sec4_sg_dma   : dma address of h/w link table
- * @sec4_sg       : pointer to h/w link table
- * @pdb           : specific RSA Protocol Data Block (PDB)
- * @hw_desc       : descriptor followed by link tables if any
- */
-struct rsa_edesc {
-	int src_nents;
-	int dst_nents;
-	int mapped_src_nents;
-	int mapped_dst_nents;
-	int sec4_sg_bytes;
-	bool bklog;
-	dma_addr_t sec4_sg_dma;
-	struct sec4_sg_entry *sec4_sg;
-	union {
-		struct rsa_pub_pdb pub;
-		struct rsa_priv_f1_pdb priv_f1;
-		struct rsa_priv_f2_pdb priv_f2;
-		struct rsa_priv_f3_pdb priv_f3;
-	} pdb;
-	u32 hw_desc[];
-};
-
-/* Descriptor construction primitives. */
-void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb);
-void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb);
-void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb);
-void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb);
-
-#endif
diff --git a/drivers/crypto/caam/pkc_desc.c b/drivers/crypto/caam/pkc_desc.c
deleted file mode 100644
index 0d5ee762e036..000000000000
--- a/drivers/crypto/caam/pkc_desc.c
+++ /dev/null
@@ -1,73 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * caam - Freescale FSL CAAM support for Public Key Cryptography descriptors
- *
- * Copyright 2016 Freescale Semiconductor, Inc.
- *
- * There is no Shared Descriptor for PKC so that the Job Descriptor must carry
- * all the desired key parameters, input and output pointers.
- */
-#include "caampkc.h"
-#include "desc_constr.h"
-
-/* Descriptor for RSA Public operation */
-void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb)
-{
-	init_job_desc_pdb(desc, 0, SIZEOF_RSA_PUB_PDB);
-	append_cmd(desc, pdb->sgf);
-	append_ptr(desc, pdb->f_dma);
-	append_ptr(desc, pdb->g_dma);
-	append_ptr(desc, pdb->n_dma);
-	append_ptr(desc, pdb->e_dma);
-	append_cmd(desc, pdb->f_len);
-	append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSAENC_PUBKEY);
-}
-
-/* Descriptor for RSA Private operation - Private Key Form #1 */
-void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb)
-{
-	init_job_desc_pdb(desc, 0, SIZEOF_RSA_PRIV_F1_PDB);
-	append_cmd(desc, pdb->sgf);
-	append_ptr(desc, pdb->g_dma);
-	append_ptr(desc, pdb->f_dma);
-	append_ptr(desc, pdb->n_dma);
-	append_ptr(desc, pdb->d_dma);
-	append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
-			 RSA_PRIV_KEY_FRM_1);
-}
-
-/* Descriptor for RSA Private operation - Private Key Form #2 */
-void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb)
-{
-	init_job_desc_pdb(desc, 0, SIZEOF_RSA_PRIV_F2_PDB);
-	append_cmd(desc, pdb->sgf);
-	append_ptr(desc, pdb->g_dma);
-	append_ptr(desc, pdb->f_dma);
-	append_ptr(desc, pdb->d_dma);
-	append_ptr(desc, pdb->p_dma);
-	append_ptr(desc, pdb->q_dma);
-	append_ptr(desc, pdb->tmp1_dma);
-	append_ptr(desc, pdb->tmp2_dma);
-	append_cmd(desc, pdb->p_q_len);
-	append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
-			 RSA_PRIV_KEY_FRM_2);
-}
-
-/* Descriptor for RSA Private operation - Private Key Form #3 */
-void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb)
-{
-	init_job_desc_pdb(desc, 0, SIZEOF_RSA_PRIV_F3_PDB);
-	append_cmd(desc, pdb->sgf);
-	append_ptr(desc, pdb->g_dma);
-	append_ptr(desc, pdb->f_dma);
-	append_ptr(desc, pdb->c_dma);
-	append_ptr(desc, pdb->p_dma);
-	append_ptr(desc, pdb->q_dma);
-	append_ptr(desc, pdb->dp_dma);
-	append_ptr(desc, pdb->dq_dma);
-	append_ptr(desc, pdb->tmp1_dma);
-	append_ptr(desc, pdb->tmp2_dma);
-	append_cmd(desc, pdb->p_q_len);
-	append_operation(desc, OP_TYPE_UNI_PROTOCOL | OP_PCLID_RSADEC_PRVKEY |
-			 RSA_PRIV_KEY_FRM_3);
-}
diff --git a/drivers/crypto/caam/Kconfig b/drivers/crypto/caam/Kconfig
index ec57bf6aaf6c..94f19126f61b 100644
--- a/drivers/crypto/caam/Kconfig
+++ b/drivers/crypto/caam/Kconfig
@@ -133,15 +133,6 @@ config CRYPTO_DEV_FSL_CAAM_AHASH_API
 	  Selecting this will offload ahash for users of the
 	  scatterlist crypto API to the SEC4 via job ring.
 
-config CRYPTO_DEV_FSL_CAAM_PKC_API
-	bool "Register public key cryptography implementations with Crypto API"
-	default y
-	select CRYPTO_RSA
-	help
-	  Selecting this will allow SEC Public key support for RSA.
-	  Supported cryptographic primitives: encryption, decryption,
-	  signature and verification.
-
 config CRYPTO_DEV_FSL_CAAM_RNG_API
 	bool "Register caam device for hwrng API"
 	default y
diff --git a/drivers/crypto/caam/Makefile b/drivers/crypto/caam/Makefile
index a17e3cf14c61..87a82474b841 100644
--- a/drivers/crypto/caam/Makefile
+++ b/drivers/crypto/caam/Makefile
@@ -20,7 +20,6 @@ caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API) += caamalg.o
 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += caamalg_qi.o
 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
-caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caampkc.o pkc_desc.o
 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_BLOB_GEN) += blob_gen.o
 
 caam-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += qi.o
diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h
index 6e48bf7d6054..744b6586171c 100644
--- a/drivers/crypto/caam/intern.h
+++ b/drivers/crypto/caam/intern.h
@@ -178,24 +178,6 @@ static inline void caam_algapi_hash_exit(void)
 
 #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API */
 
-#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API
-
-int caam_pkc_init(struct device *dev);
-void caam_pkc_exit(void);
-
-#else
-
-static inline int caam_pkc_init(struct device *dev)
-{
-	return 0;
-}
-
-static inline void caam_pkc_exit(void)
-{
-}
-
-#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API */
-
 #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API
 
 int caam_rng_init(struct device *dev);
diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 239469f6882e..2c1e8275ddaf 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -38,7 +38,6 @@ static void register_algs(struct caam_drv_private_jr *jrpriv,
 
 	caam_algapi_init(dev);
 	caam_algapi_hash_init(dev);
-	caam_pkc_init(dev);
 	jrpriv->hwrng = !caam_rng_init(dev);
 	caam_qi_algapi_init(dev);
 
@@ -54,7 +53,6 @@ static void unregister_algs(void)
 		goto algs_unlock;
 
 	caam_qi_algapi_exit();
-	caam_pkc_exit();
 	caam_algapi_hash_exit();
 	caam_algapi_exit();
 
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [EXT] [PATCH] crypto: caam - Remove public key support
  2026-09-04  5:37     ` [PATCH] crypto: caam - Remove public key support Herbert Xu
@ 2026-09-09  7:23       ` Varun Sethi
  0 siblings, 0 replies; 5+ messages in thread
From: Varun Sethi @ 2026-09-09  7:23 UTC (permalink / raw)
  To: Herbert Xu, Changwei Zou, Sahil Malhotra
  Cc: davem@davemloft.net, gaurav.jain@nxp.com, Horia Geanta,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	lukas@wunner.de, Pankaj Gupta

[-- Attachment #1: Type: text/plain, Size: 59536 bytes --]

Hi Herbert,
Gaurav and Meenakshi were maintaining the CAAM driver but have left NXP
sometime back. Sahil Malhotra would be taking up this responsibility now.
Please allow Sahil a few weeks to fully transition into this role.

Regards
Varun
> -----Original Message-----
> From: Herbert Xu <herbert@gondor.apana.org.au>
> Sent: 04 September 2026 11:08 AM
> To: Changwei Zou <changwei.zou@canonical.com>
> Cc: davem@davemloft.net; gaurav.jain@nxp.com; Horia Geanta
> <horia.geanta@nxp.com>; linux-crypto@vger.kernel.org; linux-
> kernel@vger.kernel.org; lukas@wunner.de; Pankaj Gupta
> <pankaj.gupta@nxp.com>
> Subject: [EXT] [PATCH] crypto: caam - Remove public key support
> 
> Caution: This is an external email. Please take care when clicking links
or opening
> attachments. When in doubt, report the message using the 'Report this
email'
> button
> 
> 
> On Fri, Aug 21, 2026 at 03:18:24PM +1000, Changwei Zou wrote:
> >
> > A new version with two patches and a cover letter is available at the
following
> link.
> 
> This driver hasn't been actively maintained for years.
> 
> Let's just remove it:
> 
> ---8<---
> Remove the public key part of the caam driver because it has been
> unmaintained and there are serious bugs in it.
> 
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> 
> diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
> deleted file mode 100644
> index cb001aa1de66..000000000000
> --- a/drivers/crypto/caam/caampkc.c
> +++ /dev/null
> @@ -1,1230 +0,0 @@
> -// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
> -/*
> - * caam - Freescale FSL CAAM support for Public Key Cryptography
> - *
> - * Copyright 2016 Freescale Semiconductor, Inc.
> - * Copyright 2018-2019, 2023 NXP
> - *
> - * There is no Shared Descriptor for PKC so that the Job Descriptor must
carry
> - * all the desired key parameters, input and output pointers.
> - */
> -#include "compat.h"
> -#include "regs.h"
> -#include "intern.h"
> -#include "jr.h"
> -#include "error.h"
> -#include "desc_constr.h"
> -#include "sg_sw_sec4.h"
> -#include "caampkc.h"
> -#include <crypto/internal/engine.h>
> -#include <linux/dma-mapping.h>
> -#include <linux/err.h>
> -#include <linux/kernel.h>
> -#include <linux/slab.h>
> -#include <linux/string.h>
> -
> -#define DESC_RSA_PUB_LEN       (2 * CAAM_CMD_SZ + SIZEOF_RSA_PUB_PDB)
> -#define DESC_RSA_PRIV_F1_LEN   (2 * CAAM_CMD_SZ + \
> -                                SIZEOF_RSA_PRIV_F1_PDB)
> -#define DESC_RSA_PRIV_F2_LEN   (2 * CAAM_CMD_SZ + \
> -                                SIZEOF_RSA_PRIV_F2_PDB)
> -#define DESC_RSA_PRIV_F3_LEN   (2 * CAAM_CMD_SZ + \
> -                                SIZEOF_RSA_PRIV_F3_PDB)
> -#define CAAM_RSA_MAX_INPUT_SIZE        512 /* for a 4096-bit modulus */
> -
> -/* buffer filled with zeros, used for padding */
> -static u8 *zero_buffer;
> -
> -/*
> - * variable used to avoid double free of resources in case
> - * algorithm registration was unsuccessful
> - */
> -static bool init_done;
> -
> -struct caam_akcipher_alg {
> -       struct akcipher_engine_alg akcipher;
> -       bool registered;
> -};
> -
> -static void rsa_io_unmap(struct device *dev, struct rsa_edesc *edesc,
> -                        struct akcipher_request *req)
> -{
> -       struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
> -
> -       dma_unmap_sg(dev, req->dst, edesc->dst_nents, DMA_FROM_DEVICE);
> -       dma_unmap_sg(dev, req_ctx->fixup_src, edesc->src_nents,
> DMA_TO_DEVICE);
> -
> -       if (edesc->sec4_sg_bytes)
> -               dma_unmap_single(dev, edesc->sec4_sg_dma,
edesc->sec4_sg_bytes,
> -                                DMA_TO_DEVICE);
> -}
> -
> -static void rsa_pub_unmap(struct device *dev, struct rsa_edesc *edesc,
> -                         struct akcipher_request *req)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct rsa_pub_pdb *pdb = &edesc->pdb.pub;
> -
> -       dma_unmap_single(dev, pdb->n_dma, key->n_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->e_dma, key->e_sz, DMA_TO_DEVICE);
> -}
> -
> -static void rsa_priv_f1_unmap(struct device *dev, struct rsa_edesc
*edesc,
> -                             struct akcipher_request *req)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct rsa_priv_f1_pdb *pdb = &edesc->pdb.priv_f1;
> -
> -       dma_unmap_single(dev, pdb->n_dma, key->n_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
> -}
> -
> -static void rsa_priv_f2_unmap(struct device *dev, struct rsa_edesc
*edesc,
> -                             struct akcipher_request *req)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2;
> -       size_t p_sz = key->p_sz;
> -       size_t q_sz = key->q_sz;
> -
> -       dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
> -       dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_BIDIRECTIONAL);
> -}
> -
> -static void rsa_priv_f3_unmap(struct device *dev, struct rsa_edesc
*edesc,
> -                             struct akcipher_request *req)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3;
> -       size_t p_sz = key->p_sz;
> -       size_t q_sz = key->q_sz;
> -
> -       dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->dp_dma, p_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->dq_dma, q_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE);
> -       dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
> -       dma_unmap_single(dev, pdb->tmp2_dma, q_sz, DMA_BIDIRECTIONAL);
> -}
> -
> -/* RSA Job Completion handler */
> -static void rsa_pub_done(struct device *dev, u32 *desc, u32 err, void
*context)
> -{
> -       struct akcipher_request *req = context;
> -       struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
> -       struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
> -       struct rsa_edesc *edesc;
> -       int ecode = 0;
> -       bool has_bklog;
> -
> -       if (err)
> -               ecode = caam_jr_strstatus(dev, err);
> -
> -       edesc = req_ctx->edesc;
> -       has_bklog = edesc->bklog;
> -
> -       rsa_pub_unmap(dev, edesc, req);
> -       rsa_io_unmap(dev, edesc, req);
> -       kfree(edesc);
> -
> -       /*
> -        * If no backlog flag, the completion of the request is done
> -        * by CAAM, not crypto engine.
> -        */
> -       if (!has_bklog)
> -               akcipher_request_complete(req, ecode);
> -       else
> -               crypto_finalize_akcipher_request(jrp->engine, req, ecode);
> -}
> -
> -static void rsa_priv_f_done(struct device *dev, u32 *desc, u32 err,
> -                           void *context)
> -{
> -       struct akcipher_request *req = context;
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
> -       struct rsa_edesc *edesc;
> -       int ecode = 0;
> -       bool has_bklog;
> -
> -       if (err)
> -               ecode = caam_jr_strstatus(dev, err);
> -
> -       edesc = req_ctx->edesc;
> -       has_bklog = edesc->bklog;
> -
> -       switch (key->priv_form) {
> -       case FORM1:
> -               rsa_priv_f1_unmap(dev, edesc, req);
> -               break;
> -       case FORM2:
> -               rsa_priv_f2_unmap(dev, edesc, req);
> -               break;
> -       case FORM3:
> -               rsa_priv_f3_unmap(dev, edesc, req);
> -       }
> -
> -       rsa_io_unmap(dev, edesc, req);
> -       kfree(edesc);
> -
> -       /*
> -        * If no backlog flag, the completion of the request is done
> -        * by CAAM, not crypto engine.
> -        */
> -       if (!has_bklog)
> -               akcipher_request_complete(req, ecode);
> -       else
> -               crypto_finalize_akcipher_request(jrp->engine, req, ecode);
> -}
> -
> -/**
> - * caam_rsa_count_leading_zeros - Count leading zeros, need it to strip,
> - *                                from a given scatterlist
> - *
> - * @sgl   : scatterlist to count zeros from
> - * @nbytes: number of zeros, in bytes, to strip
> - * @flags : operation flags
> - */
> -static int caam_rsa_count_leading_zeros(struct scatterlist *sgl,
> -                                       unsigned int nbytes,
> -                                       unsigned int flags)
> -{
> -       struct sg_mapping_iter miter;
> -       int lzeros, ents;
> -       unsigned int len;
> -       unsigned int tbytes = nbytes;
> -       const u8 *buff;
> -
> -       ents = sg_nents_for_len(sgl, nbytes);
> -       if (ents < 0)
> -               return ents;
> -
> -       sg_miter_start(&miter, sgl, ents, SG_MITER_FROM_SG | flags);
> -
> -       lzeros = 0;
> -       len = 0;
> -       while (nbytes > 0) {
> -               /* do not strip more than given bytes */
> -               while (len && !*buff && lzeros < nbytes) {
> -                       lzeros++;
> -                       len--;
> -                       buff++;
> -               }
> -
> -               if (len && *buff)
> -                       break;
> -
> -               if (!sg_miter_next(&miter))
> -                       break;
> -
> -               buff = miter.addr;
> -               len = miter.length;
> -
> -               nbytes -= lzeros;
> -               lzeros = 0;
> -       }
> -
> -       miter.consumed = lzeros;
> -       sg_miter_stop(&miter);
> -       nbytes -= lzeros;
> -
> -       return tbytes - nbytes;
> -}
> -
> -static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req,
> -                                        size_t desclen)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct device *dev = ctx->dev;
> -       struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct rsa_edesc *edesc;
> -       gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
> -                      GFP_KERNEL : GFP_ATOMIC;
> -       int sg_flags = (flags == GFP_ATOMIC) ? SG_MITER_ATOMIC : 0;
> -       int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes;
> -       int src_nents, dst_nents;
> -       int mapped_src_nents, mapped_dst_nents;
> -       unsigned int diff_size = 0;
> -       int lzeros;
> -
> -       if (req->src_len > key->n_sz) {
> -               /*
> -                * strip leading zeros and
> -                * return the number of zeros to skip
> -                */
> -               lzeros = caam_rsa_count_leading_zeros(req->src,
req->src_len -
> -                                                     key->n_sz,
sg_flags);
> -               if (lzeros < 0)
> -                       return ERR_PTR(lzeros);
> -
> -               req_ctx->fixup_src = scatterwalk_ffwd(req_ctx->src,
req->src,
> -                                                     lzeros);
> -               req_ctx->fixup_src_len = req->src_len - lzeros;
> -       } else {
> -               /*
> -                * input src is less then n key modulus,
> -                * so there will be zero padding
> -                */
> -               diff_size = key->n_sz - req->src_len;
> -               req_ctx->fixup_src = req->src;
> -               req_ctx->fixup_src_len = req->src_len;
> -       }
> -
> -       src_nents = sg_nents_for_len(req_ctx->fixup_src,
> -                                    req_ctx->fixup_src_len);
> -       dst_nents = sg_nents_for_len(req->dst, req->dst_len);
> -
> -       mapped_src_nents = dma_map_sg(dev, req_ctx->fixup_src, src_nents,
> -                                     DMA_TO_DEVICE);
> -       if (unlikely(!mapped_src_nents)) {
> -               dev_err(dev, "unable to map source\n");
> -               return ERR_PTR(-ENOMEM);
> -       }
> -       mapped_dst_nents = dma_map_sg(dev, req->dst, dst_nents,
> -                                     DMA_FROM_DEVICE);
> -       if (unlikely(!mapped_dst_nents)) {
> -               dev_err(dev, "unable to map destination\n");
> -               goto src_fail;
> -       }
> -
> -       if (!diff_size && mapped_src_nents == 1)
> -               sec4_sg_len = 0; /* no need for an input hw s/g table */
> -       else
> -               sec4_sg_len = mapped_src_nents + !!diff_size;
> -       sec4_sg_index = sec4_sg_len;
> -
> -       if (mapped_dst_nents > 1)
> -               sec4_sg_len += pad_sg_nents(mapped_dst_nents);
> -       else
> -               sec4_sg_len = pad_sg_nents(sec4_sg_len);
> -
> -       sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
> -
> -       /* allocate space for base edesc, hw desc commands and link tables
*/
> -       edesc = kzalloc(sizeof(*edesc) + desclen + sec4_sg_bytes, flags);
> -       if (!edesc)
> -               goto dst_fail;
> -
> -       edesc->sec4_sg = (void *)edesc + sizeof(*edesc) + desclen;
> -       if (diff_size)
> -               dma_to_sec4_sg_one(edesc->sec4_sg, ctx->padding_dma,
diff_size,
> -                                  0);
> -
> -       if (sec4_sg_index)
> -               sg_to_sec4_sg_last(req_ctx->fixup_src,
req_ctx->fixup_src_len,
> -                                  edesc->sec4_sg + !!diff_size, 0);
> -
> -       if (mapped_dst_nents > 1)
> -               sg_to_sec4_sg_last(req->dst, req->dst_len,
> -                                  edesc->sec4_sg + sec4_sg_index, 0);
> -
> -       /* Save nents for later use in Job Descriptor */
> -       edesc->src_nents = src_nents;
> -       edesc->dst_nents = dst_nents;
> -
> -       req_ctx->edesc = edesc;
> -
> -       if (!sec4_sg_bytes)
> -               return edesc;
> -
> -       edesc->mapped_src_nents = mapped_src_nents;
> -       edesc->mapped_dst_nents = mapped_dst_nents;
> -
> -       edesc->sec4_sg_dma = dma_map_single(dev, edesc->sec4_sg,
> -                                           sec4_sg_bytes, DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, edesc->sec4_sg_dma)) {
> -               dev_err(dev, "unable to map S/G table\n");
> -               goto sec4_sg_fail;
> -       }
> -
> -       edesc->sec4_sg_bytes = sec4_sg_bytes;
> -
> -       print_hex_dump_debug("caampkc sec4_sg@" __stringify(__LINE__) ":
",
> -                            DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
> -                            edesc->sec4_sg_bytes, 1);
> -
> -       return edesc;
> -
> -sec4_sg_fail:
> -       kfree(edesc);
> -dst_fail:
> -       dma_unmap_sg(dev, req->dst, dst_nents, DMA_FROM_DEVICE);
> -src_fail:
> -       dma_unmap_sg(dev, req_ctx->fixup_src, src_nents, DMA_TO_DEVICE);
> -       return ERR_PTR(-ENOMEM);
> -}
> -
> -static int akcipher_do_one_req(struct crypto_engine *engine, void *areq)
> -{
> -       struct akcipher_request *req = container_of(areq,
> -                                                   struct
akcipher_request,
> -                                                   base);
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct device *jrdev = ctx->dev;
> -       u32 *desc = req_ctx->edesc->hw_desc;
> -       int ret;
> -
> -       req_ctx->edesc->bklog = true;
> -
> -       ret = caam_jr_enqueue(jrdev, desc, req_ctx->akcipher_op_done,
req);
> -
> -       if (ret == -ENOSPC && engine->retry_support)
> -               return ret;
> -
> -       if (ret != -EINPROGRESS) {
> -               rsa_pub_unmap(jrdev, req_ctx->edesc, req);
> -               rsa_io_unmap(jrdev, req_ctx->edesc, req);
> -               kfree(req_ctx->edesc);
> -       } else {
> -               ret = 0;
> -       }
> -
> -       return ret;
> -}
> -
> -static int set_rsa_pub_pdb(struct akcipher_request *req,
> -                          struct rsa_edesc *edesc)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct device *dev = ctx->dev;
> -       struct rsa_pub_pdb *pdb = &edesc->pdb.pub;
> -       int sec4_sg_index = 0;
> -
> -       pdb->n_dma = dma_map_single(dev, key->n, key->n_sz,
DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->n_dma)) {
> -               dev_err(dev, "Unable to map RSA modulus memory\n");
> -               return -ENOMEM;
> -       }
> -
> -       pdb->e_dma = dma_map_single(dev, key->e, key->e_sz,
DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->e_dma)) {
> -               dev_err(dev, "Unable to map RSA public exponent
memory\n");
> -               dma_unmap_single(dev, pdb->n_dma, key->n_sz,
DMA_TO_DEVICE);
> -               return -ENOMEM;
> -       }
> -
> -       if (edesc->mapped_src_nents > 1) {
> -               pdb->sgf |= RSA_PDB_SGF_F;
> -               pdb->f_dma = edesc->sec4_sg_dma;
> -               sec4_sg_index += edesc->mapped_src_nents;
> -       } else {
> -               pdb->f_dma = sg_dma_address(req_ctx->fixup_src);
> -       }
> -
> -       if (edesc->mapped_dst_nents > 1) {
> -               pdb->sgf |= RSA_PDB_SGF_G;
> -               pdb->g_dma = edesc->sec4_sg_dma +
> -                            sec4_sg_index * sizeof(struct sec4_sg_entry);
> -       } else {
> -               pdb->g_dma = sg_dma_address(req->dst);
> -       }
> -
> -       pdb->sgf |= (key->e_sz << RSA_PDB_E_SHIFT) | key->n_sz;
> -       pdb->f_len = req_ctx->fixup_src_len;
> -
> -       return 0;
> -}
> -
> -static int set_rsa_priv_f1_pdb(struct akcipher_request *req,
> -                              struct rsa_edesc *edesc)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct device *dev = ctx->dev;
> -       struct rsa_priv_f1_pdb *pdb = &edesc->pdb.priv_f1;
> -       int sec4_sg_index = 0;
> -
> -       pdb->n_dma = dma_map_single(dev, key->n, key->n_sz,
DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->n_dma)) {
> -               dev_err(dev, "Unable to map modulus memory\n");
> -               return -ENOMEM;
> -       }
> -
> -       pdb->d_dma = dma_map_single(dev, key->d, key->d_sz,
DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->d_dma)) {
> -               dev_err(dev, "Unable to map RSA private exponent
memory\n");
> -               dma_unmap_single(dev, pdb->n_dma, key->n_sz,
DMA_TO_DEVICE);
> -               return -ENOMEM;
> -       }
> -
> -       if (edesc->mapped_src_nents > 1) {
> -               pdb->sgf |= RSA_PRIV_PDB_SGF_G;
> -               pdb->g_dma = edesc->sec4_sg_dma;
> -               sec4_sg_index += edesc->mapped_src_nents;
> -
> -       } else {
> -               struct caam_rsa_req_ctx *req_ctx =
akcipher_request_ctx(req);
> -
> -               pdb->g_dma = sg_dma_address(req_ctx->fixup_src);
> -       }
> -
> -       if (edesc->mapped_dst_nents > 1) {
> -               pdb->sgf |= RSA_PRIV_PDB_SGF_F;
> -               pdb->f_dma = edesc->sec4_sg_dma +
> -                            sec4_sg_index * sizeof(struct sec4_sg_entry);
> -       } else {
> -               pdb->f_dma = sg_dma_address(req->dst);
> -       }
> -
> -       pdb->sgf |= (key->d_sz << RSA_PDB_D_SHIFT) | key->n_sz;
> -
> -       return 0;
> -}
> -
> -static int set_rsa_priv_f2_pdb(struct akcipher_request *req,
> -                              struct rsa_edesc *edesc)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct device *dev = ctx->dev;
> -       struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2;
> -       int sec4_sg_index = 0;
> -       size_t p_sz = key->p_sz;
> -       size_t q_sz = key->q_sz;
> -
> -       pdb->d_dma = dma_map_single(dev, key->d, key->d_sz,
DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->d_dma)) {
> -               dev_err(dev, "Unable to map RSA private exponent
memory\n");
> -               return -ENOMEM;
> -       }
> -
> -       pdb->p_dma = dma_map_single(dev, key->p, p_sz, DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->p_dma)) {
> -               dev_err(dev, "Unable to map RSA prime factor p memory\n");
> -               goto unmap_d;
> -       }
> -
> -       pdb->q_dma = dma_map_single(dev, key->q, q_sz, DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->q_dma)) {
> -               dev_err(dev, "Unable to map RSA prime factor q memory\n");
> -               goto unmap_p;
> -       }
> -
> -       pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz,
> DMA_BIDIRECTIONAL);
> -       if (dma_mapping_error(dev, pdb->tmp1_dma)) {
> -               dev_err(dev, "Unable to map RSA tmp1 memory\n");
> -               goto unmap_q;
> -       }
> -
> -       pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz,
> DMA_BIDIRECTIONAL);
> -       if (dma_mapping_error(dev, pdb->tmp2_dma)) {
> -               dev_err(dev, "Unable to map RSA tmp2 memory\n");
> -               goto unmap_tmp1;
> -       }
> -
> -       if (edesc->mapped_src_nents > 1) {
> -               pdb->sgf |= RSA_PRIV_PDB_SGF_G;
> -               pdb->g_dma = edesc->sec4_sg_dma;
> -               sec4_sg_index += edesc->mapped_src_nents;
> -       } else {
> -               struct caam_rsa_req_ctx *req_ctx =
akcipher_request_ctx(req);
> -
> -               pdb->g_dma = sg_dma_address(req_ctx->fixup_src);
> -       }
> -
> -       if (edesc->mapped_dst_nents > 1) {
> -               pdb->sgf |= RSA_PRIV_PDB_SGF_F;
> -               pdb->f_dma = edesc->sec4_sg_dma +
> -                            sec4_sg_index * sizeof(struct sec4_sg_entry);
> -       } else {
> -               pdb->f_dma = sg_dma_address(req->dst);
> -       }
> -
> -       pdb->sgf |= (key->d_sz << RSA_PDB_D_SHIFT) | key->n_sz;
> -       pdb->p_q_len = (q_sz << RSA_PDB_Q_SHIFT) | p_sz;
> -
> -       return 0;
> -
> -unmap_tmp1:
> -       dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
> -unmap_q:
> -       dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
> -unmap_p:
> -       dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
> -unmap_d:
> -       dma_unmap_single(dev, pdb->d_dma, key->d_sz, DMA_TO_DEVICE);
> -
> -       return -ENOMEM;
> -}
> -
> -static int set_rsa_priv_f3_pdb(struct akcipher_request *req,
> -                              struct rsa_edesc *edesc)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct device *dev = ctx->dev;
> -       struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3;
> -       int sec4_sg_index = 0;
> -       size_t p_sz = key->p_sz;
> -       size_t q_sz = key->q_sz;
> -
> -       pdb->p_dma = dma_map_single(dev, key->p, p_sz, DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->p_dma)) {
> -               dev_err(dev, "Unable to map RSA prime factor p memory\n");
> -               return -ENOMEM;
> -       }
> -
> -       pdb->q_dma = dma_map_single(dev, key->q, q_sz, DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->q_dma)) {
> -               dev_err(dev, "Unable to map RSA prime factor q memory\n");
> -               goto unmap_p;
> -       }
> -
> -       pdb->dp_dma = dma_map_single(dev, key->dp, p_sz, DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->dp_dma)) {
> -               dev_err(dev, "Unable to map RSA exponent dp memory\n");
> -               goto unmap_q;
> -       }
> -
> -       pdb->dq_dma = dma_map_single(dev, key->dq, q_sz, DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->dq_dma)) {
> -               dev_err(dev, "Unable to map RSA exponent dq memory\n");
> -               goto unmap_dp;
> -       }
> -
> -       pdb->c_dma = dma_map_single(dev, key->qinv, p_sz, DMA_TO_DEVICE);
> -       if (dma_mapping_error(dev, pdb->c_dma)) {
> -               dev_err(dev, "Unable to map RSA CRT coefficient qinv
memory\n");
> -               goto unmap_dq;
> -       }
> -
> -       pdb->tmp1_dma = dma_map_single(dev, key->tmp1, p_sz,
> DMA_BIDIRECTIONAL);
> -       if (dma_mapping_error(dev, pdb->tmp1_dma)) {
> -               dev_err(dev, "Unable to map RSA tmp1 memory\n");
> -               goto unmap_qinv;
> -       }
> -
> -       pdb->tmp2_dma = dma_map_single(dev, key->tmp2, q_sz,
> DMA_BIDIRECTIONAL);
> -       if (dma_mapping_error(dev, pdb->tmp2_dma)) {
> -               dev_err(dev, "Unable to map RSA tmp2 memory\n");
> -               goto unmap_tmp1;
> -       }
> -
> -       if (edesc->mapped_src_nents > 1) {
> -               pdb->sgf |= RSA_PRIV_PDB_SGF_G;
> -               pdb->g_dma = edesc->sec4_sg_dma;
> -               sec4_sg_index += edesc->mapped_src_nents;
> -       } else {
> -               struct caam_rsa_req_ctx *req_ctx =
akcipher_request_ctx(req);
> -
> -               pdb->g_dma = sg_dma_address(req_ctx->fixup_src);
> -       }
> -
> -       if (edesc->mapped_dst_nents > 1) {
> -               pdb->sgf |= RSA_PRIV_PDB_SGF_F;
> -               pdb->f_dma = edesc->sec4_sg_dma +
> -                            sec4_sg_index * sizeof(struct sec4_sg_entry);
> -       } else {
> -               pdb->f_dma = sg_dma_address(req->dst);
> -       }
> -
> -       pdb->sgf |= key->n_sz;
> -       pdb->p_q_len = (q_sz << RSA_PDB_Q_SHIFT) | p_sz;
> -
> -       return 0;
> -
> -unmap_tmp1:
> -       dma_unmap_single(dev, pdb->tmp1_dma, p_sz, DMA_BIDIRECTIONAL);
> -unmap_qinv:
> -       dma_unmap_single(dev, pdb->c_dma, p_sz, DMA_TO_DEVICE);
> -unmap_dq:
> -       dma_unmap_single(dev, pdb->dq_dma, q_sz, DMA_TO_DEVICE);
> -unmap_dp:
> -       dma_unmap_single(dev, pdb->dp_dma, p_sz, DMA_TO_DEVICE);
> -unmap_q:
> -       dma_unmap_single(dev, pdb->q_dma, q_sz, DMA_TO_DEVICE);
> -unmap_p:
> -       dma_unmap_single(dev, pdb->p_dma, p_sz, DMA_TO_DEVICE);
> -
> -       return -ENOMEM;
> -}
> -
> -static int akcipher_enqueue_req(struct device *jrdev,
> -                               void (*cbk)(struct device *jrdev, u32
*desc,
> -                                           u32 err, void *context),
> -                               struct akcipher_request *req)
> -{
> -       struct caam_drv_private_jr *jrpriv = dev_get_drvdata(jrdev);
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
> -       struct rsa_edesc *edesc = req_ctx->edesc;
> -       u32 *desc = edesc->hw_desc;
> -       int ret;
> -
> -       req_ctx->akcipher_op_done = cbk;
> -       /*
> -        * Only the backlog request are sent to crypto-engine since the
others
> -        * can be handled by CAAM, if free, especially since JR has up to
1024
> -        * entries (more than the 10 entries from crypto-engine).
> -        */
> -       if (req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)
> -               ret =
crypto_transfer_akcipher_request_to_engine(jrpriv->engine,
> -                                                                req);
> -       else
> -               ret = caam_jr_enqueue(jrdev, desc, cbk, req);
> -
> -       if ((ret != -EINPROGRESS) && (ret != -EBUSY)) {
> -               switch (key->priv_form) {
> -               case FORM1:
> -                       rsa_priv_f1_unmap(jrdev, edesc, req);
> -                       break;
> -               case FORM2:
> -                       rsa_priv_f2_unmap(jrdev, edesc, req);
> -                       break;
> -               case FORM3:
> -                       rsa_priv_f3_unmap(jrdev, edesc, req);
> -                       break;
> -               default:
> -                       rsa_pub_unmap(jrdev, edesc, req);
> -               }
> -               rsa_io_unmap(jrdev, edesc, req);
> -               kfree(edesc);
> -       }
> -
> -       return ret;
> -}
> -
> -static int caam_rsa_enc(struct akcipher_request *req)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       struct device *jrdev = ctx->dev;
> -       struct rsa_edesc *edesc;
> -       int ret;
> -
> -       if (unlikely(!key->n || !key->e))
> -               return -EINVAL;
> -
> -       if (req->dst_len < key->n_sz) {
> -               req->dst_len = key->n_sz;
> -               dev_err(jrdev, "Output buffer length less than parameter
n\n");
> -               return -EOVERFLOW;
> -       }
> -
> -       /* Allocate extended descriptor */
> -       edesc = rsa_edesc_alloc(req, DESC_RSA_PUB_LEN);
> -       if (IS_ERR(edesc))
> -               return PTR_ERR(edesc);
> -
> -       /* Set RSA Encrypt Protocol Data Block */
> -       ret = set_rsa_pub_pdb(req, edesc);
> -       if (ret)
> -               goto init_fail;
> -
> -       /* Initialize Job Descriptor */
> -       init_rsa_pub_desc(edesc->hw_desc, &edesc->pdb.pub);
> -
> -       return akcipher_enqueue_req(jrdev, rsa_pub_done, req);
> -
> -init_fail:
> -       rsa_io_unmap(jrdev, edesc, req);
> -       kfree(edesc);
> -       return ret;
> -}
> -
> -static int caam_rsa_dec_priv_f1(struct akcipher_request *req)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct device *jrdev = ctx->dev;
> -       struct rsa_edesc *edesc;
> -       int ret;
> -
> -       /* Allocate extended descriptor */
> -       edesc = rsa_edesc_alloc(req, DESC_RSA_PRIV_F1_LEN);
> -       if (IS_ERR(edesc))
> -               return PTR_ERR(edesc);
> -
> -       /* Set RSA Decrypt Protocol Data Block - Private Key Form #1 */
> -       ret = set_rsa_priv_f1_pdb(req, edesc);
> -       if (ret)
> -               goto init_fail;
> -
> -       /* Initialize Job Descriptor */
> -       init_rsa_priv_f1_desc(edesc->hw_desc, &edesc->pdb.priv_f1);
> -
> -       return akcipher_enqueue_req(jrdev, rsa_priv_f_done, req);
> -
> -init_fail:
> -       rsa_io_unmap(jrdev, edesc, req);
> -       kfree(edesc);
> -       return ret;
> -}
> -
> -static int caam_rsa_dec_priv_f2(struct akcipher_request *req)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct device *jrdev = ctx->dev;
> -       struct rsa_edesc *edesc;
> -       int ret;
> -
> -       /* Allocate extended descriptor */
> -       edesc = rsa_edesc_alloc(req, DESC_RSA_PRIV_F2_LEN);
> -       if (IS_ERR(edesc))
> -               return PTR_ERR(edesc);
> -
> -       /* Set RSA Decrypt Protocol Data Block - Private Key Form #2 */
> -       ret = set_rsa_priv_f2_pdb(req, edesc);
> -       if (ret)
> -               goto init_fail;
> -
> -       /* Initialize Job Descriptor */
> -       init_rsa_priv_f2_desc(edesc->hw_desc, &edesc->pdb.priv_f2);
> -
> -       return akcipher_enqueue_req(jrdev, rsa_priv_f_done, req);
> -
> -init_fail:
> -       rsa_io_unmap(jrdev, edesc, req);
> -       kfree(edesc);
> -       return ret;
> -}
> -
> -static int caam_rsa_dec_priv_f3(struct akcipher_request *req)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct device *jrdev = ctx->dev;
> -       struct rsa_edesc *edesc;
> -       int ret;
> -
> -       /* Allocate extended descriptor */
> -       edesc = rsa_edesc_alloc(req, DESC_RSA_PRIV_F3_LEN);
> -       if (IS_ERR(edesc))
> -               return PTR_ERR(edesc);
> -
> -       /* Set RSA Decrypt Protocol Data Block - Private Key Form #3 */
> -       ret = set_rsa_priv_f3_pdb(req, edesc);
> -       if (ret)
> -               goto init_fail;
> -
> -       /* Initialize Job Descriptor */
> -       init_rsa_priv_f3_desc(edesc->hw_desc, &edesc->pdb.priv_f3);
> -
> -       return akcipher_enqueue_req(jrdev, rsa_priv_f_done, req);
> -
> -init_fail:
> -       rsa_io_unmap(jrdev, edesc, req);
> -       kfree(edesc);
> -       return ret;
> -}
> -
> -static int caam_rsa_dec(struct akcipher_request *req)
> -{
> -       struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -       int ret;
> -
> -       if (unlikely(!key->n || !key->d))
> -               return -EINVAL;
> -
> -       if (req->dst_len < key->n_sz) {
> -               req->dst_len = key->n_sz;
> -               dev_err(ctx->dev, "Output buffer length less than
parameter n\n");
> -               return -EOVERFLOW;
> -       }
> -
> -       if (key->priv_form == FORM3)
> -               ret = caam_rsa_dec_priv_f3(req);
> -       else if (key->priv_form == FORM2)
> -               ret = caam_rsa_dec_priv_f2(req);
> -       else
> -               ret = caam_rsa_dec_priv_f1(req);
> -
> -       return ret;
> -}
> -
> -static void caam_rsa_free_key(struct caam_rsa_key *key)
> -{
> -       kfree_sensitive(key->d);
> -       kfree_sensitive(key->p);
> -       kfree_sensitive(key->q);
> -       kfree_sensitive(key->dp);
> -       kfree_sensitive(key->dq);
> -       kfree_sensitive(key->qinv);
> -       kfree_sensitive(key->tmp1);
> -       kfree_sensitive(key->tmp2);
> -       kfree(key->e);
> -       kfree(key->n);
> -       memset(key, 0, sizeof(*key));
> -}
> -
> -static void caam_rsa_drop_leading_zeros(const u8 **ptr, size_t *nbytes)
> -{
> -       while (!**ptr && *nbytes) {
> -               (*ptr)++;
> -               (*nbytes)--;
> -       }
> -}
> -
> -/**
> - * caam_read_rsa_crt - Used for reading dP, dQ, qInv CRT members.
> - * dP, dQ and qInv could decode to less than corresponding p, q length,
as the
> - * BER-encoding requires that the minimum number of bytes be used to
encode
> the
> - * integer. dP, dQ, qInv decoded values have to be zero-padded to
appropriate
> - * length.
> - *
> - * @ptr   : pointer to {dP, dQ, qInv} CRT member
> - * @nbytes: length in bytes of {dP, dQ, qInv} CRT member
> - * @dstlen: length in bytes of corresponding p or q prime factor
> - */
> -static u8 *caam_read_rsa_crt(const u8 *ptr, size_t nbytes, size_t dstlen)
> -{
> -       u8 *dst;
> -
> -       caam_rsa_drop_leading_zeros(&ptr, &nbytes);
> -       if (!nbytes)
> -               return NULL;
> -
> -       dst = kzalloc(dstlen, GFP_KERNEL);
> -       if (!dst)
> -               return NULL;
> -
> -       memcpy(dst + (dstlen - nbytes), ptr, nbytes);
> -
> -       return dst;
> -}
> -
> -/**
> - * caam_read_raw_data - Read a raw byte stream as a positive integer.
> - * The function skips buffer's leading zeros, copies the remained data
> - * to a buffer allocated in the GFP_KERNEL zone and returns
> - * the address of the new buffer.
> - *
> - * @buf   : The data to read
> - * @nbytes: The amount of data to read
> - */
> -static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes)
> -{
> -
> -       caam_rsa_drop_leading_zeros(&buf, nbytes);
> -       if (!*nbytes)
> -               return NULL;
> -
> -       return kmemdup(buf, *nbytes, GFP_KERNEL);
> -}
> -
> -static int caam_rsa_check_key_length(unsigned int len)
> -{
> -       if (len > 4096)
> -               return -EINVAL;
> -       return 0;
> -}
> -
> -static int caam_rsa_set_pub_key(struct crypto_akcipher *tfm, const void
*key,
> -                               unsigned int keylen)
> -{
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct rsa_key raw_key = {NULL};
> -       struct caam_rsa_key *rsa_key = &ctx->key;
> -       int ret;
> -
> -       /* Free the old RSA key if any */
> -       caam_rsa_free_key(rsa_key);
> -
> -       ret = rsa_parse_pub_key(&raw_key, key, keylen);
> -       if (ret)
> -               return ret;
> -
> -       /* Copy key in DMA zone */
> -       rsa_key->e = kmemdup(raw_key.e, raw_key.e_sz, GFP_KERNEL);
> -       if (!rsa_key->e)
> -               goto err;
> -
> -       /*
> -        * Skip leading zeros and copy the positive integer to a buffer
> -        * allocated in the GFP_KERNEL zone. The decryption descriptor
> -        * expects a positive integer for the RSA modulus and uses its
length as
> -        * decryption output length.
> -        */
> -       rsa_key->n = caam_read_raw_data(raw_key.n, &raw_key.n_sz);
> -       if (!rsa_key->n)
> -               goto err;
> -
> -       if (caam_rsa_check_key_length(raw_key.n_sz << 3)) {
> -               caam_rsa_free_key(rsa_key);
> -               return -EINVAL;
> -       }
> -
> -       rsa_key->e_sz = raw_key.e_sz;
> -       rsa_key->n_sz = raw_key.n_sz;
> -
> -       return 0;
> -err:
> -       caam_rsa_free_key(rsa_key);
> -       return -ENOMEM;
> -}
> -
> -static int caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
> -                                      struct rsa_key *raw_key)
> -{
> -       struct caam_rsa_key *rsa_key = &ctx->key;
> -       size_t p_sz = raw_key->p_sz;
> -       size_t q_sz = raw_key->q_sz;
> -       unsigned aligned_size;
> -
> -       rsa_key->p = caam_read_raw_data(raw_key->p, &p_sz);
> -       if (!rsa_key->p)
> -               return -ENOMEM;
> -       rsa_key->p_sz = p_sz;
> -
> -       rsa_key->q = caam_read_raw_data(raw_key->q, &q_sz);
> -       if (!rsa_key->q)
> -               goto free_p;
> -       rsa_key->q_sz = q_sz;
> -
> -       aligned_size = ALIGN(raw_key->p_sz, dma_get_cache_alignment());
> -       rsa_key->tmp1 = kzalloc(aligned_size, GFP_KERNEL);
> -       if (!rsa_key->tmp1)
> -               goto free_q;
> -
> -       aligned_size = ALIGN(raw_key->q_sz, dma_get_cache_alignment());
> -       rsa_key->tmp2 = kzalloc(aligned_size, GFP_KERNEL);
> -       if (!rsa_key->tmp2)
> -               goto free_tmp1;
> -
> -       rsa_key->priv_form = FORM2;
> -
> -       rsa_key->dp = caam_read_rsa_crt(raw_key->dp, raw_key->dp_sz,
p_sz);
> -       if (!rsa_key->dp)
> -               goto free_tmp2;
> -
> -       rsa_key->dq = caam_read_rsa_crt(raw_key->dq, raw_key->dq_sz,
q_sz);
> -       if (!rsa_key->dq)
> -               goto free_dp;
> -
> -       rsa_key->qinv = caam_read_rsa_crt(raw_key->qinv, raw_key->qinv_sz,
> -                                         q_sz);
> -       if (!rsa_key->qinv)
> -               goto free_dq;
> -
> -       rsa_key->priv_form = FORM3;
> -
> -       return 0;
> -
> -free_dq:
> -       kfree_sensitive(rsa_key->dq);
> -free_dp:
> -       kfree_sensitive(rsa_key->dp);
> -free_tmp2:
> -       kfree_sensitive(rsa_key->tmp2);
> -free_tmp1:
> -       kfree_sensitive(rsa_key->tmp1);
> -free_q:
> -       kfree_sensitive(rsa_key->q);
> -free_p:
> -       kfree_sensitive(rsa_key->p);
> -       return -ENOMEM;
> -}
> -
> -static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void
*key,
> -                                unsigned int keylen)
> -{
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct rsa_key raw_key = {NULL};
> -       struct caam_rsa_key *rsa_key = &ctx->key;
> -       int ret;
> -
> -       /* Free the old RSA key if any */
> -       caam_rsa_free_key(rsa_key);
> -
> -       ret = rsa_parse_priv_key(&raw_key, key, keylen);
> -       if (ret)
> -               return ret;
> -
> -       /* Copy key in DMA zone */
> -       rsa_key->d = kmemdup(raw_key.d, raw_key.d_sz, GFP_KERNEL);
> -       if (!rsa_key->d)
> -               goto err;
> -
> -       rsa_key->e = kmemdup(raw_key.e, raw_key.e_sz, GFP_KERNEL);
> -       if (!rsa_key->e)
> -               goto err;
> -
> -       /*
> -        * Skip leading zeros and copy the positive integer to a buffer
> -        * allocated in the GFP_KERNEL zone. The decryption descriptor
> -        * expects a positive integer for the RSA modulus and uses its
length as
> -        * decryption output length.
> -        */
> -       rsa_key->n = caam_read_raw_data(raw_key.n, &raw_key.n_sz);
> -       if (!rsa_key->n)
> -               goto err;
> -
> -       if (caam_rsa_check_key_length(raw_key.n_sz << 3)) {
> -               caam_rsa_free_key(rsa_key);
> -               return -EINVAL;
> -       }
> -
> -       rsa_key->d_sz = raw_key.d_sz;
> -       rsa_key->e_sz = raw_key.e_sz;
> -       rsa_key->n_sz = raw_key.n_sz;
> -
> -       ret = caam_rsa_set_priv_key_form(ctx, &raw_key);
> -       if (ret)
> -               goto err;
> -
> -       return 0;
> -
> -err:
> -       caam_rsa_free_key(rsa_key);
> -       return -ENOMEM;
> -}
> -
> -static unsigned int caam_rsa_max_size(struct crypto_akcipher *tfm)
> -{
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -
> -       return ctx->key.n_sz;
> -}
> -
> -/* Per session pkc's driver context creation function */
> -static int caam_rsa_init_tfm(struct crypto_akcipher *tfm)
> -{
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -
> -       akcipher_set_reqsize(tfm, sizeof(struct caam_rsa_req_ctx));
> -
> -       ctx->dev = caam_jr_alloc();
> -
> -       if (IS_ERR(ctx->dev)) {
> -               pr_err("Job Ring Device allocation for transform
failed\n");
> -               return PTR_ERR(ctx->dev);
> -       }
> -
> -       ctx->padding_dma = dma_map_single(ctx->dev, zero_buffer,
> -                                         CAAM_RSA_MAX_INPUT_SIZE - 1,
> -                                         DMA_TO_DEVICE);
> -       if (dma_mapping_error(ctx->dev, ctx->padding_dma)) {
> -               dev_err(ctx->dev, "unable to map padding\n");
> -               caam_jr_free(ctx->dev);
> -               return -ENOMEM;
> -       }
> -
> -       return 0;
> -}
> -
> -/* Per session pkc's driver context cleanup function */
> -static void caam_rsa_exit_tfm(struct crypto_akcipher *tfm)
> -{
> -       struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
> -       struct caam_rsa_key *key = &ctx->key;
> -
> -       dma_unmap_single(ctx->dev, ctx->padding_dma,
> CAAM_RSA_MAX_INPUT_SIZE -
> -                        1, DMA_TO_DEVICE);
> -       caam_rsa_free_key(key);
> -       caam_jr_free(ctx->dev);
> -}
> -
> -static struct caam_akcipher_alg caam_rsa = {
> -       .akcipher.base = {
> -               .encrypt = caam_rsa_enc,
> -               .decrypt = caam_rsa_dec,
> -               .set_pub_key = caam_rsa_set_pub_key,
> -               .set_priv_key = caam_rsa_set_priv_key,
> -               .max_size = caam_rsa_max_size,
> -               .init = caam_rsa_init_tfm,
> -               .exit = caam_rsa_exit_tfm,
> -               .base = {
> -                       .cra_name = "rsa",
> -                       .cra_driver_name = "rsa-caam",
> -                       .cra_priority = 3000,
> -                       .cra_module = THIS_MODULE,
> -                       .cra_ctxsize = sizeof(struct caam_rsa_ctx) +
> -                                      CRYPTO_DMA_PADDING,
> -               },
> -       },
> -       .akcipher.op = {
> -               .do_one_request = akcipher_do_one_req,
> -       },
> -};
> -
> -/* Public Key Cryptography module initialization handler */
> -int caam_pkc_init(struct device *ctrldev)
> -{
> -       struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
> -       u32 pk_inst, pkha;
> -       int err;
> -       init_done = false;
> -
> -       /* Determine public key hardware accelerator presence. */
> -       if (priv->era < 10) {
> -               pk_inst = (rd_reg32(&priv->jr[0]->perfmon.cha_num_ls) &
> -                          CHA_ID_LS_PK_MASK) >> CHA_ID_LS_PK_SHIFT;
> -       } else {
> -               pkha = rd_reg32(&priv->jr[0]->vreg.pkha);
> -               pk_inst = pkha & CHA_VER_NUM_MASK;
> -
> -               /*
> -                * Newer CAAMs support partially disabled functionality.
If this is the
> -                * case, the number is non-zero, but this bit is set to
indicate that
> -                * no encryption or decryption is supported. Only signing
and
> verifying
> -                * is supported.
> -                */
> -               if (pkha & CHA_VER_MISC_PKHA_NO_CRYPT)
> -                       pk_inst = 0;
> -       }
> -
> -       /* Do not register algorithms if PKHA is not present. */
> -       if (!pk_inst)
> -               return 0;
> -
> -       /* allocate zero buffer, used for padding input */
> -       zero_buffer = kzalloc(CAAM_RSA_MAX_INPUT_SIZE - 1, GFP_KERNEL);
> -       if (!zero_buffer)
> -               return -ENOMEM;
> -
> -       err = crypto_engine_register_akcipher(&caam_rsa.akcipher);
> -
> -       if (err) {
> -               kfree(zero_buffer);
> -               dev_warn(ctrldev, "%s alg registration failed\n",
> -                        caam_rsa.akcipher.base.base.cra_driver_name);
> -       } else {
> -               init_done = true;
> -               caam_rsa.registered = true;
> -               dev_info(ctrldev, "caam pkc algorithms registered in
/proc/crypto\n");
> -       }
> -
> -       return err;
> -}
> -
> -void caam_pkc_exit(void)
> -{
> -       if (!init_done)
> -               return;
> -
> -       if (caam_rsa.registered)
> -               crypto_engine_unregister_akcipher(&caam_rsa.akcipher);
> -
> -       kfree(zero_buffer);
> -}
> diff --git a/drivers/crypto/caam/caampkc.h b/drivers/crypto/caam/caampkc.h
> deleted file mode 100644
> index 96d03704c9be..000000000000
> --- a/drivers/crypto/caam/caampkc.h
> +++ /dev/null
> @@ -1,155 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -/*
> - * caam - Freescale FSL CAAM support for Public Key Cryptography
descriptors
> - *
> - * Copyright 2016 Freescale Semiconductor, Inc.
> - *
> - * There is no Shared Descriptor for PKC so that the Job Descriptor must
carry
> - * all the desired key parameters, input and output pointers.
> - */
> -
> -#ifndef _PKC_DESC_H_
> -#define _PKC_DESC_H_
> -#include "compat.h"
> -#include "pdb.h"
> -
> -/**
> - * caam_priv_key_form - CAAM RSA private key representation
> - * CAAM RSA private key may have either of three forms.
> - *
> - * 1. The first representation consists of the pair (n, d), where the
> - *    components have the following meanings:
> - *        n      the RSA modulus
> - *        d      the RSA private exponent
> - *
> - * 2. The second representation consists of the triplet (p, q, d), where
the
> - *    components have the following meanings:
> - *        p      the first prime factor of the RSA modulus n
> - *        q      the second prime factor of the RSA modulus n
> - *        d      the RSA private exponent
> - *
> - * 3. The third representation consists of the quintuple (p, q, dP, dQ,
qInv),
> - *    where the components have the following meanings:
> - *        p      the first prime factor of the RSA modulus n
> - *        q      the second prime factor of the RSA modulus n
> - *        dP     the first factors's CRT exponent
> - *        dQ     the second factors's CRT exponent
> - *        qInv   the (first) CRT coefficient
> - *
> - * The benefit of using the third or the second key form is lower
computational
> - * cost for the decryption and signature operations.
> - */
> -enum caam_priv_key_form {
> -       FORM1,
> -       FORM2,
> -       FORM3
> -};
> -
> -/**
> - * caam_rsa_key - CAAM RSA key structure. Keys are allocated in DMA zone.
> - * @n           : RSA modulus raw byte stream
> - * @e           : RSA public exponent raw byte stream
> - * @d           : RSA private exponent raw byte stream
> - * @p           : RSA prime factor p of RSA modulus n
> - * @q           : RSA prime factor q of RSA modulus n
> - * @dp          : RSA CRT exponent of p
> - * @dp          : RSA CRT exponent of q
> - * @qinv        : RSA CRT coefficient
> - * @tmp1        : CAAM uses this temporary buffer as internal state
buffer.
> - *                It is assumed to be as long as p.
> - * @tmp2        : CAAM uses this temporary buffer as internal state
buffer.
> - *                It is assumed to be as long as q.
> - * @n_sz        : length in bytes of RSA modulus n
> - * @e_sz        : length in bytes of RSA public exponent
> - * @d_sz        : length in bytes of RSA private exponent
> - * @p_sz        : length in bytes of RSA prime factor p of RSA modulus n
> - * @q_sz        : length in bytes of RSA prime factor q of RSA modulus n
> - * @priv_form   : CAAM RSA private key representation
> - */
> -struct caam_rsa_key {
> -       u8 *n;
> -       u8 *e;
> -       u8 *d;
> -       u8 *p;
> -       u8 *q;
> -       u8 *dp;
> -       u8 *dq;
> -       u8 *qinv;
> -       u8 *tmp1;
> -       u8 *tmp2;
> -       size_t n_sz;
> -       size_t e_sz;
> -       size_t d_sz;
> -       size_t p_sz;
> -       size_t q_sz;
> -       enum caam_priv_key_form priv_form;
> -};
> -
> -/**
> - * caam_rsa_ctx - per session context.
> - * @key         : RSA key in DMA zone
> - * @dev         : device structure
> - * @padding_dma : dma address of padding, for adding it to the input
> - */
> -struct caam_rsa_ctx {
> -       struct caam_rsa_key key;
> -       struct device *dev;
> -       dma_addr_t padding_dma;
> -
> -};
> -
> -/**
> - * caam_rsa_req_ctx - per request context.
> - * @src           : input scatterlist (stripped of leading zeros)
> - * @fixup_src     : input scatterlist (that might be stripped of leading
zeros)
> - * @fixup_src_len : length of the fixup_src input scatterlist
> - * @edesc         : s/w-extended rsa descriptor
> - * @akcipher_op_done : callback used when operation is done
> - */
> -struct caam_rsa_req_ctx {
> -       struct scatterlist src[2];
> -       struct scatterlist *fixup_src;
> -       unsigned int fixup_src_len;
> -       struct rsa_edesc *edesc;
> -       void (*akcipher_op_done)(struct device *jrdev, u32 *desc, u32 err,
> -                                void *context);
> -};
> -
> -/**
> - * rsa_edesc - s/w-extended rsa descriptor
> - * @src_nents     : number of segments in input s/w scatterlist
> - * @dst_nents     : number of segments in output s/w scatterlist
> - * @mapped_src_nents: number of segments in input h/w link table
> - * @mapped_dst_nents: number of segments in output h/w link table
> - * @sec4_sg_bytes : length of h/w link table
> - * @bklog         : stored to determine if the request needs backlog
> - * @sec4_sg_dma   : dma address of h/w link table
> - * @sec4_sg       : pointer to h/w link table
> - * @pdb           : specific RSA Protocol Data Block (PDB)
> - * @hw_desc       : descriptor followed by link tables if any
> - */
> -struct rsa_edesc {
> -       int src_nents;
> -       int dst_nents;
> -       int mapped_src_nents;
> -       int mapped_dst_nents;
> -       int sec4_sg_bytes;
> -       bool bklog;
> -       dma_addr_t sec4_sg_dma;
> -       struct sec4_sg_entry *sec4_sg;
> -       union {
> -               struct rsa_pub_pdb pub;
> -               struct rsa_priv_f1_pdb priv_f1;
> -               struct rsa_priv_f2_pdb priv_f2;
> -               struct rsa_priv_f3_pdb priv_f3;
> -       } pdb;
> -       u32 hw_desc[];
> -};
> -
> -/* Descriptor construction primitives. */
> -void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb);
> -void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb);
> -void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb);
> -void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb);
> -
> -#endif
> diff --git a/drivers/crypto/caam/pkc_desc.c
b/drivers/crypto/caam/pkc_desc.c
> deleted file mode 100644
> index 0d5ee762e036..000000000000
> --- a/drivers/crypto/caam/pkc_desc.c
> +++ /dev/null
> @@ -1,73 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -/*
> - * caam - Freescale FSL CAAM support for Public Key Cryptography
descriptors
> - *
> - * Copyright 2016 Freescale Semiconductor, Inc.
> - *
> - * There is no Shared Descriptor for PKC so that the Job Descriptor must
carry
> - * all the desired key parameters, input and output pointers.
> - */
> -#include "caampkc.h"
> -#include "desc_constr.h"
> -
> -/* Descriptor for RSA Public operation */
> -void init_rsa_pub_desc(u32 *desc, struct rsa_pub_pdb *pdb)
> -{
> -       init_job_desc_pdb(desc, 0, SIZEOF_RSA_PUB_PDB);
> -       append_cmd(desc, pdb->sgf);
> -       append_ptr(desc, pdb->f_dma);
> -       append_ptr(desc, pdb->g_dma);
> -       append_ptr(desc, pdb->n_dma);
> -       append_ptr(desc, pdb->e_dma);
> -       append_cmd(desc, pdb->f_len);
> -       append_operation(desc, OP_TYPE_UNI_PROTOCOL |
> OP_PCLID_RSAENC_PUBKEY);
> -}
> -
> -/* Descriptor for RSA Private operation - Private Key Form #1 */
> -void init_rsa_priv_f1_desc(u32 *desc, struct rsa_priv_f1_pdb *pdb)
> -{
> -       init_job_desc_pdb(desc, 0, SIZEOF_RSA_PRIV_F1_PDB);
> -       append_cmd(desc, pdb->sgf);
> -       append_ptr(desc, pdb->g_dma);
> -       append_ptr(desc, pdb->f_dma);
> -       append_ptr(desc, pdb->n_dma);
> -       append_ptr(desc, pdb->d_dma);
> -       append_operation(desc, OP_TYPE_UNI_PROTOCOL |
> OP_PCLID_RSADEC_PRVKEY |
> -                        RSA_PRIV_KEY_FRM_1);
> -}
> -
> -/* Descriptor for RSA Private operation - Private Key Form #2 */
> -void init_rsa_priv_f2_desc(u32 *desc, struct rsa_priv_f2_pdb *pdb)
> -{
> -       init_job_desc_pdb(desc, 0, SIZEOF_RSA_PRIV_F2_PDB);
> -       append_cmd(desc, pdb->sgf);
> -       append_ptr(desc, pdb->g_dma);
> -       append_ptr(desc, pdb->f_dma);
> -       append_ptr(desc, pdb->d_dma);
> -       append_ptr(desc, pdb->p_dma);
> -       append_ptr(desc, pdb->q_dma);
> -       append_ptr(desc, pdb->tmp1_dma);
> -       append_ptr(desc, pdb->tmp2_dma);
> -       append_cmd(desc, pdb->p_q_len);
> -       append_operation(desc, OP_TYPE_UNI_PROTOCOL |
> OP_PCLID_RSADEC_PRVKEY |
> -                        RSA_PRIV_KEY_FRM_2);
> -}
> -
> -/* Descriptor for RSA Private operation - Private Key Form #3 */
> -void init_rsa_priv_f3_desc(u32 *desc, struct rsa_priv_f3_pdb *pdb)
> -{
> -       init_job_desc_pdb(desc, 0, SIZEOF_RSA_PRIV_F3_PDB);
> -       append_cmd(desc, pdb->sgf);
> -       append_ptr(desc, pdb->g_dma);
> -       append_ptr(desc, pdb->f_dma);
> -       append_ptr(desc, pdb->c_dma);
> -       append_ptr(desc, pdb->p_dma);
> -       append_ptr(desc, pdb->q_dma);
> -       append_ptr(desc, pdb->dp_dma);
> -       append_ptr(desc, pdb->dq_dma);
> -       append_ptr(desc, pdb->tmp1_dma);
> -       append_ptr(desc, pdb->tmp2_dma);
> -       append_cmd(desc, pdb->p_q_len);
> -       append_operation(desc, OP_TYPE_UNI_PROTOCOL |
> OP_PCLID_RSADEC_PRVKEY |
> -                        RSA_PRIV_KEY_FRM_3);
> -}
> diff --git a/drivers/crypto/caam/Kconfig b/drivers/crypto/caam/Kconfig
> index ec57bf6aaf6c..94f19126f61b 100644
> --- a/drivers/crypto/caam/Kconfig
> +++ b/drivers/crypto/caam/Kconfig
> @@ -133,15 +133,6 @@ config CRYPTO_DEV_FSL_CAAM_AHASH_API
>           Selecting this will offload ahash for users of the
>           scatterlist crypto API to the SEC4 via job ring.
> 
> -config CRYPTO_DEV_FSL_CAAM_PKC_API
> -       bool "Register public key cryptography implementations with Crypto
API"
> -       default y
> -       select CRYPTO_RSA
> -       help
> -         Selecting this will allow SEC Public key support for RSA.
> -         Supported cryptographic primitives: encryption, decryption,
> -         signature and verification.
> -
>  config CRYPTO_DEV_FSL_CAAM_RNG_API
>         bool "Register caam device for hwrng API"
>         default y
> diff --git a/drivers/crypto/caam/Makefile b/drivers/crypto/caam/Makefile
> index a17e3cf14c61..87a82474b841 100644
> --- a/drivers/crypto/caam/Makefile
> +++ b/drivers/crypto/caam/Makefile
> @@ -20,7 +20,6 @@ caam_jr-
> $(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API) += caamalg.o
>  caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += caamalg_qi.o
>  caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
>  caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
> -caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caampkc.o
> pkc_desc.o
>  caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_BLOB_GEN) += blob_gen.o
> 
>  caam-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += qi.o
> diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h
> index 6e48bf7d6054..744b6586171c 100644
> --- a/drivers/crypto/caam/intern.h
> +++ b/drivers/crypto/caam/intern.h
> @@ -178,24 +178,6 @@ static inline void caam_algapi_hash_exit(void)
> 
>  #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API */
> 
> -#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API
> -
> -int caam_pkc_init(struct device *dev);
> -void caam_pkc_exit(void);
> -
> -#else
> -
> -static inline int caam_pkc_init(struct device *dev)
> -{
> -       return 0;
> -}
> -
> -static inline void caam_pkc_exit(void)
> -{
> -}
> -
> -#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API */
> -
>  #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API
> 
>  int caam_rng_init(struct device *dev);
> diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
> index 239469f6882e..2c1e8275ddaf 100644
> --- a/drivers/crypto/caam/jr.c
> +++ b/drivers/crypto/caam/jr.c
> @@ -38,7 +38,6 @@ static void register_algs(struct caam_drv_private_jr
> *jrpriv,
> 
>         caam_algapi_init(dev);
>         caam_algapi_hash_init(dev);
> -       caam_pkc_init(dev);
>         jrpriv->hwrng = !caam_rng_init(dev);
>         caam_qi_algapi_init(dev);
> 
> @@ -54,7 +53,6 @@ static void unregister_algs(void)
>                 goto algs_unlock;
> 
>         caam_qi_algapi_exit();
> -       caam_pkc_exit();
>         caam_algapi_hash_exit();
>         caam_algapi_exit();
> 
> --
> Email: Herbert Xu <herbert@gondor.apana.org.au>
> Home Page:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fgondor.ap
> ana.org.au%2F~herbert%2F&data=05%7C02%7Cv.sethi%40nxp.com%7C33199c
> 44b5f145e8981a08df0a48d61a%7C686ea1d3bc2b4c6fa92cd99c5c301635%7
> C0%7C0%7C639240980112891619%7CUnknown%7CTWFpbGZsb3d8eyJFbXB
> 0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbC
> IsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=JF5DELvKDNeBeGHPR%2F3VjQa
> qZgMoz4yDcO5rC%2BWHqEU%3D&reserved=0
> PGP Key:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fgondor.ap
> ana.org.au%2F~herbert%2Fpubkey.txt&data=05%7C02%7Cv.sethi%40nxp.com%
> 7C33199c44b5f145e8981a08df0a48d61a%7C686ea1d3bc2b4c6fa92cd99c5c
> 301635%7C0%7C0%7C639240980112908987%7CUnknown%7CTWFpbGZsb3
> d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIj
> oiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Er%2F9fVTTfGOzcuO
> 35eetZ7IPo6Ub21U0AG5iqDXR9vM%3D&reserved=0


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 11074 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-09  7:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05  4:19 [PATCH] crypto: caam - Use bounce buffer for unaligned RSA destination buffers Changwei Zou
2026-08-15  1:00 ` Herbert Xu
2026-08-21  5:18   ` Changwei Zou
2026-09-04  5:37     ` [PATCH] crypto: caam - Remove public key support Herbert Xu
2026-09-09  7:23       ` [EXT] " Varun Sethi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox