blob: 68f7bd6c02f22a921fc9b3b239eb25345a0a1c50 [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
100
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200101static void assign_uplink_tbf_usf(
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200102 struct gprs_rlcmac_pdch *pdch,
103 int ts,
104 struct gprs_rlcmac_tbf *tbf, int8_t usf)
105{
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200106 tbf->trx->ul_tbf[tbf->tfi] = tbf;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200107 pdch->ul_tbf[tbf->tfi] = tbf;
108 tbf->pdch[ts] = pdch;
109 tbf->dir.ul.usf[ts] = usf;
110}
111
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200112static void assign_dlink_tbf(
113 struct gprs_rlcmac_pdch *pdch,
114 int ts,
115 struct gprs_rlcmac_tbf *tbf)
116{
117 tbf->trx->dl_tbf[tbf->tfi] = tbf;
118 pdch->dl_tbf[tbf->tfi] = tbf;
119 tbf->pdch[ts] = pdch;
120}
121
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200122
123/* Slot Allocation: Algorithm A
124 *
125 * Assign single slot for uplink and downlink
126 */
127int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
128 struct gprs_rlcmac_tbf *old_tbf,
129 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
130{
131 struct gprs_rlcmac_pdch *pdch;
132 uint8_t ts;
133 int8_t usf; /* must be signed */
134
135 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm A) for class "
136 "%d\n", tbf->ms_class);
137
138 for (ts = 0; ts < 8; ts++) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200139 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200140 if (!pdch->enable) {
141 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, because "
142 "not enabled\n", ts);
143 continue;
144 }
145 break;
146 }
147 if (ts == 8)
148 return -EINVAL;
149
150 tbf->tsc = pdch->tsc;
151 if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
152 /* if USF available */
153 usf = find_free_usf(pdch, ts);
154 if (usf < 0) {
155 LOGP(DRLCMAC, LOGL_NOTICE, "- Failed "
156 "allocating TS=%d, no USF available\n", ts);
157 return -EBUSY;
158 }
159 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign uplink "
160 "TS=%d USF=%d\n", ts, usf);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200161 assign_uplink_tbf_usf(pdch, ts, tbf, usf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200162 } else {
163 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign downlink TS=%d\n", ts);
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200164 assign_dlink_tbf(pdch, ts, tbf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200165 }
166 /* the only one TS is the common TS */
167 tbf->first_ts = tbf->first_common_ts = ts;
168
169 return 0;
170}
171
172/* Slot Allocation: Algorithm B
173 *
174 * Assign as many downlink slots as possible.
175 * Assign one uplink slot. (With free USF)
176 *
177 */
178int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
179 struct gprs_rlcmac_tbf *old_tbf,
180 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
181{
182 struct gprs_rlcmac_pdch *pdch;
183 const struct gprs_ms_multislot_class *ms_class;
184 uint8_t Rx, Tx, Sum; /* Maximum Number of Slots: RX, Tx, Sum Rx+Tx */
185 uint8_t Tta, Ttb, Tra, Trb, Tt, Tr; /* Minimum Number of Slots */
186 uint8_t Type; /* Type of Mobile */
187 uint8_t rx_win_min = 0, rx_win_max = 7;
188 uint8_t tx_win_min, tx_win_max, tx_range;
189 uint8_t rx_window = 0, tx_window = 0;
190 static const char *digit[10] = { "0","1","2","3","4","5","6","7","8","9" };
191 int8_t usf[8] = { -1, -1, -1, -1, -1, -1, -1, -1 }; /* must be signed */
192 int8_t tsc = -1; /* must be signed */
193 int8_t first_common_ts = -1;
194 uint8_t i, ts;
195 uint8_t slotcount = 0;
196
197
198 if (tbf->ms_class >= 32) {
199 LOGP(DRLCMAC, LOGL_ERROR, "Multislot class %d out of range.\n",
200 tbf->ms_class);
201 return -EINVAL;
202 }
203
204 if (tbf->ms_class) {
205 ms_class = &gprs_ms_multislot_class[tbf->ms_class];
206 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
207 "class %d\n", tbf->ms_class);
208 } else {
209 ms_class = &gprs_ms_multislot_class[12];
210 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
211 "unknow class (assuming 12)\n");
212 }
213
214 if (ms_class->tx == MS_NA) {
215 LOGP(DRLCMAC, LOGL_NOTICE, "Multislot class %d not "
216 "applicable.\n", tbf->ms_class);
217 return -EINVAL;
218 }
219
220 Rx = ms_class->rx;
221#if 0
222 if (Rx > 4) {
223 LOGP(DRLCMAC, LOGL_DEBUG, "- Degrading max Rx slots to 4\n");
224 Rx = 4;
225 }
226#endif
227 Tx = ms_class->tx;
228#if 0
229 if (Tx > 4) {
230 LOGP(DRLCMAC, LOGL_DEBUG, "- Degrading max Tx slots to 4\n");
231 Tx = 4;
232 }
233#endif
234 Sum = ms_class->sum;
235 Tta = ms_class->ta;
236 Ttb = ms_class->tb;
237 Tra = ms_class->ra;
238 Trb = ms_class->rb;
239 Type = ms_class->type;
240
241 /* Tta and Ttb may depend on hopping or frequency change */
242 if (Ttb == MS_A) {
243 if (/* FIXME: hopping*/ 0)
244 Ttb = 1;
245 else
246 Ttb = 0;
247 }
248 if (Trb == MS_A) {
249 if (/* FIXME: hopping*/ 0)
250 Trb = 1;
251 else
252 Trb = 0;
253 }
254 if (Ttb == MS_B) {
255 /* FIXME: or frequency change */
256 if (/* FIXME: hopping*/ 0)
257 Ttb = 1;
258 else
259 Ttb = 0;
260 }
261 if (Trb == MS_C) {
262 /* FIXME: or frequency change */
263 if (/* FIXME: hopping*/ 0)
264 Trb = 1;
265 else
266 Trb = 0;
267 }
268
269 LOGP(DRLCMAC, LOGL_DEBUG, "- Rx=%d Tx=%d Sum Rx+Tx=%s Tta=%s Ttb=%d "
270 " Tra=%d Trb=%d Type=%d\n", Rx, Tx,
271 (Sum == MS_NA) ? "N/A" : digit[Sum],
272 (Tta == MS_NA) ? "N/A" : digit[Tta], Ttb, Tra, Trb, Type);
273
274 /* select the values for time contraints */
275 if (/* FIXME: monitoring */0) {
276 /* applicable to type 1 and type 2 */
277 Tt = Ttb;
278 Tr = Tra;
279 } else {
280 /* applicable to type 1 and type 2 */
281 Tt = Ttb;
282 Tr = Trb;
283 }
284
285 /* select a window of Rx slots if available
286 * The maximum allowed slots depend on RX or the window of available
287 * slots.
288 * This must be done for uplink TBF also, because it is the basis
289 * for calculating control slot and uplink slot(s). */
290 for (ts = 0, i = 0; ts < 8; ts++) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200291 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200292 /* check if enabled */
293 if (!pdch->enable) {
294 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, because "
295 "not enabled\n", ts);
296 /* increase window for Type 1 */
297 if (Type == 1 && rx_window)
298 i++;
299 continue;
300 }
301 /* check if TSC changes */
302 if (tsc < 0)
303 tbf->tsc = tsc = pdch->tsc;
304 else if (tsc != pdch->tsc) {
305 LOGP(DRLCMAC, LOGL_ERROR, "Skipping TS %d of TRX=%d, "
306 "because it has different TSC than lower TS "
307 "of TRX. In order to allow multislot, all "
308 "slots must be configured with the same "
Holger Hans Peter Freyther96efa702013-09-29 07:44:39 +0200309 "TSC!\n", ts, tbf->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200310 /* increase window for Type 1 */
311 if (Type == 1 && rx_window)
312 i++;
313 continue;
314 }
315
316 if (!rx_window)
317 rx_win_min = ts;
318
319 rx_window |= (1 << ts);
320 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected DL TS %d\n", ts);
321
322 /* range of window (required for Type 1) */
323 rx_win_max = ts;
324
325 if (++i == Rx) {
326 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because slots / "
327 "window reached maximum alowed Rx size\n");
328 break;
329 }
330 }
331
332 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected slots for RX: "
333 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
334 ((rx_window & 0x01)) ? 'D' : '.',
335 ((rx_window & 0x02)) ? 'D' : '.',
336 ((rx_window & 0x04)) ? 'D' : '.',
337 ((rx_window & 0x08)) ? 'D' : '.',
338 ((rx_window & 0x10)) ? 'D' : '.',
339 ((rx_window & 0x20)) ? 'D' : '.',
340 ((rx_window & 0x40)) ? 'D' : '.',
341 ((rx_window & 0x80)) ? 'D' : '.');
342
343 /* reduce window, if existing uplink slots collide RX window */
344 if (Type == 1 && old_tbf && old_tbf->direction == GPRS_RLCMAC_UL_TBF) {
345 uint8_t collide = 0, ul_usage = 0;
346 int j;
347
348 /* calculate mask of colliding slots */
349 for (ts = 0; ts < 8; ts++) {
350 if (old_tbf->pdch[ts]) {
351 ul_usage |= (1 << ts);
352 /* mark bits from TS-t .. TS+r */
353 for (j = ts - Tt; j != ((ts + Tr + 1) & 7);
354 j = (j + 1) & 7)
355 collide |= (1 << j);
356 }
357 }
358 LOGP(DRLCMAC, LOGL_DEBUG, "- Not allowed slots due to existing "
359 "UL allocation: (TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7) "
360 " D=downlink x=not usable\n",
361 ((ul_usage & 0x01)) ? 'D' : ((collide & 0x01))?'x':'.',
362 ((ul_usage & 0x02)) ? 'D' : ((collide & 0x02))?'x':'.',
363 ((ul_usage & 0x04)) ? 'D' : ((collide & 0x04))?'x':'.',
364 ((ul_usage & 0x08)) ? 'D' : ((collide & 0x08))?'x':'.',
365 ((ul_usage & 0x10)) ? 'D' : ((collide & 0x10))?'x':'.',
366 ((ul_usage & 0x20)) ? 'D' : ((collide & 0x20))?'x':'.',
367 ((ul_usage & 0x40)) ? 'D' : ((collide & 0x40))?'x':'.',
368 ((ul_usage & 0x80)) ? 'D' : ((collide & 0x80))?'x':'.');
369
370 /* apply mask to reduce tx_window (shifted by 3 slots) */
371 rx_window &= ~(collide << 3);
372 rx_window &= ~(collide >> 5);
373 LOGP(DRLCMAC, LOGL_DEBUG, "- Remaining slots for RX: "
374 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
375 ((rx_window & 0x01)) ? 'D' : '.',
376 ((rx_window & 0x02)) ? 'D' : '.',
377 ((rx_window & 0x04)) ? 'D' : '.',
378 ((rx_window & 0x08)) ? 'D' : '.',
379 ((rx_window & 0x10)) ? 'D' : '.',
380 ((rx_window & 0x20)) ? 'D' : '.',
381 ((rx_window & 0x40)) ? 'D' : '.',
382 ((rx_window & 0x80)) ? 'D' : '.');
383 if (!rx_window) {
384 LOGP(DRLCMAC, LOGL_NOTICE, "No suitable downlink slots "
385 "available with current uplink assignment\n");
386 return -EBUSY;
387 }
388
389 /* calculate new min/max */
390 for (ts = rx_win_min; ts <= rx_win_max; ts++) {
391 if ((rx_window & (1 << ts)))
392 break;
393 rx_win_min = ts + 1;
394 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
395 "raising start of DL window to %d\n",
396 rx_win_min);
397 }
398 for (ts = rx_win_max; ts >= rx_win_min; ts--) {
399 if ((rx_window & (1 << ts)))
400 break;
401 rx_win_max = ts - 1;
402 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
403 "lowering end of DL window to %d\n",
404 rx_win_max);
405 }
406 }
407
408 /* reduce window, to allow at least one uplink TX slot
409 * this is only required for Type 1 */
410 if (Type == 1 && rx_win_max - rx_win_min + 1 + Tt + 1 + Tr > 8) {
411 rx_win_max = rx_win_min + 7 - Tt - 1 - Tr;
412 LOGP(DRLCMAC, LOGL_DEBUG, "- Reduce RX window due to time "
413 "contraints to %d slots\n",
414 rx_win_max - rx_win_min + 1);
415 }
416
417 LOGP(DRLCMAC, LOGL_DEBUG, "- RX-Window is: %d..%d\n", rx_win_min,
418 rx_win_max);
419
420 /* calculate TX window */
421 if (Type == 1) {
422 /* calculate TX window (shifted by 3 timeslots)
423 * it uses the space between tx_win_max and tx_win_min */
424 tx_win_min = (rx_win_max - 2 + Tt) & 7;
425 tx_win_max = (rx_win_min + 4 - Tr) & 7;
426 /* calculate the TX window size (might be larger than Tx) */
427 tx_range = (tx_win_max - tx_win_min + 1) & 7;
428 } else {
429 /* TX and RX simultaniously */
430 tx_win_min = rx_win_min;
431 tx_win_max = 7;
432 /* TX window size (might be larger than Tx) */
433 tx_range = tx_win_max - tx_win_min + 1;
434 }
435
436 LOGP(DRLCMAC, LOGL_DEBUG, "- TX-Window is: %d..%d\n", tx_win_min,
437 tx_win_max);
438
439 /* select a window of Tx slots if available
440 * The maximum allowed slots depend on TX or the window of available
441 * slots.
442 *
443 * also assign the first common ts, which is used for control or single
444 * slot. */
445 if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
446 for (ts = tx_win_min, i = 0; i < tx_range; ts = (ts + 1) & 7) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200447 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200448 /* check if enabled */
449 if (!pdch->enable) {
450 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
451 "because not enabled\n", ts);
452 continue;
453 }
454 /* check if TSC changes */
455 if (tsc < 0)
456 tbf->tsc = tsc = pdch->tsc;
457 else if (tsc != pdch->tsc) {
458 LOGP(DRLCMAC, LOGL_ERROR, "Skipping TS %d of "
459 "TRX=%d, because it has different TSC "
460 "than lower TS of TRX. In order to "
461 "allow multislot, all slots must be "
462 "configured with the same TSC!\n",
Holger Hans Peter Freyther96efa702013-09-29 07:44:39 +0200463 ts, tbf->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200464 /* increase window for Type 1 */
465 if (Type == 1)
466 i++;
467 continue;
468 }
469 /* check for free usf */
470 usf[ts] = find_free_usf(pdch, ts);
471 if (usf[ts] < 0) {
472 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
473 "because no USF available\n", ts);
474 /* increase window for Type 1 */
475 if (Type == 1)
476 i++;
477 continue;
478 }
479
480 if (!tx_window)
481 first_common_ts = ts;
482
483 tx_window |= (1 << ts);
484 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected UL TS %d\n", ts);
485
486 if (1 && Type == 1) { /* FIXME: multislot UL assignment */
487 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because "
488 "1 slot assigned\n");
489 break;
490 }
491 if (++i == Tx) {
492 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because "
493 "slots / window reached maximum "
494 "allowed Tx size\n");
495 break;
496 }
497 }
498
499 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected TX window: "
500 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
501 ((tx_window & 0x01)) ? 'U' : '.',
502 ((tx_window & 0x02)) ? 'U' : '.',
503 ((tx_window & 0x04)) ? 'U' : '.',
504 ((tx_window & 0x08)) ? 'U' : '.',
505 ((tx_window & 0x10)) ? 'U' : '.',
506 ((tx_window & 0x20)) ? 'U' : '.',
507 ((tx_window & 0x40)) ? 'U' : '.',
508 ((tx_window & 0x80)) ? 'U' : '.');
509
510 if (!tx_window) {
511 LOGP(DRLCMAC, LOGL_NOTICE, "No suitable uplink slots "
512 "available\n");
513 return -EBUSY;
514 }
515 } else {
516 /* assign the first common ts, which is used for control or
517 * single slot. */
518 for (ts = tx_win_min, i = 0; i < tx_range; ts = (ts + 1) & 7) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200519 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200520 /* check if enabled */
521 if (!pdch->enable) {
522 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
523 "because not enabled\n", ts);
524 continue;
525 }
526 first_common_ts = ts;
527 break;
528 }
529 }
530
531 if (first_common_ts < 0) {
532 LOGP(DRLCMAC, LOGL_NOTICE, "No first common slots available\n");
533 return -EINVAL;
534 }
535
536 if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
537 /* assign downlink */
538 if (rx_window == 0) {
539 LOGP(DRLCMAC, LOGL_NOTICE, "No downlink slots "
540 "available\n");
541 return -EINVAL;
542 }
543 for (ts = 0; ts < 8; ts++) {
544 if ((rx_window & (1 << ts))) {
545 /* be sure to select a single downlink slots
546 * that can be used for uplink, if multiple
547 * slots are assigned later. */
548 if (single && first_common_ts != ts)
549 continue;
550 LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS "
551 "%d\n", ts);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200552 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200553 assign_dlink_tbf(pdch, ts, tbf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200554 slotcount++;
555 if (slotcount == 1)
556 tbf->first_ts = ts;
557 if (single)
558 break;
559 }
560 }
561 } else {
562 /* assign uplink */
563 if (tx_window == 0) {
564 LOGP(DRLCMAC, LOGL_NOTICE, "No uplink slots "
565 "available\n");
566 return -EINVAL;
567 }
568 for (ts = 0; ts < 8; ts++) {
569 if ((tx_window & (1 << ts))) {
570 LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS "
571 "%d\n", ts);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200572 pdch = &tbf->trx->pdch[ts];
573 assign_uplink_tbf_usf(pdch, ts, tbf, usf[ts]);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200574 slotcount++;
575 if (slotcount == 1)
576 tbf->first_ts = ts;
577 if (single)
578 break;
579 }
580 }
581 }
582 if (single && slotcount) {
583 LOGP(DRLCMAC, LOGL_INFO, "Using single slot at TS %d for %s\n",
584 tbf->first_ts,
585 (tbf->direction == GPRS_RLCMAC_DL_TBF) ? "DL" : "UL");
586 } else {
587 LOGP(DRLCMAC, LOGL_INFO, "Using %d slots for %s\n", slotcount,
588 (tbf->direction == GPRS_RLCMAC_DL_TBF) ? "DL" : "UL");
589 }
590 if (slotcount == 0)
591 return -EBUSY;
592
593 tbf->first_common_ts = first_common_ts;
594
595 return 0;
596}