[PATCH net-next 4/6] eth: fbnic: report temperature and voltage thresholds via hwmon
From: Zinc Lim <hidden>
Date: 2026-07-21 22:15:52
Also in:
linux-hwmon, lkml
Subsystem:
meta ethernet drivers, networking drivers, the rest · Maintainers:
Alexander Duyck, Jakub Kicinski, Andrew Lunn, "David S. Miller", Eric Dumazet, Paolo Abeni, Linus Torvalds
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_DATA sentinel in the capability response
parser, and a read of such an attribute returns -ENODATA.
Signed-off-by: Zinc Lim <redacted>
---
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(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
index 283d25fae79e..d814bd4041a0 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c@@ -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; }
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
index 42a5f83ddb45..68ffd49e0cdd 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h@@ -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 };
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
index f35cb0065093..4938f7b39140 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c@@ -7,16 +7,6 @@ #include "fbnic.h" #include "fbnic_mac.h" -static int fbnic_hwmon_sensor_id(enum hwmon_sensor_types type) -{ - if (type == hwmon_temp) - return FBNIC_SENSOR_TEMP; - if (type == hwmon_in) - return FBNIC_SENSOR_VOLTAGE; - - return -EOPNOTSUPP; -} - static umode_t fbnic_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr, int channel)
@@ -88,14 +78,58 @@ static int fbnic_hwmon_sensor_read(struct fbnic_dev *fbd, int id, long *val) return err; } +static int fbnic_hwmon_read_threshold(long thr, long *val) +{ + if (thr == FBNIC_SENSOR_NO_DATA) + return -ENODATA; + + *val = thr; + return 0; +} + +static int fbnic_hwmon_temp_read(struct fbnic_dev *fbd, u32 attr, long *val) +{ + 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); + default: + return -EOPNOTSUPP; + } +} + +static int fbnic_hwmon_in_read(struct fbnic_dev *fbd, u32 attr, long *val) +{ + 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); + default: + return -EOPNOTSUPP; + } +} + 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); - int id; - id = fbnic_hwmon_sensor_id(type); - return id < 0 ? id : fbnic_hwmon_sensor_read(fbd, id, val); + switch (type) { + case hwmon_temp: + return fbnic_hwmon_temp_read(fbd, attr, val); + case hwmon_in: + return fbnic_hwmon_in_read(fbd, attr, val); + default: + return -EOPNOTSUPP; + } } static const struct hwmon_ops fbnic_hwmon_ops = {
@@ -104,8 +138,11 @@ 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_CHANNEL_INFO(in, HWMON_I_INPUT), + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_CRIT), + HWMON_CHANNEL_INFO(in, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX), NULL };
--
2.53.0-Meta