drivers/infiniband/core/uverbs_std_types_device.c

Source file repositories/reference/linux-study-clean/drivers/infiniband/core/uverbs_std_types_device.c

File Facts

System
Linux kernel
Corpus path
drivers/infiniband/core/uverbs_std_types_device.c
Extension
.c
Size
15573 bytes
Lines
559
Domain
Driver Families
Bucket
drivers/infiniband
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

if (user_entry_size > sizeof(*entries)) {
			if (clear_user(user_entries + sizeof(*entries),
				       user_entry_size - sizeof(*entries)))
				return -EFAULT;
		}

		entries++;
		user_entries += user_entry_size;
	}

	return uverbs_output_written(attrs,
				     UVERBS_ATTR_QUERY_GID_TABLE_RESP_ENTRIES);
}

static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_GID_TABLE)(
	struct uverbs_attr_bundle *attrs)
{
	struct ib_uverbs_gid_entry *entries;
	struct ib_ucontext *ucontext;
	struct ib_device *ib_dev;
	size_t user_entry_size;
	ssize_t num_entries;
	int max_entries;
	u32 flags;
	int ret;

	ret = uverbs_get_flags32(&flags, attrs,
				 UVERBS_ATTR_QUERY_GID_TABLE_FLAGS, 0);
	if (ret)
		return ret;

	ret = uverbs_get_const(&user_entry_size, attrs,
			       UVERBS_ATTR_QUERY_GID_TABLE_ENTRY_SIZE);
	if (ret)
		return ret;

	if (!user_entry_size)
		return -EINVAL;

	max_entries = uverbs_attr_ptr_get_array_size(
		attrs, UVERBS_ATTR_QUERY_GID_TABLE_RESP_ENTRIES,
		user_entry_size);
	if (max_entries <= 0)
		return max_entries ?: -EINVAL;

	ucontext = ib_uverbs_get_ucontext(attrs);
	if (IS_ERR(ucontext))
		return PTR_ERR(ucontext);
	ib_dev = ucontext->device;

	entries = uverbs_kcalloc(attrs, max_entries, sizeof(*entries));
	if (IS_ERR(entries))
		return PTR_ERR(entries);

	num_entries = rdma_query_gid_table(ib_dev, entries, max_entries);
	if (num_entries < 0)
		return -EINVAL;

	ret = copy_gid_entries_to_user(attrs, entries, num_entries,
				       user_entry_size);
	if (ret)
		return ret;

	ret = uverbs_copy_to(attrs,
			     UVERBS_ATTR_QUERY_GID_TABLE_RESP_NUM_ENTRIES,
			     &num_entries, sizeof(num_entries));
	return ret;
}

static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_GID_ENTRY)(
	struct uverbs_attr_bundle *attrs)
{
	struct ib_uverbs_gid_entry entry = {};
	const struct ib_gid_attr *gid_attr;
	struct ib_ucontext *ucontext;
	struct ib_device *ib_dev;
	struct net_device *ndev;
	u32 gid_index;
	u32 port_num;
	u32 flags;
	int ret;

	ret = uverbs_get_flags32(&flags, attrs,
				 UVERBS_ATTR_QUERY_GID_ENTRY_FLAGS, 0);
	if (ret)
		return ret;

	ret = uverbs_get_const(&port_num, attrs,
			       UVERBS_ATTR_QUERY_GID_ENTRY_PORT);
	if (ret)

Annotation

Implementation Notes