blob: 55ee5399329f894688f9e5ea9b5dd75f0b2105ab [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
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053033/** @class Status
34 * @brief Implementation of OCC Active Status
35 */
36class Status : public Interface
37{
38 public:
39 Status() = delete;
40 ~Status() = default;
41 Status(const Status&) = delete;
42 Status& operator=(const Status&) = delete;
43 Status(Status&&) = default;
44 Status& operator=(Status&&) = default;
45
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053046 /** @brief Constructs the Status object and
47 * the underlying device object
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053048 *
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053049 * @param[in] bus - DBus bus to attach to
50 * @param[in] event - sd_event unique pointer reference
51 * @param[in] path - DBus object path
Edward A. James636577f2017-10-06 10:53:55 -050052 * @param[in] manager - OCC manager instance
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053053 * @param[in] callBack - Callback handler to invoke during
54 * property change
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053055 */
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053056 Status(sdbusplus::bus::bus& bus,
57 EventPtr& event,
58 const char* path,
Edward A. James636577f2017-10-06 10:53:55 -050059 const Manager& manager,
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053060 std::function<void(bool)> callBack = nullptr)
Vishwanatha Subbannab57f1512017-09-04 15:06:20 +053061 : Interface(bus, path, true),
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053062 bus(bus),
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053063 path(path),
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053064 callBack(callBack),
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053065 instance(((this->path.back() - '0'))),
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053066 device(event,
Lei YU0ab90ca2017-07-13 17:02:23 +080067#ifdef I2C_OCC
68 i2c_occ::getI2cDeviceName(path),
69#else
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053070 name + std::to_string(instance + 1),
Lei YU0ab90ca2017-07-13 17:02:23 +080071#endif
Edward A. James636577f2017-10-06 10:53:55 -050072 manager,
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053073 std::bind(&Status::deviceErrorHandler, this)),
74 hostControlSignal(
75 bus,
76 sdbusRule::type::signal() +
77 sdbusRule::member("CommandComplete") +
78 sdbusRule::path("/org/open_power/control/host0") +
79 sdbusRule::interface("org.open_power.Control.Host") +
80 sdbusRule::argN(0, Control::convertForMessage(
81 Control::Host::Command::OCCReset)),
82 std::bind(std::mem_fn(&Status::hostControlEvent),
83 this, std::placeholders::_1))
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053084 {
Vishwanatha Subbannab57f1512017-09-04 15:06:20 +053085 // Check to see if we have OCC already bound. If so, just set it
86 if (device.bound())
87 {
88 this->occActive(true);
89 }
90
91 // Announce that we are ready
92 this->emit_object_added();
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053093 }
94
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053095 /** @brief Since we are overriding the setter-occActive but not the
96 * getter-occActive, we need to have this using in order to
97 * allow passthrough usage of the getter-occActive
98 */
99 using Base::Status::occActive;
100
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530101 /** @brief SET OccActive to True or False
102 *
103 * @param[in] value - Intended value
104 *
105 * @return - Updated value of the property
106 */
107 bool occActive(bool value) override;
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530108
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530109 /** @brief Starts OCC error detection */
110 inline void addErrorWatch()
111 {
112 return device.addErrorWatch();
113 }
114
115 /** @brief Stops OCC error detection */
116 inline void removeErrorWatch()
117 {
118 return device.removeErrorWatch();
119 }
120
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530121 private:
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530122
123 /** @brief sdbus handle */
124 sdbusplus::bus::bus& bus;
125
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530126 /** @brief OCC dbus object path */
127 std::string path;
128
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530129 /** @brief Callback handler to be invoked during property change.
130 * This is a handler in Manager class
131 */
132 std::function<void(bool)> callBack;
133
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530134 /** @brief occ name prefix */
135 std::string name = OCC_NAME;
136
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +0530137 /** @brief OCC instance number. Ex, 0,1, etc */
138 int instance;
139
140 /** @brief OCC instance to Sensor ID mapping */
141 static const std::map<instanceID, sensorID> sensorMap;
142
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530143 /** @brief OCC device object to do bind and unbind */
144 Device device;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530145
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530146 /** @brief Subscribe to host control signal
147 *
148 * Once the OCC reset is requested, BMC sends that message to host.
149 * If the host does not ack the message, then there would be a timeout
150 * and we need to catch that to log an error
151 **/
152 sdbusplus::bus::match_t hostControlSignal;
153
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530154 /** @brief Callback handler when device errors are detected */
155 void deviceErrorHandler();
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530156
157 /** @brief Callback function on host control signals
158 *
159 * @param[in] msg - Data associated with subscribed signal
160 */
161 void hostControlEvent(sdbusplus::message::message& msg);
162
163 /** @brief Sends a message to host control command handler to reset OCC
164 */
165 void resetOCC();
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530166};
167
168} // namespace occ
169} // namespace open_power