Skip to content

Commit 616f0f8

Browse files
andreamerellovinodkoul
authored andcommitted
dmaengine: xilinx_dma: commonize DMA copy size calculation
This patch removes a bit of duplicated code by introducing a new function that implements calculations for DMA copy size, and prepares for changes to the copy size calculation that will happen in following patches. Suggested-by: Vinod Koul <vkoul@kernel.org> Signed-off-by: Andrea Merello <andrea.merello@gmail.com> Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com> Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent bfeffd1 commit 616f0f8

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

drivers/dma/xilinx/xilinx_dma.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ struct xilinx_dma_config {
425425
* @rxs_clk: DMA s2mm stream clock
426426
* @nr_channels: Number of channels DMA device supports
427427
* @chan_id: DMA channel identifier
428+
* @max_buffer_len: Max buffer length
428429
*/
429430
struct xilinx_dma_device {
430431
void __iomem *regs;
@@ -444,6 +445,7 @@ struct xilinx_dma_device {
444445
struct clk *rxs_clk;
445446
u32 nr_channels;
446447
u32 chan_id;
448+
u32 max_buffer_len;
447449
};
448450

449451
/* Macros */
@@ -959,6 +961,25 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan)
959961
return 0;
960962
}
961963

964+
/**
965+
* xilinx_dma_calc_copysize - Calculate the amount of data to copy
966+
* @chan: Driver specific DMA channel
967+
* @size: Total data that needs to be copied
968+
* @done: Amount of data that has been already copied
969+
*
970+
* Return: Amount of data that has to be copied
971+
*/
972+
static int xilinx_dma_calc_copysize(struct xilinx_dma_chan *chan,
973+
int size, int done)
974+
{
975+
size_t copy;
976+
977+
copy = min_t(size_t, size - done,
978+
chan->xdev->max_buffer_len);
979+
980+
return copy;
981+
}
982+
962983
/**
963984
* xilinx_dma_tx_status - Get DMA transaction status
964985
* @dchan: DMA channel
@@ -992,7 +1013,7 @@ static enum dma_status xilinx_dma_tx_status(struct dma_chan *dchan,
9921013
list_for_each_entry(segment, &desc->segments, node) {
9931014
hw = &segment->hw;
9941015
residue += (hw->control - hw->status) &
995-
XILINX_DMA_MAX_TRANS_LEN;
1016+
chan->xdev->max_buffer_len;
9961017
}
9971018
}
9981019
spin_unlock_irqrestore(&chan->lock, flags);
@@ -1254,7 +1275,7 @@ static void xilinx_cdma_start_transfer(struct xilinx_dma_chan *chan)
12541275

12551276
/* Start the transfer */
12561277
dma_ctrl_write(chan, XILINX_DMA_REG_BTT,
1257-
hw->control & XILINX_DMA_MAX_TRANS_LEN);
1278+
hw->control & chan->xdev->max_buffer_len);
12581279
}
12591280

12601281
list_splice_tail_init(&chan->pending_list, &chan->active_list);
@@ -1357,7 +1378,7 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan)
13571378

13581379
/* Start the transfer */
13591380
dma_ctrl_write(chan, XILINX_DMA_REG_BTT,
1360-
hw->control & XILINX_DMA_MAX_TRANS_LEN);
1381+
hw->control & chan->xdev->max_buffer_len);
13611382
}
13621383

13631384
list_splice_tail_init(&chan->pending_list, &chan->active_list);
@@ -1718,7 +1739,7 @@ xilinx_cdma_prep_memcpy(struct dma_chan *dchan, dma_addr_t dma_dst,
17181739
struct xilinx_cdma_tx_segment *segment;
17191740
struct xilinx_cdma_desc_hw *hw;
17201741

1721-
if (!len || len > XILINX_DMA_MAX_TRANS_LEN)
1742+
if (!len || len > chan->xdev->max_buffer_len)
17221743
return NULL;
17231744

17241745
desc = xilinx_dma_alloc_tx_descriptor(chan);
@@ -1808,8 +1829,8 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg(
18081829
* Calculate the maximum number of bytes to transfer,
18091830
* making sure it is less than the hw limit
18101831
*/
1811-
copy = min_t(size_t, sg_dma_len(sg) - sg_used,
1812-
XILINX_DMA_MAX_TRANS_LEN);
1832+
copy = xilinx_dma_calc_copysize(chan, sg_dma_len(sg),
1833+
sg_used);
18131834
hw = &segment->hw;
18141835

18151836
/* Fill in the descriptor */
@@ -1913,8 +1934,8 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_dma_cyclic(
19131934
* Calculate the maximum number of bytes to transfer,
19141935
* making sure it is less than the hw limit
19151936
*/
1916-
copy = min_t(size_t, period_len - sg_used,
1917-
XILINX_DMA_MAX_TRANS_LEN);
1937+
copy = xilinx_dma_calc_copysize(chan, period_len,
1938+
sg_used);
19181939
hw = &segment->hw;
19191940
xilinx_axidma_buf(chan, hw, buf_addr, sg_used,
19201941
period_len * i);
@@ -2628,6 +2649,8 @@ static int xilinx_dma_probe(struct platform_device *pdev)
26282649

26292650
/* Retrieve the DMA engine properties from the device tree */
26302651
xdev->has_sg = of_property_read_bool(node, "xlnx,include-sg");
2652+
xdev->max_buffer_len = XILINX_DMA_MAX_TRANS_LEN;
2653+
26312654
if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA)
26322655
xdev->mcdma = of_property_read_bool(node, "xlnx,mcdma");
26332656

0 commit comments

Comments
 (0)