Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel 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 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <ipmid/api-types.hpp> |
| 20 | #include <ipmid/utils.hpp> |
| 21 | #include <phosphor-logging/log.hpp> |
| 22 | #include <sdbusplus/bus.hpp> |
| 23 | #include <sdbusplus/message.hpp> |
| 24 | #include <sdbusplus/timer.hpp> |
| 25 | #include <variantvisitors.hpp> |
| 26 | #include <vector> |
| 27 | |
| 28 | #define FAN_SENSOR_NOT_PRESENT (0 << 0) |
| 29 | #define FAN_SENSOR_PRESENT (1 << 0) |
| 30 | #define FAN_NOT_PRESENT (0 << 1) |
| 31 | #define FAN_PRESENT (1 << 1) |
| 32 | |
| 33 | namespace ipmi |
| 34 | { |
| 35 | |
| 36 | // TODO: Service names may change. Worth to consider dynamic detection. |
| 37 | static constexpr const char* fanService = "xyz.openbmc_project.FanSensor"; |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 38 | static constexpr const char* buttonService = |
| 39 | "xyz.openbmc_project.Chassis.Buttons"; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 40 | static constexpr const char* ledServicePrefix = |
| 41 | "xyz.openbmc_project.LED.Controller."; |
| 42 | |
| 43 | static constexpr const char* ledPathPrefix = |
| 44 | "/xyz/openbmc_project/led/physical/"; |
| 45 | static constexpr const char* fanPwmPath = |
| 46 | "/xyz/openbmc_project/sensors/fan_pwm/Pwm_"; |
Richard Marian Thomaiyar | 147daec | 2019-06-15 07:43:48 +0530 | [diff] [blame] | 47 | static constexpr const char* fanTachBasePath = |
| 48 | "/xyz/openbmc_project/sensors/fan_tach/"; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 49 | |
| 50 | static constexpr const char* fanIntf = "xyz.openbmc_project.Sensor.Value"; |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 51 | static constexpr const char* buttonIntf = "xyz.openbmc_project.Chassis.Buttons"; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 52 | static constexpr const char* ledIntf = "xyz.openbmc_project.Led.Physical"; |
| 53 | |
| 54 | static constexpr const char* busPropertyIntf = |
| 55 | "org.freedesktop.DBus.Properties"; |
| 56 | static constexpr const char* ledStateStr = |
| 57 | "xyz.openbmc_project.Led.Physical.Action."; // Comes with postfix Off/On |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 58 | |
Richard Marian Thomaiyar | 666dd01 | 2019-08-02 20:55:37 +0530 | [diff] [blame] | 59 | static constexpr const char* specialModeService = |
| 60 | "xyz.openbmc_project.SpecialMode"; |
| 61 | static constexpr const char* specialModeObjPath = |
| 62 | "/xyz/openbmc_project/security/special_mode"; |
| 63 | static constexpr const char* specialModeIntf = |
| 64 | "xyz.openbmc_project.Security.SpecialMode"; |
| 65 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 66 | enum class SmActionGet : uint8_t |
| 67 | { |
| 68 | sample = 0, |
| 69 | ignore = 1, |
| 70 | revert = 2 |
| 71 | }; |
| 72 | |
| 73 | enum class SmActionSet : uint8_t |
| 74 | { |
| 75 | forceDeasserted = 0, |
| 76 | forceAsserted = 1, |
| 77 | revert = 2 |
| 78 | }; |
| 79 | |
| 80 | enum class SmSignalGet : uint8_t |
| 81 | { |
| 82 | smPowerButton = 0, |
| 83 | smResetButton = 1, |
| 84 | smSleepButton, |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 85 | smNMIButton = 3, |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 86 | smChassisIntrusion = 4, |
| 87 | smPowerGood, |
| 88 | smPowerRequestGet, |
| 89 | smSleepRequestGet, |
| 90 | smFrbTimerHaltGet, |
| 91 | smForceUpdate, |
| 92 | smRingIndication, |
| 93 | smCarrierDetect, |
| 94 | smIdentifyButton = 0xc, |
| 95 | smFanPwmGet = 0xd, |
| 96 | smSignalReserved, |
| 97 | smFanTachometerGet = 0xf, |
| 98 | smNcsiDiag = 0x10, |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 99 | smGetSignalMax |
| 100 | }; |
| 101 | |
| 102 | enum class SmSignalSet : uint8_t |
| 103 | { |
| 104 | smPowerLed = 0, |
| 105 | smPowerFaultLed, |
| 106 | smClusterLed, |
| 107 | smDiskFaultLed, |
| 108 | smCoolingFaultLed, |
| 109 | smFanPowerSpeed = 5, |
| 110 | smPowerRequestSet, |
| 111 | smSleepRequestSet, |
| 112 | smAcpiSci, |
| 113 | smSpeaker, |
| 114 | smFanPackFaultLed, |
| 115 | smCpuFailLed, |
| 116 | smDimmFailLed, |
| 117 | smIdentifyLed, |
| 118 | smHddLed, |
| 119 | smSystemReadyLed, |
| 120 | smLcdBacklight = 0x10, |
| 121 | smSetSignalMax |
| 122 | }; |
| 123 | |
| 124 | struct SetSmSignalReq |
| 125 | { |
| 126 | SmSignalSet Signal; |
| 127 | uint8_t Instance; |
| 128 | SmActionSet Action; |
| 129 | uint8_t Value; |
| 130 | }; |
| 131 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 132 | class LedProperty |
| 133 | { |
| 134 | SmSignalSet signal; |
| 135 | std::string name; |
| 136 | std::string prevState; |
| 137 | std::string currentState; |
| 138 | bool isLocked; |
| 139 | |
| 140 | public: |
| 141 | LedProperty(SmSignalSet signal_, std::string name_) : |
| 142 | signal(signal_), name(name_), prevState(""), isLocked(false) |
| 143 | { |
| 144 | } |
| 145 | |
| 146 | LedProperty() = delete; |
| 147 | |
| 148 | SmSignalSet getSignal() const |
| 149 | { |
| 150 | return signal; |
| 151 | } |
| 152 | |
| 153 | void setLock(const bool& lock) |
| 154 | { |
| 155 | isLocked = lock; |
| 156 | } |
| 157 | void setPrevState(const std::string& state) |
| 158 | { |
| 159 | prevState = state; |
| 160 | } |
| 161 | void setCurrState(const std::string& state) |
| 162 | { |
| 163 | currentState = state; |
| 164 | } |
| 165 | std::string getCurrState() const |
| 166 | { |
| 167 | return currentState; |
| 168 | } |
| 169 | bool getLock() const |
| 170 | { |
| 171 | return isLocked; |
| 172 | } |
| 173 | std::string getPrevState() const |
| 174 | { |
| 175 | return prevState; |
| 176 | } |
| 177 | std::string getName() const |
| 178 | { |
| 179 | return name; |
| 180 | } |
| 181 | }; |
| 182 | |
| 183 | /** @class Manufacturing |
| 184 | * |
| 185 | * @brief Implemet commands to support Manufacturing Test Mode. |
| 186 | */ |
| 187 | class Manufacturing |
| 188 | { |
| 189 | std::string path; |
| 190 | std::string gpioPaths[(uint8_t)SmSignalGet::smGetSignalMax]; |
| 191 | std::vector<LedProperty> ledPropertyList; |
| 192 | void initData(); |
| 193 | |
| 194 | public: |
| 195 | Manufacturing(); |
| 196 | |
| 197 | ipmi_return_codes detectAccessLvl(ipmi_request_t request, |
| 198 | ipmi_data_len_t req_len); |
| 199 | |
| 200 | LedProperty* findLedProperty(const SmSignalSet& signal) |
| 201 | { |
| 202 | auto it = std::find_if(ledPropertyList.begin(), ledPropertyList.end(), |
| 203 | [&signal](const LedProperty& led) { |
| 204 | return led.getSignal() == signal; |
| 205 | }); |
| 206 | if (it != ledPropertyList.end()) |
| 207 | { |
| 208 | return &(*it); |
| 209 | } |
| 210 | return nullptr; |
| 211 | } |
| 212 | |
| 213 | std::string getLedPropertyName(const SmSignalSet signal) |
| 214 | { |
| 215 | LedProperty* led = findLedProperty(signal); |
| 216 | if (led != nullptr) |
| 217 | { |
| 218 | return led->getName(); |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | return ""; |
| 223 | } |
| 224 | } |
| 225 | |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 226 | int8_t getProperty(const std::string& service, const std::string& path, |
| 227 | const std::string& interface, |
| 228 | const std::string& propertyName, ipmi::Value* value); |
| 229 | int8_t setProperty(const std::string& service, const std::string& path, |
| 230 | const std::string& interface, |
| 231 | const std::string& propertyName, ipmi::Value value); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 232 | int8_t disablePidControlService(const bool disable); |
| 233 | |
| 234 | void revertTimerHandler(); |
| 235 | |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame^] | 236 | bool isMfgMode(void) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 237 | { |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame^] | 238 | ipmi::Value mode; |
| 239 | if (getProperty(specialModeService, specialModeObjPath, specialModeIntf, |
| 240 | "SpecialMode", &mode) != 0) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 241 | { |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame^] | 242 | return false; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 243 | } |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame^] | 244 | if (std::get<std::string>(mode) == |
| 245 | "xyz.openbmc_project.Control.Security.SpecialMode.Modes." |
| 246 | "Manufacturing") |
| 247 | { |
| 248 | return true; |
| 249 | } |
| 250 | return false; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 253 | bool revertFanPWM = false; |
| 254 | bool revertLedCallback = false; |
| 255 | phosphor::Timer revertTimer; |
Ayushi Smriti | d872a4a | 2019-10-15 10:20:11 +0530 | [diff] [blame] | 256 | int mtmTestBeepFd = -1; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | } // namespace ipmi |