From: Zinc Lim <limzhineng2@gmail.com>
To: Alexander Duyck <alexanderduyck@fb.com>,
Jakub Kicinski <kuba@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Guenter Roeck <linux@roeck-us.net>,
Simon Horman <horms@kernel.org>,
Mohsin Bashir <mohsin.bashr@gmail.com>
Cc: kernel-team@meta.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
zinclim@meta.com, Zinc Lim <limzhineng2@gmail.com>
Subject: [PATCH net-next v2 5/6] eth: fbnic: report temperature and voltage alarms via hwmon
Date: Mon, 24 Aug 2026 10:50:58 -0700 [thread overview]
Message-ID: <20260824175059.2485048-6-limzhineng2@gmail.com> (raw)
In-Reply-To: <20260824175059.2485048-1-limzhineng2@gmail.com>
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.
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.
Signed-off-by: Zinc Lim <limzhineng2@gmail.com>
---
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 68 +++++++++++++++++--
1 file changed, 61 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
index 4938f7b39140..c5cddd9cef12 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
@@ -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
};
--
2.53.0-Meta
next prev parent reply other threads:[~2026-08-24 17:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 17:50 [PATCH net-next v2 0/6] eth: fbnic: expand hwmon sensor support Zinc Lim
2026-08-24 17:50 ` [PATCH net-next v2 1/6] eth: fbnic: move sensor read logic out of fbnic_mac Zinc Lim
2026-08-25 17:51 ` sashiko-bot
2026-08-24 17:50 ` [PATCH net-next v2 2/6] eth: fbnic: expose all hwmon attributes unconditionally as read-only Zinc Lim
2026-08-25 17:51 ` sashiko-bot
2026-08-24 17:50 ` [PATCH net-next v2 3/6] eth: fbnic: cache hwmon sensor readings Zinc Lim
2026-08-25 17:51 ` sashiko-bot
2026-08-24 17:50 ` [PATCH net-next v2 4/6] eth: fbnic: report temperature and voltage thresholds via hwmon Zinc Lim
2026-08-25 17:51 ` sashiko-bot
2026-08-24 17:50 ` Zinc Lim [this message]
2026-08-25 17:51 ` [PATCH net-next v2 5/6] eth: fbnic: report temperature and voltage alarms " sashiko-bot
2026-08-24 17:50 ` [PATCH net-next v2 6/6] eth: fbnic: firmware notifies hwmon on sensor threshold events Zinc Lim
2026-08-25 17:51 ` sashiko-bot
2026-08-24 20:02 ` [PATCH net-next v2 0/6] eth: fbnic: expand hwmon sensor support Jakub Kicinski
-- strict thread matches above, loose matches on Subject: below --
2026-08-31 21:22 Zinc Lim
2026-08-31 21:22 ` [PATCH net-next v2 5/6] eth: fbnic: report temperature and voltage alarms via hwmon Zinc Lim
2026-09-01 21:23 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260824175059.2485048-6-limzhineng2@gmail.com \
--to=limzhineng2@gmail.com \
--cc=alexanderduyck@fb.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mohsin.bashr@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=zinclim@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.