Skip to contentSkip to conversation

spi: zynqmp-gqspi: Improve error recovery by resetting

PATCH In review Sean Anderson 5 participants 25 messages Jan 16, 2025 – Jan 27, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover spi: zynqmp-gqspi: Improve error recovery by resetting

This series adds support for resetting the QSPI controller if we have a timeout. I find this greatly improves the stability of the device, which would tend to break after any timeout.

Sean Anderson (5):
dt-bindings: spi: zynqmp-qspi: Add reset
spi: zynqmp-gqspi: Reset device in probe
spi: zynqmp-gqspi: Abort operations on timeout
spi: zynqmp-gqspi: Allow interrupting operations
ARM64: xilinx: zynqmp: Add QSPI reset

 .../bindings/spi/spi-zynqmp-qspi.yaml         |  6 ++
 arch/arm64/boot/dts/xilinx/zynqmp.dtsi        |  1 +
 drivers/spi/spi-zynqmp-gqspi.c                | 64 +++++++++++++++----
 3 files changed, 59 insertions(+), 12 deletions(-)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#1 lore raw

PATCH 1/5 dt-bindings: spi: zynqmp-qspi: Add reset

Add a reset to help recover from cancelled operations.

---

 Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +6 -0
index 04d4d3b4916d..901e15fcce2d 100644
@@ -36,12 +36,16 @@ properties:
   power-domains:
     maxItems: 1
 
+  resets:
+    maxItems: 1
+
 required:
   - compatible
   - reg
   - interrupts
   - clock-names
   - clocks
+  - resets
 
 unevaluatedProperties: false
 
@@ -66,6 +70,7 @@ allOf:
 examples:
   - |
     #include <dt-bindings/clock/xlnx-zynqmp-clk.h>
+    #include <dt-bindings/reset/xlnx-zynqmp-resets.h>
     soc {
       #address-cells = <2>;
       #size-cells = <2>;
@@ -76,6 +81,7 @@ examples:
         clock-names = "ref_clk", "pclk";
         interrupts = <0 15 4>;
         interrupt-parent = <&gic>;
+        resets = <&zynqmp_reset ZYNQMP_RESET_QSPI>;
         reg = <0x0 0xff0f0000 0x0 0x1000>,
               <0x0 0xc0000000 0x0 0x8000000>;
       };
Signature · 1 line
2.35.1.1320.gc452695387.dirty
maintainer
#2 lore raw

Re: [PATCH 1/5] dt-bindings: spi: zynqmp-qspi: Add reset

Quoted 16 lines · Sean Anderson

Add a reset to help recover from cancelled operations.

---

  Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml | 6 ++++++
  1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0 -0
index 04d4d3b4916d..901e15fcce2d 100644
@@ -36,12 +36,16 @@ properties:
    power-domains:
      maxItems: 1
 

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml properties: · line 48

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +4 -0
+  resets:
+    maxItems: 1
+
  required:
    - compatible
    - reg
    - interrupts
    - clock-names
    - clocks
+  - resets

In 2/5 you are calling devm_reset_control_get_optional_exclusive() that's why I expect reset is not really required property.

M

#3 lore raw

Re: [PATCH 1/5] dt-bindings: spi: zynqmp-qspi: Add reset

Quoted 22 lines · Michal Simek
Quoted 19 lines · Sean Anderson

Add a reset to help recover from cancelled operations.

---

  Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml | 6 ++++++
  1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +2 -0
index 04d4d3b4916d..901e15fcce2d 100644
@@ -36,12 +36,16 @@ properties:
    power-domains:
      maxItems: 1
  +  resets:
+    maxItems: 1
+
  required:
Quoted 8 lines

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml properties: · line 48

Quoted 6 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +1 -0
    - compatible
    - reg
    - interrupts
    - clock-names
    - clocks
+  - resets

In 2/5 you are calling devm_reset_control_get_optional_exclusive() that's why I expect reset is not really required property.

It's optional for the driver for backwards compatibility. But for the devicetree we make it mandatory since it should be included in all new devicetrees.

--Sean

maintainer
#4 lore raw

Re: [PATCH 1/5] dt-bindings: spi: zynqmp-qspi: Add reset

Quoted 32 lines · Sean Anderson
Quoted 22 lines · Michal Simek
Quoted 19 lines · Sean Anderson

Add a reset to help recover from cancelled operations.

---

  Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml | 6 ++++++
  1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +2 -0
index 04d4d3b4916d..901e15fcce2d 100644
@@ -36,12 +36,16 @@ properties:
    power-domains:
      maxItems: 1
  +  resets:
+    maxItems: 1
+
  required:
Quoted 8 lines

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml properties: · line 48

Quoted 6 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +1 -0
    - compatible
    - reg
    - interrupts
    - clock-names
    - clocks
+  - resets

In 2/5 you are calling devm_reset_control_get_optional_exclusive() that's why I expect reset is not really required property.

Quoted 3 lines

It's optional for the driver for backwards compatibility. But for the devicetree we make it mandatory since it should be included in all new devicetrees.

Generally, we discourage new required properties as that's an ABI change. The exception is really when optional was a mistake. That's arguably the case here if the h/w always has a reset.

Unfortunately, there's not a way to distinguish 'required' from 'required for new users'.

Rob

#5 lore raw

Re: [PATCH 1/5] dt-bindings: spi: zynqmp-qspi: Add reset

Quoted 33 lines · Rob Herring
Quoted 32 lines · Sean Anderson
Quoted 30 lines · Michal Simek
Quoted 15 lines · Sean Anderson

Add a reset to help recover from cancelled operations.

---

  Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml | 6 ++++++
  1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0 -0
index 04d4d3b4916d..901e15fcce2d 100644
@@ -36,12 +36,16 @@ properties:
    power-domains:
      maxItems: 1

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml properties: · line 47

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +3 -0
  +  resets:
+    maxItems: 1
+
  required:
    - compatible
    - reg
    - interrupts
    - clock-names
    - clocks
+  - resets

In 2/5 you are calling devm_reset_control_get_optional_exclusive() that's why I expect reset is not really required property.

Quoted 7 lines
Quoted 3 lines

It's optional for the driver for backwards compatibility. But for the devicetree we make it mandatory since it should be included in all new devicetrees.

Generally, we discourage new required properties as that's an ABI change. The exception is really when optional was a mistake. That's arguably the case here if the h/w always has a reset.

This device has a reset on ZynqMP and Versal.

The driver still considers this property optional, so it's not an ABI break. But I made it required in the schema to help out the folks at AMD when they get around to upstreaming the Versal devicetree :)

Quoted 2 lines

Unfortunately, there's not a way to distinguish 'required' from 'required for new users'.

I will add a note to the commit message about this situation.

--Sean

maintainer
#6 lore raw

Re: [PATCH 1/5] dt-bindings: spi: zynqmp-qspi: Add reset

Quoted 42 lines · Sean Anderson
Quoted 33 lines · Rob Herring
Quoted 32 lines · Sean Anderson
Quoted 30 lines · Michal Simek
Quoted 15 lines · Sean Anderson

Add a reset to help recover from cancelled operations.

---

   Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml | 6 ++++++
   1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0 -0
index 04d4d3b4916d..901e15fcce2d 100644
@@ -36,12 +36,16 @@ properties:
     power-domains:
       maxItems: 1

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml properties: · line 47

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +3 -0
   +  resets:
+    maxItems: 1
+
   required:
     - compatible
     - reg
     - interrupts
     - clock-names
     - clocks
+  - resets

In 2/5 you are calling devm_reset_control_get_optional_exclusive() that's why I expect reset is not really required property.

Quoted 7 lines
Quoted 3 lines

It's optional for the driver for backwards compatibility. But for the devicetree we make it mandatory since it should be included in all new devicetrees.

Generally, we discourage new required properties as that's an ABI change. The exception is really when optional was a mistake. That's arguably the case here if the h/w always has a reset.

Quoted 5 lines

This device has a reset on ZynqMP and Versal.

The driver still considers this property optional, so it's not an ABI break. But I made it required in the schema to help out the folks at AMD when they get around to upstreaming the Versal devicetree :)

Pretty much every IP block has hardware reset wired. It is just user decision if that reset is going to be handled or if low level firmware allows to handle it.

