2020-08-27 07:54:40 -07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
|
2016-06-16 06:45:23 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
|
|
|
|
* Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RXE_POOL_H
|
|
|
|
#define RXE_POOL_H
|
|
|
|
|
|
|
|
enum rxe_elem_type {
|
|
|
|
RXE_TYPE_UC,
|
|
|
|
RXE_TYPE_PD,
|
|
|
|
RXE_TYPE_AH,
|
|
|
|
RXE_TYPE_SRQ,
|
|
|
|
RXE_TYPE_QP,
|
|
|
|
RXE_TYPE_CQ,
|
|
|
|
RXE_TYPE_MR,
|
|
|
|
RXE_TYPE_MW,
|
|
|
|
RXE_NUM_TYPES, /* keep me last */
|
|
|
|
};
|
|
|
|
|
2021-11-02 22:02:31 -07:00
|
|
|
struct rxe_pool_elem {
|
2016-06-16 06:45:23 -07:00
|
|
|
struct rxe_pool *pool;
|
2021-11-02 22:02:33 -07:00
|
|
|
void *obj;
|
2016-06-16 06:45:23 -07:00
|
|
|
struct kref ref_cnt;
|
|
|
|
struct list_head list;
|
2022-06-12 15:34:34 -07:00
|
|
|
struct completion complete;
|
2016-06-16 06:45:23 -07:00
|
|
|
u32 index;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rxe_pool {
|
|
|
|
struct rxe_dev *rxe;
|
2021-11-02 22:02:32 -07:00
|
|
|
const char *name;
|
2022-03-03 17:08:01 -07:00
|
|
|
void (*cleanup)(struct rxe_pool_elem *elem);
|
2016-06-16 06:45:23 -07:00
|
|
|
enum rxe_elem_type type;
|
|
|
|
|
|
|
|
unsigned int max_elem;
|
|
|
|
atomic_t num_elem;
|
2021-11-02 22:02:32 -07:00
|
|
|
size_t elem_size;
|
|
|
|
size_t elem_offset;
|
2016-06-16 06:45:23 -07:00
|
|
|
|
2022-03-03 17:08:04 -07:00
|
|
|
struct xarray xa;
|
|
|
|
struct xa_limit limit;
|
|
|
|
u32 next;
|
2016-06-16 06:45:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* initialize a pool of objects with given limit on
|
|
|
|
* number of elements. gets parameters from rxe_type_info
|
|
|
|
* pool elements will be allocated out of a slab cache
|
|
|
|
*/
|
2022-03-03 17:08:04 -07:00
|
|
|
void rxe_pool_init(struct rxe_dev *rxe, struct rxe_pool *pool,
|
2022-03-03 17:08:02 -07:00
|
|
|
enum rxe_elem_type type);
|
2016-06-16 06:45:23 -07:00
|
|
|
|
|
|
|
/* free resources from object pool */
|
2018-12-06 04:04:38 -07:00
|
|
|
void rxe_pool_cleanup(struct rxe_pool *pool);
|
2020-12-16 16:15:49 -07:00
|
|
|
|
2019-02-03 05:55:51 -07:00
|
|
|
/* connect already allocated object to pool */
|
2022-06-12 15:34:34 -07:00
|
|
|
int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem,
|
|
|
|
bool sleepable);
|
|
|
|
#define rxe_add_to_pool(pool, obj) __rxe_add_to_pool(pool, &(obj)->elem, true)
|
|
|
|
#define rxe_add_to_pool_ah(pool, obj, sleepable) __rxe_add_to_pool(pool, \
|
|
|
|
&(obj)->elem, sleepable)
|
2019-02-03 05:55:51 -07:00
|
|
|
|
2022-03-03 17:08:00 -07:00
|
|
|
/* lookup an indexed object from index. takes a reference on object */
|
2021-01-25 14:16:37 -07:00
|
|
|
void *rxe_pool_get_index(struct rxe_pool *pool, u32 index);
|
2020-12-16 16:15:49 -07:00
|
|
|
|
2022-03-03 17:08:04 -07:00
|
|
|
int __rxe_get(struct rxe_pool_elem *elem);
|
2022-03-03 17:08:05 -07:00
|
|
|
#define rxe_get(obj) __rxe_get(&(obj)->elem)
|
2016-06-16 06:45:23 -07:00
|
|
|
|
2022-03-03 17:08:04 -07:00
|
|
|
int __rxe_put(struct rxe_pool_elem *elem);
|
2022-03-03 17:08:05 -07:00
|
|
|
#define rxe_put(obj) __rxe_put(&(obj)->elem)
|
2016-06-16 06:45:23 -07:00
|
|
|
|
2022-06-12 15:34:34 -07:00
|
|
|
int __rxe_cleanup(struct rxe_pool_elem *elem, bool sleepable);
|
|
|
|
#define rxe_cleanup(obj) __rxe_cleanup(&(obj)->elem, true)
|
|
|
|
#define rxe_cleanup_ah(obj, sleepable) __rxe_cleanup(&(obj)->elem, sleepable)
|
|
|
|
|
2022-03-03 17:08:05 -07:00
|
|
|
#define rxe_read(obj) kref_read(&(obj)->elem.ref_cnt)
|
2022-02-08 14:16:36 -07:00
|
|
|
|
2022-06-12 15:34:34 -07:00
|
|
|
void __rxe_finalize(struct rxe_pool_elem *elem);
|
|
|
|
#define rxe_finalize(obj) __rxe_finalize(&(obj)->elem)
|
|
|
|
|
2016-06-16 06:45:23 -07:00
|
|
|
#endif /* RXE_POOL_H */
|