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