* [PATCH v2 0/3] mmc: sunxi: preparation for A523 UHS support
@ 2026-11-26 18:29 Jernej Skrabec
2026-11-26 18:29 ` [PATCH v2 1/3] mmc: sunxi: Set the IDMA DMA mask Jernej Skrabec
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jernej Skrabec @ 2026-11-26 18:29 UTC (permalink / raw)
To: Ulf Hansson
Cc: Chen-Yu Tsai, Samuel Holland, Andre Przywara, Anfernee Cao,
linux-mmc, linux-arm-kernel, linux-sunxi, linux-kernel,
Jernej Skrabec
This series paves the way for SD card UHS-I support on the A523, which
will follow in a later series together with the A523 clock phases,
delay-chain tuning and the PF bank supply switch.
It improves the DMA setup and error reporting, which the UHS-I work
builds upon: a DMA mask matching the shifted IDMA addresses, IDMA
descriptors built from the mapped DMA segments as the DMA API requires,
and CRC errors reported as -EILSEQ instead of -ETIMEDOUT, so the MMC
core can request retuning.
Tested on H3, H6 and H616 SoCs, on multiple boards, including Tanix TX6
and OrangePi Plus2E.
Changes in v2:
- dropped patch 1, applied to mmc fixes
- rebased on mmc next, which now contains the probe error path fix
the DMA mask patch depended on
- Link to v1: https://lore.kernel.org/r/20261103183030.81078-1-jernej.skrabec@gmail.com
Best regards,
Jernej
Jernej Skrabec (3):
mmc: sunxi: Set the IDMA DMA mask
mmc: sunxi: Build IDMA descriptors from mapped SG list
mmc: sunxi: Distinguish CRC and timeout errors
drivers/mmc/host/sunxi-mmc.c | 116 +++++++++++++++++++++++------------
1 file changed, 77 insertions(+), 39 deletions(-)
base-commit: 299ac25f5af7cbba27d80e4eaa8f9c703c96b2dc
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] mmc: sunxi: Set the IDMA DMA mask
2026-11-26 18:29 [PATCH v2 0/3] mmc: sunxi: preparation for A523 UHS support Jernej Skrabec
@ 2026-11-26 18:29 ` Jernej Skrabec
2026-11-26 18:29 ` [PATCH v2 2/3] mmc: sunxi: Build IDMA descriptors from mapped SG list Jernej Skrabec
2026-11-26 18:29 ` [PATCH v2 3/3] mmc: sunxi: Distinguish CRC and timeout errors Jernej Skrabec
2 siblings, 0 replies; 6+ messages in thread
From: Jernej Skrabec @ 2026-11-26 18:29 UTC (permalink / raw)
To: Ulf Hansson
Cc: Chen-Yu Tsai, Samuel Holland, Andre Przywara, Anfernee Cao,
linux-mmc, linux-arm-kernel, linux-sunxi, linux-kernel,
Jernej Skrabec
Controllers with a non-zero idma_des_shift (D1, A100 and H616) store
buffer and descriptor addresses shifted right by two, so they can
address 34 bits of physical memory. The driver never sets a DMA mask,
so the default 32-bit mask applies. On boards with DRAM above 4 GiB,
like H616 boards with 4 GiB of DRAM starting at 0x40000000, every
buffer above that limit is needlessly bounced through SWIOTLB.
Set the DMA mask to the range the controller can address. For the
other controllers, it stays at 32 bits.
Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
---
drivers/mmc/host/sunxi-mmc.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index c7fda9c66537..c53d47576864 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -1390,6 +1390,11 @@ static int sunxi_mmc_probe(struct platform_device *pdev)
if (ret)
return ret;
+ ret = dma_set_mask_and_coherent(&pdev->dev,
+ DMA_BIT_MASK(32 + host->cfg->idma_des_shift));
+ if (ret)
+ goto error_disable_mmc;
+
host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
&host->sg_dma, GFP_KERNEL);
if (!host->sg_cpu) {
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] mmc: sunxi: Build IDMA descriptors from mapped SG list
2026-11-26 18:29 [PATCH v2 0/3] mmc: sunxi: preparation for A523 UHS support Jernej Skrabec
2026-11-26 18:29 ` [PATCH v2 1/3] mmc: sunxi: Set the IDMA DMA mask Jernej Skrabec
@ 2026-11-26 18:29 ` Jernej Skrabec
2026-11-26 18:35 ` sashiko-bot
2026-11-26 18:29 ` [PATCH v2 3/3] mmc: sunxi: Distinguish CRC and timeout errors Jernej Skrabec
2 siblings, 1 reply; 6+ messages in thread
From: Jernej Skrabec @ 2026-11-26 18:29 UTC (permalink / raw)
To: Ulf Hansson
Cc: Chen-Yu Tsai, Samuel Holland, Andre Przywara, Anfernee Cao,
linux-mmc, linux-arm-kernel, linux-sunxi, linux-kernel,
Jernej Skrabec
dma_map_sg() may merge scatterlist entries and returns the number of
resulting DMA segments. The DMA API requires using only that many
segments, with sg_dma_address() and sg_dma_len() (see
Documentation/core-api/dma-api.rst).
The driver instead builds one descriptor per original entry and uses
its CPU side length. Build the descriptors from the mapped segments
instead, and split segments longer than one descriptor can handle.
This can't overflow the descriptor table, as each original entry fits
into a single descriptor.
Also check the alignment of the mapped segments, and unmap the
scatterlist when it is misaligned instead of leaking the mapping.
Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
---
drivers/mmc/host/sunxi-mmc.c | 91 +++++++++++++++++++++---------------
1 file changed, 54 insertions(+), 37 deletions(-)
diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index c53d47576864..b862df26e192 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -356,36 +356,49 @@ static int sunxi_mmc_init_host(struct sunxi_mmc_host *host)
}
static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
- struct mmc_data *data)
+ struct mmc_data *data, int nents)
{
struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu;
dma_addr_t next_desc = host->sg_dma;
- int i, max_len = (1 << host->cfg->idma_des_size_bits);
-
- for (i = 0; i < data->sg_len; i++) {
- pdes[i].config = cpu_to_le32(SDXC_IDMAC_DES0_CH |
- SDXC_IDMAC_DES0_OWN |
- SDXC_IDMAC_DES0_DIC);
-
- if (data->sg[i].length == max_len)
- pdes[i].buf_size = 0; /* 0 == max_len */
- else
- pdes[i].buf_size = cpu_to_le32(data->sg[i].length);
-
- next_desc += sizeof(struct sunxi_idma_des);
- pdes[i].buf_addr_ptr1 =
- cpu_to_le32(sg_dma_address(&data->sg[i]) >>
- host->cfg->idma_des_shift);
- pdes[i].buf_addr_ptr2 =
- cpu_to_le32(next_desc >>
- host->cfg->idma_des_shift);
+ unsigned int max_len = 1 << host->cfg->idma_des_size_bits;
+ unsigned int i, d = 0;
+ struct scatterlist *sg;
+
+ /* dma_map_sg() may merge entries beyond the descriptor size. */
+ for_each_sg(data->sg, sg, nents, i) {
+ dma_addr_t addr = sg_dma_address(sg);
+ unsigned int len = sg_dma_len(sg);
+
+ while (len) {
+ unsigned int chunk = min(len, max_len);
+
+ pdes[d].config = cpu_to_le32(SDXC_IDMAC_DES0_CH |
+ SDXC_IDMAC_DES0_OWN |
+ SDXC_IDMAC_DES0_DIC);
+
+ if (chunk == max_len)
+ pdes[d].buf_size = 0; /* 0 == max_len */
+ else
+ pdes[d].buf_size = cpu_to_le32(chunk);
+
+ next_desc += sizeof(struct sunxi_idma_des);
+ pdes[d].buf_addr_ptr1 =
+ cpu_to_le32(addr >> host->cfg->idma_des_shift);
+ pdes[d].buf_addr_ptr2 =
+ cpu_to_le32(next_desc >>
+ host->cfg->idma_des_shift);
+
+ addr += chunk;
+ len -= chunk;
+ d++;
+ }
}
pdes[0].config |= cpu_to_le32(SDXC_IDMAC_DES0_FD);
- pdes[i - 1].config |= cpu_to_le32(SDXC_IDMAC_DES0_LD |
+ pdes[d - 1].config |= cpu_to_le32(SDXC_IDMAC_DES0_LD |
SDXC_IDMAC_DES0_ER);
- pdes[i - 1].config &= cpu_to_le32(~SDXC_IDMAC_DES0_DIC);
- pdes[i - 1].buf_addr_ptr2 = 0;
+ pdes[d - 1].config &= cpu_to_le32(~SDXC_IDMAC_DES0_DIC);
+ pdes[d - 1].buf_addr_ptr2 = 0;
/*
* Avoid the io-store starting the idmac hitting io-mem before the
@@ -397,7 +410,7 @@ static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
static int sunxi_mmc_map_dma(struct sunxi_mmc_host *host,
struct mmc_data *data)
{
- u32 i, dma_len;
+ int i, dma_len;
struct scatterlist *sg;
dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
@@ -407,24 +420,28 @@ static int sunxi_mmc_map_dma(struct sunxi_mmc_host *host,
return -ENOMEM;
}
- for_each_sg(data->sg, sg, data->sg_len, i) {
- if (sg->offset & 3 || sg->length & 3) {
+ for_each_sg(data->sg, sg, dma_len, i) {
+ dma_addr_t addr = sg_dma_address(sg);
+
+ if (addr & 3 || sg_dma_len(sg) & 3) {
dev_err(mmc_dev(host->mmc),
- "unaligned scatterlist: os %x length %d\n",
- sg->offset, sg->length);
+ "unaligned DMA segment: address %pad length %u\n",
+ &addr, sg_dma_len(sg));
+ dma_unmap_sg(mmc_dev(host->mmc), data->sg,
+ data->sg_len, mmc_get_dma_dir(data));
return -EINVAL;
}
}
- return 0;
+ return dma_len;
}
static void sunxi_mmc_start_dma(struct sunxi_mmc_host *host,
- struct mmc_data *data)
+ struct mmc_data *data, int nents)
{
u32 rval;
- sunxi_mmc_init_idma_des(host, data);
+ sunxi_mmc_init_idma_des(host, data, nents);
rval = mmc_readl(host, REG_GCTRL);
rval |= SDXC_DMA_ENABLE_BIT;
@@ -1016,7 +1033,7 @@ static void sunxi_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
u32 imask = SDXC_INTERRUPT_ERROR_BIT;
u32 cmd_val = SDXC_START | (cmd->opcode & 0x3f);
bool wait_dma = host->wait_dma;
- int ret;
+ int nents = 0;
/* Check for set_ios errors (should never happen) */
if (host->ferror) {
@@ -1026,11 +1043,11 @@ static void sunxi_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
}
if (data) {
- ret = sunxi_mmc_map_dma(host, data);
- if (ret < 0) {
+ nents = sunxi_mmc_map_dma(host, data);
+ if (nents < 0) {
dev_err(mmc_dev(mmc), "map DMA failed\n");
- cmd->error = ret;
- data->error = ret;
+ cmd->error = nents;
+ data->error = nents;
mmc_request_done(mmc, mrq);
return;
}
@@ -1091,7 +1108,7 @@ static void sunxi_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
if (data) {
mmc_writel(host, REG_BLKSZ, data->blksz);
mmc_writel(host, REG_BCNTR, data->blksz * data->blocks);
- sunxi_mmc_start_dma(host, data);
+ sunxi_mmc_start_dma(host, data, nents);
}
host->mrq = mrq;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] mmc: sunxi: Distinguish CRC and timeout errors
2026-11-26 18:29 [PATCH v2 0/3] mmc: sunxi: preparation for A523 UHS support Jernej Skrabec
2026-11-26 18:29 ` [PATCH v2 1/3] mmc: sunxi: Set the IDMA DMA mask Jernej Skrabec
2026-11-26 18:29 ` [PATCH v2 2/3] mmc: sunxi: Build IDMA descriptors from mapped SG list Jernej Skrabec
@ 2026-11-26 18:29 ` Jernej Skrabec
2026-11-26 18:40 ` sashiko-bot
2 siblings, 1 reply; 6+ messages in thread
From: Jernej Skrabec @ 2026-11-26 18:29 UTC (permalink / raw)
To: Ulf Hansson
Cc: Chen-Yu Tsai, Samuel Holland, Andre Przywara, Anfernee Cao,
linux-mmc, linux-arm-kernel, linux-sunxi, linux-kernel,
Jernej Skrabec
The driver reports every command and data error as -ETIMEDOUT. The MMC
core however relies on -EILSEQ to recognize CRC errors, which mean
that the sampling point drifted, and flags the host for retuning when
it sees one. With every error reported as a timeout, retuning is never
triggered.
Report response and data CRC, start bit and end bit errors as -EILSEQ
and keep reporting timeouts as -ETIMEDOUT, attributed to the command or
data phase that actually failed. Report any other error as -EIO.
Currently supported SoCs don't implement tuning, so this doesn't change
much for them, but it is needed for the upcoming A523 delay-chain
tuning support.
Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
---
drivers/mmc/host/sunxi-mmc.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index b862df26e192..c2e84c22d3fa 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -537,13 +537,29 @@ static irqreturn_t sunxi_mmc_finalize_request(struct sunxi_mmc_host *host)
if (host->int_sum & SDXC_INTERRUPT_ERROR_BIT) {
sunxi_mmc_dump_errinfo(host);
- mrq->cmd->error = -ETIMEDOUT;
+
+ if (host->int_sum &
+ (SDXC_RESP_ERROR | SDXC_RESP_CRC_ERROR))
+ mrq->cmd->error = -EILSEQ;
+ else if (host->int_sum & SDXC_RESP_TIMEOUT)
+ mrq->cmd->error = -ETIMEDOUT;
if (data) {
- data->error = -ETIMEDOUT;
+ if (host->int_sum &
+ (SDXC_DATA_CRC_ERROR | SDXC_START_BIT_ERROR |
+ SDXC_END_BIT_ERROR))
+ data->error = -EILSEQ;
+ else if (host->int_sum &
+ (SDXC_DATA_TIMEOUT | SDXC_FIFO_RUN_ERROR |
+ SDXC_HARD_WARE_LOCKED))
+ data->error = -ETIMEDOUT;
+
host->manual_stop_mrq = mrq;
}
+ if (!mrq->cmd->error && (!data || !data->error))
+ mrq->cmd->error = -EIO;
+
if (mrq->stop)
mrq->stop->error = -ETIMEDOUT;
} else {
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/3] mmc: sunxi: Build IDMA descriptors from mapped SG list
2026-11-26 18:29 ` [PATCH v2 2/3] mmc: sunxi: Build IDMA descriptors from mapped SG list Jernej Skrabec
@ 2026-11-26 18:35 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-26 18:35 UTC (permalink / raw)
To: Jernej Skrabec; +Cc: linux-sunxi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mmc: sunxi: missing Fixes trailer for DMA mapping and descriptor
fixes
--
commit b07dce4aab49723d2241431ba76eb43d418b71cd
Author: Jernej Skrabec <jernej.skrabec@gmail.com>
> mmc: sunxi: Build IDMA descriptors from mapped SG list
>
> dma_map_sg() may merge scatterlist entries and returns the number of
> resulting DMA segments. The DMA API requires using only that many
> segments, with sg_dma_address() and sg_dma_len() (see
> Documentation/core-api/dma-api.rst).
>
> The driver instead builds one descriptor per original entry and uses
> its CPU side length. Build the descriptors from the mapped segments
> instead, and split segments longer than one descriptor can handle.
> This can't overflow the descriptor table, as each original entry fits
> into a single descriptor.
>
> Also check the alignment of the mapped segments, and unmap the
> scatterlist when it is misaligned instead of leaking the mapping.
>
> Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
[Severity: Low]
Both the unmapped scatterlist usage in sunxi_mmc_init_idma_des() and the
DMA mapping leak on misaligned segments in sunxi_mmc_map_dma() date back
to the initial driver commit. Should this include:
Fixes: 3cbcb16095f9 ("mmc: sunxi: Add driver for SD/MMC hosts found on Allwinner sunxi SoCs")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126182944.3136900-1-jernej.skrabec@gmail.com?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 3/3] mmc: sunxi: Distinguish CRC and timeout errors
2026-11-26 18:29 ` [PATCH v2 3/3] mmc: sunxi: Distinguish CRC and timeout errors Jernej Skrabec
@ 2026-11-26 18:40 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-26 18:40 UTC (permalink / raw)
To: Jernej Skrabec; +Cc: linux-sunxi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mmc: sunxi: non-timeout errors set -ETIMEDOUT in
sunxi_mmc_finalize_request()
--
commit 91cd8b46121add6c52d6b5bc5490c76bdc44d0e9
Author: Jernej Skrabec <jernej.skrabec@gmail.com>
mmc: sunxi: Distinguish CRC and timeout errors
This commit updates sunxi_mmc_finalize_request() to report CRC, start
bit, and end bit errors as -EILSEQ, timeouts as -ETIMEDOUT, and other
errors as -EIO.
> diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
> index b862df26e1926..c2e84c22d3fad 100644
> --- a/drivers/mmc/host/sunxi-mmc.c
> +++ b/drivers/mmc/host/sunxi-mmc.c
> @@ -537,13 +537,29 @@ static irqreturn_t sunxi_mmc_finalize_request(struct sunxi_mmc_host *host)
>
> if (host->int_sum & SDXC_INTERRUPT_ERROR_BIT) {
> sunxi_mmc_dump_errinfo(host);
> - mrq->cmd->error = -ETIMEDOUT;
> +
> + if (host->int_sum &
> + (SDXC_RESP_ERROR | SDXC_RESP_CRC_ERROR))
> + mrq->cmd->error = -EILSEQ;
> + else if (host->int_sum & SDXC_RESP_TIMEOUT)
> + mrq->cmd->error = -ETIMEDOUT;
>
> if (data) {
> - data->error = -ETIMEDOUT;
> + if (host->int_sum &
> + (SDXC_DATA_CRC_ERROR | SDXC_START_BIT_ERROR |
> + SDXC_END_BIT_ERROR))
> + data->error = -EILSEQ;
> + else if (host->int_sum &
> + (SDXC_DATA_TIMEOUT | SDXC_FIFO_RUN_ERROR |
> + SDXC_HARD_WARE_LOCKED))
> + data->error = -ETIMEDOUT;
> +
> host->manual_stop_mrq = mrq;
> }
>
> + if (!mrq->cmd->error && (!data || !data->error))
> + mrq->cmd->error = -EIO;
[Severity: Medium]
Should SDXC_FIFO_RUN_ERROR and SDXC_HARD_WARE_LOCKED be reported as -EIO
rather than setting data->error to -ETIMEDOUT?
SDXC_INTERRUPT_ERROR_BIT contains only the nine bits already tested by the
cmd and data branches above:
drivers/mmc/host/sunxi-mmc.c:
#define SDXC_INTERRUPT_ERROR_BIT \
(SDXC_RESP_ERROR | SDXC_RESP_CRC_ERROR | SDXC_DATA_CRC_ERROR | \
SDXC_RESP_TIMEOUT | SDXC_DATA_TIMEOUT | SDXC_FIFO_RUN_ERROR | \
SDXC_HARD_WARE_LOCKED | SDXC_START_BIT_ERROR | SDXC_END_BIT_ERROR)
When data is non-NULL, grouping SDXC_FIFO_RUN_ERROR and
SDXC_HARD_WARE_LOCKED with SDXC_DATA_TIMEOUT means a FIFO underrun/overrun
or hardware lock error during a data transfer sets data->error = -ETIMEDOUT
instead of -EIO, and the !data->error fallback check below can never trigger.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126182944.3136900-1-jernej.skrabec@gmail.com?part=3
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-26 18:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 18:29 [PATCH v2 0/3] mmc: sunxi: preparation for A523 UHS support Jernej Skrabec
2026-11-26 18:29 ` [PATCH v2 1/3] mmc: sunxi: Set the IDMA DMA mask Jernej Skrabec
2026-11-26 18:29 ` [PATCH v2 2/3] mmc: sunxi: Build IDMA descriptors from mapped SG list Jernej Skrabec
2026-11-26 18:35 ` sashiko-bot
2026-11-26 18:29 ` [PATCH v2 3/3] mmc: sunxi: Distinguish CRC and timeout errors Jernej Skrabec
2026-11-26 18:40 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox