[PATCH 2/2] crypto: caam: caamrng: map desc and buffer

Lucas Stach l.stach at pengutronix.de
Thu Mar 7 01:13:33 PST 2024


Am Donnerstag, dem 07.03.2024 um 09:39 +0100 schrieb Rouven Czerwinski:
> With DMA API debugging Barebox complains that some buffers are never
> mapped before a sync. Add the map and unmap function calls.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski at pengutronix.de>
> ---
>  drivers/crypto/caam/caamrng.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
> index ea154913ca..1b5713f978 100644
> --- a/drivers/crypto/caam/caamrng.c
> +++ b/drivers/crypto/caam/caamrng.c
> @@ -91,6 +91,7 @@ static void rng_done(struct device *jrdev, u32 *desc, u32 err, void *context)
>  
>  	/* Buffer refilled, invalidate cache */
>  	dma_sync_single_for_cpu(jrdev, bd->addr, RN_BUF_SIZE, DMA_FROM_DEVICE);
> +	dma_unmap_single(jrdev, (unsigned long)desc, desc_bytes(desc), DMA_TO_DEVICE);
>  }
>  
>  static inline int submit_job(struct caam_rng_ctx *ctx, int to_current)
> @@ -102,6 +103,7 @@ static inline int submit_job(struct caam_rng_ctx *ctx, int to_current)
>  
>  	dev_dbg(jrdev, "submitting job %d\n", !(to_current ^ ctx->current_buf));
>  
> +	dma_map_single(jrdev, (void *)desc, desc_bytes(desc), DMA_TO_DEVICE);
>  	dma_sync_single_for_device(jrdev, (unsigned long)desc, desc_bytes(desc),
>  				   DMA_TO_DEVICE);
>  
> @@ -180,6 +182,7 @@ static inline int rng_create_sh_desc(struct caam_rng_ctx *ctx)
>  
>  	ctx->sh_desc_dma = (dma_addr_t)desc;
>  
> +	dma_map_single(ctx->jrdev, desc, desc_bytes(desc), DMA_TO_DEVICE);
>  	dma_sync_single_for_device(ctx->jrdev, (unsigned long)desc, desc_bytes(desc),
>  				   DMA_TO_DEVICE);

Same comment on those syncs as the patch before.

>  
> @@ -210,6 +213,7 @@ static int caam_init_buf(struct caam_rng_ctx *ctx, int buf_id)
>  	int err;
>  
>  	bd->buf = dma_alloc_coherent(RN_BUF_SIZE, &bd->addr);
> +	dma_map_single(ctx->jrdev, (void *)bd->addr, RN_BUF_SIZE, DMA_FROM_DEVICE);

This looks wrong. A device coherent buffer doesn't ever need to be
mapped via the streaming DMA API. The DMA debug is probably confused by
the bogus dma_sync_single_for_cpu() in rng_done(), which shouldn't be
there, as the buffer is allocated from coherent memory and thus doesn't
need to be synced.

Regards,
Lucas

>  
>  	err = rng_create_job_desc(ctx, buf_id);
>  	if (err)




More information about the barebox mailing list