[Skiboot] [PATCH 06/11] fsp-sensor: add a status property

Cédric Le Goater clg at fr.ibm.com
Thu Feb 5 17:30:54 AEDT 2015


This patch adds a new status property for the sensors available
on a Power system.

The status of a FSP sensor can be returned by one or more PRS
command modifiers. For power supply and fans, we choose the PRS
modifier (and not DATA) to return the AC_FAULTED bit. For the
ambient temperature, we have no choice, the DATA modifier needs
to be used.

We leave the decoding to the responsibility of the OS driver. This
is a change from the current implementation which should not add
too much complexity in the driver. The status bits being :

		   PRS		PARAM/DATA
		 Modifier	 Modifier

  0x0010	ON SUPPORTED
  0x0008	ON

  0x0004	AC FAULTED	EM ALERT
  0x0002	FAULTED		FAULTED
  0x0001	PRESENT		PRESENT

we will expect Linux to only use bits[1-3] to reflect the status as
a *_alarm or *_fault attribute. bits [4-5] can be discarded.

For the core temperature sensors, we change the trip bits layout to
be the same but, as they are always set, we brutaly assign the value
to nil for the moment until we know why.

Signed-off-by: Cédric Le Goater <clg at fr.ibm.com>
---

 Changes since RFC :

 - added DTS status

 hw/dts.c            |   24 +++++++++++++++++++++-
 hw/fsp/fsp-sensor.c |   55 +++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 68 insertions(+), 11 deletions(-)

diff --git a/hw/dts.c b/hw/dts.c
index 356080e9e756..b5498d95924b 100644
--- a/hw/dts.c
+++ b/hw/dts.c
@@ -112,6 +112,12 @@ static int dts_read_core_temp(uint32_t pir, struct dts *dts)
 
 	prlog(PR_TRACE, "DTS: Chip %x Core %x temp:%dC trip:%x\n",
 	      chip_id, core, dts->temp, dts->trip);
+
+	/*
+	 * FIXME: The trip bits are always set ?! Just discard
+	 * them for the moment until we understand why.
+	 */
+	dts->trip = 0;
 	return 0;
 }
 
@@ -158,7 +164,18 @@ int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data)
 	if (attr == SENSOR_DTS_ATTR_TEMP_MAX)
 		*sensor_data = dts.temp;
 	else if (attr == SENSOR_DTS_ATTR_TEMP_TRIP)
-		*sensor_data = dts.trip;
+		/*
+		 * shift left the trip bits and add a 'present' bit to
+		 * fit the common layout for status. The meaning is
+		 * slighty different but testing against 0x6 should
+		 * raise an alarm
+		 *
+		 *   fatal         11            1
+		 *   critical      10            1
+		 *   warning       01            1
+		 *   no trip       00            1
+		 */
+		*sensor_data = (dts.trip << 1) | 0x1;
 
 	return 0;
 }
@@ -199,6 +216,11 @@ bool dts_sensor_create_nodes(void)
 			dt_add_property_string(node, "compatible",
 					       "ibm,opal-sensor");
 			dt_add_property_cells(node, "sensor-data", handler);
+
+			handler = sensor_make_handler(sensor_class,
+					c->pir, SENSOR_DTS_ATTR_TEMP_TRIP);
+			dt_add_property_cells(node, "sensor-status", handler);
+
 		}
 	}
 
