summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-08-11 15:44:09 -0600
committerCommit Bot <commit-bot@chromium.org>2020-08-13 02:19:48 +0000
commita9ab8ea074fb28f9d11225b5800a8cf7339a9218 (patch)
tree81fc23f6a8352e77c66e3c1d17fecd7e3b849aca /common
parentc7134fa6499b03d3ee625f84f0412a7ddafb572a (diff)
downloadchrome-ec-a9ab8ea074fb28f9d11225b5800a8cf7339a9218.tar.gz
TCPMv2: Check discard flag before processing received messages
When an outgoing message is discarded due to receiving an incoming message, the new message will arrive the same state machine cycle as the discard notification (if chunking is disabled). Child states of the sender response and VDM send parent should verify their message wasn't discarded before reading the received message. The parent will continue to handle the discard flag after the child run state. BRANCH=None BUG=b:162753650 TEST=on Volteer with chunking disabled, Gatkex creek is able to continue correctly after message discard Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I9c6343c7713351b38639668a721291eba31519bc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2350502 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Tested-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/usbc/usb_pe_drp_sm.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index 5de59c56c2..5f1db976d5 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -150,6 +150,18 @@
| PE_FLAGS_MSG_DISCARDED \
| PE_FLAGS_VDM_REQUEST_TIMEOUT)
+/*
+ * Combination to check whether a reply to a message was received. Our message
+ * should have sent (i.e. not been discarded) and a partner message is ready to
+ * process.
+ *
+ * When chunking is disabled (ex. for PD 2.0), these flags will set
+ * on the same run cycle. With chunking, received message will take an
+ * additional cycle to be flagged.
+ */
+#define PE_CHK_REPLY(port) (PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED) && \
+ !PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED))
+
/* 6.7.3 Hard Reset Counter */
#define N_HARD_RESET_COUNT 2
@@ -3524,7 +3536,7 @@ static void pe_drs_send_swap_run(int port)
* 1) A Reject Message is received.
* 2) Or a Wait Message is received.
*/
- if (PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
+ if (PE_CHK_REPLY(port)) {
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
type = PD_HEADER_TYPE(rx_emsg[port].header);
@@ -3739,7 +3751,7 @@ static void pe_prs_src_snk_send_swap_run(int port)
* 1) A Reject Message is received.
* 2) Or a Wait Message is received.
*/
- if (PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
+ if (PE_CHK_REPLY(port)) {
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
type = PD_HEADER_TYPE(rx_emsg[port].header);
@@ -4238,7 +4250,7 @@ static enum vdm_response_result parse_vdm_response_common(int port)
uint8_t cnt;
uint8_t ext;
- if (!PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED))
+ if (!PE_CHK_REPLY(port))
return VDM_RESULT_WAITING;
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
@@ -5170,7 +5182,7 @@ static void pe_vcs_send_swap_run(int port)
uint8_t cnt;
enum tcpm_transmit_type sop;
- if (PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
+ if (PE_CHK_REPLY(port)) {
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
type = PD_HEADER_TYPE(rx_emsg[port].header);
@@ -5440,7 +5452,7 @@ static void pe_dr_snk_get_sink_cap_run(int port)
* Transition to PE_SEND_SOFT_RESET state when:
* 1) An unexpected message is received
*/
- if (PE_CHK_FLAG(port, PE_FLAGS_MSG_RECEIVED)) {
+ if (PE_CHK_REPLY(port)) {
PE_CLR_FLAG(port, PE_FLAGS_MSG_RECEIVED);
type = PD_HEADER_TYPE(rx_emsg[port].header);