blob: bf69296ddf7183c4c15af68d73cbe1e81c6ffc87 [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];
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200107 if (!pdch->is_enabled()) {
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200108 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;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200150
151 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm A) for class "
152 "%d\n", tbf->ms_class);
153
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200154 ts = find_enabled_pdch(tbf->trx, 0);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200155 if (ts == 8)
156 return -EINVAL;
157
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200158 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200159 tbf->tsc = pdch->tsc;
160 if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
Holger Hans Peter Freyther948a3d62013-09-30 14:10:23 +0200161 int8_t usf; /* must be signed */
162
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200163 /* if USF available */
164 usf = find_free_usf(pdch, ts);
165 if (usf < 0) {
166 LOGP(DRLCMAC, LOGL_NOTICE, "- Failed "
167 "allocating TS=%d, no USF available\n", ts);
168 return -EBUSY;
169 }
170 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign uplink "
171 "TS=%d USF=%d\n", ts, usf);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200172 assign_uplink_tbf_usf(pdch, ts, tbf, usf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200173 } else {
174 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign downlink TS=%d\n", ts);
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200175 assign_dlink_tbf(pdch, ts, tbf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200176 }
177 /* the only one TS is the common TS */
178 tbf->first_ts = tbf->first_common_ts = ts;
179
180 return 0;
181}
182
183/* Slot Allocation: Algorithm B
184 *
185 * Assign as many downlink slots as possible.
186 * Assign one uplink slot. (With free USF)
187 *
188 */
189int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
190 struct gprs_rlcmac_tbf *old_tbf,
191 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
192{
193 struct gprs_rlcmac_pdch *pdch;
194 const struct gprs_ms_multislot_class *ms_class;
195 uint8_t Rx, Tx, Sum; /* Maximum Number of Slots: RX, Tx, Sum Rx+Tx */
196 uint8_t Tta, Ttb, Tra, Trb, Tt, Tr; /* Minimum Number of Slots */
197 uint8_t Type; /* Type of Mobile */
198 uint8_t rx_win_min = 0, rx_win_max = 7;
199 uint8_t tx_win_min, tx_win_max, tx_range;
200 uint8_t rx_window = 0, tx_window = 0;
201 static const char *digit[10] = { "0","1","2","3","4","5","6","7","8","9" };
202 int8_t usf[8] = { -1, -1, -1, -1, -1, -1, -1, -1 }; /* must be signed */
203 int8_t tsc = -1; /* must be signed */
204 int8_t first_common_ts = -1;
205 uint8_t i, ts;
206 uint8_t slotcount = 0;
207
208
209 if (tbf->ms_class >= 32) {
210 LOGP(DRLCMAC, LOGL_ERROR, "Multislot class %d out of range.\n",
211 tbf->ms_class);
212 return -EINVAL;
213 }
214
215 if (tbf->ms_class) {
216 ms_class = &gprs_ms_multislot_class[tbf->ms_class];
217 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
218 "class %d\n", tbf->ms_class);
219 } else {
220 ms_class = &gprs_ms_multislot_class[12];
221 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
222 "unknow class (assuming 12)\n");
223 }
224
225 if (ms_class->tx == MS_NA) {
226 LOGP(DRLCMAC, LOGL_NOTICE, "Multislot class %d not "
227 "applicable.\n", tbf->ms_class);
228 return -EINVAL;
229 }
230
231 Rx = ms_class->rx;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200232 Tx = ms_class->tx;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200233 Sum = ms_class->sum;
234 Tta = ms_class->ta;
235 Ttb = ms_class->tb;
236 Tra = ms_class->ra;
237 Trb = ms_class->rb;
238 Type = ms_class->type;
239
240 /* Tta and Ttb may depend on hopping or frequency change */
Holger Hans Peter Freyther11a74892013-09-29 08:13:42 +0200241 if (Ttb == MS_A)
242 Ttb = 0;
243 if (Trb == MS_A)
244 Trb = 0;
245 if (Ttb == MS_B)
246 Ttb = 0;
247 if (Trb == MS_C)
248 Trb = 0;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200249
250 LOGP(DRLCMAC, LOGL_DEBUG, "- Rx=%d Tx=%d Sum Rx+Tx=%s Tta=%s Ttb=%d "
251 " Tra=%d Trb=%d Type=%d\n", Rx, Tx,
252 (Sum == MS_NA) ? "N/A" : digit[Sum],
253 (Tta == MS_NA) ? "N/A" : digit[Tta], Ttb, Tra, Trb, Type);
254
255 /* select the values for time contraints */
Holger Hans Peter Freyther11a74892013-09-29 08:13:42 +0200256 /* applicable to type 1 and type 2 */
257 Tt = Ttb;
258 Tr = Trb;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200259
260 /* select a window of Rx slots if available
261 * The maximum allowed slots depend on RX or the window of available
262 * slots.
263 * This must be done for uplink TBF also, because it is the basis
264 * for calculating control slot and uplink slot(s). */
265 for (ts = 0, i = 0; ts < 8; ts++) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200266 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200267 /* check if enabled */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200268 if (!pdch->is_enabled()) {
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200269 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, because "
270 "not enabled\n", ts);
271 /* increase window for Type 1 */
272 if (Type == 1 && rx_window)
273 i++;
274 continue;
275 }
276 /* check if TSC changes */
277 if (tsc < 0)
278 tbf->tsc = tsc = pdch->tsc;
279 else if (tsc != pdch->tsc) {
280 LOGP(DRLCMAC, LOGL_ERROR, "Skipping TS %d of TRX=%d, "
281 "because it has different TSC than lower TS "
282 "of TRX. In order to allow multislot, all "
283 "slots must be configured with the same "
Holger Hans Peter Freyther96efa702013-09-29 07:44:39 +0200284 "TSC!\n", ts, tbf->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200285 /* increase window for Type 1 */
286 if (Type == 1 && rx_window)
287 i++;
288 continue;
289 }
290
291 if (!rx_window)
292 rx_win_min = ts;
293
294 rx_window |= (1 << ts);
295 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected DL TS %d\n", ts);
296
297 /* range of window (required for Type 1) */
298 rx_win_max = ts;
299
300 if (++i == Rx) {
301 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because slots / "
302 "window reached maximum alowed Rx size\n");
303 break;
304 }
305 }
306
307 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected slots for RX: "
308 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
309 ((rx_window & 0x01)) ? 'D' : '.',
310 ((rx_window & 0x02)) ? 'D' : '.',
311 ((rx_window & 0x04)) ? 'D' : '.',
312 ((rx_window & 0x08)) ? 'D' : '.',
313 ((rx_window & 0x10)) ? 'D' : '.',
314 ((rx_window & 0x20)) ? 'D' : '.',
315 ((rx_window & 0x40)) ? 'D' : '.',
316 ((rx_window & 0x80)) ? 'D' : '.');
317
318 /* reduce window, if existing uplink slots collide RX window */
319 if (Type == 1 && old_tbf && old_tbf->direction == GPRS_RLCMAC_UL_TBF) {
320 uint8_t collide = 0, ul_usage = 0;
321 int j;
322
323 /* calculate mask of colliding slots */
324 for (ts = 0; ts < 8; ts++) {
325 if (old_tbf->pdch[ts]) {
326 ul_usage |= (1 << ts);
327 /* mark bits from TS-t .. TS+r */
328 for (j = ts - Tt; j != ((ts + Tr + 1) & 7);
329 j = (j + 1) & 7)
330 collide |= (1 << j);
331 }
332 }
333 LOGP(DRLCMAC, LOGL_DEBUG, "- Not allowed slots due to existing "
334 "UL allocation: (TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7) "
335 " D=downlink x=not usable\n",
336 ((ul_usage & 0x01)) ? 'D' : ((collide & 0x01))?'x':'.',
337 ((ul_usage & 0x02)) ? 'D' : ((collide & 0x02))?'x':'.',
338 ((ul_usage & 0x04)) ? 'D' : ((collide & 0x04))?'x':'.',
339 ((ul_usage & 0x08)) ? 'D' : ((collide & 0x08))?'x':'.',
340 ((ul_usage & 0x10)) ? 'D' : ((collide & 0x10))?'x':'.',
341 ((ul_usage & 0x20)) ? 'D' : ((collide & 0x20))?'x':'.',
342 ((ul_usage & 0x40)) ? 'D' : ((collide & 0x40))?'x':'.',
343 ((ul_usage & 0x80)) ? 'D' : ((collide & 0x80))?'x':'.');
344
345 /* apply mask to reduce tx_window (shifted by 3 slots) */
346 rx_window &= ~(collide << 3);
347 rx_window &= ~(collide >> 5);
348 LOGP(DRLCMAC, LOGL_DEBUG, "- Remaining slots for RX: "
349 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
350 ((rx_window & 0x01)) ? 'D' : '.',
351 ((rx_window & 0x02)) ? 'D' : '.',
352 ((rx_window & 0x04)) ? 'D' : '.',
353 ((rx_window & 0x08)) ? 'D' : '.',
354 ((rx_window & 0x10)) ? 'D' : '.',
355 ((rx_window & 0x20)) ? 'D' : '.',
356 ((rx_window & 0x40)) ? 'D' : '.',
357 ((rx_window & 0x80)) ? 'D' : '.');
358 if (!rx_window) {
359 LOGP(DRLCMAC, LOGL_NOTICE, "No suitable downlink slots "
360 "available with current uplink assignment\n");
361 return -EBUSY;
362 }
363
364 /* calculate new min/max */
365 for (ts = rx_win_min; ts <= rx_win_max; ts++) {
366 if ((rx_window & (1 << ts)))
367 break;
368 rx_win_min = ts + 1;
369 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
370 "raising start of DL window to %d\n",
371 rx_win_min);
372 }
373 for (ts = rx_win_max; ts >= rx_win_min; ts--) {
374 if ((rx_window & (1 << ts)))
375 break;
376 rx_win_max = ts - 1;
377 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
378 "lowering end of DL window to %d\n",
379 rx_win_max);
380 }
381 }
382
383 /* reduce window, to allow at least one uplink TX slot
384 * this is only required for Type 1 */
385 if (Type == 1 && rx_win_max - rx_win_min + 1 + Tt + 1 + Tr > 8) {
386 rx_win_max = rx_win_min + 7 - Tt - 1 - Tr;
387 LOGP(DRLCMAC, LOGL_DEBUG, "- Reduce RX window due to time "
388 "contraints to %d slots\n",
389 rx_win_max - rx_win_min + 1);
390 }
391
392 LOGP(DRLCMAC, LOGL_DEBUG, "- RX-Window is: %d..%d\n", rx_win_min,
393 rx_win_max);
394
395 /* calculate TX window */
396 if (Type == 1) {
397 /* calculate TX window (shifted by 3 timeslots)
398 * it uses the space between tx_win_max and tx_win_min */
399 tx_win_min = (rx_win_max - 2 + Tt) & 7;
400 tx_win_max = (rx_win_min + 4 - Tr) & 7;
401 /* calculate the TX window size (might be larger than Tx) */
402 tx_range = (tx_win_max - tx_win_min + 1) & 7;
403 } else {
404 /* TX and RX simultaniously */
405 tx_win_min = rx_win_min;
406 tx_win_max = 7;
407 /* TX window size (might be larger than Tx) */
408 tx_range = tx_win_max - tx_win_min + 1;
409 }
410
411 LOGP(DRLCMAC, LOGL_DEBUG, "- TX-Window is: %d..%d\n", tx_win_min,
412 tx_win_max);
413
414 /* select a window of Tx slots if available
415 * The maximum allowed slots depend on TX or the window of available
416 * slots.
417 *
418 * also assign the first common ts, which is used for control or single
419 * slot. */
420 if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
421 for (ts = tx_win_min, i = 0; i < tx_range; ts = (ts + 1) & 7) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200422 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200423 /* check if enabled */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200424 if (!pdch->is_enabled()) {
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200425 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
426 "because not enabled\n", ts);
427 continue;
428 }
429 /* check if TSC changes */
430 if (tsc < 0)
431 tbf->tsc = tsc = pdch->tsc;
432 else if (tsc != pdch->tsc) {
433 LOGP(DRLCMAC, LOGL_ERROR, "Skipping TS %d of "
434 "TRX=%d, because it has different TSC "
435 "than lower TS of TRX. In order to "
436 "allow multislot, all slots must be "
437 "configured with the same TSC!\n",
Holger Hans Peter Freyther96efa702013-09-29 07:44:39 +0200438 ts, tbf->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200439 /* increase window for Type 1 */
440 if (Type == 1)
441 i++;
442 continue;
443 }
444 /* check for free usf */
445 usf[ts] = find_free_usf(pdch, ts);
446 if (usf[ts] < 0) {
447 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
448 "because no USF available\n", ts);
449 /* increase window for Type 1 */
450 if (Type == 1)
451 i++;
452 continue;
453 }
454
455 if (!tx_window)
456 first_common_ts = ts;
457
458 tx_window |= (1 << ts);
459 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected UL TS %d\n", ts);
460
461 if (1 && Type == 1) { /* FIXME: multislot UL assignment */
462 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because "
463 "1 slot assigned\n");
464 break;
465 }
466 if (++i == Tx) {
467 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because "
468 "slots / window reached maximum "
469 "allowed Tx size\n");
470 break;
471 }
472 }
473
474 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected TX window: "
475 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
476 ((tx_window & 0x01)) ? 'U' : '.',
477 ((tx_window & 0x02)) ? 'U' : '.',
478 ((tx_window & 0x04)) ? 'U' : '.',
479 ((tx_window & 0x08)) ? 'U' : '.',
480 ((tx_window & 0x10)) ? 'U' : '.',
481 ((tx_window & 0x20)) ? 'U' : '.',
482 ((tx_window & 0x40)) ? 'U' : '.',
483 ((tx_window & 0x80)) ? 'U' : '.');
484
485 if (!tx_window) {
486 LOGP(DRLCMAC, LOGL_NOTICE, "No suitable uplink slots "
487 "available\n");
488 return -EBUSY;
489 }
490 } else {
491 /* assign the first common ts, which is used for control or
492 * single slot. */
493 for (ts = tx_win_min, i = 0; i < tx_range; ts = (ts + 1) & 7) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200494 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200495 /* check if enabled */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200496 if (!pdch->is_enabled()) {
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200497 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
498 "because not enabled\n", ts);
499 continue;
500 }
501 first_common_ts = ts;
502 break;
503 }
504 }
505
506 if (first_common_ts < 0) {
507 LOGP(DRLCMAC, LOGL_NOTICE, "No first common slots available\n");
508 return -EINVAL;
509 }
510
511 if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
512 /* assign downlink */
513 if (rx_window == 0) {
514 LOGP(DRLCMAC, LOGL_NOTICE, "No downlink slots "
515 "available\n");
516 return -EINVAL;
517 }
518 for (ts = 0; ts < 8; ts++) {
519 if ((rx_window & (1 << ts))) {
520 /* be sure to select a single downlink slots
521 * that can be used for uplink, if multiple
522 * slots are assigned later. */
523 if (single && first_common_ts != ts)
524 continue;
525 LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS "
526 "%d\n", ts);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200527 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200528 assign_dlink_tbf(pdch, ts, tbf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200529 slotcount++;
530 if (slotcount == 1)
531 tbf->first_ts = ts;
532 if (single)
533 break;
534 }
535 }
536 } else {
537 /* assign uplink */
538 if (tx_window == 0) {
539 LOGP(DRLCMAC, LOGL_NOTICE, "No uplink slots "
540 "available\n");
541 return -EINVAL;
542 }
543 for (ts = 0; ts < 8; ts++) {
544 if ((tx_window & (1 << ts))) {
545 LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS "
546 "%d\n", ts);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200547 pdch = &tbf->trx->pdch[ts];
548 assign_uplink_tbf_usf(pdch, ts, tbf, usf[ts]);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200549 slotcount++;
550 if (slotcount == 1)
551 tbf->first_ts = ts;
552 if (single)
553 break;
554 }
555 }
556 }
557 if (single && slotcount) {
558 LOGP(DRLCMAC, LOGL_INFO, "Using single slot at TS %d for %s\n",
559 tbf->first_ts,
560 (tbf->direction == GPRS_RLCMAC_DL_TBF) ? "DL" : "UL");
561 } else {
562 LOGP(DRLCMAC, LOGL_INFO, "Using %d slots for %s\n", slotcount,
563 (tbf->direction == GPRS_RLCMAC_DL_TBF) ? "DL" : "UL");
564 }
565 if (slotcount == 0)
566 return -EBUSY;
567
568 tbf->first_common_ts = first_common_ts;
569
570 return 0;
571}