Patrick Williams | 768730d | 2023-09-06 16:27:20 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 3 | #include "storagehandler.hpp" |
| 4 | |
| 5 | #include "fruread.hpp" |
| 6 | #include "read_fru_data.hpp" |
| 7 | #include "selutility.hpp" |
| 8 | #include "sensorhandler.hpp" |
| 9 | #include "storageaddsel.hpp" |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 10 | |
Lei YU | 52d9124 | 2017-10-17 22:52:28 +0800 | [diff] [blame] | 11 | #include <arpa/inet.h> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 12 | #include <systemd/sd-bus.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 13 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 14 | #include <ipmid/api.hpp> |
Vernon Mauery | 9cf0838 | 2023-04-28 14:00:11 -0700 | [diff] [blame] | 15 | #include <ipmid/entity_map_json.hpp> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 16 | #include <ipmid/utils.hpp> |
| 17 | #include <phosphor-logging/elog-errors.hpp> |
| 18 | #include <phosphor-logging/elog.hpp> |
| 19 | #include <phosphor-logging/log.hpp> |
| 20 | #include <sdbusplus/server.hpp> |
| 21 | #include <xyz/openbmc_project/Common/error.hpp> |
| 22 | #include <xyz/openbmc_project/Logging/SEL/error.hpp> |
| 23 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 24 | #include <algorithm> |
Lei YU | 52d9124 | 2017-10-17 22:52:28 +0800 | [diff] [blame] | 25 | #include <chrono> |
| 26 | #include <cstdio> |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 27 | #include <cstring> |
Vernon Mauery | bdda800 | 2019-02-26 10:18:51 -0800 | [diff] [blame] | 28 | #include <filesystem> |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 29 | #include <optional> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 30 | #include <string> |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 31 | #include <variant> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 32 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 33 | void register_netfn_storage_functions() __attribute__((constructor)); |
| 34 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 35 | unsigned int g_sel_time = 0xFFFFFFFF; |
Patrick Venture | db0cbe6 | 2019-09-09 14:47:22 -0700 | [diff] [blame] | 36 | namespace ipmi |
| 37 | { |
| 38 | namespace sensor |
| 39 | { |
| 40 | extern const IdInfoMap sensors; |
| 41 | } // namespace sensor |
| 42 | } // namespace ipmi |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 43 | extern const ipmi::sensor::InvObjectIDMap invSensors; |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 44 | extern const FruMap frus; |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 45 | constexpr uint8_t eventDataSize = 3; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 46 | namespace |
| 47 | { |
shamim ali | 071d00c | 2022-03-02 15:42:46 +0530 | [diff] [blame] | 48 | constexpr auto SystemdTimeService = "org.freedesktop.timedate1"; |
| 49 | constexpr auto SystemdTimePath = "/org/freedesktop/timedate1"; |
| 50 | constexpr auto SystemdTimeInterface = "org.freedesktop.timedate1"; |
| 51 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 52 | constexpr auto TIME_INTERFACE = "xyz.openbmc_project.Time.EpochTime"; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 53 | constexpr auto BMC_TIME_PATH = "/xyz/openbmc_project/time/bmc"; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 54 | constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 55 | constexpr auto PROPERTY_ELAPSED = "Elapsed"; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 56 | |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 57 | constexpr auto logWatchPath = "/xyz/openbmc_project/logging"; |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 58 | constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry"; |
| 59 | constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry"; |
| 60 | constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 61 | } // namespace |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 62 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 63 | using InternalFailure = |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 64 | sdbusplus::error::xyz::openbmc_project::common::InternalFailure; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 65 | using namespace phosphor::logging; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 66 | using namespace ipmi::fru; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 67 | using namespace xyz::openbmc_project::logging::sel; |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 68 | using SELCreated = |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 69 | sdbusplus::error::xyz::openbmc_project::logging::sel::Created; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 70 | |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 71 | using SELRecordID = uint16_t; |
| 72 | using SELEntry = ipmi::sel::SELEventRecordFormat; |
| 73 | using SELCacheMap = std::map<SELRecordID, SELEntry>; |
| 74 | |
| 75 | SELCacheMap selCacheMap __attribute__((init_priority(101))); |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 76 | bool selCacheMapInitialized; |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 77 | std::unique_ptr<sdbusplus::bus::match_t> selAddedMatch |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 78 | __attribute__((init_priority(101))); |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 79 | std::unique_ptr<sdbusplus::bus::match_t> selRemovedMatch |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 80 | __attribute__((init_priority(101))); |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 81 | std::unique_ptr<sdbusplus::bus::match_t> selUpdatedMatch |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 82 | __attribute__((init_priority(101))); |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 83 | |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 84 | static inline uint16_t getLoggingId(const std::string& p) |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 85 | { |
| 86 | namespace fs = std::filesystem; |
| 87 | fs::path entryPath(p); |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 88 | return std::stoul(entryPath.filename().string()); |
| 89 | } |
| 90 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 91 | static inline std::string getLoggingObjPath(uint16_t id) |
| 92 | { |
| 93 | return std::string(ipmi::sel::logBasePath) + "/" + std::to_string(id); |
| 94 | } |
| 95 | |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 96 | std::optional<std::pair<uint16_t, SELEntry>> |
| 97 | parseLoggingEntry(const std::string& p) |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 98 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 99 | try |
| 100 | { |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 101 | auto id = getLoggingId(p); |
| 102 | ipmi::sel::GetSELEntryResponse record{}; |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 103 | record = ipmi::sel::convertLogEntrytoSEL(p); |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 104 | return std::pair<uint16_t, SELEntry>({id, std::move(record.event)}); |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 105 | } |
| 106 | catch (const std::exception& e) |
| 107 | { |
| 108 | fprintf(stderr, "Failed to convert %s to SEL: %s\n", p.c_str(), |
| 109 | e.what()); |
| 110 | } |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 111 | return std::nullopt; |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 112 | } |
| 113 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 114 | static void selAddedCallback(sdbusplus::message_t& m) |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 115 | { |
| 116 | sdbusplus::message::object_path objPath; |
| 117 | try |
| 118 | { |
| 119 | m.read(objPath); |
| 120 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 121 | catch (const sdbusplus::exception_t& e) |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 122 | { |
| 123 | log<level::ERR>("Failed to read object path"); |
| 124 | return; |
| 125 | } |
| 126 | std::string p = objPath; |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 127 | auto entry = parseLoggingEntry(p); |
| 128 | if (entry) |
| 129 | { |
| 130 | selCacheMap.insert(std::move(*entry)); |
| 131 | } |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 132 | } |
| 133 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 134 | static void selRemovedCallback(sdbusplus::message_t& m) |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 135 | { |
| 136 | sdbusplus::message::object_path objPath; |
| 137 | try |
| 138 | { |
| 139 | m.read(objPath); |
| 140 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 141 | catch (const sdbusplus::exception_t& e) |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 142 | { |
| 143 | log<level::ERR>("Failed to read object path"); |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 144 | } |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 145 | try |
| 146 | { |
| 147 | std::string p = objPath; |
| 148 | selCacheMap.erase(getLoggingId(p)); |
| 149 | } |
| 150 | catch (const std::invalid_argument& e) |
| 151 | { |
| 152 | log<level::ERR>("Invalid logging entry ID"); |
| 153 | } |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 154 | } |
| 155 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 156 | static void selUpdatedCallback(sdbusplus::message_t& m) |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 157 | { |
| 158 | std::string p = m.get_path(); |
| 159 | auto entry = parseLoggingEntry(p); |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 160 | if (entry) |
| 161 | { |
| 162 | selCacheMap.insert_or_assign(entry->first, std::move(entry->second)); |
| 163 | } |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 164 | } |
| 165 | |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 166 | void registerSelCallbackHandler() |
| 167 | { |
| 168 | using namespace sdbusplus::bus::match::rules; |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 169 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 170 | if (!selAddedMatch) |
| 171 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 172 | selAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 173 | bus, interfacesAdded(logWatchPath), |
| 174 | std::bind(selAddedCallback, std::placeholders::_1)); |
| 175 | } |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 176 | if (!selRemovedMatch) |
| 177 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 178 | selRemovedMatch = std::make_unique<sdbusplus::bus::match_t>( |
Lei YU | b6b72b0 | 2021-09-14 21:06:05 +0800 | [diff] [blame] | 179 | bus, interfacesRemoved(logWatchPath), |
| 180 | std::bind(selRemovedCallback, std::placeholders::_1)); |
| 181 | } |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 182 | if (!selUpdatedMatch) |
| 183 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 184 | selUpdatedMatch = std::make_unique<sdbusplus::bus::match_t>( |
Lei YU | 4106e42 | 2021-09-15 10:55:51 +0800 | [diff] [blame] | 185 | bus, |
| 186 | type::signal() + member("PropertiesChanged"s) + |
| 187 | interface("org.freedesktop.DBus.Properties"s) + |
| 188 | argN(0, logEntryIntf), |
| 189 | std::bind(selUpdatedCallback, std::placeholders::_1)); |
| 190 | } |
Lei YU | d955525 | 2021-09-14 20:30:41 +0800 | [diff] [blame] | 191 | } |
| 192 | |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 193 | void initSELCache() |
| 194 | { |
Lei YU | c10cda1 | 2022-01-06 16:01:57 +0800 | [diff] [blame] | 195 | registerSelCallbackHandler(); |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 196 | ipmi::sel::ObjectPaths paths; |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 197 | try |
| 198 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 199 | ipmi::sel::readLoggingObjectPaths(paths); |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 200 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 201 | catch (const sdbusplus::exception_t& e) |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 202 | { |
| 203 | log<level::ERR>("Failed to get logging object paths"); |
| 204 | return; |
| 205 | } |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 206 | for (const auto& p : paths) |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 207 | { |
Lei YU | a0bb2a3 | 2021-09-24 11:03:56 +0800 | [diff] [blame] | 208 | auto entry = parseLoggingEntry(p); |
| 209 | if (entry) |
| 210 | { |
| 211 | selCacheMap.insert(std::move(*entry)); |
| 212 | } |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 213 | } |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 214 | selCacheMapInitialized = true; |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 215 | } |
| 216 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 217 | /** |
| 218 | * @enum Device access mode |
| 219 | */ |
| 220 | enum class AccessMode |
| 221 | { |
| 222 | bytes, ///< Device is accessed by bytes |
| 223 | words ///< Device is accessed by words |
| 224 | }; |
| 225 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 226 | /** @brief implements the get SEL Info command |
| 227 | * @returns IPMI completion code plus response data |
| 228 | * - selVersion - SEL revision |
| 229 | * - entries - Number of log entries in SEL. |
| 230 | * - freeSpace - Free Space in bytes. |
| 231 | * - addTimeStamp - Most recent addition timestamp |
| 232 | * - eraseTimeStamp - Most recent erase timestamp |
| 233 | * - operationSupport - Reserve & Delete SEL operations supported |
| 234 | */ |
| 235 | |
| 236 | ipmi::RspType<uint8_t, // SEL revision. |
| 237 | uint16_t, // number of log entries in SEL. |
| 238 | uint16_t, // free Space in bytes. |
| 239 | uint32_t, // most recent addition timestamp |
| 240 | uint32_t, // most recent erase timestamp. |
| 241 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 242 | bool, // SEL allocation info supported |
| 243 | bool, // reserve SEL supported |
| 244 | bool, // partial Add SEL Entry supported |
| 245 | bool, // delete SEL supported |
| 246 | uint3_t, // reserved |
| 247 | bool // overflow flag |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 248 | > |
| 249 | ipmiStorageGetSelInfo() |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 250 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 251 | uint16_t entries = 0; |
| 252 | // Most recent addition timestamp. |
| 253 | uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 254 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 255 | if (!selCacheMapInitialized) |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 256 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 257 | // In case the initSELCache() fails, try it again |
| 258 | initSELCache(); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 259 | } |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 260 | if (!selCacheMap.empty()) |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 261 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 262 | entries = static_cast<uint16_t>(selCacheMap.size()); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 263 | |
| 264 | try |
| 265 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 266 | auto objPath = getLoggingObjPath(selCacheMap.rbegin()->first); |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 267 | addTimeStamp = static_cast<uint32_t>( |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 268 | (ipmi::sel::getEntryTimeStamp(objPath).count())); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 269 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 270 | catch (const InternalFailure& e) |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 271 | {} |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 272 | catch (const std::runtime_error& e) |
| 273 | { |
| 274 | log<level::ERR>(e.what()); |
| 275 | } |
| 276 | } |
| 277 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 278 | constexpr uint8_t selVersion = ipmi::sel::selVersion; |
| 279 | constexpr uint16_t freeSpace = 0xFFFF; |
| 280 | constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp; |
| 281 | constexpr uint3_t reserved{0}; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 282 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 283 | return ipmi::responseSuccess( |
| 284 | selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp, |
| 285 | ipmi::sel::operationSupport::getSelAllocationInfo, |
| 286 | ipmi::sel::operationSupport::reserveSel, |
| 287 | ipmi::sel::operationSupport::partialAddSelEntry, |
| 288 | ipmi::sel::operationSupport::deleteSel, reserved, |
| 289 | ipmi::sel::operationSupport::overflow); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 290 | } |
| 291 | |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 292 | ipmi_ret_t getSELEntry(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, |
| 293 | ipmi_response_t response, ipmi_data_len_t data_len, |
| 294 | ipmi_context_t) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 295 | { |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 296 | if (*data_len != sizeof(ipmi::sel::GetSELEntryRequest)) |
| 297 | { |
| 298 | *data_len = 0; |
| 299 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 300 | } |
| 301 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 302 | auto requestData = |
| 303 | reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 304 | |
| 305 | if (requestData->reservationID != 0) |
| 306 | { |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 307 | if (!checkSELReservation(requestData->reservationID)) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 308 | { |
| 309 | *data_len = 0; |
| 310 | return IPMI_CC_INVALID_RESERVATION_ID; |
| 311 | } |
| 312 | } |
| 313 | |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 314 | if (!selCacheMapInitialized) |
| 315 | { |
| 316 | // In case the initSELCache() fails, try it again |
| 317 | initSELCache(); |
| 318 | } |
| 319 | |
| 320 | if (selCacheMap.empty()) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 321 | { |
| 322 | *data_len = 0; |
| 323 | return IPMI_CC_SENSOR_INVALID; |
| 324 | } |
| 325 | |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 326 | SELCacheMap::const_iterator iter; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 327 | |
| 328 | // Check for the requested SEL Entry. |
| 329 | if (requestData->selRecordID == ipmi::sel::firstEntry) |
| 330 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 331 | iter = selCacheMap.begin(); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 332 | } |
| 333 | else if (requestData->selRecordID == ipmi::sel::lastEntry) |
| 334 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 335 | if (selCacheMap.size() > 1) |
| 336 | { |
| 337 | iter = selCacheMap.end(); |
| 338 | --iter; |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | // Only one entry exists, return the first |
| 343 | iter = selCacheMap.begin(); |
| 344 | } |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 345 | } |
| 346 | else |
| 347 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 348 | iter = selCacheMap.find(requestData->selRecordID); |
| 349 | if (iter == selCacheMap.end()) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 350 | { |
| 351 | *data_len = 0; |
| 352 | return IPMI_CC_SENSOR_INVALID; |
| 353 | } |
| 354 | } |
| 355 | |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 356 | ipmi::sel::GetSELEntryResponse record{0, iter->second}; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 357 | // Identify the next SEL record ID |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 358 | ++iter; |
| 359 | if (iter == selCacheMap.end()) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 360 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 361 | record.nextRecordID = ipmi::sel::lastEntry; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 362 | } |
| 363 | else |
| 364 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 365 | record.nextRecordID = iter->first; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | if (requestData->readLength == ipmi::sel::entireRecord) |
| 369 | { |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 370 | std::memcpy(response, &record, sizeof(record)); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 371 | *data_len = sizeof(record); |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | if (requestData->offset >= ipmi::sel::selRecordSize || |
| 376 | requestData->readLength > ipmi::sel::selRecordSize) |
| 377 | { |
| 378 | *data_len = 0; |
| 379 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 380 | } |
| 381 | |
| 382 | auto diff = ipmi::sel::selRecordSize - requestData->offset; |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 383 | auto readLength = std::min(diff, |
| 384 | static_cast<int>(requestData->readLength)); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 385 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 386 | std::memcpy(response, &record.nextRecordID, |
| 387 | sizeof(record.nextRecordID)); |
| 388 | std::memcpy(static_cast<uint8_t*>(response) + |
| 389 | sizeof(record.nextRecordID), |
Lei YU | af378fa | 2020-12-02 16:28:57 +0800 | [diff] [blame] | 390 | &record.event.eventRecord.recordID + requestData->offset, |
| 391 | readLength); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 392 | *data_len = sizeof(record.nextRecordID) + readLength; |
| 393 | } |
| 394 | |
| 395 | return IPMI_CC_OK; |
| 396 | } |
| 397 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 398 | /** @brief implements the delete SEL entry command |
| 399 | * @request |
| 400 | * - reservationID; // reservation ID. |
| 401 | * - selRecordID; // SEL record ID. |
| 402 | * |
| 403 | * @returns ipmi completion code plus response data |
| 404 | * - Record ID of the deleted record |
| 405 | */ |
| 406 | ipmi::RspType<uint16_t // deleted record ID |
| 407 | > |
| 408 | deleteSELEntry(uint16_t reservationID, uint16_t selRecordID) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 409 | { |
Brad Bishop | 1a4117b | 2018-11-21 15:48:18 -0500 | [diff] [blame] | 410 | namespace fs = std::filesystem; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 411 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 412 | if (!checkSELReservation(reservationID)) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 413 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 414 | return ipmi::responseInvalidReservationId(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 415 | } |
| 416 | |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 417 | // Per the IPMI spec, need to cancel the reservation when a SEL entry is |
| 418 | // deleted |
| 419 | cancelSELReservation(); |
| 420 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 421 | if (!selCacheMapInitialized) |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 422 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 423 | // In case the initSELCache() fails, try it again |
| 424 | initSELCache(); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 425 | } |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 426 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 427 | if (selCacheMap.empty()) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 428 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 429 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 430 | } |
| 431 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 432 | SELCacheMap::const_iterator iter; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 433 | uint16_t delRecordID = 0; |
| 434 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 435 | if (selRecordID == ipmi::sel::firstEntry) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 436 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 437 | delRecordID = selCacheMap.begin()->first; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 438 | } |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 439 | else if (selRecordID == ipmi::sel::lastEntry) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 440 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 441 | delRecordID = selCacheMap.rbegin()->first; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 442 | } |
| 443 | else |
| 444 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 445 | delRecordID = selRecordID; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 446 | } |
| 447 | |
Jian | 7d5f481 | 2022-02-23 19:30:27 +0800 | [diff] [blame] | 448 | iter = selCacheMap.find(delRecordID); |
| 449 | if (iter == selCacheMap.end()) |
| 450 | { |
| 451 | return ipmi::responseSensorInvalid(); |
| 452 | } |
| 453 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 454 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 455 | std::string service; |
| 456 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 457 | auto objPath = getLoggingObjPath(iter->first); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 458 | try |
| 459 | { |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 460 | service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, objPath); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 461 | } |
| 462 | catch (const std::runtime_error& e) |
| 463 | { |
| 464 | log<level::ERR>(e.what()); |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 465 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 466 | } |
| 467 | |
Lei YU | eba8e9a | 2021-09-15 13:16:17 +0800 | [diff] [blame] | 468 | auto methodCall = bus.new_method_call(service.c_str(), objPath.c_str(), |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 469 | ipmi::sel::logDeleteIntf, "Delete"); |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 470 | try |
| 471 | { |
| 472 | auto reply = bus.call(methodCall); |
| 473 | } |
| 474 | catch (const std::exception& e) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 475 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 476 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 477 | } |
| 478 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 479 | return ipmi::responseSuccess(delRecordID); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 480 | } |
| 481 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 482 | /** @brief implements the Clear SEL command |
| 483 | * @request |
| 484 | * - reservationID // Reservation ID. |
| 485 | * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) } |
| 486 | * - eraseOperation; // requested operation. |
| 487 | * |
| 488 | * @returns ipmi completion code plus response data |
| 489 | * - erase status |
| 490 | */ |
| 491 | |
| 492 | ipmi::RspType<uint8_t // erase status |
| 493 | > |
| 494 | clearSEL(uint16_t reservationID, const std::array<char, 3>& clr, |
| 495 | uint8_t eraseOperation) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 496 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 497 | static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'}; |
| 498 | if (clr != clrOk) |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 499 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 500 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 503 | if (!checkSELReservation(reservationID)) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 504 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 505 | return ipmi::responseInvalidReservationId(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 506 | } |
| 507 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 508 | /* |
| 509 | * Erasure status cannot be fetched from DBUS, so always return erasure |
| 510 | * status as `erase completed`. |
| 511 | */ |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 512 | if (eraseOperation == ipmi::sel::getEraseStatus) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 513 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 514 | return ipmi::responseSuccess( |
| 515 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 516 | } |
| 517 | |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 518 | // Per the IPMI spec, need to cancel any reservation when the SEL is cleared |
| 519 | cancelSELReservation(); |
| 520 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 521 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Lotus Xu | 78fe1b1 | 2021-05-23 17:26:56 +0800 | [diff] [blame] | 522 | auto service = ipmi::getService(bus, ipmi::sel::logIntf, ipmi::sel::logObj); |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 523 | auto method = bus.new_method_call(service.c_str(), ipmi::sel::logObj, |
| 524 | ipmi::sel::logIntf, |
| 525 | ipmi::sel::logDeleteAllMethod); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 526 | try |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 527 | { |
Lotus Xu | 78fe1b1 | 2021-05-23 17:26:56 +0800 | [diff] [blame] | 528 | bus.call_noreply(method); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 529 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 530 | catch (const sdbusplus::exception_t& e) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 531 | { |
Lotus Xu | 78fe1b1 | 2021-05-23 17:26:56 +0800 | [diff] [blame] | 532 | log<level::ERR>("Error eraseAll ", entry("ERROR=%s", e.what())); |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 533 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 534 | } |
| 535 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 536 | return ipmi::responseSuccess( |
| 537 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 538 | } |
| 539 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 540 | /** @brief implements the get SEL time command |
| 541 | * @returns IPMI completion code plus response data |
| 542 | * -current time |
| 543 | */ |
| 544 | ipmi::RspType<uint32_t> // current time |
| 545 | ipmiStorageGetSelTime() |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 546 | { |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 547 | using namespace std::chrono; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 548 | uint64_t bmc_time_usec = 0; |
| 549 | std::stringstream bmcTime; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 550 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 551 | try |
| 552 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 553 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 554 | auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH); |
George Liu | 42f64ef | 2024-02-05 15:03:18 +0800 | [diff] [blame] | 555 | auto propValue = ipmi::getDbusProperty( |
| 556 | bus, service, BMC_TIME_PATH, TIME_INTERFACE, PROPERTY_ELAPSED); |
| 557 | bmc_time_usec = std::get<uint64_t>(propValue); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 558 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 559 | catch (const InternalFailure& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 560 | { |
| 561 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 562 | return ipmi::responseUnspecifiedError(); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 563 | } |
Tom Joseph | 30fd0a1 | 2019-09-24 06:53:22 +0530 | [diff] [blame] | 564 | catch (const std::exception& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 565 | { |
| 566 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 567 | return ipmi::responseUnspecifiedError(); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 568 | } |
| 569 | |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 570 | bmcTime << "BMC time:" |
| 571 | << duration_cast<seconds>(microseconds(bmc_time_usec)).count(); |
| 572 | log<level::DEBUG>(bmcTime.str().c_str()); |
Nagaraju Goruganti | 8960b7c | 2018-04-29 22:38:40 -0500 | [diff] [blame] | 573 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 574 | // Time is really long int but IPMI wants just uint32. This works okay until |
| 575 | // the number of seconds since 1970 overflows uint32 size.. Still a whole |
| 576 | // lot of time here to even think about that. |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 577 | return ipmi::responseSuccess( |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 578 | duration_cast<seconds>(microseconds(bmc_time_usec)).count()); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 579 | } |
| 580 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 581 | /** @brief implements the set SEL time command |
| 582 | * @param selDeviceTime - epoch time |
| 583 | * -local time as the number of seconds from 00:00:00, January 1, 1970 |
| 584 | * @returns IPMI completion code |
| 585 | */ |
| 586 | ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 587 | { |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 588 | using namespace std::chrono; |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 589 | microseconds usec{seconds(selDeviceTime)}; |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 590 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 591 | try |
| 592 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 593 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
shamim ali | 071d00c | 2022-03-02 15:42:46 +0530 | [diff] [blame] | 594 | bool ntp = std::get<bool>( |
| 595 | ipmi::getDbusProperty(bus, SystemdTimeService, SystemdTimePath, |
| 596 | SystemdTimeInterface, "NTP")); |
| 597 | if (ntp) |
| 598 | { |
| 599 | return ipmi::responseCommandNotAvailable(); |
| 600 | } |
| 601 | |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 602 | auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH); |
Andrew Geissler | 6467ed2 | 2020-05-16 16:03:53 -0500 | [diff] [blame] | 603 | std::variant<uint64_t> value{(uint64_t)usec.count()}; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 604 | |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 605 | // Set bmc time |
| 606 | auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 607 | DBUS_PROPERTIES, "Set"); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 608 | |
| 609 | method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value); |
| 610 | auto reply = bus.call(method); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 611 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 612 | catch (const InternalFailure& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 613 | { |
| 614 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 615 | return ipmi::responseUnspecifiedError(); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 616 | } |
Tom Joseph | 30fd0a1 | 2019-09-24 06:53:22 +0530 | [diff] [blame] | 617 | catch (const std::exception& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 618 | { |
| 619 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 620 | return ipmi::responseUnspecifiedError(); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 621 | } |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 622 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 623 | return ipmi::responseSuccess(); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 624 | } |
| 625 | |
Xiaochao Ma | f020c44 | 2022-10-31 11:09:38 +0800 | [diff] [blame] | 626 | /** @brief implements the get SEL timezone command |
| 627 | * @returns IPMI completion code plus response data |
| 628 | * -current timezone |
| 629 | */ |
| 630 | ipmi::RspType<int16_t> ipmiStorageGetSelTimeUtcOffset() |
| 631 | { |
| 632 | time_t timep; |
| 633 | struct tm* gmTime; |
| 634 | struct tm* localTime; |
| 635 | |
| 636 | time(&timep); |
| 637 | localTime = localtime(&timep); |
| 638 | auto validLocalTime = mktime(localTime); |
| 639 | gmTime = gmtime(&timep); |
| 640 | auto validGmTime = mktime(gmTime); |
| 641 | auto timeEquation = (validLocalTime - validGmTime) / 60; |
| 642 | |
| 643 | return ipmi::responseSuccess(timeEquation); |
| 644 | } |
| 645 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 646 | /** @brief implements the reserve SEL command |
| 647 | * @returns IPMI completion code plus response data |
| 648 | * - SEL reservation ID. |
| 649 | */ |
| 650 | ipmi::RspType<uint16_t> ipmiStorageReserveSel() |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 651 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 652 | return ipmi::responseSuccess(reserveSel()); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 653 | } |
| 654 | |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 655 | /** @brief implements the Add SEL entry command |
| 656 | * @request |
| 657 | * |
| 658 | * - recordID ID used for SEL Record access |
| 659 | * - recordType Record Type |
| 660 | * - timeStamp Time when event was logged. LS byte first |
| 661 | * - generatorID software ID if event was generated from |
| 662 | * system software |
| 663 | * - evmRev event message format version |
| 664 | * - sensorType sensor type code for service that generated |
| 665 | * the event |
| 666 | * - sensorNumber number of sensors that generated the event |
| 667 | * - eventDir event dir |
| 668 | * - eventData event data field contents |
| 669 | * |
| 670 | * @returns ipmi completion code plus response data |
| 671 | * - RecordID of the Added SEL entry |
| 672 | */ |
| 673 | ipmi::RspType<uint16_t // recordID of the Added SEL entry |
| 674 | > |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 675 | ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, |
| 676 | [[maybe_unused]] uint32_t timeStamp, uint16_t generatorID, |
| 677 | [[maybe_unused]] uint8_t evmRev, uint8_t sensorType, |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 678 | uint8_t sensorNumber, uint8_t eventDir, |
| 679 | std::array<uint8_t, eventDataSize> eventData) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 680 | { |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 681 | std::string objpath; |
| 682 | static constexpr auto systemRecordType = 0x02; |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 683 | // Hostboot sends SEL with OEM record type 0xDE to indicate that there is |
| 684 | // a maintenance procedure associated with eSEL record. |
| 685 | static constexpr auto procedureType = 0xDE; |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 686 | cancelSELReservation(); |
| 687 | if (recordType == systemRecordType) |
| 688 | { |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 689 | for (const auto& it : invSensors) |
| 690 | { |
| 691 | if (it.second.sensorID == sensorNumber) |
| 692 | { |
| 693 | objpath = it.first; |
| 694 | break; |
| 695 | } |
| 696 | } |
| 697 | auto selDataStr = ipmi::sel::toHexStr(eventData); |
| 698 | |
| 699 | bool assert = (eventDir & 0x80) ? false : true; |
| 700 | |
| 701 | recordID = report<SELCreated>(Created::RECORD_TYPE(recordType), |
| 702 | Created::GENERATOR_ID(generatorID), |
| 703 | Created::SENSOR_DATA(selDataStr.c_str()), |
| 704 | Created::EVENT_DIR(assert), |
| 705 | Created::SENSOR_PATH(objpath.c_str())); |
| 706 | } |
Patrick Williams | 768730d | 2023-09-06 16:27:20 -0500 | [diff] [blame] | 707 | #ifdef OPEN_POWER_SUPPORT |
Lotus Xu | 57d3557 | 2021-01-24 11:13:13 +0800 | [diff] [blame] | 708 | else if (recordType == procedureType) |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 709 | { |
| 710 | // In the OEM record type 0xDE, byte 11 in the SEL record indicate the |
| 711 | // procedure number. |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 712 | createProcedureLogEntry(sensorType); |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 713 | } |
Patrick Williams | 768730d | 2023-09-06 16:27:20 -0500 | [diff] [blame] | 714 | #endif |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 715 | |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 716 | return ipmi::responseSuccess(recordID); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 717 | } |
| 718 | |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 719 | bool isFruPresent(ipmi::Context::ptr& ctx, const std::string& fruPath) |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 720 | { |
| 721 | using namespace ipmi::fru; |
| 722 | |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 723 | std::string service; |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 724 | boost::system::error_code ec = getService(ctx, invItemInterface, |
| 725 | invObjPath + fruPath, service); |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 726 | if (!ec) |
| 727 | { |
| 728 | bool result; |
| 729 | ec = ipmi::getDbusProperty(ctx, service, invObjPath + fruPath, |
| 730 | invItemInterface, itemPresentProp, result); |
| 731 | if (!ec) |
| 732 | { |
| 733 | return result; |
| 734 | } |
| 735 | } |
Konstantin Aladyshev | c7e4b04 | 2021-12-24 15:30:47 +0300 | [diff] [blame] | 736 | |
| 737 | ipmi::ObjectValueTree managedObjects; |
Nan Zhou | 947da1b | 2022-09-20 20:40:59 +0000 | [diff] [blame] | 738 | ec = getManagedObjects(ctx, "xyz.openbmc_project.EntityManager", |
| 739 | "/xyz/openbmc_project/inventory", managedObjects); |
Konstantin Aladyshev | c7e4b04 | 2021-12-24 15:30:47 +0300 | [diff] [blame] | 740 | if (!ec) |
| 741 | { |
| 742 | auto connection = managedObjects.find(fruPath); |
| 743 | if (connection != managedObjects.end()) |
| 744 | { |
| 745 | return true; |
| 746 | } |
| 747 | } |
| 748 | |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 749 | return false; |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 750 | } |
| 751 | |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 752 | /** @brief implements the get FRU Inventory Area Info command |
| 753 | * |
| 754 | * @returns IPMI completion code plus response data |
| 755 | * - FRU Inventory area size in bytes, |
| 756 | * - access bit |
| 757 | **/ |
| 758 | ipmi::RspType<uint16_t, // FRU Inventory area size in bytes, |
| 759 | uint8_t // access size (bytes / words) |
| 760 | > |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 761 | ipmiStorageGetFruInvAreaInfo(ipmi::Context::ptr ctx, uint8_t fruID) |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 762 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 763 | auto iter = frus.find(fruID); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 764 | if (iter == frus.end()) |
| 765 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 766 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 767 | } |
| 768 | |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 769 | auto path = iter->second[0].path; |
Konstantin Aladyshev | 69e3cd4 | 2021-11-26 16:46:17 +0300 | [diff] [blame] | 770 | if (!isFruPresent(ctx, path)) |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 771 | { |
| 772 | return ipmi::responseSensorInvalid(); |
| 773 | } |
| 774 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 775 | try |
| 776 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 777 | return ipmi::responseSuccess( |
| 778 | static_cast<uint16_t>(getFruAreaData(fruID).size()), |
| 779 | static_cast<uint8_t>(AccessMode::bytes)); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 780 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 781 | catch (const InternalFailure& e) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 782 | { |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 783 | log<level::ERR>(e.what()); |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 784 | return ipmi::responseUnspecifiedError(); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 785 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 786 | } |
| 787 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 788 | /**@brief implements the Read FRU Data command |
| 789 | * @param fruDeviceId - FRU device ID. FFh = reserved |
| 790 | * @param offset - FRU inventory offset to read |
| 791 | * @param readCount - count to read |
| 792 | * |
| 793 | * @return IPMI completion code plus response data |
| 794 | * - returnCount - response data count. |
| 795 | * - data - response data |
| 796 | */ |
| 797 | ipmi::RspType<uint8_t, // count returned |
| 798 | std::vector<uint8_t>> // FRU data |
| 799 | ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset, |
| 800 | uint8_t readCount) |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 801 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 802 | if (fruDeviceId == 0xFF) |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 803 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 804 | return ipmi::responseInvalidFieldRequest(); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 805 | } |
| 806 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 807 | auto iter = frus.find(fruDeviceId); |
| 808 | if (iter == frus.end()) |
| 809 | { |
| 810 | return ipmi::responseSensorInvalid(); |
| 811 | } |
| 812 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 813 | try |
| 814 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 815 | const auto& fruArea = getFruAreaData(fruDeviceId); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 816 | auto size = fruArea.size(); |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 817 | |
Tom Joseph | efcd68b | 2018-04-26 18:46:27 +0530 | [diff] [blame] | 818 | if (offset >= size) |
| 819 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 820 | return ipmi::responseParmOutOfRange(); |
Tom Joseph | efcd68b | 2018-04-26 18:46:27 +0530 | [diff] [blame] | 821 | } |
| 822 | |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 823 | // Write the count of response data. |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 824 | uint8_t returnCount; |
| 825 | if ((offset + readCount) <= size) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 826 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 827 | returnCount = readCount; |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 828 | } |
| 829 | else |
| 830 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 831 | returnCount = size - offset; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 832 | } |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 833 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 834 | std::vector<uint8_t> fruData((fruArea.begin() + offset), |
| 835 | (fruArea.begin() + offset + returnCount)); |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 836 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 837 | return ipmi::responseSuccess(returnCount, fruData); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 838 | } |
| 839 | catch (const InternalFailure& e) |
| 840 | { |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 841 | log<level::ERR>(e.what()); |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 842 | return ipmi::responseUnspecifiedError(); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 843 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 844 | } |
| 845 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 846 | ipmi::RspType<uint8_t, // SDR version |
| 847 | uint16_t, // record count LS first |
| 848 | uint16_t, // free space in bytes, LS first |
| 849 | uint32_t, // addition timestamp LS first |
| 850 | uint32_t, // deletion timestamp LS first |
| 851 | uint8_t> // operation Support |
| 852 | ipmiGetRepositoryInfo() |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 853 | { |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 854 | constexpr uint8_t sdrVersion = 0x51; |
| 855 | constexpr uint16_t freeSpace = 0xFFFF; |
| 856 | constexpr uint32_t additionTimestamp = 0x0; |
| 857 | constexpr uint32_t deletionTimestamp = 0x0; |
| 858 | constexpr uint8_t operationSupport = 0; |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 859 | |
Willy Tu | 0ca3bfe | 2022-01-28 09:40:18 -0800 | [diff] [blame] | 860 | // Get SDR count. This returns the total number of SDRs in the device. |
| 861 | const auto& entityRecords = |
| 862 | ipmi::sensor::EntityInfoMapContainer::getContainer() |
| 863 | ->getIpmiEntityRecords(); |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 864 | uint16_t records = ipmi::sensor::sensors.size() + frus.size() + |
| 865 | entityRecords.size(); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 866 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 867 | return ipmi::responseSuccess(sdrVersion, records, freeSpace, |
| 868 | additionTimestamp, deletionTimestamp, |
| 869 | operationSupport); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 870 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 871 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 872 | void register_netfn_storage_functions() |
| 873 | { |
Lei YU | 3df3661 | 2021-09-15 11:41:11 +0800 | [diff] [blame] | 874 | selCacheMapInitialized = false; |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame] | 875 | initSELCache(); |
Willy Tu | d351a72 | 2021-08-12 14:33:40 -0700 | [diff] [blame] | 876 | // Handlers with dbus-sdr handler implementation. |
| 877 | // Do not register the hander if it dynamic sensors stack is used. |
| 878 | |
| 879 | #ifndef FEATURE_DYNAMIC_SENSORS |
Thang Tran | 292c917 | 2023-06-26 10:03:04 +0700 | [diff] [blame] | 880 | |
| 881 | #ifndef FEATURE_DYNAMIC_STORAGES_ONLY |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 882 | // <Get SEL Info> |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 883 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 884 | ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User, |
| 885 | ipmiStorageGetSelInfo); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 886 | |
Xiaochao Ma | f020c44 | 2022-10-31 11:09:38 +0800 | [diff] [blame] | 887 | // <Get SEL Timezone> |
| 888 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 889 | ipmi::storage::cmdGetSelTimeUtcOffset, |
| 890 | ipmi::Privilege::User, |
| 891 | ipmiStorageGetSelTimeUtcOffset); |
| 892 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 893 | // <Get SEL Entry> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 894 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL, |
| 895 | getSELEntry, PRIVILEGE_USER); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 896 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 897 | // <Delete SEL Entry> |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 898 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 899 | ipmi::storage::cmdDeleteSelEntry, |
| 900 | ipmi::Privilege::Operator, deleteSELEntry); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 901 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 902 | // <Add SEL Entry> |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 903 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 904 | ipmi::storage::cmdAddSelEntry, |
| 905 | ipmi::Privilege::Operator, ipmiStorageAddSEL); |
| 906 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 907 | // <Clear SEL> |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 908 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 909 | ipmi::storage::cmdClearSel, ipmi::Privilege::Operator, |
| 910 | clearSEL); |
| 911 | |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 912 | // <Get FRU Inventory Area Info> |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 913 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 914 | ipmi::storage::cmdGetFruInventoryAreaInfo, |
| 915 | ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo); |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 916 | |
Jason M. Bills | b5248c9 | 2019-06-24 15:53:08 -0700 | [diff] [blame] | 917 | // <READ FRU Data> |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 918 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 919 | ipmi::storage::cmdReadFruData, |
| 920 | ipmi::Privilege::Operator, ipmiStorageReadFruData); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 921 | |
Thang Tran | 292c917 | 2023-06-26 10:03:04 +0700 | [diff] [blame] | 922 | #endif // FEATURE_DYNAMIC_STORAGES_ONLY |
| 923 | |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 924 | // <Get Repository Info> |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 925 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 926 | ipmi::storage::cmdGetSdrRepositoryInfo, |
| 927 | ipmi::Privilege::User, ipmiGetRepositoryInfo); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 928 | |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 929 | // <Reserve SDR Repository> |
jayaprakash Mutyala | d957823 | 2019-05-13 20:22:50 +0000 | [diff] [blame] | 930 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 931 | ipmi::storage::cmdReserveSdrRepository, |
| 932 | ipmi::Privilege::User, ipmiSensorReserveSdr); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 933 | |
| 934 | // <Get SDR> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 935 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr, |
| 936 | ipmi_sen_get_sdr, PRIVILEGE_USER); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 937 | |
Willy Tu | d351a72 | 2021-08-12 14:33:40 -0700 | [diff] [blame] | 938 | #endif |
| 939 | |
| 940 | // Common Handers used by both implementation. |
| 941 | |
| 942 | // <Reserve SEL> |
| 943 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 944 | ipmi::storage::cmdReserveSel, ipmi::Privilege::User, |
| 945 | ipmiStorageReserveSel); |
| 946 | |
Thang Tran | dbf66e1 | 2023-09-21 13:07:24 +0700 | [diff] [blame] | 947 | // <Get SEL Time> |
| 948 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 949 | ipmi::storage::cmdGetSelTime, ipmi::Privilege::User, |
| 950 | ipmiStorageGetSelTime); |
| 951 | |
| 952 | // <Set SEL Time> |
| 953 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 954 | ipmi::storage::cmdSetSelTime, |
| 955 | ipmi::Privilege::Operator, ipmiStorageSetSelTime); |
| 956 | |
Marri Devender Rao | 908f750 | 2017-07-10 01:49:54 -0500 | [diff] [blame] | 957 | ipmi::fru::registerCallbackHandler(); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 958 | return; |
| 959 | } |