Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2487776pxb; Mon, 19 Apr 2021 06:57:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7CI1ZpBygo3bmeUrzu8DetaO2UQ8VcbCqLPtkDD/hJiJG/DwDSNjuM3V6aoFcQh8kdr0R X-Received: by 2002:a50:9feb:: with SMTP id c98mr17977470edf.104.1618840644821; Mon, 19 Apr 2021 06:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618840644; cv=none; d=google.com; s=arc-20160816; b=CVK+k9ZSxk+LKqSEMAtiRlsqPmFIbN7LKWbDQ4FX7j4uuh8brYn29ZN1sF3GU12a1Z zKtgoBoXie6aSBDqP73fpGA9O3Gtu+KYKie64sJRiy0bGcFLFtYk4ByZ81T0Bk0xxI5A J31wySKh8t3qbFmnIvWsAvYJW28mnst8JzBEQn/HHiz7YjMn5xF3dbTCxxvVkx2EvKy2 zO11OU7Hw/EpOo4kXWiDcxiTSuVFDwOoSR2XUbV2/6hzQlQhPj3lwR6UI6pX/m6fQeTn PMF6z/Zkm6Te/i6rD88D8ELC8HEtDUmChjIoDoC/Ycwkn6z09vFQIhX9V9QTGSBYUbza bWQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=dCgf0UyEDbuAQcdjW3A/2DyuF5Yu/jNA8mZrnhHTsic=; b=deqO55cCc1bHKgOAyKZZ5sEE77CoXOnDgwO6QPoM9HsyNy4UDEJezsII+HlCNAjh+g 3d/QJdu5wtiMxKBj1whWTfWdtPrgipJw+deMtht8BavKZmwm3hGEClMrhecjhYOhEoWy 9knr2qi+13mRCiMRAxZ/HpxZsO132B6DyKJvhzstq7vl9MaiQbEzaQDl+78rH9/XLY7l 4l1hbG/KYWrVUQ/tGTymjque5/sqOtctVBnFAr8eY4EDrrwOWRxdHP14UPhSbv0HTuFx RdIBTED9agLR9IBGYa/vG0IXarD8tf0aaBJxR3Jq/VTFPUb8ZUw1ardWRiL3mSL1Why8 kRoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ng+XW4kT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si12266321eds.182.2021.04.19.06.57.01; Mon, 19 Apr 2021 06:57:24 -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=pass header.i=@linaro.org header.s=google header.b=Ng+XW4kT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229790AbhDSMkS (ORCPT + 99 others); Mon, 19 Apr 2021 08:40:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239095AbhDSMkQ (ORCPT ); Mon, 19 Apr 2021 08:40:16 -0400 Received: from mail-vs1-xe32.google.com (mail-vs1-xe32.google.com [IPv6:2607:f8b0:4864:20::e32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE546C061760 for ; Mon, 19 Apr 2021 05:39:45 -0700 (PDT) Received: by mail-vs1-xe32.google.com with SMTP id t23so1136329vso.11 for ; Mon, 19 Apr 2021 05:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dCgf0UyEDbuAQcdjW3A/2DyuF5Yu/jNA8mZrnhHTsic=; b=Ng+XW4kTt/2k/byFWBo8TBLnivqKioqq7Y7Q26+nqjeMa1t6fBTzrNW2wSzDjFmUST 6+VMQ/GVSTMGMIXwJA3FWn0TNCMpfF/RQJnQKAlTrNaf0LD0WDnGwJhddi7s8fNg9/It o9iVzdQm5HA38ElnyZS/fAi0EY3dzuFCfyZhsYGvDo29mXwEIvuWgUySYwdScl2nHNll 3cwUyc6UQlA0yjuIPu8tLEta//tFjsz1i1wyjxr0G7Xr9+KIN5q/KRautINTxIiS9/Xq hL4IZmIxqMSecR2J/1/pp54wnmnySz28xj404hQrwDfPSTKZOdAVKrlfAs3qe1hwduVZ 8pHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dCgf0UyEDbuAQcdjW3A/2DyuF5Yu/jNA8mZrnhHTsic=; b=DW7jV748rvoc0uEzvzFmT/zhu0tESDbRt6JXsK9itV57s22II3il68hFNelyr18N9a jDc8kAD1DkCgRXUS1hp2Zj/zApnwE9ukZhN6RrPN25T4ncF2fXEF3suQa/nqyx3eueAA 3QEDIQMOytfPalJcCxZnPRwp19ocou86CC/MD6B09pm0O9MKUfTOygJhWAMSOkWn+p5w WOgr3B5fzjnpD+B2rcSSQEs9GalZGi9Nf5T7vIVkGbTL8BY8NB1vhEEuaKKt6Ld6x2Dh DgBQg5wAQhTJi78AAQWhRt+0Bl+jHIwbiUPsjIPwKi6T08iYvib1v16ZqDiN4erLypua fPng== X-Gm-Message-State: AOAM531TGN0nrmIJQrEuYJhuku/YbMkTDwMKgbAkEo/hRTVzai6urZ+F yme7oNw/BN2+6Ox39bwlgnjrWdkOjQYRyWfPGGiVUQ== X-Received: by 2002:a67:fd48:: with SMTP id g8mr13799346vsr.55.1618835985083; Mon, 19 Apr 2021 05:39:45 -0700 (PDT) MIME-Version: 1.0 References: <20210418055953.26959-1-avri.altman@wdc.com> <20210418055953.26959-2-avri.altman@wdc.com> In-Reply-To: <20210418055953.26959-2-avri.altman@wdc.com> From: Ulf Hansson Date: Mon, 19 Apr 2021 14:39:08 +0200 Message-ID: Subject: Re: [PATCH v2 1/2] mmc: block: Issue flush only if allowed To: Avri Altman Cc: linux-mmc , Adrian Hunter , Linux Kernel Mailing List , Brendan Peter Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 18 Apr 2021 at 08:00, Avri Altman wrote: > > 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. Avri, thanks for your patch. Overall this looks good to me. However things are becoming more and more messy in these layers of the mmc core. In particular, I would like us to take advantage of the bus_ops callbacks, when eMMC and/or SD specific features need different implementations. I have posted a patch [1], that moves the eMMC cache flushing into a bus_ops callback. Would you mind rebasing this series on top of that? Kind regards Uffe [1] https://patchwork.kernel.org/project/linux-mmc/patch/20210419122943.68234-1-ulf.hansson@linaro.org/ > > 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 | 7 +++++++ > drivers/mmc/core/mmc_ops.c | 4 +--- > drivers/mmc/core/mmc_ops.h | 5 +++++ > 3 files changed, 13 insertions(+), 3 deletions(-) > > diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c > index fe5892d30778..6800feb70c92 100644 > --- a/drivers/mmc/core/block.c > +++ b/drivers/mmc/core/block.c > @@ -1476,6 +1476,11 @@ 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)) { > + blk_mq_end_request(req, BLK_STS_OK); > + return -EPERM; > + } > + > mrq->cmd->opcode = MMC_SWITCH; > mrq->cmd->arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | > (EXT_CSD_FLUSH_CACHE << 16) | > @@ -2226,6 +2231,8 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req) > switch (req_op(req)) { > case REQ_OP_FLUSH: > ret = mmc_blk_cqe_issue_flush(mq, req); > + if (ret == -EPERM) > + return MMC_REQ_FINISHED; > break; > case REQ_OP_READ: > case REQ_OP_WRITE: > diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c > index f413474f0f80..9c2a665be034 100644 > --- a/drivers/mmc/core/mmc_ops.c > +++ b/drivers/mmc/core/mmc_ops.c > @@ -967,9 +967,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 >