Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
James Feist | 35e257a | 2020-06-05 13:30:51 -0700 | [diff] [blame] | 18 | #include "health.hpp" |
| 19 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 20 | #include <boost/container/flat_map.hpp> |
| 21 | #include <node.hpp> |
| 22 | #include <utils/json_utils.hpp> |
| 23 | |
| 24 | namespace redfish |
| 25 | { |
| 26 | |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 27 | using InterfacesProperties = boost::container::flat_map< |
| 28 | std::string, |
| 29 | boost::container::flat_map<std::string, dbus::utility::DbusVariantType>>; |
| 30 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 31 | void getResourceList(std::shared_ptr<AsyncResp> aResp, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 32 | const std::string &subclass, |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 33 | const std::vector<const char *> &collectionName) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 34 | { |
| 35 | BMCWEB_LOG_DEBUG << "Get available system cpu/mem resources."; |
| 36 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 37 | [subclass, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 38 | const boost::system::error_code ec, |
| 39 | const boost::container::flat_map< |
| 40 | std::string, boost::container::flat_map< |
| 41 | std::string, std::vector<std::string>>> |
| 42 | &subtree) { |
| 43 | if (ec) |
| 44 | { |
| 45 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 46 | messages::internalError(aResp->res); |
| 47 | return; |
| 48 | } |
| 49 | nlohmann::json &members = aResp->res.jsonValue["Members"]; |
| 50 | members = nlohmann::json::array(); |
| 51 | |
| 52 | for (const auto &object : subtree) |
| 53 | { |
| 54 | auto iter = object.first.rfind("/"); |
| 55 | if ((iter != std::string::npos) && (iter < object.first.size())) |
| 56 | { |
| 57 | members.push_back( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 58 | {{"@odata.id", "/redfish/v1/Systems/system/" + |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 59 | subclass + "/" + |
| 60 | object.first.substr(iter + 1)}}); |
| 61 | } |
| 62 | } |
| 63 | aResp->res.jsonValue["Members@odata.count"] = members.size(); |
| 64 | }, |
| 65 | "xyz.openbmc_project.ObjectMapper", |
| 66 | "/xyz/openbmc_project/object_mapper", |
| 67 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 68 | "/xyz/openbmc_project/inventory", 0, collectionName); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 69 | } |
| 70 | |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 71 | void getCpuDataByInterface(std::shared_ptr<AsyncResp> aResp, |
| 72 | const InterfacesProperties &cpuInterfacesProperties) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 73 | { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 74 | BMCWEB_LOG_DEBUG << "Get CPU resources by interface."; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 75 | |
Ed Tanous | 99131cd | 2019-10-24 11:12:47 -0700 | [diff] [blame] | 76 | const bool *present = nullptr; |
| 77 | const bool *functional = nullptr; |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 78 | for (const auto &interface : cpuInterfacesProperties) |
| 79 | { |
| 80 | for (const auto &property : interface.second) |
| 81 | { |
| 82 | if (property.first == "ProcessorCoreCount") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 83 | { |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 84 | const uint16_t *coresCount = |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 85 | std::get_if<uint16_t>(&property.second); |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 86 | if (coresCount == nullptr) |
| 87 | { |
| 88 | // Important property not in desired type |
| 89 | messages::internalError(aResp->res); |
| 90 | return; |
| 91 | } |
| 92 | if (*coresCount == 0) |
| 93 | { |
| 94 | // Slot is not populated, set status end return |
| 95 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 96 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 97 | // HTTP Code will be set up automatically, just return |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | aResp->res.jsonValue["TotalCores"] = *coresCount; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 102 | } |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 103 | else if (property.first == "ProcessorType") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 104 | { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 105 | aResp->res.jsonValue["Name"] = property.second; |
| 106 | } |
| 107 | else if (property.first == "Manufacturer") |
| 108 | { |
| 109 | const std::string *value = |
| 110 | std::get_if<std::string>(&property.second); |
| 111 | if (value != nullptr) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 112 | { |
| 113 | aResp->res.jsonValue["Manufacturer"] = property.second; |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 114 | // Otherwise would be unexpected. |
| 115 | if (value->find("Intel") != std::string::npos) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 116 | { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 117 | aResp->res.jsonValue["ProcessorArchitecture"] = "x86"; |
| 118 | aResp->res.jsonValue["InstructionSet"] = "x86-64"; |
| 119 | } |
| 120 | else if (value->find("IBM") != std::string::npos) |
| 121 | { |
| 122 | aResp->res.jsonValue["ProcessorArchitecture"] = "Power"; |
| 123 | aResp->res.jsonValue["InstructionSet"] = "PowerISA"; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | else if (property.first == "ProcessorMaxSpeed") |
| 128 | { |
| 129 | aResp->res.jsonValue["MaxSpeedMHz"] = property.second; |
| 130 | } |
| 131 | else if (property.first == "ProcessorThreadCount") |
| 132 | { |
| 133 | aResp->res.jsonValue["TotalThreads"] = property.second; |
| 134 | } |
| 135 | else if (property.first == "Model") |
| 136 | { |
| 137 | const std::string *value = |
| 138 | std::get_if<std::string>(&property.second); |
| 139 | if (value != nullptr) |
| 140 | { |
| 141 | aResp->res.jsonValue["Model"] = *value; |
| 142 | } |
| 143 | } |
Gunnar Mills | f9dcc11 | 2020-02-13 13:19:43 -0600 | [diff] [blame] | 144 | else if (property.first == "PartNumber") |
| 145 | { |
| 146 | aResp->res.jsonValue["PartNumber"] = property.second; |
| 147 | } |
| 148 | else if (property.first == "SerialNumber") |
| 149 | { |
| 150 | aResp->res.jsonValue["SerialNumber"] = property.second; |
| 151 | } |
| 152 | else if (property.first == "Version") |
| 153 | { |
| 154 | aResp->res.jsonValue["Version"] = property.second; |
| 155 | } |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 156 | else if (property.first == "Present") |
| 157 | { |
| 158 | present = std::get_if<bool>(&property.second); |
| 159 | } |
| 160 | else if (property.first == "Functional") |
| 161 | { |
| 162 | functional = std::get_if<bool>(&property.second); |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | if ((present == nullptr) || (functional == nullptr)) |
| 168 | { |
| 169 | // Important property not in desired type |
| 170 | messages::internalError(aResp->res); |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | if (*present == false) |
| 175 | { |
| 176 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 177 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 182 | if (*functional == true) |
| 183 | { |
| 184 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 185 | } |
| 186 | else |
| 187 | { |
| 188 | aResp->res.jsonValue["Status"]["Health"] = "Critical"; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | void getCpuDataByService(std::shared_ptr<AsyncResp> aResp, |
| 196 | const std::string &cpuId, const std::string &service, |
| 197 | const std::string &objPath) |
| 198 | { |
| 199 | BMCWEB_LOG_DEBUG << "Get available system cpu resources by service."; |
| 200 | |
| 201 | crow::connections::systemBus->async_method_call( |
| 202 | [cpuId, service, objPath, aResp{std::move(aResp)}]( |
| 203 | const boost::system::error_code ec, |
| 204 | const dbus::utility::ManagedObjectType &dbusData) { |
| 205 | if (ec) |
| 206 | { |
| 207 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 208 | messages::internalError(aResp->res); |
| 209 | return; |
| 210 | } |
| 211 | aResp->res.jsonValue["Id"] = cpuId; |
| 212 | aResp->res.jsonValue["Name"] = "Processor"; |
| 213 | aResp->res.jsonValue["ProcessorType"] = "CPU"; |
| 214 | |
| 215 | std::string corePath = objPath + "/core"; |
| 216 | size_t totalCores = 0; |
| 217 | for (const auto &object : dbusData) |
| 218 | { |
| 219 | if (object.first.str == objPath) |
| 220 | { |
| 221 | getCpuDataByInterface(aResp, object.second); |
| 222 | } |
| 223 | else if (boost::starts_with(object.first.str, corePath)) |
| 224 | { |
| 225 | for (const auto &interface : object.second) |
| 226 | { |
| 227 | if (interface.first == |
| 228 | "xyz.openbmc_project.Inventory.Item") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 229 | { |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 230 | for (const auto &property : interface.second) |
| 231 | { |
| 232 | if (property.first == "Present") |
| 233 | { |
| 234 | const bool *present = |
| 235 | std::get_if<bool>(&property.second); |
| 236 | if (present != nullptr) |
| 237 | { |
| 238 | if (*present == true) |
| 239 | { |
| 240 | totalCores++; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | } |
Gunnar Mills | b957ba5 | 2019-01-31 15:58:15 -0600 | [diff] [blame] | 245 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 246 | } |
| 247 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 248 | } |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 249 | // In getCpuDataByInterface(), state and health are set |
| 250 | // based on the present and functional status. If core |
| 251 | // count is zero, then it has a higher precedence. |
| 252 | if (totalCores == 0) |
| 253 | { |
| 254 | // Slot is not populated, set status end return |
| 255 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 256 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 257 | } |
| 258 | aResp->res.jsonValue["TotalCores"] = totalCores; |
| 259 | return; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 260 | }, |
RAJESWARAN THILLAIGOVINDAN | ec8faf9 | 2019-02-21 10:59:03 -0600 | [diff] [blame] | 261 | service, "/xyz/openbmc_project/inventory", |
| 262 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 263 | } |
| 264 | |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 265 | void getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp, |
| 266 | const std::string &acclrtrId, |
| 267 | const std::string &service, |
| 268 | const std::string &objPath) |
| 269 | { |
| 270 | BMCWEB_LOG_DEBUG |
| 271 | << "Get available system Accelerator resources by service."; |
| 272 | crow::connections::systemBus->async_method_call( |
| 273 | [acclrtrId, aResp{std::move(aResp)}]( |
| 274 | const boost::system::error_code ec, |
| 275 | const boost::container::flat_map< |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 276 | std::string, std::variant<std::string, uint32_t, uint16_t, |
| 277 | bool>> &properties) { |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 278 | if (ec) |
| 279 | { |
| 280 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 281 | messages::internalError(aResp->res); |
| 282 | return; |
| 283 | } |
| 284 | aResp->res.jsonValue["Id"] = acclrtrId; |
| 285 | aResp->res.jsonValue["Name"] = "Processor"; |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 286 | const bool *accPresent = nullptr; |
| 287 | const bool *accFunctional = nullptr; |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 288 | std::string state = ""; |
| 289 | |
| 290 | for (const auto &property : properties) |
| 291 | { |
| 292 | if (property.first == "Functional") |
| 293 | { |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 294 | accFunctional = std::get_if<bool>(&property.second); |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 295 | } |
| 296 | else if (property.first == "Present") |
| 297 | { |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 298 | accPresent = std::get_if<bool>(&property.second); |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | if (!accPresent || !accFunctional) |
| 303 | { |
| 304 | BMCWEB_LOG_DEBUG << "Required properties missing in DBUS " |
| 305 | "response"; |
| 306 | messages::internalError(aResp->res); |
| 307 | return; |
| 308 | } |
| 309 | |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 310 | if (*accPresent && *accFunctional) |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 311 | { |
| 312 | state = "Enabled"; |
| 313 | } |
Santosh Puranik | 94e1b82 | 2019-07-24 04:48:32 -0500 | [diff] [blame] | 314 | else if (*accPresent) |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 315 | { |
| 316 | state = "UnavailableOffline"; |
| 317 | } |
| 318 | else |
| 319 | { |
| 320 | state = "Absent"; |
| 321 | } |
| 322 | aResp->res.jsonValue["Status"]["State"] = state; |
| 323 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 324 | aResp->res.jsonValue["ProcessorType"] = "Accelerator"; |
| 325 | }, |
| 326 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 327 | } |
| 328 | |
| 329 | void getCpuData(std::shared_ptr<AsyncResp> aResp, const std::string &cpuId, |
| 330 | const std::vector<const char *> inventoryItems) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 331 | { |
| 332 | BMCWEB_LOG_DEBUG << "Get available system cpu resources."; |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 333 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 334 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 335 | [cpuId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 336 | const boost::system::error_code ec, |
| 337 | const boost::container::flat_map< |
| 338 | std::string, boost::container::flat_map< |
| 339 | std::string, std::vector<std::string>>> |
| 340 | &subtree) { |
| 341 | if (ec) |
| 342 | { |
| 343 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 344 | messages::internalError(aResp->res); |
| 345 | return; |
| 346 | } |
| 347 | for (const auto &object : subtree) |
| 348 | { |
| 349 | if (boost::ends_with(object.first, cpuId)) |
| 350 | { |
| 351 | for (const auto &service : object.second) |
| 352 | { |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 353 | for (const auto &inventory : service.second) |
| 354 | if (inventory == |
| 355 | "xyz.openbmc_project.Inventory.Item.Cpu") |
| 356 | { |
| 357 | getCpuDataByService(aResp, cpuId, service.first, |
| 358 | object.first); |
| 359 | } |
| 360 | else if (inventory == "xyz.openbmc_project." |
| 361 | "Inventory.Item.Accelerator") |
| 362 | { |
| 363 | getAcceleratorDataByService( |
| 364 | aResp, cpuId, service.first, object.first); |
| 365 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 366 | return; |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | // Object not found |
| 371 | messages::resourceNotFound(aResp->res, "Processor", cpuId); |
| 372 | return; |
| 373 | }, |
| 374 | "xyz.openbmc_project.ObjectMapper", |
| 375 | "/xyz/openbmc_project/object_mapper", |
| 376 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 377 | "/xyz/openbmc_project/inventory", 0, inventoryItems); |
| 378 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 379 | |
| 380 | void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 381 | const std::string &dimmId, const std::string &service, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 382 | const std::string &objPath) |
| 383 | { |
James Feist | 35e257a | 2020-06-05 13:30:51 -0700 | [diff] [blame] | 384 | auto health = std::make_shared<HealthPopulate>(aResp); |
| 385 | health->selfPath = objPath; |
| 386 | health->populate(); |
| 387 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 388 | BMCWEB_LOG_DEBUG << "Get available system components."; |
| 389 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 390 | [dimmId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 391 | const boost::system::error_code ec, |
| 392 | const boost::container::flat_map< |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 393 | std::string, std::variant<std::string, uint32_t, uint16_t>> |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 394 | &properties) { |
| 395 | if (ec) |
| 396 | { |
| 397 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 398 | messages::internalError(aResp->res); |
| 399 | |
| 400 | return; |
| 401 | } |
| 402 | aResp->res.jsonValue["Id"] = dimmId; |
| 403 | aResp->res.jsonValue["Name"] = "DIMM Slot"; |
| 404 | |
| 405 | const auto memorySizeProperty = properties.find("MemorySizeInKB"); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 406 | if (memorySizeProperty != properties.end()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 407 | { |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 408 | const uint32_t *memorySize = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 409 | std::get_if<uint32_t>(&memorySizeProperty->second); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 410 | if (memorySize == nullptr) |
| 411 | { |
| 412 | // Important property not in desired type |
| 413 | messages::internalError(aResp->res); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 414 | |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 415 | return; |
| 416 | } |
| 417 | if (*memorySize == 0) |
| 418 | { |
| 419 | // Slot is not populated, set status end return |
| 420 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 421 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 422 | // HTTP Code will be set up automatically, just return |
| 423 | return; |
| 424 | } |
| 425 | aResp->res.jsonValue["CapacityMiB"] = (*memorySize >> 10); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 426 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 427 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 428 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 429 | |
| 430 | for (const auto &property : properties) |
| 431 | { |
| 432 | if (property.first == "MemoryDataWidth") |
| 433 | { |
| 434 | aResp->res.jsonValue["DataWidthBits"] = property.second; |
| 435 | } |
Manojkiran Eda | 7e236ca | 2019-06-25 23:06:32 +0530 | [diff] [blame] | 436 | else if (property.first == "PartNumber") |
| 437 | { |
| 438 | aResp->res.jsonValue["PartNumber"] = property.second; |
| 439 | } |
| 440 | else if (property.first == "SerialNumber") |
| 441 | { |
| 442 | aResp->res.jsonValue["SerialNumber"] = property.second; |
| 443 | } |
| 444 | else if (property.first == "Manufacturer") |
| 445 | { |
| 446 | aResp->res.jsonValue["Manufacturer"] = property.second; |
| 447 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 448 | else if (property.first == "MemoryType") |
| 449 | { |
| 450 | const auto *value = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 451 | std::get_if<std::string>(&property.second); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 452 | if (value != nullptr) |
| 453 | { |
| 454 | aResp->res.jsonValue["MemoryDeviceType"] = *value; |
| 455 | if (boost::starts_with(*value, "DDR")) |
| 456 | { |
| 457 | aResp->res.jsonValue["MemoryType"] = "DRAM"; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | }, |
| 463 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 464 | } |
| 465 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 466 | void getDimmData(std::shared_ptr<AsyncResp> aResp, const std::string &dimmId) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 467 | { |
| 468 | BMCWEB_LOG_DEBUG << "Get available system dimm resources."; |
| 469 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 470 | [dimmId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 471 | const boost::system::error_code ec, |
| 472 | const boost::container::flat_map< |
| 473 | std::string, boost::container::flat_map< |
| 474 | std::string, std::vector<std::string>>> |
| 475 | &subtree) { |
| 476 | if (ec) |
| 477 | { |
| 478 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 479 | messages::internalError(aResp->res); |
| 480 | |
| 481 | return; |
| 482 | } |
| 483 | for (const auto &object : subtree) |
| 484 | { |
| 485 | if (boost::ends_with(object.first, dimmId)) |
| 486 | { |
| 487 | for (const auto &service : object.second) |
| 488 | { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 489 | getDimmDataByService(aResp, dimmId, service.first, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 490 | object.first); |
| 491 | return; |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | // Object not found |
| 496 | messages::resourceNotFound(aResp->res, "Memory", dimmId); |
| 497 | return; |
| 498 | }, |
| 499 | "xyz.openbmc_project.ObjectMapper", |
| 500 | "/xyz/openbmc_project/object_mapper", |
| 501 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 502 | "/xyz/openbmc_project/inventory", 0, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 503 | std::array<const char *, 1>{"xyz.openbmc_project.Inventory.Item.Dimm"}); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 504 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 505 | |
| 506 | class ProcessorCollection : public Node |
| 507 | { |
| 508 | public: |
| 509 | /* |
| 510 | * Default Constructor |
| 511 | */ |
| 512 | ProcessorCollection(CrowApp &app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 513 | Node(app, "/redfish/v1/Systems/system/Processors/") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 514 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 515 | entityPrivileges = { |
| 516 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 517 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 518 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 519 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 520 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 521 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 522 | } |
| 523 | |
| 524 | private: |
| 525 | /** |
| 526 | * Functions triggers appropriate requests on DBus |
| 527 | */ |
| 528 | void doGet(crow::Response &res, const crow::Request &req, |
| 529 | const std::vector<std::string> ¶ms) override |
| 530 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 531 | res.jsonValue["@odata.type"] = |
| 532 | "#ProcessorCollection.ProcessorCollection"; |
| 533 | res.jsonValue["Name"] = "Processor Collection"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 534 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 535 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Processors/"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 536 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 537 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 538 | getResourceList(asyncResp, "Processors", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 539 | {"xyz.openbmc_project.Inventory.Item.Cpu", |
| 540 | "xyz.openbmc_project.Inventory.Item.Accelerator"}); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 541 | } |
| 542 | }; |
| 543 | |
| 544 | class Processor : public Node |
| 545 | { |
| 546 | public: |
| 547 | /* |
| 548 | * Default Constructor |
| 549 | */ |
| 550 | Processor(CrowApp &app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 551 | Node(app, "/redfish/v1/Systems/system/Processors/<str>/", std::string()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 552 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 553 | entityPrivileges = { |
| 554 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 555 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 556 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 557 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 558 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 559 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 560 | } |
| 561 | |
| 562 | private: |
| 563 | /** |
| 564 | * Functions triggers appropriate requests on DBus |
| 565 | */ |
| 566 | void doGet(crow::Response &res, const crow::Request &req, |
| 567 | const std::vector<std::string> ¶ms) override |
| 568 | { |
| 569 | // Check if there is required param, truly entering this shall be |
| 570 | // impossible |
| 571 | if (params.size() != 1) |
| 572 | { |
| 573 | messages::internalError(res); |
| 574 | |
| 575 | res.end(); |
| 576 | return; |
| 577 | } |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 578 | const std::string &processorId = params[0]; |
Gunnar Mills | f9dcc11 | 2020-02-13 13:19:43 -0600 | [diff] [blame] | 579 | res.jsonValue["@odata.type"] = "#Processor.v1_7_0.Processor"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 580 | res.jsonValue["@odata.id"] = |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 581 | "/redfish/v1/Systems/system/Processors/" + processorId; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 582 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 583 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 584 | |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 585 | getCpuData(asyncResp, processorId, |
| 586 | {"xyz.openbmc_project.Inventory.Item.Cpu", |
| 587 | "xyz.openbmc_project.Inventory.Item.Accelerator"}); |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 588 | } |
| 589 | }; |
| 590 | |
| 591 | class MemoryCollection : public Node |
| 592 | { |
| 593 | public: |
| 594 | /* |
| 595 | * Default Constructor |
| 596 | */ |
| 597 | MemoryCollection(CrowApp &app) : |
| 598 | Node(app, "/redfish/v1/Systems/system/Memory/") |
| 599 | { |
| 600 | entityPrivileges = { |
| 601 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 602 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 603 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 604 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 605 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 606 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 607 | } |
| 608 | |
| 609 | private: |
| 610 | /** |
| 611 | * Functions triggers appropriate requests on DBus |
| 612 | */ |
| 613 | void doGet(crow::Response &res, const crow::Request &req, |
| 614 | const std::vector<std::string> ¶ms) override |
| 615 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 616 | res.jsonValue["@odata.type"] = "#MemoryCollection.MemoryCollection"; |
| 617 | res.jsonValue["Name"] = "Memory Module Collection"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 618 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Memory/"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 619 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 620 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 621 | getResourceList(asyncResp, "Memory", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame] | 622 | {"xyz.openbmc_project.Inventory.Item.Dimm"}); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 623 | } |
| 624 | }; |
| 625 | |
| 626 | class Memory : public Node |
| 627 | { |
| 628 | public: |
| 629 | /* |
| 630 | * Default Constructor |
| 631 | */ |
| 632 | Memory(CrowApp &app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 633 | Node(app, "/redfish/v1/Systems/system/Memory/<str>/", std::string()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 634 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 635 | entityPrivileges = { |
| 636 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 637 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 638 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 639 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 640 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 641 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 642 | } |
| 643 | |
| 644 | private: |
| 645 | /** |
| 646 | * Functions triggers appropriate requests on DBus |
| 647 | */ |
| 648 | void doGet(crow::Response &res, const crow::Request &req, |
| 649 | const std::vector<std::string> ¶ms) override |
| 650 | { |
| 651 | // Check if there is required param, truly entering this shall be |
| 652 | // impossible |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 653 | if (params.size() != 1) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 654 | { |
| 655 | messages::internalError(res); |
| 656 | res.end(); |
| 657 | return; |
| 658 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 659 | const std::string &dimmId = params[0]; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 660 | |
Rapkiewicz, Pawel | bb3d994 | 2018-11-22 10:59:11 +0100 | [diff] [blame] | 661 | res.jsonValue["@odata.type"] = "#Memory.v1_6_0.Memory"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 662 | res.jsonValue["@odata.id"] = |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 663 | "/redfish/v1/Systems/system/Memory/" + dimmId; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 664 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 665 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 666 | getDimmData(asyncResp, dimmId); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 667 | } |
| 668 | }; |
| 669 | |
| 670 | } // namespace redfish |