linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] spi: Fix problem with interrupted slave transmission
@ 2019-09-24 11:05 Lukasz Majewski
  2019-09-24 11:05 ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Lukasz Majewski @ 2019-09-24 11:05 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, krzk, Lukasz Majewski

This patch series fixes problem with recovering Vybrid's NXP DSPI
controller state after master transmission distortion.

It was tested with a setup where /dev/spidevX.Y devices were used in
a loopback mode (provided by proper HW connections). During this test
the distortion was introduced and the system was assessed if it is
possible to continue correct SPI transmission.

This series applies clearly on v5.2 (tag) and current mainline:
SHA1: 4c07e2ddab5b6b57dbcb09aedbda1f484d5940cc

Lukasz Majewski (2):
  spi: Add call to spi_slave_abort() function when spidev driver is
    released
  spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver

 drivers/spi/spi-fsl-dspi.c | 20 ++++++++++++++++++++
 drivers/spi/spidev.c       |  1 +
 2 files changed, 21 insertions(+)

-- 
2.20.1


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

* [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
  2019-09-24 11:05 [PATCH 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
@ 2019-09-24 11:05 ` Lukasz Majewski
  2019-09-24 20:08   ` Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree Mark Brown
  2019-09-26  6:52   ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Geert Uytterhoeven
  2019-09-24 11:05 ` [PATCH 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver Lukasz Majewski
  2019-09-25  9:11 ` [PATCH v2 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
  2 siblings, 2 replies; 13+ messages in thread
From: Lukasz Majewski @ 2019-09-24 11:05 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, krzk, Lukasz Majewski

This change is necessary for spidev devices (e.g. /dev/spidev3.0) working
in the slave mode (like NXP's dspi driver for Vybrid SoC).

When SPI HW works in this mode - the master is responsible for providing
CS and CLK signals. However, when some fault happens - like for example
distortion on SPI lines - the SPI Linux driver needs a chance to recover
from this abnormal situation and prepare itself for next (correct)
transmission.

This change doesn't pose any threat on drivers working in master mode as
spi_slave_abort() function checks if SPI slave mode is supported.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
---
 drivers/spi/spidev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 255786f2e844..fe9ea7e55e5b 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -627,6 +627,7 @@ static int spidev_release(struct inode *inode, struct file *filp)
 		if (dofree)
 			kfree(spidev);
 	}
+	spi_slave_abort(spidev->spi);
 	mutex_unlock(&device_list_lock);
 
 	return 0;
-- 
2.20.1


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

* [PATCH 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver
  2019-09-24 11:05 [PATCH 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
  2019-09-24 11:05 ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
@ 2019-09-24 11:05 ` Lukasz Majewski
  2019-10-01 11:41   ` Applied "spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver" to the spi tree Mark Brown
  2019-09-25  9:11 ` [PATCH v2 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
  2 siblings, 1 reply; 13+ messages in thread
From: Lukasz Majewski @ 2019-09-24 11:05 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, krzk, Lukasz Majewski

This change provides the dspi_slave_abort() function, which is a callback
for slave_abort() method of SPI controller generic driver.

As in the SPI slave mode the transmission is driven by master, any
distortion may cause the slave to enter undefined internal state.
To avoid this problem the dspi_slave_abort() terminates all pending and
ongoing DMA transactions (with sync) and clears internal FIFOs.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
---
 drivers/spi/spi-fsl-dspi.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index bec758e978fb..2c0f211eed87 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -1006,6 +1006,25 @@ static void dspi_init(struct fsl_dspi *dspi)
 			     SPI_CTARE_FMSZE(0) | SPI_CTARE_DTCP(1));
 }
 
+static int dspi_slave_abort(struct spi_master *master)
+{
+	struct fsl_dspi *dspi = spi_master_get_devdata(master);
+
+	/*
+	 * Terminate all pending DMA transactions for the SPI working
+	 * in SLAVE mode.
+	 */
+	dmaengine_terminate_sync(dspi->dma->chan_rx);
+	dmaengine_terminate_sync(dspi->dma->chan_tx);
+
+	/* Clear the internal DSPI RX and TX FIFO buffers */
+	regmap_update_bits(dspi->regmap, SPI_MCR,
+			   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF,
+			   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF);
+
+	return 0;
+}
+
 static int dspi_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -1030,6 +1049,7 @@ static int dspi_probe(struct platform_device *pdev)
 	ctlr->dev.of_node = pdev->dev.of_node;
 
 	ctlr->cleanup = dspi_cleanup;
+	ctlr->slave_abort = dspi_slave_abort;
 	ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
 
 	pdata = dev_get_platdata(&pdev->dev);
-- 
2.20.1


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

* Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree
  2019-09-24 11:05 ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
@ 2019-09-24 20:08   ` Mark Brown
  2019-09-26  6:52   ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Geert Uytterhoeven
  1 sibling, 0 replies; 13+ messages in thread
From: Mark Brown @ 2019-09-24 20:08 UTC (permalink / raw)
  To: Lukasz Majewski; +Cc: krzk, linux-kernel, linux-spi, Mark Brown

The patch

   spi: Add call to spi_slave_abort() function when spidev driver is released

has been applied to the spi tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-5.4

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

From bf390d25e03b38248a0a4f7d0002bbb495a82fe9 Mon Sep 17 00:00:00 2001
From: Lukasz Majewski <lukma@denx.de>
Date: Tue, 24 Sep 2019 13:05:46 +0200
Subject: [PATCH] spi: Add call to spi_slave_abort() function when spidev
 driver is released

This change is necessary for spidev devices (e.g. /dev/spidev3.0) working
in the slave mode (like NXP's dspi driver for Vybrid SoC).

When SPI HW works in this mode - the master is responsible for providing
CS and CLK signals. However, when some fault happens - like for example
distortion on SPI lines - the SPI Linux driver needs a chance to recover
from this abnormal situation and prepare itself for next (correct)
transmission.

This change doesn't pose any threat on drivers working in master mode as
spi_slave_abort() function checks if SPI slave mode is supported.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Link: https://lore.kernel.org/r/20190924110547.14770-2-lukma@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/spi/spidev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 255786f2e844..fe9ea7e55e5b 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -627,6 +627,7 @@ static int spidev_release(struct inode *inode, struct file *filp)
 		if (dofree)
 			kfree(spidev);
 	}
+	spi_slave_abort(spidev->spi);
 	mutex_unlock(&device_list_lock);
 
 	return 0;
-- 
2.20.1


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

* [PATCH v2 0/2] spi: Fix problem with interrupted slave transmission
  2019-09-24 11:05 [PATCH 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
  2019-09-24 11:05 ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
  2019-09-24 11:05 ` [PATCH 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver Lukasz Majewski
@ 2019-09-25  9:11 ` Lukasz Majewski
  2019-09-25  9:11   ` [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
  2019-09-25  9:11   ` [PATCH v2 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver Lukasz Majewski
  2 siblings, 2 replies; 13+ messages in thread
From: Lukasz Majewski @ 2019-09-25  9:11 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, krzk, Lukasz Majewski

This patch series fixes problem with recovering Vybrid's NXP DSPI
controller state after master transmission distortion.

It was tested with a setup where /dev/spidevX.Y devices were used in
a loopback mode (provided by proper HW connections). During this test
the distortion was introduced and the system was assessed if it is
possible to continue correct SPI transmission.

This series applies clearly on v5.2 (tag) and current mainline:
SHA1: 351c8a09b00b5c51c8f58b016fffe51f87e2d820

Lukasz Majewski (2):
  spi: Add call to spi_slave_abort() function when spidev driver is
    released
  spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver

 drivers/spi/spi-fsl-dspi.c | 20 ++++++++++++++++++++
 drivers/spi/spidev.c       |  3 +++
 2 files changed, 23 insertions(+)

-- 
2.20.1


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

* [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
  2019-09-25  9:11 ` [PATCH v2 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
@ 2019-09-25  9:11   ` Lukasz Majewski
  2019-09-25 16:45     ` Mark Brown
  2019-09-25 16:47     ` Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree Mark Brown
  2019-09-25  9:11   ` [PATCH v2 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver Lukasz Majewski
  1 sibling, 2 replies; 13+ messages in thread
From: Lukasz Majewski @ 2019-09-25  9:11 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, krzk, Lukasz Majewski

This change is necessary for spidev devices (e.g. /dev/spidev3.0) working
in the slave mode (like NXP's dspi driver for Vybrid SoC).

When SPI HW works in this mode - the master is responsible for providing
CS and CLK signals. However, when some fault happens - like for example
distortion on SPI lines - the SPI Linux driver needs a chance to recover
from this abnormal situation and prepare itself for next (correct)
transmission.

This change doesn't pose any threat on drivers working in master mode as
spi_slave_abort() function checks if SPI slave mode is supported.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Link: https://lore.kernel.org/r/20190924110547.14770-2-lukma@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
Reported-by: kbuild test robot <lkp@intel.com>

---
Changes for v2:
- Add #ifdef CONFIG_SPI_SLAVE to not compile in spi_slave_abort() on systems
  which are only using master mode.
  (The spi_slave_abort() is 'protected' by this Kconfig define in drivers/spi.c
  file).
  This error was spotted by kbuild test robot from Intel.
---
 drivers/spi/spidev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 255786f2e844..3ea9d8a3e6e8 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -627,6 +627,9 @@ static int spidev_release(struct inode *inode, struct file *filp)
 		if (dofree)
 			kfree(spidev);
 	}
+#ifdef CONFIG_SPI_SLAVE
+	spi_slave_abort(spidev->spi);
+#endif
 	mutex_unlock(&device_list_lock);
 
 	return 0;
-- 
2.20.1


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

* [PATCH v2 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver
  2019-09-25  9:11 ` [PATCH v2 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
  2019-09-25  9:11   ` [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
@ 2019-09-25  9:11   ` Lukasz Majewski
  1 sibling, 0 replies; 13+ messages in thread
From: Lukasz Majewski @ 2019-09-25  9:11 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, krzk, Lukasz Majewski

This change provides the dspi_slave_abort() function, which is a callback
for slave_abort() method of SPI controller generic driver.

As in the SPI slave mode the transmission is driven by master, any
distortion may cause the slave to enter undefined internal state.
To avoid this problem the dspi_slave_abort() terminates all pending and
ongoing DMA transactions (with sync) and clears internal FIFOs.

Signed-off-by: Lukasz Majewski <lukma@denx.de>

---
Changes for v2:
- None
---
 drivers/spi/spi-fsl-dspi.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index bec758e978fb..2c0f211eed87 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -1006,6 +1006,25 @@ static void dspi_init(struct fsl_dspi *dspi)
 			     SPI_CTARE_FMSZE(0) | SPI_CTARE_DTCP(1));
 }
 
+static int dspi_slave_abort(struct spi_master *master)
+{
+	struct fsl_dspi *dspi = spi_master_get_devdata(master);
+
+	/*
+	 * Terminate all pending DMA transactions for the SPI working
+	 * in SLAVE mode.
+	 */
+	dmaengine_terminate_sync(dspi->dma->chan_rx);
+	dmaengine_terminate_sync(dspi->dma->chan_tx);
+
+	/* Clear the internal DSPI RX and TX FIFO buffers */
+	regmap_update_bits(dspi->regmap, SPI_MCR,
+			   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF,
+			   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF);
+
+	return 0;
+}
+
 static int dspi_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -1030,6 +1049,7 @@ static int dspi_probe(struct platform_device *pdev)
 	ctlr->dev.of_node = pdev->dev.of_node;
 
 	ctlr->cleanup = dspi_cleanup;
+	ctlr->slave_abort = dspi_slave_abort;
 	ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
 
 	pdata = dev_get_platdata(&pdev->dev);
-- 
2.20.1


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

* Re: [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
  2019-09-25  9:11   ` [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
@ 2019-09-25 16:45     ` Mark Brown
  2019-09-25 19:57       ` Lukasz Majewski
  2019-09-25 16:47     ` Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree Mark Brown
  1 sibling, 1 reply; 13+ messages in thread
From: Mark Brown @ 2019-09-25 16:45 UTC (permalink / raw)
  To: Lukasz Majewski; +Cc: linux-spi, linux-kernel, krzk

[-- Attachment #1: Type: text/plain, Size: 541 bytes --]

On Wed, Sep 25, 2019 at 11:11:42AM +0200, Lukasz Majewski wrote:
> This change is necessary for spidev devices (e.g. /dev/spidev3.0) working
> in the slave mode (like NXP's dspi driver for Vybrid SoC).

Please do not submit new versions of already applied patches, please
submit incremental updates to the existing code.  Modifying existing
commits creates problems for other users building on top of those
commits so it's best practice to only change pubished git commits if
absolutely essential.

That said I'll handle this this one time.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree
  2019-09-25  9:11   ` [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
  2019-09-25 16:45     ` Mark Brown
@ 2019-09-25 16:47     ` Mark Brown
  1 sibling, 0 replies; 13+ messages in thread
From: Mark Brown @ 2019-09-25 16:47 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: kbuild test robot, krzk, linux-kernel, linux-spi, Mark Brown

The patch

   spi: Add call to spi_slave_abort() function when spidev driver is released

has been applied to the spi tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-5.4

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

From 9f918a728cf86b2757b6a7025e1f46824bfe3155 Mon Sep 17 00:00:00 2001
From: Lukasz Majewski <lukma@denx.de>
Date: Wed, 25 Sep 2019 11:11:42 +0200
Subject: [PATCH] spi: Add call to spi_slave_abort() function when spidev
 driver is released

This change is necessary for spidev devices (e.g. /dev/spidev3.0) working
in the slave mode (like NXP's dspi driver for Vybrid SoC).

When SPI HW works in this mode - the master is responsible for providing
CS and CLK signals. However, when some fault happens - like for example
distortion on SPI lines - the SPI Linux driver needs a chance to recover
from this abnormal situation and prepare itself for next (correct)
transmission.

This change doesn't pose any threat on drivers working in master mode as
spi_slave_abort() function checks if SPI slave mode is supported.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Link: https://lore.kernel.org/r/20190924110547.14770-2-lukma@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
Reported-by: kbuild test robot <lkp@intel.com>
Link: https://lore.kernel.org/r/20190925091143.15468-2-lukma@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/spi/spidev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 255786f2e844..3ea9d8a3e6e8 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -627,6 +627,9 @@ static int spidev_release(struct inode *inode, struct file *filp)
 		if (dofree)
 			kfree(spidev);
 	}
+#ifdef CONFIG_SPI_SLAVE
+	spi_slave_abort(spidev->spi);
+#endif
 	mutex_unlock(&device_list_lock);
 
 	return 0;
-- 
2.20.1


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

* Re: [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
  2019-09-25 16:45     ` Mark Brown
@ 2019-09-25 19:57       ` Lukasz Majewski
  0 siblings, 0 replies; 13+ messages in thread
From: Lukasz Majewski @ 2019-09-25 19:57 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, krzk

[-- Attachment #1: Type: text/plain, Size: 885 bytes --]

Hi Mark,

> On Wed, Sep 25, 2019 at 11:11:42AM +0200, Lukasz Majewski wrote:
> > This change is necessary for spidev devices (e.g. /dev/spidev3.0)
> > working in the slave mode (like NXP's dspi driver for Vybrid SoC).  
> 
> Please do not submit new versions of already applied patches, please
> submit incremental updates to the existing code.  Modifying existing
> commits creates problems for other users building on top of those
> commits so it's best practice to only change pubished git commits if
> absolutely essential.
> 
> That said I'll handle this this one time.

Thanks for help (and patience).


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
  2019-09-24 11:05 ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
  2019-09-24 20:08   ` Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree Mark Brown
@ 2019-09-26  6:52   ` Geert Uytterhoeven
  2019-09-26  7:59     ` Lukasz Majewski
  1 sibling, 1 reply; 13+ messages in thread
From: Geert Uytterhoeven @ 2019-09-26  6:52 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Mark Brown, linux-spi, Linux Kernel Mailing List, Krzysztof Kozlowski

Hi Lukasz,

On Thu, Sep 26, 2019 at 3:33 AM Lukasz Majewski <lukma@denx.de> wrote:
> This change is necessary for spidev devices (e.g. /dev/spidev3.0) working
> in the slave mode (like NXP's dspi driver for Vybrid SoC).
>
> When SPI HW works in this mode - the master is responsible for providing
> CS and CLK signals. However, when some fault happens - like for example
> distortion on SPI lines - the SPI Linux driver needs a chance to recover
> from this abnormal situation and prepare itself for next (correct)
> transmission.
>
> This change doesn't pose any threat on drivers working in master mode as
> spi_slave_abort() function checks if SPI slave mode is supported.
>
> Signed-off-by: Lukasz Majewski <lukma@denx.de>

Thanks for your patch!

Yesterday I saw this appear on spi/for-next, but I couldn't find the
email in my mbox.  Today it has arrived. Looks like gmail had some troubles
("Delivered after 138401 seconds", ugh).

> --- a/drivers/spi/spidev.c
> +++ b/drivers/spi/spidev.c
> @@ -627,6 +627,7 @@ static int spidev_release(struct inode *inode, struct file *filp)
>                 if (dofree)
>                         kfree(spidev);
>         }
> +       spi_slave_abort(spidev->spi);

Looks good to me.  Just wondering if this should be done for the last user only,
i.e. in the "if" block above, like resetting speed_hz?

>         mutex_unlock(&device_list_lock);
>
>         return 0;

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
  2019-09-26  6:52   ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Geert Uytterhoeven
@ 2019-09-26  7:59     ` Lukasz Majewski
  0 siblings, 0 replies; 13+ messages in thread
From: Lukasz Majewski @ 2019-09-26  7:59 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Mark Brown, linux-spi, Linux Kernel Mailing List, Krzysztof Kozlowski

[-- Attachment #1: Type: text/plain, Size: 2349 bytes --]

Hi Geert,

> Hi Lukasz,
> 
> On Thu, Sep 26, 2019 at 3:33 AM Lukasz Majewski <lukma@denx.de> wrote:
> > This change is necessary for spidev devices (e.g. /dev/spidev3.0)
> > working in the slave mode (like NXP's dspi driver for Vybrid SoC).
> >
> > When SPI HW works in this mode - the master is responsible for
> > providing CS and CLK signals. However, when some fault happens -
> > like for example distortion on SPI lines - the SPI Linux driver
> > needs a chance to recover from this abnormal situation and prepare
> > itself for next (correct) transmission.
> >
> > This change doesn't pose any threat on drivers working in master
> > mode as spi_slave_abort() function checks if SPI slave mode is
> > supported.
> >
> > Signed-off-by: Lukasz Majewski <lukma@denx.de>  
> 
> Thanks for your patch!
> 
> Yesterday I saw this appear on spi/for-next, but I couldn't find the
> email in my mbox.  Today it has arrived. Looks like gmail had some
> troubles ("Delivered after 138401 seconds", ugh).

I've already sent v2 of this patch, as Intel Linux test setup spot the
error with lack of #define guards.

> 
> > --- a/drivers/spi/spidev.c
> > +++ b/drivers/spi/spidev.c
> > @@ -627,6 +627,7 @@ static int spidev_release(struct inode *inode,
> > struct file *filp) if (dofree)
> >                         kfree(spidev);
> >         }
> > +       spi_slave_abort(spidev->spi);  
> 
> Looks good to me.  Just wondering if this should be done for the last
> user only, i.e. in the "if" block above, like resetting speed_hz?

I also thought about this. However, from my use case the user must end
the transmission with CTRL+C on his user space program, which in turn
communicate via SPI with /dev/spidev3.0.

There might be many (potential) programs using the /dev/spidev3.0 at the
same time, so the usage count may be not one.

For the above reason I've moved it outside the above if().

> 
> >         mutex_unlock(&device_list_lock);
> >
> >         return 0;  
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Applied "spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver" to the spi tree
  2019-09-24 11:05 ` [PATCH 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver Lukasz Majewski
@ 2019-10-01 11:41   ` Mark Brown
  0 siblings, 0 replies; 13+ messages in thread
From: Mark Brown @ 2019-10-01 11:41 UTC (permalink / raw)
  To: Lukasz Majewski; +Cc: krzk, linux-kernel, linux-spi, Mark Brown

The patch

   spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver

has been applied to the spi tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-5.5

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

From f4b323905d8b3e28b2a9cef9325dbec1b0f7f064 Mon Sep 17 00:00:00 2001
From: Lukasz Majewski <lukma@denx.de>
Date: Tue, 24 Sep 2019 13:05:47 +0200
Subject: [PATCH] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI
 driver

This change provides the dspi_slave_abort() function, which is a callback
for slave_abort() method of SPI controller generic driver.

As in the SPI slave mode the transmission is driven by master, any
distortion may cause the slave to enter undefined internal state.
To avoid this problem the dspi_slave_abort() terminates all pending and
ongoing DMA transactions (with sync) and clears internal FIFOs.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Link: https://lore.kernel.org/r/20190924110547.14770-3-lukma@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/spi/spi-fsl-dspi.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index bec758e978fb..2c0f211eed87 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -1006,6 +1006,25 @@ static void dspi_init(struct fsl_dspi *dspi)
 			     SPI_CTARE_FMSZE(0) | SPI_CTARE_DTCP(1));
 }
 
+static int dspi_slave_abort(struct spi_master *master)
+{
+	struct fsl_dspi *dspi = spi_master_get_devdata(master);
+
+	/*
+	 * Terminate all pending DMA transactions for the SPI working
+	 * in SLAVE mode.
+	 */
+	dmaengine_terminate_sync(dspi->dma->chan_rx);
+	dmaengine_terminate_sync(dspi->dma->chan_tx);
+
+	/* Clear the internal DSPI RX and TX FIFO buffers */
+	regmap_update_bits(dspi->regmap, SPI_MCR,
+			   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF,
+			   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF);
+
+	return 0;
+}
+
 static int dspi_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -1030,6 +1049,7 @@ static int dspi_probe(struct platform_device *pdev)
 	ctlr->dev.of_node = pdev->dev.of_node;
 
 	ctlr->cleanup = dspi_cleanup;
+	ctlr->slave_abort = dspi_slave_abort;
 	ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
 
 	pdata = dev_get_platdata(&pdev->dev);
-- 
2.20.1


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

end of thread, other threads:[~2019-10-01 11:41 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-24 11:05 [PATCH 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
2019-09-24 11:05 ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
2019-09-24 20:08   ` Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree Mark Brown
2019-09-26  6:52   ` [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Geert Uytterhoeven
2019-09-26  7:59     ` Lukasz Majewski
2019-09-24 11:05 ` [PATCH 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver Lukasz Majewski
2019-10-01 11:41   ` Applied "spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver" to the spi tree Mark Brown
2019-09-25  9:11 ` [PATCH v2 0/2] spi: Fix problem with interrupted slave transmission Lukasz Majewski
2019-09-25  9:11   ` [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released Lukasz Majewski
2019-09-25 16:45     ` Mark Brown
2019-09-25 19:57       ` Lukasz Majewski
2019-09-25 16:47     ` Applied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree Mark Brown
2019-09-25  9:11   ` [PATCH v2 2/2] spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver Lukasz Majewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).