public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dmaengine: tegra: Fix burst size calculation
@ 2026-02-24  8:34 Kartik Rajput
  2026-02-24 22:18 ` Frank Li
  0 siblings, 1 reply; 4+ messages in thread
From: Kartik Rajput @ 2026-02-24  8:34 UTC (permalink / raw)
  To: ldewangan, jonathanh, akhilrajeev, vkoul, Frank.Li,
	thierry.reding, digetx, pkunapuli, dmaengine, linux-tegra,
	linux-kernel
  Cc: Kartik Rajput, stable

Currently, the Tegra GPC DMA hardware requires the transfer length to
be a multiple of the max burst size configured for the channel. When a
client requests a transfer where the length is not evenly divisible by
the configured max burst size, the DMA hangs with partial burst at
the end.

Fix this by reducing the burst size to the largest power-of-2 value
that evenly divides the transfer length. For example, a 40-byte
transfer with a 16-byte max burst will now use an 8-byte burst
(40 / 8 = 5 complete bursts) instead of causing a hang.

This issue was observed with the PL011 UART driver where TX DMA
transfers of arbitrary lengths were stuck.

Fixes: ee17028009d4 ("dmaengine: tegra: Add tegra gpcdma driver")
Cc: stable@vger.kernel.org
Signed-off-by: Kartik Rajput <kkartik@nvidia.com>
---
 drivers/dma/tegra186-gpc-dma.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/dma/tegra186-gpc-dma.c b/drivers/dma/tegra186-gpc-dma.c
index 4d6fe0efa76e..7df0a745e7b8 100644
--- a/drivers/dma/tegra186-gpc-dma.c
+++ b/drivers/dma/tegra186-gpc-dma.c
@@ -825,6 +825,13 @@ static unsigned int get_burst_size(struct tegra_dma_channel *tdc,
 	 * len to calculate the optimum burst size
 	 */
 	burst_byte = burst_size ? burst_size * slave_bw : len;
+
+	/*
+	 * Find the largest burst size that evenly divides the transfer length.
+	 * The hardware requires the transfer length to be a multiple of the
+	 * burst size - partial bursts are not supported.
+	 */
+	burst_byte = min(burst_byte, 1U << __ffs(len));
 	burst_mmio_width = burst_byte / 4;
 
 	if (burst_mmio_width < TEGRA_GPCDMA_MMIOSEQ_BURST_MIN)
-- 
2.43.0


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

* Re: [PATCH] dmaengine: tegra: Fix burst size calculation
  2026-02-24  8:34 [PATCH] dmaengine: tegra: Fix burst size calculation Kartik Rajput
@ 2026-02-24 22:18 ` Frank Li
  2026-02-25  6:06   ` Kartik Rajput
  0 siblings, 1 reply; 4+ messages in thread
From: Frank Li @ 2026-02-24 22:18 UTC (permalink / raw)
  To: Kartik Rajput
  Cc: ldewangan, jonathanh, akhilrajeev, vkoul, Frank.Li,
	thierry.reding, digetx, pkunapuli, dmaengine, linux-tegra,
	linux-kernel, stable

On Tue, Feb 24, 2026 at 02:04:54PM +0530, Kartik Rajput wrote:
> Currently, the Tegra GPC DMA hardware requires the transfer length to
> be a multiple of the max burst size configured for the channel. When a
> client requests a transfer where the length is not evenly divisible by
> the configured max burst size, the DMA hangs with partial burst at
> the end.
>
> Fix this by reducing the burst size to the largest power-of-2 value
> that evenly divides the transfer length. For example, a 40-byte
> transfer with a 16-byte max burst will now use an 8-byte burst
> (40 / 8 = 5 complete bursts) instead of causing a hang.
>
> This issue was observed with the PL011 UART driver where TX DMA
> transfers of arbitrary lengths were stuck.

Suppose set burst size by UART driver through dma_config_slave. it depend
on uart's watermark settings.

Optimaized method as your example is set first transfer burst length 32,
the second transfer is 8.

Frank
>
> Fixes: ee17028009d4 ("dmaengine: tegra: Add tegra gpcdma driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Kartik Rajput <kkartik@nvidia.com>
> ---
>  drivers/dma/tegra186-gpc-dma.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/drivers/dma/tegra186-gpc-dma.c b/drivers/dma/tegra186-gpc-dma.c
> index 4d6fe0efa76e..7df0a745e7b8 100644
> --- a/drivers/dma/tegra186-gpc-dma.c
> +++ b/drivers/dma/tegra186-gpc-dma.c
> @@ -825,6 +825,13 @@ static unsigned int get_burst_size(struct tegra_dma_channel *tdc,
>  	 * len to calculate the optimum burst size
>  	 */
>  	burst_byte = burst_size ? burst_size * slave_bw : len;
> +
> +	/*
> +	 * Find the largest burst size that evenly divides the transfer length.
> +	 * The hardware requires the transfer length to be a multiple of the
> +	 * burst size - partial bursts are not supported.
> +	 */
> +	burst_byte = min(burst_byte, 1U << __ffs(len));
>  	burst_mmio_width = burst_byte / 4;
>
>  	if (burst_mmio_width < TEGRA_GPCDMA_MMIOSEQ_BURST_MIN)
> --
> 2.43.0
>

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

* Re: [PATCH] dmaengine: tegra: Fix burst size calculation
  2026-02-24 22:18 ` Frank Li
