Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 3 | #include "i2c_occ.hpp" |
| 4 | #include "occ_device.hpp" |
| 5 | #include "occ_events.hpp" |
| 6 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 7 | #include <functional> |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 8 | #include <org/open_power/Control/Host/server.hpp> |
| 9 | #include <org/open_power/OCC/Status/server.hpp> |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 10 | #include <sdbusplus/bus.hpp> |
| 11 | #include <sdbusplus/server/object.hpp> |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 12 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 13 | namespace open_power |
| 14 | { |
| 15 | namespace occ |
| 16 | { |
| 17 | |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 18 | class Manager; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 19 | namespace Base = sdbusplus::org::open_power::OCC::server; |
| 20 | using Interface = sdbusplus::server::object::object<Base::Status>; |
| 21 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 22 | // IPMID's host control application |
| 23 | namespace Control = sdbusplus::org::open_power::Control::server; |
| 24 | |
| 25 | // For waiting on signals |
| 26 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 27 | |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 28 | // OCC status instance. Ex. for "occ0", the instance is 0 |
| 29 | using instanceID = int; |
| 30 | |
| 31 | // IPMI sensor ID for a given OCC instance |
| 32 | using sensorID = uint8_t; |
| 33 | |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 34 | // Human readable sensor name for DBus tree. E.g. "CPU0_OCC" |
| 35 | using sensorName = std::string; |
| 36 | |
| 37 | // OCC sensors definitions in the map |
| 38 | using sensorDefs = std::tuple<sensorID, sensorName>; |
| 39 | |
Eddie James | e7d976b | 2018-02-26 13:42:45 -0600 | [diff] [blame] | 40 | // OCC sysfs name prefix |
| 41 | const std::string sysfsName = "occ-hwmon"; |
| 42 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 43 | /** @class Status |
| 44 | * @brief Implementation of OCC Active Status |
| 45 | */ |
| 46 | class Status : public Interface |
| 47 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 48 | public: |
| 49 | Status() = delete; |
| 50 | ~Status() = default; |
| 51 | Status(const Status&) = delete; |
| 52 | Status& operator=(const Status&) = delete; |
| 53 | Status(Status&&) = default; |
| 54 | Status& operator=(Status&&) = default; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 55 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 56 | /** @brief Constructs the Status object and |
| 57 | * the underlying device object |
| 58 | * |
| 59 | * @param[in] bus - DBus bus to attach to |
| 60 | * @param[in] event - sd_event unique pointer reference |
| 61 | * @param[in] path - DBus object path |
| 62 | * @param[in] manager - OCC manager instance |
| 63 | * @param[in] callBack - Callback handler to invoke during |
| 64 | * property change |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 65 | * @param[in] resetCallBack - callback handler to invoke for resetting the |
| 66 | * OCC if PLDM is the host communication |
| 67 | * protocol |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 68 | */ |
| 69 | Status(sdbusplus::bus::bus& bus, EventPtr& event, const char* path, |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 70 | const Manager& manager, std::function<void(bool)> callBack = nullptr |
| 71 | #ifdef PLDM |
| 72 | , |
| 73 | std::function<void(instanceID)> resetCallBack = nullptr |
| 74 | #endif |
| 75 | ) : |
| 76 | |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 77 | Interface(bus, getDbusPath(path).c_str(), true), |
| 78 | bus(bus), path(path), callBack(callBack), instance(getInstance(path)), |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 79 | device(event, |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 80 | #ifdef I2C_OCC |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 81 | fs::path(DEV_PATH) / i2c_occ::getI2cDeviceName(path), |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 82 | #else |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 83 | fs::path(DEV_PATH) / |
| 84 | fs::path(sysfsName + "." + std::to_string(instance + 1)), |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 85 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 86 | manager, *this, |
| 87 | std::bind(std::mem_fn(&Status::deviceErrorHandler), this, |
| 88 | std::placeholders::_1)), |
| 89 | hostControlSignal( |
| 90 | bus, |
| 91 | sdbusRule::type::signal() + sdbusRule::member("CommandComplete") + |
| 92 | sdbusRule::path("/org/open_power/control/host0") + |
| 93 | sdbusRule::interface("org.open_power.Control.Host") + |
| 94 | sdbusRule::argN(0, Control::convertForMessage( |
| 95 | Control::Host::Command::OCCReset)), |
| 96 | std::bind(std::mem_fn(&Status::hostControlEvent), this, |
| 97 | std::placeholders::_1)) |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 98 | #ifdef PLDM |
| 99 | , |
| 100 | resetCallBack(resetCallBack) |
| 101 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 102 | { |
| 103 | // Check to see if we have OCC already bound. If so, just set it |
| 104 | if (device.bound()) |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 105 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 106 | this->occActive(true); |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 107 | } |
| 108 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 109 | // Announce that we are ready |
| 110 | this->emit_object_added(); |
| 111 | } |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 112 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 113 | /** @brief Since we are overriding the setter-occActive but not the |
| 114 | * getter-occActive, we need to have this using in order to |
| 115 | * allow passthrough usage of the getter-occActive |
| 116 | */ |
| 117 | using Base::Status::occActive; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 118 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 119 | /** @brief SET OccActive to True or False |
| 120 | * |
| 121 | * @param[in] value - Intended value |
| 122 | * |
| 123 | * @return - Updated value of the property |
| 124 | */ |
| 125 | bool occActive(bool value) override; |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 126 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 127 | /** @brief Starts OCC error detection */ |
| 128 | inline void addErrorWatch() |
| 129 | { |
| 130 | return device.addErrorWatch(); |
| 131 | } |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 132 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 133 | /** @brief Stops OCC error detection */ |
| 134 | inline void removeErrorWatch() |
| 135 | { |
| 136 | return device.removeErrorWatch(); |
| 137 | } |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 138 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 139 | /** @brief Starts to watch how many OCCs are present on the master */ |
| 140 | inline void addPresenceWatchMaster() |
| 141 | { |
| 142 | return device.addPresenceWatchMaster(); |
| 143 | } |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 144 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 145 | private: |
| 146 | /** @brief sdbus handle */ |
| 147 | sdbusplus::bus::bus& bus; |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 148 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 149 | /** @brief OCC dbus object path */ |
| 150 | std::string path; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 151 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 152 | /** @brief Callback handler to be invoked during property change. |
| 153 | * This is a handler in Manager class |
| 154 | */ |
| 155 | std::function<void(bool)> callBack; |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 156 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 157 | /** @brief OCC instance number. Ex, 0,1, etc */ |
| 158 | int instance; |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 159 | |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 160 | /** @brief OCC instance to Sensor definitions mapping */ |
| 161 | static const std::map<instanceID, sensorDefs> sensorMap; |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 162 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 163 | /** @brief OCC device object to do bind and unbind */ |
| 164 | Device device; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 165 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 166 | /** @brief Subscribe to host control signal |
| 167 | * |
| 168 | * Once the OCC reset is requested, BMC sends that message to host. |
| 169 | * If the host does not ack the message, then there would be a timeout |
| 170 | * and we need to catch that to log an error |
| 171 | **/ |
| 172 | sdbusplus::bus::match_t hostControlSignal; |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 173 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 174 | /** @brief Callback handler when device errors are detected |
| 175 | * |
| 176 | * @param[in] error - True if an error is reported, false otherwise |
| 177 | */ |
| 178 | void deviceErrorHandler(bool error); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 179 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 180 | /** @brief Callback function on host control signals |
| 181 | * |
| 182 | * @param[in] msg - Data associated with subscribed signal |
| 183 | */ |
| 184 | void hostControlEvent(sdbusplus::message::message& msg); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 185 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 186 | /** @brief Sends a message to host control command handler to reset OCC |
| 187 | */ |
| 188 | void resetOCC(); |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 189 | |
| 190 | /** @brief Determines the instance ID by specified object path. |
| 191 | * @param[in] path Estimated OCC Dbus object path |
| 192 | * @return Instance number |
| 193 | */ |
| 194 | static int getInstance(const std::string& path) |
| 195 | { |
| 196 | return (path.empty() ? 0 : path.back() - '0'); |
| 197 | } |
| 198 | |
| 199 | /** @brief Override the sensor name with name from the definition. |
| 200 | * @param[in] estimatedPath - Estimated OCC Dbus object path |
| 201 | * @return Fixed OCC DBus object path |
| 202 | */ |
| 203 | static std::string getDbusPath(const std::string& estimatedPath) |
| 204 | { |
| 205 | if (!estimatedPath.empty()) |
| 206 | { |
| 207 | auto it = sensorMap.find(getInstance(estimatedPath)); |
| 208 | if (sensorMap.end() != it) |
| 209 | { |
| 210 | auto& name = std::get<1>(it->second); |
| 211 | if (!name.empty() && name != "None") |
| 212 | { |
| 213 | auto path = fs::path(estimatedPath); |
| 214 | path.replace_filename(name); |
| 215 | return path.string(); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | return estimatedPath; |
| 221 | } |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 222 | #ifdef PLDM |
| 223 | std::function<void(instanceID)> resetCallBack = nullptr; |
| 224 | #endif |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | } // namespace occ |
| 228 | } // namespace open_power |