drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.c- Extension
.c- Size
- 4516 bytes
- Lines
- 200
- 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/rhashtable.hnet/flow_offload.hen/tc_priv.hact_stats.hen/fs.h
Detected Declarations
struct mlx5e_tc_act_stats_handlestruct mlx5e_tc_act_statsfunction mlx5e_tc_act_stats_createfunction mlx5e_tc_act_stats_freefunction mlx5e_tc_act_stats_addfunction mlx5e_tc_act_stats_del_flowfunction list_for_each_entryfunction mlx5e_tc_act_stats_add_flowfunction list_for_each_entryfunction mlx5e_tc_act_stats_fill_stats
Annotated Snippet
struct mlx5e_tc_act_stats_handle {
struct rhashtable ht;
spinlock_t ht_lock; /* protects hashtable */
};
struct mlx5e_tc_act_stats {
unsigned long tc_act_cookie;
struct mlx5_fc *counter;
u64 lastpackets;
u64 lastbytes;
struct rhash_head hash;
struct rcu_head rcu_head;
};
static const struct rhashtable_params act_counters_ht_params = {
.head_offset = offsetof(struct mlx5e_tc_act_stats, hash),
.key_offset = offsetof(struct mlx5e_tc_act_stats, tc_act_cookie),
.key_len = sizeof_field(struct mlx5e_tc_act_stats, tc_act_cookie),
.automatic_shrinking = true,
};
struct mlx5e_tc_act_stats_handle *
mlx5e_tc_act_stats_create(void)
{
struct mlx5e_tc_act_stats_handle *handle;
int err;
handle = kvzalloc_obj(*handle);
if (!handle)
return ERR_PTR(-ENOMEM);
err = rhashtable_init(&handle->ht, &act_counters_ht_params);
if (err)
goto err;
spin_lock_init(&handle->ht_lock);
return handle;
err:
kvfree(handle);
return ERR_PTR(err);
}
void mlx5e_tc_act_stats_free(struct mlx5e_tc_act_stats_handle *handle)
{
rhashtable_destroy(&handle->ht);
kvfree(handle);
}
static int
mlx5e_tc_act_stats_add(struct mlx5e_tc_act_stats_handle *handle,
unsigned long act_cookie,
struct mlx5_fc *counter)
{
struct mlx5e_tc_act_stats *act_stats, *old_act_stats;
struct rhashtable *ht = &handle->ht;
u64 lastused;
int err = 0;
act_stats = kvzalloc_obj(*act_stats);
if (!act_stats)
return -ENOMEM;
act_stats->tc_act_cookie = act_cookie;
act_stats->counter = counter;
mlx5_fc_query_cached_raw(counter,
&act_stats->lastbytes,
&act_stats->lastpackets, &lastused);
rcu_read_lock();
old_act_stats = rhashtable_lookup_get_insert_fast(ht,
&act_stats->hash,
act_counters_ht_params);
if (IS_ERR(old_act_stats)) {
err = PTR_ERR(old_act_stats);
goto err_hash_insert;
} else if (old_act_stats) {
err = -EEXIST;
goto err_hash_insert;
}
rcu_read_unlock();
return 0;
err_hash_insert:
rcu_read_unlock();
kvfree(act_stats);
return err;
Annotation
- Immediate include surface: `linux/rhashtable.h`, `net/flow_offload.h`, `en/tc_priv.h`, `act_stats.h`, `en/fs.h`.
- Detected declarations: `struct mlx5e_tc_act_stats_handle`, `struct mlx5e_tc_act_stats`, `function mlx5e_tc_act_stats_create`, `function mlx5e_tc_act_stats_free`, `function mlx5e_tc_act_stats_add`, `function mlx5e_tc_act_stats_del_flow`, `function list_for_each_entry`, `function mlx5e_tc_act_stats_add_flow`, `function list_for_each_entry`, `function mlx5e_tc_act_stats_fill_stats`.
- 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.