Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2017 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 | |
Patrick Venture | 31b35d5 | 2019-10-20 13:25:16 -0700 | [diff] [blame] | 17 | #include "sensorcommands.hpp" |
| 18 | |
| 19 | #include "commandutils.hpp" |
| 20 | #include "ipmi_to_redfish_hooks.hpp" |
| 21 | #include "sdrutils.hpp" |
| 22 | #include "sensorutils.hpp" |
| 23 | #include "storagecommands.hpp" |
Patrick Venture | c2a07d4 | 2020-05-30 16:35:03 -0700 | [diff] [blame] | 24 | #include "types.hpp" |
Patrick Venture | 31b35d5 | 2019-10-20 13:25:16 -0700 | [diff] [blame] | 25 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 26 | #include <boost/algorithm/string.hpp> |
| 27 | #include <boost/container/flat_map.hpp> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 28 | #include <ipmid/api.hpp> |
| 29 | #include <ipmid/utils.hpp> |
| 30 | #include <phosphor-logging/log.hpp> |
| 31 | #include <sdbusplus/bus.hpp> |
| 32 | |
| 33 | #include <algorithm> |
| 34 | #include <array> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 35 | #include <chrono> |
| 36 | #include <cmath> |
Patrick Venture | 5c2d26e | 2019-09-25 17:43:53 -0700 | [diff] [blame] | 37 | #include <cstring> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 38 | #include <iostream> |
Patrick Venture | b10ec8b | 2019-09-25 16:39:14 -0700 | [diff] [blame] | 39 | #include <map> |
Patrick Venture | fd2a938 | 2019-09-25 17:47:25 -0700 | [diff] [blame] | 40 | #include <memory> |
Patrick Venture | c4e9de6 | 2019-09-25 17:40:54 -0700 | [diff] [blame] | 41 | #include <optional> |
Patrick Venture | e615402 | 2019-09-25 17:50:25 -0700 | [diff] [blame] | 42 | #include <stdexcept> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 43 | #include <string> |
Patrick Venture | 38f46f2 | 2019-09-25 17:41:26 -0700 | [diff] [blame] | 44 | #include <utility> |
Patrick Venture | eb02a5c | 2019-09-25 17:44:43 -0700 | [diff] [blame] | 45 | #include <variant> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 46 | |
| 47 | namespace ipmi |
| 48 | { |
| 49 | using ManagedObjectType = |
| 50 | std::map<sdbusplus::message::object_path, |
| 51 | std::map<std::string, std::map<std::string, DbusVariant>>>; |
| 52 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 53 | static constexpr int sensorMapUpdatePeriod = 10; |
Alex Qiu | 09701ef | 2020-07-15 17:56:21 -0700 | [diff] [blame] | 54 | static constexpr int sensorMapSdrUpdatePeriod = 60; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 55 | |
| 56 | constexpr size_t maxSDRTotalSize = |
| 57 | 76; // Largest SDR Record Size (type 01) + SDR Overheader Size |
| 58 | constexpr static const uint32_t noTimestamp = 0xFFFFFFFF; |
| 59 | |
| 60 | static uint16_t sdrReservationID; |
| 61 | static uint32_t sdrLastAdd = noTimestamp; |
| 62 | static uint32_t sdrLastRemove = noTimestamp; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 63 | static constexpr size_t lastRecordIndex = 0xFFFF; |
| 64 | static constexpr int GENERAL_ERROR = -1; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 65 | |
Richard Marian Thomaiyar | 01fbcb5 | 2018-11-19 22:04:34 +0530 | [diff] [blame] | 66 | SensorSubTree sensorTree; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 67 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 68 | static boost::container::flat_map<std::string, ManagedObjectType> SensorCache; |
| 69 | |
Jason M. Bills | 17add59 | 2018-11-12 14:30:12 -0800 | [diff] [blame] | 70 | // Specify the comparison required to sort and find char* map objects |
| 71 | struct CmpStr |
| 72 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 73 | bool operator()(const char* a, const char* b) const |
Jason M. Bills | 17add59 | 2018-11-12 14:30:12 -0800 | [diff] [blame] | 74 | { |
| 75 | return std::strcmp(a, b) < 0; |
| 76 | } |
| 77 | }; |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 78 | const static boost::container::flat_map<const char*, SensorUnits, CmpStr> |
Jason M. Bills | 17add59 | 2018-11-12 14:30:12 -0800 | [diff] [blame] | 79 | sensorUnits{{{"temperature", SensorUnits::degreesC}, |
| 80 | {"voltage", SensorUnits::volts}, |
| 81 | {"current", SensorUnits::amps}, |
| 82 | {"fan_tach", SensorUnits::rpm}, |
| 83 | {"power", SensorUnits::watts}}}; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 84 | |
| 85 | void registerSensorFunctions() __attribute__((constructor)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 86 | |
| 87 | static sdbusplus::bus::match::match sensorAdded( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 88 | *getSdBus(), |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 89 | "type='signal',member='InterfacesAdded',arg0path='/xyz/openbmc_project/" |
| 90 | "sensors/'", |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 91 | [](sdbusplus::message::message& m) { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 92 | sensorTree.clear(); |
| 93 | sdrLastAdd = std::chrono::duration_cast<std::chrono::seconds>( |
| 94 | std::chrono::system_clock::now().time_since_epoch()) |
| 95 | .count(); |
| 96 | }); |
| 97 | |
| 98 | static sdbusplus::bus::match::match sensorRemoved( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 99 | *getSdBus(), |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 100 | "type='signal',member='InterfacesRemoved',arg0path='/xyz/openbmc_project/" |
| 101 | "sensors/'", |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 102 | [](sdbusplus::message::message& m) { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 103 | sensorTree.clear(); |
| 104 | sdrLastRemove = std::chrono::duration_cast<std::chrono::seconds>( |
| 105 | std::chrono::system_clock::now().time_since_epoch()) |
| 106 | .count(); |
| 107 | }); |
| 108 | |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 109 | // this keeps track of deassertions for sensor event status command. A |
| 110 | // deasertion can only happen if an assertion was seen first. |
| 111 | static boost::container::flat_map< |
| 112 | std::string, boost::container::flat_map<std::string, std::optional<bool>>> |
| 113 | thresholdDeassertMap; |
| 114 | |
| 115 | static sdbusplus::bus::match::match thresholdChanged( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 116 | *getSdBus(), |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 117 | "type='signal',member='PropertiesChanged',interface='org.freedesktop.DBus." |
| 118 | "Properties',arg0namespace='xyz.openbmc_project.Sensor.Threshold'", |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 119 | [](sdbusplus::message::message& m) { |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 120 | boost::container::flat_map<std::string, std::variant<bool, double>> |
| 121 | values; |
| 122 | m.read(std::string(), values); |
| 123 | |
| 124 | auto findAssert = |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 125 | std::find_if(values.begin(), values.end(), [](const auto& pair) { |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 126 | return pair.first.find("Alarm") != std::string::npos; |
| 127 | }); |
| 128 | if (findAssert != values.end()) |
| 129 | { |
| 130 | auto ptr = std::get_if<bool>(&(findAssert->second)); |
| 131 | if (ptr == nullptr) |
| 132 | { |
| 133 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 134 | "thresholdChanged: Assert non bool"); |
| 135 | return; |
| 136 | } |
| 137 | if (*ptr) |
| 138 | { |
| 139 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 140 | "thresholdChanged: Assert", |
| 141 | phosphor::logging::entry("SENSOR=%s", m.get_path())); |
| 142 | thresholdDeassertMap[m.get_path()][findAssert->first] = *ptr; |
| 143 | } |
| 144 | else |
| 145 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 146 | auto& value = |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 147 | thresholdDeassertMap[m.get_path()][findAssert->first]; |
| 148 | if (value) |
| 149 | { |
| 150 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 151 | "thresholdChanged: deassert", |
| 152 | phosphor::logging::entry("SENSOR=%s", m.get_path())); |
| 153 | value = *ptr; |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | }); |
| 158 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 159 | static void getSensorMaxMin(const SensorMap& sensorMap, double& max, |
| 160 | double& min) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 161 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 162 | max = 127; |
| 163 | min = -128; |
| 164 | |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 165 | auto sensorObject = sensorMap.find("xyz.openbmc_project.Sensor.Value"); |
| 166 | auto critical = |
| 167 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 168 | auto warning = |
| 169 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 170 | |
| 171 | if (sensorObject != sensorMap.end()) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 172 | { |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 173 | auto maxMap = sensorObject->second.find("MaxValue"); |
| 174 | auto minMap = sensorObject->second.find("MinValue"); |
| 175 | |
| 176 | if (maxMap != sensorObject->second.end()) |
| 177 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 178 | max = std::visit(VariantToDoubleVisitor(), maxMap->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 179 | } |
| 180 | if (minMap != sensorObject->second.end()) |
| 181 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 182 | min = std::visit(VariantToDoubleVisitor(), minMap->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 183 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 184 | } |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 185 | if (critical != sensorMap.end()) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 186 | { |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 187 | auto lower = critical->second.find("CriticalLow"); |
| 188 | auto upper = critical->second.find("CriticalHigh"); |
| 189 | if (lower != critical->second.end()) |
| 190 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 191 | double value = std::visit(VariantToDoubleVisitor(), lower->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 192 | min = std::min(value, min); |
| 193 | } |
| 194 | if (upper != critical->second.end()) |
| 195 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 196 | double value = std::visit(VariantToDoubleVisitor(), upper->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 197 | max = std::max(value, max); |
| 198 | } |
| 199 | } |
| 200 | if (warning != sensorMap.end()) |
| 201 | { |
| 202 | |
| 203 | auto lower = warning->second.find("WarningLow"); |
| 204 | auto upper = warning->second.find("WarningHigh"); |
| 205 | if (lower != warning->second.end()) |
| 206 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 207 | double value = std::visit(VariantToDoubleVisitor(), lower->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 208 | min = std::min(value, min); |
| 209 | } |
| 210 | if (upper != warning->second.end()) |
| 211 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 212 | double value = std::visit(VariantToDoubleVisitor(), upper->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 213 | max = std::max(value, max); |
| 214 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 218 | static bool getSensorMap(boost::asio::yield_context yield, |
| 219 | std::string sensorConnection, std::string sensorPath, |
Alex Qiu | 09701ef | 2020-07-15 17:56:21 -0700 | [diff] [blame] | 220 | SensorMap& sensorMap, |
| 221 | int updatePeriod = sensorMapUpdatePeriod) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 222 | { |
| 223 | static boost::container::flat_map< |
| 224 | std::string, std::chrono::time_point<std::chrono::steady_clock>> |
| 225 | updateTimeMap; |
| 226 | |
| 227 | auto updateFind = updateTimeMap.find(sensorConnection); |
| 228 | auto lastUpdate = std::chrono::time_point<std::chrono::steady_clock>(); |
| 229 | if (updateFind != updateTimeMap.end()) |
| 230 | { |
| 231 | lastUpdate = updateFind->second; |
| 232 | } |
| 233 | |
| 234 | auto now = std::chrono::steady_clock::now(); |
| 235 | |
| 236 | if (std::chrono::duration_cast<std::chrono::seconds>(now - lastUpdate) |
Alex Qiu | 09701ef | 2020-07-15 17:56:21 -0700 | [diff] [blame] | 237 | .count() > updatePeriod) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 238 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 239 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 240 | boost::system::error_code ec; |
| 241 | auto managedObjects = dbus->yield_method_call<ManagedObjectType>( |
| 242 | yield, ec, sensorConnection.c_str(), "/", |
| 243 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 244 | if (ec) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 245 | { |
| 246 | phosphor::logging::log<phosphor::logging::level::ERR>( |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 247 | "GetMangagedObjects for getSensorMap failed", |
| 248 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 249 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 250 | return false; |
| 251 | } |
| 252 | |
| 253 | SensorCache[sensorConnection] = managedObjects; |
Alex Qiu | 09701ef | 2020-07-15 17:56:21 -0700 | [diff] [blame] | 254 | // Update time after finish building the map which allow the |
| 255 | // data to be cached for updatePeriod plus the build time. |
| 256 | updateTimeMap[sensorConnection] = std::chrono::steady_clock::now(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 257 | } |
| 258 | auto connection = SensorCache.find(sensorConnection); |
| 259 | if (connection == SensorCache.end()) |
| 260 | { |
| 261 | return false; |
| 262 | } |
| 263 | auto path = connection->second.find(sensorPath); |
| 264 | if (path == connection->second.end()) |
| 265 | { |
| 266 | return false; |
| 267 | } |
| 268 | sensorMap = path->second; |
| 269 | |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | /* sensor commands */ |
James Feist | 7aaf3fe | 2019-06-25 11:52:11 -0700 | [diff] [blame] | 274 | namespace meHealth |
| 275 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 276 | constexpr const char* busname = "xyz.openbmc_project.NodeManagerProxy"; |
| 277 | constexpr const char* path = "/xyz/openbmc_project/status/me"; |
| 278 | constexpr const char* interface = "xyz.openbmc_project.SetHealth"; |
| 279 | constexpr const char* method = "SetHealth"; |
| 280 | constexpr const char* critical = "critical"; |
| 281 | constexpr const char* warning = "warning"; |
| 282 | constexpr const char* ok = "ok"; |
James Feist | 7aaf3fe | 2019-06-25 11:52:11 -0700 | [diff] [blame] | 283 | } // namespace meHealth |
| 284 | |
| 285 | static void setMeStatus(uint8_t eventData2, uint8_t eventData3, bool disable) |
| 286 | { |
| 287 | constexpr const std::array<uint8_t, 10> critical = { |
| 288 | 0x1, 0x2, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xD, 0xE}; |
| 289 | constexpr const std::array<uint8_t, 5> warning = {0x3, 0xA, 0x13, 0x19, |
| 290 | 0x1A}; |
| 291 | |
| 292 | std::string state; |
| 293 | if (std::find(critical.begin(), critical.end(), eventData2) != |
| 294 | critical.end()) |
| 295 | { |
| 296 | state = meHealth::critical; |
| 297 | } |
| 298 | // special case 0x3 as we only care about a few states |
| 299 | else if (eventData2 == 0x3) |
| 300 | { |
| 301 | if (eventData3 <= 0x2) |
| 302 | { |
| 303 | state = meHealth::warning; |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | return; |
| 308 | } |
| 309 | } |
| 310 | else if (std::find(warning.begin(), warning.end(), eventData2) != |
| 311 | warning.end()) |
| 312 | { |
| 313 | state = meHealth::warning; |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | return; |
| 318 | } |
| 319 | if (disable) |
| 320 | { |
| 321 | state = meHealth::ok; |
| 322 | } |
| 323 | |
| 324 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 325 | auto setHealth = |
| 326 | dbus->new_method_call(meHealth::busname, meHealth::path, |
| 327 | meHealth::interface, meHealth::method); |
| 328 | setHealth.append(std::to_string(static_cast<size_t>(eventData2)), state); |
| 329 | try |
| 330 | { |
| 331 | dbus->call(setHealth); |
| 332 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 333 | catch (sdbusplus::exception_t&) |
James Feist | 7aaf3fe | 2019-06-25 11:52:11 -0700 | [diff] [blame] | 334 | { |
| 335 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 336 | "Failed to set ME Health"); |
| 337 | } |
| 338 | } |
| 339 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 340 | ipmi::RspType<> ipmiSenPlatformEvent(ipmi::message::Payload& p) |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 341 | { |
James Feist | 7aaf3fe | 2019-06-25 11:52:11 -0700 | [diff] [blame] | 342 | constexpr const uint8_t meId = 0x2C; |
| 343 | constexpr const uint8_t meSensorNum = 0x17; |
| 344 | constexpr const uint8_t disabled = 0x80; |
| 345 | |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 346 | uint8_t generatorID = 0; |
| 347 | uint8_t evmRev = 0; |
| 348 | uint8_t sensorType = 0; |
| 349 | uint8_t sensorNum = 0; |
| 350 | uint8_t eventType = 0; |
| 351 | uint8_t eventData1 = 0; |
| 352 | std::optional<uint8_t> eventData2 = 0; |
| 353 | std::optional<uint8_t> eventData3 = 0; |
| 354 | |
| 355 | // todo: This check is supposed to be based on the incoming channel. |
| 356 | // e.g. system channel will provide upto 8 bytes including generator |
| 357 | // ID, but ipmb channel will provide only up to 7 bytes without the |
| 358 | // generator ID. |
| 359 | // Support for this check is coming in future patches, so for now just base |
| 360 | // it on if the first byte is the EvMRev (0x04). |
| 361 | if (p.size() && p.data()[0] == 0x04) |
| 362 | { |
| 363 | p.unpack(evmRev, sensorType, sensorNum, eventType, eventData1, |
| 364 | eventData2, eventData3); |
| 365 | // todo: the generator ID for this channel is supposed to come from the |
| 366 | // IPMB requesters slave address. Support for this is coming in future |
| 367 | // patches, so for now just assume it is coming from the ME (0x2C). |
| 368 | generatorID = 0x2C; |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | p.unpack(generatorID, evmRev, sensorType, sensorNum, eventType, |
| 373 | eventData1, eventData2, eventData3); |
| 374 | } |
| 375 | if (!p.fullyUnpacked()) |
| 376 | { |
| 377 | return ipmi::responseReqDataLenInvalid(); |
| 378 | } |
| 379 | |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 380 | // Send this request to the Redfish hooks to log it as a Redfish message |
| 381 | // instead. There is no need to add it to the SEL, so just return success. |
| 382 | intel_oem::ipmi::sel::checkRedfishHooks( |
| 383 | generatorID, evmRev, sensorType, sensorNum, eventType, eventData1, |
| 384 | eventData2.value_or(0xFF), eventData3.value_or(0xFF)); |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 385 | |
James Feist | 7aaf3fe | 2019-06-25 11:52:11 -0700 | [diff] [blame] | 386 | if (generatorID == meId && sensorNum == meSensorNum && eventData2 && |
| 387 | eventData3) |
| 388 | { |
| 389 | setMeStatus(*eventData2, *eventData3, (eventType & disabled)); |
| 390 | } |
| 391 | |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 392 | return ipmi::responseSuccess(); |
| 393 | } |
| 394 | |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 395 | ipmi::RspType<uint8_t, uint8_t, uint8_t, std::optional<uint8_t>> |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 396 | ipmiSenGetSensorReading(ipmi::Context::ptr ctx, uint8_t sensnum) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 397 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 398 | std::string connection; |
| 399 | std::string path; |
| 400 | |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 401 | auto status = getSensorConnection(ctx, sensnum, connection, path); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 402 | if (status) |
| 403 | { |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 404 | return ipmi::response(status); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | SensorMap sensorMap; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 408 | if (!getSensorMap(ctx->yield, connection, path, sensorMap)) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 409 | { |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 410 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 411 | } |
| 412 | auto sensorObject = sensorMap.find("xyz.openbmc_project.Sensor.Value"); |
| 413 | |
| 414 | if (sensorObject == sensorMap.end() || |
| 415 | sensorObject->second.find("Value") == sensorObject->second.end()) |
| 416 | { |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 417 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 418 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 419 | auto& valueVariant = sensorObject->second["Value"]; |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 420 | double reading = std::visit(VariantToDoubleVisitor(), valueVariant); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 421 | |
Yong Li | 1f2eb5e | 2019-05-23 14:07:17 +0800 | [diff] [blame] | 422 | double max = 0; |
| 423 | double min = 0; |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 424 | getSensorMaxMin(sensorMap, max, min); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 425 | |
| 426 | int16_t mValue = 0; |
| 427 | int16_t bValue = 0; |
| 428 | int8_t rExp = 0; |
| 429 | int8_t bExp = 0; |
| 430 | bool bSigned = false; |
| 431 | |
| 432 | if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned)) |
| 433 | { |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 434 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 435 | } |
| 436 | |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 437 | uint8_t value = |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 438 | scaleIPMIValueFromDouble(reading, mValue, rExp, bValue, bExp, bSigned); |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 439 | uint8_t operation = |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 440 | static_cast<uint8_t>(IPMISensorReadingByte2::sensorScanningEnable); |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 441 | operation |= |
James Feist | 81a95c1 | 2019-03-01 15:08:28 -0800 | [diff] [blame] | 442 | static_cast<uint8_t>(IPMISensorReadingByte2::eventMessagesEnable); |
James Feist | 1ee6ed8 | 2020-06-17 16:16:50 -0700 | [diff] [blame] | 443 | bool notReading = std::isnan(reading); |
| 444 | |
| 445 | if (!notReading) |
| 446 | { |
| 447 | auto availableObject = |
| 448 | sensorMap.find("xyz.openbmc_project.State.Decorator.Availability"); |
| 449 | if (availableObject != sensorMap.end()) |
| 450 | { |
| 451 | auto findAvailable = availableObject->second.find("Available"); |
| 452 | if (findAvailable != availableObject->second.end()) |
| 453 | { |
| 454 | bool* available = std::get_if<bool>(&(findAvailable->second)); |
| 455 | if (available && !(*available)) |
| 456 | { |
| 457 | notReading = true; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | if (notReading) |
| 464 | { |
| 465 | operation |= static_cast<uint8_t>( |
| 466 | IPMISensorReadingByte2::readingStateUnavailable); |
| 467 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 468 | |
Josh Lehan | 06aa21a | 2020-10-28 21:59:06 -0700 | [diff] [blame^] | 469 | int byteValue; |
| 470 | if (bSigned) |
| 471 | { |
| 472 | byteValue = static_cast<int>(static_cast<int8_t>(value)); |
| 473 | } |
| 474 | else |
| 475 | { |
| 476 | byteValue = static_cast<int>(static_cast<uint8_t>(value)); |
| 477 | } |
| 478 | |
| 479 | // Keep stats on the reading just obtained, even if it is "NaN" |
| 480 | if (details::sdrStatsTable.updateReading(sensnum, reading, byteValue)) |
| 481 | { |
| 482 | // This is the first reading, show the coefficients |
| 483 | double step = (max - min) / 255.0; |
| 484 | std::cerr << "IPMI sensor " << details::sdrStatsTable.getName(sensnum) |
| 485 | << ": Range min=" << min << " max=" << max |
| 486 | << ", step=" << step |
| 487 | << ", Coefficients mValue=" << static_cast<int>(mValue) |
| 488 | << " rExp=" << static_cast<int>(rExp) |
| 489 | << " bValue=" << static_cast<int>(bValue) |
| 490 | << " bExp=" << static_cast<int>(bExp) |
| 491 | << " bSigned=" << static_cast<int>(bSigned) << "\n"; |
| 492 | }; |
| 493 | |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 494 | uint8_t thresholds = 0; |
| 495 | |
| 496 | auto warningObject = |
| 497 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 498 | if (warningObject != sensorMap.end()) |
| 499 | { |
| 500 | auto alarmHigh = warningObject->second.find("WarningAlarmHigh"); |
| 501 | auto alarmLow = warningObject->second.find("WarningAlarmLow"); |
| 502 | if (alarmHigh != warningObject->second.end()) |
| 503 | { |
| 504 | if (std::get<bool>(alarmHigh->second)) |
| 505 | { |
| 506 | thresholds |= static_cast<uint8_t>( |
| 507 | IPMISensorReadingByte3::upperNonCritical); |
| 508 | } |
| 509 | } |
| 510 | if (alarmLow != warningObject->second.end()) |
| 511 | { |
| 512 | if (std::get<bool>(alarmLow->second)) |
| 513 | { |
| 514 | thresholds |= static_cast<uint8_t>( |
| 515 | IPMISensorReadingByte3::lowerNonCritical); |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | auto criticalObject = |
| 521 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 522 | if (criticalObject != sensorMap.end()) |
| 523 | { |
| 524 | auto alarmHigh = criticalObject->second.find("CriticalAlarmHigh"); |
| 525 | auto alarmLow = criticalObject->second.find("CriticalAlarmLow"); |
| 526 | if (alarmHigh != criticalObject->second.end()) |
| 527 | { |
| 528 | if (std::get<bool>(alarmHigh->second)) |
| 529 | { |
| 530 | thresholds |= |
| 531 | static_cast<uint8_t>(IPMISensorReadingByte3::upperCritical); |
| 532 | } |
| 533 | } |
| 534 | if (alarmLow != criticalObject->second.end()) |
| 535 | { |
| 536 | if (std::get<bool>(alarmLow->second)) |
| 537 | { |
| 538 | thresholds |= |
| 539 | static_cast<uint8_t>(IPMISensorReadingByte3::lowerCritical); |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | // no discrete as of today so optional byte is never returned |
| 545 | return ipmi::responseSuccess(value, operation, thresholds, std::nullopt); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 546 | } |
| 547 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 548 | /** @brief implements the Set Sensor threshold command |
| 549 | * @param sensorNumber - sensor number |
| 550 | * @param lowerNonCriticalThreshMask |
| 551 | * @param lowerCriticalThreshMask |
| 552 | * @param lowerNonRecovThreshMask |
| 553 | * @param upperNonCriticalThreshMask |
| 554 | * @param upperCriticalThreshMask |
| 555 | * @param upperNonRecovThreshMask |
| 556 | * @param reserved |
| 557 | * @param lowerNonCritical - lower non-critical threshold |
| 558 | * @param lowerCritical - Lower critical threshold |
| 559 | * @param lowerNonRecoverable - Lower non recovarable threshold |
| 560 | * @param upperNonCritical - Upper non-critical threshold |
| 561 | * @param upperCritical - Upper critical |
| 562 | * @param upperNonRecoverable - Upper Non-recoverable |
| 563 | * |
| 564 | * @returns IPMI completion code |
| 565 | */ |
| 566 | ipmi::RspType<> ipmiSenSetSensorThresholds( |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 567 | ipmi::Context::ptr ctx, uint8_t sensorNum, bool lowerNonCriticalThreshMask, |
| 568 | bool lowerCriticalThreshMask, bool lowerNonRecovThreshMask, |
| 569 | bool upperNonCriticalThreshMask, bool upperCriticalThreshMask, |
| 570 | bool upperNonRecovThreshMask, uint2_t reserved, uint8_t lowerNonCritical, |
| 571 | uint8_t lowerCritical, uint8_t lowerNonRecoverable, |
| 572 | uint8_t upperNonCritical, uint8_t upperCritical, |
| 573 | uint8_t upperNonRecoverable) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 574 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 575 | constexpr uint8_t thresholdMask = 0xFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 576 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 577 | if (reserved) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 578 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 579 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | // lower nc and upper nc not suppported on any sensor |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 583 | if (lowerNonRecovThreshMask || upperNonRecovThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 584 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 585 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 586 | } |
| 587 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 588 | // if none of the threshold mask are set, nothing to do |
| 589 | if (!(lowerNonCriticalThreshMask | lowerCriticalThreshMask | |
| 590 | lowerNonRecovThreshMask | upperNonCriticalThreshMask | |
| 591 | upperCriticalThreshMask | upperNonRecovThreshMask)) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 592 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 593 | return ipmi::responseSuccess(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | std::string connection; |
| 597 | std::string path; |
| 598 | |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 599 | ipmi::Cc status = getSensorConnection(ctx, sensorNum, connection, path); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 600 | if (status) |
| 601 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 602 | return ipmi::response(status); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 603 | } |
| 604 | SensorMap sensorMap; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 605 | if (!getSensorMap(ctx->yield, connection, path, sensorMap)) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 606 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 607 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 610 | double max = 0; |
| 611 | double min = 0; |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 612 | getSensorMaxMin(sensorMap, max, min); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 613 | |
| 614 | int16_t mValue = 0; |
| 615 | int16_t bValue = 0; |
| 616 | int8_t rExp = 0; |
| 617 | int8_t bExp = 0; |
| 618 | bool bSigned = false; |
| 619 | |
| 620 | if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned)) |
| 621 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 622 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 625 | // store a vector of property name, value to set, and interface |
| 626 | std::vector<std::tuple<std::string, uint8_t, std::string>> thresholdsToSet; |
| 627 | |
| 628 | // define the indexes of the tuple |
| 629 | constexpr uint8_t propertyName = 0; |
| 630 | constexpr uint8_t thresholdValue = 1; |
| 631 | constexpr uint8_t interface = 2; |
| 632 | // verifiy all needed fields are present |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 633 | if (lowerCriticalThreshMask || upperCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 634 | { |
| 635 | auto findThreshold = |
| 636 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 637 | if (findThreshold == sensorMap.end()) |
| 638 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 639 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 640 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 641 | if (lowerCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 642 | { |
| 643 | auto findLower = findThreshold->second.find("CriticalLow"); |
| 644 | if (findLower == findThreshold->second.end()) |
| 645 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 646 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 647 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 648 | thresholdsToSet.emplace_back("CriticalLow", lowerCritical, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 649 | findThreshold->first); |
| 650 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 651 | if (upperCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 652 | { |
| 653 | auto findUpper = findThreshold->second.find("CriticalHigh"); |
| 654 | if (findUpper == findThreshold->second.end()) |
| 655 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 656 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 657 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 658 | thresholdsToSet.emplace_back("CriticalHigh", upperCritical, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 659 | findThreshold->first); |
| 660 | } |
| 661 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 662 | if (lowerNonCriticalThreshMask || upperNonCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 663 | { |
| 664 | auto findThreshold = |
| 665 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 666 | if (findThreshold == sensorMap.end()) |
| 667 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 668 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 669 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 670 | if (lowerNonCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 671 | { |
| 672 | auto findLower = findThreshold->second.find("WarningLow"); |
| 673 | if (findLower == findThreshold->second.end()) |
| 674 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 675 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 676 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 677 | thresholdsToSet.emplace_back("WarningLow", lowerNonCritical, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 678 | findThreshold->first); |
| 679 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 680 | if (upperNonCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 681 | { |
| 682 | auto findUpper = findThreshold->second.find("WarningHigh"); |
| 683 | if (findUpper == findThreshold->second.end()) |
| 684 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 685 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 686 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 687 | thresholdsToSet.emplace_back("WarningHigh", upperNonCritical, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 688 | findThreshold->first); |
| 689 | } |
| 690 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 691 | for (const auto& property : thresholdsToSet) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 692 | { |
| 693 | // from section 36.3 in the IPMI Spec, assume all linear |
| 694 | double valueToSet = ((mValue * std::get<thresholdValue>(property)) + |
Josh Lehan | 86236a2 | 2019-11-18 17:53:33 -0800 | [diff] [blame] | 695 | (bValue * std::pow(10.0, bExp))) * |
| 696 | std::pow(10.0, rExp); |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 697 | setDbusProperty( |
| 698 | *getSdBus(), connection, path, std::get<interface>(property), |
| 699 | std::get<propertyName>(property), ipmi::Value(valueToSet)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 700 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 701 | return ipmi::responseSuccess(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 702 | } |
| 703 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 704 | IPMIThresholds getIPMIThresholds(const SensorMap& sensorMap) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 705 | { |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 706 | IPMIThresholds resp; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 707 | auto warningInterface = |
| 708 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 709 | auto criticalInterface = |
| 710 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 711 | |
| 712 | if ((warningInterface != sensorMap.end()) || |
| 713 | (criticalInterface != sensorMap.end())) |
| 714 | { |
| 715 | auto sensorPair = sensorMap.find("xyz.openbmc_project.Sensor.Value"); |
| 716 | |
| 717 | if (sensorPair == sensorMap.end()) |
| 718 | { |
| 719 | // should not have been able to find a sensor not implementing |
| 720 | // the sensor object |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 721 | throw std::runtime_error("Invalid sensor map"); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Chen,Yugang | 606dd9f | 2019-07-01 10:37:30 +0800 | [diff] [blame] | 724 | double max = 0; |
| 725 | double min = 0; |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 726 | getSensorMaxMin(sensorMap, max, min); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 727 | |
| 728 | int16_t mValue = 0; |
| 729 | int16_t bValue = 0; |
| 730 | int8_t rExp = 0; |
| 731 | int8_t bExp = 0; |
| 732 | bool bSigned = false; |
| 733 | |
| 734 | if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned)) |
| 735 | { |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 736 | throw std::runtime_error("Invalid sensor atrributes"); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 737 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 738 | if (warningInterface != sensorMap.end()) |
| 739 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 740 | auto& warningMap = warningInterface->second; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 741 | |
| 742 | auto warningHigh = warningMap.find("WarningHigh"); |
| 743 | auto warningLow = warningMap.find("WarningLow"); |
| 744 | |
| 745 | if (warningHigh != warningMap.end()) |
| 746 | { |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 747 | |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 748 | double value = |
| 749 | std::visit(VariantToDoubleVisitor(), warningHigh->second); |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 750 | resp.warningHigh = scaleIPMIValueFromDouble( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 751 | value, mValue, rExp, bValue, bExp, bSigned); |
| 752 | } |
| 753 | if (warningLow != warningMap.end()) |
| 754 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 755 | double value = |
| 756 | std::visit(VariantToDoubleVisitor(), warningLow->second); |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 757 | resp.warningLow = scaleIPMIValueFromDouble( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 758 | value, mValue, rExp, bValue, bExp, bSigned); |
| 759 | } |
| 760 | } |
| 761 | if (criticalInterface != sensorMap.end()) |
| 762 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 763 | auto& criticalMap = criticalInterface->second; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 764 | |
| 765 | auto criticalHigh = criticalMap.find("CriticalHigh"); |
| 766 | auto criticalLow = criticalMap.find("CriticalLow"); |
| 767 | |
| 768 | if (criticalHigh != criticalMap.end()) |
| 769 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 770 | double value = |
| 771 | std::visit(VariantToDoubleVisitor(), criticalHigh->second); |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 772 | resp.criticalHigh = scaleIPMIValueFromDouble( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 773 | value, mValue, rExp, bValue, bExp, bSigned); |
| 774 | } |
| 775 | if (criticalLow != criticalMap.end()) |
| 776 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 777 | double value = |
| 778 | std::visit(VariantToDoubleVisitor(), criticalLow->second); |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 779 | resp.criticalLow = scaleIPMIValueFromDouble( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 780 | value, mValue, rExp, bValue, bExp, bSigned); |
| 781 | } |
| 782 | } |
| 783 | } |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 784 | return resp; |
| 785 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 786 | |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 787 | ipmi::RspType<uint8_t, // readable |
| 788 | uint8_t, // lowerNCrit |
| 789 | uint8_t, // lowerCrit |
| 790 | uint8_t, // lowerNrecoverable |
| 791 | uint8_t, // upperNC |
| 792 | uint8_t, // upperCrit |
| 793 | uint8_t> // upperNRecoverable |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 794 | ipmiSenGetSensorThresholds(ipmi::Context::ptr ctx, uint8_t sensorNumber) |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 795 | { |
| 796 | std::string connection; |
| 797 | std::string path; |
| 798 | |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 799 | auto status = getSensorConnection(ctx, sensorNumber, connection, path); |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 800 | if (status) |
| 801 | { |
| 802 | return ipmi::response(status); |
| 803 | } |
| 804 | |
| 805 | SensorMap sensorMap; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 806 | if (!getSensorMap(ctx->yield, connection, path, sensorMap)) |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 807 | { |
| 808 | return ipmi::responseResponseError(); |
| 809 | } |
| 810 | |
| 811 | IPMIThresholds thresholdData; |
| 812 | try |
| 813 | { |
| 814 | thresholdData = getIPMIThresholds(sensorMap); |
| 815 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 816 | catch (std::exception&) |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 817 | { |
| 818 | return ipmi::responseResponseError(); |
| 819 | } |
| 820 | |
| 821 | uint8_t readable = 0; |
| 822 | uint8_t lowerNC = 0; |
| 823 | uint8_t lowerCritical = 0; |
| 824 | uint8_t lowerNonRecoverable = 0; |
| 825 | uint8_t upperNC = 0; |
| 826 | uint8_t upperCritical = 0; |
| 827 | uint8_t upperNonRecoverable = 0; |
| 828 | |
| 829 | if (thresholdData.warningHigh) |
| 830 | { |
| 831 | readable |= |
| 832 | 1 << static_cast<uint8_t>(IPMIThresholdRespBits::upperNonCritical); |
| 833 | upperNC = *thresholdData.warningHigh; |
| 834 | } |
| 835 | if (thresholdData.warningLow) |
| 836 | { |
| 837 | readable |= |
| 838 | 1 << static_cast<uint8_t>(IPMIThresholdRespBits::lowerNonCritical); |
| 839 | lowerNC = *thresholdData.warningLow; |
| 840 | } |
| 841 | |
| 842 | if (thresholdData.criticalHigh) |
| 843 | { |
| 844 | readable |= |
| 845 | 1 << static_cast<uint8_t>(IPMIThresholdRespBits::upperCritical); |
| 846 | upperCritical = *thresholdData.criticalHigh; |
| 847 | } |
| 848 | if (thresholdData.criticalLow) |
| 849 | { |
| 850 | readable |= |
| 851 | 1 << static_cast<uint8_t>(IPMIThresholdRespBits::lowerCritical); |
| 852 | lowerCritical = *thresholdData.criticalLow; |
| 853 | } |
| 854 | |
| 855 | return ipmi::responseSuccess(readable, lowerNC, lowerCritical, |
| 856 | lowerNonRecoverable, upperNC, upperCritical, |
| 857 | upperNonRecoverable); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 858 | } |
| 859 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 860 | /** @brief implements the get Sensor event enable command |
| 861 | * @param sensorNumber - sensor number |
| 862 | * |
| 863 | * @returns IPMI completion code plus response data |
| 864 | * - enabled - Sensor Event messages |
| 865 | * - assertionEnabledLsb - Assertion event messages |
| 866 | * - assertionEnabledMsb - Assertion event messages |
| 867 | * - deassertionEnabledLsb - Deassertion event messages |
| 868 | * - deassertionEnabledMsb - Deassertion event messages |
| 869 | */ |
| 870 | |
| 871 | ipmi::RspType<uint8_t, // enabled |
| 872 | uint8_t, // assertionEnabledLsb |
| 873 | uint8_t, // assertionEnabledMsb |
| 874 | uint8_t, // deassertionEnabledLsb |
| 875 | uint8_t> // deassertionEnabledMsb |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 876 | ipmiSenGetSensorEventEnable(ipmi::Context::ptr ctx, uint8_t sensorNum) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 877 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 878 | std::string connection; |
| 879 | std::string path; |
| 880 | |
Patrick Venture | a41714c | 2019-09-25 16:59:41 -0700 | [diff] [blame] | 881 | uint8_t enabled = 0; |
| 882 | uint8_t assertionEnabledLsb = 0; |
| 883 | uint8_t assertionEnabledMsb = 0; |
| 884 | uint8_t deassertionEnabledLsb = 0; |
| 885 | uint8_t deassertionEnabledMsb = 0; |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 886 | |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 887 | auto status = getSensorConnection(ctx, sensorNum, connection, path); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 888 | if (status) |
| 889 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 890 | return ipmi::response(status); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | SensorMap sensorMap; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 894 | if (!getSensorMap(ctx->yield, connection, path, sensorMap)) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 895 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 896 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | auto warningInterface = |
| 900 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 901 | auto criticalInterface = |
| 902 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 903 | if ((warningInterface != sensorMap.end()) || |
| 904 | (criticalInterface != sensorMap.end())) |
| 905 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 906 | enabled = static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 907 | IPMISensorEventEnableByte2::sensorScanningEnable); |
| 908 | if (warningInterface != sensorMap.end()) |
| 909 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 910 | auto& warningMap = warningInterface->second; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 911 | |
| 912 | auto warningHigh = warningMap.find("WarningHigh"); |
| 913 | auto warningLow = warningMap.find("WarningLow"); |
| 914 | if (warningHigh != warningMap.end()) |
| 915 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 916 | assertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 917 | IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh); |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 918 | deassertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 919 | IPMISensorEventEnableThresholds::upperNonCriticalGoingLow); |
| 920 | } |
| 921 | if (warningLow != warningMap.end()) |
| 922 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 923 | assertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 924 | IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow); |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 925 | deassertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 926 | IPMISensorEventEnableThresholds::lowerNonCriticalGoingHigh); |
| 927 | } |
| 928 | } |
| 929 | if (criticalInterface != sensorMap.end()) |
| 930 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 931 | auto& criticalMap = criticalInterface->second; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 932 | |
| 933 | auto criticalHigh = criticalMap.find("CriticalHigh"); |
| 934 | auto criticalLow = criticalMap.find("CriticalLow"); |
| 935 | |
| 936 | if (criticalHigh != criticalMap.end()) |
| 937 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 938 | assertionEnabledMsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 939 | IPMISensorEventEnableThresholds::upperCriticalGoingHigh); |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 940 | deassertionEnabledMsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 941 | IPMISensorEventEnableThresholds::upperCriticalGoingLow); |
| 942 | } |
| 943 | if (criticalLow != criticalMap.end()) |
| 944 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 945 | assertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 946 | IPMISensorEventEnableThresholds::lowerCriticalGoingLow); |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 947 | deassertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 948 | IPMISensorEventEnableThresholds::lowerCriticalGoingHigh); |
| 949 | } |
| 950 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 951 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 952 | |
| 953 | return ipmi::responseSuccess(enabled, assertionEnabledLsb, |
| 954 | assertionEnabledMsb, deassertionEnabledLsb, |
| 955 | deassertionEnabledMsb); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 956 | } |
| 957 | |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 958 | /** @brief implements the get Sensor event status command |
| 959 | * @param sensorNumber - sensor number, FFh = reserved |
| 960 | * |
| 961 | * @returns IPMI completion code plus response data |
| 962 | * - sensorEventStatus - Sensor Event messages state |
| 963 | * - assertions - Assertion event messages |
| 964 | * - deassertions - Deassertion event messages |
| 965 | */ |
| 966 | ipmi::RspType<uint8_t, // sensorEventStatus |
| 967 | std::bitset<16>, // assertions |
| 968 | std::bitset<16> // deassertion |
| 969 | > |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 970 | ipmiSenGetSensorEventStatus(ipmi::Context::ptr ctx, uint8_t sensorNum) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 971 | { |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 972 | if (sensorNum == reservedSensorNumber) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 973 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 974 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 975 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 976 | |
| 977 | std::string connection; |
| 978 | std::string path; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 979 | auto status = getSensorConnection(ctx, sensorNum, connection, path); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 980 | if (status) |
| 981 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 982 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 983 | "ipmiSenGetSensorEventStatus: Sensor connection Error", |
| 984 | phosphor::logging::entry("SENSOR=%d", sensorNum)); |
| 985 | return ipmi::response(status); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | SensorMap sensorMap; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 989 | if (!getSensorMap(ctx->yield, connection, path, sensorMap)) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 990 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 991 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 992 | "ipmiSenGetSensorEventStatus: Sensor Mapping Error", |
| 993 | phosphor::logging::entry("SENSOR=%s", path.c_str())); |
| 994 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 995 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 996 | auto warningInterface = |
| 997 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 998 | auto criticalInterface = |
| 999 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 1000 | |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1001 | uint8_t sensorEventStatus = |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1002 | static_cast<uint8_t>(IPMISensorEventEnableByte2::sensorScanningEnable); |
| 1003 | |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 1004 | std::optional<bool> criticalDeassertHigh = |
| 1005 | thresholdDeassertMap[path]["CriticalAlarmHigh"]; |
| 1006 | std::optional<bool> criticalDeassertLow = |
| 1007 | thresholdDeassertMap[path]["CriticalAlarmLow"]; |
| 1008 | std::optional<bool> warningDeassertHigh = |
| 1009 | thresholdDeassertMap[path]["WarningAlarmHigh"]; |
| 1010 | std::optional<bool> warningDeassertLow = |
| 1011 | thresholdDeassertMap[path]["WarningAlarmLow"]; |
| 1012 | |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1013 | std::bitset<16> assertions = 0; |
| 1014 | std::bitset<16> deassertions = 0; |
| 1015 | |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 1016 | if (criticalDeassertHigh && !*criticalDeassertHigh) |
| 1017 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1018 | deassertions.set(static_cast<size_t>( |
| 1019 | IPMIGetSensorEventEnableThresholds::upperCriticalGoingHigh)); |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 1020 | } |
| 1021 | if (criticalDeassertLow && !*criticalDeassertLow) |
| 1022 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1023 | deassertions.set(static_cast<size_t>( |
| 1024 | IPMIGetSensorEventEnableThresholds::upperCriticalGoingLow)); |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 1025 | } |
| 1026 | if (warningDeassertHigh && !*warningDeassertHigh) |
| 1027 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1028 | deassertions.set(static_cast<size_t>( |
| 1029 | IPMIGetSensorEventEnableThresholds::upperNonCriticalGoingHigh)); |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 1030 | } |
| 1031 | if (warningDeassertLow && !*warningDeassertLow) |
| 1032 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1033 | deassertions.set(static_cast<size_t>( |
| 1034 | IPMIGetSensorEventEnableThresholds::lowerNonCriticalGoingHigh)); |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 1035 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1036 | if ((warningInterface != sensorMap.end()) || |
| 1037 | (criticalInterface != sensorMap.end())) |
| 1038 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1039 | sensorEventStatus = static_cast<size_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1040 | IPMISensorEventEnableByte2::eventMessagesEnable); |
| 1041 | if (warningInterface != sensorMap.end()) |
| 1042 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1043 | auto& warningMap = warningInterface->second; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1044 | |
| 1045 | auto warningHigh = warningMap.find("WarningAlarmHigh"); |
| 1046 | auto warningLow = warningMap.find("WarningAlarmLow"); |
| 1047 | auto warningHighAlarm = false; |
| 1048 | auto warningLowAlarm = false; |
| 1049 | |
| 1050 | if (warningHigh != warningMap.end()) |
| 1051 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1052 | warningHighAlarm = std::get<bool>(warningHigh->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1053 | } |
| 1054 | if (warningLow != warningMap.end()) |
| 1055 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1056 | warningLowAlarm = std::get<bool>(warningLow->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1057 | } |
| 1058 | if (warningHighAlarm) |
| 1059 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1060 | assertions.set( |
| 1061 | static_cast<size_t>(IPMIGetSensorEventEnableThresholds:: |
| 1062 | upperNonCriticalGoingHigh)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1063 | } |
| 1064 | if (warningLowAlarm) |
| 1065 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1066 | assertions.set( |
| 1067 | static_cast<size_t>(IPMIGetSensorEventEnableThresholds:: |
| 1068 | lowerNonCriticalGoingLow)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | if (criticalInterface != sensorMap.end()) |
| 1072 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1073 | auto& criticalMap = criticalInterface->second; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1074 | |
| 1075 | auto criticalHigh = criticalMap.find("CriticalAlarmHigh"); |
| 1076 | auto criticalLow = criticalMap.find("CriticalAlarmLow"); |
| 1077 | auto criticalHighAlarm = false; |
| 1078 | auto criticalLowAlarm = false; |
| 1079 | |
| 1080 | if (criticalHigh != criticalMap.end()) |
| 1081 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1082 | criticalHighAlarm = std::get<bool>(criticalHigh->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1083 | } |
| 1084 | if (criticalLow != criticalMap.end()) |
| 1085 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1086 | criticalLowAlarm = std::get<bool>(criticalLow->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1087 | } |
| 1088 | if (criticalHighAlarm) |
| 1089 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1090 | assertions.set( |
| 1091 | static_cast<size_t>(IPMIGetSensorEventEnableThresholds:: |
| 1092 | upperCriticalGoingHigh)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1093 | } |
| 1094 | if (criticalLowAlarm) |
| 1095 | { |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1096 | assertions.set(static_cast<size_t>( |
| 1097 | IPMIGetSensorEventEnableThresholds::lowerCriticalGoingLow)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1098 | } |
| 1099 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1102 | return ipmi::responseSuccess(sensorEventStatus, assertions, deassertions); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1105 | static int getSensorDataRecord(ipmi::Context::ptr ctx, |
| 1106 | std::vector<uint8_t>& recordData, |
| 1107 | uint16_t recordID) |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1108 | { |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1109 | size_t fruCount = 0; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1110 | ipmi::Cc ret = ipmi::storage::getFruSdrCount(ctx, fruCount); |
| 1111 | if (ret != ipmi::ccSuccess) |
| 1112 | { |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1113 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1114 | "getSensorDataRecord: getFruSdrCount error"); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1115 | return GENERAL_ERROR; |
| 1116 | } |
| 1117 | |
| 1118 | size_t lastRecord = sensorTree.size() + fruCount + |
| 1119 | ipmi::storage::type12Count + |
| 1120 | ipmi::storage::nmDiscoverySDRCount - 1; |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1121 | if (recordID == lastRecordIndex) |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1122 | { |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1123 | recordID = lastRecord; |
| 1124 | } |
| 1125 | if (recordID > lastRecord) |
| 1126 | { |
| 1127 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1128 | "getSensorDataRecord: recordID > lastRecord error"); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1129 | return GENERAL_ERROR; |
| 1130 | } |
| 1131 | |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1132 | if (recordID >= sensorTree.size()) |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1133 | { |
| 1134 | size_t fruIndex = recordID - sensorTree.size(); |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1135 | size_t type12End = fruCount + ipmi::storage::type12Count; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1136 | |
| 1137 | if (fruIndex >= type12End) |
| 1138 | { |
| 1139 | // NM discovery SDR |
| 1140 | size_t nmDiscoveryIndex = fruIndex - type12End; |
| 1141 | if (nmDiscoveryIndex >= ipmi::storage::nmDiscoverySDRCount) |
| 1142 | { |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1143 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1144 | "getSensorDataRecord: NM DiscoveryIndex error"); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1145 | return GENERAL_ERROR; |
| 1146 | } |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1147 | recordData = |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1148 | ipmi::storage::getNMDiscoverySDR(nmDiscoveryIndex, recordID); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1149 | } |
| 1150 | else if (fruIndex >= fruCount) |
| 1151 | { |
| 1152 | // handle type 12 hardcoded records |
| 1153 | size_t type12Index = fruIndex - fruCount; |
| 1154 | if (type12Index >= ipmi::storage::type12Count) |
| 1155 | { |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1156 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1157 | "getSensorDataRecord: type12Index error"); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1158 | return GENERAL_ERROR; |
| 1159 | } |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1160 | recordData = ipmi::storage::getType12SDRs(type12Index, recordID); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | // handle fru records |
| 1165 | get_sdr::SensorDataFruRecord data; |
| 1166 | ret = ipmi::storage::getFruSdrs(ctx, fruIndex, data); |
| 1167 | if (ret != IPMI_CC_OK) |
| 1168 | { |
| 1169 | return GENERAL_ERROR; |
| 1170 | } |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1171 | data.header.record_id_msb = recordID >> 8; |
| 1172 | data.header.record_id_lsb = recordID & 0xFF; |
| 1173 | recordData.insert(recordData.end(), (uint8_t*)&data, |
| 1174 | ((uint8_t*)&data) + sizeof(data)); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1175 | } |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | std::string connection; |
| 1181 | std::string path; |
| 1182 | auto status = getSensorConnection(ctx, recordID, connection, path); |
| 1183 | if (status) |
| 1184 | { |
| 1185 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1186 | "getSensorDataRecord: getSensorConnection error"); |
| 1187 | return GENERAL_ERROR; |
| 1188 | } |
| 1189 | SensorMap sensorMap; |
| 1190 | if (!getSensorMap(ctx->yield, connection, path, sensorMap, |
| 1191 | sensorMapUpdatePeriod)) |
| 1192 | { |
| 1193 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1194 | "getSensorDataRecord: getSensorMap error"); |
| 1195 | return GENERAL_ERROR; |
| 1196 | } |
| 1197 | uint16_t sensorNum = getSensorNumberFromPath(path); |
| 1198 | if (sensorNum == invalidSensorNumber) |
| 1199 | { |
| 1200 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1201 | "getSensorDataRecord: invalidSensorNumber"); |
| 1202 | return GENERAL_ERROR; |
| 1203 | } |
| 1204 | uint8_t sensornumber = static_cast<uint8_t>(sensorNum); |
| 1205 | uint8_t lun = static_cast<uint8_t>(sensorNum >> 8); |
| 1206 | |
| 1207 | get_sdr::SensorDataFullRecord record = {0}; |
| 1208 | |
| 1209 | get_sdr::header::set_record_id( |
| 1210 | recordID, reinterpret_cast<get_sdr::SensorDataRecordHeader*>(&record)); |
| 1211 | |
| 1212 | record.header.sdr_version = ipmiSdrVersion; |
| 1213 | record.header.record_type = get_sdr::SENSOR_DATA_FULL_RECORD; |
| 1214 | record.header.record_length = sizeof(get_sdr::SensorDataFullRecord) - |
| 1215 | sizeof(get_sdr::SensorDataRecordHeader); |
| 1216 | record.key.owner_id = 0x20; |
| 1217 | record.key.owner_lun = lun; |
| 1218 | record.key.sensor_number = sensornumber; |
| 1219 | |
| 1220 | record.body.sensor_capabilities = 0x68; // auto rearm - todo hysteresis |
| 1221 | record.body.sensor_type = getSensorTypeFromPath(path); |
| 1222 | std::string type = getSensorTypeStringFromPath(path); |
| 1223 | auto typeCstr = type.c_str(); |
| 1224 | auto findUnits = sensorUnits.find(typeCstr); |
| 1225 | if (findUnits != sensorUnits.end()) |
| 1226 | { |
| 1227 | record.body.sensor_units_2_base = |
| 1228 | static_cast<uint8_t>(findUnits->second); |
| 1229 | } // else default 0x0 unspecified |
| 1230 | |
| 1231 | record.body.event_reading_type = getSensorEventTypeFromPath(path); |
| 1232 | |
| 1233 | auto sensorObject = sensorMap.find("xyz.openbmc_project.Sensor.Value"); |
| 1234 | if (sensorObject == sensorMap.end()) |
| 1235 | { |
| 1236 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1237 | "getSensorDataRecord: sensorObject error"); |
| 1238 | return GENERAL_ERROR; |
| 1239 | } |
| 1240 | |
| 1241 | uint8_t entityId = 0; |
| 1242 | uint8_t entityInstance = 0x01; |
| 1243 | |
| 1244 | // follow the association chain to get the parent board's entityid and |
| 1245 | // entityInstance |
| 1246 | updateIpmiFromAssociation(path, sensorMap, entityId, entityInstance); |
| 1247 | |
| 1248 | record.body.entity_id = entityId; |
| 1249 | record.body.entity_instance = entityInstance; |
| 1250 | |
| 1251 | auto maxObject = sensorObject->second.find("MaxValue"); |
| 1252 | auto minObject = sensorObject->second.find("MinValue"); |
| 1253 | |
| 1254 | // If min and/or max are left unpopulated, |
| 1255 | // then default to what a signed byte would be, namely (-128,127) range. |
| 1256 | auto max = static_cast<double>(std::numeric_limits<int8_t>::max()); |
| 1257 | auto min = static_cast<double>(std::numeric_limits<int8_t>::lowest()); |
| 1258 | if (maxObject != sensorObject->second.end()) |
| 1259 | { |
| 1260 | max = std::visit(VariantToDoubleVisitor(), maxObject->second); |
| 1261 | } |
| 1262 | |
| 1263 | if (minObject != sensorObject->second.end()) |
| 1264 | { |
| 1265 | min = std::visit(VariantToDoubleVisitor(), minObject->second); |
| 1266 | } |
| 1267 | |
| 1268 | int16_t mValue = 0; |
| 1269 | int8_t rExp = 0; |
| 1270 | int16_t bValue = 0; |
| 1271 | int8_t bExp = 0; |
| 1272 | bool bSigned = false; |
| 1273 | |
| 1274 | if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned)) |
| 1275 | { |
| 1276 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1277 | "getSensorDataRecord: getSensorAttributes error"); |
| 1278 | return GENERAL_ERROR; |
| 1279 | } |
| 1280 | |
| 1281 | // The record.body is a struct SensorDataFullRecordBody |
| 1282 | // from sensorhandler.hpp in phosphor-ipmi-host. |
| 1283 | // The meaning of these bits appears to come from |
| 1284 | // table 43.1 of the IPMI spec. |
| 1285 | // The above 5 sensor attributes are stuffed in as follows: |
| 1286 | // Byte 21 = AA000000 = analog interpretation, 10 signed, 00 unsigned |
| 1287 | // Byte 22-24 are for other purposes |
| 1288 | // Byte 25 = MMMMMMMM = LSB of M |
| 1289 | // Byte 26 = MMTTTTTT = MSB of M (signed), and Tolerance |
| 1290 | // Byte 27 = BBBBBBBB = LSB of B |
| 1291 | // Byte 28 = BBAAAAAA = MSB of B (signed), and LSB of Accuracy |
| 1292 | // Byte 29 = AAAAEE00 = MSB of Accuracy, exponent of Accuracy |
| 1293 | // Byte 30 = RRRRBBBB = rExp (signed), bExp (signed) |
| 1294 | |
| 1295 | // apply M, B, and exponents, M and B are 10 bit values, exponents are 4 |
| 1296 | record.body.m_lsb = mValue & 0xFF; |
| 1297 | |
| 1298 | uint8_t mBitSign = (mValue < 0) ? 1 : 0; |
| 1299 | uint8_t mBitNine = (mValue & 0x0100) >> 8; |
| 1300 | |
| 1301 | // move the smallest bit of the MSB into place (bit 9) |
| 1302 | // the MSbs are bits 7:8 in m_msb_and_tolerance |
| 1303 | record.body.m_msb_and_tolerance = (mBitSign << 7) | (mBitNine << 6); |
| 1304 | |
| 1305 | record.body.b_lsb = bValue & 0xFF; |
| 1306 | |
| 1307 | uint8_t bBitSign = (bValue < 0) ? 1 : 0; |
| 1308 | uint8_t bBitNine = (bValue & 0x0100) >> 8; |
| 1309 | |
| 1310 | // move the smallest bit of the MSB into place (bit 9) |
| 1311 | // the MSbs are bits 7:8 in b_msb_and_accuracy_lsb |
| 1312 | record.body.b_msb_and_accuracy_lsb = (bBitSign << 7) | (bBitNine << 6); |
| 1313 | |
| 1314 | uint8_t rExpSign = (rExp < 0) ? 1 : 0; |
| 1315 | uint8_t rExpBits = rExp & 0x07; |
| 1316 | |
| 1317 | uint8_t bExpSign = (bExp < 0) ? 1 : 0; |
| 1318 | uint8_t bExpBits = bExp & 0x07; |
| 1319 | |
| 1320 | // move rExp and bExp into place |
| 1321 | record.body.r_b_exponents = |
| 1322 | (rExpSign << 7) | (rExpBits << 4) | (bExpSign << 3) | bExpBits; |
| 1323 | |
| 1324 | // Set the analog reading byte interpretation accordingly |
| 1325 | record.body.sensor_units_1 = (bSigned ? 1 : 0) << 7; |
| 1326 | |
| 1327 | // TODO(): Perhaps care about Tolerance, Accuracy, and so on |
| 1328 | // These seem redundant, but derivable from the above 5 attributes |
| 1329 | // Original comment said "todo fill out rest of units" |
| 1330 | |
| 1331 | // populate sensor name from path |
| 1332 | std::string name; |
| 1333 | size_t nameStart = path.rfind("/"); |
| 1334 | if (nameStart != std::string::npos) |
| 1335 | { |
| 1336 | name = path.substr(nameStart + 1, std::string::npos - nameStart); |
| 1337 | } |
| 1338 | |
| 1339 | std::replace(name.begin(), name.end(), '_', ' '); |
| 1340 | if (name.size() > FULL_RECORD_ID_STR_MAX_LENGTH) |
| 1341 | { |
| 1342 | // try to not truncate by replacing common words |
| 1343 | constexpr std::array<std::pair<const char*, const char*>, 2> |
| 1344 | replaceWords = {std::make_pair("Output", "Out"), |
| 1345 | std::make_pair("Input", "In")}; |
| 1346 | for (const auto& [find, replace] : replaceWords) |
| 1347 | { |
| 1348 | boost::replace_all(name, find, replace); |
| 1349 | } |
| 1350 | |
| 1351 | name.resize(FULL_RECORD_ID_STR_MAX_LENGTH); |
| 1352 | } |
| 1353 | record.body.id_string_info = name.size(); |
| 1354 | std::strncpy(record.body.id_string, name.c_str(), |
| 1355 | sizeof(record.body.id_string)); |
| 1356 | |
Josh Lehan | 06aa21a | 2020-10-28 21:59:06 -0700 | [diff] [blame^] | 1357 | // Remember the sensor name, as determined for this sensor number |
| 1358 | details::sdrStatsTable.updateName(sensornumber, name); |
| 1359 | |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1360 | IPMIThresholds thresholdData; |
| 1361 | try |
| 1362 | { |
| 1363 | thresholdData = getIPMIThresholds(sensorMap); |
| 1364 | } |
| 1365 | catch (std::exception&) |
| 1366 | { |
| 1367 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1368 | "getSensorDataRecord: getIPMIThresholds error"); |
| 1369 | return GENERAL_ERROR; |
| 1370 | } |
| 1371 | |
| 1372 | if (thresholdData.criticalHigh) |
| 1373 | { |
| 1374 | record.body.upper_critical_threshold = *thresholdData.criticalHigh; |
| 1375 | record.body.supported_deassertions[1] |= static_cast<uint8_t>( |
| 1376 | IPMISensorEventEnableThresholds::criticalThreshold); |
| 1377 | record.body.supported_deassertions[1] |= static_cast<uint8_t>( |
| 1378 | IPMISensorEventEnableThresholds::upperCriticalGoingHigh); |
| 1379 | record.body.supported_assertions[1] |= static_cast<uint8_t>( |
| 1380 | IPMISensorEventEnableThresholds::upperCriticalGoingHigh); |
| 1381 | record.body.discrete_reading_setting_mask[0] |= |
| 1382 | static_cast<uint8_t>(IPMISensorReadingByte3::upperCritical); |
| 1383 | } |
| 1384 | if (thresholdData.warningHigh) |
| 1385 | { |
| 1386 | record.body.upper_noncritical_threshold = *thresholdData.warningHigh; |
| 1387 | record.body.supported_deassertions[1] |= static_cast<uint8_t>( |
| 1388 | IPMISensorEventEnableThresholds::nonCriticalThreshold); |
| 1389 | record.body.supported_deassertions[0] |= static_cast<uint8_t>( |
| 1390 | IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh); |
| 1391 | record.body.supported_assertions[0] |= static_cast<uint8_t>( |
| 1392 | IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh); |
| 1393 | record.body.discrete_reading_setting_mask[0] |= |
| 1394 | static_cast<uint8_t>(IPMISensorReadingByte3::upperNonCritical); |
| 1395 | } |
| 1396 | if (thresholdData.criticalLow) |
| 1397 | { |
| 1398 | record.body.lower_critical_threshold = *thresholdData.criticalLow; |
| 1399 | record.body.supported_assertions[1] |= static_cast<uint8_t>( |
| 1400 | IPMISensorEventEnableThresholds::criticalThreshold); |
| 1401 | record.body.supported_deassertions[0] |= static_cast<uint8_t>( |
| 1402 | IPMISensorEventEnableThresholds::lowerCriticalGoingLow); |
| 1403 | record.body.supported_assertions[0] |= static_cast<uint8_t>( |
| 1404 | IPMISensorEventEnableThresholds::lowerCriticalGoingLow); |
| 1405 | record.body.discrete_reading_setting_mask[0] |= |
| 1406 | static_cast<uint8_t>(IPMISensorReadingByte3::lowerCritical); |
| 1407 | } |
| 1408 | if (thresholdData.warningLow) |
| 1409 | { |
| 1410 | record.body.lower_noncritical_threshold = *thresholdData.warningLow; |
| 1411 | record.body.supported_assertions[1] |= static_cast<uint8_t>( |
| 1412 | IPMISensorEventEnableThresholds::nonCriticalThreshold); |
| 1413 | record.body.supported_deassertions[0] |= static_cast<uint8_t>( |
| 1414 | IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow); |
| 1415 | record.body.supported_assertions[0] |= static_cast<uint8_t>( |
| 1416 | IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow); |
| 1417 | record.body.discrete_reading_setting_mask[0] |= |
| 1418 | static_cast<uint8_t>(IPMISensorReadingByte3::lowerNonCritical); |
| 1419 | } |
| 1420 | |
| 1421 | // everything that is readable is setable |
| 1422 | record.body.discrete_reading_setting_mask[1] = |
| 1423 | record.body.discrete_reading_setting_mask[0]; |
| 1424 | recordData.insert(recordData.end(), (uint8_t*)&record, |
| 1425 | ((uint8_t*)&record) + sizeof(record)); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1426 | return 0; |
| 1427 | } |
| 1428 | |
| 1429 | /** @brief implements the get SDR Info command |
| 1430 | * @param count - Operation |
| 1431 | * |
| 1432 | * @returns IPMI completion code plus response data |
| 1433 | * - sdrCount - sensor/SDR count |
| 1434 | * - lunsAndDynamicPopulation - static/Dynamic sensor population flag |
| 1435 | */ |
| 1436 | static ipmi::RspType<uint8_t, // respcount |
| 1437 | uint8_t, // dynamic population flags |
| 1438 | uint32_t // last time a sensor was added |
| 1439 | > |
| 1440 | ipmiSensorGetDeviceSdrInfo(ipmi::Context::ptr ctx, |
| 1441 | std::optional<uint8_t> count) |
| 1442 | { |
| 1443 | uint8_t sdrCount = 0; |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1444 | uint16_t recordID = 0; |
| 1445 | std::vector<uint8_t> record; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1446 | // Sensors are dynamically allocated, and there is at least one LUN |
| 1447 | uint8_t lunsAndDynamicPopulation = 0x80; |
| 1448 | constexpr uint8_t getSdrCount = 0x01; |
| 1449 | constexpr uint8_t getSensorCount = 0x00; |
| 1450 | |
| 1451 | if (!getSensorSubtree(sensorTree) || sensorTree.empty()) |
| 1452 | { |
| 1453 | return ipmi::responseResponseError(); |
| 1454 | } |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1455 | uint16_t numSensors = sensorTree.size(); |
| 1456 | if (count.value_or(0) == getSdrCount) |
| 1457 | { |
| 1458 | // Count the number of Type 1 SDR entries assigned to the LUN |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1459 | while (!getSensorDataRecord(ctx, record, recordID++)) |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1460 | { |
| 1461 | get_sdr::SensorDataRecordHeader* hdr = |
| 1462 | reinterpret_cast<get_sdr::SensorDataRecordHeader*>( |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1463 | record.data()); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1464 | if (hdr->record_type == get_sdr::SENSOR_DATA_FULL_RECORD) |
| 1465 | { |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1466 | get_sdr::SensorDataFullRecord* recordData = |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1467 | reinterpret_cast<get_sdr::SensorDataFullRecord*>( |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1468 | record.data()); |
| 1469 | if (ctx->lun == recordData->key.owner_lun) |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1470 | { |
| 1471 | sdrCount++; |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | } |
| 1476 | else if (count.value_or(0) == getSensorCount) |
| 1477 | { |
| 1478 | // Return the number of sensors attached to the LUN |
| 1479 | if ((ctx->lun == 0) && (numSensors > 0)) |
| 1480 | { |
| 1481 | sdrCount = |
| 1482 | (numSensors > maxSensorsPerLUN) ? maxSensorsPerLUN : numSensors; |
| 1483 | } |
| 1484 | else if ((ctx->lun == 1) && (numSensors > maxSensorsPerLUN)) |
| 1485 | { |
| 1486 | sdrCount = (numSensors > (2 * maxSensorsPerLUN)) |
| 1487 | ? maxSensorsPerLUN |
| 1488 | : (numSensors - maxSensorsPerLUN) & maxSensorsPerLUN; |
| 1489 | } |
| 1490 | else if (ctx->lun == 3) |
| 1491 | { |
| 1492 | if (numSensors <= maxIPMISensors) |
| 1493 | { |
| 1494 | sdrCount = |
| 1495 | (numSensors - (2 * maxSensorsPerLUN)) & maxSensorsPerLUN; |
| 1496 | } |
| 1497 | else |
| 1498 | { |
| 1499 | // error |
| 1500 | throw std::out_of_range( |
| 1501 | "Maximum number of IPMI sensors exceeded."); |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | else |
| 1506 | { |
| 1507 | return ipmi::responseInvalidFieldRequest(); |
| 1508 | } |
| 1509 | |
| 1510 | // Get Sensor count. This returns the number of sensors |
| 1511 | if (numSensors > 0) |
| 1512 | { |
| 1513 | lunsAndDynamicPopulation |= 1; |
| 1514 | } |
| 1515 | if (numSensors > maxSensorsPerLUN) |
| 1516 | { |
| 1517 | lunsAndDynamicPopulation |= 2; |
| 1518 | } |
| 1519 | if (numSensors >= (maxSensorsPerLUN * 2)) |
| 1520 | { |
| 1521 | lunsAndDynamicPopulation |= 8; |
| 1522 | } |
| 1523 | if (numSensors > maxIPMISensors) |
| 1524 | { |
| 1525 | // error |
| 1526 | throw std::out_of_range("Maximum number of IPMI sensors exceeded."); |
| 1527 | } |
| 1528 | |
| 1529 | return ipmi::responseSuccess(sdrCount, lunsAndDynamicPopulation, |
| 1530 | sdrLastAdd); |
| 1531 | } |
| 1532 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1533 | /* end sensor commands */ |
| 1534 | |
| 1535 | /* storage commands */ |
| 1536 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1537 | ipmi::RspType<uint8_t, // sdr version |
| 1538 | uint16_t, // record count |
| 1539 | uint16_t, // free space |
| 1540 | uint32_t, // most recent addition |
| 1541 | uint32_t, // most recent erase |
| 1542 | uint8_t // operationSupport |
| 1543 | > |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 1544 | ipmiStorageGetSDRRepositoryInfo(ipmi::Context::ptr ctx) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1545 | { |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1546 | constexpr const uint16_t unspecifiedFreeSpace = 0xFFFF; |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1547 | if (!getSensorSubtree(sensorTree) && sensorTree.empty()) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1548 | { |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1549 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1552 | size_t fruCount = 0; |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 1553 | ipmi::Cc ret = ipmi::storage::getFruSdrCount(ctx, fruCount); |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1554 | if (ret != ipmi::ccSuccess) |
| 1555 | { |
| 1556 | return ipmi::response(ret); |
| 1557 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1558 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1559 | uint16_t recordCount = |
| 1560 | sensorTree.size() + fruCount + ipmi::storage::type12Count; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1561 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1562 | uint8_t operationSupport = static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1563 | SdrRepositoryInfoOps::overflow); // write not supported |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1564 | |
| 1565 | operationSupport |= |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1566 | static_cast<uint8_t>(SdrRepositoryInfoOps::allocCommandSupported); |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1567 | operationSupport |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1568 | SdrRepositoryInfoOps::reserveSDRRepositoryCommandSupported); |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1569 | return ipmi::responseSuccess(ipmiSdrVersion, recordCount, |
| 1570 | unspecifiedFreeSpace, sdrLastAdd, |
| 1571 | sdrLastRemove, operationSupport); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1574 | /** @brief implements the get SDR allocation info command |
| 1575 | * |
| 1576 | * @returns IPMI completion code plus response data |
| 1577 | * - allocUnits - Number of possible allocation units |
| 1578 | * - allocUnitSize - Allocation unit size in bytes. |
| 1579 | * - allocUnitFree - Number of free allocation units |
| 1580 | * - allocUnitLargestFree - Largest free block in allocation units |
| 1581 | * - maxRecordSize - Maximum record size in allocation units. |
| 1582 | */ |
| 1583 | ipmi::RspType<uint16_t, // allocUnits |
| 1584 | uint16_t, // allocUnitSize |
| 1585 | uint16_t, // allocUnitFree |
| 1586 | uint16_t, // allocUnitLargestFree |
| 1587 | uint8_t // maxRecordSize |
| 1588 | > |
| 1589 | ipmiStorageGetSDRAllocationInfo() |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1590 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1591 | // 0000h unspecified number of alloc units |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1592 | constexpr uint16_t allocUnits = 0; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1593 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1594 | constexpr uint16_t allocUnitFree = 0; |
| 1595 | constexpr uint16_t allocUnitLargestFree = 0; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1596 | // only allow one block at a time |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1597 | constexpr uint8_t maxRecordSize = 1; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1598 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1599 | return ipmi::responseSuccess(allocUnits, maxSDRTotalSize, allocUnitFree, |
| 1600 | allocUnitLargestFree, maxRecordSize); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1603 | /** @brief implements the reserve SDR command |
| 1604 | * @returns IPMI completion code plus response data |
| 1605 | * - sdrReservationID |
| 1606 | */ |
| 1607 | ipmi::RspType<uint16_t> ipmiStorageReserveSDR() |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1608 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1609 | sdrReservationID++; |
James Feist | a80cb90 | 2019-02-14 13:05:25 -0800 | [diff] [blame] | 1610 | if (sdrReservationID == 0) |
| 1611 | { |
| 1612 | sdrReservationID++; |
| 1613 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1614 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1615 | return ipmi::responseSuccess(sdrReservationID); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1618 | ipmi::RspType<uint16_t, // next record ID |
| 1619 | std::vector<uint8_t> // payload |
| 1620 | > |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 1621 | ipmiStorageGetSDR(ipmi::Context::ptr ctx, uint16_t reservationID, |
| 1622 | uint16_t recordID, uint8_t offset, uint8_t bytesToRead) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1623 | { |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1624 | size_t fruCount = 0; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1625 | // reservation required for partial reads with non zero offset into |
| 1626 | // record |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1627 | if ((sdrReservationID == 0 || reservationID != sdrReservationID) && offset) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1628 | { |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1629 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1630 | "ipmiStorageGetSDR: responseInvalidReservationId"); |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1631 | return ipmi::responseInvalidReservationId(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1632 | } |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 1633 | ipmi::Cc ret = ipmi::storage::getFruSdrCount(ctx, fruCount); |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1634 | if (ret != ipmi::ccSuccess) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1635 | { |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1636 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1637 | "ipmiStorageGetSDR: getFruSdrCount error"); |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1638 | return ipmi::response(ret); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
Yong Li | fee5e4c | 2020-01-17 19:36:29 +0800 | [diff] [blame] | 1641 | size_t lastRecord = sensorTree.size() + fruCount + |
| 1642 | ipmi::storage::type12Count + |
| 1643 | ipmi::storage::nmDiscoverySDRCount - 1; |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1644 | uint16_t nextRecordId = lastRecord > recordID ? recordID + 1 : 0XFFFF; |
| 1645 | |
| 1646 | if (!getSensorSubtree(sensorTree) && sensorTree.empty()) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1647 | { |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1648 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1649 | "ipmiStorageGetSDR: getSensorSubtree error"); |
| 1650 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1653 | std::vector<uint8_t> record; |
| 1654 | if (getSensorDataRecord(ctx, record, recordID)) |
| 1655 | { |
| 1656 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1657 | "ipmiStorageGetSDR: fail to get SDR"); |
| 1658 | return ipmi::responseInvalidFieldRequest(); |
| 1659 | } |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1660 | get_sdr::SensorDataRecordHeader* hdr = |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1661 | reinterpret_cast<get_sdr::SensorDataRecordHeader*>(record.data()); |
Kuiying Wang | b910987 | 2021-01-15 15:54:59 +0800 | [diff] [blame] | 1662 | if (!hdr) |
| 1663 | { |
| 1664 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1665 | "ipmiStorageGetSDR: record header is null"); |
| 1666 | return ipmi::responseSuccess(nextRecordId, record); |
Kuiying Wang | b910987 | 2021-01-15 15:54:59 +0800 | [diff] [blame] | 1667 | } |
| 1668 | |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1669 | size_t sdrLength = |
| 1670 | sizeof(get_sdr::SensorDataRecordHeader) + hdr->record_length; |
| 1671 | if (sdrLength < (offset + bytesToRead)) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1672 | { |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1673 | bytesToRead = sdrLength - offset; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1676 | uint8_t* respStart = reinterpret_cast<uint8_t*>(hdr) + offset; |
Kuiying Wang | b910987 | 2021-01-15 15:54:59 +0800 | [diff] [blame] | 1677 | if (!respStart) |
| 1678 | { |
| 1679 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1680 | "ipmiStorageGetSDR: record is null"); |
| 1681 | return ipmi::responseSuccess(nextRecordId, record); |
Kuiying Wang | b910987 | 2021-01-15 15:54:59 +0800 | [diff] [blame] | 1682 | } |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1683 | std::vector<uint8_t> recordData(respStart, respStart + bytesToRead); |
Kuiying Wang | 17eadbf | 2021-02-06 23:38:22 +0800 | [diff] [blame] | 1684 | |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1685 | return ipmi::responseSuccess(nextRecordId, recordData); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1686 | } |
| 1687 | /* end storage commands */ |
| 1688 | |
| 1689 | void registerSensorFunctions() |
| 1690 | { |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 1691 | // <Platform Event> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1692 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1693 | ipmi::sensor_event::cmdPlatformEvent, |
| 1694 | ipmi::Privilege::Operator, ipmiSenPlatformEvent); |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 1695 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1696 | // <Get Sensor Reading> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1697 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1698 | ipmi::sensor_event::cmdGetSensorReading, |
| 1699 | ipmi::Privilege::User, ipmiSenGetSensorReading); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1700 | |
| 1701 | // <Get Sensor Threshold> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1702 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1703 | ipmi::sensor_event::cmdGetSensorThreshold, |
| 1704 | ipmi::Privilege::User, ipmiSenGetSensorThresholds); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1705 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 1706 | // <Set Sensor Threshold> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1707 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1708 | ipmi::sensor_event::cmdSetSensorThreshold, |
| 1709 | ipmi::Privilege::Operator, |
| 1710 | ipmiSenSetSensorThresholds); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1711 | |
| 1712 | // <Get Sensor Event Enable> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1713 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1714 | ipmi::sensor_event::cmdGetSensorEventEnable, |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 1715 | ipmi::Privilege::User, ipmiSenGetSensorEventEnable); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1716 | |
| 1717 | // <Get Sensor Event Status> |
jayaprakash Mutyala | ccf88f6 | 2019-05-13 16:57:16 +0000 | [diff] [blame] | 1718 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1719 | ipmi::sensor_event::cmdGetSensorEventStatus, |
| 1720 | ipmi::Privilege::User, ipmiSenGetSensorEventStatus); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1721 | |
| 1722 | // register all storage commands for both Sensor and Storage command |
| 1723 | // versions |
| 1724 | |
| 1725 | // <Get SDR Repository Info> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1726 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1727 | ipmi::storage::cmdGetSdrRepositoryInfo, |
| 1728 | ipmi::Privilege::User, |
| 1729 | ipmiStorageGetSDRRepositoryInfo); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1730 | |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1731 | // <Get Device SDR Info> |
| 1732 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor, |
| 1733 | ipmi::sensor_event::cmdGetDeviceSdrInfo, |
| 1734 | ipmi::Privilege::User, ipmiSensorGetDeviceSdrInfo); |
| 1735 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1736 | // <Get SDR Allocation Info> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1737 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1738 | ipmi::storage::cmdGetSdrRepositoryAllocInfo, |
| 1739 | ipmi::Privilege::User, |
| 1740 | ipmiStorageGetSDRAllocationInfo); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1741 | |
| 1742 | // <Reserve SDR Repo> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1743 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1744 | ipmi::sensor_event::cmdReserveDeviceSdrRepository, |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1745 | ipmi::Privilege::User, ipmiStorageReserveSDR); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1746 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1747 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1748 | ipmi::storage::cmdReserveSdrRepository, |
| 1749 | ipmi::Privilege::User, ipmiStorageReserveSDR); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1750 | |
| 1751 | // <Get Sdr> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1752 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1753 | ipmi::sensor_event::cmdGetDeviceSdr, |
| 1754 | ipmi::Privilege::User, ipmiStorageGetSDR); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1755 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1756 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1757 | ipmi::storage::cmdGetSdr, ipmi::Privilege::User, |
| 1758 | ipmiStorageGetSDR); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1759 | } |
| 1760 | } // namespace ipmi |