linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc_spi: fail gracefully if host or card do not support the switch command
@ 2009-06-11 15:13 Wolfgang Mües
  2009-06-13 11:08 ` Pierre Ossman
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfgang Mües @ 2009-06-11 15:13 UTC (permalink / raw)
  To: Pierre Ossman
  Cc: Andrew Morton, Matt Fleming, David Brownell, Mike Frysinger,
	linux-kernel

From: Wolfgang Muees <wolfgang.mues@auerswald.de>

The switch command (typically speed switching from 25 to 50 MHz clock)
can be rejected by _both_ the host controller/driver and by the card.
Elder revisions of the SD card do not support speed switching.
Fail gracefully if the reject is comming from the card.

Signed-off-by: Wolfgang Muees <wolfgang.mues@auerswald.de>

---
diff -uprN 2_6_29_rc7_patch_retries/drivers/mmc/core/mmc.c 2_6_29_rc7_patch_switch/drivers/mmc/core/mmc.c
--- 2_6_29_rc7_patch_retries/drivers/mmc/core/mmc.c	2009-03-04 02:05:22.000000000 +0100
+++ 2_6_29_rc7_patch_switch/drivers/mmc/core/mmc.c	2009-06-11 17:09:48.000000000 +0200
@@ -180,11 +180,11 @@ static int mmc_read_ext_csd(struct mmc_c
 
 	err = mmc_send_ext_csd(card, ext_csd);
 	if (err) {
-		/*
-		 * We all hosts that cannot perform the command
-		 * to fail more gracefully
-		 */
-		if (err != -EINVAL)
+		/* If the host or the card can't do the switch,
+		 * fail more gracefully. */
+		if ((err != -EINVAL)
+		 && (err != -ENOSYS)
+		 && (err != -EFAULT))
 			goto out;
 
 		/*
diff -uprN 2_6_29_rc7_patch_retries/drivers/mmc/core/sd.c 2_6_29_rc7_patch_switch/drivers/mmc/core/sd.c
--- 2_6_29_rc7_patch_retries/drivers/mmc/core/sd.c	2009-04-07 15:39:22.000000000 +0200
+++ 2_6_29_rc7_patch_switch/drivers/mmc/core/sd.c	2009-06-11 17:09:43.000000000 +0200
@@ -210,11 +210,11 @@ static int mmc_read_switch(struct mmc_ca
 
 	err = mmc_sd_switch(card, 0, 0, 1, status);
 	if (err) {
-		/*
-		 * We all hosts that cannot perform the command
-		 * to fail more gracefully
-		 */
-		if (err != -EINVAL)
+		/* If the host or the card can't do the switch,
+		 * fail more gracefully. */
+		if ((err != -EINVAL)
+		 && (err != -ENOSYS)
+		 && (err != -EFAULT))
 			goto out;
 
 		printk(KERN_WARNING "%s: problem reading switch "
---
regards

i. A. Wolfgang Mües
-- 
Auerswald GmbH & Co. KG
Hardware Development
Telefon: +49 (0)5306 9219 0
Telefax: +49 (0)5306 9219 94 
E-Mail: Wolfgang.Mues@Auerswald.de
Web: http://www.auerswald.de
 
--------------------------------------------------------------
Auerswald GmbH & Co. KG, Vor den Grashöfen 1, 38162 Cremlingen
Registriert beim AG Braunschweig HRA 13289
p.h.G Auerswald Geschäftsführungsges. mbH
Registriert beim AG Braunschweig HRB 7463
Geschäftsführer: Dipl-Ing. Gerhard Auerswald

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mmc_spi: fail gracefully if host or card do not support the switch command
  2009-06-11 15:13 [PATCH] mmc_spi: fail gracefully if host or card do not support the switch command Wolfgang Mües
@ 2009-06-13 11:08 ` Pierre Ossman
  2009-06-15  8:36   ` Wolfgang Mües
  0 siblings, 1 reply; 5+ messages in thread
From: Pierre Ossman @ 2009-06-13 11:08 UTC (permalink / raw)
  To: Wolfgang Mües
  Cc: Andrew Morton, Matt Fleming, David Brownell, Mike Frysinger,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 969 bytes --]

On Thu, 11 Jun 2009 16:13:27 +0100
Wolfgang Mües <wolfgang.mues@auerswald.de> wrote:

> From: Wolfgang Muees <wolfgang.mues@auerswald.de>
> 
> The switch command (typically speed switching from 25 to 50 MHz clock)
> can be rejected by _both_ the host controller/driver and by the card.
> Elder revisions of the SD card do not support speed switching.
> Fail gracefully if the reject is comming from the card.
> 
> Signed-off-by: Wolfgang Muees <wolfgang.mues@auerswald.de>
> 

Have you ever seen this in practice? For SD there are several checks
before the switch command is actually issued. Sounds like there is
something else wrong here. Have you turned off your EMP thingy? ;)

PS. Please use the @ossman.eu address.

Rgds
-- 
     -- Pierre Ossman

  WARNING: This correspondence is being monitored by the
  Swedish government. Make sure your server uses encryption
  for SMTP traffic and consider using PGP for end-to-end
  encryption.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mmc_spi: fail gracefully if host or card do not support the switch command
  2009-06-13 11:08 ` Pierre Ossman
@ 2009-06-15  8:36   ` Wolfgang Mües
  2009-06-15 19:24     ` Pierre Ossman
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfgang Mües @ 2009-06-15  8:36 UTC (permalink / raw)
  To: Pierre Ossman
  Cc: Andrew Morton, Matt Fleming, David Brownell, Mike Frysinger,
	linux-kernel

Hello Pierre,

Am Samstag, 13. Juni 2009 schrieb Pierre Ossman:
> > The switch command (typically speed switching from 25 to 50 MHz clock)
> > can be rejected by _both_ the host controller/driver and by the card.
> > Elder revisions of the SD card do not support speed switching.
> > Fail gracefully if the reject is comming from the card.

> Have you ever seen this in practice?

Yes, I have. An old 1 GByte SD card.

> For SD there are several checks 
> before the switch command is actually issued.

But there are two cases not covered by these checks:

a) the switch command is supported, but the card is not capable of switching 
to 50 MHz.

b) the card rejects the switch command in SPI mode, because it is not 
mandatory here.

So yes, the checks can be improved. But only extending the error codes was a 
simple, fast and minimal solution.

regards

i. A. Wolfgang Mües
-- 
Auerswald GmbH & Co. KG
Hardware Development
Telefon: +49 (0)5306 9219 0
Telefax: +49 (0)5306 9219 94 
E-Mail: Wolfgang.Mues@Auerswald.de
Web: http://www.auerswald.de
 
--------------------------------------------------------------
Auerswald GmbH & Co. KG, Vor den Grashöfen 1, 38162 Cremlingen
Registriert beim AG Braunschweig HRA 13289
p.h.G Auerswald Geschäftsführungsges. mbH
Registriert beim AG Braunschweig HRB 7463
Geschäftsführer: Dipl-Ing. Gerhard Auerswald

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mmc_spi: fail gracefully if host or card do not support the switch command
  2009-06-15  8:36   ` Wolfgang Mües
@ 2009-06-15 19:24     ` Pierre Ossman
  0 siblings, 0 replies; 5+ messages in thread
From: Pierre Ossman @ 2009-06-15 19:24 UTC (permalink / raw)
  To: Wolfgang Mües
  Cc: Andrew Morton, Matt Fleming, David Brownell, Mike Frysinger,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 958 bytes --]

On Mon, 15 Jun 2009 10:36:05 +0200
Wolfgang Mües <wolfgang.mues@auerswald.de> wrote:

> Am Samstag, 13. Juni 2009 schrieb Pierre Ossman:
> > For SD there are several checks 
> > before the switch command is actually issued.
> 
> But there are two cases not covered by these checks:
> 
> a) the switch command is supported, but the card is not capable of switching 
> to 50 MHz.
> 

But a successful switch command (even if the response is that the card
cannot do it) should not need the checks you added. The switch data
structure is checked further down.

> b) the card rejects the switch command in SPI mode, because it is not 
> mandatory here.

I cannot see anything in the spec backing up this claim.

Rgds
-- 
     -- Pierre Ossman

  WARNING: This correspondence is being monitored by the
  Swedish government. Make sure your server uses encryption
  for SMTP traffic and consider using PGP for end-to-end
  encryption.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] mmc_spi: fail gracefully if host or card do not support the switch command
