From f559241762d565cb758da2f2cf6bcee30e188fe3 Mon Sep 17 00:00:00 2001 From: zhucc2 Date: Tue, 2 Mar 2021 17:38:45 +0800 Subject: [PATCH] mmc: use max discard ignoring max_busy_timeout parameter. On kernel 4.14, no matter sd card type, all use max discard value. However, kernel 5.4 remove this logical, and will cause system watchdog, if user format 512GB/1TB class 10 card. Change-Id: Idc6b00187b8800465fca4af8f720aaf87db5700b Reviewed-on: https://gerrit.mot.com/1890338 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Huosheng Liao Submit-Approved: Jira Key --- drivers/mmc/core/core.c | 6 ++++++ drivers/mmc/host/sdhci-msm.c | 1 + include/linux/mmc/host.h | 2 ++ 3 files changed, 9 insertions(+) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 8ca425538576..ff015f5ca282 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2927,6 +2927,12 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card) struct mmc_host *host = card->host; unsigned int max_discard, max_trim; + if (!host->max_busy_timeout || + (host->caps2 & MMC_CAP2_MAX_DISCARD_SIZE)) + { + pr_err("mmc_calc_max_discard UINT_MAX = %d \n",UINT_MAX); + return UINT_MAX; + } /* * Without erase_group_def set, MMC erase timeout depends on clock * frequence which can change. In that case, the best choice is diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c index b12c3dd8607e..6a88499d1c90 100644 --- a/drivers/mmc/host/sdhci-msm.c +++ b/drivers/mmc/host/sdhci-msm.c @@ -4549,6 +4549,7 @@ static int sdhci_msm_probe(struct platform_device *pdev) host->timeout_clk_div = 4; msm_host->mmc->caps2 |= MMC_CAP2_CLK_SCALE; #endif + msm_host->mmc->caps2 |= MMC_CAP2_MAX_DISCARD_SIZE; sdhci_msm_setup_pm(pdev, msm_host); host->mmc_host_ops.execute_tuning = sdhci_msm_execute_tuning; diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 38cfd8faa2d2..162640f0bc88 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -483,6 +483,8 @@ struct mmc_host { #if defined(CONFIG_SDC_QTI) #define MMC_CAP2_CLK_SCALE (1 << 28) /* Allow dynamic clk scaling */ #endif +/* use max discard ignoring max_busy_timeout parameter */ +#define MMC_CAP2_MAX_DISCARD_SIZE (1 << 31) int fixed_drv_type; /* fixed driver type for non-removable media */