All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Ulf Hansson <ulf.hansson@linaro.org>, linux-mmc@vger.kernel.org
Cc: Jaehoon Chung <jh80.chung@samsung.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Chaotian Jing <chaotian.jing@mediatek.com>
Subject: Re: [PATCH 4/4] mmc: core: Don't use ->card_busy() and CMD13 in combination when polling
Date: Fri, 21 Oct 2016 12:19:23 +0300	[thread overview]
Message-ID: <e9e44d6e-f2a6-13f0-4938-3fa1757b40e8@intel.com> (raw)
In-Reply-To: <1476951579-26125-5-git-send-email-ulf.hansson@linaro.org>

On 20/10/16 11:19, Ulf Hansson wrote:
> 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 <ulf.hansson@linaro.org>
> ---
>  drivers/mmc/core/mmc_ops.c | 30 ++++++++++++++----------------
>  1 file changed, 14 insertions(+), 16 deletions(-)
> 
> 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);

I didn't really have time to look at these patches, sorry :-(.  But this
loop looks like it could use a cond_resched()

> +		} 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);
>  }
>  
>  /**
> 


  reply	other threads:[~2016-10-21  9:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161020082027epcas1p47e0913622727117286f7ad026259eb2b@epcas1p4.samsung.com>
2016-10-20  8:19 ` [PATCH 0/4] mmc: core: Clean-up and improve polling code in __mmc_switch() Ulf Hansson
2016-10-20  8:19   ` [PATCH 1/4] mmc: core: Make mmc_switch_status() available for mmc core Ulf Hansson
2016-10-20  8:19   ` [PATCH 2/4] mmc: core: Clarify code which deals with polling in __mmc_switch() Ulf Hansson
2016-10-20  8:19   ` [PATCH 3/4] mmc: core: Factor out code related to " Ulf Hansson
2016-10-20  8:19   ` [PATCH 4/4] mmc: core: Don't use ->card_busy() and CMD13 in combination when polling Ulf Hansson
2016-10-21  9:19     ` Adrian Hunter [this message]
2016-10-25  8:45       ` Ulf Hansson
2016-10-25 10:58         ` Adrian Hunter
2016-10-24  7:49     ` Linus Walleij
2016-10-25  8:44       ` Ulf Hansson
2016-10-21  7:49   ` [PATCH 0/4] mmc: core: Clean-up and improve polling code in __mmc_switch() Jaehoon Chung
2016-10-21  8:22     ` Ulf Hansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e9e44d6e-f2a6-13f0-4938-3fa1757b40e8@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=chaotian.jing@mediatek.com \
    --cc=jh80.chung@samsung.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.