spi: xilinx: Detect stall with Unknown commands
Subsystems (3)
PATCH 1/3 spi: xilinx: Detect stall with Unknown commands
When the core is configured in C_SPI_MODE > 0, it integrates a lookup table that automatically configures the core in dual or quad mode based on the command (first byte on the tx fifo).
Unfortunately, that list mode_?_memoy_*.mif does not contain all the supported commands by the flash.
Since 4.14 spi-nor automatically tries to probe the flash using SFDP (command 0x5a), and that command is not part of the list_mode table.
Whit the right combination of C_SPI_MODE and C_SPI_MEMORY this leads into a stall that can only be recovered with a soft rest.
This patch detects this kind of stall and returns -EIO to the caller on those commands. spi-nor can handle this error properly:
m25p80 spi0.0: Detected stall. Check C_SPI_MODE and C_SPI_MEMORY. 0x21 0x2404 m25p80 spi0.0: SPI transfer failed: -5spi_master spi0: failed to transfer one message from queue
m25p80 spi0.0: s25sl064p (8192 Kbytes)
--- drivers/spi/spi-xilinx.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/spi/spi-xilinx.c +11 -0
@@ -271,6 +271,7 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)while (remaining_words) {int n_words, tx_words, rx_words;u32 sr; +int stalled; n_words =min (remaining_words, xspi->buffer_size);
@@ -299,7 +300,17 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)/* Read out all the data from the Rx FIFO */ rx_words = n_words; + stalled =10 ;while (rx_words) { +if (rx_words == n_words && !(stalled--) && + !(sr &XSPI_SR_TX_EMPTY_MASK ) && + (sr &XSPI_SR_RX_EMPTY_MASK )) { +dev_err (&spi->dev, +"Detected stall. Check C_SPI_MODE and C_SPI_MEMORY\n" ); +xspi_init_hw (xspi); +return -EIO ; + } +if ((sr &XSPI_SR_TX_EMPTY_MASK ) && (rx_words >1 )) {xilinx_spi_rx (xspi); rx_words--;
Signature · 6 lines
2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20171121090904.6901-1-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 2/3 spi: xilinx: Add support for xlnx,axi-quad-spi-1.00.a
The driver has been successfully tested with Xilinx's core axi-quad-spi-1.0.0a. Documented on DS843:
--- Documentation/devicetree/bindings/spi/spi-xilinx.txt | 2 +- drivers/spi/spi-xilinx.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/spi/spi-xilinx.txt +1 -1
@@ -2,7 +2,7 @@ Xilinx SPI controller Device Tree Bindings ------------------------------------------------- Required properties: -- compatible : Should be "xlnx,xps-spi-2.00.a" or "xlnx,xps-spi-2.00.b" +- compatible : Should be "xlnx,xps-spi-2.00.a", "xlnx,xps-spi-2.00.b" or "xlnx,axi-quad-spi-1.00.a" - reg : Physical base address and size of SPI registers map. - interrupts : Property with a value describing the interrupt number.
drivers/spi/spi-xilinx.c +1 -0
@@ -381,6 +381,7 @@ static int xilinx_spi_find_buffer_size(struct xilinx_spi *xspi) }static const struct of_device_id xilinx_spi_of_match[] = { + { .compatible ="xlnx,axi-quad-spi-1.00.a" , }, { .compatible ="xlnx,xps-spi-2.00.a" , }, { .compatible ="xlnx,xps-spi-2.00.b" , }, {}
Signature · 6 lines
2.15.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20171121090904.6901-2-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Rob Herring
Acked-byRe: [PATCH 2/3] spi: xilinx: Add support for xlnx,axi-quad-spi-1.00.a
Quoted 5 lines · Ricardo Ribalda Delgado
The driver has been successfully tested with Xilinx's core axi-quad-spi-1.0.0a. Documented on DS843:
Quoted 8 lines
Cc Mark Brown <[email protected]>Cc Rob Herring <[email protected]>Signed-off-by Ricardo Ribalda Delgado <[email protected]>--- Documentation/devicetree/bindings/spi/spi-xilinx.txt | 2 +- drivers/spi/spi-xilinx.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Applied "spi: xilinx: Add support for xlnx,axi-quad-spi-1.00.a" to the spi tree
In reply to a message not in the archiveThe patch
spi: xilinx: Add support for xlnx,axi-quad-spi-1.00.a
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
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
a094c2fa093cf7fd0fe23d15cc2abca4083c6a45Mon Sep 17 00:00:00 2001
From: Ricardo Ribalda <[email protected]>
Date: Tue, 21 Nov 2017 10:09:03 +0100
Subject: [PATCH] spi: xilinx: Add support for xlnx,axi-quad-spi-1.00.a
The driver has been successfully tested with Xilinx's core axi-quad-spi-1.0.0a. Documented on DS843:
--- Documentation/devicetree/bindings/spi/spi-xilinx.txt | 2 +- drivers/spi/spi-xilinx.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/spi/spi-xilinx.txt +1 -1
@@ -2,7 +2,7 @@ Xilinx SPI controller Device Tree Bindings ------------------------------------------------- Required properties: -- compatible : Should be "xlnx,xps-spi-2.00.a" or "xlnx,xps-spi-2.00.b" +- compatible : Should be "xlnx,xps-spi-2.00.a", "xlnx,xps-spi-2.00.b" or "xlnx,axi-quad-spi-1.00.a" - reg : Physical base address and size of SPI registers map. - interrupts : Property with a value describing the interrupt number.
drivers/spi/spi-xilinx.c +1 -0
@@ -381,6 +381,7 @@ static int xilinx_spi_find_buffer_size(struct xilinx_spi *xspi) }static const struct of_device_id xilinx_spi_of_match[] = { + { .compatible ="xlnx,axi-quad-spi-1.00.a" , }, { .compatible ="xlnx,xps-spi-2.00.a" , }, { .compatible ="xlnx,xps-spi-2.00.b" , }, {}
Signature · 6 lines
2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 MAINTAINERS: Add Ricardo Ribalda for spi-xilinx
In reply to a message not in the archiveSince almost half of the driver comes from changes from me, I have access to the hardware and we are using it in a current product I volunteer for maintaining this driver.
--- CREDITS | 1 + MAINTAINERS | 6 ++++++ drivers/spi/spi-xilinx.c | 1 + 3 files changed, 8 insertions(+)
CREDITS +1 -0
@@ -3071,6 +3071,7 @@ D: Several AX.25 hacks N: Ricardo Ribalda Delgado E: [email protected] W: http://ribalda.com +D: Xilinx QUAD SPI driver D: PLX USB338x driver D: PCA9634 driver D: Option GTM671WFS
MAINTAINERS +6 -0
@@ -14786,6 +14786,12 @@ M: John Linn <[email protected]> S: Maintained F: drivers/net/ethernet/xilinx/xilinx_axienet* +XILINX SPI DRIVER +M: Ricardo Ribalda <[email protected]> +L: [email protected] +S: Supported +F: drivers/spi/spi-xilinx.c + XILINX UARTLITE SERIAL DRIVER M: Peter Korsgaard <jacmet-OfajU3CKLf1/[email protected]> L: [email protected]
drivers/spi/spi-xilinx.c +1 -0
@@ -4,6 +4,7 @@* Author: MontaVista Software, Inc. * [email protected] * +* Copyright (C) 2015-2017 Ricardo Ribalda, Qtechnology A/S * Copyright (c) 2010 Secret Lab Technologies, Ltd. * Copyright (c) 2009 Intel Corporation * 2002-2007 (c) MontaVista Software, Inc.
Signature · 6 lines
2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
drivers/spi/spi-xilinx.c static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) · line 307
Quoted 5 lines · Ricardo Ribalda Delgado
drivers/spi/spi-xilinx.c +4
-0+ stalled =10 ;while (rx_words) { +if (rx_words == n_words && !(stalled--) && + !(sr &XSPI_SR_TX_EMPTY_MASK ) && + (sr &XSPI_SR_RX_EMPTY_MASK )) {
10 seems like a small number for what is essentially just a busy spin - are we sure that we won't reasonably hit a case where the CPU is sufficiently fast and the bus sufficiently slow we falsely detect a stall? Where did this number come from?
A message that is not in the archive (sent off-list or not yet received): 20171122111215.2isnpg3nfry3g3ll-GFdadSzt00ze9xe1eoZjHA@public.gmane.org
Hi Mark
Quoted 8 lines · Mark Brown
drivers/spi/spi-xilinx.c static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) · line 307
Quoted 5 lines · Ricardo Ribalda Delgado
drivers/spi/spi-xilinx.c +4
-0+ stalled =10 ;while (rx_words) { +if (rx_words == n_words && !(stalled--) && + !(sr &XSPI_SR_TX_EMPTY_MASK ) && + (sr &XSPI_SR_RX_EMPTY_MASK )) {
Quoted 4 lines
10 seems like a small number for what is essentially just a busy spin - are we sure that we won't reasonably hit a case where the CPU is sufficiently fast and the bus sufficiently slow we falsely detect a stall? Where did this number come from?
This code is executed after all the data has been pushed to the out fifo. Since we are not inhibitng tx, the moment the empty mask is evaluated, at least one byte should be out.
After 1 day of use I have been able to locate one event when stalled was two. So 10 is very conservative number.
In other words: 10 is one order of magnitude bigger than the worst measured case.
Thanks for your review :)
Signature · 5 lines
Ricardo Ribalda -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAPybu_2MBMFOy+RDSSai1pGf_+A4AD6=gbyWbZSLEPQetjfBxA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Hi again
Quoted 21 lines · Ricardo Ribalda Delgado
Hi Mark
Quoted 8 lines · Mark Brown
drivers/spi/spi-xilinx.c static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) · line 307
Quoted 5 lines · Ricardo Ribalda Delgado
drivers/spi/spi-xilinx.c +4
-0+ stalled =10 ;while (rx_words) { +if (rx_words == n_words && !(stalled--) && + !(sr &XSPI_SR_TX_EMPTY_MASK ) && + (sr &XSPI_SR_RX_EMPTY_MASK )) {Quoted 4 lines
10 seems like a small number for what is essentially just a busy spin - are we sure that we won't reasonably hit a case where the CPU is sufficiently fast and the bus sufficiently slow we falsely detect a stall? Where did this number come from?
This code is executed after all the data has been pushed to the out fifo. Since we are not inhibitng tx, the moment the empty mask is evaluated, at least one byte should be out.
Quoted 5 lines
After 1 day of use I have been able to locate one event when stalled was two. So 10 is very conservative number.
In other words: 10 is one order of magnitude bigger than the worst measured case.
If it makes you more comfortable I could add something like
if (n_tries < 8)
msleep(10);
Regards!
Quoted 6 lines
Thanks for your review :)
--
Ricardo Ribalda
Signature · 5 lines
Ricardo Ribalda -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Applied "spi: xilinx: Detect stall with Unknown commands" to the spi tree
In reply to a message not in the archiveThe patch
spi: xilinx: Detect stall with Unknown commands
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
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
fe56ebb8b93de2593f9e200d4ea3b2714287490bMon Sep 17 00:00:00 2001
From: Ricardo Ribalda <[email protected]>
Date: Tue, 21 Nov 2017 10:09:02 +0100
Subject: [PATCH] spi: xilinx: Detect stall with Unknown commands
When the core is configured in C_SPI_MODE > 0, it integrates a lookup table that automatically configures the core in dual or quad mode based on the command (first byte on the tx fifo).
Unfortunately, that list mode_?_memoy_*.mif does not contain all the supported commands by the flash.
Since 4.14 spi-nor automatically tries to probe the flash using SFDP (command 0x5a), and that command is not part of the list_mode table.
Whit the right combination of C_SPI_MODE and C_SPI_MEMORY this leads into a stall that can only be recovered with a soft rest.
This patch detects this kind of stall and returns -EIO to the caller on those commands. spi-nor can handle this error properly:
m25p80 spi0.0: Detected stall. Check C_SPI_MODE and C_SPI_MEMORY. 0x21 0x2404 m25p80 spi0.0: SPI transfer failed: -5spi_master spi0: failed to transfer one message from queue
m25p80 spi0.0: s25sl064p (8192 Kbytes)
--- drivers/spi/spi-xilinx.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/spi/spi-xilinx.c +11 -0
@@ -271,6 +271,7 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)while (remaining_words) {int n_words, tx_words, rx_words;u32 sr; +int stalled; n_words =min (remaining_words, xspi->buffer_size);
@@ -299,7 +300,17 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)/* Read out all the data from the Rx FIFO */ rx_words = n_words; + stalled =10 ;while (rx_words) { +if (rx_words == n_words && !(stalled--) && + !(sr &XSPI_SR_TX_EMPTY_MASK ) && + (sr &XSPI_SR_RX_EMPTY_MASK )) { +dev_err (&spi->dev, +"Detected stall. Check C_SPI_MODE and C_SPI_MEMORY\n" ); +xspi_init_hw (xspi); +return -EIO ; + } +if ((sr &XSPI_SR_TX_EMPTY_MASK ) && (rx_words >1 )) {xilinx_spi_rx (xspi); rx_words--;
Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html