spi: Fix problem with interrupted slave transmission
Subsystems (2)
cover spi: Fix problem with interrupted slave transmission
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(+)
Signature · 1 line
2.20.1
PATCH 1/2 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.
--- drivers/spi/spidev.c | 1 + 1 file changed, 1 insertion(+)
drivers/spi/spidev.c +1 -0
@@ -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 ;
Signature · 1 line
2.20.1
Mark Brown
maintainerApplied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree
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
Quoted 1 line
From
bf390d25e03b38248a0a4f7d0002bbb495a82fe9Mon Sep 17 00:00:00 2001
From: Lukasz Majewski <[email protected]>
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.
--- drivers/spi/spidev.c | 1 + 1 file changed, 1 insertion(+)
drivers/spi/spidev.c +1 -0
@@ -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 ;
Signature · 1 line
2.20.1
Re: [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
In reply to Lukasz MajewskiHi Lukasz,
Quoted 9 lines · 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.
Quoted 4 lines
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 <[email protected]>
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).
drivers/spi/spidev.c static int spidev_release(struct inode *inode, struct file *filp) · line 630
Quoted 7 lines
drivers/spi/spidev.c +1
-0@@ -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?
drivers/spi/spidev.c static int spidev_release(struct inode *inode, struct file *filp) · line 633
Quoted 3 lines
drivers/spi/spidev.c +0
-0mutex_unlock (&device_list_lock);return 0 ;
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] 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
Re: [PATCH 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
Hi Geert,
Quoted 16 lines
Hi Lukasz,
Quoted 13 lines · 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.
Quoted 7 lines
Quoted 1 line
Signed-off-by Lukasz Majewski <[email protected]>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.
Quoted 11 lines
drivers/spi/spidev.c static int spidev_release(struct inode *inode, · line 630
Quoted 8 lines
drivers/spi/spidev.c +1
-0@@ -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().
Quoted 9 lines
drivers/spi/spidev.c static int spidev_release(struct inode *inode, struct file *filp) · line 633
Quoted 4 lines
drivers/spi/spidev.c +0
-0mutex_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: [email protected]
PATCH 2/2 spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver
In reply to Lukasz MajewskiThis 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.
--- drivers/spi/spi-fsl-dspi.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/spi/spi-fsl-dspi.c +20 -0
@@ -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);
Signature · 1 line
2.20.1
Mark Brown
maintainerApplied "spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver" to the spi tree
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
Quoted 1 line
From
f4b323905d8b3e28b2a9cef9325dbec1b0f7f064Mon Sep 17 00:00:00 2001
From: Lukasz Majewski <[email protected]>
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.
--- drivers/spi/spi-fsl-dspi.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/spi/spi-fsl-dspi.c +20 -0
@@ -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);
Signature · 1 line
2.20.1
v2 cover spi: Fix problem with interrupted slave transmission
In reply to Lukasz MajewskiThis 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(+)
Signature · 1 line
2.20.1
PATCH v2 1/2 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.
---
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(+)
drivers/spi/spidev.c +3 -0
@@ -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 ;
Signature · 1 line
2.20.1
Mark Brown
maintainerRe: [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
Quoted 2 lines · 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).
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.
Re: [PATCH v2 1/2] spi: Add call to spi_slave_abort() function when spidev driver is released
Hi Mark,
Quoted 11 lines · Lukasz Majewski
Quoted 2 lines
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: [email protected]
Mark Brown
maintainerApplied "spi: Add call to spi_slave_abort() function when spidev driver is released" to the spi tree
In reply to Lukasz MajewskiThe 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
Quoted 1 line
From
9f918a728cf86b2757b6a7025e1f46824bfe3155Mon Sep 17 00:00:00 2001
From: Lukasz Majewski <[email protected]>
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.
--- drivers/spi/spidev.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/spi/spidev.c +3 -0
@@ -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 ;
Signature · 1 line
2.20.1
PATCH v2 2/2 spi: Introduce dspi_slave_abort() function for NXP's dspi SPI driver
In reply to Lukasz MajewskiThis 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.
---
Changes for v2:
- None
--- drivers/spi/spi-fsl-dspi.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/spi/spi-fsl-dspi.c +20 -0
@@ -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);
Signature · 1 line
2.20.1