diff mbox

[V2] hw/ipmi-sensor: Fix setting of firmware progress sensor properly.

Message ID 1478195891-24374-1-git-send-email-ppaidipe@linux.vnet.ibm.com
State Accepted
Headers show

Commit Message

ppaidipe Nov. 3, 2016, 5:58 p.m. UTC
From: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com>

Currently Hostboot populates /bmc/sensors dt node and corresponding sensors
only for BMC platforms, And for FSP platforms hostboot is not populating any
fsp sensors(Management sensors) and also there is no firmware progress sensor
exist in fsp platforms. Due to which OPAL incorrectly setting firmware status
on a sensor id "00" which is not at all exist.

    On a FSP system:
     cat /sys/firmware/opal/msglog | grep -i setting
    [   21.189204883,6] IPMI: setting fw progress sensor 00 to 07
    [   21.189559121,6] IPMI: setting fw progress sensor 00 to 13
    cat /sys/firmware/opal/msglog | grep -i skiboot
    [   84.127416495,5] SkiBoot skiboot-5.4.0-rc3 starting...

    On a BMC system:
    cat /sys/firmware/opal/msglog | grep -i setting
    [    3.166286901,6] IPMI: setting fw progress sensor 05 to 14
    [   14.259153338,6] IPMI: setting fw progress sensor 05 to 07
    [   14.469070593,5] IPMI: Resetting boot count on successful boot
    [   15.001210324,6] IPMI: setting fw progress sensor 05 to 13

So this patch fixes this incorrect setting on a fsp system, and also sets the sensor
only if OPAL initialises ipmi sensors and corresponding sensor exists for a given
sensor type in the device tree.

    After patch:
	On a FSP system:
	cat /sys/firmware/opal/msglog | grep -i setting

	On a BMC system:
	 cat /sys/firmware/opal/msglog | grep -i setting
	[    3.164859816,6] IPMI: setting fw progress sensor 05 to 14
	[   14.024941077,6] IPMI: setting fw progress sensor 05 to 07
	[   14.211514767,5] IPMI: Resetting boot count on successful boot
	[   14.252554375,6] IPMI: setting fw progress sensor 05 to 13

Signed-off-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com>

Changes in V2:
	- Addressed the Joel's below suggestions
	- Added sensors_present variable to check ipmi sensors initialized.
	- Get the sensor ID only if sensor_type exist in the device tree.
	- Set the sensor reading only when sensor ID is received.

Signed-off-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com>
---
 hw/ipmi/ipmi-sensor.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
 include/ipmi.h        |  3 +++
 2 files changed, 45 insertions(+), 2 deletions(-)

Comments

Stewart Smith Nov. 8, 2016, 12:41 a.m. UTC | #1
ppaidipe@linux.vnet.ibm.com writes:
> From: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com>
>
> Currently Hostboot populates /bmc/sensors dt node and corresponding sensors
> only for BMC platforms, And for FSP platforms hostboot is not populating any
> fsp sensors(Management sensors) and also there is no firmware progress sensor
> exist in fsp platforms. Due to which OPAL incorrectly setting firmware status
> on a sensor id "00" which is not at all exist.
>
>     On a FSP system:
>      cat /sys/firmware/opal/msglog | grep -i setting
>     [   21.189204883,6] IPMI: setting fw progress sensor 00 to 07
>     [   21.189559121,6] IPMI: setting fw progress sensor 00 to 13
>     cat /sys/firmware/opal/msglog | grep -i skiboot
>     [   84.127416495,5] SkiBoot skiboot-5.4.0-rc3 starting...
>
>     On a BMC system:
>     cat /sys/firmware/opal/msglog | grep -i setting
>     [    3.166286901,6] IPMI: setting fw progress sensor 05 to 14
>     [   14.259153338,6] IPMI: setting fw progress sensor 05 to 07
>     [   14.469070593,5] IPMI: Resetting boot count on successful boot
>     [   15.001210324,6] IPMI: setting fw progress sensor 05 to 13
>
> So this patch fixes this incorrect setting on a fsp system, and also sets the sensor
> only if OPAL initialises ipmi sensors and corresponding sensor exists for a given
> sensor type in the device tree.
>
>     After patch:
> 	On a FSP system:
> 	cat /sys/firmware/opal/msglog | grep -i setting
>
> 	On a BMC system:
> 	 cat /sys/firmware/opal/msglog | grep -i setting
> 	[    3.164859816,6] IPMI: setting fw progress sensor 05 to 14
> 	[   14.024941077,6] IPMI: setting fw progress sensor 05 to 07
> 	[   14.211514767,5] IPMI: Resetting boot count on successful boot
> 	[   14.252554375,6] IPMI: setting fw progress sensor 05 to 13
>
> Signed-off-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com>
>
> Changes in V2:
> 	- Addressed the Joel's below suggestions
> 	- Added sensors_present variable to check ipmi sensors initialized.
> 	- Get the sensor ID only if sensor_type exist in the device tree.
> 	- Set the sensor reading only when sensor ID is received.
>
> Signed-off-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com>

