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 | |
Ayushi Smriti | d872a4a | 2019-10-15 10:20:11 +0530 | [diff] [blame] | 17 | #include <linux/input.h> |
| 18 | |
Richard Marian Thomaiyar | 147daec | 2019-06-15 07:43:48 +0530 | [diff] [blame] | 19 | #include <boost/container/flat_map.hpp> |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 20 | #include <ipmid/api.hpp> |
| 21 | #include <manufacturingcommands.hpp> |
| 22 | #include <oemcommands.hpp> |
| 23 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 24 | #include <filesystem> |
| 25 | #include <fstream> |
| 26 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 27 | namespace ipmi |
| 28 | { |
| 29 | |
| 30 | Manufacturing mtm; |
| 31 | |
| 32 | static auto revertTimeOut = |
| 33 | std::chrono::duration_cast<std::chrono::microseconds>( |
| 34 | std::chrono::seconds(60)); // 1 minute timeout |
| 35 | |
Yong Li | f267a67 | 2019-08-29 11:16:07 +0800 | [diff] [blame] | 36 | static constexpr uint8_t slotAddressTypeBus = 0; |
| 37 | static constexpr uint8_t slotAddressTypeUniqueid = 1; |
| 38 | static constexpr uint8_t slotI2CMaxReadSize = 35; |
| 39 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 40 | static constexpr const char* callbackMgrService = |
| 41 | "xyz.openbmc_project.CallbackManager"; |
| 42 | static constexpr const char* callbackMgrIntf = |
| 43 | "xyz.openbmc_project.CallbackManager"; |
| 44 | static constexpr const char* callbackMgrObjPath = |
| 45 | "/xyz/openbmc_project/CallbackManager"; |
| 46 | static constexpr const char* retriggerLedUpdate = "RetriggerLEDUpdate"; |
| 47 | |
| 48 | const static constexpr char* systemDService = "org.freedesktop.systemd1"; |
| 49 | const static constexpr char* systemDObjPath = "/org/freedesktop/systemd1"; |
| 50 | const static constexpr char* systemDMgrIntf = |
| 51 | "org.freedesktop.systemd1.Manager"; |
| 52 | const static constexpr char* pidControlService = "phosphor-pid-control.service"; |
| 53 | |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 54 | static inline Cc resetMtmTimer(ipmi::Context::ptr ctx) |
Richard Marian Thomaiyar | 666dd01 | 2019-08-02 20:55:37 +0530 | [diff] [blame] | 55 | { |
Richard Marian Thomaiyar | 666dd01 | 2019-08-02 20:55:37 +0530 | [diff] [blame] | 56 | boost::system::error_code ec; |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 57 | ctx->bus->yield_method_call<>(ctx->yield, ec, specialModeService, |
| 58 | specialModeObjPath, specialModeIntf, |
| 59 | "ResetTimer"); |
Richard Marian Thomaiyar | 666dd01 | 2019-08-02 20:55:37 +0530 | [diff] [blame] | 60 | if (ec) |
| 61 | { |
| 62 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 63 | "Failed to reset the manufacturing mode timer"); |
| 64 | return ccUnspecifiedError; |
| 65 | } |
| 66 | return ccSuccess; |
| 67 | } |
| 68 | |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 69 | int getGpioPathForSmSignal(const SmSignalGet signal, std::string& path) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 70 | { |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 71 | switch (signal) |
| 72 | { |
| 73 | case SmSignalGet::smPowerButton: |
| 74 | path = "/xyz/openbmc_project/chassis/buttons/power"; |
| 75 | break; |
| 76 | case SmSignalGet::smResetButton: |
| 77 | path = "/xyz/openbmc_project/chassis/buttons/reset"; |
| 78 | break; |
| 79 | case SmSignalGet::smNMIButton: |
| 80 | path = "/xyz/openbmc_project/chassis/buttons/nmi"; |
| 81 | break; |
Richard Marian Thomaiyar | 8e5e2b0 | 2019-08-01 07:50:55 +0530 | [diff] [blame] | 82 | case SmSignalGet::smIdentifyButton: |
| 83 | path = "/xyz/openbmc_project/chassis/buttons/id"; |
| 84 | break; |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 85 | default: |
| 86 | return -1; |
| 87 | break; |
| 88 | } |
| 89 | return 0; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Patrick Venture | 3789039 | 2019-09-25 17:05:03 -0700 | [diff] [blame] | 92 | ipmi_ret_t ledStoreAndSet(SmSignalSet signal, const std::string& setState) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 93 | { |
| 94 | LedProperty* ledProp = mtm.findLedProperty(signal); |
| 95 | if (ledProp == nullptr) |
| 96 | { |
| 97 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 98 | } |
| 99 | |
| 100 | std::string ledName = ledProp->getName(); |
| 101 | std::string ledService = ledServicePrefix + ledName; |
| 102 | std::string ledPath = ledPathPrefix + ledName; |
| 103 | ipmi::Value presentState; |
| 104 | |
| 105 | if (false == ledProp->getLock()) |
| 106 | { |
| 107 | if (mtm.getProperty(ledService.c_str(), ledPath.c_str(), ledIntf, |
| 108 | "State", &presentState) != 0) |
| 109 | { |
| 110 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 111 | } |
| 112 | ledProp->setPrevState(std::get<std::string>(presentState)); |
| 113 | ledProp->setLock(true); |
| 114 | if (signal == SmSignalSet::smPowerFaultLed || |
| 115 | signal == SmSignalSet::smSystemReadyLed) |
| 116 | { |
| 117 | mtm.revertLedCallback = true; |
| 118 | } |
| 119 | } |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 120 | if (mtm.setProperty(ledService, ledPath, ledIntf, "State", |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 121 | ledStateStr + setState) != 0) |
| 122 | { |
| 123 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 124 | } |
| 125 | return IPMI_CC_OK; |
| 126 | } |
| 127 | |
| 128 | ipmi_ret_t ledRevert(SmSignalSet signal) |
| 129 | { |
| 130 | LedProperty* ledProp = mtm.findLedProperty(signal); |
| 131 | if (ledProp == nullptr) |
| 132 | { |
| 133 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 134 | } |
| 135 | if (true == ledProp->getLock()) |
| 136 | { |
| 137 | ledProp->setLock(false); |
| 138 | if (signal == SmSignalSet::smPowerFaultLed || |
| 139 | signal == SmSignalSet::smSystemReadyLed) |
| 140 | { |
| 141 | try |
| 142 | { |
| 143 | ipmi::method_no_args::callDbusMethod( |
| 144 | *getSdBus(), callbackMgrService, callbackMgrObjPath, |
| 145 | callbackMgrIntf, retriggerLedUpdate); |
| 146 | } |
| 147 | catch (sdbusplus::exception_t& e) |
| 148 | { |
| 149 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 150 | } |
| 151 | mtm.revertLedCallback = false; |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | std::string ledName = ledProp->getName(); |
| 156 | std::string ledService = ledServicePrefix + ledName; |
| 157 | std::string ledPath = ledPathPrefix + ledName; |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 158 | if (mtm.setProperty(ledService, ledPath, ledIntf, "State", |
| 159 | ledProp->getPrevState()) != 0) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 160 | { |
| 161 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | return IPMI_CC_OK; |
| 166 | } |
| 167 | |
| 168 | void Manufacturing::initData() |
| 169 | { |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 170 | ledPropertyList.push_back( |
| 171 | LedProperty(SmSignalSet::smPowerFaultLed, "status_amber")); |
| 172 | ledPropertyList.push_back( |
| 173 | LedProperty(SmSignalSet::smSystemReadyLed, "status_green")); |
| 174 | ledPropertyList.push_back( |
| 175 | LedProperty(SmSignalSet::smIdentifyLed, "identify")); |
| 176 | } |
| 177 | |
| 178 | void Manufacturing::revertTimerHandler() |
| 179 | { |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 180 | |
| 181 | #ifdef BMC_VALIDATION_UNSECURE_FEATURE |
| 182 | if (mtm.getMfgMode() == SpecialMode::valUnsecure) |
| 183 | { |
| 184 | // Don't revert the behaviour for validation unsecure mode. |
| 185 | return; |
| 186 | } |
| 187 | #endif |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 188 | if (revertFanPWM) |
| 189 | { |
| 190 | revertFanPWM = false; |
| 191 | disablePidControlService(false); |
| 192 | } |
| 193 | |
Ayushi Smriti | d872a4a | 2019-10-15 10:20:11 +0530 | [diff] [blame] | 194 | if (mtmTestBeepFd != -1) |
| 195 | { |
| 196 | ::close(mtmTestBeepFd); |
| 197 | mtmTestBeepFd = -1; |
| 198 | } |
| 199 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 200 | for (const auto& ledProperty : ledPropertyList) |
| 201 | { |
| 202 | const std::string& ledName = ledProperty.getName(); |
Jayaprakash Mutyala | f365614 | 2021-01-24 01:04:19 +0000 | [diff] [blame] | 203 | if (ledName == "identify" && mtm.getMfgMode() == SpecialMode::mfg) |
| 204 | { |
| 205 | // Don't revert the behaviour for manufacturing mode |
| 206 | continue; |
| 207 | } |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 208 | ledRevert(ledProperty.getSignal()); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | Manufacturing::Manufacturing() : |
| 213 | revertTimer([&](void) { revertTimerHandler(); }) |
| 214 | { |
| 215 | initData(); |
| 216 | } |
| 217 | |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 218 | int8_t Manufacturing::getProperty(const std::string& service, |
| 219 | const std::string& path, |
| 220 | const std::string& interface, |
| 221 | const std::string& propertyName, |
| 222 | ipmi::Value* reply) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 223 | { |
| 224 | try |
| 225 | { |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 226 | *reply = ipmi::getDbusProperty(*getSdBus(), service, path, interface, |
| 227 | propertyName); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 228 | } |
| 229 | catch (const sdbusplus::exception::SdBusError& e) |
| 230 | { |
| 231 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 232 | "ERROR: getProperty"); |
| 233 | return -1; |
| 234 | } |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 239 | int8_t Manufacturing::setProperty(const std::string& service, |
| 240 | const std::string& path, |
| 241 | const std::string& interface, |
| 242 | const std::string& propertyName, |
| 243 | ipmi::Value value) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 244 | { |
| 245 | try |
| 246 | { |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 247 | ipmi::setDbusProperty(*getSdBus(), service, path, interface, |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 248 | propertyName, value); |
| 249 | } |
| 250 | catch (const sdbusplus::exception::SdBusError& e) |
| 251 | { |
| 252 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 253 | "ERROR: setProperty"); |
| 254 | return -1; |
| 255 | } |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | int8_t Manufacturing::disablePidControlService(const bool disable) |
| 261 | { |
| 262 | try |
| 263 | { |
| 264 | auto dbus = getSdBus(); |
| 265 | auto method = dbus->new_method_call(systemDService, systemDObjPath, |
| 266 | systemDMgrIntf, |
| 267 | disable ? "StopUnit" : "StartUnit"); |
| 268 | method.append(pidControlService, "replace"); |
| 269 | auto reply = dbus->call(method); |
| 270 | } |
| 271 | catch (const sdbusplus::exception::SdBusError& e) |
| 272 | { |
| 273 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 274 | "ERROR: phosphor-pid-control service start or stop failed"); |
| 275 | return -1; |
| 276 | } |
| 277 | return 0; |
| 278 | } |
| 279 | |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 280 | ipmi::RspType<uint8_t, // Signal value |
| 281 | std::optional<uint16_t> // Fan tach value |
| 282 | > |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 283 | appMTMGetSignal(ipmi::Context::ptr ctx, uint8_t signalTypeByte, |
Richard Marian Thomaiyar | 147daec | 2019-06-15 07:43:48 +0530 | [diff] [blame] | 284 | uint8_t instance, uint8_t actionByte) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 285 | { |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 286 | // mfg filter logic is used to allow MTM get signal command only in |
| 287 | // manfacturing mode. |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 288 | |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 289 | SmSignalGet signalType = static_cast<SmSignalGet>(signalTypeByte); |
| 290 | SmActionGet action = static_cast<SmActionGet>(actionByte); |
| 291 | |
| 292 | switch (signalType) |
| 293 | { |
anil kumar appana | 98705b3 | 2019-09-11 14:15:50 +0000 | [diff] [blame] | 294 | case SmSignalGet::smChassisIntrusion: |
| 295 | { |
| 296 | ipmi::Value reply; |
| 297 | if (mtm.getProperty(intrusionService, intrusionPath, intrusionIntf, |
| 298 | "Status", &reply) < 0) |
| 299 | { |
| 300 | return ipmi::responseInvalidFieldRequest(); |
| 301 | } |
| 302 | std::string* intrusionStatus = std::get_if<std::string>(&reply); |
| 303 | if (!intrusionStatus) |
| 304 | { |
| 305 | return ipmi::responseUnspecifiedError(); |
| 306 | } |
| 307 | |
| 308 | uint8_t status = 0; |
| 309 | if (!intrusionStatus->compare("Normal")) |
| 310 | { |
| 311 | status = static_cast<uint8_t>(IntrusionStatus::normal); |
| 312 | } |
| 313 | else if (!intrusionStatus->compare("HardwareIntrusion")) |
| 314 | { |
| 315 | status = |
| 316 | static_cast<uint8_t>(IntrusionStatus::hardwareIntrusion); |
| 317 | } |
| 318 | else if (!intrusionStatus->compare("TamperingDetected")) |
| 319 | { |
| 320 | status = |
| 321 | static_cast<uint8_t>(IntrusionStatus::tamperingDetected); |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | return ipmi::responseUnspecifiedError(); |
| 326 | } |
| 327 | return ipmi::responseSuccess(status, std::nullopt); |
| 328 | } |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 329 | case SmSignalGet::smFanPwmGet: |
| 330 | { |
| 331 | ipmi::Value reply; |
Richard Marian Thomaiyar | 147daec | 2019-06-15 07:43:48 +0530 | [diff] [blame] | 332 | std::string fullPath = fanPwmPath + std::to_string(instance + 1); |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 333 | if (mtm.getProperty(fanService, fullPath, fanIntf, "Value", |
| 334 | &reply) < 0) |
| 335 | { |
| 336 | return ipmi::responseInvalidFieldRequest(); |
| 337 | } |
| 338 | double* doubleVal = std::get_if<double>(&reply); |
| 339 | if (doubleVal == nullptr) |
| 340 | { |
| 341 | return ipmi::responseUnspecifiedError(); |
| 342 | } |
| 343 | uint8_t sensorVal = std::round(*doubleVal); |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 344 | resetMtmTimer(ctx); |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 345 | return ipmi::responseSuccess(sensorVal, std::nullopt); |
| 346 | } |
| 347 | break; |
| 348 | case SmSignalGet::smFanTachometerGet: |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 349 | { |
Richard Marian Thomaiyar | 147daec | 2019-06-15 07:43:48 +0530 | [diff] [blame] | 350 | boost::system::error_code ec; |
| 351 | using objFlatMap = boost::container::flat_map< |
| 352 | std::string, boost::container::flat_map< |
| 353 | std::string, std::vector<std::string>>>; |
| 354 | |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 355 | auto flatMap = ctx->bus->yield_method_call<objFlatMap>( |
| 356 | ctx->yield, ec, "xyz.openbmc_project.ObjectMapper", |
Richard Marian Thomaiyar | 147daec | 2019-06-15 07:43:48 +0530 | [diff] [blame] | 357 | "/xyz/openbmc_project/object_mapper", |
| 358 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 359 | fanTachBasePath, 0, std::array<const char*, 1>{fanIntf}); |
| 360 | if (ec) |
| 361 | { |
| 362 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 363 | "Failed to query fan tach sub tree objects"); |
| 364 | return ipmi::responseUnspecifiedError(); |
| 365 | } |
| 366 | if (instance >= flatMap.size()) |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 367 | { |
| 368 | return ipmi::responseInvalidFieldRequest(); |
| 369 | } |
Richard Marian Thomaiyar | 147daec | 2019-06-15 07:43:48 +0530 | [diff] [blame] | 370 | auto itr = flatMap.nth(instance); |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 371 | ipmi::Value reply; |
Richard Marian Thomaiyar | 147daec | 2019-06-15 07:43:48 +0530 | [diff] [blame] | 372 | if (mtm.getProperty(fanService, itr->first, fanIntf, "Value", |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 373 | &reply) < 0) |
| 374 | { |
| 375 | return ipmi::responseInvalidFieldRequest(); |
| 376 | } |
| 377 | |
| 378 | double* doubleVal = std::get_if<double>(&reply); |
| 379 | if (doubleVal == nullptr) |
| 380 | { |
| 381 | return ipmi::responseUnspecifiedError(); |
| 382 | } |
| 383 | uint8_t sensorVal = FAN_PRESENT | FAN_SENSOR_PRESENT; |
| 384 | std::optional<uint16_t> fanTach = std::round(*doubleVal); |
| 385 | |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 386 | resetMtmTimer(ctx); |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 387 | return ipmi::responseSuccess(sensorVal, fanTach); |
| 388 | } |
| 389 | break; |
Richard Marian Thomaiyar | 8e5e2b0 | 2019-08-01 07:50:55 +0530 | [diff] [blame] | 390 | case SmSignalGet::smIdentifyButton: |
| 391 | { |
| 392 | if (action == SmActionGet::revert || action == SmActionGet::ignore) |
| 393 | { |
| 394 | // ButtonMasked property is not supported for ID button as it is |
| 395 | // unnecessary. Hence if requested for revert / ignore, override |
| 396 | // it to sample action to make tools happy. |
| 397 | action = SmActionGet::sample; |
| 398 | } |
| 399 | // fall-through |
| 400 | } |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 401 | case SmSignalGet::smResetButton: |
| 402 | case SmSignalGet::smPowerButton: |
| 403 | case SmSignalGet::smNMIButton: |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 404 | { |
| 405 | std::string path; |
| 406 | if (getGpioPathForSmSignal(signalType, path) < 0) |
| 407 | { |
| 408 | return ipmi::responseInvalidFieldRequest(); |
| 409 | } |
| 410 | |
| 411 | switch (action) |
| 412 | { |
| 413 | case SmActionGet::sample: |
| 414 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 415 | "case SmActionGet::sample"); |
| 416 | break; |
| 417 | case SmActionGet::ignore: |
| 418 | { |
| 419 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 420 | "case SmActionGet::ignore"); |
| 421 | if (mtm.setProperty(buttonService, path, buttonIntf, |
| 422 | "ButtonMasked", true) < 0) |
| 423 | { |
| 424 | return ipmi::responseUnspecifiedError(); |
| 425 | } |
| 426 | } |
| 427 | break; |
| 428 | case SmActionGet::revert: |
| 429 | { |
| 430 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 431 | "case SmActionGet::revert"); |
| 432 | if (mtm.setProperty(buttonService, path, buttonIntf, |
| 433 | "ButtonMasked", false) < 0) |
| 434 | { |
| 435 | return ipmi::responseUnspecifiedError(); |
| 436 | } |
| 437 | } |
| 438 | break; |
| 439 | |
| 440 | default: |
| 441 | return ipmi::responseInvalidFieldRequest(); |
| 442 | break; |
| 443 | } |
| 444 | |
| 445 | ipmi::Value reply; |
| 446 | if (mtm.getProperty(buttonService, path, buttonIntf, |
| 447 | "ButtonPressed", &reply) < 0) |
| 448 | { |
| 449 | return ipmi::responseUnspecifiedError(); |
| 450 | } |
| 451 | bool* valPtr = std::get_if<bool>(&reply); |
| 452 | if (valPtr == nullptr) |
| 453 | { |
| 454 | return ipmi::responseUnspecifiedError(); |
| 455 | } |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 456 | resetMtmTimer(ctx); |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 457 | uint8_t sensorVal = *valPtr; |
| 458 | return ipmi::responseSuccess(sensorVal, std::nullopt); |
| 459 | } |
| 460 | break; |
Richard Marian Thomaiyar | 1b74a21 | 2019-08-03 13:26:17 +0530 | [diff] [blame] | 461 | case SmSignalGet::smNcsiDiag: |
| 462 | { |
| 463 | constexpr const char* netBasePath = "/sys/class/net/eth"; |
| 464 | constexpr const char* carrierSuffix = "/carrier"; |
| 465 | std::ifstream netIfs(netBasePath + std::to_string(instance) + |
| 466 | carrierSuffix); |
| 467 | if (!netIfs.good()) |
| 468 | { |
| 469 | return ipmi::responseInvalidFieldRequest(); |
| 470 | } |
| 471 | std::string carrier; |
| 472 | netIfs >> carrier; |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 473 | resetMtmTimer(ctx); |
Richard Marian Thomaiyar | 1b74a21 | 2019-08-03 13:26:17 +0530 | [diff] [blame] | 474 | return ipmi::responseSuccess( |
| 475 | static_cast<uint8_t>(std::stoi(carrier)), std::nullopt); |
| 476 | } |
| 477 | break; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 478 | default: |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 479 | return ipmi::responseInvalidFieldRequest(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 480 | break; |
| 481 | } |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 484 | ipmi::RspType<> appMTMSetSignal(ipmi::Context::ptr ctx, uint8_t signalTypeByte, |
| 485 | uint8_t instance, uint8_t actionByte, |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 486 | std::optional<uint8_t> pwmSpeed) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 487 | { |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 488 | // mfg filter logic is used to allow MTM set signal command only in |
| 489 | // manfacturing mode. |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 490 | |
| 491 | SmSignalSet signalType = static_cast<SmSignalSet>(signalTypeByte); |
| 492 | SmActionSet action = static_cast<SmActionSet>(actionByte); |
| 493 | Cc retCode = ccSuccess; |
| 494 | int8_t ret = 0; |
| 495 | |
| 496 | switch (signalType) |
| 497 | { |
| 498 | case SmSignalSet::smPowerFaultLed: |
| 499 | case SmSignalSet::smSystemReadyLed: |
| 500 | case SmSignalSet::smIdentifyLed: |
| 501 | switch (action) |
| 502 | { |
| 503 | case SmActionSet::forceDeasserted: |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 504 | { |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 505 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 506 | "case SmActionSet::forceDeasserted"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 507 | |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 508 | retCode = ledStoreAndSet(signalType, std::string("Off")); |
| 509 | if (retCode != ccSuccess) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 510 | { |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 511 | return ipmi::response(retCode); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 512 | } |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 513 | mtm.revertTimer.start(revertTimeOut); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 514 | } |
| 515 | break; |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 516 | case SmActionSet::forceAsserted: |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 517 | { |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 518 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 519 | "case SmActionSet::forceAsserted"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 520 | |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 521 | retCode = ledStoreAndSet(signalType, std::string("On")); |
| 522 | if (retCode != ccSuccess) |
| 523 | { |
| 524 | return ipmi::response(retCode); |
| 525 | } |
| 526 | mtm.revertTimer.start(revertTimeOut); |
| 527 | if (SmSignalSet::smPowerFaultLed == signalType) |
| 528 | { |
| 529 | // Deassert "system ready" |
| 530 | retCode = ledStoreAndSet(SmSignalSet::smSystemReadyLed, |
| 531 | std::string("Off")); |
| 532 | } |
| 533 | else if (SmSignalSet::smSystemReadyLed == signalType) |
| 534 | { |
| 535 | // Deassert "fault led" |
| 536 | retCode = ledStoreAndSet(SmSignalSet::smPowerFaultLed, |
| 537 | std::string("Off")); |
| 538 | } |
| 539 | } |
| 540 | break; |
| 541 | case SmActionSet::revert: |
| 542 | { |
| 543 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 544 | "case SmActionSet::revert"); |
| 545 | retCode = ledRevert(signalType); |
| 546 | } |
| 547 | break; |
| 548 | default: |
| 549 | { |
| 550 | return ipmi::responseInvalidFieldRequest(); |
| 551 | } |
| 552 | } |
| 553 | break; |
| 554 | case SmSignalSet::smFanPowerSpeed: |
| 555 | { |
| 556 | if ((action == SmActionSet::forceAsserted) && (!pwmSpeed)) |
| 557 | { |
| 558 | return ipmi::responseReqDataLenInvalid(); |
| 559 | } |
| 560 | |
| 561 | if ((action == SmActionSet::forceAsserted) && (*pwmSpeed > 100)) |
| 562 | { |
| 563 | return ipmi::responseInvalidFieldRequest(); |
| 564 | } |
| 565 | |
| 566 | uint8_t pwmValue = 0; |
| 567 | switch (action) |
| 568 | { |
| 569 | case SmActionSet::revert: |
| 570 | { |
| 571 | if (mtm.revertFanPWM) |
| 572 | { |
| 573 | ret = mtm.disablePidControlService(false); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 574 | if (ret < 0) |
| 575 | { |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 576 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 577 | } |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 578 | mtm.revertFanPWM = false; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 579 | } |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 580 | } |
| 581 | break; |
| 582 | case SmActionSet::forceAsserted: |
| 583 | { |
| 584 | pwmValue = *pwmSpeed; |
| 585 | } // fall-through |
| 586 | case SmActionSet::forceDeasserted: |
| 587 | { |
| 588 | if (!mtm.revertFanPWM) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 589 | { |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 590 | ret = mtm.disablePidControlService(true); |
| 591 | if (ret < 0) |
| 592 | { |
| 593 | return ipmi::responseUnspecifiedError(); |
| 594 | } |
| 595 | mtm.revertFanPWM = true; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 596 | } |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 597 | mtm.revertTimer.start(revertTimeOut); |
| 598 | std::string fanPwmInstancePath = |
| 599 | fanPwmPath + std::to_string(instance + 1); |
| 600 | |
| 601 | ret = |
| 602 | mtm.setProperty(fanService, fanPwmInstancePath, fanIntf, |
| 603 | "Value", static_cast<double>(pwmValue)); |
| 604 | if (ret < 0) |
| 605 | { |
| 606 | return ipmi::responseUnspecifiedError(); |
| 607 | } |
| 608 | } |
| 609 | break; |
| 610 | default: |
| 611 | { |
| 612 | return ipmi::responseInvalidFieldRequest(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 613 | } |
| 614 | } |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 615 | } |
| 616 | break; |
Ayushi Smriti | d872a4a | 2019-10-15 10:20:11 +0530 | [diff] [blame] | 617 | case SmSignalSet::smSpeaker: |
| 618 | { |
| 619 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 620 | "Performing Speaker SmActionSet", |
| 621 | phosphor::logging::entry("ACTION=%d", |
| 622 | static_cast<uint8_t>(action))); |
| 623 | switch (action) |
| 624 | { |
| 625 | case SmActionSet::forceAsserted: |
| 626 | { |
| 627 | char beepDevName[] = "/dev/input/event0"; |
| 628 | if (mtm.mtmTestBeepFd != -1) |
| 629 | { |
| 630 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 631 | "mtm beep device is opened already!"); |
| 632 | // returning success as already beep is in progress |
| 633 | return ipmi::response(retCode); |
| 634 | } |
| 635 | |
| 636 | if ((mtm.mtmTestBeepFd = |
| 637 | ::open(beepDevName, O_RDWR | O_CLOEXEC)) < 0) |
| 638 | { |
| 639 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 640 | "Failed to open input device"); |
| 641 | return ipmi::responseUnspecifiedError(); |
| 642 | } |
| 643 | |
| 644 | struct input_event event; |
| 645 | event.type = EV_SND; |
| 646 | event.code = SND_TONE; |
| 647 | event.value = 2000; |
| 648 | |
| 649 | if (::write(mtm.mtmTestBeepFd, &event, |
| 650 | sizeof(struct input_event)) != |
| 651 | sizeof(struct input_event)) |
| 652 | { |
| 653 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 654 | "Failed to write a tone sound event"); |
| 655 | ::close(mtm.mtmTestBeepFd); |
| 656 | mtm.mtmTestBeepFd = -1; |
| 657 | return ipmi::responseUnspecifiedError(); |
| 658 | } |
| 659 | mtm.revertTimer.start(revertTimeOut); |
| 660 | } |
| 661 | break; |
| 662 | case SmActionSet::revert: |
| 663 | case SmActionSet::forceDeasserted: |
| 664 | { |
| 665 | if (mtm.mtmTestBeepFd != -1) |
| 666 | { |
| 667 | ::close(mtm.mtmTestBeepFd); |
| 668 | mtm.mtmTestBeepFd = -1; |
| 669 | } |
| 670 | } |
| 671 | break; |
| 672 | default: |
| 673 | { |
| 674 | return ipmi::responseInvalidFieldRequest(); |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | break; |
Richard Marian Thomaiyar | 3594c6d | 2019-11-19 21:29:04 +0530 | [diff] [blame] | 679 | case SmSignalSet::smDiskFaultLed: |
| 680 | { |
| 681 | boost::system::error_code ec; |
| 682 | using objPaths = std::vector<std::string>; |
| 683 | std::string driveBasePath = |
| 684 | "/xyz/openbmc_project/inventory/item/drive/"; |
| 685 | static constexpr const char* driveLedIntf = |
| 686 | "xyz.openbmc_project.Led.Group"; |
| 687 | static constexpr const char* hsbpService = |
| 688 | "xyz.openbmc_project.HsbpManager"; |
| 689 | |
| 690 | auto driveList = ctx->bus->yield_method_call<objPaths>( |
| 691 | ctx->yield, ec, "xyz.openbmc_project.ObjectMapper", |
| 692 | "/xyz/openbmc_project/object_mapper", |
| 693 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", |
| 694 | driveBasePath, 0, std::array<const char*, 1>{driveLedIntf}); |
| 695 | if (ec) |
| 696 | { |
| 697 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 698 | "Failed to query HSBP drive sub tree objects"); |
| 699 | return ipmi::responseUnspecifiedError(); |
| 700 | } |
| 701 | std::string driveObjPath = |
| 702 | driveBasePath + "Drive_" + std::to_string(instance + 1); |
| 703 | if (std::find(driveList.begin(), driveList.end(), driveObjPath) == |
| 704 | driveList.end()) |
| 705 | { |
| 706 | return ipmi::responseInvalidFieldRequest(); |
| 707 | } |
| 708 | bool driveLedState = false; |
| 709 | switch (action) |
| 710 | { |
| 711 | case SmActionSet::forceAsserted: |
| 712 | { |
| 713 | driveLedState = true; |
| 714 | } |
| 715 | break; |
| 716 | case SmActionSet::revert: |
| 717 | { |
| 718 | driveLedState = false; |
| 719 | } |
| 720 | break; |
| 721 | case SmActionSet::forceDeasserted: |
| 722 | { |
| 723 | driveLedState = false; |
| 724 | } |
| 725 | break; |
| 726 | default: |
| 727 | { |
| 728 | return ipmi::responseInvalidFieldRequest(); |
| 729 | } |
| 730 | } |
| 731 | ret = mtm.setProperty(hsbpService, driveObjPath, driveLedIntf, |
| 732 | "Asserted", driveLedState); |
| 733 | if (ret < 0) |
| 734 | { |
| 735 | return ipmi::responseUnspecifiedError(); |
| 736 | } |
| 737 | } |
| 738 | break; |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 739 | default: |
| 740 | { |
| 741 | return ipmi::responseInvalidFieldRequest(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 742 | } |
| 743 | } |
Richard Marian Thomaiyar | 4cc1015 | 2019-08-02 23:21:45 +0530 | [diff] [blame] | 744 | if (retCode == ccSuccess) |
| 745 | { |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 746 | resetMtmTimer(ctx); |
Richard Marian Thomaiyar | 4cc1015 | 2019-08-02 23:21:45 +0530 | [diff] [blame] | 747 | } |
Ayushi Smriti | 5e3bf55 | 2019-07-30 15:32:06 +0000 | [diff] [blame] | 748 | return ipmi::response(retCode); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 751 | ipmi::RspType<> mtmKeepAlive(ipmi::Context::ptr ctx, uint8_t reserved, |
Richard Marian Thomaiyar | 666dd01 | 2019-08-02 20:55:37 +0530 | [diff] [blame] | 752 | const std::array<char, 5>& intentionalSignature) |
| 753 | { |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 754 | // mfg filter logic is used to allow MTM keep alive command only in |
| 755 | // manfacturing mode |
| 756 | |
Richard Marian Thomaiyar | 666dd01 | 2019-08-02 20:55:37 +0530 | [diff] [blame] | 757 | constexpr std::array<char, 5> signatureOk = {'I', 'N', 'T', 'E', 'L'}; |
| 758 | if (intentionalSignature != signatureOk || reserved != 0) |
| 759 | { |
| 760 | return ipmi::responseInvalidFieldRequest(); |
| 761 | } |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 762 | return ipmi::response(resetMtmTimer(ctx)); |
Richard Marian Thomaiyar | 666dd01 | 2019-08-02 20:55:37 +0530 | [diff] [blame] | 763 | } |
| 764 | |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 765 | static constexpr unsigned int makeCmdKey(unsigned int netFn, unsigned int cmd) |
| 766 | { |
| 767 | return (netFn << 8) | cmd; |
| 768 | } |
| 769 | |
Yong Li | 85feb13 | 2019-08-09 16:06:03 +0800 | [diff] [blame] | 770 | ipmi::Cc mfgFilterMessage(ipmi::message::Request::ptr request) |
| 771 | { |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 772 | // Restricted commands, must be executed only in Manufacturing mode |
| 773 | switch (makeCmdKey(request->ctx->netFn, request->ctx->cmd)) |
Yong Li | 85feb13 | 2019-08-09 16:06:03 +0800 | [diff] [blame] | 774 | { |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 775 | // i2c master write read command needs additional checking |
| 776 | case makeCmdKey(ipmi::netFnApp, ipmi::app::cmdMasterWriteRead): |
| 777 | if (request->payload.size() > 4) |
| 778 | { |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 779 | // Allow write data count > 1 only in Special mode |
| 780 | if (mtm.getMfgMode() == SpecialMode::none) |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 781 | { |
| 782 | return ipmi::ccInsufficientPrivilege; |
| 783 | } |
| 784 | } |
jayaprakash Mutyala | 2d4a019 | 2019-11-11 22:12:45 +0000 | [diff] [blame] | 785 | return ipmi::ccSuccess; |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 786 | case makeCmdKey(ipmi::netFnOemOne, |
| 787 | ipmi::intel::general::cmdGetSmSignal): |
| 788 | case makeCmdKey(ipmi::netFnOemOne, |
| 789 | ipmi::intel::general::cmdSetSmSignal): |
| 790 | case makeCmdKey(ipmi::netFnOemOne, |
| 791 | ipmi::intel::general::cmdMtmKeepAlive): |
| 792 | case makeCmdKey(ipmi::netFnOemOne, |
| 793 | ipmi::intel::general::cmdSetManufacturingData): |
| 794 | case makeCmdKey(ipmi::netFnOemOne, |
| 795 | ipmi::intel::general::cmdGetManufacturingData): |
Vernon Mauery | 27d2356 | 2021-08-12 10:43:39 -0700 | [diff] [blame] | 796 | case makeCmdKey(ipmi::intel::netFnGeneral, |
| 797 | ipmi::intel::general::cmdSetFITcLayout): |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 798 | case makeCmdKey(ipmi::netFnStorage, ipmi::storage::cmdWriteFruData): |
AppaRao Puli | 9a13daa | 2020-07-13 17:53:00 +0530 | [diff] [blame] | 799 | case makeCmdKey(ipmi::netFnOemTwo, ipmi::intel::platform::cmdClearCMOS): |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 800 | |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 801 | // Check for Special mode |
| 802 | if (mtm.getMfgMode() == SpecialMode::none) |
Yong Li | 85feb13 | 2019-08-09 16:06:03 +0800 | [diff] [blame] | 803 | { |
Ayushi Smriti | e0511e5 | 2019-08-27 17:30:34 +0000 | [diff] [blame] | 804 | return ipmi::ccInvalidCommand; |
Yong Li | 85feb13 | 2019-08-09 16:06:03 +0800 | [diff] [blame] | 805 | } |
jayaprakash Mutyala | 2d4a019 | 2019-11-11 22:12:45 +0000 | [diff] [blame] | 806 | return ipmi::ccSuccess; |
| 807 | case makeCmdKey(ipmi::netFnStorage, ipmi::storage::cmdDeleteSelEntry): |
| 808 | { |
| 809 | return ipmi::ccInvalidCommand; |
| 810 | } |
Yong Li | 85feb13 | 2019-08-09 16:06:03 +0800 | [diff] [blame] | 811 | } |
Yong Li | 85feb13 | 2019-08-09 16:06:03 +0800 | [diff] [blame] | 812 | return ipmi::ccSuccess; |
| 813 | } |
| 814 | |
Richard Marian Thomaiyar | 1f0839c | 2019-08-25 20:10:52 +0530 | [diff] [blame] | 815 | static constexpr uint8_t maxEthSize = 6; |
| 816 | static constexpr uint8_t maxSupportedEth = 3; |
| 817 | static constexpr const char* factoryEthAddrBaseFileName = |
| 818 | "/var/sofs/factory-settings/network/mac/eth"; |
| 819 | |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 820 | ipmi::RspType<> setManufacturingData(ipmi::Context::ptr ctx, uint8_t dataType, |
Richard Marian Thomaiyar | 1f0839c | 2019-08-25 20:10:52 +0530 | [diff] [blame] | 821 | std::array<uint8_t, maxEthSize> ethData) |
| 822 | { |
| 823 | // mfg filter logic will restrict this command executing only in mfg mode. |
| 824 | if (dataType >= maxSupportedEth) |
| 825 | { |
| 826 | return ipmi::responseParmOutOfRange(); |
| 827 | } |
| 828 | |
| 829 | constexpr uint8_t invalidData = 0; |
| 830 | constexpr uint8_t validData = 1; |
| 831 | constexpr uint8_t ethAddrStrSize = |
| 832 | 19; // XX:XX:XX:XX:XX:XX + \n + null termination; |
| 833 | std::vector<uint8_t> buff(ethAddrStrSize); |
| 834 | std::snprintf(reinterpret_cast<char*>(buff.data()), ethAddrStrSize, |
| 835 | "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", ethData.at(0), |
| 836 | ethData.at(1), ethData.at(2), ethData.at(3), ethData.at(4), |
| 837 | ethData.at(5)); |
| 838 | std::ofstream oEthFile(factoryEthAddrBaseFileName + |
| 839 | std::to_string(dataType), |
| 840 | std::ofstream::out); |
| 841 | if (!oEthFile.good()) |
| 842 | { |
| 843 | return ipmi::responseUnspecifiedError(); |
| 844 | } |
| 845 | |
| 846 | oEthFile << reinterpret_cast<char*>(buff.data()); |
Johnathan Mantey | 6d83e4e | 2020-05-08 11:01:01 -0700 | [diff] [blame] | 847 | oEthFile.flush(); |
Richard Marian Thomaiyar | 1f0839c | 2019-08-25 20:10:52 +0530 | [diff] [blame] | 848 | oEthFile.close(); |
| 849 | |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 850 | resetMtmTimer(ctx); |
Richard Marian Thomaiyar | 1f0839c | 2019-08-25 20:10:52 +0530 | [diff] [blame] | 851 | return ipmi::responseSuccess(); |
| 852 | } |
| 853 | |
| 854 | ipmi::RspType<uint8_t, std::array<uint8_t, maxEthSize>> |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 855 | getManufacturingData(ipmi::Context::ptr ctx, uint8_t dataType) |
Richard Marian Thomaiyar | 1f0839c | 2019-08-25 20:10:52 +0530 | [diff] [blame] | 856 | { |
| 857 | // mfg filter logic will restrict this command executing only in mfg mode. |
| 858 | if (dataType >= maxSupportedEth) |
| 859 | { |
| 860 | return ipmi::responseParmOutOfRange(); |
| 861 | } |
| 862 | std::array<uint8_t, maxEthSize> ethData{0}; |
| 863 | constexpr uint8_t invalidData = 0; |
| 864 | constexpr uint8_t validData = 1; |
| 865 | |
| 866 | std::ifstream iEthFile(factoryEthAddrBaseFileName + |
| 867 | std::to_string(dataType), |
| 868 | std::ifstream::in); |
| 869 | if (!iEthFile.good()) |
| 870 | { |
| 871 | return ipmi::responseSuccess(invalidData, ethData); |
| 872 | } |
| 873 | std::string ethStr; |
| 874 | iEthFile >> ethStr; |
| 875 | uint8_t* data = ethData.data(); |
| 876 | std::sscanf(ethStr.c_str(), "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", |
| 877 | data, (data + 1), (data + 2), (data + 3), (data + 4), |
| 878 | (data + 5)); |
| 879 | |
Richard Marian Thomaiyar | 357ddc7 | 2019-09-01 22:40:07 +0530 | [diff] [blame] | 880 | resetMtmTimer(ctx); |
Richard Marian Thomaiyar | 1f0839c | 2019-08-25 20:10:52 +0530 | [diff] [blame] | 881 | return ipmi::responseSuccess(validData, ethData); |
| 882 | } |
| 883 | |
Yong Li | f267a67 | 2019-08-29 11:16:07 +0800 | [diff] [blame] | 884 | /** @brief implements slot master write read IPMI command which can be used for |
| 885 | * low-level I2C/SMBus write, read or write-read access for PCIE slots |
| 886 | * @param reserved - skip 6 bit |
| 887 | * @param addressType - address type |
| 888 | * @param bbSlotNum - baseboard slot number |
| 889 | * @param riserSlotNum - riser slot number |
| 890 | * @param reserved2 - skip 2 bit |
| 891 | * @param slaveAddr - slave address |
| 892 | * @param readCount - number of bytes to be read |
| 893 | * @param writeData - data to be written |
| 894 | * |
| 895 | * @returns IPMI completion code plus response data |
| 896 | */ |
| 897 | ipmi::RspType<std::vector<uint8_t>> |
| 898 | appSlotI2CMasterWriteRead(uint6_t reserved, uint2_t addressType, |
| 899 | uint3_t bbSlotNum, uint3_t riserSlotNum, |
| 900 | uint2_t resvered2, uint8_t slaveAddr, |
| 901 | uint8_t readCount, std::vector<uint8_t> writeData) |
| 902 | { |
| 903 | const size_t writeCount = writeData.size(); |
| 904 | std::string i2cBus; |
| 905 | if (addressType == slotAddressTypeBus) |
| 906 | { |
| 907 | std::string path = "/dev/i2c-mux/Riser_" + |
| 908 | std::to_string(static_cast<uint8_t>(bbSlotNum)) + |
| 909 | "_Mux/Pcie_Slot_" + |
| 910 | std::to_string(static_cast<uint8_t>(riserSlotNum)); |
| 911 | |
| 912 | if (std::filesystem::exists(path) && std::filesystem::is_symlink(path)) |
| 913 | { |
| 914 | i2cBus = std::filesystem::read_symlink(path); |
| 915 | } |
| 916 | else |
| 917 | { |
| 918 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 919 | "Master write read command: Cannot get BusID"); |
| 920 | return ipmi::responseInvalidFieldRequest(); |
| 921 | } |
| 922 | } |
| 923 | else if (addressType == slotAddressTypeUniqueid) |
| 924 | { |
| 925 | i2cBus = "/dev/i2c-" + |
| 926 | std::to_string(static_cast<uint8_t>(bbSlotNum) | |
| 927 | (static_cast<uint8_t>(riserSlotNum) << 3)); |
| 928 | } |
| 929 | else |
| 930 | { |
| 931 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 932 | "Master write read command: invalid request"); |
| 933 | return ipmi::responseInvalidFieldRequest(); |
| 934 | } |
| 935 | |
| 936 | // Allow single byte write as it is offset byte to read the data, rest allow |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 937 | // only in Special mode. |
Yong Li | f267a67 | 2019-08-29 11:16:07 +0800 | [diff] [blame] | 938 | if (writeCount > 1) |
| 939 | { |
Richard Marian Thomaiyar | ae13ac6 | 2019-12-17 15:45:12 +0530 | [diff] [blame] | 940 | if (mtm.getMfgMode() == SpecialMode::none) |
Yong Li | f267a67 | 2019-08-29 11:16:07 +0800 | [diff] [blame] | 941 | { |
| 942 | return ipmi::responseInsufficientPrivilege(); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | if (readCount > slotI2CMaxReadSize) |
| 947 | { |
| 948 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 949 | "Master write read command: Read count exceeds limit"); |
| 950 | return ipmi::responseParmOutOfRange(); |
| 951 | } |
| 952 | |
| 953 | if (!readCount && !writeCount) |
| 954 | { |
| 955 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 956 | "Master write read command: Read & write count are 0"); |
| 957 | return ipmi::responseInvalidFieldRequest(); |
| 958 | } |
| 959 | |
| 960 | std::vector<uint8_t> readBuf(readCount); |
| 961 | |
| 962 | ipmi::Cc retI2C = ipmi::i2cWriteRead(i2cBus, slaveAddr, writeData, readBuf); |
| 963 | if (retI2C != ipmi::ccSuccess) |
| 964 | { |
| 965 | return ipmi::response(retI2C); |
| 966 | } |
| 967 | |
| 968 | return ipmi::responseSuccess(readBuf); |
| 969 | } |
Yong Li | 068b4f2 | 2019-09-17 16:32:18 +0800 | [diff] [blame] | 970 | |
| 971 | ipmi::RspType<> clearCMOS() |
| 972 | { |
Yong Li | d0d010b | 2019-11-18 12:15:21 +0800 | [diff] [blame] | 973 | // There is an i2c device on bus 4, the slave address is 0x38. Based on the |
Yong Li | eaeb6cb | 2020-03-09 20:21:50 +0800 | [diff] [blame] | 974 | // spec, writing 0x1 to address 0x61 on this device, will trigger the clear |
Yong Li | 068b4f2 | 2019-09-17 16:32:18 +0800 | [diff] [blame] | 975 | // CMOS action. |
Yong Li | d0d010b | 2019-11-18 12:15:21 +0800 | [diff] [blame] | 976 | constexpr uint8_t slaveAddr = 0x38; |
Yong Li | 068b4f2 | 2019-09-17 16:32:18 +0800 | [diff] [blame] | 977 | std::string i2cBus = "/dev/i2c-4"; |
Yong Li | eaeb6cb | 2020-03-09 20:21:50 +0800 | [diff] [blame] | 978 | std::vector<uint8_t> writeData = {0x61, 0x1}; |
Yong Li | 068b4f2 | 2019-09-17 16:32:18 +0800 | [diff] [blame] | 979 | std::vector<uint8_t> readBuf(0); |
| 980 | |
Yong Li | 068b4f2 | 2019-09-17 16:32:18 +0800 | [diff] [blame] | 981 | ipmi::Cc retI2C = ipmi::i2cWriteRead(i2cBus, slaveAddr, writeData, readBuf); |
| 982 | return ipmi::response(retI2C); |
| 983 | } |
Vernon Mauery | 27d2356 | 2021-08-12 10:43:39 -0700 | [diff] [blame] | 984 | |
| 985 | ipmi::RspType<> setFITcLayout(uint32_t layout) |
| 986 | { |
| 987 | static constexpr const char* factoryFITcLayout = |
| 988 | "/var/sofs/factory-settings/layout/fitc"; |
| 989 | std::filesystem::path fitcDir = |
| 990 | std::filesystem::path(factoryFITcLayout).parent_path(); |
| 991 | std::error_code ec; |
| 992 | std::filesystem::create_directories(fitcDir, ec); |
| 993 | if (ec) |
| 994 | { |
| 995 | return ipmi::responseUnspecifiedError(); |
| 996 | } |
| 997 | try |
| 998 | { |
| 999 | std::ofstream file(factoryFITcLayout); |
| 1000 | file << layout; |
| 1001 | file.flush(); |
| 1002 | file.close(); |
| 1003 | } |
| 1004 | catch (const std::exception& e) |
| 1005 | { |
| 1006 | return ipmi::responseUnspecifiedError(); |
| 1007 | } |
| 1008 | |
| 1009 | return ipmi::responseSuccess(); |
| 1010 | } |
| 1011 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1012 | } // namespace ipmi |
| 1013 | |
| 1014 | void register_mtm_commands() __attribute__((constructor)); |
| 1015 | void register_mtm_commands() |
| 1016 | { |
Jason M. Bills | 38d2b5a | 2019-06-03 16:26:11 -0700 | [diff] [blame] | 1017 | // <Get SM Signal> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1018 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnGeneral, |
| 1019 | ipmi::intel::general::cmdGetSmSignal, |
| 1020 | ipmi::Privilege::Admin, ipmi::appMTMGetSignal); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1021 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1022 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnGeneral, |
| 1023 | ipmi::intel::general::cmdSetSmSignal, |
| 1024 | ipmi::Privilege::Admin, ipmi::appMTMSetSignal); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1025 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1026 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnGeneral, |
| 1027 | ipmi::intel::general::cmdMtmKeepAlive, |
| 1028 | ipmi::Privilege::Admin, ipmi::mtmKeepAlive); |
Richard Marian Thomaiyar | 666dd01 | 2019-08-02 20:55:37 +0530 | [diff] [blame] | 1029 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1030 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnGeneral, |
| 1031 | ipmi::intel::general::cmdSetManufacturingData, |
| 1032 | ipmi::Privilege::Admin, ipmi::setManufacturingData); |
Richard Marian Thomaiyar | 1f0839c | 2019-08-25 20:10:52 +0530 | [diff] [blame] | 1033 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1034 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnGeneral, |
| 1035 | ipmi::intel::general::cmdGetManufacturingData, |
| 1036 | ipmi::Privilege::Admin, ipmi::getManufacturingData); |
Richard Marian Thomaiyar | 1f0839c | 2019-08-25 20:10:52 +0530 | [diff] [blame] | 1037 | |
Vernon Mauery | 27d2356 | 2021-08-12 10:43:39 -0700 | [diff] [blame] | 1038 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnGeneral, |
| 1039 | ipmi::intel::general::cmdSetFITcLayout, |
| 1040 | ipmi::Privilege::Admin, ipmi::setFITcLayout); |
| 1041 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1042 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1043 | ipmi::intel::general::cmdSlotI2CMasterWriteRead, |
| 1044 | ipmi::Privilege::Admin, |
| 1045 | ipmi::appSlotI2CMasterWriteRead); |
Yong Li | f267a67 | 2019-08-29 11:16:07 +0800 | [diff] [blame] | 1046 | |
Yong Li | 068b4f2 | 2019-09-17 16:32:18 +0800 | [diff] [blame] | 1047 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnPlatform, |
| 1048 | ipmi::intel::platform::cmdClearCMOS, |
| 1049 | ipmi::Privilege::Admin, ipmi::clearCMOS); |
| 1050 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1051 | ipmi::registerFilter(ipmi::prioOemBase, |
Yong Li | 85feb13 | 2019-08-09 16:06:03 +0800 | [diff] [blame] | 1052 | [](ipmi::message::Request::ptr request) { |
| 1053 | return ipmi::mfgFilterMessage(request); |
| 1054 | }); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1055 | } |