blob: a53cba442a0239c8b71497537de9fb3e9d296226 [file] [log] [blame]
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +05301#include "config.h"
Gunnar Mills94df8c92018-09-14 14:50:03 -05002
3#include "occ_pass_through.hpp"
4
5#include "elog-errors.hpp"
6
7#include <errno.h>
8#include <fcntl.h>
Chris Caina8857c52021-01-27 11:53:05 -06009#include <fmt/core.h>
Gunnar Mills94df8c92018-09-14 14:50:03 -050010#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 Caina8857c52021-01-27 11:53:05 -060018
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050019namespace open_power
20{
21namespace occ
22{
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050023
George Liuf3b75142021-06-10 11:22:50 +080024PassThrough::PassThrough(const char* path) :
25 Iface(utils::getBus(), path), path(path),
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053026 devicePath(OCC_DEV_PATH + std::to_string((this->path.back() - '0') + 1)),
Chris Caina8857c52021-01-27 11:53:05 -060027 occInstance(this->path.back() - '0'),
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +053028 activeStatusSignal(
George Liuf3b75142021-06-10 11:22:50 +080029 utils::getBus(),
30 sdbusRule::propertiesChanged(path, "org.open_power.OCC.Status"),
Gunnar Mills94df8c92018-09-14 14:50:03 -050031 std::bind(std::mem_fn(&PassThrough::activeStatusEvent), this,
Chris Caina8857c52021-01-27 11:53:05 -060032 std::placeholders::_1)),
George Liuf3b75142021-06-10 11:22:50 +080033 occCmd(occInstance, path)
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050034{
Vishwanatha Subbanna38b08d72017-04-14 18:12:14 +053035 // Nothing to do.
36}
37
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -050038std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
39{
Gunnar Mills94df8c92018-09-14 14:50:03 -050040 std::vector<int32_t> response{};
Vishwanatha Subbanna67d50ad2017-04-17 23:21:52 +053041
Vishwanatha Subbanna7d700e22017-05-19 19:58:01 +053042 // OCC only understands [bytes] so need array of bytes. Doing this
43 // because rest-server currently treats all int* as 32 bit integer.
Chris Caina8857c52021-01-27 11:53:05 -060044 std::vector<uint8_t> cmdInBytes, rsp;
Vishwanatha Subbanna7d700e22017-05-19 19:58:01 +053045 cmdInBytes.resize(command.size());
46
47 // Populate uint8_t version of vector.
48 std::transform(command.begin(), command.end(), cmdInBytes.begin(),
Gunnar Mills94df8c92018-09-14 14:50:03 -050049 [](decltype(cmdInBytes)::value_type x) { return x; });
Vishwanatha Subbanna7d700e22017-05-19 19:58:01 +053050
Chris Caina8857c52021-01-27 11:53:05 -060051 rsp = send(cmdInBytes);
Vishwanatha Subbanna67d50ad2017-04-17 23:21:52 +053052
Chris Caina8857c52021-01-27 11:53:05 -060053 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
60std::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 Subbanna67d50ad2017-04-17 23:21:52 +053073 {
Chris Caina8857c52021-01-27 11:53:05 -060074 if (response.size() >= 5)
Vishwanatha Subbanna67d50ad2017-04-17 23:21:52 +053075 {
Chris Caina8857c52021-01-27 11:53:05 -060076 log<level::DEBUG>(fmt::format("PassThrough::send() "
77 "response had {} bytes",
78 response.size())
79 .c_str());
Vishwanatha Subbanna67d50ad2017-04-17 23:21:52 +053080 }
81 else
82 {
Chris Caina8857c52021-01-27 11:53:05 -060083 log<level::ERR>("PassThrough::send() Invalid OCC response");
84 dump_hex(response);
Vishwanatha Subbanna67d50ad2017-04-17 23:21:52 +053085 }
86 }
Chris Caina8857c52021-01-27 11:53:05 -060087 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 James4f4712d2018-06-21 15:57:02 -050098
Vishwanatha Subbanna67d50ad2017-04-17 23:21:52 +053099 return response;
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -0500100}
101
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +0530102// Called at OCC Status change signal
103void PassThrough::activeStatusEvent(sdbusplus::message::message& msg)
104{
105 std::string statusInterface;
Patrick Williamse0962702020-05-13 17:50:22 -0500106 std::map<std::string, std::variant<bool>> msgData;
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +0530107 msg.read(statusInterface, msgData);
108
109 auto propertyMap = msgData.find("OccActive");
110 if (propertyMap != msgData.end())
111 {
112 // Extract the OccActive property
Patrick Williams305ff8b2020-05-13 11:17:39 -0500113 if (std::get<bool>(propertyMap->second))
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +0530114 {
Eddie James4f4712d2018-06-21 15:57:02 -0500115 occActive = true;
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +0530116 }
117 else
118 {
Eddie James4f4712d2018-06-21 15:57:02 -0500119 occActive = false;
Vishwanatha Subbanna3e5422e2017-08-10 18:25:26 +0530120 }
121 }
122 return;
123}
124
Deepak Kodihalli6b492fb2017-03-18 01:09:28 -0500125} // namespace occ
126} // namespace open_power