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 | |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 7 | #include <ipmid/api.hpp> |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 8 | #include <phosphor-logging/elog-errors.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 9 | #include <phosphor-logging/elog.hpp> |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 10 | #include <phosphor-logging/log.hpp> |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Common/error.hpp> |
Patrick Venture | 894571d | 2017-11-09 14:46:54 -0800 | [diff] [blame] | 12 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 13 | #include <bitset> |
| 14 | #include <cstdint> |
| 15 | #include <string> |
| 16 | |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 17 | using phosphor::logging::commit; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 18 | using phosphor::logging::level; |
| 19 | using phosphor::logging::log; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 20 | using sdbusplus::error::xyz::openbmc_project::common::InternalFailure; |
Patrick Venture | 5e6ac71 | 2017-10-25 12:16:19 -0700 | [diff] [blame] | 21 | |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 22 | static bool lastCallSuccessful = false; |
| 23 | |
| 24 | void reportError() |
| 25 | { |
| 26 | // We don't want to fill the SEL with errors if the daemon dies and doesn't |
| 27 | // come back but the watchdog keeps on ticking. Instead, we only report the |
| 28 | // error if we haven't reported one since the last successful call |
| 29 | if (!lastCallSuccessful) |
| 30 | { |
| 31 | return; |
| 32 | } |
| 33 | lastCallSuccessful = false; |
| 34 | |
| 35 | // TODO: This slow down the end of the IPMI transaction waiting |
| 36 | // for the commit to finish. commit<>() can take at least 5 seconds |
| 37 | // to complete. 5s is very slow for an IPMI command and ends up |
| 38 | // congesting the IPMI channel needlessly, especially if the watchdog |
| 39 | // is ticking fairly quickly and we have some transient issues. |
| 40 | commit<InternalFailure>(); |
| 41 | } |
| 42 | |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 43 | ipmi::RspType<> ipmiAppResetWatchdogTimer() |
Patrick Venture | 5e6ac71 | 2017-10-25 12:16:19 -0700 | [diff] [blame] | 44 | { |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 45 | try |
| 46 | { |
| 47 | WatchdogService wd_service; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 48 | |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 49 | // Notify the caller if we haven't initialized our timer yet |
| 50 | // so it can configure actions and timeouts |
William A. Kennington III | 2ecf512 | 2018-04-27 14:31:51 -0700 | [diff] [blame] | 51 | if (!wd_service.getInitialized()) |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 52 | { |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 53 | lastCallSuccessful = true; |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 54 | |
| 55 | constexpr uint8_t ccWatchdogNotInit = 0x80; |
| 56 | return ipmi::response(ccWatchdogNotInit); |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 57 | } |
| 58 | |
William A. Kennington III | 4b017a9 | 2018-04-27 14:31:08 -0700 | [diff] [blame] | 59 | // The ipmi standard dictates we enable the watchdog during reset |
| 60 | wd_service.resetTimeRemaining(true); |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 61 | lastCallSuccessful = true; |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 62 | return ipmi::responseSuccess(); |
Patrick Venture | 5e6ac71 | 2017-10-25 12:16:19 -0700 | [diff] [blame] | 63 | } |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 64 | catch (const InternalFailure& e) |
| 65 | { |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 66 | reportError(); |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 67 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 68 | } |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 69 | catch (const std::exception& e) |
| 70 | { |
| 71 | const std::string e_str = std::string("wd_reset: ") + e.what(); |
| 72 | log<level::ERR>(e_str.c_str()); |
Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 73 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 5325f2c | 2018-01-08 15:17:09 -0800 | [diff] [blame] | 74 | } |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 75 | catch (...) |
| 76 | { |
| 77 | log<level::ERR>("wd_reset: Unknown Error"); |
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 | |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 89 | static constexpr uint8_t wdTimeoutActionMax = 3; |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 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 | |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 176 | static bool timerNotLogFlags = false; |
Yong Li | a729bf4 | 2019-10-14 12:42:10 +0800 | [diff] [blame] | 177 | static std::bitset<8> timerUseExpirationFlags = 0; |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 178 | static uint3_t timerPreTimeoutInterrupt = 0; |
Yong Li | a729bf4 | 2019-10-14 12:42:10 +0800 | [diff] [blame] | 179 | static constexpr uint8_t wdExpirationFlagReservedBit0 = 0x0; |
| 180 | static constexpr uint8_t wdExpirationFlagReservedBit6 = 0x6; |
| 181 | static constexpr uint8_t wdExpirationFlagReservedBit7 = 0x7; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 182 | |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 183 | /**@brief The Set Watchdog Timer ipmi command. |
| 184 | * |
| 185 | * @param |
| 186 | * - timerUse |
| 187 | * - dontStopTimer |
| 188 | * - dontLog |
| 189 | * - timerAction |
| 190 | * - pretimeout |
| 191 | * - expireFlags |
| 192 | * - initialCountdown |
| 193 | * |
| 194 | * @return completion code on success. |
| 195 | **/ |
Yong Li | a729bf4 | 2019-10-14 12:42:10 +0800 | [diff] [blame] | 196 | ipmi::RspType<> |
| 197 | ipmiSetWatchdogTimer(uint3_t timerUse, uint3_t reserved, bool dontStopTimer, |
| 198 | bool dontLog, uint3_t timeoutAction, uint1_t reserved1, |
| 199 | uint3_t preTimeoutInterrupt, uint1_t reserved2, |
| 200 | uint8_t preTimeoutInterval, |
| 201 | std::bitset<8> expFlagValue, uint16_t initialCountdown) |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 202 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 203 | if ((timerUse == wdTimerUseResTimer1) || |
| 204 | (timerUse == wdTimerUseResTimer2) || |
| 205 | (timerUse == wdTimerUseResTimer3) || |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 206 | (timeoutAction > wdTimeoutActionMax) || |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 207 | (preTimeoutInterrupt == wdTimeoutInterruptTimer) || |
Yong Li | a729bf4 | 2019-10-14 12:42:10 +0800 | [diff] [blame] | 208 | (reserved | reserved1 | reserved2 | |
| 209 | expFlagValue.test(wdExpirationFlagReservedBit0) | |
| 210 | expFlagValue.test(wdExpirationFlagReservedBit6) | |
| 211 | expFlagValue.test(wdExpirationFlagReservedBit7))) |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 212 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 213 | return ipmi::responseInvalidFieldRequest(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 214 | } |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 215 | |
| 216 | if (preTimeoutInterval > (initialCountdown / 10)) |
| 217 | { |
| 218 | return ipmi::responseInvalidFieldRequest(); |
| 219 | } |
| 220 | |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 221 | timerNotLogFlags = dontLog; |
| 222 | timerPreTimeoutInterrupt = preTimeoutInterrupt; |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 223 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 224 | try |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 225 | { |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 226 | WatchdogService wd_service; |
| 227 | // 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] | 228 | if (!(dontStopTimer)) |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 229 | { |
| 230 | wd_service.setEnabled(false); |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 231 | } |
| 232 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 233 | // Set the action based on the request |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 234 | const auto ipmi_action = static_cast<IpmiAction>( |
| 235 | static_cast<uint8_t>(timeoutAction) & wd_timeout_action_mask); |
William A. Kennington III | b638de2 | 2018-02-09 16:12:53 -0800 | [diff] [blame] | 236 | wd_service.setExpireAction(ipmiActionToWdAction(ipmi_action)); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 237 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 238 | const auto ipmiTimerUse = types::enum_cast<IpmiTimerUse>(timerUse); |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 239 | wd_service.setTimerUse(ipmiTimerUseToWdTimerUse(ipmiTimerUse)); |
| 240 | |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 241 | wd_service.setExpiredTimerUse(WatchdogService::TimerUse::Reserved); |
| 242 | |
Yong Li | a729bf4 | 2019-10-14 12:42:10 +0800 | [diff] [blame] | 243 | timerUseExpirationFlags &= ~expFlagValue; |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 244 | |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 245 | // Set the new interval and the time remaining deci -> mill seconds |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 246 | const uint64_t interval = initialCountdown * 100; |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 247 | wd_service.setInterval(interval); |
William A. Kennington III | ebc53cb | 2019-12-05 17:04:29 -0800 | [diff] [blame] | 248 | wd_service.resetTimeRemaining(false); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 249 | |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 250 | // Mark as initialized so that future resets behave correctly |
| 251 | wd_service.setInitialized(true); |
Tim Chao | 65362f4 | 2023-11-14 14:47:25 +0800 | [diff] [blame] | 252 | wd_service.setLogTimeout(!dontLog); |
William A. Kennington III | de14a02 | 2018-02-09 16:11:18 -0800 | [diff] [blame] | 253 | |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 254 | lastCallSuccessful = true; |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 255 | return ipmi::responseSuccess(); |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 256 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 257 | catch (const std::domain_error&) |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 258 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 259 | return ipmi::responseInvalidFieldRequest(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 260 | } |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 261 | catch (const InternalFailure& e) |
| 262 | { |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 263 | reportError(); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 264 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 265 | } |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 266 | catch (const std::exception& e) |
| 267 | { |
| 268 | const std::string e_str = std::string("wd_set: ") + e.what(); |
| 269 | log<level::ERR>(e_str.c_str()); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 270 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 271 | } |
| 272 | catch (...) |
| 273 | { |
| 274 | log<level::ERR>("wd_set: Unknown Error"); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 275 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 5257525 | 2018-02-09 15:54:56 -0800 | [diff] [blame] | 276 | } |
William A. Kennington III | 61d5f7b | 2018-02-09 15:23:53 -0800 | [diff] [blame] | 277 | } |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 278 | |
| 279 | /** @brief Converts a DBUS Watchdog Action to IPMI defined action |
| 280 | * @param[in] wd_action The DBUS Watchdog Action |
| 281 | * @return The IpmiAction that the wd_action maps to |
| 282 | */ |
| 283 | IpmiAction wdActionToIpmiAction(WatchdogService::Action wd_action) |
| 284 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 285 | switch (wd_action) |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 286 | { |
| 287 | case WatchdogService::Action::None: |
| 288 | { |
| 289 | return IpmiAction::None; |
| 290 | } |
| 291 | case WatchdogService::Action::HardReset: |
| 292 | { |
| 293 | return IpmiAction::HardReset; |
| 294 | } |
| 295 | case WatchdogService::Action::PowerOff: |
| 296 | { |
| 297 | return IpmiAction::PowerOff; |
| 298 | } |
| 299 | case WatchdogService::Action::PowerCycle: |
| 300 | { |
| 301 | return IpmiAction::PowerCycle; |
| 302 | } |
| 303 | default: |
| 304 | { |
| 305 | // We have no method via IPMI to signal that the action is unknown |
| 306 | // or unmappable in some way. |
| 307 | // Just ignore the error and return NONE so the host can reconcile. |
| 308 | return IpmiAction::None; |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 313 | IpmiTimerUse wdTimerUseToIpmiTimerUse(WatchdogService::TimerUse wdTimerUse) |
| 314 | { |
| 315 | switch (wdTimerUse) |
| 316 | { |
| 317 | case WatchdogService::TimerUse::Reserved: |
| 318 | { |
| 319 | return IpmiTimerUse::Reserved; |
| 320 | } |
| 321 | case WatchdogService::TimerUse::BIOSFRB2: |
| 322 | { |
| 323 | return IpmiTimerUse::BIOSFRB2; |
| 324 | } |
| 325 | case WatchdogService::TimerUse::BIOSPOST: |
| 326 | { |
| 327 | return IpmiTimerUse::BIOSPOST; |
| 328 | } |
| 329 | case WatchdogService::TimerUse::OSLoad: |
| 330 | { |
| 331 | return IpmiTimerUse::OSLoad; |
| 332 | } |
| 333 | |
| 334 | case WatchdogService::TimerUse::SMSOS: |
| 335 | { |
| 336 | return IpmiTimerUse::SMSOS; |
| 337 | } |
| 338 | case WatchdogService::TimerUse::OEM: |
| 339 | { |
| 340 | return IpmiTimerUse::OEM; |
| 341 | } |
| 342 | default: |
| 343 | { |
| 344 | return IpmiTimerUse::Reserved; |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 349 | static constexpr uint8_t wd_running = 0x1 << 6; |
| 350 | |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 351 | /**@brief The getWatchdogTimer ipmi command. |
| 352 | * |
| 353 | * @return Completion code plus timer details. |
| 354 | * - timerUse |
| 355 | * - timerAction |
| 356 | * - pretimeout |
| 357 | * - expireFlags |
| 358 | * - initialCountdown |
| 359 | * - presentCountdown |
| 360 | **/ |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 361 | ipmi::RspType<uint3_t, // timerUse - timer use |
| 362 | uint3_t, // timerUse - reserved |
| 363 | bool, // timerUse - timer is started |
| 364 | bool, // timerUse - don't log |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 365 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 366 | uint3_t, // timerAction - timeout action |
| 367 | uint1_t, // timerAction - reserved |
| 368 | uint3_t, // timerAction - pre-timeout interrupt |
| 369 | uint1_t, // timerAction - reserved |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 370 | |
Yong Li | a729bf4 | 2019-10-14 12:42:10 +0800 | [diff] [blame] | 371 | uint8_t, // pretimeout |
| 372 | std::bitset<8>, // expireFlags |
| 373 | uint16_t, // initial Countdown - Little Endian (deciseconds) |
| 374 | uint16_t // present Countdown - Little Endian (deciseconds) |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 375 | > |
| 376 | ipmiGetWatchdogTimer() |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 377 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 378 | uint16_t presentCountdown = 0; |
| 379 | uint8_t pretimeout = 0; |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 380 | |
| 381 | try |
| 382 | { |
| 383 | WatchdogService wd_service; |
| 384 | WatchdogService::Properties wd_prop = wd_service.getProperties(); |
| 385 | |
| 386 | // Build and return the response |
Yong Li | f7c9db0 | 2019-01-15 13:45:33 +0800 | [diff] [blame] | 387 | // Interval and timeRemaining need converted from milli -> deci seconds |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 388 | uint16_t initialCountdown = htole16(wd_prop.interval / 100); |
| 389 | |
| 390 | if (wd_prop.expiredTimerUse != WatchdogService::TimerUse::Reserved) |
| 391 | { |
Yong Li | a729bf4 | 2019-10-14 12:42:10 +0800 | [diff] [blame] | 392 | timerUseExpirationFlags.set(static_cast<uint8_t>( |
| 393 | wdTimerUseToIpmiTimerUse(wd_prop.expiredTimerUse))); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 394 | } |
| 395 | |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 396 | if (wd_prop.enabled) |
| 397 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 398 | presentCountdown = htole16(wd_prop.timeRemaining / 100); |
Yong Li | f7c9db0 | 2019-01-15 13:45:33 +0800 | [diff] [blame] | 399 | } |
| 400 | else |
| 401 | { |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 402 | if (wd_prop.expiredTimerUse == WatchdogService::TimerUse::Reserved) |
| 403 | { |
| 404 | presentCountdown = initialCountdown; |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 405 | } |
| 406 | else |
| 407 | { |
| 408 | presentCountdown = 0; |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 409 | // Automatically clear it whenever a timer expiration occurs. |
| 410 | timerNotLogFlags = false; |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 411 | } |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 412 | } |
Yong Li | 118907e | 2019-01-11 17:36:17 +0800 | [diff] [blame] | 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; |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 418 | return ipmi::responseSuccess( |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 419 | types::enum_cast<uint3_t>( |
| 420 | wdTimerUseToIpmiTimerUse(wd_prop.timerUse)), |
| 421 | 0, wd_prop.enabled, timerNotLogFlags, |
| 422 | types::enum_cast<uint3_t>( |
| 423 | wdActionToIpmiAction(wd_prop.expireAction)), |
| 424 | 0, timerPreTimeoutInterrupt, 0, pretimeout, timerUseExpirationFlags, |
Yong Li | 4dd71af | 2019-09-29 14:18:07 +0800 | [diff] [blame] | 425 | initialCountdown, presentCountdown); |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 426 | } |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 427 | catch (const InternalFailure& e) |
| 428 | { |
William A. Kennington III | bae471c | 2018-06-15 10:38:01 -0700 | [diff] [blame] | 429 | reportError(); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 430 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 021b4c1 | 2018-05-10 11:12:51 -0700 | [diff] [blame] | 431 | } |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 432 | catch (const std::exception& e) |
| 433 | { |
| 434 | const std::string e_str = std::string("wd_get: ") + e.what(); |
| 435 | log<level::ERR>(e_str.c_str()); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 436 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 437 | } |
| 438 | catch (...) |
| 439 | { |
| 440 | log<level::ERR>("wd_get: Unknown Error"); |
Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 441 | return ipmi::responseUnspecifiedError(); |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 442 | } |
| 443 | } |