Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: core: Respect host's max_busy_timeout when sending sleep cmd

When sending the sleep command for host drivers supporting
MMC_CAP_WAIT_WHILE_BUSY, we need to confirm that max_busy_timeout is
big enough comparing to the sleep timeout specified from card's
EXT_CSD. If this isn't case, we use a R1 response instead of R1B and
fallback to use a delay instead.

Do note that a max_busy_timeout set to zero by the host, is interpreted
as it can cope with whatever timeout the mmc core provides it with.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Chris Ball <chris@printf.net>

authored by

Ulf Hansson and committed by
Chris Ball
cb962e04 57de31f6

+16 -3
+16 -3
drivers/mmc/core/mmc.c
··· 1358 1358 { 1359 1359 struct mmc_command cmd = {0}; 1360 1360 struct mmc_card *card = host->card; 1361 + unsigned int timeout_ms = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000); 1361 1362 int err; 1362 1363 1363 1364 err = mmc_deselect_cards(host); ··· 1369 1368 cmd.arg = card->rca << 16; 1370 1369 cmd.arg |= 1 << 15; 1371 1370 1372 - cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 1371 + /* 1372 + * If the max_busy_timeout of the host is specified, validate it against 1373 + * the sleep cmd timeout. A failure means we need to prevent the host 1374 + * from doing hw busy detection, which is done by converting to a R1 1375 + * response instead of a R1B. 1376 + */ 1377 + if (host->max_busy_timeout && (timeout_ms > host->max_busy_timeout)) { 1378 + cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 1379 + } else { 1380 + cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 1381 + cmd.busy_timeout = timeout_ms; 1382 + } 1383 + 1373 1384 err = mmc_wait_for_cmd(host, &cmd, 0); 1374 1385 if (err) 1375 1386 return err; ··· 1392 1379 * SEND_STATUS command to poll the status because that command (and most 1393 1380 * others) is invalid while the card sleeps. 1394 1381 */ 1395 - if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) 1396 - mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000)); 1382 + if (!cmd.busy_timeout || !(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) 1383 + mmc_delay(timeout_ms); 1397 1384 1398 1385 return err; 1399 1386 }