Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 1 | #include "config.h" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 2 | |
| 3 | #include "occ_pass_through.hpp" |
| 4 | |
| 5 | #include "elog-errors.hpp" |
| 6 | |
| 7 | #include <errno.h> |
| 8 | #include <fcntl.h> |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 9 | #include <fmt/core.h> |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 10 | #include <unistd.h> |
| 11 | |
| 12 | #include <algorithm> |
| 13 | #include <memory> |
| 14 | #include <org/open_power/OCC/Device/error.hpp> |
| 15 | #include <phosphor-logging/elog.hpp> |
| 16 | #include <phosphor-logging/log.hpp> |
| 17 | #include <string> |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 18 | |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 19 | namespace open_power |
| 20 | { |
| 21 | namespace occ |
| 22 | { |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 23 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 24 | PassThrough::PassThrough(sdbusplus::bus::bus& bus, const char* path) : |
| 25 | Iface(bus, path), path(path), |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 26 | devicePath(OCC_DEV_PATH + std::to_string((this->path.back() - '0') + 1)), |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 27 | occInstance(this->path.back() - '0'), |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 28 | activeStatusSignal( |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 29 | bus, sdbusRule::propertiesChanged(path, "org.open_power.OCC.Status"), |
| 30 | std::bind(std::mem_fn(&PassThrough::activeStatusEvent), this, |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 31 | std::placeholders::_1)), |
| 32 | occCmd(occInstance, bus, path) |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 33 | { |
Vishwanatha Subbanna | 38b08d7 | 2017-04-14 18:12:14 +0530 | [diff] [blame] | 34 | // Nothing to do. |
| 35 | } |
| 36 | |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 37 | std::vector<int32_t> PassThrough::send(std::vector<int32_t> command) |
| 38 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 39 | std::vector<int32_t> response{}; |
Vishwanatha Subbanna | 67d50ad | 2017-04-17 23:21:52 +0530 | [diff] [blame] | 40 | |
Vishwanatha Subbanna | 7d700e2 | 2017-05-19 19:58:01 +0530 | [diff] [blame] | 41 | // OCC only understands [bytes] so need array of bytes. Doing this |
| 42 | // because rest-server currently treats all int* as 32 bit integer. |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 43 | std::vector<uint8_t> cmdInBytes, rsp; |
Vishwanatha Subbanna | 7d700e2 | 2017-05-19 19:58:01 +0530 | [diff] [blame] | 44 | cmdInBytes.resize(command.size()); |
| 45 | |
| 46 | // Populate uint8_t version of vector. |
| 47 | std::transform(command.begin(), command.end(), cmdInBytes.begin(), |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 48 | [](decltype(cmdInBytes)::value_type x) { return x; }); |
Vishwanatha Subbanna | 7d700e2 | 2017-05-19 19:58:01 +0530 | [diff] [blame] | 49 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 50 | rsp = send(cmdInBytes); |
Vishwanatha Subbanna | 67d50ad | 2017-04-17 23:21:52 +0530 | [diff] [blame] | 51 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 52 | response.resize(rsp.size()); |
| 53 | std::transform(rsp.begin(), rsp.end(), response.begin(), |
| 54 | [](decltype(response)::value_type x) { return x; }); |
| 55 | |
| 56 | return response; |
| 57 | } |
| 58 | |
| 59 | std::vector<uint8_t> PassThrough::send(std::vector<uint8_t> command) |
| 60 | { |
| 61 | using namespace phosphor::logging; |
| 62 | using namespace sdbusplus::org::open_power::OCC::Device::Error; |
| 63 | |
| 64 | std::vector<uint8_t> response{}; |
| 65 | |
| 66 | log<level::DEBUG>( |
| 67 | fmt::format("PassThrough::send() Sending 0x{:02X} command to OCC{}", |
| 68 | command.front(), occInstance) |
| 69 | .c_str()); |
| 70 | CmdStatus status = occCmd.send(command, response); |
| 71 | if (status == CmdStatus::SUCCESS) |
Vishwanatha Subbanna | 67d50ad | 2017-04-17 23:21:52 +0530 | [diff] [blame] | 72 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 73 | if (response.size() >= 5) |
Vishwanatha Subbanna | 67d50ad | 2017-04-17 23:21:52 +0530 | [diff] [blame] | 74 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 75 | log<level::DEBUG>(fmt::format("PassThrough::send() " |
| 76 | "response had {} bytes", |
| 77 | response.size()) |
| 78 | .c_str()); |
Vishwanatha Subbanna | 67d50ad | 2017-04-17 23:21:52 +0530 | [diff] [blame] | 79 | } |
| 80 | else |
| 81 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 82 | log<level::ERR>("PassThrough::send() Invalid OCC response"); |
| 83 | dump_hex(response); |
Vishwanatha Subbanna | 67d50ad | 2017-04-17 23:21:52 +0530 | [diff] [blame] | 84 | } |
| 85 | } |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 86 | else |
| 87 | { |
| 88 | if (status == CmdStatus::OPEN_FAILURE) |
| 89 | { |
| 90 | log<level::WARNING>("PassThrough::send() - OCC not active yet"); |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | log<level::ERR>("PassThrough::send() - OCC command failed!"); |
| 95 | } |
| 96 | } |
Eddie James | 4f4712d | 2018-06-21 15:57:02 -0500 | [diff] [blame] | 97 | |
Vishwanatha Subbanna | 67d50ad | 2017-04-17 23:21:52 +0530 | [diff] [blame] | 98 | return response; |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 99 | } |
| 100 | |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 101 | // Called at OCC Status change signal |
| 102 | void PassThrough::activeStatusEvent(sdbusplus::message::message& msg) |
| 103 | { |
| 104 | std::string statusInterface; |
Patrick Williams | e096270 | 2020-05-13 17:50:22 -0500 | [diff] [blame] | 105 | std::map<std::string, std::variant<bool>> msgData; |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 106 | msg.read(statusInterface, msgData); |
| 107 | |
| 108 | auto propertyMap = msgData.find("OccActive"); |
| 109 | if (propertyMap != msgData.end()) |
| 110 | { |
| 111 | // Extract the OccActive property |
Patrick Williams | 305ff8b | 2020-05-13 11:17:39 -0500 | [diff] [blame] | 112 | if (std::get<bool>(propertyMap->second)) |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 113 | { |
Eddie James | 4f4712d | 2018-06-21 15:57:02 -0500 | [diff] [blame] | 114 | occActive = true; |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 115 | } |
| 116 | else |
| 117 | { |
Eddie James | 4f4712d | 2018-06-21 15:57:02 -0500 | [diff] [blame] | 118 | occActive = false; |
Vishwanatha Subbanna | 3e5422e | 2017-08-10 18:25:26 +0530 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | return; |
| 122 | } |
| 123 | |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 124 | } // namespace occ |
| 125 | } // namespace open_power |