Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3445282pxf; Mon, 22 Mar 2021 06:42:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygEt7hCr/hTQBaLOG7cS4YauqgRXlKRfiUJZOEyvNIT3tewcbH/3B+0gWrf707y8gY3Jw4 X-Received: by 2002:a17:906:3295:: with SMTP id 21mr19319346ejw.88.1616420527731; Mon, 22 Mar 2021 06:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616420527; cv=none; d=google.com; s=arc-20160816; b=MNOYspoVyjg2YWQpWCMfDHiNMq+1OvzFmyYufx5wU5KjpmxDa4mKQRnnpnW749CAOM eHYDb6qkY4BszmuxK1+WWGYNW0Z/kCId3HVXiHHrWiE9APnj5/rBp2bpUmp418rS+SsM aqOmVO7+/sjb01/8vzzdoHMmFlmLmtN1HKy7rmuUhMzmMAynWDnefD7BTINtZFjk6qoP 2+K7Wf1ysej1+0jjDjvnSWmYHiHcsN4ObOoK+PqjiEiAPGjJ7bSnv66gMVWTLMaQPXhE jHDXhTS85PNquzQOQ7Tgv7XJmzzuPYoUfoQwVDill0GJLuvvGU+y4Cyi04fGf8RNla+8 Oe+Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=uou4F7t9ILgkZkvsO8AVdN3S6UfzWC2r9BXuz/80s1U=; b=t5qXVpWfiQL1Ww0f6+73OrIzynNCAEAT+EgE4oX7eEXtMhRyQmr+40XFiXYM1AumSN ATblCxeGYyQg9cGOPf+rOQ7wWp9PX8faqRLmhtVpxkC1ECX1xs49SiwbGgidautiq218 H5wIpwp5ecR/DuY5won5X60U//GLob+saaj9T7xjR3ct0ny4fb3m/ljeBV2PPcoRv05E eZafniPkvI2BcV50/XmS0sGiz+sHCQmVT0zLBcJDynfb1rIk1p4a4wpPfXMn7MAKN3M9 RL5kqe4VhdCo3UjshLSQmE26/HSLrhVrry3ZEpqJMV8BcVBCWx+q3pijc4lxXEu3WItz OeHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=GO66Cdc7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si11743519edv.29.2021.03.22.06.41.43; Mon, 22 Mar 2021 06:42:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=GO66Cdc7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbhCVNiH (ORCPT + 99 others); Mon, 22 Mar 2021 09:38:07 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:49481 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbhCVNhj (ORCPT ); Mon, 22 Mar 2021 09:37:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616420259; x=1647956259; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wGMs1i8GIsX+8EmvtvhoYSNrVnYNajIZfQ9Kyx3KzkE=; b=GO66Cdc7Bh2WZ9MWcJp9byIKeVSCU+m3phlUUgFE/DoBPaVWx64vxv3P l6Vd0LkVMy5s7qmV6WsB5BFtq4UsJuTr7PQ2dy+Y1l3TDnDbkUAN7N5b+ OadGId3tJdpZFhm8hzzJ3iILKBCqZAQyeV8Eyw1jyFHzX7kWkAisssMdu QAA537xYNZdBFfLnzRUMIYQzYaqtfjSwvYmj0lf1PUBDzoxvEDfUT7KeB oqlANgwAXS3rxGz8h8qumLt/3UHlJPAmsfkmxkhGVbT6NX2HBaJOIlpnI ELerAnqRutJ7tup0GBUuI2uXB9liAlSNGuC6Cw2k+qrk22CHv+ItMJEsG w==; IronPort-SDR: ypwj/r+fw7AMTorQERVsJqub6BSnHXxi9AcXIB/7caUesE/sm7KekTT1/y0Qmt5aAHY35WH0zr EhvkdCiGVYu22Ba1tO0UMh+lk4N/n+Jxco0bUKKaOBZXFjbSBXytKiI06D72Z9zyeVwJXfUJqE Q60r/5lW9yOwrB0BkkYsBFeoj4VPml1IYaSNY9n7hbZD/vxrC4n44/FpgLGfX6Fuq7kXUaE0cX bd3fk7A/qjMQF+3lo3r5SuN+eQzxtQdLtX/XIPER+6gbWtGZ8EQY0DNU4ZY/Hd+7KStlJUUL9K EPE= X-IronPort-AV: E=Sophos;i="5.81,269,1610380800"; d="scan'208";a="162662254" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Mar 2021 21:37:38 +0800 IronPort-SDR: EKPy2R58q53Zyyv06juLFHVHcn6c7NHkEA4i0Maezs5liJhS/a4E5clLHlvaVeSZQD/++XpTFw bVi39YuZxHaetgq76EoE2DGksWuc6jfvx6EE6UnyiZGvGKqZzeunPqBC6cxmbFLPMe1rmjqAIv v9MXpJRhljx14lospbFGj64HazZFasBGbaTG64dMx6O7AUFgFprDwbNRqf7X3d97mHosEWZJDq WyQ/TrspTPShS81LD4D2wWrc76y0qhVkQROPSlnBi5e+Q8HQLf0lc3XbBqq4kKdIqJrsHb3xQu cQBqOkvfPhMJ5lnf9mjbGGdb Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2021 06:19:46 -0700 IronPort-SDR: KnPH3ktiq33w5JmrhXn2KpQbgFZRyaNdd91I2gCPct12qTcVssVzjWADRT7OuD0xk051X7Rctv jT3PohrIMcoTBbslNCE0IGlmL4LjFKyPsnUxAmZ5dH1qwwta41aks91tCi8RLib4fFHUXCfRpM GFDHUDqVxEsmA8VKvQaWTkW5nE0fqHTnG1XQC4IyY6U+76n/cecqUgzbD5p7OP85FN7j1oaUVa IZzP+FyIwWt0IKqI1Od7AXoR+rpJhtuVLW/QRSNxSKPPUxxhIay56JtxgeRoVMLD907Bf4KT+b Xyw= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Mar 2021 06:37:36 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , linux-kernel@vger.kernel.org, Avri Altman , Brendan Peter Subject: [PATCH 1/2] mmc: block: Issue flush only if allowed Date: Mon, 22 Mar 2021 15:36:44 +0200 Message-Id: <20210322133645.4901-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210322133645.4901-1-avri.altman@wdc.com> References: <20210322133645.4901-1-avri.altman@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cache may be flushed to the nonvolatile storage by writing to FLUSH_CACHE byte (EXT_CSD byte [32]). When in command queueing mode, the cache may be flushed by issuing a CMDQ_TASK_ DEV_MGMT (CMD48) with a FLUSH_CACHE op-code. Either way, verify that The cache function is turned ON before doing so. fixes: 1e8e55b67030 (mmc: block: Add CQE support) Reported-by: Brendan Peter Tested-by: Brendan Peter Signed-off-by: Avri Altman --- drivers/mmc/core/block.c | 3 +++ drivers/mmc/core/mmc_ops.c | 4 +--- drivers/mmc/core/mmc_ops.h | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 42e27a298218..a93c66aa91db 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1473,6 +1473,9 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue *mq, struct request *req) struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req); struct mmc_request *mrq = mmc_blk_cqe_prep_dcmd(mqrq, req); + if (mmc_card_mmc(mq->card) && !mmc_flush_allowed(mq->card)) + return 0; + mrq->cmd->opcode = MMC_SWITCH; mrq->cmd->arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | (EXT_CSD_FLUSH_CACHE << 16) | diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index baa6314f69b4..b8a0c9ac8a20 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -988,9 +988,7 @@ int mmc_flush_cache(struct mmc_card *card) { int err = 0; - if (mmc_card_mmc(card) && - (card->ext_csd.cache_size > 0) && - (card->ext_csd.cache_ctrl & 1)) { + if (mmc_card_mmc(card) && mmc_flush_allowed(card)) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_FLUSH_CACHE, 1, MMC_CACHE_FLUSH_TIMEOUT_MS); diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index 632009260e51..bf2b315addd7 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -19,6 +19,11 @@ enum mmc_busy_cmd { struct mmc_host; struct mmc_card; +static inline bool mmc_flush_allowed(struct mmc_card *card) +{ + return card->ext_csd.cache_size > 0 && (card->ext_csd.cache_ctrl & 1); +} + int mmc_select_card(struct mmc_card *card); int mmc_deselect_cards(struct mmc_host *host); int mmc_set_dsr(struct mmc_host *host); -- 2.25.1