From cfc740514c3de776534d22673ebf05fe8c906c5b Mon Sep 17 00:00:00 2001 From: Abe Levkoy Date: Mon, 15 May 2023 12:46:52 -0600 Subject: TCPMv2: Do not attempt Enter_USB under PD 2.0 If the port partner is not PD 3.0 or higher, do not consider it to support USB4/Enter_USB. If the AP requests USB4 entry, disregard the request and consider mode entry complete. Avoid repeatedly sending Enter_USB to a PD 2.0 partner. BUG=b:279421317 TEST=twister -s drivers/drivers.usbc_usb4_mode Change-Id: I3e82738f816e6dd5af24d627b6cd971a34d74586 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4533369 Commit-Queue: Abe Levkoy Tested-by: Abe Levkoy Reviewed-by: Jameson Thies --- .../drivers/usbc_usb4_mode/src/usbc_usb4_mode.c | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'zephyr') diff --git a/zephyr/test/drivers/usbc_usb4_mode/src/usbc_usb4_mode.c b/zephyr/test/drivers/usbc_usb4_mode/src/usbc_usb4_mode.c index 4c21aaeac4..25fcff61e1 100644 --- a/zephyr/test/drivers/usbc_usb4_mode/src/usbc_usb4_mode.c +++ b/zephyr/test/drivers/usbc_usb4_mode/src/usbc_usb4_mode.c @@ -259,6 +259,44 @@ ZTEST_F(usbc_usb4_mode, test_verify_usb4_passive_entry_exit) USB_PD_MUX_USB_ENABLED, "Failed to see USB set"); } +/* If the partner claims to support USB4, but communication is only PD 2.0, the + * EC should disregard a request to enter USB4 from the host. + */ +ZTEST_F(usbc_usb4_mode, test_verify_usb4_pd2_no_entry) +{ + struct ec_response_typec_status status; + + tcpci_partner_init(&fixture->partner, PD_REV20); + fixture->partner.cable = &passive_usb4; + connect_sink_to_port(&fixture->partner, fixture->tcpci_emul, + fixture->charger_emul); + + /* Instruct partner port to accept Enter_USB message */ + fixture->partner.enter_usb_accept = true; + + /* Verify that we properly identify a USB4 capable passive cable */ + verify_cable_found(fixture->partner.cable); + + status = host_cmd_typec_status(TEST_PORT); + zassert_equal((status.mux_state & USB_MUX_CHECK_MASK), + USB_PD_MUX_USB_ENABLED, "Unexpected starting mux: 0x%02x", + status.mux_state); + + host_cmd_typec_control_enter_mode(TEST_PORT, TYPEC_MODE_USB4); + k_sleep(K_SECONDS(1)); + + /* PD 2.0 doesn't include Enter_USB, so it's not possible to enter USB4 + * mode. A Discover Identity ACK indicating support for USB4 isn't even + * valid under PD 2.0. If the host nevertheless commands the EC to enter + * USB4, the EC should not attempt to do so. + */ + status = host_cmd_typec_status(TEST_PORT); + zassert_equal((status.mux_state & USB_MUX_CHECK_MASK), + USB_PD_MUX_USB_ENABLED, "Failed to see USB still set"); + zassert_not_equal((status.mux_state & USB_MUX_CHECK_MASK), + USB_PD_MUX_USB4_ENABLED, "Unexpected USB4 mode set"); +} + /* * TODO(b/260095516): This test suite is only testing the default good case, and * one error case where the cable doesn't support USB4. This suite needs to be -- cgit v1.2.1