drivers/infiniband/core/verbs.c

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

File Facts

System
Linux kernel
Corpus path
drivers/infiniband/core/verbs.c
Extension
.c
Size
86154 bytes
Lines
3194
Domain
Driver Families
Bucket
drivers/infiniband
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 ib_speed_attr {
	const char *str;
	int speed;
};

#define IB_SPEED_ATTR(speed_type, _str, _speed) \
	[speed_type] = {.str = _str, .speed = _speed}

static const struct ib_speed_attr ib_speed_attrs[] = {
	IB_SPEED_ATTR(IB_SPEED_SDR, " SDR", 25),
	IB_SPEED_ATTR(IB_SPEED_DDR, " DDR", 50),
	IB_SPEED_ATTR(IB_SPEED_QDR, " QDR", 100),
	IB_SPEED_ATTR(IB_SPEED_FDR10, " FDR10", 100),
	IB_SPEED_ATTR(IB_SPEED_FDR, " FDR", 140),
	IB_SPEED_ATTR(IB_SPEED_EDR, " EDR", 250),
	IB_SPEED_ATTR(IB_SPEED_HDR, " HDR", 500),
	IB_SPEED_ATTR(IB_SPEED_NDR, " NDR", 1000),
	IB_SPEED_ATTR(IB_SPEED_XDR, " XDR", 2000),
};

int ib_port_attr_to_speed_info(struct ib_port_attr *attr,
			       struct ib_port_speed_info *speed_info)
{
	int speed_idx = attr->active_speed;

	switch (attr->active_speed) {
	case IB_SPEED_DDR:
	case IB_SPEED_QDR:
	case IB_SPEED_FDR10:
	case IB_SPEED_FDR:
	case IB_SPEED_EDR:
	case IB_SPEED_HDR:
	case IB_SPEED_NDR:
	case IB_SPEED_XDR:
	case IB_SPEED_SDR:
		break;
	default:
		speed_idx = IB_SPEED_SDR; /* Default to SDR for invalid rates */
		break;
	}

	speed_info->str = ib_speed_attrs[speed_idx].str;
	speed_info->rate = ib_speed_attrs[speed_idx].speed;
	speed_info->rate *= ib_width_enum_to_int(attr->active_width);
	if (speed_info->rate < 0)
		return -EINVAL;

	return 0;
}
EXPORT_SYMBOL(ib_port_attr_to_speed_info);

__attribute_const__ enum rdma_transport_type
rdma_node_get_transport(unsigned int node_type)
{

	if (node_type == RDMA_NODE_USNIC)
		return RDMA_TRANSPORT_USNIC;
	if (node_type == RDMA_NODE_USNIC_UDP)
		return RDMA_TRANSPORT_USNIC_UDP;
	if (node_type == RDMA_NODE_RNIC)
		return RDMA_TRANSPORT_IWARP;
	if (node_type == RDMA_NODE_UNSPECIFIED)
		return RDMA_TRANSPORT_UNSPECIFIED;

	return RDMA_TRANSPORT_IB;
}
EXPORT_SYMBOL(rdma_node_get_transport);

enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
					      u32 port_num)
{
	enum rdma_transport_type lt;
	if (device->ops.get_link_layer)
		return device->ops.get_link_layer(device, port_num);

	lt = rdma_node_get_transport(device->node_type);
	if (lt == RDMA_TRANSPORT_IB)
		return IB_LINK_LAYER_INFINIBAND;

	return IB_LINK_LAYER_ETHERNET;
}
EXPORT_SYMBOL(rdma_port_get_link_layer);

/* Protection domains */

/**
 * __ib_alloc_pd - Allocates an unused protection domain.
 * @device: The device on which to allocate the protection domain.
 * @flags: protection domain flags
 * @caller: caller's build-time module name

Annotation

Implementation Notes