aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc/core/core.c')
-rw-r--r--drivers/mmc/core/core.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index e55cde6d436d..59b452d5dc81 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -58,6 +58,9 @@
58 */ 58 */
59#define MMC_BKOPS_MAX_TIMEOUT (4 * 60 * 1000) /* max time to wait in ms */ 59#define MMC_BKOPS_MAX_TIMEOUT (4 * 60 * 1000) /* max time to wait in ms */
60 60
61/* The max erase timeout, used when host->max_busy_timeout isn't specified */
62#define MMC_ERASE_TIMEOUT_MS (60 * 1000) /* 60 s */
63
61static const unsigned freqs[] = { 400000, 300000, 200000, 100000 }; 64static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };
62 65
63/* 66/*
@@ -2352,6 +2355,8 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card,
2352 struct mmc_host *host = card->host; 2355 struct mmc_host *host = card->host;
2353 unsigned int max_discard, x, y, qty = 0, max_qty, min_qty, timeout; 2356 unsigned int max_discard, x, y, qty = 0, max_qty, min_qty, timeout;
2354 unsigned int last_timeout = 0; 2357 unsigned int last_timeout = 0;
2358 unsigned int max_busy_timeout = host->max_busy_timeout ?
2359 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS;
2355 2360
2356 if (card->erase_shift) { 2361 if (card->erase_shift) {
2357 max_qty = UINT_MAX >> card->erase_shift; 2362 max_qty = UINT_MAX >> card->erase_shift;
@@ -2374,15 +2379,15 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card,
2374 * matter what size of 'host->max_busy_timeout', but if the 2379 * matter what size of 'host->max_busy_timeout', but if the
2375 * 'host->max_busy_timeout' is large enough for more discard sectors, 2380 * 'host->max_busy_timeout' is large enough for more discard sectors,
2376 * then we can continue to increase the max discard sectors until we 2381 * then we can continue to increase the max discard sectors until we
2377 * get a balance value. 2382 * get a balance value. In cases when the 'host->max_busy_timeout'
2383 * isn't specified, use the default max erase timeout.
2378 */ 2384 */
2379 do { 2385 do {
2380 y = 0; 2386 y = 0;
2381 for (x = 1; x && x <= max_qty && max_qty - x >= qty; x <<= 1) { 2387 for (x = 1; x && x <= max_qty && max_qty - x >= qty; x <<= 1) {
2382 timeout = mmc_erase_timeout(card, arg, qty + x); 2388 timeout = mmc_erase_timeout(card, arg, qty + x);
2383 2389
2384 if (qty + x > min_qty && 2390 if (qty + x > min_qty && timeout > max_busy_timeout)
2385 timeout > host->max_busy_timeout)
2386 break; 2391 break;
2387 2392
2388 if (timeout < last_timeout) 2393 if (timeout < last_timeout)
@@ -2427,9 +2432,6 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
2427 struct mmc_host *host = card->host; 2432 struct mmc_host *host = card->host;
2428 unsigned int max_discard, max_trim; 2433 unsigned int max_discard, max_trim;
2429 2434
2430 if (!host->max_busy_timeout)
2431 return UINT_MAX;
2432
2433 /* 2435 /*
2434 * Without erase_group_def set, MMC erase timeout depends on clock 2436 * Without erase_group_def set, MMC erase timeout depends on clock
2435 * frequence which can change. In that case, the best choice is 2437 * frequence which can change. In that case, the best choice is
@@ -2447,7 +2449,8 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
2447 max_discard = 0; 2449 max_discard = 0;
2448 } 2450 }
2449 pr_debug("%s: calculated max. discard sectors %u for timeout %u ms\n", 2451 pr_debug("%s: calculated max. discard sectors %u for timeout %u ms\n",
2450 mmc_hostname(host), max_discard, host->max_busy_timeout); 2452 mmc_hostname(host), max_discard, host->max_busy_timeout ?
2453 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS);
2451 return max_discard; 2454 return max_discard;
2452} 2455}
2453EXPORT_SYMBOL(mmc_calc_max_discard); 2456EXPORT_SYMBOL(mmc_calc_max_discard);