Skip to contentSkip to conversation

MMC-over-SPI for 2.6.22-rc4-mm

PATCH In review David Brownell 2 participants 31 messages Jun 10, 2007 – Jul 12, 2007 25 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover MMC-over-SPI for 2.6.22-rc4-mm

Here's the latest, which (modulo review issues) should be mergeable against the latest git-mmc code (plus the crc7 patch, also in mm; and the 4wire patch).

- headers learn about SPI ... a minor change from the last version, removing that "R1D" message type hack

- mmc_block learns about SPI ... no change

- mmc core updates ... fixed merge conflicts with git-mmc, updated the CID/CSD handling, the new card unlock/code has been updated to know about SPI

- mmc_spi host dirver ... cleanups from those CID/CSD updates, bugfixes for chipselect handling, started cleanup of DMA code

I ran into some failures triggered when CRCs were enabled. The trigger may be platform-specific (e.g. GCC bugs). The flakey non-recovery is a different issue altogether.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706101257.45278.david-b-yBeKhBN/[email protected]

#2 lore raw

PATCH 1/4 MMC-over-SPI header updates

Teach the MMC/SD/SDIO system headers that some hosts use SPI mode

- New host capabilities bits
* MMC_CAP_SPI, with mmc_host_is_spi() test
* MMC_CAP_SPI_CRC, if it's ready to use CRCs

- SPI-specific declarations:
* Response types, MMC_RSP_SPI_R*
* Two SPI-only commands
* Status bits used native to SPI: R1_SPI_*, R2_SPI_*

- Fix a few (unrelated) whitespace bugs in the headers.

None of these changes affects current code.

---
 include/linux/mmc/core.h |   21 ++++++++++++++++++--
 include/linux/mmc/host.h |    4 +++
 include/linux/mmc/mmc.h  |   48 ++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 64 insertions(+), 9 deletions(-)
