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