[PATCH v2 0/2] mmc: meson-mx-sdhc: fix DMA error handling and add bounce buffer

From: ZHENPENG YUAN

Date: Tue Dec 01 2026 - 07:31:43 EST


Hi Ulf, Martin, and all,

First, please accept my apologies for the long delay in following up on
this thread -- some personal matters kept me from getting back to this
sooner.

This v2 series follows up on the RFC discussion [1] and addresses all
the issues raised there, including Ulf's request to see an updated patch
[2] and the critical bug flagged during RFC review [3]:

1. Fix DMA completion, error reporting, and retry handling (Patch 1/2)

During RFC review, Sashiko flagged [3] that
meson_mx_sdhc_irq_thread() only checked !data->error without checking
!cmd->error before accounting bytes_xfered (and, in the RFC, copying
from the bounce buffer). That same bug exists in the upstream driver
since its introduction: a command error can report a full transfer
length, and a data error can skip dma_unmap_sg().

Patch 1/2 separates this into a standalone fix ahead of the bounce
buffer change so it can be applied and backported independently. It
clears bytes_xfered on each attempt, checks controller readiness
before programming a command and propagates poll failures, unmaps DMA
for every data request, accounts bytes_xfered only when both cmd and
data succeed, and keeps DMA mapping errors local to the request.

2. Add 128 KiB multi-segment DMA bounce buffer (Patch 2/2)

In response to Martin's question in [1], the comparison reported in
[4] confirmed that MMC_CAP2_MERGE_CAPABLE alone does not help on
Meson8b (Xunlei OneCloud): dma_get_merge_boundary() returns 0,
host->can_dma_map_merge remains 0, and max_segments stays at 1
(13.05 MiB/s vs 13.11 MiB/s baseline, compared to 69.43 MiB/s with
the 128 KiB bounce buffer for 1 MiB sequential reads).

Patch 2/2 updates the bounce buffer implementation since the RFC:
- Selects direct DMA vs bounce buffering based on data->sg_len == 1.
- Allocates the 128 KiB bounce buffer via devm_get_free_pages() and
falls back to single-segment requests if allocation fails.
- Keeps the tested 128 KiB transfer size and bounds
mmc->max_blk_count so block-mode SDIO requests fit as well.

Disclosure and testing status:
- Codex assisted with refactoring the v2 patches and changelogs.
- The OneCloud throughput numbers were measured on the earlier RFC
bounce-buffer prototype. This rebased v2 series against mmc/next
(7aa13b7bc3a4) has not yet been compiled or tested on hardware.

[1] https://lore.kernel.org/linux-mmc/CAFBinCBo0C=KABcg5ueDTRSJhF9vmWnPwYHbaMGTOYppOsabwA@xxxxxxxxxxxxxx/T/#t
[2] https://lore.kernel.org/r/CAPx+jO_oAnJFY9hodP6gxPCD2ch0=+0MNXkKoJXz=3OzeAq+iQ@xxxxxxxxxxxxxx
[3] https://lore.kernel.org/r/sashiko-outbox-192112@xxxxxxxxxx
[4] https://lore.kernel.org/r/CAEDN0nBEK5PvkV-eC11XHYG04Occgs6o9_9K67OZn+xtkh68yQ@xxxxxxxxxxxxxx

ZHENPENG YUAN (2):
mmc: meson-mx-sdhc: complete failed DMA requests with zero bytes
mmc: meson-mx-sdhc: bounce multi-segment DMA requests

drivers/mmc/host/meson-mx-sdhc-mmc.c | 155 ++++++++++++++++++---------
1 file changed, 107 insertions(+), 48 deletions(-)


base-commit: 7aa13b7bc3a4d1efc0cbe3d24233db2c033cbf01
--
2.54.0.windows.1