Skip to content

[RFC] dai: zephyr: request a burst, not the whole FIFO, from the DMA - #11521

Open
mohittalwar23 wants to merge 1 commit into
thesofproject:mainfrom
mohittalwar23:rfc/dai-zephyr-burst
Open

mohittalwar23 wants to merge 1 commit into
thesofproject:mainfrom
mohittalwar23:rfc/dai-zephyr-burst

Conversation

@mohittalwar23

Copy link
Copy Markdown

RFC, from the Zephyr i.MX8MP SAI/SDMA discussion (zephyrproject-rtos/zephyr#117960),
where we were asked to raise the SOF side separately.

dai_set_dma_config() copies config->burst_elems straight into
dma_config.source_burst_length. Zephyr documents that field as the bytes moved per DMA
request. For SAI, ESAI and MICFIL, though, burst_elems is dai_get_fifo_depth(): the
whole FIFO in bytes (512 B 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
that request. SOF's own native drivers never forward it raw: imx/edma.c halves it and
imx/sdma.c scales it.

This patch requests 6 samples per request, the figure Linux's fsl_sai uses
(FSL_SAI_MAXBURST_TX/RX). It keeps the caller's value when that is smaller.

What it changes today. Code reading only, apart from the i.MX8MP rows:

DAI / DMA Before → after Effect
Intel SSP, ALH 2 / 4 → unchanged none
Intel HDA 8 → 6 × width none: the HDA DMA driver ignores burst
Intel DMIC 1 << BFTH → capped at 6 × width only for blobs with BFTH ≥ 5, and only where GPDMA serves DMIC
NXP SAI/ESAI over eDMA (i.MX8QM/QXP/8ULP/93/95) FIFO bytes → 6 × width NBYTES drops; dma_nxp_edma then needs block size % (6 × width) == 0
NXP SAI over SDMA (i.MX8MP) 512 → 24 (S32) none yet: Zephyr's dma_nxp_sdma doesn't read the burst today

The questions for reviewers:

  1. Is "bytes per request" the contract SOF should follow for source_burst_length?
  2. Should this apply to every DAI, or only where the DMA driver derives a watermark from
    the burst?
  3. Is the eDMA NBYTES change acceptable, or should eDMA keep its current value?

Testing (i.MX8MP EVK, NXP BSP Linux 6.6.52, imx8mp-evk-sof-wm8960). Each run played
a 12 s scale on repeat for 2 minutes, then looped the headset mic to the headphones for 2
minutes, while listening.

  • SOF main against its Zephyr pin, with and without this patch: they sound the same.
    Both were clean, with 0 xruns and no DSP warnings. A functional battery (S16/S24/S32,
    periods 24/48/192/1024, capture, 8 s loopback) was also identical. That's expected,
    since today's Zephyr SDMA driver ignores the burst.

  • Zephyr with the SDMA series from Draft upstream discussion: i.MX8MP MCUX SAI cannot use Zephyr SDMA reliably zephyrproject-rtos/zephyr#117960, which derives the SAI watermark from the
    burst. For this test only, the series' 64 B clamp was removed, so the DMA uses exactly
    what SOF asks for:

    • without this patch: the SAI FIFO underruns continuously (about 2,500 warnings in
      15 s), every aplay fails with Input/output error, and the headphones only click;
    • with it: the DMA uses a 24 B watermark, and the scale and the mic loop are both
      clean, with 0 xruns.

    The series itself keeps the 64 B clamp until SOF settles this, so it doesn't depend on
    this patch.

  • Not tested on Intel or on NXP eDMA platforms; I have no hardware for them.

Cc: @dbaluta @iuliana-prodan @LaurentiuM1234

@sofci

sofci commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

@mohittalwar23 mohittalwar23 changed the title dai: zephyr: request a burst, not the whole FIFO, from the DMA [RFC] dai: zephyr: request a burst, not the whole FIFO, from the DMA Nov 22, 2026

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @dbaluta @thesofproject/nxp needs your approvals.

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 <talwarmohit2005@gmail.com>
@mohittalwar23

Copy link
Copy Markdown
Author

Updated: the code comments are one line each now, and the details are in the commit message. The code itself is unchanged.

Testing, on the i.MX8MP EVK: 2 minutes of scale playback and 2 minutes of headset mic loopback, listening, with xruns counted and the DSP log checked. Both on SOF's Zephyr pin (same as without the patch) and on Zephyr with the SDMA series, where the DMA actually uses the burst (24 bytes per request): clean, 0 xruns.

Without the patch, with the SDMA driver's 64-byte cap removed for the test, the SDMA moves 512 bytes per request: playback was only clicks, every aplay stopped with Input/output error, and the DSP logged about 2,500 SAI FIFO underruns in 15 s.

@mohittalwar23
mohittalwar23 marked this pull request as ready for review November 26, 2026 13:36
@dbaluta

dbaluta commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

@lgirdwood LGTM. Thanks @mohittalwar23 !

@mohittalwar23

Copy link
Copy Markdown
Author

Thanks @dbaluta! I could only test on i.MX8MP (SDMA). On the eDMA platforms (i.MX8QM/QXP/93/95) this changes NBYTES to 6 samples, so if someone has one of those boards at hand, a quick playback check would be good.

Same for Intel Platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants