From patchwork Tue May 4 16:12:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 430882 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936445jao; Tue, 4 May 2021 09:12:43 -0700 (PDT) X-Received: by 2002:a2e:b5bc:: with SMTP id f28mr555ljn.210.1620144763715; Tue, 04 May 2021 09:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144763; cv=none; d=google.com; s=arc-20160816; b=DIGmKmbJxoGHvT9ORZ2eV7/AoT2u8JAwLyPyH5MjtMeMf2XBnclWStEja0JkfZllJZ wp2nzOMtPmoNSvt4j+Gr6Iy4aJBKSHvb6EeTSKsIGPRQW25O29fnqX/5G0TBTmd1r12O pX/osDCYm5vXOTbgrp60e5AQcPFFtDoVYeT08Rs1eUl2ck205z9v8M+NyeioE8Gg4t59 Tc8NSLCLTelZlUJYbmwhztAtMNJrc4eMhtVH57XI7bkAkFgUY7sW57txb0aBrsgaQwS8 YOkFyDHMHN9sFFLDAnfi7t0hpaVXZyBtyBDr4UYCF52bM/a69EqF+spgk1yDh0Q51mbG NRQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=BD0REsdi9mYrsTQHgnQYm8ynmTMvDhWbCRyzYdtenaE=; b=YN3Js3x7fp/J14ZiuDmhU6um+tyc8gvmEFzrHC1KkvFsE0oFBt6Qsi44ht5cSFPqL2 ZF+bU/ajt9c/+K3E9YSoy8j0y98SoBCqx6b1DaCgC9gPrCplLRLdjJLhWv01GL508i2r ZihyYCBa1pdrdPn8P/AVjFEo2SkhKGjTxq2Z4rv9awNIPj6X+h0/ppxz/H6HkHk/++XP jFoq9tSG1tyGlmYeTE1Lnj2mXjXB6uSx+gY3l/CktFneZk/np1/tRns0rvZFdAJ5L2tz ZVHbftZFIzGbCdVsR/kWWc6vIZuNXNhDCyu6v66n1+ji7OSjSVSXTxsiHrPh3YRb/nxs eD9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BNrJU8ET; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id k12sor592204lfo.112.2021.05.04.09.12.43 for (Google Transport Security); Tue, 04 May 2021 09:12:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BNrJU8ET; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BD0REsdi9mYrsTQHgnQYm8ynmTMvDhWbCRyzYdtenaE=; b=BNrJU8ETwTzMQmDoewcwRrwdt+JF/8bPFkNqC9iSYX8GmcOdxoZUPWw9E4k0cnGKvk 77PhDK128+Z1d73zP2zPsDGLqcOZA04MD5Ys3wFNpOmsNZv1z0Yak4clljxF8NwEiVdY y93x/3Sx8ITu7wIKkkWw5t/QHsdQzwokdnLWsU4akPfRIFxjPS6u6rNGB9xbC6z4Rhvi PdxHhC34fXzWlJpQGf92/0W5QoV76LROJ3y3ExKR0XPlE2ByVMXKdaclarn5RP7OSIb6 5vrWZawduBZ9kpPE+YYKSt5n9MKaPfD65yTIMiZvkIGJb9mEJhqntqAbw9r+PTdPsM1i mtAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BD0REsdi9mYrsTQHgnQYm8ynmTMvDhWbCRyzYdtenaE=; b=kfRlMk+lF9wwhTFQeNiTkzAobyWQUentn5fBRycakVpm7v7s+fR/8m0Dco6X9nWJ2W 5BZVcmyjuhbfgJtl0u0PTHXRVom4cUsqbSkQXamOlKgIcpBJKM5e7Dv73eoLFfO1fOU+ ApnLVY5pNPpc0FwWgHQ+5+GgtmlTT83jrxkD/rukUiUORGqusE0HDP1gy/SOtJQ8hPjC CjjPVmjhxpTLvVxc9fXsBGCi54wXWvTc2RKYFhneOKHcNsWWRygTObh90mEmVTJD0q3T G77FaxY+nOMBu1nOva5q8sZFOOcNkJ1WAUqmKRppK8W+7VF/ZGoeBIb9OcHvmuCTBZKZ pwgA== X-Gm-Message-State: AOAM532Wz17j2zFEeNz/XdYC5OEQhwZ/8sLWYn/GUSjFEPdahx390vxi Li/qADpnbjsMIbVrxDe+cA+sQyw9 X-Google-Smtp-Source: ABdhPJzTWescUDGeNdcqNOKmn/4NYKWiyZROmOnTzqAYSbKve6znLgTJKGetZjhuqJS77CByg7cxeQ== X-Received: by 2002:a19:48d7:: with SMTP id v206mr17301695lfa.629.1620144763115; Tue, 04 May 2021 09:12:43 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:41 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/11] mmc: core: Enable eMMC sleep commands to use HW busy polling Date: Tue, 4 May 2021 18:12:16 +0200 Message-Id: <20210504161222.101536-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 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. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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);