]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: dwc3: Add trace event for dwc3_set_prtcap
authorKuen-Han Tsai <khtsai@google.com>
Fri, 22 Aug 2025 09:23:45 +0000 (17:23 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 6 Sep 2025 13:21:59 +0000 (15:21 +0200)
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>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/20250822092411.173519-1-khtsai@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/core.c
drivers/usb/dwc3/debug.h
drivers/usb/dwc3/trace.h

index 8002c23a5a02acb8f3e87b2662a53998a4cf4f5c..370fc524a468eb8377e69a36ae689b4b05f4f0de 100644 (file)
@@ -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)
index 09d703852a92bd9b86fde2262c45068af6aa8c9b..6e1cdcdce7cc39c59c503192fcf86a8f61dbfd47 100644 (file)
 
 #include "core.h"
 
+/**
+ * dwc3_mode_string - returns mode name
+ * @mode: GCTL.PrtCapDir value
+ */
+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
index bdeb1aaf65d83cd07e1a10f545cd4c0a39f7e85e..b6ba984bafcd9085840ae47b8799e62fdd5821ed 100644 (file)
 #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),