From cae52db36eb4fb88c47737f65f3d2f6322efea56 Mon Sep 17 00:00:00 2001 From: Jonathan Bell Date: Wed, 8 Jan 2025 15:09:53 +0000 Subject: [PATCH] mmc: sd: filter card CQ support based on an allow-list We have found that many SD cards in the field, even of the same make and model, have latent bugs in their CQ implementation. Some product lines have fewer bugs with newer manufacture dates, but this is not a guarantee that a particular card is at a particular firmware revision level. Many of these bugs lead to card hangs or data corruption. Add a quirk to mark a card as having a tested, working CQ implementation and ignore the capability if absent. Signed-off-by: Jonathan Bell --- drivers/mmc/core/card.h | 5 +++++ drivers/mmc/core/sd.c | 4 ++++ include/linux/mmc/card.h | 1 + 3 files changed, 10 insertions(+) diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h index 0efdd58841f75f..950e21238bcf2e 100644 --- a/drivers/mmc/core/card.h +++ b/drivers/mmc/core/card.h @@ -295,4 +295,9 @@ static inline int mmc_card_broken_sd_poweroff_notify(const struct mmc_card *c) return c->quirks & MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY; } +static inline int mmc_card_working_sd_cq(const struct mmc_card *c) +{ + return c->quirks & MMC_QUIRK_WORKING_SD_CQ; +} + #endif diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index cd0cef8aebe03d..ece494e6c078a8 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -1501,6 +1501,10 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, goto free_card; } + /* Disallow command queueing on unvetted cards */ + if (!mmc_card_working_sd_cq(card)) + card->ext_csd.cmdq_support = false; + /* Enable command queueing if supported */ if (card->ext_csd.cmdq_support && host->caps2 & MMC_CAP2_CQE) { /* diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 92255a1dc0c6d3..6289155f806f15 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -295,6 +295,7 @@ struct mmc_card { #define MMC_QUIRK_BROKEN_SD_CACHE (1<<15) /* Disable broken SD cache support */ #define MMC_QUIRK_BROKEN_CACHE_FLUSH (1<<16) /* Don't flush cache until the write has occurred */ #define MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY (1<<17) /* Disable broken SD poweroff notify support */ +#define MMC_QUIRK_WORKING_SD_CQ (1<<30) /* SD card has known-good CQ implementation */ #define MMC_QUIRK_ERASE_BROKEN (1<<31) /* Skip erase */ bool written_flag; /* Indicates eMMC has been written since power on */