linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap
@ 2025-08-18  6:07 Kuen-Han Tsai
  2025-08-18  6:07 ` [PATCH 2/2] usb: dwc3: Refactor dwc3_mode_show Kuen-Han Tsai
  2025-08-21 23:30 ` [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap Thinh Nguyen
  0 siblings, 2 replies; 5+ messages in thread
From: Kuen-Han Tsai @ 2025-08-18  6:07 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh; +Cc: linux-usb, linux-kernel, Kuen-Han Tsai

Changes to the port capability can be indirectly observed by tracing
register writes to DWC3_GCTL. However, this requires interpreting the
raw value, which is neither intuitive nor precise for debugging.
Monitoring these mode changes is essential for resolving issues related
to USB role switching and enumeration.

Introduce a dedicated trace event to provide a human-readable log when
the port capability is configured.

Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
---
 drivers/usb/dwc3/core.c  |  1 +
 drivers/usb/dwc3/debug.h | 18 ++++++++++++++++++
 drivers/usb/dwc3/trace.h | 17 +++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 8002c23a5a02..370fc524a468 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -156,6 +156,7 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy)
 	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
 
 	dwc->current_dr_role = mode;
+	trace_dwc3_set_prtcap(mode);
 }
 
 static void __dwc3_set_mode(struct work_struct *work)
diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index 09d703852a92..70d90790f872 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -13,6 +13,24 @@
 
 #include "core.h"
 
