blob: c097908b303b6905d52eb937c599a69e1ed91116 [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
17namespace Base = sdbusplus::org::open_power::OCC::server;
18using Interface = sdbusplus::server::object::object<Base::Status>;
19
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053020// IPMID's host control application
21namespace Control = sdbusplus::org::open_power::Control::server;
22
23// For waiting on signals
24namespace sdbusRule = sdbusplus::bus::match::rules;
25
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053026// OCC status instance. Ex. for "occ0", the instance is 0
27using instanceID = int;
28
29// IPMI sensor ID for a given OCC instance
30using sensorID = uint8_t;
31
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053032/** @class Status
33 * @brief Implementation of OCC Active Status
34 */
35class Status : public Interface
36{
37 public:
38 Status() = delete;
39 ~Status() = default;
40 Status(const Status&) = delete;
41 Status& operator=(const Status&) = delete;
42 Status(Status&&) = default;
43 Status& operator=(Status&&) = default;
44
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053045 /** @brief Constructs the Status object and
46 * the underlying device object
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053047 *
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053048 * @param[in] bus - DBus bus to attach to
49 * @param[in] event - sd_event unique pointer reference
50 * @param[in] path - DBus object path
51 * @param[in] callBack - Callback handler to invoke during
52 * property change
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053053 */
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053054 Status(sdbusplus::bus::bus& bus,
55 EventPtr& event,
56 const char* path,
57 std::function<void(bool)> callBack = nullptr)
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053058 : Interface(bus, path),
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053059 bus(bus),
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053060 path(path),
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053061 callBack(callBack),
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053062 instance(((this->path.back() - '0'))),
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053063 device(event,
Lei YU0ab90ca2017-07-13 17:02:23 +080064#ifdef I2C_OCC
65 i2c_occ::getI2cDeviceName(path),
66#else
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053067 name + std::to_string(instance + 1),
Lei YU0ab90ca2017-07-13 17:02:23 +080068#endif
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053069 std::bind(&Status::deviceErrorHandler, this)),
70 hostControlSignal(
71 bus,
72 sdbusRule::type::signal() +
73 sdbusRule::member("CommandComplete") +
74 sdbusRule::path("/org/open_power/control/host0") +
75 sdbusRule::interface("org.open_power.Control.Host") +
76 sdbusRule::argN(0, Control::convertForMessage(
77 Control::Host::Command::OCCReset)),
78 std::bind(std::mem_fn(&Status::hostControlEvent),
79 this, std::placeholders::_1))
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053080 {
81 // Nothing to do here
82 }
83
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053084 /** @brief Since we are overriding the setter-occActive but not the
85 * getter-occActive, we need to have this using in order to
86 * allow passthrough usage of the getter-occActive
87 */
88 using Base::Status::occActive;
89
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053090 /** @brief SET OccActive to True or False
91 *
92 * @param[in] value - Intended value
93 *
94 * @return - Updated value of the property
95 */
96 bool occActive(bool value) override;
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053097
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053098 /** @brief Starts OCC error detection */
99 inline void addErrorWatch()
100 {
101 return device.addErrorWatch();
102 }
103
104 /** @brief Stops OCC error detection */
105 inline void removeErrorWatch()
106 {
107 return device.removeErrorWatch();
108 }
109
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530110 private:
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530111
112 /** @brief sdbus handle */
113 sdbusplus::bus::bus& bus;
114
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530115 /** @brief OCC dbus object path */
116 std::string path;
117
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530118 /** @brief Callback handler to be invoked during property change.
119 * This is a handler in Manager class
120 */
121 std::function<void(bool)> callBack;
122
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530123 /** @brief occ name prefix */
124 std::string name = OCC_NAME;
125
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +0530126 /** @brief OCC instance number. Ex, 0,1, etc */
127 int instance;
128
129 /** @brief OCC instance to Sensor ID mapping */
130 static const std::map<instanceID, sensorID> sensorMap;
131
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530132 /** @brief OCC device object to do bind and unbind */
133 Device device;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530134
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530135 /** @brief Subscribe to host control signal
136 *
137 * Once the OCC reset is requested, BMC sends that message to host.
138 * If the host does not ack the message, then there would be a timeout
139 * and we need to catch that to log an error
140 **/
141 sdbusplus::bus::match_t hostControlSignal;
142
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530143 /** @brief Callback handler when device errors are detected */
144 void deviceErrorHandler();
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530145
146 /** @brief Callback function on host control signals
147 *
148 * @param[in] msg - Data associated with subscribed signal
149 */
150 void hostControlEvent(sdbusplus::message::message& msg);
151
152 /** @brief Sends a message to host control command handler to reset OCC
153 */
154 void resetOCC();
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530155};
156
157} // namespace occ
158} // namespace open_power