Skip to contentSkip to conversation

usb: typec: tps6598x: Add IRQ flag and register tracing

PATCH Superseded Guido Günther 5 participants 13 messages Feb 12, 2021 – Feb 15, 2021

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover usb: typec: tps6598x: Add IRQ flag and register tracing

This series adds tracing events for the chips IRQ and registers that are useful to figure out the current data and power status. This came about since diagnosing why a certain usb-c hub or dp-alt-mode adapter fails is hard with the information in /sys/class/typec alone since this does not have a timeline of events (and we don't want every typec user having to also buy a PD analyzer). With this series debugging these kinds of things starts to become fun:

   # echo 1 > /sys/kernel/debug/tracing/events/tps6598x/enable
   # cat /sys/kernel/debug/tracing/trace_pipe
   irq/79-0-003f-526     [003] ....   512.717871: tps6598x_irq: event1=PLUG_EVENT|DATA_STATUS_UPDATE|STATUS_UPDATE, event2=
   irq/79-0-003f-526     [003] ....   512.722408: tps6598x_status: conn: conn-Ra, pp_5v0: off, pp_hv: off, pp_ext: off, pp_cable: off, pwr-src: vin-3p3, vbus: vSafe0V, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE
   irq/79-0-003f-526     [003] ....   512.727127: tps6598x_data_status: DATA_CONNECTION|USB2_CONNECTION|USB3_CONNECTION
   irq/79-0-003f-526     [003] ....   512.769571: tps6598x_irq: event1=PP_SWITCH_CHANGED|STATUS_UPDATE, event2=
   irq/79-0-003f-526     [003] ....   512.773380: tps6598x_status: conn: conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, vbus: vSafe0V, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526     [003] ....   512.872450: tps6598x_irq: event1=POWER_STATUS_UPDATE|PD_STATUS_UPDATE, event2=
   irq/79-0-003f-526     [003] ....   512.876311: tps6598x_status: conn: conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, vbus: vSafe0V, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526     [003] ....   512.880237: tps6598x_power_status: conn: 1, pwr-role: source, typec: usb, bc: sdp
   irq/79-0-003f-526     [003] ....   513.072682: tps6598x_irq: event1=STATUS_UPDATE, event2=
   irq/79-0-003f-526     [003] ....   513.076390: tps6598x_status: conn: conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, vbus: vSafe5V, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526     [003] ....   513.090676: tps6598x_irq: event1=ERROR_CANNOT_PROVIDE_PWR, event2=
   irq/79-0-003f-526     [003] ....   513.094368: tps6598x_status: conn: conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, vbus: vSafe5V, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526     [003] ....   513.109606: tps6598x_irq: event1=NEW_CONTRACT_AS_PROVIDER|POWER_STATUS_UPDATE|STATUS_UPDATE|SRC_TRANSITION, event2=
   irq/79-0-003f-526     [003] ....   513.113777: tps6598x_status: conn: conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, vbus: pd, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526     [003] ....   513.117475: tps6598x_power_status: conn: 1, pwr-role: source, typec: pd, bc: sdp
   irq/79-0-003f-526     [003] ....   513.137469: tps6598x_irq: event1=VDM_RECEIVED, event2=
   irq/79-0-003f-526     [003] ....   513.141570: tps6598x_status: conn: conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, vbus: pd, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526     [003] ....   513.281926: tps6598x_irq: event1=VDM_RECEIVED, event2=
   irq/79-0-003f-526     [003] ....   513.285638: tps6598x_status: conn: conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, vbus: pd, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526     [003] ....   513.300515: tps6598x_irq: event1=VDM_RECEIVED|DATA_STATUS_UPDATE, event2=
   irq/79-0-003f-526     [003] ....   513.304226: tps6598x_status: conn: conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, vbus: pd, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526     [003] ....   513.308302: tps6598x_data_status: DATA_CONNECTION|USB2_CONNECTION|USB3_CONNECTION|DP_CONNECTION, DP pinout D

It should not impose any problems for firmwares that don't have IRQs for the registers enabled. The trace will then just be missing those events.

Patch is against next-20210210.

changes from v1:
- Fix issues on 32bit arches and missing include spotted by kbuild (build testes on mips)

Guido Günther (4):
usb: typec: tps6598x: Add trace event for IRQ events
usb: typec: tps6598x: Add trace event for status register
usb: typec: tps6598x: Add trace event for power status register
usb: typec: tps6598x: Add trace event for data status

 drivers/usb/typec/Makefile         |   3 +
 drivers/usb/typec/tps6598x.c       |  66 ++++---
 drivers/usb/typec/tps6598x.h       | 185 +++++++++++++++++++
 drivers/usb/typec/tps6598x_trace.h | 283 +++++++++++++++++++++++++++++
 4 files changed, 511 insertions(+), 26 deletions(-)
 create mode 100644 drivers/usb/typec/tps6598x.h
 create mode 100644 drivers/usb/typec/tps6598x_trace.h
Signature · 1 line
2.30.0
#1 lore raw

PATCH v2 1/4 usb: typec: tps6598x: Add trace event for IRQ events

Allow to get irq event information via the tracing framework. This allows to inspect USB-C negotiation at runtime.

---
 drivers/usb/typec/Makefile         |  3 +
 drivers/usb/typec/tps6598x.c       |  9 ++-
 drivers/usb/typec/tps6598x.h       | 64 ++++++++++++++++++++
 drivers/usb/typec/tps6598x_trace.h | 97 ++++++++++++++++++++++++++++++
 4 files changed, 170 insertions(+), 3 deletions(-)
 create mode 100644 drivers/usb/typec/tps6598x.h
 create mode 100644 drivers/usb/typec/tps6598x_trace.h
drivers/usb/typec/Makefile +3 -0
index d03b48c4b864..27aa12129190 100644
@@ -1,4 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
+# define_trace.h needs to know how to find our header
+CFLAGS_tps6598x.o		:= -I$(src)
+
 obj-$(CONFIG_TYPEC)		+= typec.o
 typec-y				:= class.o mux.o bus.o
 obj-$(CONFIG_TYPEC)		+= altmodes/
drivers/usb/typec/tps6598x.c +6 -3
index 6e6ef6317523..bc34b35e909f 100644
@@ -6,6 +6,8 @@
  * Author: Heikki Krogerus <[email protected]>
  */
 
+#include "tps6598x.h"
+
 #include <linux/i2c.h>
 #include <linux/acpi.h>
 #include <linux/module.h>
@@ -15,6 +17,9 @@
 #include <linux/usb/typec.h>
 #include <linux/usb/role.h>
 
+#define CREATE_TRACE_POINTS
+#include "tps6598x_trace.h"
+
 /* Register offsets */
 #define TPS_REG_VID			0x00
 #define TPS_REG_MODE			0x03
@@ -32,9 +37,6 @@
 #define TPS_REG_POWER_STATUS		0x3f
 #define TPS_REG_RX_IDENTITY_SOP		0x48
 
-/* TPS_REG_INT_* bits */
-#define TPS_REG_INT_PLUG_EVENT		BIT(3)
-
 /* TPS_REG_STATUS bits */
 #define TPS_STATUS_PLUG_PRESENT		BIT(0)
 #define TPS_STATUS_ORIENTATION		BIT(4)
@@ -428,6 +430,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
 		dev_err(tps->dev, "%s: failed to read events\n", __func__);
 		goto err_unlock;
 	}
