Article View: linux.kernel.netdev
Article #3379[PATCH net-next v4 2/6] eth: fbnic: cache hwmon sensor readings
From: Zinc Lim
Date: Wed, 14 Oct 2026 22:22
Date: Wed, 14 Oct 2026 22:22
155 lines
13174 bytes
13174 bytes
Each 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 in fbnic_mbx_init() so the first read always refreshes.
Signed-off-by: Zinc Lim <limzhineng2@gmail.com>
---
drivers/net/ethernet/meta/fbnic/fbnic.h | 7 +++++
drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 7 +++++
drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 7 +++++
drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 31 +++++++++++++------
4 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic.h b/drivers/net/ethernet/meta/fbnic/fbnic.h
index 1f9fbd71447f..857a64b518f3 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic.h
+++ b/drivers/net/ethernet/meta/fbnic/fbnic.h
@@ -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;
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
index 49b8813a3564..82307f212f58 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
@@ -105,6 +105,13 @@ void fbnic_mbx_init(struct fbnic_dev *fbd)
/* Reset FW Capabilities */
memset(&fbd->fw_cap, 0, sizeof(fbd->fw_cap));
+ /* Seed cache with sentinel so the first read always refreshes. The
+ * cache mirrors what firmware reported, so drop it when the mailbox
+ * restarts.
+ */
+ fbd->hwmon_cache.temp_mdeg = FBNIC_SENSOR_NO_DATA;
+ fbd->hwmon_cache.volt_mv = FBNIC_SENSOR_NO_DATA;
+
/* Reinitialize mailbox memory */
for (i = 0; i < FBNIC_IPC_MBX_INDICES; i++)
memset(&fbd->mbx[i], 0, sizeof(struct fbnic_fw_mbx));
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
index f47669129c9d..ddedb7c0e0a7 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
@@ -6,6 +6,7 @@
#include <linux/completion.h>
#include <linux/if_ether.h>
+#include <linux/limits.h>
#include <linux/types.h>
struct fbnic_dev;
@@ -59,6 +60,12 @@ enum {
(BIT(FBNIC_FW_CAP_F_BMC_TCAM_REINIT) | \
BIT(FBNIC_FW_CAP_F_BMC_MACDA_SYNC))
+/* 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 {
unsigned long state;
struct {
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
index 6c8c66ab86c1..0c3fe2a37227 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
@@ -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"
@@ -30,26 +31,31 @@ 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 && cache->last_read == jiffies) {
+ *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,
@@ -72,7 +78,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:
--
2.53.0-Meta
Technical Details
Message-ID:
<20261014222225.2803660-3-limzhineng2@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346463-linux-kernel-netdev=dewy.ruReferences:
<20261014222225.2803660-1-limzhineng2@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-346463-linux-kernel-netdev=dewy.ru
From: limzhineng2@gmail.com (Zinc Lim)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v4 2/6] eth: fbnic: cache hwmon sensor readings
Date: Wed, 14 Oct 2026 15:22:20 -0700
Organization: Usenet Network
Message-ID: <20261014222225.2803660-3-limzhineng2@gmail.com>
References: <20261014222225.2803660-1-limzhineng2@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2400476"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:uzXSnJo1phSQuLeKCiq6ccnZSgU= sha256:X+sjoSj3PnwopkjdEqrVDiWVvrwuJFKS/Sn8ulBG24M=
sha1:wVt5kWyzXNEQ4Ex5ZCFCtar23wk= sha256:sIz3ug+7+50+NM5t73IWR0+IP1MRZIoz+50Sal1epVc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 0B5E11101F1; Thu, 15 Oct 2026 01:25:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.748
X-Spam-Status: No, score=-0.748 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id ud3CXJDJbtGL;
Thu, 15 Oct 2026 01:25:17 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-346463-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mail.dewy.ru (Postfix) with ESMTPS id DAE82110165; Thu, 15 Oct 2026 01:25:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sin.lore.kernel.org (Postfix) with ESMTP id 76D6F3130D; Wed, 14 Oct 2026 22:22:46 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id B83864B7A53;
Wed, 14 Oct 2026 22:22:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lZYc8oAs"
X-Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F7DB4AB3B4
for <netdev@vger.kernel.org>; Wed, 14 Oct 2026 22:22:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.178
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792016554; cv=none; b=TaSACmn3y94vz2ysCJ+e8FWIQf1rzWNUVqPXButVh0vgpCCLErfj85V3sgev4d19yKifTXyf1MNJa5jQuRVuyg/Mh5UWOYvWjaIaFp0oBt5HcCcu99TuPWifS+3ksPdAMRMbuIoixJVfxetN3e+iT7R4SMQY1ojXUq1W3BOKVBM=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792016554; c=relaxed/simple;
bh=1LQQnH3Df+SOEKqlRwe0Shj3+oVhATZyZAPjcDT/2BY=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
MIME-Version; b=V7DNK8WMpzOdioYBSrOI5mpP6239dLR19MNwUlSTzIUbPm8tP98dVgwBaLJtIgpvYiO4G1t2044GaVhJwB7zeyH78L48WsKcxUePyldISWlacJnN0Ty57VJKRtwGq6E5j0ApH66a1IUGTnRXNjfJRQgiggXgoVasJu1iOlWMq1I=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lZYc8oAs; arc=none smtp.client-ip=74.125.82.178
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-35a31bb9fb6so6306872eec.1
for <netdev@vger.kernel.org>; Wed, 14 Oct 2026 15:22:32 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792016552; x=1792621352; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=k7E54Gamm23I7pb6W2akdaDghKzKpOihGThuE98U3QY=;
b=lZYc8oAsqSIr19FS936xk9dnom0krY5ok2UcOKs4KnPE5I4/DJqjT4g8HITQ38wn+9
XzNrCi7h7pjMESHkYtm2D5j9GRKFA66rzXxLRW1R2HT/tvZxHrjuc1SpcJACFqoW2H9f
dqQaoDC975xiF+qs3Ok/Sap5suL34XYgnWWJSNkN88Wu6G+Yz2poCndS2MqE7b+bV6ko
GFoeJJpc5pVUx3cSEEKQ2r7uM/zaDfiMskomzEk9Ah1kvO6//hmaKVRksDdEbDhKROve
Or7OfSNIjvZTT32fV7DrKx/GDqhp/X920o6IOtE/vvbtQ+kfKqJTGqzPNml0Lkq6gpOF
QnTQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792016552; x=1792621352;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=k7E54Gamm23I7pb6W2akdaDghKzKpOihGThuE98U3QY=;
b=tuJnk/lqon0bj3W27iDAb+m12J7aZxk9flKlEbQrXVk7qVkuRKgmGI6zreMd5KtM/L
eJ9pC9fu8eofFKu4uW0MTCdbQhfJi0gx3PB8s+EzYP+4vUvWSqpJRiSSEJx3ELG00GUL
aDYNhD4YnOJu2sBV2PbpvvbjobnW+F6ay1sYlSAsI7D0UWAxeHJZMnNml01kj4fFR4Lu
WuJJhHQbbnsRf6A3Dq8t3QbzgOUneACT7f3m9Vsy5zC+Hg5OeHQrzreMA8wCdhwsH95/
BU5QkiKFhZR/huSlXxpyj/xBZeIrHAKH1Bmq7D5f3f0Oadf1jxqM0STPTwYfRtIr9phA
IJeQ==
X-Forwarded-Encrypted: i=1; AKwUvByz0YYaVNUdUY01c6E5yMorEGAjv1tQRMCSeA/iCtQnsAjM1WGqeTwZIRmDQjUVoR7yHIEGPyM=@vger.kernel.org
X-Gm-Message-State: AFq9FYI8Q5emlZ8Fa4y8Bi3izyzg36+5KnRe0aMYuZI/R/9G2yVwRGtW
6MP7QuQiTyPjy18cUW3OCJi8sW1WnYSJFpgvhHymOMqAcPajtW7mqdmz
X-Gm-Gg: AYBFou20zqH+0nXvHCbFDOI5/5CI9wynb3Xufvqf0nGgByKv+ts3RSlDsQtTWC4moJa
avv/15c0TzM8VWgzMgywrjFJPKJSZEJRsJvTYjoc7HP4njX3EcMTgCq1hh8YlJ1X0LIqq0+ZA5+
g3kP3w4Duavww6tSooGFikxWapalXiHw1lESOUMDlVDG6PVv5tfAWF/sz/vRj6y8a+i6LZPJpsl
WpQ0EdgiGQ8C70mGTKcH5bdvX1nUC5G8wdrfU2mRT1kr03F6D013lav8MTVrHSUYaPRiUm3VkDM
hAfu1pCVW8a8+j9akkPEX74Gkw6B3iO4TTaS6T9h/vdWiZqjKhXQlLOH5BQvSaljOWcW7Q6e8tb
R5esdHUEJxeHN6DAGa51J/5cYxkzUaFuDg5O6U3j3xzt0dSD+Tjg9QJ5mN9t3eweCrUAcO0n92U
u40PJ+Lf5A6H6spjM6/Q1gsLqJEorsgHnExoTQxqo+d+JZmvksSIgkaakDUR32Ja/RRGFmwUgI5
b7UlA==
X-Received: by 2002:a05:7300:8b14:b0:35f:f0:8edf with SMTP id 5a478bee46e88-35f00f09f07mr1334564eec.13.1792016552128;
Wed, 14 Oct 2026 15:22:32 -0700 (PDT)
X-Received: from localhost ([2620:10d:c090:500::5:7561])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-35f0c3bcf80sm1295905eec.7.2026.10.14.15.22.31
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 14 Oct 2026 15:22:31 -0700 (PDT)
X-Cc: kernel-team@meta.com,
netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-hwmon@vger.kernel.org,
zinclim@meta.com,
limzhineng2@gmail.com
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261014222225.2803660-1-limzhineng2@gmail.com>
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>