blob: a2ab6ab59b68db812c4571bcfdcd8f10710f5d60 [file] [log] [blame]
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05301#include "occ_status.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05002
Chris Cain17257672021-10-22 13:41:03 -05003#include "occ_manager.hpp"
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +05304#include "occ_sensor.hpp"
Chris Cain78e86012021-03-04 16:15:31 -06005#include "powermode.hpp"
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05306#include "utils.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05007
Chris Caina8857c52021-01-27 11:53:05 -06008#include <fmt/core.h>
9
Chris Cain78e86012021-03-04 16:15:31 -060010#ifdef POWER10
11#include <com/ibm/Host/Target/server.hpp>
12#endif
Gunnar Mills94df8c92018-09-14 14:50:03 -050013#include <phosphor-logging/log.hpp>
Chris Cain78e86012021-03-04 16:15:31 -060014
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053015namespace open_power
16{
17namespace occ
18{
Chris Cain78e86012021-03-04 16:15:31 -060019
Chris Caina8857c52021-01-27 11:53:05 -060020using namespace phosphor::logging;
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053021
22// Handles updates to occActive property
23bool Status::occActive(bool value)
24{
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053025 if (value != this->occActive())
26 {
Chris Caina8857c52021-01-27 11:53:05 -060027 log<level::INFO>(fmt::format("Status::occActive OCC{} changed to {}",
28 instance, value)
29 .c_str());
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053030 if (value)
31 {
32 // Bind the device
33 device.bind();
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053034
Edward A. James9fd2bdc2017-11-08 16:18:57 -060035 // Start watching for errors
36 addErrorWatch();
37
Chris Caina8857c52021-01-27 11:53:05 -060038 // Reset last OCC state
39 lastState = 0;
40
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053041 // Call into Manager to let know that we have bound
Edward A. James9fd2bdc2017-11-08 16:18:57 -060042 if (this->callBack)
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053043 {
44 this->callBack(value);
Edward A. James9fd2bdc2017-11-08 16:18:57 -060045 }
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053046 }
47 else
48 {
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053049 // Call into Manager to let know that we will unbind.
Edward A. James9fd2bdc2017-11-08 16:18:57 -060050 if (this->callBack)
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053051 {
52 this->callBack(value);
Edward A. James9fd2bdc2017-11-08 16:18:57 -060053 }
54
Chris Caina7b74dc2021-11-10 17:03:43 -060055#ifdef POWER10
56 if (safeStateDelayTimer.isEnabled())
57 {
58 // stop safe delay timer
59 safeStateDelayTimer.setEnabled(false);
60 }
61#endif
62
Edward A. James9fd2bdc2017-11-08 16:18:57 -060063 // Stop watching for errors
64 removeErrorWatch();
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053065
66 // Do the unbind.
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053067 device.unBind();
68 }
69 }
Edward A. James5e177972017-10-25 15:50:31 -050070 else if (value && !device.bound())
71 {
72 // Existing error watch is on a dead file descriptor.
Edward A. James9fd2bdc2017-11-08 16:18:57 -060073 removeErrorWatch();
Edward A. James5e177972017-10-25 15:50:31 -050074
75 /*
76 * In it's constructor, Status checks Device::bound() to see if OCC is
77 * active or not.
78 * Device::bound() checks for occX-dev0 directory.
79 * We will lose occX-dev0 directories during FSI rescan.
80 * So, if we start this application (and construct Status), and then
81 * later do FSI rescan, we will end up with occActive = true and device
82 * NOT bound. Lets correct that situation here.
83 */
84 device.bind();
85
86 // Add error watch again
Edward A. James9fd2bdc2017-11-08 16:18:57 -060087 addErrorWatch();
Edward A. James5e177972017-10-25 15:50:31 -050088 }
Eddie James6d6d1b32019-04-22 10:45:08 -050089 else if (!value && device.bound())
90 {
91 removeErrorWatch();
92
93 // In the event that the application never receives the active signal
94 // even though the OCC is active (this can occur if the BMC is rebooted
95 // with the host on, since the initial OCC driver probe will discover
96 // the OCCs), this application needs to be able to unbind the device
97 // when we get the OCC inactive signal.
98 device.unBind();
99 }
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530100 return Base::Status::occActive(value);
101}
102
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530103// Callback handler when a device error is reported.
Eddie Jamescbad2192021-10-07 09:39:39 -0500104void Status::deviceError()
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530105{
Eddie Jamescbad2192021-10-07 09:39:39 -0500106 // This would deem OCC inactive
107 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530108
Eddie Jamescbad2192021-10-07 09:39:39 -0500109 // Reset the OCC
110 this->resetOCC();
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530111}
112
113// Sends message to host control command handler to reset OCC
114void Status::resetOCC()
115{
Chris Caina8857c52021-01-27 11:53:05 -0600116 log<level::INFO>(
117 fmt::format(">>Status::resetOCC() - requesting reset for OCC{}",
118 instance)
119 .c_str());
Tom Joseph00325232020-07-29 17:51:48 +0530120#ifdef PLDM
121 if (resetCallBack)
122 {
123 this->resetCallBack(instance);
124 }
125#else
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530126 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
127 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
128
129 // This will throw exception on failure
George Liuf3b75142021-06-10 11:22:50 +0800130 auto service = utils::getService(CONTROL_HOST_PATH, CONTROL_HOST_INTF);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530131
George Liuf3b75142021-06-10 11:22:50 +0800132 auto& bus = utils::getBus();
Gunnar Mills94df8c92018-09-14 14:50:03 -0500133 auto method = bus.new_method_call(service.c_str(), CONTROL_HOST_PATH,
134 CONTROL_HOST_INTF, "Execute");
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530135 // OCC Reset control command
Gunnar Mills94df8c92018-09-14 14:50:03 -0500136 method.append(convertForMessage(Control::Host::Command::OCCReset).c_str());
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530137
138 // OCC Sensor ID for callout reasons
Patrick Williamse0962702020-05-13 17:50:22 -0500139 method.append(std::variant<uint8_t>(std::get<0>(sensorMap.at(instance))));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530140 bus.call_noreply(method);
141 return;
Tom Joseph00325232020-07-29 17:51:48 +0530142#endif
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530143}
144
145// Handler called by Host control command handler to convey the
146// status of the executed command
147void Status::hostControlEvent(sdbusplus::message::message& msg)
148{
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530149 std::string cmdCompleted{};
150 std::string cmdStatus{};
151
152 msg.read(cmdCompleted, cmdStatus);
153
154 log<level::DEBUG>("Host control signal values",
Gunnar Mills94df8c92018-09-14 14:50:03 -0500155 entry("COMMAND=%s", cmdCompleted.c_str()),
156 entry("STATUS=%s", cmdStatus.c_str()));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530157
Gunnar Mills94df8c92018-09-14 14:50:03 -0500158 if (Control::Host::convertResultFromString(cmdStatus) !=
159 Control::Host::Result::Success)
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530160 {
Gunnar Mills94df8c92018-09-14 14:50:03 -0500161 if (Control::Host::convertCommandFromString(cmdCompleted) ==
162 Control::Host::Command::OCCReset)
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530163 {
Gunnar Mills85e65202018-04-08 15:01:54 -0500164 // Must be a Timeout. Log an Error trace
Alexander Filippov1d69e192019-03-21 18:12:07 +0300165 log<level::ERR>(
166 "Error resetting the OCC.", entry("PATH=%s", path.c_str()),
167 entry("SENSORID=0x%X", std::get<0>(sensorMap.at(instance))));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530168 }
169 }
170 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530171}
172
Chris Caina8857c52021-01-27 11:53:05 -0600173void Status::readOccState()
174{
175 unsigned int state;
176 const fs::path filename =
177 fs::path(DEV_PATH) /
178 fs::path(sysfsName + "." + std::to_string(instance + 1)) / "occ_state";
179
Chris Caina8857c52021-01-27 11:53:05 -0600180 std::ifstream file(filename, std::ios::in);
181 const int open_errno = errno;
182 if (file)
183 {
184 file >> state;
185 if (state != lastState)
186 {
187 // Trace OCC state changes
188 log<level::INFO>(
189 fmt::format("Status::readOccState: OCC{} state 0x{:02X}",
190 instance, state)
191 .c_str());
192 lastState = state;
Chris Cain78e86012021-03-04 16:15:31 -0600193
194#ifdef POWER10
Chris Cain17257672021-10-22 13:41:03 -0500195 if (OccState(state) == OccState::ACTIVE)
196 {
Chris Caina7b74dc2021-11-10 17:03:43 -0600197 if (device.master())
198 {
199 // Special processing by master OCC when it goes active
200 occsWentActive();
201 }
202
Chris Cain17257672021-10-22 13:41:03 -0500203 CmdStatus status = sendAmbient();
204 if (status != CmdStatus::SUCCESS)
205 {
206 log<level::ERR>(
207 fmt::format(
208 "readOccState: Sending Ambient failed with status {}",
209 status)
210 .c_str());
211 }
212 }
Chris Caina7b74dc2021-11-10 17:03:43 -0600213
214 if (OccState(state) == OccState::SAFE)
215 {
216 // start safe delay timer (before requesting reset)
217 using namespace std::literals::chrono_literals;
218 safeStateDelayTimer.restartOnce(60s);
219 }
220 else if (safeStateDelayTimer.isEnabled())
221 {
222 // stop safe delay timer (no longer in SAFE state)
223 safeStateDelayTimer.setEnabled(false);
224 }
Chris Cain78e86012021-03-04 16:15:31 -0600225#endif
Chris Caina8857c52021-01-27 11:53:05 -0600226 }
227 file.close();
228 }
229 else
230 {
231 // If not able to read, OCC may be offline
232 log<level::DEBUG>(
233 fmt::format("Status::readOccState: open failed (errno={})",
234 open_errno)
235 .c_str());
236 lastState = 0;
237 }
238}
239
Chris Cain78e86012021-03-04 16:15:31 -0600240#ifdef POWER10
241// Check if Hypervisor target is PowerVM
242bool Status::isPowerVM()
243{
244 using namespace open_power::occ::powermode;
245 namespace Hyper = sdbusplus::com::ibm::Host::server;
246 constexpr auto HYPE_PATH = "/com/ibm/host0/hypervisor";
247 constexpr auto HYPE_INTERFACE = "com.ibm.Host.Target";
248 constexpr auto HYPE_PROP = "Target";
249
250 bool powerVmTarget = false;
251
252 // This will throw exception on failure
253 auto& bus = utils::getBus();
254 auto service = utils::getService(HYPE_PATH, HYPE_INTERFACE);
255 auto method = bus.new_method_call(service.c_str(), HYPE_PATH,
256 "org.freedesktop.DBus.Properties", "Get");
257 method.append(HYPE_INTERFACE, HYPE_PROP);
258 auto reply = bus.call(method);
259
260 std::variant<std::string> hyperEntryValue;
261 reply.read(hyperEntryValue);
262 auto propVal = std::get<std::string>(hyperEntryValue);
263 if (Hyper::Target::convertHypervisorFromString(propVal) ==
264 Hyper::Target::Hypervisor::PowerVM)
265 {
266 powerVmTarget = true;
267 }
268
269 log<level::DEBUG>(
270 fmt::format("Status::isPowerVM returning {}", powerVmTarget).c_str());
271
272 return powerVmTarget;
273}
274
275// Get the requested power mode
276SysPwrMode Status::getMode()
277{
278 using namespace open_power::occ::powermode;
279 SysPwrMode pmode = SysPwrMode::NO_CHANGE;
280
281 // This will throw exception on failure
282 auto& bus = utils::getBus();
283 auto service = utils::getService(PMODE_PATH, PMODE_INTERFACE);
284 auto method = bus.new_method_call(service.c_str(), PMODE_PATH,
285 "org.freedesktop.DBus.Properties", "Get");
286 method.append(PMODE_INTERFACE, POWER_MODE_PROP);
287 auto reply = bus.call(method);
288
289 std::variant<std::string> stateEntryValue;
290 reply.read(stateEntryValue);
291 auto propVal = std::get<std::string>(stateEntryValue);
292 pmode = powermode::convertStringToMode(propVal);
293
294 log<level::DEBUG>(
295 fmt::format("Status::getMode returning {}", pmode).c_str());
296
297 return pmode;
298}
299
Chris Cain1d51da22021-09-21 14:13:41 -0500300// Get the requested power mode
301bool Status::getIPSParms(uint8_t& enterUtil, uint16_t& enterTime,
302 uint8_t& exitUtil, uint16_t& exitTime)
303{
304 using namespace open_power::occ::powermode;
305 // Defaults:
306 bool ipsEnabled = false; // Disabled
307 enterUtil = 8; // Enter Utilization (8%)
308 enterTime = 240; // Enter Delay Time (240s)
309 exitUtil = 12; // Exit Utilization (12%)
310 exitTime = 10; // Exit Delay Time (10s)
311
312 std::map<std::string, std::variant<bool, uint8_t, uint64_t>>
313 ipsProperties{};
314
315 // Get all IPS properties from DBus
316 try
317 {
318 auto& bus = utils::getBus();
319 auto service = utils::getService(PIPS_PATH, PIPS_INTERFACE);
320 auto method =
321 bus.new_method_call(service.c_str(), PIPS_PATH,
322 "org.freedesktop.DBus.Properties", "GetAll");
323 method.append(PIPS_INTERFACE);
324 auto reply = bus.call(method);
325 reply.read(ipsProperties);
326 }
327 catch (const sdbusplus::exception::exception& e)
328 {
329 log<level::ERR>(
330 fmt::format(
331 "Unable to read Idle Power Saver parameters so it will be disabled: {}",
332 e.what())
333 .c_str());
334 return ipsEnabled;
335 }
336
337 auto ipsEntry = ipsProperties.find(IPS_ENABLED_PROP);
338 if (ipsEntry != ipsProperties.end())
339 {
340 ipsEnabled = std::get<bool>(ipsEntry->second);
341 }
342 else
343 {
344 log<level::ERR>(
345 fmt::format("Status::getIPSParms could not find property: {}",
346 IPS_ENABLED_PROP)
347 .c_str());
348 }
349
350 ipsEntry = ipsProperties.find(IPS_ENTER_UTIL);
351 if (ipsEntry != ipsProperties.end())
352 {
353 enterUtil = std::get<uint8_t>(ipsEntry->second);
354 }
355 else
356 {
357 log<level::ERR>(
358 fmt::format("Status::getIPSParms could not find property: {}",
359 IPS_ENTER_UTIL)
360 .c_str());
361 }
362
363 ipsEntry = ipsProperties.find(IPS_ENTER_TIME);
364 if (ipsEntry != ipsProperties.end())
365 {
366 std::chrono::milliseconds ms(std::get<uint64_t>(ipsEntry->second));
367 enterTime =
368 std::chrono::duration_cast<std::chrono::seconds>(ms).count();
369 }
370 else
371 {
372 log<level::ERR>(
373 fmt::format("Status::getIPSParms could not find property: {}",
374 IPS_ENTER_TIME)
375 .c_str());
376 }
377
378 ipsEntry = ipsProperties.find(IPS_EXIT_UTIL);
379 if (ipsEntry != ipsProperties.end())
380 {
381 exitUtil = std::get<uint8_t>(ipsEntry->second);
382 }
383 else
384 {
385 log<level::ERR>(
386 fmt::format("Status::getIPSParms could not find property: {}",
387 IPS_EXIT_UTIL)
388 .c_str());
389 }
390
391 ipsEntry = ipsProperties.find(IPS_EXIT_TIME);
392 if (ipsEntry != ipsProperties.end())
393 {
394 std::chrono::milliseconds ms(std::get<uint64_t>(ipsEntry->second));
395 exitTime = std::chrono::duration_cast<std::chrono::seconds>(ms).count();
396 }
397 else
398 {
399 log<level::ERR>(
400 fmt::format("Status::getIPSParms could not find property: {}",
401 IPS_EXIT_TIME)
402 .c_str());
403 }
404
405 if (enterUtil > exitUtil)
406 {
407 log<level::ERR>(
408 fmt::format(
409 "ERROR: Idle Power Saver Enter Utilization ({}%) is > Exit Utilization ({}%) - using Exit for both",
410 enterUtil, exitUtil)
411 .c_str());
412 enterUtil = exitUtil;
413 }
414
415 return ipsEnabled;
416}
417
Chris Cain78e86012021-03-04 16:15:31 -0600418// Special processing that needs to happen once the OCCs change to ACTIVE state
419void Status::occsWentActive()
420{
421 CmdStatus status = CmdStatus::SUCCESS;
422
423 status = sendModeChange();
424 if (status != CmdStatus::SUCCESS)
425 {
George Liub5ca1012021-09-10 12:53:11 +0800426 log<level::ERR>(
427 fmt::format(
428 "Status::occsWentActive: OCC mode change failed with status {}",
429 status)
430 .c_str());
Chris Cain78e86012021-03-04 16:15:31 -0600431 }
432
433 status = sendIpsData();
434 if (status != CmdStatus::SUCCESS)
435 {
436 log<level::ERR>(
437 fmt::format(
George Liub5ca1012021-09-10 12:53:11 +0800438 "Status::occsWentActive: Sending Idle Power Save Config data failed with status {}",
Chris Cain78e86012021-03-04 16:15:31 -0600439 status)
440 .c_str());
441 }
442}
443
444// Send mode change request to the master OCC
445CmdStatus Status::sendModeChange()
446{
447 CmdStatus status = CmdStatus::FAILURE;
448
449 if (!device.master())
450 {
451 log<level::ERR>(
George Liub5ca1012021-09-10 12:53:11 +0800452 fmt::format(
453 "Status::sendModeChange: MODE CHANGE does not get sent to slave OCC{}",
454 instance)
Chris Cain78e86012021-03-04 16:15:31 -0600455 .c_str());
456 return status;
457 }
458 if (!isPowerVM())
459 {
460 // Mode change is only supported on PowerVM systems
George Liub5ca1012021-09-10 12:53:11 +0800461 log<level::DEBUG>(
462 "Status::sendModeChange: MODE CHANGE does not get sent on non-PowerVM systems");
Chris Cain78e86012021-03-04 16:15:31 -0600463 return CmdStatus::SUCCESS;
464 }
465
466 const SysPwrMode newMode = getMode();
467
468 if (VALID_POWER_MODE_SETTING(newMode))
469 {
470 std::vector<std::uint8_t> cmd, rsp;
Chris Cain1d51da22021-09-21 14:13:41 -0500471 cmd.reserve(9);
Chris Cain78e86012021-03-04 16:15:31 -0600472 cmd.push_back(uint8_t(CmdType::SET_MODE_AND_STATE));
473 cmd.push_back(0x00); // Data Length (2 bytes)
474 cmd.push_back(0x06);
475 cmd.push_back(0x30); // Data (Version)
476 cmd.push_back(uint8_t(OccState::NO_CHANGE));
477 cmd.push_back(uint8_t(newMode));
478 cmd.push_back(0x00); // Mode Data (Freq Point)
479 cmd.push_back(0x00); //
480 cmd.push_back(0x00); // reserved
George Liub5ca1012021-09-10 12:53:11 +0800481 log<level::INFO>(
482 fmt::format(
483 "Status::sendModeChange: SET_MODE({}) command to OCC{} ({} bytes)",
484 newMode, instance, cmd.size())
485 .c_str());
Chris Cain78e86012021-03-04 16:15:31 -0600486 status = occCmd.send(cmd, rsp);
487 if (status == CmdStatus::SUCCESS)
488 {
489 if (rsp.size() == 5)
490 {
Chris Cain1d51da22021-09-21 14:13:41 -0500491 if (RspStatus::SUCCESS != RspStatus(rsp[2]))
Chris Cain78e86012021-03-04 16:15:31 -0600492 {
493 log<level::ERR>(
George Liub5ca1012021-09-10 12:53:11 +0800494 fmt::format(
495 "Status::sendModeChange: SET MODE failed with status 0x{:02X}",
496 rsp[2])
Chris Cain78e86012021-03-04 16:15:31 -0600497 .c_str());
Chris Cain1d51da22021-09-21 14:13:41 -0500498 dump_hex(rsp);
499 status = CmdStatus::FAILURE;
Chris Cain78e86012021-03-04 16:15:31 -0600500 }
501 }
502 else
503 {
504 log<level::ERR>(
505 "Status::sendModeChange: INVALID SET MODE response");
506 dump_hex(rsp);
Chris Cain1d51da22021-09-21 14:13:41 -0500507 status = CmdStatus::FAILURE;
Chris Cain78e86012021-03-04 16:15:31 -0600508 }
509 }
510 else
511 {
512 if (status == CmdStatus::OPEN_FAILURE)
513 {
Chris Cain1d51da22021-09-21 14:13:41 -0500514 log<level::INFO>("Status::sendModeChange: OCC not active yet");
515 status = CmdStatus::SUCCESS;
Chris Cain78e86012021-03-04 16:15:31 -0600516 }
517 else
518 {
519 log<level::ERR>("Status::sendModeChange: SET_MODE FAILED!");
520 }
521 }
522 }
523 else
524 {
525 log<level::ERR>(
526 fmt::format(
527 "Status::sendModeChange: Unable to set power mode to {}",
528 newMode)
529 .c_str());
Chris Cain1d51da22021-09-21 14:13:41 -0500530 status = CmdStatus::FAILURE;
Chris Cain78e86012021-03-04 16:15:31 -0600531 }
532
533 return status;
534}
535
536// Send Idle Power Saver config data to the master OCC
537CmdStatus Status::sendIpsData()
538{
539 CmdStatus status = CmdStatus::FAILURE;
540
541 if (!device.master())
542 {
543 log<level::ERR>(
George Liub5ca1012021-09-10 12:53:11 +0800544 fmt::format(
545 "Status::sendIpsData: SET_CFG_DATA[IPS] does not get sent to slave OCC{}",
546 instance)
Chris Cain78e86012021-03-04 16:15:31 -0600547 .c_str());
548 return status;
549 }
550 if (!isPowerVM())
551 {
552 // Idle Power Saver data is only supported on PowerVM systems
George Liub5ca1012021-09-10 12:53:11 +0800553 log<level::DEBUG>(
554 "Status::sendIpsData: SET_CFG_DATA[IPS] does not get sent on non-PowerVM systems");
Chris Cain78e86012021-03-04 16:15:31 -0600555 return CmdStatus::SUCCESS;
556 }
557
Chris Cain1d51da22021-09-21 14:13:41 -0500558 uint8_t enterUtil, exitUtil;
559 uint16_t enterTime, exitTime;
560 const bool ipsEnabled =
561 getIPSParms(enterUtil, enterTime, exitUtil, exitTime);
562
George Liub5ca1012021-09-10 12:53:11 +0800563 log<level::INFO>(
564 fmt::format(
Chris Cain1d51da22021-09-21 14:13:41 -0500565 "Idle Power Saver Parameters: enabled:{}, enter:{}%/{}s, exit:{}%/{}s",
566 ipsEnabled, enterUtil, enterTime, exitUtil, exitTime)
George Liub5ca1012021-09-10 12:53:11 +0800567 .c_str());
Chris Cain1d51da22021-09-21 14:13:41 -0500568
569 std::vector<std::uint8_t> cmd, rsp;
570 cmd.reserve(12);
571 cmd.push_back(uint8_t(CmdType::SET_CONFIG_DATA));
572 cmd.push_back(0x00); // Data Length (2 bytes)
573 cmd.push_back(0x09); //
574 cmd.push_back(0x11); // Config Format: IPS Settings
575 cmd.push_back(0x00); // Version
576 cmd.push_back(ipsEnabled ? 1 : 0); // IPS Enable
577 cmd.push_back(enterTime >> 8); // Enter Delay Time
578 cmd.push_back(enterTime & 0xFF); //
579 cmd.push_back(enterUtil); // Enter Utilization
580 cmd.push_back(exitTime >> 8); // Exit Delay Time
581 cmd.push_back(exitTime & 0xFF); //
582 cmd.push_back(exitUtil); // Exit Utilization
583 log<level::INFO>(fmt::format("Status::sendIpsData: SET_CFG_DATA[IPS] "
584 "command to OCC{} ({} bytes)",
585 instance, cmd.size())
586 .c_str());
Chris Cain78e86012021-03-04 16:15:31 -0600587 status = occCmd.send(cmd, rsp);
588 if (status == CmdStatus::SUCCESS)
589 {
590 if (rsp.size() == 5)
591 {
Chris Cain1d51da22021-09-21 14:13:41 -0500592 if (RspStatus::SUCCESS != RspStatus(rsp[2]))
Chris Cain78e86012021-03-04 16:15:31 -0600593 {
594 log<level::ERR>(
George Liub5ca1012021-09-10 12:53:11 +0800595 fmt::format(
596 "Status::sendIpsData: SET_CFG_DATA[IPS] failed with status 0x{:02X}",
597 rsp[2])
Chris Cain78e86012021-03-04 16:15:31 -0600598 .c_str());
Chris Cain1d51da22021-09-21 14:13:41 -0500599 dump_hex(rsp);
600 status = CmdStatus::FAILURE;
Chris Cain78e86012021-03-04 16:15:31 -0600601 }
602 }
603 else
604 {
605 log<level::ERR>(
606 "Status::sendIpsData: INVALID SET_CFG_DATA[IPS] response");
607 dump_hex(rsp);
Chris Cain1d51da22021-09-21 14:13:41 -0500608 status = CmdStatus::FAILURE;
Chris Cain78e86012021-03-04 16:15:31 -0600609 }
610 }
611 else
612 {
613 if (status == CmdStatus::OPEN_FAILURE)
614 {
Chris Cain1d51da22021-09-21 14:13:41 -0500615 log<level::INFO>("Status::sendIpsData: OCC not active yet");
616 status = CmdStatus::SUCCESS;
Chris Cain78e86012021-03-04 16:15:31 -0600617 }
618 else
619 {
620 log<level::ERR>("Status::sendIpsData: SET_CFG_DATA[IPS] FAILED!");
621 }
622 }
623
624 return status;
625}
626
Chris Cain17257672021-10-22 13:41:03 -0500627// Send Ambient and Altitude to the OCC
628CmdStatus Status::sendAmbient(const uint8_t inTemp, const uint16_t inAltitude)
629{
630 CmdStatus status = CmdStatus::FAILURE;
631 bool ambientValid = true;
632 uint8_t ambientTemp = inTemp;
633 uint16_t altitude = inAltitude;
634
635 if (ambientTemp == 0xFF)
636 {
637 // Get latest readings from manager
638 manager.getAmbientData(ambientValid, ambientTemp, altitude);
639 log<level::DEBUG>(
640 fmt::format("sendAmbient: valid: {}, Ambient: {}C, altitude: {}m",
641 ambientValid, ambientTemp, altitude)
642 .c_str());
643 }
644
645 std::vector<std::uint8_t> cmd, rsp;
646 cmd.reserve(11);
647 cmd.push_back(uint8_t(CmdType::SEND_AMBIENT));
648 cmd.push_back(0x00); // Data Length (2 bytes)
649 cmd.push_back(0x08); //
650 cmd.push_back(0x00); // Version
651 cmd.push_back(ambientValid ? 0 : 0xFF); // Ambient Status
652 cmd.push_back(ambientTemp); // Ambient Temperature
653 cmd.push_back(altitude >> 8); // Altitude in meters (2 bytes)
654 cmd.push_back(altitude & 0xFF); //
655 cmd.push_back(0x00); // Reserved (3 bytes)
656 cmd.push_back(0x00);
657 cmd.push_back(0x00);
658 log<level::DEBUG>(fmt::format("sendAmbient: SEND_AMBIENT "
659 "command to OCC{} ({} bytes)",
660 instance, cmd.size())
661 .c_str());
662 status = occCmd.send(cmd, rsp);
663 if (status == CmdStatus::SUCCESS)
664 {
665 if (rsp.size() == 5)
666 {
667 if (RspStatus::SUCCESS != RspStatus(rsp[2]))
668 {
669 log<level::ERR>(
670 fmt::format(
671 "sendAmbient: SEND_AMBIENT failed with status 0x{:02X}",
672 rsp[2])
673 .c_str());
674 dump_hex(rsp);
675 status = CmdStatus::FAILURE;
676 }
677 }
678 else
679 {
680 log<level::ERR>("sendAmbient: INVALID SEND_AMBIENT response");
681 dump_hex(rsp);
682 status = CmdStatus::FAILURE;
683 }
684 }
685 else
686 {
687 if (status == CmdStatus::OPEN_FAILURE)
688 {
689 // OCC not active yet
690 status = CmdStatus::SUCCESS;
691 }
692 else
693 {
694 log<level::ERR>("sendAmbient: SEND_AMBIENT FAILED!");
695 }
696 }
697
698 return status;
699}
Chris Caina7b74dc2021-11-10 17:03:43 -0600700
701// Called when safe timer expires to determine if OCCs need to be reset
702void Status::safeStateDelayExpired()
703{
704 if (this->occActive())
705 {
706 log<level::INFO>(
707 fmt::format(
708 "safeStateDelayExpired: OCC{} is in SAFE state, requesting reset",
709 instance)
710 .c_str());
711 // Disable and reset to try recovering
712 deviceError();
713 }
714}
Chris Cain78e86012021-03-04 16:15:31 -0600715#endif // POWER10
716
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530717} // namespace occ
718} // namespace open_power