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