The same logic applies to clocks too.

Quoted 4 lines
Quoted 2 lines

Unfortunately, there's not a way to distinguish 'required' from 'required for new users'.

I will add a note to the commit message about this situation.

Again even new users don't need to have an access to this feature.
Not sure what's the right way to go here but in our arm64 based chip reset is provided via firmware interface and I have no issue to say we are expecting reset property to be present but it is up to firmware implementation if a reset is actually happening on HW level.

Thanks,
Michal

maintainer
#7 lore raw

Re: [PATCH 1/5] dt-bindings: spi: zynqmp-qspi: Add reset

In reply to Sean Anderson
Quoted 42 lines · Sean Anderson
Quoted 33 lines · Rob Herring
Quoted 32 lines · Sean Anderson
Quoted 30 lines · Michal Simek
Quoted 15 lines · Sean Anderson

Add a reset to help recover from cancelled operations.

---

  Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml | 6 ++++++
  1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0 -0
index 04d4d3b4916d..901e15fcce2d 100644
@@ -36,12 +36,16 @@ properties:
    power-domains:
      maxItems: 1

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml properties: · line 47

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +3 -0
  +  resets:
+    maxItems: 1
+
  required:
    - compatible
    - reg
    - interrupts
    - clock-names
    - clocks
+  - resets

In 2/5 you are calling devm_reset_control_get_optional_exclusive() that's why I expect reset is not really required property.

Quoted 7 lines
Quoted 3 lines

It's optional for the driver for backwards compatibility. But for the devicetree we make it mandatory since it should be included in all new devicetrees.

Generally, we discourage new required properties as that's an ABI change. The exception is really when optional was a mistake. That's arguably the case here if the h/w always has a reset.

Quoted 5 lines

This device has a reset on ZynqMP and Versal.

The driver still considers this property optional, so it's not an ABI break. But I made it required in the schema to help out the folks at AMD when they get around to upstreaming the Versal devicetree :)

Not 'the driver', but 'a driver'. You can't say what *all* drivers do. If I write a new driver and read the schema, then I can say 'resets is required so I'll make it required in my new driver'. But then my new driver doesn't work with an older DT that didn't have resets which was valid at the time.

Rob

#8 lore raw

Re: [PATCH 1/5] dt-bindings: spi: zynqmp-qspi: Add reset

Quoted 49 lines · Rob Herring
Quoted 42 lines · Sean Anderson
Quoted 33 lines · Rob Herring
Quoted 32 lines · Sean Anderson
Quoted 30 lines · Michal Simek
Quoted 15 lines · Sean Anderson

Add a reset to help recover from cancelled operations.

---

  Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml | 6 ++++++
  1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0 -0
index 04d4d3b4916d..901e15fcce2d 100644
@@ -36,12 +36,16 @@ properties:
    power-domains:
      maxItems: 1

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml properties: · line 47

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +3 -0
  +  resets:
+    maxItems: 1
+
  required:
    - compatible
    - reg
    - interrupts
    - clock-names
    - clocks
+  - resets

In 2/5 you are calling devm_reset_control_get_optional_exclusive() that's why I expect reset is not really required property.

Quoted 7 lines
Quoted 3 lines

It's optional for the driver for backwards compatibility. But for the devicetree we make it mandatory since it should be included in all new devicetrees.

Generally, we discourage new required properties as that's an ABI change. The exception is really when optional was a mistake. That's arguably the case here if the h/w always has a reset.

Quoted 5 lines

This device has a reset on ZynqMP and Versal.

The driver still considers this property optional, so it's not an ABI break. But I made it required in the schema to help out the folks at AMD when they get around to upstreaming the Versal devicetree :)

Quoted 5 lines

Not 'the driver', but 'a driver'. You can't say what *all* drivers do. If I write a new driver and read the schema, then I can say 'resets is required so I'll make it required in my new driver'. But then my new driver doesn't work with an older DT that didn't have resets which was valid at the time.

OK, I'll add a description to this effect. The humans can read that, and the machines won't care.

--Sean

#9 lore raw

PATCH 2/5 spi: zynqmp-gqspi: Reset device in probe

In reply to Sean Anderson

Ensure we get a clean slate (without any bootloader settings) by resetting the device before we initialize it.

