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