+	trace_tps6598x_irq(event1, event2);
 
 	ret = tps6598x_read32(tps, TPS_REG_STATUS, &status);
 	if (ret) {
drivers/usb/typec/tps6598x.h new file +64 -0

64 lines not on this page · raw message

drivers/usb/typec/tps6598x_trace.h new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.30.0
#2 lore raw

PATCH v2 2/4 usb: typec: tps6598x: Add trace event for status register

In reply to Guido Günther

This allows to trace status information which helps to debug problems with role switching, etc.

---
 drivers/usb/typec/tps6598x.c       | 26 ++++-----
 drivers/usb/typec/tps6598x.h       | 66 +++++++++++++++++++++
 drivers/usb/typec/tps6598x_trace.h | 94 ++++++++++++++++++++++++++++++
 3 files changed, 171 insertions(+), 15 deletions(-)
drivers/usb/typec/tps6598x.c +11 -15
index bc34b35e909f..559aa175f948 100644
@@ -37,13 +37,6 @@
 #define TPS_REG_POWER_STATUS		0x3f
 #define TPS_REG_RX_IDENTITY_SOP		0x48
 
-/* TPS_REG_STATUS bits */
-#define TPS_STATUS_PLUG_PRESENT		BIT(0)
-#define TPS_STATUS_ORIENTATION		BIT(4)
-#define TPS_STATUS_PORTROLE(s)		(!!((s) & BIT(5)))
-#define TPS_STATUS_DATAROLE(s)		(!!((s) & BIT(6)))
-#define TPS_STATUS_VCONN(s)		(!!((s) & BIT(7)))
-
 /* TPS_REG_SYSTEM_CONF bits */
 #define TPS_SYSCONF_PORTINFO(c)		((c) & 7)
 
@@ -258,9 +251,9 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status)
 	}
 
 	typec_set_pwr_opmode(tps->port, mode);
-	typec_set_pwr_role(tps->port, TPS_STATUS_PORTROLE(status));
-	typec_set_vconn_role(tps->port, TPS_STATUS_VCONN(status));
-	tps6598x_set_data_role(tps, TPS_STATUS_DATAROLE(status), true);
+	typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status));
+	typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status));
+	tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), true);
 
 	tps->partner = typec_register_partner(tps->port, &desc);
 	if (IS_ERR(tps->partner))
@@ -280,9 +273,10 @@ static void tps6598x_disconnect(struct tps6598x *tps, u32 status)
 		typec_unregister_partner(tps->partner);
 	tps->partner = NULL;
 	typec_set_pwr_opmode(tps->port, TYPEC_PWR_MODE_USB);
-	typec_set_pwr_role(tps->port, TPS_STATUS_PORTROLE(status));
-	typec_set_vconn_role(tps->port, TPS_STATUS_VCONN(status));
-	tps6598x_set_data_role(tps, TPS_STATUS_DATAROLE(status), false);
+	typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status));
+	typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status));
+	tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), false);
+
 	power_supply_changed(tps->psy);
 }
 
