Skip to content

mmc: Speed up reboot with an absent card #6747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: rpi-6.12.y
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion drivers/mmc/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,16 @@ void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq)
struct mmc_command *cmd;

while (1) {
wait_for_completion(&mrq->completion);
if (!host->rescan_disable)
wait_for_completion(&mrq->completion);

cmd = mrq->cmd;

if (host->rescan_disable) {
cmd->error = -ENOENT;
break;
}

if (!cmd->error || !cmd->retries ||
mmc_card_removed(host->card))
break;
Expand Down Expand Up @@ -619,6 +625,11 @@ EXPORT_SYMBOL(mmc_is_req_done);
*/
void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
{
if (host->rescan_disable) {
mrq->cmd->error = -ENOENT;
return;
}

__mmc_start_req(host, mrq);

if (!mrq->cap_cmd_during_tfr)
Expand Down Expand Up @@ -2265,6 +2276,8 @@ void mmc_rescan(struct work_struct *work)

for (i = 0; i < ARRAY_SIZE(freqs); i++) {
unsigned int freq = freqs[i];
if (host->rescan_disable)
return;
if (freq > host->f_max) {
if (i + 1 < ARRAY_SIZE(freqs))
continue;
Expand Down
3 changes: 3 additions & 0 deletions drivers/mmc/core/mmc_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ int __mmc_poll_for_busy(struct mmc_host *host, unsigned int period_us,

timeout = jiffies + msecs_to_jiffies(timeout_ms) + 1;
do {
if (host->rescan_disable)
return -ENOENT;

/*
* Due to the possibility of being preempted while polling,
* check the expiration time first.
Expand Down
4 changes: 4 additions & 0 deletions drivers/mmc/core/sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
ocr |= R4_18V_PRESENT;

try_again:
if (host->rescan_disable) {
err = -ENOENT;
goto remove;
}
if (!retries) {
pr_warn("%s: Skipping voltage switch\n", mmc_hostname(host));
ocr &= ~R4_18V_PRESENT;
Expand Down
7 changes: 5 additions & 2 deletions drivers/mmc/host/sdhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,8 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,

static bool sdhci_needs_reset(struct sdhci_host *host, struct mmc_request *mrq)
{
if (!mrq)
return false;
return (!(host->flags & SDHCI_DEVICE_DEAD) &&
((mrq->cmd && mrq->cmd->error) ||
(mrq->sbc && mrq->sbc->error) ||
Expand Down Expand Up @@ -1629,6 +1631,7 @@ static void sdhci_finish_data(struct sdhci_host *host)

static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
{
const unsigned long default_timeout_secs = 5;
int flags;
u32 mask;
unsigned long timeout;
Expand Down Expand Up @@ -1704,10 +1707,10 @@ static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
timeout = jiffies;
if (host->data_timeout)
timeout += nsecs_to_jiffies(host->data_timeout);
else if (!cmd->data && cmd->busy_timeout > 9000)
else if (!cmd->data && cmd->busy_timeout > (default_timeout_secs - 1) * 1000)
timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ;
else
timeout += 10 * HZ;
timeout += default_timeout_secs * HZ;
sdhci_mod_timer(host, cmd->mrq, timeout);

if (host->use_external_dma)
Expand Down