Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp478724pxb; Thu, 31 Mar 2022 09:37:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7E8V3q8ZwYn468lAiPuSxXN5Z024tqcre3JBN8ZUUuR7X9rPOzNHihfHDLLmSeJ/W/Q9D X-Received: by 2002:a17:906:4408:b0:6da:bec1:2808 with SMTP id x8-20020a170906440800b006dabec12808mr5652156ejo.543.1648744666710; Thu, 31 Mar 2022 09:37:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648744666; cv=none; d=google.com; s=arc-20160816; b=t4w7tRAyTJp6bhQFDFErZ2+IWzpsCmosTk2HuR2qrE/jm3naqqto73CXC+j1y4vVKw lVFcsC9o8tZPUpnaN/3J4Y2Z6qKR3v8qOLTMr3OxAIFK+wLjOHLZ8/cbvCzM+JeIOXoj zJyRgRIGgYLZSKo+FsvJLTDwU2botPCRmPi0RPbrlYNDTPYKDSibeeqqpjlqIw5IzU2O xruMxcEICiZwg5ZRzVH/I0sC6zEt4RQvuOvnKu4SogKH7qmoQNNOqHi9k4FuNaIZHgE6 p8IfcQesaVvcsn8VHvLT0xmoPcmZdrisx0LrJgPbZeCNQN2LU1lr/pFBqlpDvNJ/imP7 93ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=o4Cv3uhzbD9+IkAEkvAzFOf1gLPdBdUTNc6USpBA21k=; b=bxzLnVUyP4Sm6kTZSBzF5ElJzkvPTTP+19aAA9hPNx4RXWG7y5WUdgw0P5UJPkIaqb KRomcftsEx08Gqwt8RRF7ih0Tdj5iQfo09dQb6zivY28hKpTrLniCdYJlc76Bw/rkhJQ 5MYuUlTmJzb6jsTye074XPqNItp9A4aUB6KKFpBk35pHEvucTK6sK+AmnAD/HDSw7SKe Gh8Eb9Cb3x4wcdtr/KJMURi1QCg45voTxYb0NlgIdLwpkEI6TopRnlD9lvcbn08ml7TH iWK/40a89lTiBBzq7tTLFseuoO48iPjxJBp898RGlO3mxLdUhf+VVrI63CP0NMx3u0aF 4FhA== 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 b1-20020a50be81000000b0041947932452si55264edk.439.2022.03.31.09.37.19; Thu, 31 Mar 2022 09:37:46 -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 S232228AbiCaHeQ (ORCPT + 99 others); Thu, 31 Mar 2022 03:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230313AbiCaHeP (ORCPT ); Thu, 31 Mar 2022 03:34:15 -0400 Received: from out28-145.mail.aliyun.com (out28-145.mail.aliyun.com [115.124.28.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9E041F2DCC; Thu, 31 Mar 2022 00:32:27 -0700 (PDT) X-Alimail-AntiSpam: AC=CONTINUE;BC=0.2316432|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_alarm|0.00797514-0.00208816-0.989937;FP=0|0|0|0|0|-1|-1|-1;HT=ay29a033018047203;MF=michael@allwinnertech.com;NM=1;PH=DS;RN=19;RT=19;SR=0;TI=SMTPD_---.NGpUuXy_1648711941; Received: from SunxiBot.allwinnertech.com(mailfrom:michael@allwinnertech.com fp:SMTPD_---.NGpUuXy_1648711941) by smtp.aliyun-inc.com(33.38.168.42); Thu, 31 Mar 2022 15:32:23 +0800 From: Michael Wu To: ulf.hansson@linaro.org, axboe@kernel.dk, adrian.hunter@intel.com, avri.altman@wdc.com, kch@nvidia.com, beanhuo@micron.com, swboyd@chromium.org, digetx@gmail.com, bigeasy@linutronix.de, CLoehle@hyperstone.com, cjb@laptop.org, arnd@arndb.de, andreiw@motorola.com, tgih.jun@samsung.com, jh80.chung@samsung.com, linus.walleij@linaro.org Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, allwinner-opensource-support@allwinnertech.com Subject: [PATCH v2] mmc: block: enable cache-flushing when mmc cache is on Date: Thu, 31 Mar 2022 15:32:23 +0800 Message-Id: <20220331073223.106415-1-michael@allwinnertech.com> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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 The mmc core enables cache by default. But it only enables cache-flushing when host supports cmd23 and eMMC supports reliable-write. For hosts which do not support cmd23 or eMMCs which do not support reliable-write, the cache can not be flushed by `sync` command. This may leads to cache data lost. This patch enables cache-flushing as long as cache is enabled, no matter host supports cmd23 and/or eMMC supports reliable write or not. For SD cards, backwards compatibility is guaranteed. Newer components like SD5.0 which have cache are also supported in advance, which means this patch will also be applicable if SD5.0 cache is added to the mmc core in the future. Fixes: f4c5522b0a88 ("mmc: Reliable write support.") Fixes: 881d1c25f765 ("mmc: core: Add cache control for eMMC4.5 device") Fixes: 130206a615a9 ("mmc: core: Add support for cache ctrl for SD cards") Fixes: d0c97cfb81eb ("mmc: core: Use CMD23 for multiblock transfers when we can.") Fixes: e9d5c746246c ("mmc/block: switch to using blk_queue_write_cache()") Reviewed-by: Avri Altman Reviewed-by: Ulf Hansson Signed-off-by: Michael Wu --- drivers/mmc/core/block.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 4e67c1403cc9..ec76ed82abb9 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2350,6 +2350,8 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, struct mmc_blk_data *md; int devidx, ret; char cap_str[10]; + bool cache_enabled = false; + bool fua_enabled = false; devidx = ida_simple_get(&mmc_blk_ida, 0, max_devices, GFP_KERNEL); if (devidx < 0) { @@ -2429,13 +2431,17 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, md->flags |= MMC_BLK_CMD23; } - if (mmc_card_mmc(card) && - md->flags & MMC_BLK_CMD23 && + if (md->flags & MMC_BLK_CMD23 && ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) || card->ext_csd.rel_sectors)) { md->flags |= MMC_BLK_REL_WR; - blk_queue_write_cache(md->queue.queue, true, true); + fua_enabled = true; + cache_enabled = true; } + if (mmc_cache_enabled(card->host)) + cache_enabled = true; + + blk_queue_write_cache(md->queue.queue, cache_enabled, fua_enabled); string_get_size((u64)size, 512, STRING_UNITS_2, cap_str, sizeof(cap_str)); -- 2.29.0