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_QUEUE_H
35#define RXE_QUEUE_H
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58struct rxe_queue_buf {
59 __u32 log2_elem_size;
60 __u32 index_mask;
61 __u32 pad_1[30];
62 __u32 producer_index;
63 __u32 pad_2[31];
64 __u32 consumer_index;
65 __u32 pad_3[31];
66 __u8 data[0];
67};
68
69struct rxe_queue {
70 struct rxe_dev *rxe;
71 struct rxe_queue_buf *buf;
72 struct rxe_mmap_info *ip;
73 size_t buf_size;
74 size_t elem_size;
75 unsigned int log2_elem_size;
76 unsigned int index_mask;
77};
78
79int do_mmap_info(struct rxe_dev *rxe,
80 struct ib_udata *udata,
81 bool is_req,
82 struct ib_ucontext *context,
83 struct rxe_queue_buf *buf,
84 size_t buf_size,
85 struct rxe_mmap_info **ip_p);
86
87void rxe_queue_reset(struct rxe_queue *q);
88
89struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe,
90 int *num_elem,
91 unsigned int elem_size);
92
93int rxe_queue_resize(struct rxe_queue *q,
94 unsigned int *num_elem_p,
95 unsigned int elem_size,
96 struct ib_ucontext *context,
97 struct ib_udata *udata,
98
99 spinlock_t *producer_lock,
100
101 spinlock_t *consumer_lock);
102
103void rxe_queue_cleanup(struct rxe_queue *queue);
104
105static inline int next_index(struct rxe_queue *q, int index)
106{
107 return (index + 1) & q->buf->index_mask;
108}
109
110static inline int queue_empty(struct rxe_queue *q)
111{
112 return ((q->buf->producer_index - q->buf->consumer_index)
113 & q->index_mask) == 0;
114}
115
116static inline int queue_full(struct rxe_queue *q)
117{
118 return ((q->buf->producer_index + 1 - q->buf->consumer_index)
119 & q->index_mask) == 0;
120}
121
122static inline void advance_producer(struct rxe_queue *q)
123{
124 q->buf->producer_index = (q->buf->producer_index + 1)
125 & q->index_mask;
126}
127
128static inline void advance_consumer(struct rxe_queue *q)
129{
130 q->buf->consumer_index = (q->buf->consumer_index + 1)
131 & q->index_mask;
132}
133
134static inline void *producer_addr(struct rxe_queue *q)
135{
136 return q->buf->data + ((q->buf->producer_index & q->index_mask)
137 << q->log2_elem_size);
138}
139
140static inline void *consumer_addr(struct rxe_queue *q)
141{
142 return q->buf->data + ((q->buf->consumer_index & q->index_mask)
143 << q->log2_elem_size);
144}
145
146static inline unsigned int producer_index(struct rxe_queue *q)
147{
148 return q->buf->producer_index;
149}
150
151static inline unsigned int consumer_index(struct rxe_queue *q)
152{
153 return q->buf->consumer_index;
154}
155
156static inline void *addr_from_index(struct rxe_queue *q, unsigned int index)
157{
158 return q->buf->data + ((index & q->index_mask)
159 << q->buf->log2_elem_size);
160}
161
162static inline unsigned int index_from_addr(const struct rxe_queue *q,
163 const void *addr)
164{
165 return (((u8 *)addr - q->buf->data) >> q->log2_elem_size)
166 & q->index_mask;
167}
168
169static inline unsigned int queue_count(const struct rxe_queue *q)
170{
171 return (q->buf->producer_index - q->buf->consumer_index)
172 & q->index_mask;
173}
174
175static inline void *queue_head(struct rxe_queue *q)
176{
177 return queue_empty(q) ? NULL : consumer_addr(q);
178}
179
180#endif
181