Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7632749rwp; Tue, 18 Jul 2023 19:56:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlFU6G0oQQwYDqZ71dFwGS60eO/51G8XfXJSMUWXiyeov7agAXWgp5rn6tJrgnHYfkAbDtYO X-Received: by 2002:a17:903:183:b0:1b6:6f12:502e with SMTP id z3-20020a170903018300b001b66f12502emr19952037plg.49.1689735392771; Tue, 18 Jul 2023 19:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689735392; cv=none; d=google.com; s=arc-20160816; b=W4Me/To9rEZmip93AgQQ1wLPkdYyaCDvkg5wj0oWupA7+NoFxT8T0D6Lt7OB4us8+q zcwLhdXW7q0+CQuWhH7is4zuqTlBl3sOJAV+goAv50gxT95raONuaeojNrAxoGmuMTAl CES6qaRmc7mhdgieIBPPPLnQPI4VUplWoBK7DnJarXlskJ1+yyS2EF5AofokT9OnxEAm h9UtKaDV+96QOP2RYEMLPQyy8voDg9kldtkDlIwGtveA0HU7YAmwp4VSbbLCS6fimJ9D +KDm0X0/lrirAHUwgNEo9MI5eFq8jxBSZtPupxdXtFz1QzflFTLscNDIHBnDTC5VHmjh BUkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=alrunddGyr7n1O6dTU2394duvap6e5CEXKLxFMKdcbQ=; fh=lywJFhKbKOgl0BcNS4ue5qp1+0Fvc0AuD4qN9hGJxpw=; b=xApQoHBb6w+KEEZLaKjC5m/0jAWAJxxEYH4pbM09fIqmrrZe4fn+gbuNCeOH3aoE0e y4XSYJNmOU5/rMr1Ci9T2Ija5W7nCla8px3eF9ZFnHS6q3cQSw5VqBJZb1LcOF2aU362 SyMPR13BxGgL+/bRyOgnC0au8TR2QV+SUEKUaUaQxw6M2rpNfrFXu4JKvUy3ciTAZBZW 698sYDwyLWH5ejmquWVcsdM5d8yZ7c6YUccXh/tQZd7zm0JD+moxksHXZgbau6Ixba9k p4HWQGz/hC3eb+VWdEXh6ZJuvZgMKi+iHwWCgUyDAjaDuP9zi5u9xStWe88uIBEm72ZO qrKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=F+9xO7EH; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d15-20020a170902cecf00b001ae141947acsi2741909plg.183.2023.07.18.19.56.21; Tue, 18 Jul 2023 19:56:32 -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; dkim=pass header.i=@gmail.com header.s=20221208 header.b=F+9xO7EH; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbjGSCqc (ORCPT + 99 others); Tue, 18 Jul 2023 22:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjGSCqb (ORCPT ); Tue, 18 Jul 2023 22:46:31 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30693FC; Tue, 18 Jul 2023 19:46:30 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-63719ad32e7so38054596d6.1; Tue, 18 Jul 2023 19:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689734789; x=1692326789; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=alrunddGyr7n1O6dTU2394duvap6e5CEXKLxFMKdcbQ=; b=F+9xO7EHDJJtK+PpR7Mqu0aMYjSiAtGBIIg9T9AY9eIPoeu3iY2VrUPbPHDMt4BEMQ OM1HeTcAf8slfv2WNu4347kqsqqbdZA1L37hiZ+WBIWBc3rS92XGUf5YJsaHJFiaGhn7 fYUuW24LjTBvwoWRzJBXl7BlgEf9GkGyEbWj/5VXav9t952p488jO08EjO4WpAL9I75y 4R5k3HTsJr9/Vkj0xTaoR+TCW3q/T3HO7JKqoYEwkhaGH0oiSz5eMs8v0G5l3C6fbkBN A0ZVDy3KaS8F9iVRDnhpbxZtU4+Wce1JLfhCmrq1RtoMYm7wtniGLkUacQliqdEl47fr GUZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689734789; x=1692326789; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=alrunddGyr7n1O6dTU2394duvap6e5CEXKLxFMKdcbQ=; b=BJtCWmrSxU6XclCZc/by1QUPFpz8JMjlb9HSi2rTIQdlGF8Mcdrqa8xgQ/y1P0C6tH /RrCRVy+jcBpgcrch0htcWe1KlwmylGp7Le9f42lsnHCCG6nhpeJSq+ywt9nsotGU5Nk lKvhDZmWWQ2bixVDnd+MfAC0mmiizmWZbHXlz2grPRSxuEyZtvon94PXSlFUW32thNIQ U4mRAN54WFrPqmumPf6pllqtMZfLMDydkIdEDNRcmU8zcTjRHN1jisn1KYQ1rnIN4RaL g6TnfYStqBHoU/bLVF3IlU/VFhg5KtNOx+nctqIbJiIh5Khy+EL++x/NAPMGAvuk4XrB l/7A== X-Gm-Message-State: ABy/qLbMSrRkgxE6Xs/YbTsJ14zQ6x8hadX2iZPL1uNlIa+08C1+iZVi s0u0NB9e99UpG8iijF4qNuUHncEHhjgZ3pkDd47GlZXAeSc= X-Received: by 2002:a0c:b394:0:b0:635:e303:ed6d with SMTP id t20-20020a0cb394000000b00635e303ed6dmr15390732qve.52.1689734789236; Tue, 18 Jul 2023 19:46:29 -0700 (PDT) MIME-Version: 1.0 References: <20230718011504.10947-1-wenchao.chen@unisoc.com> In-Reply-To: From: Wenchao Chen Date: Wed, 19 Jul 2023 10:46:18 +0800 Message-ID: Subject: Re: [PATCH] mmc: core: Remove FW revision from CID check To: Adrian Hunter Cc: Wenchao Chen , ulf.hansson@linaro.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, zhenxiong.lai@unisoc.com, chunyan.zhang@unisoc.com, yuelin.tang@unisoc.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,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 On Tue, Jul 18, 2023 at 2:13=E2=80=AFPM Adrian Hunter wrote: > > On 18/07/23 04:15, Wenchao Chen wrote: > > 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. > > What is the use-case for this? I would have thought it is safer > not to assume anything about the card after the firmware has been > upgraded. > Hi adrian Understood, but we have case: 1.Before the firmware upgrade [T5745@C0] mmc0 oldcard raw->cid[2]: 32691160, raw->cid[3]: d924180= 0 PRV=3D69 2.After the firmware upgrade [T5745@C0] mmc0 cid[2]: 32011160 cid[3]: d9241800 PRV=3D01 If the PRV is not excluded in the CID check, then the mmc initialization will fail after the mmc reset. In addition, CRC is excluded because some controllers support SDHCI_QUIRK2_RSP_136_HAS_CRC. > > > > 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[] =3D { > > 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] !=3D raw_cid[0] || cid[1] !=3D raw_cid[1] || > > + (cid[2] & ~MMC_CID_PRV_MASK) !=3D (raw_cid[2] & ~MMC_CID_= PRV_MASK) || > > + (cid[3] & ~MMC_CID_CRC_MASK) !=3D (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, u= 32 ocr, > > goto err; > > > > if (oldcard) { > > - if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) !=3D 0) { > > + if (mmc_check_cid(cid, oldcard->raw_cid)) { > > pr_debug("%s: Perhaps the card was replaced\n", > > mmc_hostname(host)); > > err =3D -ENOENT; >