From patchwork Wed Feb 1 13:48:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 6496 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 D827423E0C for ; Wed, 1 Feb 2012 14:15:04 +0000 (UTC) Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id C4A9EA18509 for ; Wed, 1 Feb 2012 14:15:04 +0000 (UTC) Received: by bkar19 with SMTP id r19so1425047bka.11 for ; Wed, 01 Feb 2012 06:15:04 -0800 (PST) Received: by 10.205.134.129 with SMTP id ic1mr12622415bkc.92.1328105704464; Wed, 01 Feb 2012 06:15:04 -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.204.130.220 with SMTP id u28cs212030bks; Wed, 1 Feb 2012 06:15:04 -0800 (PST) Received: by 10.213.22.129 with SMTP id n1mr2004715ebb.30.1328105703584; Wed, 01 Feb 2012 06:15:03 -0800 (PST) Received: from eu1sys200aog106.obsmtp.com (eu1sys200aog106.obsmtp.com. [207.126.144.121]) by mx.google.com with SMTP id z11si9492601eef.68.2012.02.01.06.15.00 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 01 Feb 2012 06:15:03 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.121 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.121; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.121 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 eu1sys200aob106.postini.com ([207.126.147.11]) with SMTP ID DSNKTylI3GCzSpC42RiakCWDmBavMDKbB3Aq@postini.com; Wed, 01 Feb 2012 14:15:03 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 03336D5; Wed, 1 Feb 2012 13:39:57 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id BD12CB19; Wed, 1 Feb 2012 13:48:24 +0000 (GMT) Received: from exdcvycastm004.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm004", Issuer "exdcvycastm004" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 2E12424C07C; Wed, 1 Feb 2012 14:48:17 +0100 (CET) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.2) with Microsoft SMTP Server (TLS) id 8.3.83.0; Wed, 1 Feb 2012 14:48:23 +0100 From: Ulf Hansson To: , Chris Ball Cc: Adrian Hunter , Per Forlin , Ulf Hansson , Johan Rudholm , Lee Jones Subject: [PATCH V2] mmc: core: Detect card removal on I/O error Date: Wed, 1 Feb 2012 14:48:20 +0100 Message-ID: <1328104100-1880-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 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;