@ 2009-09-09 13:02 Wolfgang Mües
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Mües @ 2009-09-09 13:02 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel, linux-mmc

From: Wolfgang Muees <wolfgang.mues@auerswald.de>

Some time ago, I have send a patch to the mmc_spi subsystem changing the error 
codes. This was after a discussion with Pierre about using EINVAL only for 
non-recoverable errors. This patch was accepted as

http://git.kernel.org/linus/fdd858db7113ca64132de390188d7ca00701013d

Unfortunately, several weeks later, I realized that this patch has opened a 
little can of worms because there are SD cards on the market which

a) claim that they support the switch command
AND
b) refuse to execute this command if operating in SPI mode.

So, such a card would get unusuable in an embedded linux system in SPI mode, 
because the init sequence terminates with an error.

This patch adds the missing error codes to the caller of the switch command
and restores the old bahaviour to fail gracefully if these commands can not
execute.

This patch should go into 2.6.31 to show up in embedded systems ASAP.

Signed-off-by: Wolfgang Muees <wolfgang.mues@auerswald.de>

---
diff -uprN 2_6_31_rc8/drivers/mmc/core/mmc.c 2_6_31_rc8_switch/drivers/mmc/core/mmc.c
--- 2_6_31_rc8/drivers/mmc/core/mmc.c	2009-08-28 02:59:04.000000000 +0200
+++ 2_6_31_rc8_switch/drivers/mmc/core/mmc.c	2009-09-09 14:44:45.000000000 +0200
@@ -180,11 +180,11 @@ static int mmc_read_ext_csd(struct mmc_c

 	err = mmc_send_ext_csd(card, ext_csd);
 	if (err) {
-		/*
-		 * We all hosts that cannot perform the command
-		 * to fail more gracefully
-		 */
-		if (err != -EINVAL)
+		/* If the host or the card can't do the switch,
+		 * fail more gracefully. */
+		if ((err != -EINVAL)
+		 && (err != -ENOSYS)
+		 && (err != -EFAULT))
 			goto out;

 		/*
diff -uprN 2_6_31_rc8/drivers/mmc/core/sd.c 2_6_31_rc8_switch/drivers/mmc/core/sd.c
--- 2_6_31_rc8/drivers/mmc/core/sd.c	2009-08-28 02:59:04.000000000 +0200
+++ 2_6_31_rc8_switch/drivers/mmc/core/sd.c	2009-09-09 14:45:34.000000000 +0200
@@ -210,11 +210,11 @@ static int mmc_read_switch(struct mmc_ca

 	err = mmc_sd_switch(card, 0, 0, 1, status);
 	if (err) {
-		/*
-		 * We all hosts that cannot perform the command
-		 * to fail more gracefully
-		 */
-		if (err != -EINVAL)
+		/* If the host or the card can't do the switch,
+		 * fail more gracefully. */
+		if ((err != -EINVAL)
+		 && (err != -ENOSYS)
+		 && (err != -EFAULT))
 			goto out;

 		printk(KERN_WARNING "%s: problem reading switch "
---
regards

i. A. Wolfgang Mües
-- 
Auerswald GmbH & Co. KG
Hardware Development
Telefon: +49 (0)5306 9219 0
Telefax: +49 (0)5306 9219 94 
E-Mail: Wolfgang.Mues@Auerswald.de
Web: http://www.auerswald.de
 
--------------------------------------------------------------
Auerswald GmbH & Co. KG, Vor den Grashöfen 1, 38162 Cremlingen
Registriert beim AG Braunschweig HRA 13289
p.h.G Auerswald Geschäftsführungsges. mbH
Registriert beim AG Braunschweig HRB 7463
Geschäftsführer: Dipl-Ing. Gerhard Auerswald

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-09-09 13:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-11 15:13 [PATCH] mmc_spi: fail gracefully if host or card do not support the switch command Wolfgang Mües
2009-06-13 11:08 ` Pierre Ossman
2009-06-15  8:36   ` Wolfgang Mües
2009-06-15 19:24     ` Pierre Ossman
2009-09-09 13:02 Wolfgang Mües

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).