mmc: allow upper layers to know immediately if card has been removed
Add a function mmc_detect_card_removed() which upper layers can use to determine immediately if a card has been removed. This function should be called after an I/O request fails so that all queued I/O requests can be errored out immediately instead of waiting for the card device to be removed. Change-Id: Iad4806319b6ad67048674adfdd919458186521d6 Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: Sujit Reddy Thumma <sthumma@codeaurora.org> Signed-off-by: Chris Ball <cjb@laptop.org> [sthumma@codeaurora.org: Fixed merge conflicts] Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
This commit is contained in:
committed by
Sujit Reddy Thumma
parent
8eb2874b58
commit
8b581b08ef
@@ -105,7 +105,7 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
|
||||
cmd->retries = 0;
|
||||
}
|
||||
|
||||
if (err && cmd->retries) {
|
||||
if (err && cmd->retries && !mmc_card_removed(host->card)) {
|
||||
pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
|
||||
mmc_hostname(host), cmd->opcode, err);
|
||||
|
||||
@@ -238,6 +238,10 @@ void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
|
||||
|
||||
mrq->done_data = &complete;
|
||||
mrq->done = mmc_wait_done;
|
||||
if (mmc_card_removed(host->card)) {
|
||||
mrq->cmd->error = -ENOMEDIUM;
|
||||
return;
|
||||
}
|
||||
|
||||
mmc_start_request(host, mrq);
|
||||
|
||||
@@ -1250,6 +1254,7 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay)
|
||||
#endif
|
||||
|
||||
wake_lock(&host->detect_wake_lock);
|
||||
host->detect_change = 1;
|
||||
mmc_schedule_delayed_work(&host->detect, delay);
|
||||
}
|
||||
|
||||
@@ -1658,6 +1663,43 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
int _mmc_detect_card_removed(struct mmc_host *host)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((host->caps & MMC_CAP_NONREMOVABLE) || !host->bus_ops->alive)
|
||||
return 0;
|
||||
|
||||
if (!host->card || mmc_card_removed(host->card))
|
||||
return 1;
|
||||
|
||||
ret = host->bus_ops->alive(host);
|
||||
if (ret) {
|
||||
mmc_card_set_removed(host->card);
|
||||
pr_debug("%s: card remove detected\n", mmc_hostname(host));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mmc_detect_card_removed(struct mmc_host *host)
|
||||
{
|
||||
struct mmc_card *card = host->card;
|
||||
|
||||
WARN_ON(!host->claimed);
|
||||
/*
|
||||
* The card will be considered unchanged unless we have been asked to
|
||||
* detect a change or host requires polling to provide card detection.
|
||||
*/
|
||||
if (card && !host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL))
|
||||
return mmc_card_removed(card);
|
||||
|
||||
host->detect_change = 0;
|
||||
|
||||
return _mmc_detect_card_removed(host);
|
||||
}
|
||||
EXPORT_SYMBOL(mmc_detect_card_removed);
|
||||
|
||||
void mmc_rescan(struct work_struct *work)
|
||||
{
|
||||
struct mmc_host *host =
|
||||
@@ -1683,6 +1725,8 @@ void mmc_rescan(struct work_struct *work)
|
||||
if (host->bus_dead)
|
||||
extend_wakelock = 1;
|
||||
|
||||
host->detect_change = 0;
|
||||
|
||||
/*
|
||||
* Let mmc_bus_put() free the bus/bus_ops if we've found that
|
||||
* the card is no longer present.
|
||||
|
||||
@@ -24,6 +24,7 @@ struct mmc_bus_ops {
|
||||
int (*resume)(struct mmc_host *);
|
||||
int (*power_save)(struct mmc_host *);
|
||||
int (*power_restore)(struct mmc_host *);
|
||||
int (*alive)(struct mmc_host *);
|
||||
};
|
||||
|
||||
void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
|
||||
@@ -60,6 +61,8 @@ void mmc_rescan(struct work_struct *work);
|
||||
void mmc_start_host(struct mmc_host *host);
|
||||
void mmc_stop_host(struct mmc_host *host);
|
||||
|
||||
int _mmc_detect_card_removed(struct mmc_host *host);
|
||||
|
||||
int mmc_attach_mmc(struct mmc_host *host);
|
||||
int mmc_attach_sd(struct mmc_host *host);
|
||||
int mmc_attach_sdio(struct mmc_host *host);
|
||||
|
||||
@@ -873,6 +873,14 @@ static void mmc_remove(struct mmc_host *host)
|
||||
mmc_release_host(host);
|
||||
}
|
||||
|
||||
/*
|
||||
* Card detection - card is alive.
|
||||
*/
|
||||
static int mmc_alive(struct mmc_host *host)
|
||||
{
|
||||
return mmc_send_status(host->card, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Card detection callback from host.
|
||||
*/
|
||||
@@ -888,7 +896,7 @@ static void mmc_detect(struct mmc_host *host)
|
||||
/*
|
||||
* Just check if our card has been removed.
|
||||
*/
|
||||
err = mmc_send_status(host->card, NULL);
|
||||
err = _mmc_detect_card_removed(host);
|
||||
|
||||
mmc_release_host(host);
|
||||
|
||||
@@ -992,6 +1000,7 @@ static const struct mmc_bus_ops mmc_ops = {
|
||||
.suspend = NULL,
|
||||
.resume = NULL,
|
||||
.power_restore = mmc_power_restore,
|
||||
.alive = mmc_alive,
|
||||
};
|
||||
|
||||
static const struct mmc_bus_ops mmc_ops_unsafe = {
|
||||
@@ -1002,6 +1011,7 @@ static const struct mmc_bus_ops mmc_ops_unsafe = {
|
||||
.suspend = mmc_suspend,
|
||||
.resume = mmc_resume,
|
||||
.power_restore = mmc_power_restore,
|
||||
.alive = mmc_alive,
|
||||
};
|
||||
|
||||
static void mmc_attach_bus_ops(struct mmc_host *host)
|
||||
|
||||
@@ -1043,6 +1043,14 @@ static void mmc_sd_remove(struct mmc_host *host)
|
||||
mmc_release_host(host);
|
||||
}
|
||||
|
||||
/*
|
||||
* Card detection - card is alive.
|
||||
*/
|
||||
static int mmc_sd_alive(struct mmc_host *host)
|
||||
{
|
||||
return mmc_send_status(host->card, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Card detection callback from host.
|
||||
*/
|
||||
@@ -1063,7 +1071,7 @@ static void mmc_sd_detect(struct mmc_host *host)
|
||||
*/
|
||||
#ifdef CONFIG_MMC_PARANOID_SD_INIT
|
||||
while(retries) {
|
||||
err = mmc_send_status(host->card, NULL);
|
||||
err = _mmc_detect_card_removed(host);
|
||||
if (err) {
|
||||
retries--;
|
||||
udelay(5);
|
||||
@@ -1076,7 +1084,7 @@ static void mmc_sd_detect(struct mmc_host *host)
|
||||
__func__, mmc_hostname(host), err);
|
||||
}
|
||||
#else
|
||||
err = mmc_send_status(host->card, NULL);
|
||||
err = _mmc_detect_card_removed(host);
|
||||
#endif
|
||||
mmc_release_host(host);
|
||||
|
||||
@@ -1163,6 +1171,7 @@ static const struct mmc_bus_ops mmc_sd_ops = {
|
||||
.suspend = NULL,
|
||||
.resume = NULL,
|
||||
.power_restore = mmc_sd_power_restore,
|
||||
.alive = mmc_sd_alive,
|
||||
};
|
||||
|
||||
static const struct mmc_bus_ops mmc_sd_ops_unsafe = {
|
||||
@@ -1171,6 +1180,7 @@ static const struct mmc_bus_ops mmc_sd_ops_unsafe = {
|
||||
.suspend = mmc_sd_suspend,
|
||||
.resume = mmc_sd_resume,
|
||||
.power_restore = mmc_sd_power_restore,
|
||||
.alive = mmc_sd_alive,
|
||||
};
|
||||
|
||||
static void mmc_sd_attach_bus_ops(struct mmc_host *host)
|
||||
|
||||
@@ -581,6 +581,14 @@ static void mmc_sdio_remove(struct mmc_host *host)
|
||||
host->card = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Card detection - card is alive.
|
||||
*/
|
||||
static int mmc_sdio_alive(struct mmc_host *host)
|
||||
{
|
||||
return mmc_select_card(host->card);
|
||||
}
|
||||
|
||||
/*
|
||||
* Card detection callback from host.
|
||||
*/
|
||||
@@ -603,7 +611,7 @@ static void mmc_sdio_detect(struct mmc_host *host)
|
||||
/*
|
||||
* Just check if our card has been removed.
|
||||
*/
|
||||
err = mmc_select_card(host->card);
|
||||
err = _mmc_detect_card_removed(host);
|
||||
|
||||
mmc_release_host(host);
|
||||
|
||||
@@ -783,6 +791,7 @@ static const struct mmc_bus_ops mmc_sdio_ops = {
|
||||
.suspend = mmc_sdio_suspend,
|
||||
.resume = mmc_sdio_resume,
|
||||
.power_restore = mmc_sdio_power_restore,
|
||||
.alive = mmc_sdio_alive,
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -177,6 +177,7 @@ struct mmc_card {
|
||||
#define MMC_STATE_HIGHSPEED_DDR (1<<4) /* card is in high speed mode */
|
||||
#define MMC_STATE_ULTRAHIGHSPEED (1<<5) /* card is in ultra high speed mode */
|
||||
#define MMC_CARD_SDXC (1<<6) /* card is SDXC */
|
||||
#define MMC_CARD_REMOVED (1<<7) /* card has been removed */
|
||||
unsigned int quirks; /* card quirks */
|
||||
#define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */
|
||||
#define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */
|
||||
@@ -314,6 +315,7 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
|
||||
#define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR)
|
||||
#define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
|
||||
#define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
|
||||
#define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED))
|
||||
|
||||
#define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
|
||||
#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
|
||||
@@ -322,6 +324,7 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
|
||||
#define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR)
|
||||
#define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
|
||||
#define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
|
||||
#define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
|
||||
|
||||
/*
|
||||
* Quirk add/remove for MMC products.
|
||||
|
||||
@@ -166,6 +166,8 @@ extern void mmc_release_host(struct mmc_host *host);
|
||||
extern void mmc_do_release_host(struct mmc_host *host);
|
||||
extern int mmc_try_claim_host(struct mmc_host *host);
|
||||
|
||||
extern int mmc_detect_card_removed(struct mmc_host *host);
|
||||
|
||||
/**
|
||||
* mmc_claim_host - exclusively claim a host
|
||||
* @host: mmc host to claim
|
||||
|
||||
@@ -266,6 +266,7 @@ struct mmc_host {
|
||||
|
||||
struct delayed_work detect;
|
||||
struct wake_lock detect_wake_lock;
|
||||
int detect_change; /* card detect flag */
|
||||
|
||||
const struct mmc_bus_ops *bus_ops; /* current bus driver */
|
||||
unsigned int bus_refs; /* reference counter */
|
||||
|
||||
Reference in New Issue
Block a user