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