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