@@ -366,7 +360,7 @@ static int tps6598x_dr_set(struct typec_port *port, enum typec_data_role role)
 	if (ret)
 		goto out_unlock;
 
-	if (role != TPS_STATUS_DATAROLE(status)) {
+	if (role != TPS_STATUS_TO_TYPEC_DATAROLE(status)) {
 		ret = -EPROTO;
 		goto out_unlock;
 	}
@@ -396,7 +390,7 @@ static int tps6598x_pr_set(struct typec_port *port, enum typec_role role)
 	if (ret)
 		goto out_unlock;
 
-	if (role != TPS_STATUS_PORTROLE(status)) {
+	if (role != TPS_STATUS_TO_TYPEC_PORTROLE(status)) {
 		ret = -EPROTO;
 		goto out_unlock;
 	}
@@ -437,6 +431,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
 		dev_err(tps->dev, "%s: failed to read status\n", __func__);
 		goto err_clear_ints;
 	}
+	trace_tps6598x_status(status);
 
 	/* Handle plug insert or removal */
 	if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) {
@@ -612,6 +607,7 @@ static int tps6598x_probe(struct i2c_client *client)
 	ret = tps6598x_read32(tps, TPS_REG_STATUS, &status);
 	if (ret < 0)
 		return ret;
+	trace_tps6598x_status(status);
 
 	ret = tps6598x_read32(tps, TPS_REG_SYSTEM_CONF, &conf);
 	if (ret < 0)
drivers/usb/typec/tps6598x.h +66 -0

72 lines not on this page · raw message

drivers/usb/typec/tps6598x_trace.h +94 -0

106 lines not on this page · raw message

Signature · 1 line
2.30.0
#3 lore raw

Re: [PATCH v2 2/4] usb: typec: tps6598x: Add trace event for status register

I love your patch! Perhaps something to improve:

Hi "Guido,

I love your patch! Perhaps something to improve:

[auto build test WARNING on usb/usb-testing]
[also build test WARNING on v5.11-rc7 next-20210211]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Guido-G-nther/usb-typec-tps6598x-Add-IRQ-flag-and-register-tracing/20210212-200855
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
config: openrisc-randconfig-s032-20210209 (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-215-g0fb77bb6-dirty
# https://github.com/0day-ci/linux/commit/ba45e1d5e1fd25b6aed8724106e6c7d5adef7a20
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Guido-G-nther/usb-typec-tps6598x-Add-IRQ-flag-and-register-tracing/20210212-200855 git checkout ba45e1d5e1fd25b6aed8724106e6c7d5adef7a20
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=openrisc

If you fix the issue, kindly add following tag as appropriate

"sparse warnings: (new ones prefixed by >>)"
drivers/usb/typec/tps6598x.c: note: in included file (through include/trace/trace_events.h, include/trace/define_trace.h, drivers/usb/typec/tps6598x_trace.h):

>> drivers/usb/typec/./tps6598x_trace.h:157:1: sparse: sparse: too long token expansion

vim +157 drivers/usb/typec/./tps6598x_trace.h

c90c0282e4ce33 Guido Günther 2021-02-12 156

ba45e1d5e1fd25 Guido Günther 2021-02-12 @157  TRACE_EVENT(tps6598x_status,
ba45e1d5e1fd25 Guido Günther 2021-02-12  158  	    TP_PROTO(u32 status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  159  	    TP_ARGS(status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  160  
ba45e1d5e1fd25 Guido Günther 2021-02-12  161  	    TP_STRUCT__entry(
ba45e1d5e1fd25 Guido Günther 2021-02-12  162  			     __field(u32, status)
ba45e1d5e1fd25 Guido Günther 2021-02-12  163  			     ),
ba45e1d5e1fd25 Guido Günther 2021-02-12  164  
ba45e1d5e1fd25 Guido Günther 2021-02-12  165  	    TP_fast_assign(
ba45e1d5e1fd25 Guido Günther 2021-02-12  166  			   __entry->status = status;
ba45e1d5e1fd25 Guido Günther 2021-02-12  167  			   ),
ba45e1d5e1fd25 Guido Günther 2021-02-12  168  
ba45e1d5e1fd25 Guido Günther 2021-02-12  169  	    TP_printk("conn: %s, pp_5v0: %s, pp_hv: %s, pp_ext: %s, pp_cable: %s, "
ba45e1d5e1fd25 Guido Günther 2021-02-12  170  		      "pwr-src: %s, vbus: %s, usb-host: %s, legacy: %s, flags: %s",
ba45e1d5e1fd25 Guido Günther 2021-02-12  171  		      show_status_conn_state(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  172  		      show_status_pp_switch_state(TPS_STATUS_PP_5V0_SWITCH(__entry->status)),
ba45e1d5e1fd25 Guido Günther 2021-02-12  173  		      show_status_pp_switch_state(TPS_STATUS_PP_HV_SWITCH(__entry->status)),
ba45e1d5e1fd25 Guido Günther 2021-02-12  174  		      show_status_pp_switch_state(TPS_STATUS_PP_EXT_SWITCH(__entry->status)),
ba45e1d5e1fd25 Guido Günther 2021-02-12  175  		      show_status_pp_switch_state(TPS_STATUS_PP_CABLE_SWITCH(__entry->status)),
ba45e1d5e1fd25 Guido Günther 2021-02-12  176  		      show_status_power_sources(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  177  		      show_status_vbus_status(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  178  		      show_status_usb_host_present(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  179  		      show_status_legacy(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  180  		      show_status_flags(__entry->status)
ba45e1d5e1fd25 Guido Günther 2021-02-12  181  		    )
ba45e1d5e1fd25 Guido Günther 2021-02-12  182  );
ba45e1d5e1fd25 Guido Günther 2021-02-12  183  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

_______________________________________________
kbuild mailing list -- kbuild(a)lists.01.org
To unsubscribe send an email to kbuild-leave(a)lists.01.org

#4 lore raw

Re: [PATCH v2 2/4] usb: typec: tps6598x: Add trace event for status register

Hi ,

Quoted 26 lines · kernel test robot

Hi "Guido,

I love your patch! Perhaps something to improve:

[auto build test WARNING on usb/usb-testing]
[also build test WARNING on v5.11-rc7 next-20210211]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Guido-G-nther/usb-typec-tps6598x-Add-IRQ-flag-and-register-tracing/20210212-200855
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
config: openrisc-randconfig-s032-20210209 (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-215-g0fb77bb6-dirty
# https://github.com/0day-ci/linux/commit/ba45e1d5e1fd25b6aed8724106e6c7d5adef7a20
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Guido-G-nther/usb-typec-tps6598x-Add-IRQ-flag-and-register-tracing/20210212-200855 git checkout ba45e1d5e1fd25b6aed8724106e6c7d5adef7a20
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=openrisc

Quoted 8 lines

If you fix the issue, kindly add following tag as appropriate

"sparse warnings: (new ones prefixed by >>)"
drivers/usb/typec/tps6598x.c: note: in included file (through include/trace/trace_events.h, include/trace/define_trace.h, drivers/usb/typec/tps6598x_trace.h):

Quoted 1 line
Quoted 1 line

drivers/usb/typec/./tps6598x_trace.h:157:1: sparse: sparse: too long token expansion

I looked around but didn't find any hints how to fix this. Any pointers I missed (added the sparse list to cc:)?

Cheers,
-- Guido

Quoted 39 lines

vim +157 drivers/usb/typec/./tps6598x_trace.h

c90c0282e4ce33 Guido Günther 2021-02-12 156

ba45e1d5e1fd25 Guido Günther 2021-02-12 @157  TRACE_EVENT(tps6598x_status,
ba45e1d5e1fd25 Guido Günther 2021-02-12  158  	    TP_PROTO(u32 status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  159  	    TP_ARGS(status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  160  
ba45e1d5e1fd25 Guido Günther 2021-02-12  161  	    TP_STRUCT__entry(
ba45e1d5e1fd25 Guido Günther 2021-02-12  162  			     __field(u32, status)
ba45e1d5e1fd25 Guido Günther 2021-02-12  163  			     ),
ba45e1d5e1fd25 Guido Günther 2021-02-12  164  
ba45e1d5e1fd25 Guido Günther 2021-02-12  165  	    TP_fast_assign(
ba45e1d5e1fd25 Guido Günther 2021-02-12  166  			   __entry->status = status;
ba45e1d5e1fd25 Guido Günther 2021-02-12  167  			   ),
ba45e1d5e1fd25 Guido Günther 2021-02-12  168  
ba45e1d5e1fd25 Guido Günther 2021-02-12  169  	    TP_printk("conn: %s, pp_5v0: %s, pp_hv: %s, pp_ext: %s, pp_cable: %s, "
ba45e1d5e1fd25 Guido Günther 2021-02-12  170  		      "pwr-src: %s, vbus: %s, usb-host: %s, legacy: %s, flags: %s",
ba45e1d5e1fd25 Guido Günther 2021-02-12  171  		      show_status_conn_state(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  172  		      show_status_pp_switch_state(TPS_STATUS_PP_5V0_SWITCH(__entry->status)),
ba45e1d5e1fd25 Guido Günther 2021-02-12  173  		      show_status_pp_switch_state(TPS_STATUS_PP_HV_SWITCH(__entry->status)),
ba45e1d5e1fd25 Guido Günther 2021-02-12  174  		      show_status_pp_switch_state(TPS_STATUS_PP_EXT_SWITCH(__entry->status)),
ba45e1d5e1fd25 Guido Günther 2021-02-12  175  		      show_status_pp_switch_state(TPS_STATUS_PP_CABLE_SWITCH(__entry->status)),
ba45e1d5e1fd25 Guido Günther 2021-02-12  176  		      show_status_power_sources(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  177  		      show_status_vbus_status(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  178  		      show_status_usb_host_present(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  179  		      show_status_legacy(__entry->status),
ba45e1d5e1fd25 Guido Günther 2021-02-12  180  		      show_status_flags(__entry->status)
ba45e1d5e1fd25 Guido Günther 2021-02-12  181  		    )
ba45e1d5e1fd25 Guido Günther 2021-02-12  182  );
ba45e1d5e1fd25 Guido Günther 2021-02-12  183  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

#5 lore raw

Re: [PATCH v2 2/4] usb: typec: tps6598x: Add trace event for status register

[trimmed CC: list]

On 14/02/2021 17:06, Guido Günther wrote:
[snip]

Quoted 11 lines
Quoted 8 lines

If you fix the issue, kindly add following tag as appropriate

"sparse warnings: (new ones prefixed by >>)"
drivers/usb/typec/tps6598x.c: note: in included file (through include/trace/trace_events.h, include/trace/define_trace.h, drivers/usb/typec/tps6598x_trace.h):

Quoted 1 line
Quoted 1 line

drivers/usb/typec/./tps6598x_trace.h:157:1: sparse: sparse: too long token expansion

I looked around but didn't find any hints how to fix this. Any pointers I missed (added the sparse list to cc:)?

This is a limitation of sparse; when using the 'stringize' pre-processor operator #, the maximum size of the resulting string is about 8k (if I remember correctly).

It just so happens that I have a WIP patch from 2011 hanging around to fix this - I didn't submit the patch, since it was easier to change the original source (so that it didn't need such a huge string!). ;-)

Also, it was a very 'quick-n-dirty' patch which could probably be somewhat improved (and may not even apply to the current codebase*).

ATB,
Ramsay Jones

*) I just tried to apply the patch but, as expected, there are conflicts.

#6 lore raw

Re: [PATCH v2 2/4] usb: typec: tps6598x: Add trace event for status register

Quoted 8 lines · Ramsay Jones
Quoted 4 lines

I looked around but didn't find any hints how to fix this. Any pointers I missed (added the sparse list to cc:)?

This is a limitation of sparse; when using the 'stringize' pre-processor operator #, the maximum size of the resulting string is about 8k (if I remember correctly).

Well, yes and no.

The C89 standard actually says that a string literal can be at most 509 characters to be portable. C99 increased it to 4095 characters.

Sparse makes the limit higher, and the limit could easily be expanded way past 8kB - but the point is that large string literals are actually not guaranteed to be valid C.

So honestly, it really sounds like that TRACE_EVENT() thing is doing something it shouldn't be doing.

I don't think there's any fundamental limit why sparse does 8kB as a limit (just a few random buffers). Making sparse accept larger ones should be as simple as just increasing MAX_STRING, but I really don't think the kernel should encourage that kind of excessive string sizes.

I wouldn't be surprised if tracing buffers etc make such strings useless anyway.

Linus

#7 lore raw

Re: [PATCH v2 2/4] usb: typec: tps6598x: Add trace event for status register

Quoted 7 lines · Linus Torvalds

The C89 standard actually says that a string literal can be at most 509 characters to be portable. C99 increased it to 4095 characters.

Sparse makes the limit higher, and the limit could easily be expanded way past 8kB - but the point is that large string literals are actually not guaranteed to be valid C.

Looking around, there's a couple of other similar cases:

drivers/infiniband/hw/hfi1/./trace_tx.h:727:1: error: too long token expansion arch/x86/purgatory/kexec-purgatory.c:1340:9: warning: trying to
concatenate 21400-character string (8191 bytes max)
drivers/scsi/constants.c:318:9: warning: trying to concatenate
26550-character string (8191 bytes max)
kernel/trace/trace.c:5290:1: warning: trying to concatenate
10842-character string (8191 bytes max)

but those four are the only ones I see from a quick x86-64 allmodconfig build.

Please try to avoid it.

Linus

#8 lore raw

Re: [PATCH v2 2/4] usb: typec: tps6598x: Add trace event for status register

In reply to Linus Torvalds
Quoted 16 lines · Linus Torvalds
Quoted 8 lines · Ramsay Jones
Quoted 4 lines

I looked around but didn't find any hints how to fix this. Any pointers I missed (added the sparse list to cc:)?

This is a limitation of sparse; when using the 'stringize' pre-processor operator #, the maximum size of the resulting string is about 8k (if I remember correctly).

Well, yes and no.

The C89 standard actually says that a string literal can be at most 509 characters to be portable. C99 increased it to 4095 characters.

Quoted 6 lines

Sparse makes the limit higher, and the limit could easily be expanded way past 8kB - but the point is that large string literals are actually not guaranteed to be valid C.

So honestly, it really sounds like that TRACE_EVENT() thing is doing something it shouldn't be doing.

Yep, as I said, I didn't submit the patch - rather I changed the source so as not to need such a long string.

Quoted 4 lines

I don't think there's any fundamental limit why sparse does 8kB as a limit (just a few random buffers). Making sparse accept larger ones should be as simple as just increasing MAX_STRING, but I really don't think the kernel should encourage that kind of excessive string sizes.

I agree, but I wiggled my patch (which doesn't increase MAX_STRING) to apply to the current codebase, and ... it now fails two tests! ;-) (It seems, in the intervening 9 years, the show_token_sequence() function fixed the quoting of double-quotes in the resulting strings, which my patch fails to do).

Sorry for the noise.

ATB,
Ramsay Jones

#9 lore raw

Re: [PATCH v2 2/4] usb: typec: tps6598x: Add trace event for status register

In reply to Linus Torvalds
Quoted 16 lines · Linus Torvalds
Quoted 8 lines · Ramsay Jones
Quoted 4 lines

I looked around but didn't find any hints how to fix this. Any pointers I missed (added the sparse list to cc:)?

This is a limitation of sparse; when using the 'stringize' pre-processor operator #, the maximum size of the resulting string is about 8k (if I remember correctly).

Well, yes and no.

The C89 standard actually says that a string literal can be at most 509 characters to be portable. C99 increased it to 4095 characters.

Quoted 6 lines

Sparse makes the limit higher, and the limit could easily be expanded way past 8kB - but the point is that large string literals are actually not guaranteed to be valid C.

So honestly, it really sounds like that TRACE_EVENT() thing is doing something it shouldn't be doing.

In itself, it's OKish but it does a lot of macro expansions and most arguments are macros of macros of ... but the problem seems to be limited to TP_printk().

In the current case, the offender is the string 'print_fmt_tps6598x_status' which is just under 26K long especially because it expand TPS6598X_STATUS_FLAGS_MASK but also because the arguments use FIELD_GET() and thus __BF_FIELD_CHECK().

Quoted 5 lines

I don't think there's any fundamental limit why sparse does 8kB as a limit (just a few random buffers). Making sparse accept larger ones should be as simple as just increasing MAX_STRING, but I really don't think the kernel should encourage that kind of excessive string sizes.

Like you noted, there are just a few cases in the kernel and IIRC there is or was one case in it too.
I would tend to increase MAX_STRING to something like 32 or 64K, in order to keep it reasonable but let sparse to continue its processing, but add a warning when the string/token is bigger than the current 8K.

-- Luc

#10 lore raw

Re: [PATCH v2 2/4] usb: typec: tps6598x: Add trace event for status register

Hi,

Quoted 24 lines · Luc Van Oostenryck
Quoted 16 lines · Linus Torvalds
Quoted 8 lines · Ramsay Jones
Quoted 4 lines

I looked around but didn't find any hints how to fix this. Any pointers I missed (added the sparse list to cc:)?

This is a limitation of sparse; when using the 'stringize' pre-processor operator #, the maximum size of the resulting string is about 8k (if I remember correctly).

Well, yes and no.

The C89 standard actually says that a string literal can be at most 509 characters to be portable. C99 increased it to 4095 characters.

Quoted 6 lines

Sparse makes the limit higher, and the limit could easily be expanded way past 8kB - but the point is that large string literals are actually not guaranteed to be valid C.

So honestly, it really sounds like that TRACE_EVENT() thing is doing something it shouldn't be doing.

Quoted 8 lines

In itself, it's OKish but it does a lot of macro expansions and most arguments are macros of macros of ... but the problem seems to be limited to TP_printk().

In the current case, the offender is the string 'print_fmt_tps6598x_status' which is just under 26K long especially because it expand TPS6598X_STATUS_FLAGS_MASK but also because the arguments use FIELD_GET() and thus __BF_FIELD_CHECK().

That was a great hint! Using a custom FIELD_GET() that drops the __BF_FIELD_CHECK() makes things fit.
Cheers,
-- Guido

Quoted 14 lines
Quoted 5 lines

I don't think there's any fundamental limit why sparse does 8kB as a limit (just a few random buffers). Making sparse accept larger ones should be as simple as just increasing MAX_STRING, but I really don't think the kernel should encourage that kind of excessive string sizes.

Like you noted, there are just a few cases in the kernel and IIRC there is or was one case in it too.
I would tend to increase MAX_STRING to something like 32 or 64K, in order to keep it reasonable but let sparse to continue its processing, but add a warning when the string/token is bigger than the current 8K.

-- Luc

#11 lore raw

PATCH v2 3/4 usb: typec: tps6598x: Add trace event for power status register

In reply to Guido Günther

Together with the PD status register this is vital for debugging power negotiations at runtime.

---
 drivers/usb/typec/tps6598x.c       | 19 +++++++++------
 drivers/usb/typec/tps6598x.h       | 19 +++++++++++++++
 drivers/usb/typec/tps6598x_trace.h | 38 ++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 7 deletions(-)
drivers/usb/typec/tps6598x.c +12 -7
index 559aa175f948..3e6ad3ba7fc8 100644
@@ -50,11 +50,6 @@ enum {
 	TPS_PORTINFO_SOURCE,
 };
 
-/* TPS_REG_POWER_STATUS bits */
-#define TPS_POWER_STATUS_CONNECTION	BIT(0)
-#define TPS_POWER_STATUS_SOURCESINK	BIT(1)
-#define TPS_POWER_STATUS_PWROPMODE(p)	(((p) & GENMASK(3, 2)) >> 2)
-
 /* TPS_REG_RX_IDENTITY_SOP */
 struct tps6598x_rx_identity_reg {
 	u8 status;
@@ -414,6 +409,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
 	u64 event1;
 	u64 event2;
 	u32 status;
+	u16 pwr_status;
 	int ret;
 
 	mutex_lock(&tps->lock);
@@ -433,6 +429,15 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
 	}
 	trace_tps6598x_status(status);
 
+	if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE) {
+		ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
+		if (ret < 0) {
+			dev_err(tps->dev, "failed to read power status: %d\n", ret);
+			goto err_clear_ints;
+		}
+		trace_tps6598x_power_status(pwr_status);
+	}
+
 	/* Handle plug insert or removal */
 	if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) {
 		if (status & TPS_STATUS_PLUG_PRESENT) {
@@ -497,8 +502,8 @@ static int tps6598x_psy_get_online(struct tps6598x *tps,
 	if (ret < 0)
 		return ret;
 
-	if ((pwr_status & TPS_POWER_STATUS_CONNECTION) &&
-	    (pwr_status & TPS_POWER_STATUS_SOURCESINK)) {
+	if (TPS_POWER_STATUS_CONNECTION(pwr_status) &&
+	    TPS_POWER_STATUS_SOURCESINK(pwr_status)) {
 		val->intval = 1;
 	} else {
 		val->intval = 0;
drivers/usb/typec/tps6598x.h +19 -0
index 866fd1deb471..3f6503377678 100644
@@ -127,4 +127,23 @@
 #define TPS_REG_INT_HARD_RESET				BIT(1)
 #define TPS_REG_INT_PD_SOFT_RESET			BIT(0)
 
+/* TPS_REG_POWER_STATUS bits */
+#define TPS_POWER_STATUS_CONNECTION(x)  FIELD_GET(BIT(0), (x))
+#define TPS_POWER_STATUS_SOURCESINK(x)	FIELD_GET(BIT(1), (x))
+#define TPS_POWER_STATUS_BC12_DET(x)	FIELD_GET(BIT(2), (x))
+
+#define TPS_POWER_STATUS_TYPEC_CURRENT_MASK GENMASK(3, 2)
+#define TPS_POWER_STATUS_PWROPMODE(p)	    FIELD_GET(TPS_POWER_STATUS_TYPEC_CURRENT_MASK, (p))
+#define TPS_POWER_STATUS_BC12_STATUS_MASK   GENMASK(6, 5)
+#define TPS_POWER_STATUS_BC12_STATUS(p)	    FIELD_GET(TPS_POWER_STATUS_BC12_STATUS_MASK, (p))
+
+#define TPS_POWER_STATUS_TYPEC_CURRENT_USB     0
+#define TPS_POWER_STATUS_TYPEC_CURRENT_1A5     1
+#define TPS_POWER_STATUS_TYPEC_CURRENT_3A0     2
+#define TPS_POWER_STATUS_TYPEC_CURRENT_PD      3
+
+#define TPS_POWER_STATUS_BC12_STATUS_SDP 0
+#define TPS_POWER_STATUS_BC12_STATUS_CDP 2
+#define TPS_POWER_STATUS_BC12_STATUS_DCP 3
+
 #endif /* __TPS6598X_H__ */
drivers/usb/typec/tps6598x_trace.h +38 -0
index e0677b9c5c53..78a5a6ca337b 100644
@@ -134,6 +134,24 @@
 		      { TPS_STATUS_HIGH_VOLAGE_WARNING,	"HIGH_VOLAGE_WARNING" }, \
 		      { TPS_STATUS_HIGH_LOW_VOLTAGE_WARNING, "HIGH_LOW_VOLTAGE_WARNING" })
 
+#define show_power_status_source_sink(power_status) \
+	__print_symbolic(TPS_POWER_STATUS_SOURCESINK(power_status), \
+		{ 1, "sink" }, \
+		{ 0, "source" })
+
+#define show_power_status_typec_status(power_status) \
+	__print_symbolic(TPS_POWER_STATUS_PWROPMODE(power_status), \
+		{ TPS_POWER_STATUS_TYPEC_CURRENT_PD,  "pd" }, \
+		{ TPS_POWER_STATUS_TYPEC_CURRENT_3A0, "3.0A" }, \
+		{ TPS_POWER_STATUS_TYPEC_CURRENT_1A5, "1.5A" }, \
+		{ TPS_POWER_STATUS_TYPEC_CURRENT_USB, "usb" })
+
+#define show_power_status_bc12_status(power_status) \
+	__print_symbolic(TPS_POWER_STATUS_BC12_STATUS(power_status), \
+		{ TPS_POWER_STATUS_BC12_STATUS_DCP, "dcp" }, \
+		{ TPS_POWER_STATUS_BC12_STATUS_CDP, "cdp" }, \
+		{ TPS_POWER_STATUS_BC12_STATUS_SDP, "sdp" })
+
 TRACE_EVENT(tps6598x_irq,
 	    TP_PROTO(u64 event1,
 		     u64 event2),
@@ -181,6 +199,26 @@ TRACE_EVENT(tps6598x_status,
 		    )
 );
 
+TRACE_EVENT(tps6598x_power_status,
+	    TP_PROTO(u16 power_status),
+	    TP_ARGS(power_status),
+
+	    TP_STRUCT__entry(
+			     __field(u16, power_status)
+			     ),
+
+	    TP_fast_assign(
+			   __entry->power_status = power_status;
+			   ),
+
+	    TP_printk("conn: %d, pwr-role: %s, typec: %s, bc: %s",
+		      !!TPS_POWER_STATUS_CONNECTION(__entry->power_status),
+		      show_power_status_source_sink(__entry->power_status),
+		      show_power_status_typec_status(__entry->power_status),
+		      show_power_status_bc12_status(__entry->power_status)
+		    )
+);
+
 #endif /* _TPS6598X_TRACE_H_ */
 
 /* This part must be outside protection */
Signature · 1 line
2.30.0
#12 lore raw

PATCH v2 4/4 usb: typec: tps6598x: Add trace event for data status

In reply to Guido Günther

This is useful to debug DP negotiation and pin assignment even when the firmware does all the work.

---
 drivers/usb/typec/tps6598x.c       | 12 ++++++-
 drivers/usb/typec/tps6598x.h       | 36 ++++++++++++++++++++
 drivers/usb/typec/tps6598x_trace.h | 54 ++++++++++++++++++++++++++++++
 3 files changed, 101 insertions(+), 1 deletion(-)
drivers/usb/typec/tps6598x.c +11 -1
index 3e6ad3ba7fc8..a4ec8e56c2b9 100644
@@ -36,6 +36,7 @@
 #define TPS_REG_CTRL_CONF		0x29
 #define TPS_REG_POWER_STATUS		0x3f
 #define TPS_REG_RX_IDENTITY_SOP		0x48
+#define TPS_REG_DATA_STATUS		0x5f
 
 /* TPS_REG_SYSTEM_CONF bits */
 #define TPS_SYSCONF_PORTINFO(c)		((c) & 7)
@@ -408,7 +409,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
 	struct tps6598x *tps = data;
 	u64 event1;
 	u64 event2;
-	u32 status;
+	u32 status, data_status;
 	u16 pwr_status;
 	int ret;
 
@@ -438,6 +439,15 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
 		trace_tps6598x_power_status(pwr_status);
 	}
 
+	if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) {
+		ret = tps6598x_read32(tps, TPS_REG_DATA_STATUS, &data_status);
+		if (ret < 0) {
+			dev_err(tps->dev, "failed to read data status: %d\n", ret);
+			goto err_clear_ints;
+		}
+		trace_tps6598x_data_status(data_status);
+	}
+
 	/* Handle plug insert or removal */
 	if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) {
 		if (status & TPS_STATUS_PLUG_PRESENT) {
drivers/usb/typec/tps6598x.h +36 -0
index 3f6503377678..1afc22ab4dbb 100644
@@ -146,4 +146,40 @@
 #define TPS_POWER_STATUS_BC12_STATUS_CDP 2
 #define TPS_POWER_STATUS_BC12_STATUS_DCP 3
 
+/* TPS_REG_DATA_STATUS bits */
+#define TPS_DATA_STATUS_DATA_CONNECTION	     BIT(0)
+#define TPS_DATA_STATUS_UPSIDE_DOWN	     BIT(1)
+#define TPS_DATA_STATUS_ACTIVE_CABLE	     BIT(2)
+#define TPS_DATA_STATUS_USB2_CONNECTION	     BIT(4)
+#define TPS_DATA_STATUS_USB3_CONNECTION	     BIT(5)
+#define TPS_DATA_STATUS_USB3_GEN2	     BIT(6)
+#define TPS_DATA_STATUS_USB_DATA_ROLE	     BIT(7)
+#define TPS_DATA_STATUS_DP_CONNECTION	     BIT(8)
+#define TPS_DATA_STATUS_DP_SINK		     BIT(9)
+#define TPS_DATA_STATUS_TBT_CONNECTION	     BIT(16)
+#define TPS_DATA_STATUS_TBT_TYPE	     BIT(17)
+#define TPS_DATA_STATUS_OPTICAL_CABLE	     BIT(18)
+#define TPS_DATA_STATUS_ACTIVE_LINK_TRAIN    BIT(20)
+#define TPS_DATA_STATUS_FORCE_LSX	     BIT(23)
+#define TPS_DATA_STATUS_POWER_MISMATCH	     BIT(24)
+
+#define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK GENMASK(11, 10)
+#define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT(x) \
+	FIELD_GET(TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK, (x))
+#define TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK   GENMASK(27, 25)
+#define TPS_DATA_STATUS_TBT_CABLE_SPEED	       FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK, (x))
+#define TPS_DATA_STATUS_TBT_CABLE_GEN_MASK     GENMASK(29, 28)
+#define TPS_DATA_STATUS_TBT_CABLE_GEN	       FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_GEN_MASK, (x))
+
+/* Map data status to DP spec assignments */
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT(x) \
+	((TPS_DATA_STATUS_DP_PIN_ASSIGNMENT(x) << 1) | \
+		FIELD_GET(TPS_DATA_STATUS_USB3_CONNECTION, (x)))
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_E    0
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_F    BIT(0)
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_C    BIT(1)
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_D    (BIT(1) | BIT(0))
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_A    BIT(2)
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B    (BIT(2) | BIT(1))
+
 #endif /* __TPS6598X_H__ */
drivers/usb/typec/tps6598x_trace.h +54 -0

66 lines not on this page · raw message

Signature · 1 line
2.30.0