2021-10-11 13:30:12

by Amelie Delaunay

[permalink] [raw]
Subject: [PATCH 0/3] dmaengine: stm32-dma: some corner case fixes

This patchset brings some fixes to STM32 DMA driver.
It fixes undefined behaviour of STM32 DMA controller when an unaligned address
is used.
It also prevents accidental repeated completion using dma_cookie_complete() in
terminate_all().

Amelie Delaunay (3):
dmaengine: stm32-dma: mark pending descriptor complete in
terminate_all
dmaengine: stm32-dma: fix stm32_dma_get_max_width
dmaengine: stm32-dma: fix burst in case of unaligned memory address

drivers/dma/stm32-dma.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

--
2.25.1


2021-10-11 16:16:55

by Amelie Delaunay

[permalink] [raw]
Subject: [PATCH 3/3] dmaengine: stm32-dma: fix burst in case of unaligned memory address

Theorically, address pointers used by STM32 DMA must be chosen so as to
ensure that all transfers within a burst block are aligned on the address
boundary equal to the size of the transfer.
If this is always the case for peripheral addresses on STM32, it is not for
memory addresses if the user doesn't respect this alignment constraint.
To avoid a weird behavior of the DMA controller in this case (no error
triggered but data are not transferred as expected), force no burst.

Signed-off-by: Amelie Delaunay <[email protected]>
---
drivers/dma/stm32-dma.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 6e4ef44941ef..2283c500f4ce 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -753,8 +753,14 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
if (src_bus_width < 0)
return src_bus_width;

- /* Set memory burst size */
- src_maxburst = STM32_DMA_MAX_BURST;
+ /*
+ * Set memory burst size - burst not possible if address is not aligned on
+ * the address boundary equal to the size of the transfer
+ */
+ if (buf_addr % buf_len)
+ src_maxburst = 1;
+ else
+ src_maxburst = STM32_DMA_MAX_BURST;
src_best_burst = stm32_dma_get_best_burst(buf_len,
src_maxburst,
fifoth,
@@ -803,8 +809,14 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
if (dst_bus_width < 0)
return dst_bus_width;

- /* Set memory burst size */
- dst_maxburst = STM32_DMA_MAX_BURST;
+ /*
+ * Set memory burst size - burst not possible if address is not aligned on
+ * the address boundary equal to the size of the transfer
+ */
+ if (buf_addr % buf_len)
+ dst_maxburst = 1;
+ else
+ dst_maxburst = STM32_DMA_MAX_BURST;
dst_best_burst = stm32_dma_get_best_burst(buf_len,
dst_maxburst,
fifoth,
--
2.25.1

2021-10-18 06:47:42

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 0/3] dmaengine: stm32-dma: some corner case fixes

On 11-10-21, 11:42, Amelie Delaunay wrote:
> This patchset brings some fixes to STM32 DMA driver.
> It fixes undefined behaviour of STM32 DMA controller when an unaligned address
> is used.
> It also prevents accidental repeated completion using dma_cookie_complete() in
> terminate_all().

Applied, thanks

--
~Vinod