All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V4] mmc: core: Detect card removal on I/O error
@ 2012-02-06  9:42 Ulf Hansson
  2012-02-06 17:31 ` Linus Walleij
  2012-03-05 15:10 ` Ulf Hansson
  0 siblings, 2 replies; 4+ messages in thread
From: Ulf Hansson @ 2012-02-06  9:42 UTC (permalink / raw)
  To: linux-mmc, Chris Ball
  Cc: Adrian Hunter, Per Forlin, Ulf Hansson, Johan Rudholm, Lee Jones

To prevent I/O as soon as possible at card removal, a new
detect work is re-scheduled without a delay to let a rescan
remove the card device as soon a possible.

Additionally, MMC_CAP2_DETECT_ON_ERR can now be used to handle
"slowly" removed cards that a scheduled detect work did not
detect as removed. To prevent further I/O requests for these
lingering removed cards, check if card has been removed and then
schedule a detect work to properly remove it.

Signed-off-by: Ulf Hansson <ulf.hansson@stericsson.com>
---

Changes in v4:
	- Rebased on latest mmc-next branch.
	- Prevent scheduling a second not needed detect work.

Changes in v3:
	- Check for card is NULL and minor code simplifications.

Changes in v2:
	- Updated according to review comments.
	- Merging two patches for this feature into one.

---
 drivers/mmc/core/core.c  |   24 +++++++++++++++++++++---
 include/linux/mmc/host.h |    1 +
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 8a19143..a8f7efe 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2112,18 +2112,36 @@ int _mmc_detect_card_removed(struct mmc_host *host)
 int mmc_detect_card_removed(struct mmc_host *host)
 {
 	struct mmc_card *card = host->card;
+	int ret;
 
 	WARN_ON(!host->claimed);
+
+	if (!card)
+		return 1;
+
+	ret = mmc_card_removed(card);
 	/*
 	 * 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);
+	if (!host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL) &&
+	    !(host->caps2 & MMC_CAP2_DETECT_ON_ERR))
+		return ret;
 
 	host->detect_change = 0;
+	if (!ret) {
+		ret = _mmc_detect_card_removed(host);
+		if (ret && (host->caps2 & MMC_CAP2_DETECT_ON_ERR)) {
+			/*
+			 * Schedule a detect work as soon as possible to let a
+			 * rescan handle the card removal.
+			 */
+			cancel_delayed_work(&host->detect);
+			mmc_detect_change(host, 0);
+		}
+	}
 
-	return _mmc_detect_card_removed(host);
+	return ret;
 }
 EXPORT_SYMBOL(mmc_detect_card_removed);
 
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 20d7c82..e9f9e88 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -258,6 +258,7 @@ struct mmc_host {
 #define MMC_CAP2_HS200		(MMC_CAP2_HS200_1_8V_SDR | \
 				 MMC_CAP2_HS200_1_2V_SDR)
 #define MMC_CAP2_BROKEN_VOLTAGE	(1 << 7)	/* Use the broken voltage */
+#define MMC_CAP2_DETECT_ON_ERR	(1 << 8)	/* On I/O err check card removal */
 
 	mmc_pm_flag_t		pm_caps;	/* supported pm features */
 	unsigned int        power_notify_type;
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V4] mmc: core: Detect card removal on I/O error
  2012-02-06  9:42 [PATCH V4] mmc: core: Detect card removal on I/O error Ulf Hansson
@ 2012-02-06 17:31 ` Linus Walleij
  2012-03-05 15:10 ` Ulf Hansson
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2012-02-06 17:31 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: linux-mmc, Chris Ball, Adrian Hunter, Per Forlin, Johan Rudholm,
	Lee Jones

On Mon, Feb 6, 2012 at 10:42 AM, Ulf Hansson <ulf.hansson@stericsson.com> wrote:

> To prevent I/O as soon as possible at card removal, a new
> detect work is re-scheduled without a delay to let a rescan
> remove the card device as soon a possible.
>
> Additionally, MMC_CAP2_DETECT_ON_ERR can now be used to handle
> "slowly" removed cards that a scheduled detect work did not
> detect as removed. To prevent further I/O requests for these
> lingering removed cards, check if card has been removed and then
> schedule a detect work to properly remove it.
>
> Signed-off-by: Ulf Hansson <ulf.hansson@stericsson.com>

Acked-by: Linus Walleij <linus.walleij@linaro.org>

