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" |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 10 | namespace open_power |
| 11 | { |
| 12 | namespace occ |
| 13 | { |
| 14 | |
| 15 | namespace Base = sdbusplus::org::open_power::OCC::server; |
| 16 | using Interface = sdbusplus::server::object::object<Base::Status>; |
| 17 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 18 | // IPMID's host control application |
| 19 | namespace Control = sdbusplus::org::open_power::Control::server; |
| 20 | |
| 21 | // For waiting on signals |
| 22 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 23 | |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 24 | // OCC status instance. Ex. for "occ0", the instance is 0 |
| 25 | using instanceID = int; |
| 26 | |
| 27 | // IPMI sensor ID for a given OCC instance |
| 28 | using sensorID = uint8_t; |
| 29 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 30 | /** @class Status |
| 31 | * @brief Implementation of OCC Active Status |
| 32 | */ |
| 33 | class Status : public Interface |
| 34 | { |
| 35 | public: |
| 36 | Status() = delete; |
| 37 | ~Status() = default; |
| 38 | Status(const Status&) = delete; |
| 39 | Status& operator=(const Status&) = delete; |
| 40 | Status(Status&&) = default; |
| 41 | Status& operator=(Status&&) = default; |
| 42 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 43 | /** @brief Constructs the Status object and |
| 44 | * the underlying device object |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 45 | * |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame^] | 46 | * @param[in] bus - DBus bus to attach to |
| 47 | * @param[in] event - sd_event unique pointer reference |
| 48 | * @param[in] path - DBus object path |
| 49 | * @param[in] callBack - Callback handler to invoke during |
| 50 | * property change |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 51 | */ |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame^] | 52 | Status(sdbusplus::bus::bus& bus, |
| 53 | EventPtr& event, |
| 54 | const char* path, |
| 55 | std::function<void(bool)> callBack = nullptr) |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 56 | : Interface(bus, path), |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 57 | bus(bus), |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 58 | path(path), |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame^] | 59 | callBack(callBack), |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 60 | instance(((this->path.back() - '0'))), |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 61 | device(event, |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 62 | name + std::to_string(instance + 1), |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 63 | std::bind(&Status::deviceErrorHandler, this)), |
| 64 | hostControlSignal( |
| 65 | bus, |
| 66 | sdbusRule::type::signal() + |
| 67 | sdbusRule::member("CommandComplete") + |
| 68 | sdbusRule::path("/org/open_power/control/host0") + |
| 69 | sdbusRule::interface("org.open_power.Control.Host") + |
| 70 | sdbusRule::argN(0, Control::convertForMessage( |
| 71 | Control::Host::Command::OCCReset)), |
| 72 | std::bind(std::mem_fn(&Status::hostControlEvent), |
| 73 | this, std::placeholders::_1)) |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 74 | { |
| 75 | // Nothing to do here |
| 76 | } |
| 77 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 78 | /** @brief Since we are overriding the setter-occActive but not the |
| 79 | * getter-occActive, we need to have this using in order to |
| 80 | * allow passthrough usage of the getter-occActive |
| 81 | */ |
| 82 | using Base::Status::occActive; |
| 83 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 84 | /** @brief SET OccActive to True or False |
| 85 | * |
| 86 | * @param[in] value - Intended value |
| 87 | * |
| 88 | * @return - Updated value of the property |
| 89 | */ |
| 90 | bool occActive(bool value) override; |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 91 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame^] | 92 | /** @brief Starts OCC error detection */ |
| 93 | inline void addErrorWatch() |
| 94 | { |
| 95 | return device.addErrorWatch(); |
| 96 | } |
| 97 | |
| 98 | /** @brief Stops OCC error detection */ |
| 99 | inline void removeErrorWatch() |
| 100 | { |
| 101 | return device.removeErrorWatch(); |
| 102 | } |
| 103 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 104 | private: |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 105 | |
| 106 | /** @brief sdbus handle */ |
| 107 | sdbusplus::bus::bus& bus; |
| 108 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 109 | /** @brief OCC dbus object path */ |
| 110 | std::string path; |
| 111 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame^] | 112 | /** @brief Callback handler to be invoked during property change. |
| 113 | * This is a handler in Manager class |
| 114 | */ |
| 115 | std::function<void(bool)> callBack; |
| 116 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 117 | /** @brief occ name prefix */ |
| 118 | std::string name = OCC_NAME; |
| 119 | |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 120 | /** @brief OCC instance number. Ex, 0,1, etc */ |
| 121 | int instance; |
| 122 | |
| 123 | /** @brief OCC instance to Sensor ID mapping */ |
| 124 | static const std::map<instanceID, sensorID> sensorMap; |
| 125 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 126 | /** @brief OCC device object to do bind and unbind */ |
| 127 | Device device; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 128 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 129 | /** @brief Subscribe to host control signal |
| 130 | * |
| 131 | * Once the OCC reset is requested, BMC sends that message to host. |
| 132 | * If the host does not ack the message, then there would be a timeout |
| 133 | * and we need to catch that to log an error |
| 134 | **/ |
| 135 | sdbusplus::bus::match_t hostControlSignal; |
| 136 | |
Vishwanatha Subbanna | d298105 | 2017-08-09 21:42:10 +0530 | [diff] [blame] | 137 | /** @brief Indicates whether a hub FSI scan has been attempted or not */ |
| 138 | static bool hubFsiScanDone; |
| 139 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 140 | /** @brief Callback handler when device errors are detected */ |
| 141 | void deviceErrorHandler(); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 142 | |
| 143 | /** @brief Callback function on host control signals |
| 144 | * |
| 145 | * @param[in] msg - Data associated with subscribed signal |
| 146 | */ |
| 147 | void hostControlEvent(sdbusplus::message::message& msg); |
| 148 | |
| 149 | /** @brief Sends a message to host control command handler to reset OCC |
| 150 | */ |
| 151 | void resetOCC(); |
Vishwanatha Subbanna | d298105 | 2017-08-09 21:42:10 +0530 | [diff] [blame] | 152 | |
| 153 | /** @brief Initiates hub FSI scan so that /dev/occ files are created |
| 154 | */ |
| 155 | void scanHubFSI(); |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | } // namespace occ |
| 159 | } // namespace open_power |