blob: 08dfdd92ce72b474f3343021f531149f1633f441 [file] [log] [blame]
Patrick Venture02261c02018-10-31 15:16:23 -07001#include <config.h>
2
Vishwanatha Subbanna07655062017-07-14 20:31:57 +05303#include <host-interface.hpp>
William A. Kennington III822eaf62019-02-12 15:20:06 -08004#include <ipmid-host/cmd-utils.hpp>
5#include <ipmid-host/cmd.hpp>
Patrick Venture02261c02018-10-31 15:16:23 -07006#include <oemhandler.hpp>
7#include <phosphor-logging/log.hpp>
Patrick Williams490126f2023-05-10 07:50:22 -05008
9#include <chrono>
10#include <functional>
Vishwanatha Subbanna07655062017-07-14 20:31:57 +053011namespace open_power
12{
13namespace host
14{
15namespace command
16{
17
18// IPMI command
19// https://github.com/openbmc/openbmc/issues/2082 for handling
20// Non-OEM commands that need to send SMS_ATN
21using OEMCmd = uint8_t;
22
23// Map of IPMI OEM command to its equivalent interface command.
24// This is needed when invoking the callback handler to indicate
25// the status of the executed command.
26static const std::map<OEMCmd, Host::Command> intfCommand = {
Patrick Venture02261c02018-10-31 15:16:23 -070027 {IPMI_CMD_OCC_RESET, Base::Host::Command::OCCReset}};
Vishwanatha Subbanna07655062017-07-14 20:31:57 +053028
29// Called at user request
Patrick Williams61950102020-05-13 17:49:58 -050030void Host::execute(Base::Host::Command command, std::variant<uint8_t> data)
Vishwanatha Subbanna07655062017-07-14 20:31:57 +053031{
32 using namespace phosphor::logging;
33
Patrick Venture02261c02018-10-31 15:16:23 -070034 log<level::INFO>(
35 "Pushing cmd on to queue",
36 entry("CONTROL_HOST_CMD=%s", convertForMessage(command).c_str()));
Vishwanatha Subbanna07655062017-07-14 20:31:57 +053037
38 // If the command is OCCReset, then all we need is just sensor ID
39 // This is the only command that is being used now.
40 if (command == Base::Host::Command::OCCReset)
41 {
Patrick Williams12f96692020-05-13 11:40:26 -050042 auto sensorID = std::get<uint8_t>(data);
Vishwanatha Subbanna07655062017-07-14 20:31:57 +053043
Patrick Williamsd9c74ac2024-08-16 15:20:03 -040044 auto cmd = std::make_tuple(
45 std::make_pair(IPMI_CMD_OCC_RESET, sensorID),
46 std::bind(&Host::commandStatusHandler, this, std::placeholders::_1,
47 std::placeholders::_2));
Vishwanatha Subbanna07655062017-07-14 20:31:57 +053048
49 return ipmid_send_cmd_to_host(std::move(cmd));
50 }
51 return;
52}
53
54// Called into by Command Manager
55void Host::commandStatusHandler(IpmiCmdData cmd, bool status)
56{
57 // Need to convert <cmd> to the equivalent one mentioned in spec
58 auto value = status ? Result::Success : Result::Failure;
59
60 // Fire a signal
61 this->commandComplete(intfCommand.at(std::get<0>(cmd)), value);
62}
63
64} // namespace command
65} // namespace host
Patrick Venture02261c02018-10-31 15:16:23 -070066} // namespace open_power