All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
@ 2022-11-16 16:49 ` Marc Kleine-Budde
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2022-11-16 16:49 UTC (permalink / raw)
  To: Mark Brown, linux-spi
  Cc: kernel, Shawn Guo, NXP Linux Team, linux-arm-kernel,
	Marc Kleine-Budde, Frieder Schrempf, Fabio Estevam, David Jander,
	stable

The SPI framework checks for each transfer (with the struct
spi_controller::can_dma callback) whether the driver wants to use DMA
for the transfer. If the driver returns true, the SPI framework will
map the transfer's data to the device, start the actual transfer and
map the data back.

In commit 07e759387788 ("spi: spi-imx: add PIO polling support") the
spi-imx driver's spi_imx_transfer_one() function was extended. If the
estimated duration of a transfer does not exceed a configurable
duration, a polling transfer function is used. This check happens
before checking if the driver decided earlier for a DMA transfer.

If spi_imx_can_dma() decided to use a DMA transfer, and the user
configured a big maximum polling duration, a polling transfer will be
used. The DMA unmap after the transfer destroys the transferred data.

To fix this problem check in spi_imx_transfer_one() if the driver
decided for DMA transfer first, then check the limits for a polling
transfer.

Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")
Link: https://lore.kernel.org/all/20221111003032.82371-1-festevam@gmail.com
Reported-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Reported-by: Fabio Estevam <festevam@gmail.com>
Tested-by: Fabio Estevam <festevam@gmail.com>
Cc: David Jander <david@protonic.nl>
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/spi/spi-imx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 30d82cc7300b..3240c139f8f3 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -1607,6 +1607,13 @@ static int spi_imx_transfer_one(struct spi_controller *controller,
 	if (spi_imx->slave_mode)
 		return spi_imx_pio_transfer_slave(spi, transfer);
 
+	/*
+	 * If we decided in spi_imx_can_dma() that we want to do a DMA
+	 * transfer, the SPI transfer has already been mapped, so we
+	 * have to do the DMA transfer here.
+	 */
+	if (spi_imx->usedma)
+		return spi_imx_dma_transfer(spi_imx, transfer);
 	/*
 	 * Calculate the estimated time in us the transfer runs. Find
 	 * the number of Hz per byte per polling limit.
@@ -1618,9 +1625,6 @@ static int spi_imx_transfer_one(struct spi_controller *controller,
 	if (transfer->len < byte_limit)
 		return spi_imx_poll_transfer(spi, transfer);
 
-	if (spi_imx->usedma)
-		return spi_imx_dma_transfer(spi_imx, transfer);
-
 	return spi_imx_pio_transfer(spi, transfer);
 }
 
-- 
2.35.1



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

* [PATCH] spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
@ 2022-11-16 16:49 ` Marc Kleine-Budde
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2022-11-16 16:49 UTC (permalink / raw)
  To: Mark Brown, linux-spi
  Cc: kernel, Shawn Guo, NXP Linux Team, linux-arm-kernel,
	Marc Kleine-Budde, Frieder Schrempf, Fabio Estevam, David Jander,
	stable

The SPI framework checks for each transfer (with the struct
spi_controller::can_dma callback) whether the driver wants to use DMA
for the transfer. If the driver returns true, the SPI framework will
map the transfer's data to the device, start the actual transfer and
map the data back.

In commit 07e759387788 ("spi: spi-imx: add PIO polling support") the
spi-imx driver's spi_imx_transfer_one() function was extended. If the
estimated duration of a transfer does not exceed a configurable
duration, a polling transfer function is used. This check happens
before checking if the driver decided earlier for a DMA transfer.

If spi_imx_can_dma() decided to use a DMA transfer, and the user
configured a big maximum polling duration, a polling transfer will be
used. The DMA unmap after the transfer destroys the transferred data.

