eth: fbnic: expand hwmon sensor support
Subsystems (4)
cover eth: fbnic: expand hwmon sensor support
fbnic currently exposes only the raw temperature and voltage readings (temp1_input, in0_input) via hwmon. This series builds that out into a complete sensor interface and hardens the read path.
The firmware capability response already carries per-board sensor thresholds, and the firmware can asynchronously report when a sensor crosses one of them. This series surfaces both to userspace and cleans up the supporting plumbing:
- Move the sensor read logic out of fbnic_mac, closer to its only caller in the hwmon code, and drop the now-unused get_sensor op.
- Expose all hwmon attributes unconditionally as read-only (0444).
- Cache the temperature and voltage readings for the current jiffy so a burst of attribute reads issues a single firmware round-trip.
- Parse and expose the temperature (min/max/crit) and voltage (min/max) thresholds. Thresholds the firmware did not populate read back as -ENODATA.
- Add the corresponding alarm attributes, computed by comparing a live reading against the stored thresholds.
- Translate the firmware's sensor-threshold-exceeded message into an hwmon event so userspace is notified on the relevant attribute.
Zinc Lim (6):
eth: fbnic: move sensor read logic out of fbnic_mac
eth: fbnic: expose all hwmon attributes unconditionally as read-only
eth: fbnic: cache hwmon sensor readings
eth: fbnic: report temperature and voltage thresholds via hwmon
eth: fbnic: report temperature and voltage alarms via hwmon
eth: fbnic: firmware notifies hwmon on sensor threshold events
drivers/net/ethernet/meta/fbnic/fbnic.h | 8 + drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 75 +++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 30 ++ drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 260 ++++++++++++++++-- drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 55 ---- drivers/net/ethernet/meta/fbnic/fbnic_mac.h | 2 - 6 files changed, 346 insertions(+), 84 deletions(-)
--
2.53.0-Meta
PATCH 1/6 eth: fbnic: move sensor read logic out of fbnic_mac
The sensor read lived behind the fbnic_mac get_sensor op, but it is only ever used by the hwmon subsystem. Move the read into fbnic_hwmon.c and call it directly there, closer to where it is used, and drop the now-unused get_sensor op from struct fbnic_mac. No functional change.
--- drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 56 ++++++++++++++++++- drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 55 ------------------ drivers/net/ethernet/meta/fbnic/fbnic_mac.h | 2 - 3 files changed, 54 insertions(+), 59 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +54 -2
@@ -28,15 +28,67 @@ static umode_t fbnic_hwmon_is_visible(const void *drvdata,return 0 ; } +static int fbnic_hwmon_sensor_read (struct fbnic_dev *fbd,int id,long *val) +{ +struct fbnic_fw_completion *fw_cmpl; +int err =0 ; +s32 *sensor; + + fw_cmpl =fbnic_fw_alloc_cmpl (FBNIC_TLV_MSG_ID_TSENE_READ_RESP ); +if (!fw_cmpl) +return -ENOMEM ; + +switch (id) { +case FBNIC_SENSOR_TEMP : + sensor = &fw_cmpl->u.tsene.millidegrees; +break ; +case FBNIC_SENSOR_VOLTAGE : + sensor = &fw_cmpl->u.tsene.millivolts; +break ; +default : + err = -EINVAL ; + goto exit_free; + } + + err =fbnic_fw_xmit_tsene_read_msg (fbd, fw_cmpl); +if (err) { +dev_err (fbd->dev, +"Failed to transmit TSENE read msg, err %d\n" , + err); + goto exit_free; + } + +if (!wait_for_completion_timeout (&fw_cmpl->done,10 *HZ )) { +dev_err (fbd->dev,"Timed out waiting for TSENE read\n" ); + err = -ETIMEDOUT ; + goto exit_cleanup; + } + +/* Handle error returned by firmware */ +if (fw_cmpl->result) { + err = fw_cmpl->result; +dev_err (fbd->dev,"%s: Firmware returned error %d\n" , + __func__, err); + goto exit_cleanup; + } + + *val = *sensor; +exit_cleanup: +fbnic_mbx_clear_cmpl (fbd, fw_cmpl); +exit_free: +fbnic_fw_put_cmpl (fw_cmpl); + +return err; +} +static int fbnic_hwmon_read (struct device *dev,enum hwmon_sensor_types type,u32 attr,int channel,long *val) {struct fbnic_dev *fbd =dev_get_drvdata (dev); -const struct fbnic_mac *mac = fbd->mac;int id; id =fbnic_hwmon_sensor_id (type); -return id <0 ? id : mac->get_sensor (fbd, id, val); +return id <0 ? id :fbnic_hwmon_sensor_read (fbd, id, val); }static const struct hwmon_ops fbnic_hwmon_ops = {
drivers/net/ethernet/meta/fbnic/fbnic_mac.c +0 -55
67 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_mac.h +0 -2
@@ -137,8 +137,6 @@ struct fbnic_mac {void (*link_down)(struct fbnic_dev *fbd);void (*link_up)(struct fbnic_dev *fbd,bool tx_pause,bool rx_pause); - -int (*get_sensor)(struct fbnic_dev *fbd,int id,long *val); };int fbnic_mac_init (struct fbnic_dev *fbd);
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH net-next 1/6] eth: fbnic: move sensor read logic out of fbnic_mac
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] A positive firmware error code causes fbnic_hwmon_sensor_read to return a positive value to the hwmon core, which treats it as success and leaks an uninitialized stack variable.
- [High] Mailbox completions lack transaction IDs, allowing late firmware responses from timed-out requests to erroneously complete subsequent requests.
--
--- Patch [1]: [PATCH net-next 1/6] eth: fbnic: move sensor read logic out of fbnic_mac --- commit 3d23a98846b8fe29f6da2d75356fdb3ad9559179
Author: Zinc Lim <[email protected]>
eth: fbnic: move sensor read logic out of fbnic_mac
The sensor read lived behind the fbnic_mac get_sensor op, but it is only ever used by the hwmon subsystem. Move the read into fbnic_hwmon.c and call it directly there, closer to where it is used, and drop the now-unused get_sensor op from struct fbnic_mac. No functional change.
Quoted 5 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +0
-0@@ -28,15 +28,67 @@ static umode_t fbnic_hwmon_is_visible(const void *drvdata,
[ ... ]
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c static umode_t fbnic_hwmon_is_visible(const void *drvdata, · line 65
Quoted 13 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +13
-0+ err =fbnic_fw_xmit_tsene_read_msg (fbd, fw_cmpl); +if (err) { +dev_err (fbd->dev, +"Failed to transmit TSENE read msg, err %d\n" , + err); + goto exit_free; + } + +if (!wait_for_completion_timeout (&fw_cmpl->done,10 *HZ )) { +dev_err (fbd->dev,"Timed out waiting for TSENE read\n" ); + err = -ETIMEDOUT ; + goto exit_cleanup; + }
[Severity: High]
This is a pre-existing issue, but does timing out and clearing the completion slot expose the driver to late responses matching the next request?
If wait_for_completion_timeout() times out, the mailbox slot is cleared. Since the matching logic in fbnic_fw_get_cmpl_by_type() uses only the message type:
if (fbd->cmpl_data[i] &&
fbd->cmpl_data[i]->msg_type == msg_type) {Will a delayed response to this request erroneously complete a subsequent request of the same type?
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c static umode_t fbnic_hwmon_is_visible(const void *drvdata, · line 73
Quoted 8 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +8
-0+ +/* Handle error returned by firmware */ +if (fw_cmpl->result) { + err = fw_cmpl->result; +dev_err (fbd->dev,"%s: Firmware returned error %d\n" , + __func__, err); + goto exit_cleanup; + }
[Severity: High]
This isn't a bug introduced by this patch, but what happens if the firmware returns a positive error code in fw_cmpl->result?
Since this error code is propagated back to the hwmon core, and the hwmon core only checks for negative error codes, will it treat a positive value as success and leak an uninitialized stack variable (val) to userspace?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/6 eth: fbnic: expose all hwmon attributes unconditionally as read-only
In reply to Zinc LimAll fbnic hwmon attributes are read-only and always present, so fbnic_hwmon_is_visible() can simply return 0444 for everything instead of matching on the sensor type and attribute. This also prepares for the threshold and alarm attributes added in the following patches: they are exposed unconditionally and reads return attribute values.
--- drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +1 -6
@@ -20,12 +20,7 @@ static umode_t fbnic_hwmon_is_visible(const void *drvdata,enum hwmon_sensor_types type, u32 attr, int channel) { - if (type == hwmon_temp && attr == hwmon_temp_input) - return 0444; - if (type == hwmon_in && attr == hwmon_in_input) - return 0444; - -return 0 ; + return 0444; }static int fbnic_hwmon_sensor_read (struct fbnic_dev *fbd,int id,long *val)
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH net-next 2/6] eth: fbnic: expose all hwmon attributes unconditionally as read-only
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
All fbnic hwmon attributes are read-only and always present, so
fbnic_hwmon_is_visible()can simply return 0444 for everything instead of matching on the sensor type and attribute. This also prepares for the threshold and alarm attributes added in the following patches: they are exposed unconditionally and reads return attribute values.Signed-off-by Zinc Lim <[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
PATCH 3/6 eth: fbnic: cache hwmon sensor readings
In reply to Zinc LimEach hwmon attribute access triggers its own TSENE firmware mailbox round-trip, so reading the full set of attributes or polling them at a high rate floods the firmware mailbox with quick, successive IPC messages for data that barely changes between ticks.
Cache the last temperature and voltage reading and serve reads from it for the remainder of the current jiffy. A single TSENE response carries both readings, so one transaction on a miss refreshes both and satisfies a whole batch of reads. The cache is seeded with the FBNIC_SENSOR_NO_DATA sentinel at registration so the first read always refreshes, and concurrent reads are serialized by the hwmon core so no additional locking is required.
--- drivers/net/ethernet/meta/fbnic/fbnic.h | 7 ++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 7 ++++ drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 36 +++++++++++++------ 3 files changed, 40 insertions(+), 10 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic.h +7 -0
@@ -22,11 +22,18 @@ struct fbnic_napi_vector;#define FBNIC_MAX_NAPI_VECTORS 128u#define FBNIC_MBX_CMPL_SLOTS 4 +struct fbnic_hwmon_cache { +unsigned long last_read; +s32 temp_mdeg; +s32 volt_mv; +}; +struct fbnic_dev {struct device *dev;struct net_device *netdev;struct dentry *dbg_fbd;struct device *hwmon; +struct fbnic_hwmon_cache hwmon_cache;struct devlink_health_reporter *fw_reporter;struct devlink_health_reporter *otp_reporter;
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +7 -0
@@ -6,6 +6,7 @@#include <linux/completion.h> #include <linux/if_ether.h> +#include <linux/limits.h> #include <linux/types.h> struct fbnic_dev ;
@@ -44,6 +45,12 @@ struct fbnic_fw_ver {char commit[FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE ]; }; +/* Sentinel for a sensor value the driver does not have: a threshold the +* firmware never populated (older firmware) or a cache entry not yet +* refreshed. +*/ +#define FBNIC_SENSOR_NO_DATA S32_MIN +struct fbnic_fw_cap {struct {struct fbnic_fw_ver mgmt, bootloader;
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +26 -10
@@ -2,6 +2,7 @@/* Copyright (c) Meta Platforms, Inc. and affiliates. */ #include <linux/hwmon.h> +#include <linux/jiffies.h> #include "fbnic.h" #include "fbnic_mac.h"
@@ -25,26 +26,32 @@ static umode_t fbnic_hwmon_is_visible(const void *drvdata,static int fbnic_hwmon_sensor_read (struct fbnic_dev *fbd,int id,long *val) { +struct fbnic_hwmon_cache *cache = &fbd->hwmon_cache;struct fbnic_fw_completion *fw_cmpl;int err =0 ; -s32 *sensor; - - fw_cmpl =fbnic_fw_alloc_cmpl (FBNIC_TLV_MSG_ID_TSENE_READ_RESP ); -if (!fw_cmpl) -return -ENOMEM ; +s32 *cached;switch (id) {case FBNIC_SENSOR_TEMP : - sensor = &fw_cmpl->u.tsene.millidegrees; + cached = &cache->temp_mdeg;break ;case FBNIC_SENSOR_VOLTAGE : - sensor = &fw_cmpl->u.tsene.millivolts; + cached = &cache->volt_mv;break ;default : - err = -EINVAL ; - goto exit_free; +return -EINVAL ; + } + +if (*cached !=FBNIC_SENSOR_NO_DATA && +time_is_after_eq_jiffies (cache->last_read)) { + *val = *cached; +return 0 ; } + fw_cmpl =fbnic_fw_alloc_cmpl (FBNIC_TLV_MSG_ID_TSENE_READ_RESP ); +if (!fw_cmpl) +return -ENOMEM ; + err =fbnic_fw_xmit_tsene_read_msg (fbd, fw_cmpl);if (err) { dev_err(fbd->dev,
@@ -67,7 +74,12 @@ static int fbnic_hwmon_sensor_read(struct fbnic_dev *fbd, int id, long *val) goto exit_cleanup; } - *val = *sensor; +/* FW returns both readings in one response, cache both. */ + cache->temp_mdeg = fw_cmpl->u.tsene.millidegrees; + cache->volt_mv = fw_cmpl->u.tsene.millivolts; + cache->last_read = jiffies; + + *val = *cached; exit_cleanup:fbnic_mbx_clear_cmpl (fbd, fw_cmpl); exit_free:
@@ -107,6 +119,10 @@ void fbnic_hwmon_register(struct fbnic_dev *fbd)if (!IS_REACHABLE (CONFIG_HWMON ))return ; +/* Seed cache with sentinel so the first read always refreshes. */ + fbd->hwmon_cache.temp_mdeg =FBNIC_SENSOR_NO_DATA ; + fbd->hwmon_cache.volt_mv =FBNIC_SENSOR_NO_DATA ; + fbd->hwmon =hwmon_device_register_with_info (fbd->dev,"fbnic" , fbd, &fbnic_chip_info,NULL );
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH net-next 3/6] eth: fbnic: cache hwmon sensor readings
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The hardware monitoring cache expiration check is vulnerable to a 24-day jiffies wraparound bug…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The hardware monitoring cache expiration check is vulnerable to a 24-day jiffies wraparound bug on 32-bit systems, which can cause the driver to indefinitely serve stale sensor readings. --
--- Patch [3]: [PATCH net-next 3/6] eth: fbnic: cache hwmon sensor readings --- commit 4d77f6b947d1d111d9ffbbeb2ef3742b0f54686f
Author: Zinc Lim <[email protected]>
Subject: eth: fbnic: cache hwmon sensor readings
This commit introduces caching for hardware monitoring sensor readings to reduce firmware mailbox IPC traffic. It caches the temperature and voltage values and serves them for the remainder of the current jiffy, using a sentinel value to ensure the first read always triggers a refresh.
Quoted 3 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +0
-0
[ ... ]
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +3
-0@@ -25,26 +26,32 @@ static int fbnic_hwmon_sensor_read(struct fbnic_dev *fbd, int id, long *val) { +struct fbnic_hwmon_cache *cache = &fbd->hwmon_cache;struct fbnic_fw_completion *fw_cmpl;int err =0 ; +s32 *cached;switch (id) {case FBNIC_SENSOR_TEMP : + cached = &cache->temp_mdeg;
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c static int fbnic_hwmon_sensor_read(struct fbnic_dev *fbd, int id, long *val) · line 44
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +6
-0break ;case FBNIC_SENSOR_VOLTAGE : + cached = &cache->volt_mv;break ;default : +return -EINVAL ; + } + +if (*cached !=FBNIC_SENSOR_NO_DATA && +time_is_after_eq_jiffies (cache->last_read)) {
[Severity: Medium]
Can this cache expiration check cause stale readings on 32-bit systems due to jiffies wraparound?
If the hwmon sysfs files are not read for ~24.8 days, the jiffies counter will advance such that the signed subtraction in time_is_after_eq_jiffies() underflows. This would cause the macro to evaluate to true, resulting in a cache hit.
Since a cache hit bypasses the firmware read and does not update last_read, would the driver continually return the same stale cached value for the next 24.8 days until the difference wraps back to negative?
Given the commit message mentions serving reads "for the remainder of the current jiffy", should this explicitly check for jiffies == cache->last_read instead?
Quoted 3 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +2
-0+ *val = *cached; +return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH 4/6 eth: fbnic: report temperature and voltage thresholds via hwmon
In reply to Zinc LimThe firmware capability response carries per-board temperature (min/max/crit) and voltage (min/max) thresholds. Parse and store them in fbnic_fw_cap, and expose them through the hwmon interface as temp1_{min,max,crit} and in0_{min,max}.
The thresholds are always exposed. Values the firmware did not report are stored as the FBNIC_SENSOR_NO_DATA sentinel in the capability response parser, and a read of such an attribute returns -ENODATA.
--- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 21 ++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 14 ++++ drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 67 ++++++++++++++----- 3 files changed, 87 insertions(+), 15 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +21 -0
@@ -575,6 +575,11 @@ static const struct fbnic_tlv_index fbnic_fw_cap_resp_index[] = {FBNIC_TLV_ATTR_STRING (FBNIC_FW_CAP_RESP_UEFI_COMMIT_STR ,FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE ),FBNIC_TLV_ATTR_U32 (FBNIC_FW_CAP_RESP_ANTI_ROLLBACK_VERSION ), +FBNIC_TLV_ATTR_S32 (FBNIC_FW_CAP_RESP_TEMP_MIN ), +FBNIC_TLV_ATTR_S32 (FBNIC_FW_CAP_RESP_TEMP_MAX ), +FBNIC_TLV_ATTR_S32 (FBNIC_FW_CAP_RESP_TEMP_CRIT ), +FBNIC_TLV_ATTR_S32 (FBNIC_FW_CAP_RESP_VOLT_MIN ), +FBNIC_TLV_ATTR_S32 (FBNIC_FW_CAP_RESP_VOLT_MAX ), FBNIC_TLV_ATTR_LAST };
@@ -702,6 +707,22 @@ static int fbnic_fw_parse_cap_resp(void *opaque, struct fbnic_tlv_msg **results)/* Always assume we need a BMC reinit */ fbd->fw_cap.need_bmc_tcam_reinit = true; + fbd->fw_cap.temp.min = +fbnic_tlv_attr_get_signed (results[FBNIC_FW_CAP_RESP_TEMP_MIN ], +FBNIC_SENSOR_NO_DATA ); + fbd->fw_cap.temp.max = +fbnic_tlv_attr_get_signed (results[FBNIC_FW_CAP_RESP_TEMP_MAX ], +FBNIC_SENSOR_NO_DATA ); + fbd->fw_cap.temp.crit = +fbnic_tlv_attr_get_signed (results[FBNIC_FW_CAP_RESP_TEMP_CRIT ], +FBNIC_SENSOR_NO_DATA ); + fbd->fw_cap.volt.min = +fbnic_tlv_attr_get_signed (results[FBNIC_FW_CAP_RESP_VOLT_MIN ], +FBNIC_SENSOR_NO_DATA ); + fbd->fw_cap.volt.max = +fbnic_tlv_attr_get_signed (results[FBNIC_FW_CAP_RESP_VOLT_MAX ], +FBNIC_SENSOR_NO_DATA ); +return 0 ; }
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +14 -0
@@ -51,6 +51,12 @@ struct fbnic_fw_ver {*/ #define FBNIC_SENSOR_NO_DATA S32_MIN +struct fbnic_threshold { +s32 min; +s32 max; +s32 crit; +}; +struct fbnic_fw_cap {struct {struct fbnic_fw_ver mgmt, bootloader;
@@ -67,6 +73,8 @@ struct fbnic_fw_cap {u8 link_speed;u8 link_fec;u32 anti_rollback_version; +struct fbnic_threshold temp; +struct fbnic_threshold volt; };struct fbnic_fw_completion {
@@ -249,6 +257,12 @@ enum {FBNIC_FW_CAP_RESP_UEFI_VERSION =0x11 ,FBNIC_FW_CAP_RESP_UEFI_COMMIT_STR =0x12 ,FBNIC_FW_CAP_RESP_ANTI_ROLLBACK_VERSION =0x15 , +/* 0x16 and 0x17 are reserved for future use */ +FBNIC_FW_CAP_RESP_TEMP_MIN =0x18 , +FBNIC_FW_CAP_RESP_TEMP_MAX =0x19 , +FBNIC_FW_CAP_RESP_TEMP_CRIT =0x1a , +FBNIC_FW_CAP_RESP_VOLT_MIN =0x1b , +FBNIC_FW_CAP_RESP_VOLT_MAX =0x1c ,FBNIC_FW_CAP_RESP_MSG_MAX };
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +52 -15
90 lines not on this page · raw message
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH net-next 4/6] eth: fbnic: report temperature and voltage thresholds via hwmon
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
The firmware capability response carries per-board temperature (min/max/crit) and voltage (min/max) thresholds. Parse and store them in
fbnic_fw_cap, and expose them through the hwmon interface as temp1_{min,max,crit} and in0_{min,max}.The thresholds are always exposed. Values the firmware did not report are stored as the
FBNIC_SENSOR_NO_DATAsentinel in the capability response parser, and a read of such an attribute returns-ENODATA.Signed-off-by Zinc Lim <[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
PATCH 5/6 eth: fbnic: report temperature and voltage alarms via hwmon
In reply to Zinc LimBuilding on the temperature and voltage thresholds stored in fbnic_fw_cap, expose alarm attributes through the hwmon interface:
temp1_{min,max,crit}_alarm and in0_{min,max}_alarm.
Each alarm is computed by taking a live sensor reading and comparing it against the corresponding stored threshold. The static thresholds (min/max/crit) are returned first straight from fbnic_fw_cap without a firmware round-trip, and unsupported attributes are rejected up front, so only attributes that actually need a live value fall through to a single sensor read that then feeds input and every alarm.
A threshold the firmware did not populate reports -ENODATA for both the threshold attribute and its alarm.
--- drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +61 -7
@@ -87,34 +87,84 @@ static int fbnic_hwmon_read_threshold(long thr, long *val)return 0 ; } +static int fbnic_hwmon_read_alarm (long a,long b,long *val) +{ +if (a ==FBNIC_SENSOR_NO_DATA || b ==FBNIC_SENSOR_NO_DATA ) +return -ENODATA ; + + *val = a >= b; +return 0 ; +} +static int fbnic_hwmon_temp_read (struct fbnic_dev *fbd,u32 attr,long *val) { +int err; +switch (attr) { -case hwmon_temp_input: -return fbnic_hwmon_sensor_read (fbd,FBNIC_SENSOR_TEMP , val);case hwmon_temp_min:return fbnic_hwmon_read_threshold (fbd->fw_cap.temp.min, val);case hwmon_temp_max:return fbnic_hwmon_read_threshold (fbd->fw_cap.temp.max, val);case hwmon_temp_crit:return fbnic_hwmon_read_threshold (fbd->fw_cap.temp.crit, val); +case hwmon_temp_input: +case hwmon_temp_min_alarm: +case hwmon_temp_max_alarm: +case hwmon_temp_crit_alarm: +break ;default :return -EOPNOTSUPP ; } + + err =fbnic_hwmon_sensor_read (fbd,FBNIC_SENSOR_TEMP , val); +if (err) +return err; + +switch (attr) { +case hwmon_temp_input: +return 0 ; +case hwmon_temp_min_alarm: +return fbnic_hwmon_read_alarm (fbd->fw_cap.temp.min, *val, val); +case hwmon_temp_max_alarm: +return fbnic_hwmon_read_alarm (*val, fbd->fw_cap.temp.max, val); +case hwmon_temp_crit_alarm: +return fbnic_hwmon_read_alarm (*val, fbd->fw_cap.temp.crit, val); + } + +return -EOPNOTSUPP ; }static int fbnic_hwmon_in_read (struct fbnic_dev *fbd,u32 attr,long *val) { +int err; +switch (attr) { -case hwmon_in_input: -return fbnic_hwmon_sensor_read (fbd,FBNIC_SENSOR_VOLTAGE , val);case hwmon_in_min:return fbnic_hwmon_read_threshold (fbd->fw_cap.volt.min, val);case hwmon_in_max:return fbnic_hwmon_read_threshold (fbd->fw_cap.volt.max, val); +case hwmon_in_input: +case hwmon_in_min_alarm: +case hwmon_in_max_alarm: +break ;default :return -EOPNOTSUPP ; } + + err =fbnic_hwmon_sensor_read (fbd,FBNIC_SENSOR_VOLTAGE , val); +if (err) +return err; + +switch (attr) { +case hwmon_in_input: +return 0 ; +case hwmon_in_min_alarm: +return fbnic_hwmon_read_alarm (fbd->fw_cap.volt.min, *val, val); +case hwmon_in_max_alarm: +return fbnic_hwmon_read_alarm (*val, fbd->fw_cap.volt.max, val); + } + +return -EOPNOTSUPP ; } static int fbnic_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
@@ -139,10 +189,14 @@ static const struct hwmon_ops fbnic_hwmon_ops = {static const struct hwmon_channel_info *fbnic_hwmon_info[] = {HWMON_CHANNEL_INFO (temp, -HWMON_T_INPUT |HWMON_T_MIN |HWMON_T_MAX | -HWMON_T_CRIT ), +HWMON_T_INPUT | +HWMON_T_MIN |HWMON_T_MIN_ALARM | +HWMON_T_MAX |HWMON_T_MAX_ALARM | +HWMON_T_CRIT |HWMON_T_CRIT_ALARM ),HWMON_CHANNEL_INFO (in, -HWMON_I_INPUT |HWMON_I_MIN |HWMON_I_MAX ), +HWMON_I_INPUT | +HWMON_I_MIN |HWMON_I_MIN_ALARM | +HWMON_I_MAX |HWMON_I_MAX_ALARM ),NULL };
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH net-next 5/6] eth: fbnic: report temperature and voltage alarms via hwmon
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Unpopulated alarm attributes trigger unnecessary firmware reads instead of being rejected up…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Unpopulated alarm attributes trigger unnecessary firmware reads instead of being rejected up front.
- [Medium] Hardware monitoring alarms are improperly computed in software by the driver.
--
--- Patch [5]: [PATCH net-next 5/6] eth: fbnic: report temperature and voltage alarms via hwmon --- commit 6d735c75df1c02d16911aecd205cd4bf98b0bb3b
Author: Zinc Lim <[email protected]>
eth: fbnic: report temperature and voltage alarms via hwmon
Building on the temperature and voltage thresholds stored in fbnic_fw_cap, expose alarm attributes through the hwmon interface:
temp1_{min,max,crit}_alarm and in0_{min,max}_alarm.
Quoted 4 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +0
-0
[ ... ]
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c static int fbnic_hwmon_read_threshold(long thr, long *val) · line 95
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +6
-0@@ -87,34 +87,84 @@ static int fbnic_hwmon_read_threshold(long thr, long *val)return 0 ; } +static int fbnic_hwmon_read_alarm (long a,long b,long *val) +{ +if (a ==FBNIC_SENSOR_NO_DATA || b ==FBNIC_SENSOR_NO_DATA ) +return -ENODATA ; + + *val = a >= b;
[Severity: Medium]
Is it intentional to compute alarms in software by comparing the live sensor reading against the threshold here?
According to the hwmon sysfs ABI documentation, drivers should not make comparisons of readings to thresholds themselves. Alarms are expected to be hardware-latched indications that can catch transient spikes between polls.
If the hardware does not support latched alarms, should these alarm attributes be omitted entirely so user-space tools can handle their own software threshold comparisons?
Quoted 16 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +5
-2+return 0 ; +} +static int fbnic_hwmon_temp_read (struct fbnic_dev *fbd,u32 attr,long *val) { +int err; +switch (attr) { -case hwmon_temp_input: -return fbnic_hwmon_sensor_read (fbd,FBNIC_SENSOR_TEMP , val);case hwmon_temp_min:return fbnic_hwmon_read_threshold (fbd->fw_cap.temp.min, val);case hwmon_temp_max:return fbnic_hwmon_read_threshold (fbd->fw_cap.temp.max, val);case hwmon_temp_crit:return fbnic_hwmon_read_threshold (fbd->fw_cap.temp.crit, val);
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c static int fbnic_hwmon_read_threshold(long thr, long *val) · line 119
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +7
-0+case hwmon_temp_input: +case hwmon_temp_min_alarm: +case hwmon_temp_max_alarm: +case hwmon_temp_crit_alarm: +break ;default :return -EOPNOTSUPP ; } + + err =fbnic_hwmon_sensor_read (fbd,FBNIC_SENSOR_TEMP , val);
[Severity: Medium]
The commit message notes that unsupported attributes are rejected up front, but does this code fall through for unpopulated alarm thresholds and trigger a blocking firmware read before eventually returning -ENODATA?
If fbd->fw_cap.temp.min is FBNIC_SENSOR_NO_DATA, reading hwmon_temp_min_alarm will hit the break statement above, execute this sensor read, and then fail later inside fbnic_hwmon_read_alarm().
Could we check the threshold value up front before issuing the mailbox request?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH 6/6 eth: fbnic: firmware notifies hwmon on sensor threshold events
In reply to Zinc LimThe firmware sends an unsolicited message via the new FBNIC_TLV_MSG_ID_SENSOR_THRESHOLD_EXCEEDED_RESP IPC message when a temperature or voltage sensor crosses one of its thresholds. Parse this message and translate it into the corresponding hwmon alarm (temp1_{min,max,crit}_alarm or in0_{min,max}_alarm) via hwmon_notify_event(), so userspace listeners are woken on the relevant sysfs attribute.
fbnic_hwmon_notify_event() is driven from the FW mailbox IRQ path, so it can run concurrently with hwmon registration and teardown. Guard the publish/teardown of fbd->hwmon: register publishes it with WRITE_ONCE() only after a successful registration (and leaves it NULL on failure), unregister clears it with WRITE_ONCE(NULL) and then synchronize_irq(fbd->fw_msix_vector) to drain any in-flight mailbox IRQ before unregistering, and notify_event reads it once with READ_ONCE() and skips the notification when it is NULL.
--- drivers/net/ethernet/meta/fbnic/fbnic.h | 1 + drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 54 +++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 9 +++ drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 68 ++++++++++++++++--- 4 files changed, 124 insertions(+), 8 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic.h +1 -0
@@ -192,6 +192,7 @@ void fbnic_fw_free_mbx(struct fbnic_dev *fbd);void fbnic_hwmon_register (struct fbnic_dev *fbd);void fbnic_hwmon_unregister (struct fbnic_dev *fbd); +void fbnic_hwmon_notify_event (struct fbnic_dev *fbd,int id,long val);int fbnic_mac_request_irq (struct fbnic_dev *fbd);void fbnic_mac_free_irq (struct fbnic_dev *fbd);
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +54 -0
66 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +9 -0
@@ -227,6 +227,7 @@ enum {FBNIC_TLV_MSG_ID_QSFP_READ_RESP =0x39 ,FBNIC_TLV_MSG_ID_TSENE_READ_REQ =0x3C ,FBNIC_TLV_MSG_ID_TSENE_READ_RESP =0x3D , +FBNIC_TLV_MSG_ID_SENSOR_THRESHOLD_EXCEEDED_RESP =0x40 ,FBNIC_TLV_MSG_ID_LOG_SEND_LOGS_REQ =0x43 ,FBNIC_TLV_MSG_ID_LOG_MSG_REQ =0x44 , FBNIC_TLV_MSG_ID_LOG_MSG_RESP = 0x45,
@@ -296,6 +297,14 @@ enum {FBNIC_FW_TSENE_MSG_MAX }; +enum { +FBNIC_FW_TSENE_THERM_EXCEEDED_FLAG =0x0 , +FBNIC_FW_TSENE_VOLT_EXCEEDED_FLAG =0x1 , +FBNIC_FW_TSENE_THERMAL =0x2 , +FBNIC_FW_TSENE_VOLTAGE =0x3 , +FBNIC_FW_TSENE_EXCEEDED_MSG_MAX , +}; +enum {FBNIC_FW_OWNERSHIP_FLAG =0x0 ,FBNIC_FW_OWNERSHIP_TIME =0x1 ,
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +60 -8
88 lines not on this page · raw message
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewRe: [PATCH net-next 6/6] eth: fbnic: firmware notifies hwmon on sensor threshold events
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Medium] Uninitialized sensor thresholds default to S32_MIN, causing alarm checks to always evaluate to true and trigger incorrect alarms.
- [Low] Missing IS_REACHABLE(CONFIG_HWMON) guard in fbnic_hwmon_notify_event causes a linker error when CONFIG_HWMON is disabled.
Pre-existing issues:
- [High] Error path in fbnic_fw_request_mbx saves a freed IRQ vector, leading to a double-free on device removal. --
--- Patch [6]: [PATCH net-next 6/6] eth: fbnic: firmware notifies hwmon on sensor threshold events --- commit 47c1b3bcb6116f975f3ccbd306542f2c5e9bd4f2
Author: Zinc Lim <[email protected]>
eth: fbnic: firmware notifies hwmon on sensor threshold events
The firmware sends an unsolicited message via the new FBNIC_TLV_MSG_ID_SENSOR_THRESHOLD_EXCEEDED_RESP IPC message when a temperature or voltage sensor crosses one of its thresholds. Parse this message and translate it into the corresponding hwmon alarm (temp1_{min,max,crit}_alarm or in0_{min,max}_alarm) via hwmon_notify_event(), so userspace listeners are woken on the relevant sysfs attribute.
Quoted 4 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +0
-0@@ -214,22 +216,72 @@ void fbnic_hwmon_register(struct fbnic_dev *fbd)
[ ... ]
Quoted 4 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +4
-0+void fbnic_hwmon_notify_event (struct fbnic_dev *fbd,int id,long val) +{ +enum hwmon_sensor_types type; +struct device *hwmon;
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c void fbnic_hwmon_register(struct fbnic_dev *fbd) · line 262
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +10
-0+s32 attr =-1 ; + +switch (id) { +case FBNIC_SENSOR_TEMP : + type = hwmon_temp; + +if (val <= fbd->fw_cap.temp.min) + attr = hwmon_temp_min_alarm; +else if (val >= fbd->fw_cap.temp.crit) + attr = hwmon_temp_crit_alarm;
[Severity: Medium]
Will this evaluate to true if the firmware does not provide a critical threshold?
It appears that fbnic_fw_parse_cap_resp() initializes these thresholds to the sentinel value FBNIC_SENSOR_NO_DATA (S32_MIN) when they aren't provided.
Since S32_MIN is the minimum possible 32-bit integer, any valid temperature reading will be greater than S32_MIN, causing this condition to incorrectly evaluate to true and preventing subsequent valid threshold checks from being evaluated.
Quoted 14 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +14
-0+else if (val >= fbd->fw_cap.temp.max) + attr = hwmon_temp_max_alarm; + +break ; +case FBNIC_SENSOR_VOLTAGE : + type = hwmon_in; + +if (val <= fbd->fw_cap.volt.min) + attr = hwmon_in_min_alarm; +else if (val >= fbd->fw_cap.volt.max) + attr = hwmon_in_max_alarm; + +break ; +default :
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c void fbnic_hwmon_register(struct fbnic_dev *fbd) · line 286
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +10
-0+return ; + } + +/* Pair with WRITE_ONCE() in fbnic_hwmon_unregister(). Skip the +* notification if hwmon failed to register or has already been torn +* down. +*/ + hwmon =READ_ONCE (fbd->hwmon); +if (attr >=0 && hwmon) +hwmon_notify_event (hwmon, type, attr,0 );
[Severity: Low]
Does this result in a linker error if CONFIG_HWMON is disabled?
Since fbnic_hwmon_notify_event() is built unconditionally when CONFIG_FBNIC is enabled, and hwmon_notify_event() is declared in include/linux/hwmon.h without a fallback stub for !CONFIG_HWMON, calling it without an IS_REACHABLE(CONFIG_HWMON) guard will cause the linker to fail to resolve hwmon_notify_event().
Quoted 1 line
}
[Severity: High]
This is a pre-existing issue, but does the error path in fbnic_fw_request_mbx() save a freed IRQ vector?
drivers/net/ethernet/meta/fbnic/fbnic_irq.c:fbnic_fw_request_mbx() {
...
if (err)
free_irq(vector, fbd);
fbd->fw_msix_vector = vector;
...
}If a device resumes from suspend and this path fails, fbd->fw_msix_vector is left holding the freed vector number.
Later, when the device is removed, fbnic_remove() invokes fbnic_fw_free_mbx(). Since fbd->fw_msix_vector is non-zero, it skips the safety check and attempts to free the already freed vector, leading to a double-free.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Jakub Kicinski
maintainerRe: [PATCH net-next 6/6] eth: fbnic: firmware notifies hwmon on sensor threshold events
In reply to Zinc LimQuoted 29 lines · On Tue, 21 Jul 2026 15:15:40 -0700 Zinc Lim wrote:
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +29
-0+void fbnic_hwmon_notify_event (struct fbnic_dev *fbd,int id,long val) +{ +enum hwmon_sensor_types type; +struct device *hwmon; +s32 attr =-1 ; + +switch (id) { +case FBNIC_SENSOR_TEMP : + type = hwmon_temp; + +if (val <= fbd->fw_cap.temp.min) + attr = hwmon_temp_min_alarm; +else if (val >= fbd->fw_cap.temp.crit) + attr = hwmon_temp_crit_alarm; +else if (val >= fbd->fw_cap.temp.max) + attr = hwmon_temp_max_alarm; + +break ; +case FBNIC_SENSOR_VOLTAGE : + type = hwmon_in; + +if (val <= fbd->fw_cap.volt.min) + attr = hwmon_in_min_alarm; +else if (val >= fbd->fw_cap.volt.max) + attr = hwmon_in_max_alarm; + +break ; +default : +return ;
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c void fbnic_hwmon_register(struct fbnic_dev *fbd) · line 287
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c +9
-0+ } + +/* Pair with WRITE_ONCE() in fbnic_hwmon_unregister(). Skip the +* notification if hwmon failed to register or has already been torn +* down. +*/ + hwmon =READ_ONCE (fbd->hwmon); +if (attr >=0 && hwmon) +hwmon_notify_event (hwmon, type, attr,0 ); }
We need a
if (!IS_REACHABLE(CONFIG_HWMON)) return;
in this function, so that compiler can eliminate the hwmon_notify_event() call _completely_ if HWMON is a module and the driver is built into the main kernel image.
Signature · 1 line
pw-bot: cr