Skip to content

Commit 3003cbf

Browse files
committed
mmc: sdhci: Fix ADMA for PAGE_SIZE >= 64KiB
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2144641 commit 3d7c194 Author: Adrian Hunter <adrian.hunter@intel.com> Date: Mon, 15 Nov 2021 10:23:45 +0200 The block layer forces a minimum segment size of PAGE_SIZE, so a segment can be too big for the ADMA table, if PAGE_SIZE >= 64KiB. Fix by writing multiple descriptors, noting that the ADMA table is sized for 4KiB chunks anyway, so it will be big enough. Reported-and-tested-by: Bough Chen <haibo.chen@nxp.com> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20211115082345.802238-1-adrian.hunter@intel.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Mark Salter <msalter@redhat.com>
1 parent 057373c commit 3003cbf

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

drivers/mmc/host/sdhci.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,19 @@ static void sdhci_adma_table_pre(struct sdhci_host *host,
771771
len -= offset;
772772
}
773773

774-
BUG_ON(len > 65536);
774+
/*
775+
* The block layer forces a minimum segment size of PAGE_SIZE,
776+
* so 'len' can be too big here if PAGE_SIZE >= 64KiB. Write
777+
* multiple descriptors, noting that the ADMA table is sized
778+
* for 4KiB chunks anyway, so it will be big enough.
779+
*/
780+
while (len > host->max_adma) {
781+
int n = 32 * 1024; /* 32KiB*/
782+
783+
__sdhci_adma_write_desc(host, &desc, addr, n, ADMA2_TRAN_VALID);
784+
addr += n;
785+
len -= n;
786+
}
775787

776788
/* tran, valid */
777789
if (len)
@@ -3968,6 +3980,7 @@ struct sdhci_host *sdhci_alloc_host(struct device *dev,
39683980
* descriptor for each segment, plus 1 for a nop end descriptor.
39693981
*/
39703982
host->adma_table_cnt = SDHCI_MAX_SEGS * 2 + 1;
3983+
host->max_adma = 65536;
39713984

39723985
host->max_timeout_count = 0xE;
39733986

@@ -4633,10 +4646,12 @@ int sdhci_setup_host(struct sdhci_host *host)
46334646
* be larger than 64 KiB though.
46344647
*/
46354648
if (host->flags & SDHCI_USE_ADMA) {
4636-
if (host->quirks & SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC)
4649+
if (host->quirks & SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC) {
4650+
host->max_adma = 65532; /* 32-bit alignment */
46374651
mmc->max_seg_size = 65535;
4638-
else
4652+
} else {
46394653
mmc->max_seg_size = 65536;
4654+
}
46404655
} else {
46414656
mmc->max_seg_size = mmc->max_req_size;
46424657
}

drivers/mmc/host/sdhci.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ struct sdhci_adma2_64_desc {
340340

341341
/*
342342
* Maximum segments assuming a 512KiB maximum requisition size and a minimum
343-
* 4KiB page size.
343+
* 4KiB page size. Note this also allows enough for multiple descriptors in
344+
* case of PAGE_SIZE >= 64KiB.
344345
*/
345346
#define SDHCI_MAX_SEGS 128
346347

@@ -543,6 +544,7 @@ struct sdhci_host {
543544
unsigned int blocks; /* remaining PIO blocks */
544545

545546
int sg_count; /* Mapped sg entries */
547+
int max_adma; /* Max. length in ADMA descriptor */
546548

547549
void *adma_table; /* ADMA descriptor table */
548550
void *align_buffer; /* Bounce buffer */

0 commit comments

Comments
 (0)