All of lore.kernel.org
 help / color / mirror / Atom feed
From: Haijun Zhang <Haijun.Zhang@freescale.com>
To: linux-mmc@vger.kernel.org
Cc: Haijun Zhang <Haijun.Zhang@freescale.com>,
	Jerry Huang <Chang-Ming.Huang@freescale.com>,
	Anton Vorontsov <cbouatmailru@gmail.com>
Subject: [PATCH 2/2] Powerpc/eSDHC: Add limit to data and erase timeout value calculation
Date: Mon, 19 Nov 2012 11:38:29 +0800	[thread overview]
Message-ID: <1353296310-10786-2-git-send-email-Haijun.Zhang@freescale.com> (raw)
In-Reply-To: <1353296310-10786-1-git-send-email-Haijun.Zhang@freescale.com>

Some cards apply too larg timeout value for host to response,
So limit the maximum data transfer timeout value and maximum erase
timeout value to aviod timeout issue.

Signed-off-by: Haijun Zhang <Haijun.Zhang@freescale.com>
Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
---
changes for v2:
	- Add limit to data and erase timeout value calculation

 drivers/mmc/core/core.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 893144e..ed5744b 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -636,6 +636,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;
 
 	/*
@@ -721,6 +722,10 @@ 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 < div_u64(data->timeout_ns, 1000000))
+		data->timeout_ns = (u64)host->max_discard_to * 1000000;
 }
 EXPORT_SYMBOL(mmc_set_data_timeout);
 
@@ -1880,7 +1885,7 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card,
 		return 0;
 
 	if (qty == 1)
-		return 1;
+		return 1 << card->erase_shift;
 
 	/* Convert qty to sectors */
 	if (card->erase_shift)
@@ -1898,16 +1903,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) {
+		if (mmc_card_sd(card))
+			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;
+	}
 
 	max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG);
 	if (mmc_can_trim(card)) {
-- 
1.7.0.4



  reply	other threads:[~2012-11-19  3:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-19  3:38 [PATCH] Powerpc eSDHC: Use u64 to calculate the timeout value to avoid overflow Haijun Zhang
2012-11-19  3:38 ` Haijun Zhang [this message]
2012-11-19  5:04   ` [PATCH 2/2] Powerpc/eSDHC: Add limit to data and erase timeout value calculation Anton Vorontsov
2012-11-19  5:23     ` Zhang Haijun-B42677
2012-11-19  5:33       ` Anton Vorontsov
2012-11-19  5:57         ` Zhang Haijun-B42677
2012-11-19  3:38 ` [PATCH 1/2 v2] Powerpc/eSDHC: Calculate the applicable mmc erase timeout value Haijun Zhang
2012-11-19  5:02 ` [PATCH] Powerpc eSDHC: Use u64 to calculate the timeout value to avoid overflow Anton Vorontsov

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=1353296310-10786-2-git-send-email-Haijun.Zhang@freescale.com \
    --to=haijun.zhang@freescale.com \
    --cc=Chang-Ming.Huang@freescale.com \
    --cc=cbouatmailru@gmail.com \
    --cc=linux-mmc@vger.kernel.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.