All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dmaengine: jz4780: set DMA maximum segment size
@ 2022-04-11 15:36 Aidan MacDonald
  2022-04-20 11:43 ` Vinod Koul
  0 siblings, 1 reply; 2+ messages in thread
From: Aidan MacDonald @ 2022-04-11 15:36 UTC (permalink / raw)
  To: paul, vkoul; +Cc: linux-mips, dmaengine, linux-kernel

Set the maximum segment size, since the hardware can do transfers larger
than the default 64 KiB returned by dma_get_max_seg_size().

The maximum segment size is limited by the 24-bit transfer count field
in DMA descriptors. The number of bytes is equal to the transfer count
times the transfer size unit, which is selected by the driver based on
the DMA buffer address and length of the transfer. The size unit can be
as small as 1 byte, so set the maximum segment size to 2^24-1 bytes to
ensure the transfer count will not overflow regardless of the size unit
selected by the driver.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
---
 drivers/dma/dma-jz4780.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c
index fc513eb2b289..e2ec540e6519 100644
--- a/drivers/dma/dma-jz4780.c
+++ b/drivers/dma/dma-jz4780.c
@@ -8,6 +8,7 @@
 
 #include <linux/clk.h>
 #include <linux/dmapool.h>
+#include <linux/dma-mapping.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
@@ -911,6 +912,14 @@ static int jz4780_dma_probe(struct platform_device *pdev)
 
 	dd = &jzdma->dma_device;
 
+	/*
+	 * The real segment size limit is dependent on the size unit selected
+	 * for the transfer. Because the size unit is selected automatically
+	 * and may be as small as 1 byte, use a safe limit of 2^24-1 bytes to
+	 * ensure the 24-bit transfer count in the descriptor cannot overflow.
+	 */
+	dma_set_max_seg_size(dev, 0xffffff);
+
 	dma_cap_set(DMA_MEMCPY, dd->cap_mask);
 	dma_cap_set(DMA_SLAVE, dd->cap_mask);
 	dma_cap_set(DMA_CYCLIC, dd->cap_mask);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] dmaengine: jz4780: set DMA maximum segment size
  2022-04-11 15:36 [PATCH] dmaengine: jz4780: set DMA maximum segment size Aidan MacDonald
@ 2022-04-20 11:43 ` Vinod Koul
  0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2022-04-20 11:43 UTC (permalink / raw)
  To: Aidan MacDonald; +Cc: paul, linux-mips, dmaengine, linux-kernel

On 11-04-22, 16:36, Aidan MacDonald wrote:
> Set the maximum segment size, since the hardware can do transfers larger
> than the default 64 KiB returned by dma_get_max_seg_size().
> 
> The maximum segment size is limited by the 24-bit transfer count field
> in DMA descriptors. The number of bytes is equal to the transfer count
> times the transfer size unit, which is selected by the driver based on
> the DMA buffer address and length of the transfer. The size unit can be
> as small as 1 byte, so set the maximum segment size to 2^24-1 bytes to
> ensure the transfer count will not overflow regardless of the size unit
> selected by the driver.

Applied, thanks

-- 
~Vinod

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-20 11:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-11 15:36 [PATCH] dmaengine: jz4780: set DMA maximum segment size Aidan MacDonald
2022-04-20 11:43 ` Vinod Koul

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.