blob: f14bd7db40066b33ac07d2e68c27d83f3d9c05bc [file] [log] [blame]
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05301#pragma once
2
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +05303#include <functional>
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05304#include <sdbusplus/bus.hpp>
5#include <sdbusplus/server/object.hpp>
6#include <org/open_power/OCC/Status/server.hpp>
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05307#include <org/open_power/Control/Host/server.hpp>
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +05308#include "occ_events.hpp"
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05309#include "occ_device.hpp"
Lei YU0ab90ca2017-07-13 17:02:23 +080010#include "i2c_occ.hpp"
11
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053012namespace open_power
13{
14namespace occ
15{
16
Edward A. James636577f2017-10-06 10:53:55 -050017class Manager;
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053018namespace Base = sdbusplus::org::open_power::OCC::server;
19using Interface = sdbusplus::server::object::object<Base::Status>;
20
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053021// IPMID's host control application
22namespace Control = sdbusplus::org::open_power::Control::server;
23
24// For waiting on signals
25namespace sdbusRule = sdbusplus::bus::match::rules;
26
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053027// OCC status instance. Ex. for "occ0", the instance is 0
28using instanceID = int;
29
30// IPMI sensor ID for a given OCC instance
31using sensorID = uint8_t;
32
Eddie Jamese7d976b2018-02-26 13:42:45 -060033// OCC sysfs name prefix
34const std::string sysfsName = "occ-hwmon";
35
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053036/** @class Status
37 * @brief Implementation of OCC Active Status
38 */
39class Status : public Interface
40{
41 public:
42 Status() = delete;
43 ~Status() = default;
44 Status(const Status&) = delete;
45 Status& operator=(const Status&) = delete;
46 Status(Status&&) = default;
47 Status& operator=(Status&&) = default;
48
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053049 /** @brief Constructs the Status object and
50 * the underlying device object
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053051 *
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053052 * @param[in] bus - DBus bus to attach to
53 * @param[in] event - sd_event unique pointer reference
54 * @param[in] path - DBus object path
Edward A. James636577f2017-10-06 10:53:55 -050055 * @param[in] manager - OCC manager instance
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053056 * @param[in] callBack - Callback handler to invoke during
57 * property change
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053058 */
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053059 Status(sdbusplus::bus::bus& bus,
60 EventPtr& event,
61 const char* path,
Edward A. James636577f2017-10-06 10:53:55 -050062 const Manager& manager,
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053063 std::function<void(bool)> callBack = nullptr)
Vishwanatha Subbannab57f1512017-09-04 15:06:20 +053064 : Interface(bus, path, true),
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053065 bus(bus),
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053066 path(path),
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053067 callBack(callBack),
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053068 instance(((this->path.back() - '0'))),
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053069 device(event,
Lei YU0ab90ca2017-07-13 17:02:23 +080070#ifdef I2C_OCC
71 i2c_occ::getI2cDeviceName(path),
72#else
Eddie Jamese7d976b2018-02-26 13:42:45 -060073 sysfsName + "." + std::to_string(instance + 1),
Lei YU0ab90ca2017-07-13 17:02:23 +080074#endif
Edward A. James636577f2017-10-06 10:53:55 -050075 manager,
Eddie James482e31f2017-09-14 13:17:17 -050076 *this,
77 std::bind(std::mem_fn(&Status::deviceErrorHandler), this,
78 std::placeholders::_1)),
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053079 hostControlSignal(
80 bus,
81 sdbusRule::type::signal() +
82 sdbusRule::member("CommandComplete") +
83 sdbusRule::path("/org/open_power/control/host0") +
84 sdbusRule::interface("org.open_power.Control.Host") +
85 sdbusRule::argN(0, Control::convertForMessage(
86 Control::Host::Command::OCCReset)),
87 std::bind(std::mem_fn(&Status::hostControlEvent),
88 this, std::placeholders::_1))
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053089 {
Vishwanatha Subbannab57f1512017-09-04 15:06:20 +053090 // Check to see if we have OCC already bound. If so, just set it
91 if (device.bound())
92 {
93 this->occActive(true);
94 }
95
96 // Announce that we are ready
97 this->emit_object_added();
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053098 }
99
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530100 /** @brief Since we are overriding the setter-occActive but not the
101 * getter-occActive, we need to have this using in order to
102 * allow passthrough usage of the getter-occActive
103 */
104 using Base::Status::occActive;
105
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530106 /** @brief SET OccActive to True or False
107 *
108 * @param[in] value - Intended value
109 *
110 * @return - Updated value of the property
111 */
112 bool occActive(bool value) override;
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530113
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530114 /** @brief Starts OCC error detection */
115 inline void addErrorWatch()
116 {
117 return device.addErrorWatch();
118 }
119
120 /** @brief Stops OCC error detection */
121 inline void removeErrorWatch()
122 {
123 return device.removeErrorWatch();
124 }
125
Eddie Jamesdae2d942017-12-20 10:50:03 -0600126 /** @brief Starts to watch how many OCCs are present on the master */
127 inline void addPresenceWatchMaster()
128 {
129 return device.addPresenceWatchMaster();
130 }
131
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530132 private:
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530133
134 /** @brief sdbus handle */
135 sdbusplus::bus::bus& bus;
136
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530137 /** @brief OCC dbus object path */
138 std::string path;
139
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530140 /** @brief Callback handler to be invoked during property change.
141 * This is a handler in Manager class
142 */
143 std::function<void(bool)> callBack;
144
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +0530145 /** @brief OCC instance number. Ex, 0,1, etc */
146 int instance;
147
148 /** @brief OCC instance to Sensor ID mapping */
149 static const std::map<instanceID, sensorID> sensorMap;
150
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530151 /** @brief OCC device object to do bind and unbind */
152 Device device;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530153
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530154 /** @brief Subscribe to host control signal
155 *
156 * Once the OCC reset is requested, BMC sends that message to host.
157 * If the host does not ack the message, then there would be a timeout
158 * and we need to catch that to log an error
159 **/
160 sdbusplus::bus::match_t hostControlSignal;
161
Eddie James482e31f2017-09-14 13:17:17 -0500162 /** @brief Callback handler when device errors are detected
163 *
164 * @param[in] error - True if an error is reported, false otherwise
165 */
166 void deviceErrorHandler(bool error);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530167
168 /** @brief Callback function on host control signals
169 *
170 * @param[in] msg - Data associated with subscribed signal
171 */
172 void hostControlEvent(sdbusplus::message::message& msg);
173
174 /** @brief Sends a message to host control command handler to reset OCC
175 */
176 void resetOCC();
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530177};
178
179} // namespace occ
180} // namespace open_power