diff options
-rw-r--r-- | redfish-core/lib/pcie.hpp | 161 |
1 files changed, 81 insertions, 80 deletions
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp index 969e1fae84..4bf5626aba 100644 --- a/redfish-core/lib/pcie.hpp +++ b/redfish-core/lib/pcie.hpp @@ -224,7 +224,7 @@ inline std::optional<pcie_device::PCIeTypes> } inline void addPCIeDeviceProperties( - crow::Response& resp, + crow::Response& resp, const std::string& pcieDeviceId, const dbus::utility::DBusPropertiesMap& pcieDevProperties) { const std::string* manufacturer = nullptr; @@ -276,6 +276,10 @@ inline void addPCIeDeviceProperties( { resp.jsonValue["PCIeInterface"]["Manufacturer"] = *manufacturer; } + + resp.jsonValue["PCIeFunctions"]["@odata.id"] = crow::utility::urlFromPieces( + "redfish", "v1", "Systems", "system", "PCIeDevices", pcieDeviceId, + "PCIeFunctions"); } inline void getPCIeDeviceProperties( @@ -339,8 +343,10 @@ inline void handlePCIeDeviceGet(App& app, const crow::Request& req, addPCIeDeviceCommonProperties(aResp, pcieDeviceId); getPCIeDeviceProperties( aResp, pcieDevicePath, service, - [aResp](const dbus::utility::DBusPropertiesMap& pcieDevProperties) { - addPCIeDeviceProperties(aResp->res, pcieDevProperties); + [aResp, pcieDeviceId]( + const dbus::utility::DBusPropertiesMap& pcieDevProperties) { + addPCIeDeviceProperties(aResp->res, pcieDeviceId, + pcieDevProperties); }); }); } @@ -353,6 +359,77 @@ inline void requestRoutesSystemPCIeDevice(App& app) std::bind_front(handlePCIeDeviceGet, std::ref(app))); } +inline void addPCIeFunctionList( + crow::Response& res, const std::string& pcieDeviceId, + const dbus::utility::DBusPropertiesMap& pcieDevProperties) +{ + nlohmann::json& pcieFunctionList = res.jsonValue["Members"]; + pcieFunctionList = nlohmann::json::array(); + static constexpr const int maxPciFunctionNum = 8; + + for (int functionNum = 0; functionNum < maxPciFunctionNum; functionNum++) + { + // Check if this function exists by + // looking for a device ID + std::string devIDProperty = + "Function" + std::to_string(functionNum) + "DeviceId"; + const std::string* property = nullptr; + for (const auto& propEntry : pcieDevProperties) + { + if (propEntry.first == devIDProperty) + { + property = std::get_if<std::string>(&propEntry.second); + break; + } + } + if (property == nullptr || property->empty()) + { + continue; + } + + nlohmann::json::object_t pcieFunction; + pcieFunction["@odata.id"] = crow::utility::urlFromPieces( + "redfish", "v1", "Systems", "system", "PCIeDevices", pcieDeviceId, + "PCIeFunctions", std::to_string(functionNum)); + pcieFunctionList.push_back(std::move(pcieFunction)); + } + res.jsonValue["PCIeFunctions@odata.count"] = pcieFunctionList.size(); +} + +inline void handlePCIeFunctionCollectionGet( + App& app, const crow::Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& aResp, + const std::string& pcieDeviceId) +{ + if (!redfish::setUpRedfishRoute(app, req, aResp)) + { + return; + } + + getValidPCIeDevicePath( + pcieDeviceId, aResp, + [aResp, pcieDeviceId](const std::string& pcieDevicePath, + const std::string& service) { + aResp->res.addHeader( + boost::beast::http::field::link, + "</redfish/v1/JsonSchemas/PCIeFunctionCollection/PCIeFunctionCollection.json>; rel=describedby"); + aResp->res.jsonValue["@odata.type"] = + "#PCIeFunctionCollection.PCIeFunctionCollection"; + aResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( + "redfish", "v1", "Systems", "system", "PCIeDevices", pcieDeviceId, + "PCIeFunctions"); + aResp->res.jsonValue["Name"] = "PCIe Function Collection"; + aResp->res.jsonValue["Description"] = + "Collection of PCIe Functions for PCIe Device " + pcieDeviceId; + getPCIeDeviceProperties( + aResp, pcieDevicePath, service, + [aResp, pcieDeviceId]( + const dbus::utility::DBusPropertiesMap& pcieDevProperties) { + addPCIeFunctionList(aResp->res, pcieDeviceId, pcieDevProperties); + }); + }); +} + inline void requestRoutesSystemPCIeFunctionCollection(App& app) { /** @@ -362,83 +439,7 @@ inline void requestRoutesSystemPCIeFunctionCollection(App& app) "/redfish/v1/Systems/system/PCIeDevices/<str>/PCIeFunctions/") .privileges(redfish::privileges::getPCIeFunctionCollection) .methods(boost::beast::http::verb::get)( - [&app](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& device) { - if (!redfish::setUpRedfishRoute(app, req, asyncResp)) - { - return; - } - - asyncResp->res.jsonValue["@odata.type"] = - "#PCIeFunctionCollection.PCIeFunctionCollection"; - asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( - "redfish", "v1", "Systems", "system", "PCIeDevices", device, - "PCIeFunctions"); - asyncResp->res.jsonValue["Name"] = "PCIe Function Collection"; - asyncResp->res.jsonValue["Description"] = - "Collection of PCIe Functions for PCIe Device " + device; - - auto getPCIeDeviceCallback = - [asyncResp, device]( - const boost::system::error_code& ec, - const dbus::utility::DBusPropertiesMap& pcieDevProperties) { - if (ec) - { - BMCWEB_LOG_DEBUG - << "failed to get PCIe Device properties ec: " << ec.value() - << ": " << ec.message(); - if (ec.value() == - boost::system::linux_error::bad_request_descriptor) - { - messages::resourceNotFound(asyncResp->res, "PCIeDevice", - device); - } - else - { - messages::internalError(asyncResp->res); - } - return; - } - - nlohmann::json& pcieFunctionList = - asyncResp->res.jsonValue["Members"]; - pcieFunctionList = nlohmann::json::array(); - static constexpr const int maxPciFunctionNum = 8; - for (int functionNum = 0; functionNum < maxPciFunctionNum; - functionNum++) - { - // Check if this function exists by looking for a - // device ID - std::string devIDProperty = - "Function" + std::to_string(functionNum) + "DeviceId"; - const std::string* property = nullptr; - for (const auto& propEntry : pcieDevProperties) - { - if (propEntry.first == devIDProperty) - { - property = std::get_if<std::string>(&propEntry.second); - } - } - if (property == nullptr || property->empty()) - { - continue; - } - nlohmann::json::object_t pcieFunction; - pcieFunction["@odata.id"] = crow::utility::urlFromPieces( - "redfish", "v1", "Systems", "system", "PCIeDevices", device, - "PCIeFunctions", std::to_string(functionNum)); - pcieFunctionList.push_back(std::move(pcieFunction)); - } - asyncResp->res.jsonValue["Members@odata.count"] = - pcieFunctionList.size(); - }; - std::string escapedPath = std::string(pciePath) + "/" + device; - dbus::utility::escapePathForDbus(escapedPath); - sdbusplus::asio::getAllProperties( - *crow::connections::systemBus, pcieService, escapedPath, - pcieDeviceInterface, std::move(getPCIeDeviceCallback)); - }); + std::bind_front(handlePCIeFunctionCollectionGet, std::ref(app))); } inline void requestRoutesSystemPCIeFunction(App& app) |