summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/watchdog/phosphor-watchdog/0001-Customize-phosphor-watchdog-for-Intel-platforms.patch
blob: d137f6971770a4127e3c2d21e5567de0745de931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
From 0e426ce8bcde3b6fb131405ef265250a96aa7e0a Mon Sep 17 00:00:00 2001
From: James Feist <james.feist@linux.intel.com>
Date: Mon, 17 Jun 2019 12:00:58 -0700
Subject: [PATCH] Customize phosphor-watchdog for Intel platforms

This patch adds various changes to phosphor-watchdog that are
required for compatibility with Intel platforms.

   1. Add Redfish messages for watchdog timeout and pre-interrupt
   2. Use dbus properties for power control insted of service files
   3. Use host status to enable/disable watchdog
   4. Set preTimeoutInterruptOccurFlag
   5. Assign watchdog cause for correct reset cause reporting

Signed-off-by: James Feist <james.feist@linux.intel.com>
Signed-off-by: Ren Yu <yux.ren@intel.com>
Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
---
 watchdog.cpp | 212 ++++++++++++++++++++++++++++++++++++++++++++++++---
 watchdog.hpp |  23 +++++-
 2 files changed, 224 insertions(+), 11 deletions(-)

diff --git a/watchdog.cpp b/watchdog.cpp
index 9090760..2685401 100644
--- a/watchdog.cpp
+++ b/watchdog.cpp
@@ -1,11 +1,14 @@
 #include "watchdog.hpp"
 
