Re: [EXT] Re: [PATCH] usb: typec: tcpm: reset counter when enter into unattached state after try role

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Xu,

On Mon, Feb 19, 2024 at 08:36:50AM +0000, Xu Yang wrote:
> > Connecting an unpowered USB-C 4-port HUB:
> > 
> > Before reverting this patch: (endless loop)
> > 
> > [    0.657246] Setting usb_comm capable false
> > [    0.661870] Setting voltage/current limit 0 mV 0 mA
> > [    0.661880] polarity 0
> > [    0.661883] Requesting mux state 0, usb-role 0, orientation 0
> > [    0.663879] state change INVALID_STATE -> SNK_UNATTACHED [rev1 NONE_AMS]
> > [    0.663891] CC1: 0 -> 0, CC2: 0 -> 0 [state SNK_UNATTACHED, polarity 0, disconnected]
> > [    0.663897] 4-0022: registered
> > [    0.663962] Setting usb_comm capable false
> > [    0.669903] Setting voltage/current limit 0 mV 0 mA
> > [    0.669914] polarity 0
> > [    0.669917] Requesting mux state 0, usb-role 0, orientation 0
> > [    0.672166] cc:=2
> > [    0.679360] pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms [rev1 NONE_AMS]
> > [    0.779554] state change PORT_RESET -> PORT_RESET_WAIT_OFF [delayed 100 ms]
> > [    0.779570] state change PORT_RESET_WAIT_OFF -> SNK_UNATTACHED [rev1 NONE_AMS]
> > [    0.779576] Start toggling
> > [   12.957711] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> > [   12.957720] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > [   12.957729] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > [   13.157924] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > [   13.157939] cc:=2
> > [   13.167339] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
> > [   13.267545] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
> > [   13.267561] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
> > [   13.267566] cc:=3
> > [   13.278148] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
> 
> Based on my assumption, the DRP port is presenting Rp-default termination on CC line again,
> then tcpc should report CC change due to a connection is established in 100 ms. However, this
> CC change is not reported here. This leads to state from SRC_TRYWAIT to SRC_TRYWAIT_UNATTACHED
> rather SRC_TRYWAIT_DEBOUNCE.
> 
> Below log is a normal case.
> 
> ---
> [  149.954434] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> [  149.954447] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> [  149.954452] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> [  150.154543] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> [  150.154554] cc:=2
> [  150.154859] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
> [  150.254881] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
> [  150.254893] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
> [  150.254896] cc:=3
> [  150.255200] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
> [  150.257288] CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]
> [  150.257295] state change SRC_TRYWAIT -> SRC_TRYWAIT_DEBOUNCE [rev1 NONE_AMS]
> [  150.257300] pending state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED @ 200 ms [rev1 NONE_AMS]
> [  150.457319] state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED [delayed 200 ms]
> [  150.457329] cc:=3
> [  150.457606] polarity 1
> [  150.458314] Requesting mux state 1, usb-role 1, orientation 2
> [  150.460722] vbus:=1 charge=0
> ---

So I tried with tcpci based system and it works with your patch:

[    2.644265] Setting usb_comm capable false
[    2.645756] Setting voltage/current limit 0 mV 0 mA
[    2.645762] polarity 0
[    2.647884] Requesting mux state 0, usb-role 0, orientation 0
[    2.649661] state change INVALID_STATE -> SNK_UNATTACHED [rev1 NONE_AMS]
[    2.650611] CC1: 0 -> 0, CC2: 0 -> 0 [state SNK_UNATTACHED, polarity 0, disconnected]
[    2.650617] 2-004e: registered
[    2.650619] Setting usb_comm capable false
[    2.652276] Setting voltage/current limit 0 mV 0 mA
[    2.652282] polarity 0
[    2.654410] Requesting mux state 0, usb-role 0, orientation 0
[    2.655799] cc:=2
[    2.656612] pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms [rev1 NONE_AMS]
[    2.656615] state change PORT_RESET -> PORT_RESET_WAIT_OFF [delayed 100 ms]
[    2.656616] state change PORT_RESET_WAIT_OFF -> SNK_UNATTACHED [rev1 NONE_AMS]
[    2.656617] Start toggling

[   24.268594] CC1: 0 -> 2, CC2: 0 -> 0 [state TOGGLING, polarity 0, connected]
[   24.268599] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   24.268602] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   24.468659] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   24.468664] cc:=2
[   24.469899] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   24.473708] CC1: 2 -> 0, CC2: 0 -> 0 [state SNK_TRY, polarity 0, disconnected]

               ^^^^ this is extra

[   24.569964] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   24.569968] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   24.569970] cc:=5
[   24.571089] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   24.574996] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, connected]

               ^^^ this is different from your log due to prior change to 0/0
	       and here the fusb302 backed tcpm would fail/diverge, due to lack of this
	       line

[   24.575001] state change SRC_TRYWAIT -> SRC_TRYWAIT_DEBOUNCE [rev1 NONE_AMS]
[   24.575004] pending state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED @ 200 ms [rev1 NONE_AMS]
[   24.775066] state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED [delayed 200 ms]

               .... lack of cc:=5? after => SRC_ATTACHED

[   24.775070] polarity 0
[   24.778209] Requesting mux state 1, usb-role 1, orientation 1
[   24.779236] vbus:=1 charge=0
[   24.780234] pending state change SRC_ATTACHED -> SRC_UNATTACHED @ 480 ms [rev1 NONE_AMS]
[   24.782755] VBUS on
[   24.782758] state change SRC_ATTACHED -> SRC_STARTUP [rev1 NONE_AMS]
[   24.782773] AMS POWER_NEGOTIATION start
[   24.782774] cc:=4
[   24.783540] pending state change SRC_STARTUP -> AMS_START @ 16 ms [rev3 POWER_NEGOTIATION]
[   24.799554] state change SRC_STARTUP -> AMS_START [delayed 16 ms]
[   24.799558] state change AMS_START -> SRC_SEND_CAPABILITIES [rev3 POWER_NEGOTIATION]
[   24.799559] PD TX, header: 0x11a1
[   24.807710] PD TX complete, status: 2
[   24.807765] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   24.957845] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]

So it looks slightly different from your log, but ends up working because
there's an CC change event after "pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms".

So I think your patch changes some assumptions about the need for the CC change
event in this state, which breaks the state machine. If I strip the logs to just
cc events:

Your normal case:

[  149.954434] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
[  150.154554] cc:=2
[  150.254896] cc:=3
[  150.257288] CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]
[  150.457329] cc:=3

My husb311 working case:

[   24.268594] CC1: 0 -> 2, CC2: 0 -> 0 [state TOGGLING, polarity 0, connected]
[   24.468664] cc:=2
[   24.473708] CC1: 2 -> 0, CC2: 0 -> 0 [state SNK_TRY, polarity 0, disconnected]
[   24.569970] cc:=5
[   24.574996] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, connected]

My non-working fusb302 case:

[   12.957711] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
[   13.157939] cc:=2
[   13.267566] cc:=3
[   13.462597] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   13.662827] cc:=2

kind regards,
	o.

> So the issue may be why that CC change is not reported?
> 
> Please refer to USB Type-C Specification
> Figure 4-17 Connection State Diagram: DRP with Accessory and Try.SNK Support
> 
> Thanks,
> Xu Yang
> 
> > [   13.378347] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
> > [   13.378364] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
> > [   13.378373] Start toggling
> > [   13.387019] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
> > [   13.462597] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
> > [   13.462606] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > [   13.462613] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > [   13.662808] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > [   13.662827] cc:=2
> 




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux