163fa15dbSBob Pearson /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 28700e3e7SMoni Shoua /* 38700e3e7SMoni Shoua * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. 48700e3e7SMoni Shoua * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved. 58700e3e7SMoni Shoua */ 68700e3e7SMoni Shoua 78700e3e7SMoni Shoua #ifndef RXE_POOL_H 88700e3e7SMoni Shoua #define RXE_POOL_H 98700e3e7SMoni Shoua 108700e3e7SMoni Shoua enum rxe_elem_type { 118700e3e7SMoni Shoua RXE_TYPE_UC, 128700e3e7SMoni Shoua RXE_TYPE_PD, 138700e3e7SMoni Shoua RXE_TYPE_AH, 148700e3e7SMoni Shoua RXE_TYPE_SRQ, 158700e3e7SMoni Shoua RXE_TYPE_QP, 168700e3e7SMoni Shoua RXE_TYPE_CQ, 178700e3e7SMoni Shoua RXE_TYPE_MR, 188700e3e7SMoni Shoua RXE_TYPE_MW, 198700e3e7SMoni Shoua RXE_NUM_TYPES, /* keep me last */ 208700e3e7SMoni Shoua }; 218700e3e7SMoni Shoua 2202827b67SBob Pearson struct rxe_pool_elem { 238700e3e7SMoni Shoua struct rxe_pool *pool; 24b92d766cSBob Pearson void *obj; 258700e3e7SMoni Shoua struct kref ref_cnt; 268700e3e7SMoni Shoua struct list_head list; 27*215d0a75SBob Pearson struct completion complete; 288700e3e7SMoni Shoua u32 index; 298700e3e7SMoni Shoua }; 308700e3e7SMoni Shoua 318700e3e7SMoni Shoua struct rxe_pool { 328700e3e7SMoni Shoua struct rxe_dev *rxe; 33c95acedbSBob Pearson const char *name; 34b4a47f68SBob Pearson void (*cleanup)(struct rxe_pool_elem *elem); 358700e3e7SMoni Shoua enum rxe_elem_type type; 368700e3e7SMoni Shoua 378700e3e7SMoni Shoua unsigned int max_elem; 388700e3e7SMoni Shoua atomic_t num_elem; 39c95acedbSBob Pearson size_t elem_size; 40c95acedbSBob Pearson size_t elem_offset; 418700e3e7SMoni Shoua 423225717fSBob Pearson struct xarray xa; 433225717fSBob Pearson struct xa_limit limit; 443225717fSBob Pearson u32 next; 458700e3e7SMoni Shoua }; 468700e3e7SMoni Shoua 478700e3e7SMoni Shoua /* initialize a pool of objects with given limit on 488700e3e7SMoni Shoua * number of elements. gets parameters from rxe_type_info 498700e3e7SMoni Shoua * pool elements will be allocated out of a slab cache 508700e3e7SMoni Shoua */ 513225717fSBob Pearson void rxe_pool_init(struct rxe_dev *rxe, struct rxe_pool *pool, 523ccffe8aSBob Pearson enum rxe_elem_type type); 538700e3e7SMoni Shoua 548700e3e7SMoni Shoua /* free resources from object pool */ 551ceb25c8SYuval Shaia void rxe_pool_cleanup(struct rxe_pool *pool); 568700e3e7SMoni Shoua 5721a428a0SLeon Romanovsky /* connect already allocated object to pool */ 58*215d0a75SBob Pearson int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem, 59*215d0a75SBob Pearson bool sleepable); 60*215d0a75SBob Pearson #define rxe_add_to_pool(pool, obj) __rxe_add_to_pool(pool, &(obj)->elem, true) 61*215d0a75SBob Pearson #define rxe_add_to_pool_ah(pool, obj, sleepable) __rxe_add_to_pool(pool, \ 62*215d0a75SBob Pearson &(obj)->elem, sleepable) 6321a428a0SLeon Romanovsky 643c3e4d58SBob Pearson /* lookup an indexed object from index. takes a reference on object */ 658700e3e7SMoni Shoua void *rxe_pool_get_index(struct rxe_pool *pool, u32 index); 668700e3e7SMoni Shoua 673225717fSBob Pearson int __rxe_get(struct rxe_pool_elem *elem); 683197706aSBob Pearson #define rxe_get(obj) __rxe_get(&(obj)->elem) 698700e3e7SMoni Shoua 703225717fSBob Pearson int __rxe_put(struct rxe_pool_elem *elem); 713197706aSBob Pearson #define rxe_put(obj) __rxe_put(&(obj)->elem) 728700e3e7SMoni Shoua 73*215d0a75SBob Pearson int __rxe_cleanup(struct rxe_pool_elem *elem, bool sleepable); 74*215d0a75SBob Pearson #define rxe_cleanup(obj) __rxe_cleanup(&(obj)->elem, true) 75*215d0a75SBob Pearson #define rxe_cleanup_ah(obj, sleepable) __rxe_cleanup(&(obj)->elem, sleepable) 76*215d0a75SBob Pearson 773197706aSBob Pearson #define rxe_read(obj) kref_read(&(obj)->elem.ref_cnt) 78d5724055SBob Pearson 79*215d0a75SBob Pearson void __rxe_finalize(struct rxe_pool_elem *elem); 80*215d0a75SBob Pearson #define rxe_finalize(obj) __rxe_finalize(&(obj)->elem) 81*215d0a75SBob Pearson 828700e3e7SMoni Shoua #endif /* RXE_POOL_H */ 83