diff options
author | Edward Hill <ecgh@chromium.org> | 2020-07-27 19:01:55 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-01 04:00:43 +0000 |
commit | 44504b4e0a648e81bd353b6a3d19cdfc3bc107da (patch) | |
tree | 34e8f59bd95d09184ab6d59898599b2451964b43 | |
parent | 0f93e28bc7d3bfe61ba792d31d6a9ed7be43728e (diff) | |
download | chrome-ec-44504b4e0a648e81bd353b6a3d19cdfc3bc107da.tar.gz |
TCPMv2: Soft reset on failure to send source caps
pe_report_error() defers to PE_SRC_SEND_CAPABILITIES for custom
error handling (via PE_FLAGS_PROTOCOL_ERROR).
pe_src_send_capabilities_run() was correctly going to PE_SRC_DISCOVERY
when we are not connected (PD 3.0 8.3.3.2.3), but it was failing to
send soft reset when we are already connected (PD 3.0 8.3.3.4.1.1).
BUG=b:161835483
BRANCH=none
TEST=make run-usb_pe_drp
PD 3.0 compliance test TD.PD.SRC3.E26
(Soft_Reset sent regardless of Rp value)
Signed-off-by: Edward Hill <ecgh@chromium.org>
Change-Id: Id71e38a69006e95b7ff4f7145e86bd5ac64c7577
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2321869
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | common/usbc/usb_pe_drp_sm.c | 16 | ||||
-rw-r--r-- | test/fake_prl.c | 2 | ||||
-rw-r--r-- | test/usb_pe_drp.c | 36 |
3 files changed, 49 insertions, 5 deletions
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index 6775396db0..30097dc2af 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -1781,14 +1781,22 @@ static void pe_src_send_capabilities_run(int port) * 1) The Protocol Layer indicates that the Message has not been sent * and we are presently not Connected * + * Send soft reset when: + * 1) The Protocol Layer indicates that the Message has not been sent + * and we are already Connected + * + * See section 8.3.3.4.1.1 PE_SRC_Send_Soft_Reset State and section + * 8.3.3.2.3 PE_SRC_Send_Capabilities State. + * * NOTE: The PE_FLAGS_PROTOCOL_ERROR is set if a GoodCRC Message * is not received. */ - if (PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR) && - !PE_CHK_FLAG(port, PE_FLAGS_PD_CONNECTION)) { + if (PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR)) { PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR); - - set_state_pe(port, PE_SRC_DISCOVERY); + if (!PE_CHK_FLAG(port, PE_FLAGS_PD_CONNECTION)) + set_state_pe(port, PE_SRC_DISCOVERY); + else + pe_send_soft_reset(port, TCPC_TX_SOP); return; } diff --git a/test/fake_prl.c b/test/fake_prl.c index 162e63298f..dcfdce9606 100644 --- a/test/fake_prl.c +++ b/test/fake_prl.c @@ -27,7 +27,7 @@ void prl_hard_reset_complete(int port) int prl_is_running(int port) { - return 0; + return 1; } void prl_reset(int port) diff --git a/test/usb_pe_drp.c b/test/usb_pe_drp.c index 18eee89c68..6cd1fb2bde 100644 --- a/test/usb_pe_drp.c +++ b/test/usb_pe_drp.c @@ -278,6 +278,41 @@ test_static int test_extended_message_not_supported_snk(void) return test_extended_message_not_supported(); } +static int test_send_caps_error(void) +{ + /* + * See section 8.3.3.4.1.1 PE_SRC_Send_Soft_Reset State and section + * 8.3.3.2.3 PE_SRC_Send_Capabilities State. + * + * Transition to the PE_SRC_Discovery state when: + * 1) The Protocol Layer indicates that the Message has not been sent + * and we are presently not Connected + */ + fake_prl_clear_last_sent_ctrl_msg(PORT0); + pe_set_flag(PORT0, PE_FLAGS_PROTOCOL_ERROR); + pe_clr_flag(PORT0, PE_FLAGS_PD_CONNECTION); + set_state_pe(PORT0, PE_SRC_SEND_CAPABILITIES); + task_wait_event(10 * MSEC); + TEST_EQ(fake_prl_get_last_sent_ctrl_msg(PORT0), 0, "%d"); + TEST_EQ(get_state_pe(PORT0), PE_SRC_DISCOVERY, "%d"); + + /* + * Send soft reset when: + * 1) The Protocol Layer indicates that the Message has not been sent + * and we are already Connected + */ + fake_prl_clear_last_sent_ctrl_msg(PORT0); + pe_set_flag(PORT0, PE_FLAGS_PROTOCOL_ERROR); + pe_set_flag(PORT0, PE_FLAGS_PD_CONNECTION); + set_state_pe(PORT0, PE_SRC_SEND_CAPABILITIES); + task_wait_event(10 * MSEC); + TEST_EQ(fake_prl_get_last_sent_ctrl_msg(PORT0), + PD_CTRL_SOFT_RESET, "%d"); + TEST_EQ(get_state_pe(PORT0), PE_SEND_SOFT_RESET, "%d"); + + return EC_SUCCESS; +} + void run_test(int argc, char **argv) { test_reset(); @@ -288,6 +323,7 @@ void run_test(int argc, char **argv) RUN_TEST(test_extended_message_not_supported_src); RUN_TEST(test_extended_message_not_supported_snk); #endif + RUN_TEST(test_send_caps_error); /* Do basic state machine validity checks last. */ RUN_TEST(test_pe_no_parent_cycles); |