blob: 078447cf661d1fb8d5aa522d1b988249f2e7d3ed [file] [log] [blame]
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +05301#include "occ_status.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05002
Chris Cain17257672021-10-22 13:41:03 -05003#include "occ_manager.hpp"
Vishwanatha Subbanna6add0b82017-07-21 19:02:37 +05304#include "occ_sensor.hpp"
Chris Cain78e86012021-03-04 16:15:31 -06005#include "powermode.hpp"
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05306#include "utils.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05007
8#include <phosphor-logging/log.hpp>
Chris Cain78e86012021-03-04 16:15:31 -06009
Chris Caine2d0a432022-03-28 11:08:49 -050010#include <filesystem>
Patrick Williams48002492024-02-13 21:43:32 -060011#include <format>
Chris Caine2d0a432022-03-28 11:08:49 -050012
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053013namespace open_power
14{
15namespace occ
16{
Chris Cain78e86012021-03-04 16:15:31 -060017
Chris Caina8857c52021-01-27 11:53:05 -060018using namespace phosphor::logging;
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053019
Chris Cainc86d80f2023-05-04 15:49:18 -050020using ThrottleObj =
21 sdbusplus::xyz::openbmc_project::Control::Power::server::Throttle;
22
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +053023// Handles updates to occActive property
24bool Status::occActive(bool value)
25{
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053026 if (value != this->occActive())
27 {
Patrick Williams48002492024-02-13 21:43:32 -060028 log<level::INFO>(std::format("Status::occActive OCC{} changed to {}",
Chris Caina8857c52021-01-27 11:53:05 -060029 instance, value)
30 .c_str());
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053031 if (value)
32 {
Chris Cainc86d80f2023-05-04 15:49:18 -050033 // Clear prior throttle reason (before setting device active)
34 updateThrottle(false, THROTTLED_ALL);
35
Eddie Jamesaced3092022-04-22 16:19:30 -050036 // Set the device active
37 device.setActive(true);
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053038
Chris Cain6d8f37a2022-04-29 13:46:01 -050039 // Update the OCC active sensor
40 Base::Status::occActive(value);
41
Edward A. James9fd2bdc2017-11-08 16:18:57 -060042 // Start watching for errors
43 addErrorWatch();
44
Chris Caina8857c52021-01-27 11:53:05 -060045 // Reset last OCC state
46 lastState = 0;
47
Chris Cain5d66a0a2022-02-09 08:52:10 -060048 if (device.master())
49 {
Chris Cain5d66a0a2022-02-09 08:52:10 -060050 // Update powercap bounds from OCC
Chris Cain40501a22022-03-14 17:33:27 -050051 manager.updatePcapBounds();
Chris Cain5d66a0a2022-02-09 08:52:10 -060052 }
53
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053054 // Call into Manager to let know that we have bound
Chris Cain1be43372021-12-09 19:29:37 -060055 if (this->managerCallBack)
Vishwanatha Subbanna2dc9b1a2017-08-18 18:29:41 +053056 {
Sheldon Bailey373af752022-02-21 15:14:00 -060057 this->managerCallBack(instance, value);
Edward A. James9fd2bdc2017-11-08 16:18:57 -060058 }
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053059 }
60 else
61 {
Chris Caina7b74dc2021-11-10 17:03:43 -060062#ifdef POWER10
Chris Cain1be43372021-12-09 19:29:37 -060063 if (pmode && device.master())
Chris Cain36f9cde2021-11-22 11:18:21 -060064 {
65 // Prevent mode changes
66 pmode->setMasterActive(false);
67 }
Chris Caina7b74dc2021-11-10 17:03:43 -060068 if (safeStateDelayTimer.isEnabled())
69 {
70 // stop safe delay timer
71 safeStateDelayTimer.setEnabled(false);
72 }
73#endif
Chris Cain36f9cde2021-11-22 11:18:21 -060074 // Call into Manager to let know that we will unbind.
Chris Cain1be43372021-12-09 19:29:37 -060075 if (this->managerCallBack)
Chris Cain36f9cde2021-11-22 11:18:21 -060076 {
Sheldon Bailey373af752022-02-21 15:14:00 -060077 this->managerCallBack(instance, value);
Chris Cain36f9cde2021-11-22 11:18:21 -060078 }
79
Edward A. James9fd2bdc2017-11-08 16:18:57 -060080 // Stop watching for errors
81 removeErrorWatch();
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053082
Eddie Jamesaced3092022-04-22 16:19:30 -050083 // Set the device inactive
84 device.setActive(false);
Chris Cainc86d80f2023-05-04 15:49:18 -050085
86 // Clear throttles (OCC not active after disabling device)
87 updateThrottle(false, THROTTLED_ALL);
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053088 }
89 }
Eddie Jamesaced3092022-04-22 16:19:30 -050090 else if (value && !device.active())
Edward A. James5e177972017-10-25 15:50:31 -050091 {
92 // Existing error watch is on a dead file descriptor.
Edward A. James9fd2bdc2017-11-08 16:18:57 -060093 removeErrorWatch();
Edward A. James5e177972017-10-25 15:50:31 -050094
95 /*
96 * In it's constructor, Status checks Device::bound() to see if OCC is
97 * active or not.
98 * Device::bound() checks for occX-dev0 directory.
99 * We will lose occX-dev0 directories during FSI rescan.
100 * So, if we start this application (and construct Status), and then
101 * later do FSI rescan, we will end up with occActive = true and device
102 * NOT bound. Lets correct that situation here.
103 */
Eddie Jamesaced3092022-04-22 16:19:30 -0500104 device.setActive(true);
Edward A. James5e177972017-10-25 15:50:31 -0500105
106 // Add error watch again
Edward A. James9fd2bdc2017-11-08 16:18:57 -0600107 addErrorWatch();
Edward A. James5e177972017-10-25 15:50:31 -0500108 }
Eddie Jamesaced3092022-04-22 16:19:30 -0500109 else if (!value && device.active())
Eddie James6d6d1b32019-04-22 10:45:08 -0500110 {
111 removeErrorWatch();
112
113 // In the event that the application never receives the active signal
114 // even though the OCC is active (this can occur if the BMC is rebooted
115 // with the host on, since the initial OCC driver probe will discover
116 // the OCCs), this application needs to be able to unbind the device
117 // when we get the OCC inactive signal.
Eddie Jamesaced3092022-04-22 16:19:30 -0500118 device.setActive(false);
Eddie James6d6d1b32019-04-22 10:45:08 -0500119 }
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530120 return Base::Status::occActive(value);
121}
122
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530123// Callback handler when a device error is reported.
Eddie James9789e712022-05-25 15:43:40 -0500124void Status::deviceError(Error::Descriptor d)
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530125{
Chris Cain36f9cde2021-11-22 11:18:21 -0600126#ifdef POWER10
Chris Cain1be43372021-12-09 19:29:37 -0600127 if (pmode && device.master())
128 {
129 // Prevent mode changes
130 pmode->setMasterActive(false);
131 }
Chris Cain36f9cde2021-11-22 11:18:21 -0600132#endif
133
Eddie James9789e712022-05-25 15:43:40 -0500134 if (d.log)
135 {
136 FFDC::createOCCResetPEL(instance, d.path, d.err, d.callout);
137 }
138
Eddie Jamescbad2192021-10-07 09:39:39 -0500139 // This would deem OCC inactive
140 this->occActive(false);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530141
Eddie Jamescbad2192021-10-07 09:39:39 -0500142 // Reset the OCC
143 this->resetOCC();
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530144}
145
146// Sends message to host control command handler to reset OCC
147void Status::resetOCC()
148{
Chris Caina8857c52021-01-27 11:53:05 -0600149 log<level::INFO>(
Patrick Williams48002492024-02-13 21:43:32 -0600150 std::format(">>Status::resetOCC() - requesting reset for OCC{}",
Chris Caina8857c52021-01-27 11:53:05 -0600151 instance)
152 .c_str());
Tom Joseph00325232020-07-29 17:51:48 +0530153#ifdef PLDM
154 if (resetCallBack)
155 {
156 this->resetCallBack(instance);
157 }
158#else
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530159 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0";
160 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host";
161
162 // This will throw exception on failure
George Liuf3b75142021-06-10 11:22:50 +0800163 auto service = utils::getService(CONTROL_HOST_PATH, CONTROL_HOST_INTF);
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530164
George Liuf3b75142021-06-10 11:22:50 +0800165 auto& bus = utils::getBus();
Gunnar Mills94df8c92018-09-14 14:50:03 -0500166 auto method = bus.new_method_call(service.c_str(), CONTROL_HOST_PATH,
167 CONTROL_HOST_INTF, "Execute");
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530168 // OCC Reset control command
Gunnar Mills94df8c92018-09-14 14:50:03 -0500169 method.append(convertForMessage(Control::Host::Command::OCCReset).c_str());
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530170
171 // OCC Sensor ID for callout reasons
Patrick Williamse0962702020-05-13 17:50:22 -0500172 method.append(std::variant<uint8_t>(std::get<0>(sensorMap.at(instance))));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530173 bus.call_noreply(method);
174 return;
Tom Joseph00325232020-07-29 17:51:48 +0530175#endif
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530176}
177
178// Handler called by Host control command handler to convey the
179// status of the executed command
Patrick Williamsaf408082022-07-22 19:26:54 -0500180void Status::hostControlEvent(sdbusplus::message_t& msg)
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530181{
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530182 std::string cmdCompleted{};
183 std::string cmdStatus{};
184
185 msg.read(cmdCompleted, cmdStatus);
186
187 log<level::DEBUG>("Host control signal values",
Gunnar Mills94df8c92018-09-14 14:50:03 -0500188 entry("COMMAND=%s", cmdCompleted.c_str()),
189 entry("STATUS=%s", cmdStatus.c_str()));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530190
Gunnar Mills94df8c92018-09-14 14:50:03 -0500191 if (Control::Host::convertResultFromString(cmdStatus) !=
192 Control::Host::Result::Success)
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530193 {
Gunnar Mills94df8c92018-09-14 14:50:03 -0500194 if (Control::Host::convertCommandFromString(cmdCompleted) ==
195 Control::Host::Command::OCCReset)
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530196 {
Gunnar Mills85e65202018-04-08 15:01:54 -0500197 // Must be a Timeout. Log an Error trace
Alexander Filippov1d69e192019-03-21 18:12:07 +0300198 log<level::ERR>(
199 "Error resetting the OCC.", entry("PATH=%s", path.c_str()),
200 entry("SENSORID=0x%X", std::get<0>(sensorMap.at(instance))));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +0530201 }
202 }
203 return;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +0530204}
205
Sheldon Bailey373af752022-02-21 15:14:00 -0600206// Called from Manager::pollerTimerExpired() in preperation to POLL OCC.
Chris Caina8857c52021-01-27 11:53:05 -0600207void Status::readOccState()
208{
Sheldon Bailey373af752022-02-21 15:14:00 -0600209 currentOccReadRetriesCount = occReadRetries;
210 occReadStateNow();
Chris Caina8857c52021-01-27 11:53:05 -0600211}
212
Chris Cain78e86012021-03-04 16:15:31 -0600213#ifdef POWER10
Chris Cain78e86012021-03-04 16:15:31 -0600214// Special processing that needs to happen once the OCCs change to ACTIVE state
215void Status::occsWentActive()
216{
217 CmdStatus status = CmdStatus::SUCCESS;
218
Chris Cain36f9cde2021-11-22 11:18:21 -0600219 status = pmode->sendModeChange();
Chris Cain78e86012021-03-04 16:15:31 -0600220 if (status != CmdStatus::SUCCESS)
221 {
George Liub5ca1012021-09-10 12:53:11 +0800222 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600223 std::format(
George Liub5ca1012021-09-10 12:53:11 +0800224 "Status::occsWentActive: OCC mode change failed with status {}",
225 status)
226 .c_str());
Chris Cainc567dc82022-04-01 15:09:17 -0500227
228 // Disable and reset to try recovering
229 deviceError();
Chris Cain78e86012021-03-04 16:15:31 -0600230 }
231
Chris Cain36f9cde2021-11-22 11:18:21 -0600232 status = pmode->sendIpsData();
Chris Cain78e86012021-03-04 16:15:31 -0600233 if (status != CmdStatus::SUCCESS)
234 {
235 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600236 std::format(
George Liub5ca1012021-09-10 12:53:11 +0800237 "Status::occsWentActive: Sending Idle Power Save Config data failed with status {}",
Chris Cain78e86012021-03-04 16:15:31 -0600238 status)
239 .c_str());
Chris Cainc567dc82022-04-01 15:09:17 -0500240
241 if (status == CmdStatus::COMM_FAILURE)
242 {
243 // Disable and reset to try recovering
244 deviceError();
245 }
Chris Cain78e86012021-03-04 16:15:31 -0600246 }
247}
248
Chris Cain17257672021-10-22 13:41:03 -0500249// Send Ambient and Altitude to the OCC
250CmdStatus Status::sendAmbient(const uint8_t inTemp, const uint16_t inAltitude)
251{
252 CmdStatus status = CmdStatus::FAILURE;
253 bool ambientValid = true;
254 uint8_t ambientTemp = inTemp;
255 uint16_t altitude = inAltitude;
256
257 if (ambientTemp == 0xFF)
258 {
259 // Get latest readings from manager
260 manager.getAmbientData(ambientValid, ambientTemp, altitude);
261 log<level::DEBUG>(
Patrick Williams48002492024-02-13 21:43:32 -0600262 std::format("sendAmbient: valid: {}, Ambient: {}C, altitude: {}m",
Chris Cain17257672021-10-22 13:41:03 -0500263 ambientValid, ambientTemp, altitude)
264 .c_str());
265 }
266
267 std::vector<std::uint8_t> cmd, rsp;
268 cmd.reserve(11);
269 cmd.push_back(uint8_t(CmdType::SEND_AMBIENT));
270 cmd.push_back(0x00); // Data Length (2 bytes)
271 cmd.push_back(0x08); //
272 cmd.push_back(0x00); // Version
273 cmd.push_back(ambientValid ? 0 : 0xFF); // Ambient Status
274 cmd.push_back(ambientTemp); // Ambient Temperature
275 cmd.push_back(altitude >> 8); // Altitude in meters (2 bytes)
276 cmd.push_back(altitude & 0xFF); //
277 cmd.push_back(0x00); // Reserved (3 bytes)
278 cmd.push_back(0x00);
279 cmd.push_back(0x00);
Patrick Williams48002492024-02-13 21:43:32 -0600280 log<level::DEBUG>(std::format("sendAmbient: SEND_AMBIENT "
Chris Cain17257672021-10-22 13:41:03 -0500281 "command to OCC{} ({} bytes)",
282 instance, cmd.size())
283 .c_str());
284 status = occCmd.send(cmd, rsp);
285 if (status == CmdStatus::SUCCESS)
286 {
287 if (rsp.size() == 5)
288 {
289 if (RspStatus::SUCCESS != RspStatus(rsp[2]))
290 {
291 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600292 std::format(
Chris Cainc567dc82022-04-01 15:09:17 -0500293 "sendAmbient: SEND_AMBIENT failed with rspStatus 0x{:02X}",
Chris Cain17257672021-10-22 13:41:03 -0500294 rsp[2])
295 .c_str());
296 dump_hex(rsp);
297 status = CmdStatus::FAILURE;
298 }
299 }
300 else
301 {
Chris Cainc567dc82022-04-01 15:09:17 -0500302 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600303 std::format(
Chris Cainc567dc82022-04-01 15:09:17 -0500304 "sendAmbient: INVALID SEND_AMBIENT response length:{}",
305 rsp.size())
306 .c_str());
Chris Cain17257672021-10-22 13:41:03 -0500307 dump_hex(rsp);
308 status = CmdStatus::FAILURE;
309 }
310 }
311 else
312 {
Chris Cainc567dc82022-04-01 15:09:17 -0500313 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600314 std::format(
Chris Cainc567dc82022-04-01 15:09:17 -0500315 "sendAmbient: SEND_AMBIENT FAILED! with status 0x{:02X}",
316 status)
317 .c_str());
318
319 if (status == CmdStatus::COMM_FAILURE)
Chris Cain17257672021-10-22 13:41:03 -0500320 {
Chris Cainc567dc82022-04-01 15:09:17 -0500321 // Disable and reset to try recovering
322 deviceError();
Chris Cain17257672021-10-22 13:41:03 -0500323 }
324 }
325
326 return status;
327}
Chris Caina7b74dc2021-11-10 17:03:43 -0600328
329// Called when safe timer expires to determine if OCCs need to be reset
330void Status::safeStateDelayExpired()
331{
332 if (this->occActive())
333 {
334 log<level::INFO>(
Patrick Williams48002492024-02-13 21:43:32 -0600335 std::format(
Chris Caina7b74dc2021-11-10 17:03:43 -0600336 "safeStateDelayExpired: OCC{} is in SAFE state, requesting reset",
337 instance)
338 .c_str());
339 // Disable and reset to try recovering
Eddie James9789e712022-05-25 15:43:40 -0500340 deviceError(Error::Descriptor(SAFE_ERROR_PATH));
Chris Caina7b74dc2021-11-10 17:03:43 -0600341 }
342}
Chris Cain78e86012021-03-04 16:15:31 -0600343#endif // POWER10
344
Chris Caine2d0a432022-03-28 11:08:49 -0500345fs::path Status::getHwmonPath()
Chris Cain5d66a0a2022-02-09 08:52:10 -0600346{
347 using namespace std::literals::string_literals;
348
Chris Caine2d0a432022-03-28 11:08:49 -0500349 if (!fs::exists(hwmonPath))
350 {
351 static bool tracedFail[8] = {0};
Chris Cain5d66a0a2022-02-09 08:52:10 -0600352
Chris Caine2d0a432022-03-28 11:08:49 -0500353 if (!hwmonPath.empty())
354 {
355 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600356 std::format("Status::getHwmonPath(): path no longer exists: {}",
Chris Caine2d0a432022-03-28 11:08:49 -0500357 hwmonPath.c_str())
358 .c_str());
359 hwmonPath.clear();
360 }
361
362 // Build the base HWMON path
Patrick Williamsa49c9872023-05-10 07:50:35 -0500363 fs::path prefixPath = fs::path{OCC_HWMON_PATH + "occ-hwmon."s +
364 std::to_string(instance + 1) +
365 "/hwmon/"s};
Chris Caine2d0a432022-03-28 11:08:49 -0500366
367 // Get the hwmonXX directory name
368 try
369 {
370 // there should only be one directory
371 const int numDirs = std::distance(
372 fs::directory_iterator(prefixPath), fs::directory_iterator{});
373 if (numDirs == 1)
374 {
375 hwmonPath = *fs::directory_iterator(prefixPath);
376 tracedFail[instance] = false;
377 }
378 else
379 {
380 if (!tracedFail[instance])
381 {
382 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600383 std::format(
Chris Caine2d0a432022-03-28 11:08:49 -0500384 "Status::getHwmonPath(): Found multiple ({}) hwmon paths!",
385 numDirs)
386 .c_str());
387 tracedFail[instance] = true;
388 }
389 }
390 }
391 catch (const fs::filesystem_error& e)
392 {
393 if (!tracedFail[instance])
394 {
395 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600396 std::format(
Chris Caine2d0a432022-03-28 11:08:49 -0500397 "Status::getHwmonPath(): error accessing {}: {}",
398 prefixPath.c_str(), e.what())
399 .c_str());
400 tracedFail[instance] = true;
401 }
402 }
403 }
404
405 return hwmonPath;
Chris Cain5d66a0a2022-02-09 08:52:10 -0600406}
407
Sheldon Bailey373af752022-02-21 15:14:00 -0600408// Called to read state and upon failure to read after occReadStateFailTimer.
409void Status::occReadStateNow()
410{
411 unsigned int state;
412 const fs::path filename =
413 fs::path(DEV_PATH) /
414 fs::path(sysfsName + "." + std::to_string(instance + 1)) / "occ_state";
415
416 std::ifstream file;
417 bool goodFile = false;
418
419 // open file.
420 file.open(filename, std::ios::in);
421 const int openErrno = errno;
422
423 // File is open and state can be used.
424 if (file.is_open() && file.good())
425 {
426 goodFile = true;
427 file >> state;
428
429 if (state != lastState)
430 {
431 // Trace OCC state changes
432 log<level::INFO>(
Patrick Williams48002492024-02-13 21:43:32 -0600433 std::format(
Chris Cainbd551de2022-04-26 13:41:16 -0500434 "Status::readOccState: OCC{} state 0x{:02X} (lastState: 0x{:02X})",
435 instance, state, lastState)
Sheldon Bailey373af752022-02-21 15:14:00 -0600436 .c_str());
437 lastState = state;
438#ifdef POWER10
439 if (OccState(state) == OccState::ACTIVE)
440 {
441 if (pmode && device.master())
442 {
443 // Set the master OCC on the PowerMode object
444 pmode->setMasterOcc(path);
445 // Enable mode changes
446 pmode->setMasterActive();
447
448 // Special processing by master OCC when it goes active
449 occsWentActive();
450 }
451
452 CmdStatus status = sendAmbient();
453 if (status != CmdStatus::SUCCESS)
454 {
455 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600456 std::format(
Sheldon Bailey373af752022-02-21 15:14:00 -0600457 "readOccState: Sending Ambient failed with status {}",
458 status)
459 .c_str());
460 }
461 }
462
463 // If OCC in known Good State.
464 if ((OccState(state) == OccState::ACTIVE) ||
465 (OccState(state) == OccState::CHARACTERIZATION) ||
466 (OccState(state) == OccState::OBSERVATION))
467 {
468 // Good OCC State then sensors valid again
469 stateValid = true;
470
471 if (safeStateDelayTimer.isEnabled())
472 {
473 // stop safe delay timer (no longer in SAFE state)
474 safeStateDelayTimer.setEnabled(false);
475 }
476 }
477 // Else not Valid state We would be in SAFE mode.
478 // This captures both SAFE mode, and 0x00, or other invalid
479 // state values.
480 else
481 {
482 if (!safeStateDelayTimer.isEnabled())
483 {
484 // start safe delay timer (before requesting reset)
485 using namespace std::literals::chrono_literals;
486 safeStateDelayTimer.restartOnce(60s);
487 }
488 // Not valid state, update sensors to Nan & not functional.
489 stateValid = false;
490 }
491#else
492 // Before P10 state not checked, only used good file open.
493 stateValid = true;
494#endif
495 }
496 }
497 file.close();
498
499 // if failed to Read a state or not a valid state -> Attempt retry
500 // after 1 Second delay if allowed.
501 if ((!goodFile) || (!stateValid))
502 {
503 if (!goodFile)
504 {
505 // If not able to read, OCC may be offline
506 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600507 std::format("Status::readOccState: open failed (errno={})",
Sheldon Bailey373af752022-02-21 15:14:00 -0600508 openErrno)
509 .c_str());
510 }
511 else
512 {
513 // else this failed due to state not valid.
Chris Cainbd551de2022-04-26 13:41:16 -0500514 if (state != lastState)
515 {
516 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600517 std::format(
Chris Cainbd551de2022-04-26 13:41:16 -0500518 "Status::readOccState: OCC{} Invalid state 0x{:02X} (last state: 0x{:02X})",
519 instance, state, lastState)
520 .c_str());
521 }
Sheldon Bailey373af752022-02-21 15:14:00 -0600522 }
523
524#ifdef READ_OCC_SENSORS
Sheldon Baileyc8dd4592022-05-12 10:15:14 -0500525 manager.setSensorValueToNaN(instance);
Sheldon Bailey373af752022-02-21 15:14:00 -0600526#endif
527
528 // See occReadRetries for number of retry attempts.
529 if (currentOccReadRetriesCount > 0)
530 {
531 --currentOccReadRetriesCount;
532#ifdef POWER10
533 using namespace std::chrono_literals;
534 occReadStateFailTimer.restartOnce(1s);
535#endif
536 }
537 else
538 {
Chris Cainbae4d072022-02-28 09:46:50 -0600539#ifdef POWER10
540 if (!stateValid && occActive())
541 {
542 if (!safeStateDelayTimer.isEnabled())
543 {
544 log<level::ERR>(
545 "Starting 60 sec delay timer before requesting a reset");
546 // start safe delay timer (before requesting reset)
547 using namespace std::literals::chrono_literals;
548 safeStateDelayTimer.restartOnce(60s);
549 }
550 }
551#else
Sheldon Bailey373af752022-02-21 15:14:00 -0600552 // State could not be determined, set it to NO State.
553 lastState = 0;
554
555 // Disable the ability to send Failed actions until OCC is
556 // Active again.
557 stateValid = false;
558
559 // Disable and reset to try recovering
560 deviceError();
Chris Cainbae4d072022-02-28 09:46:50 -0600561#endif
Sheldon Bailey373af752022-02-21 15:14:00 -0600562 }
563 }
564}
565
Chris Cainc86d80f2023-05-04 15:49:18 -0500566// Update processor throttle status on dbus
567void Status::updateThrottle(const bool isThrottled, const uint8_t newReason)
568{
569 if (!throttleHandle)
570 {
571 return;
572 }
573
574 uint8_t newThrottleCause = throttleCause;
575
576 if (isThrottled) // throttled due to newReason
577 {
578 if ((newReason & throttleCause) == 0)
579 {
580 // set the bit(s) for passed in reason
581 newThrottleCause |= newReason;
582 }
583 // else no change
584 }
585 else // no longer throttled due to newReason
586 {
587 if ((newReason & throttleCause) != 0)
588 {
589 // clear the bit(s) for passed in reason
590 newThrottleCause &= ~newReason;
591 }
592 // else no change
593 }
594
595 if (newThrottleCause != throttleCause)
596 {
597 if (newThrottleCause == THROTTLED_NONE)
598 {
599 log<level::DEBUG>(
Patrick Williams48002492024-02-13 21:43:32 -0600600 std::format(
Chris Cainc86d80f2023-05-04 15:49:18 -0500601 "updateThrottle: OCC{} no longer throttled (prior reason: {})",
602 instance, throttleCause)
603 .c_str());
604 throttleCause = THROTTLED_NONE;
605 throttleHandle->throttled(false);
606 throttleHandle->throttleCauses({});
607 }
608 else
609 {
610 log<level::DEBUG>(
Patrick Williams48002492024-02-13 21:43:32 -0600611 std::format(
Chris Cainc86d80f2023-05-04 15:49:18 -0500612 "updateThrottle: OCC{} is throttled with reason {} (prior reason: {})",
613 instance, newThrottleCause, throttleCause)
614 .c_str());
615 throttleCause = newThrottleCause;
616
617 std::vector<ThrottleObj::ThrottleReasons> updatedCauses;
618 if (throttleCause & THROTTLED_POWER)
619 {
620 updatedCauses.push_back(
621 throttleHandle->ThrottleReasons::PowerLimit);
622 }
623 if (throttleCause & THROTTLED_THERMAL)
624 {
625 updatedCauses.push_back(
626 throttleHandle->ThrottleReasons::ThermalLimit);
627 }
628 if (throttleCause & THROTTLED_SAFE)
629 {
630 updatedCauses.push_back(
631 throttleHandle->ThrottleReasons::ManagementDetectedFault);
632 }
633 throttleHandle->throttleCauses(updatedCauses);
634 throttleHandle->throttled(true);
635 }
636 }
637 // else no change to throttle status
638}
639
640// Get processor path associated with this OCC
641void Status::readProcAssociation()
642{
643 std::string managingPath = path + "/power_managing";
644 log<level::DEBUG>(
Patrick Williams48002492024-02-13 21:43:32 -0600645 std::format("readProcAssociation: getting endpoints for {} ({})",
Chris Cainc86d80f2023-05-04 15:49:18 -0500646 managingPath, path)
647 .c_str());
648 try
649 {
650 utils::PropertyValue procPathProperty{};
651 procPathProperty = utils::getProperty(
652 managingPath, "xyz.openbmc_project.Association", "endpoints");
653 auto result = std::get<std::vector<std::string>>(procPathProperty);
654 if (result.size() > 0)
655 {
656 procPath = result[0];
657 log<level::INFO>(
Patrick Williams48002492024-02-13 21:43:32 -0600658 std::format("readProcAssociation: OCC{} has proc={}", instance,
Chris Cainc86d80f2023-05-04 15:49:18 -0500659 procPath.c_str())
660 .c_str());
661 }
662 else
663 {
664 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600665 std::format(
Chris Cainc86d80f2023-05-04 15:49:18 -0500666 "readProcAssociation: No processor associated with OCC{} / {}",
667 instance, path)
668 .c_str());
669 }
670 }
671 catch (const sdbusplus::exception_t& e)
672 {
673 log<level::ERR>(
Patrick Williams48002492024-02-13 21:43:32 -0600674 std::format(
Chris Cainc86d80f2023-05-04 15:49:18 -0500675 "readProcAssociation: Unable to get proc assocated with {} - {}",
676 path, e.what())
677 .c_str());
678 procPath = {};
679 }
680}
681
Vishwanatha Subbanna307d80b2017-06-28 15:56:09 +0530682} // namespace occ
683} // namespace open_power