mmc: propagate error codes back from bus drivers' suspend/resume methods
PATCH 92/232 mmc: propagate error codes back from bus drivers' suspend/resume methods
From: Nicolas Pitre <[email protected]>
Especially for SDIO drivers which may have special conditions/errors to report, it is a good thing to relay the returned error code back to upper layers.
This also allows for the rationalization of the resume path where code to "remove" a no-longer-existing or replaced card was duplicated into the MMC, SD and SDIO bus drivers.
In the SDIO case, if a function suspend method returns an error, then all previously suspended functions are resumed and the error returned. An exception is made for -ENOSYS which the core interprets as "we don't support suspend so just kick the card out for suspend and return success".
When resuming SDIO cards, the core code only validates the manufacturer and product IDs to make sure the same kind of card is still present before invoking functions resume methods. It's the function driver's responsibility to perform further tests to confirm that the actual same card is present (same MAC address, etc.) and return an error otherwise.
---
drivers/mmc/core/core.c | 35 +++++++++++++++++++----- drivers/mmc/core/core.h | 4 +- drivers/mmc/core/mmc.c | 15 +++------- drivers/mmc/core/sd.c | 15 +++------- drivers/mmc/core/sdio.c | 54 ++++++++++++++++++++------------------ 5 files changed, 69 insertions(+), 54 deletions(-)
drivers/mmc/core/core.c renamed from drivers/mmc/core/core.c~mmc-propagate-error-codes-back-from-bus-drivers-suspend-resume-methods +28 -7
@@ -1236,6 +1236,8 @@ EXPORT_SYMBOL(mmc_card_can_sleep);*/ int mmc_suspend_host (struct mmc_host *host,pm_message_t state) { +int err =0 ; +if (host->caps &MMC_CAP_DISABLE )cancel_delayed_work (&host->disable);cancel_delayed_work (&host->detect);
@@ -1244,21 +1246,26 @@ int mmc_suspend_host(struct mmc_host *hommc_bus_get (host);if (host->bus_ops && !host->bus_dead) {if (host->bus_ops->suspend) - host->bus_ops->suspend (host); -if (!host->bus_ops->resume) { + err = host->bus_ops->suspend (host); +if (err == -ENOSYS || !host->bus_ops->resume) { +/* +* We simply "remove" the card in this case. +* It will be redetected on resume. +*/ if (host->bus_ops->remove) host->bus_ops->remove (host); -mmc_claim_host (host);mmc_detach_bus (host);mmc_release_host (host); + err =0 ; } }mmc_bus_put (host); -mmc_power_off (host); +if (!err) +mmc_power_off (host); -return 0 ; +return err; }EXPORT_SYMBOL (mmc_suspend_host);
@@ -1269,12 +1276,26 @@ EXPORT_SYMBOL(mmc_suspend_host);*/ int mmc_resume_host (struct mmc_host *host) { +int err =0 ; +mmc_bus_get (host);if (host->bus_ops && !host->bus_dead) {mmc_power_up (host);mmc_select_voltage (host, host->ocr);BUG_ON (!host->bus_ops->resume); - host->bus_ops->resume (host); + err = host->bus_ops->resume (host); +if (err) { +printk (KERN_WARNING "%s: error %d during resume " +"(card was removed?)\n" , +mmc_hostname (host), err); +if (host->bus_ops->remove) + host->bus_ops->remove (host); +mmc_claim_host (host); +mmc_detach_bus (host); +mmc_release_host (host); +/* no need to bother upper layers */ + err =0 ; + } }mmc_bus_put (host);
@@ -1284,7 +1305,7 @@ int mmc_resume_host(struct mmc_host *hos*/ mmc_detect_change (host,1 ); -return 0 ; +return err; }EXPORT_SYMBOL (mmc_resume_host);
drivers/mmc/core/core.h renamed from drivers/mmc/core/core.h~mmc-propagate-error-codes-back-from-bus-drivers-suspend-resume-methods +2 -2
@@ -20,8 +20,8 @@ struct mmc_bus_ops {int (*sleep)(struct mmc_host *);void (*remove)(struct mmc_host *);void (*detect)(struct mmc_host *); -void (*suspend)(struct mmc_host *); -void (*resume)(struct mmc_host *); +int (*suspend)(struct mmc_host *); +int (*resume)(struct mmc_host *);void (*power_save)(struct mmc_host *);void (*power_restore)(struct mmc_host *); };
drivers/mmc/core/mmc.c renamed from drivers/mmc/core/mmc.c~mmc-propagate-error-codes-back-from-bus-drivers-suspend-resume-methods +5 -10
@@ -530,7 +530,7 @@ static void mmc_detect(struct mmc_host */* * Suspend callback from host. */ -static void mmc_suspend (struct mmc_host *host) +static int mmc_suspend (struct mmc_host *host) {BUG_ON (!host);BUG_ON (!host->card);
@@ -540,6 +540,8 @@ static void mmc_suspend(struct mmc_hostmmc_deselect_cards (host); host->card->state &= ~MMC_STATE_HIGHSPEED ;mmc_release_host (host); + +return 0 ; }/*
@@ -548,7 +550,7 @@ static void mmc_suspend(struct mmc_host* This function tries to determine if the same card is still present * and, if so, restore all state to it. */ -static void mmc_resume (struct mmc_host *host) +static int mmc_resume (struct mmc_host *host) {int err;
@@ -559,14 +561,7 @@ static void mmc_resume(struct mmc_host * err =mmc_init_card (host, host->ocr, host->card);mmc_release_host (host); -if (err) { -mmc_remove (host); - -mmc_claim_host (host); -mmc_detach_bus (host); -mmc_release_host (host); - } - +return err; }static void mmc_power_restore (struct mmc_host *host)
drivers/mmc/core/sd.c renamed from drivers/mmc/core/sd.c~mmc-propagate-error-codes-back-from-bus-drivers-suspend-resume-methods +5 -10
@@ -564,7 +564,7 @@ static void mmc_sd_detect(struct mmc_hos/* * Suspend callback from host. */ -static void mmc_sd_suspend (struct mmc_host *host) +static int mmc_sd_suspend (struct mmc_host *host) {BUG_ON (!host);BUG_ON (!host->card);
@@ -574,6 +574,8 @@ static void mmc_sd_suspend(struct mmc_hommc_deselect_cards (host); host->card->state &= ~MMC_STATE_HIGHSPEED ;mmc_release_host (host); + +return 0 ; }/*
@@ -582,7 +584,7 @@ static void mmc_sd_suspend(struct mmc_ho* This function tries to determine if the same card is still present * and, if so, restore all state to it. */ -static void mmc_sd_resume (struct mmc_host *host) +static int mmc_sd_resume (struct mmc_host *host) {int err;
@@ -593,14 +595,7 @@ static void mmc_sd_resume(struct mmc_hos err =mmc_sd_init_card (host, host->ocr, host->card);mmc_release_host (host); -if (err) { -mmc_sd_remove (host); - -mmc_claim_host (host); -mmc_detach_bus (host); -mmc_release_host (host); - } - +return err; }static void mmc_sd_power_restore (struct mmc_host *host)
drivers/mmc/core/sdio.c renamed from drivers/mmc/core/sdio.c~mmc-propagate-error-codes-back-from-bus-drivers-suspend-resume-methods +29 -25
97 lines not on this page · raw message
_