hwmon: Add support for currX_emergency and inX_[l]emergency attributes
Subsystems (2)
Guenter Roeck
maintainerPATCH v2 1/1 hwmon: Add support for currX_emergency and inX_[l]emergency attributes
Some hardware monitoring chips support three alarm levels for current and voltage high limits, and three alarm levels for voltage low limits. Add support for currX_emergency, inX_emergency, and inX_lemergency attributes together with the appropriate alarm attributes to support such chips.
---
v2: Also support inX_lemergency for voltage low emergency limits.
Documentation/ABI/testing/sysfs-class-hwmon | 36 +++++++++++++++++++++ Documentation/hwmon/sysfs-interface.rst | 12 +++++++ drivers/hwmon/hwmon.c | 6 ++++ include/linux/hwmon.h | 12 +++++++ 4 files changed, 66 insertions(+)
Documentation/ABI/testing/sysfs-class-hwmon +36 -0
@@ -61,6 +61,18 @@ Description: take drastic action such as power down or reset. At the very least, it should report a fault. +What: /sys/class/hwmon/hwmonX/inY_lemergency +Description: + Voltage emergency min value. + + Unit: millivolt + + RW + + If voltage drops to or below this limit, the system is + expected to take drastic action such as immediate power + down or reset. At the very least, it should report a fault. + What: /sys/class/hwmon/hwmonX/inY_max Description: Voltage max value.
@@ -81,6 +93,18 @@ Description: take drastic action such as power down or reset. At the very least, it should report a fault. +What: /sys/class/hwmon/hwmonX/inY_emergency +Description: + Voltage emergency max value. + + Unit: millivolt + + RW + + If voltage reaches or exceeds this limit, the system is expected + to take drastic action such as immediate power down or reset. + At the very least, it should report a fault. + What: /sys/class/hwmon/hwmonX/inY_input Description: Voltage input value.
@@ -647,6 +671,18 @@ Description: RW +What: /sys/class/hwmon/hwmonX/currY_emergency +Description: + Current emergency high value. + + Unit: milliampere + + RW + + If a current reaches or exceeds this limit, the system is + expected to take drastic action such as immediate power down + or reset. At the very least, it should report a fault. + What: /sys/class/hwmon/hwmonX/currY_input Description: Current input value
Documentation/hwmon/sysfs-interface.rst +12 -0
@@ -121,12 +121,18 @@ Voltages `in[0-*]_lcrit` Voltage critical min value. +`in[0-*]_lemergency` + Voltage emergency min value. + `in[0-*]_max` Voltage max value. `in[0-*]_crit` Voltage critical max value. +`in[0-*]_emergency` + Voltage emergency max value. + `in[0-*]_input` Voltage input value.
@@ -332,6 +338,9 @@ Currents `curr[1-*]_crit` Current critical high value. +`curr[1-*]_emergency` + Current emergency high value. + `curr[1-*]_input` Current input value.
@@ -527,12 +536,15 @@ implementation. +-------------------------------+-----------------------+ | **`in[0-*]_min_alarm`, | Limit alarm | | `in[0-*]_max_alarm`, | | +| `in[0-*]_lemergency_alarm`, | | | `in[0-*]_lcrit_alarm`, | - 0: no alarm | | `in[0-*]_crit_alarm`, | - 1: alarm | +| `in[0-*]_emergency_alarm`, | | | `curr[1-*]_min_alarm`, | | | `curr[1-*]_max_alarm`, | RO | | `curr[1-*]_lcrit_alarm`, | | | `curr[1-*]_crit_alarm`, | | +| `curr[1-*]_emergency_alarm`, | | | `power[1-*]_cap_alarm`, | | | `power[1-*]_max_alarm`, | | | `power[1-*]_crit_alarm`, | |
drivers/hwmon/hwmon.c +6 -0
@@ -621,6 +621,8 @@ static const char * const hwmon_in_attr_templates[] = { [hwmon_in_max] = "in%d_max", [hwmon_in_lcrit] = "in%d_lcrit", [hwmon_in_crit] = "in%d_crit", + [hwmon_in_lemergency] = "in%d_lemergency", + [hwmon_in_emergency] = "in%d_emergency", [hwmon_in_average] = "in%d_average", [hwmon_in_lowest] = "in%d_lowest", [hwmon_in_highest] = "in%d_highest",
@@ -631,6 +633,8 @@ static const char * const hwmon_in_attr_templates[] = { [hwmon_in_max_alarm] = "in%d_max_alarm", [hwmon_in_lcrit_alarm] = "in%d_lcrit_alarm", [hwmon_in_crit_alarm] = "in%d_crit_alarm", + [hwmon_in_lemergency_alarm] = "in%d_lemergency_alarm", + [hwmon_in_emergency_alarm] = "in%d_emergency_alarm", [hwmon_in_rated_min] = "in%d_rated_min", [hwmon_in_rated_max] = "in%d_rated_max", [hwmon_in_beep] = "in%d_beep",
@@ -644,6 +648,7 @@ static const char * const hwmon_curr_attr_templates[] = { [hwmon_curr_max] = "curr%d_max", [hwmon_curr_lcrit] = "curr%d_lcrit", [hwmon_curr_crit] = "curr%d_crit", + [hwmon_curr_emergency] = "curr%d_emergency", [hwmon_curr_average] = "curr%d_average", [hwmon_curr_lowest] = "curr%d_lowest", [hwmon_curr_highest] = "curr%d_highest",
@@ -654,6 +659,7 @@ static const char * const hwmon_curr_attr_templates[] = { [hwmon_curr_max_alarm] = "curr%d_max_alarm", [hwmon_curr_lcrit_alarm] = "curr%d_lcrit_alarm", [hwmon_curr_crit_alarm] = "curr%d_crit_alarm", + [hwmon_curr_emergency_alarm] = "curr%d_emergency_alarm", [hwmon_curr_rated_min] = "curr%d_rated_min", [hwmon_curr_rated_max] = "curr%d_rated_max", [hwmon_curr_beep] = "curr%d_beep",
include/linux/hwmon.h +12 -0
@@ -134,6 +134,8 @@ enum hwmon_in_attributes { hwmon_in_max, hwmon_in_lcrit, hwmon_in_crit, + hwmon_in_lemergency, + hwmon_in_emergency, hwmon_in_average, hwmon_in_lowest, hwmon_in_highest,
@@ -144,6 +146,8 @@ enum hwmon_in_attributes { hwmon_in_max_alarm, hwmon_in_lcrit_alarm, hwmon_in_crit_alarm, + hwmon_in_lemergency_alarm, + hwmon_in_emergency_alarm, hwmon_in_rated_min, hwmon_in_rated_max, hwmon_in_beep,
@@ -156,6 +160,8 @@ enum hwmon_in_attributes {#define HWMON_I_MAX BIT(hwmon_in_max)#define HWMON_I_LCRIT BIT(hwmon_in_lcrit)#define HWMON_I_CRIT BIT(hwmon_in_crit) +#define HWMON_I_LEMERGENCY BIT(hwmon_in_lemergency) +#define HWMON_I_EMERGENCY BIT(hwmon_in_emergency)#define HWMON_I_AVERAGE BIT(hwmon_in_average)#define HWMON_I_LOWEST BIT(hwmon_in_lowest)#define HWMON_I_HIGHEST BIT(hwmon_in_highest)
@@ -166,6 +172,8 @@ enum hwmon_in_attributes {#define HWMON_I_MAX_ALARM BIT(hwmon_in_max_alarm)#define HWMON_I_LCRIT_ALARM BIT(hwmon_in_lcrit_alarm)#define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm) +#define HWMON_I_LEMERGENCY_ALARM BIT(hwmon_in_lemergency_alarm) +#define HWMON_I_EMERGENCY_ALARM BIT(hwmon_in_emergency_alarm)#define HWMON_I_RATED_MIN BIT(hwmon_in_rated_min)#define HWMON_I_RATED_MAX BIT(hwmon_in_rated_max)#define HWMON_I_BEEP BIT(hwmon_in_beep)
@@ -178,6 +186,7 @@ enum hwmon_curr_attributes { hwmon_curr_max, hwmon_curr_lcrit, hwmon_curr_crit, + hwmon_curr_emergency, hwmon_curr_average, hwmon_curr_lowest, hwmon_curr_highest,
@@ -188,6 +197,7 @@ enum hwmon_curr_attributes { hwmon_curr_max_alarm, hwmon_curr_lcrit_alarm, hwmon_curr_crit_alarm, + hwmon_curr_emergency_alarm, hwmon_curr_rated_min, hwmon_curr_rated_max, hwmon_curr_beep,
@@ -199,6 +209,7 @@ enum hwmon_curr_attributes {#define HWMON_C_MAX BIT(hwmon_curr_max)#define HWMON_C_LCRIT BIT(hwmon_curr_lcrit)#define HWMON_C_CRIT BIT(hwmon_curr_crit) +#define HWMON_C_EMERGENCY BIT(hwmon_curr_emergency)#define HWMON_C_AVERAGE BIT(hwmon_curr_average)#define HWMON_C_LOWEST BIT(hwmon_curr_lowest)#define HWMON_C_HIGHEST BIT(hwmon_curr_highest)
@@ -209,6 +220,7 @@ enum hwmon_curr_attributes {#define HWMON_C_MAX_ALARM BIT(hwmon_curr_max_alarm)#define HWMON_C_LCRIT_ALARM BIT(hwmon_curr_lcrit_alarm)#define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm) +#define HWMON_C_EMERGENCY_ALARM BIT(hwmon_curr_emergency_alarm)#define HWMON_C_RATED_MIN BIT(hwmon_curr_rated_min)#define HWMON_C_RATED_MAX BIT(hwmon_curr_rated_max)#define HWMON_C_BEEP BIT(hwmon_curr_beep)
Signature · 1 line
2.45.2
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Internal ABI breakage in the habanalabs driver caused by inserting values into hwmon enums. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Internal ABI breakage in the habanalabs driver caused by inserting values into hwmon enums. --
--- Patch [1]: [PATCH v2] hwmon: Add support for currX_emergency and inX_[l]emergency attributes --- commit 618b70e656b029d918a4d90557dfadbd253324dd
Author: Guenter Roeck <[email protected]>
hwmon: Add support for currX_emergency and inX_[l]emergency attributes
This commit adds new emergency limit attributes for current and voltage to the hardware monitoring subsystem. It updates the hwmon core code, the enumerations, and the sysfs ABI documentation to support the new alarms.
include/linux/hwmon.h enum hwmon_in_attributes { · line 138
Quoted 10 lines
include/linux/hwmon.h +2
-0@@ -134,6 +134,8 @@ enum hwmon_in_attributes { hwmon_in_max, hwmon_in_lcrit, hwmon_in_crit, + hwmon_in_lemergency, + hwmon_in_emergency,
[Severity: High]
Does inserting these elements here break downstream drivers that rely on the historical integer mapping?
For example, in drivers/accel/habanalabs/common/hwmon.c:adjust_hwmon_flags(), the driver performs a hardcoded bitwise shift assuming the Linux hwmon enum values perfectly match the firmware API shifted by 1:
flags = (cpucp_flags << 1) | HWMON_I_ENABLE;
By inserting elements into the middle of this enum, all subsequent values (like hwmon_in_average) shift by 2. This causes the habanalabs driver to incorrectly map firmware sensors to Linux hwmon attributes. For instance, inX_highest will map to inX_average, and reading from these incorrectly mapped attributes via sysfs will fail with -EINVAL.
Can these new enum values be added to the end of the enum instead, or does habanalabs need to be updated to decouple it from the hwmon enum ordering?
Quoted 3 lines
include/linux/hwmon.h +0
-0hwmon_in_average, hwmon_in_lowest, hwmon_in_highest,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Guenter Roeck
maintainerQuoted 35 lines · On 8/13/26 18:20, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Internal ABI breakage in the habanalabs driver caused by inserting values into hwmon enums. ----- Patch [1]: [PATCH v2] hwmon: Add support for
currX_emergencyand inX_[l]emergency attributes --- commit618b70e656b029d918a4d90557dfadbd253324dd
Author: Guenter Roeck <[email protected]>hwmon: Add support for
currX_emergencyand inX_[l]emergency attributesThis commit adds new emergency limit attributes for current and voltage to the hardware monitoring subsystem. It updates the hwmon core code, the enumerations, and the sysfs ABI documentation to support the new alarms.
include/linux/hwmon.h enum hwmon_in_attributes { · line 138
Quoted 10 lines
include/linux/hwmon.h +2
-0@@ -134,6 +134,8 @@ enum hwmon_in_attributes { hwmon_in_max, hwmon_in_lcrit, hwmon_in_crit, + hwmon_in_lemergency, + hwmon_in_emergency,[Severity: High]
Does inserting these elements here break downstream drivers that rely on the historical integer mapping?For example, in drivers/accel/habanalabs/common/hwmon.c:adjust_hwmon_flags(), the driver performs a hardcoded bitwise shift assuming the Linux hwmon enum values perfectly match the firmware API shifted by 1:
flags = (cpucp_flags << 1) | HWMON_I_ENABLE;
Quoted 9 lines
By inserting elements into the middle of this enum, all subsequent values (like
hwmon_in_average) shift by 2. This causes the habanalabs driver to incorrectly map firmware sensors to Linux hwmon attributes. For instance,inX_highestwill map toinX_average, and reading from these incorrectly mapped attributes via sysfs will fail with-EINVAL.Can these new enum values be added to the end of the enum instead, or does habanalabs need to be updated to decouple it from the hwmon enum ordering?
There is no guarantee of a specific ordering of those flags. They can and will change position and/or ordering as new flags are added. The hwmon subsystem must not be held hostage by some driver making up their own rules. FWIW, I don't even understand what the habanalabs driver is doing and what assumptions it is making about the position and ordering of the flags.
Guenter
Hi Guenter,
Quoted 1 line · Guenter Roeck
Some hardware monitoring chips support three alarm levels for current and voltage high limits, and three alarm levels for voltage low limits. Add support for
currX_emergency,inX_emergency, andinX_lemergencyattributes together with the appropriate alarm attributes to support such chips. Cc: Manaf Meethalavalappu Pallikunhi <[email protected]>Signed-off-by: Guenter Roeck <[email protected]>
Thanks for the patch.
The change looks good to me. I applied the patch and validated the emergency limit alarm for voltage and current sensors with my Qualcomm BCL series applied on top of it, on the Qualcomm Glymur CRD platform.
Guenter Roeck
maintainerQuoted 6 lines · Manaf Meethalavalappu Pallikunhi
Hi Guenter,
Quoted 1 line · Guenter Roeck
Some hardware monitoring chips support three alarm levels for current and voltage high limits, and three alarm levels for voltage low limits. Add support for
currX_emergency,inX_emergency, andinX_lemergencyattributes together with the appropriate alarm attributes to support such chips. Cc: Manaf Meethalavalappu Pallikunhi <[email protected]>Signed-off-by: Guenter Roeck <[email protected]>
Quoted 7 lines
Thanks for the patch.
The change looks good to me. I applied the patch and validated the emergency limit alarm for voltage and current sensors with my Qualcomm BCL series applied on top of it, on the Qualcomm Glymur CRD platform.
Thanks!
Guenter