e5148707bdaaa7a9b3e902f6e26d8e147eb874a5
[openwrt/staging/pepe2k.git] /
1 From d70a60eb03ae4fc687b91b5f6c4684000be21c5f Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.com>
3 Date: Wed, 8 Jan 2025 15:09:53 +0000
4 Subject: [PATCH] mmc: sd: filter card CQ support based on an allow-list
5
6 We have found that many SD cards in the field, even of the same make and
7 model, have latent bugs in their CQ implementation. Some product lines
8 have fewer bugs with newer manufacture dates, but this is not a
9 guarantee that a particular card is at a particular firmware revision
10 level.
11
12 Many of these bugs lead to card hangs or data corruption. Add a quirk to
13 mark a card as having a tested, working CQ implementation and ignore the
14 capability if absent.
15
16 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
17 ---
18 drivers/mmc/core/card.h | 5 +++++
19 drivers/mmc/core/sd.c | 4 ++++
20 include/linux/mmc/card.h | 1 +
21 3 files changed, 10 insertions(+)
22
23 --- a/drivers/mmc/core/card.h
24 +++ b/drivers/mmc/core/card.h
25 @@ -292,4 +292,9 @@ static inline int mmc_card_broken_sd_pow
26 return c->quirks & MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY;
27 }
28
29 +static inline int mmc_card_working_sd_cq(const struct mmc_card *c)
30 +{
31 + return c->quirks & MMC_QUIRK_WORKING_SD_CQ;
32 +}
33 +
34 #endif
35 --- a/drivers/mmc/core/sd.c
36 +++ b/drivers/mmc/core/sd.c
37 @@ -1506,6 +1506,10 @@ cont:
38 goto free_card;
39 }
40
41 + /* Disallow command queueing on unvetted cards */
42 + if (!mmc_card_working_sd_cq(card))
43 + card->ext_csd.cmdq_support = false;
44 +
45 /* Enable command queueing if supported */
46 if (card->ext_csd.cmdq_support && host->caps2 & MMC_CAP2_CQE) {
47 /*
48 --- a/include/linux/mmc/card.h
49 +++ b/include/linux/mmc/card.h
50 @@ -297,6 +297,7 @@ struct mmc_card {
51 #define MMC_QUIRK_BROKEN_SD_CACHE (1<<15) /* Disable broken SD cache support */
52 #define MMC_QUIRK_BROKEN_CACHE_FLUSH (1<<16) /* Don't flush cache until the write has occurred */
53 #define MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY (1<<17) /* Disable broken SD poweroff notify support */
54 +#define MMC_QUIRK_WORKING_SD_CQ (1<<30) /* SD card has known-good CQ implementation */
55 #define MMC_QUIRK_ERASE_BROKEN (1<<31) /* Skip erase */
56
57 bool written_flag; /* Indicates eMMC has been written since power on */