From 378721d6da770c36aeb609bee8996503836f473f Mon Sep 17 00:00:00 2001 From: Mohit Talwar Date: Sun, 6 Sep 2026 19:39:59 +0530 Subject: [PATCH] dai: zephyr: request a burst, not the whole FIFO, from the DMA dai_set_dma_config() assigns config->burst_elems straight into dma_config.source_burst_length. Zephyr documents that field as the bytes moved per DMA request, but burst_elems carries dai_get_fifo_depth() for SAI and friends, so the engine is asked to move a whole FIFO per request. The peripheral has nothing like that available when it raises the request, so the excess is discarded: the ring drains faster than real time while the FIFO starves. SOF's own drivers never use burst_elems raw. src/drivers/imx/edma.c halves it, "divide by two to fill the FIFO to half its size", and src/drivers/imx/sdma.c applies burst_elems * width / 8. Only the Zephyr path forwards it unscaled. Request a small fixed number of samples instead, matching the figure Linux uses on the same hardware (fsl_sai's FSL_SAI_MAXBURST_TX is 6 words), and keep the caller's value when it is smaller still. Measured on an i.MX8MP EVK, with a Zephyr SDMA driver that takes its watermark from the burst length (an out-of-tree series, its 64 byte safety clamp removed for the test). Without this change the engine is asked for 512 bytes per request, the SAI FIFO underruns continuously and every playback fails with an I/O error. With it the engine uses 24 bytes, and playback and a headset-mic loopback run clean with no xruns. The nxp_sdma driver at SOF's current Zephyr pin ignores the burst, so there both builds behave the same. Signed-off-by: Mohit Talwar --- src/audio/dai-zephyr.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index 2cbdfe998a2c..b215ff47f3df 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -940,6 +940,12 @@ static int dai_get_dma_slot(struct dai_data *dd, struct comp_dev *dev, uint32_t return 0; } +/* + * Samples the DMA moves per peripheral request. Matches the figure Linux uses + * for the same hardware (FSL_SAI_MAXBURST_TX/RX). + */ +#define DAI_ZEPHYR_DMA_MAXBURST_SAMPLES 6 + static int dai_set_sg_config(struct dai_data *dd, struct comp_dev *dev, uint32_t period_bytes, uint32_t period_count) { @@ -1065,10 +1071,22 @@ static int dai_set_dma_config(struct dai_data *dd, struct comp_dev *dev) dma_cfg->source_data_size = config->src_width; dma_cfg->dest_data_size = config->dest_width; - if (config->burst_elems) + /* + * Zephyr documents source_burst_length as the bytes moved per DMA + * request, not the size of the peripheral FIFO. config->burst_elems + * carries dai_get_fifo_depth() for most DAIs, so it cannot be passed + * through: asking for a whole FIFO per request makes the engine take + * more than the peripheral has when it raises that request. + * + * SOF's own drivers never use burst_elems raw either - imx/edma.c + * halves it "to fill the FIFO to half its size" and imx/sdma.c applies + * burst_elems * width / 8. Linux picks the burst first and derives the + * peripheral watermark from it: fsl_sai uses FSL_SAI_MAXBURST of 6 + * words. Follow that and request a small, fixed number of samples. + */ + dma_cfg->source_burst_length = DAI_ZEPHYR_DMA_MAXBURST_SAMPLES * config->src_width; + if (config->burst_elems && dma_cfg->source_burst_length > config->burst_elems) dma_cfg->source_burst_length = config->burst_elems; - else - dma_cfg->source_burst_length = 8; dma_cfg->dest_burst_length = dma_cfg->source_burst_length; dma_cfg->cyclic = config->cyclic;