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> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 25 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 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"; |
Jayaprakash Mutyala | fc5c80e | 2024-10-18 07:07:46 +0000 | [diff] [blame^] | 40 | static constexpr const char* ledService = "xyz.openbmc_project.LED.Controller"; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 41 | |
| 42 | static constexpr const char* ledPathPrefix = |
| 43 | "/xyz/openbmc_project/led/physical/"; |
| 44 | static constexpr const char* fanPwmPath = |
Alex Schendel | 90eb787 | 2022-09-01 11:56:52 -0700 | [diff] [blame] | 45 | "/xyz/openbmc_project/sensors/fan_pwm/"; |
Richard Marian Thomaiyar | 147daec | 2019-06-15 07:43:48 +0530 | [diff] [blame] | 46 | static constexpr const char* fanTachBasePath = |
| 47 | "/xyz/openbmc_project/sensors/fan_tach/"; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 48 | |
| 49 | static constexpr const char* fanIntf = "xyz.openbmc_project.Sensor.Value"; |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 50 | static constexpr const char* buttonIntf = "xyz.openbmc_project.Chassis.Buttons"; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 51 | static constexpr const char* ledIntf = "xyz.openbmc_project.Led.Physical"; |
| 52 | |
anil kumar appana | 98705b3 | 2019-09-11 14:15:50 +0000 | [diff] [blame] | 53 | static constexpr const char* intrusionService = |
| 54 | "xyz.openbmc_project.IntrusionSensor"; |
| 55 | static constexpr const char* intrusionPath = |
| 56 | "/xyz/openbmc_project/Intrusion/Chassis_Intrusion"; |
| 57 | static constexpr const char* intrusionIntf = |
| 58 | "xyz.openbmc_project.Chassis.Intrusion"; |
| 59 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 60 | static constexpr const char* busPropertyIntf = |
| 61 | "org.freedesktop.DBus.Properties"; |
| 62 | static constexpr const char* ledStateStr = |
| 63 | "xyz.openbmc_project.Led.Physical.Action."; // Comes with postfix Off/On |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 64 | |
Richard Marian Thomaiyar | 666dd01 | 2019-08-02 20:55:37 +0530 | [diff] [blame] | 65 | static constexpr const char* specialModeService = |
| 66 | "xyz.openbmc_project.SpecialMode"; |
| 67 | static constexpr const char* specialModeObjPath = |
| 68 | "/xyz/openbmc_project/security/special_mode"; |
| 69 | static constexpr const char* specialModeIntf = |
| 70 | "xyz.openbmc_project.Security.SpecialMode"; |
| 71 | |
Vasu V | 97c3090 | 2023-05-19 15:56:15 +0530 | [diff] [blame] | 72 | static constexpr const char* mctpPcieSlotService = |
| 73 | "xyz.openbmc_project.MCTP_SMBus_PCIe_slot"; |
| 74 | static constexpr const char* mctpHsbpService = |
| 75 | "xyz.openbmc_project.MCTP_SMBus_HSBP"; |
| 76 | static constexpr const char* mctpObjPath = "/xyz/openbmc_project/mctp"; |
| 77 | static constexpr const char* mctpBaseIntf = "xyz.openbmc_project.MCTP.Base"; |
| 78 | |
| 79 | constexpr const uint8_t slotNumMask = 0x0F; |
| 80 | constexpr const uint8_t muxTypeMask = 0xF0; |
| 81 | constexpr const uint8_t muxTypeShift = 4; |
| 82 | |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 83 | enum class SpecialMode : uint8_t |
| 84 | { |
| 85 | none = 0, |
| 86 | mfg = 1, |
| 87 | #ifdef BMC_VALIDATION_UNSECURE_FEATURE |
| 88 | valUnsecure = 2 |
| 89 | #endif |
| 90 | }; |
| 91 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 92 | enum class SmActionGet : uint8_t |
| 93 | { |
| 94 | sample = 0, |
| 95 | ignore = 1, |
| 96 | revert = 2 |
| 97 | }; |
| 98 | |
| 99 | enum class SmActionSet : uint8_t |
| 100 | { |
| 101 | forceDeasserted = 0, |
| 102 | forceAsserted = 1, |
| 103 | revert = 2 |
| 104 | }; |
| 105 | |
| 106 | enum class SmSignalGet : uint8_t |
| 107 | { |
| 108 | smPowerButton = 0, |
| 109 | smResetButton = 1, |
| 110 | smSleepButton, |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 111 | smNMIButton = 3, |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 112 | smChassisIntrusion = 4, |
| 113 | smPowerGood, |
| 114 | smPowerRequestGet, |
| 115 | smSleepRequestGet, |
| 116 | smFrbTimerHaltGet, |
| 117 | smForceUpdate, |
| 118 | smRingIndication, |
| 119 | smCarrierDetect, |
| 120 | smIdentifyButton = 0xc, |
| 121 | smFanPwmGet = 0xd, |
| 122 | smSignalReserved, |
| 123 | smFanTachometerGet = 0xf, |
| 124 | smNcsiDiag = 0x10, |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 125 | smGetSignalMax |
| 126 | }; |
| 127 | |
| 128 | enum class SmSignalSet : uint8_t |
| 129 | { |
| 130 | smPowerLed = 0, |
| 131 | smPowerFaultLed, |
| 132 | smClusterLed, |
| 133 | smDiskFaultLed, |
| 134 | smCoolingFaultLed, |
| 135 | smFanPowerSpeed = 5, |
| 136 | smPowerRequestSet, |
| 137 | smSleepRequestSet, |
| 138 | smAcpiSci, |
| 139 | smSpeaker, |
| 140 | smFanPackFaultLed, |
| 141 | smCpuFailLed, |
| 142 | smDimmFailLed, |
| 143 | smIdentifyLed, |
| 144 | smHddLed, |
| 145 | smSystemReadyLed, |
| 146 | smLcdBacklight = 0x10, |
| 147 | smSetSignalMax |
| 148 | }; |
| 149 | |
anil kumar appana | 98705b3 | 2019-09-11 14:15:50 +0000 | [diff] [blame] | 150 | /** @enum IntrusionStatus |
| 151 | .* |
| 152 | * Intrusion Status |
| 153 | */ |
| 154 | enum class IntrusionStatus : uint8_t |
| 155 | { |
| 156 | normal = 0, |
| 157 | hardwareIntrusion, |
| 158 | tamperingDetected |
| 159 | }; |
| 160 | |
Arun P. Mohanan | 06584cd | 2021-08-13 20:56:01 +0530 | [diff] [blame] | 161 | enum SupportedFeatureControls : uint8_t |
| 162 | { |
| 163 | mctp = 0, |
Jason M. Bills | 5cb2c04 | 2021-08-17 12:03:39 -0700 | [diff] [blame] | 164 | pcieScan, |
Vasu V | 97c3090 | 2023-05-19 15:56:15 +0530 | [diff] [blame] | 165 | mctpSlotSupport |
| 166 | }; |
| 167 | |
| 168 | enum SupportedFeatureMuxs : uint8_t |
| 169 | { |
| 170 | pcieMuxSlot = 0, |
| 171 | pcieMcioMuxSlot, |
| 172 | pcieM2EdSffMuxSlot, |
| 173 | leftRaiserMuxSlot, |
| 174 | rightRaiserMuxSlot, |
| 175 | HsbpMuxSlot |
Arun P. Mohanan | 06584cd | 2021-08-13 20:56:01 +0530 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | enum SupportedFeatureActions : uint8_t |
| 179 | { |
| 180 | stop = 0, |
| 181 | start, |
| 182 | disable, |
| 183 | enable, |
| 184 | }; |
| 185 | |
| 186 | enum SupportedMCTPBindings : uint8_t |
| 187 | { |
| 188 | mctpPCIe = 0, |
| 189 | mctpSMBusHSBP, |
| 190 | mctpSMBusPCIeSlot |
| 191 | }; |
| 192 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 193 | struct SetSmSignalReq |
| 194 | { |
| 195 | SmSignalSet Signal; |
| 196 | uint8_t Instance; |
| 197 | SmActionSet Action; |
| 198 | uint8_t Value; |
| 199 | }; |
| 200 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 201 | class LedProperty |
| 202 | { |
| 203 | SmSignalSet signal; |
| 204 | std::string name; |
| 205 | std::string prevState; |
| 206 | std::string currentState; |
| 207 | bool isLocked; |
| 208 | |
| 209 | public: |
| 210 | LedProperty(SmSignalSet signal_, std::string name_) : |
| 211 | signal(signal_), name(name_), prevState(""), isLocked(false) |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 212 | {} |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 213 | |
| 214 | LedProperty() = delete; |
| 215 | |
| 216 | SmSignalSet getSignal() const |
| 217 | { |
| 218 | return signal; |
| 219 | } |
| 220 | |
| 221 | void setLock(const bool& lock) |
| 222 | { |
| 223 | isLocked = lock; |
| 224 | } |
| 225 | void setPrevState(const std::string& state) |
| 226 | { |
| 227 | prevState = state; |
| 228 | } |
| 229 | void setCurrState(const std::string& state) |
| 230 | { |
| 231 | currentState = state; |
| 232 | } |
| 233 | std::string getCurrState() const |
| 234 | { |
| 235 | return currentState; |
| 236 | } |
| 237 | bool getLock() const |
| 238 | { |
| 239 | return isLocked; |
| 240 | } |
| 241 | std::string getPrevState() const |
| 242 | { |
| 243 | return prevState; |
| 244 | } |
| 245 | std::string getName() const |
| 246 | { |
| 247 | return name; |
| 248 | } |
| 249 | }; |
| 250 | |
| 251 | /** @class Manufacturing |
| 252 | * |
| 253 | * @brief Implemet commands to support Manufacturing Test Mode. |
| 254 | */ |
| 255 | class Manufacturing |
| 256 | { |
| 257 | std::string path; |
| 258 | std::string gpioPaths[(uint8_t)SmSignalGet::smGetSignalMax]; |
| 259 | std::vector<LedProperty> ledPropertyList; |
| 260 | void initData(); |
| 261 | |
| 262 | public: |
| 263 | Manufacturing(); |
| 264 | |
| 265 | ipmi_return_codes detectAccessLvl(ipmi_request_t request, |
| 266 | ipmi_data_len_t req_len); |
| 267 | |
| 268 | LedProperty* findLedProperty(const SmSignalSet& signal) |
| 269 | { |
| 270 | auto it = std::find_if(ledPropertyList.begin(), ledPropertyList.end(), |
| 271 | [&signal](const LedProperty& led) { |
Patrick Williams | 1bcced0 | 2024-08-16 15:20:24 -0400 | [diff] [blame] | 272 | return led.getSignal() == signal; |
| 273 | }); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 274 | if (it != ledPropertyList.end()) |
| 275 | { |
| 276 | return &(*it); |
| 277 | } |
| 278 | return nullptr; |
| 279 | } |
| 280 | |
| 281 | std::string getLedPropertyName(const SmSignalSet signal) |
| 282 | { |
| 283 | LedProperty* led = findLedProperty(signal); |
| 284 | if (led != nullptr) |
| 285 | { |
| 286 | return led->getName(); |
| 287 | } |
| 288 | else |
| 289 | { |
| 290 | return ""; |
| 291 | } |
| 292 | } |
| 293 | |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 294 | int8_t getProperty(const std::string& service, const std::string& path, |
| 295 | const std::string& interface, |
| 296 | const std::string& propertyName, ipmi::Value* value); |
| 297 | int8_t setProperty(const std::string& service, const std::string& path, |
| 298 | const std::string& interface, |
| 299 | const std::string& propertyName, ipmi::Value value); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 300 | int8_t disablePidControlService(const bool disable); |
| 301 | |
| 302 | void revertTimerHandler(); |
| 303 | |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 304 | SpecialMode getMfgMode(void) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 305 | { |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 306 | ipmi::Value mode; |
| 307 | if (getProperty(specialModeService, specialModeObjPath, specialModeIntf, |
| 308 | "SpecialMode", &mode) != 0) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 309 | { |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 310 | return SpecialMode::none; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 311 | } |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 312 | if (std::get<std::string>(mode) == |
| 313 | "xyz.openbmc_project.Control.Security.SpecialMode.Modes." |
| 314 | "Manufacturing") |
| 315 | { |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 316 | return SpecialMode::mfg; |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 317 | } |
Richard Marian Thomaiyar | 99d7d35 | 2019-11-11 12:11:35 +0530 | [diff] [blame] | 318 | #ifdef BMC_VALIDATION_UNSECURE_FEATURE |
| 319 | if (std::get<std::string>(mode) == |
| 320 | "xyz.openbmc_project.Control.Security.SpecialMode.Modes." |
| 321 | "ValidationUnsecure") |
| 322 | { |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 323 | return SpecialMode::valUnsecure; |
Richard Marian Thomaiyar | 99d7d35 | 2019-11-11 12:11:35 +0530 | [diff] [blame] | 324 | } |
| 325 | #endif |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 326 | return SpecialMode::none; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 329 | bool revertFanPWM = false; |
| 330 | bool revertLedCallback = false; |
Patrick Williams | f0feb49 | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 331 | sdbusplus::Timer revertTimer; |
Ayushi Smriti | d872a4a | 2019-10-15 10:20:11 +0530 | [diff] [blame] | 332 | int mtmTestBeepFd = -1; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | } // namespace ipmi |