mmc: core: Use a default maximum erase timeout
In cases when the host->max_busy_timeout isn't specified, the calculated number of maximum discard sectors defaults to UINT_MAX. This may cause a too long timeout for a discard request. Avoid this by using a default maximum erase timeout of 60s, used when we calculate the maximum number of sectors that are allowed to be discarded per request. Do note that the minimum number of sectors to be discarded is still at least one "preferred erase size". Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Reviewed-by: Shawn Lin <shawn.lin@rock-chips.com>
This commit is contained in:
parent
4ae12588e0
commit
12182affc7
1 changed files with 10 additions and 7 deletions
|
@ -58,6 +58,9 @@
|
|||
*/
|
||||
#define MMC_BKOPS_MAX_TIMEOUT (4 * 60 * 1000) /* max time to wait in ms */
|
||||
|
||||
/* The max erase timeout, used when host->max_busy_timeout isn't specified */
|
||||
#define MMC_ERASE_TIMEOUT_MS (60 * 1000) /* 60 s */
|
||||
|
||||
static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };
|
||||
|
||||
/*
|
||||
|
@ -2352,6 +2355,8 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card,
|
|||
struct mmc_host *host = card->host;
|
||||
unsigned int max_discard, x, y, qty = 0, max_qty, min_qty, timeout;
|
||||
unsigned int last_timeout = 0;
|
||||
unsigned int max_busy_timeout = host->max_busy_timeout ?
|
||||
host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS;
|
||||
|
||||
if (card->erase_shift) {
|
||||
max_qty = UINT_MAX >> card->erase_shift;
|
||||
|
@ -2374,15 +2379,15 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card,
|
|||
* matter what size of 'host->max_busy_timeout', but if the
|
||||
* 'host->max_busy_timeout' is large enough for more discard sectors,
|
||||
* then we can continue to increase the max discard sectors until we
|
||||
* get a balance value.
|
||||
* get a balance value. In cases when the 'host->max_busy_timeout'
|
||||
* isn't specified, use the default max erase timeout.
|
||||
*/
|
||||
do {
|
||||
y = 0;
|
||||
for (x = 1; x && x <= max_qty && max_qty - x >= qty; x <<= 1) {
|
||||
timeout = mmc_erase_timeout(card, arg, qty + x);
|
||||
|
||||
if (qty + x > min_qty &&
|
||||
timeout > host->max_busy_timeout)
|
||||
if (qty + x > min_qty && timeout > max_busy_timeout)
|
||||
break;
|
||||
|
||||
if (timeout < last_timeout)
|
||||
|
@ -2427,9 +2432,6 @@ 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_busy_timeout)
|
||||
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
|
||||
|
@ -2447,7 +2449,8 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
|
|||
max_discard = 0;
|
||||
}
|
||||
pr_debug("%s: calculated max. discard sectors %u for timeout %u ms\n",
|
||||
mmc_hostname(host), max_discard, host->max_busy_timeout);
|
||||
mmc_hostname(host), max_discard, host->max_busy_timeout ?
|
||||
host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS);
|
||||
return max_discard;
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_calc_max_discard);
|
||||
|
|
Loading…
Reference in a new issue