drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c- Extension
.c- Size
- 17213 bytes
- Lines
- 602
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/rtnetlink.hfbnic.h
Detected Declarations
function fbnic_hw_stat_rst32function fbnic_hw_stat_rd32function fbnic_stat_rd64function fbnic_hw_stat_rst64function fbnic_hw_stat_rd64function fbnic_reset_tmi_statsfunction fbnic_get_tmi_stats32function fbnic_get_tmi_statsfunction fbnic_reset_tti_statsfunction fbnic_get_tti_stats32function fbnic_get_tti_statsfunction fbnic_reset_rpc_statsfunction fbnic_get_rpc_stats32function fbnic_reset_rxb_fifo_statsfunction fbnic_reset_rxb_enq_statsfunction fbnic_reset_rxb_deq_statsfunction fbnic_reset_rxb_statsfunction fbnic_get_rxb_fifo_stats32function fbnic_get_rxb_fifo_statsfunction fbnic_get_rxb_enq_stats32function fbnic_get_rxb_enq_statsfunction fbnic_get_rxb_deq_stats32function fbnic_get_rxb_deq_statsfunction fbnic_get_rxb_stats32function fbnic_get_rxb_statsfunction fbnic_reset_hw_rxq_statsfunction fbnic_get_hw_rxq_stats32function fbnic_get_hw_q_statsfunction fbnic_reset_pcie_stats_asicfunction fbnic_get_pcie_stats_asic64function fbnic_reset_phy_statsfunction fbnic_get_phy_stats32function fbnic_reset_hw_mac_statsfunction fbnic_reset_hw_statsfunction fbnic_init_hw_statsfunction __fbnic_get_hw_stats32function fbnic_get_hw_stats32function fbnic_get_hw_stats
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) Meta Platforms, Inc. and affiliates. */
#include <linux/rtnetlink.h>
#include "fbnic.h"
static void fbnic_hw_stat_rst32(struct fbnic_dev *fbd, u32 reg,
struct fbnic_stat_counter *stat)
{
/* We do not touch the "value" field here.
* It gets zeroed out on fbd structure allocation.
* After that we want it to grow continuously
* through device resets and power state changes.
*/
stat->u.old_reg_value_32 = rd32(fbd, reg);
}
static void fbnic_hw_stat_rd32(struct fbnic_dev *fbd, u32 reg,
struct fbnic_stat_counter *stat)
{
u32 new_reg_value;
new_reg_value = rd32(fbd, reg);
stat->value += new_reg_value - stat->u.old_reg_value_32;
stat->u.old_reg_value_32 = new_reg_value;
}
u64 fbnic_stat_rd64(struct fbnic_dev *fbd, u32 reg, u32 offset)
{
u32 prev_upper, upper, lower, diff;
prev_upper = rd32(fbd, reg + offset);
lower = rd32(fbd, reg);
upper = rd32(fbd, reg + offset);
diff = upper - prev_upper;
if (!diff)
return ((u64)upper << 32) | lower;
if (diff > 1)
dev_warn_once(fbd->dev,
"Stats inconsistent, upper 32b of %#010x updating too quickly\n",
reg * 4);
/* Return only the upper bits as we cannot guarantee
* the accuracy of the lower bits. We will add them in
* when the counter slows down enough that we can get
* a snapshot with both upper values being the same
* between reads.
*/
return ((u64)upper << 32);
}
static void fbnic_hw_stat_rst64(struct fbnic_dev *fbd, u32 reg, s32 offset,
struct fbnic_stat_counter *stat)
{
/* Record initial counter values and compute deltas from there to ensure
* stats start at 0 after reboot/reset. This avoids exposing absolute
* hardware counter values to userspace.
*/
stat->u.old_reg_value_64 = fbnic_stat_rd64(fbd, reg, offset);
}
static void fbnic_hw_stat_rd64(struct fbnic_dev *fbd, u32 reg, s32 offset,
struct fbnic_stat_counter *stat)
{
u64 new_reg_value;
new_reg_value = fbnic_stat_rd64(fbd, reg, offset);
stat->value += new_reg_value - stat->u.old_reg_value_64;
stat->u.old_reg_value_64 = new_reg_value;
}
static void fbnic_reset_tmi_stats(struct fbnic_dev *fbd,
struct fbnic_tmi_stats *tmi)
{
fbnic_hw_stat_rst32(fbd, FBNIC_TMI_DROP_PKTS, &tmi->drop.frames);
fbnic_hw_stat_rst64(fbd, FBNIC_TMI_DROP_BYTE_L, 1, &tmi->drop.bytes);
fbnic_hw_stat_rst32(fbd,
FBNIC_TMI_ILLEGAL_PTP_REQS,
&tmi->ptp_illegal_req);
fbnic_hw_stat_rst32(fbd, FBNIC_TMI_GOOD_PTP_TS, &tmi->ptp_good_ts);
fbnic_hw_stat_rst32(fbd, FBNIC_TMI_BAD_PTP_TS, &tmi->ptp_bad_ts);
}
static void fbnic_get_tmi_stats32(struct fbnic_dev *fbd,
struct fbnic_tmi_stats *tmi)
{
Annotation
- Immediate include surface: `linux/rtnetlink.h`, `fbnic.h`.
- Detected declarations: `function fbnic_hw_stat_rst32`, `function fbnic_hw_stat_rd32`, `function fbnic_stat_rd64`, `function fbnic_hw_stat_rst64`, `function fbnic_hw_stat_rd64`, `function fbnic_reset_tmi_stats`, `function fbnic_get_tmi_stats32`, `function fbnic_get_tmi_stats`, `function fbnic_reset_tti_stats`, `function fbnic_get_tti_stats32`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.