2021-04-20 05:56:50

by Avri Altman

[permalink] [raw]
Subject: [PATCH v3 0/2] Do not flush cache when it is disabled

v2 -> v3:
- rebase onto recent cache changes

v1 -> v2:
- Attend Adrian's comments

Cache is a temporary storage space in an eMMC device. Volatile by
nature, the cache should in typical case reduce the access time compared
to an access to the main nonvolatile storage.

The cache function can be turned ON and OFF. Once OFF, the host is not
expected to issue a flush-cache command to the device.

Avri Altman (2):
mmc: block: Issue flush only if allowed
mmc: block: Update ext_csd.cache_ctrl if it was written

drivers/mmc/core/block.c | 19 +++++++++++++++++++
drivers/mmc/core/mmc.c | 2 +-
drivers/mmc/core/mmc_ops.h | 5 +++++
3 files changed, 25 insertions(+), 1 deletion(-)

--
2.25.1


2021-04-20 05:58:11

by Avri Altman

[permalink] [raw]
Subject: [PATCH v3 2/2] mmc: block: Update ext_csd.cache_ctrl if it was written

The cache function can be turned ON and OFF by writing to the CACHE_CTRL
byte (EXT_CSD byte [33]). However, card->ext_csd.cache_ctrl is only
set on init if cache size > 0.

Fix that by explicitly setting ext_csd.cache_ctrl on ext-csd write.

Signed-off-by: Avri Altman <[email protected]>
---
drivers/mmc/core/block.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 5b6501fc9fb7..8b07ed5e08de 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -572,6 +572,18 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
main_md->part_curr = value & EXT_CSD_PART_CONFIG_ACC_MASK;
}

+ /*
+ * Make sure to update CACHE_CTRL in case it was changed. The cache
+ * will get turned back on if the card is re-initialized, e.g.
+ * suspend/resume or hw reset in recovery.
+ */
+ if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_CACHE_CTRL) &&
+ (cmd.opcode == MMC_SWITCH)) {
+ u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd.arg) & 1;
+
+ card->ext_csd.cache_ctrl = value;
+ }
+
/*
* According to the SD specs, some commands require a delay after
* issuing the command.
--
2.25.1

2021-04-20 11:23:53

by Adrian Hunter

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] mmc: block: Update ext_csd.cache_ctrl if it was written

On 20/04/21 8:53 am, Avri Altman wrote:
> The cache function can be turned ON and OFF by writing to the CACHE_CTRL
> byte (EXT_CSD byte [33]). However, card->ext_csd.cache_ctrl is only
> set on init if cache size > 0.
>
> Fix that by explicitly setting ext_csd.cache_ctrl on ext-csd write.
>
> Signed-off-by: Avri Altman <[email protected]>

Acked-by: Adrian Hunter <[email protected]>

> ---
> drivers/mmc/core/block.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 5b6501fc9fb7..8b07ed5e08de 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -572,6 +572,18 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
> main_md->part_curr = value & EXT_CSD_PART_CONFIG_ACC_MASK;
> }
>
> + /*
> + * Make sure to update CACHE_CTRL in case it was changed. The cache
> + * will get turned back on if the card is re-initialized, e.g.
> + * suspend/resume or hw reset in recovery.
> + */
> + if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_CACHE_CTRL) &&
> + (cmd.opcode == MMC_SWITCH)) {
> + u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd.arg) & 1;
> +
> + card->ext_csd.cache_ctrl = value;
> + }
> +
> /*
> * According to the SD specs, some commands require a delay after
> * issuing the command.
>