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