To fix this problem check in spi_imx_transfer_one() if the driver
decided for DMA transfer first, then check the limits for a polling
transfer.

Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")
Link: https://lore.kernel.org/all/20221111003032.82371-1-festevam@gmail.com
Reported-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Reported-by: Fabio Estevam <festevam@gmail.com>
Tested-by: Fabio Estevam <festevam@gmail.com>
Cc: David Jander <david@protonic.nl>
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/spi/spi-imx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 30d82cc7300b..3240c139f8f3 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -1607,6 +1607,13 @@ static int spi_imx_transfer_one(struct spi_controller *controller,
 	if (spi_imx->slave_mode)
 		return spi_imx_pio_transfer_slave(spi, transfer);
 
+	/*
+	 * If we decided in spi_imx_can_dma() that we want to do a DMA
+	 * transfer, the SPI transfer has already been mapped, so we
+	 * have to do the DMA transfer here.
+	 */
+	if (spi_imx->usedma)
+		return spi_imx_dma_transfer(spi_imx, transfer);
 	/*
 	 * Calculate the estimated time in us the transfer runs. Find
 	 * the number of Hz per byte per polling limit.
@@ -1618,9 +1625,6 @@ static int spi_imx_transfer_one(struct spi_controller *controller,
 	if (transfer->len < byte_limit)
 		return spi_imx_poll_transfer(spi, transfer);
 
-	if (spi_imx->usedma)
-		return spi_imx_dma_transfer(spi_imx, transfer);
-
 	return spi_imx_pio_transfer(spi, transfer);
 }
 
-- 
2.35.1



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
  2022-11-16 16:49 ` Marc Kleine-Budde
@ 2022-11-16 17:03   ` Frieder Schrempf
  -1 siblings, 0 replies; 6+ messages in thread
From: Frieder Schrempf @ 2022-11-16 17:03 UTC (permalink / raw)
  To: Marc Kleine-Budde, Mark Brown, linux-spi
  Cc: kernel, Shawn Guo, NXP Linux Team, linux-arm-kernel,
	Fabio Estevam, David Jander, stable

On 16.11.22 17:49, Marc Kleine-Budde wrote:
> The SPI framework checks for each transfer (with the struct
> spi_controller::can_dma callback) whether the driver wants to use DMA
> for the transfer. If the driver returns true, the SPI framework will
> map the transfer's data to the device, start the actual transfer and
> map the data back.
> 
> In commit 07e759387788 ("spi: spi-imx: add PIO polling support") the
> spi-imx driver's spi_imx_transfer_one() function was extended. If the
> estimated duration of a transfer does not exceed a configurable
> duration, a polling transfer function is used. This check happens
> before checking if the driver decided earlier for a DMA transfer.
> 
> If spi_imx_can_dma() decided to use a DMA transfer, and the user
> configured a big maximum polling duration, a polling transfer will be
> used. The DMA unmap after the transfer destroys the transferred data.
> 
> To fix this problem check in spi_imx_transfer_one() if the driver
> decided for DMA transfer first, then check the limits for a polling
> transfer.
> 
> Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")
> Link: https://lore.kernel.org/all/20221111003032.82371-1-festevam@gmail.com
> Reported-by: Frieder Schrempf <frieder.schrempf@kontron.de>
> Reported-by: Fabio Estevam <festevam@gmail.com>
> Tested-by: Fabio Estevam <festevam@gmail.com>
> Cc: David Jander <david@protonic.nl>
> Cc: stable@vger.kernel.org
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

Tested-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

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

* Re: [PATCH] spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
@ 2022-11-16 17:03   ` Frieder Schrempf
  0 siblings, 0 replies; 6+ messages in thread
From: Frieder Schrempf @ 2022-11-16 17:03 UTC (permalink / raw)
  To: Marc Kleine-Budde, Mark Brown, linux-spi
  Cc: kernel, Shawn Guo, NXP Linux Team, linux-arm-kernel,
	Fabio Estevam, David Jander, stable

On 16.11.22 17:49, Marc Kleine-Budde wrote:
> The SPI framework checks for each transfer (with the struct
> spi_controller::can_dma callback) whether the driver wants to use DMA
> for the transfer. If the driver returns true, the SPI framework will
> map the transfer's data to the device, start the actual transfer and
> map the data back.
> 
> In commit 07e759387788 ("spi: spi-imx: add PIO polling support") the
> spi-imx driver's spi_imx_transfer_one() function was extended. If the
> estimated duration of a transfer does not exceed a configurable
> duration, a polling transfer function is used. This check happens
> before checking if the driver decided earlier for a DMA transfer.
> 
> If spi_imx_can_dma() decided to use a DMA transfer, and the user
> configured a big maximum polling duration, a polling transfer will be
> used. The DMA unmap after the transfer destroys the transferred data.
> 
> To fix this problem check in spi_imx_transfer_one() if the driver
> decided for DMA transfer first, then check the limits for a polling
> transfer.
> 
> Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")
> Link: https://lore.kernel.org/all/20221111003032.82371-1-festevam@gmail.com
> Reported-by: Frieder Schrempf <frieder.schrempf@kontron.de>
> Reported-by: Fabio Estevam <festevam@gmail.com>
> Tested-by: Fabio Estevam <festevam@gmail.com>
> Cc: David Jander <david@protonic.nl>
> Cc: stable@vger.kernel.org
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

Tested-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
  2022-11-16 16:49 ` Marc Kleine-Budde
@ 2022-11-18 14:16   ` Mark Brown
  -1 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2022-11-18 14:16 UTC (permalink / raw)
  To: linux-spi, Marc Kleine-Budde
  Cc: stable, Shawn Guo, Fabio Estevam, linux-arm-kernel, David Jander,
	NXP Linux Team, Frieder Schrempf, kernel

On Wed, 16 Nov 2022 17:49:30 +0100, Marc Kleine-Budde wrote:
> The SPI framework checks for each transfer (with the struct
> spi_controller::can_dma callback) whether the driver wants to use DMA
> for the transfer. If the driver returns true, the SPI framework will
> map the transfer's data to the device, start the actual transfer and
> map the data back.
> 
> In commit 07e759387788 ("spi: spi-imx: add PIO polling support") the
> spi-imx driver's spi_imx_transfer_one() function was extended. If the
> estimated duration of a transfer does not exceed a configurable
> duration, a polling transfer function is used. This check happens
> before checking if the driver decided earlier for a DMA transfer.
> 
> [...]

Applied to

   broonie/spi.git for-next

Thanks!

[1/1] spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
      commit: e85e9e0d8cb759013d6474011c227f92e442d746

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

* Re: [PATCH] spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
@ 2022-11-18 14:16   ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2022-11-18 14:16 UTC (permalink / raw)
  To: linux-spi, Marc Kleine-Budde
  Cc: stable, Shawn Guo, Fabio Estevam, linux-arm-kernel, David Jander,
	NXP Linux Team, Frieder Schrempf, kernel

On Wed, 16 Nov 2022 17:49:30 +0100, Marc Kleine-Budde wrote:
> The SPI framework checks for each transfer (with the struct
> spi_controller::can_dma callback) whether the driver wants to use DMA
> for the transfer. If the driver returns true, the SPI framework will
> map the transfer's data to the device, start the actual transfer and
> map the data back.
> 
> In commit 07e759387788 ("spi: spi-imx: add PIO polling support") the
> spi-imx driver's spi_imx_transfer_one() function was extended. If the
> estimated duration of a transfer does not exceed a configurable
> duration, a polling transfer function is used. This check happens
> before checking if the driver decided earlier for a DMA transfer.
> 
> [...]

Applied to

   broonie/spi.git for-next

Thanks!

[1/1] spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
      commit: e85e9e0d8cb759013d6474011c227f92e442d746

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-11-18 14:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 16:49 [PATCH] spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first Marc Kleine-Budde
2022-11-16 16:49 ` Marc Kleine-Budde
2022-11-16 17:03 ` Frieder Schrempf
2022-11-16 17:03   ` Frieder Schrempf
2022-11-18 14:16 ` Mark Brown
2022-11-18 14:16   ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.