include/linux/mmc/host.h +4 -0
@@ -90,6 +90,8 @@ struct mmc_host {
 #define MMC_CAP_BYTEBLOCK	(1 << 2)	/* Can do non-log2 block sizes */
 #define MMC_CAP_MMC_HIGHSPEED	(1 << 3)	/* Can do MMC high-speed timing */
 #define MMC_CAP_SD_HIGHSPEED	(1 << 4)	/* Can do SD high-speed timing */
+#define MMC_CAP_SPI		(1 << 5)	/* Talks only SPI protocols */
+#define MMC_CAP_SPI_CRC		(1 << 6)	/* Handles CRC option in SPI */
 
 	/* host specific block data */
 	unsigned int		max_seg_size;	/* see blk_queue_max_segment_size */
@@ -137,6 +139,8 @@ static inline void *mmc_priv(struct mmc_
 	return (void *)host->private;
 }
 
+#define mmc_host_is_spi(host)	((host)->caps & MMC_CAP_SPI)
+
 #define mmc_dev(x)	((x)->parent)
 #define mmc_classdev(x)	(&(x)->class_dev)
 #define mmc_hostname(x)	((x)->class_dev.bus_id)
include/linux/mmc/core.h +19 -2
@@ -25,14 +25,19 @@ struct mmc_command {
 #define MMC_RSP_CRC	(1 << 2)		/* expect valid crc */
 #define MMC_RSP_BUSY	(1 << 3)		/* card may send busy */
 #define MMC_RSP_OPCODE	(1 << 4)		/* response contains opcode */
-#define MMC_CMD_MASK	(3 << 5)		/* command type */
+
+#define MMC_CMD_MASK	(3 << 5)		/* non-SPI command type */
 #define MMC_CMD_AC	(0 << 5)
 #define MMC_CMD_ADTC	(1 << 5)
 #define MMC_CMD_BC	(2 << 5)
 #define MMC_CMD_BCR	(3 << 5)
 
+#define MMC_RSP_SPI_S1	(1 << 7)		/* one status byte */
+#define MMC_RSP_SPI_S2	(1 << 8)		/* second status byte */
+#define MMC_RSP_SPI_OCR	(1 << 9)		/* OCR */
+
 /*
- * These are the response types, and correspond to valid bit
+ * These are the native response types, and correspond to valid bit
  * patterns of the above flags.  One additional valid pattern
  * is all zeros, which means we don't expect a response.
  */
@@ -47,6 +52,18 @@ struct mmc_command {
 #define mmc_resp_type(cmd)	((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
 
 /*
+ * These are the SPI response types.  Commands return R1, with maybe
+ * more info.  Zero is an invalid type, meaning that the caller
+ * forgot to say which response type applies to this command.
+ */
+#define MMC_RSP_SPI_R1	(MMC_RSP_SPI_S1)
+#define MMC_RSP_SPI_R1B	(MMC_RSP_SPI_S1|MMC_RSP_BUSY)
+#define MMC_RSP_SPI_R2	(MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
+#define MMC_RSP_SPI_R3	(MMC_RSP_SPI_S1|MMC_RSP_SPI_OCR)
+
+#define mmc_spi_resp_type(cmd)	((cmd)->flags & (MMC_RSP_SPI_S1|MMC_RSP_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_OCR))
+
+/*
  * These are the command types.
  */
 #define mmc_cmd_type(cmd)	((cmd)->flags & MMC_CMD_MASK)
include/linux/mmc/mmc.h +41 -7

88 lines not on this page · raw message

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706101305.53151.david-b-yBeKhBN/[email protected]

#4 lore raw

Re: [patch 1/4] MMC-over-SPI header updates

Quoted 26 lines · David Brownell

Teach the MMC/SD/SDIO system headers that some hosts use SPI mode

- New host capabilities bits
* MMC_CAP_SPI, with mmc_host_is_spi() test
* MMC_CAP_SPI_CRC, if it's ready to use CRCs

- SPI-specific declarations:
* Response types, MMC_RSP_SPI_R*
* Two SPI-only commands
* Status bits used native to SPI: R1_SPI_*, R2_SPI_*

- Fix a few (unrelated) whitespace bugs in the headers.

None of these changes affects current code.

---
 include/linux/mmc/core.h |   21 ++++++++++++++++++--
 include/linux/mmc/host.h |    4 +++
 include/linux/mmc/mmc.h  |   48 ++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 64 insertions(+), 9 deletions(-)

include/linux/mmc/host.h struct mmc_host { · line 97

Quoted 8 lines
include/linux/mmc/host.h +2 -0
@@ -90,6 +90,8 @@ struct mmc_host {
 #define MMC_CAP_BYTEBLOCK	(1 << 2)	/* Can do non-log2 block sizes */
 #define MMC_CAP_MMC_HIGHSPEED	(1 << 3)	/* Can do MMC high-speed timing */
 #define MMC_CAP_SD_HIGHSPEED	(1 << 4)	/* Can do SD high-speed timing */
+#define MMC_CAP_SPI		(1 << 5)	/* Talks only SPI protocols */
+#define MMC_CAP_SPI_CRC		(1 << 6)	/* Handles CRC option in SPI */
 
 	/* host specific block data */
 	unsigned int		max_seg_size;	/* see blk_queue_max_segment_size */

I still don't see the point of the SPI_CRC cap. It's not like we will have multiple SPI host drivers, so either we support CRC or we don't. No need to have this dynamic.

include/linux/mmc/host.h

Quoted 5 lines
include/linux/mmc/host.h +4 -0
+#define MMC_RSP_SPI_S1	(1 << 7)		/* one status byte */
+#define MMC_RSP_SPI_S2	(1 << 8)		/* second status byte */
+#define MMC_RSP_SPI_OCR	(1 << 9)		/* OCR */
+

You should describe form, not contents. The host driver shouldn't care what's in the chunks, only how they need to be transferred. So size and things like CRC, but not their meaning.

include/linux/mmc/host.h

Quoted 12 lines
include/linux/mmc/host.h +11 -0
+#define R1_STATE_IDLE		0		/* resetting; maybe opendrain */
+#define R1_STATE_READY		1		/* opendrain; ident soon */
+#define R1_STATE_IDENT		2		/* opendrain; setaddr soon */
+#define R1_STATE_STBY		3		/* addressed, ready to use */
+#define R1_STATE_TRAN		4
+#define R1_STATE_DATA		5
+#define R1_STATE_RCV		6
+#define R1_STATE_PRG		7
+#define R1_STATE_DIS		8
+#define R1_STATE(x)		(((x) & 0xf) << 9)
+

This seems to be for the mapping voodoo in the spi host. And that is not something we want, so this is not needed.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [patch 1/4] MMC-over-SPI header updates

Quoted 14 lines · Pierre Ossman
Quoted 13 lines · David Brownell

Teach the MMC/SD/SDIO system headers that some hosts use SPI mode

...

include/linux/mmc/host.h +2 -0
@@ -90,6 +90,8 @@ struct mmc_host {
 #define MMC_CAP_BYTEBLOCK	(1 << 2)	/* Can do non-log2 block sizes */
 #define MMC_CAP_MMC_HIGHSPEED	(1 << 3)	/* Can do MMC high-speed timing */
 #define MMC_CAP_SD_HIGHSPEED	(1 << 4)	/* Can do SD high-speed timing */
+#define MMC_CAP_SPI		(1 << 5)	/* Talks only SPI protocols */
+#define MMC_CAP_SPI_CRC		(1 << 6)	/* Handles CRC option in SPI */
 
Quoted 6 lines

include/linux/mmc/host.h struct mmc_host { · line 97

Quoted 2 lines
include/linux/mmc/host.h +0 -0
 	/* host specific block data */
 	unsigned int		max_seg_size;	/* see blk_queue_max_segment_size */

I still don't see the point of the SPI_CRC cap. It's not like we will have multiple SPI host drivers, so either we support CRC or we don't. No need to have this dynamic.

The point is that this way we can keep the host driver out of the business of deciding whether or not to enable CRC mode. The main alternative would be to move that module parameter into the MMC core.

Quoted 8 lines

include/linux/mmc/host.h

Quoted 4 lines
include/linux/mmc/host.h +4 -0
+#define MMC_RSP_SPI_S1	(1 << 7)		/* one status byte */
+#define MMC_RSP_SPI_S2	(1 << 8)		/* second status byte */
+#define MMC_RSP_SPI_OCR	(1 << 9)		/* OCR */
+

You should describe form, not contents. The host driver shouldn't care what's in the chunks, only how they need to be transferred. So size and things like CRC, but not their meaning.

This directly matches every MMC spec I've seen ... they define the response format in those terms. And I made this change per your request ... the host driver checks for "R1", "R2", etc which are built up from those components.

I'll note that the "native" bits include meaning too ... opcode is most certainly meaning, as is CRC.

Quoted 6 lines
Quoted 6 lines
include/linux/mmc/host.h +6 -0
+#define R1_STATE_IDLE		0		/* resetting; maybe opendrain */
+#define R1_STATE_READY		1		/* opendrain; ident soon */
+#define R1_STATE_IDENT		2		/* opendrain; setaddr soon */
+#define R1_STATE_STBY		3		/* addressed, ready to use */
+#define R1_STATE_TRAN		4
+#define R1_STATE_DATA		5
Quoted 8 lines

include/linux/mmc/host.h

Quoted 5 lines
include/linux/mmc/host.h +5 -0
+#define R1_STATE_RCV		6
+#define R1_STATE_PRG		7
+#define R1_STATE_DIS		8
+#define R1_STATE(x)		(((x) & 0xf) << 9)
+

This seems to be for the mapping voodoo in the spi host. And that is not something we want, so this is not needed.

OK, I can remove that stuff now that the raw SPI status bytes are being returned in resp[] ... I'll have to update the spi_mmc driver though, and I'll hold off on that for a bit since I expect you'll send comments specifically on that driver.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706121106.42067.david-b-yBeKhBN/[email protected]

#8 lore raw

Re: [patch 1/4] MMC-over-SPI header updates

Quoted 5 lines · David Brownell

The point is that this way we can keep the host driver out of the business of deciding whether or not to enable CRC mode. The main alternative would be to move that module parameter into the MMC core.

Why would we want to turn it off?

Quoted 5 lines

This directly matches every MMC spec I've seen ... they define the response format in those terms. And I made this change per your request ... the host driver checks for "R1", "R2", etc which are built up from those components.

The components we defined for native mode cannot be found in the specs, we derived them from the descriptions. So the same thing goes for SPI.

The point of this exercise is that we do not have to modify host drivers when new response types show up (which it has when MMC got extended to SD, and SD to SDIO).

So when R666 shows up, which happens to contain the anti-christ and be 5 bytes long, we can describe this using existing defines and not have to modify the host drivers. Having a name like "OCR" then does not describe properly what we want the host to do.

Quoted 3 lines

I'll note that the "native" bits include meaning too ... opcode is most certainly meaning, as is CRC.

Granted, this is a bit fuzzy in some areas. These two are sometimes not reported by hw, we can only tell it to check that they are correct. And there is no real variation what we want to do with these values. Compare that to the payload where it is difficult, if not impossible, for the host driver to determine what we want to do with it.

Just trust me on this, we do _not_ want semantics in the host drivers. It has caused problems with at least three host drivers so far, and omap is still unable to use SD cards because it tries to parse responses by itself.

The rule of thumb is, data the core wants back should not be parsed by the host driver. Things the core just wants validated is ok to parse in the host driver.

Quoted 6 lines

OK, I can remove that stuff now that the raw SPI status bytes are being returned in resp[] ... I'll have to update the spi_mmc driver though, and I'll hold off on that for a bit since I expect you'll send comments specifically on that driver.

Great. I'll ignore the mapping parts in there for now then and review the rest of the code.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Re: [patch 1/4] MMC-over-SPI header updates

Quoted 7 lines · Pierre Ossman
Quoted 4 lines · David Brownell

The point is that this way we can keep the host driver out of the business of deciding whether or not to enable CRC mode. The main alternative would be to move that module parameter into the MMC core.

Why would we want to turn it off?

It starts "off", and needs to be turned "on". Reasons to leave it off include performance (I measured over 30% slower with CRCs on while writing a 120+ MB SD partition), and of course the fact that the CRC stuff is the very newest feature in the code (thanks Jan!), and is not yet as trustworthy (viz. the intermittent bug I noted).

Quoted 7 lines
Quoted 4 lines

This directly matches every MMC spec I've seen ... they define the response format in those terms. And I made this change per your request ... the host driver checks for "R1", "R2", etc which are built up from those components.

The components we defined for native mode cannot be found in the specs, we derived them from the descriptions. So the same thing goes for SPI.

Umm ... no, not really; did you cross-check with the SPI specs? All the requests return one status byte. One returns a second one. One returns the OCR in the place that second byte would be. Some leave the chip in a "busy" state. Those are the components out of which the SPI_R1, SPI_R1B, SPI_R2, and SPI_R3 are built. (R3 is the one which includes OCR.)

Quoted 3 lines

The point of this exercise is that we do not have to modify host drivers when new response types show up (which it has when MMC got extended to SD, and SD to SDIO).

That seems like a fantasy to me. We don't know in advance how those types will be defined (or if they even will be!), so there's no way we can know whether or not new types will need to be defined.

In fact it's almost certain that we *would* have to change that low level protocol code to understand additional response types. The handling for them has to be hand coded in all cases...

Quoted 4 lines

So when R666 shows up, which happens to contain the anti-christ and be 5 bytes long, we can describe this using existing defines and not have to modify the host drivers. Having a name like "OCR" then does not describe properly what we want the host to do.

Leaving the semantic question of where those 5 bytes would need to be stored. Clearly since it was defined as a new response type, the answer used for R3 would not be appropriate... and R3 is the only 5 byte response currently defined.

Quoted 9 lines
Quoted 3 lines

I'll note that the "native" bits include meaning too ... opcode is most certainly meaning, as is CRC.

Granted, this is a bit fuzzy in some areas. These two are sometimes not reported by hw, we can only tell it to check that they are correct. And there is no real variation what we want to do with these values. Compare that to the payload where it is difficult, if not impossible, for the host driver to determine what we want to do with it.

You're missing the point that those values you're objecting to are fully defined as part of the protocol, so we *DO* know exactly what to do ...

Quoted 3 lines

Just trust me on this, we do _not_ want semantics in the host drivers. It has caused problems with at least three host drivers so far, and omap is still unable to use SD cards because it tries to parse responses by itself.

This isn't the OMAP driver though. And I can't exactly make sense of the guts of your objection (see next).

Quoted 2 lines

The rule of thumb is, data the core wants back should not be parsed by the host driver. Things the core just wants validated is ok to parse in the host driver.

That's a fine policy. (Though I've observed that most policies driving interface design need to be broken sometimes.)

You've objected surprisingly vociferously ... given that so far as I understand what you mean, that's the exact rule now followed in the mmc_spi host driver!

Quoted 9 lines
Quoted 6 lines

OK, I can remove that stuff now that the raw SPI status bytes are being returned in resp[] ... I'll have to update the spi_mmc driver though, and I'll hold off on that for a bit since I expect you'll send comments specifically on that driver.

Great. I'll ignore the mapping parts in there for now then and review the rest of the code.

Well, the R1_STATE bits of the mapping.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706131433.21238.david-b-yBeKhBN/[email protected]

#12 lore raw

Re: [patch 1/4] MMC-over-SPI header updates

Quoted 7 lines · David Brownell

It starts "off", and needs to be turned "on". Reasons to leave it off include performance (I measured over 30% slower with CRCs on while writing a 120+ MB SD partition), and of course the fact that the CRC stuff is the very newest feature in the code (thanks Jan!), and is not yet as trustworthy (viz. the intermittent bug I noted).

Any CRC bugs should surface rather quickly, so that shouldn't be an isse. Performance might be though, but do people really feel that those 30% is worth losing CRC? I sure wouldn't feel comfortable with that.

Quoted 8 lines

Umm ... no, not really; did you cross-check with the SPI specs? All the requests return one status byte. One returns a second one. One returns the OCR in the place that second byte would be. Some leave the chip in a "busy" state. Those are the components out of which the SPI_R1, SPI_R1B, SPI_R2, and SPI_R3 are built. (R3 is the one which includes OCR.)

But the controller will be fine just knowing "one byte", "two bytes" and "five bytes" respectively.

Quoted 11 lines

That seems like a fantasy to me. We don't know in advance how those types will be defined (or if they even will be!), so there's no way we can know whether or not new types will need to be defined.

In fact it's almost certain that we *would* have to change that low level protocol code to understand additional response types. The handling for them has to be hand coded in all cases...

From experience, I'd say it's likely that formats are reused. Looking at native

mode, we originally had R1, R1b, R2 and R3. Yet we are now able to support R4 through R7 using the components already defined.

Quoted 6 lines

Leaving the semantic question of where those 5 bytes would need to be stored. Clearly since it was defined as a new response type, the answer used for R3 would not be appropriate... and R3 is the only 5 byte response currently defined.

Why not? It's not like we store R1 and R2 differently except for their size.

Quoted 4 lines

You're missing the point that those values you're objecting to are fully defined as part of the protocol, so we *DO* know exactly what to do ...

My point is that we're spreading that knowledge into too many areas. Keep it in the core and let the host driver deal with shuffling bits.

Quoted 3 lines

Well, the R1_STATE bits of the mapping.

All mappings. The host driver shouldn't lie to the core.

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

Re: [patch 1/4] MMC-over-SPI header updates

Quoted 10 lines · Pierre Ossman
Quoted 7 lines · David Brownell

It starts "off", and needs to be turned "on". Reasons to leave it off include performance (I measured over 30% slower with CRCs on while writing a 120+ MB SD partition), and of course the fact that the CRC stuff is the very newest feature in the code (thanks Jan!), and is not yet as trustworthy (viz. the intermittent bug I noted).

Any CRC bugs should surface rather quickly, so that shouldn't be an isse.

Surfaced != fixed. The issue is that resolving them isn't all that straightforward. There's that one issue I surfaced, for example; it turns up some nasty recovery issues wholly unrelated to CRCs.

Quoted 2 lines

Performance might be though, but do people really feel that those 30% is worth losing CRC? I sure wouldn't feel comfortable with that.

If *you* want CRCs, then don't use the "use_crc=n" module option. The stack is usable without them; most hardware isn't glitchey enough to need them as more than a safety blanket.

Eventually, performance tuning should reduce that penalty, but until then the option is certainly in the "must have" category for at least developers.

Quoted 8 lines
Quoted 4 lines

That seems like a fantasy to me. We don't know in advance how those types will be defined (or if they even will be!), so there's no way we can know whether or not new types will need to be defined.
...

From experience, I'd say it's likely that formats are reused. Looking at native mode, we originally had R1, R1b, R2 and R3. Yet we are now able to support R4 through R7 using the components already defined.

You had to define new types, and update the code to use them. It was nice of the spec writers to make that easy for you, but you can't rely on that happening every time.

It seems like the new SDHC stuff has only one significant change affecting SPI: there are now two requests which return a status byte plus four data bytes. One uses the previously defined R3 response type. The other uses a newly defined R7 type.

So it seems like that particular issue can be addressed by morphing the current MMC_RSP_SPI_OCR code into an MMC_RSP_SPI_4BYTE type, along the lines of what you were talking about.

Quoted 4 lines
Quoted 2 lines

Well, the R1_STATE bits of the mapping.

All mappings. The host driver shouldn't lie to the core.

Mappings aren't lies though. It's more like translation: you can say something in French or in English, and get across the same core meaning. To get certain details you'll want the original language ... but that doesn't mean the translation was a lie.

That said, I'd be glad to eventually see those R1 mappings begone, when the core stops needing them.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706161150.58273.david-b-yBeKhBN/[email protected]

#16 lore raw

Re: [patch 1/4] MMC-over-SPI header updates

Quoted 7 lines · David Brownell
Quoted 1 line · Pierre Ossman

Any CRC bugs should surface rather quickly, so that shouldn't be an isse.

Surfaced != fixed. The issue is that resolving them isn't all that straightforward. There's that one issue I surfaced, for example; it turns up some nasty recovery issues wholly unrelated to CRCs.

I still think we should have the ambition that this can be made to work. We can always remove it if that proves impossible (or not worth the effort).

Quoted 5 lines

If *you* want CRCs, then don't use the "use_crc=n" module option. The stack is usable without them; most hardware isn't glitchey enough to need them as more than a safety blanket.

Silent data loss gives me the willies.

Quoted 4 lines

Eventually, performance tuning should reduce that penalty, but until then the option is certainly in the "must have" category for at least developers.

Fair enough.

Quoted 8 lines
Quoted 3 lines

From experience, I'd say it's likely that formats are reused. Looking at native mode, we originally had R1, R1b, R2 and R3. Yet we are now able to support R4 through R7 using the components already defined.

You had to define new types, and update the code to use them. It was nice of the spec writers to make that easy for you, but you can't rely on that happening every time.

You act like that happen by dumb luck. I'd say they looked at the existing spec and designed the new features in a way that reused as much as possible. Sound engineering really.

Quoted 10 lines

It seems like the new SDHC stuff has only one significant change affecting SPI: there are now two requests which return a status byte plus four data bytes. One uses the previously defined R3 response type. The other uses a newly defined R7 type.

So it seems like that particular issue can be addressed by morphing the current MMC_RSP_SPI_OCR code into an MMC_RSP_SPI_4BYTE type, along the lines of what you were talking about.

My point exactly. I see no point in _OCR, but there is a possible gain with _4BYTE (in the worst case, we get the same thing as if we'd done _OCR).

Quoted 7 lines

Mappings aren't lies though. It's more like translation: you can say something in French or in English, and get across the same core meaning. To get certain details you'll want the original language ... but that doesn't mean the translation was a lie.

You can't really compare computer protocols to human language. The level of precision differs greatly.

Since you can't do a pure substitution, you have to simplify or try to guess data. Both cases are accidents waiting to happen since the core is coded on the assumption that the values reported are 100% correct.

Quoted 3 lines

That said, I'd be glad to eventually see those R1 mappings begone, when the core stops needing them.

So change the core.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#18 lore raw

Re: [patch 1/4] MMC-over-SPI header updates

Quoted 10 lines · Pierre Ossman
Quoted 6 lines · David Brownell
Quoted 1 line · Pierre Ossman

Any CRC bugs should surface rather quickly, so that shouldn't be an isse.

Surfaced != fixed. The issue is that resolving them isn't all that straightforward. There's that one issue I surfaced, for example; it turns up some nasty recovery issues wholly unrelated to CRCs.

I still think we should have the ambition that this can be made to work. We can always remove it if that proves impossible (or not worth the effort).

And I never disagreed with that.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

#19 lore raw

PATCH 2/4 MMC-over-SPI card driver update

In reply to a message not in the archive

Teaching the MMC/SD block card driver about SPI.

- Provide the SPI response type flags with each request issued. The model is that if no such flags are provided, it will be rejected by the MMC-over-SPI host.

- Understand that multiblock SPI writes don't use STOP_TRANSMISSION.

---
 drivers/mmc/card/block.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/mmc/card/block.c +13 -7
@@ -151,7 +151,7 @@ static u32 mmc_sd_num_wr_blocks(struct m
 
 	cmd.opcode = MMC_APP_CMD;
 	cmd.arg = card->rca << 16;
-	cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+	cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
 
 	err = mmc_wait_for_cmd(card->host, &cmd, 0);
 	if ((err != MMC_ERR_NONE) || !(cmd.resp[0] & R1_APP_CMD))
@@ -161,7 +161,7 @@ static u32 mmc_sd_num_wr_blocks(struct m
 
 	cmd.opcode = SD_APP_SEND_NUM_WR_BLKS;
 	cmd.arg = 0;
-	cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
+	cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
 
 	memset(&data, 0, sizeof(struct mmc_data));
 
@@ -220,11 +220,11 @@ static int mmc_blk_issue_rq(struct mmc_q
 		brq.cmd.arg = req->sector;
 		if (!mmc_card_blockaddr(card))
 			brq.cmd.arg <<= 9;
-		brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
+		brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
 		brq.data.blksz = 1 << md->block_bits;
 		brq.stop.opcode = MMC_STOP_TRANSMISSION;
 		brq.stop.arg = 0;
-		brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
+		brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
 		brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
 		if (brq.data.blocks > card->host->max_blk_count)
 			brq.data.blocks = card->host->max_blk_count;
@@ -244,7 +244,12 @@ static int mmc_blk_issue_rq(struct mmc_q
 
 		if (brq.data.blocks > 1) {
 			brq.data.flags |= MMC_DATA_MULTI;
-			brq.mrq.stop = &brq.stop;
+			/* SPI multiblock writes terminate using a special
+			 * token, not a STOP_TRANSMISSION request.
+			 */
+			if (!mmc_host_is_spi(card->host)
+					|| rq_data_dir(req) == READ)
+				brq.mrq.stop = &brq.stop;
 			readcmd = MMC_READ_MULTIPLE_BLOCK;
 			writecmd = MMC_WRITE_MULTIPLE_BLOCK;
 		} else {
@@ -308,7 +313,8 @@ static int mmc_blk_issue_rq(struct mmc_q
 
 				cmd.opcode = MMC_SEND_STATUS;
 				cmd.arg = card->rca << 16;
-				cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+				cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1
+						| MMC_CMD_AC;
 				err = mmc_wait_for_cmd(card->host, &cmd, 5);
 				if (err) {
 					printk(KERN_ERR "%s: error %d requesting status\n",
@@ -511,7 +517,7 @@ mmc_blk_set_blksize(struct mmc_blk_data 
 	mmc_claim_host(card->host);
 	cmd.opcode = MMC_SET_BLOCKLEN;
 	cmd.arg = 1 << md->block_bits;
-	cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+	cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
 	err = mmc_wait_for_cmd(card->host, &cmd, 5);
 	mmc_release_host(card->host);
 

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706101306.39081.david-b-yBeKhBN/[email protected]

#21 lore raw

Re: [patch 2/4] MMC-over-SPI card driver update

Quoted 9 lines · David Brownell

Teaching the MMC/SD block card driver about SPI.

- Provide the SPI response type flags with each request issued. The model is that if no such flags are provided, it will be rejected by the MMC-over-SPI host.

- Understand that multiblock SPI writes don't use STOP_TRANSMISSION.

Looks ok.

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#22 lore raw

PATCH 3/4 MMC-over-SPI core updates

In reply to a message not in the archive

Teach the MMC/SD/SDIO core about using SPI mode.

- Use mmc_host_is_spi() so enumeration works through SPI protocols, not just the native (and sometimes parallel) ones

- Provide the SPI response type flags with each request issued, including rquests from the new lock/unlock code. The model is that if no such flags are provided, it will be rejected by the MMC-over-SPI host.

- Understand that some commands act a bit differently ... notably the OP_COND command doesn't return the OCR, and does status differently.

Those changes required some new and updated primitives:

- Provide utilities to access two SPI-only requests, and one request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only
* mmc_spi_send_cid() ... works without broadcast mode

- Updated internal routines:
* previous mmc_send_csd() modified into mmc_send_cxd_native(); it uses native "R2" responses, which include 16 bytes of data.
* previous mmc_send_ext_csd() becomes new mmc_send_cxd_data() helper for command-and-data access

- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper

- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use those helper routines based on whether they're native or SPI

The current assumption is that nobody will want a controller driver to handle both SPI *and* the faster "native" MMC/SD protocols, even on hardware which can do that.

The SPI support hasn't been tested on the new MMC4 cards (they're not widely available) or with the new card lock/unlock mechanism. Likewise SD cards with 4GB and up may have surprises lurking.

---
 drivers/mmc/core/core.c    |   38 ++++++++-
 drivers/mmc/core/mmc.c     |   26 ++++--
 drivers/mmc/core/mmc_ops.c |  173 +++++++++++++++++++++++++++++++++++----------
 drivers/mmc/core/mmc_ops.h |    4 +
 drivers/mmc/core/sd.c      |   36 ++++++---
 drivers/mmc/core/sd_ops.c  |   17 +++-
 6 files changed, 226 insertions(+), 68 deletions(-)
drivers/mmc/core/mmc_ops.h +4 -0
@@ -26,5 +26,9 @@ int mmc_switch(struct mmc_card *card, u8
 int mmc_send_status(struct mmc_card *card, u32 *status);
 int mmc_lock_unlock(struct mmc_card *card, struct key *key, int mode);
 
+int mmc_spi_send_cid(struct mmc_host *host, u32 *cid);
+int mmc_spi_read_ocr(struct mmc_host *host, u32 *ocrp);
+int mmc_spi_set_crc(struct mmc_host *host);
+
 #endif
 
drivers/mmc/core/core.c +31 -7
@@ -386,8 +386,13 @@ static void mmc_power_up(struct mmc_host
 	int bit = fls(host->ocr_avail) - 1;
 
 	host->ios.vdd = bit;
-	host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
-	host->ios.chip_select = MMC_CS_DONTCARE;
+	if (mmc_host_is_spi(host)) {
+		host->ios.chip_select = MMC_CS_HIGH;
+		host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
+	} else {
+		host->ios.chip_select = MMC_CS_DONTCARE;
+		host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
+	}
 	host->ios.power_mode = MMC_POWER_UP;
 	host->ios.bus_width = MMC_BUS_WIDTH_1;
 	host->ios.timing = MMC_TIMING_LEGACY;
@@ -406,8 +411,10 @@ static void mmc_power_off(struct mmc_hos
 {
 	host->ios.clock = 0;
 	host->ios.vdd = 0;
-	host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
-	host->ios.chip_select = MMC_CS_DONTCARE;
+	if (!mmc_host_is_spi(host)) {
+		host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
+		host->ios.chip_select = MMC_CS_DONTCARE;
+	}
 	host->ios.power_mode = MMC_POWER_OFF;
 	host->ios.bus_width = MMC_BUS_WIDTH_1;
 	host->ios.timing = MMC_TIMING_LEGACY;
@@ -498,6 +505,19 @@ void mmc_detect_change(struct mmc_host *
 EXPORT_SYMBOL(mmc_detect_change);
 
 
+static int mmc_spi_fixup(struct mmc_host *host, u32 *ocrp)
+{
+	int err;
+
+	if (!mmc_host_is_spi(host))
+		return MMC_ERR_NONE;
+
+	err = mmc_spi_read_ocr(host, ocrp);
+	if (err == MMC_ERR_NONE);
+		err = mmc_spi_set_crc(host);
+	return err;
+}
+
 void mmc_rescan(struct work_struct *work)
 {
 	struct mmc_host *host =
@@ -519,11 +539,13 @@ void mmc_rescan(struct work_struct *work
 		mmc_power_up(host);
 		mmc_go_idle(host);
 
-		mmc_send_if_cond(host, host->ocr_avail);
+		if (!mmc_host_is_spi(host))
+			mmc_send_if_cond(host, host->ocr_avail);
 
 		err = mmc_send_app_op_cond(host, 0, &ocr);
 		if (err == MMC_ERR_NONE) {
-			if (mmc_attach_sd(host, ocr))
+			err = mmc_spi_fixup(host, &ocr);
+			if (err != MMC_ERR_NONE || mmc_attach_sd(host, ocr))
 				mmc_power_off(host);
 		} else {
 			/*
@@ -532,7 +554,9 @@ void mmc_rescan(struct work_struct *work
 			 */
 			err = mmc_send_op_cond(host, 0, &ocr);
 			if (err == MMC_ERR_NONE) {
-				if (mmc_attach_mmc(host, ocr))
+				err = mmc_spi_fixup(host, &ocr);
+				if (err != MMC_ERR_NONE
+						|| mmc_attach_mmc(host, ocr))
 					mmc_power_off(host);
 			} else {
 				mmc_power_off(host);
drivers/mmc/core/mmc_ops.c +137 -36

291 lines not on this page · raw message

drivers/mmc/core/mmc.c +17 -9
@@ -320,9 +320,15 @@ static int mmc_init_card(struct mmc_host
 	/*
 	 * Fetch CID from card.
 	 */
-	err = mmc_all_send_cid(host, cid);
-	if (err != MMC_ERR_NONE)
-		goto err;
+	if (mmc_host_is_spi(host)) {
+		err = mmc_spi_send_cid(host, cid);
+		if (err != MMC_ERR_NONE)
+			goto err;
+	} else {
+		err = mmc_all_send_cid(host, cid);
+		if (err != MMC_ERR_NONE)
+			goto err;
+	}
 
 	if (oldcard) {
 		if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
@@ -343,13 +349,15 @@ static int mmc_init_card(struct mmc_host
 	}
 
 	/*
-	 * Set card RCA.
+	 * For native busses:  set card RCA and leave open drain mode.
 	 */
-	err = mmc_set_relative_addr(card);
-	if (err != MMC_ERR_NONE)
-		goto free_card;
+	if (!mmc_host_is_spi(host)) {
+		err = mmc_set_relative_addr(card);
+		if (err != MMC_ERR_NONE)
+			goto free_card;
 
-	mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
+		mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
+	}
 
 	/*
 	 * Check if card is locked.
@@ -385,7 +393,7 @@ static int mmc_init_card(struct mmc_host
 
 	if (!oldcard) {
 		/*
-		 * Fetch and process extened CSD.
+		 * Fetch and process extended CSD.
 		 */
 		err = mmc_read_ext_csd(card);
 		if (err != MMC_ERR_NONE)
drivers/mmc/core/sd.c +25 -11
@@ -379,9 +379,19 @@ static int mmc_sd_init_card(struct mmc_h
 	/*
 	 * Fetch CID from card.
 	 */
-	err = mmc_all_send_cid(host, cid);
-	if (err != MMC_ERR_NONE)
-		goto err;
+	if (mmc_host_is_spi(host)) {
+		err = mmc_spi_set_crc(host);
+		if (err != MMC_ERR_NONE)
+			goto err;
+		err = mmc_spi_send_cid(host, cid);
+		if (err != MMC_ERR_NONE)
+			goto err;
+	} else {
+		err = mmc_all_send_cid(host, cid);
+		if (err != MMC_ERR_NONE)
+			goto err;
+	}
+
 
 	if (oldcard) {
 		if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
@@ -401,13 +411,15 @@ static int mmc_sd_init_card(struct mmc_h
 	}
 
 	/*
-	 * Set card RCA.
+	 * For native busses:  set card RCA and leave open drain mode.
 	 */
-	err = mmc_send_relative_addr(host, &card->rca);
-	if (err != MMC_ERR_NONE)
-		goto free_card;
+	if (!mmc_host_is_spi(host)) {
+		err = mmc_send_relative_addr(host, &card->rca);
+		if (err != MMC_ERR_NONE)
+			goto free_card;
 
-	mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
+		mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
+	}
 
 	/*
 	 * Check if card is locked.
@@ -455,9 +467,11 @@ static int mmc_sd_init_card(struct mmc_h
 		/*
 		 * Fetch switch information from card.
 		 */
-		err = mmc_read_switch(card);
-		if (err != MMC_ERR_NONE)
-			goto free_card;
+		if (!mmc_host_is_spi(host)) {
+			err = mmc_read_switch(card);
+			if (err != MMC_ERR_NONE)
+				goto free_card;
+		}
 	}
 
 	/*
drivers/mmc/core/sd_ops.c +12 -5
@@ -89,10 +89,10 @@ int mmc_app_cmd(struct mmc_host *host, s
 
 	if (card) {
 		cmd.arg = card->rca << 16;
-		cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+		cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
 	} else {
 		cmd.arg = 0;
-		cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR;
+		cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_BCR;
 	}
 
 	err = mmc_wait_for_cmd(host, &cmd, 0);
@@ -148,14 +148,18 @@ int mmc_send_app_op_cond(struct mmc_host
 
 	cmd.opcode = SD_APP_OP_COND;
 	cmd.arg = ocr;
-	cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
+	cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
 
 	for (i = 100; i; i--) {
 		err = mmc_wait_for_app_cmd(host, NULL, &cmd, MMC_CMD_RETRIES);
 		if (err != MMC_ERR_NONE)
 			break;
 
-		if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
+		if (mmc_host_is_spi(host)) {
+			/* wait until reset completes */
+			if (!(cmd.resp[2] & R1_SPI_IDLE))
+				break;
+		} else if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
 			break;
 
 		err = MMC_ERR_TIMEOUT;
@@ -175,6 +179,9 @@ int mmc_send_if_cond(struct mmc_host *ho
 	int err;
 	static const u8 test_pattern = 0xAA;
 
+	if (mmc_host_is_spi(host))
+		return MMC_ERR_FAILED;
+
 	/*
 	 * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND
 	 * before SD_APP_OP_COND. This command will harmlessly fail for
@@ -242,7 +249,7 @@ int mmc_app_send_scr(struct mmc_card *ca
 
 	cmd.opcode = SD_APP_SEND_SCR;
 	cmd.arg = 0;
-	cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
+	cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
 
 	data.blksz = 8;
 	data.blocks = 1;

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706101307.11394.david-b-yBeKhBN/[email protected]

#24 lore raw

Re: [patch 3/4] MMC-over-SPI core updates

Quoted 10 lines · David Brownell
drivers/mmc/core/core.c +6 -0
@@ -498,6 +505,19 @@ void mmc_detect_change(struct mmc_host *
 EXPORT_SYMBOL(mmc_detect_change);
 
 
+static int mmc_spi_fixup(struct mmc_host *host, u32 *ocrp)
+{
+	int err;
+
+	if (!mmc_host_is_spi(host))
+		return MMC_ERR_NONE;

drivers/mmc/core/core.c void mmc_detect_change(struct mmc_host * · line 523

Quoted 10 lines
drivers/mmc/core/core.c +7 -0
+
+	err = mmc_spi_read_ocr(host, ocrp);
+	if (err == MMC_ERR_NONE);
+		err = mmc_spi_set_crc(host);
+	return err;
+}
+
 void mmc_rescan(struct work_struct *work)
 {
 	struct mmc_host *host =

I'd prefer if this is in mmc_rescan(). It's so little code that all this does is hide the init sequence.

drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work · line 544

Quoted 8 lines
drivers/mmc/core/core.c +2 -1
@@ -519,11 +539,13 @@ void mmc_rescan(struct work_struct *work
 		mmc_power_up(host);
 		mmc_go_idle(host);
 
-		mmc_send_if_cond(host, host->ocr_avail);
+		if (!mmc_host_is_spi(host))
+			mmc_send_if_cond(host, host->ocr_avail);
 

If you have a look at the SD physical spec (the public one), you'll see that if_cond is needed on SPI aswell. I know you don't have cards for testing, but let's code according to spec and try to find people who can test all parts.

drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work · line 551

Quoted 8 lines
drivers/mmc/core/core.c +2 -1
 		err = mmc_send_app_op_cond(host, 0, &ocr);
 		if (err == MMC_ERR_NONE) {
-			if (mmc_attach_sd(host, ocr))
+			err = mmc_spi_fixup(host, &ocr);
+			if (err != MMC_ERR_NONE || mmc_attach_sd(host, ocr))
 				mmc_power_off(host);
 		} else {
 			/*

Looking at the example flow charts in the specs, this is not the proper way. I've spent the morning staring at both specs in parallel, and here's how I think it should be done:

[CMD8 for SD]
CMD58 [with HCS bit for MMC]
ACMD51, OK -> SD
CMD1, OK -> MMC

The SD spec states that both ACMD51 and CMD1 is legal, but nothing about why both are supported. It also states that CMD1 has a bit indicating SDHC support (as if CMD8 isn't enough), but ACMD51 doesn't. But the flow charts show ACMD51, not CMD1. :/

The next step, in the bus handlers, will have to get the OCR on their own. SD states that the OCR is valid in the initial CMD58 (before CMD1/ACMD51), but MMC states that it is not. So for the sake of consistency, let both paths reissue a CMD58 for the OCR.

drivers/mmc/core/mmc_ops.c static int _mmc_select_card(struct mmc_h · line 40

Quoted 13 lines
drivers/mmc/core/mmc_ops.c +4 -0
@@ -31,6 +31,10 @@ static int _mmc_select_card(struct mmc_h
 
 	BUG_ON(!host);
 
+	/* SPI doesn't multiplex; "select" is meaningless */
+	if (mmc_host_is_spi(host))
+		return MMC_ERR_NONE;
+
 	memset(&cmd, 0, sizeof(struct mmc_command));
 
 	cmd.opcode = MMC_SELECT_CARD;

I do not like this. Unsupported commands shouldn't be issued. We should not have voodoo in here that makes them a no-op. That just obscures things. Feel free to put a check in there if you feel the risk is too great.

drivers/mmc/core/mmc_ops.c int mmc_set_relative_addr(struct mmc_car · line 214

Quoted 11 lines
drivers/mmc/core/mmc_ops.c +9 -1
-int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
+struct mmc_cxd {
+	struct mmc_card	*card;		/* optional */
+	void		*buf;
+	unsigned	len;
+	u32		opcode;
+	u32		arg;
+	unsigned	flags;
+};
+

This seems overly complex. You can do this with arguments as most of that struct is superfluous:

- card can be specified at all times if you reorg the init a bit, allowing you
to drop the host argument.

- arg and flags are the same for all three commands, so those can be dropped.

drivers/mmc/core/mmc_ops.c int mmc_send_ext_csd(struct mmc_card *ca · line 255

Quoted 6 lines
drivers/mmc/core/mmc_ops.c +2 -0
@@ -230,6 +251,85 @@ int mmc_send_ext_csd(struct mmc_card *ca
 	return MMC_ERR_NONE;
 }
 
+int mmc_spi_read_ocr(struct mmc_host *host, u32 *ocrp)
+{

How about moving these further down so that the mmc_send_cxd_data() users are right below it?

Also, the theme I've tried to have here is to take a card pointer whenever you operate on a specific card, and a host pointer for bus wide things. It adds a bit of readability.

Quoted 11 lines
drivers/mmc/core/mmc.c +2 -3
@@ -320,9 +320,15 @@ static int mmc_init_card(struct mmc_host
 	/*
 	 * Fetch CID from card.
 	 */
-	err = mmc_all_send_cid(host, cid);
-	if (err != MMC_ERR_NONE)
-		goto err;
+	if (mmc_host_is_spi(host)) {
+		err = mmc_spi_send_cid(host, cid);

drivers/mmc/core/mmc.c static int mmc_init_card(struct mmc_host · line 334

Quoted 10 lines
drivers/mmc/core/mmc.c +7 -0
+		if (err != MMC_ERR_NONE)
+			goto err;
+	} else {
+		err = mmc_all_send_cid(host, cid);
+		if (err != MMC_ERR_NONE)
+			goto err;
+	}
 
 	if (oldcard) {
 		if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)

This is entirely subjective, but wouldn't this be cleaner:

	if (mmc_host_is_spi(host))
		err = mmc_spi_send_cid(host, cid);
	else
		err = mmc_all_send_cid(host, cid);

	if (err != MMC_ERR_NONE)
		goto err;

It's fewer lines at least, which should make Linus happy. ;)

drivers/mmc/core/mmc.c static int mmc_sd_init_card(struct mmc_h · line 415

Quoted 7 lines
drivers/mmc/core/mmc.c +1 -1
@@ -401,13 +411,15 @@ static int mmc_sd_init_card(struct mmc_h
 	}
 
 	/*
-	 * Set card RCA.
+	 * For native busses:  set card RCA and leave open drain mode.
 	 */

While your in the processes of fixing my crappy comments, this command actually gets, not sends the RCA (SD is a bit backwards). :)

Quoted 5 lines
drivers/mmc/core/mmc.c +0 -1
@@ -455,9 +467,11 @@ static int mmc_sd_init_card(struct mmc_h
 		/*
 		 * Fetch switch information from card.
 		 */
-		err = mmc_read_switch(card);

drivers/mmc/core/mmc.c static int mmc_sd_init_card(struct mmc_h · line 477

Quoted 10 lines
drivers/mmc/core/mmc.c +5 -2
-		if (err != MMC_ERR_NONE)
-			goto free_card;
+		if (!mmc_host_is_spi(host)) {
+			err = mmc_read_switch(card);
+			if (err != MMC_ERR_NONE)
+				goto free_card;
+		}
 	}
 
 	/*

Don't you want high-speed on your SPI bus? ;)

Add a FIXME here if you don't have the cards to test this. Or implement it according to spec and wait for bug reports.

Quoted 5 lines
drivers/mmc/core/sd_ops.c +0 -0
@@ -89,10 +89,10 @@ int mmc_app_cmd(struct mmc_host *host, s
 
 	if (card) {

drivers/mmc/core/sd_ops.c int mmc_app_cmd(struct mmc_host *host, s · line 98

Quoted 10 lines
drivers/mmc/core/sd_ops.c +2 -2
 		cmd.arg = card->rca << 16;
-		cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+		cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
 	} else {
 		cmd.arg = 0;
-		cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR;
+		cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_BCR;
 	}
 
 	err = mmc_wait_for_cmd(host, &cmd, 0);

You also need to fix the check further down as SPI doesn't have a bit indicating if it toggled into ACMD mode.

drivers/mmc/core/sd_ops.c int mmc_send_if_cond(struct mmc_host *ho · line 187

Quoted 10 lines
drivers/mmc/core/sd_ops.c +3 -0
@@ -175,6 +179,9 @@ int mmc_send_if_cond(struct mmc_host *ho
 	int err;
 	static const u8 test_pattern = 0xAA;
 
+	if (mmc_host_is_spi(host))
+		return MMC_ERR_FAILED;
+
 	/*
 	 * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND
 	 * before SD_APP_OP_COND. This command will harmlessly fail for

See above, we need this for SDHC.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#26 lore raw

Re: [patch 3/4] MMC-over-SPI core updates

Quoted 16 lines · Pierre Ossman
Quoted 15 lines · David Brownell
drivers/mmc/core/core.c +11 -0
@@ -498,6 +505,19 @@ void mmc_detect_change(struct mmc_host *
 EXPORT_SYMBOL(mmc_detect_change);
 
 
+static int mmc_spi_fixup(struct mmc_host *host, u32 *ocrp)
+{
+	int err;
+
+	if (!mmc_host_is_spi(host))
+		return MMC_ERR_NONE;
+
+	err = mmc_spi_read_ocr(host, ocrp);
+	if (err == MMC_ERR_NONE);
+		err = mmc_spi_set_crc(host);
+	return err;
Quoted 8 lines

drivers/mmc/core/core.c void mmc_detect_change(struct mmc_host * · line 523

Quoted 5 lines
drivers/mmc/core/core.c +2 -0
+}
+
 void mmc_rescan(struct work_struct *work)
 {
 	struct mmc_host *host =

I'd prefer if this is in mmc_rescan(). It's so little code that all this does is hide the init sequence.

I can move it. I tried expanding it inline there, and thought the result was worse: (a) duplication, in both MMC and SD code paths; (b) it complicates otherwise-clean logic; (c) you had asked that the core patch be small.

You're quite sure you want those drawbacks ... ?

Quoted 4 lines
Quoted 4 lines
drivers/mmc/core/core.c +0 -0
@@ -519,11 +539,13 @@ void mmc_rescan(struct work_struct *work
 		mmc_power_up(host);
 		mmc_go_idle(host);
 
Quoted 8 lines

drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work · line 544

Quoted 4 lines
drivers/mmc/core/core.c +2 -1
-		mmc_send_if_cond(host, host->ocr_avail);
+		if (!mmc_host_is_spi(host))
+			mmc_send_if_cond(host, host->ocr_avail);
 

If you have a look at the SD physical spec (the public one), you'll see that if_cond is needed on SPI aswell. I know you don't have cards for testing, but let's code according to spec and try to find people who can test all parts.

I just grabbed a new version of that spec; the original omitted absolutely *everything* about SPI.

Quoted 13 lines

drivers/mmc/core/core.c void mmc_rescan(struct work_struct *work · line 551

Quoted 8 lines
drivers/mmc/core/core.c +2 -1
 		err = mmc_send_app_op_cond(host, 0, &ocr);
 		if (err == MMC_ERR_NONE) {
-			if (mmc_attach_sd(host, ocr))
+			err = mmc_spi_fixup(host, &ocr);
+			if (err != MMC_ERR_NONE || mmc_attach_sd(host, ocr))
 				mmc_power_off(host);
 		} else {
 			/*

Looking at the example flow charts in the specs, this is not the proper way. I've spent the morning staring at both specs in parallel, and here's how I think it should be done:

Quoted 4 lines

[CMD8 for SD]
CMD58 [with HCS bit for MMC]
ACMD51, OK -> SD
CMD1, OK -> MMC

I'll have to get back to you on that after I read that new SD doc.

Quoted 4 lines

The SD spec states that both ACMD51 and CMD1 is legal, but nothing about why both are supported. It also states that CMD1 has a bit indicating SDHC support (as if CMD8 isn't enough), but ACMD51 doesn't. But the flow charts show ACMD51, not CMD1. :/

I think it's the usual reason: ACMD fails on MMC, so use that early to sort out SD-vs-MMC. The Linux stack might be marginally quicker if that were the *ONLY* reason it used ACMD51.

Quoted 4 lines

The next step, in the bus handlers, will have to get the OCR on their own. SD states that the OCR is valid in the initial CMD58 (before CMD1/ACMD51), but MMC states that it is not. So for the sake of consistency, let both paths reissue a CMD58 for the OCR.

That's done in the spi_fixup() routine. ;)

I observed that some cards didn't like CMD58 (READ_OCR) until after the reset was done, although all the specs I have say that it's supposed to work while the reset is happening.

Quoted 12 lines
Quoted 12 lines
drivers/mmc/core/mmc_ops.c +4 -0
@@ -31,6 +31,10 @@ static int _mmc_select_card(struct mmc_h
 
 	BUG_ON(!host);
 
+	/* SPI doesn't multiplex; "select" is meaningless */
+	if (mmc_host_is_spi(host))
+		return MMC_ERR_NONE;
+
 	memset(&cmd, 0, sizeof(struct mmc_command));
 
Quoted 5 lines

drivers/mmc/core/mmc_ops.c static int _mmc_select_card(struct mmc_h · line 40

Quoted 1 line
drivers/mmc/core/mmc_ops.c +0 -0
 	cmd.opcode = MMC_SELECT_CARD;

I do not like this. Unsupported commands shouldn't be issued. We should not have voodoo in here that makes them a no-op. That just obscures things. Feel free to put a check in there if you feel the risk is too great.

Again, you had asked for the core patch to be small ... and the patch is smaller that way, than when replicating it to both call site.

Quoted 4 lines
Quoted 4 lines
drivers/mmc/core/mmc_ops.c +3 -1
-int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
+struct mmc_cxd {
+	struct mmc_card	*card;		/* optional */
+	void		*buf;
Quoted 8 lines

drivers/mmc/core/mmc_ops.c int mmc_set_relative_addr(struct mmc_car · line 214

Quoted 6 lines
drivers/mmc/core/mmc_ops.c +6 -0
+	unsigned	len;
+	u32		opcode;
+	u32		arg;
+	unsigned	flags;
+};
+

This seems overly complex.

The direct translation of the existing code would have needed them all as function parameters; ungood to have so many params!

Quoted 5 lines

You can do this with arguments as most of that struct is superfluous:

- card can be specified at all times if you reorg the init a bit, allowing you
to drop the host argument.

Hmm, that may be right. I was trying to touch that code as little as possible ... less to break that way!

Quoted 1 line

- arg and flags are the same for all three commands, so those can be dropped.

Arg is zero (except in the native send_csd), and two of the three commands are not valid down that route in the native code. So I suppose it wouldn't hurt to pass an R1 response code there, knowing that it will never be used, even though the correct code for those is R2. That sort of trick is a bit too ugly for my personal taste; I would not have thought of always passing invalid parameters. ;)

Quoted 9 lines

drivers/mmc/core/mmc_ops.c int mmc_send_ext_csd(struct mmc_card *ca · line 255

Quoted 6 lines
drivers/mmc/core/mmc_ops.c +2 -0
@@ -230,6 +251,85 @@ int mmc_send_ext_csd(struct mmc_card *ca
 	return MMC_ERR_NONE;
 }
 
+int mmc_spi_read_ocr(struct mmc_host *host, u32 *ocrp)
+{

How about moving these further down so that the mmc_send_cxd_data() users are right below it?

I'll move it so that and the crc routine are _after_ them ... to keep all related code together.

Quoted 3 lines

Also, the theme I've tried to have here is to take a card pointer whenever you operate on a specific card, and a host pointer for bus wide things. It adds a bit of readability.

There's a difference for SPI?!? :)

Actually, the CRC and OCR stuff gets called before a card struct is available. That may be different in the rest of the code.

Quoted 32 lines
Quoted 11 lines
drivers/mmc/core/mmc.c +2 -3
@@ -320,9 +320,15 @@ static int mmc_init_card(struct mmc_host
 	/*
 	 * Fetch CID from card.
 	 */
-	err = mmc_all_send_cid(host, cid);
-	if (err != MMC_ERR_NONE)
-		goto err;
+	if (mmc_host_is_spi(host)) {
+		err = mmc_spi_send_cid(host, cid);

drivers/mmc/core/mmc.c static int mmc_init_card(struct mmc_host · line 334

Quoted 10 lines
drivers/mmc/core/mmc.c +7 -0
+		if (err != MMC_ERR_NONE)
+			goto err;
+	} else {
+		err = mmc_all_send_cid(host, cid);
+		if (err != MMC_ERR_NONE)
+			goto err;
+	}
 
 	if (oldcard) {
 		if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)

This is entirely subjective, but wouldn't this be cleaner:

	if (mmc_host_is_spi(host))
		err = mmc_spi_send_cid(host, cid);
	else
		err = mmc_all_send_cid(host, cid);

	if (err != MMC_ERR_NONE)
		goto err;
Quoted 1 line

It's fewer lines at least, which should make Linus happy. ;)

Likewise on the SD side. Though ... *both* need to re-enable the CRC mode, currently only the SD path does so; fixed.

Quoted 10 lines

drivers/mmc/core/mmc.c static int mmc_sd_init_card(struct mmc_h · line 415

Quoted 7 lines
drivers/mmc/core/mmc.c +1 -1
@@ -401,13 +411,15 @@ static int mmc_sd_init_card(struct mmc_h
 	}
 
 	/*
-	 * Set card RCA.
+	 * For native busses:  set card RCA and leave open drain mode.
 	 */

While your in the processes of fixing my crappy comments, this command actually gets, not sends the RCA (SD is a bit backwards). :)

Done (in sd.c only).

Quoted 14 lines
Quoted 14 lines
drivers/mmc/core/mmc.c +5 -3
@@ -455,9 +467,11 @@ static int mmc_sd_init_card(struct mmc_h
 		/*
 		 * Fetch switch information from card.
 		 */
-		err = mmc_read_switch(card);
-		if (err != MMC_ERR_NONE)
-			goto free_card;
+		if (!mmc_host_is_spi(host)) {
+			err = mmc_read_switch(card);
+			if (err != MMC_ERR_NONE)
+				goto free_card;
+		}
 	}
 
Quoted 6 lines

drivers/mmc/core/mmc.c static int mmc_sd_init_card(struct mmc_h · line 477

Quoted 1 line
drivers/mmc/core/mmc.c +0 -0
 	/*

Don't you want high-speed on your SPI bus? ;)

Add a FIXME here if you don't have the cards to test this. Or implement it according to spec and wait for bug reports.

I'll add a REVISIT, unless I get inspired by this updated spec that I just downloaded.

Quoted 14 lines
Quoted 14 lines
drivers/mmc/core/sd_ops.c +2 -2
@@ -89,10 +89,10 @@ int mmc_app_cmd(struct mmc_host *host, s
 
 	if (card) {
 		cmd.arg = card->rca << 16;
-		cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+		cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
 	} else {
 		cmd.arg = 0;
-		cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR;
+		cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_BCR;
 	}
 
Quoted 4 lines

drivers/mmc/core/sd_ops.c int mmc_app_cmd(struct mmc_host *host, s · line 98

Quoted 1 line
drivers/mmc/core/sd_ops.c +0 -0
 	err = mmc_wait_for_cmd(host, &cmd, 0);

You also need to fix the check further down as SPI doesn't have a bit indicating if it toggled into ACMD mode.

Right now this is not needed, since the host records that and hands it back in the R1 status mapping.

Other than that status mapping, this is useful to make sure the right tracing statements are emitted: report ACMDx not CMDx. It makes message tracing easier to read. (This is something the MMC/SD core might benefit from, too. Did I mention I'm glad that it now issues the CMDx messages in decimal, matching all docs, not hex? :)

Quoted 4 lines
Quoted 4 lines
drivers/mmc/core/sd_ops.c +0 -0
@@ -175,6 +179,9 @@ int mmc_send_if_cond(struct mmc_host *ho
 	int err;
 	static const u8 test_pattern = 0xAA;
 
Quoted 8 lines

drivers/mmc/core/sd_ops.c int mmc_send_if_cond(struct mmc_host *ho · line 187

Quoted 6 lines
drivers/mmc/core/sd_ops.c +3 -0
+	if (mmc_host_is_spi(host))
+		return MMC_ERR_FAILED;
+
 	/*
 	 * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND
 	 * before SD_APP_OP_COND. This command will harmlessly fail for

See above, we need this for SDHC.

If the doc I just downloaded covers SDHC, I can code it to spec.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706131753.47453.david-b-yBeKhBN/[email protected]

#28 lore raw

Re: [patch 3/4] MMC-over-SPI core updates

Quoted 8 lines · David Brownell

I can move it. I tried expanding it inline there, and thought the result was worse: (a) duplication, in both MMC and SD code paths; (b) it complicates otherwise-clean logic; (c) you had asked that the core patch be small.

You're quite sure you want those drawbacks ... ?

Fairly. The idea when I did the rewrite was that the initial detection (that identifies card type) should be fairly clear and shouldn't require you to dig around in other areas.

As for the patches being small, I guess I wasn't clear. I'd like to see small patches so that they are easily reviewed, but the total changes can be as large as needs be. The end results is the most important part, so if you do not see a way to split up patches then I'll just have to deal with reviewing large ones.

Quoted 4 lines

I just grabbed a new version of that spec; the original omitted absolutely *everything* about SPI.

How evil.

Quoted 5 lines

I think it's the usual reason: ACMD fails on MMC, so use that early to sort out SD-vs-MMC. The Linux stack might be marginally quicker if that were the *ONLY* reason it used ACMD51.

The specs are unclear, especially when comparing old and new ones. We'll just have to feel our way forward here.

Quoted 5 lines

I observed that some cards didn't like CMD58 (READ_OCR) until after the reset was done, although all the specs I have say that it's supposed to work while the reset is happening.

That's not good, as high-capacity MMC needs an initial READ_OCR. :/

Quoted 4 lines

The direct translation of the existing code would have needed them all as function parameters; ungood to have so many params!

I don't think a temporary structure makes it better. It just makes things less readable and gives the impression that it's a persistent object.

Quoted 4 lines

Hmm, that may be right. I was trying to touch that code as little as possible ... less to break that way!

Where's your sense of advanture? ;)

Quoted 9 lines

Arg is zero (except in the native send_csd), and two of the three commands are not valid down that route in the native code. So I suppose it wouldn't hurt to pass an R1 response code there, knowing that it will never be used, even though the correct code for those is R2. That sort of trick is a bit too ugly for my personal taste; I would not have thought of always passing invalid parameters. ;)

I won't tell anyone if you don't ;)

Quoted 6 lines

There's a difference for SPI?!? :)

Actually, the CRC and OCR stuff gets called before a card struct is available. That may be different in the rest of the code.

Right, never mind then.

Quoted 6 lines
Quoted 2 lines

You also need to fix the check further down as SPI doesn't have a bit indicating if it toggled into ACMD mode.

Right now this is not needed, since the host records that and hands it back in the R1 status mapping.

In other words, lying to the core. Someone looking at that function will get the impression that the system can verify that the card entered app command mode even on spi, even though it can't. Don't try to get the round peg into the square hole. Change the hole.

Quoted 6 lines

Other than that status mapping, this is useful to make sure the right tracing statements are emitted: report ACMDx not CMDx. It makes message tracing easier to read. (This is something the MMC/SD core might benefit from, too. Did I mention I'm glad that it now issues the CMDx messages in decimal, matching all docs, not hex? :)

On my todo list. :)

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#30 lore raw

Re: [patch 3/4] MMC-over-SPI core updates

Quoted 7 lines · Pierre Ossman
Quoted 6 lines · David Brownell

I can move it. I tried expanding it inline there, and thought the result was worse: (a) duplication, in both MMC and SD code paths; (b) it complicates otherwise-clean logic; (c) you had asked that the core patch be small.

Quoted 6 lines
Quoted 2 lines

You're quite sure you want those drawbacks ... ?

Fairly. The idea when I did the rewrite was that the initial detection (that identifies card type) should be fairly clear and shouldn't require you to dig around in other areas.

I figured calling mmc_spi_fixup() would be very clear, and since it's defined right before the routine using it then digging would be a non-issue.

But if you want uglified code, I suppose I could do that. ;)

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

You also need to fix the check further down as SPI doesn't have a bit indicating if it toggled into ACMD mode.

Right now this is not needed, since the host records that and hands it back in the R1 status mapping.

In other words, lying to the core.

I can't see it that way. It's just a different way of managing that status than you currently expect.

Quoted 4 lines

Someone looking at that function will get the
impression that the system can verify that the card entered app command mode even on spi, even though it can't. Don't try to get the round peg into the square hole. Change the hole.

So, get rid of all R1_APP_CMD checks in the MMC stack? That's what I'll do for now.

I count two of them, and they are both superfluous since they follow successful completion of MMC_APP_CMD. The only way that can succeed is if the card supports APP_CMD and enters that mode...

(The alternative would be to do the superfluous checks only for non-SPI hosts, but that'd seem pointless.)

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706161416.17802.david-b-yBeKhBN/[email protected]

#32 lore raw

Re: [patch 3/4] MMC-over-SPI core updates

Quoted 4 lines · David Brownell

I can't see it that way. It's just a different way of managing that status than you currently expect.

You seem to be stuck in the idea that we want some voodoo translation layer between native MMC and the SPI version. That is not desirable for a multitude of reasons, so make sure the core knows SPI and the host driver is just a hardware interface (like the other host drivers).

Quoted 9 lines

So, get rid of all R1_APP_CMD checks in the MMC stack? That's what I'll do for now.

I count two of them, and they are both superfluous since they follow successful completion of MMC_APP_CMD. The only way that can succeed is if the card supports APP_CMD and enters that mode...

The specs that was coded against suggested it was prudent to check the bit. It's not like it's a measurable performance hit to do it.

Quoted 2 lines

(The alternative would be to do the superfluous checks only for non-SPI hosts, but that'd seem pointless.)

I don't agree. Preferably we would always check it, but we can't with SPI so we'll have to cross our fingers there.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#34 lore raw

Re: [patch 3/4] MMC-over-SPI core updates

Quoted 4 lines · Pierre Ossman

You seem to be stuck in the idea that we want some voodoo translation layer between native MMC and the SPI version. That is not desirable for a multitude of reasons, so make sure the core knows SPI and the host driver is just a hardware interface (like the other host drivers).

I *HAVE* been moving SPI knowledge into the core, at your request.

Remember that the "how does it move" problems turn up issues. You shouldn't take my comments as "being stuck" on some kind of "voodoo" notion. Any more than I take *your* comments that way.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

#35 lore raw

PATCH 4/4 MMC-over-SPI host driver

In reply to a message not in the archive

This is the latest version of the MMC-over-SPI support. It works on 2.6.22-rc4-mm1, along with the preceding patches which teach the rest of the MMC stack about SPI so that this host driver can focus on doing only lowlevel SPI-specific stuff.

It's been lightly tested on MMC and SD cards, reading and writing ext3 filesystems (including fsck). This includes CRC mode, which is now enabled by default.

The main issue of note was observed on one SD card: sometimes a write triggers CRC errors, then the card seems to stop responding until it's been power cycled. Work around the former by passing the "use_crc=n" module parameter, if it appears on your platform.

Cc Hans-Peter Nilsson <[email protected]>
Cc Jan Nikitenko <[email protected]>
Cc Mike Lavender <mike-UTnDXsALFwNjMdQLN6DIHgC/[email protected]>
---
 drivers/mmc/host/Kconfig    |   13 
 drivers/mmc/host/Makefile   |    1 
 drivers/mmc/host/mmc_spi.c  | 1526 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/mmc_spi.h |   32 
 4 files changed, 1572 insertions(+)
drivers/mmc/host/Kconfig +13 -0
@@ -100,3 +100,16 @@ config MMC_TIFM_SD
           To compile this driver as a module, choose M here: the
 	  module will be called tifm_sd.
 
+config MMC_SPI
+	tristate "MMC/SD over SPI"
+	depends on MMC && SPI_MASTER && EXPERIMENTAL
+	select CRC7
+	select CRC_ITU_T
+	help
+	  Some systems accss MMC/SD cards using the SPI protocol instead of
+	  using an MMC/SD controller.  The disadvantage of using SPI is that
+	  it's often not as fast; its compensating advantage is that SPI is
+	  available on many systems without native MMC/SD controllers.
+
+	  If unsure, or if your system has no SPI controller driver, say N.
+
drivers/mmc/host/Makefile +1 -0
@@ -15,4 +15,5 @@ obj-$(CONFIG_MMC_AU1X)		+= au1xmmc.o
 obj-$(CONFIG_MMC_OMAP)		+= omap.o
 obj-$(CONFIG_MMC_AT91)		+= at91_mci.o
 obj-$(CONFIG_MMC_TIFM_SD)	+= tifm_sd.o
+obj-$(CONFIG_MMC_SPI)		+= mmc_spi.o
 
include/linux/spi/mmc_spi.h new file +32 -0
@@ -0,0 +1,32 @@
+#ifndef __LINUX_SPI_MMC_SPI_H
+#define __LINUX_SPI_MMC_SPI_H
+
+struct device;
+struct mmc_host;
+
+/* Put this in platform_data of a device being used to manage an MMC/SD
+ * card slot.  (Modeled after PXA mmc glue; see that for usage examples.)
+ *
+ * REVISIT This is not a spi-specific notion.  Any card slot should be
+ * able to handle it.  If the MMC core doesn't adopt this kind of notion,
+ * switch the "struct device *" parameters over to "struct spi_device *".
+ */
+struct mmc_spi_platform_data {
+	/* driver activation and (optional) card detect irq hookup */
+	int (*init)(struct device *,
+		irqreturn_t (*)(int, void *),
+		void *);
+	void (*exit)(struct device *, void *);
+
+	/* how long to debounce card detect, in msecs */
+	unsigned detect_delay;
+
+	/* sense switch on sd cards */
+	int (*get_ro)(struct device *);
+
+	/* power management */
+	unsigned int ocr_mask;			/* available voltages */
+	void (*setpower)(struct device *, unsigned int maskval);
+};
+
+#endif /* __LINUX_SPI_MMC_SPI_H */
drivers/mmc/host/mmc_spi.c new file +1526 -0

1,526 lines not on this page · raw message

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706101308.07910.david-b-yBeKhBN/[email protected]

#37 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

drivers/mmc/host/mmc_spi.c line 38

Quoted 7 lines · David Brownell
drivers/mmc/host/mmc_spi.c new file +7 -0
+#include <linux/device.h>
+#include <linux/blkdev.h>
+#include <linux/dma-mapping.h>
+
+#include <linux/mmc/host.h>
+#include <linux/mmc/mmc.h>
+

This header file is a warning sign. Hopefully it's just the mapping that needs it, so it should go away in the next revision.

drivers/mmc/host/mmc_spi.c line 101

Quoted 3 lines
drivers/mmc/host/mmc_spi.c new file +3 -0
+
+
+#define CRC_GO_IDLE_STATE	0x95	/* constant CRC for GO_IDLE */

Isn't this just optimisation now that we have CRC calculation? And if so, is the speed gain worth the complexity?

drivers/mmc/host/mmc_spi.c line 111

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+
+/* The unit for these timeouts is milliseconds.  See mmc_spi_scanbyte.  */
+#define MINI_TIMEOUT		1
+#define READ_TIMEOUT		100
+#define WRITE_TIMEOUT		250
+

Shouldn't these be set in the request by the core?

drivers/mmc/host/mmc_spi.c line 185

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+
+	/* Specs say to write ones most of the time, even when the card
+	 * has no need to read its input data; and many cards won't care.
+	 * This is our source of those ones.
+	 */
+	void			*ones;

If this is just read, can't it be a global const?

Quoted 7 lines
drivers/mmc/host/mmc_spi.c new file +7 -0
+
+	if (cmd->opcode == MMC_STOP_TRANSMISSION) {
+		/*
+		 * We can't tell whether we read block data or the
+		 * command reply, so to cope with trash data during
+		 * the latency, we just read in 14 bytes (8 would be
+		 * enough according to the MMC spec; SD doesn't say)

drivers/mmc/host/mmc_spi.c line 433

Quoted 10 lines
drivers/mmc/host/mmc_spi.c new file +10 -0
+		 * after the command and fake a clean reply.  We could
+		 * avoid this if we saved what the card sent us while
+		 * we sent the command, and treat it like a normal
+		 * response if we didn't get a SPI_TOKEN_SINGLE.
+		 */
+		(void) mmc_spi_readbytes(host, host->command.buf,
+				sizeof host->command.buf);
+		(void) mmc_spi_readbytes(host, host->command.buf,
+				sizeof host->command.buf);
+		value = 0;

Didn't you tweak the block driver to not send MMC_STOP_TRANSMISSION?

drivers/mmc/host/mmc_spi.c line 498

Quoted 7 lines
drivers/mmc/host/mmc_spi.c new file +7 -0
+
+	if (!host->app_cmd
+			&& cmd->error == MMC_ERR_NONE
+			&& cmd->opcode == MMC_APP_CMD) {
+		host->app_cmd = 1;
+		cmd->resp[0] |= R1_APP_CMD;
+	}

Why does the host need to keep track of app command state?

drivers/mmc/host/mmc_spi.c line 573

Quoted 9 lines
drivers/mmc/host/mmc_spi.c new file +9 -0
+
+	/*
+	 * If this was part of a successful request with a stop-part,
+	 * our caller signals the request as done.
+	 */
+	if (status == 0 && mrq->stop == NULL)
+		mmc_request_done(host->mmc, mrq);
+	return status;
+}

I assume the comment should have read "without".

drivers/mmc/host/mmc_spi.c line 674

Quoted 9 lines
drivers/mmc/host/mmc_spi.c new file +9 -0
+
+static inline int resp2status(u8 write_resp)
+{
+	switch (SPI_MMC_RESPONSE_CODE(write_resp)) {
+	case SPI_RESPONSE_ACCEPTED:
+		return 0;
+	case SPI_RESPONSE_CRC_ERR:
+		/* host shall then issue MMC_STOP_TRANSMISSION */
+		return -ECRC;

What's with the made-up errno?

We should check what other parts of the kernel uses for CRC errors.

drivers/mmc/host/mmc_spi.c line 842

Quoted 5 lines
drivers/mmc/host/mmc_spi.c new file +5 -0
+
+	if (data->flags & MMC_DATA_READ) {
+		direction = DMA_FROM_DEVICE;
+		multiple = (cmd->opcode == MMC_READ_MULTIPLE_BLOCK);
+

multiple = (cmd->data->blocks > 1)

drivers/mmc/host/mmc_spi.c line 857

Quoted 4 lines
drivers/mmc/host/mmc_spi.c new file +4 -0
+	} else {
+		direction = DMA_TO_DEVICE;
+		multiple = (cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK);
+	}

same thing here

drivers/mmc/host/mmc_spi.c line 888

Quoted 8 lines
drivers/mmc/host/mmc_spi.c new file +8 -0
+
+		/* allow pio too, with kmap handling any highmem */
+		kmap_addr = kmap(sg->page);
+		if (direction == DMA_TO_DEVICE)
+			t->tx_buf = kmap_addr + sg->offset;
+		else
+			t->rx_buf = kmap_addr + sg->offset;
+

If you want highmem, you also need to be prepared for clustered sg entries. kmap only maps a single page, and a clustered sg might be larger than that.

drivers/mmc/host/mmc_spi.c line 942

Quoted 5 lines
drivers/mmc/host/mmc_spi.c new file +5 -0
+
+	/* NOTE if caller issues SET_BLOCK_COUNT before a multiblock write,
+	 * this STOP_TRAN logic isn't needed except when we stop early for
+	 * errors.  Currently, mmc_block doesn't issue that request.
+	 */

But will it hurt? Other commands might behave like that.

drivers/mmc/host/mmc_spi.c line 1018

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+
+	if (mrq->data && (mrq->data->blksz > MMC_SPI_BLOCKSIZE)) {
+		mrq->cmd->error = MMC_ERR_INVALID;
+		return -EINVAL;
+	}
+

If you've set your parameters correct, then this shouldn't be possible. So do a BUG_ON() if you want to have a test.

drivers/mmc/host/mmc_spi.c line 1054

Quoted 8 lines
drivers/mmc/host/mmc_spi.c new file +8 -0
+
+/*
+ * RESET is started when cmd->opcode == MMC_GO_IDLE_STATE.  This can't
+ * be just a standard protocol operation.
+ *
+ * We expect the MMC core to be responsible for "very hard" resets like
+ * power cycling the card; there's no accessible reset signal.
+ */

Why can't you do this on POWER_ON? I do not like it looking at opcodes, even if this one isn't likely to change.

Quoted 7 lines
drivers/mmc/host/mmc_spi.c new file +7 -0
+	/*
+	 * Do a burst with chipselect deactivated.  We need to do this
+	 * to meet the requirement of 74 clock cycles with chipselect
+	 * high before CMD0.  (Section 6.4.1, in "Simplified Physical
+	 * Layer Specification 2.0".)  Some cards are particularly
+	 * needy of this (e.g. Viking "SD256") while most others don't
+	 * seem to care.  Note that it's not enough to deactivate

drivers/mmc/host/mmc_spi.c line 1089

Quoted 10 lines
drivers/mmc/host/mmc_spi.c new file +10 -0
+	 * chipselect without toggling the clock.  Beware of the hack:
+	 * we "know" that mmc_spi_readbytes uses the host->status
+	 * spi_transfer.
+	 *
+	 * Note that this is one of two places MMC/SD plays games with
+	 * the SPI protocol.  The other is that when chipselect is
+	 * released while the card returns BUSY status, the clock must
+	 * issue several cycles with chipselect high before the card
+	 * will stop driving its output.
+	 */

Sounds like this signaling can be done with the chip select ios already present in the mmc layer. Then we won't need voodoo in the host driver.

Quoted 13 lines
drivers/mmc/host/mmc_spi.c new file +13 -0
+
+	/* issue software reset */
+	cmd->arg = 0;
+	status = mmc_spi_command_send(host, mrq, CRC_GO_IDLE_STATE, cmd, 0);
+	if (status < 0) {
+		/* Maybe:
+		 *  - there's no card present
+		 *  - the card isn't seated correctly (bad contacts)
+		 *  - it didn't leave MMC/SD mode
+		 *  - there's other confusion in the card state
+		 *
+		 * Power cycling the card ought to help a lot.
+		 * At any rate, let's try again.

drivers/mmc/host/mmc_spi.c line 1132

Quoted 10 lines
drivers/mmc/host/mmc_spi.c new file +10 -0
+		 */
+		status = mmc_spi_command_send(host, mrq,
+				CRC_GO_IDLE_STATE, cmd, 0);
+		if (status < 0)
+			dev_dbg(&host->spi->dev,
+				"can't initialize; no card%s?\n",
+				could_invert_cs
+					? ""
+					: " or chip-select error");
+	}

No, no, no... This is not the kind of behaviour you want to hide down in the host driver. This is a decision the core should make. Don't put the layer cake in the blender.

drivers/mmc/host/mmc_spi.c line 1156

Quoted 10 lines
drivers/mmc/host/mmc_spi.c new file +10 -0
+
+	/* MMC core and layered drivers *MUST* issue SPI-aware commands */
+	cmd = mrq->stop;
+	if (cmd && !mmc_spi_resp_type(cmd)) {
+		dev_dbg(&host->spi->dev, "bogus STOP command\n");
+		dump_stack();
+		cmd->error = MMC_ERR_INVALID;
+		goto fail;
+	}
+

This seems like something that should just be in debug builds.

drivers/mmc/host/mmc_spi.c line 1257

Quoted 11 lines
drivers/mmc/host/mmc_spi.c new file +11 -0
+
+static int mmc_spi_get_ro(struct mmc_host *mmc)
+{
+	struct mmc_spi_host *host = mmc_priv(mmc);
+
+	if (host->pdata && host->pdata->get_ro)
+		return host->pdata->get_ro(mmc->parent);
+	/* board doesn't support read only detection; assume writeable */
+	return 0;
+}
+

A printk() might be nice so the user knows why the switch isn't being respected.

drivers/mmc/host/mmc_spi.c line 1296

Quoted 10 lines
drivers/mmc/host/mmc_spi.c new file +10 -0
+
+	/* SanDisk and Hitachi MMC docs both show clock timing diagrams
+	 * with clock starting low (CPOL=0) and sampling on leading edge
+	 * (CPHA=0); clock is measured between rising edges.  Sandisk SD
+	 * docs show clock starting high (CPOL=1) and sampling on trailing
+	 * edge (CPHA=1), measuring between falling edges.
+	 *
+	 * Docs are very explicit that sampling is on the rising edge, so
+	 * the difference between SPI_MODE_0 and SPI_MODE_3 may not matter.
+	 */

Sure you haven't looked at high-speed versus legacy clocking?

drivers/mmc/host/mmc_spi.c line 1412

Quoted 12 lines
drivers/mmc/host/mmc_spi.c new file +12 -0
+
+	if (spi->master->cdev.dev->dma_mask) {
+		struct device	*dev = spi->master->cdev.dev;
+
+		host->dma_dev = dev;
+		host->dma = dma_map_single(dev, host,
+				sizeof *host, DMA_BIDIRECTIONAL);
+		host->ones_dma = dma_map_single(dev, ones,
+				MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
+		host->data_dma = dma_map_single(dev, host->data,
+				sizeof *host->data, DMA_BIDIRECTIONAL);
+

This might be wasteful if the system has an iommu.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#39 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

Quoted 11 lines · Pierre Ossman

drivers/mmc/host/mmc_spi.c line 38

Quoted 7 lines · David Brownell
drivers/mmc/host/mmc_spi.c new file +7 -0
+#include <linux/device.h>
+#include <linux/blkdev.h>
+#include <linux/dma-mapping.h>
+
+#include <linux/mmc/host.h>
+#include <linux/mmc/mmc.h>
+

This header file is a warning sign. Hopefully it's just the mapping that needs it, so it should go away in the next revision.

There were other cases, as I recall. Maybe the core has changed so much that some of them are no longer needed. I removed as many as seemed safe.

Quoted 6 lines

drivers/mmc/host/mmc_spi.c line 101

Quoted 3 lines
drivers/mmc/host/mmc_spi.c new file +3 -0
+
+
+#define CRC_GO_IDLE_STATE	0x95	/* constant CRC for GO_IDLE */

Isn't this just optimisation now that we have CRC calculation? And if so, is the speed gain worth the complexity?

Unless CRCs will always be on -- implying a significant performance penalty on the kind of platform which *most* needs the MMC-over-SPI support! -- ISTR that it's not optional; GO_IDLE always needs a CRC, even if other requests don't use one. That's why the specs list that CRC explicitly.

Quoted 7 lines

drivers/mmc/host/mmc_spi.c line 111

Quoted 5 lines
drivers/mmc/host/mmc_spi.c new file +5 -0
+/* The unit for these timeouts is milliseconds.  See mmc_spi_scanbyte.  */
+#define MINI_TIMEOUT		1
+#define READ_TIMEOUT		100
+#define WRITE_TIMEOUT		250
+

Shouldn't these be set in the request by the core?

Not the MINI timeout, for sure. Maybe some of the others. (MINI should actually be 1..8 bytes, not N msec.)

The whole issue of timeouts needs investiation still ... like, does the core even understand them right (for SPI).

Quoted 8 lines

drivers/mmc/host/mmc_spi.c line 185

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+
+	/* Specs say to write ones most of the time, even when the card
+	 * has no need to read its input data; and many cards won't care.
+	 * This is our source of those ones.
+	 */
+	void			*ones;

If this is just read, can't it be a global const?

What do you mean by that? It can't be "static", since such memory is not generally DMA-safe. Maybe the pointer could be static; but each device would need its own DMA mapping; and there will usually be more than one of these per system, so I can't see much need to share that buffer between host/card instances.

Quoted 11 lines
Quoted 11 lines
drivers/mmc/host/mmc_spi.c new file +11 -0
+
+	if (cmd->opcode == MMC_STOP_TRANSMISSION) {
+		/*
+		 * We can't tell whether we read block data or the
+		 * command reply, so to cope with trash data during
+		 * the latency, we just read in 14 bytes (8 would be
+		 * enough according to the MMC spec; SD doesn't say)
+		 * after the command and fake a clean reply.  We could
+		 * avoid this if we saved what the card sent us while
+		 * we sent the command, and treat it like a normal
+		 * response if we didn't get a SPI_TOKEN_SINGLE.
Quoted 8 lines

drivers/mmc/host/mmc_spi.c line 433

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+		 */
+		(void) mmc_spi_readbytes(host, host->command.buf,
+				sizeof host->command.buf);
+		(void) mmc_spi_readbytes(host, host->command.buf,
+				sizeof host->command.buf);
+		value = 0;

Didn't you tweak the block driver to not send MMC_STOP_TRANSMISSION?

Only for writes. Reads still use this. (Writes use a lowlevel token replacing the normal next-block token.)

Quoted 9 lines

drivers/mmc/host/mmc_spi.c line 498

Quoted 7 lines
drivers/mmc/host/mmc_spi.c new file +7 -0
+
+	if (!host->app_cmd
+			&& cmd->error == MMC_ERR_NONE
+			&& cmd->opcode == MMC_APP_CMD) {
+		host->app_cmd = 1;
+		cmd->resp[0] |= R1_APP_CMD;
+	}

Why does the host need to keep track of app command state?

As noted in a previous reply (which you've not yet seen):
(a) Because the MMC core relies on it to do so, and
(b) Because otherwise diagnostics report CMDx instead of ACMDx.

You didn't comment on the mapping applied to cmd->resp[0] ...

Quoted 11 lines

drivers/mmc/host/mmc_spi.c line 573

Quoted 9 lines
drivers/mmc/host/mmc_spi.c new file +9 -0
+
+	/*
+	 * If this was part of a successful request with a stop-part,
+	 * our caller signals the request as done.
+	 */
+	if (status == 0 && mrq->stop == NULL)
+		mmc_request_done(host->mmc, mrq);
+	return status;
+}

I assume the comment should have read "without".

No; this handles the request_done() for success without a stop part. Caller does it otherwise...

Quoted 11 lines

drivers/mmc/host/mmc_spi.c line 674

Quoted 9 lines
drivers/mmc/host/mmc_spi.c new file +9 -0
+
+static inline int resp2status(u8 write_resp)
+{
+	switch (SPI_MMC_RESPONSE_CODE(write_resp)) {
+	case SPI_RESPONSE_ACCEPTED:
+		return 0;
+	case SPI_RESPONSE_CRC_ERR:
+		/* host shall then issue MMC_STOP_TRANSMISSION */
+		return -ECRC;

What's with the made-up errno?

Readability.

Quoted 1 line

We should check what other parts of the kernel uses for CRC errors.

If you can find some convention for CRC errors, this can change; otherwise that won't matter, since only *this* code cares.

The MMC layer seems to only use the MMC-internal status codes. (Which is a different issue ... that's generaly frowned upon.)

Quoted 7 lines

drivers/mmc/host/mmc_spi.c line 842

Quoted 5 lines
drivers/mmc/host/mmc_spi.c new file +5 -0
+
+	if (data->flags & MMC_DATA_READ) {
+		direction = DMA_FROM_DEVICE;
+		multiple = (cmd->opcode == MMC_READ_MULTIPLE_BLOCK);
+

multiple = (cmd->data->blocks > 1)

Can that now be relied upon? The reason it was coded this way (and likewise for writes) was that previously that was NOT true.

I recall trying that at some point, and watching lots of stuff break...

Quoted 10 lines

drivers/mmc/host/mmc_spi.c line 888

Quoted 7 lines
drivers/mmc/host/mmc_spi.c new file +7 -0
+		/* allow pio too, with kmap handling any highmem */
+		kmap_addr = kmap(sg->page);
+		if (direction == DMA_TO_DEVICE)
+			t->tx_buf = kmap_addr + sg->offset;
+		else
+			t->rx_buf = kmap_addr + sg->offset;
+

If you want highmem, you also need to be prepared for clustered sg entries. kmap only maps a single page, and a clustered sg might be larger than that.

Actually it'd be best if we never saw highmem. Fortunately that conceptual abortion doesn't is rare (to the point of nonexistence) on platforms which use this. Maybe the driver should even depend on !HIGHMEM, just to be sure.

Quoted 7 lines

drivers/mmc/host/mmc_spi.c line 942

Quoted 5 lines
drivers/mmc/host/mmc_spi.c new file +5 -0
+
+	/* NOTE if caller issues SET_BLOCK_COUNT before a multiblock write,
+	 * this STOP_TRAN logic isn't needed except when we stop early for
+	 * errors.  Currently, mmc_block doesn't issue that request.
+	 */

But will it hurt? Other commands might behave like that.

I think it's unspecified whether it would hurt. STOP_TRAN is however specified ONLY for those specific protocol messages.

I suspect you need to rethink how you're viewing this host driver a bit ... it implements low level protocols, and as such it can't avoid understanding relevant facts. Offloading high level protocol stuff to the core is fine. By analogy, link level drivers know about link level issues (STOP_TRAN, PPPOE, etc), but not about the packets they encapsulate (CMDx, ARP, etc).

Quoted 9 lines

drivers/mmc/host/mmc_spi.c line 1018

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+
+	if (mrq->data && (mrq->data->blksz > MMC_SPI_BLOCKSIZE)) {
+		mrq->cmd->error = MMC_ERR_INVALID;
+		return -EINVAL;
+	}
+

If you've set your parameters correct, then this shouldn't be possible. So do a BUG_ON() if you want to have a test.

Which parameters?

The standard kernel policy is to avoid BUG_ON like the plague if there's any way to report an error to the upper level code and have it proceed. If the system can proceed, it's not any kind of BUG().

Quoted 11 lines

drivers/mmc/host/mmc_spi.c line 1054

Quoted 8 lines
drivers/mmc/host/mmc_spi.c new file +8 -0
+
+/*
+ * RESET is started when cmd->opcode == MMC_GO_IDLE_STATE.  This can't
+ * be just a standard protocol operation.
+ *
+ * We expect the MMC core to be responsible for "very hard" resets like
+ * power cycling the card; there's no accessible reset signal.
+ */

Why can't you do this on POWER_ON? I do not like it looking at opcodes, even if this one isn't likely to change.

Something to think about. This is pretty much the way Jan's patch delievered it. I found that "74 clocks" stuff in the powerup sequence, which is perhaps what you did. That'd mean the set_ios() stuff *really* needs to be refactored. I don't really trust the reset logic anyway...

Jan, any comments? You were the last person to really look at this part.

Quoted 12 lines
Quoted 12 lines
drivers/mmc/host/mmc_spi.c new file +12 -0
+	/*
+	 * Do a burst with chipselect deactivated.  We need to do this
+	 * to meet the requirement of 74 clock cycles with chipselect
+	 * high before CMD0.  (Section 6.4.1, in "Simplified Physical
+	 * Layer Specification 2.0".)  Some cards are particularly
+	 * needy of this (e.g. Viking "SD256") while most others don't
+	 * seem to care.  Note that it's not enough to deactivate
+	 * chipselect without toggling the clock.  Beware of the hack:
+	 * we "know" that mmc_spi_readbytes uses the host->status
+	 * spi_transfer.
+	 *
+	 * Note that this is one of two places MMC/SD plays games with
Quoted 8 lines

drivers/mmc/host/mmc_spi.c line 1089

Quoted 5 lines
drivers/mmc/host/mmc_spi.c new file +5 -0
+	 * the SPI protocol.  The other is that when chipselect is
+	 * released while the card returns BUSY status, the clock must
+	 * issue several cycles with chipselect high before the card
+	 * will stop driving its output.
+	 */

Sounds like this signaling can be done with the chip select ios already present in the mmc layer. Then we won't need voodoo in the host driver.

No.

Quoted 19 lines
Quoted 19 lines
drivers/mmc/host/mmc_spi.c new file +19 -0
+
+	/* issue software reset */
+	cmd->arg = 0;
+	status = mmc_spi_command_send(host, mrq, CRC_GO_IDLE_STATE, cmd, 0);
+	if (status < 0) {
+		/* Maybe:
+		 *  - there's no card present
+		 *  - the card isn't seated correctly (bad contacts)
+		 *  - it didn't leave MMC/SD mode
+		 *  - there's other confusion in the card state
+		 *
+		 * Power cycling the card ought to help a lot.
+		 * At any rate, let's try again.
+		 */
+		status = mmc_spi_command_send(host, mrq,
+				CRC_GO_IDLE_STATE, cmd, 0);
+		if (status < 0)
+			dev_dbg(&host->spi->dev,
+				"can't initialize; no card%s?\n",
Quoted 8 lines

drivers/mmc/host/mmc_spi.c line 1132

Quoted 4 lines
drivers/mmc/host/mmc_spi.c new file +4 -0
+				could_invert_cs
+					? ""
+					: " or chip-select error");
+	}

No, no, no... This is not the kind of behaviour you want to hide down in the host driver. This is a decision the core should make. Don't put the layer cake in the blender.

Good point. I think that came from frustration with some cases of the "we can't really power cycle on this board" logic not behaving. I'll just return the first command_send().

Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/mmc_spi.c new file +4 -0
+
+	/* MMC core and layered drivers *MUST* issue SPI-aware commands */
+	cmd = mrq->stop;
+	if (cmd && !mmc_spi_resp_type(cmd)) {
Quoted 8 lines

drivers/mmc/host/mmc_spi.c line 1156

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+		dev_dbg(&host->spi->dev, "bogus STOP command\n");
+		dump_stack();
+		cmd->error = MMC_ERR_INVALID;
+		goto fail;
+	}
+

This seems like something that should just be in debug builds.

Just this sanity check, not both?

Quoted 5 lines
Quoted 5 lines
drivers/mmc/host/mmc_spi.c new file +5 -0
+
+static int mmc_spi_get_ro(struct mmc_host *mmc)
+{
+	struct mmc_spi_host *host = mmc_priv(mmc);
+
Quoted 8 lines

drivers/mmc/host/mmc_spi.c line 1257

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+	if (host->pdata && host->pdata->get_ro)
+		return host->pdata->get_ro(mmc->parent);
+	/* board doesn't support read only detection; assume writeable */
+	return 0;
+}
+

A printk() might be nice so the user knows why the switch isn't being respected.

ISTR that not many of the other drivers do that, at least not there. I can update the startup message to say if it has power on/off support.

Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/mmc_spi.c new file +4 -0
+
+	/* SanDisk and Hitachi MMC docs both show clock timing diagrams
+	 * with clock starting low (CPOL=0) and sampling on leading edge
+	 * (CPHA=0); clock is measured between rising edges.  Sandisk SD
Quoted 8 lines

drivers/mmc/host/mmc_spi.c line 1296

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+	 * docs show clock starting high (CPOL=1) and sampling on trailing
+	 * edge (CPHA=1), measuring between falling edges.
+	 *
+	 * Docs are very explicit that sampling is on the rising edge, so
+	 * the difference between SPI_MODE_0 and SPI_MODE_3 may not matter.
+	 */

Sure you haven't looked at high-speed versus legacy clocking?

Nyet.

Quoted 6 lines
Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+
+	if (spi->master->cdev.dev->dma_mask) {
+		struct device	*dev = spi->master->cdev.dev;
+
+		host->dma_dev = dev;
+		host->dma = dma_map_single(dev, host,
Quoted 8 lines

drivers/mmc/host/mmc_spi.c line 1412

Quoted 6 lines
drivers/mmc/host/mmc_spi.c new file +6 -0
+				sizeof *host, DMA_BIDIRECTIONAL);
+		host->ones_dma = dma_map_single(dev, ones,
+				MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
+		host->data_dma = dma_map_single(dev, host->data,
+				sizeof *host->data, DMA_BIDIRECTIONAL);
+

This might be wasteful if the system has an iommu.

Systems without a "native" MMC/SD controller are unlikely to spend silicon to put an IOMMU on the SPI controller. I've seen them on a few other controllers ... but that seems to have been a short lived experiment, phased out in newer chips.

And in any case, that's like one page plus one cacheline. If there were an IOMMU, surely it can afford that much overhead.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706132105.51711.david-b-yBeKhBN/[email protected]

#41 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

Quoted 5 lines · David Brownell

There were other cases, as I recall. Maybe the core has changed so much that some of them are no longer needed. I removed as many as seemed safe.

Which are left? I doubt they are needed.

Quoted 7 lines

Unless CRCs will always be on -- implying a significant performance penalty on the kind of platform which *most* needs the MMC-over-SPI support! -- ISTR that it's not optional; GO_IDLE always needs a CRC, even if other requests don't use one. That's why the specs list that CRC explicitly.

Since it depends unconditionally on CRC7, you will always be able to calculate that in runtime.

And in order for the host to know when to calculate it, I suggest another feel to the ios structure. And drop the CAP_CRC, we'll consider CRC support mandatory (even though you can have the option of turning it off in runtime).

Quoted 7 lines

Not the MINI timeout, for sure. Maybe some of the others. (MINI should actually be 1..8 bytes, not N msec.)

The whole issue of timeouts needs investiation still ... like, does the core even understand them right (for SPI).

Probably not. So add it. ;)

Quoted 7 lines

What do you mean by that? It can't be "static", since such memory is not generally DMA-safe. Maybe the pointer could be static; but each device would need its own DMA mapping; and there will usually be more than one of these per system, so I can't see much need to share that buffer between host/card instances.

I didn't check how much data was in that thing, but it feels wrong not to share memory when we know it's read-only.

Quoted 5 lines
Quoted 1 line

Didn't you tweak the block driver to not send MMC_STOP_TRANSMISSION?

Only for writes. Reads still use this. (Writes use a lowlevel token replacing the normal next-block token.)

You should trigger on it being data->stop, not on the opcode. Again, for forward compatibility.

Quoted 5 lines

As noted in a previous reply (which you've not yet seen):
(a) Because the MMC core relies on it to do so, and
(b) Because otherwise diagnostics report CMDx instead of ACMDx.

(a) should go away and (b) can be moved to the core.

Quoted 1 line

You didn't comment on the mapping applied to cmd->resp[0] ...

I thought you were going to remove all of them, but it seems I misunderstood. The host driver shouldn't try to fake being a native controller as that will come back to bite us in the ass eventually when we find some odd corner case. Report the true SPI stuff up to the core and modify the core to understand it.

Quoted 11 lines
Quoted 10 lines

drivers/mmc/host/mmc_spi.c line 573

Quoted 9 lines
drivers/mmc/host/mmc_spi.c new file +9 -0
+
+	/*
+	 * If this was part of a successful request with a stop-part,
+	 * our caller signals the request as done.
+	 */
+	if (status == 0 && mrq->stop == NULL)
+		mmc_request_done(host->mmc, mrq);
+	return status;
+}

I assume the comment should have read "without".

Quoted 3 lines

No; this handles the request_done() for success without a stop part. Caller does it otherwise...

Ah, so the comment doesn't describe why this is done, rather it describes why mmc_request_done() isn't always called here?

Perhaps a rewording is in order as it has already confused at least one person. :)

Quoted 12 lines
Quoted 11 lines

drivers/mmc/host/mmc_spi.c line 674

Quoted 10 lines
drivers/mmc/host/mmc_spi.c new file +9 -0
+
+static inline int resp2status(u8 write_resp)
+{
+	switch (SPI_MMC_RESPONSE_CODE(write_resp)) {
+	case SPI_RESPONSE_ACCEPTED:
+		return 0;
+	case SPI_RESPONSE_CRC_ERR:
+		/* host shall then issue MMC_STOP_TRANSMISSION */
+		return -ECRC;

What's with the made-up errno?

Quoted 2 lines

Readability.

Not sure it helps in that area. Many will get confused by an errno they do not recognize.

Quoted 6 lines
Quoted 2 lines

We should check what other parts of the kernel uses for CRC errors.

If you can find some convention for CRC errors, this can change; otherwise that won't matter, since only *this* code cares.

I'm a neat freak. ;)

Won't EILSEQ do?

Quoted 3 lines

The MMC layer seems to only use the MMC-internal status codes. (Which is a different issue ... that's generaly frowned upon.)

I know, it's part of the baggage I got when I took over. It's on my todo list to get rid of those codes. They've been annoying the hell out of me.

Quoted 8 lines
Quoted 1 line

multiple = (cmd->data->blocks > 1)

Can that now be relied upon? The reason it was coded this way (and likewise for writes) was that previously that was NOT true.

I recall trying that at some point, and watching lots of stuff break...

I don't know your exact meaning of "multiple" here, but if it means "more than one block", then checking the block count is the correct way.

Quoted 6 lines

Actually it'd be best if we never saw highmem. Fortunately that conceptual abortion doesn't is rare (to the point of nonexistence) on platforms which use this. Maybe the driver should even depend on !HIGHMEM, just to be sure.

You can tell the MMC layer that by setting your DMA mask properly.

Quoted 4 lines

I think it's unspecified whether it would hurt. STOP_TRAN is however specified ONLY for those specific protocol messages.

I don't like sticking that information in here. We should code this into the request somewhere and let the core determine which opcodes needs it.

Quoted 8 lines

I suspect you need to rethink how you're viewing this host driver a bit ... it implements low level protocols, and as such it can't avoid understanding relevant facts. Offloading high level protocol stuff to the core is fine. By analogy, link level drivers know about link level issues (STOP_TRAN, PPPOE, etc), but not about the packets they encapsulate (CMDx, ARP, etc).

I'd say your driver is more like the PHY (with some acceleration like computing CRC), and the core contains the MAC.

Quoted 4 lines
Quoted 2 lines

If you've set your parameters correct, then this shouldn't be possible. So do a BUG_ON() if you want to have a test.

Which parameters?

max_blk_size and friends in the host structure.

Quoted 6 lines

The standard kernel policy is to avoid BUG_ON like the plague if there's any way to report an error to the upper level code and have it proceed. If the system can proceed, it's not any kind of BUG().

WARN_ON() or something then. I'm not saying you should remove your if-clause (not saying you should keep it either); but the fact is that this is an internal kernel interface, so giving the wrong parameters is a bug that should be exposed.

Quoted 5 lines
Quoted 2 lines

Sounds like this signaling can be done with the chip select ios already present in the mmc layer. Then we won't need voodoo in the host driver.

No.

Why not? It would allow us to keep higher protocol semantics (which varying delays depending on opcodes is after all) in the core.

Quoted 4 lines
Quoted 1 line

This seems like something that should just be in debug builds.

Just this sanity check, not both?

Both.

Quoted 5 lines
Quoted 1 line

A printk() might be nice so the user knows why the switch isn't being respected.

ISTR that not many of the other drivers do that, at least not there. I can update the startup message to say if it has power on/off support.

Just because the other boys are misbehaving doesn't mean you have to. ;)

Quoted 9 lines

Systems without a "native" MMC/SD controller are unlikely to spend silicon to put an IOMMU on the SPI controller. I've seen them on a few other controllers ... but that seems to have been a short lived experiment, phased out in newer chips.

And in any case, that's like one page plus one cacheline. If there were an IOMMU, surely it can afford that much overhead.

Not if everyone has that attitude. ;)

It's not an issue I'm going to press, but I though I should point it out at least.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#43 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

Quoted 7 lines · Pierre Ossman
Quoted 4 lines · David Brownell

There were other cases, as I recall. Maybe the core has changed so much that some of them are no longer needed. I removed as many as seemed safe.

Which are left? I doubt they are needed.

If the MMC core and block code change more, many can go. Remember that I was making such core changes in small, safe doses!

Right now it looks like the main reason to keep including mmc.h is to handle one aspect of mapping the data error token. Four of its bits are part of normal R2 response, suitable for shift-and-mask handling, but the 0x10 bit seems to be vendor specific ... so for now, if that's set I map it to R2_SPI_ERROR (generic "it broke") and use that symbol to avoid excess magic numbers.

Quoted 3 lines

I suggest another feel
to the ios structure. And drop the CAP_CRC, we'll consider CRC support mandatory (even though you can have the option of turning it off in runtime).

That's not a complete description. :)
You're thinking of something like this?

- always do the (dirt cheap) crc7 in the command;
- move the module parameter into mmc core, default spi_crc=y;
- add mmc_ios.spi_crc, initialized to match the module parameter;
- mmc_spi_set_crc() uses that parameter; and
- mmc_spi host will use that instead of its current use_crc, to tell whether it should init or verify datablock CRC16 values.

Except this doesn't seem like an ios-style thing to me... that's on top of me disliking that confusing and error-prone "check N parameters to see which ones should change this time" API style.

Having a simple flag in mmc_host would be much better.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		return -ECRC;

What's with the made-up errno?

Readability.

Not sure it helps in that area. Many will get confused by an errno they do not recognize.

I'll leave a #define pending a better solution though. Maybe MMC_ERRNO_BADCRC not ECRC?

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

We should check what other parts of the kernel uses for CRC errors.

If you can find some convention for CRC errors, this can change; otherwise that won't matter, since only *this* code cares.

I'm a neat freak. ;)

Won't EILSEQ do?

After changing the existing usage of that code, and assuming that code becomes reserved for that role within the MMC stack...

Quoted 7 lines
Quoted 5 lines

Actually it'd be best if we never saw highmem. Fortunately that conceptual abortion doesn't is rare (to the point of nonexistence) on platforms which use this. Maybe the driver should even depend on !HIGHMEM, just to be sure.

You can tell the MMC layer that by setting your DMA mask properly.

That's at best an implementation quirk; those masks don't say a thing about how kernel virtual memory space is managed (which is why code needs to care about HIGHMEM). For now I'll just say the driver depends on !HIGHMEM.

Quoted 5 lines
Quoted 2 lines

I think it's unspecified whether it would hurt. STOP_TRAN is however specified ONLY for those specific protocol messages.

I don't like sticking that information in here. We should code this into the request somewhere and let the core determine which opcodes needs it.

It *IS* already encoded in the request: only multiblock writes need to use that token. Likewise they use special start tokens for each block. And in the same way, other data blocks use a third kind of start token; and may have data-dependent CRC values. All such values are managed below the core.

This is just something that a person adding SET_BLOCK_COUNT support (CMD23, for MMC only) would need to worry about. And that command seems to be "reserved" in more documents than not, so it's unlikely to ever matter. I updated that comment.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

If you've set your parameters correct, then this shouldn't be possible. So do a BUG_ON() if you want to have a test.

Which parameters?

max_blk_size and friends in the host structure.

OK, I'll just set that and get rid of the test. I didn't much like that test, but I did want to make sure that the limit was not broken.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Sounds like this signaling can be done with the chip select ios already present in the mmc layer. Then we won't need voodoo in the host driver.

No.

Why not? It would allow us to keep higher protocol semantics (which varying delays depending on opcodes is after all) in the core.

Well for starters, it's packaged in the mmc_ios which holds things that don't change between requests, but SPI chipselect always goes active at the beginning of every request and then goes inactive when it's done.

It seems the only reason to have it in mmc_ios is to help work around some wbsd quirks during card enumeration. Other controllers manage to keep that signal pulled up until entering 4-wire mode.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706171329.12709.david-b-yBeKhBN/[email protected]

#45 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

Quoted 11 lines · David Brownell

If the MMC core and block code change more, many can go. Remember that I was making such core changes in small, safe doses!

Right now it looks like the main reason to keep including mmc.h is to handle one aspect of mapping the data error token. Four of its bits are part of normal R2 response, suitable for shift-and-mask handling, but the 0x10 bit seems to be vendor specific ... so for now, if that's set I map it to R2_SPI_ERROR (generic "it broke") and use that symbol to avoid excess magic numbers.

Don't map at all. Just give the core what you got from the card.

Quoted 8 lines
Quoted 4 lines

I suggest another feel
to the ios structure. And drop the CAP_CRC, we'll consider CRC support mandatory (even though you can have the option of turning it off in runtime).

That's not a complete description. :)
You're thinking of something like this?

Quoted 7 lines

- always do the (dirt cheap) crc7 in the command;
- move the module parameter into mmc core, default spi_crc=y;
- add mmc_ios.spi_crc, initialized to match the module parameter;
- mmc_spi_set_crc() uses that parameter; and
- mmc_spi host will use that instead of its current use_crc, to tell whether it should init or verify datablock CRC16 values.

Yes. It more clearly separates mechanism (the host driver) from policy (the mmc core).

Quoted 4 lines

Except this doesn't seem like an ios-style thing to me... that's on top of me disliking that confusing and error-prone "check N parameters to see which ones should change this time" API style.

I'm no fan of this ios thing either, but it's what we've got and it hasn't been worth the effort to rewrite it yet.

Quoted 1 line

Having a simple flag in mmc_host would be much better.

Perhaps. But there's a lot of value in consistency.

Quoted 4 lines

I'll leave a #define pending a better solution though. Maybe MMC_ERRNO_BADCRC not ECRC?

Well, since we're scrapping those custom error codes, then that's probably not a good idea. We can hold off on this issue until that mess is sorted out.

Quoted 4 lines

After changing the existing usage of that code, and assuming that code becomes reserved for that role within the MMC stack...

Overloading use of errno:s is rather common. Just look at ETIMEDOUT.

Quoted 7 lines

It *IS* already encoded in the request: only multiblock writes need to use that token. Likewise they use special start tokens for each block. And in the same way, other data blocks use a third kind of start token; and may have data-dependent CRC values. All such values are managed below the core.

Quoted 5 lines

This is just something that a person adding SET_BLOCK_COUNT support (CMD23, for MMC only) would need to worry about. And that command seems to be "reserved" in more documents than not, so it's unlikely to ever matter. I updated that comment.

Well, that person shouldn't have to worry about it as the host driver should service all valid requests.

Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Sounds like this signaling can be done with the chip select ios already present in the mmc layer. Then we won't need voodoo in the host driver.

No.

Why not? It would allow us to keep higher protocol semantics (which varying delays depending on opcodes is after all) in the core.

Well for starters, it's packaged in the mmc_ios which holds things that don't change between requests, but SPI chipselect always goes active at the beginning of every request and then goes inactive when it's done.

Who said mmc_ios doesn't change between requests? And as your code states, it isn't as simple as keeping it on during just the request.

Quoted 4 lines

It seems the only reason to have it in mmc_ios is to help work around some wbsd quirks during card enumeration. Other controllers manage to keep that signal pulled up until entering 4-wire mode.

We try to think a bit more general than that, even though it was first implemented because the wbsd driver needed it.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#47 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

Quoted 4 lines
Quoted 2 lines

Right now it looks like the main reason to keep including mmc.h is to handle one aspect of mapping the data error token. ...

Don't map at all. Just give the core what you got from the card.

Tried that, it fails for the obvious (in retrospect) reason: after each command that's issued, something needs to ensure that the return code won't be MMC_ERR_NONE after errors. That means looking at those R1 bits which report that hardware status.

And it's got to do that pretty much immediately, since when an error shows up in the command, the data stage must not be performed. It's impractical to consider delegating such triage to the core.

The data token was a bit of a red herring, and after some re-factoring it turned out that there's no current win to reporting those slightly more detailed data stage errors. (Or any obvious place to report them...)

Quoted 10 lines
Quoted 9 lines

You're thinking of something like this?

- always do the (dirt cheap) crc7 in the command;
- move the module parameter into mmc core, default spi_crc=y;
- add mmc_ios.spi_crc, initialized to match the module parameter;
- mmc_spi_set_crc() uses that parameter; and
- mmc_spi host will use that instead of its current use_crc, to tell whether it should init or verify datablock CRC16 values.

Quoted 2 lines

Yes. It more clearly separates mechanism (the host driver) from policy (the mmc core).

OK, I'll look down that route.

Quoted 10 lines
Quoted 3 lines

Except this doesn't seem like an ios-style thing to me... that's on top of me disliking that confusing and error-prone "check N parameters to see which ones should change this time" API style.

I'm no fan of this ios thing either, but it's what we've got and it hasn't been worth the effort to rewrite it yet.

Quoted 1 line

Having a simple flag in mmc_host would be much better.

Perhaps. But there's a lot of value in consistency.

Unless you strongly object, I'll go the flag route though. The thing is, the IOS thing ("kitchen sink") will never vanish if it keeps growning at every opportunity.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 20070620170511.EC564F31CB-ZcXrCSuhvln6VZ3dlLfH/[email protected]

#49 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

Quoted 8 lines · David Brownell
Quoted 3 lines
Quoted 2 lines

Right now it looks like the main reason to keep including mmc.h is to handle one aspect of mapping the data error token. ...

Don't map at all. Just give the core what you got from the card.

Tried that, it fails for the obvious (in retrospect) reason: after each command that's issued, something needs to ensure that the return code won't be MMC_ERR_NONE after errors. That means looking at those R1 bits which report that hardware status.

The error codes were never supposed to report card status, only controller status. So MMC_ERR_NONE is perfectly valid for a status response filled with error bits.

Quoted 4 lines

And it's got to do that pretty much immediately, since when an error shows up in the command, the data stage must not be performed. It's impractical to consider delegating such triage to the core.

This is an architectural limitation in the MMC layer that affects the native protocol aswell. If you need it fixed, I'd say we have to do it in a proper, general manner.

Why can't you do what native controllers do, just fling the data out there and break when the card doesn't respond properly to it?

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Having a simple flag in mmc_host would be much better.

Perhaps. But there's a lot of value in consistency.

Unless you strongly object, I'll go the flag route though. The thing is, the IOS thing ("kitchen sink") will never vanish if it keeps growning at every opportunity.

But if we keep inventing new systems ad-hoc, we'll have a much bigger mess to deal with.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#51 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

Quoted 5 lines · Pierre Ossman
Quoted 4 lines · David Brownell
Quoted 3 lines
Quoted 2 lines

Right now it looks like the main reason to keep including mmc.h is to handle one aspect of mapping the data error token. ...

Don't map at all. Just give the core what you got from the card.

Quoted 8 lines
Quoted 4 lines

Tried that, it fails for the obvious (in retrospect) reason: after each command that's issued, something needs to ensure that the return code won't be MMC_ERR_NONE after errors. That means looking at those R1 bits which report that hardware status.

The error codes were never supposed to report card status, only controller status. So MMC_ERR_NONE is perfectly valid for a status response filled with error bits.

If so, then the MMC core is full of bugs, needing fixes that are *FAR* beyond scope of my patches.

Essentially every error check compares against MMC_ERR_NONE.

This distinction you're making between "controller" and "card" seems unnatural -- and counterproductive -- in this context. What the core code expects to see is fault reports. It doesn't actually understand layering to any relevant degree; all it cares about is whether the operation it requested has succeeded or not.

Quoted 8 lines
Quoted 4 lines

And it's got to do that pretty much immediately, since when an error shows up in the command, the data stage must not be performed. It's impractical to consider delegating such triage to the core.

This is an architectural limitation in the MMC layer that affects the native protocol aswell. If you need it fixed, I'd say we have to do it in a proper, general manner.

So, I wait for patches from you which fix all those issues?

Quoted 2 lines

Why can't you do what native controllers do, just fling the data out there and break when the card doesn't respond properly to it?

Because that would be a remarkably ... naive? ... way to implement *any* protocol stack. If I were grading college students again, any such implementation would be seriously downgraded. It's a virtual certainty that throwing garbage commands (like that "data") will make things break. At best, it enters a recoverable fault mode, only wasting the time used to recover from having thrown known-to-be garbage bytes at the card. At worst ... devices become unrecoverable with weaker provocations than that.

I sure hope you have heard that old chestnut, "Be liberal in what you accept, and conservative in what you send."

That's an ancient principle for robust interoperation. The first RFC describing it was RFC 760, but the principle predates that 1980 document by at least a few years. The way to apply that principle here is obvious: don't throw known garbage commands at a card.

Quoted 10 lines
Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Having a simple flag in mmc_host would be much better.

Perhaps. But there's a lot of value in consistency.

Unless you strongly object, I'll go the flag route though. The thing is, the IOS thing ("kitchen sink") will never vanish if it keeps growning at every opportunity.

But if we keep inventing new systems ad-hoc, we'll have a much bigger mess to deal with.

State flags predate the notion of this "ios" thingie; they're far from being an "ad-hoc" notion.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

A message that is not in the archive (sent off-list or not yet received): 200706221418.44214.david-b-yBeKhBN/[email protected]

#53 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

Sorry for being unresponsive to your mails. I appreciate the hard work you're doing, but I have too many other things on my table to answer you in a timely manner. I hope you can put up with the delays.

Quoted 4 lines · On Fri, 22 Jun 2007 14:18:43 -0700 David Brownell…

If so, then the MMC core is full of bugs, needing fixes that are *FAR* beyond scope of my patches.

Quoted 9 lines

Essentially every error check compares against MMC_ERR_NONE.

This distinction you're making between "controller" and "card" seems unnatural -- and counterproductive -- in this context. What the core code expects to see is fault reports. It doesn't actually understand layering to any relevant degree; all it cares about is whether the operation it requested has succeeded or not.

Indeed. But the status bits in the responses are context dependent and the same for all controllers. I fully agree that we pay too little attention to them as it is. But fixing this should be done in the core, not in each and every host driver.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

And it's got to do that pretty much immediately, since when an error shows up in the command, the data stage must not be performed. It's impractical to consider delegating such triage to the core.

Quoted 6 lines
Quoted 3 lines

This is an architectural limitation in the MMC layer that affects the native protocol aswell. If you need it fixed, I'd say we have to do it in a proper, general manner.

So, I wait for patches from you which fix all those issues?

This is not a problem in practice, so it is not something I will prioritize.

The big problem fixing this is that it is very difficult, if not impossible, to be able to apply some policy between the command response and the data. Most hardware will simply trod along and start shuffling data, no matter the response

Quoted 11 lines

Because that would be a remarkably ... naive? ... way to implement *any* protocol stack. If I were grading college students again, any such implementation would be seriously downgraded. It's a virtual certainty that throwing garbage commands (like that "data") will make things break. At best, it enters a recoverable fault mode, only wasting the time used to recover from having thrown known-to-be garbage bytes at the card. At worst ... devices become unrecoverable with weaker provocations than that.

The system is crap from a theoretical point of view. But the system differentiates between commands and data well enough for this to not be a problem in practice. Solving this is complex and will be a no or little gain.

Quoted 4 lines

State flags predate the notion of this "ios" thingie; they're far from being an "ad-hoc" notion.

In other systems, yes. But it is inconsistent when it comes to the mmc code.

Rgds

Signature · 11 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
#54 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

In reply to a message not in the archive
Quoted 5 lines · Pierre Ossman
Quoted 4 lines · David Brownell
Quoted 3 lines
Quoted 2 lines

Right now it looks like the main reason to keep including mmc.h is to handle one aspect of mapping the data error token. ...

Don't map at all. Just give the core what you got from the card.

Quoted 8 lines
Quoted 4 lines

Tried that, it fails for the obvious (in retrospect) reason: after each command that's issued, something needs to ensure that the return code won't be MMC_ERR_NONE after errors. That means looking at those R1 bits which report that hardware status.

The error codes were never supposed to report card status, only controller status. So MMC_ERR_NONE is perfectly valid for a status response filled with error bits.

As I said earlier: not with the current codebase, which disagrees with your "only controller status" notion. The original authors of that code clearly had a "single level fault reporting" model in mind; after all, that's pretty much standard practice everywhere.

I've worked with "multi level fault reporting" frameworks, and they have uniformly been a pain in the posterior unless they can be used in a "single level" mode. Being able to drill down to lower level details is an OK thing, although it's rarely used for anything except debugging. Being *forced* to do so is evil, especially when the structure of those lower layers can be complex and nonuniform.

In this case, for example, you're assuming there *is* a "controller". There might not be one; SPI (and for that matter the native protocol) can just be bitbanged. If there's hardware acceleration for various protocol messages, that's fine but irrelevant to whether or not the sequencing requirements of the protocol were followed.

Quoted 8 lines
Quoted 4 lines

And it's got to do that pretty much immediately, since when an error shows up in the command, the data stage must not be performed. It's impractical to consider delegating such triage to the core.

This is an architectural limitation in the MMC layer that affects the native protocol aswell. If you need it fixed, I'd say we have to do it in a proper, general manner.

Disagree. See above: single layer fault reporting models are the norm ... for very good reasons. And even in those simpler models, very little code ever cares about fault details when it comes to recovery strategies.

Quoted 2 lines

Why can't you do what native controllers do, just fling the data out there and break when the card doesn't respond properly to it?

One reason is that the "native" controllers split command and data streams into different physical channels. Cards can't ever mistake data for commands ... which is a very real possibility with SPI.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

#55 lore raw

Re: [patch 4/4] MMC-over-SPI host driver

In reply to a message not in the archive
Quoted 9 lines · Pierre Ossman
Quoted 6 lines · David Brownell

Not the MINI timeout, for sure. Maybe some of the others. (MINI should actually be 1..8 bytes, not N msec.)

The whole issue of timeouts needs investiation still ... like, does the core even understand them right (for SPI).

Probably not. So add it. ;)

The latest specs say to use fixed timeouts, ignoring CSD values. So the latest code (which I'll repost when git-mmc merges) got rid of the bogus MINI timeout, and uses those timeouts unconditionally. There seems to be no downside to using slightly longer timeouts than a given older-spec card would tolerate.

- Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/