Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 1 | #include "occ_status.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 2 | |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame^] | 3 | #include "occ_manager.hpp" |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame] | 4 | #include "occ_sensor.hpp" |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 5 | #include "powermode.hpp" |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 6 | #include "utils.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 7 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 8 | #include <fmt/core.h> |
| 9 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 10 | #ifdef POWER10 |
| 11 | #include <com/ibm/Host/Target/server.hpp> |
| 12 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 13 | #include <phosphor-logging/log.hpp> |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 14 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 15 | namespace open_power |
| 16 | { |
| 17 | namespace occ |
| 18 | { |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 19 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 20 | using namespace phosphor::logging; |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 21 | |
| 22 | // Handles updates to occActive property |
| 23 | bool Status::occActive(bool value) |
| 24 | { |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 25 | if (value != this->occActive()) |
| 26 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 27 | log<level::INFO>(fmt::format("Status::occActive OCC{} changed to {}", |
| 28 | instance, value) |
| 29 | .c_str()); |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 30 | if (value) |
| 31 | { |
| 32 | // Bind the device |
| 33 | device.bind(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 34 | |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 35 | // Start watching for errors |
| 36 | addErrorWatch(); |
| 37 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 38 | // Reset last OCC state |
| 39 | lastState = 0; |
| 40 | |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 41 | // Call into Manager to let know that we have bound |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 42 | if (this->callBack) |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 43 | { |
| 44 | this->callBack(value); |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 45 | } |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 46 | } |
| 47 | else |
| 48 | { |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 49 | // Call into Manager to let know that we will unbind. |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 50 | if (this->callBack) |
Vishwanatha Subbanna | 2dc9b1a | 2017-08-18 18:29:41 +0530 | [diff] [blame] | 51 | { |
| 52 | this->callBack(value); |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // Stop watching for errors |
| 56 | removeErrorWatch(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 57 | |
| 58 | // Do the unbind. |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 59 | device.unBind(); |
| 60 | } |
| 61 | } |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 62 | else if (value && !device.bound()) |
| 63 | { |
| 64 | // Existing error watch is on a dead file descriptor. |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 65 | removeErrorWatch(); |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * In it's constructor, Status checks Device::bound() to see if OCC is |
| 69 | * active or not. |
| 70 | * Device::bound() checks for occX-dev0 directory. |
| 71 | * We will lose occX-dev0 directories during FSI rescan. |
| 72 | * So, if we start this application (and construct Status), and then |
| 73 | * later do FSI rescan, we will end up with occActive = true and device |
| 74 | * NOT bound. Lets correct that situation here. |
| 75 | */ |
| 76 | device.bind(); |
| 77 | |
| 78 | // Add error watch again |
Edward A. James | 9fd2bdc | 2017-11-08 16:18:57 -0600 | [diff] [blame] | 79 | addErrorWatch(); |
Edward A. James | 5e17797 | 2017-10-25 15:50:31 -0500 | [diff] [blame] | 80 | } |
Eddie James | 6d6d1b3 | 2019-04-22 10:45:08 -0500 | [diff] [blame] | 81 | else if (!value && device.bound()) |
| 82 | { |
| 83 | removeErrorWatch(); |
| 84 | |
| 85 | // In the event that the application never receives the active signal |
| 86 | // even though the OCC is active (this can occur if the BMC is rebooted |
| 87 | // with the host on, since the initial OCC driver probe will discover |
| 88 | // the OCCs), this application needs to be able to unbind the device |
| 89 | // when we get the OCC inactive signal. |
| 90 | device.unBind(); |
| 91 | } |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 92 | return Base::Status::occActive(value); |
| 93 | } |
| 94 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 95 | // Callback handler when a device error is reported. |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 96 | void Status::deviceError() |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 97 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 98 | // This would deem OCC inactive |
| 99 | this->occActive(false); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 100 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 101 | // Reset the OCC |
| 102 | this->resetOCC(); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // Sends message to host control command handler to reset OCC |
| 106 | void Status::resetOCC() |
| 107 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 108 | log<level::INFO>( |
| 109 | fmt::format(">>Status::resetOCC() - requesting reset for OCC{}", |
| 110 | instance) |
| 111 | .c_str()); |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 112 | #ifdef PLDM |
| 113 | if (resetCallBack) |
| 114 | { |
| 115 | this->resetCallBack(instance); |
| 116 | } |
| 117 | #else |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 118 | constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0"; |
| 119 | constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host"; |
| 120 | |
| 121 | // This will throw exception on failure |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 122 | auto service = utils::getService(CONTROL_HOST_PATH, CONTROL_HOST_INTF); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 123 | |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 124 | auto& bus = utils::getBus(); |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 125 | auto method = bus.new_method_call(service.c_str(), CONTROL_HOST_PATH, |
| 126 | CONTROL_HOST_INTF, "Execute"); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 127 | // OCC Reset control command |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 128 | method.append(convertForMessage(Control::Host::Command::OCCReset).c_str()); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 129 | |
| 130 | // OCC Sensor ID for callout reasons |
Patrick Williams | e096270 | 2020-05-13 17:50:22 -0500 | [diff] [blame] | 131 | method.append(std::variant<uint8_t>(std::get<0>(sensorMap.at(instance)))); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 132 | bus.call_noreply(method); |
| 133 | return; |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 134 | #endif |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // Handler called by Host control command handler to convey the |
| 138 | // status of the executed command |
| 139 | void Status::hostControlEvent(sdbusplus::message::message& msg) |
| 140 | { |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 141 | std::string cmdCompleted{}; |
| 142 | std::string cmdStatus{}; |
| 143 | |
| 144 | msg.read(cmdCompleted, cmdStatus); |
| 145 | |
| 146 | log<level::DEBUG>("Host control signal values", |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 147 | entry("COMMAND=%s", cmdCompleted.c_str()), |
| 148 | entry("STATUS=%s", cmdStatus.c_str())); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 149 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 150 | if (Control::Host::convertResultFromString(cmdStatus) != |
| 151 | Control::Host::Result::Success) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 152 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 153 | if (Control::Host::convertCommandFromString(cmdCompleted) == |
| 154 | Control::Host::Command::OCCReset) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 155 | { |
Gunnar Mills | 85e6520 | 2018-04-08 15:01:54 -0500 | [diff] [blame] | 156 | // Must be a Timeout. Log an Error trace |
Alexander Filippov | 1d69e19 | 2019-03-21 18:12:07 +0300 | [diff] [blame] | 157 | log<level::ERR>( |
| 158 | "Error resetting the OCC.", entry("PATH=%s", path.c_str()), |
| 159 | entry("SENSORID=0x%X", std::get<0>(sensorMap.at(instance)))); |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | return; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 163 | } |
| 164 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 165 | void Status::readOccState() |
| 166 | { |
| 167 | unsigned int state; |
| 168 | const fs::path filename = |
| 169 | fs::path(DEV_PATH) / |
| 170 | fs::path(sysfsName + "." + std::to_string(instance + 1)) / "occ_state"; |
| 171 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 172 | std::ifstream file(filename, std::ios::in); |
| 173 | const int open_errno = errno; |
| 174 | if (file) |
| 175 | { |
| 176 | file >> state; |
| 177 | if (state != lastState) |
| 178 | { |
| 179 | // Trace OCC state changes |
| 180 | log<level::INFO>( |
| 181 | fmt::format("Status::readOccState: OCC{} state 0x{:02X}", |
| 182 | instance, state) |
| 183 | .c_str()); |
| 184 | lastState = state; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 185 | |
| 186 | #ifdef POWER10 |
| 187 | if ((OccState(state) == OccState::ACTIVE) && (device.master())) |
| 188 | { |
| 189 | // Kernel detected that the master OCC went to active state |
| 190 | occsWentActive(); |
| 191 | } |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame^] | 192 | if (OccState(state) == OccState::ACTIVE) |
| 193 | { |
| 194 | CmdStatus status = sendAmbient(); |
| 195 | if (status != CmdStatus::SUCCESS) |
| 196 | { |
| 197 | log<level::ERR>( |
| 198 | fmt::format( |
| 199 | "readOccState: Sending Ambient failed with status {}", |
| 200 | status) |
| 201 | .c_str()); |
| 202 | } |
| 203 | } |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 204 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 205 | } |
| 206 | file.close(); |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | // If not able to read, OCC may be offline |
| 211 | log<level::DEBUG>( |
| 212 | fmt::format("Status::readOccState: open failed (errno={})", |
| 213 | open_errno) |
| 214 | .c_str()); |
| 215 | lastState = 0; |
| 216 | } |
| 217 | } |
| 218 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 219 | #ifdef POWER10 |
| 220 | // Check if Hypervisor target is PowerVM |
| 221 | bool Status::isPowerVM() |
| 222 | { |
| 223 | using namespace open_power::occ::powermode; |
| 224 | namespace Hyper = sdbusplus::com::ibm::Host::server; |
| 225 | constexpr auto HYPE_PATH = "/com/ibm/host0/hypervisor"; |
| 226 | constexpr auto HYPE_INTERFACE = "com.ibm.Host.Target"; |
| 227 | constexpr auto HYPE_PROP = "Target"; |
| 228 | |
| 229 | bool powerVmTarget = false; |
| 230 | |
| 231 | // This will throw exception on failure |
| 232 | auto& bus = utils::getBus(); |
| 233 | auto service = utils::getService(HYPE_PATH, HYPE_INTERFACE); |
| 234 | auto method = bus.new_method_call(service.c_str(), HYPE_PATH, |
| 235 | "org.freedesktop.DBus.Properties", "Get"); |
| 236 | method.append(HYPE_INTERFACE, HYPE_PROP); |
| 237 | auto reply = bus.call(method); |
| 238 | |
| 239 | std::variant<std::string> hyperEntryValue; |
| 240 | reply.read(hyperEntryValue); |
| 241 | auto propVal = std::get<std::string>(hyperEntryValue); |
| 242 | if (Hyper::Target::convertHypervisorFromString(propVal) == |
| 243 | Hyper::Target::Hypervisor::PowerVM) |
| 244 | { |
| 245 | powerVmTarget = true; |
| 246 | } |
| 247 | |
| 248 | log<level::DEBUG>( |
| 249 | fmt::format("Status::isPowerVM returning {}", powerVmTarget).c_str()); |
| 250 | |
| 251 | return powerVmTarget; |
| 252 | } |
| 253 | |
| 254 | // Get the requested power mode |
| 255 | SysPwrMode Status::getMode() |
| 256 | { |
| 257 | using namespace open_power::occ::powermode; |
| 258 | SysPwrMode pmode = SysPwrMode::NO_CHANGE; |
| 259 | |
| 260 | // This will throw exception on failure |
| 261 | auto& bus = utils::getBus(); |
| 262 | auto service = utils::getService(PMODE_PATH, PMODE_INTERFACE); |
| 263 | auto method = bus.new_method_call(service.c_str(), PMODE_PATH, |
| 264 | "org.freedesktop.DBus.Properties", "Get"); |
| 265 | method.append(PMODE_INTERFACE, POWER_MODE_PROP); |
| 266 | auto reply = bus.call(method); |
| 267 | |
| 268 | std::variant<std::string> stateEntryValue; |
| 269 | reply.read(stateEntryValue); |
| 270 | auto propVal = std::get<std::string>(stateEntryValue); |
| 271 | pmode = powermode::convertStringToMode(propVal); |
| 272 | |
| 273 | log<level::DEBUG>( |
| 274 | fmt::format("Status::getMode returning {}", pmode).c_str()); |
| 275 | |
| 276 | return pmode; |
| 277 | } |
| 278 | |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 279 | // Get the requested power mode |
| 280 | bool Status::getIPSParms(uint8_t& enterUtil, uint16_t& enterTime, |
| 281 | uint8_t& exitUtil, uint16_t& exitTime) |
| 282 | { |
| 283 | using namespace open_power::occ::powermode; |
| 284 | // Defaults: |
| 285 | bool ipsEnabled = false; // Disabled |
| 286 | enterUtil = 8; // Enter Utilization (8%) |
| 287 | enterTime = 240; // Enter Delay Time (240s) |
| 288 | exitUtil = 12; // Exit Utilization (12%) |
| 289 | exitTime = 10; // Exit Delay Time (10s) |
| 290 | |
| 291 | std::map<std::string, std::variant<bool, uint8_t, uint64_t>> |
| 292 | ipsProperties{}; |
| 293 | |
| 294 | // Get all IPS properties from DBus |
| 295 | try |
| 296 | { |
| 297 | auto& bus = utils::getBus(); |
| 298 | auto service = utils::getService(PIPS_PATH, PIPS_INTERFACE); |
| 299 | auto method = |
| 300 | bus.new_method_call(service.c_str(), PIPS_PATH, |
| 301 | "org.freedesktop.DBus.Properties", "GetAll"); |
| 302 | method.append(PIPS_INTERFACE); |
| 303 | auto reply = bus.call(method); |
| 304 | reply.read(ipsProperties); |
| 305 | } |
| 306 | catch (const sdbusplus::exception::exception& e) |
| 307 | { |
| 308 | log<level::ERR>( |
| 309 | fmt::format( |
| 310 | "Unable to read Idle Power Saver parameters so it will be disabled: {}", |
| 311 | e.what()) |
| 312 | .c_str()); |
| 313 | return ipsEnabled; |
| 314 | } |
| 315 | |
| 316 | auto ipsEntry = ipsProperties.find(IPS_ENABLED_PROP); |
| 317 | if (ipsEntry != ipsProperties.end()) |
| 318 | { |
| 319 | ipsEnabled = std::get<bool>(ipsEntry->second); |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | log<level::ERR>( |
| 324 | fmt::format("Status::getIPSParms could not find property: {}", |
| 325 | IPS_ENABLED_PROP) |
| 326 | .c_str()); |
| 327 | } |
| 328 | |
| 329 | ipsEntry = ipsProperties.find(IPS_ENTER_UTIL); |
| 330 | if (ipsEntry != ipsProperties.end()) |
| 331 | { |
| 332 | enterUtil = std::get<uint8_t>(ipsEntry->second); |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | log<level::ERR>( |
| 337 | fmt::format("Status::getIPSParms could not find property: {}", |
| 338 | IPS_ENTER_UTIL) |
| 339 | .c_str()); |
| 340 | } |
| 341 | |
| 342 | ipsEntry = ipsProperties.find(IPS_ENTER_TIME); |
| 343 | if (ipsEntry != ipsProperties.end()) |
| 344 | { |
| 345 | std::chrono::milliseconds ms(std::get<uint64_t>(ipsEntry->second)); |
| 346 | enterTime = |
| 347 | std::chrono::duration_cast<std::chrono::seconds>(ms).count(); |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | log<level::ERR>( |
| 352 | fmt::format("Status::getIPSParms could not find property: {}", |
| 353 | IPS_ENTER_TIME) |
| 354 | .c_str()); |
| 355 | } |
| 356 | |
| 357 | ipsEntry = ipsProperties.find(IPS_EXIT_UTIL); |
| 358 | if (ipsEntry != ipsProperties.end()) |
| 359 | { |
| 360 | exitUtil = std::get<uint8_t>(ipsEntry->second); |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | log<level::ERR>( |
| 365 | fmt::format("Status::getIPSParms could not find property: {}", |
| 366 | IPS_EXIT_UTIL) |
| 367 | .c_str()); |
| 368 | } |
| 369 | |
| 370 | ipsEntry = ipsProperties.find(IPS_EXIT_TIME); |
| 371 | if (ipsEntry != ipsProperties.end()) |
| 372 | { |
| 373 | std::chrono::milliseconds ms(std::get<uint64_t>(ipsEntry->second)); |
| 374 | exitTime = std::chrono::duration_cast<std::chrono::seconds>(ms).count(); |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | log<level::ERR>( |
| 379 | fmt::format("Status::getIPSParms could not find property: {}", |
| 380 | IPS_EXIT_TIME) |
| 381 | .c_str()); |
| 382 | } |
| 383 | |
| 384 | if (enterUtil > exitUtil) |
| 385 | { |
| 386 | log<level::ERR>( |
| 387 | fmt::format( |
| 388 | "ERROR: Idle Power Saver Enter Utilization ({}%) is > Exit Utilization ({}%) - using Exit for both", |
| 389 | enterUtil, exitUtil) |
| 390 | .c_str()); |
| 391 | enterUtil = exitUtil; |
| 392 | } |
| 393 | |
| 394 | return ipsEnabled; |
| 395 | } |
| 396 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 397 | // Special processing that needs to happen once the OCCs change to ACTIVE state |
| 398 | void Status::occsWentActive() |
| 399 | { |
| 400 | CmdStatus status = CmdStatus::SUCCESS; |
| 401 | |
| 402 | status = sendModeChange(); |
| 403 | if (status != CmdStatus::SUCCESS) |
| 404 | { |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 405 | log<level::ERR>( |
| 406 | fmt::format( |
| 407 | "Status::occsWentActive: OCC mode change failed with status {}", |
| 408 | status) |
| 409 | .c_str()); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | status = sendIpsData(); |
| 413 | if (status != CmdStatus::SUCCESS) |
| 414 | { |
| 415 | log<level::ERR>( |
| 416 | fmt::format( |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 417 | "Status::occsWentActive: Sending Idle Power Save Config data failed with status {}", |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 418 | status) |
| 419 | .c_str()); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | // Send mode change request to the master OCC |
| 424 | CmdStatus Status::sendModeChange() |
| 425 | { |
| 426 | CmdStatus status = CmdStatus::FAILURE; |
| 427 | |
| 428 | if (!device.master()) |
| 429 | { |
| 430 | log<level::ERR>( |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 431 | fmt::format( |
| 432 | "Status::sendModeChange: MODE CHANGE does not get sent to slave OCC{}", |
| 433 | instance) |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 434 | .c_str()); |
| 435 | return status; |
| 436 | } |
| 437 | if (!isPowerVM()) |
| 438 | { |
| 439 | // Mode change is only supported on PowerVM systems |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 440 | log<level::DEBUG>( |
| 441 | "Status::sendModeChange: MODE CHANGE does not get sent on non-PowerVM systems"); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 442 | return CmdStatus::SUCCESS; |
| 443 | } |
| 444 | |
| 445 | const SysPwrMode newMode = getMode(); |
| 446 | |
| 447 | if (VALID_POWER_MODE_SETTING(newMode)) |
| 448 | { |
| 449 | std::vector<std::uint8_t> cmd, rsp; |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 450 | cmd.reserve(9); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 451 | cmd.push_back(uint8_t(CmdType::SET_MODE_AND_STATE)); |
| 452 | cmd.push_back(0x00); // Data Length (2 bytes) |
| 453 | cmd.push_back(0x06); |
| 454 | cmd.push_back(0x30); // Data (Version) |
| 455 | cmd.push_back(uint8_t(OccState::NO_CHANGE)); |
| 456 | cmd.push_back(uint8_t(newMode)); |
| 457 | cmd.push_back(0x00); // Mode Data (Freq Point) |
| 458 | cmd.push_back(0x00); // |
| 459 | cmd.push_back(0x00); // reserved |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 460 | log<level::INFO>( |
| 461 | fmt::format( |
| 462 | "Status::sendModeChange: SET_MODE({}) command to OCC{} ({} bytes)", |
| 463 | newMode, instance, cmd.size()) |
| 464 | .c_str()); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 465 | status = occCmd.send(cmd, rsp); |
| 466 | if (status == CmdStatus::SUCCESS) |
| 467 | { |
| 468 | if (rsp.size() == 5) |
| 469 | { |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 470 | if (RspStatus::SUCCESS != RspStatus(rsp[2])) |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 471 | { |
| 472 | log<level::ERR>( |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 473 | fmt::format( |
| 474 | "Status::sendModeChange: SET MODE failed with status 0x{:02X}", |
| 475 | rsp[2]) |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 476 | .c_str()); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 477 | dump_hex(rsp); |
| 478 | status = CmdStatus::FAILURE; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | log<level::ERR>( |
| 484 | "Status::sendModeChange: INVALID SET MODE response"); |
| 485 | dump_hex(rsp); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 486 | status = CmdStatus::FAILURE; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | else |
| 490 | { |
| 491 | if (status == CmdStatus::OPEN_FAILURE) |
| 492 | { |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 493 | log<level::INFO>("Status::sendModeChange: OCC not active yet"); |
| 494 | status = CmdStatus::SUCCESS; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 495 | } |
| 496 | else |
| 497 | { |
| 498 | log<level::ERR>("Status::sendModeChange: SET_MODE FAILED!"); |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | log<level::ERR>( |
| 505 | fmt::format( |
| 506 | "Status::sendModeChange: Unable to set power mode to {}", |
| 507 | newMode) |
| 508 | .c_str()); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 509 | status = CmdStatus::FAILURE; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | return status; |
| 513 | } |
| 514 | |
| 515 | // Send Idle Power Saver config data to the master OCC |
| 516 | CmdStatus Status::sendIpsData() |
| 517 | { |
| 518 | CmdStatus status = CmdStatus::FAILURE; |
| 519 | |
| 520 | if (!device.master()) |
| 521 | { |
| 522 | log<level::ERR>( |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 523 | fmt::format( |
| 524 | "Status::sendIpsData: SET_CFG_DATA[IPS] does not get sent to slave OCC{}", |
| 525 | instance) |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 526 | .c_str()); |
| 527 | return status; |
| 528 | } |
| 529 | if (!isPowerVM()) |
| 530 | { |
| 531 | // Idle Power Saver data is only supported on PowerVM systems |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 532 | log<level::DEBUG>( |
| 533 | "Status::sendIpsData: SET_CFG_DATA[IPS] does not get sent on non-PowerVM systems"); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 534 | return CmdStatus::SUCCESS; |
| 535 | } |
| 536 | |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 537 | uint8_t enterUtil, exitUtil; |
| 538 | uint16_t enterTime, exitTime; |
| 539 | const bool ipsEnabled = |
| 540 | getIPSParms(enterUtil, enterTime, exitUtil, exitTime); |
| 541 | |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 542 | log<level::INFO>( |
| 543 | fmt::format( |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 544 | "Idle Power Saver Parameters: enabled:{}, enter:{}%/{}s, exit:{}%/{}s", |
| 545 | ipsEnabled, enterUtil, enterTime, exitUtil, exitTime) |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 546 | .c_str()); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 547 | |
| 548 | std::vector<std::uint8_t> cmd, rsp; |
| 549 | cmd.reserve(12); |
| 550 | cmd.push_back(uint8_t(CmdType::SET_CONFIG_DATA)); |
| 551 | cmd.push_back(0x00); // Data Length (2 bytes) |
| 552 | cmd.push_back(0x09); // |
| 553 | cmd.push_back(0x11); // Config Format: IPS Settings |
| 554 | cmd.push_back(0x00); // Version |
| 555 | cmd.push_back(ipsEnabled ? 1 : 0); // IPS Enable |
| 556 | cmd.push_back(enterTime >> 8); // Enter Delay Time |
| 557 | cmd.push_back(enterTime & 0xFF); // |
| 558 | cmd.push_back(enterUtil); // Enter Utilization |
| 559 | cmd.push_back(exitTime >> 8); // Exit Delay Time |
| 560 | cmd.push_back(exitTime & 0xFF); // |
| 561 | cmd.push_back(exitUtil); // Exit Utilization |
| 562 | log<level::INFO>(fmt::format("Status::sendIpsData: SET_CFG_DATA[IPS] " |
| 563 | "command to OCC{} ({} bytes)", |
| 564 | instance, cmd.size()) |
| 565 | .c_str()); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 566 | status = occCmd.send(cmd, rsp); |
| 567 | if (status == CmdStatus::SUCCESS) |
| 568 | { |
| 569 | if (rsp.size() == 5) |
| 570 | { |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 571 | if (RspStatus::SUCCESS != RspStatus(rsp[2])) |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 572 | { |
| 573 | log<level::ERR>( |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 574 | fmt::format( |
| 575 | "Status::sendIpsData: SET_CFG_DATA[IPS] failed with status 0x{:02X}", |
| 576 | rsp[2]) |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 577 | .c_str()); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 578 | dump_hex(rsp); |
| 579 | status = CmdStatus::FAILURE; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | else |
| 583 | { |
| 584 | log<level::ERR>( |
| 585 | "Status::sendIpsData: INVALID SET_CFG_DATA[IPS] response"); |
| 586 | dump_hex(rsp); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 587 | status = CmdStatus::FAILURE; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | else |
| 591 | { |
| 592 | if (status == CmdStatus::OPEN_FAILURE) |
| 593 | { |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 594 | log<level::INFO>("Status::sendIpsData: OCC not active yet"); |
| 595 | status = CmdStatus::SUCCESS; |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 596 | } |
| 597 | else |
| 598 | { |
| 599 | log<level::ERR>("Status::sendIpsData: SET_CFG_DATA[IPS] FAILED!"); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | return status; |
| 604 | } |
| 605 | |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame^] | 606 | // Send Ambient and Altitude to the OCC |
| 607 | CmdStatus Status::sendAmbient(const uint8_t inTemp, const uint16_t inAltitude) |
| 608 | { |
| 609 | CmdStatus status = CmdStatus::FAILURE; |
| 610 | bool ambientValid = true; |
| 611 | uint8_t ambientTemp = inTemp; |
| 612 | uint16_t altitude = inAltitude; |
| 613 | |
| 614 | if (ambientTemp == 0xFF) |
| 615 | { |
| 616 | // Get latest readings from manager |
| 617 | manager.getAmbientData(ambientValid, ambientTemp, altitude); |
| 618 | log<level::DEBUG>( |
| 619 | fmt::format("sendAmbient: valid: {}, Ambient: {}C, altitude: {}m", |
| 620 | ambientValid, ambientTemp, altitude) |
| 621 | .c_str()); |
| 622 | } |
| 623 | |
| 624 | std::vector<std::uint8_t> cmd, rsp; |
| 625 | cmd.reserve(11); |
| 626 | cmd.push_back(uint8_t(CmdType::SEND_AMBIENT)); |
| 627 | cmd.push_back(0x00); // Data Length (2 bytes) |
| 628 | cmd.push_back(0x08); // |
| 629 | cmd.push_back(0x00); // Version |
| 630 | cmd.push_back(ambientValid ? 0 : 0xFF); // Ambient Status |
| 631 | cmd.push_back(ambientTemp); // Ambient Temperature |
| 632 | cmd.push_back(altitude >> 8); // Altitude in meters (2 bytes) |
| 633 | cmd.push_back(altitude & 0xFF); // |
| 634 | cmd.push_back(0x00); // Reserved (3 bytes) |
| 635 | cmd.push_back(0x00); |
| 636 | cmd.push_back(0x00); |
| 637 | log<level::DEBUG>(fmt::format("sendAmbient: SEND_AMBIENT " |
| 638 | "command to OCC{} ({} bytes)", |
| 639 | instance, cmd.size()) |
| 640 | .c_str()); |
| 641 | status = occCmd.send(cmd, rsp); |
| 642 | if (status == CmdStatus::SUCCESS) |
| 643 | { |
| 644 | if (rsp.size() == 5) |
| 645 | { |
| 646 | if (RspStatus::SUCCESS != RspStatus(rsp[2])) |
| 647 | { |
| 648 | log<level::ERR>( |
| 649 | fmt::format( |
| 650 | "sendAmbient: SEND_AMBIENT failed with status 0x{:02X}", |
| 651 | rsp[2]) |
| 652 | .c_str()); |
| 653 | dump_hex(rsp); |
| 654 | status = CmdStatus::FAILURE; |
| 655 | } |
| 656 | } |
| 657 | else |
| 658 | { |
| 659 | log<level::ERR>("sendAmbient: INVALID SEND_AMBIENT response"); |
| 660 | dump_hex(rsp); |
| 661 | status = CmdStatus::FAILURE; |
| 662 | } |
| 663 | } |
| 664 | else |
| 665 | { |
| 666 | if (status == CmdStatus::OPEN_FAILURE) |
| 667 | { |
| 668 | // OCC not active yet |
| 669 | status = CmdStatus::SUCCESS; |
| 670 | } |
| 671 | else |
| 672 | { |
| 673 | log<level::ERR>("sendAmbient: SEND_AMBIENT FAILED!"); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | return status; |
| 678 | } |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 679 | #endif // POWER10 |
| 680 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 681 | } // namespace occ |
| 682 | } // namespace open_power |