Patrick Venture | 02261c0 | 2018-10-31 15:16:23 -0700 | [diff] [blame] | 1 | #include <config.h> |
| 2 | |
Vishwanatha Subbanna | 0765506 | 2017-07-14 20:31:57 +0530 | [diff] [blame] | 3 | #include <chrono> |
| 4 | #include <functional> |
Vishwanatha Subbanna | 0765506 | 2017-07-14 20:31:57 +0530 | [diff] [blame] | 5 | #include <host-interface.hpp> |
William A. Kennington III | 822eaf6 | 2019-02-12 15:20:06 -0800 | [diff] [blame] | 6 | #include <ipmid-host/cmd-utils.hpp> |
| 7 | #include <ipmid-host/cmd.hpp> |
Patrick Venture | 02261c0 | 2018-10-31 15:16:23 -0700 | [diff] [blame] | 8 | #include <oemhandler.hpp> |
| 9 | #include <phosphor-logging/log.hpp> |
Vishwanatha Subbanna | 0765506 | 2017-07-14 20:31:57 +0530 | [diff] [blame] | 10 | namespace open_power |
| 11 | { |
| 12 | namespace host |
| 13 | { |
| 14 | namespace command |
| 15 | { |
| 16 | |
| 17 | // IPMI command |
| 18 | // https://github.com/openbmc/openbmc/issues/2082 for handling |
| 19 | // Non-OEM commands that need to send SMS_ATN |
| 20 | using OEMCmd = uint8_t; |
| 21 | |
| 22 | // Map of IPMI OEM command to its equivalent interface command. |
| 23 | // This is needed when invoking the callback handler to indicate |
| 24 | // the status of the executed command. |
| 25 | static const std::map<OEMCmd, Host::Command> intfCommand = { |
Patrick Venture | 02261c0 | 2018-10-31 15:16:23 -0700 | [diff] [blame] | 26 | {IPMI_CMD_OCC_RESET, Base::Host::Command::OCCReset}}; |
Vishwanatha Subbanna | 0765506 | 2017-07-14 20:31:57 +0530 | [diff] [blame] | 27 | |
| 28 | // Called at user request |
Patrick Williams | 6195010 | 2020-05-13 17:49:58 -0500 | [diff] [blame] | 29 | void Host::execute(Base::Host::Command command, std::variant<uint8_t> data) |
Vishwanatha Subbanna | 0765506 | 2017-07-14 20:31:57 +0530 | [diff] [blame] | 30 | { |
| 31 | using namespace phosphor::logging; |
| 32 | |
Patrick Venture | 02261c0 | 2018-10-31 15:16:23 -0700 | [diff] [blame] | 33 | log<level::INFO>( |
| 34 | "Pushing cmd on to queue", |
| 35 | entry("CONTROL_HOST_CMD=%s", convertForMessage(command).c_str())); |
Vishwanatha Subbanna | 0765506 | 2017-07-14 20:31:57 +0530 | [diff] [blame] | 36 | |
| 37 | // If the command is OCCReset, then all we need is just sensor ID |
| 38 | // This is the only command that is being used now. |
| 39 | if (command == Base::Host::Command::OCCReset) |
| 40 | { |
Patrick Williams | 12f9669 | 2020-05-13 11:40:26 -0500 | [diff] [blame] | 41 | auto sensorID = std::get<uint8_t>(data); |
Vishwanatha Subbanna | 0765506 | 2017-07-14 20:31:57 +0530 | [diff] [blame] | 42 | |
| 43 | auto cmd = std::make_tuple(std::make_pair(IPMI_CMD_OCC_RESET, sensorID), |
Patrick Venture | 02261c0 | 2018-10-31 15:16:23 -0700 | [diff] [blame] | 44 | std::bind(&Host::commandStatusHandler, this, |
| 45 | std::placeholders::_1, |
| 46 | std::placeholders::_2)); |
Vishwanatha Subbanna | 0765506 | 2017-07-14 20:31:57 +0530 | [diff] [blame] | 47 | |
| 48 | return ipmid_send_cmd_to_host(std::move(cmd)); |
| 49 | } |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // Called into by Command Manager |
| 54 | void Host::commandStatusHandler(IpmiCmdData cmd, bool status) |
| 55 | { |
| 56 | // Need to convert <cmd> to the equivalent one mentioned in spec |
| 57 | auto value = status ? Result::Success : Result::Failure; |
| 58 | |
| 59 | // Fire a signal |
| 60 | this->commandComplete(intfCommand.at(std::get<0>(cmd)), value); |
| 61 | } |
| 62 | |
| 63 | } // namespace command |
| 64 | } // namespace host |
Patrick Venture | 02261c0 | 2018-10-31 15:16:23 -0700 | [diff] [blame] | 65 | } // namespace open_power |