mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] crypto: caam: map DMA buffers instead of single_sync
@ 2024-03-08  7:35 Rouven Czerwinski
  2024-03-08  7:35 ` [PATCH v2 2/2] crypto: caam: caamrng: dma map descriptors Rouven Czerwinski
  0 siblings, 1 reply; 3+ messages in thread
From: Rouven Czerwinski @ 2024-03-08  7:35 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

With dma api debugging enabled, Barebox complains correctly that the
result and desc buffer are never mapped correctly. Add the correct map
and unmap sequence instead of the sync single.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
v2:
- remove dma_sync_single_for_device() calls

 drivers/crypto/caam/rng_self_test.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/rng_self_test.c b/drivers/crypto/caam/rng_self_test.c
index b6fcc3bc09..7bb340acbd 100644
--- a/drivers/crypto/caam/rng_self_test.c
+++ b/drivers/crypto/caam/rng_self_test.c
@@ -186,10 +186,8 @@ int caam_rng_self_test(struct device *dev, const u8 caam_era, const u8 rngvid,
 
 	construct_rng_self_test_jobdesc(desc, rng_st_dsc, result, desc_size);
 
-	dma_sync_single_for_device(dev, (unsigned long)desc,
-			desc_size * sizeof(*desc), DMA_TO_DEVICE);
-	dma_sync_single_for_device(dev, (unsigned long)result,
-			result_size * sizeof(*result), DMA_FROM_DEVICE);
+	dma_map_single(dev, desc, desc_size * sizeof(*desc), DMA_TO_DEVICE);
+	dma_map_single(dev, result, result_size * sizeof(*result), DMA_FROM_DEVICE);
 
 	/* wait for job completion */
 	ret = caam_jr_enqueue(dev, desc, rng_self_test_done, &job_err);
@@ -218,6 +216,8 @@ int caam_rng_self_test(struct device *dev, const u8 caam_era, const u8 rngvid,
 	ret = 0;
 
 err:
+	dma_unmap_single(dev, (dma_addr_t)desc, desc_size * sizeof(*desc), DMA_TO_DEVICE);
+	dma_unmap_single(dev, (dma_addr_t)result, result_size * sizeof(*result), DMA_FROM_DEVICE);
 	dma_free(desc);
 	dma_free(result);
 	return ret;
-- 
2.39.2




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

* [PATCH v2 2/2] crypto: caam: caamrng: dma map descriptors
  2024-03-08  7:35 [PATCH v2 1/2] crypto: caam: map DMA buffers instead of single_sync Rouven Czerwinski
@ 2024-03-08  7:35 ` Rouven Czerwinski
  2024-03-08  9:55   ` Lucas Stach
  0 siblings, 1 reply; 3+ messages in thread
From: Rouven Czerwinski @ 2024-03-08  7:35 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

With DMA API debugging Barebox complains that the descriptors are never
mapped before a sync. Add the map and unmap function calls.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
v2:
- remove dma_map_sync_single_for_device() calls
- remove dma_map_single for dma coherent memory

 drivers/crypto/caam/caamrng.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index ea154913ca..03e75d0b7b 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,8 +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_sync_single_for_device(jrdev, (unsigned long)desc, desc_bytes(desc),
-				   DMA_TO_DEVICE);
+	dma_map_single(jrdev, (void *)desc, desc_bytes(desc), DMA_TO_DEVICE);
 
 	err = caam_jr_enqueue(jrdev, desc, rng_done, ctx);
 	if (!err)
@@ -180,8 +180,7 @@ static inline int rng_create_sh_desc(struct caam_rng_ctx *ctx)
 
 	ctx->sh_desc_dma = (dma_addr_t)desc;
 
-	dma_sync_single_for_device(ctx->jrdev, (unsigned long)desc, desc_bytes(desc),
-				   DMA_TO_DEVICE);
+	dma_map_single(ctx->jrdev, desc, desc_bytes(desc), DMA_TO_DEVICE);
 
 	print_hex_dump_debug("rng shdesc@: ", DUMP_PREFIX_OFFSET, 16, 4,
 		       desc, desc_bytes(desc), 1);
-- 
2.39.2




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

* Re: [PATCH v2 2/2] crypto: caam: caamrng: dma map descriptors
  2024-03-08  7:35 ` [PATCH v2 2/2] crypto: caam: caamrng: dma map descriptors Rouven Czerwinski
@ 2024-03-08  9:55   ` Lucas Stach
  0 siblings, 0 replies; 3+ messages in thread
From: Lucas Stach @ 2024-03-08  9:55 UTC (permalink / raw)
  To: Rouven Czerwinski, barebox

Am Freitag, dem 08.03.2024 um 08:35 +0100 schrieb Rouven Czerwinski:
> With DMA API debugging Barebox complains that the descriptors are never
> mapped before a sync. Add the map and unmap function calls.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
> v2:
> - remove dma_map_sync_single_for_device() calls
> - remove dma_map_single for dma coherent memory
> 
>  drivers/crypto/caam/caamrng.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
> index ea154913ca..03e75d0b7b 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,8 +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_sync_single_for_device(jrdev, (unsigned long)desc, desc_bytes(desc),
> -				   DMA_TO_DEVICE);
> +	dma_map_single(jrdev, (void *)desc, desc_bytes(desc), DMA_TO_DEVICE);
>  
>  	err = caam_jr_enqueue(jrdev, desc, rng_done, ctx);
>  	if (!err)
> @@ -180,8 +180,7 @@ static inline int rng_create_sh_desc(struct caam_rng_ctx *ctx)
>  
>  	ctx->sh_desc_dma = (dma_addr_t)desc;
>  
> -	dma_sync_single_for_device(ctx->jrdev, (unsigned long)desc, desc_bytes(desc),
> -				   DMA_TO_DEVICE);
> +	dma_map_single(ctx->jrdev, desc, desc_bytes(desc), DMA_TO_DEVICE);

dma_map_single returns the DMA address that should be stored in
ctx->sh_desc_dma instead of the simple cast from virtual to DMA address
in the line above.

The other two dma_map/unmap calls in this patch look like a layering
violation. I would argue that those should move down into
caam_jr_enqueue and caam_jr_dequeue, to avoid the equally silly cast
from virt to DMA in those functions.

Regards,
Lucas

>  
>  	print_hex_dump_debug("rng shdesc@: ", DUMP_PREFIX_OFFSET, 16, 4,
>  		       desc, desc_bytes(desc), 1);




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

end of thread, other threads:[~2024-03-08  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08  7:35 [PATCH v2 1/2] crypto: caam: map DMA buffers instead of single_sync Rouven Czerwinski
2024-03-08  7:35 ` [PATCH v2 2/2] crypto: caam: caamrng: dma map descriptors Rouven Czerwinski
2024-03-08  9:55   ` Lucas Stach

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