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