drivers/net/netdevsim/hwstats.c
Source file repositories/reference/linux-study-clean/drivers/net/netdevsim/hwstats.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/netdevsim/hwstats.c- Extension
.c- Size
- 12413 bytes
- Lines
- 481
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/debugfs.hnetdevsim.h
Detected Declarations
struct nsim_dev_hwstats_fopsenum nsim_dev_hwstats_dofunction nsim_dev_hwstats_get_list_headfunction nsim_dev_hwstats_traffic_bumpfunction list_for_each_entryfunction nsim_dev_hwstats_traffic_workfunction nsim_dev_hwslist_find_hwsdevfunction list_for_each_entryfunction nsim_dev_hwsdev_enablefunction nsim_dev_hwsdev_disablefunction nsim_dev_hwsdev_report_deltafunction nsim_dev_hwsdev_report_usedfunction nsim_dev_hwstats_event_off_xstatsfunction nsim_dev_hwsdev_finifunction __nsim_dev_hwstats_event_unregisterfunction nsim_dev_hwstats_event_unregisterfunction nsim_dev_hwstats_eventfunction nsim_dev_netdevice_eventfunction nsim_dev_hwstats_enable_ifindexfunction nsim_dev_hwstats_disable_ifindexfunction nsim_dev_hwstats_fail_ifindexfunction nsim_dev_hwstats_do_writefunction nsim_dev_hwstats_initfunction nsim_dev_hwsdev_list_wipefunction nsim_dev_hwstats_exit
Annotated Snippet
struct nsim_dev_hwstats_fops {
enum nsim_dev_hwstats_do action;
enum netdev_offload_xstats_type type;
};
static ssize_t
nsim_dev_hwstats_do_write(struct file *file,
const char __user *data,
size_t count, loff_t *ppos)
{
struct nsim_dev_hwstats *hwstats = file->private_data;
const struct nsim_dev_hwstats_fops *hwsfops;
struct list_head *hwsdev_list;
int ifindex;
int err;
hwsfops = debugfs_get_aux(file);
err = kstrtoint_from_user(data, count, 0, &ifindex);
if (err)
return err;
hwsdev_list = nsim_dev_hwstats_get_list_head(hwstats, hwsfops->type);
if (WARN_ON(!hwsdev_list))
return -EINVAL;
switch (hwsfops->action) {
case NSIM_DEV_HWSTATS_DO_DISABLE:
err = nsim_dev_hwstats_disable_ifindex(hwstats, ifindex,
hwsfops->type,
hwsdev_list);
break;
case NSIM_DEV_HWSTATS_DO_ENABLE:
err = nsim_dev_hwstats_enable_ifindex(hwstats, ifindex,
hwsfops->type,
hwsdev_list);
break;
case NSIM_DEV_HWSTATS_DO_FAIL:
err = nsim_dev_hwstats_fail_ifindex(hwstats, ifindex,
hwsfops->type,
hwsdev_list);
break;
}
if (err)
return err;
return count;
}
static struct debugfs_short_fops debugfs_ops = {
.write = nsim_dev_hwstats_do_write,
.llseek = generic_file_llseek,
};
#define NSIM_DEV_HWSTATS_FOPS(ACTION, TYPE) \
{ \
.action = ACTION, \
.type = TYPE, \
}
static const struct nsim_dev_hwstats_fops nsim_dev_hwstats_l3_disable_fops =
NSIM_DEV_HWSTATS_FOPS(NSIM_DEV_HWSTATS_DO_DISABLE,
NETDEV_OFFLOAD_XSTATS_TYPE_L3);
static const struct nsim_dev_hwstats_fops nsim_dev_hwstats_l3_enable_fops =
NSIM_DEV_HWSTATS_FOPS(NSIM_DEV_HWSTATS_DO_ENABLE,
NETDEV_OFFLOAD_XSTATS_TYPE_L3);
static const struct nsim_dev_hwstats_fops nsim_dev_hwstats_l3_fail_fops =
NSIM_DEV_HWSTATS_FOPS(NSIM_DEV_HWSTATS_DO_FAIL,
NETDEV_OFFLOAD_XSTATS_TYPE_L3);
#undef NSIM_DEV_HWSTATS_FOPS
int nsim_dev_hwstats_init(struct nsim_dev *nsim_dev)
{
struct nsim_dev_hwstats *hwstats = &nsim_dev->hwstats;
struct net *net = nsim_dev_net(nsim_dev);
int err;
mutex_init(&hwstats->hwsdev_list_lock);
INIT_LIST_HEAD(&hwstats->l3_list);
hwstats->netdevice_nb.notifier_call = nsim_dev_netdevice_event;
err = register_netdevice_notifier_net(net, &hwstats->netdevice_nb);
if (err)
goto err_mutex_destroy;
hwstats->ddir = debugfs_create_dir("hwstats", nsim_dev->ddir);
if (IS_ERR(hwstats->ddir)) {
Annotation
- Immediate include surface: `linux/debugfs.h`, `netdevsim.h`.
- Detected declarations: `struct nsim_dev_hwstats_fops`, `enum nsim_dev_hwstats_do`, `function nsim_dev_hwstats_get_list_head`, `function nsim_dev_hwstats_traffic_bump`, `function list_for_each_entry`, `function nsim_dev_hwstats_traffic_work`, `function nsim_dev_hwslist_find_hwsdev`, `function list_for_each_entry`, `function nsim_dev_hwsdev_enable`, `function nsim_dev_hwsdev_disable`.
- 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.