@ 2026-02-25  6:06   ` Kartik Rajput
  2026-02-25 20:06     ` Frank Li
  0 siblings, 1 reply; 4+ messages in thread
From: Kartik Rajput @ 2026-02-25  6:06 UTC (permalink / raw)
  To: Frank Li
  Cc: ldewangan, jonathanh, akhilrajeev, vkoul, Frank.Li,
	thierry.reding, digetx, pkunapuli, dmaengine, linux-tegra,
	linux-kernel, stable

On 25/02/26 03:48, Frank Li wrote:
> External email: Use caution opening links or attachments
> 
> 
> On Tue, Feb 24, 2026 at 02:04:54PM +0530, Kartik Rajput wrote:
>> Currently, the Tegra GPC DMA hardware requires the transfer length to
>> be a multiple of the max burst size configured for the channel. When a
>> client requests a transfer where the length is not evenly divisible by
>> the configured max burst size, the DMA hangs with partial burst at
>> the end.
>>
>> Fix this by reducing the burst size to the largest power-of-2 value
>> that evenly divides the transfer length. For example, a 40-byte
>> transfer with a 16-byte max burst will now use an 8-byte burst
>> (40 / 8 = 5 complete bursts) instead of causing a hang.
>>
>> This issue was observed with the PL011 UART driver where TX DMA
>> transfers of arbitrary lengths were stuck.
> 
> Suppose set burst size by UART driver through dma_config_slave. it depend
> on uart's watermark settings.
> 
> Optimaized method as your example is set first transfer burst length 32,
> the second transfer is 8.
> 
> Frank
>>
>> Fixes: ee17028009d4 ("dmaengine: tegra: Add tegra gpcdma driver")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Kartik Rajput <kkartik@nvidia.com>
>> ---
>>   drivers/dma/tegra186-gpc-dma.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/drivers/dma/tegra186-gpc-dma.c b/drivers/dma/tegra186-gpc-dma.c
>> index 4d6fe0efa76e..7df0a745e7b8 100644
>> --- a/drivers/dma/tegra186-gpc-dma.c
>> +++ b/drivers/dma/tegra186-gpc-dma.c
>> @@ -825,6 +825,13 @@ static unsigned int get_burst_size(struct tegra_dma_channel *tdc,
>>         * len to calculate the optimum burst size
>>         */
>>        burst_byte = burst_size ? burst_size * slave_bw : len;
>> +
>> +     /*
>> +      * Find the largest burst size that evenly divides the transfer length.
>> +      * The hardware requires the transfer length to be a multiple of the
>> +      * burst size - partial bursts are not supported.
>> +      */
>> +     burst_byte = min(burst_byte, 1U << __ffs(len));
>>        burst_mmio_width = burst_byte / 4;
>>
>>        if (burst_mmio_width < TEGRA_GPCDMA_MMIOSEQ_BURST_MIN)
>> --
>> 2.43.0
>>

Hi Frank,

Thanks for reviewing the patch.

The primary goal of this change is correctness. GPCDMA requires the programmed
burst size to evenly divide the transfer length; otherwise, the transfer can hang
due to an incomplete final burst.

While dmaengine_slave_config() allows clients to specify a maxburst based on
their FIFO configuration, DMAengine does not guarantee that every submitted
transfer length will be divisible by that value. Since clients may submit
arbitrary lengths, the driver must ensure the programmed burst size is valid
for each descriptor.

This change simply makes sure the burst we program does not exceed the
configured maxburst and divides the transfer length, so we don’t end up
programming something the hardware cannot handle.


Thanks,
Kartik

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

* Re: [PATCH] dmaengine: tegra: Fix burst size calculation
  2026-02-25  6:06   ` Kartik Rajput
@ 2026-02-25 20:06     ` Frank Li
  0 siblings, 0 replies; 4+ messages in thread
From: Frank Li @ 2026-02-25 20:06 UTC (permalink / raw)
  To: Kartik Rajput
  Cc: ldewangan, jonathanh, akhilrajeev, vkoul, Frank.Li,
	thierry.reding, digetx, pkunapuli, dmaengine, linux-tegra,
	linux-kernel, stable

On Wed, Feb 25, 2026 at 11:36:18AM +0530, Kartik Rajput wrote:
> On 25/02/26 03:48, Frank Li wrote:
> > External email: Use caution opening links or attachments
> >
> >
> > On Tue, Feb 24, 2026 at 02:04:54PM +0530, Kartik Rajput wrote:
> > > Currently, the Tegra GPC DMA hardware requires the transfer length to
> > > be a multiple of the max burst size configured for the channel. When a
> > > client requests a transfer where the length is not evenly divisible by
> > > the configured max burst size, the DMA hangs with partial burst at
> > > the end.
> > >
> > > Fix this by reducing the burst size to the largest power-of-2 value
> > > that evenly divides the transfer length. For example, a 40-byte
> > > transfer with a 16-byte max burst will now use an 8-byte burst
> > > (40 / 8 = 5 complete bursts) instead of causing a hang.
> > >
> > > This issue was observed with the PL011 UART driver where TX DMA
> > > transfers of arbitrary lengths were stuck.
> >
> > Suppose set burst size by UART driver through dma_config_slave. it depend
> > on uart's watermark settings.
> >
> > Optimaized method as your example is set first transfer burst length 32,
> > the second transfer is 8.
> >
> > Frank
> > >
> > > Fixes: ee17028009d4 ("dmaengine: tegra: Add tegra gpcdma driver")
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Kartik Rajput <kkartik@nvidia.com>
> > > ---
> > >   drivers/dma/tegra186-gpc-dma.c | 7 +++++++
> > >   1 file changed, 7 insertions(+)
> > >
> > > diff --git a/drivers/dma/tegra186-gpc-dma.c b/drivers/dma/tegra186-gpc-dma.c
> > > index 4d6fe0efa76e..7df0a745e7b8 100644
> > > --- a/drivers/dma/tegra186-gpc-dma.c
> > > +++ b/drivers/dma/tegra186-gpc-dma.c
> > > @@ -825,6 +825,13 @@ static unsigned int get_burst_size(struct tegra_dma_channel *tdc,
> > >         * len to calculate the optimum burst size
> > >         */
> > >        burst_byte = burst_size ? burst_size * slave_bw : len;
> > > +
> > > +     /*
> > > +      * Find the largest burst size that evenly divides the transfer length.
> > > +      * The hardware requires the transfer length to be a multiple of the
> > > +      * burst size - partial bursts are not supported.
> > > +      */
> > > +     burst_byte = min(burst_byte, 1U << __ffs(len));
> > >        burst_mmio_width = burst_byte / 4;
> > >
> > >        if (burst_mmio_width < TEGRA_GPCDMA_MMIOSEQ_BURST_MIN)
> > > --
> > > 2.43.0
> > >
>
> Hi Frank,
>
> Thanks for reviewing the patch.
>
> The primary goal of this change is correctness. GPCDMA requires the programmed
> burst size to evenly divide the transfer length; otherwise, the transfer can hang
> due to an incomplete final burst.
>
> While dmaengine_slave_config() allows clients to specify a maxburst based on
> their FIFO configuration, DMAengine does not guarantee that every submitted
> transfer length will be divisible by that value. Since clients may submit
> arbitrary lengths, the driver must ensure the programmed burst size is valid
> for each descriptor.
>
> This change simply makes sure the burst we program does not exceed the
> configured maxburst and divides the transfer length, so we don’t end up
> programming something the hardware cannot handle.

Okay, it is fine.

Reviewed-by: Frank Li <Frank.Li@nxp.com>
>
>
> Thanks,
> Kartik

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

end of thread, other threads:[~2026-02-25 20:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-24  8:34 [PATCH] dmaengine: tegra: Fix burst size calculation Kartik Rajput
2026-02-24 22:18 ` Frank Li
2026-02-25  6:06   ` Kartik Rajput
2026-02-25 20:06     ` Frank Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox