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"}; |
Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 38 | |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 39 | static inline void handlePCIeDevicePath( |
| 40 | const std::string& pcieDeviceId, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 41 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 42 | const dbus::utility::MapperGetSubTreePathsResponse& pcieDevicePaths, |
| 43 | const std::function<void(const std::string& pcieDevicePath, |
| 44 | const std::string& service)>& callback) |
| 45 | |
| 46 | { |
| 47 | for (const std::string& pcieDevicePath : pcieDevicePaths) |
| 48 | { |
| 49 | std::string pciecDeviceName = |
| 50 | sdbusplus::message::object_path(pcieDevicePath).filename(); |
| 51 | if (pciecDeviceName.empty() || pciecDeviceName != pcieDeviceId) |
| 52 | { |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | dbus::utility::getDbusObject( |
| 57 | pcieDevicePath, {}, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 58 | [pcieDevicePath, asyncResp, |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 59 | callback](const boost::system::error_code& ec, |
| 60 | const dbus::utility::MapperGetObject& object) { |
| 61 | if (ec || object.empty()) |
| 62 | { |
| 63 | BMCWEB_LOG_ERROR << "DBUS response error " << ec; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 64 | messages::internalError(asyncResp->res); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | callback(pcieDevicePath, object.begin()->first); |
| 68 | }); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | BMCWEB_LOG_WARNING << "PCIe Device not found"; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 73 | messages::resourceNotFound(asyncResp->res, "PCIeDevice", pcieDeviceId); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static inline void getValidPCIeDevicePath( |
| 77 | const std::string& pcieDeviceId, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 78 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 79 | const std::function<void(const std::string& pcieDevicePath, |
| 80 | const std::string& service)>& callback) |
| 81 | { |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 82 | dbus::utility::getSubTreePaths( |
Lakshmi Yadlapati | 94c3a10 | 2023-04-05 18:11:22 -0500 | [diff] [blame] | 83 | inventoryPath, 0, pcieDeviceInterface, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 84 | [pcieDeviceId, asyncResp, |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 85 | callback](const boost::system::error_code& ec, |
| 86 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 87 | pcieDevicePaths) { |
| 88 | if (ec) |
| 89 | { |
| 90 | BMCWEB_LOG_ERROR << "D-Bus response error on GetSubTree " << ec; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 91 | messages::internalError(asyncResp->res); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 92 | return; |
| 93 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 94 | handlePCIeDevicePath(pcieDeviceId, asyncResp, pcieDevicePaths, |
| 95 | callback); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 96 | return; |
| 97 | }); |
| 98 | } |
| 99 | |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 100 | static inline void handlePCIeDeviceCollectionGet( |
| 101 | crow::App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 102 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 103 | const std::string& systemName) |
| 104 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 105 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 106 | { |
| 107 | return; |
| 108 | } |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 109 | if constexpr (bmcwebEnableMultiHost) |
| 110 | { |
| 111 | // Option currently returns no systems. TBD |
| 112 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 113 | systemName); |
| 114 | return; |
| 115 | } |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 116 | if (systemName != "system") |
| 117 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 118 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 119 | systemName); |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 120 | return; |
| 121 | } |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 122 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 123 | asyncResp->res.addHeader(boost::beast::http::field::link, |
| 124 | "</redfish/v1/JsonSchemas/PCIeDeviceCollection/" |
| 125 | "PCIeDeviceCollection.json>; rel=describedby"); |
| 126 | asyncResp->res.jsonValue["@odata.type"] = |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 127 | "#PCIeDeviceCollection.PCIeDeviceCollection"; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 128 | asyncResp->res.jsonValue["@odata.id"] = |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 129 | "/redfish/v1/Systems/system/PCIeDevices"; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 130 | asyncResp->res.jsonValue["Name"] = "PCIe Device Collection"; |
| 131 | asyncResp->res.jsonValue["Description"] = "Collection of PCIe Devices"; |
| 132 | asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); |
| 133 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 134 | |
Lakshmi Yadlapati | 9e9325e | 2023-05-02 10:30:44 -0500 | [diff] [blame] | 135 | pcie_util::getPCIeDeviceList(asyncResp, "Members"); |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 136 | } |
| 137 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 138 | inline void requestRoutesSystemPCIeDeviceCollection(App& app) |
Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 139 | { |
Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Functions triggers appropriate requests on DBus |
| 142 | */ |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 143 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/PCIeDevices/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 144 | .privileges(redfish::privileges::getPCIeDeviceCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 145 | .methods(boost::beast::http::verb::get)( |
Lakshmi Yadlapati | b38fa2a | 2023-03-10 16:19:46 -0600 | [diff] [blame] | 146 | std::bind_front(handlePCIeDeviceCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 149 | inline void |
Lakshmi Yadlapati | e164f1b | 2023-04-12 17:01:34 -0500 | [diff] [blame] | 150 | getPCIeDeviceHealth(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 151 | const std::string& pcieDevicePath, |
| 152 | const std::string& service) |
| 153 | { |
| 154 | sdbusplus::asio::getProperty<bool>( |
| 155 | *crow::connections::systemBus, service, pcieDevicePath, |
| 156 | "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", |
| 157 | [asyncResp](const boost::system::error_code& ec, const bool value) { |
| 158 | if (ec) |
| 159 | { |
| 160 | if (ec.value() != EBADR) |
| 161 | { |
| 162 | BMCWEB_LOG_ERROR << "DBUS response error for Health " |
| 163 | << ec.value(); |
| 164 | messages::internalError(asyncResp->res); |
| 165 | } |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | if (!value) |
| 170 | { |
| 171 | asyncResp->res.jsonValue["Status"]["Health"] = "Critical"; |
| 172 | } |
| 173 | }); |
| 174 | } |
| 175 | |
| 176 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 177 | getPCIeDeviceState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 178 | const std::string& pcieDevicePath, |
| 179 | const std::string& service) |
Lakshmi Yadlapati | c6bb328 | 2023-04-12 16:56:49 -0500 | [diff] [blame] | 180 | { |
| 181 | sdbusplus::asio::getProperty<bool>( |
| 182 | *crow::connections::systemBus, service, pcieDevicePath, |
| 183 | "xyz.openbmc_project.Inventory.Item", "Present", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 184 | [asyncResp](const boost::system::error_code& ec, const bool value) { |
Lakshmi Yadlapati | c6bb328 | 2023-04-12 16:56:49 -0500 | [diff] [blame] | 185 | if (ec) |
| 186 | { |
| 187 | if (ec.value() != EBADR) |
| 188 | { |
| 189 | BMCWEB_LOG_ERROR << "DBUS response error for State"; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 190 | messages::internalError(asyncResp->res); |
Lakshmi Yadlapati | c6bb328 | 2023-04-12 16:56:49 -0500 | [diff] [blame] | 191 | } |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | if (!value) |
| 196 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 197 | asyncResp->res.jsonValue["Status"]["State"] = "Absent"; |
Lakshmi Yadlapati | c6bb328 | 2023-04-12 16:56:49 -0500 | [diff] [blame] | 198 | } |
| 199 | }); |
| 200 | } |
| 201 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 202 | inline void |
| 203 | getPCIeDeviceAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 204 | const std::string& pcieDevicePath, |
| 205 | const std::string& service) |
SunnySrivastava1984 | 913e773 | 2021-01-27 06:23:24 -0600 | [diff] [blame] | 206 | { |
| 207 | sdbusplus::asio::getAllProperties( |
| 208 | *crow::connections::systemBus, service, pcieDevicePath, |
| 209 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 210 | [pcieDevicePath, asyncResp{asyncResp}]( |
| 211 | const boost::system::error_code& ec, |
| 212 | const dbus::utility::DBusPropertiesMap& assetList) { |
SunnySrivastava1984 | 913e773 | 2021-01-27 06:23:24 -0600 | [diff] [blame] | 213 | if (ec) |
| 214 | { |
| 215 | if (ec.value() != EBADR) |
| 216 | { |
| 217 | BMCWEB_LOG_ERROR << "DBUS response error for Properties" |
| 218 | << ec.value(); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 219 | messages::internalError(asyncResp->res); |
SunnySrivastava1984 | 913e773 | 2021-01-27 06:23:24 -0600 | [diff] [blame] | 220 | } |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | const std::string* manufacturer = nullptr; |
| 225 | const std::string* model = nullptr; |
| 226 | const std::string* partNumber = nullptr; |
| 227 | const std::string* serialNumber = nullptr; |
| 228 | const std::string* sparePartNumber = nullptr; |
| 229 | |
| 230 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 231 | dbus_utils::UnpackErrorPrinter(), assetList, "Manufacturer", |
| 232 | manufacturer, "Model", model, "PartNumber", partNumber, |
| 233 | "SerialNumber", serialNumber, "SparePartNumber", sparePartNumber); |
| 234 | |
| 235 | if (!success) |
| 236 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 237 | messages::internalError(asyncResp->res); |
SunnySrivastava1984 | 913e773 | 2021-01-27 06:23:24 -0600 | [diff] [blame] | 238 | return; |
| 239 | } |
| 240 | |
| 241 | if (manufacturer != nullptr) |
| 242 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 243 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
SunnySrivastava1984 | 913e773 | 2021-01-27 06:23:24 -0600 | [diff] [blame] | 244 | } |
| 245 | if (model != nullptr) |
| 246 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 247 | asyncResp->res.jsonValue["Model"] = *model; |
SunnySrivastava1984 | 913e773 | 2021-01-27 06:23:24 -0600 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | if (partNumber != nullptr) |
| 251 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 252 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
SunnySrivastava1984 | 913e773 | 2021-01-27 06:23:24 -0600 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | if (serialNumber != nullptr) |
| 256 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 257 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
SunnySrivastava1984 | 913e773 | 2021-01-27 06:23:24 -0600 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | if (sparePartNumber != nullptr && !sparePartNumber->empty()) |
| 261 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 262 | asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; |
SunnySrivastava1984 | 913e773 | 2021-01-27 06:23:24 -0600 | [diff] [blame] | 263 | } |
| 264 | }); |
| 265 | } |
| 266 | |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 267 | inline void addPCIeDeviceProperties( |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 268 | crow::Response& resp, const std::string& pcieDeviceId, |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 269 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) |
| 270 | { |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 271 | const std::string* deviceType = nullptr; |
| 272 | const std::string* generationInUse = nullptr; |
| 273 | const int64_t* lanesInUse = nullptr; |
| 274 | |
| 275 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 276 | dbus_utils::UnpackErrorPrinter(), pcieDevProperties, "DeviceType", |
| 277 | deviceType, "GenerationInUse", generationInUse, "LanesInUse", |
Lakshmi Yadlapati | bad2c4a | 2023-04-07 09:14:37 -0500 | [diff] [blame] | 278 | lanesInUse); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 279 | |
| 280 | if (!success) |
| 281 | { |
| 282 | messages::internalError(resp); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | if (deviceType != nullptr && !deviceType->empty()) |
| 287 | { |
| 288 | resp.jsonValue["PCIeInterface"]["DeviceType"] = *deviceType; |
| 289 | } |
| 290 | |
| 291 | if (generationInUse != nullptr) |
| 292 | { |
| 293 | std::optional<pcie_device::PCIeTypes> redfishGenerationInUse = |
Lakshmi Yadlapati | c49c329 | 2023-04-19 16:42:35 -0500 | [diff] [blame] | 294 | pcie_util::redfishPcieGenerationFromDbus(*generationInUse); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 295 | |
| 296 | if (!redfishGenerationInUse) |
| 297 | { |
Lakshmi Yadlapati | cf3b484 | 2023-06-27 02:36:53 -0500 | [diff] [blame^] | 298 | BMCWEB_LOG_WARNING << "Unknown PCIe Device Generation: " |
| 299 | << *generationInUse; |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 300 | } |
Lakshmi Yadlapati | cf3b484 | 2023-06-27 02:36:53 -0500 | [diff] [blame^] | 301 | else |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 302 | { |
Lakshmi Yadlapati | cf3b484 | 2023-06-27 02:36:53 -0500 | [diff] [blame^] | 303 | if (*redfishGenerationInUse == pcie_device::PCIeTypes::Invalid) |
| 304 | { |
| 305 | BMCWEB_LOG_ERROR << "Invalid PCIe Device Generation: " |
| 306 | << *generationInUse; |
| 307 | messages::internalError(resp); |
| 308 | return; |
| 309 | } |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 310 | resp.jsonValue["PCIeInterface"]["PCIeType"] = |
| 311 | *redfishGenerationInUse; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | // The default value of LanesInUse is 0, and the field will be |
| 316 | // left as off if it is a default value. |
| 317 | if (lanesInUse != nullptr && *lanesInUse != 0) |
| 318 | { |
| 319 | resp.jsonValue["PCIeInterface"]["LanesInUse"] = *lanesInUse; |
| 320 | } |
| 321 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 322 | resp.jsonValue["PCIeFunctions"]["@odata.id"] = boost::urls::format( |
| 323 | "/redfish/v1/Systems/system/PCIeDevices/{}/PCIeFunctions", |
| 324 | pcieDeviceId); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | inline void getPCIeDeviceProperties( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 328 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 329 | const std::string& pcieDevicePath, const std::string& service, |
| 330 | const std::function<void( |
| 331 | const dbus::utility::DBusPropertiesMap& pcieDevProperties)>&& callback) |
| 332 | { |
| 333 | sdbusplus::asio::getAllProperties( |
| 334 | *crow::connections::systemBus, service, pcieDevicePath, |
| 335 | "xyz.openbmc_project.Inventory.Item.PCIeDevice", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 336 | [asyncResp, |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 337 | callback](const boost::system::error_code& ec, |
| 338 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) { |
| 339 | if (ec) |
| 340 | { |
| 341 | if (ec.value() != EBADR) |
| 342 | { |
| 343 | BMCWEB_LOG_ERROR << "DBUS response error for Properties"; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 344 | messages::internalError(asyncResp->res); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 345 | } |
| 346 | return; |
| 347 | } |
| 348 | callback(pcieDevProperties); |
| 349 | }); |
| 350 | } |
| 351 | |
| 352 | inline void addPCIeDeviceCommonProperties( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 353 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 354 | const std::string& pcieDeviceId) |
| 355 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 356 | asyncResp->res.addHeader( |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 357 | boost::beast::http::field::link, |
| 358 | "</redfish/v1/JsonSchemas/PCIeDevice/PCIeDevice.json>; rel=describedby"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 359 | asyncResp->res.jsonValue["@odata.type"] = "#PCIeDevice.v1_9_0.PCIeDevice"; |
| 360 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 361 | "/redfish/v1/Systems/system/PCIeDevices/{}", pcieDeviceId); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 362 | asyncResp->res.jsonValue["Name"] = "PCIe Device"; |
| 363 | asyncResp->res.jsonValue["Id"] = pcieDeviceId; |
| 364 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
Lakshmi Yadlapati | e164f1b | 2023-04-12 17:01:34 -0500 | [diff] [blame] | 365 | asyncResp->res.jsonValue["Status"]["Health"] = "OK"; |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 366 | } |
| 367 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 368 | inline void |
| 369 | handlePCIeDeviceGet(App& app, const crow::Request& req, |
| 370 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 371 | const std::string& systemName, |
| 372 | const std::string& pcieDeviceId) |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 373 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 374 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 375 | { |
| 376 | return; |
| 377 | } |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 378 | if constexpr (bmcwebEnableMultiHost) |
| 379 | { |
| 380 | // Option currently returns no systems. TBD |
| 381 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 382 | systemName); |
| 383 | return; |
| 384 | } |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 385 | if (systemName != "system") |
| 386 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 387 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 388 | systemName); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 389 | return; |
| 390 | } |
| 391 | |
| 392 | getValidPCIeDevicePath( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 393 | pcieDeviceId, asyncResp, |
| 394 | [asyncResp, pcieDeviceId](const std::string& pcieDevicePath, |
| 395 | const std::string& service) { |
| 396 | addPCIeDeviceCommonProperties(asyncResp, pcieDeviceId); |
| 397 | getPCIeDeviceAsset(asyncResp, pcieDevicePath, service); |
| 398 | getPCIeDeviceState(asyncResp, pcieDevicePath, service); |
Lakshmi Yadlapati | e164f1b | 2023-04-12 17:01:34 -0500 | [diff] [blame] | 399 | getPCIeDeviceHealth(asyncResp, pcieDevicePath, service); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 400 | getPCIeDeviceProperties( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 401 | asyncResp, pcieDevicePath, service, |
| 402 | [asyncResp, pcieDeviceId]( |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 403 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 404 | addPCIeDeviceProperties(asyncResp->res, pcieDeviceId, |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 405 | pcieDevProperties); |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 406 | }); |
| 407 | }); |
| 408 | } |
| 409 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 410 | inline void requestRoutesSystemPCIeDevice(App& app) |
Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 411 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 412 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/PCIeDevices/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 413 | .privileges(redfish::privileges::getPCIeDevice) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 414 | .methods(boost::beast::http::verb::get)( |
Lakshmi Yadlapati | 543f9a7 | 2023-03-10 17:06:05 -0600 | [diff] [blame] | 415 | std::bind_front(handlePCIeDeviceGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 418 | inline void addPCIeFunctionList( |
| 419 | crow::Response& res, const std::string& pcieDeviceId, |
| 420 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) |
| 421 | { |
| 422 | nlohmann::json& pcieFunctionList = res.jsonValue["Members"]; |
| 423 | pcieFunctionList = nlohmann::json::array(); |
| 424 | static constexpr const int maxPciFunctionNum = 8; |
| 425 | |
| 426 | for (int functionNum = 0; functionNum < maxPciFunctionNum; functionNum++) |
| 427 | { |
| 428 | // Check if this function exists by |
| 429 | // looking for a device ID |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 430 | std::string devIDProperty = "Function" + std::to_string(functionNum) + |
| 431 | "DeviceId"; |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 432 | const std::string* property = nullptr; |
| 433 | for (const auto& propEntry : pcieDevProperties) |
| 434 | { |
| 435 | if (propEntry.first == devIDProperty) |
| 436 | { |
| 437 | property = std::get_if<std::string>(&propEntry.second); |
| 438 | break; |
| 439 | } |
| 440 | } |
| 441 | if (property == nullptr || property->empty()) |
| 442 | { |
| 443 | continue; |
| 444 | } |
| 445 | |
| 446 | nlohmann::json::object_t pcieFunction; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 447 | pcieFunction["@odata.id"] = boost::urls::format( |
| 448 | "/redfish/v1/Systems/system/PCIeDevices/{}/PCIeFunctions/{}", |
| 449 | pcieDeviceId, std::to_string(functionNum)); |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 450 | pcieFunctionList.emplace_back(std::move(pcieFunction)); |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 451 | } |
| 452 | res.jsonValue["PCIeFunctions@odata.count"] = pcieFunctionList.size(); |
| 453 | } |
| 454 | |
| 455 | inline void handlePCIeFunctionCollectionGet( |
| 456 | App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 457 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 458 | const std::string& systemName, const std::string& pcieDeviceId) |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 459 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 460 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 461 | { |
| 462 | return; |
| 463 | } |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 464 | if constexpr (bmcwebEnableMultiHost) |
| 465 | { |
| 466 | // Option currently returns no systems. TBD |
| 467 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 468 | systemName); |
| 469 | return; |
| 470 | } |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 471 | |
| 472 | getValidPCIeDevicePath( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 473 | pcieDeviceId, asyncResp, |
| 474 | [asyncResp, pcieDeviceId](const std::string& pcieDevicePath, |
| 475 | const std::string& service) { |
| 476 | asyncResp->res.addHeader( |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 477 | boost::beast::http::field::link, |
| 478 | "</redfish/v1/JsonSchemas/PCIeFunctionCollection/PCIeFunctionCollection.json>; rel=describedby"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 479 | asyncResp->res.jsonValue["@odata.type"] = |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 480 | "#PCIeFunctionCollection.PCIeFunctionCollection"; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 481 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 482 | "/redfish/v1/Systems/system/PCIeDevices/{}/PCIeFunctions", |
| 483 | pcieDeviceId); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 484 | asyncResp->res.jsonValue["Name"] = "PCIe Function Collection"; |
| 485 | asyncResp->res.jsonValue["Description"] = |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 486 | "Collection of PCIe Functions for PCIe Device " + pcieDeviceId; |
| 487 | getPCIeDeviceProperties( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 488 | asyncResp, pcieDevicePath, service, |
| 489 | [asyncResp, pcieDeviceId]( |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 490 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 491 | addPCIeFunctionList(asyncResp->res, pcieDeviceId, |
| 492 | pcieDevProperties); |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 493 | }); |
| 494 | }); |
| 495 | } |
| 496 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 497 | inline void requestRoutesSystemPCIeFunctionCollection(App& app) |
| 498 | { |
| 499 | /** |
| 500 | * Functions triggers appropriate requests on DBus |
| 501 | */ |
| 502 | BMCWEB_ROUTE(app, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 503 | "/redfish/v1/Systems/<str>/PCIeDevices/<str>/PCIeFunctions/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 504 | .privileges(redfish::privileges::getPCIeFunctionCollection) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 505 | .methods(boost::beast::http::verb::get)( |
Lakshmi Yadlapati | 35ad613 | 2023-03-10 22:31:49 -0600 | [diff] [blame] | 506 | std::bind_front(handlePCIeFunctionCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 509 | inline bool validatePCIeFunctionId( |
Myung Bae | d5e74b8 | 2023-05-31 11:28:02 -0500 | [diff] [blame] | 510 | uint64_t pcieFunctionId, |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 511 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) |
| 512 | { |
Myung Bae | d5e74b8 | 2023-05-31 11:28:02 -0500 | [diff] [blame] | 513 | std::string functionName = "Function" + std::to_string(pcieFunctionId); |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 514 | std::string devIDProperty = functionName + "DeviceId"; |
| 515 | |
| 516 | const std::string* devIdProperty = nullptr; |
| 517 | for (const auto& property : pcieDevProperties) |
| 518 | { |
| 519 | if (property.first == devIDProperty) |
| 520 | { |
| 521 | devIdProperty = std::get_if<std::string>(&property.second); |
| 522 | break; |
| 523 | } |
| 524 | } |
| 525 | return (devIdProperty != nullptr && !devIdProperty->empty()); |
| 526 | } |
| 527 | |
| 528 | inline void addPCIeFunctionProperties( |
Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 529 | crow::Response& resp, uint64_t pcieFunctionId, |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 530 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) |
| 531 | { |
Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 532 | std::string functionName = "Function" + std::to_string(pcieFunctionId); |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 533 | for (const auto& property : pcieDevProperties) |
| 534 | { |
| 535 | const std::string* strProperty = |
| 536 | std::get_if<std::string>(&property.second); |
| 537 | |
| 538 | if (property.first == functionName + "DeviceId") |
| 539 | { |
| 540 | resp.jsonValue["DeviceId"] = *strProperty; |
| 541 | } |
| 542 | if (property.first == functionName + "VendorId") |
| 543 | { |
| 544 | resp.jsonValue["VendorId"] = *strProperty; |
| 545 | } |
| 546 | // TODO: FunctionType and DeviceClass are Redfish enums. The D-Bus |
| 547 | // property strings should be mapped correctly to ensure these |
| 548 | // strings are Redfish enum values. For now just check for empty. |
| 549 | if (property.first == functionName + "FunctionType") |
| 550 | { |
| 551 | if (!strProperty->empty()) |
| 552 | { |
| 553 | resp.jsonValue["FunctionType"] = *strProperty; |
| 554 | } |
| 555 | } |
| 556 | if (property.first == functionName + "DeviceClass") |
| 557 | { |
| 558 | if (!strProperty->empty()) |
| 559 | { |
| 560 | resp.jsonValue["DeviceClass"] = *strProperty; |
| 561 | } |
| 562 | } |
| 563 | if (property.first == functionName + "ClassCode") |
| 564 | { |
| 565 | resp.jsonValue["ClassCode"] = *strProperty; |
| 566 | } |
| 567 | if (property.first == functionName + "RevisionId") |
| 568 | { |
| 569 | resp.jsonValue["RevisionId"] = *strProperty; |
| 570 | } |
| 571 | if (property.first == functionName + "SubsystemId") |
| 572 | { |
| 573 | resp.jsonValue["SubsystemId"] = *strProperty; |
| 574 | } |
| 575 | if (property.first == functionName + "SubsystemVendorId") |
| 576 | { |
| 577 | resp.jsonValue["SubsystemVendorId"] = *strProperty; |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | inline void addPCIeFunctionCommonProperties(crow::Response& resp, |
| 583 | const std::string& pcieDeviceId, |
Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 584 | uint64_t pcieFunctionId) |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 585 | { |
| 586 | resp.addHeader( |
| 587 | boost::beast::http::field::link, |
| 588 | "</redfish/v1/JsonSchemas/PCIeFunction/PCIeFunction.json>; rel=describedby"); |
| 589 | resp.jsonValue["@odata.type"] = "#PCIeFunction.v1_2_3.PCIeFunction"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 590 | resp.jsonValue["@odata.id"] = boost::urls::format( |
| 591 | "/redfish/v1/Systems/system/PCIeDevices/{}/PCIeFunctions/{}", |
Lakshmi Yadlapati | 768a143 | 2023-06-14 12:45:54 -0500 | [diff] [blame] | 592 | pcieDeviceId, std::to_string(pcieFunctionId)); |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 593 | resp.jsonValue["Name"] = "PCIe Function"; |
Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 594 | resp.jsonValue["Id"] = std::to_string(pcieFunctionId); |
| 595 | resp.jsonValue["FunctionId"] = pcieFunctionId; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 596 | resp.jsonValue["Links"]["PCIeDevice"]["@odata.id"] = boost::urls::format( |
| 597 | "/redfish/v1/Systems/system/PCIeDevices/{}", pcieDeviceId); |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | inline void |
| 601 | handlePCIeFunctionGet(App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 602 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 603 | const std::string& systemName, |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 604 | const std::string& pcieDeviceId, |
Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 605 | const std::string& pcieFunctionIdStr) |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 606 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 607 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 608 | { |
| 609 | return; |
| 610 | } |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 611 | if constexpr (bmcwebEnableMultiHost) |
| 612 | { |
| 613 | // Option currently returns no systems. TBD |
| 614 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 615 | systemName); |
| 616 | return; |
| 617 | } |
| 618 | if (systemName != "system") |
| 619 | { |
| 620 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 621 | systemName); |
| 622 | return; |
| 623 | } |
| 624 | |
Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 625 | uint64_t pcieFunctionId = 0; |
| 626 | std::from_chars_result result = std::from_chars( |
| 627 | &*pcieFunctionIdStr.begin(), &*pcieFunctionIdStr.end(), pcieFunctionId); |
| 628 | if (result.ec != std::errc{} || result.ptr != &*pcieFunctionIdStr.end()) |
| 629 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 630 | messages::resourceNotFound(asyncResp->res, "PCIeFunction", |
Ed Tanous | e14742c | 2023-05-31 10:27:49 -0700 | [diff] [blame] | 631 | pcieFunctionIdStr); |
| 632 | return; |
| 633 | } |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 634 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 635 | getValidPCIeDevicePath(pcieDeviceId, asyncResp, |
| 636 | [asyncResp, pcieDeviceId, |
| 637 | pcieFunctionId](const std::string& pcieDevicePath, |
| 638 | const std::string& service) { |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 639 | getPCIeDeviceProperties( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 640 | asyncResp, pcieDevicePath, service, |
| 641 | [asyncResp, pcieDeviceId, pcieFunctionId]( |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 642 | const dbus::utility::DBusPropertiesMap& pcieDevProperties) { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 643 | addPCIeFunctionCommonProperties(asyncResp->res, pcieDeviceId, |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 644 | pcieFunctionId); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 645 | addPCIeFunctionProperties(asyncResp->res, pcieFunctionId, |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 646 | pcieDevProperties); |
| 647 | }); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 648 | }); |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 649 | } |
| 650 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 651 | inline void requestRoutesSystemPCIeFunction(App& app) |
| 652 | { |
| 653 | BMCWEB_ROUTE( |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 654 | app, "/redfish/v1/Systems/<str>/PCIeDevices/<str>/PCIeFunctions/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 655 | .privileges(redfish::privileges::getPCIeFunction) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 656 | .methods(boost::beast::http::verb::get)( |
Lakshmi Yadlapati | 727a046 | 2023-03-10 23:49:00 -0600 | [diff] [blame] | 657 | std::bind_front(handlePCIeFunctionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 658 | } |
Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 659 | |
| 660 | } // namespace redfish |