From patchwork Fri Feb 3 09:14:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 6588 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 925B323EB0 for ; Fri, 3 Feb 2012 09:14:56 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 4B789A18054 for ; Fri, 3 Feb 2012 09:14:56 +0000 (UTC) Received: by iabz7 with SMTP id z7so6115395iab.11 for ; Fri, 03 Feb 2012 01:14:55 -0800 (PST) Received: by 10.42.177.133 with SMTP id bi5mr6966152icb.40.1328260495755; Fri, 03 Feb 2012 01:14:55 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.169.210 with SMTP id a18cs7657ibz; Fri, 3 Feb 2012 01:14:55 -0800 (PST) Received: by 10.213.29.205 with SMTP id r13mr2361205ebc.5.1328260494069; Fri, 03 Feb 2012 01:14:54 -0800 (PST) Received: from eu1sys200aog114.obsmtp.com (eu1sys200aog114.obsmtp.com. [207.126.144.137]) by mx.google.com with SMTP id m50si3045271eeh.140.2012.02.03.01.14.50 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 03 Feb 2012 01:14:53 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.137 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.137; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.137 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) smtp.mail=ulf.hansson@stericsson.com Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob114.postini.com ([207.126.147.11]) with SMTP ID DSNKTyulhqkb18MlxaYq8Bm0RdV5ymPW/wnA@postini.com; Fri, 03 Feb 2012 09:14:53 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 6A15514C; Fri, 3 Feb 2012 09:06:13 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 079BC18DE; Fri, 3 Feb 2012 09:14:40 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 8B10324C07C; Fri, 3 Feb 2012 10:14:34 +0100 (CET) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.83.0; Fri, 3 Feb 2012 10:14:38 +0100 From: Ulf Hansson To: , Chris Ball Cc: Adrian Hunter , Per Forlin , Ulf Hansson , Johan Rudholm , Lee Jones Subject: [PATCH V3] mmc: core: Detect card removal on I/O error Date: Fri, 3 Feb 2012 10:14:03 +0100 Message-ID: <1328260443-30380-1-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.5.4 MIME-Version: 1.0 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 --- 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 | 19 +++++++++++++++++-- include/linux/mmc/host.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index bec0bf2..26d3a66 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2077,18 +2077,33 @@ 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); /* * 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)) + if (card && !host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL) + && !(host->caps2 & MMC_CAP2_DETECT_ON_ERR)) return mmc_card_removed(card); host->detect_change = 0; - return _mmc_detect_card_removed(host); + ret = mmc_card_removed(card); + if (!ret) { + ret = _mmc_detect_card_removed(host); + if (ret) { + /* + * 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 ret; } EXPORT_SYMBOL(mmc_detect_card_removed); diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index dd13e05..368a2b9 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -257,6 +257,7 @@ struct mmc_host { #define MMC_CAP2_HS200_1_2V_SDR (1 << 6) /* can support */ #define MMC_CAP2_HS200 (MMC_CAP2_HS200_1_8V_SDR | \ MMC_CAP2_HS200_1_2V_SDR) +#define MMC_CAP2_DETECT_ON_ERR (1 << 7) /* On I/O err check card removal */ mmc_pm_flag_t pm_caps; /* supported pm features */ unsigned int power_notify_type;