Patrick Venture | 5e6ac71 | 2017-10-25 12:16:19 -0700 | [diff] [blame] | 1 | #include "watchdog.hpp" |
| 2 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 3 | #include "watchdog_service.hpp" |
| 4 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 5 | #include <endian.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 6 | |
| 7 | #include <cstdint> |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 8 | #include <ipmid/api.hpp> |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 9 | #include <phosphor-logging/elog-errors.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 10 | #include <phosphor-logging/elog.hpp> |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 11 | #include <phosphor-logging/log.hpp> |
| 12 | #include <string> |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 13 | #include <xyz/openbmc_project/Common/error.hpp> |
Patrick Venture | 894571d | 2017-11-09 14:46:54 -0800 | [diff] [blame] | 14 | |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 15 | using phosphor::logging::commit; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 16 | using phosphor::logging::level; |
| 17 | using phosphor::logging::log; |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 18 | using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Patrick Venture | 5e6ac71 | 2017-10-25 12:16:19 -0700 | [diff] [blame] | 19 | |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 20 | static bool lastCallSuccessful = false; |
| 21 | |
| 22 | void reportError() |
| 23 | { |
| 24 | // We don't want to fill the SEL with errors if the daemon dies and doesn't |
| 25 | // come back but the watchdog keeps on ticking. Instead, we only report the |
| 26 | // error if we haven't reported one since the last successful call |
| 27 | if (!lastCallSuccessful) |
| 28 | { |
| 29 | return; |
| 30 | } |
| 31 | lastCallSuccessful = false; |
| 32 | |
| 33 | // TODO: This slow down the end of the IPMI transaction waiting |
| 34 | // for the commit to finish. commit<>() can take at least 5 seconds |
| 35 | // to complete. 5s is very slow for an IPMI command and ends up |
| 36 | // congesting the IPMI channel needlessly, especially if the watchdog |
| 37 | // is ticking fairly quickly and we have some transient issues. |
| 38 | commit<InternalFailure>(); |
| 39 | } |
| 40 | |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 41 | ipmi::RspType<> ipmiAppResetWatchdogTimer() |
Patrick Venture | 5e6ac71 | 2017-10-25 12:16:19 -0700 | [diff] [blame] | 42 | { |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 43 | try |
| 44 | { |
| 45 | WatchdogService wd_service; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 46 | |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 47 | // Notify the caller if we haven't initialized our timer yet |
| 48 | // so it can configure actions and timeouts |
William A. Kennington III | 2ecf512 | 2018-04-27 14:31:51 -0700 | [diff] [blame] | 49 | if (!wd_service.getInitialized()) |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 50 | { |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 51 | lastCallSuccessful = true; |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 52 | |
| 53 | constexpr uint8_t ccWatchdogNotInit = 0x80; |
| 54 | return ipmi::response(ccWatchdogNotInit); |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 55 | } |
| 56 | |
William A. Kennington III | 4b017a9 | 2018-04-27 14:31:08 -0700 | [diff] [blame] | 57 | // The ipmi standard dictates we enable the watchdog during reset |
| 58 | wd_service.resetTimeRemaining(true); |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 59 | lastCallSuccessful = true; |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 60 | return ipmi::responseSuccess(); |
Patrick Venture | 5e6ac71 | 2017-10-25 12:16:19 -0700 | [diff] [blame] | 61 | } |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 62 | catch (const InternalFailure& e) |
| 63 | { |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 64 | reportError(); |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 65 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 66 | } |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 67 | catch (const std::exception& e) |
| 68 | { |
| 69 | const std::string e_str = std::string("wd_reset: ") + e.what(); |
| 70 | log<level::ERR>(e_str.c_str()); |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 71 | reportError(); |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 72 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 5325f2c | 2018-01-08 15:17:09 -0800 | [diff] [blame] | 73 | } |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 74 | catch (...) |
| 75 | { |
| 76 | log<level::ERR>("wd_reset: Unknown Error"); |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 77 | reportError(); |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 78 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 5325f2c | 2018-01-08 15:17:09 -0800 | [diff] [blame] | 79 | } |
Patrick Venture | 5e6ac71 | 2017-10-25 12:16:19 -0700 | [diff] [blame] | 80 | } |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 81 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 82 | static constexpr uint8_t wd_dont_stop = 0x1 << 6; |
| 83 | static constexpr uint8_t wd_timeout_action_mask = 0x3; |
| 84 | |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 85 | static constexpr uint8_t wdTimerUseResTimer1 = 0x0; |
| 86 | static constexpr uint8_t wdTimerUseResTimer2 = 0x6; |
| 87 | static constexpr uint8_t wdTimerUseResTimer3 = 0x7; |
| 88 | |
| 89 | static constexpr uint8_t wdTimeoutActionTimer = 0x40; |
| 90 | static constexpr uint8_t wdTimeoutInterruptTimer = 0x04; |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 91 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 92 | enum class IpmiAction : uint8_t |
| 93 | { |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 94 | None = 0x0, |
| 95 | HardReset = 0x1, |
| 96 | PowerOff = 0x2, |
| 97 | PowerCycle = 0x3, |
| 98 | }; |
| 99 | |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 100 | /** @brief Converts an IPMI Watchdog Action to DBUS defined action |
| 101 | * @param[in] ipmi_action The IPMI Watchdog Action |
| 102 | * @return The Watchdog Action that the ipmi_action maps to |
| 103 | */ |
| 104 | WatchdogService::Action ipmiActionToWdAction(IpmiAction ipmi_action) |
| 105 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 106 | switch (ipmi_action) |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 107 | { |
| 108 | case IpmiAction::None: |
| 109 | { |
| 110 | return WatchdogService::Action::None; |
| 111 | } |
| 112 | case IpmiAction::HardReset: |
| 113 | { |
| 114 | return WatchdogService::Action::HardReset; |
| 115 | } |
| 116 | case IpmiAction::PowerOff: |
| 117 | { |
| 118 | return WatchdogService::Action::PowerOff; |
| 119 | } |
| 120 | case IpmiAction::PowerCycle: |
| 121 | { |
| 122 | return WatchdogService::Action::PowerCycle; |
| 123 | } |
| 124 | default: |
| 125 | { |
| 126 | throw std::domain_error("IPMI Action is invalid"); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 131 | enum class IpmiTimerUse : uint8_t |
| 132 | { |
| 133 | Reserved = 0x0, |
| 134 | BIOSFRB2 = 0x1, |
| 135 | BIOSPOST = 0x2, |
| 136 | OSLoad = 0x3, |
| 137 | SMSOS = 0x4, |
| 138 | OEM = 0x5, |
| 139 | }; |
| 140 | |
| 141 | WatchdogService::TimerUse ipmiTimerUseToWdTimerUse(IpmiTimerUse ipmiTimerUse) |
| 142 | { |
| 143 | switch (ipmiTimerUse) |
| 144 | { |
| 145 | case IpmiTimerUse::Reserved: |
| 146 | { |
| 147 | return WatchdogService::TimerUse::Reserved; |
| 148 | } |
| 149 | case IpmiTimerUse::BIOSFRB2: |
| 150 | { |
| 151 | return WatchdogService::TimerUse::BIOSFRB2; |
| 152 | } |
| 153 | case IpmiTimerUse::BIOSPOST: |
| 154 | { |
| 155 | return WatchdogService::TimerUse::BIOSPOST; |
| 156 | } |
| 157 | case IpmiTimerUse::OSLoad: |
| 158 | { |
| 159 | return WatchdogService::TimerUse::OSLoad; |
| 160 | } |
| 161 | case IpmiTimerUse::SMSOS: |
| 162 | { |
| 163 | return WatchdogService::TimerUse::SMSOS; |
| 164 | } |
| 165 | case IpmiTimerUse::OEM: |
| 166 | { |
| 167 | return WatchdogService::TimerUse::OEM; |
| 168 | } |
| 169 | default: |
| 170 | { |
| 171 | return WatchdogService::TimerUse::Reserved; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 176 | static uint8_t timerLogFlags = 0; |
| 177 | static uint8_t timerActions = 0; |
| 178 | static uint8_t timerUseExpirationFlags = 0; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 179 | |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 180 | /**@brief The Set Watchdog Timer ipmi command. |
| 181 | * |
| 182 | * @param |
| 183 | * - timerUse |
| 184 | * - dontStopTimer |
| 185 | * - dontLog |
| 186 | * - timerAction |
| 187 | * - pretimeout |
| 188 | * - expireFlags |
| 189 | * - initialCountdown |
| 190 | * |
| 191 | * @return completion code on success. |
| 192 | **/ |
| 193 | ipmi::RspType<> ipmiSetWatchdogTimer( |
| 194 | uint3_t timerUse, uint3_t reserved, bool dontStopTimer, bool dontLog, |
| 195 | uint3_t timeoutAction, uint1_t reserved1, uint3_t preTimeoutInterrupt, |
| 196 | uint1_t reserved2, uint8_t preTimeoutInterval, uint1_t reserved3, |
| 197 | uint5_t expFlagValue, uint2_t reserved4, uint16_t initialCountdown) |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 198 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 199 | if ((timerUse == wdTimerUseResTimer1) || |
| 200 | (timerUse == wdTimerUseResTimer2) || |
| 201 | (timerUse == wdTimerUseResTimer3) || |
| 202 | (timeoutAction == wdTimeoutActionTimer) || |
| 203 | (preTimeoutInterrupt == wdTimeoutInterruptTimer) || |
| 204 | (reserved1 | reserved2 | reserved3 | reserved4)) |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 205 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 206 | return ipmi::responseInvalidFieldRequest(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 207 | } |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 208 | |
| 209 | if (preTimeoutInterval > (initialCountdown / 10)) |
| 210 | { |
| 211 | return ipmi::responseInvalidFieldRequest(); |
| 212 | } |
| 213 | |
| 214 | timerLogFlags = static_cast<uint8_t>(dontLog); |
| 215 | timerActions &= static_cast<uint8_t>(timeoutAction) | |
| 216 | static_cast<uint8_t>(preTimeoutInterrupt) << 4; |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 217 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 218 | try |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 219 | { |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 220 | WatchdogService wd_service; |
| 221 | // Stop the timer if the don't stop bit is not set |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 222 | if (!(dontStopTimer)) |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 223 | { |
| 224 | wd_service.setEnabled(false); |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 225 | } |
| 226 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 227 | // Set the action based on the request |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 228 | const auto ipmi_action = static_cast<IpmiAction>( |
| 229 | static_cast<uint8_t>(timeoutAction) & wd_timeout_action_mask); |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 230 | wd_service.setExpireAction(ipmiActionToWdAction(ipmi_action)); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 231 | |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 232 | const auto ipmiTimerUse = |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 233 | static_cast<IpmiTimerUse>(static_cast<uint8_t>(timerUse)); |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 234 | wd_service.setTimerUse(ipmiTimerUseToWdTimerUse(ipmiTimerUse)); |
| 235 | |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 236 | wd_service.setExpiredTimerUse(WatchdogService::TimerUse::Reserved); |
| 237 | |
| 238 | timerUseExpirationFlags &= static_cast<uint8_t>(~expFlagValue) << 2; |
| 239 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 240 | // Set the new interval and the time remaining deci -> mill seconds |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 241 | const uint64_t interval = initialCountdown * 100; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 242 | wd_service.setInterval(interval); |
| 243 | wd_service.setTimeRemaining(interval); |
| 244 | |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 245 | // Mark as initialized so that future resets behave correctly |
| 246 | wd_service.setInitialized(true); |
| 247 | |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 248 | lastCallSuccessful = true; |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 249 | return ipmi::responseSuccess(); |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 250 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 251 | catch (const std::domain_error&) |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 252 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 253 | return ipmi::responseInvalidFieldRequest(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 254 | } |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 255 | catch (const InternalFailure& e) |
| 256 | { |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 257 | reportError(); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 258 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 259 | } |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 260 | catch (const std::exception& e) |
| 261 | { |
| 262 | const std::string e_str = std::string("wd_set: ") + e.what(); |
| 263 | log<level::ERR>(e_str.c_str()); |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 264 | reportError(); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 265 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 266 | } |
| 267 | catch (...) |
| 268 | { |
| 269 | log<level::ERR>("wd_set: Unknown Error"); |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 270 | reportError(); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 271 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 272 | } |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 273 | } |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 274 | |
| 275 | /** @brief Converts a DBUS Watchdog Action to IPMI defined action |
| 276 | * @param[in] wd_action The DBUS Watchdog Action |
| 277 | * @return The IpmiAction that the wd_action maps to |
| 278 | */ |
| 279 | IpmiAction wdActionToIpmiAction(WatchdogService::Action wd_action) |
| 280 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 281 | switch (wd_action) |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 282 | { |
| 283 | case WatchdogService::Action::None: |
| 284 | { |
| 285 | return IpmiAction::None; |
| 286 | } |
| 287 | case WatchdogService::Action::HardReset: |
| 288 | { |
| 289 | return IpmiAction::HardReset; |
| 290 | } |
| 291 | case WatchdogService::Action::PowerOff: |
| 292 | { |
| 293 | return IpmiAction::PowerOff; |
| 294 | } |
| 295 | case WatchdogService::Action::PowerCycle: |
| 296 | { |
| 297 | return IpmiAction::PowerCycle; |
| 298 | } |
| 299 | default: |
| 300 | { |
| 301 | // We have no method via IPMI to signal that the action is unknown |
| 302 | // or unmappable in some way. |
| 303 | // Just ignore the error and return NONE so the host can reconcile. |
| 304 | return IpmiAction::None; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 309 | IpmiTimerUse wdTimerUseToIpmiTimerUse(WatchdogService::TimerUse wdTimerUse) |
| 310 | { |
| 311 | switch (wdTimerUse) |
| 312 | { |
| 313 | case WatchdogService::TimerUse::Reserved: |
| 314 | { |
| 315 | return IpmiTimerUse::Reserved; |
| 316 | } |
| 317 | case WatchdogService::TimerUse::BIOSFRB2: |
| 318 | { |
| 319 | return IpmiTimerUse::BIOSFRB2; |
| 320 | } |
| 321 | case WatchdogService::TimerUse::BIOSPOST: |
| 322 | { |
| 323 | return IpmiTimerUse::BIOSPOST; |
| 324 | } |
| 325 | case WatchdogService::TimerUse::OSLoad: |
| 326 | { |
| 327 | return IpmiTimerUse::OSLoad; |
| 328 | } |
| 329 | |
| 330 | case WatchdogService::TimerUse::SMSOS: |
| 331 | { |
| 332 | return IpmiTimerUse::SMSOS; |
| 333 | } |
| 334 | case WatchdogService::TimerUse::OEM: |
| 335 | { |
| 336 | return IpmiTimerUse::OEM; |
| 337 | } |
| 338 | default: |
| 339 | { |
| 340 | return IpmiTimerUse::Reserved; |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 345 | static constexpr uint8_t wd_running = 0x1 << 6; |
| 346 | |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 347 | /**@brief The getWatchdogTimer ipmi command. |
| 348 | * |
| 349 | * @return Completion code plus timer details. |
| 350 | * - timerUse |
| 351 | * - timerAction |
| 352 | * - pretimeout |
| 353 | * - expireFlags |
| 354 | * - initialCountdown |
| 355 | * - presentCountdown |
| 356 | **/ |
| 357 | ipmi::RspType<uint8_t, // timerUse |
| 358 | uint8_t, // timerAction |
| 359 | uint8_t, // pretimeout |
| 360 | uint8_t, // expireFlags |
| 361 | uint16_t, // initial Countdown - Little Endian (deciseconds) |
| 362 | uint16_t // present Countdown - Little Endian (deciseconds) |
| 363 | > |
| 364 | ipmiGetWatchdogTimer() |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 365 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 366 | uint8_t expireFlags = 0; |
| 367 | uint16_t presentCountdown = 0; |
| 368 | uint8_t pretimeout = 0; |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 369 | |
| 370 | try |
| 371 | { |
| 372 | WatchdogService wd_service; |
| 373 | WatchdogService::Properties wd_prop = wd_service.getProperties(); |
| 374 | |
| 375 | // Build and return the response |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 376 | uint8_t timerUse = 0; |
| 377 | timerUse |= timerLogFlags; |
| 378 | |
| 379 | uint8_t timerAction = timerActions; |
Yong Li | f7c9db0 | 2019-01-15 13:45:33 +0800 | [diff] [blame] | 380 | |
| 381 | // Interval and timeRemaining need converted from milli -> deci seconds |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 382 | uint16_t initialCountdown = htole16(wd_prop.interval / 100); |
| 383 | |
| 384 | if (wd_prop.expiredTimerUse != WatchdogService::TimerUse::Reserved) |
| 385 | { |
| 386 | timerUseExpirationFlags |= |
| 387 | 1 << static_cast<uint8_t>( |
| 388 | wdTimerUseToIpmiTimerUse(wd_prop.expiredTimerUse)); |
| 389 | } |
| 390 | |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 391 | if (wd_prop.enabled) |
| 392 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 393 | timerUse |= wd_running; |
| 394 | presentCountdown = htole16(wd_prop.timeRemaining / 100); |
| 395 | expireFlags = 0; |
Yong Li | f7c9db0 | 2019-01-15 13:45:33 +0800 | [diff] [blame] | 396 | } |
| 397 | else |
| 398 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 399 | if (wd_prop.expiredTimerUse == WatchdogService::TimerUse::Reserved) |
| 400 | { |
| 401 | presentCountdown = initialCountdown; |
| 402 | expireFlags = 0; |
| 403 | } |
| 404 | else |
| 405 | { |
| 406 | presentCountdown = 0; |
| 407 | expireFlags = timerUseExpirationFlags; |
| 408 | } |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 409 | } |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 410 | |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 411 | timerUse |= |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 412 | static_cast<uint8_t>(wdTimerUseToIpmiTimerUse(wd_prop.timerUse)); |
| 413 | |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 414 | // TODO: Do something about having pretimeout support |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 415 | pretimeout = 0; |
| 416 | |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 417 | lastCallSuccessful = true; |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 418 | return ipmi::responseSuccess(timerUse, timerAction, pretimeout, |
| 419 | expireFlags, initialCountdown, |
| 420 | presentCountdown); |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 421 | } |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 422 | catch (const InternalFailure& e) |
| 423 | { |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 424 | reportError(); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 425 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 426 | } |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 427 | catch (const std::exception& e) |
| 428 | { |
| 429 | const std::string e_str = std::string("wd_get: ") + e.what(); |
| 430 | log<level::ERR>(e_str.c_str()); |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 431 | reportError(); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 432 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 433 | } |
| 434 | catch (...) |
| 435 | { |
| 436 | log<level::ERR>("wd_get: Unknown Error"); |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 437 | reportError(); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 438 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 439 | } |
| 440 | } |