This source file includes following definitions.
- uwb_drp_avail_init
- uwb_drp_available
- uwb_drp_avail_reserve_pending
- uwb_drp_avail_reserve
- uwb_drp_avail_release
- uwb_drp_avail_ie_update
- get_val
- buffer_to_bmp
- uwbd_evt_get_drp_avail
- uwbd_evt_handle_rc_drp_avail
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 #include <linux/errno.h>
26 #include <linux/module.h>
27 #include <linux/device.h>
28 #include <linux/bitmap.h>
29 #include "uwb-internal.h"
30
31
32
33
34
35
36
37 void uwb_drp_avail_init(struct uwb_rc *rc)
38 {
39 bitmap_fill(rc->drp_avail.global, UWB_NUM_MAS);
40 bitmap_fill(rc->drp_avail.local, UWB_NUM_MAS);
41 bitmap_fill(rc->drp_avail.pending, UWB_NUM_MAS);
42 }
43
44
45
46
47
48
49 void uwb_drp_available(struct uwb_rc *rc, struct uwb_mas_bm *avail)
50 {
51 bitmap_and(avail->bm, rc->drp_avail.global, rc->drp_avail.local, UWB_NUM_MAS);
52 bitmap_and(avail->bm, avail->bm, rc->drp_avail.pending, UWB_NUM_MAS);
53 }
54
55
56
57
58
59
60
61
62 int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas)
63 {
64 struct uwb_mas_bm avail;
65
66 uwb_drp_available(rc, &avail);
67 if (!bitmap_subset(mas->bm, avail.bm, UWB_NUM_MAS))
68 return -EBUSY;
69
70 bitmap_andnot(rc->drp_avail.pending, rc->drp_avail.pending, mas->bm, UWB_NUM_MAS);
71 return 0;
72 }
73
74
75
76
77
78
79 void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas)
80 {
81 bitmap_or(rc->drp_avail.pending, rc->drp_avail.pending, mas->bm, UWB_NUM_MAS);
82 bitmap_andnot(rc->drp_avail.local, rc->drp_avail.local, mas->bm, UWB_NUM_MAS);
83 rc->drp_avail.ie_valid = false;
84 }
85
86
87
88
89
90
91 void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas)
92 {
93 bitmap_or(rc->drp_avail.local, rc->drp_avail.local, mas->bm, UWB_NUM_MAS);
94 bitmap_or(rc->drp_avail.pending, rc->drp_avail.pending, mas->bm, UWB_NUM_MAS);
95 rc->drp_avail.ie_valid = false;
96 uwb_rsv_handle_drp_avail_change(rc);
97 }
98
99
100
101
102
103
104
105 void uwb_drp_avail_ie_update(struct uwb_rc *rc)
106 {
107 struct uwb_mas_bm avail;
108
109 bitmap_and(avail.bm, rc->drp_avail.global, rc->drp_avail.local, UWB_NUM_MAS);
110
111 rc->drp_avail.ie.hdr.element_id = UWB_IE_DRP_AVAILABILITY;
112 rc->drp_avail.ie.hdr.length = UWB_NUM_MAS / 8;
113 uwb_mas_bm_copy_le(rc->drp_avail.ie.bmp, &avail);
114 rc->drp_avail.ie_valid = true;
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128 static
129 unsigned long get_val(u8 *array, size_t itr, size_t len)
130 {
131 unsigned long val = 0;
132 size_t top = itr + len;
133
134 BUG_ON(len > sizeof(val));
135
136 while (itr < top) {
137 val <<= 8;
138 val |= array[top - 1];
139 top--;
140 }
141 val <<= 8 * (sizeof(val) - len);
142 return val;
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189 static
190 void buffer_to_bmp(unsigned long *bmp_itr, void *_buffer,
191 size_t buffer_size)
192 {
193 u8 *buffer = _buffer;
194 size_t itr, len;
195 unsigned long val;
196
197 itr = 0;
198 while (itr < buffer_size) {
199 len = buffer_size - itr >= sizeof(val) ?
200 sizeof(val) : buffer_size - itr;
201 val = get_val(buffer, itr, len);
202 bmp_itr[itr / sizeof(val)] = val;
203 itr += sizeof(val);
204 }
205 }
206
207
208
209
210
211
212
213
214 static
215 int uwbd_evt_get_drp_avail(struct uwb_event *evt, unsigned long *bmp)
216 {
217 struct device *dev = &evt->rc->uwb_dev.dev;
218 struct uwb_rc_evt_drp_avail *drp_evt;
219 int result = -EINVAL;
220
221
222 if (evt->notif.size < sizeof(*drp_evt)) {
223 dev_err(dev, "DRP Availability Change: Not enough "
224 "data to decode event [%zu bytes, %zu "
225 "needed]\n", evt->notif.size, sizeof(*drp_evt));
226 goto error;
227 }
228 drp_evt = container_of(evt->notif.rceb, struct uwb_rc_evt_drp_avail, rceb);
229 buffer_to_bmp(bmp, drp_evt->bmp, UWB_NUM_MAS/8);
230 result = 0;
231 error:
232 return result;
233 }
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259 int uwbd_evt_handle_rc_drp_avail(struct uwb_event *evt)
260 {
261 int result;
262 struct uwb_rc *rc = evt->rc;
263 DECLARE_BITMAP(bmp, UWB_NUM_MAS);
264
265 result = uwbd_evt_get_drp_avail(evt, bmp);
266 if (result < 0)
267 return result;
268
269 mutex_lock(&rc->rsvs_mutex);
270 bitmap_copy(rc->drp_avail.global, bmp, UWB_NUM_MAS);
271 rc->drp_avail.ie_valid = false;
272 uwb_rsv_handle_drp_avail_change(rc);
273 mutex_unlock(&rc->rsvs_mutex);
274
275 uwb_rsv_sched_update(rc);
276
277 return 0;
278 }