Linux-mmc Archive on lore.kernel.org
 help / color / Atom feed
From: Ulf Hansson <ulf.hansson@linaro.org>
To: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
Cc: "linux-mmc@vger.kernel.org" <linux-mmc@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mmc: core: limit probe clock frequency to configured f_max
Date: Thu, 16 Jan 2020 15:07:22 +0100
Message-ID: <CAPDyKFpZWnkK7UmCZ8M4UnM05wR3MQsPrpEjOJuwkKcN2gePSg@mail.gmail.com> (raw)
In-Reply-To: <f471bceaf237d582d746bd289c4c4f3639cb7b45.1577962382.git.mirq-linux@rere.qmqm.pl>

On Thu, 2 Jan 2020 at 11:54, Michał Mirosław <mirq-linux@rere.qmqm.pl> wrote:
>
> Currently MMC core disregards host->f_max during card initialization
> phase. Obey upper boundary for the clock frequency and skip faster
> speeds when they are above the limit.

Is this a hypothetical problem or a real problem?

>
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
>  drivers/mmc/core/core.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index abf8f5eb0a1c..aa54d359dab7 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -2330,7 +2330,13 @@ void mmc_rescan(struct work_struct *work)
>         }
>
>         for (i = 0; i < ARRAY_SIZE(freqs); i++) {
> -               if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min)))
> +               unsigned int freq = freqs[i];
> +               if (freq > host->f_max) {
> +                       if (i + 1 < ARRAY_SIZE(freqs))
> +                               continue;
> +                       freq = host->f_max;

This looks wrong to me. For example, what if f_max = 250KHz and f_min = 50 KHz.

Then we should try with 250KHz, then 200KHz and then 100KHz. This
isn't what the above code does, I think.

Instead it will try with 200KHz and then 100KHz, thus skip 250KHz.

Maybe we should figure out what index of freqs[] to start the loop for
(before actually starting the loop), depending on the value of f_max -
rather than always start at 0.

> +               }
> +               if (!mmc_rescan_try_freq(host, max(freq, host->f_min)))
>                         break;
>                 if (freqs[i] <= host->f_min)
>                         break;
> @@ -2344,7 +2350,7 @@ void mmc_rescan(struct work_struct *work)
>
>  void mmc_start_host(struct mmc_host *host)
>  {
> -       host->f_init = max(freqs[0], host->f_min);
> +       host->f_init = max(min(freqs[0], host->f_max), host->f_min);
>         host->rescan_disable = 0;
>         host->ios.power_mode = MMC_POWER_UNDEFINED;
>
> --
> 2.20.1
>

Kind regards
Uffe

  reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-02 10:54 Michał Mirosław
2020-01-16 14:07 ` Ulf Hansson [this message]
2020-01-17 14:05   ` Michał Mirosław
2020-01-17 15:26     ` Ulf Hansson
2020-01-17 16:14       ` Michał Mirosław
2020-01-20 11:25         ` 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=CAPDyKFpZWnkK7UmCZ8M4UnM05wR3MQsPrpEjOJuwkKcN2gePSg@mail.gmail.com \
    --to=ulf.hansson@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=mirq-linux@rere.qmqm.pl \
    /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

Linux-mmc Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mmc/0 linux-mmc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mmc linux-mmc/ https://lore.kernel.org/linux-mmc \
		linux-mmc@vger.kernel.org
	public-inbox-index linux-mmc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-mmc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git