---

 drivers/spi/spi-zynqmp-gqspi.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +22 -2
index 549a6e0c9654..7d138f45b692 100644
@@ -17,6 +17,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/reset.h>
 #include <linux/spi/spi.h>
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
@@ -171,6 +172,7 @@ struct qspi_platform_data {
  * @regs:		Virtual address of the QSPI controller registers
  * @refclk:		Pointer to the peripheral clock
  * @pclk:		Pointer to the APB clock
+ * @reset:		Pointer to reset controller
  * @irq:		IRQ number
  * @dev:		Pointer to struct device
  * @txbuf:		Pointer to the TX buffer
@@ -193,6 +195,7 @@ struct zynqmp_qspi {
 	void __iomem *regs;
 	struct clk *refclk;
 	struct clk *pclk;
+	struct reset_control *reset;
 	int irq;
 	struct device *dev;
 	const void *txbuf;
@@ -351,10 +354,17 @@ static void zynqmp_qspi_set_tapdelay(struct zynqmp_qspi *xqspi, u32 baudrateval)
  *	- Set clock polarity and
  *	- Enable the QSPI controller
  */
-static void zynqmp_qspi_init_hw(struct zynqmp_qspi *xqspi)
+static int zynqmp_qspi_init_hw(struct zynqmp_qspi *xqspi)
 {
 	u32 config_reg, baud_rate_val = 0;
 	ulong clk_rate;
+	int ret;
+
+	ret = reset_control_reset(xqspi->reset);
+	if (ret) {
+		dev_err(xqspi->dev, "Unable to reset: %pe\n", &ret);
+		return ret;
+	}
 
 	/* Select the GQSPI mode */
 	zynqmp_gqspi_write(xqspi, GQSPI_SEL_OFST, GQSPI_SEL_MASK);
@@ -436,6 +446,8 @@ static void zynqmp_qspi_init_hw(struct zynqmp_qspi *xqspi)
 
 	/* Enable the GQSPI */
 	zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, GQSPI_EN_MASK);
+
+	return 0;
 }
 
 /**
@@ -1259,6 +1271,12 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
 	if (IS_ERR(xqspi->regs))
 		return PTR_ERR(xqspi->regs);
 
+	xqspi->reset =
+		devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(xqspi->reset))
+		return dev_err_probe(dev, PTR_ERR(xqspi->reset),
+				     "could not get reset\n");
+
 	xqspi->pclk = devm_clk_get(&pdev->dev, "pclk");
 	if (IS_ERR(xqspi->pclk))
 		return dev_err_probe(dev, PTR_ERR(xqspi->pclk),
@@ -1300,7 +1318,9 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
 	xqspi->speed_hz = ctlr->max_speed_hz;
 
 	/* QSPI controller initializations */
-	zynqmp_qspi_init_hw(xqspi);
+	ret = zynqmp_qspi_init_hw(xqspi);
+	if (ret)
+		goto clk_dis_all;
 
 	xqspi->irq = platform_get_irq(pdev, 0);
 	if (xqspi->irq < 0) {
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#10 lore raw

PATCH 3/5 spi: zynqmp-gqspi: Abort operations on timeout

In reply to Sean Anderson

When an operation times out, we leave the device (and driver) in an inconsistent state. This generally results in all subsequent operations timing out. Attempt to address this by resetting/reinitializing the device when we have a timeout. This tends to be fairly robust.

---

 drivers/spi/spi-zynqmp-gqspi.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +20 -10
index 7d138f45b692..cf47466ec982 100644
@@ -1057,6 +1057,21 @@ static unsigned long zynqmp_qspi_timeout(struct zynqmp_qspi *xqspi, u8 bits,
 	return msecs_to_jiffies(timeout + 100);
 }
 
+
+static int zynqmp_qspi_wait(struct zynqmp_qspi *xqspi, unsigned long timeout)
+{
+	int ret;
+
+	ret = wait_for_completion_timeout(&xqspi->data_completion, timeout);
+	if (ret)
+		return 0;
+	dev_err(xqspi->dev, "Operation timed out\n");
+
+	/* Attempt to recover as best we can */
+	zynqmp_qspi_init_hw(xqspi);
+	return -ETIMEDOUT;
+}
+
 /**
  * zynqmp_qspi_exec_op() - Initiates the QSPI transfer
  * @mem: The SPI memory
@@ -1104,11 +1119,9 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
 				   GQSPI_IER_TXNOT_FULL_MASK);
 		timeout = zynqmp_qspi_timeout(xqspi, op->cmd.buswidth,
 					      op->cmd.nbytes);
-		if (!wait_for_completion_timeout(&xqspi->data_completion,
-						 timeout)) {
-			err = -ETIMEDOUT;
+		err = zynqmp_qspi_wait(xqspi, timeout);
+		if (err)
 			goto return_err;
-		}
 	}
 
 	if (op->addr.nbytes) {
@@ -1133,11 +1146,9 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
 				   GQSPI_IER_TXNOT_FULL_MASK);
 		timeout = zynqmp_qspi_timeout(xqspi, op->addr.buswidth,
 					      op->addr.nbytes);
-		if (!wait_for_completion_timeout(&xqspi->data_completion,
-						 timeout)) {
-			err = -ETIMEDOUT;
+		err = zynqmp_qspi_wait(xqspi, timeout);
+		if (err)
 			goto return_err;
-		}
 	}
 
 	if (op->dummy.nbytes) {
@@ -1204,8 +1215,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
 		}
 		timeout = zynqmp_qspi_timeout(xqspi, op->data.buswidth,
 					      op->data.nbytes);
-		if (!wait_for_completion_timeout(&xqspi->data_completion, timeout))
-			err = -ETIMEDOUT;
+		err = zynqmp_qspi_wait(xqspi, timeout);
 	}
 
 return_err:
Signature · 1 line
2.35.1.1320.gc452695387.dirty
maintainer
#11 lore raw

Re: [PATCH 3/5] spi: zynqmp-gqspi: Abort operations on timeout

Quoted 16 lines · Sean Anderson

When an operation times out, we leave the device (and driver) in an inconsistent state. This generally results in all subsequent operations timing out. Attempt to address this by resetting/reinitializing the device when we have a timeout. This tends to be fairly robust.

---

  drivers/spi/spi-zynqmp-gqspi.c | 30 ++++++++++++++++++++----------
  1 file changed, 20 insertions(+), 10 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +0 -0
index 7d138f45b692..cf47466ec982 100644

drivers/spi/spi-zynqmp-gqspi.c static unsigned long zynqmp_qspi_timeout(struct zynqmp_qspi *xqspi, u8 bits, · line 1060

Quoted 4 lines
drivers/spi/spi-zynqmp-gqspi.c +1 -0
@@ -1057,6 +1057,21 @@ static unsigned long zynqmp_qspi_timeout(struct zynqmp_qspi *xqspi, u8 bits,
  	return msecs_to_jiffies(timeout + 100);
  }
 
+

unnecessary newline here.

drivers/spi/spi-zynqmp-gqspi.c static unsigned long zynqmp_qspi_timeout(struct zynqmp_qspi *xqspi, u8 bits, · line 1067

Quoted 7 lines
drivers/spi/spi-zynqmp-gqspi.c +7 -0
+static int zynqmp_qspi_wait(struct zynqmp_qspi *xqspi, unsigned long timeout)
+{
+	int ret;
+
+	ret = wait_for_completion_timeout(&xqspi->data_completion, timeout);
+	if (ret)
+		return 0;

newline here please

Quoted 39 lines
drivers/spi/spi-zynqmp-gqspi.c +11 -8
+	dev_err(xqspi->dev, "Operation timed out\n");
+
+	/* Attempt to recover as best we can */
+	zynqmp_qspi_init_hw(xqspi);
+	return -ETIMEDOUT;
+}
+
  /**
   * zynqmp_qspi_exec_op() - Initiates the QSPI transfer
   * @mem: The SPI memory
@@ -1104,11 +1119,9 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
  				   GQSPI_IER_TXNOT_FULL_MASK);
  		timeout = zynqmp_qspi_timeout(xqspi, op->cmd.buswidth,
  					      op->cmd.nbytes);
-		if (!wait_for_completion_timeout(&xqspi->data_completion,
-						 timeout)) {
-			err = -ETIMEDOUT;
+		err = zynqmp_qspi_wait(xqspi, timeout);
+		if (err)
  			goto return_err;
-		}
  	}
 
  	if (op->addr.nbytes) {
@@ -1133,11 +1146,9 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
  				   GQSPI_IER_TXNOT_FULL_MASK);
  		timeout = zynqmp_qspi_timeout(xqspi, op->addr.buswidth,
  					      op->addr.nbytes);
-		if (!wait_for_completion_timeout(&xqspi->data_completion,
-						 timeout)) {
-			err = -ETIMEDOUT;
+		err = zynqmp_qspi_wait(xqspi, timeout);
+		if (err)
  			goto return_err;
-		}
  	}
 
  	if (op->dummy.nbytes) {

drivers/spi/spi-zynqmp-gqspi.c static int zynqmp_qspi_exec_op(struct spi_mem *mem, · line 1221

Quoted 9 lines
drivers/spi/spi-zynqmp-gqspi.c +1 -2
@@ -1204,8 +1215,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
  		}
  		timeout = zynqmp_qspi_timeout(xqspi, op->data.buswidth,
  					      op->data.nbytes);
-		if (!wait_for_completion_timeout(&xqspi->data_completion, timeout))
-			err = -ETIMEDOUT;
+		err = zynqmp_qspi_wait(xqspi, timeout);
  	}
 
  return_err:

M

#12 lore raw

PATCH 4/5 spi: zynqmp-gqspi: Allow interrupting operations

In reply to Sean Anderson

Some operations (such as reading several megabytes of data from a flash) can take several seconds or more. Users may want to cancel such operations. Allow them to do so now that we have a way to recover.

---

 drivers/spi/spi-zynqmp-gqspi.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +14 -4
index cf47466ec982..fa4bff73324e 100644
@@ -1062,14 +1062,24 @@ static int zynqmp_qspi_wait(struct zynqmp_qspi *xqspi, unsigned long timeout)
 {
 	int ret;
 
-	ret = wait_for_completion_timeout(&xqspi->data_completion, timeout);
-	if (ret)
+	/* Only allow interrupting if we can reset the device */
+	if (xqspi->reset)
+		ret = wait_for_completion_interruptible_timeout(&xqspi->data_completion,
+								timeout);
+	else
+		ret = wait_for_completion_timeout(&xqspi->data_completion,
+						  timeout);
+	if (ret > 0)
 		return 0;
-	dev_err(xqspi->dev, "Operation timed out\n");
+
+	if (!ret) {
+		dev_err(xqspi->dev, "Operation timed out\n");
+		ret = -ETIMEDOUT;
+	}
 
 	/* Attempt to recover as best we can */
 	zynqmp_qspi_init_hw(xqspi);
-	return -ETIMEDOUT;
+	return ret;
 }
 
 /**
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#13 lore raw

Re: [PATCH 4/5] spi: zynqmp-gqspi: Allow interrupting operations

Hello Sean,

Quoted 3 lines · Sean Anderson

Some operations (such as reading several megabytes of data from a flash) can take several seconds or more. Users may want to cancel such operations. Allow them to do so now that we have a way to recover.

I fully agree with the observation, I tried myself interrupting too long transfers with another spi controller:

e0205d6203c2c ("spi: atmel: Prevent false timeouts on long transfers")

But there were issues reported, so we limited the signals to SIGKILLs:

1ca2761a77349 ("spi: atmel: Do not cancel a transfer upon any signal")

But jffs2 plays with sigkills, so for spi memories it does not work well, we had to revert:

890188d2d7e4a ("spi: atmel: Prevent spi transfers from being killed")

Same thing was also observed on Zynq7000:

26cfc0dbe43aa ("spi: spi-zynq-qspi: use wait_for_completion_timeout to make zynq_qspi_exec_mem_op not interruptible")

I would however hint to use a specific helper for deriving your timeouts if you play with spi memories, because it is interesting to adapt the values nevertheless:

d8e4ebf870187 ("spi: Create a helper to derive adaptive timeouts")

Thanks,
Miquèl

#14 lore raw

Re: [PATCH 4/5] spi: zynqmp-gqspi: Allow interrupting operations

Quoted 24 lines · Miquel Raynal

Hello Sean,

Quoted 3 lines · Sean Anderson

Some operations (such as reading several megabytes of data from a flash) can take several seconds or more. Users may want to cancel such operations. Allow them to do so now that we have a way to recover.

I fully agree with the observation, I tried myself interrupting too long transfers with another spi controller:

e0205d6203c2c ("spi: atmel: Prevent false timeouts on long transfers")

But there were issues reported, so we limited the signals to SIGKILLs:

1ca2761a77349 ("spi: atmel: Do not cancel a transfer upon any signal")

But jffs2 plays with sigkills, so for spi memories it does not work well, we had to revert:

890188d2d7e4a ("spi: atmel: Prevent spi transfers from being killed")

Same thing was also observed on Zynq7000:

Quoted 7 lines

26cfc0dbe43aa ("spi: spi-zynq-qspi: use wait_for_completion_timeout to make zynq_qspi_exec_mem_op not interruptible")

I would however hint to use a specific helper for deriving your timeouts if you play with spi memories, because it is interesting to adapt the values nevertheless:

d8e4ebf870187 ("spi: Create a helper to derive adaptive timeouts")

Hm, ok. I wasn't sure whether this was allowed, but I saw a lot of interruptable users under drivers/spi.

I guess I'll drop this patch for v2.

--Sean

#15 lore raw

PATCH 5/5 ARM64: xilinx: zynqmp: Add QSPI reset

In reply to Sean Anderson

Add a reset to the QSPI.

---

 arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +1 -0
index 467f084c6469..5dac0542a48d 100644
@@ -986,6 +986,7 @@ qspi: spi@ff0f0000 {
 			#size-cells = <0>;
 			/* iommus = <&smmu 0x873>; */
 			power-domains = <&zynqmp_firmware PD_QSPI>;
+			resets = <&zynqmp_reset ZYNQMP_RESET_QSPI>;
 		};
 
 		psgtr: phy@fd400000 {
Signature · 1 line
2.35.1.1320.gc452695387.dirty
maintainer
#16 lore raw
In reply to Sean Anderson
Quoted 3 lines · Sean Anderson

This series adds support for resetting the QSPI controller if we have a timeout. I find this greatly improves the stability of the device, which would tend to break after any timeout.

If you're hitting a timeout that tends to indicate there's already a serious stability problem...

#17 lore raw
Quoted 7 lines · Mark Brown
Quoted 3 lines · Sean Anderson

This series adds support for resetting the QSPI controller if we have a timeout. I find this greatly improves the stability of the device, which would tend to break after any timeout.

If you're hitting a timeout that tends to indicate there's already a serious stability problem...

This was mostly hit when I was hacking on the driver. But of course there are probably still bugs lurking in this driver, so I think it is good to handle the exceptional conditions in a more-robust way.

--Sean

maintainer
#18 lore raw
Quoted 8 lines · Sean Anderson
Quoted 2 lines · Mark Brown

If you're hitting a timeout that tends to indicate there's already a serious stability problem...

This was mostly hit when I was hacking on the driver. But of course there are probably still bugs lurking in this driver, so I think it is good to handle the exceptional conditions in a more-robust way.

I'm not saying it's a bad idea, but your changelog is written in a way that makes it sound like timeouts are normal.

#19 lore raw
Quoted 6 lines · Mark Brown
Quoted 4 lines · Sean Anderson
Quoted 2 lines · Mark Brown

If you're hitting a timeout that tends to indicate there's already a serious stability problem...

Quoted 6 lines
Quoted 3 lines

This was mostly hit when I was hacking on the driver. But of course there are probably still bugs lurking in this driver, so I think it is good to handle the exceptional conditions in a more-robust way.

I'm not saying it's a bad idea, but your changelog is written in a way that makes it sound like timeouts are normal.

I've updated my cover letter for v2 to include the above blurb. Hopefully that clears things up.

--Sean

#20 lore raw
In reply to Mark Brown
Quoted 7 lines · Mark Brown
Quoted 3 lines · Sean Anderson

This series adds support for resetting the QSPI controller if we have a timeout. I find this greatly improves the stability of the device, which would tend to break after any timeout.

If you're hitting a timeout that tends to indicate there's already a serious stability problem...

Yes, unless the timeout is reached for "good reasons", ie. you request substantial amounts of data (typically from a memory device) and the timeout is too short compared to the theoretical time spent in the transfer. A loaded machine can also increase the number of false positives I guess.

Cheers,
Miquèl

maintainer
#21 lore raw
Quoted 10 lines · Miquel Raynal
Quoted 2 lines · Mark Brown

If you're hitting a timeout that tends to indicate there's already a serious stability problem...

Yes, unless the timeout is reached for "good reasons", ie. you request substantial amounts of data (typically from a memory device) and the timeout is too short compared to the theoretical time spent in the transfer. A loaded machine can also increase the number of false positives I guess.

I'd argue that all of those are bad reasons, I'd only expect us to time out when there's a bug - choosing too low a timeout or doing things in a way that generates timeouts under load is a problem.

#22 lore raw
Quoted 12 lines · Mark Brown
Quoted 10 lines · Miquel Raynal
Quoted 2 lines · Mark Brown

If you're hitting a timeout that tends to indicate there's already a serious stability problem...

Yes, unless the timeout is reached for "good reasons", ie. you request substantial amounts of data (typically from a memory device) and the timeout is too short compared to the theoretical time spent in the transfer. A loaded machine can also increase the number of false positives I guess.

Quoted 3 lines

I'd argue that all of those are bad reasons, I'd only expect us to time out when there's a bug - choosing too low a timeout or doing things in a way that generates timeouts under load is a problem.

There's no transmit DMA for this device. So if you are under high load and make a long transfer, it's possible to time out. I don't know if it's possible to fix that very easily. The timeout calculation assumes that data is being transferred at the SPI bus rate.

That said, in the common case (NOR flash) writes don't work like that. To write a flash, we make a short transfer (such as an eraseblock) and then poll the status register before making another transfer. With short transfers there is less probability of timing out because the extra time makes up more of the duration.

--Sean

maintainer
#23 lore raw
Quoted 9 lines · Sean Anderson
Quoted 7 lines · Mark Brown
Quoted 5 lines · Miquel Raynal

Yes, unless the timeout is reached for "good reasons", ie. you request substantial amounts of data (typically from a memory device) and the timeout is too short compared to the theoretical time spent in the transfer. A loaded machine can also increase the number of false positives I guess.

Quoted 8 lines
Quoted 3 lines

I'd argue that all of those are bad reasons, I'd only expect us to time out when there's a bug - choosing too low a timeout or doing things in a way that generates timeouts under load is a problem.

There's no transmit DMA for this device. So if you are under high load and make a long transfer, it's possible to time out. I don't know if it's possible to fix that very easily. The timeout calculation assumes that data is being transferred at the SPI bus rate.

In that case I wouldn't expect the timeout to apply to the whole operation, or I'd expect a timeout applied waiting for something interrupt driven to not to be fired unless we stop making forward progress.

#24 lore raw
Quoted 19 lines · Mark Brown
Quoted 9 lines · Sean Anderson
Quoted 7 lines · Mark Brown
Quoted 5 lines · Miquel Raynal

Yes, unless the timeout is reached for "good reasons", ie. you request substantial amounts of data (typically from a memory device) and the timeout is too short compared to the theoretical time spent in the transfer. A loaded machine can also increase the number of false positives I guess.

Quoted 8 lines
Quoted 3 lines

I'd argue that all of those are bad reasons, I'd only expect us to time out when there's a bug - choosing too low a timeout or doing things in a way that generates timeouts under load is a problem.

There's no transmit DMA for this device. So if you are under high load and make a long transfer, it's possible to time out. I don't know if it's possible to fix that very easily. The timeout calculation assumes that data is being transferred at the SPI bus rate.

Quoted 4 lines

In that case I wouldn't expect the timeout to apply to the whole operation, or I'd expect a timeout applied waiting for something interrupt driven to not to be fired unless we stop making forward progress.

I don't know if there are any helpers we can use for this. To implement this we'd need something like schedule_timeout() but where the interrupt handler calls mod_timer() whenever it does work.

--Sean