Linux MultiMedia Card development
 help / color / mirror / Atom feed
* [PATCH] mmc: core: Remove FW revision from CID check
@ 2023-07-18  1:15 Wenchao Chen
  2023-07-18  6:13 ` Adrian Hunter
  0 siblings, 1 reply; 8+ messages in thread
From: Wenchao Chen @ 2023-07-18  1:15 UTC (permalink / raw)
  To: ulf.hansson, adrian.hunter
  Cc: linux-mmc, linux-kernel, wenchao.chen666, zhenxiong.lai,
	chunyan.zhang, yuelin.tang, Wenchao Chen

When the card is reset, mmc_card_init() will check if this
card is the previous card by comparing the CID.

If the firmware is upgraded, the product version may change,
so we remove the product version from the CID check.

Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
---
 drivers/mmc/core/mmc.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 89cd48fcec79..32a73378d5c3 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -32,6 +32,9 @@
 #define MIN_CACHE_EN_TIMEOUT_MS 1600
 #define CACHE_FLUSH_TIMEOUT_MS 30000 /* 30s */
 
+#define MMC_CID_PRV_MASK GENMASK(23, 16)
+#define MMC_CID_CRC_MASK GENMASK(7, 0)
+
 static const unsigned int tran_exp[] = {
 	10000,		100000,		1000000,	10000000,
 	0,		0,		0,		0
@@ -126,6 +129,19 @@ static int mmc_decode_cid(struct mmc_card *card)
 	return 0;
 }
 
+static int mmc_check_cid(u32 *cid, u32 *raw_cid)
+{
+	/*
+	 * When comparing CID, we need to remove the product
+	 * version (Field PRV, offset 55:48) and CRC. Because
+	 * the product version will change when the firmware
+	 * is upgraded. Also, the new CRC is different.
+	 */
+	return cid[0] != raw_cid[0] || cid[1] != raw_cid[1] ||
+		(cid[2] & ~MMC_CID_PRV_MASK) != (raw_cid[2] & ~MMC_CID_PRV_MASK) ||
+		(cid[3] & ~MMC_CID_CRC_MASK) != (raw_cid[3] & ~MMC_CID_CRC_MASK);
+}
+
 static void mmc_set_erase_size(struct mmc_card *card)
 {
 	if (card->ext_csd.erase_group_def & 1)
@@ -1640,7 +1656,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
 		goto err;
 
 	if (oldcard) {
-		if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
+		if (mmc_check_cid(cid, oldcard->raw_cid)) {
 			pr_debug("%s: Perhaps the card was replaced\n",
 				mmc_hostname(host));
 			err = -ENOENT;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-20  9:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-18  1:15 [PATCH] mmc: core: Remove FW revision from CID check Wenchao Chen
2023-07-18  6:13 ` Adrian Hunter
2023-07-18 12:32   ` Avri Altman
2023-07-19  2:57     ` Wenchao Chen
2023-07-19  2:46   ` Wenchao Chen
2023-07-20  6:44     ` Adrian Hunter
2023-07-20  8:38       ` Wenchao Chen
2023-07-20  9:11         ` Adrian Hunter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox