From 83a8ab6435d122f574f04964d6d37a31c78d85c8 Mon Sep 17 00:00:00 2001 From: Jonathan Bell Date: Thu, 13 Jun 2024 15:01:02 +0100 Subject: [PATCH 1/2] drivers: mmc: sdhci-brcmstb: improve bcm2712 card removal handling If the controller is being reset, then the CQE needs to be reset as well. For removable cards, CQHCI_SSC1 must specify a polling mode (CBC=0) otherwise it's possible that the controller stops emitting periodic CMD13s on card removal, without raising an error status interrupt. Signed-off-by: Jonathan Bell --- drivers/mmc/host/sdhci-brcmstb.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/sdhci-brcmstb.c b/drivers/mmc/host/sdhci-brcmstb.c index 730e262dc68de1..ab711de26dc44f 100644 --- a/drivers/mmc/host/sdhci-brcmstb.c +++ b/drivers/mmc/host/sdhci-brcmstb.c @@ -365,8 +365,21 @@ static void sdhci_brcmstb_cqe_enable(struct mmc_host *mmc) sdhci_cqe_enable(mmc); - /* Reset CMD13 polling timer back to eMMC specification default */ - cqhci_writel(cq_host, 0x00011000, CQHCI_SSC1); + /* + * The controller resets this register to a very short default interval + * whenever CQHCI is disabled. + * + * For removable cards CBC needs to be clear or card removal can hang + * the CQE. In polling mode, a CIT of 0x4000 "cycles" seems to produce the best + * throughput. + * + * For nonremovable cards, the specification default of CBC=1 CIT=0x1000 + * suffices. + */ + if (mmc->caps & MMC_CAP_NONREMOVABLE) + cqhci_writel(cq_host, 0x00011000, CQHCI_SSC1); + else + cqhci_writel(cq_host, 0x00004000, CQHCI_SSC1); } static const struct cqhci_host_ops sdhci_brcmstb_cqhci_ops = { @@ -386,7 +399,7 @@ static struct sdhci_ops sdhci_brcmstb_ops_2712 = { .set_clock = sdhci_bcm2712_set_clock, .set_power = sdhci_brcmstb_set_power, .set_bus_width = sdhci_set_bus_width, - .reset = sdhci_reset, + .reset = brcmstb_reset, .set_uhs_signaling = sdhci_set_uhs_signaling, .init_sd_express = bcm2712_init_sd_express, }; From 3708957ef88687e7834205bc0f93c7e7d71e1299 Mon Sep 17 00:00:00 2001 From: Jonathan Bell Date: Thu, 13 Jun 2024 15:05:40 +0100 Subject: [PATCH 2/2] drivers: mmc: core: handle card-removal when running CQE recovery Recovery claims the MMC card so the card-detect work gets significantly delayed - leading to lots of error recovery loops that can never do anything but fail. Explicitly detect the card after CQE has halted and bail if it's not there. Also ratelimit a not-very-descriptive warning - one occurrence in dmesg is enough to signal that something is amiss. Signed-off-by: Jonathan Bell --- drivers/mmc/core/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 0d59beadecb8f7..d5e9c55a9e6c92 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -543,10 +543,18 @@ int mmc_cqe_recovery(struct mmc_host *host) * Recovery is expected seldom, if at all, but it reduces performance, * so make sure it is not completely silent. */ - pr_warn("%s: running CQE recovery\n", mmc_hostname(host)); + pr_warn_ratelimited("%s: running CQE recovery\n", mmc_hostname(host)); host->cqe_ops->cqe_recovery_start(host); + err = mmc_detect_card_removed(host); + if (err) { + host->cqe_ops->cqe_recovery_finish(host); + host->cqe_ops->cqe_off(host); + mmc_retune_release(host); + return err; + } + memset(&cmd, 0, sizeof(cmd)); cmd.opcode = MMC_STOP_TRANSMISSION; cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;