Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3365482pxb; Tue, 20 Apr 2021 06:50:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXyCP32hxiLmxASh6NjwPkQNPHZ457gg8B6Zk91xmC8IoVoas0GXRXWe4X+FuBQKxA5bK+ X-Received: by 2002:a17:907:9116:: with SMTP id p22mr28214068ejq.516.1618926622681; Tue, 20 Apr 2021 06:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618926622; cv=none; d=google.com; s=arc-20160816; b=Gf1LF1FQWBAYSxCyJ602zb7Eq0718j8ThmKOUF3VEXnUC4ndKamBlK28AYChATLb5j 03yhr7fCa/Fwud+dfLtZCfBMkU9banrZpwDkt0ggj1mWR70EY7nOuW+YoOh057/wUuW7 9mlrIHbc7j1aN6waoto/CgfszsFX+Vq6J7CZsexdl0ZimSbojUNVYCVQiCbdebPghuml vopbIepUnNBMN1Jm0JWEksTUR/Goqz9449n806akgAU6giozPPdqc5EZTiseZLQ+jdL5 OI3eeOrx9tC5wsJ3+yo1Lxslb/RO4kI06yZB5QLfQBRpUC7lCcbpJejJfy9qwYDMZuL6 MNYA== 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=XoI1b6T7f6AJZ3jtzI4nwLokuOEiDzlhmAd1XwGf+zE=; b=uVseoNnNTL7q8CuvnlJ/cij5WoM3CbVq5iOxsCeddq6rAGs+vgfZnoEBf6EMdtO3Cx a22JHDxul5uO/V7Gj9WiUn572uY7TpmIiL2a/e9LhRMYvHRUi9J/d62NUSzdSebl4XKw XyNt1z2i+AORJHw88QnX/N29HRPYfOR2NUcL4x4vdtaC+23bCGCLlg5xccYCLNut4eqT r0cBjkXSi3W3yYndDm+V5KDCy1OT69tuo/TCzU4D3xHwtPeViKODio+KXbl4r2XpKjUn Tq/ok5JJytefSNQTiFwQWHxv0S5fuKJ4iJf/l9cBVvyrCTr0zQlQqyy1sR0vQb+BPYdz CNmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=jtEvbmFp; 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 a42si12524edf.438.2021.04.20.06.49.59; Tue, 20 Apr 2021 06:50:22 -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=jtEvbmFp; 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 S232637AbhDTNr0 (ORCPT + 99 others); Tue, 20 Apr 2021 09:47:26 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53204 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbhDTNr0 (ORCPT ); Tue, 20 Apr 2021 09:47:26 -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=1618926414; x=1650462414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z0lxOkGI1HbA5WK2WYt4hn56ZHJdND607vtOC4lvr5Y=; b=jtEvbmFpHwWW5RKW7dsR/A59jTCVRrgbPqOByTVnek+lDa7j88qKeohL RFHsvnTI/ODgefw4WB/W0xa0aNaD3JQxiodRJTaVPYy9xdhMFf2kjfmH8 TQFHE4LBU+zOTp47nuLehFS3TAmizAjJzNiSJ4wRAfi29noFCqTGXcoFZ dJt22CwsA+TTJR0henDNN4j0Ez+CXbbB0MIruabWTBwdF1Hd+tJdR4RL9 kPlcOe7s4kQhiLH34TtH1IWE1G1XcpTtdlnPYdgX+qgSWevE/4yoD2T+t pFDg0gtQ5yN0Bs4ltCrgcjUhyRahofVNpiByoYw5BbQf8qMSMjeBu58c9 g==; IronPort-SDR: lDfsaT8zKxs3WUXlUan3siXUbgF/2/VUvA0PBpzcvog2lk2DYEEuK/OU3jGywlWsEDuaXjULNj +aMTDb4XCvJEGGPYh4QR/DP3S/mYOcpXu9EQvoGRB5L2DF+jaem6qXIaVcJwRmCILdkstYl1aA Vo1yYzUmh3Ye5kAZCaD69DaALueyvcqqc0tWyrG7Vc/+7ub1963uL4Q2rWdX4qR/dNTzu0nITp VLV0uJC3kQ1uK9qtUfOoMtjxBoPFdB/RhlVaDkQmZV6egU5DqmSQ5Y1msm7DK/cXCuWVWTVgF7 ZGg= X-IronPort-AV: E=Sophos;i="5.82,237,1613404800"; d="scan'208";a="164889875" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 Apr 2021 21:46:54 +0800 IronPort-SDR: gSyWzu0t1Sdl5ommIbnt7bpo78adkvht9cKBfvGstzGxyQxQVCSKMkM15sk4Txujlj2v8H2JLd lY9JC8caC4LvKkjVOvIBhPVOraDTWaGDsUtdN5lFPZP5/RrYEqr24gUqvjOKYaev2bjiOg7Kvi UZUxgwECqirOiuU02lDIRZGOtb4/jrOufWYVOFzXKZfw/tTdXer7Tt6or7eq01WhuZDeZ/qEWD tVnT823QuYcrA15i8bq9Kh/WjPmfG3NFmITkT/IXOvCCk7zXFK6ue8qfxs4fic2e+Y69e5kt5B 7uXVUsTwHcoMDtoTF53je6Sq Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2021 06:27:33 -0700 IronPort-SDR: U4EJxG6aXZM6OlimiyeCnHKU0fUaUENG8e6IgsfoiqqteVYSXs7unz4n7Lrrhseypo6ixs3gdy D2qeGf77/t7k5szMidetw4mdKEwgKchFUhvE5nwmwO1AebEBsQM15gZ3vJJLypITo4gLO7fYRu Dc2QKDwh7JCTunnxHrDrXkdbnvqne1q0aq2ihD7KJILcyAS4/CnzwCBeMsd3X4HUv2/dTqhndU xUjjEcKcCmE0U4+5L7Fnbx9AuViVFiganmovHEAFRrsoYfcGqyPG+hlsuxfiw3QEm6jD7n30Ji SMM= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 20 Apr 2021 06:46:53 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org, Adrian Hunter Cc: linux-kernel@vger.kernel.org, Avri Altman , Brendan Peter Subject: [PATCH v4 1/2] mmc: block: Issue flush only if allowed Date: Tue, 20 Apr 2021 16:46:40 +0300 Message-Id: <20210420134641.57343-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420134641.57343-1-avri.altman@wdc.com> References: <20210420134641.57343-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 | 9 +++++++++ drivers/mmc/core/mmc.c | 2 +- drivers/mmc/core/mmc_ops.h | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 8bfd4d95b386..24e1ecbdd510 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2186,6 +2186,11 @@ static int mmc_blk_wait_for_idle(struct mmc_queue *mq, struct mmc_host *host) return mmc_blk_rw_wait(mq, NULL); } +static bool mmc_blk_cache_disabled(struct mmc_card *card) +{ + return mmc_card_mmc(card) && !mmc_flush_allowed(card); +} + enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req) { struct mmc_blk_data *md = mq->blkdata; @@ -2225,6 +2230,10 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req) case MMC_ISSUE_ASYNC: switch (req_op(req)) { case REQ_OP_FLUSH: + if (mmc_blk_cache_disabled(mq->card)) { + blk_mq_end_request(req, BLK_STS_OK); + return MMC_REQ_FINISHED; + } ret = mmc_blk_cqe_issue_flush(mq, req); break; case REQ_OP_READ: diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 9ad4aa537867..e3da62ffcb5e 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -2037,7 +2037,7 @@ static int _mmc_flush_cache(struct mmc_card *card) { int err = 0; - if (card->ext_csd.cache_size > 0 && card->ext_csd.cache_ctrl & 1) { + if (mmc_flush_allowed(card)) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_FLUSH_CACHE, 1, CACHE_FLUSH_TIMEOUT_MS); diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index 5782fdf4e8e9..2682bf66708a 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