diff options
author | Diana Z <dzigterman@chromium.org> | 2020-11-24 14:52:04 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-12-15 16:02:39 +0000 |
commit | 470074fc8a4df59c2e8207cb474f3e3d5ea18583 (patch) | |
tree | a338b7f6d40a413b30f862a4c51e57f3d9f68470 | |
parent | 7365b16a1e3852040939289cfc9fa2472b160c83 (diff) | |
download | chrome-ec-470074fc8a4df59c2e8207cb474f3e3d5ea18583.tar.gz |
TCPMv2: Handle message discard in snk_give_sink_cap
If a port partner sends a message while we're attempting to send sink
capabilities, then send a soft reset with the SOP of the incoming
message.
BRANCH=None
BUG=b:157228506
TEST=on drawcia with Apple A2119, PE does not get stuck in
snk_give_sink_cap state when interrupted
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: Ic4d184ac731c44b8a604a38cfd6c0cfcd3df1127
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2558909
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r-- | common/usbc/usb_pe_drp_sm.c | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index d9923eecf4..cb0b1611b9 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -1189,6 +1189,36 @@ void pe_report_discard(int port) /* TODO(b/157228506): Ensure all states are checking discard */ } +/* + * Utility function to check for an outgoing message discard during states which + * send a message as a part of an AMS and wait for the transmit to complete. + * Note these states should not be power transitioning. + * + * In these states, discard due to an incoming message is a protocol error. + */ +static bool pe_check_outgoing_discard(int port) +{ + /* + * On outgoing discard, soft reset with SOP* of incoming message + * + * See Table 6-65 Response to an incoming Message (except VDM) in PD 3.0 + * Version 2.0 Specification. + */ + if (PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED) && + PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) { + enum tcpm_transmit_type sop = + PD_HEADER_GET_SOP(rx_emsg[port].header); + + PE_CLR_FLAG(port, PE_FLAGS_MSG_DISCARDED); + PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED); + + pe_send_soft_reset(port, sop); + return true; + } + + return false; +} + void pe_report_error(int port, enum pe_error e, enum tcpm_transmit_type type) { /* This should only be called from the PD task */ @@ -4780,7 +4810,11 @@ static void pe_snk_give_sink_cap_run(int port) if (PE_CHK_FLAG(port, PE_FLAGS_TX_COMPLETE)) { PE_CLR_FLAG(port, PE_FLAGS_TX_COMPLETE); pe_set_ready_state(port); + return; } + + if (pe_check_outgoing_discard(port)) + return; } /** @@ -5929,23 +5963,8 @@ static void pe_vcs_evaluate_swap_run(int port) return; } - /* - * On outgoing discard, soft reset with SOP of incoming message - * - * See Table 6-65 Response to an incoming Message (except VDM) in PD 3.0 - * Version 2.0 Specification. - */ - if (PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED) && - PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) { - enum tcpm_transmit_type sop = - PD_HEADER_GET_SOP(rx_emsg[port].header); - - PE_CLR_FLAG(port, PE_FLAGS_MSG_DISCARDED); - PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED); - - pe_send_soft_reset(port, sop); + if (pe_check_outgoing_discard(port)) return; - } } /* |