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