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