summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/ipmi/phosphor-ipmi-host/0062-Update-IPMI-Chassis-Control-command.patch
blob: 112c1ffab3ffa546cdfb556c761392333898d1df (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
From 99f63d2af9f45badaa8aff4ef958443bea62ede8 Mon Sep 17 00:00:00 2001
From: "Jason M. Bills" <jason.m.bills@linux.intel.com>
Date: Mon, 3 Jun 2019 17:01:47 -0700
Subject: [PATCH] Update IPMI Chassis Control command

This change updates the IPMI Chassis Control command to use the new
host state transitions. This allows each chassis control action
to more closely follow the behavior defined in the IPMI spec.

ref: https://gerrit.openbmc-project.xyz/c/openbmc/docs/+/22358

Tested:
Ran each IPMI chassis control command to confirm the expected
behavior:
ipmitool power on: system is powered-on
ipmitool power off: system is forced off
ipmitool power cycle: system is forced off then powered-on
ipmitool power reset: system is hard reset
ipmitool power soft: soft power-off requested from system software

Change-Id: Ic9fba3ca4abd9a758eb88f1e6ee09f7ca64ff80a
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
---
 chassishandler.cpp | 204 +++++++++++----------------------------------
 1 file changed, 48 insertions(+), 156 deletions(-)

diff --git a/chassishandler.cpp b/chassishandler.cpp
index dfbe004be490..cd0ba3402f84 100644
--- a/chassishandler.cpp
+++ b/chassishandler.cpp
@@ -32,6 +32,7 @@
 #include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
 #include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
 #include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
+#include <xyz/openbmc_project/State/Chassis/server.hpp>
 #include <xyz/openbmc_project/State/Host/server.hpp>
 #include <xyz/openbmc_project/State/PowerOnHours/server.hpp>
 
@@ -815,59 +816,63 @@ ipmi::RspType<> ipmiSetChassisCap(bool intrusion, bool fpLockout,
 //------------------------------------------
 // Calls into Host State Manager Dbus object
 //------------------------------------------
-int initiate_state_transition(State::Host::Transition transition)
+int initiateHostStateTransition(State::Host::Transition transition)
 {
     // OpenBMC Host State Manager dbus framework
-    constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0";
-    constexpr auto HOST_STATE_MANAGER_IFACE = "xyz.openbmc_project.State.Host";
-    constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
-    constexpr auto PROPERTY = "RequestedHostTransition";
+    constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
+    constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
 
-    // sd_bus error
-    int rc = 0;
-    char* busname = NULL;
+    auto service = ipmi::getService(*getSdBus(), hostStateIntf, hostStatePath);
 
-    // SD Bus error report mechanism.
-    sd_bus_error bus_error = SD_BUS_ERROR_NULL;
+    // Convert to string equivalent of the passed in transition enum.
+    auto request = State::convertForMessage(transition);
 
-    // Gets a hook onto either a SYSTEM or SESSION bus
-    sd_bus* bus_type = ipmid_get_sd_bus_connection();
-    rc = mapper_get_service(bus_type, HOST_STATE_MANAGER_ROOT, &busname);
-    if (rc < 0)
+    try
+    {
+        ipmi::setDbusProperty(*getSdBus(), service, hostStatePath,
+                              hostStateIntf, "RequestedHostTransition",
+                              request);
+    }
+    catch (std::exception& e)
     {
         log<level::ERR>(
-            "Failed to get bus name",
-            entry("ERRNO=0x%X, OBJPATH=%s", -rc, HOST_STATE_MANAGER_ROOT));
-        return rc;
+            "Failed to initiate transition",
+            entry("EXCEPTION=%s, REQUEST=%s", e.what(), request.c_str()));
+        return -1;
     }
+    return 0;
+}
+
+//------------------------------------------
+// Calls into Chassis State Manager Dbus object
+//------------------------------------------
+int initiateChassisStateTransition(State::Chassis::Transition transition)
+{
+    // OpenBMC Chassis State Manager dbus framework
+    constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0";
+    constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis";
+
+    auto service =
+        ipmi::getService(*getSdBus(), chassisStateIntf, chassisStatePath);
 
     // Convert to string equivalent of the passed in transition enum.
     auto request = State::convertForMessage(transition);
 
-    rc = sd_bus_call_method(bus_type,                // On the system bus
-                            busname,                 // Service to contact
-                            HOST_STATE_MANAGER_ROOT, // Object path
-                            DBUS_PROPERTY_IFACE,     // Interface name
-                            "Set",                   // Method to be called
-                            &bus_error,              // object to return error
-                            nullptr,                 // Response buffer if any
-                            "ssv",                   // Takes 3 arguments
-                            HOST_STATE_MANAGER_IFACE, PROPERTY, "s",
-                            request.c_str());
-    if (rc < 0)
-    {
-        log<level::ERR>("Failed to initiate transition",
-                        entry("ERRNO=0x%X, REQUEST=%s", -rc, request.c_str()));
+    try
+    {
+        ipmi::setDbusProperty(*getSdBus(), service, chassisStatePath,
+                              chassisStateIntf, "RequestedPowerTransition",
+                              request);
     }
-    else
+    catch (std::exception& e)
     {
-        log<level::INFO>("Transition request initiated successfully");
+        log<level::ERR>(
+            "Failed to initiate transition",
+            entry("EXCEPTION=%s, REQUEST=%s", e.what(), request.c_str()));
+        return -1;
     }
 
-    sd_bus_error_free(&bus_error);
-    free(busname);
-
-    return rc;
+    return 0;
 }
 
 //------------------------------------------
@@ -1302,76 +1307,6 @@ ipmi::RspType<uint4_t, // Restart Cause
     return ipmi::responseSuccess(cause.value(), reserved, channel);
 }
 
-//-------------------------------------------------------------
-// Send a command to SoftPowerOff application to stop any timer
-//-------------------------------------------------------------
-int stop_soft_off_timer()
-{
-    constexpr auto iface = "org.freedesktop.DBus.Properties";
-    constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal."
-                                    "SoftPowerOff";
-
-    constexpr auto property = "ResponseReceived";
-    constexpr auto value = "xyz.openbmc_project.Ipmi.Internal."
-                           "SoftPowerOff.HostResponse.HostShutdown";
-
-    // Get the system bus where most system services are provided.
-    auto bus = ipmid_get_sd_bus_connection();
-
-    // Get the service name
-    // TODO openbmc/openbmc#1661 - Mapper refactor
-    //
-    // See openbmc/openbmc#1743 for some details but high level summary is that
-    // for now the code will directly call the soft off interface due to a
-    // race condition with mapper usage
-    //
-    // char *busname = nullptr;
-    // auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname);
-    // if (r < 0)
-    //{
-    //    fprintf(stderr, "Failed to get %s bus name: %s\n",
-    //            SOFTOFF_OBJPATH, -r);
-    //    return r;
-    //}
-
-    // No error object or reply expected.
-    int rc = sd_bus_call_method(bus, SOFTOFF_BUSNAME, SOFTOFF_OBJPATH, iface,
-                                "Set", nullptr, nullptr, "ssv", soft_off_iface,
-                                property, "s", value);
-    if (rc < 0)
-    {
-        log<level::ERR>("Failed to set property in SoftPowerOff object",
-                        entry("ERRNO=0x%X", -rc));
-    }
-
-    // TODO openbmc/openbmc#1661 - Mapper refactor
-    // free(busname);
-    return rc;
-}
-
-//----------------------------------------------------------------------
-// Create file to indicate there is no need for softoff notification to host
-//----------------------------------------------------------------------
-void indicate_no_softoff_needed()
-{
-    fs::path path{HOST_INBAND_REQUEST_DIR};
-    if (!fs::is_directory(path))
-    {
-        fs::create_directory(path);
-    }
-
-    // Add the host instance (default 0 for now) to the file name
-    std::string file{HOST_INBAND_REQUEST_FILE};
-    auto size = std::snprintf(nullptr, 0, file.c_str(), 0);
-    size++; // null
-    std::unique_ptr<char[]> buf(new char[size]);
-    std::snprintf(buf.get(), size, file.c_str(), 0);
-
-    // Append file name to directory and create it
-    path /= buf.get();
-    std::ofstream(path.c_str());
-}
-
 /** @brief Implementation of chassis control command
  *
  *  @param - chassisControl command byte
@@ -1384,66 +1319,22 @@ ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl)
     switch (chassisControl)
     {
         case CMD_POWER_ON:
-            rc = initiate_state_transition(State::Host::Transition::On);
+            rc = initiateHostStateTransition(State::Host::Transition::On);
             break;
         case CMD_POWER_OFF:
-            // This path would be hit in 2 conditions.
-            // 1: When user asks for power off using ipmi chassis command 0x04
-            // 2: Host asking for power off post shutting down.
-
-            // If it's a host requested power off, then need to nudge Softoff
-            // application that it needs to stop the watchdog timer if running.
-            // If it is a user requested power off, then this is not really
-            // needed. But then we need to differentiate between user and host
-            // calling this same command
-
-            // For now, we are going ahead with trying to nudge the soft off and
-            // interpret the failure to do so as a non softoff case
-            rc = stop_soft_off_timer();
-
-            // Only request the Off transition if the soft power off
-            // application is not running
-            if (rc < 0)
-            {
-                // First create a file to indicate to the soft off application
-                // that it should not run. Not doing this will result in State
-                // manager doing a default soft power off when asked for power
-                // off.
-                indicate_no_softoff_needed();
-
-                // Now request the shutdown
-                rc = initiate_state_transition(State::Host::Transition::Off);
-            }
-            else
-            {
-                log<level::INFO>("Soft off is running, so let shutdown target "
-                                 "stop the host");
-            }
+            rc =
+                initiateChassisStateTransition(State::Chassis::Transition::Off);
             break;
-
         case CMD_HARD_RESET:
-            rc = initiate_state_transition(
+            rc = initiateHostStateTransition(
                 State::Host::Transition::ForceWarmReboot);
             break;
         case CMD_POWER_CYCLE:
-            // SPEC has a section that says certain implementations can trigger
-            // PowerOn if power is Off when a command to power cycle is
-            // requested
-
-            // First create a file to indicate to the soft off application
-            // that it should not run since this is a direct user initiated
-            // power reboot request (i.e. a reboot request that is not
-            // originating via a soft power off SMS request)
-            indicate_no_softoff_needed();
-
-            rc = initiate_state_transition(State::Host::Transition::Reboot);
+            rc = initiateHostStateTransition(State::Host::Transition::Reboot);
             break;
-
         case CMD_SOFT_OFF_VIA_OVER_TEMP:
-            // Request Host State Manager to do a soft power off
-            rc = initiate_state_transition(State::Host::Transition::Off);
+            rc = initiateHostStateTransition(State::Host::Transition::Off);
             break;
-
         case CMD_PULSE_DIAGNOSTIC_INTR:
             rc = setNmiProperty(true);
             break;
-- 
2.17.1