Skip to content

Commit e713468

Browse files
ADESTMvinodkoul
authored andcommitted
dmaengine: stm32-dma3: clamp AXI burst using match data
STM32 DMA3 can be interconnected with AXI3 or AXI4 busses. In case it is interconnected with AXI3, the maximum burst length supported by AXI3 protocol is 16 beats, which is lower than the maximum burst length supported by STM32 DMA3. So the programmed burst has to be shortened when AXI port is used. Introduce struct stm32_dma3_pdata to specify the specific configurations (e.g. AXI maximum burst length) required by the SoC, so implied by the SoC specific compatible. Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com> Link: https://lore.kernel.org/r/20241016-dma3-mp25-updates-v3-6-8311fe6f228d@foss.st.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 2ff0fb9 commit e713468

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

drivers/dma/stm32/stm32-dma3.c

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ enum stm32_dma3_port_data_width {
230230
#define STM32_DMA3_CFG_SET_BOTH (STM32_DMA3_CFG_SET_DT | STM32_DMA3_CFG_SET_DMA)
231231

232232
#define STM32_DMA3_MAX_BLOCK_SIZE ALIGN_DOWN(CBR1_BNDT, 64)
233+
#define STM32_DMA3_MAX_BURST_LEN (1 + min_t(u32, FIELD_MAX(CTR1_SBL_1), \
234+
FIELD_MAX(CTR1_DBL_1)))
233235
#define port_is_ahb(maxdw) ({ typeof(maxdw) (_maxdw) = (maxdw); \
234236
((_maxdw) != DW_INVALID) && ((_maxdw) == DW_32); })
235237
#define port_is_axi(maxdw) ({ typeof(maxdw) (_maxdw) = (maxdw); \
@@ -295,6 +297,10 @@ struct stm32_dma3_chan {
295297
u32 dma_status;
296298
};
297299

