From patchwork Mon Feb 6 09:42:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 6664 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 A7F2523EB0 for ; Mon, 6 Feb 2012 09:42:59 +0000 (UTC) Received: from mail-tul01m020-f180.google.com (mail-tul01m020-f180.google.com [209.85.214.180]) by fiordland.canonical.com (Postfix) with ESMTP id 3DE18A184CE for ; Mon, 6 Feb 2012 09:42:59 +0000 (UTC) Received: by obbuo19 with SMTP id uo19so8547605obb.11 for ; Mon, 06 Feb 2012 01:42:58 -0800 (PST) Received: by 10.50.153.133 with SMTP id vg5mr9315769igb.8.1328521378308; Mon, 06 Feb 2012 01:42:58 -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 a18cs85461ibz; Mon, 6 Feb 2012 01:42:57 -0800 (PST) Received: by 10.14.95.129 with SMTP id p1mr3037029eef.10.1328521376159; Mon, 06 Feb 2012 01:42:56 -0800 (PST) Received: from eu1sys200aog119.obsmtp.com (eu1sys200aog119.obsmtp.com. [207.126.144.147]) by mx.google.com with SMTP id s42si8385035ees.106.2012.02.06.01.42.51 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 06 Feb 2012 01:42:56 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.147 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.147; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.147 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 eu1sys200aob119.postini.com ([207.126.147.11]) with SMTP ID DSNKTy+gl23zJkvkPwsUWLcJ3YpYi6nmQrWT@postini.com; Mon, 06 Feb 2012 09:42:54 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 8B32F111; Mon, 6 Feb 2012 09:34:17 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 4F4401402; Mon, 6 Feb 2012 09:42:44 +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 relay2.stm.gmessaging.net (Postfix) with ESMTPS id BEC2EA8065; Mon, 6 Feb 2012 10:42:39 +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; Mon, 6 Feb 2012 10:42:43 +0100 From: Ulf Hansson To: , Chris Ball Cc: Adrian Hunter , Per Forlin , Ulf Hansson , Johan Rudholm , Lee Jones Subject: [PATCH V4] mmc: core: Detect card removal on I/O error Date: Mon, 6 Feb 2012 10:42:39 +0100 Message-ID: <1328521359-31962-1-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.5.4 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQnGfHMj+DDEmnLFonDjXB4BBce3X/VpFQT0b3wLuFhUt027o81cTt/+SRVCL/eiRa788SBG 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 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;