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

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

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/mellanox/mlx5/core/alloc.c
Extension
.c
Size
14522 bytes
Lines
565
Domain
Driver Families
Bucket
drivers/net
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 mlx5_db_pgdir {
	struct list_head	list;
	unsigned long	       *bitmap;
	__be32		       *db_page;
	dma_addr_t		db_dma;
};

struct mlx5_dma_pool {
	/* Protects page_list and per-page allocation bitmaps. */
	struct mutex lock;
	struct list_head page_list;
	struct mlx5_core_dev *dev;
	int node;
	u8 block_shift;
};

struct mlx5_dma_pool_page {
	struct mlx5_dma_pool *pool;
	struct list_head pool_link;
	unsigned long *bitmap;
	void *buf;
	dma_addr_t dma;
};

struct mlx5_frag_buf_node_pools {
	struct mlx5_dma_pool *pools[MLX5_FRAG_BUF_POOLS_NUM];
};

struct mlx5_dma_pool_stats {
	int node;
	size_t block_size;
	size_t used_blocks;
	size_t allocated_blocks;
};

/* Handling for queue buffers -- we allocate a bunch of memory and
 * register it in a memory region at HCA virtual address 0.
 */

static void *mlx5_dma_zalloc_coherent_node(struct mlx5_core_dev *dev,
					   size_t size, dma_addr_t *dma_handle,
					   int node)
{
	struct device *device = mlx5_core_dma_dev(dev);
	struct mlx5_priv *priv = &dev->priv;
	int original_node;
	void *cpu_handle;

	mutex_lock(&priv->alloc_mutex);
	original_node = dev_to_node(device);
	set_dev_node(device, node);
	cpu_handle = dma_alloc_coherent(device, size, dma_handle,
					GFP_KERNEL);
	set_dev_node(device, original_node);
	mutex_unlock(&priv->alloc_mutex);
	return cpu_handle;
}

static void mlx5_dma_pool_destroy(struct mlx5_dma_pool *pool)
{
	mutex_destroy(&pool->lock);
	kfree(pool);
}

static struct mlx5_dma_pool *mlx5_dma_pool_create(struct mlx5_core_dev *dev,
						  int node, u8 block_shift)
{
	struct mlx5_dma_pool *pool;

	pool = kzalloc_obj(*pool);
	if (!pool)
		return NULL;

	INIT_LIST_HEAD(&pool->page_list);
	mutex_init(&pool->lock);
	pool->dev = dev;
	pool->node = node;
	pool->block_shift = block_shift;
	return pool;
}

static struct mlx5_dma_pool_page *
mlx5_dma_pool_page_alloc(struct mlx5_dma_pool *pool)
{
	int blocks_per_page = BIT(PAGE_SHIFT - pool->block_shift);
	struct mlx5_dma_pool_page *page;

	page = kzalloc_obj(*page);
	if (!page)
		goto err_out;

Annotation

Implementation Notes