All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically
@ 2023-09-29  7:45 Vincent Whitchurch
  2023-09-29  7:45 ` [PATCH v2 1/2] mmc: core: Always reselect card type Vincent Whitchurch
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Vincent Whitchurch @ 2023-09-29  7:45 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc, linux-kernel, kernel, 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 move mmc_select_card_type().
- Link to v1: https://lore.kernel.org/r/20220623080009.1775574-1-vincent.whitchurch@axis.com/

---
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,
-- 
Vincent Whitchurch <vincent.whitchurch@axis.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] mmc: core: Always reselect card type
  2023-09-29  7:45 [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically Vincent Whitchurch
@ 2023-09-29  7:45 ` Vincent Whitchurch
  2023-09-29  7:45 ` [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified Vincent Whitchurch
  2023-10-10 14:27 ` [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically Ulf Hansson
  2 siblings, 0 replies; 6+ messages in thread
From: Vincent Whitchurch @ 2023-09-29  7:45 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc, linux-kernel, kernel, Vincent Whitchurch

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.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 drivers/mmc/core/mmc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 89cd48fcec79..d372e2098ffc 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -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,

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified
  2023-09-29  7:45 [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically Vincent Whitchurch
  2023-09-29  7:45 ` [PATCH v2 1/2] mmc: core: Always reselect card type Vincent Whitchurch
@ 2023-09-29  7:45 ` Vincent Whitchurch
  2023-10-07  2:27   ` Wenchao Chen
  2023-10-10 14:27 ` [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically Ulf Hansson
  2 siblings, 1 reply; 6+ messages in thread
From: Vincent Whitchurch @ 2023-09-29  7:45 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc, linux-kernel, kernel, 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_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)

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 drivers/mmc/core/debugfs.c | 51 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 2c97b94aab23..1642ea72d22c 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -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);
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified
  2023-09-29  7:45 ` [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified Vincent Whitchurch
@ 2023-10-07  2:27   ` Wenchao Chen
  2023-10-09  7:28     ` Vincent Whitchurch
  0 siblings, 1 reply; 6+ messages in thread
From: Wenchao Chen @ 2023-10-07  2:27 UTC (permalink / raw)
  To: Vincent Whitchurch; +Cc: Ulf Hansson, linux-mmc, linux-kernel, kernel

On Fri, 29 Sept 2023 at 21:17, Vincent Whitchurch
<vincent.whitchurch@axis.com> wrote:
>
> 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_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

$(($(cat caps2) & ~(1 << 5))) looks complicated, does it use echo DDR52 > 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)
>
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> ---
>  drivers/mmc/core/debugfs.c | 51 ++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 49 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
> index 2c97b94aab23..1642ea72d22c 100644
> --- a/drivers/mmc/core/debugfs.c
> +++ b/drivers/mmc/core/debugfs.c
> @@ -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);

Would it be better to use "S_IRUSR | S_IWUSR" instead of "0600"?

>         debugfs_create_file_unsafe("clock", S_IRUSR | S_IWUSR, root, host,
>                                    &mmc_clock_fops);
>
>
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified
  2023-10-07  2:27   ` Wenchao Chen
@ 2023-10-09  7:28     ` Vincent Whitchurch
  0 siblings, 0 replies; 6+ messages in thread
From: Vincent Whitchurch @ 2023-10-09  7:28 UTC (permalink / raw)
  To: Vincent Whitchurch, wenchao.chen666
  Cc: ulf.hansson, linux-mmc, linux-kernel, kernel

On Sat, 2023-10-07 at 10:27 +0800, Wenchao Chen wrote:
> On Fri, 29 Sept 2023 at 21:17, Vincent Whitchurch
> <vincent.whitchurch@axis.com> wrote:
> >  // 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.

[...]
> >  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);
> 
> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically
  2023-09-29  7:45 [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically Vincent Whitchurch
  2023-09-29  7:45 ` [PATCH v2 1/2] mmc: core: Always reselect card type Vincent Whitchurch
  2023-09-29  7:45 ` [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified Vincent Whitchurch
@ 2023-10-10 14:27 ` Ulf Hansson
  2 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2023-10-10 14:27 UTC (permalink / raw)
  To: Vincent Whitchurch; +Cc: linux-mmc, linux-kernel, kernel

On Fri, 29 Sept 2023 at 09:45, Vincent Whitchurch
<vincent.whitchurch@axis.com> wrote:
>
> 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/20220623080009.1775574-1-vincent.whitchurch@axis.com/
>
> ---
> 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(-)
> ---

Applied for next, thanks!

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-10 14:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-29  7:45 [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically Vincent Whitchurch
2023-09-29  7:45 ` [PATCH v2 1/2] mmc: core: Always reselect card type Vincent Whitchurch
2023-09-29  7:45 ` [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified Vincent Whitchurch
2023-10-07  2:27   ` Wenchao Chen
2023-10-09  7:28     ` Vincent Whitchurch
2023-10-10 14:27 ` [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically Ulf Hansson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.