drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
Extension
.c
Size
25185 bytes
Lines
958
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 mlx5_pages_req {
	struct mlx5_core_dev *dev;
	u16	func_id;
	u8	ec_function;
	s32	npages;
	struct work_struct work;
	u8	release_all;
};

struct fw_page {
	struct rb_node		rb_node;
	u64			addr;
	struct page	       *page;
	u32			function;
	u16			func_type;
	unsigned long		bitmask;
	struct list_head	list;
	unsigned int free_count;
};

enum {
	MLX5_MAX_RECLAIM_TIME_MILI	= 5000,
	MLX5_NUM_4K_IN_PAGE		= PAGE_SIZE / MLX5_ADAPTER_PAGE_SIZE,
};

static bool mlx5_page_mgt_mode_is_vhca_id(const struct mlx5_core_dev *dev)
{
	return dev->priv.page_mgt_mode == MLX5_PAGE_MGT_MODE_VHCA_ID;
}

static void mlx5_page_mgt_mode_set(struct mlx5_core_dev *dev,
				   enum mlx5_page_mgt_mode mode)
{
	dev->priv.page_mgt_mode = mode;
}

static u32 get_function_key(struct mlx5_core_dev *dev, u16 func_vhca_id,
			    bool ec_function)
{
	if (mlx5_page_mgt_mode_is_vhca_id(dev))
		return (u32)func_vhca_id;

	return (u32)func_vhca_id | (ec_function << 16);
}

static u16 func_id_to_type(struct mlx5_core_dev *dev, u16 func_id, bool ec_function)
{
	if (!func_id)
		return mlx5_core_is_ecpf(dev) && !ec_function ?
			MLX5_HOST_PF : MLX5_SELF;

	if (func_id <= max(mlx5_core_max_vfs(dev), mlx5_core_max_ec_vfs(dev))) {
		if (ec_function)
			return MLX5_EC_VF;
		else
			return MLX5_VF;
	}
	return MLX5_SF;
}

static u16 func_vhca_id_to_type(struct mlx5_core_dev *dev, u16 func_vhca_id,
				bool ec_function)
{
	if (mlx5_page_mgt_mode_is_vhca_id(dev))
		return mlx5_esw_vhca_id_to_func_type(dev, func_vhca_id);

	return func_id_to_type(dev, func_vhca_id, ec_function);
}

static u32 mlx5_get_ec_function(u32 function)
{
	return function >> 16;
}

static u32 mlx5_get_func_vhca_id(u32 function)
{
	return function & 0xffff;
}

static struct rb_root *page_root_per_function(struct mlx5_core_dev *dev, u32 function)
{
	struct rb_root *root;
	int err;

	root = xa_load(&dev->priv.page_root_xa, function);
	if (root)
		return root;

	root = kzalloc_obj(*root);
	if (!root)

Annotation

Implementation Notes