Skip to contentSkip to conversation

hwmon (occ): Add temp sensor value check

PATCH Superseded Alexander Amelkin 4 participants 7 messages Apr 17, 2019 – Apr 18, 2019 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon (occ): Add temp sensor value check

From: Alexander Soldatov <[email protected]>

The occ driver supports two formats for the temp sensor value.

The OCC firmware for P8 supports only the first format, for which no range checking or error processing is performed in the driver. Inspecting the OCC sources for P8 reveals that OCC may send a special value 0xFFFF to indicate that a sensor read timeout has occured, see

https://github.com/open-power/occ/blob/master_p8/src/occ/cmdh/cmdh_fsp_cmds.c#L395

That situation wasn't handled in the driver. This patch adds invalid temp value check for the sensor data format 1 and handles it the same way as it is done for the format 2, where EREMOTEIO is reported for this case.

---
 drivers/hwmon/occ/common.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hwmon/occ/common.c +4 -0
index 4679acb..825631c 100644
@@ -235,6 +235,10 @@ static ssize_t occ_show_temp_1(struct device *dev,
 		val = get_unaligned_be16(&temp->sensor_id);
 		break;
 	case 1:
+		/* If a sensor timed out long enough,
+		   OCC returns 0xFFFF for that sensor.*/
+		if (temp->value == 0xFFFF)
+			return -EREMOTEIO;
 		val = get_unaligned_be16(&temp->value) * 1000;
 		break;
 	default:
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 10 lines · Alexander Amelkin

From: Alexander Soldatov <[email protected]>

The occ driver supports two formats for the temp sensor value.

The OCC firmware for P8 supports only the first format, for which no range checking or error processing is performed in the driver. Inspecting the OCC sources for P8 reveals that OCC may send a special value 0xFFFF to indicate that a sensor read timeout has occured, see

occurred

Quoted 7 lines

https://github.com/open-power/occ/blob/master_p8/src/occ/cmdh/cmdh_fsp_cmds.c#L395

That situation wasn't handled in the driver. This patch adds invalid temp value check for the sensor data format 1 and handles it the same way as it is done for the format 2, where EREMOTEIO is reported for this case.

ETIMEDOUT ? Though that is really a corner case, so I guess both are fine.

Quoted 14 lines
---
  drivers/hwmon/occ/common.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/hwmon/occ/common.c +0 -0
index 4679acb..825631c 100644

drivers/hwmon/occ/common.c static ssize_t occ_show_temp_1(struct device *dev, · line 238

Quoted 4 lines
drivers/hwmon/occ/common.c +1 -0
@@ -235,6 +235,10 @@ static ssize_t occ_show_temp_1(struct device *dev,
  		val = get_unaligned_be16(&temp->sensor_id);
  		break;
  	case 1:
+		/* If a sensor timed out long enough,

"timed out" is sufficient. "timed out long enough" is difficult to understand.

drivers/hwmon/occ/common.c static ssize_t occ_show_temp_1(struct device *dev, · line 239

Quoted 1 line
drivers/hwmon/occ/common.c +1 -0
+		   OCC returns 0xFFFF for that sensor.*/

/*
* This is how multi-line comments look like
*/

Please run checkpatch on your patches.

Thanks,
Guenter

Quoted 6 lines
drivers/hwmon/occ/common.c +2 -0
+		if (temp->value == 0xFFFF)
+			return -EREMOTEIO;
  		val = get_unaligned_be16(&temp->value) * 1000;
  		break;
  	default:
#2 lore raw
Quoted 6 lines · Guenter Roeck
Quoted 4 lines · Alexander Amelkin

Inspecting the OCC sources for P8 reveals that OCC may send a special value 0xFFFF to indicate that a sensor read timeout has occured, see

occurred

Yup. A typo. Will fix.

Quoted 9 lines
Quoted 8 lines

https://github.com/open-power/occ/blob/master_p8/src/occ/cmdh/cmdh_fsp_cmds.c#L395

That situation wasn't handled in the driver. This patch adds invalid temp value check for the sensor data format 1 and handles it the same way as it is done for the format 2, where EREMOTEIO is reported for this case.

ETIMEDOUT ? Though that is really a corner case, so I guess both are fine.

We just reused the error code used for the same case for format 2 in common.c:309 (inside occ_show_temp_2() function).

We thought it would be strange to report different codes for the same case in different format versions.

Besides, it's quite a remote I/O error indeed.

Quoted 10 lines
Quoted 10 lines

---
  drivers/hwmon/occ/common.c | 4 ++++

  1 file changed, 4 insertions(+)
Quoted 11 lines
Quoted 9 lines
drivers/hwmon/occ/common.c +0 -0
index 4679acb..825631c 100644
@@ -235,6 +235,10 @@ static ssize_t occ_show_temp_1(struct device *dev,
           val = get_unaligned_be16(&temp->sensor_id);
           break;

      case 1:
+        /* If a sensor timed out long enough,

"timed out" is sufficient. "timed out long enough" is difficult to understand.

Agreed. That's a weird wording, but I double-checked before submitting that it was just a copy-paste of the wording from the OCC sources for this case. You're probably right though that it's better to fix it.

Quoted 8 lines
Quoted 2 lines

+           OCC returns 0xFFFF for that sensor.*/

/*
 * This is how multi-line comments look like
 */

Please run checkpatch on your patches.

Mea culpa. Didn't check. Will fix tomorrow.

Quoted 4 lines

Thanks,
Guenter

Thanks.

With best regards,
Alexander Amelkin,
Leading BMC Software Engineer, YADRO
https://yadro.com

#3 lore raw

PATCH v2 1/1 hwmon (occ): Add temp sensor value check

From: Alexander Soldatov <[email protected]>

The occ driver supports two formats for the temp sensor value.

The OCC firmware for P8 supports only the first format, for which no range checking or error processing is performed in the driver. Inspecting the OCC sources for P8 reveals that OCC may send a special value 0xFFFF to indicate that a sensor read timeout has occurred, see

https://github.com/open-power/occ/blob/master_p8/src/occ/cmdh/cmdh_fsp_cmds.c#L395

That situation wasn't handled in the driver. This patch adds invalid temp value check for the sensor data format 1 and handles it the same way as it is done for the format 2, where EREMOTEIO is reported for this case.

---
 drivers/hwmon/occ/common.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hwmon/occ/common.c +6 -0
index 4679acb..825631c 100644
@@ -235,6 +235,12 @@ static ssize_t occ_show_temp_1(struct device *dev,
 		val = get_unaligned_be16(&temp->sensor_id);
 		break;
 	case 1:
+		/*
+		 * If a sensor reading has expired and couldn't be refreshed,
+		 * OCC returns 0xFFFF for that sensor.
+		 */
+		if (temp->value == 0xFFFF)
+			return -EREMOTEIO;
 		val = get_unaligned_be16(&temp->value) * 1000;
 		break;
 	default:
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#4 lore raw
Quoted 10 lines · Alexander Amelkin

From: Alexander Soldatov <[email protected]>

The occ driver supports two formats for the temp sensor value.

The OCC firmware for P8 supports only the first format, for which no range checking or error processing is performed in the driver. Inspecting the OCC sources for P8 reveals that OCC may send a special value 0xFFFF to indicate that a sensor read timeout has occurred, see

Quoted 6 lines

https://github.com/open-power/occ/blob/master_p8/src/occ/cmdh/cmdh_fsp_cmds.c#L395

That situation wasn't handled in the driver. This patch adds invalid temp value check for the sensor data format 1 and handles it the same way as it is done for the format 2, where EREMOTEIO is reported for this case.

Thanks Alexander and Guenter.

Quoted 27 lines
---
  drivers/hwmon/occ/common.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/hwmon/occ/common.c +6 -0
index 4679acb..825631c 100644
@@ -235,6 +235,12 @@ static ssize_t occ_show_temp_1(struct device *dev,
  		val = get_unaligned_be16(&temp->sensor_id);
  		break;
  	case 1:
+		/*
+		 * If a sensor reading has expired and couldn't be refreshed,
+		 * OCC returns 0xFFFF for that sensor.
+		 */
+		if (temp->value == 0xFFFF)
+			return -EREMOTEIO;
  		val = get_unaligned_be16(&temp->value) * 1000;
  		break;
  	default:
maintainer Applied
#5 lore raw
Quoted 20 lines · Eddie James
Quoted 10 lines · Alexander Amelkin

From: Alexander Soldatov <[email protected]>

The occ driver supports two formats for the temp sensor value.

The OCC firmware for P8 supports only the first format, for which no range checking or error processing is performed in the driver. Inspecting the OCC sources for P8 reveals that OCC may send a special value 0xFFFF to indicate that a sensor read timeout has occurred, see

Quoted 6 lines

https://github.com/open-power/occ/blob/master_p8/src/occ/cmdh/cmdh_fsp_cmds.c#L395

That situation wasn't handled in the driver. This patch adds invalid temp value check for the sensor data format 1 and handles it the same way as it is done for the format 2, where EREMOTEIO is reported for this case.

Quoted 5 lines

Thanks Alexander and Guenter.

Applied.

Thanks,
Guenter

Quoted 29 lines
Quoted 28 lines
---
 drivers/hwmon/occ/common.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hwmon/occ/common.c +6 -0
index 4679acb..825631c 100644
@@ -235,6 +235,12 @@ static ssize_t occ_show_temp_1(struct device *dev,
 		val = get_unaligned_be16(&temp->sensor_id);
 		break;
 	case 1:
+		/*
+		 * If a sensor reading has expired and couldn't be refreshed,
+		 * OCC returns 0xFFFF for that sensor.
+		 */
+		if (temp->value == 0xFFFF)
+			return -EREMOTEIO;
 		val = get_unaligned_be16(&temp->value) * 1000;
 		break;
 	default:
#6 lore raw
Quoted 21 lines · Guenter Roeck
Quoted 20 lines · Eddie James
Quoted 16 lines · Alexander Amelkin

From: Alexander Soldatov <[email protected]>

The occ driver supports two formats for the temp sensor value.

The OCC firmware for P8 supports only the first format, for which no range checking or error processing is performed in the driver. Inspecting the OCC sources for P8 reveals that OCC may send a special value 0xFFFF to indicate that a sensor read timeout has occurred, see

https://github.com/open-power/occ/blob/master_p8/src/occ/cmdh/cmdh_fsp_cmds.c#L395

That situation wasn't handled in the driver. This patch adds invalid temp value check for the sensor data format 1 and handles it the same way as it is done for the format 2, where EREMOTEIO is reported for this case.

Quoted 7 lines
Quoted 5 lines

Thanks Alexander and Guenter.

Applied.

I've backported and applied this to dev-5.0.

Cheers,

Andrew

Quoted 34 lines

Thanks,
Guenter

Quoted 29 lines
Quoted 28 lines
---
 drivers/hwmon/occ/common.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hwmon/occ/common.c +6 -0
index 4679acb..825631c 100644
@@ -235,6 +235,12 @@ static ssize_t occ_show_temp_1(struct device *dev,
 		val = get_unaligned_be16(&temp->sensor_id);
 		break;
 	case 1:
+		/*
+		 * If a sensor reading has expired and couldn't be refreshed,
+		 * OCC returns 0xFFFF for that sensor.
+		 */
+		if (temp->value == 0xFFFF)
+			return -EREMOTEIO;
 		val = get_unaligned_be16(&temp->value) * 1000;
 		break;
 	default: