blob: 6b3dc8c553c38d1ff3eb89dce84801b3e27de6e3 [file] [log] [blame]
Willy Tude54f482021-01-26 15:59:09 -08001/*
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
17#include "dbus-sdr/sensorcommands.hpp"
18
19#include "dbus-sdr/sdrutils.hpp"
20#include "dbus-sdr/sensorutils.hpp"
21#include "dbus-sdr/storagecommands.hpp"
Harvey Wu05d17c02021-09-15 08:46:59 +080022#include "entity_map_json.hpp"
Willy Tude54f482021-01-26 15:59:09 -080023
24#include <algorithm>
25#include <array>
26#include <boost/algorithm/string.hpp>
27#include <boost/container/flat_map.hpp>
28#include <chrono>
29#include <cmath>
30#include <cstring>
31#include <iostream>
32#include <ipmid/api.hpp>
33#include <ipmid/types.hpp>
34#include <ipmid/utils.hpp>
35#include <map>
36#include <memory>
37#include <optional>
38#include <phosphor-logging/log.hpp>
39#include <sdbusplus/bus.hpp>
40#include <stdexcept>
41#include <string>
Chalapathi Venkataramashetty6f43f4a2021-06-20 19:50:33 +000042#include <user_channel/channel_layer.hpp>
Willy Tude54f482021-01-26 15:59:09 -080043#include <utility>
44#include <variant>
45
Scron Chang2703b022021-07-06 15:47:45 +080046#ifdef FEATURE_HYBRID_SENSORS
47
48#include "sensordatahandler.hpp"
49namespace ipmi
50{
51namespace sensor
52{
53extern const IdInfoMap sensors;
54} // namespace sensor
55} // namespace ipmi
56#endif
adarshgrami042e9db2022-09-15 10:34:34 +053057namespace ipmi
58{
59namespace dcmi
60{
61// Refer Table 6-14, DCMI Entity ID Extension, DCMI v1.5 spec
62static const std::map<uint8_t, uint8_t> validEntityId{
63 {0x40, 0x37}, {0x37, 0x40}, {0x41, 0x03},
64 {0x03, 0x41}, {0x42, 0x07}, {0x07, 0x42}};
65constexpr uint8_t temperatureSensorType = 0x01;
66constexpr uint8_t maxRecords = 8;
67} // namespace dcmi
68} // namespace ipmi
JeffLind950f412021-10-20 18:49:34 +080069constexpr std::array<const char*, 7> suffixes = {
70 "_Output_Voltage", "_Input_Voltage", "_Output_Current", "_Input_Current",
71 "_Output_Power", "_Input_Power", "_Temperature"};
Willy Tude54f482021-01-26 15:59:09 -080072namespace ipmi
73{
Hao Jiangd48c9212021-02-03 15:45:06 -080074
75using phosphor::logging::entry;
76using phosphor::logging::level;
77using phosphor::logging::log;
78
Willy Tude54f482021-01-26 15:59:09 -080079static constexpr int sensorMapUpdatePeriod = 10;
Alex Qiu9ab2f942020-07-15 17:56:21 -070080static constexpr int sensorMapSdrUpdatePeriod = 60;
Willy Tude54f482021-01-26 15:59:09 -080081
Willy Tu38e7a2b2021-03-29 15:09:56 -070082// BMC I2C address is generally at 0x20
83static constexpr uint8_t bmcI2CAddr = 0x20;
84
Willy Tude54f482021-01-26 15:59:09 -080085constexpr size_t maxSDRTotalSize =
86 76; // Largest SDR Record Size (type 01) + SDR Overheader Size
87constexpr static const uint32_t noTimestamp = 0xFFFFFFFF;
88
89static uint16_t sdrReservationID;
90static uint32_t sdrLastAdd = noTimestamp;
91static uint32_t sdrLastRemove = noTimestamp;
92static constexpr size_t lastRecordIndex = 0xFFFF;
Johnathan Mantey6619ae42021-08-06 11:21:10 -070093
94// The IPMI spec defines four Logical Units (LUN), each capable of supporting
95// 255 sensors. The 256 values assigned to LUN 2 are special and are not used
96// for general purpose sensors. Each LUN reserves location 0xFF. The maximum
97// number of IPMI sensors are LUN 0 + LUN 1 + LUN 2, less the reserved
98// location.
99static constexpr size_t maxIPMISensors = ((3 * 256) - (3 * 1));
100
101static constexpr size_t lun0MaxSensorNum = 0xfe;
102static constexpr size_t lun1MaxSensorNum = 0x1fe;
103static constexpr size_t lun3MaxSensorNum = 0x3fe;
Willy Tude54f482021-01-26 15:59:09 -0800104static constexpr int GENERAL_ERROR = -1;
105
Willy Tude54f482021-01-26 15:59:09 -0800106static boost::container::flat_map<std::string, ObjectValueTree> SensorCache;
107
108// Specify the comparison required to sort and find char* map objects
109struct CmpStr
110{
111 bool operator()(const char* a, const char* b) const
112 {
113 return std::strcmp(a, b) < 0;
114 }
115};
116const static boost::container::flat_map<const char*, SensorUnits, CmpStr>
117 sensorUnits{{{"temperature", SensorUnits::degreesC},
118 {"voltage", SensorUnits::volts},
119 {"current", SensorUnits::amps},
120 {"fan_tach", SensorUnits::rpm},
121 {"power", SensorUnits::watts}}};
122
123void registerSensorFunctions() __attribute__((constructor));
124
Patrick Williams5d82f472022-07-22 19:26:53 -0500125static sdbusplus::bus::match_t sensorAdded(
Willy Tude54f482021-01-26 15:59:09 -0800126 *getSdBus(),
127 "type='signal',member='InterfacesAdded',arg0path='/xyz/openbmc_project/"
128 "sensors/'",
Patrick Williams5d82f472022-07-22 19:26:53 -0500129 [](sdbusplus::message_t&) {
Willy Tude54f482021-01-26 15:59:09 -0800130 getSensorTree().clear();
Willy Tu4eca2512022-06-20 21:14:51 -0700131 getIpmiDecoratorPaths(/*ctx=*/std::nullopt).reset();
Willy Tude54f482021-01-26 15:59:09 -0800132 sdrLastAdd = std::chrono::duration_cast<std::chrono::seconds>(
133 std::chrono::system_clock::now().time_since_epoch())
134 .count();
135 });
136
Patrick Williams5d82f472022-07-22 19:26:53 -0500137static sdbusplus::bus::match_t sensorRemoved(
Willy Tude54f482021-01-26 15:59:09 -0800138 *getSdBus(),
139 "type='signal',member='InterfacesRemoved',arg0path='/xyz/openbmc_project/"
140 "sensors/'",
Patrick Williams5d82f472022-07-22 19:26:53 -0500141 [](sdbusplus::message_t&) {
Willy Tude54f482021-01-26 15:59:09 -0800142 getSensorTree().clear();
Willy Tu4eca2512022-06-20 21:14:51 -0700143 getIpmiDecoratorPaths(/*ctx=*/std::nullopt).reset();
Willy Tude54f482021-01-26 15:59:09 -0800144 sdrLastRemove = std::chrono::duration_cast<std::chrono::seconds>(
145 std::chrono::system_clock::now().time_since_epoch())
146 .count();
147 });
148
149// this keeps track of deassertions for sensor event status command. A
150// deasertion can only happen if an assertion was seen first.
151static boost::container::flat_map<
152 std::string, boost::container::flat_map<std::string, std::optional<bool>>>
153 thresholdDeassertMap;
154
Patrick Williams5d82f472022-07-22 19:26:53 -0500155static sdbusplus::bus::match_t thresholdChanged(
Willy Tude54f482021-01-26 15:59:09 -0800156 *getSdBus(),
157 "type='signal',member='PropertiesChanged',interface='org.freedesktop.DBus."
158 "Properties',arg0namespace='xyz.openbmc_project.Sensor.Threshold'",
Patrick Williams5d82f472022-07-22 19:26:53 -0500159 [](sdbusplus::message_t& m) {
Willy Tude54f482021-01-26 15:59:09 -0800160 boost::container::flat_map<std::string, std::variant<bool, double>>
161 values;
162 m.read(std::string(), values);
163
164 auto findAssert =
165 std::find_if(values.begin(), values.end(), [](const auto& pair) {
166 return pair.first.find("Alarm") != std::string::npos;
167 });
168 if (findAssert != values.end())
169 {
170 auto ptr = std::get_if<bool>(&(findAssert->second));
171 if (ptr == nullptr)
172 {
173 phosphor::logging::log<phosphor::logging::level::ERR>(
174 "thresholdChanged: Assert non bool");
175 return;
176 }
177 if (*ptr)
178 {
179 phosphor::logging::log<phosphor::logging::level::INFO>(
180 "thresholdChanged: Assert",
181 phosphor::logging::entry("SENSOR=%s", m.get_path()));
182 thresholdDeassertMap[m.get_path()][findAssert->first] = *ptr;
183 }
184 else
185 {
186 auto& value =
187 thresholdDeassertMap[m.get_path()][findAssert->first];
188 if (value)
189 {
190 phosphor::logging::log<phosphor::logging::level::INFO>(
191 "thresholdChanged: deassert",
192 phosphor::logging::entry("SENSOR=%s", m.get_path()));
193 value = *ptr;
194 }
195 }
196 }
197 });
198
Hao Jiangd2afd052020-12-10 15:09:32 -0800199namespace sensor
200{
201static constexpr const char* vrInterface =
202 "xyz.openbmc_project.Control.VoltageRegulatorMode";
203static constexpr const char* sensorInterface =
204 "xyz.openbmc_project.Sensor.Value";
205} // namespace sensor
206
Willy Tude54f482021-01-26 15:59:09 -0800207static void getSensorMaxMin(const DbusInterfaceMap& sensorMap, double& max,
208 double& min)
209{
210 max = 127;
211 min = -128;
212
Hao Jiangd2afd052020-12-10 15:09:32 -0800213 auto sensorObject = sensorMap.find(sensor::sensorInterface);
Willy Tude54f482021-01-26 15:59:09 -0800214 auto critical =
215 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical");
216 auto warning =
217 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning");
218
219 if (sensorObject != sensorMap.end())
220 {
221 auto maxMap = sensorObject->second.find("MaxValue");
222 auto minMap = sensorObject->second.find("MinValue");
223
224 if (maxMap != sensorObject->second.end())
225 {
226 max = std::visit(VariantToDoubleVisitor(), maxMap->second);
227 }
228 if (minMap != sensorObject->second.end())
229 {
230 min = std::visit(VariantToDoubleVisitor(), minMap->second);
231 }
232 }
233 if (critical != sensorMap.end())
234 {
235 auto lower = critical->second.find("CriticalLow");
236 auto upper = critical->second.find("CriticalHigh");
237 if (lower != critical->second.end())
238 {
239 double value = std::visit(VariantToDoubleVisitor(), lower->second);
Konstantin Aladyshev8265af22021-12-16 18:18:10 +0300240 if (std::isfinite(value))
241 {
242 min = std::min(value, min);
243 }
Willy Tude54f482021-01-26 15:59:09 -0800244 }
245 if (upper != critical->second.end())
246 {
247 double value = std::visit(VariantToDoubleVisitor(), upper->second);
Konstantin Aladyshev8265af22021-12-16 18:18:10 +0300248 if (std::isfinite(value))
249 {
250 max = std::max(value, max);
251 }
Willy Tude54f482021-01-26 15:59:09 -0800252 }
253 }
254 if (warning != sensorMap.end())
255 {
256
257 auto lower = warning->second.find("WarningLow");
258 auto upper = warning->second.find("WarningHigh");
259 if (lower != warning->second.end())
260 {
261 double value = std::visit(VariantToDoubleVisitor(), lower->second);
Konstantin Aladyshev8265af22021-12-16 18:18:10 +0300262 if (std::isfinite(value))
263 {
264 min = std::min(value, min);
265 }
Willy Tude54f482021-01-26 15:59:09 -0800266 }
267 if (upper != warning->second.end())
268 {
269 double value = std::visit(VariantToDoubleVisitor(), upper->second);
Konstantin Aladyshev8265af22021-12-16 18:18:10 +0300270 if (std::isfinite(value))
271 {
272 max = std::max(value, max);
273 }
Willy Tude54f482021-01-26 15:59:09 -0800274 }
275 }
276}
277
278static bool getSensorMap(ipmi::Context::ptr ctx, std::string sensorConnection,
Alex Qiu9ab2f942020-07-15 17:56:21 -0700279 std::string sensorPath, DbusInterfaceMap& sensorMap,
280 int updatePeriod = sensorMapUpdatePeriod)
Willy Tude54f482021-01-26 15:59:09 -0800281{
Scron Chang2703b022021-07-06 15:47:45 +0800282#ifdef FEATURE_HYBRID_SENSORS
283 if (auto sensor = findStaticSensor(sensorPath);
284 sensor != ipmi::sensor::sensors.end() &&
285 getSensorEventTypeFromPath(sensorPath) !=
286 static_cast<uint8_t>(SensorEventTypeCodes::threshold))
287 {
288 // If the incoming sensor is a discrete sensor, it might fail in
289 // getManagedObjects(), return true, and use its own getFunc to get
290 // value.
291 return true;
292 }
293#endif
294
Willy Tude54f482021-01-26 15:59:09 -0800295 static boost::container::flat_map<
296 std::string, std::chrono::time_point<std::chrono::steady_clock>>
297 updateTimeMap;
298
299 auto updateFind = updateTimeMap.find(sensorConnection);
300 auto lastUpdate = std::chrono::time_point<std::chrono::steady_clock>();
301 if (updateFind != updateTimeMap.end())
302 {
303 lastUpdate = updateFind->second;
304 }
305
306 auto now = std::chrono::steady_clock::now();
307
308 if (std::chrono::duration_cast<std::chrono::seconds>(now - lastUpdate)
Alex Qiu9ab2f942020-07-15 17:56:21 -0700309 .count() > updatePeriod)
Willy Tude54f482021-01-26 15:59:09 -0800310 {
Sui Chenc2cb1bc2023-01-10 02:52:06 -0800311 bool found = false;
Willy Tude54f482021-01-26 15:59:09 -0800312
Sui Chenc2cb1bc2023-01-10 02:52:06 -0800313 // Object managers for different kinds of OpenBMC DBus interfaces.
314 // Documented in the phosphor-dbus-interfaces repository.
315 const char* paths[] = {
316 "/xyz/openbmc_project/sensors",
317 "/xyz/openbmc_project/vr",
318 };
319 constexpr size_t num_paths = sizeof(paths) / sizeof(paths[0]);
320 ObjectValueTree allManagedObjects;
321
322 for (size_t i = 0; i < num_paths; i++)
323 {
324 ObjectValueTree managedObjects;
325 boost::system::error_code ec = getManagedObjects(
326 ctx, sensorConnection.c_str(), paths[i], managedObjects);
327 if (ec)
328 {
329 phosphor::logging::log<phosphor::logging::level::ERR>(
330 "GetMangagedObjects for getSensorMap failed",
331 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
332
333 continue;
334 }
335 allManagedObjects.merge(managedObjects);
336 found = true;
337 }
338
339 if (!found)
340 {
Willy Tude54f482021-01-26 15:59:09 -0800341 return false;
342 }
343
Sui Chenc2cb1bc2023-01-10 02:52:06 -0800344 SensorCache[sensorConnection] = allManagedObjects;
Alex Qiu9ab2f942020-07-15 17:56:21 -0700345 // Update time after finish building the map which allow the
346 // data to be cached for updatePeriod plus the build time.
347 updateTimeMap[sensorConnection] = std::chrono::steady_clock::now();
Willy Tude54f482021-01-26 15:59:09 -0800348 }
349 auto connection = SensorCache.find(sensorConnection);
350 if (connection == SensorCache.end())
351 {
352 return false;
353 }
354 auto path = connection->second.find(sensorPath);
355 if (path == connection->second.end())
356 {
357 return false;
358 }
359 sensorMap = path->second;
360
361 return true;
362}
363
Hao Jiangd2afd052020-12-10 15:09:32 -0800364namespace sensor
365{
Hao Jiangd48c9212021-02-03 15:45:06 -0800366// Read VR profiles from sensor(daemon) interface
367static std::optional<std::vector<std::string>>
368 getSupportedVrProfiles(const ipmi::DbusInterfaceMap::mapped_type& object)
Hao Jiangd2afd052020-12-10 15:09:32 -0800369{
370 // get VR mode profiles from Supported Interface
Hao Jiangd48c9212021-02-03 15:45:06 -0800371 auto supportedProperty = object.find("Supported");
372 if (supportedProperty == object.end() ||
373 object.find("Selected") == object.end())
Hao Jiangd2afd052020-12-10 15:09:32 -0800374 {
375 phosphor::logging::log<phosphor::logging::level::ERR>(
376 "Missing the required Supported and Selected properties");
377 return std::nullopt;
378 }
379
380 const auto profilesPtr =
381 std::get_if<std::vector<std::string>>(&supportedProperty->second);
382
383 if (profilesPtr == nullptr)
384 {
385 phosphor::logging::log<phosphor::logging::level::ERR>(
386 "property is not array of string");
387 return std::nullopt;
388 }
Hao Jiangd48c9212021-02-03 15:45:06 -0800389 return *profilesPtr;
390}
391
392// Calculate VR Mode from input IPMI discrete event bytes
393static std::optional<std::string>
394 calculateVRMode(uint15_t assertOffset,
395 const ipmi::DbusInterfaceMap::mapped_type& VRObject)
396{
397 // get VR mode profiles from Supported Interface
398 auto profiles = getSupportedVrProfiles(VRObject);
399 if (!profiles)
400 {
401 return std::nullopt;
402 }
Hao Jiangd2afd052020-12-10 15:09:32 -0800403
404 // interpret IPMI cmd bits into profiles' index
405 long unsigned int index = 0;
406 // only one bit should be set and the highest bit should not be used.
407 if (assertOffset == 0 || assertOffset == (1u << 15) ||
408 (assertOffset & (assertOffset - 1)))
409 {
410 phosphor::logging::log<phosphor::logging::level::ERR>(
411 "IPMI cmd format incorrect",
412
413 phosphor::logging::entry("BYTES=%#02x",
414 static_cast<uint16_t>(assertOffset)));
415 return std::nullopt;
416 }
417
418 while (assertOffset != 1)
419 {
420 assertOffset >>= 1;
421 index++;
422 }
423
Hao Jiangd48c9212021-02-03 15:45:06 -0800424 if (index >= profiles->size())
Hao Jiangd2afd052020-12-10 15:09:32 -0800425 {
426 phosphor::logging::log<phosphor::logging::level::ERR>(
427 "profile index out of boundary");
428 return std::nullopt;
429 }
430
Hao Jiangd48c9212021-02-03 15:45:06 -0800431 return profiles->at(index);
Hao Jiangd2afd052020-12-10 15:09:32 -0800432}
433
434// Calculate sensor value from IPMI reading byte
435static std::optional<double>
436 calculateValue(uint8_t reading, const ipmi::DbusInterfaceMap& sensorMap,
437 const ipmi::DbusInterfaceMap::mapped_type& valueObject)
438{
439 if (valueObject.find("Value") == valueObject.end())
440 {
441 phosphor::logging::log<phosphor::logging::level::ERR>(
442 "Missing the required Value property");
443 return std::nullopt;
444 }
445
446 double max = 0;
447 double min = 0;
448 getSensorMaxMin(sensorMap, max, min);
449
450 int16_t mValue = 0;
451 int16_t bValue = 0;
452 int8_t rExp = 0;
453 int8_t bExp = 0;
454 bool bSigned = false;
455
456 if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned))
457 {
458 return std::nullopt;
459 }
460
461 double value = bSigned ? ((int8_t)reading) : reading;
462
463 value *= ((double)mValue);
464 value += ((double)bValue) * std::pow(10.0, bExp);
465 value *= std::pow(10.0, rExp);
466
467 return value;
468}
469
Willy Tu38e7a2b2021-03-29 15:09:56 -0700470// Extract file name from sensor path as the sensors SDR ID. Simplify the name
471// if it is too long.
472std::string parseSdrIdFromPath(const std::string& path)
473{
474 std::string name;
475 size_t nameStart = path.rfind("/");
476 if (nameStart != std::string::npos)
477 {
478 name = path.substr(nameStart + 1, std::string::npos - nameStart);
479 }
480
Willy Tu38e7a2b2021-03-29 15:09:56 -0700481 if (name.size() > FULL_RECORD_ID_STR_MAX_LENGTH)
482 {
483 // try to not truncate by replacing common words
JeffLind950f412021-10-20 18:49:34 +0800484 for (const auto& suffix : suffixes)
Willy Tu38e7a2b2021-03-29 15:09:56 -0700485 {
JeffLind950f412021-10-20 18:49:34 +0800486 if (boost::ends_with(name, suffix))
487 {
488 boost::replace_all(name, suffix, "");
489 break;
490 }
Willy Tu38e7a2b2021-03-29 15:09:56 -0700491 }
Duke Du97014f52021-12-16 17:21:01 +0800492 if (name.size() > FULL_RECORD_ID_STR_MAX_LENGTH)
493 {
494 name.resize(FULL_RECORD_ID_STR_MAX_LENGTH);
495 }
Willy Tu38e7a2b2021-03-29 15:09:56 -0700496 }
497 return name;
498}
499
Hao Jiangd48c9212021-02-03 15:45:06 -0800500bool getVrEventStatus(ipmi::Context::ptr ctx, const std::string& connection,
501 const std::string& path,
502 const ipmi::DbusInterfaceMap::mapped_type& object,
503 std::bitset<16>& assertions)
504{
505 auto profiles = sensor::getSupportedVrProfiles(object);
506 if (!profiles)
507 {
508 return false;
509 }
Willy Tu8366f0b2022-04-29 05:00:17 -0700510 std::string mode;
Hao Jiangd48c9212021-02-03 15:45:06 -0800511
512 auto ec = getDbusProperty(ctx, connection, path, sensor::vrInterface,
Willy Tu8366f0b2022-04-29 05:00:17 -0700513 "Selected", mode);
Hao Jiangd48c9212021-02-03 15:45:06 -0800514 if (ec)
515 {
516 log<level::ERR>("Failed to get property",
517 entry("PROPERTY=%s", "Selected"),
518 entry("PATH=%s", path.c_str()),
519 entry("INTERFACE=%s", sensor::sensorInterface),
520 entry("WHAT=%s", ec.message().c_str()));
521 return false;
522 }
523
Willy Tu8366f0b2022-04-29 05:00:17 -0700524 auto itr = std::find(profiles->begin(), profiles->end(), mode);
Hao Jiangd48c9212021-02-03 15:45:06 -0800525 if (itr == profiles->end())
526 {
527 using namespace phosphor::logging;
528 log<level::ERR>("VR mode doesn't match any of its profiles",
529 entry("PATH=%s", path.c_str()));
530 return false;
531 }
532 std::size_t index =
533 static_cast<std::size_t>(std::distance(profiles->begin(), itr));
534
Willy Tubef102a2022-06-09 15:36:09 -0700535 // map index to response event assertion bit.
536 if (index < 16)
Hao Jiangd48c9212021-02-03 15:45:06 -0800537 {
Willy Tubef102a2022-06-09 15:36:09 -0700538 assertions.set(index);
Hao Jiangd48c9212021-02-03 15:45:06 -0800539 }
540 else
541 {
542 log<level::ERR>("VR profile index reaches max assertion bit",
543 entry("PATH=%s", path.c_str()),
544 entry("INDEX=%uz", index));
545 return false;
546 }
547 if constexpr (debug)
548 {
549 std::cerr << "VR sensor " << sensor::parseSdrIdFromPath(path)
Willy Tu8366f0b2022-04-29 05:00:17 -0700550 << " mode is: [" << index << "] " << mode << std::endl;
Hao Jiangd48c9212021-02-03 15:45:06 -0800551 }
552 return true;
553}
Hao Jiangd2afd052020-12-10 15:09:32 -0800554} // namespace sensor
555
Chalapathi Venkataramashetty6f43f4a2021-06-20 19:50:33 +0000556ipmi::RspType<> ipmiSenPlatformEvent(ipmi::Context::ptr ctx,
557 ipmi::message::Payload& p)
Willy Tude54f482021-01-26 15:59:09 -0800558{
Chalapathi Venkataramashetty6f43f4a2021-06-20 19:50:33 +0000559 constexpr const uint8_t validEnvmRev = 0x04;
560 constexpr const uint8_t lastSensorType = 0x2C;
561 constexpr const uint8_t oemReserved = 0xC0;
562
Sujoy Ray3ab2c2b2021-11-01 13:17:27 -0700563 uint8_t sysgeneratorID = 0;
Chalapathi Venkataramashetty6f43f4a2021-06-20 19:50:33 +0000564 uint8_t evmRev = 0;
565 uint8_t sensorType = 0;
566 uint8_t sensorNum = 0;
567 uint8_t eventType = 0;
568 uint8_t eventData1 = 0;
569 std::optional<uint8_t> eventData2 = 0;
570 std::optional<uint8_t> eventData3 = 0;
Sujoy Ray3ab2c2b2021-11-01 13:17:27 -0700571 [[maybe_unused]] uint16_t generatorID = 0;
Chalapathi Venkataramashetty6f43f4a2021-06-20 19:50:33 +0000572 ipmi::ChannelInfo chInfo;
573
574 if (ipmi::getChannelInfo(ctx->channel, chInfo) != ipmi::ccSuccess)
575 {
576 phosphor::logging::log<phosphor::logging::level::ERR>(
577 "Failed to get Channel Info",
578 phosphor::logging::entry("CHANNEL=%d", ctx->channel));
579 return ipmi::responseUnspecifiedError();
580 }
581
582 if (static_cast<ipmi::EChannelMediumType>(chInfo.mediumType) ==
583 ipmi::EChannelMediumType::systemInterface)
584 {
585
Sujoy Ray3ab2c2b2021-11-01 13:17:27 -0700586 p.unpack(sysgeneratorID, evmRev, sensorType, sensorNum, eventType,
Chalapathi Venkataramashetty6f43f4a2021-06-20 19:50:33 +0000587 eventData1, eventData2, eventData3);
Sujoy Ray3ab2c2b2021-11-01 13:17:27 -0700588 // Refer to IPMI Spec Table 32: SEL Event Records
589 generatorID = (ctx->channel << 12) // Channel
590 | (0x0 << 10) // Reserved
591 | (0x0 << 8) // 0x0 for sys-soft ID
592 | ((sysgeneratorID << 1) | 0x1);
Chalapathi Venkataramashetty6f43f4a2021-06-20 19:50:33 +0000593 }
594 else
595 {
596
597 p.unpack(evmRev, sensorType, sensorNum, eventType, eventData1,
598 eventData2, eventData3);
Sujoy Ray3ab2c2b2021-11-01 13:17:27 -0700599 // Refer to IPMI Spec Table 32: SEL Event Records
600 generatorID = (ctx->channel << 12) // Channel
601 | (0x0 << 10) // Reserved
602 | ((ctx->lun & 0x3) << 8) // Lun
603 | (ctx->rqSA << 1);
Chalapathi Venkataramashetty6f43f4a2021-06-20 19:50:33 +0000604 }
605
606 if (!p.fullyUnpacked())
607 {
608 return ipmi::responseReqDataLenInvalid();
609 }
610
611 // Check for valid evmRev and Sensor Type(per Table 42 of spec)
612 if (evmRev != validEnvmRev)
613 {
614 return ipmi::responseInvalidFieldRequest();
615 }
616 if ((sensorType > lastSensorType) && (sensorType < oemReserved))
617 {
618 return ipmi::responseInvalidFieldRequest();
619 }
620
Willy Tude54f482021-01-26 15:59:09 -0800621 return ipmi::responseSuccess();
622}
623
Willy Tudbafbce2021-03-29 00:37:05 -0700624ipmi::RspType<> ipmiSetSensorReading(ipmi::Context::ptr ctx,
Willy Tu11d68892022-01-20 10:37:34 -0800625 uint8_t sensorNumber, uint8_t,
Willy Tudbafbce2021-03-29 00:37:05 -0700626 uint8_t reading, uint15_t assertOffset,
Willy Tu11d68892022-01-20 10:37:34 -0800627 bool, uint15_t, bool, uint8_t, uint8_t,
628 uint8_t)
Willy Tudbafbce2021-03-29 00:37:05 -0700629{
630 std::string connection;
631 std::string path;
Hao Jiange39d4d82021-04-16 17:02:40 -0700632 std::vector<std::string> interfaces;
633
634 ipmi::Cc status =
635 getSensorConnection(ctx, sensorNumber, connection, path, &interfaces);
Willy Tudbafbce2021-03-29 00:37:05 -0700636 if (status)
637 {
638 return ipmi::response(status);
639 }
640
Hao Jiangd2afd052020-12-10 15:09:32 -0800641 // we can tell the sensor type by its interface type
Hao Jiange39d4d82021-04-16 17:02:40 -0700642 if (std::find(interfaces.begin(), interfaces.end(),
643 sensor::sensorInterface) != interfaces.end())
Willy Tudbafbce2021-03-29 00:37:05 -0700644 {
Hao Jiange39d4d82021-04-16 17:02:40 -0700645 DbusInterfaceMap sensorMap;
646 if (!getSensorMap(ctx, connection, path, sensorMap))
647 {
648 return ipmi::responseResponseError();
649 }
650 auto sensorObject = sensorMap.find(sensor::sensorInterface);
Harvey Wuf61c0862021-09-15 08:48:40 +0800651 if (sensorObject == sensorMap.end())
Hao Jiange39d4d82021-04-16 17:02:40 -0700652 {
653 return ipmi::responseResponseError();
654 }
655
Jie Yangf0a89942021-07-29 15:30:25 -0700656 // Only allow external SetSensor if write permission granted
Harvey.Wu0e7a8af2022-06-10 16:46:46 +0800657 if (!details::sdrWriteTable.getWritePermission((ctx->lun << 8) |
658 sensorNumber))
Jie Yangf0a89942021-07-29 15:30:25 -0700659 {
660 return ipmi::responseResponseError();
661 }
662
Hao Jiangd2afd052020-12-10 15:09:32 -0800663 auto value =
664 sensor::calculateValue(reading, sensorMap, sensorObject->second);
665 if (!value)
666 {
667 return ipmi::responseResponseError();
668 }
669
670 if constexpr (debug)
671 {
672 phosphor::logging::log<phosphor::logging::level::INFO>(
673 "IPMI SET_SENSOR",
674 phosphor::logging::entry("SENSOR_NUM=%d", sensorNumber),
675 phosphor::logging::entry("BYTE=%u", (unsigned int)reading),
676 phosphor::logging::entry("VALUE=%f", *value));
677 }
678
679 boost::system::error_code ec =
680 setDbusProperty(ctx, connection, path, sensor::sensorInterface,
681 "Value", ipmi::Value(*value));
682
683 // setDbusProperty intended to resolve dbus exception/rc within the
Patrick Williamsef1259b2021-09-02 09:12:33 -0500684 // function but failed to achieve that. Catch exception in the ipmi
Hao Jiangd2afd052020-12-10 15:09:32 -0800685 // callback functions for now (e.g. ipmiSetSensorReading).
686 if (ec)
687 {
688 using namespace phosphor::logging;
689 log<level::ERR>("Failed to set property",
690 entry("PROPERTY=%s", "Value"),
691 entry("PATH=%s", path.c_str()),
692 entry("INTERFACE=%s", sensor::sensorInterface),
693 entry("WHAT=%s", ec.message().c_str()));
694 return ipmi::responseResponseError();
695 }
696 return ipmi::responseSuccess();
Willy Tudbafbce2021-03-29 00:37:05 -0700697 }
698
Hao Jiange39d4d82021-04-16 17:02:40 -0700699 if (std::find(interfaces.begin(), interfaces.end(), sensor::vrInterface) !=
700 interfaces.end())
Willy Tudbafbce2021-03-29 00:37:05 -0700701 {
Hao Jiange39d4d82021-04-16 17:02:40 -0700702 DbusInterfaceMap sensorMap;
703 if (!getSensorMap(ctx, connection, path, sensorMap))
704 {
705 return ipmi::responseResponseError();
706 }
707 auto sensorObject = sensorMap.find(sensor::vrInterface);
Harvey Wuf61c0862021-09-15 08:48:40 +0800708 if (sensorObject == sensorMap.end())
Hao Jiange39d4d82021-04-16 17:02:40 -0700709 {
710 return ipmi::responseResponseError();
711 }
712
Hao Jiangd2afd052020-12-10 15:09:32 -0800713 // VR sensors are treated as a special case and we will not check the
714 // write permission for VR sensors, since they always deemed writable
715 // and permission table are not applied to VR sensors.
716 auto vrMode =
717 sensor::calculateVRMode(assertOffset, sensorObject->second);
718 if (!vrMode)
719 {
720 return ipmi::responseResponseError();
721 }
722 boost::system::error_code ec = setDbusProperty(
723 ctx, connection, path, sensor::vrInterface, "Selected", *vrMode);
724 // setDbusProperty intended to resolve dbus exception/rc within the
Patrick Williamsef1259b2021-09-02 09:12:33 -0500725 // function but failed to achieve that. Catch exception in the ipmi
Hao Jiangd2afd052020-12-10 15:09:32 -0800726 // callback functions for now (e.g. ipmiSetSensorReading).
727 if (ec)
728 {
729 using namespace phosphor::logging;
730 log<level::ERR>("Failed to set property",
731 entry("PROPERTY=%s", "Selected"),
732 entry("PATH=%s", path.c_str()),
733 entry("INTERFACE=%s", sensor::sensorInterface),
734 entry("WHAT=%s", ec.message().c_str()));
735 return ipmi::responseResponseError();
736 }
737 return ipmi::responseSuccess();
Willy Tudbafbce2021-03-29 00:37:05 -0700738 }
739
Hao Jiangd2afd052020-12-10 15:09:32 -0800740 phosphor::logging::log<phosphor::logging::level::ERR>(
741 "unknown sensor type",
742 phosphor::logging::entry("PATH=%s", path.c_str()));
743 return ipmi::responseResponseError();
Willy Tudbafbce2021-03-29 00:37:05 -0700744}
745
Willy Tude54f482021-01-26 15:59:09 -0800746ipmi::RspType<uint8_t, uint8_t, uint8_t, std::optional<uint8_t>>
747 ipmiSenGetSensorReading(ipmi::Context::ptr ctx, uint8_t sensnum)
748{
749 std::string connection;
750 std::string path;
751
Chalapathi Venkataramashetty8c2f3c42021-06-13 19:51:17 +0000752 if (sensnum == reservedSensorNumber)
753 {
754 return ipmi::responseInvalidFieldRequest();
755 }
756
Willy Tude54f482021-01-26 15:59:09 -0800757 auto status = getSensorConnection(ctx, sensnum, connection, path);
758 if (status)
759 {
760 return ipmi::response(status);
761 }
762
Scron Chang2703b022021-07-06 15:47:45 +0800763#ifdef FEATURE_HYBRID_SENSORS
764 if (auto sensor = findStaticSensor(path);
765 sensor != ipmi::sensor::sensors.end() &&
766 getSensorEventTypeFromPath(path) !=
767 static_cast<uint8_t>(SensorEventTypeCodes::threshold))
768 {
769 if (ipmi::sensor::Mutability::Read !=
770 (sensor->second.mutability & ipmi::sensor::Mutability::Read))
771 {
772 return ipmi::responseIllegalCommand();
773 }
774
775 uint8_t operation;
776 try
777 {
778 ipmi::sensor::GetSensorResponse getResponse =
779 sensor->second.getFunc(sensor->second);
780
781 if (getResponse.readingOrStateUnavailable)
782 {
783 operation |= static_cast<uint8_t>(
784 IPMISensorReadingByte2::readingStateUnavailable);
785 }
786 if (getResponse.scanningEnabled)
787 {
788 operation |= static_cast<uint8_t>(
789 IPMISensorReadingByte2::sensorScanningEnable);
790 }
791 if (getResponse.allEventMessagesEnabled)
792 {
793 operation |= static_cast<uint8_t>(
794 IPMISensorReadingByte2::eventMessagesEnable);
795 }
796 return ipmi::responseSuccess(
797 getResponse.reading, operation,
798 getResponse.thresholdLevelsStates,
799 getResponse.discreteReadingSensorStates);
800 }
801 catch (const std::exception& e)
802 {
803 operation |= static_cast<uint8_t>(
804 IPMISensorReadingByte2::readingStateUnavailable);
805 return ipmi::responseSuccess(0, operation, 0, std::nullopt);
806 }
807 }
808#endif
809
Willy Tude54f482021-01-26 15:59:09 -0800810 DbusInterfaceMap sensorMap;
811 if (!getSensorMap(ctx, connection, path, sensorMap))
812 {
813 return ipmi::responseResponseError();
814 }
Hao Jiangd2afd052020-12-10 15:09:32 -0800815 auto sensorObject = sensorMap.find(sensor::sensorInterface);
Willy Tude54f482021-01-26 15:59:09 -0800816
817 if (sensorObject == sensorMap.end() ||
818 sensorObject->second.find("Value") == sensorObject->second.end())
819 {
820 return ipmi::responseResponseError();
821 }
822 auto& valueVariant = sensorObject->second["Value"];
823 double reading = std::visit(VariantToDoubleVisitor(), valueVariant);
824
825 double max = 0;
826 double min = 0;
827 getSensorMaxMin(sensorMap, max, min);
828
829 int16_t mValue = 0;
830 int16_t bValue = 0;
831 int8_t rExp = 0;
832 int8_t bExp = 0;
833 bool bSigned = false;
834
835 if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned))
836 {
837 return ipmi::responseResponseError();
838 }
839
840 uint8_t value =
841 scaleIPMIValueFromDouble(reading, mValue, rExp, bValue, bExp, bSigned);
842 uint8_t operation =
843 static_cast<uint8_t>(IPMISensorReadingByte2::sensorScanningEnable);
844 operation |=
845 static_cast<uint8_t>(IPMISensorReadingByte2::eventMessagesEnable);
846 bool notReading = std::isnan(reading);
847
848 if (!notReading)
849 {
850 auto availableObject =
851 sensorMap.find("xyz.openbmc_project.State.Decorator.Availability");
852 if (availableObject != sensorMap.end())
853 {
854 auto findAvailable = availableObject->second.find("Available");
855 if (findAvailable != availableObject->second.end())
856 {
857 bool* available = std::get_if<bool>(&(findAvailable->second));
858 if (available && !(*available))
859 {
860 notReading = true;
861 }
862 }
863 }
864 }
865
866 if (notReading)
867 {
868 operation |= static_cast<uint8_t>(
869 IPMISensorReadingByte2::readingStateUnavailable);
870 }
871
Josh Lehana55c9532020-10-28 21:59:06 -0700872 if constexpr (details::enableInstrumentation)
873 {
874 int byteValue;
875 if (bSigned)
876 {
877 byteValue = static_cast<int>(static_cast<int8_t>(value));
878 }
879 else
880 {
881 byteValue = static_cast<int>(static_cast<uint8_t>(value));
882 }
883
884 // Keep stats on the reading just obtained, even if it is "NaN"
Harvey.Wu0e7a8af2022-06-10 16:46:46 +0800885 if (details::sdrStatsTable.updateReading((ctx->lun << 8) | sensnum,
886 reading, byteValue))
Josh Lehana55c9532020-10-28 21:59:06 -0700887 {
888 // This is the first reading, show the coefficients
889 double step = (max - min) / 255.0;
890 std::cerr << "IPMI sensor "
Harvey.Wu0e7a8af2022-06-10 16:46:46 +0800891 << details::sdrStatsTable.getName((ctx->lun << 8) |
892 sensnum)
Josh Lehana55c9532020-10-28 21:59:06 -0700893 << ": Range min=" << min << " max=" << max
894 << ", step=" << step
895 << ", Coefficients mValue=" << static_cast<int>(mValue)
896 << " rExp=" << static_cast<int>(rExp)
897 << " bValue=" << static_cast<int>(bValue)
898 << " bExp=" << static_cast<int>(bExp)
899 << " bSigned=" << static_cast<int>(bSigned) << "\n";
900 }
901 }
902
Willy Tude54f482021-01-26 15:59:09 -0800903 uint8_t thresholds = 0;
904
905 auto warningObject =
906 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning");
907 if (warningObject != sensorMap.end())
908 {
909 auto alarmHigh = warningObject->second.find("WarningAlarmHigh");
910 auto alarmLow = warningObject->second.find("WarningAlarmLow");
911 if (alarmHigh != warningObject->second.end())
912 {
913 if (std::get<bool>(alarmHigh->second))
914 {
915 thresholds |= static_cast<uint8_t>(
916 IPMISensorReadingByte3::upperNonCritical);
917 }
918 }
919 if (alarmLow != warningObject->second.end())
920 {
921 if (std::get<bool>(alarmLow->second))
922 {
923 thresholds |= static_cast<uint8_t>(
924 IPMISensorReadingByte3::lowerNonCritical);
925 }
926 }
927 }
928
929 auto criticalObject =
930 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical");
931 if (criticalObject != sensorMap.end())
932 {
933 auto alarmHigh = criticalObject->second.find("CriticalAlarmHigh");
934 auto alarmLow = criticalObject->second.find("CriticalAlarmLow");
935 if (alarmHigh != criticalObject->second.end())
936 {
937 if (std::get<bool>(alarmHigh->second))
938 {
939 thresholds |=
940 static_cast<uint8_t>(IPMISensorReadingByte3::upperCritical);
941 }
942 }
943 if (alarmLow != criticalObject->second.end())
944 {
945 if (std::get<bool>(alarmLow->second))
946 {
947 thresholds |=
948 static_cast<uint8_t>(IPMISensorReadingByte3::lowerCritical);
949 }
950 }
951 }
952
953 // no discrete as of today so optional byte is never returned
954 return ipmi::responseSuccess(value, operation, thresholds, std::nullopt);
955}
956
957/** @brief implements the Set Sensor threshold command
958 * @param sensorNumber - sensor number
959 * @param lowerNonCriticalThreshMask
960 * @param lowerCriticalThreshMask
961 * @param lowerNonRecovThreshMask
962 * @param upperNonCriticalThreshMask
963 * @param upperCriticalThreshMask
964 * @param upperNonRecovThreshMask
965 * @param reserved
966 * @param lowerNonCritical - lower non-critical threshold
967 * @param lowerCritical - Lower critical threshold
968 * @param lowerNonRecoverable - Lower non recovarable threshold
969 * @param upperNonCritical - Upper non-critical threshold
970 * @param upperCritical - Upper critical
971 * @param upperNonRecoverable - Upper Non-recoverable
972 *
973 * @returns IPMI completion code
974 */
975ipmi::RspType<> ipmiSenSetSensorThresholds(
976 ipmi::Context::ptr ctx, uint8_t sensorNum, bool lowerNonCriticalThreshMask,
977 bool lowerCriticalThreshMask, bool lowerNonRecovThreshMask,
978 bool upperNonCriticalThreshMask, bool upperCriticalThreshMask,
979 bool upperNonRecovThreshMask, uint2_t reserved, uint8_t lowerNonCritical,
Willy Tu11d68892022-01-20 10:37:34 -0800980 uint8_t lowerCritical, [[maybe_unused]] uint8_t lowerNonRecoverable,
Willy Tude54f482021-01-26 15:59:09 -0800981 uint8_t upperNonCritical, uint8_t upperCritical,
Willy Tu11d68892022-01-20 10:37:34 -0800982 [[maybe_unused]] uint8_t upperNonRecoverable)
Willy Tude54f482021-01-26 15:59:09 -0800983{
Chalapathi Venkataramashetty8c2f3c42021-06-13 19:51:17 +0000984 if (sensorNum == reservedSensorNumber || reserved)
Willy Tude54f482021-01-26 15:59:09 -0800985 {
986 return ipmi::responseInvalidFieldRequest();
987 }
988
989 // lower nc and upper nc not suppported on any sensor
990 if (lowerNonRecovThreshMask || upperNonRecovThreshMask)
991 {
992 return ipmi::responseInvalidFieldRequest();
993 }
994
995 // if none of the threshold mask are set, nothing to do
996 if (!(lowerNonCriticalThreshMask | lowerCriticalThreshMask |
997 lowerNonRecovThreshMask | upperNonCriticalThreshMask |
998 upperCriticalThreshMask | upperNonRecovThreshMask))
999 {
1000 return ipmi::responseSuccess();
1001 }
1002
1003 std::string connection;
1004 std::string path;
1005
1006 ipmi::Cc status = getSensorConnection(ctx, sensorNum, connection, path);
1007 if (status)
1008 {
1009 return ipmi::response(status);
1010 }
1011 DbusInterfaceMap sensorMap;
1012 if (!getSensorMap(ctx, connection, path, sensorMap))
1013 {
1014 return ipmi::responseResponseError();
1015 }
1016
1017 double max = 0;
1018 double min = 0;
1019 getSensorMaxMin(sensorMap, max, min);
1020
1021 int16_t mValue = 0;
1022 int16_t bValue = 0;
1023 int8_t rExp = 0;
1024 int8_t bExp = 0;
1025 bool bSigned = false;
1026
1027 if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned))
1028 {
1029 return ipmi::responseResponseError();
1030 }
1031
1032 // store a vector of property name, value to set, and interface
1033 std::vector<std::tuple<std::string, uint8_t, std::string>> thresholdsToSet;
1034
1035 // define the indexes of the tuple
1036 constexpr uint8_t propertyName = 0;
1037 constexpr uint8_t thresholdValue = 1;
1038 constexpr uint8_t interface = 2;
1039 // verifiy all needed fields are present
1040 if (lowerCriticalThreshMask || upperCriticalThreshMask)
1041 {
1042 auto findThreshold =
1043 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical");
1044 if (findThreshold == sensorMap.end())
1045 {
1046 return ipmi::responseInvalidFieldRequest();
1047 }
1048 if (lowerCriticalThreshMask)
1049 {
1050 auto findLower = findThreshold->second.find("CriticalLow");
1051 if (findLower == findThreshold->second.end())
1052 {
1053 return ipmi::responseInvalidFieldRequest();
1054 }
1055 thresholdsToSet.emplace_back("CriticalLow", lowerCritical,
1056 findThreshold->first);
1057 }
1058 if (upperCriticalThreshMask)
1059 {
1060 auto findUpper = findThreshold->second.find("CriticalHigh");
1061 if (findUpper == findThreshold->second.end())
1062 {
1063 return ipmi::responseInvalidFieldRequest();
1064 }
1065 thresholdsToSet.emplace_back("CriticalHigh", upperCritical,
1066 findThreshold->first);
1067 }
1068 }
1069 if (lowerNonCriticalThreshMask || upperNonCriticalThreshMask)
1070 {
1071 auto findThreshold =
1072 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning");
1073 if (findThreshold == sensorMap.end())
1074 {
1075 return ipmi::responseInvalidFieldRequest();
1076 }
1077 if (lowerNonCriticalThreshMask)
1078 {
1079 auto findLower = findThreshold->second.find("WarningLow");
1080 if (findLower == findThreshold->second.end())
1081 {
1082 return ipmi::responseInvalidFieldRequest();
1083 }
1084 thresholdsToSet.emplace_back("WarningLow", lowerNonCritical,
1085 findThreshold->first);
1086 }
1087 if (upperNonCriticalThreshMask)
1088 {
1089 auto findUpper = findThreshold->second.find("WarningHigh");
1090 if (findUpper == findThreshold->second.end())
1091 {
1092 return ipmi::responseInvalidFieldRequest();
1093 }
1094 thresholdsToSet.emplace_back("WarningHigh", upperNonCritical,
1095 findThreshold->first);
1096 }
1097 }
1098 for (const auto& property : thresholdsToSet)
1099 {
1100 // from section 36.3 in the IPMI Spec, assume all linear
1101 double valueToSet = ((mValue * std::get<thresholdValue>(property)) +
1102 (bValue * std::pow(10.0, bExp))) *
1103 std::pow(10.0, rExp);
1104 setDbusProperty(
1105 *getSdBus(), connection, path, std::get<interface>(property),
1106 std::get<propertyName>(property), ipmi::Value(valueToSet));
1107 }
1108 return ipmi::responseSuccess();
1109}
1110
1111IPMIThresholds getIPMIThresholds(const DbusInterfaceMap& sensorMap)
1112{
1113 IPMIThresholds resp;
1114 auto warningInterface =
1115 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning");
1116 auto criticalInterface =
1117 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical");
1118
1119 if ((warningInterface != sensorMap.end()) ||
1120 (criticalInterface != sensorMap.end()))
1121 {
Hao Jiangd2afd052020-12-10 15:09:32 -08001122 auto sensorPair = sensorMap.find(sensor::sensorInterface);
Willy Tude54f482021-01-26 15:59:09 -08001123
1124 if (sensorPair == sensorMap.end())
1125 {
1126 // should not have been able to find a sensor not implementing
1127 // the sensor object
1128 throw std::runtime_error("Invalid sensor map");
1129 }
1130
1131 double max = 0;
1132 double min = 0;
1133 getSensorMaxMin(sensorMap, max, min);
1134
1135 int16_t mValue = 0;
1136 int16_t bValue = 0;
1137 int8_t rExp = 0;
1138 int8_t bExp = 0;
1139 bool bSigned = false;
1140
1141 if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned))
1142 {
1143 throw std::runtime_error("Invalid sensor atrributes");
1144 }
1145 if (warningInterface != sensorMap.end())
1146 {
1147 auto& warningMap = warningInterface->second;
1148
1149 auto warningHigh = warningMap.find("WarningHigh");
1150 auto warningLow = warningMap.find("WarningLow");
1151
1152 if (warningHigh != warningMap.end())
1153 {
1154
1155 double value =
1156 std::visit(VariantToDoubleVisitor(), warningHigh->second);
Konstantin Aladyshev8265af22021-12-16 18:18:10 +03001157 if (std::isfinite(value))
1158 {
1159 resp.warningHigh = scaleIPMIValueFromDouble(
1160 value, mValue, rExp, bValue, bExp, bSigned);
1161 }
Willy Tude54f482021-01-26 15:59:09 -08001162 }
1163 if (warningLow != warningMap.end())
1164 {
1165 double value =
1166 std::visit(VariantToDoubleVisitor(), warningLow->second);
Konstantin Aladyshev8265af22021-12-16 18:18:10 +03001167 if (std::isfinite(value))
1168 {
1169 resp.warningLow = scaleIPMIValueFromDouble(
1170 value, mValue, rExp, bValue, bExp, bSigned);
1171 }
Willy Tude54f482021-01-26 15:59:09 -08001172 }
1173 }
1174 if (criticalInterface != sensorMap.end())
1175 {
1176 auto& criticalMap = criticalInterface->second;
1177
1178 auto criticalHigh = criticalMap.find("CriticalHigh");
1179 auto criticalLow = criticalMap.find("CriticalLow");
1180
1181 if (criticalHigh != criticalMap.end())
1182 {
1183 double value =
1184 std::visit(VariantToDoubleVisitor(), criticalHigh->second);
Konstantin Aladyshev8265af22021-12-16 18:18:10 +03001185 if (std::isfinite(value))
1186 {
1187 resp.criticalHigh = scaleIPMIValueFromDouble(
1188 value, mValue, rExp, bValue, bExp, bSigned);
1189 }
Willy Tude54f482021-01-26 15:59:09 -08001190 }
1191 if (criticalLow != criticalMap.end())
1192 {
1193 double value =
1194 std::visit(VariantToDoubleVisitor(), criticalLow->second);
Konstantin Aladyshev8265af22021-12-16 18:18:10 +03001195 if (std::isfinite(value))
1196 {
1197 resp.criticalLow = scaleIPMIValueFromDouble(
1198 value, mValue, rExp, bValue, bExp, bSigned);
1199 }
Willy Tude54f482021-01-26 15:59:09 -08001200 }
1201 }
1202 }
1203 return resp;
1204}
1205
1206ipmi::RspType<uint8_t, // readable
1207 uint8_t, // lowerNCrit
1208 uint8_t, // lowerCrit
1209 uint8_t, // lowerNrecoverable
1210 uint8_t, // upperNC
1211 uint8_t, // upperCrit
1212 uint8_t> // upperNRecoverable
1213 ipmiSenGetSensorThresholds(ipmi::Context::ptr ctx, uint8_t sensorNumber)
1214{
1215 std::string connection;
1216 std::string path;
1217
Chalapathi Venkataramashetty8c2f3c42021-06-13 19:51:17 +00001218 if (sensorNumber == reservedSensorNumber)
1219 {
1220 return ipmi::responseInvalidFieldRequest();
1221 }
1222
Willy Tude54f482021-01-26 15:59:09 -08001223 auto status = getSensorConnection(ctx, sensorNumber, connection, path);
1224 if (status)
1225 {
1226 return ipmi::response(status);
1227 }
1228
1229 DbusInterfaceMap sensorMap;
1230 if (!getSensorMap(ctx, connection, path, sensorMap))
1231 {
1232 return ipmi::responseResponseError();
1233 }
1234
1235 IPMIThresholds thresholdData;
1236 try
1237 {
1238 thresholdData = getIPMIThresholds(sensorMap);
1239 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001240 catch (const std::exception&)
Willy Tude54f482021-01-26 15:59:09 -08001241 {
1242 return ipmi::responseResponseError();
1243 }
1244
1245 uint8_t readable = 0;
1246 uint8_t lowerNC = 0;
1247 uint8_t lowerCritical = 0;
1248 uint8_t lowerNonRecoverable = 0;
1249 uint8_t upperNC = 0;
1250 uint8_t upperCritical = 0;
1251 uint8_t upperNonRecoverable = 0;
1252
1253 if (thresholdData.warningHigh)
1254 {
1255 readable |=
1256 1 << static_cast<uint8_t>(IPMIThresholdRespBits::upperNonCritical);
1257 upperNC = *thresholdData.warningHigh;
1258 }
1259 if (thresholdData.warningLow)
1260 {
1261 readable |=
1262 1 << static_cast<uint8_t>(IPMIThresholdRespBits::lowerNonCritical);
1263 lowerNC = *thresholdData.warningLow;
1264 }
1265
1266 if (thresholdData.criticalHigh)
1267 {
1268 readable |=
1269 1 << static_cast<uint8_t>(IPMIThresholdRespBits::upperCritical);
1270 upperCritical = *thresholdData.criticalHigh;
1271 }
1272 if (thresholdData.criticalLow)
1273 {
1274 readable |=
1275 1 << static_cast<uint8_t>(IPMIThresholdRespBits::lowerCritical);
1276 lowerCritical = *thresholdData.criticalLow;
1277 }
1278
1279 return ipmi::responseSuccess(readable, lowerNC, lowerCritical,
1280 lowerNonRecoverable, upperNC, upperCritical,
1281 upperNonRecoverable);
1282}
1283
1284/** @brief implements the get Sensor event enable command
1285 * @param sensorNumber - sensor number
1286 *
1287 * @returns IPMI completion code plus response data
1288 * - enabled - Sensor Event messages
1289 * - assertionEnabledLsb - Assertion event messages
1290 * - assertionEnabledMsb - Assertion event messages
1291 * - deassertionEnabledLsb - Deassertion event messages
1292 * - deassertionEnabledMsb - Deassertion event messages
1293 */
1294
1295ipmi::RspType<uint8_t, // enabled
1296 uint8_t, // assertionEnabledLsb
1297 uint8_t, // assertionEnabledMsb
1298 uint8_t, // deassertionEnabledLsb
1299 uint8_t> // deassertionEnabledMsb
1300 ipmiSenGetSensorEventEnable(ipmi::Context::ptr ctx, uint8_t sensorNum)
1301{
1302 std::string connection;
1303 std::string path;
1304
1305 uint8_t enabled = 0;
1306 uint8_t assertionEnabledLsb = 0;
1307 uint8_t assertionEnabledMsb = 0;
1308 uint8_t deassertionEnabledLsb = 0;
1309 uint8_t deassertionEnabledMsb = 0;
1310
Chalapathi Venkataramashetty8c2f3c42021-06-13 19:51:17 +00001311 if (sensorNum == reservedSensorNumber)
1312 {
1313 return ipmi::responseInvalidFieldRequest();
1314 }
1315
Willy Tude54f482021-01-26 15:59:09 -08001316 auto status = getSensorConnection(ctx, sensorNum, connection, path);
1317 if (status)
1318 {
1319 return ipmi::response(status);
1320 }
1321
Scron Chang2703b022021-07-06 15:47:45 +08001322#ifdef FEATURE_HYBRID_SENSORS
1323 if (auto sensor = findStaticSensor(path);
1324 sensor != ipmi::sensor::sensors.end() &&
1325 getSensorEventTypeFromPath(path) !=
1326 static_cast<uint8_t>(SensorEventTypeCodes::threshold))
1327 {
1328 enabled = static_cast<uint8_t>(
1329 IPMISensorEventEnableByte2::sensorScanningEnable);
1330 uint16_t assertionEnabled = 0;
1331 for (auto& offsetValMap : sensor->second.propertyInterfaces.begin()
1332 ->second.begin()
1333 ->second.second)
1334 {
1335 assertionEnabled |= (1 << offsetValMap.first);
1336 }
1337 assertionEnabledLsb = static_cast<uint8_t>((assertionEnabled & 0xFF));
1338 assertionEnabledMsb =
1339 static_cast<uint8_t>(((assertionEnabled >> 8) & 0xFF));
1340
1341 return ipmi::responseSuccess(enabled, assertionEnabledLsb,
1342 assertionEnabledMsb, deassertionEnabledLsb,
1343 deassertionEnabledMsb);
1344 }
1345#endif
1346
Willy Tude54f482021-01-26 15:59:09 -08001347 DbusInterfaceMap sensorMap;
1348 if (!getSensorMap(ctx, connection, path, sensorMap))
1349 {
1350 return ipmi::responseResponseError();
1351 }
1352
1353 auto warningInterface =
1354 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning");
1355 auto criticalInterface =
1356 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical");
1357 if ((warningInterface != sensorMap.end()) ||
1358 (criticalInterface != sensorMap.end()))
1359 {
1360 enabled = static_cast<uint8_t>(
1361 IPMISensorEventEnableByte2::sensorScanningEnable);
1362 if (warningInterface != sensorMap.end())
1363 {
1364 auto& warningMap = warningInterface->second;
1365
1366 auto warningHigh = warningMap.find("WarningHigh");
1367 auto warningLow = warningMap.find("WarningLow");
1368 if (warningHigh != warningMap.end())
1369 {
1370 assertionEnabledLsb |= static_cast<uint8_t>(
1371 IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh);
1372 deassertionEnabledLsb |= static_cast<uint8_t>(
1373 IPMISensorEventEnableThresholds::upperNonCriticalGoingLow);
1374 }
1375 if (warningLow != warningMap.end())
1376 {
1377 assertionEnabledLsb |= static_cast<uint8_t>(
1378 IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow);
1379 deassertionEnabledLsb |= static_cast<uint8_t>(
1380 IPMISensorEventEnableThresholds::lowerNonCriticalGoingHigh);
1381 }
1382 }
1383 if (criticalInterface != sensorMap.end())
1384 {
1385 auto& criticalMap = criticalInterface->second;
1386
1387 auto criticalHigh = criticalMap.find("CriticalHigh");
1388 auto criticalLow = criticalMap.find("CriticalLow");
1389
1390 if (criticalHigh != criticalMap.end())
1391 {
1392 assertionEnabledMsb |= static_cast<uint8_t>(
1393 IPMISensorEventEnableThresholds::upperCriticalGoingHigh);
1394 deassertionEnabledMsb |= static_cast<uint8_t>(
1395 IPMISensorEventEnableThresholds::upperCriticalGoingLow);
1396 }
1397 if (criticalLow != criticalMap.end())
1398 {
1399 assertionEnabledLsb |= static_cast<uint8_t>(
1400 IPMISensorEventEnableThresholds::lowerCriticalGoingLow);
1401 deassertionEnabledLsb |= static_cast<uint8_t>(
1402 IPMISensorEventEnableThresholds::lowerCriticalGoingHigh);
1403 }
1404 }
1405 }
1406
1407 return ipmi::responseSuccess(enabled, assertionEnabledLsb,
1408 assertionEnabledMsb, deassertionEnabledLsb,
1409 deassertionEnabledMsb);
1410}
1411
1412/** @brief implements the get Sensor event status command
1413 * @param sensorNumber - sensor number, FFh = reserved
1414 *
1415 * @returns IPMI completion code plus response data
1416 * - sensorEventStatus - Sensor Event messages state
1417 * - assertions - Assertion event messages
1418 * - deassertions - Deassertion event messages
1419 */
1420ipmi::RspType<uint8_t, // sensorEventStatus
1421 std::bitset<16>, // assertions
1422 std::bitset<16> // deassertion
1423 >
1424 ipmiSenGetSensorEventStatus(ipmi::Context::ptr ctx, uint8_t sensorNum)
1425{
1426 if (sensorNum == reservedSensorNumber)
1427 {
1428 return ipmi::responseInvalidFieldRequest();
1429 }
1430
1431 std::string connection;
1432 std::string path;
1433 auto status = getSensorConnection(ctx, sensorNum, connection, path);
1434 if (status)
1435 {
1436 phosphor::logging::log<phosphor::logging::level::ERR>(
1437 "ipmiSenGetSensorEventStatus: Sensor connection Error",
1438 phosphor::logging::entry("SENSOR=%d", sensorNum));
1439 return ipmi::response(status);
1440 }
1441
Scron Chang2703b022021-07-06 15:47:45 +08001442#ifdef FEATURE_HYBRID_SENSORS
1443 if (auto sensor = findStaticSensor(path);
1444 sensor != ipmi::sensor::sensors.end() &&
1445 getSensorEventTypeFromPath(path) !=
1446 static_cast<uint8_t>(SensorEventTypeCodes::threshold))
1447 {
1448 auto response = ipmi::sensor::get::mapDbusToAssertion(
1449 sensor->second, path, sensor->second.sensorInterface);
1450 std::bitset<16> assertions;
1451 // deassertions are not used.
1452 std::bitset<16> deassertions = 0;
1453 uint8_t sensorEventStatus;
1454 if (response.readingOrStateUnavailable)
1455 {
1456 sensorEventStatus |= static_cast<uint8_t>(
1457 IPMISensorReadingByte2::readingStateUnavailable);
1458 }
1459 if (response.scanningEnabled)
1460 {
1461 sensorEventStatus |= static_cast<uint8_t>(
1462 IPMISensorReadingByte2::sensorScanningEnable);
1463 }
1464 if (response.allEventMessagesEnabled)
1465 {
1466 sensorEventStatus |= static_cast<uint8_t>(
1467 IPMISensorReadingByte2::eventMessagesEnable);
1468 }
1469 assertions |= response.discreteReadingSensorStates << 8;
1470 assertions |= response.thresholdLevelsStates;
1471 return ipmi::responseSuccess(sensorEventStatus, assertions,
1472 deassertions);
1473 }
1474#endif
1475
Willy Tude54f482021-01-26 15:59:09 -08001476 DbusInterfaceMap sensorMap;
1477 if (!getSensorMap(ctx, connection, path, sensorMap))
1478 {
1479 phosphor::logging::log<phosphor::logging::level::ERR>(
1480 "ipmiSenGetSensorEventStatus: Sensor Mapping Error",
1481 phosphor::logging::entry("SENSOR=%s", path.c_str()));
1482 return ipmi::responseResponseError();
1483 }
Hao Jiangd48c9212021-02-03 15:45:06 -08001484
1485 uint8_t sensorEventStatus =
1486 static_cast<uint8_t>(IPMISensorEventEnableByte2::sensorScanningEnable);
1487 std::bitset<16> assertions = 0;
1488 std::bitset<16> deassertions = 0;
1489
1490 // handle VR typed sensor
1491 auto vrInterface = sensorMap.find(sensor::vrInterface);
1492 if (vrInterface != sensorMap.end())
1493 {
1494 if (!sensor::getVrEventStatus(ctx, connection, path,
1495 vrInterface->second, assertions))
1496 {
1497 return ipmi::responseResponseError();
1498 }
1499
1500 // both Event Message and Sensor Scanning are disable for VR.
1501 sensorEventStatus = 0;
1502 return ipmi::responseSuccess(sensorEventStatus, assertions,
1503 deassertions);
1504 }
1505
Willy Tude54f482021-01-26 15:59:09 -08001506 auto warningInterface =
1507 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning");
1508 auto criticalInterface =
1509 sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical");
1510
Willy Tude54f482021-01-26 15:59:09 -08001511 std::optional<bool> criticalDeassertHigh =
1512 thresholdDeassertMap[path]["CriticalAlarmHigh"];
1513 std::optional<bool> criticalDeassertLow =
1514 thresholdDeassertMap[path]["CriticalAlarmLow"];
1515 std::optional<bool> warningDeassertHigh =
1516 thresholdDeassertMap[path]["WarningAlarmHigh"];
1517 std::optional<bool> warningDeassertLow =
1518 thresholdDeassertMap[path]["WarningAlarmLow"];
1519
Willy Tude54f482021-01-26 15:59:09 -08001520 if (criticalDeassertHigh && !*criticalDeassertHigh)
1521 {
1522 deassertions.set(static_cast<size_t>(
1523 IPMIGetSensorEventEnableThresholds::upperCriticalGoingHigh));
1524 }
1525 if (criticalDeassertLow && !*criticalDeassertLow)
1526 {
1527 deassertions.set(static_cast<size_t>(
1528 IPMIGetSensorEventEnableThresholds::upperCriticalGoingLow));
1529 }
1530 if (warningDeassertHigh && !*warningDeassertHigh)
1531 {
1532 deassertions.set(static_cast<size_t>(
1533 IPMIGetSensorEventEnableThresholds::upperNonCriticalGoingHigh));
1534 }
1535 if (warningDeassertLow && !*warningDeassertLow)
1536 {
1537 deassertions.set(static_cast<size_t>(
1538 IPMIGetSensorEventEnableThresholds::lowerNonCriticalGoingHigh));
1539 }
1540 if ((warningInterface != sensorMap.end()) ||
1541 (criticalInterface != sensorMap.end()))
1542 {
1543 sensorEventStatus = static_cast<size_t>(
1544 IPMISensorEventEnableByte2::eventMessagesEnable);
1545 if (warningInterface != sensorMap.end())
1546 {
1547 auto& warningMap = warningInterface->second;
1548
1549 auto warningHigh = warningMap.find("WarningAlarmHigh");
1550 auto warningLow = warningMap.find("WarningAlarmLow");
1551 auto warningHighAlarm = false;
1552 auto warningLowAlarm = false;
1553
1554 if (warningHigh != warningMap.end())
1555 {
1556 warningHighAlarm = std::get<bool>(warningHigh->second);
1557 }
1558 if (warningLow != warningMap.end())
1559 {
1560 warningLowAlarm = std::get<bool>(warningLow->second);
1561 }
1562 if (warningHighAlarm)
1563 {
1564 assertions.set(
1565 static_cast<size_t>(IPMIGetSensorEventEnableThresholds::
1566 upperNonCriticalGoingHigh));
1567 }
1568 if (warningLowAlarm)
1569 {
1570 assertions.set(
1571 static_cast<size_t>(IPMIGetSensorEventEnableThresholds::
1572 lowerNonCriticalGoingLow));
1573 }
1574 }
1575 if (criticalInterface != sensorMap.end())
1576 {
1577 auto& criticalMap = criticalInterface->second;
1578
1579 auto criticalHigh = criticalMap.find("CriticalAlarmHigh");
1580 auto criticalLow = criticalMap.find("CriticalAlarmLow");
1581 auto criticalHighAlarm = false;
1582 auto criticalLowAlarm = false;
1583
1584 if (criticalHigh != criticalMap.end())
1585 {
1586 criticalHighAlarm = std::get<bool>(criticalHigh->second);
1587 }
1588 if (criticalLow != criticalMap.end())
1589 {
1590 criticalLowAlarm = std::get<bool>(criticalLow->second);
1591 }
1592 if (criticalHighAlarm)
1593 {
1594 assertions.set(
1595 static_cast<size_t>(IPMIGetSensorEventEnableThresholds::
1596 upperCriticalGoingHigh));
1597 }
1598 if (criticalLowAlarm)
1599 {
1600 assertions.set(static_cast<size_t>(
1601 IPMIGetSensorEventEnableThresholds::lowerCriticalGoingLow));
1602 }
1603 }
1604 }
1605
1606 return ipmi::responseSuccess(sensorEventStatus, assertions, deassertions);
1607}
1608
Willy Tu38e7a2b2021-03-29 15:09:56 -07001609// Construct a type 1 SDR for threshold sensor.
Hao Jiange39d4d82021-04-16 17:02:40 -07001610void constructSensorSdrHeaderKey(uint16_t sensorNum, uint16_t recordID,
1611 get_sdr::SensorDataFullRecord& record)
Willy Tude54f482021-01-26 15:59:09 -08001612{
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001613 get_sdr::header::set_record_id(
1614 recordID, reinterpret_cast<get_sdr::SensorDataRecordHeader*>(&record));
1615
Willy Tu38e7a2b2021-03-29 15:09:56 -07001616 uint8_t sensornumber = static_cast<uint8_t>(sensorNum);
1617 uint8_t lun = static_cast<uint8_t>(sensorNum >> 8);
1618
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001619 record.header.sdr_version = ipmiSdrVersion;
1620 record.header.record_type = get_sdr::SENSOR_DATA_FULL_RECORD;
1621 record.header.record_length = sizeof(get_sdr::SensorDataFullRecord) -
1622 sizeof(get_sdr::SensorDataRecordHeader);
Willy Tu38e7a2b2021-03-29 15:09:56 -07001623 record.key.owner_id = bmcI2CAddr;
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001624 record.key.owner_lun = lun;
1625 record.key.sensor_number = sensornumber;
Hao Jiange39d4d82021-04-16 17:02:40 -07001626}
Willy Tu4eca2512022-06-20 21:14:51 -07001627bool constructSensorSdr(
1628 ipmi::Context::ptr ctx,
1629 const std::unordered_set<std::string>& ipmiDecoratorPaths,
1630 uint16_t sensorNum, uint16_t recordID, const std::string& service,
1631 const std::string& path, get_sdr::SensorDataFullRecord& record)
Hao Jiange39d4d82021-04-16 17:02:40 -07001632{
Hao Jiange39d4d82021-04-16 17:02:40 -07001633 constructSensorSdrHeaderKey(sensorNum, recordID, record);
1634
1635 DbusInterfaceMap sensorMap;
1636 if (!getSensorMap(ctx, service, path, sensorMap, sensorMapSdrUpdatePeriod))
1637 {
1638 phosphor::logging::log<phosphor::logging::level::ERR>(
1639 "Failed to update sensor map for threshold sensor",
1640 phosphor::logging::entry("SERVICE=%s", service.c_str()),
1641 phosphor::logging::entry("PATH=%s", path.c_str()));
1642 return false;
1643 }
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001644
1645 record.body.sensor_capabilities = 0x68; // auto rearm - todo hysteresis
1646 record.body.sensor_type = getSensorTypeFromPath(path);
1647 std::string type = getSensorTypeStringFromPath(path);
1648 auto typeCstr = type.c_str();
1649 auto findUnits = sensorUnits.find(typeCstr);
1650 if (findUnits != sensorUnits.end())
1651 {
1652 record.body.sensor_units_2_base =
1653 static_cast<uint8_t>(findUnits->second);
1654 } // else default 0x0 unspecified
1655
1656 record.body.event_reading_type = getSensorEventTypeFromPath(path);
1657
Hao Jiangd2afd052020-12-10 15:09:32 -08001658 auto sensorObject = sensorMap.find(sensor::sensorInterface);
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001659 if (sensorObject == sensorMap.end())
1660 {
1661 phosphor::logging::log<phosphor::logging::level::ERR>(
1662 "getSensorDataRecord: sensorObject error");
Willy Tu38e7a2b2021-03-29 15:09:56 -07001663 return false;
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001664 }
1665
1666 uint8_t entityId = 0;
1667 uint8_t entityInstance = 0x01;
1668
1669 // follow the association chain to get the parent board's entityid and
1670 // entityInstance
Willy Tu4eca2512022-06-20 21:14:51 -07001671 updateIpmiFromAssociation(path, ipmiDecoratorPaths, sensorMap, entityId,
1672 entityInstance);
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001673
1674 record.body.entity_id = entityId;
1675 record.body.entity_instance = entityInstance;
1676
Shakeeb Pasha93889722021-10-14 10:20:13 +05301677 double max = 0;
1678 double min = 0;
1679 getSensorMaxMin(sensorMap, max, min);
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001680
1681 int16_t mValue = 0;
1682 int8_t rExp = 0;
1683 int16_t bValue = 0;
1684 int8_t bExp = 0;
1685 bool bSigned = false;
1686
1687 if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned))
1688 {
1689 phosphor::logging::log<phosphor::logging::level::ERR>(
1690 "getSensorDataRecord: getSensorAttributes error");
Willy Tu38e7a2b2021-03-29 15:09:56 -07001691 return false;
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001692 }
1693
1694 // The record.body is a struct SensorDataFullRecordBody
1695 // from sensorhandler.hpp in phosphor-ipmi-host.
1696 // The meaning of these bits appears to come from
1697 // table 43.1 of the IPMI spec.
1698 // The above 5 sensor attributes are stuffed in as follows:
1699 // Byte 21 = AA000000 = analog interpretation, 10 signed, 00 unsigned
1700 // Byte 22-24 are for other purposes
1701 // Byte 25 = MMMMMMMM = LSB of M
1702 // Byte 26 = MMTTTTTT = MSB of M (signed), and Tolerance
1703 // Byte 27 = BBBBBBBB = LSB of B
1704 // Byte 28 = BBAAAAAA = MSB of B (signed), and LSB of Accuracy
1705 // Byte 29 = AAAAEE00 = MSB of Accuracy, exponent of Accuracy
1706 // Byte 30 = RRRRBBBB = rExp (signed), bExp (signed)
1707
1708 // apply M, B, and exponents, M and B are 10 bit values, exponents are 4
1709 record.body.m_lsb = mValue & 0xFF;
1710
1711 uint8_t mBitSign = (mValue < 0) ? 1 : 0;
1712 uint8_t mBitNine = (mValue & 0x0100) >> 8;
1713
1714 // move the smallest bit of the MSB into place (bit 9)
1715 // the MSbs are bits 7:8 in m_msb_and_tolerance
1716 record.body.m_msb_and_tolerance = (mBitSign << 7) | (mBitNine << 6);
1717
1718 record.body.b_lsb = bValue & 0xFF;
1719
1720 uint8_t bBitSign = (bValue < 0) ? 1 : 0;
1721 uint8_t bBitNine = (bValue & 0x0100) >> 8;
1722
1723 // move the smallest bit of the MSB into place (bit 9)
1724 // the MSbs are bits 7:8 in b_msb_and_accuracy_lsb
1725 record.body.b_msb_and_accuracy_lsb = (bBitSign << 7) | (bBitNine << 6);
1726
1727 uint8_t rExpSign = (rExp < 0) ? 1 : 0;
1728 uint8_t rExpBits = rExp & 0x07;
1729
1730 uint8_t bExpSign = (bExp < 0) ? 1 : 0;
1731 uint8_t bExpBits = bExp & 0x07;
1732
1733 // move rExp and bExp into place
1734 record.body.r_b_exponents =
1735 (rExpSign << 7) | (rExpBits << 4) | (bExpSign << 3) | bExpBits;
1736
1737 // Set the analog reading byte interpretation accordingly
1738 record.body.sensor_units_1 = (bSigned ? 1 : 0) << 7;
1739
1740 // TODO(): Perhaps care about Tolerance, Accuracy, and so on
1741 // These seem redundant, but derivable from the above 5 attributes
1742 // Original comment said "todo fill out rest of units"
1743
1744 // populate sensor name from path
Willy Tu38e7a2b2021-03-29 15:09:56 -07001745 auto name = sensor::parseSdrIdFromPath(path);
Paul Fertser51136982022-08-18 12:36:41 +00001746 get_sdr::body::set_id_strlen(name.size(), &record.body);
1747 get_sdr::body::set_id_type(3, &record.body); // "8-bit ASCII + Latin 1"
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001748 std::strncpy(record.body.id_string, name.c_str(),
1749 sizeof(record.body.id_string));
1750
Josh Lehana55c9532020-10-28 21:59:06 -07001751 // Remember the sensor name, as determined for this sensor number
Harvey.Wu0e7a8af2022-06-10 16:46:46 +08001752 details::sdrStatsTable.updateName(sensorNum, name);
Josh Lehana55c9532020-10-28 21:59:06 -07001753
Jie Yangf0a89942021-07-29 15:30:25 -07001754 bool sensorSettable = false;
1755 auto mutability =
1756 sensorMap.find("xyz.openbmc_project.Sensor.ValueMutability");
1757 if (mutability != sensorMap.end())
1758 {
1759 sensorSettable =
1760 mappedVariant<bool>(mutability->second, "Mutable", false);
1761 }
1762 get_sdr::body::init_settable_state(sensorSettable, &record.body);
1763
1764 // Grant write permission to sensors deemed externally settable
Harvey.Wu0e7a8af2022-06-10 16:46:46 +08001765 details::sdrWriteTable.setWritePermission(sensorNum, sensorSettable);
Willy Tu530e2772021-07-02 14:42:06 -07001766
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001767 IPMIThresholds thresholdData;
1768 try
1769 {
1770 thresholdData = getIPMIThresholds(sensorMap);
1771 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001772 catch (const std::exception&)
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001773 {
1774 phosphor::logging::log<phosphor::logging::level::ERR>(
1775 "getSensorDataRecord: getIPMIThresholds error");
Willy Tu38e7a2b2021-03-29 15:09:56 -07001776 return false;
Kuiying Wanga8b5b262021-02-06 23:38:22 +08001777 }
1778
1779 if (thresholdData.criticalHigh)
1780 {
1781 record.body.upper_critical_threshold = *thresholdData.criticalHigh;
1782 record.body.supported_deassertions[1] |= static_cast<uint8_t>(
1783 IPMISensorEventEnableThresholds::criticalThreshold);
1784 record.body.supported_deassertions[1] |= static_cast<uint8_t>(
1785 IPMISensorEventEnableThresholds::upperCriticalGoingHigh);
1786 record.body.supported_assertions[1] |= static_cast<uint8_t>(
1787 IPMISensorEventEnableThresholds::upperCriticalGoingHigh);
1788 record.body.discrete_reading_setting_mask[0] |=
1789 static_cast<uint8_t>(IPMISensorReadingByte3::upperCritical);
1790 }
1791 if (thresholdData.warningHigh)
1792 {
1793 record.body.upper_noncritical_threshold = *thresholdData.warningHigh;
1794 record.body.supported_deassertions[1] |= static_cast<uint8_t>(
1795 IPMISensorEventEnableThresholds::nonCriticalThreshold);
1796 record.body.supported_deassertions[0] |= static_cast<uint8_t>(
1797 IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh);
1798 record.body.supported_assertions[0] |= static_cast<uint8_t>(
1799 IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh);
1800 record.body.discrete_reading_setting_mask[0] |=
1801 static_cast<uint8_t>(IPMISensorReadingByte3::upperNonCritical);
1802 }
1803 if (thresholdData.criticalLow)
1804 {
1805 record.body.lower_critical_threshold = *thresholdData.criticalLow;
1806 record.body.supported_assertions[1] |= static_cast<uint8_t>(
1807 IPMISensorEventEnableThresholds::criticalThreshold);
1808 record.body.supported_deassertions[0] |= static_cast<uint8_t>(
1809 IPMISensorEventEnableThresholds::lowerCriticalGoingLow);
1810 record.body.supported_assertions[0] |= static_cast<uint8_t>(
1811 IPMISensorEventEnableThresholds::lowerCriticalGoingLow);
1812 record.body.discrete_reading_setting_mask[0] |=
1813 static_cast<uint8_t>(IPMISensorReadingByte3::lowerCritical);
1814 }
1815 if (thresholdData.warningLow)
1816 {
1817 record.body.lower_noncritical_threshold = *thresholdData.warningLow;
1818 record.body.supported_assertions[1] |= static_cast<uint8_t>(
1819 IPMISensorEventEnableThresholds::nonCriticalThreshold);
1820 record.body.supported_deassertions[0] |= static_cast<uint8_t>(
1821 IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow);
1822 record.body.supported_assertions[0] |= static_cast<uint8_t>(
1823 IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow);
1824 record.body.discrete_reading_setting_mask[0] |=
1825 static_cast<uint8_t>(IPMISensorReadingByte3::lowerNonCritical);
1826 }
1827
1828 // everything that is readable is setable
1829 record.body.discrete_reading_setting_mask[1] =
1830 record.body.discrete_reading_setting_mask[0];
Willy Tu38e7a2b2021-03-29 15:09:56 -07001831 return true;
1832}
1833
Scron Chang2703b022021-07-06 15:47:45 +08001834#ifdef FEATURE_HYBRID_SENSORS
1835// Construct a type 1 SDR for discrete Sensor typed sensor.
Willy Tu11d68892022-01-20 10:37:34 -08001836void constructStaticSensorSdr(ipmi::Context::ptr, uint16_t sensorNum,
Scron Chang2703b022021-07-06 15:47:45 +08001837 uint16_t recordID,
1838 ipmi::sensor::IdInfoMap::const_iterator sensor,
1839 get_sdr::SensorDataFullRecord& record)
1840{
1841 constructSensorSdrHeaderKey(sensorNum, recordID, record);
1842
1843 record.body.entity_id = sensor->second.entityType;
1844 record.body.sensor_type = sensor->second.sensorType;
1845 record.body.event_reading_type = sensor->second.sensorReadingType;
1846 record.body.entity_instance = sensor->second.instance;
1847 if (ipmi::sensor::Mutability::Write ==
1848 (sensor->second.mutability & ipmi::sensor::Mutability::Write))
1849 {
1850 get_sdr::body::init_settable_state(true, &(record.body));
1851 }
1852
1853 auto id_string = sensor->second.sensorName;
1854
1855 if (id_string.empty())
1856 {
1857 id_string = sensor->second.sensorNameFunc(sensor->second);
1858 }
1859
1860 if (id_string.length() > FULL_RECORD_ID_STR_MAX_LENGTH)
1861 {
1862 get_sdr::body::set_id_strlen(FULL_RECORD_ID_STR_MAX_LENGTH,
1863 &(record.body));
1864 }
1865 else
1866 {
1867 get_sdr::body::set_id_strlen(id_string.length(), &(record.body));
1868 }
Paul Fertser51136982022-08-18 12:36:41 +00001869 get_sdr::body::set_id_type(3, &record.body); // "8-bit ASCII + Latin 1"
Scron Chang2703b022021-07-06 15:47:45 +08001870 std::strncpy(record.body.id_string, id_string.c_str(),
1871 get_sdr::body::get_id_strlen(&(record.body)));
1872}
1873#endif
1874
Hao Jiange39d4d82021-04-16 17:02:40 -07001875// Construct type 3 SDR header and key (for VR and other discrete sensors)
1876void constructEventSdrHeaderKey(uint16_t sensorNum, uint16_t recordID,
1877 get_sdr::SensorDataEventRecord& record)
Willy Tu61992ad2021-03-29 15:33:20 -07001878{
1879 uint8_t sensornumber = static_cast<uint8_t>(sensorNum);
1880 uint8_t lun = static_cast<uint8_t>(sensorNum >> 8);
1881
1882 get_sdr::header::set_record_id(
1883 recordID, reinterpret_cast<get_sdr::SensorDataRecordHeader*>(&record));
1884
1885 record.header.sdr_version = ipmiSdrVersion;
1886 record.header.record_type = get_sdr::SENSOR_DATA_EVENT_RECORD;
1887 record.header.record_length = sizeof(get_sdr::SensorDataEventRecord) -
1888 sizeof(get_sdr::SensorDataRecordHeader);
1889 record.key.owner_id = bmcI2CAddr;
1890 record.key.owner_lun = lun;
1891 record.key.sensor_number = sensornumber;
1892
1893 record.body.entity_id = 0x00;
1894 record.body.entity_instance = 0x01;
Hao Jiange39d4d82021-04-16 17:02:40 -07001895}
Willy Tu61992ad2021-03-29 15:33:20 -07001896
Hao Jiange39d4d82021-04-16 17:02:40 -07001897// Construct a type 3 SDR for VR typed sensor(daemon).
Willy Tu4eca2512022-06-20 21:14:51 -07001898bool constructVrSdr(ipmi::Context::ptr ctx,
1899 const std::unordered_set<std::string>& ipmiDecoratorPaths,
1900 uint16_t sensorNum, uint16_t recordID,
1901 const std::string& service, const std::string& path,
Hao Jiange39d4d82021-04-16 17:02:40 -07001902 get_sdr::SensorDataEventRecord& record)
1903{
Hao Jiange39d4d82021-04-16 17:02:40 -07001904 constructEventSdrHeaderKey(sensorNum, recordID, record);
1905
1906 DbusInterfaceMap sensorMap;
1907 if (!getSensorMap(ctx, service, path, sensorMap, sensorMapSdrUpdatePeriod))
1908 {
1909 phosphor::logging::log<phosphor::logging::level::ERR>(
1910 "Failed to update sensor map for VR sensor",
1911 phosphor::logging::entry("SERVICE=%s", service.c_str()),
1912 phosphor::logging::entry("PATH=%s", path.c_str()));
1913 return false;
1914 }
Willy Tu61992ad2021-03-29 15:33:20 -07001915 // follow the association chain to get the parent board's entityid and
1916 // entityInstance
Willy Tu4eca2512022-06-20 21:14:51 -07001917 updateIpmiFromAssociation(path, ipmiDecoratorPaths, sensorMap,
1918 record.body.entity_id,
Willy Tu61992ad2021-03-29 15:33:20 -07001919 record.body.entity_instance);
1920
1921 // Sensor type is hardcoded as a module/board type instead of parsing from
1922 // sensor path. This is because VR control is allocated in an independent
1923 // path(/xyz/openbmc_project/vr/profile/...) which is not categorized by
1924 // types.
1925 static constexpr const uint8_t module_board_type = 0x15;
1926 record.body.sensor_type = module_board_type;
1927 record.body.event_reading_type = 0x00;
1928
1929 record.body.sensor_record_sharing_1 = 0x00;
1930 record.body.sensor_record_sharing_2 = 0x00;
1931
1932 // populate sensor name from path
1933 auto name = sensor::parseSdrIdFromPath(path);
1934 int nameSize = std::min(name.size(), sizeof(record.body.id_string));
Paul Fertser51136982022-08-18 12:36:41 +00001935 get_sdr::body::set_id_strlen(nameSize, &record.body);
1936 get_sdr::body::set_id_type(3, &record.body); // "8-bit ASCII + Latin 1"
Willy Tu61992ad2021-03-29 15:33:20 -07001937 std::memset(record.body.id_string, 0x00, sizeof(record.body.id_string));
1938 std::memcpy(record.body.id_string, name.c_str(), nameSize);
1939
1940 // Remember the sensor name, as determined for this sensor number
Harvey.Wu0e7a8af2022-06-10 16:46:46 +08001941 details::sdrStatsTable.updateName(sensorNum, name);
Hao Jiange39d4d82021-04-16 17:02:40 -07001942
1943 return true;
Willy Tu61992ad2021-03-29 15:33:20 -07001944}
1945
Johnathan Mantey6619ae42021-08-06 11:21:10 -07001946static inline uint16_t getNumberOfSensors()
1947{
1948 return std::min(getSensorTree().size(), maxIPMISensors);
1949}
1950
Willy Tu4eca2512022-06-20 21:14:51 -07001951static int getSensorDataRecord(
1952 ipmi::Context::ptr ctx,
1953 const std::unordered_set<std::string>& ipmiDecoratorPaths,
1954 std::vector<uint8_t>& recordData, uint16_t recordID,
1955 uint8_t readBytes = std::numeric_limits<uint8_t>::max())
Willy Tu38e7a2b2021-03-29 15:09:56 -07001956{
1957 size_t fruCount = 0;
1958 ipmi::Cc ret = ipmi::storage::getFruSdrCount(ctx, fruCount);
1959 if (ret != ipmi::ccSuccess)
1960 {
1961 phosphor::logging::log<phosphor::logging::level::ERR>(
1962 "getSensorDataRecord: getFruSdrCount error");
1963 return GENERAL_ERROR;
1964 }
1965
Harvey Wu05d17c02021-09-15 08:46:59 +08001966 const auto& entityRecords =
1967 ipmi::sensor::EntityInfoMapContainer::getContainer()
1968 ->getIpmiEntityRecords();
1969 size_t entityCount = entityRecords.size();
1970
1971 size_t lastRecord = getNumberOfSensors() + fruCount +
1972 ipmi::storage::type12Count + entityCount - 1;
Willy Tu38e7a2b2021-03-29 15:09:56 -07001973 if (recordID == lastRecordIndex)
1974 {
1975 recordID = lastRecord;
1976 }
1977 if (recordID > lastRecord)
1978 {
1979 phosphor::logging::log<phosphor::logging::level::ERR>(
1980 "getSensorDataRecord: recordID > lastRecord error");
1981 return GENERAL_ERROR;
1982 }
1983
Johnathan Mantey6619ae42021-08-06 11:21:10 -07001984 if (recordID >= getNumberOfSensors())
Willy Tu38e7a2b2021-03-29 15:09:56 -07001985 {
Harvey Wu05d17c02021-09-15 08:46:59 +08001986 size_t sdrIndex = recordID - getNumberOfSensors();
Willy Tu38e7a2b2021-03-29 15:09:56 -07001987
Harvey Wu05d17c02021-09-15 08:46:59 +08001988 if (sdrIndex >= fruCount + ipmi::storage::type12Count)
1989 {
1990 // handle type 8 entity map records
1991 ipmi::sensor::EntityInfoMap::const_iterator entity =
1992 entityRecords.find(static_cast<uint8_t>(
1993 sdrIndex - fruCount - ipmi::storage::type12Count));
1994 if (entity == entityRecords.end())
1995 {
1996 return IPMI_CC_SENSOR_INVALID;
1997 }
1998 recordData = ipmi::storage::getType8SDRs(entity, recordID);
1999 }
2000 else if (sdrIndex >= fruCount)
Willy Tu38e7a2b2021-03-29 15:09:56 -07002001 {
2002 // handle type 12 hardcoded records
Harvey Wu05d17c02021-09-15 08:46:59 +08002003 size_t type12Index = sdrIndex - fruCount;
Willy Tu38e7a2b2021-03-29 15:09:56 -07002004 if (type12Index >= ipmi::storage::type12Count)
2005 {
2006 phosphor::logging::log<phosphor::logging::level::ERR>(
2007 "getSensorDataRecord: type12Index error");
2008 return GENERAL_ERROR;
2009 }
2010 recordData = ipmi::storage::getType12SDRs(type12Index, recordID);
2011 }
2012 else
2013 {
2014 // handle fru records
2015 get_sdr::SensorDataFruRecord data;
Harvey Wu05d17c02021-09-15 08:46:59 +08002016 ret = ipmi::storage::getFruSdrs(ctx, sdrIndex, data);
Willy Tu38e7a2b2021-03-29 15:09:56 -07002017 if (ret != IPMI_CC_OK)
2018 {
2019 return GENERAL_ERROR;
2020 }
2021 data.header.record_id_msb = recordID >> 8;
2022 data.header.record_id_lsb = recordID & 0xFF;
2023 recordData.insert(recordData.end(), (uint8_t*)&data,
2024 ((uint8_t*)&data) + sizeof(data));
2025 }
2026
2027 return 0;
2028 }
2029
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002030 // Perform a incremental scan of the SDR Record ID's and translate the
2031 // first 765 SDR records (i.e. maxIPMISensors) into IPMI Sensor
2032 // Numbers. The IPMI sensor numbers are not linear, and have a reserved
2033 // gap at 0xff. This code creates 254 sensors per LUN, excepting LUN 2
2034 // which has special meaning.
Willy Tu38e7a2b2021-03-29 15:09:56 -07002035 std::string connection;
2036 std::string path;
Hao Jiange39d4d82021-04-16 17:02:40 -07002037 std::vector<std::string> interfaces;
Johnathan Manteyce982772021-07-28 15:08:30 -07002038 uint16_t sensNumFromRecID{recordID};
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002039 if ((recordID > lun0MaxSensorNum) && (recordID < lun1MaxSensorNum))
Johnathan Manteyce982772021-07-28 15:08:30 -07002040 {
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002041 // LUN 0 has one reserved sensor number. Compensate here by adding one
2042 // to the record ID
2043 sensNumFromRecID = recordID + 1;
Johnathan Manteyce982772021-07-28 15:08:30 -07002044 ctx->lun = 1;
2045 }
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002046 else if ((recordID >= lun1MaxSensorNum) && (recordID < maxIPMISensors))
Johnathan Manteyce982772021-07-28 15:08:30 -07002047 {
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002048 // LUN 0, 1 have a reserved sensor number. Compensate here by adding 2
2049 // to the record ID. Skip all 256 sensors in LUN 2, as it has special
2050 // rules governing its use.
2051 sensNumFromRecID = recordID + (maxSensorsPerLUN + 1) + 2;
Johnathan Manteyce982772021-07-28 15:08:30 -07002052 ctx->lun = 3;
2053 }
Hao Jiange39d4d82021-04-16 17:02:40 -07002054
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002055 auto status =
2056 getSensorConnection(ctx, static_cast<uint8_t>(sensNumFromRecID),
2057 connection, path, &interfaces);
Willy Tu38e7a2b2021-03-29 15:09:56 -07002058 if (status)
2059 {
2060 phosphor::logging::log<phosphor::logging::level::ERR>(
2061 "getSensorDataRecord: getSensorConnection error");
2062 return GENERAL_ERROR;
2063 }
Willy Tu38e7a2b2021-03-29 15:09:56 -07002064 uint16_t sensorNum = getSensorNumberFromPath(path);
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002065 // Return an error on LUN 2 assingments, and any sensor number beyond the
2066 // range of LUN 3
2067 if (((sensorNum > lun1MaxSensorNum) && (sensorNum <= maxIPMISensors)) ||
2068 (sensorNum > lun3MaxSensorNum))
Willy Tu38e7a2b2021-03-29 15:09:56 -07002069 {
2070 phosphor::logging::log<phosphor::logging::level::ERR>(
2071 "getSensorDataRecord: invalidSensorNumber");
2072 return GENERAL_ERROR;
2073 }
Johnathan Manteyce982772021-07-28 15:08:30 -07002074 uint8_t sensornumber = static_cast<uint8_t>(sensorNum);
2075 uint8_t lun = static_cast<uint8_t>(sensorNum >> 8);
2076
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002077 if ((sensornumber != static_cast<uint8_t>(sensNumFromRecID)) &&
2078 (lun != ctx->lun))
Johnathan Manteyce982772021-07-28 15:08:30 -07002079 {
2080 phosphor::logging::log<phosphor::logging::level::ERR>(
2081 "getSensorDataRecord: sensor record mismatch");
2082 return GENERAL_ERROR;
2083 }
Willy Tu38e7a2b2021-03-29 15:09:56 -07002084
Willy Tu38e7a2b2021-03-29 15:09:56 -07002085 // Construct full record (SDR type 1) for the threshold sensors
Hao Jiange39d4d82021-04-16 17:02:40 -07002086 if (std::find(interfaces.begin(), interfaces.end(),
2087 sensor::sensorInterface) != interfaces.end())
Willy Tu38e7a2b2021-03-29 15:09:56 -07002088 {
Willy Tu11d68892022-01-20 10:37:34 -08002089 get_sdr::SensorDataFullRecord record = {};
Willy Tu38e7a2b2021-03-29 15:09:56 -07002090
Hao Jiange39d4d82021-04-16 17:02:40 -07002091 // If the request doesn't read SDR body, construct only header and key
2092 // part to avoid additional DBus transaction.
2093 if (readBytes <= sizeof(record.header) + sizeof(record.key))
2094 {
2095 constructSensorSdrHeaderKey(sensorNum, recordID, record);
2096 }
Willy Tu4eca2512022-06-20 21:14:51 -07002097 else if (!constructSensorSdr(ctx, ipmiDecoratorPaths, sensorNum,
2098 recordID, connection, path, record))
Willy Tu38e7a2b2021-03-29 15:09:56 -07002099 {
2100 return GENERAL_ERROR;
2101 }
Hao Jiange39d4d82021-04-16 17:02:40 -07002102
Willy Tu38e7a2b2021-03-29 15:09:56 -07002103 recordData.insert(recordData.end(), (uint8_t*)&record,
2104 ((uint8_t*)&record) + sizeof(record));
Willy Tu61992ad2021-03-29 15:33:20 -07002105
2106 return 0;
Willy Tu38e7a2b2021-03-29 15:09:56 -07002107 }
Willy Tu61992ad2021-03-29 15:33:20 -07002108
Scron Chang2703b022021-07-06 15:47:45 +08002109#ifdef FEATURE_HYBRID_SENSORS
2110 if (auto sensor = findStaticSensor(path);
2111 sensor != ipmi::sensor::sensors.end() &&
2112 getSensorEventTypeFromPath(path) !=
2113 static_cast<uint8_t>(SensorEventTypeCodes::threshold))
2114 {
Willy Tu11d68892022-01-20 10:37:34 -08002115 get_sdr::SensorDataFullRecord record = {};
Scron Chang2703b022021-07-06 15:47:45 +08002116
2117 // If the request doesn't read SDR body, construct only header and key
2118 // part to avoid additional DBus transaction.
2119 if (readBytes <= sizeof(record.header) + sizeof(record.key))
2120 {
2121 constructSensorSdrHeaderKey(sensorNum, recordID, record);
2122 }
2123 else
2124 {
2125 constructStaticSensorSdr(ctx, sensorNum, recordID, sensor, record);
2126 }
2127
2128 recordData.insert(recordData.end(), (uint8_t*)&record,
2129 ((uint8_t*)&record) + sizeof(record));
2130
2131 return 0;
2132 }
2133#endif
2134
Willy Tu61992ad2021-03-29 15:33:20 -07002135 // Contruct SDR type 3 record for VR sensor (daemon)
Hao Jiange39d4d82021-04-16 17:02:40 -07002136 if (std::find(interfaces.begin(), interfaces.end(), sensor::vrInterface) !=
2137 interfaces.end())
Willy Tu61992ad2021-03-29 15:33:20 -07002138 {
Willy Tu11d68892022-01-20 10:37:34 -08002139 get_sdr::SensorDataEventRecord record = {};
Willy Tu61992ad2021-03-29 15:33:20 -07002140
Hao Jiange39d4d82021-04-16 17:02:40 -07002141 // If the request doesn't read SDR body, construct only header and key
2142 // part to avoid additional DBus transaction.
2143 if (readBytes <= sizeof(record.header) + sizeof(record.key))
2144 {
2145 constructEventSdrHeaderKey(sensorNum, recordID, record);
2146 }
Willy Tu4eca2512022-06-20 21:14:51 -07002147 else if (!constructVrSdr(ctx, ipmiDecoratorPaths, sensorNum, recordID,
2148 connection, path, record))
Hao Jiange39d4d82021-04-16 17:02:40 -07002149 {
2150 return GENERAL_ERROR;
2151 }
Willy Tu61992ad2021-03-29 15:33:20 -07002152 recordData.insert(recordData.end(), (uint8_t*)&record,
2153 ((uint8_t*)&record) + sizeof(record));
2154 }
2155
Willy Tude54f482021-01-26 15:59:09 -08002156 return 0;
2157}
2158
2159/** @brief implements the get SDR Info command
2160 * @param count - Operation
2161 *
2162 * @returns IPMI completion code plus response data
2163 * - sdrCount - sensor/SDR count
2164 * - lunsAndDynamicPopulation - static/Dynamic sensor population flag
2165 */
2166static ipmi::RspType<uint8_t, // respcount
2167 uint8_t, // dynamic population flags
2168 uint32_t // last time a sensor was added
2169 >
2170 ipmiSensorGetDeviceSdrInfo(ipmi::Context::ptr ctx,
2171 std::optional<uint8_t> count)
2172{
2173 auto& sensorTree = getSensorTree();
2174 uint8_t sdrCount = 0;
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002175 uint16_t recordID = 0;
2176 std::vector<uint8_t> record;
Willy Tude54f482021-01-26 15:59:09 -08002177 // Sensors are dynamically allocated, and there is at least one LUN
2178 uint8_t lunsAndDynamicPopulation = 0x80;
2179 constexpr uint8_t getSdrCount = 0x01;
2180 constexpr uint8_t getSensorCount = 0x00;
2181
2182 if (!getSensorSubtree(sensorTree) || sensorTree.empty())
2183 {
2184 return ipmi::responseResponseError();
2185 }
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002186 uint16_t numSensors = getNumberOfSensors();
Willy Tude54f482021-01-26 15:59:09 -08002187 if (count.value_or(0) == getSdrCount)
2188 {
Willy Tu4eca2512022-06-20 21:14:51 -07002189 auto& ipmiDecoratorPaths = getIpmiDecoratorPaths(ctx);
2190
Willy Tude54f482021-01-26 15:59:09 -08002191 // Count the number of Type 1 SDR entries assigned to the LUN
Willy Tu4eca2512022-06-20 21:14:51 -07002192 while (!getSensorDataRecord(
2193 ctx, ipmiDecoratorPaths.value_or(std::unordered_set<std::string>()),
2194 record, recordID++))
Willy Tude54f482021-01-26 15:59:09 -08002195 {
2196 get_sdr::SensorDataRecordHeader* hdr =
2197 reinterpret_cast<get_sdr::SensorDataRecordHeader*>(
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002198 record.data());
Willy Tude54f482021-01-26 15:59:09 -08002199 if (hdr && hdr->record_type == get_sdr::SENSOR_DATA_FULL_RECORD)
2200 {
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002201 get_sdr::SensorDataFullRecord* recordData =
Willy Tude54f482021-01-26 15:59:09 -08002202 reinterpret_cast<get_sdr::SensorDataFullRecord*>(
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002203 record.data());
2204 if (ctx->lun == recordData->key.owner_lun)
Willy Tude54f482021-01-26 15:59:09 -08002205 {
2206 sdrCount++;
2207 }
2208 }
2209 }
2210 }
2211 else if (count.value_or(0) == getSensorCount)
2212 {
2213 // Return the number of sensors attached to the LUN
2214 if ((ctx->lun == 0) && (numSensors > 0))
2215 {
2216 sdrCount =
2217 (numSensors > maxSensorsPerLUN) ? maxSensorsPerLUN : numSensors;
2218 }
2219 else if ((ctx->lun == 1) && (numSensors > maxSensorsPerLUN))
2220 {
2221 sdrCount = (numSensors > (2 * maxSensorsPerLUN))
2222 ? maxSensorsPerLUN
2223 : (numSensors - maxSensorsPerLUN) & maxSensorsPerLUN;
2224 }
2225 else if (ctx->lun == 3)
2226 {
2227 if (numSensors <= maxIPMISensors)
2228 {
2229 sdrCount =
2230 (numSensors - (2 * maxSensorsPerLUN)) & maxSensorsPerLUN;
2231 }
2232 else
2233 {
2234 // error
2235 throw std::out_of_range(
2236 "Maximum number of IPMI sensors exceeded.");
2237 }
2238 }
2239 }
2240 else
2241 {
2242 return ipmi::responseInvalidFieldRequest();
2243 }
2244
2245 // Get Sensor count. This returns the number of sensors
2246 if (numSensors > 0)
2247 {
2248 lunsAndDynamicPopulation |= 1;
2249 }
2250 if (numSensors > maxSensorsPerLUN)
2251 {
2252 lunsAndDynamicPopulation |= 2;
2253 }
2254 if (numSensors >= (maxSensorsPerLUN * 2))
2255 {
2256 lunsAndDynamicPopulation |= 8;
2257 }
2258 if (numSensors > maxIPMISensors)
2259 {
2260 // error
2261 throw std::out_of_range("Maximum number of IPMI sensors exceeded.");
2262 }
2263
2264 return ipmi::responseSuccess(sdrCount, lunsAndDynamicPopulation,
2265 sdrLastAdd);
2266}
2267
2268/* end sensor commands */
2269
2270/* storage commands */
2271
2272ipmi::RspType<uint8_t, // sdr version
2273 uint16_t, // record count
2274 uint16_t, // free space
2275 uint32_t, // most recent addition
2276 uint32_t, // most recent erase
2277 uint8_t // operationSupport
2278 >
2279 ipmiStorageGetSDRRepositoryInfo(ipmi::Context::ptr ctx)
2280{
2281 auto& sensorTree = getSensorTree();
2282 constexpr const uint16_t unspecifiedFreeSpace = 0xFFFF;
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002283 if (!getSensorSubtree(sensorTree) && sensorTree.empty())
Willy Tude54f482021-01-26 15:59:09 -08002284 {
2285 return ipmi::responseResponseError();
2286 }
2287
2288 size_t fruCount = 0;
2289 ipmi::Cc ret = ipmi::storage::getFruSdrCount(ctx, fruCount);
2290 if (ret != ipmi::ccSuccess)
2291 {
2292 return ipmi::response(ret);
2293 }
2294
2295 uint16_t recordCount =
Johnathan Mantey6619ae42021-08-06 11:21:10 -07002296 getNumberOfSensors() + fruCount + ipmi::storage::type12Count;
Willy Tude54f482021-01-26 15:59:09 -08002297
2298 uint8_t operationSupport = static_cast<uint8_t>(
2299 SdrRepositoryInfoOps::overflow); // write not supported
2300
2301 operationSupport |=
2302 static_cast<uint8_t>(SdrRepositoryInfoOps::allocCommandSupported);
2303 operationSupport |= static_cast<uint8_t>(
2304 SdrRepositoryInfoOps::reserveSDRRepositoryCommandSupported);
2305 return ipmi::responseSuccess(ipmiSdrVersion, recordCount,
2306 unspecifiedFreeSpace, sdrLastAdd,
2307 sdrLastRemove, operationSupport);
2308}
2309
2310/** @brief implements the get SDR allocation info command
2311 *
2312 * @returns IPMI completion code plus response data
2313 * - allocUnits - Number of possible allocation units
2314 * - allocUnitSize - Allocation unit size in bytes.
2315 * - allocUnitFree - Number of free allocation units
2316 * - allocUnitLargestFree - Largest free block in allocation units
2317 * - maxRecordSize - Maximum record size in allocation units.
2318 */
2319ipmi::RspType<uint16_t, // allocUnits
2320 uint16_t, // allocUnitSize
2321 uint16_t, // allocUnitFree
2322 uint16_t, // allocUnitLargestFree
2323 uint8_t // maxRecordSize
2324 >
2325 ipmiStorageGetSDRAllocationInfo()
2326{
2327 // 0000h unspecified number of alloc units
2328 constexpr uint16_t allocUnits = 0;
2329
2330 constexpr uint16_t allocUnitFree = 0;
2331 constexpr uint16_t allocUnitLargestFree = 0;
2332 // only allow one block at a time
2333 constexpr uint8_t maxRecordSize = 1;
2334
2335 return ipmi::responseSuccess(allocUnits, maxSDRTotalSize, allocUnitFree,
2336 allocUnitLargestFree, maxRecordSize);
2337}
2338
2339/** @brief implements the reserve SDR command
2340 * @returns IPMI completion code plus response data
2341 * - sdrReservationID
2342 */
2343ipmi::RspType<uint16_t> ipmiStorageReserveSDR()
2344{
2345 sdrReservationID++;
2346 if (sdrReservationID == 0)
2347 {
2348 sdrReservationID++;
2349 }
2350
2351 return ipmi::responseSuccess(sdrReservationID);
2352}
2353
2354ipmi::RspType<uint16_t, // next record ID
2355 std::vector<uint8_t> // payload
2356 >
2357 ipmiStorageGetSDR(ipmi::Context::ptr ctx, uint16_t reservationID,
2358 uint16_t recordID, uint8_t offset, uint8_t bytesToRead)
2359{
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002360 size_t fruCount = 0;
Willy Tude54f482021-01-26 15:59:09 -08002361 // reservation required for partial reads with non zero offset into
2362 // record
2363 if ((sdrReservationID == 0 || reservationID != sdrReservationID) && offset)
2364 {
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002365 phosphor::logging::log<phosphor::logging::level::ERR>(
2366 "ipmiStorageGetSDR: responseInvalidReservationId");
Willy Tude54f482021-01-26 15:59:09 -08002367 return ipmi::responseInvalidReservationId();
2368 }
Willy Tude54f482021-01-26 15:59:09 -08002369 ipmi::Cc ret = ipmi::storage::getFruSdrCount(ctx, fruCount);
2370 if (ret != ipmi::ccSuccess)
2371 {
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002372 phosphor::logging::log<phosphor::logging::level::ERR>(
2373 "ipmiStorageGetSDR: getFruSdrCount error");
Willy Tude54f482021-01-26 15:59:09 -08002374 return ipmi::response(ret);
2375 }
2376
Harvey Wu05d17c02021-09-15 08:46:59 +08002377 const auto& entityRecords =
2378 ipmi::sensor::EntityInfoMapContainer::getContainer()
2379 ->getIpmiEntityRecords();
2380 int entityCount = entityRecords.size();
2381
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002382 auto& sensorTree = getSensorTree();
Harvey Wu05d17c02021-09-15 08:46:59 +08002383 size_t lastRecord = getNumberOfSensors() + fruCount +
2384 ipmi::storage::type12Count + entityCount - 1;
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002385 uint16_t nextRecordId = lastRecord > recordID ? recordID + 1 : 0XFFFF;
2386
2387 if (!getSensorSubtree(sensorTree) && sensorTree.empty())
Willy Tude54f482021-01-26 15:59:09 -08002388 {
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002389 phosphor::logging::log<phosphor::logging::level::ERR>(
2390 "ipmiStorageGetSDR: getSensorSubtree error");
2391 return ipmi::responseResponseError();
Willy Tude54f482021-01-26 15:59:09 -08002392 }
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002393
Willy Tu4eca2512022-06-20 21:14:51 -07002394 auto& ipmiDecoratorPaths = getIpmiDecoratorPaths(ctx);
2395
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002396 std::vector<uint8_t> record;
Willy Tu4eca2512022-06-20 21:14:51 -07002397 if (getSensorDataRecord(
2398 ctx, ipmiDecoratorPaths.value_or(std::unordered_set<std::string>()),
2399 record, recordID, offset + bytesToRead))
Willy Tude54f482021-01-26 15:59:09 -08002400 {
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002401 phosphor::logging::log<phosphor::logging::level::ERR>(
2402 "ipmiStorageGetSDR: fail to get SDR");
Willy Tude54f482021-01-26 15:59:09 -08002403 return ipmi::responseInvalidFieldRequest();
2404 }
Willy Tude54f482021-01-26 15:59:09 -08002405 get_sdr::SensorDataRecordHeader* hdr =
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002406 reinterpret_cast<get_sdr::SensorDataRecordHeader*>(record.data());
Willy Tude54f482021-01-26 15:59:09 -08002407 if (!hdr)
2408 {
2409 phosphor::logging::log<phosphor::logging::level::ERR>(
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002410 "ipmiStorageGetSDR: record header is null");
2411 return ipmi::responseSuccess(nextRecordId, record);
Willy Tude54f482021-01-26 15:59:09 -08002412 }
2413
2414 size_t sdrLength =
2415 sizeof(get_sdr::SensorDataRecordHeader) + hdr->record_length;
2416 if (sdrLength < (offset + bytesToRead))
2417 {
2418 bytesToRead = sdrLength - offset;
2419 }
2420
2421 uint8_t* respStart = reinterpret_cast<uint8_t*>(hdr) + offset;
2422 if (!respStart)
2423 {
2424 phosphor::logging::log<phosphor::logging::level::ERR>(
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002425 "ipmiStorageGetSDR: record is null");
2426 return ipmi::responseSuccess(nextRecordId, record);
Willy Tude54f482021-01-26 15:59:09 -08002427 }
2428
2429 std::vector<uint8_t> recordData(respStart, respStart + bytesToRead);
Kuiying Wanga8b5b262021-02-06 23:38:22 +08002430
Willy Tude54f482021-01-26 15:59:09 -08002431 return ipmi::responseSuccess(nextRecordId, recordData);
2432}
adarshgrami042e9db2022-09-15 10:34:34 +05302433namespace dcmi
2434{
2435
2436ipmi::RspType<uint8_t, // No of instances for requested id
2437 uint8_t, // No of record ids in the response
2438 std::vector<uint16_t> // SDR Record ID corresponding to the Entity
2439 // IDs
2440 >
2441 getSensorInfo(ipmi::Context::ptr ctx, uint8_t sensorType, uint8_t entityId,
Willy Tu0679e4b2022-11-11 14:34:33 -08002442 uint8_t entityInstance,
2443 [[maybe_unused]] uint8_t instanceStart)
adarshgrami042e9db2022-09-15 10:34:34 +05302444{
2445 auto match = ipmi::dcmi::validEntityId.find(entityId);
2446 if (match == ipmi::dcmi::validEntityId.end())
2447 {
2448 log<level::ERR>("Unknown Entity ID", entry("ENTITY_ID=%d", entityId));
2449
2450 return ipmi::responseInvalidFieldRequest();
2451 }
2452
2453 if (sensorType != ipmi::dcmi::temperatureSensorType)
2454 {
2455 log<level::ERR>("Invalid sensor type",
2456 entry("SENSOR_TYPE=%d", sensorType));
2457
2458 return ipmi::responseInvalidFieldRequest();
2459 }
2460 auto& sensorTree = getSensorTree();
2461 if (!getSensorSubtree(sensorTree) && sensorTree.empty())
2462 {
2463 return ipmi::responseUnspecifiedError();
2464 }
2465
2466 std::vector<uint16_t> sensorRec{};
2467 uint8_t numInstances = 0;
2468
Willy Tu0679e4b2022-11-11 14:34:33 -08002469 auto& ipmiDecoratorPaths = getIpmiDecoratorPaths(ctx);
adarshgrami042e9db2022-09-15 10:34:34 +05302470 for (const auto& sensor : sensorTree)
2471 {
2472 auto sensorTypeValue = getSensorTypeFromPath(sensor.first);
2473 if (sensorTypeValue != ipmi::dcmi::temperatureSensorType)
2474 {
2475 continue;
2476 }
2477 const auto& connection = sensor.second.begin()->first;
2478
2479 DbusInterfaceMap sensorMap;
2480 if (!getSensorMap(ctx, connection, sensor.first, sensorMap,
2481 sensorMapSdrUpdatePeriod))
2482 {
2483 phosphor::logging::log<phosphor::logging::level::ERR>(
2484 "Failed to update sensor map for threshold sensor",
2485 phosphor::logging::entry("SERVICE=%s", connection.c_str()),
2486 phosphor::logging::entry("PATH=%s", sensor.first.c_str()));
2487 continue;
2488 }
2489 uint8_t entityIdValue = 0;
2490 uint8_t entityInstanceValue = 0;
Willy Tu0679e4b2022-11-11 14:34:33 -08002491 updateIpmiFromAssociation(
2492 sensor.first,
2493 ipmiDecoratorPaths.value_or(std::unordered_set<std::string>()),
2494 sensorMap, entityIdValue, entityInstanceValue);
adarshgrami042e9db2022-09-15 10:34:34 +05302495 if (!entityInstance)
2496 {
2497 if (entityIdValue == match->first || entityIdValue == match->second)
2498 {
2499 auto recordId = getSensorNumberFromPath(sensor.first);
2500 if (recordId != invalidSensorNumber)
2501 {
2502 numInstances++;
2503 if (numInstances <= ipmi::dcmi::maxRecords)
2504 {
2505 sensorRec.push_back(recordId);
2506 }
2507 }
2508 }
2509 }
2510 else
2511 {
2512 if (entityIdValue == match->first || entityIdValue == match->second)
2513 {
2514 if (entityInstance == entityInstanceValue)
2515 {
2516 auto recordId = getSensorNumberFromPath(sensor.first);
2517 if ((recordId != invalidSensorNumber) && sensorRec.empty())
2518 {
2519 sensorRec.push_back(recordId);
2520 }
2521 }
2522 numInstances++;
2523 }
2524 }
2525 }
2526 if (sensorRec.empty())
2527 {
2528 return ipmi::responseSensorInvalid();
2529 }
2530 uint8_t numRecords = sensorRec.size();
2531 return ipmi::responseSuccess(numInstances, numRecords, sensorRec);
2532}
2533} // namespace dcmi
2534
Willy Tude54f482021-01-26 15:59:09 -08002535/* end storage commands */
2536
2537void registerSensorFunctions()
2538{
2539 // <Platform Event>
2540 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2541 ipmi::sensor_event::cmdPlatformEvent,
2542 ipmi::Privilege::Operator, ipmiSenPlatformEvent);
2543
Willy Tudbafbce2021-03-29 00:37:05 -07002544 // <Set Sensor Reading and Event Status>
2545 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2546 ipmi::sensor_event::cmdSetSensorReadingAndEvtSts,
2547 ipmi::Privilege::Operator, ipmiSetSensorReading);
Willy Tudbafbce2021-03-29 00:37:05 -07002548
Willy Tude54f482021-01-26 15:59:09 -08002549 // <Get Sensor Reading>
2550 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2551 ipmi::sensor_event::cmdGetSensorReading,
2552 ipmi::Privilege::User, ipmiSenGetSensorReading);
2553
2554 // <Get Sensor Threshold>
2555 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2556 ipmi::sensor_event::cmdGetSensorThreshold,
2557 ipmi::Privilege::User, ipmiSenGetSensorThresholds);
2558
2559 // <Set Sensor Threshold>
2560 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2561 ipmi::sensor_event::cmdSetSensorThreshold,
2562 ipmi::Privilege::Operator,
2563 ipmiSenSetSensorThresholds);
2564
2565 // <Get Sensor Event Enable>
2566 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2567 ipmi::sensor_event::cmdGetSensorEventEnable,
2568 ipmi::Privilege::User, ipmiSenGetSensorEventEnable);
2569
2570 // <Get Sensor Event Status>
2571 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2572 ipmi::sensor_event::cmdGetSensorEventStatus,
2573 ipmi::Privilege::User, ipmiSenGetSensorEventStatus);
2574
2575 // register all storage commands for both Sensor and Storage command
2576 // versions
2577
2578 // <Get SDR Repository Info>
2579 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
2580 ipmi::storage::cmdGetSdrRepositoryInfo,
2581 ipmi::Privilege::User,
2582 ipmiStorageGetSDRRepositoryInfo);
2583
2584 // <Get Device SDR Info>
2585 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2586 ipmi::sensor_event::cmdGetDeviceSdrInfo,
2587 ipmi::Privilege::User, ipmiSensorGetDeviceSdrInfo);
2588
2589 // <Get SDR Allocation Info>
2590 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
2591 ipmi::storage::cmdGetSdrRepositoryAllocInfo,
2592 ipmi::Privilege::User,
2593 ipmiStorageGetSDRAllocationInfo);
2594
2595 // <Reserve SDR Repo>
2596 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2597 ipmi::sensor_event::cmdReserveDeviceSdrRepository,
2598 ipmi::Privilege::User, ipmiStorageReserveSDR);
2599
2600 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
2601 ipmi::storage::cmdReserveSdrRepository,
2602 ipmi::Privilege::User, ipmiStorageReserveSDR);
2603
2604 // <Get Sdr>
2605 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
2606 ipmi::sensor_event::cmdGetDeviceSdr,
2607 ipmi::Privilege::User, ipmiStorageGetSDR);
2608
2609 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
2610 ipmi::storage::cmdGetSdr, ipmi::Privilege::User,
2611 ipmiStorageGetSDR);
adarshgrami042e9db2022-09-15 10:34:34 +05302612 // <Get DCMI Sensor Info>
2613 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, ipmi::groupDCMI,
2614 ipmi::dcmi::cmdGetDcmiSensorInfo,
2615 ipmi::Privilege::User,
2616 ipmi::dcmi::getSensorInfo);
Willy Tude54f482021-01-26 15:59:09 -08002617}
2618} // namespace ipmi