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