blob: 5bfc18f23ef7f2786d51d04b00288ef94505b748 [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>
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020024#include <bts.h>
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +020025#include <tbf.h>
26
27#include <errno.h>
28
29/* 3GPP TS 05.02 Annex B.1 */
30
31#define MS_NA 255 /* N/A */
32#define MS_A 254 /* 1 with hopping, 0 without */
33#define MS_B 253 /* 1 with hopping, 0 without (change Rx to Tx)*/
34#define MS_C 252 /* 1 with hopping, 0 without (change Tx to Rx)*/
35
36struct gprs_ms_multislot_class {
37 uint8_t rx, tx, sum; /* Maximum Number of Slots: RX, Tx, Sum Rx+Tx */
38 uint8_t ta, tb, ra, rb; /* Minimum Number of Slots */
39 uint8_t type; /* Type of Mobile */
40};
41
42static const struct gprs_ms_multislot_class gprs_ms_multislot_class[32] = {
43/* M-S Class Rx Tx Sum Tta Ttb Tra Trb Type */
44/* N/A */ { MS_NA,MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA },
45/* 1 */ { 1, 1, 2, 3, 2, 4, 2, 1 },
46/* 2 */ { 2, 1, 3, 3, 2, 3, 1, 1 },
47/* 3 */ { 2, 2, 3, 3, 2, 3, 1, 1 },
48/* 4 */ { 3, 1, 4, 3, 1, 3, 1, 1 },
49/* 5 */ { 2, 2, 4, 3, 1, 3, 1, 1 },
50/* 6 */ { 3, 2, 4, 3, 1, 3, 1, 1 },
51/* 7 */ { 3, 3, 4, 3, 1, 3, 1, 1 },
52/* 8 */ { 4, 1, 5, 3, 1, 2, 1, 1 },
53/* 9 */ { 3, 2, 5, 3, 1, 2, 1, 1 },
54/* 10 */ { 4, 2, 5, 3, 1, 2, 1, 1 },
55/* 11 */ { 4, 3, 5, 3, 1, 2, 1, 1 },
56/* 12 */ { 4, 4, 5, 2, 1, 2, 1, 1 },
57/* 13 */ { 3, 3, MS_NA, MS_NA, MS_A, 3, MS_A, 2 },
58/* 14 */ { 4, 4, MS_NA, MS_NA, MS_A, 3, MS_A, 2 },
59/* 15 */ { 5, 5, MS_NA, MS_NA, MS_A, 3, MS_A, 2 },
60/* 16 */ { 6, 6, MS_NA, MS_NA, MS_A, 2, MS_A, 2 },
61/* 17 */ { 7, 7, MS_NA, MS_NA, MS_A, 1, 0, 2 },
62/* 18 */ { 8, 8, MS_NA, MS_NA, 0, 0, 0, 2 },
63/* 19 */ { 6, 2, MS_NA, 3, MS_B, 2, MS_C, 1 },
64/* 20 */ { 6, 3, MS_NA, 3, MS_B, 2, MS_C, 1 },
65/* 21 */ { 6, 4, MS_NA, 3, MS_B, 2, MS_C, 1 },
66/* 22 */ { 6, 4, MS_NA, 2, MS_B, 2, MS_C, 1 },
67/* 23 */ { 6, 6, MS_NA, 2, MS_B, 2, MS_C, 1 },
68/* 24 */ { 8, 2, MS_NA, 3, MS_B, 2, MS_C, 1 },
69/* 25 */ { 8, 3, MS_NA, 3, MS_B, 2, MS_C, 1 },
70/* 26 */ { 8, 4, MS_NA, 3, MS_B, 2, MS_C, 1 },
71/* 27 */ { 8, 4, MS_NA, 2, MS_B, 2, MS_C, 1 },
72/* 28 */ { 8, 6, MS_NA, 2, MS_B, 2, MS_C, 1 },
73/* 29 */ { 8, 8, MS_NA, 2, MS_B, 2, MS_C, 1 },
74/* N/A */ { MS_NA,MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA },
75/* N/A */ { MS_NA,MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA, MS_NA },
76};
77
78static inline int8_t find_free_usf(struct gprs_rlcmac_pdch *pdch, uint8_t ts)
79{
80 struct gprs_rlcmac_tbf *tbf;
81 uint8_t usf_map = 0;
82 uint8_t tfi, usf;
83
84 /* make map of used USF */
85 for (tfi = 0; tfi < 32; tfi++) {
86 tbf = pdch->ul_tbf[tfi];
87 if (!tbf)
88 continue;
89 usf_map |= (1 << tbf->dir.ul.usf[ts]);
90 }
91
92 /* look for USF, don't use USF=7 */
93 for (usf = 0; usf < 7; usf++) {
94 if (!(usf_map & (1 << usf)))
95 return usf;
96 }
97
98 return -1;
99}
100
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200101static int find_enabled_pdch(struct gprs_rlcmac_trx *trx, const uint8_t start_ts)
102{
103 int ts;
104 for (ts = start_ts; ts < 8; ts++) {
105 struct gprs_rlcmac_pdch *pdch;
106
107 pdch = &trx->pdch[ts];
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200108 if (!pdch->is_enabled()) {
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200109 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, because "
110 "not enabled\n", ts);
111 continue;
112 }
113 return ts;
114 }
115
116 return 8;
117}
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200118
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200119static void assign_uplink_tbf_usf(
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200120 struct gprs_rlcmac_pdch *pdch,
121 int ts,
122 struct gprs_rlcmac_tbf *tbf, int8_t usf)
123{
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200124 tbf->trx->ul_tbf[tbf->tfi] = tbf;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200125 pdch->ul_tbf[tbf->tfi] = tbf;
126 tbf->pdch[ts] = pdch;
127 tbf->dir.ul.usf[ts] = usf;
128}
129
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200130static void assign_dlink_tbf(
131 struct gprs_rlcmac_pdch *pdch,
132 int ts,
133 struct gprs_rlcmac_tbf *tbf)
134{
135 tbf->trx->dl_tbf[tbf->tfi] = tbf;
136 pdch->dl_tbf[tbf->tfi] = tbf;
137 tbf->pdch[ts] = pdch;
138}
139
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200140
141/* Slot Allocation: Algorithm A
142 *
143 * Assign single slot for uplink and downlink
144 */
145int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
146 struct gprs_rlcmac_tbf *old_tbf,
147 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
148{
149 struct gprs_rlcmac_pdch *pdch;
150 uint8_t ts;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200151
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) {
Holger Hans Peter Freyther948a3d62013-09-30 14:10:23 +0200162 int8_t usf; /* must be signed */
163
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200164 /* if USF available */
165 usf = find_free_usf(pdch, ts);
166 if (usf < 0) {
167 LOGP(DRLCMAC, LOGL_NOTICE, "- Failed "
168 "allocating TS=%d, no USF available\n", ts);
169 return -EBUSY;
170 }
171 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign uplink "
172 "TS=%d USF=%d\n", ts, usf);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200173 assign_uplink_tbf_usf(pdch, ts, tbf, usf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200174 } else {
175 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign downlink TS=%d\n", ts);
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200176 assign_dlink_tbf(pdch, ts, tbf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200177 }
178 /* the only one TS is the common TS */
179 tbf->first_ts = tbf->first_common_ts = ts;
180
181 return 0;
182}
183
184/* Slot Allocation: Algorithm B
185 *
186 * Assign as many downlink slots as possible.
187 * Assign one uplink slot. (With free USF)
188 *
189 */
190int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
191 struct gprs_rlcmac_tbf *old_tbf,
192 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
193{
194 struct gprs_rlcmac_pdch *pdch;
195 const struct gprs_ms_multislot_class *ms_class;
196 uint8_t Rx, Tx, Sum; /* Maximum Number of Slots: RX, Tx, Sum Rx+Tx */
197 uint8_t Tta, Ttb, Tra, Trb, Tt, Tr; /* Minimum Number of Slots */
198 uint8_t Type; /* Type of Mobile */
199 uint8_t rx_win_min = 0, rx_win_max = 7;
200 uint8_t tx_win_min, tx_win_max, tx_range;
201 uint8_t rx_window = 0, tx_window = 0;
202 static const char *digit[10] = { "0","1","2","3","4","5","6","7","8","9" };
203 int8_t usf[8] = { -1, -1, -1, -1, -1, -1, -1, -1 }; /* must be signed */
204 int8_t tsc = -1; /* must be signed */
205 int8_t first_common_ts = -1;
206 uint8_t i, ts;
207 uint8_t slotcount = 0;
208
209
210 if (tbf->ms_class >= 32) {
211 LOGP(DRLCMAC, LOGL_ERROR, "Multislot class %d out of range.\n",
212 tbf->ms_class);
213 return -EINVAL;
214 }
215
216 if (tbf->ms_class) {
217 ms_class = &gprs_ms_multislot_class[tbf->ms_class];
218 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
219 "class %d\n", tbf->ms_class);
220 } else {
221 ms_class = &gprs_ms_multislot_class[12];
222 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
223 "unknow class (assuming 12)\n");
224 }
225
226 if (ms_class->tx == MS_NA) {
227 LOGP(DRLCMAC, LOGL_NOTICE, "Multislot class %d not "
228 "applicable.\n", tbf->ms_class);
229 return -EINVAL;
230 }
231
232 Rx = ms_class->rx;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200233 Tx = ms_class->tx;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200234 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 */
Holger Hans Peter Freyther11a74892013-09-29 08:13:42 +0200242 if (Ttb == MS_A)
243 Ttb = 0;
244 if (Trb == MS_A)
245 Trb = 0;
246 if (Ttb == MS_B)
247 Ttb = 0;
248 if (Trb == MS_C)
249 Trb = 0;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200250
251 LOGP(DRLCMAC, LOGL_DEBUG, "- Rx=%d Tx=%d Sum Rx+Tx=%s Tta=%s Ttb=%d "
252 " Tra=%d Trb=%d Type=%d\n", Rx, Tx,
253 (Sum == MS_NA) ? "N/A" : digit[Sum],
254 (Tta == MS_NA) ? "N/A" : digit[Tta], Ttb, Tra, Trb, Type);
255
256 /* select the values for time contraints */
Holger Hans Peter Freyther11a74892013-09-29 08:13:42 +0200257 /* applicable to type 1 and type 2 */
258 Tt = Ttb;
259 Tr = Trb;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200260
261 /* select a window of Rx slots if available
262 * The maximum allowed slots depend on RX or the window of available
263 * slots.
264 * This must be done for uplink TBF also, because it is the basis
265 * for calculating control slot and uplink slot(s). */
266 for (ts = 0, i = 0; ts < 8; ts++) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200267 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200268 /* check if enabled */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200269 if (!pdch->is_enabled()) {
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200270 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, because "
271 "not enabled\n", ts);
272 /* increase window for Type 1 */
273 if (Type == 1 && rx_window)
274 i++;
275 continue;
276 }
277 /* check if TSC changes */
278 if (tsc < 0)
279 tbf->tsc = tsc = pdch->tsc;
280 else if (tsc != pdch->tsc) {
281 LOGP(DRLCMAC, LOGL_ERROR, "Skipping TS %d of TRX=%d, "
282 "because it has different TSC than lower TS "
283 "of TRX. In order to allow multislot, all "
284 "slots must be configured with the same "
Holger Hans Peter Freyther96efa702013-09-29 07:44:39 +0200285 "TSC!\n", ts, tbf->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200286 /* increase window for Type 1 */
287 if (Type == 1 && rx_window)
288 i++;
289 continue;
290 }
291
292 if (!rx_window)
293 rx_win_min = ts;
294
295 rx_window |= (1 << ts);
296 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected DL TS %d\n", ts);
297
298 /* range of window (required for Type 1) */
299 rx_win_max = ts;
300
301 if (++i == Rx) {
302 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because slots / "
303 "window reached maximum alowed Rx size\n");
304 break;
305 }
306 }
307
308 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected slots for RX: "
309 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
310 ((rx_window & 0x01)) ? 'D' : '.',
311 ((rx_window & 0x02)) ? 'D' : '.',
312 ((rx_window & 0x04)) ? 'D' : '.',
313 ((rx_window & 0x08)) ? 'D' : '.',
314 ((rx_window & 0x10)) ? 'D' : '.',
315 ((rx_window & 0x20)) ? 'D' : '.',
316 ((rx_window & 0x40)) ? 'D' : '.',
317 ((rx_window & 0x80)) ? 'D' : '.');
318
319 /* reduce window, if existing uplink slots collide RX window */
320 if (Type == 1 && old_tbf && old_tbf->direction == GPRS_RLCMAC_UL_TBF) {
321 uint8_t collide = 0, ul_usage = 0;
322 int j;
323
324 /* calculate mask of colliding slots */
325 for (ts = 0; ts < 8; ts++) {
326 if (old_tbf->pdch[ts]) {
327 ul_usage |= (1 << ts);
328 /* mark bits from TS-t .. TS+r */
329 for (j = ts - Tt; j != ((ts + Tr + 1) & 7);
330 j = (j + 1) & 7)
331 collide |= (1 << j);
332 }
333 }
334 LOGP(DRLCMAC, LOGL_DEBUG, "- Not allowed slots due to existing "
335 "UL allocation: (TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7) "
336 " D=downlink x=not usable\n",
337 ((ul_usage & 0x01)) ? 'D' : ((collide & 0x01))?'x':'.',
338 ((ul_usage & 0x02)) ? 'D' : ((collide & 0x02))?'x':'.',
339 ((ul_usage & 0x04)) ? 'D' : ((collide & 0x04))?'x':'.',
340 ((ul_usage & 0x08)) ? 'D' : ((collide & 0x08))?'x':'.',
341 ((ul_usage & 0x10)) ? 'D' : ((collide & 0x10))?'x':'.',
342 ((ul_usage & 0x20)) ? 'D' : ((collide & 0x20))?'x':'.',
343 ((ul_usage & 0x40)) ? 'D' : ((collide & 0x40))?'x':'.',
344 ((ul_usage & 0x80)) ? 'D' : ((collide & 0x80))?'x':'.');
345
346 /* apply mask to reduce tx_window (shifted by 3 slots) */
347 rx_window &= ~(collide << 3);
348 rx_window &= ~(collide >> 5);
349 LOGP(DRLCMAC, LOGL_DEBUG, "- Remaining slots for RX: "
350 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
351 ((rx_window & 0x01)) ? 'D' : '.',
352 ((rx_window & 0x02)) ? 'D' : '.',
353 ((rx_window & 0x04)) ? 'D' : '.',
354 ((rx_window & 0x08)) ? 'D' : '.',
355 ((rx_window & 0x10)) ? 'D' : '.',
356 ((rx_window & 0x20)) ? 'D' : '.',
357 ((rx_window & 0x40)) ? 'D' : '.',
358 ((rx_window & 0x80)) ? 'D' : '.');
359 if (!rx_window) {
360 LOGP(DRLCMAC, LOGL_NOTICE, "No suitable downlink slots "
361 "available with current uplink assignment\n");
362 return -EBUSY;
363 }
364
365 /* calculate new min/max */
366 for (ts = rx_win_min; ts <= rx_win_max; ts++) {
367 if ((rx_window & (1 << ts)))
368 break;
369 rx_win_min = ts + 1;
370 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
371 "raising start of DL window to %d\n",
372 rx_win_min);
373 }
374 for (ts = rx_win_max; ts >= rx_win_min; ts--) {
375 if ((rx_window & (1 << ts)))
376 break;
377 rx_win_max = ts - 1;
378 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
379 "lowering end of DL window to %d\n",
380 rx_win_max);
381 }
382 }
383
384 /* reduce window, to allow at least one uplink TX slot
385 * this is only required for Type 1 */
386 if (Type == 1 && rx_win_max - rx_win_min + 1 + Tt + 1 + Tr > 8) {
387 rx_win_max = rx_win_min + 7 - Tt - 1 - Tr;
388 LOGP(DRLCMAC, LOGL_DEBUG, "- Reduce RX window due to time "
389 "contraints to %d slots\n",
390 rx_win_max - rx_win_min + 1);
391 }
392
393 LOGP(DRLCMAC, LOGL_DEBUG, "- RX-Window is: %d..%d\n", rx_win_min,
394 rx_win_max);
395
396 /* calculate TX window */
397 if (Type == 1) {
398 /* calculate TX window (shifted by 3 timeslots)
399 * it uses the space between tx_win_max and tx_win_min */
400 tx_win_min = (rx_win_max - 2 + Tt) & 7;
401 tx_win_max = (rx_win_min + 4 - Tr) & 7;
402 /* calculate the TX window size (might be larger than Tx) */
403 tx_range = (tx_win_max - tx_win_min + 1) & 7;
404 } else {
405 /* TX and RX simultaniously */
406 tx_win_min = rx_win_min;
407 tx_win_max = 7;
408 /* TX window size (might be larger than Tx) */
409 tx_range = tx_win_max - tx_win_min + 1;
410 }
411
412 LOGP(DRLCMAC, LOGL_DEBUG, "- TX-Window is: %d..%d\n", tx_win_min,
413 tx_win_max);
414
415 /* select a window of Tx slots if available
416 * The maximum allowed slots depend on TX or the window of available
417 * slots.
418 *
419 * also assign the first common ts, which is used for control or single
420 * slot. */
421 if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
422 for (ts = tx_win_min, i = 0; i < tx_range; ts = (ts + 1) & 7) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200423 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200424 /* check if enabled */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200425 if (!pdch->is_enabled()) {
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200426 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
427 "because not enabled\n", ts);
428 continue;
429 }
430 /* check if TSC changes */
431 if (tsc < 0)
432 tbf->tsc = tsc = pdch->tsc;
433 else if (tsc != pdch->tsc) {
434 LOGP(DRLCMAC, LOGL_ERROR, "Skipping TS %d of "
435 "TRX=%d, because it has different TSC "
436 "than lower TS of TRX. In order to "
437 "allow multislot, all slots must be "
438 "configured with the same TSC!\n",
Holger Hans Peter Freyther96efa702013-09-29 07:44:39 +0200439 ts, tbf->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200440 /* increase window for Type 1 */
441 if (Type == 1)
442 i++;
443 continue;
444 }
445 /* check for free usf */
446 usf[ts] = find_free_usf(pdch, ts);
447 if (usf[ts] < 0) {
448 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
449 "because no USF available\n", ts);
450 /* increase window for Type 1 */
451 if (Type == 1)
452 i++;
453 continue;
454 }
455
456 if (!tx_window)
457 first_common_ts = ts;
458
459 tx_window |= (1 << ts);
460 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected UL TS %d\n", ts);
461
462 if (1 && Type == 1) { /* FIXME: multislot UL assignment */
463 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because "
464 "1 slot assigned\n");
465 break;
466 }
467 if (++i == Tx) {
468 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because "
469 "slots / window reached maximum "
470 "allowed Tx size\n");
471 break;
472 }
473 }
474
475 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected TX window: "
476 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
477 ((tx_window & 0x01)) ? 'U' : '.',
478 ((tx_window & 0x02)) ? 'U' : '.',
479 ((tx_window & 0x04)) ? 'U' : '.',
480 ((tx_window & 0x08)) ? 'U' : '.',
481 ((tx_window & 0x10)) ? 'U' : '.',
482 ((tx_window & 0x20)) ? 'U' : '.',
483 ((tx_window & 0x40)) ? 'U' : '.',
484 ((tx_window & 0x80)) ? 'U' : '.');
485
486 if (!tx_window) {
487 LOGP(DRLCMAC, LOGL_NOTICE, "No suitable uplink slots "
488 "available\n");
489 return -EBUSY;
490 }
491 } else {
492 /* assign the first common ts, which is used for control or
493 * single slot. */
494 for (ts = tx_win_min, i = 0; i < tx_range; ts = (ts + 1) & 7) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200495 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200496 /* check if enabled */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200497 if (!pdch->is_enabled()) {
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200498 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
499 "because not enabled\n", ts);
500 continue;
501 }
502 first_common_ts = ts;
503 break;
504 }
505 }
506
507 if (first_common_ts < 0) {
508 LOGP(DRLCMAC, LOGL_NOTICE, "No first common slots available\n");
509 return -EINVAL;
510 }
511
512 if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
513 /* assign downlink */
514 if (rx_window == 0) {
515 LOGP(DRLCMAC, LOGL_NOTICE, "No downlink slots "
516 "available\n");
517 return -EINVAL;
518 }
519 for (ts = 0; ts < 8; ts++) {
520 if ((rx_window & (1 << ts))) {
521 /* be sure to select a single downlink slots
522 * that can be used for uplink, if multiple
523 * slots are assigned later. */
524 if (single && first_common_ts != ts)
525 continue;
526 LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS "
527 "%d\n", ts);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200528 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200529 assign_dlink_tbf(pdch, ts, tbf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200530 slotcount++;
531 if (slotcount == 1)
532 tbf->first_ts = ts;
533 if (single)
534 break;
535 }
536 }
537 } else {
538 /* assign uplink */
539 if (tx_window == 0) {
540 LOGP(DRLCMAC, LOGL_NOTICE, "No uplink slots "
541 "available\n");
542 return -EINVAL;
543 }
544 for (ts = 0; ts < 8; ts++) {
545 if ((tx_window & (1 << ts))) {
546 LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS "
547 "%d\n", ts);
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200548 pdch = &tbf->trx->pdch[ts];
549 assign_uplink_tbf_usf(pdch, ts, tbf, usf[ts]);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200550 slotcount++;
551 if (slotcount == 1)
552 tbf->first_ts = ts;
553 if (single)
554 break;
555 }
556 }
557 }
558 if (single && slotcount) {
559 LOGP(DRLCMAC, LOGL_INFO, "Using single slot at TS %d for %s\n",
560 tbf->first_ts,
561 (tbf->direction == GPRS_RLCMAC_DL_TBF) ? "DL" : "UL");
562 } else {
563 LOGP(DRLCMAC, LOGL_INFO, "Using %d slots for %s\n", slotcount,
564 (tbf->direction == GPRS_RLCMAC_DL_TBF) ? "DL" : "UL");
565 }
566 if (slotcount == 0)
567 return -EBUSY;
568
569 tbf->first_common_ts = first_common_ts;
570
571 return 0;
572}