Skip to content

Commit 878e200

Browse files
Ulf Hanssoncjb
authored andcommitted
mmc: core: Do not poll for busy with status cmd for all switch cmds
Some switch operations like poweroff notify, shall according to the spec not be followed by any other new commands. For these cases and when the host does'nt support MMC_CAP_WAIT_WHILE_BUSY, we must not send status commands to poll for busy detection. Instead wait for the stated timeout from the EXT_CSD before completing the request. Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Cc: Jaehoon Chung <jh80.chung@samsung.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent d052068 commit 878e200

4 files changed

Lines changed: 24 additions & 10 deletions

File tree

‎drivers/mmc/core/core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
301301
}
302302

303303
err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
304-
EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal);
304+
EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal, true);
305305
if (err) {
306306
pr_warn("%s: Error %d starting bkops\n",
307307
mmc_hostname(card->host), err);

‎drivers/mmc/core/mmc.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,9 +1404,9 @@ static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type)
14041404
if (notify_type == EXT_CSD_POWER_OFF_LONG)
14051405
timeout = card->ext_csd.power_off_longtime;
14061406

1407-
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1408-
EXT_CSD_POWER_OFF_NOTIFICATION,
1409-
notify_type, timeout);
1407+
err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1408+
EXT_CSD_POWER_OFF_NOTIFICATION,
1409+
notify_type, timeout, true, false);
14101410
if (err)
14111411
pr_err("%s: Power Off Notification timed out, %u\n",
14121412
mmc_hostname(card->host), timeout);

‎drivers/mmc/core/mmc_ops.c‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,12 @@ int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
404404
* @timeout_ms: timeout (ms) for operation performed by register write,
405405
* timeout of zero implies maximum possible timeout
406406
* @use_busy_signal: use the busy signal as response type
407+
* @send_status: send status cmd to poll for busy
407408
*
408409
* Modifies the EXT_CSD register for selected card.
409410
*/
410411
int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
411-
unsigned int timeout_ms, bool use_busy_signal)
412+
unsigned int timeout_ms, bool use_busy_signal, bool send_status)
412413
{
413414
int err;
414415
struct mmc_command cmd = {0};
@@ -454,14 +455,26 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
454455

455456
timeout = jiffies + msecs_to_jiffies(MMC_OPS_TIMEOUT_MS);
456457
do {
457-
err = __mmc_send_status(card, &status, ignore_crc);
458-
if (err)
459-
return err;
458+
if (send_status) {
459+
err = __mmc_send_status(card, &status, ignore_crc);
460+
if (err)
461+
return err;
462+
}
460463
if (card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
461464
break;
462465
if (mmc_host_is_spi(card->host))
463466
break;
464467

468+
/*
469+
* We are not allowed to issue a status command and the host
470+
* does'nt support MMC_CAP_WAIT_WHILE_BUSY, then we can only
471+
* rely on waiting for the stated timeout to be sufficient.
472+
*/
473+
if (!send_status) {
474+
mmc_delay(timeout_ms);
475+
return 0;
476+
}
477+
465478
/* Timeout if the device never leaves the program state. */
466479
if (time_after(jiffies, timeout)) {
467480
pr_err("%s: Card stuck in programming state! %s\n",
@@ -488,7 +501,7 @@ EXPORT_SYMBOL_GPL(__mmc_switch);
488501
int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
489502
unsigned int timeout_ms)
490503
{
491-
return __mmc_switch(card, set, index, value, timeout_ms, true);
504+
return __mmc_switch(card, set, index, value, timeout_ms, true, true);
492505
}
493506
EXPORT_SYMBOL_GPL(mmc_switch);
494507

‎include/linux/mmc/core.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ extern int mmc_app_cmd(struct mmc_host *, struct mmc_card *);
151151
extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
152152
struct mmc_command *, int);
153153
extern void mmc_start_bkops(struct mmc_card *card, bool from_exception);
154-
extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool);
154+
extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool,
155+
bool);
155156
extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
156157
extern int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd);
157158

0 commit comments

Comments
 (0)