From 0203804a9f3464d1093e7314b0a113c44223bf85 Mon Sep 17 00:00:00 2001 From: tyeth Date: Tue, 20 Oct 2026 23:44:48 +0100 Subject: [PATCH] fwk: epr: make a failed EPR transition recoverable without AC removal During EPR entry/exit the EC intentionally puts the system into a transitional clamp state: charger input current is collapsed to 0mA (learn mode on) and a hard AP throttle is asserted via update_pmf_events(BIT(PD_PROGRESS_ENTER/EXIT_EPR_MODE), 1). On a healthy transition this lasts ~1.1s and both are released after the new contract lands. When the transition fails, two pieces of that transitional state currently persist beyond the transition: 1. Neither failure handler releases the PMF transition event. The normal release path, clear_prochot(), only clears the ENTER event when cypd_get_ac_power() > 100W, which is never true after a failed EPR entry (the standing SPR contract is at most 100W), so the hard throttle outlives the transition it was meant to cover and is left to the 3s force_clear_pmf_prochot backstop at best. Release the ENTER/EXIT transition events at both points where the flow is abandoned: the EPR_MODE_ENTER_FAILED/default branch of cypd_update_epr_state(), and the retry-exhausted branch of epr_flow_pending_deferred() (the path taken when the EPR event from the PD controller never arrives). The failure handler now leaves the system in the plain-SPR state (input limit is already restored by the existing cypd_update_port_state() call on both paths) instead of the mid-transition state. 2. The "EPR fail, do not retry" latch (epr_active = 0xff) is only cleared by clear_port_state() on a PORT_DISCONNECT/hard-reset response. cypd_update_port_state() deliberately preserves it, and a CCG_RESPONSE_PORT_CONNECT does not reset it, so if the disconnect response is missed (the same event-loss class the deferred retry exists for) or EC RAM outlives a PD controller reset, the latch outlives the connection that caused it and the port can never enter EPR again. Clear the latch on PORT_CONNECT: a fresh attach is a new connection, so the do-not-retry intent (no EPR retry on the contract that failed) is preserved while the latch can no longer outlive that connection. Field evidence (FW16 Ryzen AI 300 "tulip", RTX 5070, 240W EPR, EC tulip-4.0.1): instrumented captures show the system latching into the transitional state - charger input stuck at ~0/500-800mA, hard throttle asserted (BIOS runs slow, survives OS reboot), and a port stuck attach-without-contract where EC_CMD_GET_PD_PORT_STATE returns zeros and the EC reports "AC not connected". Resets of either or both PD controllers do not clear it (EC RAM state re-imposes it after every reset); only a physical AC removal recovers, because only the PD_PROGRESS_DISCONNECTED path clears the progress/event state. A healthy reference trace of the same transition (throttle on, input 500mA, ~1.1s, then release) was captured for comparison. Issue: https://github.com/tyeth/framework-system/issues/1 Telemetry/data: https://github.com/tyeth/fw16-gpu-watchdog Related: FrameworkComputer/SoftwareFirmwareIssueTracker #160 #193 #241 #243 Compile-untested: no Zephyr build environment was available; changes were limited to call sites and symbols already used in these files and verified by read-through. Co-Authored-By: Claude Fable 5 --- zephyr/program/framework/src/cypd_ccg8.c | 6 ++++++ zephyr/program/framework/src/cypress_pd_common.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/zephyr/program/framework/src/cypd_ccg8.c b/zephyr/program/framework/src/cypd_ccg8.c index 7e3738bf6c..c4026e7780 100644 --- a/zephyr/program/framework/src/cypd_ccg8.c +++ b/zephyr/program/framework/src/cypd_ccg8.c @@ -471,6 +471,9 @@ static void epr_flow_pending_deferred(void) pd_port_states[port_idx].epr_retry_count = 0; pd_port_states[port_idx].epr_support = 0; pd_epr_in_progress &= EPR_PROCESS_MASK; + /* the transition ended, release the transition throttle */ + update_pmf_events(BIT(PD_PROGRESS_ENTER_EPR_MODE), 0); + update_pmf_events(BIT(PD_PROGRESS_EXIT_EPR_MODE), 0); if (charge_port != -1) { int controller = PORT_TO_CONTROLLER(charge_port); int port = PORT_TO_CONTROLLER_PORT(charge_port); @@ -761,6 +764,9 @@ void cypd_update_epr_state(int controller, int port, int response_len) #endif /* EPR fail, do not retry */ pd_port_states[port_idx].epr_active = 0xff; + /* the transition ended, release the transition throttle */ + update_pmf_events(BIT(PD_PROGRESS_ENTER_EPR_MODE), 0); + update_pmf_events(BIT(PD_PROGRESS_EXIT_EPR_MODE), 0); } } diff --git a/zephyr/program/framework/src/cypress_pd_common.c b/zephyr/program/framework/src/cypress_pd_common.c index af4bb255c5..961987a27a 100644 --- a/zephyr/program/framework/src/cypress_pd_common.c +++ b/zephyr/program/framework/src/cypress_pd_common.c @@ -2054,6 +2054,11 @@ void cypd_port_int(int controller, int port) case CCG_RESPONSE_PORT_CONNECT: CPRINTS("CYPD_RESPONSE_PORT_CONNECT %d", port_idx); record_ucsi_connector_change_event(controller, port); +#ifdef CONFIG_PD_CCG8_EPR + /* the EPR fail latch applies to the failed connection only */ + if (pd_port_states[port_idx].epr_active == 0xff) + pd_port_states[port_idx].epr_active = 0; +#endif cypd_update_port_state(controller, port); cypd_evaluate_port_profile(controller, port, data2[0]); break;