Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2017 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 16 | #include "config.h" |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 17 | |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 18 | #include "pgood_monitor.hpp" |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 19 | |
| 20 | #include "elog-errors.hpp" |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 21 | #include "utility.hpp" |
| 22 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 23 | #include <org/open_power/Witherspoon/Fault/error.hpp> |
| 24 | #include <phosphor-logging/log.hpp> |
| 25 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 26 | namespace phosphor |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 27 | { |
| 28 | namespace power |
| 29 | { |
| 30 | |
| 31 | constexpr auto POWER_OBJ_PATH = "/org/openbmc/control/power0"; |
| 32 | constexpr auto POWER_INTERFACE = "org.openbmc.control.Power"; |
| 33 | |
| 34 | using namespace phosphor::logging; |
Brandon Wyman | e0eb45c | 2017-10-06 12:58:42 -0500 | [diff] [blame] | 35 | using namespace sdbusplus::org::open_power::Witherspoon::Fault::Error; |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 36 | |
| 37 | bool PGOODMonitor::pgoodPending() |
| 38 | { |
| 39 | bool pending = false; |
| 40 | int32_t state = 0; |
| 41 | int32_t pgood = 0; |
| 42 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 43 | auto service = util::getService(POWER_OBJ_PATH, POWER_INTERFACE, bus); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 44 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 45 | util::getProperty<int32_t>(POWER_INTERFACE, "pgood", POWER_OBJ_PATH, |
| 46 | service, bus, pgood); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 47 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 48 | // When state = 1, system was switched on |
| 49 | util::getProperty<int32_t>(POWER_INTERFACE, "state", POWER_OBJ_PATH, |
| 50 | service, bus, state); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 51 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 52 | // On but no PGOOD |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 53 | if (state && !pgood) |
| 54 | { |
| 55 | pending = true; |
| 56 | } |
| 57 | |
| 58 | return pending; |
| 59 | } |
| 60 | |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 61 | void PGOODMonitor::analyze() |
| 62 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 63 | // Timer callback. |
| 64 | // The timer expired before it was stopped. |
| 65 | // If PGOOD is still pending (it should be), |
| 66 | // then there is a real failure. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 67 | |
| 68 | if (pgoodPending()) |
| 69 | { |
Andy YF Wang | 40247cc | 2019-09-06 18:30:56 +0800 | [diff] [blame] | 70 | #ifdef DEVICE_ACCESS |
Matt Spinler | b2d7251 | 2017-08-22 09:07:01 -0500 | [diff] [blame] | 71 | device->onFailure(); |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 72 | #endif |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 73 | report<PowerOnFailure>(); |
| 74 | } |
| 75 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 76 | // The pgood-wait service (with a longer timeout) |
| 77 | // will handle powering off the system. |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 78 | timer.get_event().exit(EXIT_SUCCESS); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void PGOODMonitor::propertyChanged() |
| 82 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 83 | // Multiple properties could have changed here. |
| 84 | // Keep things simple and just recheck the important ones. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 85 | if (!pgoodPending()) |
| 86 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 87 | // PGOOD is on, or system is off, so we are done. |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 88 | timer.get_event().exit(EXIT_SUCCESS); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | void PGOODMonitor::startListening() |
| 93 | { |
| 94 | match = std::make_unique<sdbusplus::bus::match_t>( |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 95 | bus, |
| 96 | sdbusplus::bus::match::rules::propertiesChanged(POWER_OBJ_PATH, |
| 97 | POWER_INTERFACE), |
Brad Bishop | 11cb672 | 2019-09-03 14:30:06 -0400 | [diff] [blame] | 98 | [this](auto&) { this->propertyChanged(); }); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | int PGOODMonitor::run() |
| 102 | { |
| 103 | try |
| 104 | { |
| 105 | startListening(); |
| 106 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 107 | // If PGOOD came up before we got here, we're done. |
| 108 | // Otherwise if PGOOD doesn't get asserted before |
| 109 | // the timer expires, it's a failure. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 110 | if (!pgoodPending()) |
| 111 | { |
| 112 | return EXIT_SUCCESS; |
| 113 | } |
| 114 | |
William A. Kennington III | 1a0c917 | 2018-10-18 17:57:49 -0700 | [diff] [blame] | 115 | return timer.get_event().loop(); |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 116 | } |
| 117 | catch (std::exception& e) |
| 118 | { |
| 119 | log<level::ERR>(e.what()); |
| 120 | log<level::ERR>("Unexpected failure prevented PGOOD checking"); |
| 121 | } |
| 122 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 123 | // Letting the service fail won't help anything, so don't do it. |
Matt Spinler | f02daec | 2017-08-14 14:00:46 -0500 | [diff] [blame] | 124 | return EXIT_SUCCESS; |
| 125 | } |
| 126 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 127 | } // namespace power |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 128 | } // namespace phosphor |