summaryrefslogtreecommitdiff
path: root/redfish-core/lib/memory.hpp
diff options
context:
space:
mode:
authorGunnar Mills <gmills@us.ibm.com>2020-10-27 00:05:08 +0300
committerGunnar Mills <gmills@us.ibm.com>2020-10-30 05:28:03 +0300
commit313efb1c9afcb0192585579a663467c28f873286 (patch)
treefca88f22fd9dc35958b092687f758dbcbc142a12 /redfish-core/lib/memory.hpp
parent5235d9640276f2421b5fcff1d5a356101fd301e6 (diff)
downloadbmcweb-313efb1c9afcb0192585579a663467c28f873286.tar.xz
Memory: Fix potential validator error
"Other" and "Unknown" are not valid Redfish MemoryDeviceType values. Do correct converting D-Bus enum to redfish. Straight mapping (D-Bus and Redfish both contain the same name): DDR DDR2 DDR3 DDR4 DDR4E_SDRAM LPDDR4_SDRAM LPDDR3_SDRAM DDR2_SDRAM_FB_DIMM DDR2_SDRAM_FB_DIMM_PROBE (no E on the end of the d-bus name) DDR_SGRAM ROM SDRAM EDO FastPageMode PipelinedNibble Logical HBM HBM2 The following D-Bus values are not mapped: Other Unknown DRAM EDRAM VRAM SRAM RAM FLASH EEPROM FEPROM EPROM CDRAM ThreeDRM RDRAM FBD2 LPDDR_SDRAM LPDDR2_SDRAM The following Redfish values don't have a mapping to: "DDR4_SDRAM" "DDR3_SDRAM" "DDR_SDRAM" "DDR2_SDRAM" Saw this because not setting the MemoryType so defaulting to "Other" and had removed the logic to leave off all other memory properties when MemorySizeInKB is 0 (commit above). IBM systems are not setting MemorySizeInKB so it is defaulting to 0 hence why this validator error has not been seen in CI. The validator error was "ERROR - MemoryDeviceType: Invalid Enum value 'Other' found, expected ['DDR', 'DDR2', 'DDR3', 'DDR4', 'DDR4_SDRAM', 'DDR4E_SDRAM', 'LPDDR4_SDRAM', 'DDR3_SDRAM', 'LPDDR3_SDRAM', 'DDR2_SDRAM', 'DDR2_SDRAM_FB_DIMM', 'DDR2_SDRAM_FB_DIMM_PROBE', 'DDR_SGRAM', 'DDR_SDRAM', 'ROM', 'SDRAM', 'EDO', 'FastPageMode', 'PipelinedNibble', 'Logical', 'HBM', 'HBM2']" https://github.com/openbmc/phosphor-dbus-interfaces/blob/1e8c11bf2656ed4a5fb27baa2dec3a65763bb47e/xyz/openbmc_project/Inventory/Item/Dimm.interface.yaml#L120 Tested: Passes the validator. Sent this property on D-Bus to different values. Change-Id: I629a1acd81fa6648893b7f531dfaab413cc2dd8f Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Diffstat (limited to 'redfish-core/lib/memory.hpp')
-rw-r--r--redfish-core/lib/memory.hpp119
1 files changed, 111 insertions, 8 deletions
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index e7b1113355..aaff47399e 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -32,6 +32,110 @@ using DimmProperty =
using DimmProperties = boost::container::flat_map<std::string, DimmProperty>;
+inline std::string translateMemoryTypeToRedfish(const std::string& memoryType)
+{
+ if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR")
+ {
+ return "DDR";
+ }
+ if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2")
+ {
+ return "DDR2";
+ }
+ if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR3")
+ {
+ return "DDR3";
+ }
+ if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4")
+ {
+ return "DDR4";
+ }
+ if (memoryType ==
+ "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR4E_SDRAM")
+ {
+ return "DDR4E_SDRAM";
+ }
+ if (memoryType ==
+ "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR4_SDRAM")
+ {
+ return "LPDDR4_SDRAM";
+ }
+ if (memoryType ==
+ "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.LPDDR3_SDRAM")
+ {
+ return "LPDDR3_SDRAM";
+ }
+ if (memoryType ==
+ "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_SDRAM_FB_DIMM")
+ {
+ return "DDR2_SDRAM_FB_DIMM";
+ }
+ if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR2_"
+ "SDRAM_FB_DIMM_PROB")
+ {
+ return "DDR2_SDRAM_FB_DIMM_PROBE";
+ }
+ if (memoryType ==
+ "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.DDR_SGRAM")
+ {
+ return "DDR_SGRAM";
+ }
+ if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.ROM")
+ {
+ return "ROM";
+ }
+ if (memoryType ==
+ "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.SDRAM")
+ {
+ return "SDRAM";
+ }
+ if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.EDO")
+ {
+ return "EDO";
+ }
+ if (memoryType ==
+ "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.FastPageMode")
+ {
+ return "FastPageMode";
+ }
+ if (memoryType ==
+ "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.PipelinedNibble")
+ {
+ return "PipelinedNibble";
+ }
+ if (memoryType ==
+ "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.Logical")
+ {
+ return "Logical";
+ }
+ if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM")
+ {
+ return "HBM";
+ }
+ if (memoryType == "xyz.openbmc_project.Inventory.Item.Dimm.DeviceType.HBM2")
+ {
+ return "HBM2";
+ }
+ // This is values like Other or Unknown
+ // Also D-Bus values:
+ // DRAM
+ // EDRAM
+ // VRAM
+ // SRAM
+ // RAM
+ // FLASH
+ // EEPROM
+ // FEPROM
+ // EPROM
+ // CDRAM
+ // ThreeDRAM
+ // RDRAM
+ // FBD2
+ // LPDDR_SDRAM
+ // LPDDR2_SDRAM
+ return "";
+}
+
inline void dimmPropToHex(const std::shared_ptr<AsyncResp>& aResp,
const char* key,
const std::pair<std::string, DimmProperty>& property)
@@ -543,16 +647,15 @@ inline void getDimmDataByService(std::shared_ptr<AsyncResp> aResp,
std::get_if<std::string>(&property.second);
if (value != nullptr)
{
- size_t idx = value->rfind('.');
- if (idx == std::string::npos ||
- idx + 1 >= value->size())
+ std::string memoryDeviceType =
+ translateMemoryTypeToRedfish(*value);
+ // Values like "Unknown" or "Other" will return empty
+ // so just leave off
+ if (!memoryDeviceType.empty())
{
- messages::internalError(aResp->res);
- BMCWEB_LOG_DEBUG << "Invalid property type for "
- "MemoryType";
+ aResp->res.jsonValue["MemoryDeviceType"] =
+ memoryDeviceType;
}
- std::string result = value->substr(idx + 1);
- aResp->res.jsonValue["MemoryDeviceType"] = result;
if (value->find("DDR") != std::string::npos)
{
aResp->res.jsonValue["MemoryType"] = "DRAM";