| Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
| Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 4 | |
| 5 | #pragma once |
| 6 | |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 7 | #include "bmcweb_config.h" |
| 8 | |
| Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 9 | #include "app.hpp" |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 10 | #include "async_resp.hpp" |
| George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 11 | #include "dbus_utility.hpp" |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 12 | #include "error_messages.hpp" |
| 13 | #include "generated/enums/pcie_device.hpp" |
| 14 | #include "generated/enums/pcie_slots.hpp" |
| Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 15 | #include "generated/enums/resource.hpp" |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 16 | #include "http_request.hpp" |
| 17 | #include "logging.hpp" |
| Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "query.hpp" |
| 19 | #include "registries/privilege_registry.hpp" |
| Myung Bae | f7e62c1 | 2025-09-07 14:02:08 -0500 | [diff] [blame] | 20 | #include "utils/asset_utils.hpp" |
| Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 21 | #include "utils/dbus_utils.hpp" |
| Lakshmi Yadlapati | c49c329 | 2023-04-19 16:42:35 -0500 | [diff] [blame] | 22 | #include "utils/pcie_util.hpp" |
| Ed Tanous | 0ec8b83 | 2022-03-14 14:56:47 -0700 | [diff] [blame] | 23 | |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 24 | #include <asm-generic/errno.h> |
| 25 | |
| 26 | #include <boost/beast/http/field.hpp> |
| 27 | #include <boost/beast/http/verb.hpp> |
| Myung Bae | 9c75bf7 | 2023-12-10 16:38:04 -0500 | [diff] [blame^] | 28 | #include <boost/system/error_code.hpp> |
| Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 29 | #include <boost/url/format.hpp> |
| Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 30 | #include <sdbusplus/unpack_properties.hpp> |
| Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 31 | |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 32 | #include <array> |
| 33 | #include <charconv> |
| 34 | #include <cstddef> |
| 35 | #include <cstdint> |
| 36 | #include <format> |
| 37 | #include <functional> |
| Myung Bae | 8c1d054 | 2024-03-12 17:50:48 -0500 | [diff] [blame] | 38 | #include <limits> |
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 39 | #include <memory> |
| 40 | #include <optional> |
| 41 | #include <string> |
| 42 | #include <string_view> |
| 43 | #include <system_error> |
| 44 | #include <utility> |
| 45 | #include <variant> |
| Myung Bae | 8c1d054 | 2024-03-12 17:50:48 -0500 | [diff] [blame] | 46 | |
| Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 47 | namespace redfish |
| 48 | { |
| 49 | |
| Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 50 | static constexpr const char* inventoryPath = "/xyz/openbmc_project/inventory"; |
| Lakshmi Yadlapati | 94c3a10 | 2023-04-05 18:11:22 -0500 | [diff] [blame] | 51 | static constexpr std::array<std::string_view, 1> pcieDeviceInterface = { |
| 52 | "xyz.openbmc_project.Inventory.Item.PCIeDevice"}; |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 53 | static constexpr std::array<std::string_view, 1> pcieSlotInterface = { |
| 54 | "xyz.openbmc_project.Inventory.Item.PCIeSlot"}; |
| Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 55 | |
| Ed Tanous | 4ff0f1f | 2024-09-04 17:27:37 -0700 | [diff] [blame] | 56 | inline void handlePCIeDevicePath( |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 57 | const std::string& pcieDeviceId, |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 58 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 59 | const dbus::utility::MapperGetSubTreePathsResponse& pcieDevicePaths, |
| 60 | const std::function<void(const std::string& pcieDevicePath, |
| 61 | const std::string& service)>& callback) |
| 62 | |
| 63 | { |
| 64 | for (const std::string& pcieDevicePath : pcieDevicePaths) |
| 65 | { |
| 66 | std::string pciecDeviceName = |
| 67 | sdbusplus::message::object_path(pcieDevicePath).filename(); |
| 68 | if (pciecDeviceName.empty() || pciecDeviceName != pcieDeviceId) |
| 69 | { |
| 70 | continue; |
| 71 | } |
| 72 | |
| 73 | dbus::utility::getDbusObject( |
| Konstantin Aladyshev | 3a58c5a | 2024-08-05 12:57:13 +0300 | [diff] [blame] | 74 | pcieDevicePath, pcieDeviceInterface, |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 75 | [pcieDevicePath, asyncResp, |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 76 | callback](const boost::system::error_code& ec, |
| 77 | const dbus::utility::MapperGetObject& object) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 78 | if (ec || object.empty()) |
| 79 | { |
| 80 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
| 81 | messages::internalError(asyncResp->res); |
| 82 | return; |
| 83 | } |
| 84 | callback(pcieDevicePath, object.begin()->first); |
| 85 | }); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 86 | return; |
| 87 | } |
| 88 | |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 89 | BMCWEB_LOG_WARNING("PCIe Device not found"); |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 90 | messages::resourceNotFound(asyncResp->res, "PCIeDevice", pcieDeviceId); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 91 | } |
| 92 | |
| Ed Tanous | 4ff0f1f | 2024-09-04 17:27:37 -0700 | [diff] [blame] | 93 | inline void getValidPCIeDevicePath( |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 94 | const std::string& pcieDeviceId, |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 95 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 96 | const std::function<void(const std::string& pcieDevicePath, |
| 97 | const std::string& service)>& callback) |
| 98 | { |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 99 | dbus::utility::getSubTreePaths( |
| Lakshmi Yadlapati | 94c3a10 | 2023-04-05 18:11:22 -0500 | [diff] [blame] | 100 | inventoryPath, 0, pcieDeviceInterface, |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 101 | [pcieDeviceId, asyncResp, |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 102 | callback](const boost::system::error_code& ec, |
| 103 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 104 | pcieDevicePaths) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 105 | if (ec) |
| 106 | { |
| 107 | BMCWEB_LOG_ERROR("D-Bus response error on GetSubTree {}", ec); |
| 108 | messages::internalError(asyncResp->res); |
| 109 | return; |
| 110 | } |
| 111 | handlePCIeDevicePath(pcieDeviceId, asyncResp, pcieDevicePaths, |
| 112 | callback); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 113 | return; |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 114 | }); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 115 | } |
| 116 | |
| Ed Tanous | 4ff0f1f | 2024-09-04 17:27:37 -0700 | [diff] [blame] | 117 | inline void handlePCIeDeviceCollectionGet( |
| Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 118 | crow::App& app, const crow::Request& req, |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 119 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 120 | const std::string& systemName) |
| 121 | { |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 122 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 123 | { |
| 124 | return; |
| 125 | } |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 126 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 127 | { |
| 128 | // Option currently returns no systems. TBD |
| 129 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 130 | systemName); |
| 131 | return; |
| 132 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 133 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 134 | { |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 135 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 136 | systemName); |
| Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 137 | return; |
| 138 | } |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 139 | |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 140 | asyncResp->res.addHeader(boost::beast::http::field::link, |
| 141 | "</redfish/v1/JsonSchemas/PCIeDeviceCollection/" |
| 142 | "PCIeDeviceCollection.json>; rel=describedby"); |
| 143 | asyncResp->res.jsonValue["@odata.type"] = |
| Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 144 | "#PCIeDeviceCollection.PCIeDeviceCollection"; |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 145 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
| 146 | "/redfish/v1/Systems/{}/PCIeDevices", BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 147 | asyncResp->res.jsonValue["Name"] = "PCIe Device Collection"; |
| 148 | asyncResp->res.jsonValue["Description"] = "Collection of PCIe Devices"; |
| Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 149 | |
| Lakshmi Yadlapati | 70c4d54 | 2023-06-08 04:37:18 -0500 | [diff] [blame] | 150 | pcie_util::getPCIeDeviceList(asyncResp, |
| 151 | nlohmann::json::json_pointer("/Members")); |
| Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 152 | } |
| 153 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 154 | inline void requestRoutesSystemPCIeDeviceCollection(App& app) |
| Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 155 | { |
| Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 156 | /** |
| 157 | * Functions triggers appropriate requests on DBus |
| 158 | */ |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 159 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/PCIeDevices/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 160 | .privileges(redfish::privileges::getPCIeDeviceCollection) |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 161 | .methods(boost::beast::http::verb::get)( |
| Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 162 | std::bind_front(handlePCIeDeviceCollectionGet, std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| Myung Bae | 9c75bf7 | 2023-12-10 16:38:04 -0500 | [diff] [blame^] | 165 | inline void afterGetAssociatedSubTreePaths( |
| 166 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 167 | const boost::system::error_code& ec, |
| 168 | const dbus::utility::MapperGetSubTreePathsResponse& processorPaths) |
| 169 | { |
| 170 | if (ec) |
| 171 | { |
| 172 | if (ec.value() == EBADR) |
| 173 | { |
| 174 | BMCWEB_LOG_DEBUG("No processor association found"); |
| 175 | return; |
| 176 | } |
| 177 | BMCWEB_LOG_ERROR("DBUS response error {}", ec.value()); |
| 178 | messages::internalError(asyncResp->res); |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | if (processorPaths.empty()) |
| 183 | { |
| 184 | BMCWEB_LOG_DEBUG("No association found for processor"); |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | nlohmann::json& processorList = |
| 189 | asyncResp->res.jsonValue["Links"]["Processors"]; |
| 190 | for (const std::string& processorPath : processorPaths) |
| 191 | { |
| 192 | std::string processorName = |
| 193 | sdbusplus::message::object_path(processorPath).filename(); |
| 194 | if (processorName.empty()) |
| 195 | { |
| 196 | continue; |
| 197 | } |
| 198 | |
| 199 | nlohmann::json item = nlohmann::json::object(); |
| 200 | item["@odata.id"] = |
| 201 | boost::urls::format("/redfish/v1/Systems/{}/Processors/{}", |
| 202 | BMCWEB_REDFISH_SYSTEM_URI_NAME, processorName); |
| 203 | processorList.emplace_back(std::move(item)); |
| 204 | } |
| 205 | |
| 206 | asyncResp->res.jsonValue["Links"]["Processors@odata.count"] = |
| 207 | processorList.size(); |
| 208 | } |
| 209 | |
| 210 | inline void linkAssociatedProcessor( |
| 211 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 212 | const std::string& pcieDevicePath) |
| 213 | { |
| 214 | constexpr std::array<std::string_view, 2> processorInterfaces = { |
| 215 | "xyz.openbmc_project.Inventory.Item.Cpu", |
| 216 | "xyz.openbmc_project.Inventory.Item.Accelerator"}; |
| 217 | |
| 218 | dbus::utility::getAssociatedSubTreePaths( |
| 219 | pcieDevicePath + "/connected_to", |
| 220 | sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0, |
| 221 | processorInterfaces, |
| 222 | std::bind_front(afterGetAssociatedSubTreePaths, asyncResp)); |
| 223 | } |
| 224 | |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 225 | inline void addPCIeSlotProperties( |
| 226 | crow::Response& res, const boost::system::error_code& ec, |
| 227 | const dbus::utility::DBusPropertiesMap& pcieSlotProperties) |
| 228 | { |
| 229 | if (ec) |
| 230 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 231 | BMCWEB_LOG_ERROR("DBUS response error for getAllProperties{}", |
| 232 | ec.value()); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 233 | messages::internalError(res); |
| 234 | return; |
| 235 | } |
| 236 | std::string generation; |
| 237 | size_t lanes = 0; |
| 238 | std::string slotType; |
| 239 | |
| 240 | bool success = sdbusplus::unpackPropertiesNoThrow( |
| 241 | dbus_utils::UnpackErrorPrinter(), pcieSlotProperties, "Generation", |
| 242 | generation, "Lanes", lanes, "SlotType", slotType); |
| 243 | |
| 244 | if (!success) |
| 245 | { |
| 246 | messages::internalError(res); |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | std::optional<pcie_device::PCIeTypes> pcieType = |
| 251 | pcie_util::redfishPcieGenerationFromDbus(generation); |
| 252 | if (!pcieType) |
| 253 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 254 | BMCWEB_LOG_WARNING("Unknown PCIeType: {}", generation); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 255 | } |
| 256 | else |
| 257 | { |
| 258 | if (*pcieType == pcie_device::PCIeTypes::Invalid) |
| 259 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 260 | BMCWEB_LOG_ERROR("Invalid PCIeType: {}", generation); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 261 | messages::internalError(res); |
| 262 | return; |
| 263 | } |
| 264 | res.jsonValue["Slot"]["PCIeType"] = *pcieType; |
| 265 | } |
| 266 | |
| Konstantin Aladyshev | 82f8032 | 2023-07-10 15:00:38 +0300 | [diff] [blame] | 267 | if (lanes != 0) |
| 268 | { |
| 269 | res.jsonValue["Slot"]["Lanes"] = lanes; |
| 270 | } |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 271 | |
| 272 | std::optional<pcie_slots::SlotTypes> redfishSlotType = |
| 273 | pcie_util::dbusSlotTypeToRf(slotType); |
| 274 | if (!redfishSlotType) |
| 275 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 276 | BMCWEB_LOG_WARNING("Unknown PCIeSlot Type: {}", slotType); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 277 | } |
| 278 | else |
| 279 | { |
| 280 | if (*redfishSlotType == pcie_slots::SlotTypes::Invalid) |
| 281 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 282 | BMCWEB_LOG_ERROR("Invalid PCIeSlot type: {}", slotType); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 283 | messages::internalError(res); |
| 284 | return; |
| 285 | } |
| 286 | res.jsonValue["Slot"]["SlotType"] = *redfishSlotType; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | inline void getPCIeDeviceSlotPath( |
| 291 | const std::string& pcieDevicePath, |
| 292 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 293 | std::function<void(const std::string& pcieDeviceSlot)>&& callback) |
| 294 | { |
| 295 | std::string associationPath = pcieDevicePath + "/contained_by"; |
| 296 | dbus::utility::getAssociatedSubTreePaths( |
| 297 | associationPath, sdbusplus::message::object_path(inventoryPath), 0, |
| 298 | pcieSlotInterface, |
| Ed Tanous | 8cb2c02 | 2024-03-27 16:31:46 -0700 | [diff] [blame] | 299 | [callback = std::move(callback), asyncResp, pcieDevicePath]( |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 300 | const boost::system::error_code& ec, |
| 301 | const dbus::utility::MapperGetSubTreePathsResponse& endpoints) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 302 | if (ec) |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 303 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 304 | if (ec.value() == EBADR) |
| 305 | { |
| 306 | // Missing association is not an error |
| 307 | return; |
| 308 | } |
| 309 | BMCWEB_LOG_ERROR( |
| 310 | "DBUS response error for getAssociatedSubTreePaths {}", |
| 311 | ec.value()); |
| 312 | messages::internalError(asyncResp->res); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 313 | return; |
| 314 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 315 | if (endpoints.size() > 1) |
| 316 | { |
| 317 | BMCWEB_LOG_ERROR( |
| Gunnar Mills | a6bd55b | 2025-01-13 11:24:00 -0600 | [diff] [blame] | 318 | "PCIeDevice {} is associated with more than one PCIeSlot: {}", |
| 319 | pcieDevicePath, endpoints.size()); |
| Myung Bae | 67f0b9c | 2025-06-23 09:52:37 -0400 | [diff] [blame] | 320 | for (const std::string& slotPath : endpoints) |
| 321 | { |
| 322 | BMCWEB_LOG_ERROR("Invalid PCIeSlotPath: {}", slotPath); |
| 323 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 324 | messages::internalError(asyncResp->res); |
| 325 | return; |
| 326 | } |
| 327 | if (endpoints.empty()) |
| 328 | { |
| 329 | // If the device doesn't have an association, return without |
| 330 | // PCIe Slot properties |
| 331 | BMCWEB_LOG_DEBUG("PCIeDevice is not associated with PCIeSlot"); |
| 332 | return; |
| 333 | } |
| 334 | callback(endpoints[0]); |
| 335 | }); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 336 | } |
| 337 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 338 | inline void afterGetDbusObject( |
| 339 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 340 | const std::string& pcieDeviceSlot, const boost::system::error_code& ec, |
| 341 | const dbus::utility::MapperGetObject& object) |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 342 | { |
| 343 | if (ec || object.empty()) |
| 344 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 345 | BMCWEB_LOG_ERROR("DBUS response error for getDbusObject {}", |
| 346 | ec.value()); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 347 | messages::internalError(asyncResp->res); |
| 348 | return; |
| 349 | } |
| Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 350 | dbus::utility::getAllProperties( |
| 351 | object.begin()->first, pcieDeviceSlot, |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 352 | "xyz.openbmc_project.Inventory.Item.PCIeSlot", |
| 353 | [asyncResp]( |
| 354 | const boost::system::error_code& ec2, |
| 355 | const dbus::utility::DBusPropertiesMap& pcieSlotProperties) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 356 | addPCIeSlotProperties(asyncResp->res, ec2, pcieSlotProperties); |
| 357 | }); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | inline void afterGetPCIeDeviceSlotPath( |
| 361 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 362 | const std::string& pcieDeviceSlot) |
| 363 | { |
| 364 | dbus::utility::getDbusObject( |
| 365 | pcieDeviceSlot, pcieSlotInterface, |
| 366 | [asyncResp, |
| 367 | pcieDeviceSlot](const boost::system::error_code& ec, |
| 368 | const dbus::utility::MapperGetObject& object) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 369 | afterGetDbusObject(asyncResp, pcieDeviceSlot, ec, object); |
| 370 | }); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 371 | } |
| 372 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 373 | inline void getPCIeDeviceHealth( |
| 374 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 375 | const std::string& pcieDevicePath, const std::string& service) |
| Lakshmi Yadlapati | e164f1b | 2023-04-12 17:01:34 -0500 | [diff] [blame] | 376 | { |
| Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 377 | dbus::utility::getProperty<bool>( |
| 378 | service, pcieDevicePath, |
| Lakshmi Yadlapati | e164f1b | 2023-04-12 17:01:34 -0500 | [diff] [blame] | 379 | "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", |
| 380 | [asyncResp](const boost::system::error_code& ec, const bool value) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 381 | if (ec) |
| Lakshmi Yadlapati | e164f1b | 2023-04-12 17:01:34 -0500 | [diff] [blame] | 382 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 383 | if (ec.value() != EBADR) |
| 384 | { |
| 385 | BMCWEB_LOG_ERROR("DBUS response error for Health {}", |
| 386 | ec.value()); |
| 387 | messages::internalError(asyncResp->res); |
| 388 | } |
| 389 | return; |
| Lakshmi Yadlapati | e164f1b | 2023-04-12 17:01:34 -0500 | [diff] [blame] | 390 | } |
| Lakshmi Yadlapati | e164f1b | 2023-04-12 17:01:34 -0500 | [diff] [blame] | 391 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 392 | if (!value) |
| 393 | { |
| 394 | asyncResp->res.jsonValue["Status"]["Health"] = |
| 395 | resource::Health::Critical; |
| 396 | } |
| 397 | }); |
| Lakshmi Yadlapati | e164f1b | 2023-04-12 17:01:34 -0500 | [diff] [blame] | 398 | } |
| 399 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 400 | inline void getPCIeDeviceState( |
| 401 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 402 | const std::string& pcieDevicePath, const std::string& service) |
| Lakshmi Yadlapati | c6bb328 | 2023-04-12 16:56:49 -0500 | [diff] [blame] | 403 | { |
| Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 404 | dbus::utility::getProperty<bool>( |
| 405 | service, pcieDevicePath, "xyz.openbmc_project.Inventory.Item", |
| 406 | "Present", |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 407 | [asyncResp](const boost::system::error_code& ec, bool value) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 408 | if (ec) |
| Lakshmi Yadlapati | c6bb328 | 2023-04-12 16:56:49 -0500 | [diff] [blame] | 409 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 410 | if (ec.value() != EBADR) |
| 411 | { |
| 412 | BMCWEB_LOG_ERROR("DBUS response error for State"); |
| 413 | messages::internalError(asyncResp->res); |
| 414 | } |
| 415 | return; |
| Lakshmi Yadlapati | c6bb328 | 2023-04-12 16:56:49 -0500 | [diff] [blame] | 416 | } |
| Lakshmi Yadlapati | c6bb328 | 2023-04-12 16:56:49 -0500 | [diff] [blame] | 417 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 418 | if (!value) |
| 419 | { |
| 420 | asyncResp->res.jsonValue["Status"]["State"] = |
| 421 | resource::State::Absent; |
| 422 | } |
| 423 | }); |
| Lakshmi Yadlapati | c6bb328 | 2023-04-12 16:56:49 -0500 | [diff] [blame] | 424 | } |
| 425 | |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 426 | inline void addPCIeDeviceProperties( |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 427 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 428 | const std::string& pcieDeviceId, |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 429 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) |
| 430 | { |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 431 | const std::string* generationInUse = nullptr; |
| Konstantin Aladyshev | 814bf20 | 2023-07-04 16:30:10 +0300 | [diff] [blame] | 432 | const std::string* generationSupported = nullptr; |
| Konstantin Aladyshev | 9bb0a7f | 2023-07-04 12:59:34 +0300 | [diff] [blame] | 433 | const size_t* lanesInUse = nullptr; |
| Konstantin Aladyshev | 814bf20 | 2023-07-04 16:30:10 +0300 | [diff] [blame] | 434 | const size_t* maxLanes = nullptr; |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 435 | |
| 436 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| Ed Tanous | 609ba4c | 2023-07-11 09:14:24 -0700 | [diff] [blame] | 437 | dbus_utils::UnpackErrorPrinter(), pcieDevProperties, "GenerationInUse", |
| 438 | generationInUse, "GenerationSupported", generationSupported, |
| 439 | "LanesInUse", lanesInUse, "MaxLanes", maxLanes); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 440 | |
| 441 | if (!success) |
| 442 | { |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 443 | messages::internalError(asyncResp->res); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 444 | return; |
| 445 | } |
| 446 | |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 447 | if (generationInUse != nullptr) |
| 448 | { |
| 449 | std::optional<pcie_device::PCIeTypes> redfishGenerationInUse = |
| Lakshmi Yadlapati | c49c329 | 2023-04-19 16:42:35 -0500 | [diff] [blame] | 450 | pcie_util::redfishPcieGenerationFromDbus(*generationInUse); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 451 | |
| 452 | if (!redfishGenerationInUse) |
| 453 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 454 | BMCWEB_LOG_WARNING("Unknown PCIe Device Generation: {}", |
| 455 | *generationInUse); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 456 | } |
| Lakshmi Yadlapati | cf3b484 | 2023-06-27 02:36:53 -0500 | [diff] [blame] | 457 | else |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 458 | { |
| Lakshmi Yadlapati | cf3b484 | 2023-06-27 02:36:53 -0500 | [diff] [blame] | 459 | if (*redfishGenerationInUse == pcie_device::PCIeTypes::Invalid) |
| 460 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 461 | BMCWEB_LOG_ERROR("Invalid PCIe Device Generation: {}", |
| 462 | *generationInUse); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 463 | messages::internalError(asyncResp->res); |
| Lakshmi Yadlapati | cf3b484 | 2023-06-27 02:36:53 -0500 | [diff] [blame] | 464 | return; |
| 465 | } |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 466 | asyncResp->res.jsonValue["PCIeInterface"]["PCIeType"] = |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 467 | *redfishGenerationInUse; |
| 468 | } |
| 469 | } |
| 470 | |
| Konstantin Aladyshev | 814bf20 | 2023-07-04 16:30:10 +0300 | [diff] [blame] | 471 | if (generationSupported != nullptr) |
| 472 | { |
| 473 | std::optional<pcie_device::PCIeTypes> redfishGenerationSupported = |
| 474 | pcie_util::redfishPcieGenerationFromDbus(*generationSupported); |
| 475 | |
| 476 | if (!redfishGenerationSupported) |
| 477 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 478 | BMCWEB_LOG_WARNING("Unknown PCIe Device Generation: {}", |
| 479 | *generationSupported); |
| Konstantin Aladyshev | 814bf20 | 2023-07-04 16:30:10 +0300 | [diff] [blame] | 480 | } |
| 481 | else |
| 482 | { |
| 483 | if (*redfishGenerationSupported == pcie_device::PCIeTypes::Invalid) |
| 484 | { |
| Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 485 | BMCWEB_LOG_ERROR("Invalid PCIe Device Generation: {}", |
| 486 | *generationSupported); |
| Konstantin Aladyshev | 814bf20 | 2023-07-04 16:30:10 +0300 | [diff] [blame] | 487 | messages::internalError(asyncResp->res); |
| 488 | return; |
| 489 | } |
| 490 | asyncResp->res.jsonValue["PCIeInterface"]["MaxPCIeType"] = |
| 491 | *redfishGenerationSupported; |
| 492 | } |
| 493 | } |
| 494 | |
| Myung Bae | 8c1d054 | 2024-03-12 17:50:48 -0500 | [diff] [blame] | 495 | if (lanesInUse != nullptr) |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 496 | { |
| Myung Bae | 8c1d054 | 2024-03-12 17:50:48 -0500 | [diff] [blame] | 497 | if (*lanesInUse == std::numeric_limits<size_t>::max()) |
| 498 | { |
| 499 | // The default value of LanesInUse is "maxint", and the field will |
| 500 | // be null if it is a default value. |
| 501 | asyncResp->res.jsonValue["PCIeInterface"]["LanesInUse"] = nullptr; |
| 502 | } |
| 503 | else |
| 504 | { |
| 505 | asyncResp->res.jsonValue["PCIeInterface"]["LanesInUse"] = |
| 506 | *lanesInUse; |
| 507 | } |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 508 | } |
| Konstantin Aladyshev | 814bf20 | 2023-07-04 16:30:10 +0300 | [diff] [blame] | 509 | // The default value of MaxLanes is 0, and the field will be |
| 510 | // left as off if it is a default value. |
| 511 | if (maxLanes != nullptr && *maxLanes != 0) |
| 512 | { |
| 513 | asyncResp->res.jsonValue["PCIeInterface"]["MaxLanes"] = *maxLanes; |
| 514 | } |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 515 | |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 516 | asyncResp->res.jsonValue["PCIeFunctions"]["@odata.id"] = |
| 517 | boost::urls::format( |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 518 | "/redfish/v1/Systems/{}/PCIeDevices/{}/PCIeFunctions", |
| 519 | BMCWEB_REDFISH_SYSTEM_URI_NAME, pcieDeviceId); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | inline void getPCIeDeviceProperties( |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 523 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 524 | const std::string& pcieDevicePath, const std::string& service, |
| 525 | const std::function<void( |
| 526 | const dbus::utility::DBusPropertiesMap& pcieDevProperties)>&& callback) |
| 527 | { |
| Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 528 | dbus::utility::getAllProperties( |
| 529 | service, pcieDevicePath, |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 530 | "xyz.openbmc_project.Inventory.Item.PCIeDevice", |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 531 | [asyncResp, |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 532 | callback](const boost::system::error_code& ec, |
| 533 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 534 | if (ec) |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 535 | { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 536 | if (ec.value() != EBADR) |
| 537 | { |
| 538 | BMCWEB_LOG_ERROR("DBUS response error for Properties"); |
| 539 | messages::internalError(asyncResp->res); |
| 540 | } |
| 541 | return; |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 542 | } |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 543 | callback(pcieDevProperties); |
| 544 | }); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | inline void addPCIeDeviceCommonProperties( |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 548 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 549 | const std::string& pcieDeviceId) |
| 550 | { |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 551 | asyncResp->res.addHeader( |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 552 | boost::beast::http::field::link, |
| 553 | "</redfish/v1/JsonSchemas/PCIeDevice/PCIeDevice.json>; rel=describedby"); |
| Myung Bae | 9c75bf7 | 2023-12-10 16:38:04 -0500 | [diff] [blame^] | 554 | asyncResp->res.jsonValue["@odata.type"] = "#PCIeDevice.v1_19_0.PCIeDevice"; |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 555 | asyncResp->res.jsonValue["@odata.id"] = |
| 556 | boost::urls::format("/redfish/v1/Systems/{}/PCIeDevices/{}", |
| 557 | BMCWEB_REDFISH_SYSTEM_URI_NAME, pcieDeviceId); |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 558 | asyncResp->res.jsonValue["Name"] = "PCIe Device"; |
| 559 | asyncResp->res.jsonValue["Id"] = pcieDeviceId; |
| Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 560 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
| 561 | asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 562 | } |
| 563 | |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 564 | inline void afterGetValidPcieDevicePath( |
| 565 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 566 | const std::string& pcieDeviceId, const std::string& pcieDevicePath, |
| 567 | const std::string& service) |
| 568 | { |
| 569 | addPCIeDeviceCommonProperties(asyncResp, pcieDeviceId); |
| Myung Bae | f7e62c1 | 2025-09-07 14:02:08 -0500 | [diff] [blame] | 570 | asset_utils::getAssetInfo(asyncResp, service, pcieDevicePath, |
| 571 | ""_json_pointer, true); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 572 | getPCIeDeviceState(asyncResp, pcieDevicePath, service); |
| 573 | getPCIeDeviceHealth(asyncResp, pcieDevicePath, service); |
| 574 | getPCIeDeviceProperties( |
| 575 | asyncResp, pcieDevicePath, service, |
| 576 | std::bind_front(addPCIeDeviceProperties, asyncResp, pcieDeviceId)); |
| Myung Bae | 9c75bf7 | 2023-12-10 16:38:04 -0500 | [diff] [blame^] | 577 | linkAssociatedProcessor(asyncResp, pcieDevicePath); |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 578 | getPCIeDeviceSlotPath( |
| 579 | pcieDevicePath, asyncResp, |
| 580 | std::bind_front(afterGetPCIeDeviceSlotPath, asyncResp)); |
| 581 | } |
| 582 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 583 | inline void handlePCIeDeviceGet( |
| 584 | App& app, const crow::Request& req, |
| 585 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 586 | const std::string& systemName, const std::string& pcieDeviceId) |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 587 | { |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 588 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 589 | { |
| 590 | return; |
| 591 | } |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 592 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 593 | { |
| 594 | // Option currently returns no systems. TBD |
| 595 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 596 | systemName); |
| 597 | return; |
| 598 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 599 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 600 | { |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 601 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 602 | systemName); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 603 | return; |
| 604 | } |
| 605 | |
| 606 | getValidPCIeDevicePath( |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 607 | pcieDeviceId, asyncResp, |
| Lakshmi Yadlapati | a540999 | 2023-04-20 16:53:59 -0500 | [diff] [blame] | 608 | std::bind_front(afterGetValidPcieDevicePath, asyncResp, pcieDeviceId)); |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 609 | } |
| 610 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 611 | inline void requestRoutesSystemPCIeDevice(App& app) |
| Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 612 | { |
| Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 613 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/PCIeDevices/<str>/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 614 | .privileges(redfish::privileges::getPCIeDevice) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 615 | .methods(boost::beast::http::verb::get)( |
| Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 616 | std::bind_front(handlePCIeDeviceGet, std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 619 | inline void addPCIeFunctionList( |
| 620 | crow::Response& res, const std::string& pcieDeviceId, |
| 621 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) |
| 622 | { |
| 623 | nlohmann::json& pcieFunctionList = res.jsonValue["Members"]; |
| 624 | pcieFunctionList = nlohmann::json::array(); |
| 625 | static constexpr const int maxPciFunctionNum = 8; |
| 626 | |
| 627 | for (int functionNum = 0; functionNum < maxPciFunctionNum; functionNum++) |
| 628 | { |
| 629 | // Check if this function exists by |
| 630 | // looking for a device ID |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 631 | std::string devIDProperty = |
| 632 | "Function" + std::to_string(functionNum) + "DeviceId"; |
| Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 633 | const std::string* property = nullptr; |
| 634 | for (const auto& propEntry : pcieDevProperties) |
| 635 | { |
| 636 | if (propEntry.first == devIDProperty) |
| 637 | { |
| 638 | property = std::get_if<std::string>(&propEntry.second); |
| 639 | break; |
| 640 | } |
| 641 | } |
| 642 | if (property == nullptr || property->empty()) |
| 643 | { |
| 644 | continue; |
| 645 | } |
| 646 | |
| 647 | nlohmann::json::object_t pcieFunction; |
| Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 648 | pcieFunction["@odata.id"] = boost::urls::format( |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 649 | "/redfish/v1/Systems/{}/PCIeDevices/{}/PCIeFunctions/{}", |
| 650 | BMCWEB_REDFISH_SYSTEM_URI_NAME, pcieDeviceId, |
| 651 | std::to_string(functionNum)); |
| Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 652 | pcieFunctionList.emplace_back(std::move(pcieFunction)); |
| Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 653 | } |
| 654 | res.jsonValue["PCIeFunctions@odata.count"] = pcieFunctionList.size(); |
| 655 | } |
| 656 | |
| 657 | inline void handlePCIeFunctionCollectionGet( |
| 658 | App& app, const crow::Request& req, |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 659 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 660 | const std::string& systemName, const std::string& pcieDeviceId) |
| Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 661 | { |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 662 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 663 | { |
| 664 | return; |
| 665 | } |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 666 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 667 | { |
| 668 | // Option currently returns no systems. TBD |
| 669 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 670 | systemName); |
| 671 | return; |
| 672 | } |
| Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 673 | |
| 674 | getValidPCIeDevicePath( |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 675 | pcieDeviceId, asyncResp, |
| 676 | [asyncResp, pcieDeviceId](const std::string& pcieDevicePath, |
| 677 | const std::string& service) { |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 678 | asyncResp->res.addHeader( |
| 679 | boost::beast::http::field::link, |
| 680 | "</redfish/v1/JsonSchemas/PCIeFunctionCollection/PCIeFunctionCollection.json>; rel=describedby"); |
| 681 | asyncResp->res.jsonValue["@odata.type"] = |
| 682 | "#PCIeFunctionCollection.PCIeFunctionCollection"; |
| 683 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 684 | "/redfish/v1/Systems/{}/PCIeDevices/{}/PCIeFunctions", |
| 685 | BMCWEB_REDFISH_SYSTEM_URI_NAME, pcieDeviceId); |
| 686 | asyncResp->res.jsonValue["Name"] = "PCIe Function Collection"; |
| 687 | asyncResp->res.jsonValue["Description"] = |
| 688 | "Collection of PCIe Functions for PCIe Device " + pcieDeviceId; |
| 689 | getPCIeDeviceProperties( |
| 690 | asyncResp, pcieDevicePath, service, |
| 691 | [asyncResp, pcieDeviceId]( |
| 692 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) { |
| 693 | addPCIeFunctionList(asyncResp->res, pcieDeviceId, |
| 694 | pcieDevProperties); |
| 695 | }); |
| Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 696 | }); |
| 697 | } |
| 698 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 699 | inline void requestRoutesSystemPCIeFunctionCollection(App& app) |
| 700 | { |
| 701 | /** |
| 702 | * Functions triggers appropriate requests on DBus |
| 703 | */ |
| 704 | BMCWEB_ROUTE(app, |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 705 | "/redfish/v1/Systems/<str>/PCIeDevices/<str>/PCIeFunctions/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 706 | .privileges(redfish::privileges::getPCIeFunctionCollection) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 707 | .methods(boost::beast::http::verb::get)( |
| Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 708 | std::bind_front(handlePCIeFunctionCollectionGet, std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 711 | inline void addPCIeFunctionProperties( |
| Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 712 | crow::Response& resp, uint64_t pcieFunctionId, |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 713 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) |
| 714 | { |
| Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 715 | std::string functionName = "Function" + std::to_string(pcieFunctionId); |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 716 | for (const auto& property : pcieDevProperties) |
| 717 | { |
| 718 | const std::string* strProperty = |
| 719 | std::get_if<std::string>(&property.second); |
| Ed Tanous | dc8cfa6 | 2024-04-07 13:37:25 -0700 | [diff] [blame] | 720 | if (strProperty == nullptr) |
| 721 | { |
| Ed Tanous | dc8cfa6 | 2024-04-07 13:37:25 -0700 | [diff] [blame] | 722 | continue; |
| 723 | } |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 724 | if (property.first == functionName + "DeviceId") |
| 725 | { |
| 726 | resp.jsonValue["DeviceId"] = *strProperty; |
| 727 | } |
| 728 | if (property.first == functionName + "VendorId") |
| 729 | { |
| 730 | resp.jsonValue["VendorId"] = *strProperty; |
| 731 | } |
| 732 | // TODO: FunctionType and DeviceClass are Redfish enums. The D-Bus |
| 733 | // property strings should be mapped correctly to ensure these |
| 734 | // strings are Redfish enum values. For now just check for empty. |
| 735 | if (property.first == functionName + "FunctionType") |
| 736 | { |
| 737 | if (!strProperty->empty()) |
| 738 | { |
| 739 | resp.jsonValue["FunctionType"] = *strProperty; |
| 740 | } |
| 741 | } |
| 742 | if (property.first == functionName + "DeviceClass") |
| 743 | { |
| 744 | if (!strProperty->empty()) |
| 745 | { |
| 746 | resp.jsonValue["DeviceClass"] = *strProperty; |
| 747 | } |
| 748 | } |
| 749 | if (property.first == functionName + "ClassCode") |
| 750 | { |
| 751 | resp.jsonValue["ClassCode"] = *strProperty; |
| 752 | } |
| 753 | if (property.first == functionName + "RevisionId") |
| 754 | { |
| 755 | resp.jsonValue["RevisionId"] = *strProperty; |
| 756 | } |
| 757 | if (property.first == functionName + "SubsystemId") |
| 758 | { |
| 759 | resp.jsonValue["SubsystemId"] = *strProperty; |
| 760 | } |
| 761 | if (property.first == functionName + "SubsystemVendorId") |
| 762 | { |
| 763 | resp.jsonValue["SubsystemVendorId"] = *strProperty; |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | inline void addPCIeFunctionCommonProperties(crow::Response& resp, |
| 769 | const std::string& pcieDeviceId, |
| Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 770 | uint64_t pcieFunctionId) |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 771 | { |
| 772 | resp.addHeader( |
| 773 | boost::beast::http::field::link, |
| 774 | "</redfish/v1/JsonSchemas/PCIeFunction/PCIeFunction.json>; rel=describedby"); |
| 775 | resp.jsonValue["@odata.type"] = "#PCIeFunction.v1_2_3.PCIeFunction"; |
| Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 776 | resp.jsonValue["@odata.id"] = boost::urls::format( |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 777 | "/redfish/v1/Systems/{}/PCIeDevices/{}/PCIeFunctions/{}", |
| 778 | BMCWEB_REDFISH_SYSTEM_URI_NAME, pcieDeviceId, |
| 779 | std::to_string(pcieFunctionId)); |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 780 | resp.jsonValue["Name"] = "PCIe Function"; |
| Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 781 | resp.jsonValue["Id"] = std::to_string(pcieFunctionId); |
| 782 | resp.jsonValue["FunctionId"] = pcieFunctionId; |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 783 | resp.jsonValue["Links"]["PCIeDevice"]["@odata.id"] = |
| 784 | boost::urls::format("/redfish/v1/Systems/{}/PCIeDevices/{}", |
| 785 | BMCWEB_REDFISH_SYSTEM_URI_NAME, pcieDeviceId); |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 786 | } |
| 787 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 788 | inline void handlePCIeFunctionGet( |
| 789 | App& app, const crow::Request& req, |
| 790 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 791 | const std::string& systemName, const std::string& pcieDeviceId, |
| 792 | const std::string& pcieFunctionIdStr) |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 793 | { |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 794 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 795 | { |
| 796 | return; |
| 797 | } |
| Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 798 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 799 | { |
| 800 | // Option currently returns no systems. TBD |
| 801 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 802 | systemName); |
| 803 | return; |
| 804 | } |
| Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 805 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 806 | { |
| 807 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 808 | systemName); |
| 809 | return; |
| 810 | } |
| Ed Tanous | dc8cfa6 | 2024-04-07 13:37:25 -0700 | [diff] [blame] | 811 | std::string_view pcieFunctionIdView = pcieFunctionIdStr; |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 812 | |
| Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 813 | uint64_t pcieFunctionId = 0; |
| 814 | std::from_chars_result result = std::from_chars( |
| Ed Tanous | dc8cfa6 | 2024-04-07 13:37:25 -0700 | [diff] [blame] | 815 | pcieFunctionIdView.begin(), pcieFunctionIdView.end(), pcieFunctionId); |
| 816 | if (result.ec != std::errc{} || result.ptr != pcieFunctionIdView.end()) |
| Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 817 | { |
| Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 818 | messages::resourceNotFound(asyncResp->res, "PCIeFunction", |
| Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 819 | pcieFunctionIdStr); |
| 820 | return; |
| 821 | } |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 822 | |
| Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 823 | getValidPCIeDevicePath( |
| 824 | pcieDeviceId, asyncResp, |
| 825 | [asyncResp, pcieDeviceId, pcieFunctionId]( |
| 826 | const std::string& pcieDevicePath, const std::string& service) { |
| 827 | getPCIeDeviceProperties( |
| 828 | asyncResp, pcieDevicePath, service, |
| 829 | [asyncResp, pcieDeviceId, pcieFunctionId]( |
| 830 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) { |
| 831 | addPCIeFunctionCommonProperties( |
| 832 | asyncResp->res, pcieDeviceId, pcieFunctionId); |
| 833 | addPCIeFunctionProperties(asyncResp->res, pcieFunctionId, |
| 834 | pcieDevProperties); |
| 835 | }); |
| Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 836 | }); |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 837 | } |
| 838 | |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 839 | inline void requestRoutesSystemPCIeFunction(App& app) |
| 840 | { |
| 841 | BMCWEB_ROUTE( |
| Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 842 | app, "/redfish/v1/Systems/<str>/PCIeDevices/<str>/PCIeFunctions/<str>/") |
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 843 | .privileges(redfish::privileges::getPCIeFunction) |
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 844 | .methods(boost::beast::http::verb::get)( |
| Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 845 | std::bind_front(handlePCIeFunctionGet, std::ref(app))); |
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 846 | } |
| Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 847 | |
| 848 | } // namespace redfish |