Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3756405pxy; Tue, 4 May 2021 09:14:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4Pl1ARzSYK53MU0/faAwQ3AR/JbcLQ9hRoph/VIyLAPE5bYrmEWVBIU7tNuj8H36/Nor3 X-Received: by 2002:a17:906:b315:: with SMTP id n21mr22547632ejz.219.1620144877481; Tue, 04 May 2021 09:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144877; cv=none; d=google.com; s=arc-20160816; b=LJqYnpGL++wyQDm1ptCbJ7ELRGXNGkVFgivzh/O3p6J4a/EX0yZ8po7B8sCQ2FTytD kVJYkSIfjAyffGwxVEyfuVhlDJfIEpfNGCvS6GdSZ3pdMKAALxIMv115mCTPD3bOSA1I Ri/K7BUgUel27wlereYDQKRYTmTb4M2WX+wOsi2u/wgZzVJnEFgZNW2GVtSfJXKnk3a0 qYGcB9irdzKYw49lXxQuj/0bvajOwX5dC+wAvYBbL6PDpOsZcDXEFIGqj3973t4vxsbm uvm4YozZ18Bbb/01/xDOFkUfyQ4N9X2QN0a0C8eIds+H1j8kKO5OEhDZcgcKfF3d3oib fRaA== 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 :dkim-signature; bh=BD0REsdi9mYrsTQHgnQYm8ynmTMvDhWbCRyzYdtenaE=; b=zbg3rMU57ZvE1WcqaY8nQ+rhsjUkXFCs5CS7WEdZcwgxOYzPZ2Ss5L1SPTGtybmzj0 CP9AhsWOdCt/k1hRR8dPJR3doK9uEHx3M8apEApGJKzDafp1xtT8/+yD6aB/6xwrlnjy RxEL46K7C4O9xxsNpWqT11Zh68Kp4rBXmoQko+C4P0132N85dVpow1z+9LjZIs9wGZmR hew/L8oB9ZeZH8r1saatHavIJ3/PM+locdLk6fpMZD5CLDR93mA/PZOEWXPQozVeengM lE/2uctnqITgFedQntUIag3/S1FJ1MMgahPcAKlcrgtmaS/7FMqhwwHM1M6fYkj2pQtL 342A== 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 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 r18si7726346edd.372.2021.05.04.09.14.13; Tue, 04 May 2021 09:14:37 -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=BNrJU8ET; 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 S231789AbhEDQNl (ORCPT + 99 others); Tue, 4 May 2021 12:13:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231782AbhEDQNk (ORCPT ); Tue, 4 May 2021 12:13:40 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EDA9C061574 for ; Tue, 4 May 2021 09:12:44 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 12so14038425lfq.13 for ; Tue, 04 May 2021 09:12:44 -0700 (PDT) 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=qoOCrU+I7vWmL5dKT7rebCyBvRzUr1Czz5AogZNOh8waRzTqXRcOk1Qnfe85f9FoSV e+O5BCqISh7HF6xf798SPqs8pnyf1r4gJlgZLQ1JVOG7oaqmlu0SYEWvEo9EKwhwSAMQ 4dLeZwAzTHRjp7QljJopPdACt7EwweR/EpTArY5CFkwbgvL6GTT6dj/kMSIFJoOIzYry 3upDE+Rqoxe24wez8o6hNx6sBQcFdxFXoGZRpfcMzjMo9G2xULkVciihYC/r8KIYDDgB aVgLsEfEi9OuPFrlh3tAChXtM2/fMbym4PtTS5l5oLwIjWAYF0LQBIibNBOWc3EnDmvy 7HtA== X-Gm-Message-State: AOAM533N9tRnSBezevCgP8L8OwFFydPSSiceFavbW/ZPgdRAc7WRRFT9 dp8McjH6KLcmUcYwun+HwWzyp8dURQnYX+KF X-Received: by 2002:a19:48d7:: with SMTP id v206mr17301695lfa.629.1620144763115; Tue, 04 May 2021 09:12:43 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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); -- 2.25.1