summaryrefslogtreecommitdiff
path: root/common/usbc/tbt_alt_mode.c
diff options
context:
space:
mode:
authorAbe Levkoy <alevkoy@chromium.org>2020-06-26 13:42:45 -0600
committerCommit Bot <commit-bot@chromium.org>2020-07-13 19:31:35 +0000
commit4f17647abe500a84b2e3b647830dfc3dce99afdf (patch)
treea0e11f0e5d8a4b7fd932cf4a310bbab13b6e28ea /common/usbc/tbt_alt_mode.c
parent01855188026fe401ccca1257c3f8daa88ecf5bc6 (diff)
downloadchrome-ec-4f17647abe500a84b2e3b647830dfc3dce99afdf.tar.gz
TCPMv2: Remove alt mode VDM "sent" states
In alt mode modules, don't change state after constructing a VDM for the PE to send. At that point, the VDM has not been sent, it may never be sent due to message discard, and if it is sent, the AMS may be interrupted. Wait to change state until the DPM notifies the alt mode module of some response or non-response to the sent VDM. By doing this, allow the alt mode modules to react gracefully to a discarded message or interrupted AMS. Otherwise, they would get into an unexpected state and give up on alt mode setup. Reduce flash size by 104 bytes on average (volteer RO: 192; RW: 184). BUG=b:160701588,b:158572770 TEST=Observe DP and TBT setup recover from interrupted VDM sequence TEST=Observe DP still working after power cycle on puff BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I3e556771f603312b1f0f574ce8d6e7884c19cf16 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2274644 Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'common/usbc/tbt_alt_mode.c')
-rw-r--r--common/usbc/tbt_alt_mode.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/common/usbc/tbt_alt_mode.c b/common/usbc/tbt_alt_mode.c
index 75327f0143..57b0da41b8 100644
--- a/common/usbc/tbt_alt_mode.c
+++ b/common/usbc/tbt_alt_mode.c
@@ -36,24 +36,19 @@ static int tbt_prints(const char *string, int port)
/* The states of Thunderbolt negotiation */
enum tbt_states {
TBT_START = 0,
- TBT_ENTER_SOP_SENT,
TBT_ENTER_SOP_NACKED,
TBT_ACTIVE,
- TBT_EXIT_SOP_SENT,
- TBT_EXIT_SOP_RETRY_SENT,
TBT_ENTER_SOP_RETRY,
- TBT_ENTER_SOP_RETRY_SENT,
TBT_INACTIVE,
TBT_STATE_COUNT,
};
static enum tbt_states tbt_state[CONFIG_USB_PD_PORT_MAX_COUNT];
static const uint8_t state_vdm_cmd[TBT_STATE_COUNT] = {
- [TBT_ENTER_SOP_SENT] = CMD_ENTER_MODE,
+ [TBT_START] = CMD_ENTER_MODE,
[TBT_ACTIVE] = CMD_EXIT_MODE,
- [TBT_EXIT_SOP_SENT] = CMD_EXIT_MODE,
- [TBT_EXIT_SOP_RETRY_SENT] = CMD_EXIT_MODE,
- [TBT_ENTER_SOP_RETRY_SENT] = CMD_ENTER_MODE,
+ [TBT_ENTER_SOP_NACKED] = CMD_EXIT_MODE,
+ [TBT_ENTER_SOP_RETRY] = CMD_ENTER_MODE,
};
void tbt_init(int port)
@@ -101,14 +96,14 @@ void intel_vdm_acked(int port, enum tcpm_transmit_type type, int vdo_count,
return;
switch (tbt_state[port]) {
- case TBT_ENTER_SOP_SENT:
- case TBT_ENTER_SOP_RETRY_SENT:
+ case TBT_START:
+ case TBT_ENTER_SOP_RETRY:
set_tbt_compat_mode_ready(port);
dpm_set_mode_entry_done(port);
tbt_state[port] = TBT_ACTIVE;
tbt_prints("enter mode SOP", port);
break;
- case TBT_EXIT_SOP_SENT:
+ case TBT_ACTIVE:
/*
* Request to exit mode successful, so put it in
* inactive state.
@@ -116,7 +111,7 @@ void intel_vdm_acked(int port, enum tcpm_transmit_type type, int vdo_count,
tbt_prints("exit mode SOP", port);
tbt_state[port] = TBT_INACTIVE;
break;
- case TBT_EXIT_SOP_RETRY_SENT:
+ case TBT_ENTER_SOP_NACKED:
/*
* The request to exit the mode was successful,
* so try to enter the mode again.
@@ -145,7 +140,7 @@ void intel_vdm_naked(int port, enum tcpm_transmit_type type, uint8_t vdm_cmd)
return;
switch (tbt_state[port]) {
- case TBT_ENTER_SOP_SENT:
+ case TBT_START:
/*
* If a request to enter Thunderbolt mode is NAK'ed, this
* likely means the partner is already in Thunderbolt alt mode,
@@ -154,7 +149,7 @@ void intel_vdm_naked(int port, enum tcpm_transmit_type type, uint8_t vdm_cmd)
*/
tbt_state[port] = TBT_ENTER_SOP_NACKED;
break;
- case TBT_ENTER_SOP_RETRY_SENT:
+ case TBT_ENTER_SOP_RETRY:
/*
* Another NAK on the second attempt to enter Thunderbolt mode.
* Give up.
@@ -195,10 +190,6 @@ int tbt_setup_next_vdm(int port, int vdo_count, uint32_t *vdm)
if (get_usb_pd_cable_type(port) == IDH_PTYPE_PCABLE) {
vdo_count_ret =
enter_tbt_compat_mode(port, TCPC_TX_SOP, vdm);
- if (tbt_state[port] == TBT_START)
- tbt_state[port] = TBT_ENTER_SOP_SENT;
- else
- tbt_state[port] = TBT_ENTER_SOP_RETRY_SENT;
}
/*
* TODO(b/148528713): Add support for Thunderbolt active cable.
@@ -224,9 +215,6 @@ int tbt_setup_next_vdm(int port, int vdo_count, uint32_t *vdm)
VDO_SVDM_VERS(
pd_get_vdo_ver(port, TCPC_TX_SOP));
vdo_count_ret = 1;
- tbt_state[port] = (tbt_state[port] == TBT_ACTIVE) ?
- TBT_EXIT_SOP_SENT :
- TBT_EXIT_SOP_RETRY_SENT;
}
break;
case TBT_INACTIVE: