diff options
author | Diana Z <dzigterman@chromium.org> | 2023-01-17 16:49:03 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-01-25 20:35:28 +0000 |
commit | 4a475bcaf766d46feb9e7ef8c585d6f6336a485b (patch) | |
tree | de007ba30266d2f26c7c9e94f9167aca2787242f | |
parent | d83b8aa7fd9f502c3cad258d60424075716fc6da (diff) | |
download | chrome-ec-4a475bcaf766d46feb9e7ef8c585d6f6336a485b.tar.gz |
TCPMv2: Clear DPM state on disconnect
When a partner disconnects, clear the DPM state so stale data from it
won't be presented to the AP.
BRANCH=None
BUG=b:208884535
TEST=./twister -T ./zephyr/test
Change-Id: Idf800b6c5c223e67c72c2124fb111fad27ce6361
Signed-off-by: Diana Z <dzigterman@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4179363
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r-- | common/usbc/usb_pe_drp_sm.c | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c | 61 |
2 files changed, 62 insertions, 0 deletions
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index f1bf22afa2..0aff4feaaf 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -1432,6 +1432,7 @@ static void pe_clear_port_data(int port) dpm_remove_sink(port); dpm_remove_source(port); + dpm_init(port); /* Exit BIST Test mode, in case the TCPC entered it. */ tcpc_set_bist_test_mode(port, false); diff --git a/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c b/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c index 434335e9b4..19658ac232 100644 --- a/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c +++ b/zephyr/test/drivers/ap_vdm_control/src/ap_vdm_control.c @@ -492,6 +492,30 @@ ZTEST_F(ap_vdm_control, test_vdm_request_no_send) "Failed to see no message ready"); } +ZTEST_F(ap_vdm_control, test_vdm_response_disconnect_clear) +{ + struct ec_response_typec_vdm_response vdm_resp; + uint32_t vdm_req_header = VDO(USB_SID_PD, 1, CMD_DISCOVER_IDENT) | + VDO_SVDM_VERS(VDM_VER20); + struct typec_vdm_req req = { + .vdm_data = { vdm_req_header }, + .vdm_data_objects = 1, + .partner_type = TYPEC_PARTNER_SOP, + }; + + host_cmd_typec_control_vdm_req(TEST_PORT, req); + k_sleep(K_SECONDS(1)); + + /* Now disconnect and verify there's nothing to see here */ + disconnect_source_from_port(fixture->tcpci_emul, fixture->charger_emul); + + vdm_resp = host_cmd_typec_vdm_response(TEST_PORT); + zassert_equal(vdm_resp.vdm_response_err, EC_RES_UNAVAILABLE, + "Failed to see reply cleared"); + zassert_equal(vdm_resp.vdm_data_objects, 0, + "Failed to see no VDOs available"); +} + /* Tests for the DP entry flow and related requirements */ static void verify_expected_reply(enum typec_partner_type type, int expected_num_objects, uint32_t *contents) @@ -704,3 +728,40 @@ ZTEST_F(ap_vdm_control, test_vdm_attention_two) vdm_resp.vdm_attention_objects * sizeof(uint32_t)), 0, "Failed to see correct second Attention VDM contents"); } + +ZTEST_F(ap_vdm_control, test_vdm_attention_disconnect_clear) +{ + uint32_t vdm_attention_data[2]; + int opos = 1; + struct ec_response_typec_vdm_response vdm_resp; + + run_verify_dp_entry(fixture, opos); + + /* Send an Attention message */ + vdm_attention_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, + VDO_OPOS(opos) | VDO_CMDT(CMDT_INIT) | CMD_ATTENTION); + vdm_attention_data[0] |= VDO_SVDM_VERS(VDM_VER20); + vdm_attention_data[1] = VDO_DP_STATUS(1, /* IRQ_HPD */ + true, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 0, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + tcpci_partner_send_data_msg(&fixture->partner, PD_DATA_VENDOR_DEF, + vdm_attention_data, 2, 0); + + k_sleep(K_SECONDS(1)); + /* + * Disconnect and verify no messages are reported + */ + disconnect_source_from_port(fixture->tcpci_emul, fixture->charger_emul); + + vdm_resp = host_cmd_typec_vdm_response(TEST_PORT); + zassert_equal(vdm_resp.vdm_attention_objects, 0, + "Failed to see empty message"); + zassert_equal(vdm_resp.vdm_attention_left, 0, + "Failed to see no more messages"); +} |