blob: 2e12806b770c5fb32838ca22e7f8272ebe951068 [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"
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053010namespace open_power
11{
12namespace occ
13{
14
15namespace Base = sdbusplus::org::open_power::OCC::server;
16using Interface = sdbusplus::server::object::object<Base::Status>;
17
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053018// IPMID's host control application
19namespace Control = sdbusplus::org::open_power::Control::server;
20
21// For waiting on signals
22namespace sdbusRule = sdbusplus::bus::match::rules;
23
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053024// OCC status instance. Ex. for "occ0", the instance is 0
25using instanceID = int;
26
27// IPMI sensor ID for a given OCC instance
28using sensorID = uint8_t;
29
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053030/** @class Status
31 * @brief Implementation of OCC Active Status
32 */
33class Status : public Interface
34{
35 public:
36 Status() = delete;
37 ~Status() = default;
38 Status(const Status&) = delete;
39 Status& operator=(const Status&) = delete;
40 Status(Status&&) = default;
41 Status& operator=(Status&&) = default;
42
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053043 /** @brief Constructs the Status object and
44 * the underlying device object
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053045 *
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053046 * @param[in] bus - DBus bus to attach to
47 * @param[in] event - sd_event unique pointer reference
48 * @param[in] path - DBus object path
49 * @param[in] callBack - Callback handler to invoke during
50 * property change
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053051 */
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053052 Status(sdbusplus::bus::bus& bus,
53 EventPtr& event,
54 const char* path,
55 std::function<void(bool)> callBack = nullptr)
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053056 : Interface(bus, path),
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053057 bus(bus),
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053058 path(path),
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053059 callBack(callBack),
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053060 instance(((this->path.back() - '0'))),
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053061 device(event,
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +053062 name + std::to_string(instance + 1),
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053063 std::bind(&Status::deviceErrorHandler, this)),
64 hostControlSignal(
65 bus,
66 sdbusRule::type::signal() +
67 sdbusRule::member("CommandComplete") +
68 sdbusRule::path("/org/open_power/control/host0") +
69 sdbusRule::interface("org.open_power.Control.Host") +
70 sdbusRule::argN(0, Control::convertForMessage(
71 Control::Host::Command::OCCReset)),
72 std::bind(std::mem_fn(&Status::hostControlEvent),
73 this, std::placeholders::_1))
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053074 {
75 // Nothing to do here
76 }
77
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053078 /** @brief Since we are overriding the setter-occActive but not the
79 * getter-occActive, we need to have this using in order to
80 * allow passthrough usage of the getter-occActive
81 */
82 using Base::Status::occActive;
83
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053084 /** @brief SET OccActive to True or False
85 *
86 * @param[in] value - Intended value
87 *
88 * @return - Updated value of the property
89 */
90 bool occActive(bool value) override;
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053091
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053092 /** @brief Starts OCC error detection */
93 inline void addErrorWatch()
94 {
95 return device.addErrorWatch();
96 }
97
98 /** @brief Stops OCC error detection */
99 inline void removeErrorWatch()
100 {
101 return device.removeErrorWatch();
102 }
103
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530104 private:
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530105
106 /** @brief sdbus handle */
107 sdbusplus::bus::bus& bus;
108
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530109 /** @brief OCC dbus object path */
110 std::string path;
111
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +0530112 /** @brief Callback handler to be invoked during property change.
113 * This is a handler in Manager class
114 */
115 std::function<void(bool)> callBack;
116
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530117 /** @brief occ name prefix */
118 std::string name = OCC_NAME;
119
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +0530120 /** @brief OCC instance number. Ex, 0,1, etc */
121 int instance;
122
123 /** @brief OCC instance to Sensor ID mapping */
124 static const std::map<instanceID, sensorID> sensorMap;
125
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +0530126 /** @brief OCC device object to do bind and unbind */
127 Device device;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530128
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530129 /** @brief Subscribe to host control signal
130 *
131 * Once the OCC reset is requested, BMC sends that message to host.
132 * If the host does not ack the message, then there would be a timeout
133 * and we need to catch that to log an error
134 **/
135 sdbusplus::bus::match_t hostControlSignal;
136
Vishwanatha Subbannad2981052017-08-09 21:42:10 +0530137 /** @brief Indicates whether a hub FSI scan has been attempted or not */
138 static bool hubFsiScanDone;
139
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530140 /** @brief Callback handler when device errors are detected */
141 void deviceErrorHandler();
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530142
143 /** @brief Callback function on host control signals
144 *
145 * @param[in] msg - Data associated with subscribed signal
146 */
147 void hostControlEvent(sdbusplus::message::message& msg);
148
149 /** @brief Sends a message to host control command handler to reset OCC
150 */
151 void resetOCC();
Vishwanatha Subbannad2981052017-08-09 21:42:10 +0530152
153 /** @brief Initiates hub FSI scan so that /dev/occ files are created
154 */
155 void scanHubFSI();
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530156};
157
158} // namespace occ
159} // namespace open_power