summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/default/src/integration/usbc/usb_pd_rev3.c
diff options
context:
space:
mode:
authorJameson Thies <jthies@google.com>2022-11-30 22:20:43 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-12-16 04:27:24 +0000
commit602912a4efece173240610ae0ad2ff3cea9ef18d (patch)
treef9f7cb90d5b2e7094fc820bc1a3610dccc0dd733 /zephyr/test/drivers/default/src/integration/usbc/usb_pd_rev3.c
parent37c75ac808dc857dc87a44b34419af590c7f8416 (diff)
downloadchrome-ec-602912a4efece173240610ae0ad2ff3cea9ef18d.tar.gz
TCPMV2: Handle errors in pe_send_alert_run
If the EC tries to send 2 alert messages very close to each other (~30ms), it will fail with a message discarded error on the second Alert. Because pe_send_alert_run does not check for this case, it prevents the TCPMV2 PE from returning to PE_SNK_Ready. This CL updates pe_send_alert_run to look for protocol errors and discarded messages, and send a soft reset in either case. This allows the PE to return to PE_SNK_Ready. BUG=b:260912784 TEST=Tested by adding EC command to send 2 Alerts very quickly, and confirmed that if the second alert fails the Chromebook resends it. Also, "make try_build_boards", "make runhosttests" and zephyr tests. BRANCH=None Signed-off-by: Jameson Thies <jthies@google.com> Change-Id: I5cc0920a0f910c67e988a3dbf8ac0c3c611c386b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4068497 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Diffstat (limited to 'zephyr/test/drivers/default/src/integration/usbc/usb_pd_rev3.c')
-rw-r--r--zephyr/test/drivers/default/src/integration/usbc/usb_pd_rev3.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/src/integration/usbc/usb_pd_rev3.c b/zephyr/test/drivers/default/src/integration/usbc/usb_pd_rev3.c
index 781a0cc06a..f328f343ba 100644
--- a/zephyr/test/drivers/default/src/integration/usbc/usb_pd_rev3.c
+++ b/zephyr/test/drivers/default/src/integration/usbc/usb_pd_rev3.c
@@ -217,6 +217,60 @@ ZTEST_F(usb_attach_5v_3a_pd_source_rev3, verify_alert_on_power_state_change)
}
ZTEST_F(usb_attach_5v_3a_pd_source_rev3,
+ verify_simultaneous_alert_status_resolution)
+{
+ zassert_false(fixture->src_ext.alert_received);
+ zassert_false(fixture->src_ext.status_received);
+
+ tcpci_partner_common_enable_pd_logging(&fixture->source_5v_3a, true);
+ zassert_equal(pd_broadcast_alert_msg(ADO_OTP_EVENT), EC_SUCCESS);
+ tcpci_partner_send_control_msg(&fixture->source_5v_3a,
+ PD_CTRL_GET_STATUS, 0);
+ k_sleep(K_SECONDS(2));
+ tcpci_partner_common_enable_pd_logging(&fixture->source_5v_3a, false);
+
+ /*
+ * The initial Alert message will be discarded, so the expected message
+ * order is Get_Status->Status->Alert. This will be followed by another
+ * Get_Status->Status transaction, but that is covered in other tests.
+ * This test only checks the first 3 messages.
+ */
+ int i = 0;
+ bool header_mismatch = false;
+ enum tcpci_partner_msg_sender expected_senders[3] = {
+ TCPCI_PARTNER_SENDER_PARTNER, TCPCI_PARTNER_SENDER_TCPM,
+ TCPCI_PARTNER_SENDER_TCPM
+ };
+ uint16_t expected_headers[3] = { 0x0012, 0xb002, 0x1006 };
+ struct tcpci_partner_log_msg *msg;
+
+ SYS_SLIST_FOR_EACH_CONTAINER(&fixture->source_5v_3a.msg_log, msg, node)
+ {
+ uint16_t header = sys_get_le16(msg->buf);
+
+ if (i >= 3)
+ break;
+
+ if (msg->sender != expected_senders[i] ||
+ PD_HEADER_EXT(header) !=
+ PD_HEADER_EXT(expected_headers[i]) ||
+ PD_HEADER_CNT(header) !=
+ PD_HEADER_CNT(expected_headers[i]) ||
+ PD_HEADER_TYPE(header) !=
+ PD_HEADER_TYPE(expected_headers[i])) {
+ header_mismatch = true;
+ break;
+ }
+
+ i++;
+ }
+
+ zassert_false(header_mismatch);
+ zassert_true(fixture->src_ext.alert_received);
+ zassert_true(fixture->src_ext.status_received);
+}
+
+ZTEST_F(usb_attach_5v_3a_pd_source_rev3,
verify_inaction_on_pd_button_press_while_awake)
{
uint32_t ado;