From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.84.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796289092; b=BgGh7q2jEbnVjVql2NSt0EGEKiWoIVmshgrAapu/Kxi56LSAgFI9dbCK9cgMdC9OyD0/ FHM8cSeB7hyjGR88q2e0N5Cg9B0U949NBG4/ROBWLopty1tN2BFEd4uEoKSHW4+IbfCjX GUlENwo85IDGb75LBA0IyvvdakpYlzgkm1muUOff4LYF+abLbW+IS4gW6yPUB1eJuH93e Yj3JaPelEHpd6aKrf6lr7CTeV7YPkOocyUJtr8Z7S/qggmI1AbfY9yvZr7uDWrRD9onbg rhDfXsGxqnKQ8X4r5bol9WCLl3Cz3uGFJN7ShUJO+4cUXv+elKb7KPE3WMmno9zYSbw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289092; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=hwEwOJYSLCK4aiDMceHWgL8qBJcnaG3+xv6mGk1h60w=; b=2+QlQ75WZMUh1ORVwTuye4W7R+l/VPm6RI4bg4Br4Y6hjNizk6bhzhRvTJQHz/GyYrj6 7hXnuUOI+ak34IleuLspdMTmE/uzIa6NFvxEzyO4YHMBP4Nc0GvoCzaAfb1qf50dK920h IoNblFfthFQ1xcQ4zK9yZv6PrkNS3J1PH0Pklg60oeFP5rNJ3WmmgJhCw84jK5jkCWSDh gGfqhDYFL+Em0Se7esX9qdvZ8OxT3vung1a1Lb9XvUGPG7sAwXj31mRhx6UcWG6k0sgEl CHaD49ySwgw7K5zESRtlP+gsXit8/bBsM3AeEreDdIoKYgHu2SEc759RBZgZ7t3564w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=Ogt71Y3X; arc=none smtp.remote-ip=185.246.84.56 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67722606A322 for ; Thu, 3 Dec 2026 09:11:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67722606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=Ogt71Y3X Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 1B4641A1910; Thu, 3 Dec 2026 09:11:30 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id DEFA2604ED; Thu, 3 Dec 2026 09:11:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 3CB1F11EA179A; Thu, 03 Dec 2026 10:11:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796289088; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=hwEwOJYSLCK4aiDMceHWgL8qBJcnaG3+xv6mGk1h60w=; b=Ogt71Y3X0Au3ixi0udvwrozYVHIpLWiY6fkylJIia/bEWBswlSg7n5/yXYG+LA1AWBmjZ+ 3yFA05wUHoPP17kT4yAmFflm2oS+Y4ZdBNiWMjtpy0rylRG5NM1N90V9K4R86XJmYydhNF 2Yj2jPA7xAA5SQx+QWyjL8ZEO1VT3kbE2f+oIDDL7OfFZ4Ys3dwLTbLDNFik/8XVzTgHS2 3Ee5ScWlYVEkyHCJkXgabtloN6ylX/PekhQxkhOthDs6ljwU6xSeC/T6Nbei4MC+LUqMu1 roSbgyGidkJVNeOS/40svaAeBrA83SmIjk08gFbzjyvteODKDIs3ZlXPo5B9Yw== From: Paul Cercueil To: Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Kees Cook , Tony Luck , "Guilherme G. Piccoli" Cc: linux-spi@vger.kernel.org, devicetree@vger.kernel.org, Thomas Petazzoni , Sunil Kovvuri Goutham , Tanmay Jagdale , Paul Cercueil Subject: [PATCH v6 3/4] spi: cadence-xspi: Add support for panic writes Date: Thu, 3 Dec 2026 10:11:11 +0100 Message-ID: <20261203091112.9449-4-paul.cercueil@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203091112.9449-1-paul.cercueil@bootlin.com> References: <20261203091112.9449-1-paul.cercueil@bootlin.com> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 From: Tanmay Jagdale 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 Co-developed-by: Paul Cercueil Signed-off-by: Paul Cercueil --- 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