summaryrefslogtreecommitdiff
path: root/common/usbc/dp_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/dp_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/dp_alt_mode.c')
-rw-r--r--common/usbc/dp_alt_mode.c42
1 files changed, 13 insertions, 29 deletions
diff --git a/common/usbc/dp_alt_mode.c b/common/usbc/dp_alt_mode.c
index 0ae4d858dd..569c64d7ca 100644
--- a/common/usbc/dp_alt_mode.c
+++ b/common/usbc/dp_alt_mode.c
@@ -28,17 +28,11 @@
/* The state of the DP negotiation */
enum dp_states {
DP_START = 0,
- DP_ENTER_SENT,
DP_ENTER_ACKED,
DP_ENTER_NAKED,
- DP_STATUS_SENT,
DP_STATUS_ACKED,
- DP_CONFIG_SENT,
DP_ACTIVE,
- DP_EXIT_SENT,
- DP_EXIT_RETRY_SENT,
DP_ENTER_RETRY,
- DP_ENTER_RETRY_SENT,
DP_INACTIVE,
DP_STATE_COUNT
};
@@ -49,13 +43,12 @@ static enum dp_states dp_state[CONFIG_USB_PD_PORT_MAX_COUNT];
* Default of 0 indicates no command expected.
*/
static const uint8_t state_vdm_cmd[DP_STATE_COUNT] = {
- [DP_ENTER_SENT] = CMD_ENTER_MODE,
- [DP_STATUS_SENT] = CMD_DP_STATUS,
- [DP_CONFIG_SENT] = CMD_DP_CONFIG,
+ [DP_START] = CMD_ENTER_MODE,
+ [DP_ENTER_ACKED] = CMD_DP_STATUS,
+ [DP_STATUS_ACKED] = CMD_DP_CONFIG,
[DP_ACTIVE] = CMD_EXIT_MODE,
- [DP_EXIT_SENT] = CMD_EXIT_MODE,
- [DP_EXIT_RETRY_SENT] = CMD_EXIT_MODE,
- [DP_ENTER_RETRY_SENT] = CMD_ENTER_MODE,
+ [DP_ENTER_NAKED] = CMD_EXIT_MODE,
+ [DP_ENTER_RETRY] = CMD_ENTER_MODE,
};
void dp_init(int port)
@@ -110,16 +103,16 @@ void dp_vdm_acked(int port, enum tcpm_transmit_type type, int vdo_count,
/* TODO(b/155890173): Validate VDO count for specific commands */
switch (dp_state[port]) {
- case DP_ENTER_SENT:
- case DP_ENTER_RETRY_SENT:
+ case DP_START:
+ case DP_ENTER_RETRY:
dp_state[port] = DP_ENTER_ACKED;
break;
- case DP_STATUS_SENT:
+ case DP_ENTER_ACKED:
/* DP status response & UFP's DP attention have same payload. */
dfp_consume_attention(port, vdm);
dp_state[port] = DP_STATUS_ACKED;
break;
- case DP_CONFIG_SENT:
+ case DP_STATUS_ACKED:
if (modep && modep->opos && modep->fx->post_config)
modep->fx->post_config(port);
dpm_set_mode_entry_done(port);
@@ -127,7 +120,6 @@ void dp_vdm_acked(int port, enum tcpm_transmit_type type, int vdo_count,
CPRINTS("C%d: Entered DP mode", port);
break;
case DP_ACTIVE:
- case DP_EXIT_SENT:
/*
* Request to exit mode successful, so put it in
* inactive state.
@@ -135,7 +127,7 @@ void dp_vdm_acked(int port, enum tcpm_transmit_type type, int vdo_count,
CPRINTS("C%d: Exited DP mode", port);
dp_state[port] = DP_INACTIVE;
break;
- case DP_EXIT_RETRY_SENT:
+ case DP_ENTER_NAKED:
/*
* The request to exit the mode was successful,
* so try to enter the mode again.
@@ -164,7 +156,7 @@ void dp_vdm_naked(int port, enum tcpm_transmit_type type, uint8_t vdm_cmd)
return;
switch (dp_state[port]) {
- case DP_ENTER_SENT:
+ case DP_START:
/*
* If a request to enter DP mode is NAK'ed, this likely
* means the partner is already in DP alt mode, so
@@ -175,7 +167,7 @@ void dp_vdm_naked(int port, enum tcpm_transmit_type type, uint8_t vdm_cmd)
*/
dp_state[port] = DP_ENTER_NAKED;
break;
- case DP_ENTER_RETRY_SENT:
+ case DP_ENTER_RETRY:
/*
* Another NAK on the second attempt to enter DP mode.
* Give up.
@@ -211,11 +203,8 @@ int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm)
vdm[0] |= VDO_CMDT(CMDT_INIT);
vdm[0] |= VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPC_TX_SOP));
vdo_count_ret = 1;
- if (dp_state[port] == DP_START) {
+ if (dp_state[port] == DP_START)
CPRINTS("C%d: Attempting to enter DP mode", port);
- dp_state[port] = DP_ENTER_SENT;
- } else
- dp_state[port] = DP_ENTER_RETRY_SENT;
break;
case DP_ENTER_ACKED:
if (!(modep && modep->opos))
@@ -227,7 +216,6 @@ int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm)
vdm[0] |= PD_VDO_OPOS(modep->opos);
vdm[0] |= VDO_CMDT(CMDT_INIT);
vdm[0] |= VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPC_TX_SOP));
- dp_state[port] = DP_STATUS_SENT;
break;
case DP_STATUS_ACKED:
if (!(modep && modep->opos))
@@ -238,7 +226,6 @@ int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm)
return -1;
vdm[0] |= VDO_CMDT(CMDT_INIT);
vdm[0] |= VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPC_TX_SOP));
- dp_state[port] = DP_CONFIG_SENT;
break;
case DP_ENTER_NAKED:
case DP_ACTIVE:
@@ -263,9 +250,6 @@ int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm)
vdm[0] |= VDO_CMDT(CMDT_INIT);
vdm[0] |= VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPC_TX_SOP));
vdo_count_ret = 1;
- dp_state[port] = (dp_state[port] == DP_ACTIVE)
- ? DP_EXIT_SENT
- : DP_EXIT_RETRY_SENT;
break;
case DP_INACTIVE:
/*