* [PATCH 1/2] crypto: caam: map DMA buffers before sync @ 2024-03-07 8:39 Rouven Czerwinski 2024-03-07 8:39 ` [PATCH 2/2] crypto: caam: caamrng: map desc and buffer Rouven Czerwinski 2024-03-07 9:09 ` [PATCH 1/2] crypto: caam: map DMA buffers before sync Lucas Stach 0 siblings, 2 replies; 4+ messages in thread From: Rouven Czerwinski @ 2024-03-07 8:39 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. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> --- drivers/crypto/caam/rng_self_test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/crypto/caam/rng_self_test.c b/drivers/crypto/caam/rng_self_test.c index b6fcc3bc09..f5ab974a98 100644 --- a/drivers/crypto/caam/rng_self_test.c +++ b/drivers/crypto/caam/rng_self_test.c @@ -186,6 +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_map_single(dev, desc, desc_size * sizeof(*desc), DMA_TO_DEVICE); + dma_map_single(dev, result, result_size * sizeof(*result), DMA_FROM_DEVICE); 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, @@ -218,6 +220,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] 4+ messages in thread
* [PATCH 2/2] crypto: caam: caamrng: map desc and buffer 2024-03-07 8:39 [PATCH 1/2] crypto: caam: map DMA buffers before sync Rouven Czerwinski @ 2024-03-07 8:39 ` Rouven Czerwinski 2024-03-07 9:13 ` Lucas Stach 2024-03-07 9:09 ` [PATCH 1/2] crypto: caam: map DMA buffers before sync Lucas Stach 1 sibling, 1 reply; 4+ messages in thread From: Rouven Czerwinski @ 2024-03-07 8:39 UTC (permalink / raw) To: barebox; +Cc: 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@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); @@ -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); err = rng_create_job_desc(ctx, buf_id); if (err) -- 2.39.2 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] crypto: caam: caamrng: map desc and buffer 2024-03-07 8:39 ` [PATCH 2/2] crypto: caam: caamrng: map desc and buffer Rouven Czerwinski @ 2024-03-07 9:13 ` Lucas Stach 0 siblings, 0 replies; 4+ messages in thread From: Lucas Stach @ 2024-03-07 9:13 UTC (permalink / raw) To: Rouven Czerwinski, barebox 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@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) ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] crypto: caam: map DMA buffers before sync 2024-03-07 8:39 [PATCH 1/2] crypto: caam: map DMA buffers before sync Rouven Czerwinski 2024-03-07 8:39 ` [PATCH 2/2] crypto: caam: caamrng: map desc and buffer Rouven Czerwinski @ 2024-03-07 9:09 ` Lucas Stach 1 sibling, 0 replies; 4+ messages in thread From: Lucas Stach @ 2024-03-07 9:09 UTC (permalink / raw) To: Rouven Czerwinski, barebox Am Donnerstag, dem 07.03.2024 um 09:39 +0100 schrieb 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. > > Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> > --- > drivers/crypto/caam/rng_self_test.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/crypto/caam/rng_self_test.c b/drivers/crypto/caam/rng_self_test.c > index b6fcc3bc09..f5ab974a98 100644 > --- a/drivers/crypto/caam/rng_self_test.c > +++ b/drivers/crypto/caam/rng_self_test.c > @@ -186,6 +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_map_single(dev, desc, desc_size * sizeof(*desc), DMA_TO_DEVICE); > + dma_map_single(dev, result, result_size * sizeof(*result), DMA_FROM_DEVICE); > 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, While harmless, those syncs are not needed anymore after the dma_map is added, as they do the same cache maintenance operations as the map right before. Regards, Lucas > @@ -218,6 +220,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; ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-07 9:14 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-03-07 8:39 [PATCH 1/2] crypto: caam: map DMA buffers before sync Rouven Czerwinski 2024-03-07 8:39 ` [PATCH 2/2] crypto: caam: caamrng: map desc and buffer Rouven Czerwinski 2024-03-07 9:13 ` Lucas Stach 2024-03-07 9:09 ` [PATCH 1/2] crypto: caam: map DMA buffers before sync Lucas Stach
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox