sdmmc: Add erase command-38. Support erase/trim/discard/sanitize
options. Erase command (38) for SD cards allows option for erase/dicard/fule operation at block level and for MMC cards supports option for discard/trim at block level. When Sanitize is executed only the portion of data that was unmapped by a Discard command shall be removed by the Sanitize command. Unit test cases added to verify ERASE feature in SD/SDSPI mode. TRIM/DISCARD/SANITIZE tests for eMMC devices. Closes https://github.com/espressif/esp-idf/pull/7635 Closes https://github.com/espressif/esp-idf/issues/7623
This commit is contained in:
@@ -47,12 +47,17 @@
|
||||
#define MMC_SET_BLOCK_COUNT 23 /* R1 */
|
||||
#define MMC_WRITE_BLOCK_SINGLE 24 /* R1 */
|
||||
#define MMC_WRITE_BLOCK_MULTIPLE 25 /* R1 */
|
||||
#define MMC_ERASE_GROUP_START 35 /* R1 */
|
||||
#define MMC_ERASE_GROUP_END 36 /* R1 */
|
||||
#define MMC_ERASE 38 /* R1B */
|
||||
#define MMC_APP_CMD 55 /* R1 */
|
||||
|
||||
/* SD commands */ /* response type */
|
||||
#define SD_SEND_RELATIVE_ADDR 3 /* R6 */
|
||||
#define SD_SEND_SWITCH_FUNC 6 /* R1 */
|
||||
#define SD_SEND_IF_COND 8 /* R7 */
|
||||
#define SD_ERASE_GROUP_START 32 /* R1 */
|
||||
#define SD_ERASE_GROUP_END 33 /* R1 */
|
||||
#define SD_READ_OCR 58 /* R3 */
|
||||
#define SD_CRC_ON_OFF 59 /* R1 */
|
||||
|
||||
@@ -141,21 +146,26 @@
|
||||
#define SD_ARG_BUS_WIDTH_4 2
|
||||
|
||||
/* EXT_CSD fields */
|
||||
#define EXT_CSD_SANITIZE_START 165 /* WO */
|
||||
#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */
|
||||
#define EXT_CSD_BUS_WIDTH 183 /* WO */
|
||||
#define EXT_CSD_HS_TIMING 185 /* R/W */
|
||||
#define EXT_CSD_POWER_CLASS 187 /* R/W */
|
||||
#define EXT_CSD_CMD_SET 191 /* R/W */
|
||||
#define EXT_CSD_REV 192 /* RO */
|
||||
#define EXT_CSD_STRUCTURE 194 /* RO */
|
||||
#define EXT_CSD_CARD_TYPE 196 /* RO */
|
||||
#define EXT_CSD_SEC_COUNT 212 /* RO */
|
||||
#define EXT_CSD_PWR_CL_26_360 203 /* RO */
|
||||
#define EXT_CSD_PWR_CL_52_360 202 /* RO */
|
||||
#define EXT_CSD_PWR_CL_26_195 201 /* RO */
|
||||
#define EXT_CSD_PWR_CL_52_195 200 /* RO */
|
||||
#define EXT_CSD_POWER_CLASS 187 /* R/W */
|
||||
#define EXT_CSD_CMD_SET 191 /* R/W */
|
||||
#define EXT_CSD_PWR_CL_26_195 201 /* RO */
|
||||
#define EXT_CSD_PWR_CL_52_360 202 /* RO */
|
||||
#define EXT_CSD_PWR_CL_26_360 203 /* RO */
|
||||
#define EXT_CSD_SEC_COUNT 212 /* RO */
|
||||
#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */
|
||||
#define EXT_CSD_S_CMD_SET 504 /* RO */
|
||||
|
||||
/* EXT_CSD field definitions */
|
||||
#define EXT_CSD_REV_1_6 6 /* Revision 1.6 (for MMC v4.5, v4.51) */
|
||||
|
||||
#define EXT_CSD_CMD_SET_NORMAL (1U << 0)
|
||||
#define EXT_CSD_CMD_SET_SECURE (1U << 1)
|
||||
#define EXT_CSD_CMD_SET_CPSECURE (1U << 2)
|
||||
@@ -186,6 +196,12 @@
|
||||
#define EXT_CSD_CARD_TYPE_52M_V12 0x0b
|
||||
#define EXT_CSD_CARD_TYPE_52M_V12_18 0x0f
|
||||
|
||||
/* EXT_CSD_SEC_FEATURE_SUPPORT */
|
||||
#define EXT_CSD_SECURE_ER_EN (uint8_t)(1 << 0)
|
||||
#define EXT_CSD_SEC_BD_BLK_EN (uint8_t)(1 << 2)
|
||||
#define EXT_CSD_SEC_GB_CL_EN (uint8_t)(1 << 4)
|
||||
#define EXT_CSD_SEC_SANITIZE (uint8_t)(1 << 6)
|
||||
|
||||
/* EXT_CSD MMC */
|
||||
#define EXT_CSD_MMC_SIZE 512
|
||||
|
||||
@@ -336,6 +352,12 @@
|
||||
#define SCR_CMD_SUPPORT_CMD20(scr) MMC_RSP_BITS((scr), 32, 1)
|
||||
#define SCR_RESERVED2(scr) MMC_RSP_BITS((scr), 0, 32)
|
||||
|
||||
/* SSR (SD Status Register) */
|
||||
#define SSR_DAT_BUS_WIDTH(ssr) MMC_RSP_BITS((ssr), 510, 2)
|
||||
#define SSR_AU_SIZE(ssr) MMC_RSP_BITS((ssr), 428, 4)
|
||||
#define SSR_DISCARD_SUPPORT(ssr) MMC_RSP_BITS((ssr), 313, 1)
|
||||
#define SSR_FULE_SUPPORT(ssr) MMC_RSP_BITS((ssr), 312, 1)
|
||||
|
||||
/* Max supply current in SWITCH_FUNC response (in mA) */
|
||||
#define SD_SFUNC_I_MAX(status) (MMC_RSP_BITS((uint32_t *)(status), 496, 16))
|
||||
|
||||
@@ -365,6 +387,8 @@
|
||||
#define SD_ACCESS_MODE_SDR104 3 /* UHS-I, 208 MHz clock */
|
||||
#define SD_ACCESS_MODE_DDR50 4 /* UHS-I, 50 MHz clock, DDR */
|
||||
|
||||
#define SD_SSR_SIZE 64 /* SD status register */
|
||||
|
||||
/**
|
||||
* @brief Extract up to 32 sequential bits from an array of 32-bit words
|
||||
*
|
||||
|
||||
@@ -56,17 +56,35 @@ typedef struct {
|
||||
|
||||
/**
|
||||
* Decoded values from SD Configuration Register
|
||||
* Note: When new member is added, update reserved bits accordingly
|
||||
*/
|
||||
typedef struct {
|
||||
int sd_spec; /*!< SD Physical layer specification version, reported by card */
|
||||
int bus_width; /*!< bus widths supported by card: BIT(0) — 1-bit bus, BIT(2) — 4-bit bus */
|
||||
uint32_t sd_spec: 4; /*!< SD Physical layer specification version, reported by card */
|
||||
uint32_t erase_mem_state: 1; /*!< data state on card after erase whether 0 or 1 (card vendor dependent) */
|
||||
uint32_t bus_width: 4; /*!< bus widths supported by card: BIT(0) — 1-bit bus, BIT(2) — 4-bit bus */
|
||||
uint32_t reserved: 23; /*!< reserved for future expansion */
|
||||
uint32_t rsvd_mnf; /*!< reserved for manufacturer usage */
|
||||
} sdmmc_scr_t;
|
||||
|
||||
/**
|
||||
* Decoded values from SD Status Register
|
||||
* Note: When new member is added, update reserved bits accordingly
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t cur_bus_width: 2; /*!< SD current bus width */
|
||||
uint32_t discard_support: 1; /*!< SD discard feature support */
|
||||
uint32_t fule_support: 1; /*!< SD FULE (Full User Area Logical Erase) feature support */
|
||||
uint32_t reserved: 28; /*!< reserved for future expansion */
|
||||
} sdmmc_ssr_t;
|
||||
|
||||
/**
|
||||
* Decoded values of Extended Card Specific Data
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t power_class; /*!< Power class used by the card */
|
||||
uint8_t rev; /*!< Extended CSD Revision */
|
||||
uint8_t power_class; /*!< Power class used by the card */
|
||||
uint8_t erase_mem_state; /*!< data state on card after erase whether 0 or 1 (card vendor dependent) */
|
||||
uint8_t sec_feature; /*!< secure data management features supported by the card */
|
||||
} sdmmc_ext_csd_t;
|
||||
|
||||
/**
|
||||
@@ -120,7 +138,7 @@ typedef struct {
|
||||
#define SCF_WAIT_BUSY 0x2000 /*!< Wait for completion of card busy signal before returning */
|
||||
/** @endcond */
|
||||
esp_err_t error; /*!< error returned from transfer */
|
||||
int timeout_ms; /*!< response timeout, in milliseconds */
|
||||
uint32_t timeout_ms; /*!< response timeout, in milliseconds */
|
||||
} sdmmc_command_t;
|
||||
|
||||
/**
|
||||
@@ -173,6 +191,7 @@ typedef struct {
|
||||
};
|
||||
sdmmc_csd_t csd; /*!< decoded CSD (Card-Specific Data) register value */
|
||||
sdmmc_scr_t scr; /*!< decoded SCR (SD card Configuration Register) value */
|
||||
sdmmc_ssr_t ssr; /*!< decoded SSR (SD Status Register) value */
|
||||
sdmmc_ext_csd_t ext_csd; /*!< decoded EXT_CSD (Extended Card Specific Data) register value */
|
||||
uint16_t rca; /*!< RCA (Relative Card Address) */
|
||||
uint16_t max_freq_khz; /*!< Maximum frequency, in kHz, supported by the card */
|
||||
@@ -185,5 +204,28 @@ typedef struct {
|
||||
uint32_t reserved : 23; /*!< Reserved for future expansion */
|
||||
} sdmmc_card_t;
|
||||
|
||||
/**
|
||||
* SD/MMC erase command(38) arguments
|
||||
* SD:
|
||||
* ERASE: Erase the write blocks, physical/hard erase.
|
||||
*
|
||||
* DISCARD: Card may deallocate the discarded blocks partially or completely.
|
||||
* After discard operation the previously written data may be partially or
|
||||
* fully read by the host depending on card implementation.
|
||||
*
|
||||
* MMC:
|
||||
* ERASE: Does TRIM, applies erase operation to write blocks instead of Erase Group.
|
||||
*
|
||||
* DISCARD: The Discard function allows the host to identify data that is no
|
||||
* longer required so that the device can erase the data if necessary during
|
||||
* background erase events. Applies to write blocks instead of Erase Group
|
||||
* After discard operation, the original data may be remained partially or
|
||||
* fully accessible to the host dependent on device.
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
SDMMC_ERASE_ARG = 0, /*!< Erase operation on SD, Trim operation on MMC */
|
||||
SDMMC_DISCARD_ARG = 1, /*!< Discard operation for SD/MMC */
|
||||
} sdmmc_erase_arg_t;
|
||||
|
||||
#endif // _SDMMC_TYPES_H_
|
||||
|
||||
Reference in New Issue
Block a user