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