drivers/net/ethernet/intel/libie/fwlog.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/intel/libie/fwlog.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/intel/libie/fwlog.c
Extension
.c
Size
29879 bytes
Lines
1141
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct file_operations libie_debugfs_module_fops = {
	.owner = THIS_MODULE,
	.open  = libie_debugfs_module_open,
	.read = seq_read,
	.release = single_release,
	.write = libie_debugfs_module_write,
};

/**
 * libie_debugfs_nr_messages_read - read from 'nr_messages' file
 * @filp: the opened file
 * @buffer: where to write the data for the user to read
 * @count: the size of the user's buffer
 * @ppos: file position offset
 */
static ssize_t libie_debugfs_nr_messages_read(struct file *filp,
					      char __user *buffer, size_t count,
					      loff_t *ppos)
{
	struct libie_fwlog *fwlog = filp->private_data;
	char buff[32] = {};

	snprintf(buff, sizeof(buff), "%d\n",
		 fwlog->cfg.log_resolution);

	return simple_read_from_buffer(buffer, count, ppos, buff, strlen(buff));
}

/**
 * libie_debugfs_nr_messages_write - write into 'nr_messages' file
 * @filp: the opened file
 * @buf: where to find the user's data
 * @count: the length of the user's data
 * @ppos: file position offset
 */
static ssize_t
libie_debugfs_nr_messages_write(struct file *filp, const char __user *buf,
				size_t count, loff_t *ppos)
{
	struct libie_fwlog *fwlog = filp->private_data;
	struct device *dev = &fwlog->pdev->dev;
	char user_val[8], *cmd_buf;
	s16 nr_messages;
	ssize_t ret;

	/* don't allow partial writes or invalid input */
	if (*ppos != 0 || count > 4)
		return -EINVAL;

	cmd_buf = memdup_user_nul(buf, count);
	if (IS_ERR(cmd_buf))
		return PTR_ERR(cmd_buf);

	ret = sscanf(cmd_buf, "%s", user_val);
	if (ret != 1) {
		count = -EINVAL;
		goto free_cmd_buf;
	}

	ret = kstrtos16(user_val, 0, &nr_messages);
	if (ret) {
		count = ret;
		goto free_cmd_buf;
	}

	if (nr_messages < LIBIE_AQC_FW_LOG_MIN_RESOLUTION ||
	    nr_messages > LIBIE_AQC_FW_LOG_MAX_RESOLUTION) {
		dev_err(dev, "Invalid FW log number of messages %d, value must be between %d - %d\n",
			nr_messages, LIBIE_AQC_FW_LOG_MIN_RESOLUTION,
			LIBIE_AQC_FW_LOG_MAX_RESOLUTION);
		count = -EINVAL;
		goto free_cmd_buf;
	}

	fwlog->cfg.log_resolution = nr_messages;

free_cmd_buf:
	kfree(cmd_buf);

	return count;
}

static const struct file_operations libie_debugfs_nr_messages_fops = {
	.owner = THIS_MODULE,
	.open  = simple_open,
	.read = libie_debugfs_nr_messages_read,
	.write = libie_debugfs_nr_messages_write,
};

/**

Annotation

Implementation Notes