[PATCH v4 0/13] dmaengine: introduce sg_nents_for_dma() and convert users

Andy Shevchenko posted 13 patches 2 months, 2 weeks ago
There is a newer version of this series
drivers/dma/altera-msgdma.c                   |  5 ++--
drivers/dma/bcm2835-dma.c                     | 19 +-------------
drivers/dma/dma-axi-dmac.c                    |  5 +---
.../dma/dw-axi-dmac/dw-axi-dmac-platform.c    |  6 ++---
drivers/dma/k3dma.c                           |  9 ++-----
drivers/dma/lgm/lgm-dma.c                     |  9 ++-----
drivers/dma/pxa_dma.c                         |  5 ++--
drivers/dma/qcom/bam_dma.c                    |  9 ++-----
drivers/dma/qcom/qcom_adm.c                   |  9 +++----
drivers/dma/sa11x0-dma.c                      |  6 ++---
drivers/dma/sh/shdma-base.c                   |  5 ++--
drivers/dma/xilinx/xdma.c                     |  6 ++---
include/linux/scatterlist.h                   |  2 ++
lib/scatterlist.c                             | 26 +++++++++++++++++++
14 files changed, 52 insertions(+), 69 deletions(-)
[PATCH v4 0/13] dmaengine: introduce sg_nents_for_dma() and convert users
Posted by Andy Shevchenko 2 months, 2 weeks ago
A handful of the DMAengine drivers use same routine to calculate the number of
SG entries needed for the given DMA transfer. Provide a common helper for them
and convert.

I left the new helper on SG level of API because brief grepping shows potential
candidates outside of DMA engine, e.g.:

  drivers/crypto/chelsio/chcr_algo.c:154:  nents += DIV_ROUND_UP(less, entlen);
  drivers/spi/spi-stm32.c:1495:  /* Count the number of entries needed */

Changelog v4:
- fixed compilation errors (Vinod)

v3: <20251113151603.3031717-1-andriy.shevchenko@linux.intel.com>

Changelog v3:
- added missed EXPORT_SYMBOL() (Bjorn)
- left the return type as signed int (as agreed with Bjorn)
- collected tags (Bjorn)

v2: <20251110103805.3562136-1-andriy.shevchenko@linux.intel.com>

Changelog v2:
- dropped outdated patches (only 9 years passed :-)
- rebased on top of the current kernel
- left API SG wide It might

v1: https://patchwork.kernel.org/project/linux-dmaengine/patch/20161021173535.100245-1-andriy.shevchenko@linux.intel.com/

Andy Shevchenko (13):
  scatterlist: introduce sg_nents_for_dma() helper
  dmaengine: altera-msgdma: use sg_nents_for_dma() helper
  dmaengine: axi-dmac: use sg_nents_for_dma() helper
  dmaengine: bcm2835-dma: use sg_nents_for_dma() helper
  dmaengine: dw-axi-dmac: use sg_nents_for_dma() helper
  dmaengine: k3dma: use sg_nents_for_dma() helper
  dmaengine: lgm: use sg_nents_for_dma() helper
  dmaengine: pxa-dma: use sg_nents_for_dma() helper
  dmaengine: qcom: adm: use sg_nents_for_dma() helper
  dmaengine: qcom: bam_dma: use sg_nents_for_dma() helper
  dmaengine: sa11x0: use sg_nents_for_dma() helper
  dmaengine: sh: use sg_nents_for_dma() helper
  dmaengine: xilinx: xdma: use sg_nents_for_dma() helper

 drivers/dma/altera-msgdma.c                   |  5 ++--
 drivers/dma/bcm2835-dma.c                     | 19 +-------------
 drivers/dma/dma-axi-dmac.c                    |  5 +---
 .../dma/dw-axi-dmac/dw-axi-dmac-platform.c    |  6 ++---
 drivers/dma/k3dma.c                           |  9 ++-----
 drivers/dma/lgm/lgm-dma.c                     |  9 ++-----
 drivers/dma/pxa_dma.c                         |  5 ++--
 drivers/dma/qcom/bam_dma.c                    |  9 ++-----
 drivers/dma/qcom/qcom_adm.c                   |  9 +++----
 drivers/dma/sa11x0-dma.c                      |  6 ++---
 drivers/dma/sh/shdma-base.c                   |  5 ++--
 drivers/dma/xilinx/xdma.c                     |  6 ++---
 include/linux/scatterlist.h                   |  2 ++
 lib/scatterlist.c                             | 26 +++++++++++++++++++
 14 files changed, 52 insertions(+), 69 deletions(-)

-- 
2.50.1
Re: [PATCH v4 0/13] dmaengine: introduce sg_nents_for_dma() and convert users
Posted by Vinod Koul 1 month, 3 weeks ago
On 24-11-25, 13:09, Andy Shevchenko wrote:
> A handful of the DMAengine drivers use same routine to calculate the number of
> SG entries needed for the given DMA transfer. Provide a common helper for them
> and convert.
> 
> I left the new helper on SG level of API because brief grepping shows potential
> candidates outside of DMA engine, e.g.:
> 
>   drivers/crypto/chelsio/chcr_algo.c:154:  nents += DIV_ROUND_UP(less, entlen);
>   drivers/spi/spi-stm32.c:1495:  /* Count the number of entries needed */
> 
> Changelog v4:
> - fixed compilation errors (Vinod)

:-(

drivers/dma/altera-msgdma.c: In function ‘msgdma_prep_slave_sg’:
drivers/dma/altera-msgdma.c:399:29: error: unused variable ‘sg’ [-Werror=unused-variable]

Clearly your script is not working. I am surprised that you are not able
to compile these changes. Bit disappointed tbh!

-- 
~Vinod
Re: [PATCH v4 0/13] dmaengine: introduce sg_nents_for_dma() and convert users
Posted by Andy Shevchenko 4 weeks, 1 day ago
On Tue, Dec 16, 2025 at 06:41:44PM +0530, Vinod Koul wrote:
> On 24-11-25, 13:09, Andy Shevchenko wrote:
> > A handful of the DMAengine drivers use same routine to calculate the number of
> > SG entries needed for the given DMA transfer. Provide a common helper for them
> > and convert.
> > 
> > I left the new helper on SG level of API because brief grepping shows potential
> > candidates outside of DMA engine, e.g.:
> > 
> >   drivers/crypto/chelsio/chcr_algo.c:154:  nents += DIV_ROUND_UP(less, entlen);
> >   drivers/spi/spi-stm32.c:1495:  /* Count the number of entries needed */
> > 
> > Changelog v4:
> > - fixed compilation errors (Vinod)
> 
> :-(
> 
> drivers/dma/altera-msgdma.c: In function ‘msgdma_prep_slave_sg’:
> drivers/dma/altera-msgdma.c:399:29: error: unused variable ‘sg’ [-Werror=unused-variable]
> 
> Clearly your script is not working. I am surprised that you are not able
> to compile these changes. Bit disappointed tbh!

This is W=1 build with WERROR=y, yet I agree that I must have tested this as
well. Sorry, I will do v5 with carefully tested all modules to be compiled
with `make W=1`.

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH v4 0/13] dmaengine: introduce sg_nents_for_dma() and convert users
Posted by Vinod Koul 4 weeks ago
On 08-01-26, 08:46, Andy Shevchenko wrote:
> On Tue, Dec 16, 2025 at 06:41:44PM +0530, Vinod Koul wrote:
> > On 24-11-25, 13:09, Andy Shevchenko wrote:
> > > A handful of the DMAengine drivers use same routine to calculate the number of
> > > SG entries needed for the given DMA transfer. Provide a common helper for them
> > > and convert.
> > > 
> > > I left the new helper on SG level of API because brief grepping shows potential
> > > candidates outside of DMA engine, e.g.:
> > > 
> > >   drivers/crypto/chelsio/chcr_algo.c:154:  nents += DIV_ROUND_UP(less, entlen);
> > >   drivers/spi/spi-stm32.c:1495:  /* Count the number of entries needed */
> > > 
> > > Changelog v4:
> > > - fixed compilation errors (Vinod)
> > 
> > :-(
> > 
> > drivers/dma/altera-msgdma.c: In function ‘msgdma_prep_slave_sg’:
> > drivers/dma/altera-msgdma.c:399:29: error: unused variable ‘sg’ [-Werror=unused-variable]
> > 
> > Clearly your script is not working. I am surprised that you are not able
> > to compile these changes. Bit disappointed tbh!
> 
> This is W=1 build with WERROR=y, yet I agree that I must have tested this as
> well. Sorry, I will do v5 with carefully tested all modules to be compiled
> with `make W=1`.

I turned on in by builds after it was enabled mainline... so yes now it
is part of my tests

-- 
~Vinod
Re: [PATCH v4 0/13] dmaengine: introduce sg_nents_for_dma() and convert users
Posted by Vinod Koul 4 weeks ago
On Mon, 24 Nov 2025 13:09:18 +0100, Andy Shevchenko wrote:
> A handful of the DMAengine drivers use same routine to calculate the number of
> SG entries needed for the given DMA transfer. Provide a common helper for them
> and convert.
> 
> I left the new helper on SG level of API because brief grepping shows potential
> candidates outside of DMA engine, e.g.:
> 
> [...]

Applied, thanks!

[01/13] scatterlist: introduce sg_nents_for_dma() helper
        commit: 80c70bfb95cdbe0c644070f4ca4754a60f0a4830
[02/13] dmaengine: altera-msgdma: use sg_nents_for_dma() helper
        commit: 47f5cb7878cc62ed95981c5d02862b253eddb590
[03/13] dmaengine: axi-dmac: use sg_nents_for_dma() helper
        commit: 024ae9d3092c425f3ea6eae92086a2001ca2e0c7
[04/13] dmaengine: bcm2835-dma: use sg_nents_for_dma() helper
        commit: 39110c68500a149664bafb0c174baef0d42e2129
[05/13] dmaengine: dw-axi-dmac: use sg_nents_for_dma() helper
        commit: 5d6ceb254fa9ac1f50932c42a0a9a8bedaa3190d
[06/13] dmaengine: k3dma: use sg_nents_for_dma() helper
        commit: 3fc49d21f3a46866724ff8ef8a79c6e2cd9d7676
[07/13] dmaengine: lgm: use sg_nents_for_dma() helper
        commit: f9b0274f53a2d464e71f37e8f4d0d0dc41321259
[08/13] dmaengine: pxa-dma: use sg_nents_for_dma() helper
        commit: 068942eaa232ba752b744d98ff8ab22b26c8bff4
[09/13] dmaengine: qcom: adm: use sg_nents_for_dma() helper
        commit: 425f871d7acdb521d67c2578e6ae688a751d1e80
[10/13] dmaengine: qcom: bam_dma: use sg_nents_for_dma() helper
        commit: 107fdf0c4e944030bf544aea98e8ae8537914177
[11/13] dmaengine: sa11x0: use sg_nents_for_dma() helper
        commit: d7785661010e2fe113aec2500f988a8e73ac3e7b
[12/13] dmaengine: sh: use sg_nents_for_dma() helper
        commit: ac326dca6870f0d8e0787e94b1d9c2c91bb358d7
[13/13] dmaengine: xilinx: xdma: use sg_nents_for_dma() helper
        commit: 3c8a86ed002ab8fb287ee4ec92f0fd6ac5b291d2

Best regards,
-- 
~Vinod