diff mbox

[RFC,v2,6/9] fsp-sensor: add a status property

Message ID 1421910562-18973-7-git-send-email-clg@fr.ibm.com
State Superseded
Headers show

Commit Message

Cédric Le Goater Jan. 22, 2015, 7:09 a.m. UTC
The status of a resource is returned by one or more PRS command
modifiers. Depending on the resource class, this patch adds a new
status property for the resources available on the Power system.

For power supply, we use the PRS modifier. For fans, also because
the status returned by the PRS modifier contains a AC_FAULTED bit
which seems interesting to report but we could use the DATA modifier.
To be discussed. For the ambient temperature, 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. Here are the status bits :

		   PRS		PARAM/DATA
		 Modifier	 Modifier

  0x0010	ON SUPPORTED
  0x0008	ON

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

We can discard bits 4-5 and use only 1-2-3 in the driver to reflect
the status as a *_alarm or *_fault attribute as expected under Linux.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---
 hw/fsp/fsp-sensor.c |   54 +++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 44 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/hw/fsp/fsp-sensor.c b/hw/fsp/fsp-sensor.c
index dd178138b005..c08e79dae6b3 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 +676,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 +692,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 +708,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;
 }