From: Zhang Haijun <b42677@freescale.com>
To: Haijun Zhang <Haijun.Zhang@freescale.com>, linux-mmc@vger.kernel.org
Cc: cbouatmailru@gmail.com, cjb@laptop.org, scottwood@freescale.com,
X.Xie@freescale.com, ulf.hansson@linaro.org
Subject: Re: [PATCH 1/5] mmc:core: Add restrictions for data transfer and card ease
Date: Mon, 21 Oct 2013 17:18:25 +0800 [thread overview]
Message-ID: <5264F161.5010203@freescale.com> (raw)
In-Reply-To: <1380010339-25446-1-git-send-email-Haijun.Zhang@freescale.com>
Hi, all
Could any one help review this patch set for me?
Thanks in advance.
于 2013/9/24 16:12, Haijun Zhang 写道:
> At 50 Mhz SD_CLK period,
> the max timeout value = 2^27 * SD_CLK period ~= 2.69 sec.
>
> If max_discard_to was not designed, for mmc card preferred erase
> size should be used, for sd card just return UINT_MAX. Also add
> limit for data transfer, Use max_discard_to as max data timeout value
> to avoid timeout error in case data timeout was larger than
> 2.69 sec.
>
> For some crappy cards, the timeout value calculate from card was
> larger than UINT_MAX, in this case the timeout value write into
> register was not expected.
>
> This patch can reduce I/O error due to large timeout value for
> erase(CMD38) and write(CMD25) for some crappy cards.
>
> Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
> ---
> drivers/mmc/core/core.c | 45 ++++++++++++++++++++++++++++++---------------
> 1 file changed, 30 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index bf18b6b..b429baa 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -757,6 +757,7 @@ EXPORT_SYMBOL(mmc_read_bkops_status);
> */
> void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
> {
> + struct mmc_host *host = card->host;
> unsigned int mult;
>
> /*
> @@ -780,7 +781,12 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
> if (data->flags & MMC_DATA_WRITE)
> mult <<= card->csd.r2w_factor;
>
> - data->timeout_ns = card->csd.tacc_ns * mult;
> + /* Avoid over flow for some crappy cards. */
> + if ((UINT_MAX / mult) < card->csd.tacc_ns)
> + data->timeout_ns = UINT_MAX;
> + else
> + data->timeout_ns = card->csd.tacc_ns * mult;
> +
> data->timeout_clks = card->csd.tacc_clks * mult;
>
> /*
> @@ -842,6 +848,11 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
> data->timeout_ns = 100000000; /* 100ms */
> }
> }
> +
> + if (host->max_discard_to &&
> + (host->max_discard_to <
> + (data->timeout_ns / 1000000)))
> + data->timeout_ns = host->max_discard_to * 1000000;
> }
> EXPORT_SYMBOL(mmc_set_data_timeout);
>
> @@ -1816,11 +1827,14 @@ static unsigned int mmc_mmc_erase_timeout(struct mmc_card *card,
> unsigned int timeout_clks = card->csd.tacc_clks * mult;
> unsigned int timeout_us;
>
> - /* Avoid overflow: e.g. tacc_ns=80000000 mult=1280 */
> - if (card->csd.tacc_ns < 1000000)
> - timeout_us = (card->csd.tacc_ns * mult) / 1000;
> - else
> + /*
> + * Avoid over flow for some crappy cards.
> + * e.g. tacc_ns=80000000 mult=1280
> + */
> + if ((UINT_MAX / mult) < card->csd.tacc_ns)
> timeout_us = (card->csd.tacc_ns / 1000) * mult;
> + else
> + timeout_us = (card->csd.tacc_ns * mult) / 1000;
>
> /*
> * ios.clock is only a target. The real clock rate might be
> @@ -2185,16 +2199,17 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
> struct mmc_host *host = card->host;
> unsigned int max_discard, max_trim;
>
> - if (!host->max_discard_to)
> - return UINT_MAX;
> -
> - /*
> - * Without erase_group_def set, MMC erase timeout depends on clock
> - * frequence which can change. In that case, the best choice is
> - * just the preferred erase size.
> - */
> - if (mmc_card_mmc(card) && !(card->ext_csd.erase_group_def & 1))
> - return card->pref_erase;
> + if (!host->max_discard_to) {
> + /*
> + * Without erase_group_def set, MMC erase timeout depends
> + * on clock frequence which can change. In that case, the
> + * best choice is just the preferred erase size.
> + */
> + if (mmc_card_mmc(card) && !(card->ext_csd.erase_group_def & 1))
> + return card->pref_erase;
> + else
> + return UINT_MAX;
> + }
>
> max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG);
> if (mmc_can_trim(card)) {
--
Thanks & Regards
Haijun.
prev parent reply other threads:[~2013-10-21 9:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-24 8:12 [PATCH 1/5] mmc:core: Add restrictions for data transfer and card ease Haijun Zhang
2013-09-24 8:12 ` [PATCH 2/5] mmc:sdhc: Calculate timeout_clk from actual sd clock Haijun Zhang
2013-09-24 8:12 ` [PATCH 3/5] mmc:esdhc: Update timeout clock according to actual clock Haijun Zhang
2013-09-24 8:12 ` [PATCH 4/5] mmc:esdhc: Workaround about clock glitch issue on eSDHC host Haijun Zhang
2013-09-24 8:12 ` [PATCH 5/5] mmc:esdhc: Avoid writting to power register Haijun Zhang
2013-10-21 9:18 ` Zhang Haijun [this message]
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=5264F161.5010203@freescale.com \
--to=b42677@freescale.com \
--cc=Haijun.Zhang@freescale.com \
--cc=X.Xie@freescale.com \
--cc=cbouatmailru@gmail.com \
--cc=cjb@laptop.org \
--cc=linux-mmc@vger.kernel.org \
--cc=scottwood@freescale.com \
--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.