+/**
+ * dwc3_mode_string - returns mode name
+ * @mode: mode code
+ */
+static inline const char *dwc3_mode_string(u32 mode)
+{
+	switch (mode) {
+	case DWC3_GCTL_PRTCAP_HOST:
+		return "host";
+	case DWC3_GCTL_PRTCAP_DEVICE:
+		return "device";
+	case DWC3_GCTL_PRTCAP_OTG:
+		return "otg";
+	default:
+		return "UNKNOWN";
+	}
+}
+
 /**
  * dwc3_gadget_ep_cmd_string - returns endpoint command string
  * @cmd: command code
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
index bdeb1aaf65d8..b6ba984bafcd 100644
--- a/drivers/usb/dwc3/trace.h
+++ b/drivers/usb/dwc3/trace.h
@@ -19,6 +19,23 @@
 #include "core.h"
 #include "debug.h"
 
+DECLARE_EVENT_CLASS(dwc3_log_set_prtcap,
+	TP_PROTO(u32 mode),
+	TP_ARGS(mode),
+	TP_STRUCT__entry(
+		__field(u32, mode)
+	),
+	TP_fast_assign(
+		__entry->mode = mode;
+	),
+	TP_printk("mode %s", dwc3_mode_string(__entry->mode))
+);
+
+DEFINE_EVENT(dwc3_log_set_prtcap, dwc3_set_prtcap,
+	TP_PROTO(u32 mode),
+	TP_ARGS(mode)
+);
+
 DECLARE_EVENT_CLASS(dwc3_log_io,
 	TP_PROTO(void *base, u32 offset, u32 value),
 	TP_ARGS(base, offset, value),
-- 
2.51.0.rc1.163.g2494970778-goog


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

* [PATCH 2/2] usb: dwc3: Refactor dwc3_mode_show
  2025-08-18  6:07 [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap Kuen-Han Tsai
@ 2025-08-18  6:07 ` Kuen-Han Tsai
  2025-08-21 23:30   ` Thinh Nguyen
  2025-08-21 23:30 ` [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap Thinh Nguyen
  1 sibling, 1 reply; 5+ messages in thread
From: Kuen-Han Tsai @ 2025-08-18  6:07 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh; +Cc: linux-usb, linux-kernel, Kuen-Han Tsai

Use dwc3_mode_string as the single source of truth for mode-to-string
conversion.

Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
---
 drivers/usb/dwc3/debugfs.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index ebf03468fac4..d18bf5e32cc8 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -402,6 +402,7 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
 	struct dwc3		*dwc = s->private;
 	unsigned long		flags;
 	u32			reg;
+	u32			mode;
 	int			ret;
 
 	ret = pm_runtime_resume_and_get(dwc->dev);
@@ -412,18 +413,15 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
 	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
-	switch (DWC3_GCTL_PRTCAP(reg)) {
+	mode = DWC3_GCTL_PRTCAP(reg);
+	switch (mode) {
 	case DWC3_GCTL_PRTCAP_HOST:
-		seq_puts(s, "host\n");
-		break;
 	case DWC3_GCTL_PRTCAP_DEVICE:
-		seq_puts(s, "device\n");
-		break;
 	case DWC3_GCTL_PRTCAP_OTG:
-		seq_puts(s, "otg\n");
+		seq_printf(s, "%s\n", dwc3_mode_string(mode));
 		break;
 	default:
-		seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
+		seq_printf(s, "UNKNOWN %08x\n", mode);
 	}
 
 	pm_runtime_put_sync(dwc->dev);
-- 
2.51.0.rc1.163.g2494970778-goog


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

* Re: [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap
  2025-08-18  6:07 [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap Kuen-Han Tsai
  2025-08-18  6:07 ` [PATCH 2/2] usb: dwc3: Refactor dwc3_mode_show Kuen-Han Tsai
@ 2025-08-21 23:30 ` Thinh Nguyen
  2025-08-22  9:27   ` Kuen-Han Tsai
  1 sibling, 1 reply; 5+ messages in thread
From: Thinh Nguyen @ 2025-08-21 23:30 UTC (permalink / raw)
  To: Kuen-Han Tsai
  Cc: Thinh Nguyen, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org

On Mon, Aug 18, 2025, Kuen-Han Tsai wrote:
> Changes to the port capability can be indirectly observed by tracing
> register writes to DWC3_GCTL. However, this requires interpreting the
> raw value, which is neither intuitive nor precise for debugging.
> Monitoring these mode changes is essential for resolving issues related
> to USB role switching and enumeration.
> 
> Introduce a dedicated trace event to provide a human-readable log when
> the port capability is configured.
> 
> Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
> ---
>  drivers/usb/dwc3/core.c  |  1 +
>  drivers/usb/dwc3/debug.h | 18 ++++++++++++++++++
>  drivers/usb/dwc3/trace.h | 17 +++++++++++++++++
>  3 files changed, 36 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 8002c23a5a02..370fc524a468 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -156,6 +156,7 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy)
>  	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
>  
>  	dwc->current_dr_role = mode;
> +	trace_dwc3_set_prtcap(mode);
>  }
>  
>  static void __dwc3_set_mode(struct work_struct *work)
> diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
> index 09d703852a92..70d90790f872 100644
> --- a/drivers/usb/dwc3/debug.h
> +++ b/drivers/usb/dwc3/debug.h
> @@ -13,6 +13,24 @@
>  
>  #include "core.h"
>  
> +/**
> + * dwc3_mode_string - returns mode name
> + * @mode: mode code

Minor nit: would be better to document as GCTL.PrtCapDir value, but it's
obvious looking at this small function. So it's fine.

> + */
> +static inline const char *dwc3_mode_string(u32 mode)
> +{
> +	switch (mode) {
> +	case DWC3_GCTL_PRTCAP_HOST:
> +		return "host";
> +	case DWC3_GCTL_PRTCAP_DEVICE:
> +		return "device";
> +	case DWC3_GCTL_PRTCAP_OTG:
> +		return "otg";
> +	default:
> +		return "UNKNOWN";
> +	}
> +}
> +
>  /**
>   * dwc3_gadget_ep_cmd_string - returns endpoint command string
>   * @cmd: command code
> diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
> index bdeb1aaf65d8..b6ba984bafcd 100644
> --- a/drivers/usb/dwc3/trace.h
> +++ b/drivers/usb/dwc3/trace.h
> @@ -19,6 +19,23 @@
>  #include "core.h"
>  #include "debug.h"
>  
> +DECLARE_EVENT_CLASS(dwc3_log_set_prtcap,
> +	TP_PROTO(u32 mode),
> +	TP_ARGS(mode),
> +	TP_STRUCT__entry(
> +		__field(u32, mode)
> +	),
> +	TP_fast_assign(
> +		__entry->mode = mode;
> +	),
> +	TP_printk("mode %s", dwc3_mode_string(__entry->mode))
> +);
> +
> +DEFINE_EVENT(dwc3_log_set_prtcap, dwc3_set_prtcap,
> +	TP_PROTO(u32 mode),
> +	TP_ARGS(mode)
> +);
> +
>  DECLARE_EVENT_CLASS(dwc3_log_io,
>  	TP_PROTO(void *base, u32 offset, u32 value),
>  	TP_ARGS(base, offset, value),
> -- 
> 2.51.0.rc1.163.g2494970778-goog
> 

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

Thanks,
Thinh

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

* Re: [PATCH 2/2] usb: dwc3: Refactor dwc3_mode_show
  2025-08-18  6:07 ` [PATCH 2/2] usb: dwc3: Refactor dwc3_mode_show Kuen-Han Tsai
@ 2025-08-21 23:30   ` Thinh Nguyen
  0 siblings, 0 replies; 5+ messages in thread
From: Thinh Nguyen @ 2025-08-21 23:30 UTC (permalink / raw)
  To: Kuen-Han Tsai
  Cc: Thinh Nguyen, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org

On Mon, Aug 18, 2025, Kuen-Han Tsai wrote:
> Use dwc3_mode_string as the single source of truth for mode-to-string
> conversion.
> 
> Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
> ---
>  drivers/usb/dwc3/debugfs.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
> index ebf03468fac4..d18bf5e32cc8 100644
> --- a/drivers/usb/dwc3/debugfs.c
> +++ b/drivers/usb/dwc3/debugfs.c
> @@ -402,6 +402,7 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
>  	struct dwc3		*dwc = s->private;
>  	unsigned long		flags;
>  	u32			reg;
> +	u32			mode;
>  	int			ret;
>  
>  	ret = pm_runtime_resume_and_get(dwc->dev);
> @@ -412,18 +413,15 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
>  	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
>  	spin_unlock_irqrestore(&dwc->lock, flags);
>  
> -	switch (DWC3_GCTL_PRTCAP(reg)) {
> +	mode = DWC3_GCTL_PRTCAP(reg);
> +	switch (mode) {
>  	case DWC3_GCTL_PRTCAP_HOST:
> -		seq_puts(s, "host\n");
> -		break;
>  	case DWC3_GCTL_PRTCAP_DEVICE:
> -		seq_puts(s, "device\n");
> -		break;
>  	case DWC3_GCTL_PRTCAP_OTG:
> -		seq_puts(s, "otg\n");
> +		seq_printf(s, "%s\n", dwc3_mode_string(mode));
>  		break;
>  	default:
> -		seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
> +		seq_printf(s, "UNKNOWN %08x\n", mode);
>  	}
>  
>  	pm_runtime_put_sync(dwc->dev);
> -- 
> 2.51.0.rc1.163.g2494970778-goog
> 

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

Thanks,
Thinh

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

* Re: [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap
  2025-08-21 23:30 ` [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap Thinh Nguyen
@ 2025-08-22  9:27   ` Kuen-Han Tsai
  0 siblings, 0 replies; 5+ messages in thread
From: Kuen-Han Tsai @ 2025-08-22  9:27 UTC (permalink / raw)
  To: Thinh Nguyen
  Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org

Hi Thinh,

On Fri, Aug 22, 2025 at 7:30 AM Thinh Nguyen <Thinh.Nguyen@synopsys.com> wrote:
>
> On Mon, Aug 18, 2025, Kuen-Han Tsai wrote:
> > Changes to the port capability can be indirectly observed by tracing
> > register writes to DWC3_GCTL. However, this requires interpreting the
> > raw value, which is neither intuitive nor precise for debugging.
> > Monitoring these mode changes is essential for resolving issues related
> > to USB role switching and enumeration.
> >
> > Introduce a dedicated trace event to provide a human-readable log when
> > the port capability is configured.
> >
> > Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
> > ---
> >  drivers/usb/dwc3/core.c  |  1 +
> >  drivers/usb/dwc3/debug.h | 18 ++++++++++++++++++
> >  drivers/usb/dwc3/trace.h | 17 +++++++++++++++++
> >  3 files changed, 36 insertions(+)
> >
> > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> > index 8002c23a5a02..370fc524a468 100644
> > --- a/drivers/usb/dwc3/core.c
> > +++ b/drivers/usb/dwc3/core.c
> > @@ -156,6 +156,7 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy)
> >       dwc3_writel(dwc->regs, DWC3_GCTL, reg);
> >
> >       dwc->current_dr_role = mode;
> > +     trace_dwc3_set_prtcap(mode);
> >  }
> >
> >  static void __dwc3_set_mode(struct work_struct *work)
> > diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
> > index 09d703852a92..70d90790f872 100644
> > --- a/drivers/usb/dwc3/debug.h
> > +++ b/drivers/usb/dwc3/debug.h
> > @@ -13,6 +13,24 @@
> >
> >  #include "core.h"
> >
> > +/**
> > + * dwc3_mode_string - returns mode name
> > + * @mode: mode code
>
> Minor nit: would be better to document as GCTL.PrtCapDir value, but it's
> obvious looking at this small function. So it's fine.

Thanks for the review. I've updated the description for @mode in the
second patch as you suggested.

Regards,
Kuen-Han

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

end of thread, other threads:[~2025-08-22  9:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18  6:07 [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap Kuen-Han Tsai
2025-08-18  6:07 ` [PATCH 2/2] usb: dwc3: Refactor dwc3_mode_show Kuen-Han Tsai
2025-08-21 23:30   ` Thinh Nguyen
2025-08-21 23:30 ` [PATCH 1/2] usb: dwc3: Add trace event for dwc3_set_prtcap Thinh Nguyen
2025-08-22  9:27   ` Kuen-Han Tsai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).