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.

Dependency Surface

Detected Declarations

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

Implementation Notes