From c5ee27b9aa173a86e452e43571da6d7bd0a2a383 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Fri, 5 Apr 2024 10:14:33 -0400 Subject: [PATCH] New reset-with-watchdog semantics --- Cargo.lock | 2 +- task/control-plane-agent/src/mgs_common.rs | 10 +++++++--- task/control-plane-agent/src/mgs_gimlet.rs | 12 +++++++++--- task/control-plane-agent/src/mgs_psc.rs | 10 ++++++++-- task/control-plane-agent/src/mgs_sidecar.rs | 10 ++++++++-- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5c3dc1102..6eb6657ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2346,7 +2346,7 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "gateway-messages" version = "0.1.0" -source = "git+https://github.com/oxidecomputer/management-gateway-service?branch=sp-slot-watchdog#1ed45fb9ec14044aa5da136fa65ddf832079fad9" +source = "git+https://github.com/oxidecomputer/management-gateway-service?branch=sp-slot-watchdog#55f6dc7bec7e8cdc82cc059b6a5dec010bda242f" dependencies = [ "bitflags 2.5.0", "hubpack", diff --git a/task/control-plane-agent/src/mgs_common.rs b/task/control-plane-agent/src/mgs_common.rs index fa7b8086e..20c855ca8 100644 --- a/task/control-plane-agent/src/mgs_common.rs +++ b/task/control-plane-agent/src/mgs_common.rs @@ -473,12 +473,16 @@ impl MgsCommon { Ok(cnt) } - pub(crate) fn enable_sp_slot_watchdog( + pub(crate) fn reset_with_watchdog( &mut self, time_ms: u32, - ) -> Result<(), SpError> { + ) -> Result { + if self.reset_component_requested != Some(SpComponent::SP_ITSELF) { + return Err(SpError::ResetComponentTriggerWithoutPrepare); + } self.sprot.enable_sp_slot_watchdog(time_ms)?; - Ok(()) + task_jefe_api::Jefe::from(crate::JEFE.get_task_id()).request_reset(); + panic!(); // we really really shouldn't get here } pub(crate) fn disable_sp_slot_watchdog(&mut self) -> Result<(), SpError> { diff --git a/task/control-plane-agent/src/mgs_gimlet.rs b/task/control-plane-agent/src/mgs_gimlet.rs index 228f00740..79ff2821b 100644 --- a/task/control-plane-agent/src/mgs_gimlet.rs +++ b/task/control-plane-agent/src/mgs_gimlet.rs @@ -20,7 +20,7 @@ use gateway_messages::{ DiscoverResponse, Header, IgnitionCommand, IgnitionState, Message, MessageKind, MgsError, PowerState, RotRequest, RotResponse, SensorRequest, SensorResponse, SpComponent, SpError, SpPort, SpRequest, SpStateV2, - SpUpdatePrepare, UpdateChunk, UpdateId, UpdateStatus, + SpUpdatePrepare, UpdateChunk, UpdateId, UpdateStatus, WatchdogError, SERIAL_CONSOLE_IDLE_TIMEOUT, }; use heapless::{Deque, Vec}; @@ -1112,8 +1112,14 @@ impl SpHandler for MgsHandler { self.common.vpd_lock_status_all(buf) } - fn enable_sp_slot_watchdog(&mut self, time_ms: u32) -> Result<(), SpError> { - self.common.enable_sp_slot_watchdog(time_ms) + fn reset_with_watchdog( + &mut self, + time_ms: u32, + ) -> Result { + if !matches!(self.sp_update.status(), UpdateStatus::Complete(..)) { + return Err(SpError::Watchdog(WatchdogError::NoCompletedUpdate)); + } + self.common.reset_with_watchdog(time_ms) } fn disable_sp_slot_watchdog(&mut self) -> Result<(), SpError> { diff --git a/task/control-plane-agent/src/mgs_psc.rs b/task/control-plane-agent/src/mgs_psc.rs index 8ef5250cf..ead7dd968 100644 --- a/task/control-plane-agent/src/mgs_psc.rs +++ b/task/control-plane-agent/src/mgs_psc.rs @@ -650,8 +650,14 @@ impl SpHandler for MgsHandler { self.common.vpd_lock_status_all(buf) } - fn enable_sp_slot_watchdog(&mut self, time_ms: u32) -> Result<(), SpError> { - self.common.enable_sp_slot_watchdog(time_ms) + fn reset_with_watchdog( + &mut self, + time_ms: u32, + ) -> Result { + if !matches!(self.sp_update.status(), UpdateStatus::Complete(..)) { + return Err(SpError::Watchdog(WatchdogError::NoCompletedUpdate)); + } + self.common.reset_with_watchdog(time_ms) } fn disable_sp_slot_watchdog(&mut self) -> Result<(), SpError> { diff --git a/task/control-plane-agent/src/mgs_sidecar.rs b/task/control-plane-agent/src/mgs_sidecar.rs index 11191c0ed..0a1106fd4 100644 --- a/task/control-plane-agent/src/mgs_sidecar.rs +++ b/task/control-plane-agent/src/mgs_sidecar.rs @@ -759,8 +759,14 @@ impl SpHandler for MgsHandler { self.common.vpd_lock_status_all(buf) } - fn enable_sp_slot_watchdog(&mut self, time_ms: u32) -> Result<(), SpError> { - self.common.enable_sp_slot_watchdog(time_ms) + fn reset_with_watchdog( + &mut self, + time_ms: u32, + ) -> Result { + if !matches!(self.sp_update.status(), UpdateStatus::Complete(..)) { + return Err(SpError::Watchdog(WatchdogError::NoCompletedUpdate)); + } + self.common.reset_with_watchdog(time_ms) } fn disable_sp_slot_watchdog(&mut self) -> Result<(), SpError> {