From bbc22694d4cd8be65e2bfd807a311179f0ddc9c4 Mon Sep 17 00:00:00 2001 From: Badhri Jagan Sridharan Date: Mon, 31 May 2021 15:19:54 -0700 Subject: [PATCH] ANDROID: vendor_hooks: Add vendor hook for tcpm logs Context: https://lore.kernel.org/lkml/CAPTae5LbWVc4Bdiwe69cwwxEGfSYvRv=419dUGR1u8n-WUkYAA@mail.gmail.com/t/ Logs in /sys/kernel/debug/usb/tcpm* are key to debug issues related to USB charging or data. However, tcpm logbuffer logs do not wraparound once full. Whereas we want it to wrap around so that we capture relevant info in the bugreport when the user collects one. There is sentiment in upstream to get rid of the logbuffer altogether and move to tracing. But trace events are not default enabled in Android, so that implies, even if user can somehow enable the trace event, user would have repro the issue and collect the bugreport. That would cause inconvenience to the end user. The vendor hooks is needed till upstream either allows wrapping around logs (or) Android has a generic way to default enable trace events which can be captured in bugreport. bypass_log is set to true by the handler if logging into logbuffer is not needed. Bug: 189792358 Bug: 271294543 Change-Id: Icacfed2264b6c49b8e803c62f8bd820a146c169a Signed-off-by: Badhri Jagan Sridharan (cherry picked from commit bcfe28b62fb4307f7226d74c9718ba4d33224a66) --- drivers/android/vendor_hooks.c | 1 + drivers/usb/typec/tcpm/tcpm.c | 4 ++++ include/trace/hooks/typec.h | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index d721b7daa21f..ed451cd3882b 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -175,3 +175,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_typec_tcpci_get_vbus); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_store_partner_src_caps); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_get_timer); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_modify_src_caps); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_log); diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index eba5bc0c9731..6af7c21aeaac 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -607,6 +607,7 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args) char tmpbuffer[LOG_BUFFER_ENTRY_SIZE]; u64 ts_nsec = local_clock(); unsigned long rem_nsec; + bool bypass_log = false; mutex_lock(&port->logbuffer_lock); if (!port->logbuffer[port->logbuffer_head]) { @@ -619,6 +620,9 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args) } vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args); + trace_android_vh_typec_tcpm_log(tmpbuffer, &bypass_log); + if (bypass_log) + goto abort; if (tcpm_log_full(port)) { port->logbuffer_head = max(port->logbuffer_head - 1, 0); diff --git a/include/trace/hooks/typec.h b/include/trace/hooks/typec.h index afad3c1dc53f..e1b5c8be3835 100644 --- a/include/trace/hooks/typec.h +++ b/include/trace/hooks/typec.h @@ -50,6 +50,10 @@ DECLARE_HOOK(android_vh_typec_tcpm_modify_src_caps, TP_PROTO(unsigned int *nr_src_pdo, u32 (*src_pdo)[], bool *modified), TP_ARGS(nr_src_pdo, src_pdo, modified)); -#endif /* _TRACE_HOOK_TYPEC_H */ +DECLARE_HOOK(android_vh_typec_tcpm_log, + TP_PROTO(const char *log, bool *bypass), + TP_ARGS(log, bypass)); + +#endif /* _TRACE_HOOK_UFSHCD_H */ /* This part must be outside protection */ #include