Skip to content

Commit 80a7695

Browse files
stmordretVinod Koul
authored andcommitted
dmaengine: stm32-dma: fix max items per transfer
Having 0 in item counter register is valid and stands for a "No or Ended transfer". Therefore valid transfer starts from @+0 to @+0xFFFE leading to unaligned scatter gather at boundary. Thus it's safer to round down this value on its FIFO size (16 Bytes). Signed-off-by: Pierre-Yves MORDRET <[email protected]> Signed-off-by: Vinod Koul <[email protected]>
1 parent c2d86b1 commit 80a7695

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/dma/stm32-dma.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
#define STM32_DMA_TEI BIT(3) /* Transfer Error Interrupt */
3939
#define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */
4040
#define STM32_DMA_FEI BIT(0) /* FIFO Error Interrupt */
41-
#define STM32_DMA_MASKI (STM32_DMA_TCI \
42-
| STM32_DMA_TEI \
43-
| STM32_DMA_DMEI \
44-
| STM32_DMA_FEI)
4541

4642
/* DMA Stream x Configuration Register */
4743
#define STM32_DMA_SCR(x) (0x0010 + 0x18 * (x)) /* x = 0..7 */
@@ -118,6 +114,13 @@
118114
#define STM32_DMA_FIFO_THRESHOLD_FULL 0x03
119115

120116
#define STM32_DMA_MAX_DATA_ITEMS 0xffff
117+
/*
118+
* Valid transfer starts from @0 to @0xFFFE leading to unaligned scatter
119+
* gather at boundary. Thus it's safer to round down this value on FIFO
120+
* size (16 Bytes)
121+
*/
122+
#define STM32_DMA_ALIGNED_MAX_DATA_ITEMS \
123+
ALIGN_DOWN(STM32_DMA_MAX_DATA_ITEMS, 16)
121124
#define STM32_DMA_MAX_CHANNELS 0x08
122125
#define STM32_DMA_MAX_REQUEST_ID 0x08
123126
#define STM32_DMA_MAX_DATA_PARAM 0x03
@@ -869,7 +872,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg(
869872
desc->sg_req[i].len = sg_dma_len(sg);
870873

871874
nb_data_items = desc->sg_req[i].len / buswidth;
872-
if (nb_data_items > STM32_DMA_MAX_DATA_ITEMS) {
875+
if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) {
873876
dev_err(chan2dev(chan), "nb items not supported\n");
874877
goto err;
875878
}
@@ -935,7 +938,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_cyclic(
935938
return NULL;
936939

937940
nb_data_items = period_len / buswidth;
938-
if (nb_data_items > STM32_DMA_MAX_DATA_ITEMS) {
941+
if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) {
939942
dev_err(chan2dev(chan), "number of items not supported\n");
940943
return NULL;
941944
}
@@ -985,7 +988,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
985988
u32 num_sgs, best_burst, dma_burst, threshold;
986989
int i;
987990

988-
num_sgs = DIV_ROUND_UP(len, STM32_DMA_MAX_DATA_ITEMS);
991+
num_sgs = DIV_ROUND_UP(len, STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
989992
desc = stm32_dma_alloc_desc(num_sgs);
990993
if (!desc)
991994
return NULL;
@@ -994,7 +997,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
994997

995998
for (offset = 0, i = 0; offset < len; offset += xfer_count, i++) {
996999
xfer_count = min_t(size_t, len - offset,
997-
STM32_DMA_MAX_DATA_ITEMS);
1000+
STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
9981001

9991002
/* Compute best burst size */
10001003
max_width = DMA_SLAVE_BUSWIDTH_1_BYTE;

0 commit comments

Comments
 (0)