From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 574C73806D0 for ; Mon, 24 Aug 2026 17:51:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787593873; cv=none; b=eTttYwhUJCscHW97fMuZE+um7AeSJg/1xOr2BC4/2+hErmzrnlVrfDPrr1N+db736/awIUY1RM5mpcfYgT3CwBLgAwT1ChE4/oqgy4qs5dRQmtdnt5iVHUeHuyEbVJW7PvFe+oAmrf/OmIbj5LF/AG83t7AUfGcs/JXkmOoWi3U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787593873; c=relaxed/simple; bh=F4Vn7w9he8XvFaQgePxC49jos8Ircb4h09eWzonsEE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jh+bey6/+n7JrDFtUNQwUGnVVAaK/ryTtGT4QqlU+Mf7VnieravSL7IQlIzlDkXHJ7SD6blwasN8ceklQcDTvu2npfHjQBk0PS7jPd8J68C/S+lnVdgSe9h+z950/5IOwNALoCKMzWd7bm6G0GIFS+SupNSO+FSufAeqNzmdcMU= 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=fDVpcOgt; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fDVpcOgt" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-38fdeaed181so5342958a91.1 for ; Mon, 24 Aug 2026 10:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787593869; x=1788198669; 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=Q4WjCM0YGYpG6uGbEGVqjVtxdg84mLbv5nOzooF+Ac4=; b=fDVpcOgt5XZbnEKR0ZvR2QLm2c2Dr/bbUcaEsBnGtjqmfP/9+AyEbp5VpuHqumPv/v 6o46WDwiKPj2HZVMlmi0PTSLnecbQubO+nhonvO6SHd4u0MjfqvB7oWJtoQ6o14WK97o 6AU1FAAb0joNT+npr/oiiRaeqTbOzHC4RLM75RwwlfKooRzre0TlQcSsTA3+T5/EbEtX OYrxV+UyA0sGhYv/Agqtz1hb+RPqilwSrZfCdCymu2Nk56mKdmI0dzV5af9xcVe3u8gH hL5FvMZqRKuEqF5U/SL3uhiWAoR8kUpDaxGzuPbFVyB6M/+hi9Kzr/O4yspTi3pR9fLL QKyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787593869; x=1788198669; 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=Q4WjCM0YGYpG6uGbEGVqjVtxdg84mLbv5nOzooF+Ac4=; b=ZocXWBWgHVk3LN9OTeNXOSFTJlxdcbPCUX3wrTPaai2HyWvdmVn33+6I6A2r7hg5i0 kvBSXpNi5QLBj89KoJUoCdzP+sM7BdNOuMbDU5PruoWz7R0qQARl+3FRaeV6Yy8JlG9H FodjACBbtpPhojmH8ZSYDTeI4Qp4JqGNQbw9ZUkwmNzWeXBoj1eamzBlRlOHJp+o+Q1O ApRHodc9yvH3wsN46LxCrenXHIIjNUYt6eLrXRlUKNKm4wzIPdwmXpu40f3cGLHkq2YL yO3IiOyuwPXDyvSBi0VNUrp73zXSljEypgS5zN2xcU66veJ9f6aMl7WTVQpHSd+3aDbT DGZQ== X-Forwarded-Encrypted: i=1; AHgh+RrSgHmGiiBxPxpJUzVWYwP3vGbVPdUokWEWEZbnlg40X9p6by4RaepHkDgUFYGw8JJv3N6PCNAm20/hwZI=@vger.kernel.org X-Gm-Message-State: AFuF++nWT/xDB1Fy8wxCxeMjgMvWantFTLTFQomfxejC+wSpnmYWQguV FM/DKIAu0Y9sXjKV1mcMCYxdu2RYGAO0KfU48z/eqGWH9PrEgEZKRAQ7 X-Gm-Gg: AR+sD12QuHvTFarQVMqXnhkcNDEut3OPR5a1mD1Qkkniz29kSiMnkHyZO/orQ+DsX8P B6MS+pOYPLp3C67qJrXoydjggjYYx+WheAre+QMXqvIk6Fw/1vjANSVGehy397VVPsfTrK1crXV s6n4dPSVxakh5N5qb9e2I7gx14/mziE1eBcfNQn5W1Ij6hZuE8nGw1cL8QEEtB2iIlUj+2hdAZj 7SHh5+py6Q6yEPL3iDueRqf/4T0ZyORRO99PgOfQR60+t75uX+0h0qpHhSx9c/pmsGDP+FUSvGd 6Quop9htO4Us2ZKlRIc8yF7Q9/pOGIPSoQMgCcD2KcKG4aPOmzRz5xewB5aREACZAoKUBZOfLWp 6a4GlRIRpKqar04bTdV3/HfFJJyJja6d4hQ3Y59Wzf+PHMdbsJq8aqFA2SH8vu/QdC+N64rFgIW tXardaOgCAAnZt3bfz2nx9hbTCtlp13EYGOzkZyAUZccPDxsqMoETU9UiApHcDE/xs1wU= X-Received: by 2002:a17:90a:d64e:b0:38e:1497:af5b with SMTP id 98e67ed59e1d1-395c33dd84dmr53348731a91.1.1787593868662; Mon, 24 Aug 2026 10:51:08 -0700 (PDT) Received: from localhost ([2620:10d:c090:500::4:ddd2]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-141861732f8sm26815372c88.10.2026.08.24.10.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 10:51:08 -0700 (PDT) From: Zinc Lim To: Alexander Duyck , Jakub Kicinski , Andrew Lunn , "David S . Miller" , Eric Dumazet , Paolo Abeni , Guenter Roeck , Simon Horman , Mohsin Bashir Cc: kernel-team@meta.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, zinclim@meta.com, Zinc Lim Subject: [PATCH net-next v2 3/6] eth: fbnic: cache hwmon sensor readings Date: Mon, 24 Aug 2026 10:50:56 -0700 Message-ID: <20260824175059.2485048-4-limzhineng2@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260824175059.2485048-1-limzhineng2@gmail.com> References: <20260824175059.2485048-1-limzhineng2@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 at registration so the first read always refreshes, and concurrent reads are serialized by the hwmon core so no additional locking is required. Signed-off-by: Zinc Lim --- 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(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic.h b/drivers/net/ethernet/meta/fbnic/fbnic.h index d0715695c43e..f647ef07704b 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.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h index d84723e4cfa3..42a5f83ddb45 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h @@ -6,6 +6,7 @@ #include #include +#include #include 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; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c index 38bb26cb8e6c..f35cb0065093 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 +#include #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); -- 2.53.0-Meta