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, |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 73 | 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 Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 84 | { |
Vishwanatha Subbanna | b57f151 | 2017-09-04 15:06:20 +0530 | [diff] [blame] | 85 | // 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 Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 93 | } |
| 94 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 95 | /** @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 Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 101 | /** @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 Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 108 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 109 | /** @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 Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 121 | private: |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 122 | |
| 123 | /** @brief sdbus handle */ |
| 124 | sdbusplus::bus::bus& bus; |
| 125 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 126 | /** @brief OCC dbus object path */ |
| 127 | std::string path; |
| 128 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 129 | /** @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 Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 134 | /** @brief occ name prefix */ |
| 135 | std::string name = OCC_NAME; |
| 136 | |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 137 | /** @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 Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 143 | /** @brief OCC device object to do bind and unbind */ |
| 144 | Device device; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 145 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 146 | /** @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 Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 154 | /** @brief Callback handler when device errors are detected */ |
| 155 | void deviceErrorHandler(); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 156 | |
| 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 Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | } // namespace occ |
| 169 | } // namespace open_power |