From b638de22154aa4cae788d9117d2507394388f839 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Fri, 9 Feb 2018 16:12:53 -0800 Subject: watchdog: Implement watchdog action setting We now respect the action set during the SetTimeout command. This maps to one of the actions defined by the dbus Watchdog interface Change-Id: I4d13d2539a2d955a4340bf5f915ca6f3b694550a Signed-off-by: William A. Kennington III --- app/watchdog.cpp | 39 ++++++++++++++++++++++++++++++++------- app/watchdog_service.cpp | 10 ++++++++++ app/watchdog_service.hpp | 10 ++++++++++ 3 files changed, 52 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/watchdog.cpp b/app/watchdog.cpp index f28ff80..84d80b9 100644 --- a/app/watchdog.cpp +++ b/app/watchdog.cpp @@ -66,6 +66,37 @@ enum class IpmiAction : uint8_t { PowerCycle = 0x3, }; +/** @brief Converts an IPMI Watchdog Action to DBUS defined action + * @param[in] ipmi_action The IPMI Watchdog Action + * @return The Watchdog Action that the ipmi_action maps to + */ +WatchdogService::Action ipmiActionToWdAction(IpmiAction ipmi_action) +{ + switch(ipmi_action) + { + case IpmiAction::None: + { + return WatchdogService::Action::None; + } + case IpmiAction::HardReset: + { + return WatchdogService::Action::HardReset; + } + case IpmiAction::PowerOff: + { + return WatchdogService::Action::PowerOff; + } + case IpmiAction::PowerCycle: + { + return WatchdogService::Action::PowerCycle; + } + default: + { + throw std::domain_error("IPMI Action is invalid"); + } + } +} + struct wd_set_req { uint8_t timer_use; uint8_t timer_action; @@ -106,15 +137,9 @@ ipmi_ret_t ipmi_app_watchdog_set( } // Set the action based on the request - // Unfortunately we only really support enable or disable - // and don't actually support a real action. Until we have proper - // action support just map NONE as a disable action. const auto ipmi_action = static_cast( req.timer_action & wd_timeout_action_mask); - if (ipmi_action == IpmiAction::None) - { - wd_service.setEnabled(false); - } + wd_service.setExpireAction(ipmiActionToWdAction(ipmi_action)); // Set the new interval and the time remaining deci -> mill seconds const uint64_t interval = req.initial_countdown * 100; diff --git a/app/watchdog_service.cpp b/app/watchdog_service.cpp index 36a967c..f11c4bf 100644 --- a/app/watchdog_service.cpp +++ b/app/watchdog_service.cpp @@ -3,12 +3,15 @@ #include #include #include +#include #include "host-ipmid/ipmid-api.h" #include "utils.hpp" using sdbusplus::message::variant_ns::get; using sdbusplus::message::variant_ns::variant; +using sdbusplus::xyz::openbmc_project::State::server::convertForMessage; +using sdbusplus::xyz::openbmc_project::State::server::Watchdog; static constexpr char wd_path[] = "/xyz/openbmc_project/watchdog/host0"; static constexpr char wd_intf[] = "xyz.openbmc_project.State.Watchdog"; @@ -36,6 +39,8 @@ WatchdogService::Properties WatchdogService::getProperties() Properties wd_prop; wd_prop.initialized = get(properties.at("Initialized")); wd_prop.enabled = get(properties.at("Enabled")); + wd_prop.expireAction = Watchdog::convertActionFromString( + get(properties.at("ExpireAction"))); wd_prop.interval = get(properties.at("Interval")); wd_prop.timeRemaining = get(properties.at("TimeRemaining")); return wd_prop; @@ -64,6 +69,11 @@ void WatchdogService::setEnabled(bool enabled) setProperty("Enabled", enabled); } +void WatchdogService::setExpireAction(Action expireAction) +{ + setProperty("ExpireAction", convertForMessage(expireAction)); +} + void WatchdogService::setInterval(uint64_t interval) { setProperty("Interval", interval); diff --git a/app/watchdog_service.hpp b/app/watchdog_service.hpp index 1d5ffb8..432c7ce 100644 --- a/app/watchdog_service.hpp +++ b/app/watchdog_service.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include /** @class WatchdogService * @brief Access to the running OpenBMC watchdog implementation. @@ -10,12 +11,15 @@ class WatchdogService { public: WatchdogService(); + using Action = sdbusplus::xyz::openbmc_project::State::server::Watchdog::Action; + /** @brief Contains a copy of the properties enumerated by the * watchdog service. */ struct Properties { bool initialized; bool enabled; + Action expireAction; uint64_t interval; uint64_t timeRemaining; }; @@ -40,6 +44,12 @@ class WatchdogService { */ void setEnabled(bool enabled); + /** @brief Sets the value of the expireAction property on the host watchdog + * + * @param[in] expireAction - The new expireAction value + */ + void setExpireAction(Action expireAction); + /** @brief Sets the value of the interval property on the host watchdog * * @param[in] interval - The new interval value -- cgit v1.2.1