* [PATCH v5 0/4] spi: cadence-xspi: Add support for panic mem writes
@ 2026-12-02 13:21 Paul Cercueil
2026-12-02 13:21 ` [PATCH v5 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Paul Cercueil @ 2026-12-02 13:21 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 v5 of my patchset that updates the cadence-xspi driver to
add support for panic mem writes to a memory partition configured as
pstore.
I decided to split the spi-nor parts which have to go through a different
tree, and they depend on the v4's [1/7] (see [1]) to land on 7.5-rc1.
This version 5 attempts to address a few concerns that Sashiko had. I
expect it to still complain about a few things, some of which I will
debunk.
Changes in v5:
- [1/4]:
New patch, to address cdns_xspi_is_sdma_ready() not
handling DMA errors.
- [2/4]:
- Use forward declarations for cdns_xspi_is_{sdma,stig}_ready()
instead of moving them.
- Increase MRVL_XSPI_POLL_TIMEOUT_US timeout value
- [3/4]:
Update the new cdns_xspi_sdma_handle() introduced by a third-party
since the v4, so that it will work with panic writes.
Cheers,
-Paul
[1]: https://lore.kernel.org/linux-spi/20261016102917.171095-2-paul.cercueil@bootlin.com/T/
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 | 133 +++++++++++-------
2 files changed, 80 insertions(+), 54 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v5 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() 2026-12-02 13:21 [PATCH v5 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil @ 2026-12-02 13:21 ` Paul Cercueil 2026-12-02 13:27 ` sashiko-bot 2026-12-02 13:21 ` [PATCH v5 2/4] spi: cadence-xspi: Add irq-less support Paul Cercueil ` (2 subsequent siblings) 3 siblings, 1 reply; 8+ messages in thread From: Paul Cercueil @ 2026-12-02 13:21 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: v5: New patch --- drivers/spi/spi-cadence-xspi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c index a42fab719b7a..f5106df93355 100644 --- a/drivers/spi/spi-cadence-xspi.c +++ b/drivers/spi/spi-cadence-xspi.c @@ -1236,12 +1236,17 @@ 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; } + if (ctrl_stat & CDNS_XSPI_SDMA_ERROR) { + dev_err(cdns_xspi->dev, "Slave DMA transaction error\n"); + return false; + } + /* Clear the flag */ writel(CDNS_XSPI_SDMA_TRIGGER, cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); -- 2.47.3 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v5 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() 2026-12-02 13:21 ` [PATCH v5 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil @ 2026-12-02 13:27 ` sashiko-bot 0 siblings, 0 replies; 8+ messages in thread From: sashiko-bot @ 2026-12-02 13:27 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] spi: cadence-xspi: uncleared SDMA error bit in cdns_xspi_is_sdma_ready() -- commit 122949242af56dfda1b41fa7001f1b06306596ab Author: Tanmay Jagdale <tanmay@marvell.com> spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() This commit updates cdns_xspi_is_sdma_ready() to poll for CDNS_XSPI_SDMA_ERROR alongside CDNS_XSPI_SDMA_TRIGGER and return false if an SDMA error bit is set. > diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c > index a42fab719b7af..f5106df933552 100644 > --- a/drivers/spi/spi-cadence-xspi.c > +++ b/drivers/spi/spi-cadence-xspi.c > @@ -1236,12 +1236,17 @@ 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; > } > > + if (ctrl_stat & CDNS_XSPI_SDMA_ERROR) { > + dev_err(cdns_xspi->dev, "Slave DMA transaction error\n"); > + return false; > + } > + > /* Clear the flag */ > writel(CDNS_XSPI_SDMA_TRIGGER, > cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); [Severity: Medium] Should the error path clear CDNS_XSPI_SDMA_ERROR (and CDNS_XSPI_SDMA_TRIGGER if also set) in CDNS_XSPI_INTR_STATUS_REG before returning false? CDNS_XSPI_INTR_STATUS_REG is write-1-to-clear, and polled callers such as cdns_xspi_transfer_one_message_b0() run with interrupts disabled and do not clear the status register on error unwind. Leaving CDNS_XSPI_SDMA_ERROR latched will cause subsequent calls to cdns_xspi_is_sdma_ready() to immediately see the stale error bit and fail. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261202132135.470814-1-paul.cercueil@bootlin.com?part=1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v5 2/4] spi: cadence-xspi: Add irq-less support 2026-12-02 13:21 [PATCH v5 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil 2026-12-02 13:21 ` [PATCH v5 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil @ 2026-12-02 13:21 ` Paul Cercueil 2026-12-02 13:33 ` sashiko-bot 2026-12-02 13:21 ` [PATCH v5 3/4] spi: cadence-xspi: Add support for panic writes Paul Cercueil 2026-12-02 13:21 ` [PATCH v5 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional Paul Cercueil 3 siblings, 1 reply; 8+ messages in thread From: Paul Cercueil @ 2026-12-02 13:21 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: 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 f5106df93355..4a5376e495c6 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] 8+ messages in thread
* Re: [PATCH v5 2/4] spi: cadence-xspi: Add irq-less support 2026-12-02 13:21 ` [PATCH v5 2/4] spi: cadence-xspi: Add irq-less support Paul Cercueil @ 2026-12-02 13:33 ` sashiko-bot 0 siblings, 0 replies; 8+ messages in thread From: sashiko-bot @ 2026-12-02 13:33 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] spi: cadence-xspi: uncleared SDMA error bit in cdns_xspi_is_sdma_ready() -- commit b91e40d7ac9f80d3f34f93797643594a93cbc82d Author: Tanmay Jagdale <tanmay@marvell.com> spi: cadence-xspi: Add irq-less support This commit makes the interrupt line optional in spi-cadence-xspi and falls back to polling cdns_xspi_is_sdma_ready() and cdns_xspi_is_stig_ready() when no IRQ is provided. > diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c > index f5106df933552..4a5376e495c6a 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; > > 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; > } [Severity: Medium] Does cdns_xspi_is_sdma_ready() leave CDNS_XSPI_SDMA_ERROR latched in CDNS_XSPI_INTR_STATUS_REG when a Slave DMA error occurs? drivers/spi/spi-cadence-xspi.c:cdns_xspi_is_sdma_ready() { ... if (ctrl_stat & CDNS_XSPI_SDMA_ERROR) { dev_err(cdns_xspi->dev, "Slave DMA transaction error\n"); return false; } /* Clear the flag */ writel(CDNS_XSPI_SDMA_TRIGGER, cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); ... } CDNS_XSPI_INTR_STATUS_REG is write-1-to-clear. In IRQ mode, cdns_xspi_irq_handler() writes irq_status back to CDNS_XSPI_INTR_STATUS_REG, clearing CDNS_XSPI_SDMA_ERROR. In IRQ-less mode, nothing clears CDNS_XSPI_INTR_STATUS_REG between commands, so once CDNS_XSPI_SDMA_ERROR is set, every subsequent cdns_xspi_is_sdma_ready() call will immediately see the stale error bit and fail with -EIO. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261202132135.470814-1-paul.cercueil@bootlin.com?part=2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v5 3/4] spi: cadence-xspi: Add support for panic writes 2026-12-02 13:21 [PATCH v5 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil 2026-12-02 13:21 ` [PATCH v5 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil 2026-12-02 13:21 ` [PATCH v5 2/4] spi: cadence-xspi: Add irq-less support Paul Cercueil @ 2026-12-02 13:21 ` Paul Cercueil 2026-12-02 13:31 ` sashiko-bot 2026-12-02 13:21 ` [PATCH v5 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional Paul Cercueil 3 siblings, 1 reply; 8+ messages in thread From: Paul Cercueil @ 2026-12-02 13:21 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: 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 | 89 ++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c index 4a5376e495c6..55886eb5f34a 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; @@ -651,16 +653,18 @@ static int cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) sdma_trd_info = readl(cdns_xspi->iobase + CDNS_XSPI_SDMA_TRD_INFO_REG); sdma_dir = FIELD_GET(CDNS_XSPI_SDMA_DIR, sdma_trd_info); - if (sdma_size > cdns_xspi->sdma_xfer_len) { - dev_err(cdns_xspi->dev, - "SDMA size %u exceeds the requested length %u\n", - sdma_size, cdns_xspi->sdma_xfer_len); - return -EINVAL; + if (use_dma) { + if (sdma_size > cdns_xspi->sdma_xfer_len) { + dev_err(cdns_xspi->dev, + "SDMA size %u exceeds the requested length %u\n", + 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; } - 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 +688,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 +724,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 +741,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 +1123,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 +1239,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 +1282,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 +1337,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 +1417,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 +1554,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] 8+ messages in thread
* Re: [PATCH v5 3/4] spi: cadence-xspi: Add support for panic writes 2026-12-02 13:21 ` [PATCH v5 3/4] spi: cadence-xspi: Add support for panic writes Paul Cercueil @ 2026-12-02 13:31 ` sashiko-bot 0 siblings, 0 replies; 8+ messages in thread From: sashiko-bot @ 2026-12-02 13:31 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] spi: cadence-xspi: sdma_size bounds check bypassed in cdns_xspi_sdma_handle() -- commit 111b594c701d92659414802088644363c5b37dd0 Author: Tanmay Jagdale <tanmay@marvell.com> spi: cadence-xspi: Add support for panic writes This commit advertises panic write support for the Cadence XSPI controller and updates the STIG and SDMA paths to avoid sleeping, interrupts, and DMA when op->panic_write is set. > diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c > index 4a5376e495c6a..55886eb5f34ac 100644 > --- a/drivers/spi/spi-cadence-xspi.c > +++ b/drivers/spi/spi-cadence-xspi.c [ ... ] > @@ -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; > @@ -651,16 +653,18 @@ static int cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) > sdma_trd_info = readl(cdns_xspi->iobase + CDNS_XSPI_SDMA_TRD_INFO_REG); > sdma_dir = FIELD_GET(CDNS_XSPI_SDMA_DIR, sdma_trd_info); > > - if (sdma_size > cdns_xspi->sdma_xfer_len) { > - dev_err(cdns_xspi->dev, > - "SDMA size %u exceeds the requested length %u\n", > - sdma_size, cdns_xspi->sdma_xfer_len); > - return -EINVAL; > + if (use_dma) { > + if (sdma_size > cdns_xspi->sdma_xfer_len) { > + dev_err(cdns_xspi->dev, > + "SDMA size %u exceeds the requested length %u\n", > + 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; > } > - 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: [Severity: Medium] Should the sdma_size > cdns_xspi->sdma_xfer_len check remain outside the if (use_dma) block? When use_dma is false during a panic write, skipping this check passes an unvalidated sdma_size from CDNS_XSPI_SDMA_SIZE_REG to cdns_xspi_sdma_read() or cdns_xspi_sdma_write(), which can read or write past the end of cdns_xspi->in_buffer or cdns_xspi->out_buffer. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261202132135.470814-1-paul.cercueil@bootlin.com?part=3 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v5 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional 2026-12-02 13:21 [PATCH v5 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil ` (2 preceding siblings ...) 2026-12-02 13:21 ` [PATCH v5 3/4] spi: cadence-xspi: Add support for panic writes Paul Cercueil @ 2026-12-02 13:21 ` Paul Cercueil 3 siblings, 0 replies; 8+ messages in thread From: Paul Cercueil @ 2026-12-02 13:21 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-v5: 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] 8+ messages in thread
end of thread, other threads:[~2026-12-02 13:33 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 13:21 [PATCH v5 0/4] spi: cadence-xspi: Add support for panic mem writes Paul Cercueil 2026-12-02 13:21 ` [PATCH v5 1/4] spi: cadence-xspi: Handle SDMA errors in cdns_xspi_is_sdma_ready() Paul Cercueil 2026-12-02 13:27 ` sashiko-bot 2026-12-02 13:21 ` [PATCH v5 2/4] spi: cadence-xspi: Add irq-less support Paul Cercueil 2026-12-02 13:33 ` sashiko-bot 2026-12-02 13:21 ` [PATCH v5 3/4] spi: cadence-xspi: Add support for panic writes Paul Cercueil 2026-12-02 13:31 ` sashiko-bot 2026-12-02 13:21 ` [PATCH v5 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional Paul Cercueil
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox