1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#ifndef RXE_POOL_H
35#define RXE_POOL_H
36
37#define RXE_POOL_ALIGN (16)
38#define RXE_POOL_CACHE_FLAGS (0)
39
40enum rxe_pool_flags {
41 RXE_POOL_ATOMIC = BIT(0),
42 RXE_POOL_INDEX = BIT(1),
43 RXE_POOL_KEY = BIT(2),
44};
45
46enum rxe_elem_type {
47 RXE_TYPE_UC,
48 RXE_TYPE_PD,
49 RXE_TYPE_AH,
50 RXE_TYPE_SRQ,
51 RXE_TYPE_QP,
52 RXE_TYPE_CQ,
53 RXE_TYPE_MR,
54 RXE_TYPE_MW,
55 RXE_TYPE_MC_GRP,
56 RXE_TYPE_MC_ELEM,
57 RXE_NUM_TYPES,
58};
59
60struct rxe_pool_entry;
61
62struct rxe_type_info {
63 const char *name;
64 size_t size;
65 void (*cleanup)(struct rxe_pool_entry *obj);
66 enum rxe_pool_flags flags;
67 u32 max_index;
68 u32 min_index;
69 size_t key_offset;
70 size_t key_size;
71 struct kmem_cache *cache;
72};
73
74extern struct rxe_type_info rxe_type_info[];
75
76enum rxe_pool_state {
77 RXE_POOL_STATE_INVALID,
78 RXE_POOL_STATE_VALID,
79};
80
81struct rxe_pool_entry {
82 struct rxe_pool *pool;
83 struct kref ref_cnt;
84 struct list_head list;
85
86
87 struct rb_node node;
88 u32 index;
89};
90
91struct rxe_pool {
92 struct rxe_dev *rxe;
93 rwlock_t pool_lock;
94 size_t elem_size;
95 struct kref ref_cnt;
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;
100
101 unsigned int max_elem;
102 atomic_t num_elem;
103
104
105 struct rb_root tree;
106 unsigned long *table;
107 size_t table_size;
108 u32 max_index;
109 u32 min_index;
110 u32 last;
111 size_t key_offset;
112 size_t key_size;
113};
114
115
116int rxe_cache_init(void);
117
118
119void rxe_cache_exit(void);
120
121
122
123
124
125int rxe_pool_init(struct rxe_dev *rxe, struct rxe_pool *pool,
126 enum rxe_elem_type type, u32 max_elem);
127
128
129int rxe_pool_cleanup(struct rxe_pool *pool);
130
131
132void *rxe_alloc(struct rxe_pool *pool);
133
134
135
136
137void rxe_add_index(void *elem);
138
139
140void rxe_drop_index(void *elem);
141
142
143
144
145void rxe_add_key(void *elem, void *key);
146
147
148void rxe_drop_key(void *elem);
149
150
151void *rxe_pool_get_index(struct rxe_pool *pool, u32 index);
152
153
154void *rxe_pool_get_key(struct rxe_pool *pool, void *key);
155
156
157void rxe_elem_release(struct kref *kref);
158
159
160#define rxe_add_ref(elem) kref_get(&(elem)->pelem.ref_cnt)
161
162
163#define rxe_drop_ref(elem) kref_put(&(elem)->pelem.ref_cnt, rxe_elem_release)
164
165#endif
166