diff options
Diffstat (limited to 'common/usb_pd_protocol.c')
-rw-r--r-- | common/usb_pd_protocol.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index dbbe837c74..664b3830e4 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -2586,6 +2586,14 @@ void schedule_deferred_pd_interrupt(const int port) task_set_event(pd_int_task_id[port], PD_PROCESS_INTERRUPT, 0); } +/* + * Theoretically, we may need to support up to 480 USB-PD packets per second for + * intensive operations such as FW update over PD. This value has tested well + * preventing watchdog resets with a single bad port partner plugged in. + */ +#define ALERT_STORM_MAX_COUNT 480 +#define ALERT_STORM_INTERVAL SECOND + /** * Main task entry point that handles PD interrupts for a single port * @@ -2596,6 +2604,10 @@ void pd_interrupt_handler_task(void *p) { const int port = (int) p; const int port_mask = (PD_STATUS_TCPC_ALERT_0 << port); + struct { + int count; + uint32_t time; + } storm_tracker[CONFIG_USB_PD_PORT_COUNT] = { 0 }; ASSERT(port >= 0 && port < CONFIG_USB_PD_PORT_COUNT); @@ -2617,8 +2629,30 @@ void pd_interrupt_handler_task(void *p) * PD_PROCESS_INTERRUPT to check if we missed anything. */ while ((tcpc_get_alert_status() & port_mask) && - pd_is_port_enabled(port)) + pd_is_port_enabled(port)) { + uint32_t now; + tcpc_alert(port); + + now = get_time().le.lo; + if (time_after(now, storm_tracker[port].time)) { + storm_tracker[port].time = + now + ALERT_STORM_INTERVAL; + /* + * Start at 1 since we are processing + * an interrupt now + */ + storm_tracker[port].count = 1; + } else if (++storm_tracker[port].count > + ALERT_STORM_MAX_COUNT) { + CPRINTS("C%d Interrupt storm detected. " + "Disabling port for 5 seconds.", + port); + + pd_set_suspend(port, 1); + pd_deferred_resume(port); + } + } } } } @@ -3544,6 +3578,11 @@ void pd_task(void *u) CPRINTS("TCPC p%d restart failed!", port); break; } + /* Set the CC termination and state back to default */ + tcpm_set_cc(port, + PD_ROLE_DEFAULT(port) == PD_ROLE_SOURCE ? + TYPEC_CC_RP : + TYPEC_CC_RD); set_state(port, PD_DEFAULT_STATE(port)); CPRINTS("TCPC p%d resumed!", port); #endif @@ -4431,7 +4470,7 @@ DECLARE_DEFERRED(resume_pd_port); void pd_deferred_resume(int port) { atomic_or(&pd_ports_to_resume, 1 << port); - hook_call_deferred(&resume_pd_port_data, SECOND); + hook_call_deferred(&resume_pd_port_data, 5 * SECOND); } #endif /* CONFIG_USB_PD_DEFERRED_RESUME */ |