From: Paul Cercueil <paul.cercueil@bootlin.com>
To: Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Kees Cook <kees@kernel.org>,
Tony Luck <tony.luck@intel.com>,
"Guilherme G. Piccoli" <gpiccoli@igalia.com>
Cc: linux-spi@vger.kernel.org, devicetree@vger.kernel.org,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Sunil Kovvuri Goutham <sgoutham@marvell.com>,
Tanmay Jagdale <tanmay@marvell.com>,
Paul Cercueil <paul.cercueil@bootlin.com>
Subject: [PATCH v5 3/4] spi: cadence-xspi: Add support for panic writes
Date: Wed, 2 Dec 2026 14:21:34 +0100 [thread overview]
Message-ID: <20261202132135.470814-4-paul.cercueil@bootlin.com> (raw)
In-Reply-To: <20261202132135.470814-1-paul.cercueil@bootlin.com>
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
next prev parent reply other threads:[~2026-12-02 13:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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:21 ` Paul Cercueil [this message]
2026-12-02 13:21 ` [PATCH v5 4/4] spi: dt-bindings: cadence: Make XSPI's IRQ line optional Paul Cercueil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202132135.470814-4-paul.cercueil@bootlin.com \
--to=paul.cercueil@bootlin.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gpiccoli@igalia.com \
--cc=kees@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sgoutham@marvell.com \
--cc=tanmay@marvell.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox