[PATCH] opal: mem_info check for dimm presence in property

Deb McLemore debmc at linux.vnet.ibm.com
Fri Mar 10 00:29:59 UTC 2017


This patch checks if the device tree node for the dimm has a
status of okay which indicates the dimm slot is populated.

If the dimm is populated and status is okay then further properties
will be queried and verified.

Signed-off-by: Deb McLemore <debmc at linux.vnet.ibm.com>
---
 src/lib/include/fwts_devicetree.h |  5 ++++
 src/lib/src/fwts_devicetree.c     | 30 ++++++++++++++++++++
 src/opal/mem_info.c               | 59 +++++++++++++++++++++++++++------------
 3 files changed, 76 insertions(+), 18 deletions(-)

diff --git a/src/lib/include/fwts_devicetree.h b/src/lib/include/fwts_devicetree.h
index b2669c5..372bdda 100644
--- a/src/lib/include/fwts_devicetree.h
+++ b/src/lib/include/fwts_devicetree.h
@@ -51,6 +51,11 @@ static inline int fwts_devicetree_read(fwts_framework *fwts
 }
 #endif
 
+bool check_status_property_okay(fwts_framework *fw,
+				const char *my_path,
+				const char *my_prop_string,
+				const char *property);
+
 int check_property_printable(fwts_framework *fw,
 			const char *name,
 			const char *buf,
diff --git a/src/lib/src/fwts_devicetree.c b/src/lib/src/fwts_devicetree.c
index 923f8fe..bf5686a 100644
--- a/src/lib/src/fwts_devicetree.c
+++ b/src/lib/src/fwts_devicetree.c
@@ -24,6 +24,8 @@
 
 #include "fwts.h"
 
+#include <libfdt.h>
+
 int fwts_devicetree_read(fwts_framework *fwts)
 {
 	char *command, *data = NULL;
@@ -64,6 +66,34 @@ int fwts_devicetree_read(fwts_framework *fwts)
 	return FWTS_OK;
 }
 
+bool check_status_property_okay(fwts_framework *fw,
+	const char *my_path,
+	const char *my_prop_string,
+	const char *property)
+{
+	char *prop_string = strstr(my_path, my_prop_string);
+
+	if (prop_string) {
+		int prop_len;
+		int node = fdt_path_offset(fw->fdt, prop_string);
+
+		if (node >= 0) {
+			const char *prop_buf;
+
+			prop_buf = fdt_getprop(fw->fdt, node,
+					property,
+					&prop_len);
+			if (prop_len > 0) {
+				if ((!strcmp(prop_buf, "okay")) ||
+					(!strcmp(prop_buf, "ok"))) {
+					return true;
+				}
+			}
+		}
+	}
+	return false;
+}
+
 int check_property_printable(fwts_framework *fw,
 	const char *name,
 	const char *buf,
diff --git a/src/opal/mem_info.c b/src/opal/mem_info.c
index 7bda7bc..2024080 100644
--- a/src/opal/mem_info.c
+++ b/src/opal/mem_info.c
@@ -27,6 +27,8 @@
 
 #include <libfdt.h>
 
+bool found_dimm = false;
+
 static int get_dimm_property(fwts_framework *fw,
 			char *my_path,
 			bool hex,
@@ -185,30 +187,39 @@ static int process_dimm(fwts_framework *fw,
 				free(namelist[i]);
 				continue;
 			}
-			if (get_dimm_property(fw, my_path, false,
-						DT_PROPERTY_OPAL_SLOT_LOC)) {
-				failures ++;
-			}
 
-			if (get_dimm_property(fw, my_path, false,
-						DT_PROPERTY_OPAL_PART_NUM)) {
-				failures ++;
-			}
+			char my_prop_string[15];
+			strcpy(my_prop_string, "/memory-buffer");
+			if (check_status_property_okay(fw, my_path,
+						my_prop_string,
+						DT_PROPERTY_OPAL_STATUS)) {
+				found_dimm = true;
+				if (get_dimm_property(fw, my_path, false,
+					DT_PROPERTY_OPAL_STATUS)) {
+					failures ++;
+				}
 
-			if (get_dimm_property(fw, my_path, false,
-						DT_PROPERTY_OPAL_SERIAL_NUM)) {
-				failures ++;
-			}
+				if (get_dimm_property(fw, my_path, false,
+					DT_PROPERTY_OPAL_SLOT_LOC)) {
+					failures ++;
+				}
 
-			if (get_dimm_property(fw, my_path, true,
+				if (get_dimm_property(fw, my_path, false,
+					DT_PROPERTY_OPAL_PART_NUM)) {
+					failures ++;
+				}
+
+				if (get_dimm_property(fw, my_path, false,
+					DT_PROPERTY_OPAL_SERIAL_NUM)) {
+					failures ++;
+				}
+
+				if (get_dimm_property(fw, my_path, true,
 					DT_PROPERTY_OPAL_MANUFACTURER_ID)) {
-				failures ++;
+					failures ++;
+				}
 			}
 
-			if (get_dimm_property(fw, my_path, false,
-						DT_PROPERTY_OPAL_STATUS)) {
-				failures ++;
-			}
 			free(my_buffer);
 			free(namelist[i]);
 		}
@@ -401,6 +412,18 @@ static int get_linux_mem_devices(fwts_framework *fw)
 				DT_FS_PATH);
 	}
 
+	if (!found_dimm) {
+		failures ++;
+		fwts_log_nl(fw);
+		fwts_failed(fw, LOG_LEVEL_CRITICAL,
+				"OPAL MEM Info",
+				"No MEM DIMM devices (memory-buffer) were found"
+				" in \"%s\" with a status of \"okay\" or \"ok\"."
+				"  This is unexpected so please check your"
+				" system setup for issues.",
+				DT_FS_PATH);
+	}
+
 	if (failures) {
 		return FWTS_ERROR;
 	} else {
-- 
2.7.4




More information about the fwts-devel mailing list