DMA Engine development
 help / color / mirror / Atom feed
* [PATCH] dmaengine: switchtec-dma: fix FIELD_GET misuse when programming SE threshold
@ 2026-03-17  8:32 David Carlier
  2026-03-27 17:00 ` Logan Gunthorpe
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Carlier @ 2026-03-17  8:32 UTC (permalink / raw)
  To: Kelvin Cao, Logan Gunthorpe, Vinod Koul; +Cc: dmaengine, David Carlier

FIELD_GET(SE_THRESH_MASK, thresh) extracts bits [31:23] from thresh and
right-shifts them, which is the inverse of the intended operation. Since
thresh is derived from se_buf_len / 2 (at most 255), bits [31:23] are
always zero, so the SE threshold is never actually programmed into the
register.

Use FIELD_PREP() instead to correctly left-shift thresh into bits [31:23]
of the valid_en_se register, consistent with the FIELD_PREP usage for
the perf tuner config just above.

Fixes: 30eba9df76ad ("dmaengine: switchtec-dma: Implement hardware initialization and cleanup")
Signed-off-by: David Carlier <devnexen@gmail.com>
---
 drivers/dma/switchtec_dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
index 3ef928640615..71d9868ce613 100644
--- a/drivers/dma/switchtec_dma.c
+++ b/drivers/dma/switchtec_dma.c
@@ -1099,7 +1099,7 @@ static int switchtec_dma_chan_init(struct switchtec_dma_dev *swdma_dev,
 	dev_dbg(&pdev->dev, "Channel %d: SE buffer count %d\n", i, se_buf_len);
 
 	thresh = se_buf_len / 2;
-	valid_en_se |= FIELD_GET(SE_THRESH_MASK, thresh);
+	valid_en_se |= FIELD_PREP(SE_THRESH_MASK, thresh);
 	writel(valid_en_se, &swdma_chan->mmio_chan_fw->valid_en_se);
 
 	/* request irqs */
-- 
2.53.0


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

* Re: [PATCH] dmaengine: switchtec-dma: fix FIELD_GET misuse when programming SE threshold
  2026-03-17  8:32 [PATCH] dmaengine: switchtec-dma: fix FIELD_GET misuse when programming SE threshold David Carlier
@ 2026-03-27 17:00 ` Logan Gunthorpe
  2026-03-30 15:03 ` Frank Li
  2026-05-21 21:22 ` David Carlier
  2 siblings, 0 replies; 4+ messages in thread
From: Logan Gunthorpe @ 2026-03-27 17:00 UTC (permalink / raw)
  To: David Carlier, Kelvin Cao, Vinod Koul; +Cc: dmaengine



On 2026-03-17 2:32 a.m., David Carlier wrote:
> FIELD_GET(SE_THRESH_MASK, thresh) extracts bits [31:23] from thresh and
> right-shifts them, which is the inverse of the intended operation. Since
> thresh is derived from se_buf_len / 2 (at most 255), bits [31:23] are
> always zero, so the SE threshold is never actually programmed into the
> register.
> 
> Use FIELD_PREP() instead to correctly left-shift thresh into bits [31:23]
> of the valid_en_se register, consistent with the FIELD_PREP usage for
> the perf tuner config just above.
> 
> Fixes: 30eba9df76ad ("dmaengine: switchtec-dma: Implement hardware initialization and cleanup")
> Signed-off-by: David Carlier <devnexen@gmail.com>

Sorry for the delay for me to look at this, I just got back from vacation.

Butt yes this looks correct.

Thanks for the quick catch on that mistake!

Review-by: Logan Gunthorpe <logang@deltatee.com>


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

* Re: [PATCH] dmaengine: switchtec-dma: fix FIELD_GET misuse when programming SE threshold
  2026-03-17  8:32 [PATCH] dmaengine: switchtec-dma: fix FIELD_GET misuse when programming SE threshold David Carlier
  2026-03-27 17:00 ` Logan Gunthorpe
@ 2026-03-30 15:03 ` Frank Li
  2026-05-21 21:22 ` David Carlier
  2 siblings, 0 replies; 4+ messages in thread
From: Frank Li @ 2026-03-30 15:03 UTC (permalink / raw)
  To: David Carlier; +Cc: Kelvin Cao, Logan Gunthorpe, Vinod Koul, dmaengine

On Tue, Mar 17, 2026 at 08:32:52AM +0000, David Carlier wrote:
> FIELD_GET(SE_THRESH_MASK, thresh) extracts bits [31:23] from thresh and
> right-shifts them, which is the inverse of the intended operation. Since
> thresh is derived from se_buf_len / 2 (at most 255), bits [31:23] are
> always zero, so the SE threshold is never actually programmed into the
> register.
>
> Use FIELD_PREP() instead to correctly left-shift thresh into bits [31:23]
> of the valid_en_se register, consistent with the FIELD_PREP usage for
> the perf tuner config just above.
>
> Fixes: 30eba9df76ad ("dmaengine: switchtec-dma: Implement hardware initialization and cleanup")
> Signed-off-by: David Carlier <devnexen@gmail.com>
> ---

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

>  drivers/dma/switchtec_dma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
> index 3ef928640615..71d9868ce613 100644
> --- a/drivers/dma/switchtec_dma.c
> +++ b/drivers/dma/switchtec_dma.c
> @@ -1099,7 +1099,7 @@ static int switchtec_dma_chan_init(struct switchtec_dma_dev *swdma_dev,
>  	dev_dbg(&pdev->dev, "Channel %d: SE buffer count %d\n", i, se_buf_len);
>
>  	thresh = se_buf_len / 2;
> -	valid_en_se |= FIELD_GET(SE_THRESH_MASK, thresh);
> +	valid_en_se |= FIELD_PREP(SE_THRESH_MASK, thresh);
>  	writel(valid_en_se, &swdma_chan->mmio_chan_fw->valid_en_se);
>
>  	/* request irqs */
> --
> 2.53.0
>

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

* Re: [PATCH] dmaengine: switchtec-dma: fix FIELD_GET misuse when programming SE threshold
  2026-03-17  8:32 [PATCH] dmaengine: switchtec-dma: fix FIELD_GET misuse when programming SE threshold David Carlier
  2026-03-27 17:00 ` Logan Gunthorpe
  2026-03-30 15:03 ` Frank Li
@ 2026-05-21 21:22 ` David Carlier
  2 siblings, 0 replies; 4+ messages in thread
From: David Carlier @ 2026-05-21 21:22 UTC (permalink / raw)
  To: vkoul; +Cc: kelvin.cao, logang, Frank.Li, dmaengine, linux-kernel,
	David Carlier

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

Hi Vinod,

Following up on this one-line fix. The bug is still present in
linux-next as of next-20260521 at drivers/dma/switchtec_dma.c:1102 —
FIELD_GET extracts a zero from the 9-bit thresh value against the
bits 23-31 mask, so the SE threshold field is never actually written.

Original posting:
https://lore.kernel.org/dmaengine/20260317083252.13224-1-devnexen@gmail.com/

Thanks,
David

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

end of thread, other threads:[~2026-05-21 21:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17  8:32 [PATCH] dmaengine: switchtec-dma: fix FIELD_GET misuse when programming SE threshold David Carlier
2026-03-27 17:00 ` Logan Gunthorpe
2026-03-30 15:03 ` Frank Li
2026-05-21 21:22 ` David Carlier

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