300+
struct stm32_dma3_pdata {
301+
u32 axi_max_burst_len;
302+
};
303+
298304
struct stm32_dma3_ddata {
299305
struct dma_device dma_dev;
300306
void __iomem *base;
@@ -303,6 +309,7 @@ struct stm32_dma3_ddata {
303309
u32 dma_channels;
304310
u32 dma_requests;
305311
enum stm32_dma3_port_data_width ports_max_dw[2];
312+
u32 axi_max_burst_len;
306313
};
307314

308315
static inline struct stm32_dma3_ddata *to_stm32_dma3_ddata(struct stm32_dma3_chan *chan)
@@ -535,7 +542,8 @@ static enum dma_slave_buswidth stm32_dma3_get_max_dw(u32 chan_max_burst,
535542
return 1 << __ffs(len | addr | max_dw);
536543
}
537544

538-
static u32 stm32_dma3_get_max_burst(u32 len, enum dma_slave_buswidth dw, u32 chan_max_burst)
545+
static u32 stm32_dma3_get_max_burst(u32 len, enum dma_slave_buswidth dw,
546+
u32 chan_max_burst, u32 bus_max_burst)
539547
{
540548
u32 max_burst = chan_max_burst ? chan_max_burst / dw : 1;
541549

@@ -546,8 +554,9 @@ static u32 stm32_dma3_get_max_burst(u32 len, enum dma_slave_buswidth dw, u32 cha
546554
/*
547555
* HW doesn't modify the burst if burst size <= half of the fifo size.
548556
* If len is not a multiple of burst size, last burst is shortened by HW.
557+
* Take care of maximum burst supported on interconnect bus.
549558
*/
550-
return max_burst;
559+
return min_t(u32, max_burst, bus_max_burst);
551560
}
552561

553562
static int stm32_dma3_chan_prep_hw(struct stm32_dma3_chan *chan, enum dma_transfer_direction dir,
@@ -556,6 +565,7 @@ static int stm32_dma3_chan_prep_hw(struct stm32_dma3_chan *chan, enum dma_transf
556565
{
557566
struct stm32_dma3_ddata *ddata = to_stm32_dma3_ddata(chan);
558567
struct dma_device dma_device = ddata->dma_dev;
568+
u32 src_max_burst = STM32_DMA3_MAX_BURST_LEN, dst_max_burst = STM32_DMA3_MAX_BURST_LEN;
559569
u32 sdw, ddw, sbl_max, dbl_max, tcem, init_dw, init_bl_max;
560570
u32 _ctr1 = 0, _ctr2 = 0;
561571
u32 ch_conf = chan->dt_config.ch_conf;
@@ -596,10 +606,14 @@ static int stm32_dma3_chan_prep_hw(struct stm32_dma3_chan *chan, enum dma_transf
596606
_ctr1 |= CTR1_SINC;
597607
if (sap)
598608
_ctr1 |= CTR1_SAP;
609+
if (port_is_axi(sap_max_dw)) /* AXI - apply axi maximum burst limitation */
610+
src_max_burst = ddata->axi_max_burst_len;
599611
if (FIELD_GET(STM32_DMA3_DT_DINC, tr_conf))
600612
_ctr1 |= CTR1_DINC;
601613
if (dap)
602614
_ctr1 |= CTR1_DAP;
615+
if (port_is_axi(dap_max_dw)) /* AXI - apply axi maximum burst limitation */
616+
dst_max_burst = ddata->axi_max_burst_len;
603617

604618
_ctr2 |= FIELD_PREP(CTR2_REQSEL, chan->dt_config.req_line) & ~CTR2_SWREQ;
605619
if (FIELD_GET(STM32_DMA3_DT_BREQ, tr_conf))
@@ -619,11 +633,12 @@ static int stm32_dma3_chan_prep_hw(struct stm32_dma3_chan *chan, enum dma_transf
619633
/* Set destination (device) data width and burst */
620634
ddw = min_t(u32, ddw, stm32_dma3_get_max_dw(chan->max_burst, dap_max_dw,
621635
len, dst_addr));
622-
dbl_max = min_t(u32, dbl_max, stm32_dma3_get_max_burst(len, ddw, chan->max_burst));
636+
dbl_max = min_t(u32, dbl_max, stm32_dma3_get_max_burst(len, ddw, chan->max_burst,
637+
dst_max_burst));
623638

624639
/* Set source (memory) data width and burst */
625640
sdw = stm32_dma3_get_max_dw(chan->max_burst, sap_max_dw, len, src_addr);
626-
sbl_max = stm32_dma3_get_max_burst(len, sdw, chan->max_burst);
641+
sbl_max = stm32_dma3_get_max_burst(len, sdw, chan->max_burst, src_max_burst);
627642
if (!!FIELD_GET(STM32_DMA3_DT_NOPACK, tr_conf)) {
628643
sdw = ddw;
629644
sbl_max = dbl_max;
@@ -653,11 +668,12 @@ static int stm32_dma3_chan_prep_hw(struct stm32_dma3_chan *chan, enum dma_transf
653668
/* Set source (device) data width and burst */
654669
sdw = min_t(u32, sdw, stm32_dma3_get_max_dw(chan->max_burst, sap_max_dw,
655670
len, src_addr));
656-
sbl_max = min_t(u32, sbl_max, stm32_dma3_get_max_burst(len, sdw, chan->max_burst));
671+
sbl_max = min_t(u32, sbl_max, stm32_dma3_get_max_burst(len, sdw, chan->max_burst,
672+
src_max_burst));
657673

658674
/* Set destination (memory) data width and burst */
659675
ddw = stm32_dma3_get_max_dw(chan->max_burst, dap_max_dw, len, dst_addr);
660-
dbl_max = stm32_dma3_get_max_burst(len, ddw, chan->max_burst);
676+
dbl_max = stm32_dma3_get_max_burst(len, ddw, chan->max_burst, dst_max_burst);
661677
if (!!FIELD_GET(STM32_DMA3_DT_NOPACK, tr_conf) ||
662678
((_ctr2 & CTR2_PFREQ) && ddw > sdw)) { /* Packing to wider ddw not supported */
663679
ddw = sdw;
@@ -689,22 +705,24 @@ static int stm32_dma3_chan_prep_hw(struct stm32_dma3_chan *chan, enum dma_transf
689705
init_dw = sdw;
690706
init_bl_max = sbl_max;
691707
sdw = stm32_dma3_get_max_dw(chan->max_burst, sap_max_dw, len, src_addr);
692-
sbl_max = stm32_dma3_get_max_burst(len, sdw, chan->max_burst);
708+
sbl_max = stm32_dma3_get_max_burst(len, sdw, chan->max_burst, src_max_burst);
693709
if (chan->config_set & STM32_DMA3_CFG_SET_DMA) {
694710
sdw = min_t(u32, init_dw, sdw);
695-
sbl_max = min_t(u32, init_bl_max,
696-
stm32_dma3_get_max_burst(len, sdw, chan->max_burst));
711+
sbl_max = min_t(u32, init_bl_max, stm32_dma3_get_max_burst(len, sdw,
712+
chan->max_burst,
713+
src_max_burst));
697714
}
698715

699716
/* Set destination (memory) data width and burst */
700717
init_dw = ddw;
701718
init_bl_max = dbl_max;
702719
ddw = stm32_dma3_get_max_dw(chan->max_burst, dap_max_dw, len, dst_addr);
703-
dbl_max = stm32_dma3_get_max_burst(len, ddw, chan->max_burst);
720+
dbl_max = stm32_dma3_get_max_burst(len, ddw, chan->max_burst, dst_max_burst);
704721
if (chan->config_set & STM32_DMA3_CFG_SET_DMA) {
705722
ddw = min_t(u32, init_dw, ddw);
706-
dbl_max = min_t(u32, init_bl_max,
707-
stm32_dma3_get_max_burst(len, ddw, chan->max_burst));
723+
dbl_max = min_t(u32, init_bl_max, stm32_dma3_get_max_burst(len, ddw,
724+
chan->max_burst,
725+
dst_max_burst));
708726
}
709727

710728
_ctr1 |= FIELD_PREP(CTR1_SDW_LOG2, ilog2(sdw));
@@ -1647,15 +1665,20 @@ static u32 stm32_dma3_check_rif(struct stm32_dma3_ddata *ddata)
16471665
return chan_reserved;
16481666
}
16491667

1668+
static struct stm32_dma3_pdata stm32mp25_pdata = {
1669+
.axi_max_burst_len = 16,
1670+
};
1671+
16501672
static const struct of_device_id stm32_dma3_of_match[] = {
1651-
{ .compatible = "st,stm32mp25-dma3", },
1673+
{ .compatible = "st,stm32mp25-dma3", .data = &stm32mp25_pdata, },
16521674
{ /* sentinel */ },
16531675
};
16541676
MODULE_DEVICE_TABLE(of, stm32_dma3_of_match);
16551677

16561678
static int stm32_dma3_probe(struct platform_device *pdev)
16571679
{
16581680
struct device_node *np = pdev->dev.of_node;
1681+
const struct stm32_dma3_pdata *pdata;
16591682
struct stm32_dma3_ddata *ddata;
16601683
struct reset_control *reset;
16611684
struct stm32_dma3_chan *chan;
@@ -1750,6 +1773,16 @@ static int stm32_dma3_probe(struct platform_device *pdev)
17501773
else /* Dual master ports */
17511774
ddata->ports_max_dw[1] = FIELD_GET(G_M1_DATA_WIDTH_ENC, hwcfgr);
17521775

1776+
/* axi_max_burst_len is optional, if not defined, use STM32_DMA3_MAX_BURST_LEN */
1777+
ddata->axi_max_burst_len = STM32_DMA3_MAX_BURST_LEN;
1778+
pdata = device_get_match_data(&pdev->dev);
1779+
if (pdata && pdata->axi_max_burst_len) {
1780+
ddata->axi_max_burst_len = min_t(u32, pdata->axi_max_burst_len,
1781+
STM32_DMA3_MAX_BURST_LEN);
1782+
dev_dbg(&pdev->dev, "Burst is limited to %u beats through AXI port\n",
1783+
ddata->axi_max_burst_len);
1784+
}
1785+
17531786
ddata->chans = devm_kcalloc(&pdev->dev, ddata->dma_channels, sizeof(*ddata->chans),
17541787
GFP_KERNEL);
17551788
if (!ddata->chans) {

0 commit comments

Comments
 (0)