blob: 271af3f5bf59293f388ac6d96cc87ba205bb5c22 [file] [log] [blame]
George Hung9d538eb2021-04-28 10:26:40 +08001From 291629d5c3e5bea31925c9d025688897c90eb783 Mon Sep 17 00:00:00 2001
2From: "Jason M. Bills" <jason.m.bills@linux.intel.com>
3Date: Thu, 30 Jan 2020 16:22:24 -0800
4Subject: [PATCH 3/3] Update IPMI Chassis Control command transition requests
5
6This change updates the IPMI Chassis Control command to use the new
7host state transitions and chassis off transition based on the
8mapping in the design document below. This allows each chassis
9control action to more closely follow the behavior defined in the
10IPMI spec.
11
12ref: https://gerrit.openbmc-project.xyz/c/openbmc/docs/+/22358
13
14Tested:
15Ran each IPMI chassis control command to confirm the expected
16behavior:
17ipmitool power on: system is powered-on using Host.On
18ipmitool power off: system is forced off using Chassis.Off
19ipmitool power cycle: system is forced off then powered-on using
20 Host.Reboot
21ipmitool power reset: system is hard reset using Host.ForceWarmReboot
22ipmitool power soft: soft power-off requested from system software
23 using Host.Off
24
25Change-Id: Ieb42722102fde0e51a49dc4aaa3ff227a3394066
26Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
27---
28 chassishandler.cpp | 121 ++-------------------------------------------
29 1 file changed, 5 insertions(+), 116 deletions(-)
30
31diff --git a/chassishandler.cpp b/chassishandler.cpp
32index af9cba72..663081de 100644
33--- a/chassishandler.cpp
34+++ b/chassishandler.cpp
35@@ -1301,76 +1301,6 @@ ipmi::RspType<uint4_t, // Restart Cause
36 return ipmi::responseSuccess(cause.value(), reserved, channel);
37 }
38
39-//-------------------------------------------------------------
40-// Send a command to SoftPowerOff application to stop any timer
41-//-------------------------------------------------------------
42-int stop_soft_off_timer()
43-{
44- constexpr auto iface = "org.freedesktop.DBus.Properties";
45- constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal."
46- "SoftPowerOff";
47-
48- constexpr auto property = "ResponseReceived";
49- constexpr auto value = "xyz.openbmc_project.Ipmi.Internal."
50- "SoftPowerOff.HostResponse.HostShutdown";
51-
52- // Get the system bus where most system services are provided.
53- auto bus = ipmid_get_sd_bus_connection();
54-
55- // Get the service name
56- // TODO openbmc/openbmc#1661 - Mapper refactor
57- //
58- // See openbmc/openbmc#1743 for some details but high level summary is that
59- // for now the code will directly call the soft off interface due to a
60- // race condition with mapper usage
61- //
62- // char *busname = nullptr;
63- // auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname);
64- // if (r < 0)
65- //{
66- // fprintf(stderr, "Failed to get %s bus name: %s\n",
67- // SOFTOFF_OBJPATH, -r);
68- // return r;
69- //}
70-
71- // No error object or reply expected.
72- int rc = sd_bus_call_method(bus, SOFTOFF_BUSNAME, SOFTOFF_OBJPATH, iface,
73- "Set", nullptr, nullptr, "ssv", soft_off_iface,
74- property, "s", value);
75- if (rc < 0)
76- {
77- log<level::ERR>("Failed to set property in SoftPowerOff object",
78- entry("ERRNO=0x%X", -rc));
79- }
80-
81- // TODO openbmc/openbmc#1661 - Mapper refactor
82- // free(busname);
83- return rc;
84-}
85-
86-//----------------------------------------------------------------------
87-// Create file to indicate there is no need for softoff notification to host
88-//----------------------------------------------------------------------
89-void indicate_no_softoff_needed()
90-{
91- fs::path path{HOST_INBAND_REQUEST_DIR};
92- if (!fs::is_directory(path))
93- {
94- fs::create_directory(path);
95- }
96-
97- // Add the host instance (default 0 for now) to the file name
98- std::string file{HOST_INBAND_REQUEST_FILE};
99- auto size = std::snprintf(nullptr, 0, file.c_str(), 0);
100- size++; // null
101- std::unique_ptr<char[]> buf(new char[size]);
102- std::snprintf(buf.get(), size, file.c_str(), 0);
103-
104- // Append file name to directory and create it
105- path /= buf.get();
106- std::ofstream(path.c_str());
107-}
108-
109 /** @brief Implementation of chassis control command
110 *
111 * @param - chassisControl command byte
112@@ -1386,60 +1316,19 @@ ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl)
113 rc = initiateHostStateTransition(State::Host::Transition::On);
114 break;
115 case CMD_POWER_OFF:
116- // This path would be hit in 2 conditions.
117- // 1: When user asks for power off using ipmi chassis command 0x04
118- // 2: Host asking for power off post shutting down.
119-
120- // If it's a host requested power off, then need to nudge Softoff
121- // application that it needs to stop the watchdog timer if running.
122- // If it is a user requested power off, then this is not really
123- // needed. But then we need to differentiate between user and host
124- // calling this same command
125-
126- // For now, we are going ahead with trying to nudge the soft off and
127- // interpret the failure to do so as a non softoff case
128- rc = stop_soft_off_timer();
129-
130- // Only request the Off transition if the soft power off
131- // application is not running
132- if (rc < 0)
133- {
134- // First create a file to indicate to the soft off application
135- // that it should not run. Not doing this will result in State
136- // manager doing a default soft power off when asked for power
137- // off.
138- indicate_no_softoff_needed();
139-
140- // Now request the shutdown
141- rc = initiateHostStateTransition(State::Host::Transition::Off);
142- }
143- else
144- {
145- log<level::INFO>("Soft off is running, so let shutdown target "
146- "stop the host");
147- }
148+ rc =
149+ initiateChassisStateTransition(State::Chassis::Transition::Off);
150 break;
151-
152 case CMD_HARD_RESET:
153+ rc = initiateHostStateTransition(
154+ State::Host::Transition::ForceWarmReboot);
155+ break;
156 case CMD_POWER_CYCLE:
157- // SPEC has a section that says certain implementations can trigger
158- // PowerOn if power is Off when a command to power cycle is
159- // requested
160-
161- // First create a file to indicate to the soft off application
162- // that it should not run since this is a direct user initiated
163- // power reboot request (i.e. a reboot request that is not
164- // originating via a soft power off SMS request)
165- indicate_no_softoff_needed();
166-
167 rc = initiateHostStateTransition(State::Host::Transition::Reboot);
168 break;
169-
170 case CMD_SOFT_OFF_VIA_OVER_TEMP:
171- // Request Host State Manager to do a soft power off
172 rc = initiateHostStateTransition(State::Host::Transition::Off);
173 break;
174-
175 case CMD_PULSE_DIAGNOSTIC_INTR:
176 rc = setNmiProperty(true);
177 break;
178--
1792.21.0
180