All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-mmc <linux-mmc@vger.kernel.org>,
	Aaron Lu <aaron.lu@intel.com>, Philip Rakity <prakity@nvidia.com>,
	Al Cooper <alcooperx@gmail.com>,
	Arend van Spriel <arend@broadcom.com>
Subject: [PATCH V6 01/15] mmc: host: Add facility to support re-tuning
Date: Mon, 20 Apr 2015 15:09:42 +0300	[thread overview]
Message-ID: <1429531796-21987-2-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1429531796-21987-1-git-send-email-adrian.hunter@intel.com>

Currently, there is core support for tuning during
initialization. There can also be a need to re-tune
periodically (e.g. sdhci) or to re-tune after the
host controller is powered off (e.g. after PM
runtime suspend / resume) or to re-tune in response
to CRC errors.

The main requirements for re-tuning are:
  - ability to enable / disable re-tuning
  - ability to flag that re-tuning is needed
  - ability to re-tune before any request
  - ability to hold off re-tuning if the card is busy
  - ability to hold off re-tuning if re-tuning is in
  progress
  - ability to run a re-tuning timer

To support those requirements 7 members are added to struct
mmc_host:

  unsigned int		can_retune:1;	/* re-tuning can be used */
  unsigned int		doing_retune:1;	/* re-tuning in progress */
  unsigned int		retune_now:1;   /* do re-tuning at next req */
  int			need_retune;	/* re-tuning is needed */
  int			hold_retune;	/* hold off re-tuning */
  unsigned int		retune_period;  /* re-tuning period in secs */
  struct timer_list	retune_timer;	/* for periodic re-tuning */

need_retune is an integer so it can be set without needing
synchronization. hold_retune is a integer to allow nesting.

Various simple functions are provided to set / clear those
variables.

Subsequent patches take those functions into use.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/mmc/core/host.c  | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/core/host.h  |  6 +++++
 include/linux/mmc/host.h | 28 ++++++++++++++++++++
 3 files changed, 102 insertions(+)

diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 8be0df7..e90e02f 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -301,6 +301,73 @@ static inline void mmc_host_clk_sysfs_init(struct mmc_host *host)
 
 #endif
 
+void mmc_retune_enable(struct mmc_host *host)
+{
+	host->can_retune = 1;
+	if (host->retune_period)
+		mod_timer(&host->retune_timer,
+			  jiffies + host->retune_period * HZ);
+}
+
+void mmc_retune_disable(struct mmc_host *host)
+{
+	host->can_retune = 0;
+	del_timer_sync(&host->retune_timer);
+	host->retune_now = 0;
+	host->need_retune = 0;
+}
+
+void mmc_retune_timer_stop(struct mmc_host *host)
+{
+	del_timer_sync(&host->retune_timer);
+}
+EXPORT_SYMBOL(mmc_retune_timer_stop);
+
+void mmc_retune_hold(struct mmc_host *host)
+{
+	if (!host->hold_retune)
+		host->retune_now = 1;
+	host->hold_retune += 1;
+}
+
+void mmc_retune_release(struct mmc_host *host)
+{
+	if (host->hold_retune)
+		host->hold_retune -= 1;
+	else
+		WARN_ON(1);
+}
+
+int mmc_retune(struct mmc_host *host)
+{
+	int err;
+
+	if (host->retune_now)
+		host->retune_now = 0;
+	else
+		return 0;
+
+	if (!host->need_retune || host->doing_retune || !host->card)
+		return 0;
+
+	host->need_retune = 0;
+
+	host->doing_retune = 1;
+
+	err = mmc_execute_tuning(host->card);
+
+	host->doing_retune = 0;
+
+	return err;
+}
+
+static void mmc_retune_timer(unsigned long data)
+{
+	struct mmc_host *host = (struct mmc_host *)data;
+
+	mmc_retune_needed(host);
+}
+
 /**
  *	mmc_of_parse() - parse host's device-tree node
  *	@host: host whose node should be parsed.
@@ -504,6 +571,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 #ifdef CONFIG_PM
 	host->pm_notify.notifier_call = mmc_pm_notify;
 #endif
+	setup_timer(&host->retune_timer, mmc_retune_timer, (unsigned long)host);
 
 	/*
 	 * By default, hosts do not support SGIO or large requests.
diff --git a/drivers/mmc/core/host.h b/drivers/mmc/core/host.h
index f2ab9e5..992bf53 100644
--- a/drivers/mmc/core/host.h
+++ b/drivers/mmc/core/host.h
@@ -15,5 +15,11 @@
 int mmc_register_host_class(void);
 void mmc_unregister_host_class(void);
 
+void mmc_retune_enable(struct mmc_host *host);
+void mmc_retune_disable(struct mmc_host *host);
+void mmc_retune_hold(struct mmc_host *host);
+void mmc_retune_release(struct mmc_host *host);
+int mmc_retune(struct mmc_host *host);
+
 #endif
 
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index b5bedae..9c9e51b 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -12,6 +12,7 @@
 
 #include <linux/leds.h>
 #include <linux/mutex.h>
+#include <linux/timer.h>
 #include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/fault-inject.h>
@@ -321,10 +322,18 @@ struct mmc_host {
 #ifdef CONFIG_MMC_DEBUG
 	unsigned int		removed:1;	/* host is being removed */
 #endif
+	unsigned int		can_retune:1;	/* re-tuning can be used */
+	unsigned int		doing_retune:1;	/* re-tuning in progress */
+	unsigned int		retune_now:1;	/* do re-tuning at next req */
 
 	int			rescan_disable;	/* disable card detection */
 	int			rescan_entered;	/* used with nonremovable devices */
 
+	int			need_retune;	/* re-tuning is needed */
+	int			hold_retune;	/* hold off re-tuning */
+	unsigned int		retune_period;	/* re-tuning period in secs */
+	struct timer_list	retune_timer;	/* for periodic re-tuning */
+
 	bool			trigger_card_event; /* card_event necessary */
 
 	struct mmc_card		*card;		/* device attached to this host */
@@ -513,4 +522,23 @@ static inline bool mmc_card_hs400(struct mmc_card *card)
 	return card->host->ios.timing == MMC_TIMING_MMC_HS400;
 }
 
+void mmc_retune_timer_stop(struct mmc_host *host);
+
+static inline void mmc_retune_needed(struct mmc_host *host)
+{
+	if (host->can_retune)
+		host->need_retune = 1;
+}
+
+static inline void mmc_retune_not_needed(struct mmc_host *host)
+{
+	host->need_retune = 0;
+}
+
+static inline void mmc_retune_recheck(struct mmc_host *host)
+{
+	if (host->hold_retune <= 1)
+		host->retune_now = 1;
+}
+
 #endif /* LINUX_MMC_HOST_H */
-- 
1.9.1


  reply	other threads:[~2015-04-20 12:12 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-20 12:09 [PATCH V6 00/15] mmc: host: Add facility to support re-tuning Adrian Hunter
2015-04-20 12:09 ` Adrian Hunter [this message]
2015-05-04 13:14   ` [PATCH V6 01/15] " Ulf Hansson
2015-04-20 12:09 ` [PATCH V6 02/15] mmc: core: Enable / disable re-tuning Adrian Hunter
2015-04-21  8:59   ` Ulf Hansson
2015-04-21 10:37     ` Adrian Hunter
2015-04-28 13:18       ` [PATCH V7 " Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 03/15] mmc: core: Add support for re-tuning before each request Adrian Hunter
2015-05-04 13:28   ` Ulf Hansson
2015-05-06  8:02     ` Adrian Hunter
2015-05-06  9:45       ` Ulf Hansson
2015-05-06 10:17         ` Adrian Hunter
2015-05-06 10:37           ` Ulf Hansson
2015-04-20 12:09 ` [PATCH V6 04/15] mmc: core: Check re-tuning before retrying Adrian Hunter
2015-05-04 13:30   ` Ulf Hansson
2015-04-20 12:09 ` [PATCH V6 05/15] mmc: core: Hold re-tuning during switch commands Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 06/15] mmc: core: Hold re-tuning during erase commands Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 07/15] mmc: core: Hold re-tuning while bkops ongoing Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 08/15] mmc: mmc: Hold re-tuning if the card is put to sleep Adrian Hunter
2015-04-21  9:42   ` Ulf Hansson
2015-04-21 11:00     ` Adrian Hunter
2015-04-21 11:53       ` Ulf Hansson
2015-04-21 12:26         ` Adrian Hunter
2015-04-21 18:25           ` Arend van Spriel
2015-04-22  7:24             ` Adrian Hunter
2015-04-22  8:30               ` Arend van Spriel
2015-04-22  8:45                 ` Ulf Hansson
2015-05-04 13:44   ` Ulf Hansson
2015-05-06  8:39     ` Adrian Hunter
2015-05-06  9:32       ` Ulf Hansson
2015-05-06 10:28         ` Adrian Hunter
2015-05-06 11:36           ` Ulf Hansson
2015-05-06 12:42             ` Adrian Hunter
2015-05-06 13:21               ` Ulf Hansson
2015-05-07  7:49                 ` Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 09/15] mmc: core: Separate out the mmc_switch status check so it can be re-used Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 10/15] mmc: core: Add support for HS400 re-tuning Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 11/15] mmc: sdhci: Change to new way of doing re-tuning Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 12/15] mmc: sdhci: Flag re-tuning is needed on CRC or End-Bit errors Adrian Hunter
2015-05-04 13:55   ` Ulf Hansson
2015-05-06 11:09     ` Adrian Hunter
2015-05-06 11:40       ` Ulf Hansson
2015-04-20 12:09 ` [PATCH V6 13/15] mmc: block: Check re-tuning in the recovery path Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 14/15] mmc: block: Retry errored data requests when re-tuning is needed Adrian Hunter
2015-04-20 12:09 ` [PATCH V6 15/15] mmc: core: Don't print reset warning if reset is not supported Adrian Hunter
2015-05-04 10:39 ` [PATCH V6 00/15] mmc: host: Add facility to support re-tuning Adrian Hunter
2015-05-04 13:13   ` Ulf Hansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1429531796-21987-2-git-send-email-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=aaron.lu@intel.com \
    --cc=alcooperx@gmail.com \
    --cc=arend@broadcom.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=prakity@nvidia.com \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.