From patchwork Thu Jun 8 13:27:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 103387 Delivered-To: patches@linaro.org Received: by 10.140.91.77 with SMTP id y71csp2439500qgd; Thu, 8 Jun 2017 06:27:53 -0700 (PDT) X-Received: by 10.46.9.213 with SMTP id 204mr7693578ljj.120.1496928473801; Thu, 08 Jun 2017 06:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496928473; cv=none; d=google.com; s=arc-20160816; b=FPE7Byg6E88mJNlh424bCDAXX2nywGAANHC2xiUKJvUg3pjSnA/UH0IHnf1uKJLxtI oETRCwpXjSKi2TU/vgUJWWKcPepo1E6Lv0JcydFUihG7QwcYxeGyrMuSPdN4IxOzJ26T 3i+NQF+q1C2/HhAJxhb5SdxHKMumjcQIcSo2PtIpkJVrV+3B4RcSuGIOOrQGjI6phBS+ 98DcDvseRXsZ4tHSLckT9/1Qosj3T08ADqmJS9wJbm4jVUFviY0r2DpHTmcU1WBincc0 +zk9CYj00Yx6lTVQpPOcpbij46WWotjEmJzZ2a7opemf16xpHtieL/yzosGJJveAsPgi Y9Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=PZ3muIOnQn28AMZ2/pTLwJo3cbD5VMUBK2MN9yQ0dCU=; b=uUD+188TkEvj2jsHVTgk+Df+UtVsni3o06lhhQCqci+nWcVCA47uq9jw2xgZ9+CUSm f599yYiFmqIZekgHKW89PNJgpg0GvFj6jmZcJVBZCfhTt771Fdje3gzQ0eUawaayDdTg v+RHDeZ4HPWQBov7rHm2oAd41sLEvN+V60peC7WXADVVuRYxOgXwHFO0jwJviNdjuL0V KZW+3Ncd6b6j1DBQMFsZ23/jk0g1JAdPdYQ1gxDrid1CXKCuQOJf1vk/sw3huRzbTRuG gD8xb2UFAOcf3qSVEWqEYIgqSatxEKz9GYniOnn9MT2bNwbvEohonBaEwlXsbl7oqExn Bjvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::233 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-lf0-x233.google.com (mail-lf0-x233.google.com. [2a00:1450:4010:c07::233]) by mx.google.com with ESMTPS id c135si2545543lfe.407.2017.06.08.06.27.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 06:27:53 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::233 as permitted sender) client-ip=2a00:1450:4010:c07::233; 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::233 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x233.google.com with SMTP id a136so18051956lfa.0 for ; Thu, 08 Jun 2017 06:27:53 -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=PZ3muIOnQn28AMZ2/pTLwJo3cbD5VMUBK2MN9yQ0dCU=; b=TqHPDhDchN5Yc4mywRMTUl1FXWkNbxx/UHz+d88kEGMA9aOKPi6xvvrtOWU1zYhmty Dp8sveA+98ks0Oz9G45rVbvXcWvaAhttJigKSEDZr8fKFTfp5gAWUOGxD5zx4tSt+85W KgFzUtRWFOXXKLK15/dX4QpOKo+OF3qkJ5EHQ= 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; bh=PZ3muIOnQn28AMZ2/pTLwJo3cbD5VMUBK2MN9yQ0dCU=; b=FChTrxZu7ESD0IQZyvC4bgp7ZcboxrZg/SDbOafoIRCVuIqBaz5omF6Qxh9E1WuLVB 6KlNW1zdQW7r6dnnWw4kLLFoRA2dD8kAQYg+f9b4mb36ZdDqlguvfaxv5neWV7FdUFiR HpZM+55S695N5XAKpABLn3C9GA4VZRXX/tb3o1gp+dYanEgPlKfC73Wp/Cj+7elUXAJ6 xwaJejil2CT6HCjIzO0uK59shUNEMvOBENXFpC8Abw4/1AO0bB15wWWCnoeD07MaaKUc 8y6NEFgZFCw5bPhJuVNagy0fxrR7w9ThDeaQabLpufYjXG8j9W3IN08v966iKiqpxTwl 9jag== X-Gm-Message-State: AODbwcCOenm1PJAylUPx7/y6SourhVWDFLPTWV6Io4blybCCjOn+IEYW jkduUVm9vhtlrUGvpHE= X-Received: by 10.25.35.81 with SMTP id j78mr4220352lfj.27.1496928473337; Thu, 08 Jun 2017 06:27:53 -0700 (PDT) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id i8sm1025178ljb.55.2017.06.08.06.27.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jun 2017 06:27:52 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung , Adrian Hunter , Linus Walleij Subject: [PATCH 2/9] mmc: core: Move mmc bkops functions from core.c to mmc_ops.c Date: Thu, 8 Jun 2017 15:27:38 +0200 Message-Id: <1496928465-25004-3-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496928465-25004-1-git-send-email-ulf.hansson@linaro.org> References: <1496928465-25004-1-git-send-email-ulf.hansson@linaro.org> The mmc_start_bkops(), mmc_stop_bkops() and mmc_read_bkops_status() functions are all specific to eMMCs. To make this clear, let's move them from from core.c to mmc_ops.c. While moving them, get rid of MMC_BKOPS_MAX_TIMEOUT (4 min) and use the common default timeout MMC_OPS_TIMEOUT_MS (10 min) instead, as there is no need to have specific default timeout for bkops. Signed-off-by: Ulf Hansson --- drivers/mmc/core/core.c | 118 --------------------------------------------- drivers/mmc/core/mmc_ops.c | 113 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 118 deletions(-) -- 2.7.4 Reviewed-by: Linus Walleij diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index d48be0b..d7c934c 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -53,12 +53,6 @@ /* If the device is not responding */ #define MMC_CORE_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */ -/* - * Background operations can take a long time, depending on the housekeeping - * operations the card has to perform. - */ -#define MMC_BKOPS_MAX_TIMEOUT (4 * 60 * 1000) /* max time to wait in ms */ - /* The max erase timeout, used when host->max_busy_timeout isn't specified */ #define MMC_ERASE_TIMEOUT_MS (60 * 1000) /* 60 s */ @@ -362,73 +356,6 @@ static int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) return 0; } -/** - * mmc_start_bkops - start BKOPS for supported cards - * @card: MMC card to start BKOPS - * @form_exception: A flag to indicate if this function was - * called due to an exception raised by the card - * - * Start background operations whenever requested. - * When the urgent BKOPS bit is set in a R1 command response - * then background operations should be started immediately. -*/ -void mmc_start_bkops(struct mmc_card *card, bool from_exception) -{ - int err; - int timeout; - bool use_busy_signal; - - if (!card->ext_csd.man_bkops_en || mmc_card_doing_bkops(card)) - return; - - err = mmc_read_bkops_status(card); - if (err) { - pr_err("%s: Failed to read bkops status: %d\n", - mmc_hostname(card->host), err); - return; - } - - if (!card->ext_csd.raw_bkops_status) - return; - - if (card->ext_csd.raw_bkops_status < EXT_CSD_BKOPS_LEVEL_2 && - from_exception) - return; - - mmc_claim_host(card->host); - if (card->ext_csd.raw_bkops_status >= EXT_CSD_BKOPS_LEVEL_2) { - timeout = MMC_BKOPS_MAX_TIMEOUT; - use_busy_signal = true; - } else { - timeout = 0; - use_busy_signal = false; - } - - mmc_retune_hold(card->host); - - err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, - EXT_CSD_BKOPS_START, 1, timeout, 0, - use_busy_signal, true, false); - if (err) { - pr_warn("%s: Error %d starting bkops\n", - mmc_hostname(card->host), err); - mmc_retune_release(card->host); - goto out; - } - - /* - * For urgent bkops status (LEVEL_2 and more) - * bkops executed synchronously, otherwise - * the operation is in progress - */ - if (!use_busy_signal) - mmc_card_set_doing_bkops(card); - else - mmc_retune_release(card->host); -out: - mmc_release_host(card->host); -} - /* * mmc_wait_data_done() - done callback for data request * @mrq: done data request @@ -841,51 +768,6 @@ int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries EXPORT_SYMBOL(mmc_wait_for_cmd); /** - * mmc_stop_bkops - stop ongoing BKOPS - * @card: MMC card to check BKOPS - * - * Send HPI command to stop ongoing background operations to - * allow rapid servicing of foreground operations, e.g. read/ - * writes. Wait until the card comes out of the programming state - * to avoid errors in servicing read/write requests. - */ -int mmc_stop_bkops(struct mmc_card *card) -{ - int err = 0; - - err = mmc_interrupt_hpi(card); - - /* - * If err is EINVAL, we can't issue an HPI. - * It should complete the BKOPS. - */ - if (!err || (err == -EINVAL)) { - mmc_card_clr_doing_bkops(card); - mmc_retune_release(card->host); - err = 0; - } - - return err; -} - -int mmc_read_bkops_status(struct mmc_card *card) -{ - int err; - u8 *ext_csd; - - mmc_claim_host(card->host); - err = mmc_get_ext_csd(card, &ext_csd); - mmc_release_host(card->host); - if (err) - return err; - - card->ext_csd.raw_bkops_status = ext_csd[EXT_CSD_BKOPS_STATUS]; - card->ext_csd.raw_exception_status = ext_csd[EXT_CSD_EXP_EVENTS_STATUS]; - kfree(ext_csd); - return 0; -} - -/** * mmc_set_data_timeout - set the timeout for a data command * @data: data phase for command * @card: the MMC card associated with the data transfer diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index ae1fc48..0648fae 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -19,6 +19,7 @@ #include #include "core.h" +#include "card.h" #include "host.h" #include "mmc_ops.h" @@ -845,6 +846,118 @@ int mmc_can_ext_csd(struct mmc_card *card) return (card && card->csd.mmca_vsn > CSD_SPEC_VER_3); } +/** + * mmc_stop_bkops - stop ongoing BKOPS + * @card: MMC card to check BKOPS + * + * Send HPI command to stop ongoing background operations to + * allow rapid servicing of foreground operations, e.g. read/ + * writes. Wait until the card comes out of the programming state + * to avoid errors in servicing read/write requests. + */ +int mmc_stop_bkops(struct mmc_card *card) +{ + int err = 0; + + err = mmc_interrupt_hpi(card); + + /* + * If err is EINVAL, we can't issue an HPI. + * It should complete the BKOPS. + */ + if (!err || (err == -EINVAL)) { + mmc_card_clr_doing_bkops(card); + mmc_retune_release(card->host); + err = 0; + } + + return err; +} + +int mmc_read_bkops_status(struct mmc_card *card) +{ + int err; + u8 *ext_csd; + + mmc_claim_host(card->host); + err = mmc_get_ext_csd(card, &ext_csd); + mmc_release_host(card->host); + if (err) + return err; + + card->ext_csd.raw_bkops_status = ext_csd[EXT_CSD_BKOPS_STATUS]; + card->ext_csd.raw_exception_status = ext_csd[EXT_CSD_EXP_EVENTS_STATUS]; + kfree(ext_csd); + return 0; +} + +/** + * mmc_start_bkops - start BKOPS for supported cards + * @card: MMC card to start BKOPS + * @form_exception: A flag to indicate if this function was + * called due to an exception raised by the card + * + * Start background operations whenever requested. + * When the urgent BKOPS bit is set in a R1 command response + * then background operations should be started immediately. +*/ +void mmc_start_bkops(struct mmc_card *card, bool from_exception) +{ + int err; + int timeout; + bool use_busy_signal; + + if (!card->ext_csd.man_bkops_en || mmc_card_doing_bkops(card)) + return; + + err = mmc_read_bkops_status(card); + if (err) { + pr_err("%s: Failed to read bkops status: %d\n", + mmc_hostname(card->host), err); + return; + } + + if (!card->ext_csd.raw_bkops_status) + return; + + if (card->ext_csd.raw_bkops_status < EXT_CSD_BKOPS_LEVEL_2 && + from_exception) + return; + + mmc_claim_host(card->host); + if (card->ext_csd.raw_bkops_status >= EXT_CSD_BKOPS_LEVEL_2) { + timeout = MMC_OPS_TIMEOUT_MS; + use_busy_signal = true; + } else { + timeout = 0; + use_busy_signal = false; + } + + mmc_retune_hold(card->host); + + err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_BKOPS_START, 1, timeout, 0, + use_busy_signal, true, false); + if (err) { + pr_warn("%s: Error %d starting bkops\n", + mmc_hostname(card->host), err); + mmc_retune_release(card->host); + goto out; + } + + /* + * For urgent bkops status (LEVEL_2 and more) + * bkops executed synchronously, otherwise + * the operation is in progress + */ + if (!use_busy_signal) + mmc_card_set_doing_bkops(card); + else + mmc_retune_release(card->host); +out: + mmc_release_host(card->host); +} + static int mmc_cmdq_switch(struct mmc_card *card, bool enable) { u8 val = enable ? EXT_CSD_CMDQ_MODE_ENABLED : 0;