Thanks! merged with minor change to master as of 566150.
diff mbox

Patch

diff --git a/hw/ipmi/ipmi-sensor.c b/hw/ipmi/ipmi-sensor.c
index cabb745..84acb5e 100644
--- a/hw/ipmi/ipmi-sensor.c
+++ b/hw/ipmi/ipmi-sensor.c
@@ -19,6 +19,7 @@ 
 #include <opal.h>
 #include <skiboot.h>
 #include <string.h>
+#include <stdbool.h>
 
 #define IPMI_WRITE_SENSOR		(1 << 0)
 
@@ -28,6 +29,8 @@ 
 #define MAX_IPMI_SENSORS 255
 static int16_t sensors[MAX_IPMI_SENSORS];
 
+static bool sensors_present = false;
+
 struct set_sensor_req {
 	u8 sensor_number;
 	u8 operation;
@@ -37,6 +40,26 @@  struct set_sensor_req {
 	u8 event_data[3];
 };
 
+bool ipmi_sensor_type_present(uint8_t sensor_type)
+{
+        const struct dt_property *type_prop;
+        uint8_t type;
+        struct dt_node *node;
+
+        dt_for_each_compatible(dt_root, node, "ibm,ipmi-sensor") {
+                type_prop = dt_find_property(node, "ipmi-sensor-type");
+                if (!type_prop) {
+                        prlog(PR_ERR, "IPMI: sensor doesn't have ipmi-sensor-type\n");
+                        continue;
+                }
+
+                type = (uint8_t)dt_property_get_cell(type_prop, 0);
+                if (type == sensor_type)
+                        return true;
+        }
+        return false;
+}
+
 uint8_t ipmi_get_sensor_number(uint8_t sensor_type)
 {
 	assert(sensor_type < MAX_IPMI_SENSORS);
@@ -47,11 +70,19 @@  int ipmi_set_boot_count(void)
 {
 	struct set_sensor_req req;
 	struct ipmi_msg *msg;
-	int boot_count_sensor = sensors[BOOT_COUNT_SENSOR_TYPE];
+	int boot_count_sensor;
+
+	if (!sensors_present)
+		return OPAL_PARAMETER;
 
 	if (!ipmi_present())
 		return OPAL_CLOSED;
 
+        if (!ipmi_sensor_type_present(BOOT_COUNT_SENSOR_TYPE))
+                return OPAL_HARDWARE;
+
+	boot_count_sensor = sensors[BOOT_COUNT_SENSOR_TYPE];
+
 	if (boot_count_sensor < 0) {
 		prlog(PR_DEBUG, "IPMI: boot count set but not present\n");
 		return OPAL_HARDWARE;
@@ -77,11 +108,19 @@  int ipmi_set_fw_progress_sensor(uint8_t state)
 {
 	struct ipmi_msg *msg;
 	struct set_sensor_req request;
-	int fw_sensor_num = sensors[FW_PROGRESS_SENSOR_TYPE];
+	int fw_sensor_num;
+
+	if (!sensors_present)
+		return OPAL_PARAMETER;
 
 	if (!ipmi_present())
 		return OPAL_CLOSED;
 
+        if (!ipmi_sensor_type_present(FW_PROGRESS_SENSOR_TYPE))
+                return OPAL_HARDWARE;
+
+	fw_sensor_num = sensors[FW_PROGRESS_SENSOR_TYPE];
+
 	if (fw_sensor_num < 0) {
 		prlog(PR_DEBUG, "IPMI: fw progress set but not present\n");
 		return OPAL_HARDWARE;
@@ -131,4 +170,5 @@  void ipmi_sensor_init(void)
 		assert(type < MAX_IPMI_SENSORS);
 		sensors[type] = num;
 	}
+	sensors_present = true;
 }
diff --git a/include/ipmi.h b/include/ipmi.h
index a6791e4..9591661 100644
--- a/include/ipmi.h
+++ b/include/ipmi.h
@@ -271,6 +271,9 @@  void ipmi_wdt_final_reset(void);
 /* Discover id of settable ipmi sensors */
 void ipmi_sensor_init(void);
 
+/* Check sensor existence of given sensor_type */
+bool ipmi_sensor_type_present(uint8_t sensor_type);
+
 /* Get sensor number for given sensor type */
 uint8_t ipmi_get_sensor_number(uint8_t sensor_type);