Skip to content

Commit 85f2e35

Browse files
committed
Fixes for sdhci-bcm2708
possible fix for sdcard missing status. Thank naren sdcard patch improvements from naren sdhci-bcm2708: speed up DMA sync Experiments show that it doesn't really take that long to sync, so we can reduce the poll interval slightly. Might improve performance a bit. sdhci-bcm2708: remove custom clock handling The custom clock handling code is redundant and buggy. The MMC/SDHCI subsystem does a better job than it, so remove it for good. sdhci-bcm2708: add additional quirks Some additional quirks are needed for correct operation. There's no SDHCI capabilities register documented, and it always reads zero, so add SDHCI_QUIRK_MISSING_CAPS. Apparently SDHCI_QUIRK_NO_HISPD_BIT is needed for many cards to work correctly in high-speed mode, so add it as well. sdhci-bcm2708: add allow_highspeed parameter Add a parameter to disable high-speed mode for the few cards that still might have problems. High-speed mode is enabled by default. sdhci-bcm2708: assume 50 MHz eMMC clock 80 MHz clock isnt't suited well to be dividable to get SD clocks of 25 MHz (default mode) or 50 MHz (high speed mode). 50 MHz are perfect to drive the SD interface at ideal frequencies. Allow emmc clock to be specified as command line parameter sdhci-bcm2708: raise DMA sync timeout Commit d64b84c by accident reduced the maximum overall DMA sync timeout. The maximum overall timeout was reduced from 100ms to 30ms, which isn't enough for many cards. Increase it to 150ms, just to be extra safe. According to commit 872a8ff in the MMC subsystem, some cards require crazy long timeouts (3s), but as we're busy-waiting, and shouldn't delay for such a long time, let's hope 150ms will be enough for most cards. Use ndelay rather than udelay. Thanks lb Add sync_after_dma module parameter sdhci-bcm2708: use extension FIFO to buffer DMA transfers The additional FIFO might speed up transfers in some cases. sdhci-bcm2708: use multiblock-type transfers for single blocks There are issues with both single block reads (missed completion) and writes (data loss in some cases!). Just don't do single block transfers anymore, and treat them like multiblock transfers. This adds a quirk for this and uses it. Add module parameter for missing_status quirk. sdhci-bcm2708.missing_status=0 may improve interrupt latency Fix spinlock recursion in sdhci-bcm2708.c mmc: Report 3.3V support in caps sdhci: Use macros for out spin lock/unlock functions to reduce diffs with upstream code sdhci: sdhci_bcm2708_quirk_voltage_broken appears to be a no-op sdhci: sdhci_bcm2708_uhs_broken should be handled through caps reported Add low-latency mode to sdcard driver. Disable with sdhci-bcm2708.enable_llm=0. Thanks ddv2005. Allow the number of cycles delay between sdcard peripheral writes to be specified on command line with sdhci-bcm2708.cycle_delay Lazy CRC quirk: Implemented retrying mechanisms for SD SSR and SCR, disabled missing_status and spurious CRC ACMD51 quirks by default (should be fixed by the retrying-mechanishm) mmc: suppress sdcard warnings we are happy about by default sdhci-bcm2807: Increase sync_after_dma timeout The current timeout is being hit with some cards that complete successfully with a longer timeout. The timeout is not handled well, and is believed to be a code path that causes corruption. 872a8ff suggests that crappy cards can take up to 3 seconds to respond remove suspend/resume fix sign in sdhci_bcm2708_raw_writel wait calculation The ns_wait variable is intended to hold a lower bound on the number of nanoseconds that have elapsed since the last sdhci register write. However, the actual calculation of it was incorrect, as the subtraction was inverted. This commit fixes the calculation. Note that this correction has no bearing when running with the default cycle_delay of 2 and the default clock rate of 50 MHz, under which conditions ns_2clk is 40 nanoseconds and ns_wait, regardless of whether the subtraction is done correctly or incorrectly, cannot possibly be less than 40 except for during the one-microsecond period just before the tick counter wraps around to meet last_write_hpt (i.e., approximately 4295 seconds after the preceding sdhci register write). The correction in this commit only comes into play if ns_2clk > 1000, which requires a cycle_delay of 51 or greater when using the default clock rate. Under those conditions, sdhci_bcm2708_raw_writel will not wait for the full cycle_delay count if at least 1000 nanoseconds have elapsed since the last register write. sdhci: Only do one iteration of PIO reading loop Changed wording on logging. Previously, we received errors like this: mmc0: could read SD Status register (SSR) at the 3th attempt A more sensible response is now returned. A typo also fixed in comments.
1 parent a5fbd67 commit 85f2e35

