blob: 29078d0ec6ae123ce56944f26d1ccf752d386d1e [file] [log] [blame]
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +02001/* gprs_rlcmac.cpp
2 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
4 * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
5 * Copyright (C) 2013 by Holger Hans Peter Freyther
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include <gprs_rlcmac.h>
23#include <gprs_debug.h>
24#include <tbf.h>
25
26#include <errno.h>
27
28/* 3GPP TS 05.02 Annex B.1 */
29
30#define MS_NA 255 /* N/A */
31#define MS_A 254 /* 1 with hopping, 0 without */
32#define MS_B 253 /* 1 with hopping, 0 without (change Rx to Tx)*/
33#define MS_C 252 /* 1 with hopping, 0 without (change Tx to Rx)*/
34
35struct gprs_ms_multislot_class {
36 uint8_t rx, tx, sum; /* Maximum Number of Slots: RX, Tx, Sum Rx+Tx */
37 uint8_t ta, tb, ra, rb; /* Minimum Number of Slots */
38 uint8_t type; /* Type of Mobile */
39};
40
41static const struct gprs_ms_multislot_class gprs_ms_multislot_class[32] = {
42/* M-S Class Rx Tx Sum Tta Ttb Tra Trb Type */
43/* N/A */ { MS_NA,MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA },
44/* 1 */ { 1, 1, 2, 3, 2, 4, 2, 1 },
45/* 2 */ { 2, 1, 3, 3, 2, 3, 1, 1 },
46/* 3 */ { 2, 2, 3, 3, 2, 3, 1, 1 },
47/* 4 */ { 3, 1, 4, 3, 1, 3, 1, 1 },
48/* 5 */ { 2, 2, 4, 3, 1, 3, 1, 1 },
49/* 6 */ { 3, 2, 4, 3, 1, 3, 1, 1 },
50/* 7 */ { 3, 3, 4, 3, 1, 3, 1, 1 },
51/* 8 */ { 4, 1, 5, 3, 1, 2, 1, 1 },
52/* 9 */ { 3, 2, 5, 3, 1, 2, 1, 1 },
53/* 10 */ { 4, 2, 5, 3, 1, 2, 1, 1 },
54/* 11 */ { 4, 3, 5, 3, 1, 2, 1, 1 },
55/* 12 */ { 4, 4, 5, 2, 1, 2, 1, 1 },
56/* 13 */ { 3, 3, MS_NA, MS_NA, MS_A, 3, MS_A, 2 },
57/* 14 */ { 4, 4, MS_NA, MS_NA, MS_A, 3, MS_A, 2 },
58/* 15 */ { 5, 5, MS_NA, MS_NA, MS_A, 3, MS_A, 2 },
59/* 16 */ { 6, 6, MS_NA, MS_NA, MS_A, 2, MS_A, 2 },
60/* 17 */ { 7, 7, MS_NA, MS_NA, MS_A, 1, 0, 2 },
61/* 18 */ { 8, 8, MS_NA, MS_NA, 0, 0, 0, 2 },
62/* 19 */ { 6, 2, MS_NA, 3, MS_B, 2, MS_C, 1 },
63/* 20 */ { 6, 3, MS_NA, 3, MS_B, 2, MS_C, 1 },
64/* 21 */ { 6, 4, MS_NA, 3, MS_B, 2, MS_C, 1 },
65/* 22 */ { 6, 4, MS_NA, 2, MS_B, 2, MS_C, 1 },
66/* 23 */ { 6, 6, MS_NA, 2, MS_B, 2, MS_C, 1 },
67/* 24 */ { 8, 2, MS_NA, 3, MS_B, 2, MS_C, 1 },
68/* 25 */ { 8, 3, MS_NA, 3, MS_B, 2, MS_C, 1 },
69/* 26 */ { 8, 4, MS_NA, 3, MS_B, 2, MS_C, 1 },
70/* 27 */ { 8, 4, MS_NA, 2, MS_B, 2, MS_C, 1 },
71/* 28 */ { 8, 6, MS_NA, 2, MS_B, 2, MS_C, 1 },
72/* 29 */ { 8, 8, MS_NA, 2, MS_B, 2, MS_C, 1 },
73/* N/A */ { MS_NA,MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA },
74/* N/A */ { MS_NA,MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA },
75};
76
77static inline int8_t find_free_usf(struct gprs_rlcmac_pdch *pdch, uint8_t ts)
78{
79 struct gprs_rlcmac_tbf *tbf;
80 uint8_t usf_map = 0;
81 uint8_t tfi, usf;
82
83 /* make map of used USF */
84 for (tfi = 0; tfi < 32; tfi++) {
85 tbf = pdch->ul_tbf[tfi];
86 if (!tbf)
87 continue;
88 usf_map |= (1 << tbf->dir.ul.usf[ts]);
89 }
90
91 /* look for USF, don't use USF=7 */
92 for (usf = 0; usf < 7; usf++) {
93 if (!(usf_map & (1 << usf)))
94 return usf;
95 }
96
97 return -1;
98}
99
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200100static int find_enabled_pdch(struct gprs_rlcmac_trx *trx, const uint8_t start_ts)
101{
102 int ts;
103 for (ts = start_ts; ts < 8; ts++) {
104 struct gprs_rlcmac_pdch *pdch;
105
106 pdch = &trx->pdch[ts];
107 if (!pdch->enable) {
108 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, because "
109 "not enabled\n", ts);
110 continue;
111 }
112 return ts;
113 }
114
115 return 8;
116}
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200117
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200118static void assign_uplink_tbf_usf(
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200119 struct gprs_rlcmac_pdch *pdch,
120 int ts,
121 struct gprs_rlcmac_tbf *tbf, int8_t usf)
122{
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200123 tbf->trx->ul_tbf[tbf->tfi] = tbf;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200124 pdch->ul_tbf[tbf->tfi] = tbf;
125 tbf->pdch[ts] = pdch;
126 tbf->dir.ul.usf[ts] = usf;
127}
128
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200129static void assign_dlink_tbf(
130 struct gprs_rlcmac_pdch *pdch,
131 int ts,
132 struct gprs_rlcmac_tbf *tbf)
133{
134 tbf->trx->dl_tbf[tbf->tfi] = tbf;
135 pdch->dl_tbf[tbf->tfi] = tbf;
136 tbf->pdch[ts] = pdch;
137}
138
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200139
140/* Slot Allocation: Algorithm A
141 *
142 * Assign single slot for uplink and downlink
143 */
144int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
145 struct gprs_rlcmac_tbf *old_tbf,
146 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
147{
148 struct gprs_rlcmac_pdch *pdch;
149 uint8_t ts;
150 int8_t usf; /* must be signed */
151
152 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm A) for class "
153 "%d\n", tbf->ms_class);
154
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200155 ts = find_enabled_pdch(tbf->trx, 0);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200156 if (ts == 8)
157 return -EINVAL;
158
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200159 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200160 tbf->tsc = pdch->tsc;
161 if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
162 /* if USF available */
163 usf = find_free_usf(pdch, ts);
164 if (usf < 0) {
165 LOGP(DRLCMAC, LOGL_NOTICE, "- Failed "
166 "allocating TS=%d, no USF available\n", ts);
167 return -EBUSY;
168 }
169 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign uplink "
170 "TS=%d USF=%d\n", ts, usf);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200171 assign_uplink_tbf_usf(pdch, ts, tbf, usf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200172 } else {
173 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign downlink TS=%d\n", ts);
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200174 assign_dlink_tbf(pdch, ts, tbf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200175 }
176 /* the only one TS is the common TS */
177 tbf->first_ts = tbf->first_common_ts = ts;
178
179 return 0;
180}
181
182/* Slot Allocation: Algorithm B
183 *
184 * Assign as many downlink slots as possible.
185 * Assign one uplink slot. (With free USF)
186 *
187 */
188int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
189 struct gprs_rlcmac_tbf *old_tbf,
190 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
191{
192 struct gprs_rlcmac_pdch *pdch;
193 const struct gprs_ms_multislot_class *ms_class;
194 uint8_t Rx, Tx, Sum; /* Maximum Number of Slots: RX, Tx, Sum Rx+Tx */
195 uint8_t Tta, Ttb, Tra, Trb, Tt, Tr; /* Minimum Number of Slots */
196 uint8_t Type; /* Type of Mobile */
197 uint8_t rx_win_min = 0, rx_win_max = 7;
198 uint8_t tx_win_min, tx_win_max, tx_range;
199 uint8_t rx_window = 0, tx_window = 0;
200 static const char *digit[10] = { "0","1","2","3","4","5","6","7","8","9" };
201 int8_t usf[8] = { -1, -1, -1, -1, -1, -1, -1, -1 }; /* must be signed */
202 int8_t tsc = -1; /* must be signed */
203 int8_t first_common_ts = -1;
204 uint8_t i, ts;
205 uint8_t slotcount = 0;
206
207
208 if (tbf->ms_class >= 32) {
209 LOGP(DRLCMAC, LOGL_ERROR, "Multislot class %d out of range.\n",
210 tbf->ms_class);
211 return -EINVAL;
212 }
213
214 if (tbf->ms_class) {
215 ms_class = &gprs_ms_multislot_class[tbf->ms_class];
216 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
217 "class %d\n", tbf->ms_class);
218 } else {
219 ms_class = &gprs_ms_multislot_class[12];
220 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
221 "unknow class (assuming 12)\n");
222 }
223
224 if (ms_class->tx == MS_NA) {
225 LOGP(DRLCMAC, LOGL_NOTICE, "Multislot class %d not "
226 "applicable.\n", tbf->ms_class);
227 return -EINVAL;
228 }
229
230 Rx = ms_class->rx;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200231 Tx = ms_class->tx;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200232 Sum = ms_class->sum;
233 Tta = ms_class->ta;
234 Ttb = ms_class->tb;
235 Tra = ms_class->ra;
236 Trb = ms_class->rb;
237 Type = ms_class->type;
238
239 /* Tta and Ttb may depend on hopping or frequency change */
Holger Hans Peter Freyther11a74892013-09-29 08:13:42 +0200240 if (Ttb == MS_A)
241 Ttb = 0;
242 if (Trb == MS_A)
243 Trb = 0;
244 if (Ttb == MS_B)
245 Ttb = 0;
246 if (Trb == MS_C)
247 Trb = 0;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200248
249 LOGP(DRLCMAC, LOGL_DEBUG, "- Rx=%d Tx=%d Sum Rx+Tx=%s Tta=%s Ttb=%d "
250 " Tra=%d Trb=%d Type=%d\n", Rx, Tx,
251 (Sum == MS_NA) ? "N/A" : digit[Sum],
252 (Tta == MS_NA) ? "N/A" : digit[Tta], Ttb, Tra, Trb, Type);
253
254 /* select the values for time contraints */
Holger Hans Peter Freyther11a74892013-09-29 08:13:42 +0200255 /* applicable to type 1 and type 2 */
256 Tt = Ttb;
257 Tr = Trb;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200258
259 /* select a window of Rx slots if available
260 * The maximum allowed slots depend on RX or the window of available
261 * slots.
262 * This must be done for uplink TBF also, because it is the basis
263 * for calculating control slot and uplink slot(s). */
264 for (ts = 0, i = 0; ts < 8; ts++) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200265 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200266 /* check if enabled */
267 if (!pdch->enable) {
268 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, because "
269 "not enabled\n", ts);
270 /* increase window for Type 1 */
271 if (Type == 1 && rx_window)
272 i++;
273 continue;
274 }
275 /* check if TSC changes */
276 if (tsc < 0)
277 tbf->tsc = tsc = pdch->tsc;
278 else if (tsc != pdch->tsc) {
279 LOGP(DRLCMAC, LOGL_ERROR, "Skipping TS %d of TRX=%d, "
280 "because it has different TSC than lower TS "
281 "of TRX. In order to allow multislot, all "
282 "slots must be configured with the same "
Holger Hans Peter Freyther96efa702013-09-29 07:44:39 +0200283 "TSC!\n", ts, tbf->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200284 /* increase window for Type 1 */
285 if (Type == 1 && rx_window)
286 i++;
287 continue;
288 }
289
290 if (!rx_window)
291 rx_win_min = ts;
292
293 rx_window |= (1 << ts);
294 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected DL TS %d\n", ts);
295
296 /* range of window (required for Type 1) */
297 rx_win_max = ts;
298
299 if (++i == Rx) {
300 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because slots / "
301 "window reached maximum alowed Rx size\n");
302 break;
303 }
304 }
305
306 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected slots for RX: "
307 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
308 ((rx_window & 0x01)) ? 'D' : '.',
309 ((rx_window & 0x02)) ? 'D' : '.',
310 ((rx_window & 0x04)) ? 'D' : '.',
311 ((rx_window & 0x08)) ? 'D' : '.',
312 ((rx_window & 0x10)) ? 'D' : '.',
313 ((rx_window & 0x20)) ? 'D' : '.',
314 ((rx_window & 0x40)) ? 'D' : '.',
315 ((rx_window & 0x80)) ? 'D' : '.');
316
317 /* reduce window, if existing uplink slots collide RX window */
318 if (Type == 1 && old_tbf && old_tbf->direction == GPRS_RLCMAC_UL_TBF) {
319 uint8_t collide = 0, ul_usage = 0;
320 int j;
321
322 /* calculate mask of colliding slots */
323 for (ts = 0; ts < 8; ts++) {
324 if (old_tbf->pdch[ts]) {
325 ul_usage |= (1 << ts);
326 /* mark bits from TS-t .. TS+r */
327 for (j = ts - Tt; j != ((ts + Tr + 1) & 7);
328 j = (j + 1) & 7)
329 collide |= (1 << j);
330 }
331 }
332 LOGP(DRLCMAC, LOGL_DEBUG, "- Not allowed slots due to existing "
333 "UL allocation: (TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7) "
334 " D=downlink x=not usable\n",
335 ((ul_usage & 0x01)) ? 'D' : ((collide & 0x01))?'x':'.',
336 ((ul_usage & 0x02)) ? 'D' : ((collide & 0x02))?'x':'.',
337 ((ul_usage & 0x04)) ? 'D' : ((collide & 0x04))?'x':'.',
338 ((ul_usage & 0x08)) ? 'D' : ((collide & 0x08))?'x':'.',
339 ((ul_usage & 0x10)) ? 'D' : ((collide & 0x10))?'x':'.',
340 ((ul_usage & 0x20)) ? 'D' : ((collide & 0x20))?'x':'.',
341 ((ul_usage & 0x40)) ? 'D' : ((collide & 0x40))?'x':'.',
342 ((ul_usage & 0x80)) ? 'D' : ((collide & 0x80))?'x':'.');
343
344 /* apply mask to reduce tx_window (shifted by 3 slots) */
345 rx_window &= ~(collide << 3);
346 rx_window &= ~(collide >> 5);
347 LOGP(DRLCMAC, LOGL_DEBUG, "- Remaining slots for RX: "
348 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
349 ((rx_window & 0x01)) ? 'D' : '.',
350 ((rx_window & 0x02)) ? 'D' : '.',
351 ((rx_window & 0x04)) ? 'D' : '.',
352 ((rx_window & 0x08)) ? 'D' : '.',
353 ((rx_window & 0x10)) ? 'D' : '.',
354 ((rx_window & 0x20)) ? 'D' : '.',
355 ((rx_window & 0x40)) ? 'D' : '.',
356 ((rx_window & 0x80)) ? 'D' : '.');
357 if (!rx_window) {
358 LOGP(DRLCMAC, LOGL_NOTICE, "No suitable downlink slots "
359 "available with current uplink assignment\n");
360 return -EBUSY;
361 }
362
363 /* calculate new min/max */
364 for (ts = rx_win_min; ts <= rx_win_max; ts++) {
365 if ((rx_window & (1 << ts)))
366 break;
367 rx_win_min = ts + 1;
368 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
369 "raising start of DL window to %d\n",
370 rx_win_min);
371 }
372 for (ts = rx_win_max; ts >= rx_win_min; ts--) {
373 if ((rx_window & (1 << ts)))
374 break;
375 rx_win_max = ts - 1;
376 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
377 "lowering end of DL window to %d\n",
378 rx_win_max);
379 }
380 }
381
382 /* reduce window, to allow at least one uplink TX slot
383 * this is only required for Type 1 */
384 if (Type == 1 && rx_win_max - rx_win_min + 1 + Tt + 1 + Tr > 8) {
385 rx_win_max = rx_win_min + 7 - Tt - 1 - Tr;
386 LOGP(DRLCMAC, LOGL_DEBUG, "- Reduce RX window due to time "
387 "contraints to %d slots\n",
388 rx_win_max - rx_win_min + 1);
389 }
390
391 LOGP(DRLCMAC, LOGL_DEBUG, "- RX-Window is: %d..%d\n", rx_win_min,
392 rx_win_max);
393
394 /* calculate TX window */
395 if (Type == 1) {
396 /* calculate TX window (shifted by 3 timeslots)
397 * it uses the space between tx_win_max and tx_win_min */
398 tx_win_min = (rx_win_max - 2 + Tt) & 7;
399 tx_win_max = (rx_win_min + 4 - Tr) & 7;
400 /* calculate the TX window size (might be larger than Tx) */
401 tx_range = (tx_win_max - tx_win_min + 1) & 7;
402 } else {
403 /* TX and RX simultaniously */
404 tx_win_min = rx_win_min;
405 tx_win_max = 7;
406 /* TX window size (might be larger than Tx) */
407 tx_range = tx_win_max - tx_win_min + 1;
408 }
409
410 LOGP(DRLCMAC, LOGL_DEBUG, "- TX-Window is: %d..%d\n", tx_win_min,
411 tx_win_max);
412
413 /* select a window of Tx slots if available
414 * The maximum allowed slots depend on TX or the window of available
415 * slots.
416 *
417 * also assign the first common ts, which is used for control or single
418 * slot. */
419 if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
420 for (ts = tx_win_min, i = 0; i < tx_range; ts = (ts + 1) & 7) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200421 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200422 /* check if enabled */
423 if (!pdch->enable) {
424 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
425 "because not enabled\n", ts);
426 continue;
427 }
428 /* check if TSC changes */
429 if (tsc < 0)
430 tbf->tsc = tsc = pdch->tsc;
431 else if (tsc != pdch->tsc) {
432 LOGP(DRLCMAC, LOGL_ERROR, "Skipping TS %d of "
433 "TRX=%d, because it has different TSC "
434 "than lower TS of TRX. In order to "
435 "allow multislot, all slots must be "
436 "configured with the same TSC!\n",
Holger Hans Peter Freyther96efa702013-09-29 07:44:39 +0200437 ts, tbf->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200438 /* increase window for Type 1 */
439 if (Type == 1)
440 i++;
441 continue;
442 }
443 /* check for free usf */
444 usf[ts] = find_free_usf(pdch, ts);
445 if (usf[ts] < 0) {
446 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
447 "because no USF available\n", ts);
448 /* increase window for Type 1 */
449 if (Type == 1)
450 i++;
451 continue;
452 }
453
454 if (!tx_window)
455 first_common_ts = ts;
456
457 tx_window |= (1 << ts);
458 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected UL TS %d\n", ts);
459
460 if (1 && Type == 1) { /* FIXME: multislot UL assignment */
461 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because "
462 "1 slot assigned\n");
463 break;
464 }
465 if (++i == Tx) {
466 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because "
467 "slots / window reached maximum "
468 "allowed Tx size\n");
469 break;
470 }
471 }
472
473 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected TX window: "
474 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
475 ((tx_window & 0x01)) ? 'U' : '.',
476 ((tx_window & 0x02)) ? 'U' : '.',
477 ((tx_window & 0x04)) ? 'U' : '.',
478 ((tx_window & 0x08)) ? 'U' : '.',
479 ((tx_window & 0x10)) ? 'U' : '.',
480 ((tx_window & 0x20)) ? 'U' : '.',
481 ((tx_window & 0x40)) ? 'U' : '.',
482 ((tx_window & 0x80)) ? 'U' : '.');
483
484 if (!tx_window) {
485 LOGP(DRLCMAC, LOGL_NOTICE, "No suitable uplink slots "
486 "available\n");
487 return -EBUSY;
488 }
489 } else {
490 /* assign the first common ts, which is used for control or
491 * single slot. */
492 for (ts = tx_win_min, i = 0; i < tx_range; ts = (ts + 1) & 7) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200493 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200494 /* check if enabled */
495 if (!pdch->enable) {
496 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
497 "because not enabled\n", ts);
498 continue;
499 }
500 first_common_ts = ts;
501 break;
502 }
503 }
504
505 if (first_common_ts < 0) {
506 LOGP(DRLCMAC, LOGL_NOTICE, "No first common slots available\n");
507 return -EINVAL;
508 }
509
510 if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
511 /* assign downlink */
512 if (rx_window == 0) {
513 LOGP(DRLCMAC, LOGL_NOTICE, "No downlink slots "
514 "available\n");
515 return -EINVAL;
516 }
517 for (ts = 0; ts < 8; ts++) {
518 if ((rx_window & (1 << ts))) {
519 /* be sure to select a single downlink slots
520 * that can be used for uplink, if multiple
521 * slots are assigned later. */
522 if (single && first_common_ts != ts)
523 continue;
524 LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS "
525 "%d\n", ts);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200526 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200527 assign_dlink_tbf(pdch, ts, tbf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200528 slotcount++;
529 if (slotcount == 1)
530 tbf->first_ts = ts;
531 if (single)
532 break;
533 }
534 }
535 } else {
536 /* assign uplink */
537 if (tx_window == 0) {
538 LOGP(DRLCMAC, LOGL_NOTICE, "No uplink slots "
539 "available\n");
540 return -EINVAL;
541 }
542 for (ts = 0; ts < 8; ts++) {
543 if ((tx_window & (1 << ts))) {
544 LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS "
545 "%d\n", ts);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200546 pdch = &tbf->trx->pdch[ts];
547 assign_uplink_tbf_usf(pdch, ts, tbf, usf[ts]);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200548 slotcount++;
549 if (slotcount == 1)
550 tbf->first_ts = ts;
551 if (single)
552 break;
553 }
554 }
555 }
556 if (single && slotcount) {
557 LOGP(DRLCMAC, LOGL_INFO, "Using single slot at TS %d for %s\n",
558 tbf->first_ts,
559 (tbf->direction == GPRS_RLCMAC_DL_TBF) ? "DL" : "UL");
560 } else {
561 LOGP(DRLCMAC, LOGL_INFO, "Using %d slots for %s\n", slotcount,
562 (tbf->direction == GPRS_RLCMAC_DL_TBF) ? "DL" : "UL");
563 }
564 if (slotcount == 0)
565 return -EBUSY;
566
567 tbf->first_common_ts = first_common_ts;
568
569 return 0;
570}