diff --git a/hw/fsp/fsp-sensor.c b/hw/fsp/fsp-sensor.c
index dd178138b005..90bed4e90922 100644
--- a/hw/fsp/fsp-sensor.c
+++ b/hw/fsp/fsp-sensor.c
@@ -78,6 +78,7 @@ enum sensor_state {
 
 enum spcn_attr {
 	/* mod 0x01, 0x02 */
+	SENSOR_STATUS,
 	SENSOR_PRESENT,
 	SENSOR_FAULTED,
 	SENSOR_AC_FAULTED,
@@ -118,6 +119,7 @@ struct spcn_mod {
 };
 
 static struct spcn_mod_attr prs_status_attrs[] = {
+		{"status", SENSOR_STATUS},
 		{"present", SENSOR_PRESENT},
 		{"faulted", SENSOR_FAULTED},
 		{"ac-faulted", SENSOR_AC_FAULTED},
@@ -281,6 +283,9 @@ static void fsp_sensor_process_data(struct opal_sensor_data *attr)
 				sensor_mod_data[1] == attr->rid) {
 			switch (attr->spcn_attr) {
 			/* modifier 0x01, 0x02 */
+			case SENSOR_STATUS:
+				sensor_data = sensor_mod_data[3];
+				break;
 			case SENSOR_PRESENT:
 				prlog(PR_TRACE,"Not exported to device tree\n");
 				break;
@@ -498,16 +503,19 @@ static inline bool sensor_frc_is_valid(uint16_t frc)
  * its data. The routine below provides the mapping between the
  * attribute and the PRS command modifier to use.
  *
- *	resource        | data   |  thrs  |
- *	----------------+--------+--------+
- *	power_supply    | POWER  |        |
- *	----------------+--------+--------+
- *	amb-temp        | DATA   |        |
- *	                |        | PARAM  |
- *	----------------+--------+--------+
- *	fan             | DATA   |        |
- *	                |        | PARAM  |
- *	                |        |        |
+ *	resource        | data   |  thrs  | status    |
+ *	----------------+--------+--------+-----------+
+ *	power_supply    | POWER  |        |           |
+ *	                |        |        | PRS       |
+ *	----------------+--------+--------+-----------+
+ *	amb-temp        | DATA   |        | DATA      |
+ *	                |        | PARAM  | PARAM (*) |
+ *	----------------+--------+--------+-----------+
+ *	fan             | DATA   |        | DATA  (*) |
+ *	                |        | PARAM  | PARAM (*) |
+ *	                |        |        | PRS       |
+ *
+ * (*) don't use the attribute given by this command modifier
  */
 static int64_t parse_sensor_id(uint32_t handler, struct opal_sensor_data *attr)
 {
@@ -533,6 +541,21 @@ static int64_t parse_sensor_id(uint32_t handler, struct opal_sensor_data *attr)
 	case SENSOR_THRS:
 		mod = SPCN_MOD_SENSOR_PARAM_FIRST;
 		break;
+
+	case SENSOR_STATUS:
+		switch (attr->frc) {
+		case SENSOR_FRC_AMB_TEMP:
+			mod = SPCN_MOD_SENSOR_DATA_FIRST;
+			break;
+		case SENSOR_FRC_POWER_SUPPLY:
+		case SENSOR_FRC_COOLING_FAN:
+			mod = SPCN_MOD_PRS_STATUS_FIRST;
+			break;
+		default:
+			return OPAL_PARAMETER;
+		}
+		break;
+
 	default:
 		return OPAL_PARAMETER;
 	}
@@ -654,6 +677,8 @@ static int add_sensor_prs(struct dt_node *sensors, struct sensor_prs *prs)
 	if (!node)
 		return -1;
 
+	dt_add_property_cells(node, "sensor-status",
+			      sensor_handler(prs->header, SENSOR_STATUS));
 	return 0;
 }
 
@@ -668,6 +693,8 @@ static int add_sensor_param(struct dt_node *sensors, struct sensor_param *param)
 	dt_add_property_string(node, "ibm,loc-code", param->location);
 	dt_add_property_cells(node, "sensor-threshold",
 			      sensor_handler(param->header, SENSOR_THRS));
+	/* don't use the status coming from the response of the
+	 * SENSOR_PARAM subcommand */
 	return 0;
 }
 
@@ -682,6 +709,14 @@ static int add_sensor_data(struct dt_node *sensors,
 
 	dt_add_property_cells(node, "sensor-data",
 			      sensor_handler(data->header, SENSOR_DATA));
+
+	/* Let's make sure we are not adding a duplicate device node.
+	 * Some resource, like fans, get their status attribute from
+	 * three different commands ...
+	 */
+	if (data->header.frc == SENSOR_FRC_AMB_TEMP)
+		dt_add_property_cells(node, "sensor-status",
+			      sensor_handler(data->header, SENSOR_STATUS));
 	return 0;
 }
 
-- 
1.7.10.4



More information about the Skiboot mailing list