+#include <systemd/sd-journal.h>
+
 #include <algorithm>
 #include <chrono>
 #include <phosphor-logging/elog.hpp>
 #include <phosphor-logging/log.hpp>
 #include <sdbusplus/exception.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/State/Host/server.hpp>
 
 namespace phosphor
 {
@@ -18,10 +21,77 @@ using namespace phosphor::logging;
 using sdbusplus::exception::SdBusError;
 using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 
-// systemd service to kick start a target.
-constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
-constexpr auto SYSTEMD_ROOT = "/org/freedesktop/systemd1";
-constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
+const static constexpr char* currentHostState = "CurrentHostState";
+const static constexpr char* hostStatusOff =
+    "xyz.openbmc_project.State.Host.HostState.Off";
+
+const static constexpr char* actionDescription = " due to Watchdog timeout";
+const static constexpr char* hardResetDescription = "Hard Reset - System reset";
+const static constexpr char* powerOffDescription =
+    "Power Down - System power down";
+const static constexpr char* powerCycleDescription =
+    "Power Cycle - System power cycle";
+const static constexpr char* timerExpiredDescription = "Timer expired";
+
+const static constexpr char* preInterruptActionNone =
+    "xyz.openbmc_project.State.Watchdog.PreTimeoutInterruptAction.None";
+
+const static constexpr char* preInterruptDescriptionSMI = "SMI";
+const static constexpr char* preInterruptDescriptionNMI = "NMI";
+const static constexpr char* preInterruptDescriptionMI = "Messaging Interrupt";
+
+const static constexpr char* reservedDescription = "Reserved";
+
+const static constexpr char* timerUseDescriptionBIOSFRB2 = "BIOS FRB2";
+const static constexpr char* timerUseDescriptionBIOSPOST = "BIOS/POST";
+const static constexpr char* timerUseDescriptionOSLoad = "OSLoad";
+const static constexpr char* timerUseDescriptionSMSOS = "SMS/OS";
+const static constexpr char* timerUseDescriptionOEM = "OEM";
+
+namespace restart
+{
+static constexpr const char* busName =
+    "xyz.openbmc_project.Control.Host.RestartCause";
+static constexpr const char* path =
+    "/xyz/openbmc_project/control/host0/restart_cause";
+static constexpr const char* interface =
+    "xyz.openbmc_project.Control.Host.RestartCause";
+static constexpr const char* property = "RequestedRestartCause";
+} // namespace restart
+
+// chassis state manager service
+namespace chassis
+{
+static constexpr const char* busName = "xyz.openbmc_project.State.Chassis";
+static constexpr const char* path = "/xyz/openbmc_project/state/chassis0";
+static constexpr const char* interface = "xyz.openbmc_project.State.Chassis";
+static constexpr const char* request = "RequestedPowerTransition";
+} // namespace chassis
+
+namespace host
+{
+static constexpr const char* busName = "xyz.openbmc_project.State.Host";
+static constexpr const char* path = "/xyz/openbmc_project/state/host0";
+static constexpr const char* interface = "xyz.openbmc_project.State.Host";
+static constexpr const char* request = "RequestedHostTransition";
+} // namespace host
+
+void Watchdog::powerStateChangedHandler(
+    const std::map<std::string, std::variant<std::string>>& props)
+{
+    const auto iter = props.find(currentHostState);
+    if (iter != props.end())
+    {
+        const std::string* powerState = std::get_if<std::string>(&iter->second);
+        if (powerState && (*powerState == hostStatusOff))
+        {
+            if (timerEnabled())
+            {
+                enabled(false);
+            }
+        }
+    }
+}
 
 void Watchdog::resetTimeRemaining(bool enableWatchdog)
 {
@@ -102,13 +172,102 @@ uint64_t Watchdog::interval(uint64_t value)
 // Optional callback function on timer expiration
 void Watchdog::timeOutHandler()
 {
+    PreTimeoutInterruptAction preTimeoutInterruptAction = preTimeoutInterrupt();
+    std::string preInterruptActionMessageArgs{};
+
     Action action = expireAction();
+    std::string actionMessageArgs{};
+
+    expiredTimerUse(currentTimerUse());
+
+    TimerUse timeUser = expiredTimerUse();
+    std::string timeUserMessage{};
+
     if (!this->enabled())
     {
         action = fallback->action;
     }
 
-    expiredTimerUse(currentTimerUse());
+    switch (timeUser)
+    {
+        case Watchdog::TimerUse::BIOSFRB2:
+            timeUserMessage = timerUseDescriptionBIOSFRB2;
+            break;
+        case Watchdog::TimerUse::BIOSPOST:
+            timeUserMessage = timerUseDescriptionBIOSPOST;
+            break;
+        case Watchdog::TimerUse::OSLoad:
+            timeUserMessage = timerUseDescriptionOSLoad;
+            break;
+        case Watchdog::TimerUse::SMSOS:
+            timeUserMessage = timerUseDescriptionSMSOS;
+            break;
+        case Watchdog::TimerUse::OEM:
+            timeUserMessage = timerUseDescriptionOEM;
+            break;
+        default:
+            timeUserMessage = reservedDescription;
+            break;
+    }
+
+    switch (action)
+    {
+        case Watchdog::Action::HardReset:
+            actionMessageArgs = std::string(hardResetDescription) +
+                                std::string(actionDescription);
+            break;
+        case Watchdog::Action::PowerOff:
+            actionMessageArgs = std::string(powerOffDescription) +
+                                std::string(actionDescription);
+            break;
+        case Watchdog::Action::PowerCycle:
+            actionMessageArgs = std::string(powerCycleDescription) +
+                                std::string(actionDescription);
+            break;
+        case Watchdog::Action::None:
+            actionMessageArgs = timerExpiredDescription;
+            break;
+        default:
+            actionMessageArgs = reservedDescription;
+            break;
+    }
+
+    // Log into redfish event log
+    sd_journal_send("MESSAGE=IPMIWatchdog: Timed out ACTION=%s",
+                    convertForMessage(action).c_str(), "PRIORITY=%i", LOG_INFO,
+                    "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.IPMIWatchdog",
+                    "REDFISH_MESSAGE_ARGS=%s. timer use: %s",
+                    actionMessageArgs.c_str(), timeUserMessage.c_str(), NULL);
+
+    switch (preTimeoutInterruptAction)
+    {
+        case Watchdog::PreTimeoutInterruptAction::SMI:
+            preInterruptActionMessageArgs = preInterruptDescriptionSMI;
+            break;
+        case Watchdog::PreTimeoutInterruptAction::NMI:
+            preInterruptActionMessageArgs = preInterruptDescriptionNMI;
+            break;
+        case Watchdog::PreTimeoutInterruptAction::MI:
+            preInterruptActionMessageArgs = preInterruptDescriptionMI;
+            break;
+        default:
+            preInterruptActionMessageArgs = reservedDescription;
+            break;
+    }
+
+    if (preInterruptActionNone != convertForMessage(preTimeoutInterruptAction))
+    {
+        preTimeoutInterruptOccurFlag(true);
+
+        sd_journal_send("MESSAGE=IPMIWatchdog: Pre Timed out Interrupt=%s",
+                        convertForMessage(preTimeoutInterruptAction).c_str(),
+                        "PRIORITY=%i", LOG_INFO, "REDFISH_MESSAGE_ID=%s",
+                        "OpenBMC.0.1.IPMIWatchdog",
+                        "REDFISH_MESSAGE_ARGS=Timer interrupt - %s due to "
+                        "Watchdog timeout. timer use: %s",
+                        preInterruptActionMessageArgs.c_str(),
+                        timeUserMessage.c_str(), NULL);
+    }
 
     auto target = actionTargetMap.find(action);
     if (target == actionTargetMap.end())
@@ -128,12 +287,45 @@ void Watchdog::timeOutHandler()
 
         try
         {
-            auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_ROOT,
-                                              SYSTEMD_INTERFACE, "StartUnit");
-            method.append(target->second);
-            method.append("replace");
+            sdbusplus::message::message method;
+            if (action == Watchdog::Action::HardReset)
+            {
+                auto method = bus.new_method_call(
+                    restart::busName, restart::path,
+                    "org.freedesktop.DBus.Properties", "Set");
+                method.append(
+                    restart::interface, restart::property,
+                    std::variant<std::string>("xyz.openbmc_project.State.Host."
+                                              "RestartCause.WatchdogTimer"));
+                bus.call_noreply(method);
 
-            bus.call_noreply(method);
+                method = bus.new_method_call(host::busName, host::path,
+                                             "org.freedesktop.DBus.Properties",
+                                             "Set");
+                method.append(host::interface, host::request,
+                              std::variant<std::string>(target->second));
+                bus.call_noreply(method);
+            }
+            else
+            {
+                if (action == Watchdog::Action::PowerCycle)
+                {
+                    auto method = bus.new_method_call(
+                        restart::busName, restart::path,
+                        "org.freedesktop.DBus.Properties", "Set");
+                    method.append(restart::interface, restart::property,
+                                  std::variant<std::string>(
+                                      "xyz.openbmc_project.State.Host."
+                                      "RestartCause.WatchdogTimer"));
+                    bus.call_noreply(method);
+                }
+                method = bus.new_method_call(chassis::busName, chassis::path,
+                                             "org.freedesktop.DBus.Properties",
+                                             "Set");
+                method.append(chassis::interface, chassis::request,
+                              std::variant<std::string>(target->second));
+                bus.call_noreply(method);
+            }
         }
         catch (const SdBusError& e)
         {
diff --git a/watchdog.hpp b/watchdog.hpp
index 7de9bb3..b004b7a 100644
--- a/watchdog.hpp
+++ b/watchdog.hpp
@@ -68,7 +68,18 @@ class Watchdog : public WatchdogInherits
         WatchdogInherits(bus, objPath),
         bus(bus), actionTargetMap(std::move(actionTargetMap)),
         fallback(std::move(fallback)), minInterval(minInterval),
-        timer(event, std::bind(&Watchdog::timeOutHandler, this))
+        timer(event, std::bind(&Watchdog::timeOutHandler, this)),
+        powerStateChangedSignal(
+            bus,
+            sdbusplus::bus::match::rules::propertiesChanged(
+                "/xyz/openbmc_project/state/host0",
+                "xyz.openbmc_project.State.Host"),
+            [this](sdbusplus::message::message& msg) {
+                std::string objectName;
+                std::map<std::string, std::variant<std::string>> props;
+                msg.read(objectName, props);
+                powerStateChangedHandler(props);
+            })
     {
         // We set the watchdog interval with the default value.
         interval(interval());
@@ -77,6 +88,12 @@ class Watchdog : public WatchdogInherits
         tryFallbackOrDisable();
     }
 
+    /** @brief Disable watchdog when power status change meet
+     *         the specific requirement
+     */
+    void powerStateChangedHandler(
+        const std::map<std::string, std::variant<std::string>>& props);
+
     /** @brief Resets the TimeRemaining to the configured Interval
      *         Optionally enables the watchdog.
      *
@@ -165,6 +182,10 @@ class Watchdog : public WatchdogInherits
     /** @brief Contained timer object */
     sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer;
 
+    /** @brief Optional Callback handler when power status change meet
+     * the specific requirement */
+    sdbusplus::bus::match_t powerStateChangedSignal;
+
     /** @brief Optional Callback handler on timer expirartion */
     void timeOutHandler();
 
-- 
2.29.2