mmc: Allow speed modes to be adjusted dynamically
v2 cover mmc: Allow speed modes to be adjusted dynamically
During board verification, there is a need to test the various supported eMMC/SD speed modes. However, since the framework chooses the best mode supported by the card and the host controller's caps, this currently necessitates changing the devicetree for every iteration. This series provides a way to adjust speed modes dynamically via debugfs.
--
Changes in v2:
- Replace module parameter with a debugfs file.
- Add patch to move mmc_select_card_type().
- Link to v1: https://lore.kernel.org/r/[email protected]/
---
Vincent Whitchurch (2):
mmc: core: Always reselect card type
mmc: debugfs: Allow host caps to be modified
drivers/mmc/core/debugfs.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-- drivers/mmc/core/mmc.c | 7 ++++++- 2 files changed, 55 insertions(+), 3 deletions(-)
---
base-commit: 6465e260f48790807eef06b583b38ca9789b6072
change-id: 20230928-mmc-caps-2cc7c3295b2a
Best regards,
Signature · 1 line
Vincent Whitchurch <[email protected]>
PATCH v2 1/2 mmc: core: Always reselect card type
We want to allow host caps to be changed dynamically via debugfs, so for these to have an effect, ensure that the card type reselection is always applied even if the card is old.
--- drivers/mmc/core/mmc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/mmc/core/mmc.c +6 -1
@@ -419,7 +419,6 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) card->ext_csd.strobe_support = ext_csd[EXT_CSD_STROBE_SUPPORT ]; card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE ]; -mmc_select_card_type (card); card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT ]; card->ext_csd.raw_erase_timeout_mult =
@@ -1732,6 +1731,12 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,mmc_set_erase_size (card); } +/* +* Reselect the card type since host caps could have been changed when +* debugging even if the card is not new. +*/ +mmc_select_card_type (card); +/* Enable ERASE_GRP_DEF. This bit is lost after a reset or power off. */ if (card->ext_csd.rev >=3 ) { err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
Signature · 1 line
2.34.1
PATCH v2 2/2 mmc: debugfs: Allow host caps to be modified
In reply to Vincent WhitchurchDuring board verification, there is a need to test the various supported eMMC/SD speed modes. However, since the framework chooses the best mode supported by the card and the host controller's caps, this currently necessitates changing the devicetree for every iteration.
Allow the various speed mode host capabilities to be modified via debugfs in order to allow easier hardware verification. The values to be written are the raw MMC_CAP* values from include/linux/mmc/host.h. This is rather low-level, and these defines are not guaranteed to be stable, but it is perhaps good enough for the intended use case.
MMC_CAP_AGGRESSIVE_PM can also be set, in order to be able to re-initialize the card without having to physically remove and re-insert it.
/sys/kernel/debug/mmc0# grep timing ios
timing spec: 9 (mmc HS200)
// Turn on MMC_CAP_AGGRESSIVE_PM and re-trigger runtime suspend /sys/kernel/debug/mmc0# echo $(($(cat caps) | (1 << 7))) > caps /sys/kernel/debug/mmc0# echo on > /sys/bus/mmc/devices/mmc0\:0001/power/control /sys/kernel/debug/mmc0# echo auto > /sys/bus/mmc/devices/mmc0\:0001/power/control
// MMC_CAP2_HS200_1_8V_SDR
/sys/kernel/debug/mmc0# echo $(($(cat caps2) & ~(1 << 5))) > caps2 /sys/kernel/debug/mmc0# echo on > /sys/bus/mmc/devices/mmc0\:0001/power/control /sys/kernel/debug/mmc0# grep timing ios
timing spec: 8 (mmc DDR52)
--- drivers/mmc/core/debugfs.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-)
drivers/mmc/core/debugfs.c +49 -2
@@ -12,9 +12,12 @@#include <linux/slab.h> #include <linux/stat.h> #include <linux/fault-inject.h> +#include <linux/time.h> #include <linux/mmc/card.h> #include <linux/mmc/host.h> +#include <linux/mmc/mmc.h> +#include <linux/mmc/sd.h> #include "core.h" #include "card.h"
@@ -298,6 +301,49 @@ static const struct file_operations mmc_err_stats_fops = { .release = single_release, }; +static int mmc_caps_get (void *data,u64 *val) +{ + *val = *(u32 *)data; +return 0 ; +} + +static int mmc_caps_set (void *data,u64 val) +{ +u32 *caps = data; +u32 diff = *caps ^ val; +u32 allowed =MMC_CAP_AGGRESSIVE_PM | +MMC_CAP_SD_HIGHSPEED | +MMC_CAP_MMC_HIGHSPEED | +MMC_CAP_UHS | +MMC_CAP_DDR ; + +if (diff & ~allowed) +return -EINVAL ; + + *caps = val; + +return 0 ; +} + +static int mmc_caps2_set (void *data,u64 val) +{ +u32 allowed =MMC_CAP2_HSX00_1_8V |MMC_CAP2_HSX00_1_2V ; +u32 *caps = data; +u32 diff = *caps ^ val; + +if (diff & ~allowed) +return -EINVAL ; + + *caps = val; + +return 0 ; +} + +DEFINE_DEBUGFS_ATTRIBUTE (mmc_caps_fops, mmc_caps_get, mmc_caps_set, +"0x%08llx\n" ); +DEFINE_DEBUGFS_ATTRIBUTE (mmc_caps2_fops, mmc_caps_get, mmc_caps2_set, +"0x%08llx\n" ); +void mmc_add_host_debugfs (struct mmc_host *host) {struct dentry *root;
@@ -306,8 +352,9 @@ void mmc_add_host_debugfs(struct mmc_host *host) host->debugfs_root = root;debugfs_create_file ("ios" ,S_IRUSR , root, host, &mmc_ios_fops); -debugfs_create_x32 ("caps" ,S_IRUSR , root, &host->caps); -debugfs_create_x32 ("caps2" ,S_IRUSR , root, &host->caps2); +debugfs_create_file ("caps" ,0600 , root, &host->caps, &mmc_caps_fops); +debugfs_create_file ("caps2" ,0600 , root, &host->caps2, + &mmc_caps2_fops);debugfs_create_file_unsafe ("clock" ,S_IRUSR |S_IWUSR , root, host, &mmc_clock_fops);
Signature · 1 line
2.34.1
Re: [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified
Quoted 19 lines · Vincent Whitchurch
During board verification, there is a need to test the various supported eMMC/SD speed modes. However, since the framework chooses the best mode supported by the card and the host controller's caps, this currently necessitates changing the devicetree for every iteration.
Allow the various speed mode host capabilities to be modified via debugfs in order to allow easier hardware verification. The values to be written are the raw MMC_CAP* values from
include/linux/mmc/host.h. This is rather low-level, and these defines are not guaranteed to be stable, but it is perhaps good enough for the intended use case.
MMC_CAP_AGGRESSIVE_PMcan also be set, in order to be able to re-initialize the card without having to physically remove and re-insert it./sys/kernel/debug/mmc0# grep timing ios
timing spec: 9 (mmc HS200)
Quoted 7 lines
// Turn on
MMC_CAP_AGGRESSIVE_PMand re-trigger runtime suspend /sys/kernel/debug/mmc0# echo $(($(cat caps) | (1 << 7))) > caps /sys/kernel/debug/mmc0# echo on > /sys/bus/mmc/devices/mmc0\:0001/power/control /sys/kernel/debug/mmc0# echo auto > /sys/bus/mmc/devices/mmc0\:0001/power/control//
MMC_CAP2_HS200_1_8V_SDR
/sys/kernel/debug/mmc0# echo $(($(cat caps2) & ~(1 << 5))) > caps2
$(($(cat caps2) & ~(1 << 5))) looks complicated, does it use echo DDR52 > caps2?
Quoted 77 lines
/sys/kernel/debug/mmc0# echo on > /sys/bus/mmc/devices/mmc0\:0001/power/control /sys/kernel/debug/mmc0# grep timing ios
timing spec: 8 (mmc DDR52)Signed-off-by Vincent Whitchurch <[email protected]>--- drivers/mmc/core/debugfs.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-)drivers/mmc/core/debugfs.c +46
-0@@ -12,9 +12,12 @@#include <linux/slab.h> #include <linux/stat.h> #include <linux/fault-inject.h> +#include <linux/time.h> #include <linux/mmc/card.h> #include <linux/mmc/host.h> +#include <linux/mmc/mmc.h> +#include <linux/mmc/sd.h> #include "core.h" #include "card.h" @@ -298,6 +301,49 @@ static const struct file_operations mmc_err_stats_fops = { .release = single_release, }; +static int mmc_caps_get (void *data,u64 *val) +{ + *val = *(u32 *)data; +return 0 ; +} + +static int mmc_caps_set (void *data,u64 val) +{ +u32 *caps = data; +u32 diff = *caps ^ val; +u32 allowed =MMC_CAP_AGGRESSIVE_PM | +MMC_CAP_SD_HIGHSPEED | +MMC_CAP_MMC_HIGHSPEED | +MMC_CAP_UHS | +MMC_CAP_DDR ; + +if (diff & ~allowed) +return -EINVAL ; + + *caps = val; + +return 0 ; +} + +static int mmc_caps2_set (void *data,u64 val) +{ +u32 allowed =MMC_CAP2_HSX00_1_8V |MMC_CAP2_HSX00_1_2V ; +u32 *caps = data; +u32 diff = *caps ^ val; + +if (diff & ~allowed) +return -EINVAL ; + + *caps = val; + +return 0 ; +} + +DEFINE_DEBUGFS_ATTRIBUTE (mmc_caps_fops, mmc_caps_get, mmc_caps_set, +"0x%08llx\n" ); +DEFINE_DEBUGFS_ATTRIBUTE (mmc_caps2_fops, mmc_caps_get, mmc_caps2_set, +"0x%08llx\n" ); +void mmc_add_host_debugfs (struct mmc_host *host) {struct dentry *root;
drivers/mmc/core/debugfs.c void mmc_add_host_debugfs(struct mmc_host *host) · line 357
Quoted 8 lines
drivers/mmc/core/debugfs.c +3
-2@@ -306,8 +352,9 @@ void mmc_add_host_debugfs(struct mmc_host *host) host->debugfs_root = root;debugfs_create_file ("ios" ,S_IRUSR , root, host, &mmc_ios_fops); -debugfs_create_x32 ("caps" ,S_IRUSR , root, &host->caps); -debugfs_create_x32 ("caps2" ,S_IRUSR , root, &host->caps2); +debugfs_create_file ("caps" ,0600 , root, &host->caps, &mmc_caps_fops); +debugfs_create_file ("caps2" ,0600 , root, &host->caps2, + &mmc_caps2_fops);
Would it be better to use "S_IRUSR | S_IWUSR" instead of "0600"?
Quoted 7 lines
drivers/mmc/core/debugfs.c +0
-1debugfs_create_file_unsafe ("clock" ,S_IRUSR |S_IWUSR , root, host, &mmc_clock_fops); --2.34.1
Re: [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified
Quoted 6 lines · Wenchao Chen
Quoted 2 lines · Vincent Whitchurch
//
MMC_CAP2_HS200_1_8V_SDR
/sys/kernel/debug/mmc0# echo $(($(cat caps2) & ~(1 << 5))) > caps2$(($(cat caps2) & ~(1 << 5))) looks complicated, does it use echo DDR52 > caps2?
1 << 5 is (as the comment above says) MMC_CAP2_HS200_1_8V_SDR. The read-modify-write is needed to not clear unrelated bits. The MMC framework picks the best possible mode supported by both the card and the host controller, so disabling support for HS200 in the host controller leads to DDR52 being picked in this case.
[...]
Quoted 6 lines
Quoted 6 lines
void
mmc_add_host_debugfs(struct mmc_host *host)
{
struct dentry *root;drivers/mmc/core/debugfs.c +0
-0@@ -306,8 +352,9 @@ void mmc_add_host_debugfs(struct mmc_host *host) host->debugfs_root = root;
Quoted 8 lines
drivers/mmc/core/debugfs.c void mmc_add_host_debugfs(struct mmc_host *host) · line 357
Quoted 6 lines
drivers/mmc/core/debugfs.c +3
-2debugfs_create_file("ios", S_IRUSR, root, host, &mmc_ios_fops); -debugfs_create_x32 ("caps" ,S_IRUSR , root, &host->caps); -debugfs_create_x32 ("caps2" ,S_IRUSR , root, &host->caps2); +debugfs_create_file ("caps" ,0600 , root, &host->caps, &mmc_caps_fops); +debugfs_create_file ("caps2" ,0600 , root, &host->caps2, + &mmc_caps2_fops);Would it be better to use "
S_IRUSR|S_IWUSR" instead of "0600"?
No, not according to checkpatch which says that numeric permissions are preferred.
Quoted 18 lines · Vincent Whitchurch
During board verification, there is a need to test the various supported eMMC/SD speed modes. However, since the framework chooses the best mode supported by the card and the host controller's caps, this currently necessitates changing the devicetree for every iteration. This series provides a way to adjust speed modes dynamically via debugfs.
--
Changes in v2:
- Replace module parameter with a debugfs file.
- Add patch to movemmc_select_card_type().
- Link to v1: https://lore.kernel.org/r/[email protected]/---
Vincent Whitchurch (2):
mmc: core: Always reselect card type
mmc: debugfs: Allow host caps to be modified
Quoted 4 lines
drivers/mmc/core/debugfs.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-- drivers/mmc/core/mmc.c | 7 ++++++- 2 files changed, 55 insertions(+), 3 deletions(-)---
Applied for next, thanks!
Kind regards
Uffe