* [PATCH v2 0/4] usb: typec: tcpm: Fixes for talking to the cable plug as a VCONN source
@ 2026-11-18 7:26 Alexey Charkov
2026-11-18 7:26 ` [PATCH v2 1/4] usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one Alexey Charkov
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Alexey Charkov @ 2026-11-18 7:26 UTC (permalink / raw)
To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman,
RD Babiera
Cc: Sebastian Reichel, linux-usb, Alexey Charkov, stable
When a TCPM port is the VCONN source, its exchanges with the cable plug
on SOP' can leave state behind that later affects the port partner.
Patch 1 fixes a Soft_Reset meant for the port partner being sent to the
cable plug after any SOP' VDM, which left a source without a contract
until unplugged. It needs "usb: typec: tcpm: Stop a source from
repeating a cable Soft_Reset" [1] first: without it, the repeated
Soft_Reset after a VCONN Swap would now go to the port partner.
Patches 2 and 3 fix SRC_VDM_IDENTITY_REQUEST, which replays
Source_Capabilities after the first contract, and stalls until a Hard
Reset if the cable plug NAKs, answers BUSY or never answers.
Patch 4 is hardening rather than a fix for any known device: it keeps
messages from a cable plug that breaks the rules from reaching the port
partner's handlers.
The first three carry Fixes: tags and are meant for stable.
Tested on two FUSB302B ports (RK3576), source to sink through an
e-marked cable, plus injected cable plug answers (ACK, NAK, BUSY,
Not_Supported, none) and stray SOP' messages.
[1] https://lore.kernel.org/r/20261103-husb311-cable-comm-v1-1-6217dabc1a85@flipper.net
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
Changes in v2:
- Split the SRC_VDM_IDENTITY_REQUEST fix in two: keep upcoming_state for
a message from the sink and clear it when leaving directly, then move
on after a NAK, BUSY or no answer as USB PD r3.3 9.2.26.2.5.1 has it,
keeping the timeout only as a fallback (Sashiko)
- Stop passing Reject from the cable plug, and pass its VDMs only as the
answer to an outstanding SOP' request (Sashiko)
- Link to v1: https://patch.msgid.link/20261117-tcpm-soft-reset-sop-v1-0-c7e1543828c0@flipper.net
---
Alexey Charkov (4):
usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one
usb: typec: tcpm: Stop replaying Source_Capabilities after cable discovery
usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers
usb: typec: tcpm: Keep cable plug messages away from the port partner
drivers/usb/typec/tcpm/tcpm.c | 131 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 117 insertions(+), 14 deletions(-)
---
base-commit: 749a4de370409464cf8501ec5b2451df45c84eb4
change-id: 20261104-tcpm-soft-reset-sop-96b4a156f823
prerequisite-patch-id: 2ea442b68dfeee84c38efb27749d2f40487d2fff
Best regards,
--
Alexey Charkov <alchark@flipper.net>
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2 1/4] usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one 2026-11-18 7:26 [PATCH v2 0/4] usb: typec: tcpm: Fixes for talking to the cable plug as a VCONN source Alexey Charkov @ 2026-11-18 7:26 ` Alexey Charkov 2026-11-20 14:31 ` Heikki Krogerus 2026-11-18 7:26 ` [PATCH v2 2/4] usb: typec: tcpm: Stop replaying Source_Capabilities after cable discovery Alexey Charkov 2026-11-18 7:26 ` [PATCH v2 3/4] usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers Alexey Charkov 2 siblings, 1 reply; 6+ messages in thread From: Alexey Charkov @ 2026-11-18 7:26 UTC (permalink / raw) To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman, RD Babiera Cc: Sebastian Reichel, linux-usb, Alexey Charkov, stable tx_sop_type holds the SOP* of the VDM being sent, for its retries, and SOFT_RESET_SEND also reads it to tell a Soft_Reset for the cable plug, after a VCONN Swap, from one for the port partner. Nothing sets it back after a VDM, so once a VDM has gone to the cable plug, such as Discover Identity on SOP' before the first contract, every Soft_Reset meant for the port partner goes to the cable plug instead. The cable plug accepts it and the port goes back to its ready state, but the port partner never sees the Soft_Reset: a source whose Source_Capabilities got Not_Supported is then left without a contract. The VCONN Swap, in turn, overwrites the SOP* of a VDM that may still be pending. This left a FUSB302B-based source without a contract until it was unplugged, after its partner missed a message following Discover Identity to an e-marked cable. Keep one target per context: vdm_sop_type for the VDM and its retries, and soft_reset_sop_type for the next Soft_Reset. Point the latter at the cable plug only for the VCONN Swap, only once, and back at SOP whenever the protocol layer starts over or a Soft_Reset of the port partner starts, along with the SOP' MessageID counters. Fixes: 6bd181ba60e1 ("usb: typec: tcpm: add control message support to sop'") Cc: stable@vger.kernel.org Signed-off-by: Alexey Charkov <alchark@flipper.net> --- drivers/usb/typec/tcpm/tcpm.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index bb90211660ca..8c5be904d772 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -675,12 +675,13 @@ struct tcpm_port { /* SOP* Related Fields */ /* - * tx_sop_type determines which SOP* a message is being sent on. - * For messages that are queued and not sent immediately such as in - * tcpm_queue_message or messages that send after state changes, - * the tx_sop_type is set accordingly. + * Messages that are not sent right away carry their SOP* separately, + * one per context so that one cannot redirect another: + * vdm_sop_type for the VDM being sent, including its retries, and + * soft_reset_sop_type for the next Soft_Reset. */ - enum tcpm_transmit_type tx_sop_type; + enum tcpm_transmit_type vdm_sop_type; + enum tcpm_transmit_type soft_reset_sop_type; /* * Prior to discovering the port partner's Specification Revision, the * Vconn source and cable plug will use the lower of their two revisions. @@ -2003,7 +2004,7 @@ static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header, port->vdm_state = VDM_STATE_READY; port->vdm_sm_running = true; - port->tx_sop_type = tx_sop_type; + port->vdm_sop_type = tx_sop_type; mod_vdm_delayed_work(port, 0); } @@ -3065,7 +3066,7 @@ static void vdm_run_state_machine(struct tcpm_port *port) } else { tcpm_ams_finish(port); port->vdo_data[0] = 0; - if (port->tx_sop_type == TCPC_TX_SOP) + if (port->vdm_sop_type == TCPC_TX_SOP) break; /* Handle SOP' Transmission Errors */ switch (PD_VDO_CMD(vdo_hdr)) { @@ -3102,7 +3103,7 @@ static void vdm_run_state_machine(struct tcpm_port *port) case VDM_STATE_SEND_MESSAGE: /* Prepare and send VDM */ memset(&msg, 0, sizeof(msg)); - if (port->tx_sop_type == TCPC_TX_SOP_PRIME) { + if (port->vdm_sop_type == TCPC_TX_SOP_PRIME) { msg.header = PD_HEADER_LE(PD_DATA_VENDOR_DEF, 0, /* Cable Plug Indicator for DFP/UFP */ 0, /* Reserved */ @@ -3119,7 +3120,7 @@ static void vdm_run_state_machine(struct tcpm_port *port) } for (i = 0; i < port->vdo_count; i++) msg.payload[i] = cpu_to_le32(port->vdo_data[i]); - res = tcpm_pd_transmit(port, port->tx_sop_type, &msg); + res = tcpm_pd_transmit(port, port->vdm_sop_type, &msg); if (res < 0) { port->vdm_state = VDM_STATE_ERR_SEND; } else { @@ -5529,6 +5530,7 @@ static void run_state_machine(struct tcpm_port *port) port->message_id_prime = 0; port->rx_msgid = -1; port->rx_msgid_prime = -1; + port->soft_reset_sop_type = TCPC_TX_SOP; port->explicit_contract = false; /* SNK -> SRC POWER/FAST_ROLE_SWAP finished */ if (port->ams == POWER_ROLE_SWAP || @@ -5801,6 +5803,7 @@ static void run_state_machine(struct tcpm_port *port) port->message_id_prime = 0; port->rx_msgid = -1; port->rx_msgid_prime = -1; + port->soft_reset_sop_type = TCPC_TX_SOP; port->explicit_contract = false; if (port->ams == POWER_ROLE_SWAP || @@ -6193,6 +6196,7 @@ static void run_state_machine(struct tcpm_port *port) case SOFT_RESET: port->message_id = 0; port->rx_msgid = -1; + port->soft_reset_sop_type = TCPC_TX_SOP; /* remove existing capabilities */ tcpm_partner_source_caps_reset(port); tcpm_pd_send_control(port, PD_CTRL_ACCEPT, TCPC_TX_SOP); @@ -6210,6 +6214,7 @@ static void run_state_machine(struct tcpm_port *port) case SNK_SOFT_RESET: if (port->ams != NONE_AMS) tcpm_ams_finish(port); + port->soft_reset_sop_type = TCPC_TX_SOP; port->upcoming_state = SOFT_RESET_SEND; tcpm_ams_start(port, SOFT_RESET_AMS); break; @@ -6220,7 +6225,8 @@ static void run_state_machine(struct tcpm_port *port) * A Soft_Reset Message Shall be targeted at a specific entity * depending on the type of SOP* packet used. */ - if (port->tx_sop_type == TCPC_TX_SOP_PRIME) { + if (port->soft_reset_sop_type == TCPC_TX_SOP_PRIME) { + port->soft_reset_sop_type = TCPC_TX_SOP; port->message_id_prime = 0; port->rx_msgid_prime = -1; tcpm_pd_send_control(port, PD_CTRL_SOFT_RESET, TCPC_TX_SOP_PRIME); @@ -6439,7 +6445,7 @@ static void run_state_machine(struct tcpm_port *port) case VCONN_SWAP_SEND_SOFT_RESET: tcpm_swap_complete(port, port->swap_status); if (tcpm_can_communicate_sop_prime(port)) { - port->tx_sop_type = TCPC_TX_SOP_PRIME; + port->soft_reset_sop_type = TCPC_TX_SOP_PRIME; port->upcoming_state = SOFT_RESET_SEND; tcpm_ams_start(port, SOFT_RESET_AMS); } else { -- 2.56.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/4] usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one 2026-11-18 7:26 ` [PATCH v2 1/4] usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one Alexey Charkov @ 2026-11-20 14:31 ` Heikki Krogerus 0 siblings, 0 replies; 6+ messages in thread From: Heikki Krogerus @ 2026-11-20 14:31 UTC (permalink / raw) To: Alexey Charkov Cc: Badhri Jagan Sridharan, Greg Kroah-Hartman, RD Babiera, Sebastian Reichel, linux-usb, stable On Wed, Nov 18, 2026 at 11:26:39AM +0400, Alexey Charkov wrote: > tx_sop_type holds the SOP* of the VDM being sent, for its retries, and > SOFT_RESET_SEND also reads it to tell a Soft_Reset for the cable plug, > after a VCONN Swap, from one for the port partner. Nothing sets it back > after a VDM, so once a VDM has gone to the cable plug, such as Discover > Identity on SOP' before the first contract, every Soft_Reset meant for > the port partner goes to the cable plug instead. The cable plug accepts > it and the port goes back to its ready state, but the port partner never > sees the Soft_Reset: a source whose Source_Capabilities got Not_Supported > is then left without a contract. The VCONN Swap, in turn, overwrites the > SOP* of a VDM that may still be pending. This left a FUSB302B-based > source without a contract until it was unplugged, after its partner > missed a message following Discover Identity to an e-marked cable. > > Keep one target per context: vdm_sop_type for the VDM and its retries, > and soft_reset_sop_type for the next Soft_Reset. Point the latter at the > cable plug only for the VCONN Swap, only once, and back at SOP whenever > the protocol layer starts over or a Soft_Reset of the port partner > starts, along with the SOP' MessageID counters. > > Fixes: 6bd181ba60e1 ("usb: typec: tcpm: add control message support to sop'") > Cc: stable@vger.kernel.org > Signed-off-by: Alexey Charkov <alchark@flipper.net> Hopefully Badhri or RD have time to take a look, but LGTM: Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > --- > drivers/usb/typec/tcpm/tcpm.c | 28 +++++++++++++++++----------- > 1 file changed, 17 insertions(+), 11 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index bb90211660ca..8c5be904d772 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -675,12 +675,13 @@ struct tcpm_port { > > /* SOP* Related Fields */ > /* > - * tx_sop_type determines which SOP* a message is being sent on. > - * For messages that are queued and not sent immediately such as in > - * tcpm_queue_message or messages that send after state changes, > - * the tx_sop_type is set accordingly. > + * Messages that are not sent right away carry their SOP* separately, > + * one per context so that one cannot redirect another: > + * vdm_sop_type for the VDM being sent, including its retries, and > + * soft_reset_sop_type for the next Soft_Reset. > */ > - enum tcpm_transmit_type tx_sop_type; > + enum tcpm_transmit_type vdm_sop_type; > + enum tcpm_transmit_type soft_reset_sop_type; > /* > * Prior to discovering the port partner's Specification Revision, the > * Vconn source and cable plug will use the lower of their two revisions. > @@ -2003,7 +2004,7 @@ static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header, > port->vdm_state = VDM_STATE_READY; > port->vdm_sm_running = true; > > - port->tx_sop_type = tx_sop_type; > + port->vdm_sop_type = tx_sop_type; > > mod_vdm_delayed_work(port, 0); > } > @@ -3065,7 +3066,7 @@ static void vdm_run_state_machine(struct tcpm_port *port) > } else { > tcpm_ams_finish(port); > port->vdo_data[0] = 0; > - if (port->tx_sop_type == TCPC_TX_SOP) > + if (port->vdm_sop_type == TCPC_TX_SOP) > break; > /* Handle SOP' Transmission Errors */ > switch (PD_VDO_CMD(vdo_hdr)) { > @@ -3102,7 +3103,7 @@ static void vdm_run_state_machine(struct tcpm_port *port) > case VDM_STATE_SEND_MESSAGE: > /* Prepare and send VDM */ > memset(&msg, 0, sizeof(msg)); > - if (port->tx_sop_type == TCPC_TX_SOP_PRIME) { > + if (port->vdm_sop_type == TCPC_TX_SOP_PRIME) { > msg.header = PD_HEADER_LE(PD_DATA_VENDOR_DEF, > 0, /* Cable Plug Indicator for DFP/UFP */ > 0, /* Reserved */ > @@ -3119,7 +3120,7 @@ static void vdm_run_state_machine(struct tcpm_port *port) > } > for (i = 0; i < port->vdo_count; i++) > msg.payload[i] = cpu_to_le32(port->vdo_data[i]); > - res = tcpm_pd_transmit(port, port->tx_sop_type, &msg); > + res = tcpm_pd_transmit(port, port->vdm_sop_type, &msg); > if (res < 0) { > port->vdm_state = VDM_STATE_ERR_SEND; > } else { > @@ -5529,6 +5530,7 @@ static void run_state_machine(struct tcpm_port *port) > port->message_id_prime = 0; > port->rx_msgid = -1; > port->rx_msgid_prime = -1; > + port->soft_reset_sop_type = TCPC_TX_SOP; > port->explicit_contract = false; > /* SNK -> SRC POWER/FAST_ROLE_SWAP finished */ > if (port->ams == POWER_ROLE_SWAP || > @@ -5801,6 +5803,7 @@ static void run_state_machine(struct tcpm_port *port) > port->message_id_prime = 0; > port->rx_msgid = -1; > port->rx_msgid_prime = -1; > + port->soft_reset_sop_type = TCPC_TX_SOP; > port->explicit_contract = false; > > if (port->ams == POWER_ROLE_SWAP || > @@ -6193,6 +6196,7 @@ static void run_state_machine(struct tcpm_port *port) > case SOFT_RESET: > port->message_id = 0; > port->rx_msgid = -1; > + port->soft_reset_sop_type = TCPC_TX_SOP; > /* remove existing capabilities */ > tcpm_partner_source_caps_reset(port); > tcpm_pd_send_control(port, PD_CTRL_ACCEPT, TCPC_TX_SOP); > @@ -6210,6 +6214,7 @@ static void run_state_machine(struct tcpm_port *port) > case SNK_SOFT_RESET: > if (port->ams != NONE_AMS) > tcpm_ams_finish(port); > + port->soft_reset_sop_type = TCPC_TX_SOP; > port->upcoming_state = SOFT_RESET_SEND; > tcpm_ams_start(port, SOFT_RESET_AMS); > break; > @@ -6220,7 +6225,8 @@ static void run_state_machine(struct tcpm_port *port) > * A Soft_Reset Message Shall be targeted at a specific entity > * depending on the type of SOP* packet used. > */ > - if (port->tx_sop_type == TCPC_TX_SOP_PRIME) { > + if (port->soft_reset_sop_type == TCPC_TX_SOP_PRIME) { > + port->soft_reset_sop_type = TCPC_TX_SOP; > port->message_id_prime = 0; > port->rx_msgid_prime = -1; > tcpm_pd_send_control(port, PD_CTRL_SOFT_RESET, TCPC_TX_SOP_PRIME); > @@ -6439,7 +6445,7 @@ static void run_state_machine(struct tcpm_port *port) > case VCONN_SWAP_SEND_SOFT_RESET: > tcpm_swap_complete(port, port->swap_status); > if (tcpm_can_communicate_sop_prime(port)) { > - port->tx_sop_type = TCPC_TX_SOP_PRIME; > + port->soft_reset_sop_type = TCPC_TX_SOP_PRIME; > port->upcoming_state = SOFT_RESET_SEND; > tcpm_ams_start(port, SOFT_RESET_AMS); > } else { > > -- > 2.56.0 > -- heikki ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] usb: typec: tcpm: Stop replaying Source_Capabilities after cable discovery 2026-11-18 7:26 [PATCH v2 0/4] usb: typec: tcpm: Fixes for talking to the cable plug as a VCONN source Alexey Charkov 2026-11-18 7:26 ` [PATCH v2 1/4] usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one Alexey Charkov @ 2026-11-18 7:26 ` Alexey Charkov 2026-11-20 14:32 ` Heikki Krogerus 2026-11-18 7:26 ` [PATCH v2 3/4] usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers Alexey Charkov 2 siblings, 1 reply; 6+ messages in thread From: Alexey Charkov @ 2026-11-18 7:26 UTC (permalink / raw) To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman, RD Babiera Cc: Sebastian Reichel, linux-usb, Alexey Charkov, stable When its first Source_Capabilities goes unacknowledged, a source that is the VCONN source asks the cable plug for its identity in SRC_VDM_IDENTITY_REQUEST. Entering that state sets upcoming_state to SRC_SEND_CAPABILITIES, for a message from the sink that interrupts it through SRC_READY. The ACK and send error paths go to SRC_SEND_CAPABILITIES directly and leave upcoming_state set, so the first SRC_READY after the contract sends Source_Capabilities again. The second negotiation can cut into the sink's own Discover Identity, and once ended in a Hard Reset between two FUSB302B ports. Clear upcoming_state when SRC_SEND_CAPABILITIES follows SRC_VDM_IDENTITY_REQUEST directly. Fixes: af8b627046bc ("usb: typec: tcpm: add state machine support for SRC_VDM_IDENTITY_REQUEST") Cc: stable@vger.kernel.org Signed-off-by: Alexey Charkov <alchark@flipper.net> --- drivers/usb/typec/tcpm/tcpm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 8c5be904d772..b9146658f6e5 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -5544,6 +5544,12 @@ static void run_state_machine(struct tcpm_port *port) tcpm_ams_start(port, POWER_NEGOTIATION); break; case SRC_SEND_CAPABILITIES: + /* + * Straight from Discover Identity to the cable plug, rather + * than back through SRC_READY after a message from the sink + */ + if (port->prev_state == SRC_VDM_IDENTITY_REQUEST) + port->upcoming_state = INVALID_STATE; port->caps_count++; if (port->caps_count > PD_N_CAPS_COUNT) { tcpm_set_state(port, SRC_READY, 0); -- 2.56.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/4] usb: typec: tcpm: Stop replaying Source_Capabilities after cable discovery 2026-11-18 7:26 ` [PATCH v2 2/4] usb: typec: tcpm: Stop replaying Source_Capabilities after cable discovery Alexey Charkov @ 2026-11-20 14:32 ` Heikki Krogerus 0 siblings, 0 replies; 6+ messages in thread From: Heikki Krogerus @ 2026-11-20 14:32 UTC (permalink / raw) To: Alexey Charkov Cc: Badhri Jagan Sridharan, Greg Kroah-Hartman, RD Babiera, Sebastian Reichel, linux-usb, stable On Wed, Nov 18, 2026 at 11:26:40AM +0400, Alexey Charkov wrote: > When its first Source_Capabilities goes unacknowledged, a source that is > the VCONN source asks the cable plug for its identity in > SRC_VDM_IDENTITY_REQUEST. Entering that state sets upcoming_state to > SRC_SEND_CAPABILITIES, for a message from the sink that interrupts it > through SRC_READY. The ACK and send error paths go to > SRC_SEND_CAPABILITIES directly and leave upcoming_state set, so the > first SRC_READY after the contract sends Source_Capabilities again. The > second negotiation can cut into the sink's own Discover Identity, and > once ended in a Hard Reset between two FUSB302B ports. > > Clear upcoming_state when SRC_SEND_CAPABILITIES follows > SRC_VDM_IDENTITY_REQUEST directly. > > Fixes: af8b627046bc ("usb: typec: tcpm: add state machine support for SRC_VDM_IDENTITY_REQUEST") > Cc: stable@vger.kernel.org > Signed-off-by: Alexey Charkov <alchark@flipper.net> Acked-by: Heikki Krogerus <heikki.krogeurus@linux.intel.com> > --- > drivers/usb/typec/tcpm/tcpm.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index 8c5be904d772..b9146658f6e5 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -5544,6 +5544,12 @@ static void run_state_machine(struct tcpm_port *port) > tcpm_ams_start(port, POWER_NEGOTIATION); > break; > case SRC_SEND_CAPABILITIES: > + /* > + * Straight from Discover Identity to the cable plug, rather > + * than back through SRC_READY after a message from the sink > + */ > + if (port->prev_state == SRC_VDM_IDENTITY_REQUEST) > + port->upcoming_state = INVALID_STATE; > port->caps_count++; > if (port->caps_count > PD_N_CAPS_COUNT) { > tcpm_set_state(port, SRC_READY, 0); > > -- > 2.56.0 > -- heikki ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/4] usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers 2026-11-18 7:26 [PATCH v2 0/4] usb: typec: tcpm: Fixes for talking to the cable plug as a VCONN source Alexey Charkov 2026-11-18 7:26 ` [PATCH v2 1/4] usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one Alexey Charkov 2026-11-18 7:26 ` [PATCH v2 2/4] usb: typec: tcpm: Stop replaying Source_Capabilities after cable discovery Alexey Charkov @ 2026-11-18 7:26 ` Alexey Charkov 2 siblings, 0 replies; 6+ messages in thread From: Alexey Charkov @ 2026-11-18 7:26 UTC (permalink / raw) To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman, RD Babiera Cc: Sebastian Reichel, linux-usb, Alexey Charkov, stable Only an ACK from the cable plug or a failure to send Discover Identity takes SRC_VDM_IDENTITY_REQUEST on to SRC_SEND_CAPABILITIES. A NAK marks discovery complete as if it came from the port partner, a BUSY retries the request, and no answer leaves the state as it is. The source then sends no Source_Capabilities until the sink gives up with a Hard Reset, which cycles VBUS, and after a NAK it never discovers the port partner. USB PD r3.3 section 9.2.26.2.5.1 goes back to Source_Capabilities on a NAK, a BUSY or no answer in time, just as on an ACK. Move on in each of those cases, and after tTypeCSendSourceCap in any case, so that a request which never goes out cannot stall the source either. Drop a request still waiting on the cable plug, and its AMS, when moving on. Fixes: af8b627046bc ("usb: typec: tcpm: add state machine support for SRC_VDM_IDENTITY_REQUEST") Cc: stable@vger.kernel.org Signed-off-by: Alexey Charkov <alchark@flipper.net> --- drivers/usb/typec/tcpm/tcpm.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index b9146658f6e5..ab7ec5334564 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -2745,6 +2745,12 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev, break; case CMDT_RSP_NAK: tcpm_ams_finish(port); + /* Go on with Source_Capabilities, as after an ACK */ + if (port->state == SRC_VDM_IDENTITY_REQUEST && + rx_sop_type == TCPC_TX_SOP_PRIME) { + tcpm_set_state(port, SRC_SEND_CAPABILITIES, 0); + return 0; + } switch (cmd) { /* * The cable is not allowed to respond with NAK so this must've happened over SOP @@ -2812,6 +2818,11 @@ static void tcpm_handle_vdm_request(struct tcpm_port *port, if (port->vdm_state == VDM_STATE_BUSY) { /* If UFP responded busy retry after timeout */ if (PD_VDO_CMDT(p[0]) == CMDT_RSP_BUSY) { + /* No retry before the first contract */ + if (port->state == SRC_VDM_IDENTITY_REQUEST) { + tcpm_set_state(port, SRC_SEND_CAPABILITIES, 0); + return; + } port->vdm_state = VDM_STATE_WAIT_RSP_BUSY; port->vdo_retry = (p[0] & ~VDO_CMDT_MASK) | CMDT_INIT; @@ -3039,6 +3050,8 @@ static void vdm_run_state_machine(struct tcpm_port *port) port->vdm_state = VDM_STATE_ERR_TMOUT; if (port->ams != NONE_AMS) tcpm_ams_finish(port); + if (port->state == SRC_VDM_IDENTITY_REQUEST) + tcpm_set_state(port, SRC_SEND_CAPABILITIES, 0); break; case VDM_STATE_ERR_SEND: /* @@ -5548,8 +5561,18 @@ static void run_state_machine(struct tcpm_port *port) * Straight from Discover Identity to the cable plug, rather * than back through SRC_READY after a message from the sink */ - if (port->prev_state == SRC_VDM_IDENTITY_REQUEST) + if (port->prev_state == SRC_VDM_IDENTITY_REQUEST) { port->upcoming_state = INVALID_STATE; + /* Forget the request if still waiting on the cable plug */ + if (port->vdm_sop_type == TCPC_TX_SOP_PRIME && + port->vdm_state > VDM_STATE_DONE) { + port->vdm_state = VDM_STATE_DONE; + port->vdo_data[0] = 0; + mod_vdm_delayed_work(port, 0); + } + if (port->ams == DISCOVER_IDENTITY) + tcpm_ams_finish(port); + } port->caps_count++; if (port->caps_count > PD_N_CAPS_COUNT) { tcpm_set_state(port, SRC_READY, 0); @@ -6560,6 +6583,8 @@ static void run_state_machine(struct tcpm_port *port) case SRC_VDM_IDENTITY_REQUEST: mod_vdm_discovery_delayed_work(port, 0); port->upcoming_state = SRC_SEND_CAPABILITIES; + /* Go on even if Discover Identity never goes out */ + tcpm_set_state(port, SRC_SEND_CAPABILITIES, PD_T_SEND_SOURCE_CAP); break; default: -- 2.56.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-20 14:32 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-18 7:26 [PATCH v2 0/4] usb: typec: tcpm: Fixes for talking to the cable plug as a VCONN source Alexey Charkov 2026-11-18 7:26 ` [PATCH v2 1/4] usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one Alexey Charkov 2026-11-20 14:31 ` Heikki Krogerus 2026-11-18 7:26 ` [PATCH v2 2/4] usb: typec: tcpm: Stop replaying Source_Capabilities after cable discovery Alexey Charkov 2026-11-20 14:32 ` Heikki Krogerus 2026-11-18 7:26 ` [PATCH v2 3/4] usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers Alexey Charkov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox