* [PATCH v6 0/4] spi: cadence-xspi: Add support for panic mem writes
@ 2026-12-03 9:11 Paul Cercueil
2026-12-03 9:11 ` [PATCH v6 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Paul Cercueil @ 2026-12-03 9:11 UTC (permalink / raw)
To: Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Kees Cook, Tony Luck, Guilherme G. Piccoli
Cc: linux-spi, devicetree, Thomas Petazzoni, Sunil Kovvuri Goutham,
Paul Cercueil
Hi Mark,
Here is the v6 of my patchset that updates the cadence-xspi driver to
add support for panic mem writes to a memory partition configured as
pstore.
I just addressed a few issues spotted by Sashiko. I think it should pass
the automated review now (famous last words).
Changelog in v6:
- [1/4]:
- Return SDMA transfer error after cleaning the IRQ flag, and also
clear the CDNS_XSPI_SDMA_ERROR IRQ flag.
- [3/4]:
- Move check on SDMA transfer length outside the 'use_dma' branch
in cdns_xspi_sdma_handle()
Cheers,
-Paul
Tanmay Jagdale (4):
spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready()
spi: cadence-xspi: Add irq-less support
spi: cadence-xspi: Add support for panic writes
spi: dt-bindings: cadence: Make XSPI's IRQ line optional
.../devicetree/bindings/spi/cdns,xspi.yaml | 1 -
drivers/spi/spi-cadence-xspi.c | 126 +++++++++++-------
2 files changed, 77 insertions(+), 50 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v6 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() 2026-12-03 9:11 [PATCH v6 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil @ 2026-12-03 9:11 ` Paul Cercueil 2026-12-03 9:28 ` sashiko-bot 2026-12-03 9:11 ` [PATCH v6 2/4] spi: cadence-xspi: Add irq-less support Paul Cercueil ` (2 subsequent siblings) 3 siblings, 1 reply; 9+ messages in thread From: Paul Cercueil @ 2026-12-03 9:11 UTC (permalink / raw) To: Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kees Cook, Tony Luck, Guilherme G. Piccoli Cc: linux-spi, devicetree, Thomas Petazzoni, Sunil Kovvuri Goutham, Tanmay Jagdale, Paul Cercueil From: Tanmay Jagdale <tanmay@marvell.com> Handle SDMA transfer errors reported by the hardware in cdns_xspi_is_dma_ready(). When a transfer error is found, just print an error message and return false. Signed-off-by: Tanmay Jagdale <tanmay@marvell.com> Co-developed-by: Paul Cercueil <paul.cercueil@bootlin.com> Signed-off-by: Paul Cercueil <paul.cercueil@bootlin.com> --- Changelog: v6: Return SDMA transfer error after cleaning the IRQ flag, and also clear the CDNS_XSPI_SDMA_ERROR IRQ flag. v5: New patch --- drivers/spi/spi-cadence-xspi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c index a42fab719b7a..d041f90321f6 100644 --- a/drivers/spi/spi-cadence-xspi.c +++ b/drivers/spi/spi-cadence-xspi.c @@ -1236,16 +1236,21 @@ static bool cdns_xspi_is_sdma_ready(struct cdns_xspi_dev *cdns_xspi, bool sleep) if (readl_relaxed_poll_timeout (cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG, ctrl_stat, - (ctrl_stat & CDNS_XSPI_SDMA_TRIGGER), + ctrl_stat & (CDNS_XSPI_SDMA_TRIGGER | CDNS_XSPI_SDMA_ERROR), sleep ? MRVL_XSPI_POLL_DELAY_US : 0, sleep ? MRVL_XSPI_POLL_TIMEOUT_US : 0)) { return false; } /* Clear the flag */ - writel(CDNS_XSPI_SDMA_TRIGGER, + writel(CDNS_XSPI_SDMA_TRIGGER | CDNS_XSPI_SDMA_ERROR, cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); + if (ctrl_stat & CDNS_XSPI_SDMA_ERROR) { + dev_err(cdns_xspi->dev, "Slave DMA transaction error\n"); + return false; + } + return true; } -- 2.47.3 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v6 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() 2026-12-03 9:11 ` [PATCH v6 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil @ 2026-12-03 9:28 ` sashiko-bot 0 siblings, 0 replies; 9+ messages in thread From: sashiko-bot @ 2026-12-03 9:28 UTC (permalink / raw) To: Paul Cercueil; +Cc: devicetree, robh, conor+dt Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] spi: cadence-xspi: stale CDNS_XSPI_SDMA_ERROR aborts next transfer mid-command - [Low] spi: cadence-xspi: unconditional W1C clear in cdns_xspi_is_sdma_ready() drops error - [Low] spi: cadence-xspi: commit body misspells cdns_xspi_is_sdma_ready() and lacks why - [Low] spi: cadence-xspi: missing Fixes trailer for commit 931e389ded0f -- commit 53c1565afeab2108b0a98116213822b6a6211069 Author: Tanmay Jagdale <tanmay@marvell.com> > spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() > > Handle SDMA transfer errors reported by the hardware in > cdns_xspi_is_dma_ready(). When a transfer error is found, just print an > error message and return false. [Severity: Low] The function name here is misspelled as cdns_xspi_is_dma_ready() instead of cdns_xspi_is_sdma_ready(). It would also help to explain why this change is needed (for example, that an SDMA error otherwise causes cdns_xspi_is_sdma_ready() to stall until timeout without logging or clearing the flag) rather than only restating what the patch does. > > Signed-off-by: Tanmay Jagdale <tanmay@marvell.com> > Co-developed-by: Paul Cercueil <paul.cercueil@bootlin.com> > Signed-off-by: Paul Cercueil <paul.cercueil@bootlin.com> [Severity: Low] This fixes missing SDMA error handling in cdns_xspi_is_sdma_ready(). Should this include: Fixes: 931e389ded0f ("spi: cadence: Add Marvell xfer operation support") > diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c > index a42fab719b7af..d041f90321f6c 100644 > --- a/drivers/spi/spi-cadence-xspi.c > +++ b/drivers/spi/spi-cadence-xspi.c > @@ -1236,16 +1236,21 @@ static bool cdns_xspi_is_sdma_ready(struct cdns_xspi_dev *cdns_xspi, bool sleep) > if (readl_relaxed_poll_timeout > (cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG, > ctrl_stat, > - (ctrl_stat & CDNS_XSPI_SDMA_TRIGGER), > + ctrl_stat & (CDNS_XSPI_SDMA_TRIGGER | CDNS_XSPI_SDMA_ERROR), > sleep ? MRVL_XSPI_POLL_DELAY_US : 0, > sleep ? MRVL_XSPI_POLL_TIMEOUT_US : 0)) { > return false; > } [Severity: Medium] Can a stale CDNS_XSPI_SDMA_ERROR from a previous sdma_handler() abort the next transfer mid-command? In cdns_xspi_transfer_one_message_b0(), CDNS_XSPI_INTR_STATUS_REG is never cleared before triggering commands, and CDNS_XSPI_SDMA_ERROR is not checked after sdma_handler() returns (unlike cdns_xspi_send_stig_command(), which checks sdma_error after sdma_handler() as well). If hardware raises CDNS_XSPI_SDMA_ERROR during sdma_handler(), that transfer returns 0 with the error bit latched. The next chunk or message triggers a new GENERIC and DSEQ command pair, then cdns_xspi_is_sdma_ready() fails on the stale error and leaves the new command unserviced in hardware. Clearing stale status bits before triggering commands and checking CDNS_XSPI_SDMA_ERROR after sdma_handler() would prevent this. > > /* Clear the flag */ > - writel(CDNS_XSPI_SDMA_TRIGGER, > + writel(CDNS_XSPI_SDMA_TRIGGER | CDNS_XSPI_SDMA_ERROR, > cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); > > + if (ctrl_stat & CDNS_XSPI_SDMA_ERROR) { > + dev_err(cdns_xspi->dev, "Slave DMA transaction error\n"); > + return false; > + } [Severity: Low] Could this unconditional write-1-to-clear drop a concurrently asserted CDNS_XSPI_SDMA_ERROR? If hardware sets CDNS_XSPI_SDMA_ERROR between readl_relaxed_poll_timeout() observing only CDNS_XSPI_SDMA_TRIGGER and this writel(), the error bit is cleared without being seen in ctrl_stat and the function returns true. Writing ctrl_stat & (CDNS_XSPI_SDMA_TRIGGER | CDNS_XSPI_SDMA_ERROR) would clear only the observed bits, matching cdns_xspi_irq_handler(). -- Sashiko AI review · https://sashiko.dev/#/patchset/20261203091112.9449-1-paul.cercueil@bootlin.com?part=1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v6 2/4] spi: cadence-xspi: Add irq-less support 2026-12-03 9:11 [PATCH v6 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil 2026-12-03 9:11 ` [PATCH v6 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil @ 2026-12-03 9:11 ` Paul Cercueil 2026-12-03 9:36 ` sashiko-bot 2026-12-03 9:11 ` [PATCH v6 3/4] spi: cadence-xspi: Add support for panic writes Paul Cercueil 2026-12-03 9:11 ` [PATCH v6 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional Paul Cercueil 3 siblings, 1 reply; 9+ messages in thread From: Paul Cercueil @ 2026-12-03 9:11 UTC (permalink / raw) To: Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kees Cook, Tony Luck, Guilherme G. Piccoli Cc: linux-spi, devicetree, Thomas Petazzoni, Sunil Kovvuri Goutham, Tanmay Jagdale, Paul Cercueil From: Tanmay Jagdale <tanmay@marvell.com> Make the interrupt line optional. If not provided, the driver will instead resort to polling registers. This can be useful in itself, but will be used later to support write on kernel panic. Note that in irq-less mode we use cdns_xspi_is_{sdma,stig}_ready() to wait for the commands to complete. The old timeout value was way too low to cover large transfers, so it was increased to 100 ms. Signed-off-by: Tanmay Jagdale <tanmay@marvell.com> Co-developed-by: Paul Cercueil <paul.cercueil@bootlin.com> Signed-off-by: Paul Cercueil <paul.cercueil@bootlin.com> --- Changelog: v6: No change v5: - Use forward declarations for cdns_xspi_is_{sdma,stig}_ready() instead of moving them. - Increase MRVL_XSPI_POLL_TIMEOUT_US timeout value v3-v4: No change v2: Make sure we only enable interrupts if not using polling mode --- drivers/spi/spi-cadence-xspi.c | 49 +++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c index d041f90321f6..1738a5983f05 100644 --- a/drivers/spi/spi-cadence-xspi.c +++ b/drivers/spi/spi-cadence-xspi.c @@ -277,7 +277,7 @@ #define MRVL_XFER_QWORD_BYTECOUNT 8 #define MRVL_XFER_MAX_LEN (MRVL_XFER_QWORD_COUNT * MRVL_XFER_QWORD_BYTECOUNT) -#define MRVL_XSPI_POLL_TIMEOUT_US 1000 +#define MRVL_XSPI_POLL_TIMEOUT_US 100000 #define MRVL_XSPI_POLL_DELAY_US 10 /* Macros for calculating data bits in generic command @@ -365,6 +365,9 @@ struct cdns_xspi_dev { int current_xfer_qword; }; +static bool cdns_xspi_is_stig_ready(struct cdns_xspi_dev *cdns_xspi, bool sleep); +static bool cdns_xspi_is_sdma_ready(struct cdns_xspi_dev *cdns_xspi, bool sleep); + static void cdns_xspi_dma_cleanup(void *data) { struct cdns_xspi_dev *cdns_xspi = data; @@ -687,7 +690,8 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, reinit_completion(&cdns_xspi->cmd_complete); reinit_completion(&cdns_xspi->sdma_complete); - cdns_xspi->set_interrupts_handler(cdns_xspi, true); + if (cdns_xspi->irq >= 0) + cdns_xspi->set_interrupts_handler(cdns_xspi, true); cdns_xspi->sdma_error = false; memset(cmd_regs, 0, sizeof(cmd_regs)); @@ -716,20 +720,29 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, cdns_xspi_trigger_command(cdns_xspi, cmd_regs); - wait_for_completion(&cdns_xspi->sdma_complete); - if (cdns_xspi->sdma_error) { - cdns_xspi->set_interrupts_handler(cdns_xspi, false); + if (cdns_xspi->irq >= 0) { + wait_for_completion(&cdns_xspi->sdma_complete); + if (cdns_xspi->sdma_error) { + cdns_xspi->set_interrupts_handler(cdns_xspi, false); + return -EIO; + } + } else if (!cdns_xspi_is_sdma_ready(cdns_xspi, true)) { return -EIO; } ret = cdns_xspi->sdma_handler(cdns_xspi); if (ret || cdns_xspi->sdma_error) { - cdns_xspi->set_interrupts_handler(cdns_xspi, false); + if (cdns_xspi->irq >= 0) + cdns_xspi->set_interrupts_handler(cdns_xspi, false); return ret ?: -EIO; } } - wait_for_completion(&cdns_xspi->cmd_complete); - cdns_xspi->set_interrupts_handler(cdns_xspi, false); + if (cdns_xspi->irq >= 0) { + wait_for_completion(&cdns_xspi->cmd_complete); + cdns_xspi->set_interrupts_handler(cdns_xspi, false); + } else if (!cdns_xspi_is_stig_ready(cdns_xspi, true)) { + return -EIO; + } cmd_status = cdns_xspi_check_command_status(cdns_xspi); if (cmd_status) @@ -1216,6 +1229,7 @@ static int cdns_xspi_prepare_transfer(int cs, int dir, int len, u32 *cmd_regs) return 0; } +#endif /* CONFIG_64BIT */ static bool cdns_xspi_is_stig_ready(struct cdns_xspi_dev *cdns_xspi, bool sleep) { @@ -1254,6 +1268,7 @@ static bool cdns_xspi_is_sdma_ready(struct cdns_xspi_dev *cdns_xspi, bool sleep) return true; } +#ifdef CONFIG_64BIT static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller, struct spi_message *m) { @@ -1506,15 +1521,17 @@ static int cdns_xspi_probe(struct platform_device *pdev) } #endif - cdns_xspi->irq = platform_get_irq(pdev, 0); - if (cdns_xspi->irq < 0) - return -ENXIO; + cdns_xspi->irq = platform_get_irq_optional(pdev, 0); + if (cdns_xspi->irq < 0 && cdns_xspi->irq != -ENXIO) + return cdns_xspi->irq; - ret = devm_request_irq(dev, cdns_xspi->irq, cdns_xspi_irq_handler, - IRQF_SHARED, pdev->name, cdns_xspi); - if (ret) { - dev_err(dev, "Failed to request IRQ: %d\n", cdns_xspi->irq); - return ret; + if (cdns_xspi->irq >= 0) { + ret = devm_request_irq(dev, cdns_xspi->irq, cdns_xspi_irq_handler, + IRQF_SHARED, pdev->name, cdns_xspi); + if (ret) { + dev_err(dev, "Failed to request IRQ: %d\n", cdns_xspi->irq); + return ret; + } } #ifdef CONFIG_64BIT -- 2.47.3 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v6 2/4] spi: cadence-xspi: Add irq-less support 2026-12-03 9:11 ` [PATCH v6 2/4] spi: cadence-xspi: Add irq-less support Paul Cercueil @ 2026-12-03 9:36 ` sashiko-bot 0 siblings, 0 replies; 9+ messages in thread From: sashiko-bot @ 2026-12-03 9:36 UTC (permalink / raw) To: Paul Cercueil; +Cc: devicetree, robh, conor+dt Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] spi: cadence-xspi: stale SDMA status bits not cleared in IRQ-less mode - [Medium] spi: cadence-xspi: SDMA errors during sdma_handler() missed without IRQ -- commit 225aa14fe46b19e08b932b29be677c66a07c1404 Author: Tanmay Jagdale <tanmay@marvell.com> spi: cadence-xspi: Add irq-less support This commit makes the IRQ optional in the Cadence XSPI driver and falls back to polling for STIG and SDMA completion when no interrupt line is present. > diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c > index d041f90321f6c..1738a5983f054 100644 > --- a/drivers/spi/spi-cadence-xspi.c > +++ b/drivers/spi/spi-cadence-xspi.c [ ... ] > @@ -687,7 +690,8 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, > > reinit_completion(&cdns_xspi->cmd_complete); > reinit_completion(&cdns_xspi->sdma_complete); > - cdns_xspi->set_interrupts_handler(cdns_xspi, true); > + if (cdns_xspi->irq >= 0) > + cdns_xspi->set_interrupts_handler(cdns_xspi, true); > cdns_xspi->sdma_error = false; [Severity: High] Can stale CDNS_XSPI_SDMA_TRIGGER or CDNS_XSPI_SDMA_ERROR bits in CDNS_XSPI_INTR_STATUS_REG be left latched here when running without an IRQ? Skipping set_interrupts_handler() leaves CDNS_XSPI_INTR_STATUS_REG uncleared before triggering the command, so bits left over from firmware or a prior timed-out transfer remain set. cdns_xspi_is_sdma_ready() polls that register directly and clears the bits only after matching them. A stale CDNS_XSPI_SDMA_TRIGGER bit makes cdns_xspi_is_sdma_ready() return early and run sdma_handler() with stale hardware direction and size registers on the aliased in_buffer/out_buffer union, which can overwrite a caller's TX buffer during a write op. Clearing CDNS_XSPI_SDMA_TRIGGER | CDNS_XSPI_SDMA_ERROR in CDNS_XSPI_INTR_STATUS_REG before triggering the command would prevent stale status bits from being consumed. > @@ -716,20 +720,29 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, > > cdns_xspi_trigger_command(cdns_xspi, cmd_regs); > > - wait_for_completion(&cdns_xspi->sdma_complete); > - if (cdns_xspi->sdma_error) { > - cdns_xspi->set_interrupts_handler(cdns_xspi, false); > + if (cdns_xspi->irq >= 0) { > + wait_for_completion(&cdns_xspi->sdma_complete); > + if (cdns_xspi->sdma_error) { > + cdns_xspi->set_interrupts_handler(cdns_xspi, false); > + return -EIO; > + } > + } else if (!cdns_xspi_is_sdma_ready(cdns_xspi, true)) { > return -EIO; > } > ret = cdns_xspi->sdma_handler(cdns_xspi); > if (ret || cdns_xspi->sdma_error) { > - cdns_xspi->set_interrupts_handler(cdns_xspi, false); > + if (cdns_xspi->irq >= 0) > + cdns_xspi->set_interrupts_handler(cdns_xspi, false); > return ret ?: -EIO; > } [Severity: Medium] Will SDMA errors raised during sdma_handler() go undetected when cdns_xspi->irq < 0? cdns_xspi->sdma_error is only set by cdns_xspi_irq_handler(), which is not registered in IRQ-less mode. If hardware asserts CDNS_XSPI_SDMA_ERROR while sdma_handler() is transferring data, the check here misses it and the command can return success with partial data. The bit also stays latched in CDNS_XSPI_INTR_STATUS_REG because cdns_xspi_is_stig_ready() only polls CDNS_XSPI_CTRL_STATUS_REG, causing the next data-phase STIG command to fail with -EIO. Reading and clearing CDNS_XSPI_SDMA_ERROR from CDNS_XSPI_INTR_STATUS_REG after sdma_handler() when cdns_xspi->irq < 0 would catch these errors. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261203091112.9449-1-paul.cercueil@bootlin.com?part=2 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v6 3/4] spi: cadence-xspi: Add support for panic writes 2026-12-03 9:11 [PATCH v6 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil 2026-12-03 9:11 ` [PATCH v6 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil 2026-12-03 9:11 ` [PATCH v6 2/4] spi: cadence-xspi: Add irq-less support Paul Cercueil @ 2026-12-03 9:11 ` Paul Cercueil 2026-12-03 9:37 ` sashiko-bot 2026-12-03 9:11 ` [PATCH v6 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional Paul Cercueil 3 siblings, 1 reply; 9+ messages in thread From: Paul Cercueil @ 2026-12-03 9:11 UTC (permalink / raw) To: Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kees Cook, Tony Luck, Guilherme G. Piccoli Cc: linux-spi, devicetree, Thomas Petazzoni, Sunil Kovvuri Goutham, Tanmay Jagdale, Paul Cercueil From: Tanmay Jagdale <tanmay@marvell.com> Advertise support for panic writes. When a memory op is received with the 'panic' flag set, the driver will then work without relying on interrupts and without sleeping. Signed-off-by: Tanmay Jagdale <tanmay@marvell.com> Co-developed-by: Paul Cercueil <paul.cercueil@bootlin.com> Signed-off-by: Paul Cercueil <paul.cercueil@bootlin.com> --- Changelog: v6: Move check on SDMA transfer length outside the 'use_dma' branch in cdns_xspi_sdma_handle() v5: Update the new cdns_xspi_sdma_handle() introduced by a third-party since the v4, so that it will work with panic writes. v3-v4: No change v2: - Don't enable interrupts if doing a panic write - Use a new cdns_readl_poll() macro that will resolve to calling readl_relaxed_poll_timeout_atomic() when doing a panic write, or readl_relaxed_poll_timeout() otherwise. - Drop cdns_xspi->panic_write. We don't actually need to check it in cdns_xspi_is_dll_locked(), because this code is never called in the kernel panic path. --- drivers/spi/spi-cadence-xspi.c | 80 ++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c index 1738a5983f05..974dd78518e3 100644 --- a/drivers/spi/spi-cadence-xspi.c +++ b/drivers/spi/spi-cadence-xspi.c @@ -295,6 +295,10 @@ #define GENERIC_CMD_REG_3_NEEDED(len) (len > 7) #define GENERIC_CMD_REG_2_NEEDED(len) (len > 3) +#define cdns_readl_poll(addr, val, cond, delay_us, timeout_us, can_sleep) \ + ((can_sleep) ? readl_relaxed_poll_timeout(addr, val, cond, delay_us, timeout_us) \ + : readl_relaxed_poll_timeout_atomic(addr, val, cond, delay_us, timeout_us)) + enum cdns_xspi_stig_instr_type { CDNS_XSPI_STIG_INSTR_TYPE_0, CDNS_XSPI_STIG_INSTR_TYPE_1, @@ -358,7 +362,7 @@ struct cdns_xspi_dev { u8 hw_num_banks; const struct cdns_xspi_driver_data *driver_data; - int (*sdma_handler)(struct cdns_xspi_dev *cdns_xspi); + int (*sdma_handler)(struct cdns_xspi_dev *cdns_xspi, bool use_dma); void (*set_interrupts_handler)(struct cdns_xspi_dev *cdns_xspi, bool enabled); bool xfer_in_progress; @@ -484,23 +488,21 @@ static int cdns_xspi_dma_transfer(struct cdns_xspi_dev *cdns_xspi, return ret; } -static int cdns_xspi_wait_for_controller_idle(struct cdns_xspi_dev *cdns_xspi) +static int cdns_xspi_wait_for_controller_idle(struct cdns_xspi_dev *cdns_xspi, bool sleep) { u32 ctrl_stat; - return readl_relaxed_poll_timeout(cdns_xspi->iobase + - CDNS_XSPI_CTRL_STATUS_REG, - ctrl_stat, - ((ctrl_stat & - CDNS_XSPI_CTRL_BUSY) == 0), - 100, 1000); + return cdns_readl_poll(cdns_xspi->iobase + CDNS_XSPI_CTRL_STATUS_REG, + ctrl_stat, !(ctrl_stat & CDNS_XSPI_CTRL_BUSY), + 100, 1000, sleep); + } -static int cdns_xspi_set_stig_mode(struct cdns_xspi_dev *cdns_xspi) +static int cdns_xspi_set_stig_mode(struct cdns_xspi_dev *cdns_xspi, bool sleep) { int ret; - ret = cdns_xspi_wait_for_controller_idle(cdns_xspi); + ret = cdns_xspi_wait_for_controller_idle(cdns_xspi, sleep); if (ret < 0) return -EIO; @@ -641,7 +643,7 @@ static inline void cdns_xspi_sdma_write(struct cdns_xspi_dev *cdns_xspi, size_t iowrite8_rep(dst, (const u8 *)buf + offset, len); } -static int cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) +static int cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi, bool use_dma) { u32 sdma_size, sdma_trd_info; u8 sdma_dir; @@ -657,10 +659,13 @@ static int cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) sdma_size, cdns_xspi->sdma_xfer_len); return -EINVAL; } - ret = cdns_xspi_dma_transfer(cdns_xspi, sdma_size, - sdma_dir == CDNS_XSPI_SDMA_DIR_READ); - if (ret != -EAGAIN) - return ret; + + if (use_dma) { + ret = cdns_xspi_dma_transfer(cdns_xspi, sdma_size, + sdma_dir == CDNS_XSPI_SDMA_DIR_READ); + if (ret != -EAGAIN) + return ret; + } switch (sdma_dir) { case CDNS_XSPI_SDMA_DIR_READ: @@ -684,13 +689,13 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, int ret; int dummybytes = op->dummy.nbytes; - ret = cdns_xspi_set_stig_mode(cdns_xspi); + ret = cdns_xspi_set_stig_mode(cdns_xspi, !op->panic_write); if (ret) return ret; reinit_completion(&cdns_xspi->cmd_complete); reinit_completion(&cdns_xspi->sdma_complete); - if (cdns_xspi->irq >= 0) + if (cdns_xspi->irq >= 0 && !op->panic_write) cdns_xspi->set_interrupts_handler(cdns_xspi, true); cdns_xspi->sdma_error = false; @@ -720,16 +725,16 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, cdns_xspi_trigger_command(cdns_xspi, cmd_regs); - if (cdns_xspi->irq >= 0) { + if (cdns_xspi->irq >= 0 && !op->panic_write) { wait_for_completion(&cdns_xspi->sdma_complete); if (cdns_xspi->sdma_error) { cdns_xspi->set_interrupts_handler(cdns_xspi, false); return -EIO; } - } else if (!cdns_xspi_is_sdma_ready(cdns_xspi, true)) { + } else if (!cdns_xspi_is_sdma_ready(cdns_xspi, !op->panic_write)) { return -EIO; } - ret = cdns_xspi->sdma_handler(cdns_xspi); + ret = cdns_xspi->sdma_handler(cdns_xspi, !op->panic_write); if (ret || cdns_xspi->sdma_error) { if (cdns_xspi->irq >= 0) cdns_xspi->set_interrupts_handler(cdns_xspi, false); @@ -737,10 +742,10 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, } } - if (cdns_xspi->irq >= 0) { + if (cdns_xspi->irq >= 0 && !op->panic_write) { wait_for_completion(&cdns_xspi->cmd_complete); cdns_xspi->set_interrupts_handler(cdns_xspi, false); - } else if (!cdns_xspi_is_stig_ready(cdns_xspi, true)) { + } else if (!cdns_xspi_is_stig_ready(cdns_xspi, !op->panic_write)) { return -EIO; } @@ -1119,7 +1124,7 @@ static void m_iowriteq(void __iomem *addr, const void *buf, int len) } } -static int marvell_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) +static int marvell_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi, bool use_dma) { u32 sdma_size, sdma_trd_info; u8 sdma_dir; @@ -1235,24 +1240,20 @@ static bool cdns_xspi_is_stig_ready(struct cdns_xspi_dev *cdns_xspi, bool sleep) { u32 ctrl_stat; - return !readl_relaxed_poll_timeout - (cdns_xspi->iobase + CDNS_XSPI_CTRL_STATUS_REG, - ctrl_stat, - ((ctrl_stat & BIT(3)) == 0), - sleep ? MRVL_XSPI_POLL_DELAY_US : 0, - sleep ? MRVL_XSPI_POLL_TIMEOUT_US : 0); + return !cdns_readl_poll(cdns_xspi->iobase + CDNS_XSPI_CTRL_STATUS_REG, + ctrl_stat, !(ctrl_stat & BIT(3)), + MRVL_XSPI_POLL_DELAY_US, + MRVL_XSPI_POLL_TIMEOUT_US, sleep); } static bool cdns_xspi_is_sdma_ready(struct cdns_xspi_dev *cdns_xspi, bool sleep) { u32 ctrl_stat; - if (readl_relaxed_poll_timeout - (cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG, - ctrl_stat, - ctrl_stat & (CDNS_XSPI_SDMA_TRIGGER | CDNS_XSPI_SDMA_ERROR), - sleep ? MRVL_XSPI_POLL_DELAY_US : 0, - sleep ? MRVL_XSPI_POLL_TIMEOUT_US : 0)) { + if (cdns_readl_poll(cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG, ctrl_stat, + ctrl_stat & (CDNS_XSPI_SDMA_TRIGGER | CDNS_XSPI_SDMA_ERROR), + MRVL_XSPI_POLL_DELAY_US, MRVL_XSPI_POLL_TIMEOUT_US, + sleep)) { return false; } @@ -1282,7 +1283,7 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller, int cs_change = 0; int ret; - ret = cdns_xspi_set_stig_mode(cdns_xspi); + ret = cdns_xspi_set_stig_mode(cdns_xspi, true); if (ret) goto out; @@ -1337,7 +1338,7 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller, cdns_xspi->sdma_xfer_len = current_transfer_len - 1; if (!cdns_xspi_is_sdma_ready(cdns_xspi, true)) goto out; - if (cdns_xspi->sdma_handler(cdns_xspi)) + if (cdns_xspi->sdma_handler(cdns_xspi, true)) goto out; if (!cdns_xspi_is_stig_ready(cdns_xspi, true)) goto out; @@ -1417,6 +1418,10 @@ static inline bool cdns_is_marvell(struct device *dev) return strstarts(compatible, "marvell,"); } +static const struct spi_controller_mem_caps cdns_xspi_mem_caps = { + .panic_write = true, +}; + static int cdns_xspi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1550,6 +1555,7 @@ static int cdns_xspi_probe(struct platform_device *pdev) } host->num_chipselect = 1 << cdns_xspi->hw_num_banks; + host->mem_caps = &cdns_xspi_mem_caps; ret = devm_spi_register_controller(dev, host); if (ret) { -- 2.47.3 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v6 3/4] spi: cadence-xspi: Add support for panic writes 2026-12-03 9:11 ` [PATCH v6 3/4] spi: cadence-xspi: Add support for panic writes Paul Cercueil @ 2026-12-03 9:37 ` sashiko-bot 0 siblings, 0 replies; 9+ messages in thread From: sashiko-bot @ 2026-12-03 9:37 UTC (permalink / raw) To: Paul Cercueil; +Cc: devicetree, robh, conor+dt Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] spi: cadence-xspi: stale INTR_STATUS bits and missed SDMA errors in poll mode - [Medium] spi: cadence-xspi: cdns_xspi_supports_op() takes devtree_lock in panic write -- commit eea24ee8b207103bf755dc8e3c7be6db03c744ea Author: Tanmay Jagdale <tanmay@marvell.com> spi: cadence-xspi: Add support for panic writes This commit advertises panic_write support on the Cadence XSPI controller and updates STIG command execution and polling helpers to run without interrupts, DMA, or sleeping when op->panic_write is set. > diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c > index 1738a5983f054..974dd78518e39 100644 > --- a/drivers/spi/spi-cadence-xspi.c > +++ b/drivers/spi/spi-cadence-xspi.c [ ... ] > @@ -684,13 +689,13 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, > int ret; > int dummybytes = op->dummy.nbytes; > > - ret = cdns_xspi_set_stig_mode(cdns_xspi); > + ret = cdns_xspi_set_stig_mode(cdns_xspi, !op->panic_write); > if (ret) > return ret; > > reinit_completion(&cdns_xspi->cmd_complete); > reinit_completion(&cdns_xspi->sdma_complete); > - if (cdns_xspi->irq >= 0) > + if (cdns_xspi->irq >= 0 && !op->panic_write) > cdns_xspi->set_interrupts_handler(cdns_xspi, true); > cdns_xspi->sdma_error = false; > > @@ -720,16 +725,16 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, > > cdns_xspi_trigger_command(cdns_xspi, cmd_regs); > > - if (cdns_xspi->irq >= 0) { > + if (cdns_xspi->irq >= 0 && !op->panic_write) { > wait_for_completion(&cdns_xspi->sdma_complete); > if (cdns_xspi->sdma_error) { > cdns_xspi->set_interrupts_handler(cdns_xspi, false); > return -EIO; > } > - } else if (!cdns_xspi_is_sdma_ready(cdns_xspi, true)) { > + } else if (!cdns_xspi_is_sdma_ready(cdns_xspi, !op->panic_write)) { > return -EIO; > } > - ret = cdns_xspi->sdma_handler(cdns_xspi); > + ret = cdns_xspi->sdma_handler(cdns_xspi, !op->panic_write); > if (ret || cdns_xspi->sdma_error) { > if (cdns_xspi->irq >= 0) > cdns_xspi->set_interrupts_handler(cdns_xspi, false); [Severity: Medium] Can stale CDNS_XSPI_SDMA_TRIGGER or CDNS_XSPI_SDMA_ERROR bits in CDNS_XSPI_INTR_STATUS_REG break polling and panic_write commands here? Nothing clears CDNS_XSPI_INTR_STATUS_REG before triggering the STIG command when set_interrupts_handler() is skipped (and cdns_xspi_set_interrupts() never clears it either). In addition, cdns_xspi->sdma_error is only set by cdns_xspi_irq_handler(), so an SDMA error raised during sdma_handler() in polling or panic_write mode goes undetected and stays latched in CDNS_XSPI_INTR_STATUS_REG. On the next data-phase STIG command, cdns_xspi_is_sdma_ready() then observes the stale bit immediately and either aborts with -EIO (leaving the STIG engine busy) or runs sdma_handler() prematurely against stale SDMA registers. Clearing CDNS_XSPI_INTR_STATUS_REG before triggering the command and checking it for CDNS_XSPI_SDMA_ERROR after sdma_handler() in polling mode would avoid this. [ ... ] > @@ -1550,6 +1555,7 @@ static int cdns_xspi_probe(struct platform_device *pdev) > } > > host->num_chipselect = 1 << cdns_xspi->hw_num_banks; > + host->mem_caps = &cdns_xspi_mem_caps; > > ret = devm_spi_register_controller(dev, host); > if (ret) { [Severity: Medium] Can advertising panic_write deadlock on devtree_lock during a kernel panic? When CONFIG_ACPI is enabled (such as arm64 defconfig), both cadence_xspi_mem_ops and marvell_xspi_mem_ops install cdns_xspi_supports_op() even on Device Tree booted systems. spi_mem_exec_op() calls supports_op() unconditionally before exec_op(), including when op->panic_write is set. cdns_xspi_supports_op() calls device_property_read_u32() for spi-tx-bus-width and spi-rx-bus-width, which on OF-backed devices reaches of_find_property() and acquires devtree_lock via raw_spin_lock_irqsave(): CPU0 CPU1 of_find_property() raw_spin_lock_irqsave(&devtree_lock) vpanic() panic_other_cpus_shutdown() <NMI stop while holding lock> kmsg_dump_desc(KMSG_DUMP_PANIC, ...) spi_mem_exec_op() cdns_xspi_supports_op() device_property_read_u32() ... of_find_property() raw_spin_lock_irqsave( &devtree_lock) <-- spins forever If devtree_lock is held by the panicking CPU or an NMI-stopped CPU, the panic dump hangs permanently before writing the log or rebooting. Skipping the property lookups in cdns_xspi_supports_op() when op->panic_write is set (or when !has_acpi_companion(dev)) would avoid taking devtree_lock in panic context. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261203091112.9449-1-paul.cercueil@bootlin.com?part=3 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v6 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional 2026-12-03 9:11 [PATCH v6 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil ` (2 preceding siblings ...) 2026-12-03 9:11 ` [PATCH v6 3/4] spi: cadence-xspi: Add support for panic writes Paul Cercueil @ 2026-12-03 9:11 ` Paul Cercueil 2026-12-03 9:20 ` sashiko-bot 3 siblings, 1 reply; 9+ messages in thread From: Paul Cercueil @ 2026-12-03 9:11 UTC (permalink / raw) To: Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kees Cook, Tony Luck, Guilherme G. Piccoli Cc: linux-spi, devicetree, Thomas Petazzoni, Sunil Kovvuri Goutham, Tanmay Jagdale, Paul Cercueil From: Tanmay Jagdale <tanmay@marvell.com> The spi-cadence-xspi driver will happily work without an IRQ line registered, which means that this IRQ line is optional. Signed-off-by: Tanmay Jagdale <tanmay@marvell.com> Co-developed-by: Paul Cercueil <paul.cercueil@bootlin.com> Signed-off-by: Paul Cercueil <paul.cercueil@bootlin.com> --- Changelog: v3-v6: No change v2: New patch --- Documentation/devicetree/bindings/spi/cdns,xspi.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/devicetree/bindings/spi/cdns,xspi.yaml b/Documentation/devicetree/bindings/spi/cdns,xspi.yaml index b19c2e051e18..b9b8e0cfaa92 100644 --- a/Documentation/devicetree/bindings/spi/cdns,xspi.yaml +++ b/Documentation/devicetree/bindings/spi/cdns,xspi.yaml @@ -56,7 +56,6 @@ dependencies: required: - compatible - reg - - interrupts allOf: - $ref: spi-controller.yaml# -- 2.47.3 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v6 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional 2026-12-03 9:11 ` [PATCH v6 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional Paul Cercueil @ 2026-12-03 9:20 ` sashiko-bot 0 siblings, 0 replies; 9+ messages in thread From: sashiko-bot @ 2026-12-03 9:20 UTC (permalink / raw) To: Paul Cercueil; +Cc: devicetree, robh, conor+dt Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] dt-bindings: spi: interrupts made optional based on driver, not hardware -- commit cb8add302babbaa3f1c062f4de1de3b237c3eb19 Author: Tanmay Jagdale <tanmay@marvell.com> spi: dt-bindings: cadence: Make XSPI's IRQ line optional This commit removes interrupts from the required properties list in the Cadence XSPI Device Tree binding. > diff --git a/Documentation/devicetree/bindings/spi/cdns,xspi.yaml b/Documentation/devicetree/bindings/spi/cdns,xspi.yaml > index b19c2e051e189..b9b8e0cfaa920 100644 > --- a/Documentation/devicetree/bindings/spi/cdns,xspi.yaml > +++ b/Documentation/devicetree/bindings/spi/cdns,xspi.yaml > @@ -56,7 +56,6 @@ dependencies: > required: > - compatible > - reg > - - interrupts > > allOf: > - $ref: spi-controller.yaml# [Severity: Medium] Should interrupts be dropped from required based on Linux driver polling support rather than hardware wiring? Per Documentation/devicetree/bindings/writing-bindings.rst, bindings describe the hardware rather than driver capabilities, and should still include interrupts even if a driver can poll. Relaxing required globally weakens dtbs_check for all compatibles, breaks compatibility with older kernels where cdns_xspi_probe() fails with -ENXIO without interrupts, and can silently degrade hardware with a wired IRQ line to polled mode. If some hardware integrations physically leave the XSPI IRQ line unwired, document that in the commit message and keep interrupts required under allOf for fixed SoCs such as marvell,cn10-xspi-nor where the line is always wired. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261203091112.9449-1-paul.cercueil@bootlin.com?part=4 ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-03 9:37 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-03 9:11 [PATCH v6 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil 2026-12-03 9:11 ` [PATCH v6 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil 2026-12-03 9:28 ` sashiko-bot 2026-12-03 9:11 ` [PATCH v6 2/4] spi: cadence-xspi: Add irq-less support Paul Cercueil 2026-12-03 9:36 ` sashiko-bot 2026-12-03 9:11 ` [PATCH v6 3/4] spi: cadence-xspi: Add support for panic writes Paul Cercueil 2026-12-03 9:37 ` sashiko-bot 2026-12-03 9:11 ` [PATCH v6 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional Paul Cercueil 2026-12-03 9:20 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox