drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.c

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

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.c
Extension
.c
Size
8811 bytes
Lines
395
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

if (!mirror_resource) {
			mlx5hws_err(pool->ctx, "Failed to allocate mirrored resource\n");
			hws_pool_free_one_resource(resource);
			pool->resource = NULL;
			return -EINVAL;
		}
		pool->mirror_resource = mirror_resource;
	}

	return 0;
}

static int hws_pool_buddy_init(struct mlx5hws_pool *pool)
{
	struct mlx5hws_buddy_mem *buddy;

	buddy = mlx5hws_buddy_create(pool->alloc_log_sz);
	if (!buddy) {
		mlx5hws_err(pool->ctx, "Failed to create buddy order: %zu\n",
			    pool->alloc_log_sz);
		return -ENOMEM;
	}

	if (hws_pool_resource_alloc(pool) != 0) {
		mlx5hws_err(pool->ctx, "Failed to create resource type: %d size %zu\n",
			    pool->type, pool->alloc_log_sz);
		mlx5hws_buddy_cleanup(buddy);
		kfree(buddy);
		return -ENOMEM;
	}

	pool->db.buddy = buddy;

	return 0;
}

static int hws_pool_buddy_db_get_chunk(struct mlx5hws_pool *pool,
				       struct mlx5hws_pool_chunk *chunk)
{
	struct mlx5hws_buddy_mem *buddy = pool->db.buddy;

	if (!buddy) {
		mlx5hws_err(pool->ctx, "Bad buddy state\n");
		return -EINVAL;
	}

	chunk->offset = mlx5hws_buddy_alloc_mem(buddy, chunk->order);
	if (chunk->offset >= 0)
		return 0;

	return -ENOMEM;
}

static void hws_pool_buddy_db_put_chunk(struct mlx5hws_pool *pool,
					struct mlx5hws_pool_chunk *chunk)
{
	struct mlx5hws_buddy_mem *buddy;

	buddy = pool->db.buddy;
	if (!buddy) {
		mlx5hws_err(pool->ctx, "Bad buddy state\n");
		return;
	}

	mlx5hws_buddy_free_mem(buddy, chunk->offset, chunk->order);
}

static void hws_pool_buddy_db_uninit(struct mlx5hws_pool *pool)
{
	struct mlx5hws_buddy_mem *buddy;

	buddy = pool->db.buddy;
	if (buddy) {
		mlx5hws_buddy_cleanup(buddy);
		kfree(buddy);
		pool->db.buddy = NULL;
	}
}

static int hws_pool_buddy_db_init(struct mlx5hws_pool *pool)
{
	int ret;

	ret = hws_pool_buddy_init(pool);
	if (ret)
		return ret;

	pool->p_db_uninit = &hws_pool_buddy_db_uninit;
	pool->p_get_chunk = &hws_pool_buddy_db_get_chunk;
	pool->p_put_chunk = &hws_pool_buddy_db_put_chunk;

Annotation

Implementation Notes