Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6253704rwp; Mon, 17 Jul 2023 18:38:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlH9s3ZNpdEkyc8yBeDrVvg2nrcMzqsXJVwJzl0OFnPV7KSq1UrPnr21czHbT0iJRR3PZpUL X-Received: by 2002:a17:906:535e:b0:993:d616:7ca9 with SMTP id j30-20020a170906535e00b00993d6167ca9mr12521429ejo.23.1689644323677; Mon, 17 Jul 2023 18:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689644323; cv=none; d=google.com; s=arc-20160816; b=D5Tbo29EoTfxqseVQp/FcdnMM7Qqh1uWuBgRI1axwiaM/YjmZtlGgWC4+nBpy1hbDf EefxTKnNak/UbDawOSnpC+3/0cVjpwT/tV6EkZ/swE5a82HkN2RNPeT7fP8oio7WqBG/ OF4yLNsn2o68IstMazAq8U6MQzqJXXL6cCQ1QCVNnHxnAgo+stq+EFW+TMKE2oXozV+G FzeOeQ/tXMW+1ZeWYUQVyAVtW30XcvMMRvEOZf4Ox9cpeSvEeDYDYwXhF3cFhz2S12Ue OTfSrr2pwYr60Tjk/JTVP/7cwEmOYYzVOH8L8cOrOlgWFd5DCbhGqkLZWZWwiNjICYIw kl2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=fhFq1+5A3VfeopeE6805Gw14O/60dZhmFFbmk4TlCGk=; fh=kXtcevw3du17sm1tfm2px4FICZ5BnzVT+vDKTe39Ldw=; b=CB7bMGfi7oQ2WLaMVD3j9B/ak6Cl3ywC6rNJTKSNURTT/ERbS8S/JiZ3yXYOGJRqrF if8NPI3naiOOgyUZcSsEoKYrHbauBVghZFPtakvsERG8uhz89jfAuEjdCh8It9Qx2ix0 AcAvCo0QaECXzTRMEfdA997gAQtj4lfYlbAH4/IkbJ68LUTglGG9HGs9wzCCjhpVZkg2 0YJjHVylEMji2vm4Jzqw8dPnsfafLunvVI+bs6sPH0zWv2o24FQHgh+q+hmTjz2oiwgF AkjZyEhQD5hCfyHWCy8JZq3CFLi5h9gnBZdvMs+ceCo1iS1T4RH4pcYIka1klHFMGU6I RxOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n8-20020a1709065e0800b00977e10fafd3si433652eju.1045.2023.07.17.18.38.17; Mon, 17 Jul 2023 18:38:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230361AbjGRBQH (ORCPT + 99 others); Mon, 17 Jul 2023 21:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbjGRBQF (ORCPT ); Mon, 17 Jul 2023 21:16:05 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52C55ED; Mon, 17 Jul 2023 18:16:03 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 36I1Fh0f083467; Tue, 18 Jul 2023 09:15:43 +0800 (+08) (envelope-from Wenchao.Chen@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx05.spreadtrum.com [10.29.1.56]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4R4gw56j5sz2MZTl1; Tue, 18 Jul 2023 09:14:29 +0800 (CST) Received: from xm9614pcu.spreadtrum.com (10.13.2.29) by shmbx05.spreadtrum.com (10.29.1.56) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 18 Jul 2023 09:15:41 +0800 From: Wenchao Chen To: , CC: , , , , , , Wenchao Chen Subject: [PATCH] mmc: core: Remove FW revision from CID check Date: Tue, 18 Jul 2023 09:15:04 +0800 Message-ID: <20230718011504.10947-1-wenchao.chen@unisoc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.13.2.29] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To shmbx05.spreadtrum.com (10.29.1.56) X-MAIL: SHSQR01.spreadtrum.com 36I1Fh0f083467 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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