From a622e1a615a2f322b916591b69a4f3e016ab5a17 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 for SAI, ESAI and MICFIL burst_elems is dai_get_fifo_depth(), the whole FIFO in bytes (512 for i.MX8MP SAI3). A DMA driver that honours the field is asked to move a whole FIFO per request, more than the peripheral has ready when it raises the request: the excess is discarded, the ring drains faster than real time and the FIFO starves. SOF's own drivers never use burst_elems raw: src/drivers/imx/edma.c halves it and src/drivers/imx/sdma.c applies burst_elems * width / 8. Only the Zephyr path forwards it unscaled. Request 6 samples per request instead, the figure Linux's fsl_sai uses on the same hardware (FSL_SAI_MAXBURST_TX/RX), and keep the caller's value when it is smaller. Effect on other DAIs, from reading the code: Intel SSP and ALH already ask for less and are unchanged; the Intel HDA DMA driver ignores the burst; Intel DMIC is capped only for blobs with BFTH >= 5. NXP SAI and ESAI over eDMA move 6 samples per minor loop instead of a whole FIFO, so dma_nxp_edma then needs block sizes that are a multiple of that. Not tested on Intel or eDMA hardware. Tested on an i.MX8MP EVK (NXP BSP Linux 6.6.52, imx8mp-evk-sof-wm8960 DTB), with and without this patch: a scale played on repeat for 2 minutes, then the headset mic looped to the headphones for 2 minutes, listening and counting xruns. - SOF main against its Zephyr pin: both sound the same, with no xruns, as nxp_sdma at that pin ignores the burst. - Against a Zephyr SDMA series that derives the SAI watermark from the burst (zephyrproject-rtos/zephyr#117960, its 64 byte clamp removed for the test): without this patch 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 both runs are clean, with no xruns. Signed-off-by: Mohit Talwar --- src/audio/dai-zephyr.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index 2cbdfe998a2c..99b11d3029e2 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -940,6 +940,9 @@ static int dai_get_dma_slot(struct dai_data *dd, struct comp_dev *dev, uint32_t return 0; } +/* Samples moved per DMA request, as in Linux fsl_sai (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 +1068,10 @@ 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) + /* burst_elems is the DAI FIFO depth, too much to move per DMA request */ + 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;