Skip to content

Commit

Permalink
mmc: core: Read performance enhancements registers for SD cards
Browse files Browse the repository at this point in the history
In SD spec v6.x the SD function extension registers for performance
enhancements were introduced. These registers let the SD card announce
supports for various performance related features, like "self-maintenance",
"cache" and "command queuing".

Let's extend the parsing of SD function extension registers and store the
information in the struct mmc_card. This prepares for subsequent changes to
implement the complete support for new the performance enhancement
features.

Signed-off-by: Ulf Hansson <[email protected]>
Acked-by: Avri Altman <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Reviewed-by: Shawn Lin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
storulf committed Jun 14, 2021
1 parent c784f92 commit 4e6306e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
53 changes: 53 additions & 0 deletions drivers/mmc/core/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,55 @@ static int sd_parse_ext_reg_power(struct mmc_card *card, u8 fno, u8 page,
return err;
}

static int sd_parse_ext_reg_perf(struct mmc_card *card, u8 fno, u8 page,
u16 offset)
{
int err;
u8 *reg_buf;

reg_buf = kzalloc(512, GFP_KERNEL);
if (!reg_buf)
return -ENOMEM;

err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf);
if (err) {
pr_warn("%s: error %d reading PERF func of ext reg\n",
mmc_hostname(card->host), err);
goto out;
}

/* PERF revision. */
card->ext_perf.rev = reg_buf[0];

/* FX_EVENT support at bit 0. */
if (reg_buf[1] & BIT(0))
card->ext_perf.feature_support |= SD_EXT_PERF_FX_EVENT;

/* Card initiated self-maintenance support at bit 0. */
if (reg_buf[2] & BIT(0))
card->ext_perf.feature_support |= SD_EXT_PERF_CARD_MAINT;

/* Host initiated self-maintenance support at bit 1. */
if (reg_buf[2] & BIT(1))
card->ext_perf.feature_support |= SD_EXT_PERF_HOST_MAINT;

/* Cache support at bit 0. */
if (reg_buf[4] & BIT(0))
card->ext_perf.feature_support |= SD_EXT_PERF_CACHE;

/* Command queue support indicated via queue depth bits (0 to 4). */
if (reg_buf[6] & 0x1f)
card->ext_perf.feature_support |= SD_EXT_PERF_CMD_QUEUE;

card->ext_perf.fno = fno;
card->ext_perf.page = page;
card->ext_perf.offset = offset;

out:
kfree(reg_buf);
return err;
}

static int sd_parse_ext_reg(struct mmc_card *card, u8 *gen_info_buf,
u16 *next_ext_addr)
{
Expand Down Expand Up @@ -1102,6 +1151,10 @@ static int sd_parse_ext_reg(struct mmc_card *card, u8 *gen_info_buf,
if (sfc == 0x1)
return sd_parse_ext_reg_power(card, fno, page, offset);

/* Standard Function Code for performance enhancement. */
if (sfc == 0x2)
return sd_parse_ext_reg_perf(card, fno, page, offset);

return 0;
}

Expand Down
7 changes: 7 additions & 0 deletions include/linux/mmc/card.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ struct sd_ext_reg {
#define SD_EXT_POWER_OFF_NOTIFY (1<<0)
#define SD_EXT_POWER_SUSTENANCE (1<<1)
#define SD_EXT_POWER_DOWN_MODE (1<<2)
/* Performance Enhancement Function. */
#define SD_EXT_PERF_FX_EVENT (1<<0)
#define SD_EXT_PERF_CARD_MAINT (1<<1)
#define SD_EXT_PERF_HOST_MAINT (1<<2)
#define SD_EXT_PERF_CACHE (1<<3)
#define SD_EXT_PERF_CMD_QUEUE (1<<4)
};

struct sdio_cccr {
Expand Down Expand Up @@ -305,6 +311,7 @@ struct mmc_card {
struct sd_ssr ssr; /* yet more SD information */
struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
struct sd_ext_reg ext_power; /* SD extension reg for PM */
struct sd_ext_reg ext_perf; /* SD extension reg for PERF */

unsigned int sdio_funcs; /* number of SDIO functions */
atomic_t sdio_funcs_probed; /* number of probed SDIO funcs */
Expand Down

0 comments on commit 4e6306e

Please sign in to comment.