Replace CR_TCIE and CR_TEIE irq usage by a read_poll_timeout_atomic() in
stm32_ospi_wait_cmd(). It will reduce the time waiting for TCF or TEF flags
to optimize throughput.
before after
average time spent in stm32_omi_wait_cmd: 5685 ns 923 ns
Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
---
drivers/spi/spi-stm32-ospi.c | 31 ++++++-------------------------
1 file changed, 6 insertions(+), 25 deletions(-)
diff --git a/drivers/spi/spi-stm32-ospi.c b/drivers/spi/spi-stm32-ospi.c
index a6f53f06200e..d8d72e2fb4bd 100644
--- a/drivers/spi/spi-stm32-ospi.c
+++ b/drivers/spi/spi-stm32-ospi.c
@@ -34,8 +34,6 @@
#define CR_ABORT BIT(1)
#define CR_DMAEN BIT(2)
#define CR_FTHRES_SHIFT 8
-#define CR_TEIE BIT(16)
-#define CR_TCIE BIT(17)
#define CR_SMIE BIT(19)
#define CR_APMS BIT(22)
#define CR_CSSEL BIT(24)
@@ -106,7 +104,7 @@
#define STM32_ABT_TIMEOUT_US 100000
#define STM32_COMP_TIMEOUT_MS 5000
#define STM32_BUSY_TIMEOUT_US 100000
-
+#define STM32_WAIT_CMD_TIMEOUT_US 5000
#define STM32_AUTOSUSPEND_DELAY -1
@@ -116,7 +114,6 @@ struct stm32_ospi {
struct clk *clk;
struct reset_control *rstc;
- struct completion data_completion;
struct completion match_completion;
struct dma_chan *dma_chtx;
@@ -240,22 +237,16 @@ static int stm32_ospi_wait_nobusy(struct stm32_ospi *ospi)
static int stm32_ospi_wait_cmd(struct stm32_ospi *ospi)
{
void __iomem *regs_base = ospi->regs_base;
- u32 cr, sr;
+ u32 sr;
int err = 0;
- if ((readl_relaxed(regs_base + OSPI_SR) & SR_TCF) ||
- ospi->fmode == CR_FMODE_APM)
+ if (ospi->fmode == CR_FMODE_APM)
goto out;
- reinit_completion(&ospi->data_completion);
- cr = readl_relaxed(regs_base + OSPI_CR);
- writel_relaxed(cr | CR_TCIE | CR_TEIE, regs_base + OSPI_CR);
-
- if (!wait_for_completion_timeout(&ospi->data_completion,
- msecs_to_jiffies(STM32_COMP_TIMEOUT_MS)))
- err = -ETIMEDOUT;
+ err = readl_relaxed_poll_timeout_atomic(ospi->io_base + OSPI_SR, sr,
+ (sr & (SR_TEF | SR_TCF)), 1,
+ STM32_WAIT_CMD_TIMEOUT_US);
- sr = readl_relaxed(regs_base + OSPI_SR);
if (sr & SR_TCF)
/* avoid false timeout */
err = 0;
@@ -293,15 +284,6 @@ static irqreturn_t stm32_ospi_irq(int irq, void *dev_id)
cr &= ~CR_SMIE;
writel_relaxed(cr, regs_base + OSPI_CR);
complete(&ospi->match_completion);
-
- return IRQ_HANDLED;
- }
-
- if (sr & (SR_TEF | SR_TCF)) {
- /* disable irq */
- cr &= ~CR_TCIE & ~CR_TEIE;
- writel_relaxed(cr, regs_base + OSPI_CR);
- complete(&ospi->data_completion);
}
return IRQ_HANDLED;
@@ -884,7 +866,6 @@ static int stm32_ospi_get_resources(struct platform_device *pdev)
dev_info(dev, "No memory-map region found\n");
}
- init_completion(&ospi->data_completion);
init_completion(&ospi->match_completion);
return 0;
--
2.43.0
Hi Patrice,
kernel test robot noticed the following build errors:
[auto build test ERROR on 7d0a66e4bb9081d75c82ec4957c50034cb0ea449]
url: https://github.com/intel-lab-lkp/linux/commits/Patrice-Chotard/spi-stm32-ospi-Set-DMA-maxburst-dynamically/20251205-174931
base: 7d0a66e4bb9081d75c82ec4957c50034cb0ea449
patch link: https://lore.kernel.org/r/20251205-upstream_qspi_ospi_updates-v1-3-7e6c8b9f5141%40foss.st.com
patch subject: [PATCH 3/8] spi: stm32-ospi: Remove CR_TCIE and CR_TEIE irq usage
config: riscv-randconfig-002-20251206 (https://download.01.org/0day-ci/archive/20251206/202512061458.1wp2IbOG-lkp@intel.com/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251206/202512061458.1wp2IbOG-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512061458.1wp2IbOG-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/spi/spi-stm32-ospi.c:246:48: error: no member named 'io_base' in 'struct stm32_ospi'; did you mean 'mm_base'?
246 | err = readl_relaxed_poll_timeout_atomic(ospi->io_base + OSPI_SR, sr,
| ^~~~~~~
| mm_base
include/linux/iopoll.h:255:43: note: expanded from macro 'readl_relaxed_poll_timeout_atomic'
255 | readx_poll_timeout_atomic(readl_relaxed, addr, val, cond, delay_us, timeout_us)
| ^
include/linux/iopoll.h:213:71: note: expanded from macro 'readx_poll_timeout_atomic'
213 | read_poll_timeout_atomic(op, val, cond, delay_us, timeout_us, false, addr)
| ^
include/linux/iopoll.h:172:36: note: expanded from macro 'read_poll_timeout_atomic'
172 | poll_timeout_us_atomic((val) = op(args), cond, sleep_us, timeout_us, sleep_before_read)
| ^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
arch/riscv/include/asm/mmio.h:90:76: note: expanded from macro 'readl_cpu'
90 | #define readl_cpu(c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; })
| ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
| ^
include/linux/iopoll.h:102:3: note: expanded from macro 'poll_timeout_us_atomic'
102 | op; \
| ^
drivers/spi/spi-stm32-ospi.c:124:16: note: 'mm_base' declared here
124 | void __iomem *mm_base;
| ^
1 error generated.
vim +246 drivers/spi/spi-stm32-ospi.c
236
237 static int stm32_ospi_wait_cmd(struct stm32_ospi *ospi)
238 {
239 void __iomem *regs_base = ospi->regs_base;
240 u32 sr;
241 int err = 0;
242
243 if (ospi->fmode == CR_FMODE_APM)
244 goto out;
245
> 246 err = readl_relaxed_poll_timeout_atomic(ospi->io_base + OSPI_SR, sr,
247 (sr & (SR_TEF | SR_TCF)), 1,
248 STM32_WAIT_CMD_TIMEOUT_US);
249
250 if (sr & SR_TCF)
251 /* avoid false timeout */
252 err = 0;
253 if (sr & SR_TEF)
254 err = -EIO;
255
256 out:
257 /* clear flags */
258 writel_relaxed(FCR_CTCF | FCR_CTEF, regs_base + OSPI_FCR);
259
260 if (!err)
261 err = stm32_ospi_wait_nobusy(ospi);
262
263 return err;
264 }
265
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Patrice,
kernel test robot noticed the following build errors:
[auto build test ERROR on 7d0a66e4bb9081d75c82ec4957c50034cb0ea449]
url: https://github.com/intel-lab-lkp/linux/commits/Patrice-Chotard/spi-stm32-ospi-Set-DMA-maxburst-dynamically/20251205-174931
base: 7d0a66e4bb9081d75c82ec4957c50034cb0ea449
patch link: https://lore.kernel.org/r/20251205-upstream_qspi_ospi_updates-v1-3-7e6c8b9f5141%40foss.st.com
patch subject: [PATCH 3/8] spi: stm32-ospi: Remove CR_TCIE and CR_TEIE irq usage
config: sparc64-randconfig-002-20251206 (https://download.01.org/0day-ci/archive/20251206/202512061327.9CDC4SNs-lkp@intel.com/config)
compiler: sparc64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251206/202512061327.9CDC4SNs-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512061327.9CDC4SNs-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from drivers/spi/spi-stm32-ospi.c:16:
drivers/spi/spi-stm32-ospi.c: In function 'stm32_ospi_wait_cmd':
>> drivers/spi/spi-stm32-ospi.c:246:48: error: 'struct stm32_ospi' has no member named 'io_base'; did you mean 'mm_base'?
err = readl_relaxed_poll_timeout_atomic(ospi->io_base + OSPI_SR, sr,
^~~~~~~
include/linux/iopoll.h:102:3: note: in definition of macro 'poll_timeout_us_atomic'
op; \
^~
include/linux/iopoll.h:213:2: note: in expansion of macro 'read_poll_timeout_atomic'
read_poll_timeout_atomic(op, val, cond, delay_us, timeout_us, false, addr)
^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/iopoll.h:255:2: note: in expansion of macro 'readx_poll_timeout_atomic'
readx_poll_timeout_atomic(readl_relaxed, addr, val, cond, delay_us, timeout_us)
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/spi/spi-stm32-ospi.c:246:8: note: in expansion of macro 'readl_relaxed_poll_timeout_atomic'
err = readl_relaxed_poll_timeout_atomic(ospi->io_base + OSPI_SR, sr,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +246 drivers/spi/spi-stm32-ospi.c
236
237 static int stm32_ospi_wait_cmd(struct stm32_ospi *ospi)
238 {
239 void __iomem *regs_base = ospi->regs_base;
240 u32 sr;
241 int err = 0;
242
243 if (ospi->fmode == CR_FMODE_APM)
244 goto out;
245
> 246 err = readl_relaxed_poll_timeout_atomic(ospi->io_base + OSPI_SR, sr,
247 (sr & (SR_TEF | SR_TCF)), 1,
248 STM32_WAIT_CMD_TIMEOUT_US);
249
250 if (sr & SR_TCF)
251 /* avoid false timeout */
252 err = 0;
253 if (sr & SR_TEF)
254 err = -EIO;
255
256 out:
257 /* clear flags */
258 writel_relaxed(FCR_CTCF | FCR_CTEF, regs_base + OSPI_FCR);
259
260 if (!err)
261 err = stm32_ospi_wait_nobusy(ospi);
262
263 return err;
264 }
265
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.