diff mbox series

spi: pxa2xx: Set controller->max_transfer_size in dma mode

Message ID 20191016195721.3714-1-daniel.vetter@ffwll.ch (mailing list archive)
State Superseded
Headers show
Series spi: pxa2xx: Set controller->max_transfer_size in dma mode | expand

Commit Message

Daniel Vetter Oct. 16, 2019, 7:57 p.m. UTC
In DMA mode we have a maximum transfer size, past that the driver
falls back to PIO (see the check at the top of pxa2xx_spi_transfer_one).
Falling back to PIO for big transfers defeats the point of a dma engine,
hence set the max transfer size to inform spi clients that they need
to do something smarter.

This was uncovered by the drm_mipi_dbi spi panel code, which does
large spi transfers, but stopped splitting them after:

commit e143364b4c1774f68e923a5a0bb0fca28ac25888
Author: Noralf Trønnes <noralf@tronnes.org>
Date:   Fri Jul 19 17:59:10 2019 +0200

    drm/tinydrm: Remove tinydrm_spi_max_transfer_size()

After this commit the code relied on the spi core to split transfers
into max dma-able blocks, which also papered over the PIO fallback issue.

Fix this by setting the overall max transfer size to the DMA limit,
but only when the controller runs in DMA mode.

Fixes: e143364b4c17 ("drm/tinydrm: Remove tinydrm_spi_max_transfer_size()")
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Noralf Trønnes <noralf@tronnes.org>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>
Reported-and-tested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Daniel Mack <daniel@zonque.org>
Cc: Haojian Zhuang <haojian.zhuang@gmail.com>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Mark Brown <broonie@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-spi@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/spi/spi-pxa2xx.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Noralf Trønnes Oct. 16, 2019, 9:30 p.m. UTC | #1
Den 16.10.2019 21.57, skrev Daniel Vetter:
> In DMA mode we have a maximum transfer size, past that the driver
> falls back to PIO (see the check at the top of pxa2xx_spi_transfer_one).
> Falling back to PIO for big transfers defeats the point of a dma engine,
> hence set the max transfer size to inform spi clients that they need
> to do something smarter.
> 
> This was uncovered by the drm_mipi_dbi spi panel code, which does
> large spi transfers, but stopped splitting them after:
> 
> commit e143364b4c1774f68e923a5a0bb0fca28ac25888
> Author: Noralf Trønnes <noralf@tronnes.org>
> Date:   Fri Jul 19 17:59:10 2019 +0200
> 
>     drm/tinydrm: Remove tinydrm_spi_max_transfer_size()
> 
> After this commit the code relied on the spi core to split transfers
> into max dma-able blocks, which also papered over the PIO fallback issue.
> 
> Fix this by setting the overall max transfer size to the DMA limit,
> but only when the controller runs in DMA mode.
> 
> Fixes: e143364b4c17 ("drm/tinydrm: Remove tinydrm_spi_max_transfer_size()")
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Cc: Andy Shevchenko <andriy.shevchenko@intel.com>
> Reported-and-tested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Cc: Daniel Mack <daniel@zonque.org>
> Cc: Haojian Zhuang <haojian.zhuang@gmail.com>
> Cc: Robert Jarzmik <robert.jarzmik@free.fr>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-spi@vger.kernel.org
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/spi/spi-pxa2xx.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
> index bb6a14d1ab0f..f77201915033 100644
> --- a/drivers/spi/spi-pxa2xx.c
> +++ b/drivers/spi/spi-pxa2xx.c
> @@ -1707,6 +1707,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
>  		} else {
>  			controller->can_dma = pxa2xx_spi_can_dma;
>  			controller->max_dma_len = MAX_DMA_LEN;
> +			controller->max_transfer_size = MAX_DMA_LEN;

As Andy mentioned, ->max_transfer_size is a callback:

struct spi_controller {
	/*
	 * on some hardware transfer / message size may be constrained
	 * the limit may depend on device transfer settings
	 */
	size_t (*max_transfer_size)(struct spi_device *spi);

(I looked at its users and they all return a static or probe time value
so not sure why it's a callback.)

Noralf.

>  		}
>  	}
>  
>
Mark Brown Oct. 16, 2019, 9:49 p.m. UTC | #2
On Wed, Oct 16, 2019 at 11:30:51PM +0200, Noralf Trønnes wrote:

> As Andy mentioned, ->max_transfer_size is a callback:

> struct spi_controller {
> 	/*
> 	 * on some hardware transfer / message size may be constrained
> 	 * the limit may depend on device transfer settings
> 	 */
> 	size_t (*max_transfer_size)(struct spi_device *spi);

> (I looked at its users and they all return a static or probe time value
> so not sure why it's a callback.)

Huh, I wonder why we did that...  I can't find any clear record, and
like you say nothing is using it so we should probably fix it - however
that's best done separately to this :/  Sorry for the confusion, I
didn't register what Andy was saying as being pointing out the current
state of the code.
diff mbox series

Patch

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index bb6a14d1ab0f..f77201915033 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -1707,6 +1707,7 @@  static int pxa2xx_spi_probe(struct platform_device *pdev)
 		} else {
 			controller->can_dma = pxa2xx_spi_can_dma;
 			controller->max_dma_len = MAX_DMA_LEN;
+			controller->max_transfer_size = MAX_DMA_LEN;
 		}
 	}