Skip to content

Commit faeb1e7

Browse files
CTCaeramazingfate
authored andcommitted
mmc: sdhci: fix max req size based on spec
For almost 2 decades, the max allowed requests were limited to 512KB because of SDMA's max 512KiB boundary limit. ADMA2 and ADMA3 do not have such limits and were effectively made so any kind of block count would not impose interrupt and managing stress to the host. By limiting that to 512KiB, it effectively downgrades these DMA modes to SDMA. Fix that by actually following the spec: When ADMA is selected tuning mode is advised. On lesser modes 4MiB transfers is selected as max, so re-tuning if timer trigger or if requested by host interrupt, can be done in time. Otherwise, the only limit is the variable size of types used. In this implementation, 16MiB is used as maximum since tests showed that after that point, there are diminishing returns. Also 16MiB in worst case scenarios, when card is eMMC and its max speed is a generous 350MiB/s, will generate interrupts every 45ms on huge data transfers. For example, on local tests with rigorous CPU/GPU burn-in tests and abrupt cut-offs to generate huge temperature changes (upwards/downwards) to the card, tested host was fine up to 128MB/s transfers on slow cards that used SDR104 bus timing without re-tuning. In that case the 4MiB limit was overridden with a more than safe 8MiB value. In all testing cases and boards, that change brought the following: Depending on bus timing and eMMC/SD specs: * Max Read throughput increased by 2-20% * Max Write throughput increased by 50-200% Depending on CPU frequency and transfer sizes: * Reduced mmcqd cpu core usage by 4-50% Signed-off-by: CTCaer <[email protected]>
1 parent 7347378 commit faeb1e7

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

drivers/mmc/host/sdhci.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ static void sdhci_initialize_data(struct sdhci_host *host,
10951095
WARN_ON(host->data);
10961096

10971097
/* Sanity checks */
1098-
BUG_ON(data->blksz * data->blocks > 524288);
1098+
BUG_ON(data->blksz * data->blocks > host->mmc->max_req_size);
10991099
BUG_ON(data->blksz > host->mmc->max_blk_size);
11001100
BUG_ON(data->blocks > 65535);
11011101

@@ -4729,11 +4729,18 @@ int sdhci_setup_host(struct sdhci_host *host)
47294729

47304730
/*
47314731
* Maximum number of sectors in one transfer. Limited by SDMA boundary
4732-
* size (512KiB). Note some tuning modes impose a 4MiB limit, but this
4733-
* is less anyway.
4732+
* size and by tuning modes on ADMA. On tuning mode 3 16MiB is more than
4733+
* enough to cover big data transfers.
47344734
*/
4735-
mmc->max_req_size = 524288;
4736-
4735+
if (host->flags & SDHCI_USE_ADMA) {
4736+
if (host->tuning_mode != SDHCI_TUNING_MODE_3)
4737+
mmc->max_req_size = SZ_4M;
4738+
else
4739+
mmc->max_req_size = SZ_16M;
4740+
} else {
4741+
/* On PIO/SDMA use SDMA boundary size (512KiB). */
4742+
mmc->max_req_size = SZ_512K;
4743+
}
47374744
/*
47384745
* Maximum number of segments. Depends on if the hardware
47394746
* can do scatter/gather or not.

drivers/mmc/host/sdhci.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,11 @@ struct sdhci_adma2_64_desc {
340340
#define ADMA2_END 0x2
341341

342342
/*
343-
* Maximum segments assuming a 512KiB maximum requisition size and a minimum
343+
* Maximum segments assuming a 16MiB maximum requisition size and a minimum
344344
* 4KiB page size. Note this also allows enough for multiple descriptors in
345345
* case of PAGE_SIZE >= 64KiB.
346346
*/
347-
#define SDHCI_MAX_SEGS 128
347+
#define SDHCI_MAX_SEGS 4096
348348

349349
/* Allow for a a command request and a data request at the same time */
350350
#define SDHCI_MAX_MRQS 2

0 commit comments

Comments
 (0)