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