Skip to contentSkip to conversation

dmaengine: tegra186: Fix residual calculation

PATCH Superseded Akhil R 2 participants 2 messages Feb 29, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Akhil R

author
#0 lore raw

PATCH 1/1 dmaengine: tegra186: Fix residual calculation

The exisiting residual calculation returns an incorrect value when bytes_xfer == bytes_req. This scenario occurs particularly with drivers like UART where DMA is scheduled for maximum number of bytes and is terminated when the bytes inflow stops. At higher baud rates, it could request the tx_status while there is no bytes left to transfer. This will lead to incorrect residual being set. Hence return residual as '0' when bytes transferred equals to the bytes requested.

Fixes ee17028009d4 ("dmaengine: tegra: Add tegra gpcdma driver")
---
 drivers/dma/tegra186-gpc-dma.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/dma/tegra186-gpc-dma.c +3 -0
index 88547a23825b..3642508e88bb 100644
@@ -746,6 +746,9 @@ static int tegra_dma_get_residual(struct tegra_dma_channel *tdc)
 	bytes_xfer = dma_desc->bytes_xfer +
 		     sg_req[dma_desc->sg_idx].len - (wcount * 4);
 
+	if (dma_desc->bytes_req == bytes_xfer)
+		return 0;
+
 	residual = dma_desc->bytes_req - (bytes_xfer % dma_desc->bytes_req);
 
 	return residual;
Signature · 1 line
2.43.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Akhil R

The exisiting residual calculation returns an incorrect value when

s/exisiting/existing/

Quoted 18 lines

bytes_xfer == bytes_req. This scenario occurs particularly with drivers like UART where DMA is scheduled for maximum number of bytes and is terminated when the bytes inflow stops. At higher baud rates, it could request the tx_status while there is no bytes left to transfer. This will lead to incorrect residual being set. Hence return residual as '0' when bytes transferred equals to the bytes requested.

Fixes ee17028009d4 ("dmaengine: tegra: Add tegra gpcdma driver")
---
  drivers/dma/tegra186-gpc-dma.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/dma/tegra186-gpc-dma.c +0 -0
index 88547a23825b..3642508e88bb 100644

drivers/dma/tegra186-gpc-dma.c static int tegra_dma_get_residual(struct tegra_dma_channel *tdc) · line 754

Quoted 9 lines
drivers/dma/tegra186-gpc-dma.c +3 -0
@@ -746,6 +746,9 @@ static int tegra_dma_get_residual(struct tegra_dma_channel *tdc)
  	bytes_xfer = dma_desc->bytes_xfer +
  		     sg_req[dma_desc->sg_idx].len - (wcount * 4);
 
+	if (dma_desc->bytes_req == bytes_xfer)
+		return 0;
+
  	residual = dma_desc->bytes_req - (bytes_xfer % dma_desc->bytes_req);
 
  	return residual;

Thanks! Apart from the typo, looks good to me ...

Jon

Signature · 1 line
nvpublic