From patchwork Thu Oct 20 08:19:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 78442 Delivered-To: patches@linaro.org Received: by 10.140.97.247 with SMTP id m110csp657241qge; Thu, 20 Oct 2016 01:19:59 -0700 (PDT) X-Received: by 10.25.31.199 with SMTP id f190mr9859368lff.49.1476951599484; Thu, 20 Oct 2016 01:19:59 -0700 (PDT) Return-Path: Received: from mail-lf0-x22b.google.com (mail-lf0-x22b.google.com. [2a00:1450:4010:c07::22b]) by mx.google.com with ESMTPS id h68si5896839lfi.343.2016.10.20.01.19.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Oct 2016 01:19:59 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22b as permitted sender) client-ip=2a00:1450:4010:c07::22b; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22b as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x22b.google.com with SMTP id b81so71607797lfe.1 for ; Thu, 20 Oct 2016 01:19:59 -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; bh=bsOkauVCEwIgrQ5ty9mAniHXMh7Qs7hqHBMN4VtFxG4=; b=fmbT8GGzpu0vCtY+wMZbOZxt1RL0VbSV9CmB5cn4A5dqwO0Ooeh1WrqLxmaoKxdplH ORt8v6aus6rJVodWWIFhNhmuevxDfY75lLzxjwiJVoZwK79dvBjMydnylnnwVCCQO1fa 4ixrPpvyUd9Em3weY5jspN/yaLb19JOfQO8Dc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bsOkauVCEwIgrQ5ty9mAniHXMh7Qs7hqHBMN4VtFxG4=; b=We01a8ZPhep+bnI0USywsuAMqm8aoKSvz7gnRUjTFe/8sX5HijoCZVFAmggof/zqRU cu2Slh0D98UiCbi4Mlmrfzt273ob5qnyVsrVF7LjVi4IDM3lGfomcSZhQtryIdlUDvgS 81s3xUfUEDexyc9XWJSqez5c2fdmPNPtYIL/Jm6zlVTkJGXfNOzfbLB1ZUfym0VNon4h EYUReCH7Tz/XtT5MB3cTmF40YSfasFz65aqUddDFVPlk5NTOFxQ8Z0EQFtF1eCfcgz9+ +OnQ9iB00lZkvLOLZGRGDx0dlCYVPOoV/JccWXcVK7s7LbcKphfpWIs1mv8TzxuVAqQ5 bnsQ== X-Gm-Message-State: AA6/9RkgzhYNSUUs0zph4txet8wraK1s/iMmw/YchdgQc+pb4Ol4W14npApX0PMUVkYb7gxtc5I= X-Received: by 10.25.38.149 with SMTP id m143mr9840788lfm.107.1476951598981; Thu, 20 Oct 2016 01:19:58 -0700 (PDT) Return-Path: Received: from uffe-Latitude-E6430s.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id h7sm11672584ljh.21.2016.10.20.01.19.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Oct 2016 01:19:57 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung , Adrian Hunter , Linus Walleij , Chaotian Jing Subject: [PATCH 4/4] mmc: core: Don't use ->card_busy() and CMD13 in combination when polling Date: Thu, 20 Oct 2016 10:19:39 +0200 Message-Id: <1476951579-26125-5-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1476951579-26125-1-git-send-email-ulf.hansson@linaro.org> References: <1476951579-26125-1-git-send-email-ulf.hansson@linaro.org> When polling for busy after sending a MMC_SWITCH command, both the optional ->card_busy() callback and CMD13 are being used in conjunction. This doesn't make sense. Instead it's more reasonable to rely solely on the ->card_busy() callback when it exists. Let's change that and instead use the CMD13 as a fall-back. In this way we avoid sending CMD13, unless it's really needed. Within this context, let's also take the opportunity to make some additional clean-ups and clarifications to the related code. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) -- 1.9.1 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index a84a880..481bbdb 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -495,34 +495,32 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, timeout = jiffies + msecs_to_jiffies(timeout_ms) + 1; do { /* - * Due to the possibility of being preempted after - * sending the status command, check the expiration - * time first. + * Due to the possibility of being preempted while polling, + * check the expiration time first. */ expired = time_after(jiffies, timeout); - if (send_status) { + + if (host->ops->card_busy) { + busy = host->ops->card_busy(host); + } else { err = __mmc_send_status(card, &status, ignore_crc); if (err) return err; - } - if (host->ops->card_busy) { - if (!host->ops->card_busy(host)) - break; - busy = true; + busy = R1_CURRENT_STATE(status) == R1_STATE_PRG; } - /* Timeout if the device never leaves the program state. */ - if (expired && - (R1_CURRENT_STATE(status) == R1_STATE_PRG || busy)) { - pr_err("%s: Card stuck in programming state! %s\n", + /* Timeout if the device still remains busy. */ + if (expired && busy) { + pr_err("%s: Card stuck being busy! %s\n", mmc_hostname(host), __func__); return -ETIMEDOUT; } - } while (R1_CURRENT_STATE(status) == R1_STATE_PRG || busy); + } while (busy); - err = mmc_switch_status_error(host, status); + if (host->ops->card_busy && send_status) + return mmc_switch_status(card); - return err; + return mmc_switch_status_error(host, status); } /**