Commit 0bc3ee92 authored by Kyle Tso's avatar Kyle Tso Committed by Greg Kroah-Hartman

usb: typec: tcpm: Properly interrupt VDM AMS

When a VDM AMS is interrupted by Messages other than VDM, the AMS needs
to be finished properly. Also start a VDM AMS if receiving SVDM Commands
from the port partner to complement the functionality of tcpm_vdm_ams().

Fixes: 0908c5ac ("usb: typec: tcpm: AMS and Collision Avoidance")
Cc: stable <stable@vger.kernel.org>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Acked-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: default avatarKyle Tso <kyletso@google.com>
Link: https://lore.kernel.org/r/20210523015855.1785484-2-kyletso@google.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2cbd838e
...@@ -1550,6 +1550,8 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev, ...@@ -1550,6 +1550,8 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev,
if (PD_VDO_SVDM_VER(p[0]) < svdm_version) if (PD_VDO_SVDM_VER(p[0]) < svdm_version)
typec_partner_set_svdm_version(port->partner, typec_partner_set_svdm_version(port->partner,
PD_VDO_SVDM_VER(p[0])); PD_VDO_SVDM_VER(p[0]));
tcpm_ams_start(port, DISCOVER_IDENTITY);
/* 6.4.4.3.1: Only respond as UFP (device) */ /* 6.4.4.3.1: Only respond as UFP (device) */
if (port->data_role == TYPEC_DEVICE && if (port->data_role == TYPEC_DEVICE &&
port->nr_snk_vdo) { port->nr_snk_vdo) {
...@@ -1568,14 +1570,19 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev, ...@@ -1568,14 +1570,19 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev,
} }
break; break;
case CMD_DISCOVER_SVID: case CMD_DISCOVER_SVID:
tcpm_ams_start(port, DISCOVER_SVIDS);
break; break;
case CMD_DISCOVER_MODES: case CMD_DISCOVER_MODES:
tcpm_ams_start(port, DISCOVER_MODES);
break; break;
case CMD_ENTER_MODE: case CMD_ENTER_MODE:
tcpm_ams_start(port, DFP_TO_UFP_ENTER_MODE);
break; break;
case CMD_EXIT_MODE: case CMD_EXIT_MODE:
tcpm_ams_start(port, DFP_TO_UFP_EXIT_MODE);
break; break;
case CMD_ATTENTION: case CMD_ATTENTION:
tcpm_ams_start(port, ATTENTION);
/* Attention command does not have response */ /* Attention command does not have response */
*adev_action = ADEV_ATTENTION; *adev_action = ADEV_ATTENTION;
return 0; return 0;
...@@ -2287,6 +2294,12 @@ static void tcpm_pd_data_request(struct tcpm_port *port, ...@@ -2287,6 +2294,12 @@ static void tcpm_pd_data_request(struct tcpm_port *port,
bool frs_enable; bool frs_enable;
int ret; int ret;
if (tcpm_vdm_ams(port) && type != PD_DATA_VENDOR_DEF) {
port->vdm_state = VDM_STATE_ERR_BUSY;
tcpm_ams_finish(port);
mod_vdm_delayed_work(port, 0);
}
switch (type) { switch (type) {
case PD_DATA_SOURCE_CAP: case PD_DATA_SOURCE_CAP:
for (i = 0; i < cnt; i++) for (i = 0; i < cnt; i++)
...@@ -2459,6 +2472,16 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, ...@@ -2459,6 +2472,16 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
enum pd_ctrl_msg_type type = pd_header_type_le(msg->header); enum pd_ctrl_msg_type type = pd_header_type_le(msg->header);
enum tcpm_state next_state; enum tcpm_state next_state;
/*
* Stop VDM state machine if interrupted by other Messages while NOT_SUPP is allowed in
* VDM AMS if waiting for VDM responses and will be handled later.
*/
if (tcpm_vdm_ams(port) && type != PD_CTRL_NOT_SUPP && type != PD_CTRL_GOOD_CRC) {
port->vdm_state = VDM_STATE_ERR_BUSY;
tcpm_ams_finish(port);
mod_vdm_delayed_work(port, 0);
}
switch (type) { switch (type) {
case PD_CTRL_GOOD_CRC: case PD_CTRL_GOOD_CRC:
case PD_CTRL_PING: case PD_CTRL_PING:
...@@ -2717,6 +2740,13 @@ static void tcpm_pd_ext_msg_request(struct tcpm_port *port, ...@@ -2717,6 +2740,13 @@ static void tcpm_pd_ext_msg_request(struct tcpm_port *port,
enum pd_ext_msg_type type = pd_header_type_le(msg->header); enum pd_ext_msg_type type = pd_header_type_le(msg->header);
unsigned int data_size = pd_ext_header_data_size_le(msg->ext_msg.header); unsigned int data_size = pd_ext_header_data_size_le(msg->ext_msg.header);
/* stopping VDM state machine if interrupted by other Messages */
if (tcpm_vdm_ams(port)) {
port->vdm_state = VDM_STATE_ERR_BUSY;
tcpm_ams_finish(port);
mod_vdm_delayed_work(port, 0);
}
if (!(le16_to_cpu(msg->ext_msg.header) & PD_EXT_HDR_CHUNKED)) { if (!(le16_to_cpu(msg->ext_msg.header) & PD_EXT_HDR_CHUNKED)) {
tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS); tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS);
tcpm_log(port, "Unchunked extended messages unsupported"); tcpm_log(port, "Unchunked extended messages unsupported");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment