2 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 #define RXE_POOL_ALIGN (16)
38 #define RXE_POOL_CACHE_FLAGS (0)
41 RXE_POOL_ATOMIC
= BIT(0),
42 RXE_POOL_INDEX
= BIT(1),
43 RXE_POOL_KEY
= BIT(2),
57 RXE_NUM_TYPES
, /* keep me last */
60 struct rxe_pool_entry
;
62 struct rxe_type_info
{
65 void (*cleanup
)(struct rxe_pool_entry
*obj
);
66 enum rxe_pool_flags flags
;
71 struct kmem_cache
*cache
;
74 extern struct rxe_type_info rxe_type_info
[];
81 struct rxe_pool_entry
{
82 struct rxe_pool
*pool
;
84 struct list_head list
;
86 /* only used if indexed or keyed */
93 spinlock_t pool_lock
; /* pool spinlock */
96 void (*cleanup
)(struct rxe_pool_entry
*obj
);
97 enum rxe_pool_state state
;
98 enum rxe_pool_flags flags
;
99 enum rxe_elem_type type
;
101 unsigned int max_elem
;
104 /* only used if indexed or keyed */
106 unsigned long *table
;
115 /* initialize slab caches for managed objects */
116 int rxe_cache_init(void);
118 /* cleanup slab caches for managed objects */
119 void rxe_cache_exit(void);
121 /* initialize a pool of objects with given limit on
122 * number of elements. gets parameters from rxe_type_info
123 * pool elements will be allocated out of a slab cache
125 int rxe_pool_init(struct rxe_dev
*rxe
, struct rxe_pool
*pool
,
126 enum rxe_elem_type type
, u32 max_elem
);
128 /* free resources from object pool */
129 int rxe_pool_cleanup(struct rxe_pool
*pool
);
131 /* allocate an object from pool */
132 void *rxe_alloc(struct rxe_pool
*pool
);
134 /* assign an index to an indexed object and insert object into
137 void rxe_add_index(void *elem
);
139 /* drop an index and remove object from rb tree */
140 void rxe_drop_index(void *elem
);
142 /* assign a key to a keyed object and insert object into
145 void rxe_add_key(void *elem
, void *key
);
147 /* remove elem from rb tree */
148 void rxe_drop_key(void *elem
);
150 /* lookup an indexed object from index. takes a reference on object */
151 void *rxe_pool_get_index(struct rxe_pool
*pool
, u32 index
);
153 /* lookup keyed object from key. takes a reference on the object */
154 void *rxe_pool_get_key(struct rxe_pool
*pool
, void *key
);
156 /* cleanup an object when all references are dropped */
157 void rxe_elem_release(struct kref
*kref
);
159 /* take a reference on an object */
160 #define rxe_add_ref(elem) kref_get(&(elem)->pelem.ref_cnt)
162 /* drop a reference on an object */
163 #define rxe_drop_ref(elem) kref_put(&(elem)->pelem.ref_cnt, rxe_elem_release)
165 #endif /* RXE_POOL_H */