Skip to content

Documented CSD parsing expectations for SDIO lower-half#18543

Open
arjav1528 wants to merge 4 commits intoapache:masterfrom
arjav1528:dev-issue-17248
Open

Documented CSD parsing expectations for SDIO lower-half#18543
arjav1528 wants to merge 4 commits intoapache:masterfrom
arjav1528:dev-issue-17248

Conversation

@arjav1528
Copy link
Contributor

@arjav1528 arjav1528 commented Mar 16, 2026

Fixes: #17248

Summary

Addressed the issue by documenting how SDIO lower-half drivers must provide R2 (CID/CSD) responses and by adding a small sanity check in the MMCSD upper-half. include/nuttx/sdio.h now explains the R2 format, states that the upper-half expects a 128‑bit CID/CSD payload in the standard layout, and notes that controllers which strip the CRC must shift the four 32‑bit words left by one byte (with bcm2711_sdio.c and imx9_usdhc.c as examples). mmcsd_decode_csd in drivers/mmcsd/mmcsd_sdio.c gains a DEBUGASSERT(csd[0] != 0); under CONFIG_DEBUG_FEATURES to catch obviously invalid or misaligned CSDs, and the SDIO/MMCSD docs now describe the SDIO lower-half call-flow and R2/CSD expectations and point implementers to this guidance.

Impact

  • Runtime behavior: Only a debug‑only DEBUGASSERT in mmcsd_decode_csd is added; there is no behavior or performance change in non‑debug builds.
  • API/ABI: No changes to SDIO or MMCSD public interfaces; existing correct SDIO lower‑halves continue to work unchanged.
  • Documentation: SDIO docs now explicitly describe recv_r2/R2 handling (including CRC‑stripping controllers), and MMCSD docs direct SDIO lower‑half implementers there.
  • Build / compatibility / security: No new Kconfig options or dependencies beyond existing Sphinx for docs; no security impact; compatibility for /dev/mmcsd* users is unchanged.

Testing

  • make html in Documentation/ to verify the updated RST documentation builds successfully.
  • No runtime or hardware tests were performed because no SDIO/MMC-capable target hardware is available in this environment; the new DEBUGASSERT behavior is validated by static inspection only.

@arjav1528 arjav1528 changed the title Document CSD parsing expectations for SDIO lower-half Documented CSD parsing expectations for SDIO lower-half Mar 16, 2026
@github-actions github-actions bot added Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels Mar 16, 2026
@arjav1528 arjav1528 force-pushed the dev-issue-17248 branch 2 times, most recently from a20aa66 to 7616424 Compare March 16, 2026 10:40
The MMCSD upper-half (``drivers/mmcsd/mmcsd_sdio.c``) interacts with the
lower-half by sending commands and receiving responses:

1. ``SDIO_SENDCMD``: Send the command (e.g., CMD2, CMD9).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the call flow is more complex than this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, the original list read like a full call flow, but my intent was to only sketch the minimal interaction around CMD9/R2 and the CSD that the SDIO lower-half must return, however I'll update push them

* lower-half is responsible for returning the correct 128-bit layout.
*/

DEBUGASSERT(csd[0] != 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. First , csd[0] is 32 bits, so this doesn't just check that the first byte is 0.

Second, is it ever possible that the first byte (the CRC) is 0 naturally?

Are you able to test this on any targets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, I have removed the DEBUGASSERT and kept the PR on documenting the R@/CID/CSD expectations for SDIO lower halves

This update adds comprehensive documentation regarding the 136-bit response format for SDIO, including the structure of the response, CRC handling, and necessary byte-shifting for alignment. This information is crucial for developers implementing or maintaining SDIO drivers.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
This update expands the documentation for implementing an SDIO lower-half driver, detailing the required interface, call-flow, and handling of the R2 response format. It emphasizes the importance of byte-shifting when the CRC is stripped by the hardware, providing reference implementations for clarity.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
…ation

This update adds a reference to the SDIO Driver Documentation for implementers of SDIO lower-half drivers, emphasizing the importance of understanding R2/CSD response handling and the correct implementation of the lower-half interface.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
This update clarifies the call-flow for the SDIO lower-half driver implementation by providing a simplified example of the interaction between the MMCSD upper-half and the lower-half. It details the command sequence for handling R2 responses, improving the understanding of the expected behavior during card identification and initialization.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
@github-actions github-actions bot added Area: Documentation Improvements or additions to documentation and removed Area: Drivers Drivers issues labels Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Document CSD parsing for MMCSD upper-half

3 participants