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 | |
Eddie James | e7d976b | 2018-02-26 13:42:45 -0600 | [diff] [blame] | 34 | // OCC sysfs name prefix |
| 35 | const std::string sysfsName = "occ-hwmon"; |
| 36 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 37 | /** @class Status |
| 38 | * @brief Implementation of OCC Active Status |
| 39 | */ |
| 40 | class Status : public Interface |
| 41 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 42 | public: |
| 43 | Status() = delete; |
| 44 | ~Status() = default; |
| 45 | Status(const Status&) = delete; |
| 46 | Status& operator=(const Status&) = delete; |
| 47 | Status(Status&&) = default; |
| 48 | Status& operator=(Status&&) = default; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 49 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 50 | /** @brief Constructs the Status object and |
| 51 | * the underlying device object |
| 52 | * |
| 53 | * @param[in] bus - DBus bus to attach to |
| 54 | * @param[in] event - sd_event unique pointer reference |
| 55 | * @param[in] path - DBus object path |
| 56 | * @param[in] manager - OCC manager instance |
| 57 | * @param[in] callBack - Callback handler to invoke during |
| 58 | * property change |
| 59 | */ |
| 60 | Status(sdbusplus::bus::bus& bus, EventPtr& event, const char* path, |
| 61 | const Manager& manager, |
| 62 | std::function<void(bool)> callBack = nullptr) : |
| 63 | Interface(bus, path, true), |
| 64 | bus(bus), path(path), callBack(callBack), |
| 65 | instance(((this->path.back() - '0'))), |
| 66 | device(event, |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 67 | #ifdef I2C_OCC |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 68 | i2c_occ::getI2cDeviceName(path), |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 69 | #else |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 70 | sysfsName + "." + std::to_string(instance + 1), |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 71 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 72 | manager, *this, |
| 73 | std::bind(std::mem_fn(&Status::deviceErrorHandler), this, |
| 74 | std::placeholders::_1)), |
| 75 | hostControlSignal( |
| 76 | bus, |
| 77 | sdbusRule::type::signal() + 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), this, |
| 83 | std::placeholders::_1)) |
| 84 | { |
| 85 | // Check to see if we have OCC already bound. If so, just set it |
| 86 | if (device.bound()) |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 87 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 88 | this->occActive(true); |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 89 | } |
| 90 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 91 | // Announce that we are ready |
| 92 | this->emit_object_added(); |
| 93 | } |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 94 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [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; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 100 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [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 | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 108 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 109 | /** @brief Starts OCC error detection */ |
| 110 | inline void addErrorWatch() |
| 111 | { |
| 112 | return device.addErrorWatch(); |
| 113 | } |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 114 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 115 | /** @brief Stops OCC error detection */ |
| 116 | inline void removeErrorWatch() |
| 117 | { |
| 118 | return device.removeErrorWatch(); |
| 119 | } |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 120 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 121 | /** @brief Starts to watch how many OCCs are present on the master */ |
| 122 | inline void addPresenceWatchMaster() |
| 123 | { |
| 124 | return device.addPresenceWatchMaster(); |
| 125 | } |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 126 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 127 | private: |
| 128 | /** @brief sdbus handle */ |
| 129 | sdbusplus::bus::bus& bus; |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 130 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 131 | /** @brief OCC dbus object path */ |
| 132 | std::string path; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 133 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 134 | /** @brief Callback handler to be invoked during property change. |
| 135 | * This is a handler in Manager class |
| 136 | */ |
| 137 | std::function<void(bool)> callBack; |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 138 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 139 | /** @brief OCC instance number. Ex, 0,1, etc */ |
| 140 | int instance; |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 141 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 142 | /** @brief OCC instance to Sensor ID mapping */ |
| 143 | static const std::map<instanceID, sensorID> sensorMap; |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 144 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [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 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [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; |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 155 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -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 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 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); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 167 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame^] | 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 |