Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 3 | #include <functional> |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 4 | #include <sdbusplus/bus.hpp> |
| 5 | #include <sdbusplus/server/object.hpp> |
| 6 | #include <org/open_power/OCC/Status/server.hpp> |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 7 | #include <org/open_power/Control/Host/server.hpp> |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 8 | #include "occ_events.hpp" |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 9 | #include "occ_device.hpp" |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 10 | #include "i2c_occ.hpp" |
| 11 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 12 | namespace open_power |
| 13 | { |
| 14 | namespace occ |
| 15 | { |
| 16 | |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 17 | class Manager; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 18 | namespace Base = sdbusplus::org::open_power::OCC::server; |
| 19 | using Interface = sdbusplus::server::object::object<Base::Status>; |
| 20 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 21 | // IPMID's host control application |
| 22 | namespace Control = sdbusplus::org::open_power::Control::server; |
| 23 | |
| 24 | // For waiting on signals |
| 25 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 26 | |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 27 | // OCC status instance. Ex. for "occ0", the instance is 0 |
| 28 | using instanceID = int; |
| 29 | |
| 30 | // IPMI sensor ID for a given OCC instance |
| 31 | using sensorID = uint8_t; |
| 32 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 33 | /** @class Status |
| 34 | * @brief Implementation of OCC Active Status |
| 35 | */ |
| 36 | class 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 Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 46 | /** @brief Constructs the Status object and |
| 47 | * the underlying device object |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 48 | * |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 49 | * @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. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 52 | * @param[in] manager - OCC manager instance |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 53 | * @param[in] callBack - Callback handler to invoke during |
| 54 | * property change |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 55 | */ |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 56 | Status(sdbusplus::bus::bus& bus, |
| 57 | EventPtr& event, |
| 58 | const char* path, |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 59 | const Manager& manager, |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 60 | std::function<void(bool)> callBack = nullptr) |
Vishwanatha Subbanna | b57f151 | 2017-09-04 15:06:20 +0530 | [diff] [blame] | 61 | : Interface(bus, path, true), |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 62 | bus(bus), |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 63 | path(path), |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 64 | callBack(callBack), |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 65 | instance(((this->path.back() - '0'))), |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 66 | device(event, |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 67 | #ifdef I2C_OCC |
| 68 | i2c_occ::getI2cDeviceName(path), |
| 69 | #else |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 70 | name + std::to_string(instance + 1), |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 71 | #endif |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 72 | manager, |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 73 | *this, |
| 74 | std::bind(std::mem_fn(&Status::deviceErrorHandler), this, |
| 75 | std::placeholders::_1)), |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 76 | hostControlSignal( |
| 77 | bus, |
| 78 | sdbusRule::type::signal() + |
| 79 | sdbusRule::member("CommandComplete") + |
| 80 | sdbusRule::path("/org/open_power/control/host0") + |
| 81 | sdbusRule::interface("org.open_power.Control.Host") + |
| 82 | sdbusRule::argN(0, Control::convertForMessage( |
| 83 | Control::Host::Command::OCCReset)), |
| 84 | std::bind(std::mem_fn(&Status::hostControlEvent), |
| 85 | this, std::placeholders::_1)) |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 86 | { |
Vishwanatha Subbanna | b57f151 | 2017-09-04 15:06:20 +0530 | [diff] [blame] | 87 | // Check to see if we have OCC already bound. If so, just set it |
| 88 | if (device.bound()) |
| 89 | { |
| 90 | this->occActive(true); |
| 91 | } |
| 92 | |
| 93 | // Announce that we are ready |
| 94 | this->emit_object_added(); |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 95 | } |
| 96 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 97 | /** @brief Since we are overriding the setter-occActive but not the |
| 98 | * getter-occActive, we need to have this using in order to |
| 99 | * allow passthrough usage of the getter-occActive |
| 100 | */ |
| 101 | using Base::Status::occActive; |
| 102 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 103 | /** @brief SET OccActive to True or False |
| 104 | * |
| 105 | * @param[in] value - Intended value |
| 106 | * |
| 107 | * @return - Updated value of the property |
| 108 | */ |
| 109 | bool occActive(bool value) override; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 110 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 111 | /** @brief Starts OCC error detection */ |
| 112 | inline void addErrorWatch() |
| 113 | { |
| 114 | return device.addErrorWatch(); |
| 115 | } |
| 116 | |
| 117 | /** @brief Stops OCC error detection */ |
| 118 | inline void removeErrorWatch() |
| 119 | { |
| 120 | return device.removeErrorWatch(); |
| 121 | } |
| 122 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 123 | private: |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 124 | |
| 125 | /** @brief sdbus handle */ |
| 126 | sdbusplus::bus::bus& bus; |
| 127 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 128 | /** @brief OCC dbus object path */ |
| 129 | std::string path; |
| 130 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 131 | /** @brief Callback handler to be invoked during property change. |
| 132 | * This is a handler in Manager class |
| 133 | */ |
| 134 | std::function<void(bool)> callBack; |
| 135 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 136 | /** @brief occ name prefix */ |
| 137 | std::string name = OCC_NAME; |
| 138 | |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 139 | /** @brief OCC instance number. Ex, 0,1, etc */ |
| 140 | int instance; |
| 141 | |
| 142 | /** @brief OCC instance to Sensor ID mapping */ |
| 143 | static const std::map<instanceID, sensorID> sensorMap; |
| 144 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 145 | /** @brief OCC device object to do bind and unbind */ |
| 146 | Device device; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 147 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 148 | /** @brief Subscribe to host control signal |
| 149 | * |
| 150 | * Once the OCC reset is requested, BMC sends that message to host. |
| 151 | * If the host does not ack the message, then there would be a timeout |
| 152 | * and we need to catch that to log an error |
| 153 | **/ |
| 154 | sdbusplus::bus::match_t hostControlSignal; |
| 155 | |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 156 | /** @brief Callback handler when device errors are detected |
| 157 | * |
| 158 | * @param[in] error - True if an error is reported, false otherwise |
| 159 | */ |
| 160 | void deviceErrorHandler(bool error); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 161 | |
| 162 | /** @brief Callback function on host control signals |
| 163 | * |
| 164 | * @param[in] msg - Data associated with subscribed signal |
| 165 | */ |
| 166 | void hostControlEvent(sdbusplus::message::message& msg); |
| 167 | |
| 168 | /** @brief Sends a message to host control command handler to reset OCC |
| 169 | */ |
| 170 | void resetOCC(); |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | } // namespace occ |
| 174 | } // namespace open_power |