blob: 859b5b0f0551495b7cd4630f2e3f466d3f8f428d [file] [log] [blame]
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05301#pragma once
2
Gunnar Mills94df8c92018-09-14 14:50:03 -05003#include "i2c_occ.hpp"
4#include "occ_device.hpp"
5#include "occ_events.hpp"
6
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +05307#include <functional>
Gunnar Mills94df8c92018-09-14 14:50:03 -05008#include <org/open_power/Control/Host/server.hpp>
9#include <org/open_power/OCC/Status/server.hpp>
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053010#include <sdbusplus/bus.hpp>
11#include <sdbusplus/server/object.hpp>
Lei YU0ab90ca2017-07-13 17:02:23 +080012
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053013namespace open_power
14{
15namespace occ
16{
17
Edward A. James636577f2017-10-06 10:53:55 -050018class Manager;
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053019namespace Base = sdbusplus::org::open_power::OCC::server;
20using Interface = sdbusplus::server::object::object<Base::Status>;
21
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053022// IPMID's host control application
23namespace Control = sdbusplus::org::open_power::Control::server;
24
25// For waiting on signals
26namespace sdbusRule = sdbusplus::bus::match::rules;
27
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053028// OCC status instance. Ex. for "occ0", the instance is 0
29using instanceID = int;
30
31// IPMI sensor ID for a given OCC instance
32using sensorID = uint8_t;
33
Eddie Jamese7d976b2018-02-26 13:42:45 -060034// OCC sysfs name prefix
35const std::string sysfsName = "occ-hwmon";
36
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053037/** @class Status
38 * @brief Implementation of OCC Active Status
39 */
40class Status : public Interface
41{
Gunnar Mills94df8c92018-09-14 14:50:03 -050042 public:
43 Status() = delete;
44 ~Status() = default;
45 Status(const Status&) = delete;
46 Status& operator=(const Status&) = delete;
47 Status(Status&&) = default;
48 Status& operator=(Status&&) = default;
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053049
Gunnar Mills94df8c92018-09-14 14:50:03 -050050 /** @brief Constructs the Status object and
51 * the underlying device object
52 *
53 * @param[in] bus - DBus bus to attach to
54 * @param[in] event - sd_event unique pointer reference
55 * @param[in] path - DBus object path
56 * @param[in] manager - OCC manager instance
57 * @param[in] callBack - Callback handler to invoke during
58 * property change
59 */
60 Status(sdbusplus::bus::bus& bus, EventPtr& event, const char* path,
61 const Manager& manager,
62 std::function<void(bool)> callBack = nullptr) :
63 Interface(bus, path, true),
64 bus(bus), path(path), callBack(callBack),
65 instance(((this->path.back() - '0'))),
66 device(event,
Lei YU0ab90ca2017-07-13 17:02:23 +080067#ifdef I2C_OCC
Eddie James774f9af2019-03-19 20:58:53 +000068 fs::path(DEV_PATH) / i2c_occ::getI2cDeviceName(path),
Lei YU0ab90ca2017-07-13 17:02:23 +080069#else
Eddie James774f9af2019-03-19 20:58:53 +000070 fs::path(DEV_PATH) /
71 fs::path(sysfsName + "." + std::to_string(instance + 1)),
Lei YU0ab90ca2017-07-13 17:02:23 +080072#endif
Gunnar Mills94df8c92018-09-14 14:50:03 -050073 manager, *this,
74 std::bind(std::mem_fn(&Status::deviceErrorHandler), this,
75 std::placeholders::_1)),
76 hostControlSignal(
77 bus,
78 sdbusRule::type::signal() + sdbusRule::member("CommandComplete") +
79 sdbusRule::path("/org/open_power/control/host0") +
80 sdbusRule::interface("org.open_power.Control.Host") +
81 sdbusRule::argN(0, Control::convertForMessage(
82 Control::Host::Command::OCCReset)),
83 std::bind(std::mem_fn(&Status::hostControlEvent), this,
84 std::placeholders::_1))
85 {
86 // Check to see if we have OCC already bound. If so, just set it
87 if (device.bound())
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053088 {
Gunnar Mills94df8c92018-09-14 14:50:03 -050089 this->occActive(true);
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053090 }
91
Gunnar Mills94df8c92018-09-14 14:50:03 -050092 // Announce that we are ready
93 this->emit_object_added();
94 }
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053095
Gunnar Mills94df8c92018-09-14 14:50:03 -050096 /** @brief Since we are overriding the setter-occActive but not the
97 * getter-occActive, we need to have this using in order to
98 * allow passthrough usage of the getter-occActive
99 */
100 using Base::Status::occActive;
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530101
Gunnar Mills94df8c92018-09-14 14:50:03 -0500102 /** @brief SET OccActive to True or False
103 *
104 * @param[in] value - Intended value
105 *
106 * @return - Updated value of the property
107 */
108 bool occActive(bool value) override;
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530109
Gunnar Mills94df8c92018-09-14 14:50:03 -0500110 /** @brief Starts OCC error detection */
111 inline void addErrorWatch()
112 {
113 return device.addErrorWatch();
114 }
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530115
Gunnar Mills94df8c92018-09-14 14:50:03 -0500116 /** @brief Stops OCC error detection */
117 inline void removeErrorWatch()
118 {
119 return device.removeErrorWatch();
120 }
Eddie Jamesdae2d942017-12-20 10:50:03 -0600121
Gunnar Mills94df8c92018-09-14 14:50:03 -0500122 /** @brief Starts to watch how many OCCs are present on the master */
123 inline void addPresenceWatchMaster()
124 {
125 return device.addPresenceWatchMaster();
126 }
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530127
Gunnar Mills94df8c92018-09-14 14:50:03 -0500128 private:
129 /** @brief sdbus handle */
130 sdbusplus::bus::bus& bus;
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530131
Gunnar Mills94df8c92018-09-14 14:50:03 -0500132 /** @brief OCC dbus object path */
133 std::string path;
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530134
Gunnar Mills94df8c92018-09-14 14:50:03 -0500135 /** @brief Callback handler to be invoked during property change.
136 * This is a handler in Manager class
137 */
138 std::function<void(bool)> callBack;
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530139
Gunnar Mills94df8c92018-09-14 14:50:03 -0500140 /** @brief OCC instance number. Ex, 0,1, etc */
141 int instance;
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +0530142
Gunnar Mills94df8c92018-09-14 14:50:03 -0500143 /** @brief OCC instance to Sensor ID mapping */
144 static const std::map<instanceID, sensorID> sensorMap;
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +0530145
Gunnar Mills94df8c92018-09-14 14:50:03 -0500146 /** @brief OCC device object to do bind and unbind */
147 Device device;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530148
Gunnar Mills94df8c92018-09-14 14:50:03 -0500149 /** @brief Subscribe to host control signal
150 *
151 * Once the OCC reset is requested, BMC sends that message to host.
152 * If the host does not ack the message, then there would be a timeout
153 * and we need to catch that to log an error
154 **/
155 sdbusplus::bus::match_t hostControlSignal;
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530156
Gunnar Mills94df8c92018-09-14 14:50:03 -0500157 /** @brief Callback handler when device errors are detected
158 *
159 * @param[in] error - True if an error is reported, false otherwise
160 */
161 void deviceErrorHandler(bool error);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530162
Gunnar Mills94df8c92018-09-14 14:50:03 -0500163 /** @brief Callback function on host control signals
164 *
165 * @param[in] msg - Data associated with subscribed signal
166 */
167 void hostControlEvent(sdbusplus::message::message& msg);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530168
Gunnar Mills94df8c92018-09-14 14:50:03 -0500169 /** @brief Sends a message to host control command handler to reset OCC
170 */
171 void resetOCC();
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530172};
173
174} // namespace occ
175} // namespace open_power