hwmon: AMPINEL telemetry support and shared fixes
v5 cover hwmon: AMPINEL telemetry support and shared fixes
This series adds read-only AMPINEL telemetry to aquacomputer_d5next, along with shared numeric, initial-cache and report-validation fixes. The separate keyboard interface remains deliberately unsupported, and there is no HID core or generic-HID change.
Changes since v4:
- In patch 1, read the power cache once with READ_ONCE(), check that snapshot for -ENODATA and return the same value. Mark the power-cache updates with WRITE_ONCE(). This addresses the check/use race identified by Sashiko review; the HID callback does not take the hwmon read mutex.
- In patch 5, use WRITE_ONCE() for AMPINEL's power-cache update as well.
- Patches 2 through 4 are unchanged. The base remains hwmon-next 9edd5ab2656f (7.3-rc4).
Validation of this revision:
- The hwmon object builds on x86_64 and i386 with W=1 and Sparse.
- All 995 captured reports pass the actual C parser/read replay under ASan/UBSan, including simulated 32-bit long clamping and the existing shared numeric, expiry and report-validation regression cases.
- A userspace scheduling hook invokes the actual raw-event handler after a power-cache read. Valid-to-unavailable, unavailable-to-valid and valid-to-different-valid updates preserve the checked snapshot. The old double read and two independent READ_ONCE() calls fail this check. This models an interleaving, not a live-kernel race reproduction.
- The exact final source was built and installed on Linux 7.2.6 with stock hid-generic. All 24 raw USB/hwmon comparisons matched after module loading and system activation. Telemetry binds successfully, the keyboard remains unbound, and other HID devices retain their drivers and input capabilities. No AMPINEL fault or kernel WARN/Oops appeared during installation. This revision has not been tested across reboot or suspend/resume; the earlier v3 lifecycle results are separate.
The power snapshot does not provide atomic readings across different sensors. Other Aquacomputer models have synthetic regression coverage, not hardware validation here. Channel labels follow report order; alarm reporting and protection configuration remain outside this series.
AI assistance: Codex assisted with implementation, tests and submission text; Sparse was used for static analysis.
V4: https://lore.kernel.org/linux-hwmon/[email protected]/
V3: https://lore.kernel.org/linux-hwmon/[email protected]/
Vas Zayarskiy (5):
hwmon: (aquacomputer_d5next) Avoid truncating scaled sensor readings
hwmon: (aquacomputer_d5next) Expire the initial sensor cache
hwmon: (aquacomputer_d5next) Validate incoming status reports
hwmon: (aquacomputer_d5next) Skip unknown firmware version offsets
hwmon: (aquacomputer_d5next) Add AMPINEL telemetry support
Documentation/hwmon/aquacomputer_d5next.rst | 13 +++ drivers/hwmon/Kconfig | 4 +- drivers/hwmon/aquacomputer_d5next.c | 118 +++++++++++++++++--- 3 files changed, 116 insertions(+), 19 deletions(-)
base-commit: 9edd5ab2656f040d726b5388f49ceac10bb2944f
PATCH v5 1/5 hwmon: (aquacomputer_d5next) Avoid truncating scaled sensor readings
High Flow Next power is reported in watts. Multiplying the 16-bit value by one million can overflow both the signed intermediate and the u32 cache. Store power in long, perform the conversion in u64, and clamp to LONG_MAX. The other existing power conversions fit in a signed 32-bit value. Return -ENODATA for unavailable power instead of exposing the stored error as a reading.
The power cache is updated by HID reports without the hwmon read mutex. Read it once with READ_ONCE() and use that snapshot for both the availability check and the returned value. Mark the corresponding updates with WRITE_ONCE() so that the shared accesses are explicit.
Widen the shared current cache to u32. The Aquastream XT conversion to milliamperes can exceed 65535 mA; clamp its negative conversion results to zero before assigning to the unsigned cache. This also permits devices with scaled aggregate currents to store milliamperes directly.
---
Changes in v5: Snapshot the power cache once for validation and output, and mark power-cache writes with WRITE_ONCE().
drivers/hwmon/aquacomputer_d5next.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/hwmon/aquacomputer_d5next.c +18 -11
@@ -19,6 +19,7 @@#include <linux/hwmon.h> #include <linux/jiffies.h> #include <linux/ktime.h> +#include <linux/limits.h> #include <linux/module.h> #include <linux/seq_file.h> #include <linux/unaligned.h>
@@ -599,9 +600,9 @@ struct aqc_data {u32 speed_input_min[1 ];u32 speed_input_target[1 ];u32 speed_input_max[1 ]; -u32 power_input[8 ]; +long power_input[8 ];u16 voltage_input[8 ]; -u16 current_input[8 ]; +u32 current_input[8 ];/* Label values */ const char *const *temp_label;
@@ -976,7 +977,7 @@ static int aqc_legacy_read(struct aqc_data *priv)/* Calculation derived from linear regression */ sensor_value =get_unaligned_le16 (priv->buffer +AQUASTREAMXT_PUMP_CURR_OFFSET ); - priv->current_input[0 ] =DIV_ROUND_CLOSEST (sensor_value *176 ,100 ) -52 ; + priv->current_input[0 ] =max (DIV_ROUND_CLOSEST (sensor_value *176 ,100 ) -52 ,0 ); sensor_value =get_unaligned_le16 (priv->buffer +AQUASTREAMXT_PUMP_VOLTAGE_OFFSET ); priv->voltage_input[0 ] =DIV_ROUND_CLOSEST (sensor_value *1000 ,61 );
@@ -1006,6 +1007,7 @@ static int aqc_legacy_read(struct aqc_data *priv)static int aqc_read (struct device *dev,enum hwmon_sensor_types type,u32 attr,int channel,long *val) { +long power;int ret;struct aqc_data *priv =dev_get_drvdata (dev);
@@ -1070,7 +1072,10 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, }break ;case hwmon_power: - *val = priv->power_input[channel]; + power =READ_ONCE (priv->power_input[channel]); +if (power == -ENODATA ) +return -ENODATA ; + *val = power;break ;case hwmon_pwm:switch (priv->kind) {
@@ -1368,9 +1373,9 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 priv->speed_input[i] =get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + priv->fan_structure->speed); - priv->power_input[i] = -get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + - priv->fan_structure->power) *10000 ; +WRITE_ONCE (priv->power_input[i], +get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + + priv->fan_structure->power) *10000 ); priv->voltage_input[i] =get_unaligned_be16 (data + priv->fan_sensor_offsets[i] + priv->fan_structure->voltage) *10 ;
@@ -1410,7 +1415,8 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 priv->speed_input[2 ] =get_unaligned_be16 (data +AQUASTREAMULT_PRESSURE_OFFSET ); priv->speed_input[3 ] =get_unaligned_be16 (data +AQUASTREAMULT_FLOW_SENSOR_OFFSET ); - priv->power_input[1 ] =get_unaligned_be16 (data +AQUASTREAMULT_PUMP_POWER ) *10000 ; +WRITE_ONCE (priv->power_input[1 ], +get_unaligned_be16 (data +AQUASTREAMULT_PUMP_POWER ) *10000 ); priv->voltage_input[1 ] =get_unaligned_be16 (data +AQUASTREAMULT_PUMP_VOLTAGE ) *10 ;
@@ -1423,10 +1429,11 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8case highflownext:/* If external temp sensor is not connected, its power reading is also N/A */ if (priv->temp_input[1 ] == -ENODATA ) - priv->power_input[0 ] = -ENODATA ; +WRITE_ONCE (priv->power_input[0 ], -ENODATA );else - priv->power_input[0 ] = -get_unaligned_be16 (data +HIGHFLOWNEXT_POWER ) *1000000 ; +WRITE_ONCE (priv->power_input[0 ], +min_t (u64,get_unaligned_be16 (data +HIGHFLOWNEXT_POWER ) * +1000000ULL ,LONG_MAX )); priv->voltage_input[0 ] =get_unaligned_be16 (data +HIGHFLOWNEXT_5V_VOLTAGE ) *10 ; priv->voltage_input[1] =
[email protected]
AI reviewRe: [PATCH v5 1/5] hwmon: (aquacomputer_d5next) Avoid truncating scaled sensor readings
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 12 lines
High Flow Next power is reported in watts. Multiplying the 16-bit value by one million can overflow both the signed intermediate and the u32 cache. Store power in long, perform the conversion in u64, and clamp to
LONG_MAX. The other existing power conversions fit in a signed 32-bit value. Return-ENODATAfor unavailable power instead of exposing the stored error as a reading.The power cache is updated by HID reports without the hwmon read mutex. Read it once with
READ_ONCE()and use that snapshot for both the availability check and the returned value. Mark the corresponding updates withWRITE_ONCE()so that the shared accesses are explicit.
Quoted 7 lines
Widen the shared current cache to u32. The Aquastream XT conversion to milliamperes can exceed 65535 mA; clamp its negative conversion results to zero before assigning to the unsigned cache. This also permits devices with scaled aggregate currents to store milliamperes directly.
Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v5 1/5] hwmon: (aquacomputer_d5next) Avoid truncating scaled sensor readings
In reply to Vas ZayarskiyQuoted 12 lines · Vas Zayarskiy
High Flow Next power is reported in watts. Multiplying the 16-bit value by one million can overflow both the signed intermediate and the u32 cache. Store power in long, perform the conversion in u64, and clamp to
LONG_MAX. The other existing power conversions fit in a signed 32-bit value. Return-ENODATAfor unavailable power instead of exposing the stored error as a reading.The power cache is updated by HID reports without the hwmon read mutex. Read it once with
READ_ONCE()and use that snapshot for both the availability check and the returned value. Mark the corresponding updates withWRITE_ONCE()so that the shared accesses are explicit.
Quoted 7 lines
Widen the shared current cache to u32. The Aquastream XT conversion to milliamperes can exceed 65535 mA; clamp its negative conversion results to zero before assigning to the unsigned cache. This also permits devices with scaled aggregate currents to store milliamperes directly.
Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Applied.
Thanks,
Guenter
PATCH v5 2/5 hwmon: (aquacomputer_d5next) Expire the initial sensor cache
In reply to Vas ZayarskiyThe initial update timestamp makes the cache expire at the current jiffy. Since aqc_read() uses time_after(), a read in that same jiffy can expose zero-initialized data or skip the first legacy report request.
Initialize the timestamp one tick earlier so the cache starts expired for every supported device.
--- drivers/hwmon/aquacomputer_d5next.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/aquacomputer_d5next.c +1 -1
@@ -1534,7 +1534,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->hdev = hdev;hid_set_drvdata (hdev, priv); - priv->updated = jiffies -STATUS_UPDATE_INTERVAL ; + priv->updated = jiffies -STATUS_UPDATE_INTERVAL -1 ; ret =hid_parse (hdev);if (ret)
[email protected]
AI reviewRe: [PATCH v5 2/5] hwmon: (aquacomputer_d5next) Expire the initial sensor cache
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
The initial update timestamp makes the cache expire at the current jiffy. Since
aqc_read()usestime_after(), a read in that same jiffy can expose zero-initialized data or skip the first legacy report request.Initialize the timestamp one tick earlier so the cache starts expired for every supported device.
Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v5 2/5] hwmon: (aquacomputer_d5next) Expire the initial sensor cache
In reply to Vas ZayarskiyQuoted 9 lines · Vas Zayarskiy
The initial update timestamp makes the cache expire at the current jiffy. Since
aqc_read()usestime_after(), a read in that same jiffy can expose zero-initialized data or skip the first legacy report request.Initialize the timestamp one tick earlier so the cache starts expired for every supported device.
Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Applied.
Thanks,
Guenter
PATCH v5 3/5 hwmon: (aquacomputer_d5next) Validate incoming status reports
In reply to Vas ZayarskiyThe raw-event callback runs before HID core pads a short report. Check that the report is an input report and that its length matches the HID report descriptor before decoding sensor fields. Otherwise a truncated report can be read past its received data, and a feature report with the same ID can be mistaken for sensor data.
Apply these checks to every device using the shared raw-event path and check the report ID byte before updating the cache. Legacy devices keep using their separate feature-report read path.
--- drivers/hwmon/aquacomputer_d5next.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/aquacomputer_d5next.c +2 -1
@@ -1334,7 +1334,8 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8int i, j, sensor_value;struct aqc_data *priv; -if (report->id !=STATUS_REPORT_ID ) +if (report->id !=STATUS_REPORT_ID || report->type !=HID_INPUT_REPORT || + size !=hid_report_len (report) || data[0 ] !=STATUS_REPORT_ID )return 0 ; priv =hid_get_drvdata (hdev);
[email protected]
AI reviewRe: [PATCH v5 3/5] hwmon: (aquacomputer_d5next) Validate incoming status reports
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
The raw-event callback runs before HID core pads a short report. Check that the report is an input report and that its length matches the HID report descriptor before decoding sensor fields. Otherwise a truncated report can be read past its received data, and a feature report with the same ID can be mistaken for sensor data.
Quoted 6 lines
Apply these checks to every device using the shared raw-event path and check the report ID byte before updating the cache. Legacy devices keep using their separate feature-report read path.
Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v5 3/5] hwmon: (aquacomputer_d5next) Validate incoming status reports
In reply to Vas ZayarskiyQuoted 6 lines · Vas Zayarskiy
The raw-event callback runs before HID core pads a short report. Check that the report is an input report and that its length matches the HID report descriptor before decoding sensor fields. Otherwise a truncated report can be read past its received data, and a feature report with the same ID can be mistaken for sensor data.
Quoted 6 lines
Apply these checks to every device using the shared raw-event path and check the report ID byte before updating the cache. Legacy devices keep using their separate feature-report read path.
Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Applied.
Thanks,
Guenter
PATCH v5 4/5 hwmon: (aquacomputer_d5next) Skip unknown firmware version offsets
In reply to Vas ZayarskiyOnly decode the firmware version when its offset is known, matching the condition used to expose the firmware_version debugfs file. This lets a device leave the offset at zero without interpreting the report ID and following byte as a firmware version.
--- drivers/hwmon/aquacomputer_d5next.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/aquacomputer_d5next.c +2 -1
@@ -1344,7 +1344,8 @@ static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 priv->serial_number[0 ] =get_unaligned_be16 (data + priv->serial_number_start_offset); priv->serial_number[1 ] =get_unaligned_be16 (data + priv->serial_number_start_offset +SERIAL_PART_OFFSET ); - priv->firmware_version =get_unaligned_be16 (data + priv->firmware_version_offset); +if (priv->firmware_version_offset) + priv->firmware_version =get_unaligned_be16 (data + priv->firmware_version_offset);/* Physical temperature sensor readings */ for (i =0 ; i < priv->num_temp_sensors; i++) {
[email protected]
AI reviewRe: [PATCH v5 4/5] hwmon: (aquacomputer_d5next) Skip unknown firmware version offsets
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Only decode the firmware version when its offset is known, matching the condition used to expose the
firmware_versiondebugfs file. This lets a device leave the offset at zero without interpreting the report ID and following byte as a firmware version.Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v5 4/5] hwmon: (aquacomputer_d5next) Skip unknown firmware version offsets
In reply to Vas ZayarskiyQuoted 7 lines · Vas Zayarskiy
Only decode the firmware version when its offset is known, matching the condition used to expose the
firmware_versiondebugfs file. This lets a device leave the offset at zero without interpreting the report ID and following byte as a firmware version.Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Applied.
Thanks,
Guenter
PATCH v5 5/5 hwmon: (aquacomputer_d5next) Add AMPINEL telemetry support
In reply to Vas ZayarskiyAdd read-only total power, total current, input voltage, hotspot temperature and six channel currents for the Aquacomputer AMPINEL.
Decode its 544-byte input report through the existing serial-number, temperature and update path, with power, current and voltage handled in the device-specific switch. Store all readings in hwmon units.
Select the telemetry interface in probe by its vendor collection and input report layout, following the existing Aquaero and Leakshield probe filtering. No match callback or HID core change is required.
The separate keyboard interface is not supported. The driver rejects it in probe, and stock hid-generic yields to this driver's product ID entry, leaving it unbound. This intentionally limits support to telemetry; keyboard support can be addressed separately. Channel labels follow report order; configuration and alarms are not supported.
---
Changes in v5: Mark the AMPINEL power-cache write with WRITE_ONCE().
Documentation/hwmon/aquacomputer_d5next.rst | 13 ++++ drivers/hwmon/Kconfig | 4 +- drivers/hwmon/aquacomputer_d5next.c | 81 ++++++++++++++++++++- 3 files changed, 93 insertions(+), 5 deletions(-)
Documentation/hwmon/aquacomputer_d5next.rst +13 -0
@@ -13,6 +13,7 @@ Supported devices: * Aquacomputer Quadro fan controller * Aquacomputer High Flow Next sensor * Aquacomputer Leakshield leak prevention system +* Aquacomputer AMPINEL power monitor * Aquacomputer Aquastream XT watercooling pump * Aquacomputer Aquastream Ultimate watercooling pump * Aquacomputer Poweradjust 3 fan controller
@@ -69,6 +70,18 @@ The Aquastream XT pump exposes temperature readings for the coolant, external se and fan IC. It also exposes pump and fan speeds (in RPM), voltages, as well as pump current. +The AMPINEL exposes total power, total current, input voltage, hotspot +temperature and six channel currents. Channel numbers follow report order; +their mapping to physical connector pins has not been verified. The readings +are received approximately twice per second. Only sensor reads are supported; +the driver does not configure protection settings or report alarms. +The separate keyboard interface is not supported and remains unbound while +this driver is registered. + +For AMPINEL, ``power1_input`` is total power, ``in0_input`` is input voltage, +``temp1_input`` is hotspot temperature, ``curr1_input`` is total current, and +``curr[2-7]_input`` are the six channel currents. + The Aquastream Ultimate pump exposes coolant temp and an external temp sensor, along with speed, power, voltage and current of both the pump and optionally connected fan. It also exposes pressure and flow speed readings.
drivers/hwmon/Kconfig +2 -2
@@ -257,14 +257,14 @@ config SENSORS_AHT10 will be called aht10. config SENSORS_AQUACOMPUTER_D5NEXT - tristate "Aquacomputer D5 Next, Octo, Quadro, Farbwerk, Farbwerk 360, High Flow Next" + tristate "Aquacomputer D5 Next and other USB devices" depends on USB_HID select CRC16 help If you say yes here you get support for sensors and fans of the Aquacomputer D5 Next watercooling pump, Octo and Quadro fan controllers, Farbwerk and Farbwerk 360 RGB controllers, High Flow - Next sensor, where available. + Next sensor and AMPINEL power monitor, where available. This driver can also be built as a module. If so, the module will be called aquacomputer_d5next.
drivers/hwmon/aquacomputer_d5next.c +78 -3
165 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH v5 5/5] hwmon: (aquacomputer_d5next) Add AMPINEL telemetry support
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
Add read-only total power, total current, input voltage, hotspot temperature and six channel currents for the Aquacomputer AMPINEL.
Decode its 544-byte input report through the existing serial-number, temperature and update path, with power, current and voltage handled in the device-specific switch. Store all readings in hwmon units.
Select the telemetry interface in probe by its vendor collection and input report layout, following the existing Aquaero and Leakshield probe filtering. No match callback or HID core change is required.
Quoted 8 lines
The separate keyboard interface is not supported. The driver rejects it in probe, and stock hid-generic yields to this driver's product ID entry, leaving it unbound. This intentionally limits support to telemetry; keyboard support can be addressed separately. Channel labels follow report order; configuration and alarms are not supported.
Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v5 5/5] hwmon: (aquacomputer_d5next) Add AMPINEL telemetry support
In reply to Vas ZayarskiyQuoted 11 lines · Vas Zayarskiy
Add read-only total power, total current, input voltage, hotspot temperature and six channel currents for the Aquacomputer AMPINEL.
Decode its 544-byte input report through the existing serial-number, temperature and update path, with power, current and voltage handled in the device-specific switch. Store all readings in hwmon units.
Select the telemetry interface in probe by its vendor collection and input report layout, following the existing Aquaero and Leakshield probe filtering. No match callback or HID core change is required.
Quoted 8 lines
The separate keyboard interface is not supported. The driver rejects it in probe, and stock hid-generic yields to this driver's product ID entry, leaving it unbound. This intentionally limits support to telemetry; keyboard support can be addressed separately. Channel labels follow report order; configuration and alarms are not supported.
Assisted-by LLM sparseSigned-off-by Vas Zayarskiy <[email protected]>
Applied.
Thanks,
Guenter
Hi Guenter,
A quick follow-up on this series from September 27. Is there anything else I should address in v5 before it can be considered for inclusion?
V5 includes the power-cache snapshot fix and has been installed and validated locally with stock hid-generic. AMPINEL support is limited to read-only telemetry, as described in the cover letter.
Thanks,
Vas