1 From d6442f505a7bf1bebe9bd4689d021f007a269cd6 Mon Sep 17 00:00:00 2001
3 Date: Mon, 19 Nov 2012 12:46:06 +0100
4 Subject: [PATCH 038/174] Lazy CRC quirk: Implemented retrying mechanisms for
5 SD SSR and SCR, disabled missing_status and spurious CRC ACMD51 quirks by
6 default (should be fixed by the retrying-mechanishm)
9 drivers/mmc/core/sd.c | 115 +++++++++++++++++++++++++++++++++------
10 drivers/mmc/host/sdhci-bcm2708.c | 11 +++-
11 2 files changed, 108 insertions(+), 18 deletions(-)
13 --- a/drivers/mmc/core/sd.c
14 +++ b/drivers/mmc/core/sd.c
16 #include <linux/err.h>
17 #include <linux/slab.h>
18 #include <linux/stat.h>
19 +#include <linux/jiffies.h>
20 +#include <linux/nmi.h>
22 #include <linux/mmc/host.h>
23 #include <linux/mmc/card.h>
24 @@ -58,6 +60,15 @@ static const unsigned int tacc_mant[] =
29 +static const unsigned long retry_timeout_ms= 10*1000;
31 +// try at least 10 times, even if timeout is reached
32 +static const int retry_min_tries= 10;
34 +// delay between tries
35 +static const unsigned long retry_delay_ms= 10;
38 * Given the decoded CSD structure, decode the raw CID to our CID structure.
40 @@ -210,12 +221,62 @@ static int mmc_decode_scr(struct mmc_car
44 - * Fetch and process SD Status register.
45 + * Fetch and process SD Configuration Register.
47 +static int mmc_read_scr(struct mmc_card *card)
49 + unsigned long timeout_at;
52 + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
55 + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
57 + unsigned long delay_at;
60 + err = mmc_app_send_scr(card, card->raw_scr);
64 + touch_nmi_watchdog(); // we are still alive!
67 + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
68 + while( time_before( jiffies, delay_at ) )
71 + touch_nmi_watchdog(); // we are still alive!
77 + pr_err("%s: failed to read SD Configuration register (SCR) after %d tries during %lu ms, error %d\n", mmc_hostname(card->host), tries, retry_timeout_ms, err );
83 + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
86 + err = mmc_decode_scr(card);
94 + * Fetch and process SD Status Register.
96 static int mmc_read_ssr(struct mmc_card *card)
98 + unsigned long timeout_at;
99 unsigned int au, es, et, eo;
104 if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
105 @@ -227,15 +288,41 @@ static int mmc_read_ssr(struct mmc_card
106 ssr = kmalloc(64, GFP_KERNEL);
110 - err = mmc_app_sd_status(card, ssr);
112 - pr_warning("%s: problem reading SD Status "
113 - "register.\n", mmc_hostname(card->host));
116 + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
119 + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
121 + unsigned long delay_at;
124 + err= mmc_app_sd_status(card, ssr);
126 + break; // sucess!!!
128 + touch_nmi_watchdog(); // we are still alive!
131 + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
132 + while( time_before( jiffies, delay_at ) )
135 + touch_nmi_watchdog(); // we are still alive!
141 + pr_err("%s: failed to read SD Status register (SSR) after %d tries during %lu ms, error %d\n", mmc_hostname(card->host), tries, retry_timeout_ms, err );
147 + pr_info("%s: could read SD Status register (SSR) at the %dth attempt\n", mmc_hostname(card->host), tries );
150 for (i = 0; i < 16; i++)
151 ssr[i] = be32_to_cpu(ssr[i]);
153 @@ -808,15 +895,11 @@ int mmc_sd_setup_card(struct mmc_host *h
157 - * Fetch SCR from card.
158 + * Fetch and decode SD Configuration register.
160 - err = mmc_app_send_scr(card, card->raw_scr);
164 - err = mmc_decode_scr(card);
167 + err = mmc_read_scr(card);
172 * Fetch and process SD Status register.
173 --- a/drivers/mmc/host/sdhci-bcm2708.c
174 +++ b/drivers/mmc/host/sdhci-bcm2708.c
175 @@ -137,6 +137,7 @@ static bool allow_highspeed = 1;
176 static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
177 static bool sync_after_dma = 1;
178 static bool missing_status = 1;
179 +static bool spurious_crc_acmd51 = 0;
183 @@ -1103,7 +1104,7 @@ static unsigned int sdhci_bcm2708_quirk_
187 -static unsigned int sdhci_bcm2708_quirk_spurious_crc(struct sdhci_host *host)
188 +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
192 @@ -1149,7 +1150,6 @@ static struct sdhci_ops sdhci_bcm2708_op
193 .pdma_reset = sdhci_bcm2708_platdma_reset,
195 .extra_ints = sdhci_bcm2708_quirk_extra_ints,
196 - .spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc,
197 .voltage_broken = sdhci_bcm2708_quirk_voltage_broken,
198 .uhs_broken = sdhci_bcm2708_uhs_broken,
200 @@ -1194,6 +1194,11 @@ static int sdhci_bcm2708_probe(struct pl
201 sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
204 + if( spurious_crc_acmd51 ) {
205 + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
209 printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
211 host->hw_name = "BCM2708_Arasan";
212 @@ -1389,6 +1394,7 @@ module_param(allow_highspeed, bool, 0444
213 module_param(emmc_clock_freq, int, 0444);
214 module_param(sync_after_dma, bool, 0444);
215 module_param(missing_status, bool, 0444);
216 +module_param(spurious_crc_acmd51, bool, 0444);
217 module_param(enable_llm, bool, 0444);
218 module_param(cycle_delay, int, 0444);
220 @@ -1401,6 +1407,7 @@ MODULE_PARM_DESC(allow_highspeed, "Allow
221 MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
222 MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
223 MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
224 +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
225 MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");