7 files changed

Lines changed: 365 additions & 191 deletions

File tree

‎drivers/mmc/card/block.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
14041404
brq->data.blocks = 1;
14051405
}
14061406

1407-
if (brq->data.blocks > 1 || do_rel_wr) {
1407+
if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
14081408
/* SPI multiblock writes terminate using a special
14091409
* token, not a STOP_TRANSMISSION request.
14101410
*/

‎drivers/mmc/core/sd.c‎

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/slab.h>
1616
#include <linux/stat.h>
1717
#include <linux/pm_runtime.h>
18+
#include <linux/jiffies.h>
19+
#include <linux/nmi.h>
1820

1921
#include <linux/mmc/host.h>
2022
#include <linux/mmc/card.h>
@@ -67,6 +69,15 @@ static const unsigned int sd_au_size[] = {
6769
__res & __mask; \
6870
})
6971

72+
// timeout for tries
73+
static const unsigned long retry_timeout_ms= 10*1000;
74+
75+
// try at least 10 times, even if timeout is reached
76+
static const int retry_min_tries= 10;
77+
78+
// delay between tries
79+
static const unsigned long retry_delay_ms= 10;
80+
7081
/*
7182
* Given the decoded CSD structure, decode the raw CID to our CID structure.
7283
*/
@@ -219,12 +230,63 @@ static int mmc_decode_scr(struct mmc_card *card)
219230
}
220231

221232
/*
222-
* Fetch and process SD Status register.
233+
* Fetch and process SD Configuration Register.
234+
*/
235+
static int mmc_read_scr(struct mmc_card *card)
236+
{
237+
unsigned long timeout_at;
238+
int err, tries;
239+
240+
timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
241+
tries= 0;
242+
243+
while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
244+
{
245+
unsigned long delay_at;
246+
tries++;
247+
248+
err = mmc_app_send_scr(card, card->raw_scr);
249+
if( !err )
250+
break; // success!!!
251+
252+
touch_nmi_watchdog(); // we are still alive!
253+
254+
// delay
255+
delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
256+
while( time_before( jiffies, delay_at ) )
257+
{
258+
mdelay( 1 );
259+
touch_nmi_watchdog(); // we are still alive!
260+
}
261+
}
262+
263+
if( err)
264+
{
265+
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 );
266+
return err;
267+
}
268+
269+
if( tries > 1 )
270+
{
271+
pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
272+
}
273+
274+
err = mmc_decode_scr(card);
275+
if (err)
276+
return err;
277+
278+
return err;
279+
}
280+
281+
/*
282+
* Fetch and process SD Status Register.
223283
*/
224284
static int mmc_read_ssr(struct mmc_card *card)
225285
{
286+
unsigned long timeout_at;
226287
unsigned int au, es, et, eo;
227288
int err, i;
289+
int tries;
228290
u32 *ssr;
229291

230292
if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
@@ -237,14 +299,40 @@ static int mmc_read_ssr(struct mmc_card *card)
237299
if (!ssr)
238300
return -ENOMEM;
239301

240-
err = mmc_app_sd_status(card, ssr);
241-
if (err) {
242-
pr_warning("%s: problem reading SD Status "
243-
"register.\n", mmc_hostname(card->host));
244-
err = 0;
302+
timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
303+
tries= 0;
304+
305+
while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
306+
{
307+
unsigned long delay_at;
308+
tries++;
309+
310+
err= mmc_app_sd_status(card, ssr);
311+
if( !err )
312+
break; // sucess!!!
313+
314+
touch_nmi_watchdog(); // we are still alive!
315+
316+
// delay
317+
delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
318+
while( time_before( jiffies, delay_at ) )
319+
{
320+
mdelay( 1 );
321+
touch_nmi_watchdog(); // we are still alive!
322+
}
323+
}
324+
325+
if( err)
326+
{
327+
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 );
245328
goto out;
246329
}
247330

331+
if( tries > 1 )
332+
{
333+
pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
334+
}
335+
248336
for (i = 0; i < 16; i++)
249337
ssr[i] = be32_to_cpu(ssr[i]);
250338

@@ -826,14 +914,10 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
826914

827915
if (!reinit) {
828916
/*
829-
* Fetch SCR from card.
917+
* Fetch and decode SD Configuration register.
830918
*/
831-
err = mmc_app_send_scr(card, card->raw_scr);
832-
if (err)
833-
return err;
834-
835-
err = mmc_decode_scr(card);
836-
if (err)
919+
err = mmc_read_scr(card);
920+
if( err )
837921
return err;
838922

839923
/*

0 commit comments

Comments
 (0)