Lines Matching refs:pool
31 static int dr_arg_pool_alloc_objs(struct dr_arg_pool *pool) in dr_arg_pool_alloc_objs() argument
43 pool->dmn->info.caps.log_header_modify_argument_granularity; in dr_arg_pool_alloc_objs()
46 max_t(u32, pool->dmn->info.caps.log_header_modify_argument_granularity, in dr_arg_pool_alloc_objs()
49 min_t(u32, pool->dmn->info.caps.log_header_modify_argument_max_alloc, in dr_arg_pool_alloc_objs()
52 if (pool->log_chunk_size > object_range) { in dr_arg_pool_alloc_objs()
53 mlx5dr_err(pool->dmn, "Required chunk size (%d) is not supported\n", in dr_arg_pool_alloc_objs()
54 pool->log_chunk_size); in dr_arg_pool_alloc_objs()
58 num_of_objects = (1 << (object_range - pool->log_chunk_size)); in dr_arg_pool_alloc_objs()
60 ret = mlx5dr_cmd_create_modify_header_arg(pool->dmn->mdev, in dr_arg_pool_alloc_objs()
62 pool->dmn->pdn, in dr_arg_pool_alloc_objs()
65 mlx5dr_err(pool->dmn, "failed allocating object with range: %d:\n", in dr_arg_pool_alloc_objs()
77 arg_obj->log_chunk_size = pool->log_chunk_size; in dr_arg_pool_alloc_objs()
82 arg_obj->obj_offset = i * (1 << pool->log_chunk_size); in dr_arg_pool_alloc_objs()
84 list_splice_tail_init(&cur_list, &pool->free_list); in dr_arg_pool_alloc_objs()
89 mlx5dr_cmd_destroy_modify_header_arg(pool->dmn->mdev, obj_id); in dr_arg_pool_alloc_objs()
97 static struct mlx5dr_arg_obj *dr_arg_pool_get_arg_obj(struct dr_arg_pool *pool) in dr_arg_pool_get_arg_obj() argument
102 mutex_lock(&pool->mutex); in dr_arg_pool_get_arg_obj()
103 if (list_empty(&pool->free_list)) { in dr_arg_pool_get_arg_obj()
104 ret = dr_arg_pool_alloc_objs(pool); in dr_arg_pool_get_arg_obj()
109 arg_obj = list_first_entry_or_null(&pool->free_list, in dr_arg_pool_get_arg_obj()
118 mutex_unlock(&pool->mutex); in dr_arg_pool_get_arg_obj()
122 static void dr_arg_pool_put_arg_obj(struct dr_arg_pool *pool, in dr_arg_pool_put_arg_obj() argument
125 mutex_lock(&pool->mutex); in dr_arg_pool_put_arg_obj()
126 list_add(&arg_obj->list_node, &pool->free_list); in dr_arg_pool_put_arg_obj()
127 mutex_unlock(&pool->mutex); in dr_arg_pool_put_arg_obj()
133 struct dr_arg_pool *pool; in dr_arg_pool_create() local
135 pool = kzalloc(sizeof(*pool), GFP_KERNEL); in dr_arg_pool_create()
136 if (!pool) in dr_arg_pool_create()
139 pool->dmn = dmn; in dr_arg_pool_create()
141 INIT_LIST_HEAD(&pool->free_list); in dr_arg_pool_create()
142 mutex_init(&pool->mutex); in dr_arg_pool_create()
144 pool->log_chunk_size = chunk_size; in dr_arg_pool_create()
145 if (dr_arg_pool_alloc_objs(pool)) in dr_arg_pool_create()
148 return pool; in dr_arg_pool_create()
151 kfree(pool); in dr_arg_pool_create()
156 static void dr_arg_pool_destroy(struct dr_arg_pool *pool) in dr_arg_pool_destroy() argument
160 list_for_each_entry_safe(arg_obj, tmp_arg, &pool->free_list, list_node) { in dr_arg_pool_destroy()
163 mlx5dr_cmd_destroy_modify_header_arg(pool->dmn->mdev, arg_obj->obj_id); in dr_arg_pool_destroy()
167 mutex_destroy(&pool->mutex); in dr_arg_pool_destroy()
168 kfree(pool); in dr_arg_pool_destroy()