Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp26837pxy; Thu, 6 May 2021 19:21:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkuHuPBWSui/aSnRjB5P7BNeMYjO/9AaiKtzwqMa1zic8WitqvePjynltvCBjEw6UAw6bi X-Received: by 2002:a17:902:ec87:b029:ee:910d:acf5 with SMTP id x7-20020a170902ec87b02900ee910dacf5mr7645928plg.66.1620354096406; Thu, 06 May 2021 19:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620354096; cv=none; d=google.com; s=arc-20160816; b=Rc6q1XW45JH8X+/eKm3dse6MqpEHM2X+aV4EAOjN0tKB+0Q9YhAxYNsEG9l8bfKSnp gNj89fdf7RcFp+P0V3lu0GeWzC/j+qmZTflejPxwPorPHIlBuqKxdsc3KHytJE4MsiR+ 8FANEjQNReTvBFL03TDHoc48KKqlYk2pZy72dI9hLllLKzUOMq90xbL/OmWNR9mAiK3+ yaT+LWUOrXuTYjp/3cxnufZeCWdqlJtdOG//PlU6ba2NqQgKVSZZ7WsNys7GvgFl6O6k JrGanVHWm5Lfz5v5+j5nLROjBjRfYhXOAGcpld+QIG5kCyDLS35noJPTLXU3w9uLRVbL wojg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:subject:cc:user-agent:mime-version:date:message-id; bh=pEBd5fdL2cTvmweyhWgoJjvkuCtQFzRHBqlYDsdewKU=; b=NzfH88AdqkRoDhpFOHHWzr1ks62zTEOmb7+SXzfKe4xpsTq8Pd5JO4dZRk79BkkuJ3 +7gflF2vSGIjBvbg3Ic7GxZNY53DQ6kUywJoov8AkWG3/Y87GFfaSgjTZeMTWKyknegv 8KniMppaGCV+Qshsjmnczp8bq991J4kwkLZHcIKAUXUHxeIyzdgpZkTv8OTisybW/VfY g/tdD1pPu/ROlpxwAKP0DYgipDgkrCbZX6PsETVl/QtSED21wYeQRvCy0qbTzk1lMtIc mmmY4v5ZFGklrw0HUj5oRkRCLbIJiQWZFbdUlH0fTAso23OU8YnG2I/PZXvAxSfxzD+V y8nw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y23si4652470pfm.56.2021.05.06.19.21.11; Thu, 06 May 2021 19:21:36 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234137AbhEGBxs (ORCPT + 99 others); Thu, 6 May 2021 21:53:48 -0400 Received: from regular1.263xmail.com ([211.150.70.196]:39754 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231288AbhEGBxr (ORCPT ); Thu, 6 May 2021 21:53:47 -0400 Received: from localhost (unknown [192.168.167.16]) by regular1.263xmail.com (Postfix) with ESMTP id 23DBC1FAB; Fri, 7 May 2021 09:52:47 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-SKE-CHECKED: 1 X-ABS-CHECKED: 1 Received: from [172.16.12.64] (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P31917T139684271351552S1620352363371334_; Fri, 07 May 2021 09:52:45 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: X-RL-SENDER: shawn.lin@rock-chips.com X-SENDER: lintao@rock-chips.com X-LOGIN-NAME: shawn.lin@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-RCPT-COUNT: 10 X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 Message-ID: Date: Fri, 7 May 2021 09:52:43 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Thunderbird/87.0 Cc: shawn.lin@rock-chips.com, Linus Walleij , Wolfram Sang , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 05/11] mmc: core: Enable eMMC sleep commands to use HW busy polling To: Ulf Hansson , linux-mmc@vger.kernel.org, Adrian Hunter References: <20210504161222.101536-1-ulf.hansson@linaro.org> <20210504161222.101536-6-ulf.hansson@linaro.org> From: Shawn Lin In-Reply-To: <20210504161222.101536-6-ulf.hansson@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/5/5 0:12, Ulf Hansson wrote: > After the eMMC sleep command (CMD5) has been sent, the card start signals > busy on the DAT0 line, which can be monitored to understand when it's > allowed to proceed to power off the VCC regulator. > > When MMC_CAP_WAIT_WHILE_BUSY isn't supported by the host the DAT0 line > isn't being monitored for busy completion, but instead we are waiting a > fixed period of time. The time corresponds to the sleep timeout that is > specified in the EXT_CSD register of the eMMC card. This is many cases > suboptimal, as the timeout corresponds to the worst case scenario. > > To improve the situation add support for HW busy polling through the > ->card_busy() host ops, when the host supports this. Reviewed-by: Shawn Lin > > Signed-off-by: Ulf Hansson > --- > drivers/mmc/core/mmc.c | 25 ++++++++++++++++++++----- > 1 file changed, 20 insertions(+), 5 deletions(-) > > diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c > index 63a7bd0b239c..13074aa1f605 100644 > --- a/drivers/mmc/core/mmc.c > +++ b/drivers/mmc/core/mmc.c > @@ -1905,6 +1905,14 @@ static int mmc_can_sleep(struct mmc_card *card) > return card->ext_csd.rev >= 3; > } > > +static int mmc_sleep_busy_cb(void *cb_data, bool *busy) > +{ > + struct mmc_host *host = cb_data; > + > + *busy = host->ops->card_busy(host); > + return 0; > +} > + > static int mmc_sleep(struct mmc_host *host) > { > struct mmc_command cmd = {}; > @@ -1930,13 +1938,20 @@ static int mmc_sleep(struct mmc_host *host) > goto out_release; > > /* > - * If the host does not wait while the card signals busy, then we will > - * will have to wait the sleep/awake timeout. Note, we cannot use the > - * SEND_STATUS command to poll the status because that command (and most > - * others) is invalid while the card sleeps. > + * If the host does not wait while the card signals busy, then we can > + * try to poll, but only if the host supports HW polling, as the > + * SEND_STATUS cmd is not allowed. If we can't poll, then we simply need > + * to wait the sleep/awake timeout. > */ > - if (!use_r1b_resp || !(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) > + if (host->caps & MMC_CAP_WAIT_WHILE_BUSY && use_r1b_resp) > + goto out_release; > + > + if (!host->ops->card_busy) { > mmc_delay(timeout_ms); > + goto out_release; > + } > + > + err = __mmc_poll_for_busy(card, timeout_ms, &mmc_sleep_busy_cb, host); > > out_release: > mmc_retune_release(host); >