Thanks,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V4] mmc: core: Detect card removal on I/O error
  2012-02-06  9:42 [PATCH V4] mmc: core: Detect card removal on I/O error Ulf Hansson
  2012-02-06 17:31 ` Linus Walleij
@ 2012-03-05 15:10 ` Ulf Hansson
  2012-03-05 15:47   ` Chris Ball
  1 sibling, 1 reply; 4+ messages in thread
From: Ulf Hansson @ 2012-03-05 15:10 UTC (permalink / raw)
  To: Chris Ball
  Cc: Ulf HANSSON, linux-mmc@vger.kernel.org, Adrian Hunter, Per FORLIN,
	Johan RUDHOLM, Lee Jones

Hi Chris,

Just wondering if you see any issues with proceeding with this patch?

Thanks!

Br
Ulf Hansson


On 02/06/2012 10:42 AM, Ulf HANSSON wrote:
> To prevent I/O as soon as possible at card removal, a new
> detect work is re-scheduled without a delay to let a rescan
> remove the card device as soon a possible.
>
> Additionally, MMC_CAP2_DETECT_ON_ERR can now be used to handle
> "slowly" removed cards that a scheduled detect work did not
> detect as removed. To prevent further I/O requests for these
> lingering removed cards, check if card has been removed and then
> schedule a detect work to properly remove it.
>
> Signed-off-by: Ulf Hansson<ulf.hansson@stericsson.com>
> ---
>
> Changes in v4:
> 	- Rebased on latest mmc-next branch.
> 	- Prevent scheduling a second not needed detect work.
>
> Changes in v3:
> 	- Check for card is NULL and minor code simplifications.
>
> Changes in v2:
> 	- Updated according to review comments.
> 	- Merging two patches for this feature into one.
>
> ---
>   drivers/mmc/core/core.c  |   24 +++++++++++++++++++++---
>   include/linux/mmc/host.h |    1 +
>   2 files changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 8a19143..a8f7efe 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -2112,18 +2112,36 @@ int _mmc_detect_card_removed(struct mmc_host *host)
>   int mmc_detect_card_removed(struct mmc_host *host)
>   {
>   	struct mmc_card *card = host->card;
> +	int ret;
>
>   	WARN_ON(!host->claimed);
> +
> +	if (!card)
> +		return 1;
> +
> +	ret = mmc_card_removed(card);
>   	/*
>   	 * 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);
> +	if (!host->detect_change&&  !(host->caps&  MMC_CAP_NEEDS_POLL)&&
> +	    !(host->caps2&  MMC_CAP2_DETECT_ON_ERR))
> +		return ret;
>
>   	host->detect_change = 0;
> +	if (!ret) {
> +		ret = _mmc_detect_card_removed(host);
> +		if (ret&&  (host->caps2&  MMC_CAP2_DETECT_ON_ERR)) {
> +			/*
> +			 * Schedule a detect work as soon as possible to let a
> +			 * rescan handle the card removal.
> +			 */
> +			cancel_delayed_work(&host->detect);
> +			mmc_detect_change(host, 0);
> +		}
> +	}
>
> -	return _mmc_detect_card_removed(host);
> +	return ret;
>   }
>   EXPORT_SYMBOL(mmc_detect_card_removed);
>
> diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
> index 20d7c82..e9f9e88 100644
> --- a/include/linux/mmc/host.h
> +++ b/include/linux/mmc/host.h
> @@ -258,6 +258,7 @@ struct mmc_host {
>   #define MMC_CAP2_HS200		(MMC_CAP2_HS200_1_8V_SDR | \
>   				 MMC_CAP2_HS200_1_2V_SDR)
>   #define MMC_CAP2_BROKEN_VOLTAGE	(1<<  7)	/* Use the broken voltage */
> +#define MMC_CAP2_DETECT_ON_ERR	(1<<  8)	/* On I/O err check card removal */
>
>   	mmc_pm_flag_t		pm_caps;	/* supported pm features */
>   	unsigned int        power_notify_type;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V4] mmc: core: Detect card removal on I/O error
  2012-03-05 15:10 ` Ulf Hansson
@ 2012-03-05 15:47   ` Chris Ball
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Ball @ 2012-03-05 15:47 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: linux-mmc@vger.kernel.org, Adrian Hunter, Per FORLIN,
	Johan RUDHOLM, Lee Jones

Hi Ulf,

On Mon, Mar 05 2012, Ulf Hansson wrote:
> Just wondering if you see any issues with proceeding with this patch?

Thanks for the reminder -- looks good, pushed to mmc-next for 3.4.

- Chris.
-- 
Chris Ball   <cjb@laptop.org>   <http://printf.net/>
One Laptop Per Child

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-03-05 15:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-06  9:42 [PATCH V4] mmc: core: Detect card removal on I/O error Ulf Hansson
2012-02-06 17:31 ` Linus Walleij
2012-03-05 15:10 ` Ulf Hansson
2012-03-05 15:47   ` Chris Ball

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.