Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH v3] usb: typec: tcpm: advance vdm_discovery_state on Discover Identity Not_Supported
@ 2026-11-23  7:51 Xu Yang
  2026-11-23  7:58 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Xu Yang @ 2026-11-23  7:51 UTC (permalink / raw)
  To: badhri, heikki.krogerus, gregkh; +Cc: linux-usb, linux-kernel, imx, jun.li

From: Xu Yang <xu.yang_2@nxp.com>

Commit Fixes: 205dc9cb39f5 ("usb: typec: tcpm: implement retry mechanism
for Discover Identity VDMs") advances vdm_discovery_state to
VDM_DISCOVERY_COMPLETE when a CMDT_RSP_NAK is received, but it does not
advance the state when a non-modal port returns PD_CTRL_NOT_SUPP.

This can re-arm another vdm_discovery_work if the port is going to
respond with PD_CTRL_NOT_SUPP to the partner.

  tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS);
    tcpm_queue_message();
      mod_tcpm_delayed_work();
        tcpm_state_machine_work()
          tcpm_send_queued_message()  -> send PD_MSG_CTRL_NOT_SUPP
          run_state_machine()
            case SRC_READY:
            case SNK_READY:
              mod_vdm_discovery_delayed_work(port, 0);

If both the port and its partner do not support modal operation, they
will send DISCOVER_IDENTITY to each other infinitely.

Advance vdm_discovery_state to VDM_DISCOVERY_COMPLETE in this path as
well. In particular, update the state to VDM_DISCOVERY_COMPLETE if it comes
from the port partner, and to VDM_DISCOVERY_CABLE_IDENT if it comes from a
cable.

Fixes: 205dc9cb39f5 ("usb: typec: tcpm: implement retry mechanism for Discover Identity VDMs")
Cc: stable@vger.kernel.org
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: RD Babiera <rdbabiera@google.com>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>

---
Changes in v3:
 - cc stable mail list
 - add Rb and Ab tag
Changes in v2:
 - cover a cable returns PD_CTRL_NOT_SUPP case reported by sashiko
 - kick off vdm_discovery work to continue working
 - correct previous wrong fix commit id
---
 drivers/usb/typec/tcpm/tcpm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 51e5c72799f2..09bfa596bc5c 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -3909,6 +3909,16 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
 		case SRC_READY:
 		case SNK_READY:
 			if (port->vdm_state > VDM_STATE_READY) {
+				if (port->ams == DISCOVER_IDENTITY) {
+					if (rx_sop_type == TCPC_TX_SOP) {
+						tcpm_update_vdm_discovery_state(port,
+								VDM_DISCOVERY_COMPLETE);
+					} else if (rx_sop_type == TCPC_TX_SOP_PRIME) {
+						tcpm_update_vdm_discovery_state(port,
+								VDM_DISCOVERY_CABLE_IDENT);
+						mod_vdm_discovery_delayed_work(port, 0);
+					}
+				}
 				port->vdm_state = VDM_STATE_DONE;
 				if (tcpm_vdm_ams(port))
 					tcpm_ams_finish(port);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] usb: typec: tcpm: advance vdm_discovery_state on Discover Identity Not_Supported
  2026-11-23  7:51 [PATCH v3] usb: typec: tcpm: advance vdm_discovery_state on Discover Identity Not_Supported Xu Yang
@ 2026-11-23  7:58 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-23  7:58 UTC (permalink / raw)
  To: Xu Yang; +Cc: linux-usb, imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: typec: tcpm: vdm_discovery_state stuck on DISCOVER_SVIDS
  Not_Supported
--

commit 547bf5077436d4ff437ef8c78eb36f03f1e9104c
Author: Xu Yang <xu.yang_2@nxp.com>

usb: typec: tcpm: advance vdm_discovery_state on Discover Identity Not_Supported

This commit updates port->vdm_discovery_state when PD_CTRL_NOT_SUPP is
received during a DISCOVER_IDENTITY AMS so that discovery does not loop
when communicating with a non-modal partner or cable.

> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index bf7fd632d815e..b695908e410e7 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3913,6 +3913,16 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
>  		case SRC_READY:
>  		case SNK_READY:
>  			if (port->vdm_state > VDM_STATE_READY) {
> +				if (port->ams == DISCOVER_IDENTITY) {
> +					if (rx_sop_type == TCPC_TX_SOP) {
> +						tcpm_update_vdm_discovery_state(port,
> +								VDM_DISCOVERY_COMPLETE);
> +					} else if (rx_sop_type == TCPC_TX_SOP_PRIME) {
> +						tcpm_update_vdm_discovery_state(port,
> +								VDM_DISCOVERY_CABLE_IDENT);
> +						mod_vdm_discovery_delayed_work(port, 0);
> +					}
> +				}

[Severity: Medium]
Can port->vdm_discovery_state remain stuck if a partner or cable replies
with PD_CTRL_NOT_SUPP to DISCOVER_SVIDS or DISCOVER_MODES?

When a partner ACKs CMD_DISCOVER_IDENT, tcpm_pd_svdm() and
tcpm_vdm_discovery_work() advance port->vdm_discovery_state to
VDM_DISCOVERY_PARTNER_IDENT or VDM_DISCOVERY_CABLE_IDENT and send
CMD_DISCOVER_SVID (with port->ams == DISCOVER_SVIDS) before checking
supports_modal(port).  A partner or cable that supports Discover Identity
but does not support modal operation can therefore reply with
PD_CTRL_NOT_SUPP to CMD_DISCOVER_SVID.

In tcpm_pd_svdm(), CMDT_RSP_NAK marks discovery complete for both
CMD_DISCOVER_IDENT and CMD_DISCOVER_SVID, and vdm_run_state_machine()
handles SOP' errors for CMD_DISCOVER_SVID and CMD_DISCOVER_MODES by
calling tcpm_register_partner_altmodes(port) and advancing to
VDM_DISCOVERY_COMPLETE.  Checking only port->ams == DISCOVER_IDENTITY
here leaves port->vdm_discovery_state incomplete on PD_CTRL_NOT_SUPP for
DISCOVER_SVIDS or DISCOVER_MODES, so later entries into SRC_READY or
SNK_READY re-run tcpm_vdm_discovery_work() and deferred partner altmodes
are not registered if an active cable returns PD_CTRL_NOT_SUPP on SOP'.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123075136.650549-1-xu.yang_2@oss.nxp.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-23  7:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  7:51 [PATCH v3] usb: typec: tcpm: advance vdm_discovery_state on Discover Identity Not_Supported Xu Yang
2026-11-23  7:58 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox