blob: f48d8d4ffe1f2eb46aa21c5cc2ecc31e70566697 [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
Holger Hans Peter Freyther6796ed22013-10-20 16:45:10 +020078static inline int8_t find_free_usf(struct gprs_rlcmac_pdch *pdch)
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +020079{
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;
Holger Hans Peter Freyther6796ed22013-10-20 16:45:10 +020089 usf_map |= (1 << tbf->dir.ul.usf[pdch->ts_no]);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +020090 }
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,
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200121 struct gprs_rlcmac_tbf *tbf, int8_t usf)
122{
Holger Hans Peter Freyther34f6e5e2013-10-27 20:31:47 +0100123 tbf->trx->ul_tbf[tbf->tfi()] = tbf;
124 pdch->ul_tbf[tbf->tfi()] = tbf;
Holger Hans Peter Freyther6796ed22013-10-20 16:45:10 +0200125 tbf->pdch[pdch->ts_no] = pdch;
126 tbf->dir.ul.usf[pdch->ts_no] = usf;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200127}
128
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200129static void assign_dlink_tbf(
130 struct gprs_rlcmac_pdch *pdch,
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200131 struct gprs_rlcmac_tbf *tbf)
132{
Holger Hans Peter Freyther34f6e5e2013-10-27 20:31:47 +0100133 tbf->trx->dl_tbf[tbf->tfi()] = tbf;
134 pdch->dl_tbf[tbf->tfi()] = tbf;
Holger Hans Peter Freyther6796ed22013-10-20 16:45:10 +0200135 tbf->pdch[pdch->ts_no] = pdch;
Holger Hans Peter Freyther8481a052013-09-29 08:08:28 +0200136}
137
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200138
139/* Slot Allocation: Algorithm A
140 *
141 * Assign single slot for uplink and downlink
142 */
143int alloc_algorithm_a(struct gprs_rlcmac_bts *bts,
144 struct gprs_rlcmac_tbf *old_tbf,
145 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
146{
147 struct gprs_rlcmac_pdch *pdch;
148 uint8_t ts;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200149
150 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm A) for class "
151 "%d\n", tbf->ms_class);
152
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200153 ts = find_enabled_pdch(tbf->trx, 0);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200154 if (ts == 8)
155 return -EINVAL;
156
Holger Hans Peter Freytherb0a00752013-09-29 08:18:17 +0200157 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200158 if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
Holger Hans Peter Freyther948a3d62013-09-30 14:10:23 +0200159 int8_t usf; /* must be signed */
160
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200161 /* if USF available */
Holger Hans Peter Freyther6796ed22013-10-20 16:45:10 +0200162 usf = find_free_usf(pdch);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200163 if (usf < 0) {
164 LOGP(DRLCMAC, LOGL_NOTICE, "- Failed "
165 "allocating TS=%d, no USF available\n", ts);
166 return -EBUSY;
167 }
168 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign uplink "
169 "TS=%d USF=%d\n", ts, usf);
Holger Hans Peter Freyther6796ed22013-10-20 16:45:10 +0200170 assign_uplink_tbf_usf(pdch, tbf, usf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200171 } else {
172 LOGP(DRLCMAC, LOGL_DEBUG, "- Assign downlink TS=%d\n", ts);
Holger Hans Peter Freyther6796ed22013-10-20 16:45:10 +0200173 assign_dlink_tbf(pdch, tbf);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200174 }
175 /* the only one TS is the common TS */
176 tbf->first_ts = tbf->first_common_ts = ts;
177
178 return 0;
179}
180
181/* Slot Allocation: Algorithm B
182 *
183 * Assign as many downlink slots as possible.
184 * Assign one uplink slot. (With free USF)
185 *
186 */
187int alloc_algorithm_b(struct gprs_rlcmac_bts *bts,
188 struct gprs_rlcmac_tbf *old_tbf,
189 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single)
190{
191 struct gprs_rlcmac_pdch *pdch;
192 const struct gprs_ms_multislot_class *ms_class;
193 uint8_t Rx, Tx, Sum; /* Maximum Number of Slots: RX, Tx, Sum Rx+Tx */
194 uint8_t Tta, Ttb, Tra, Trb, Tt, Tr; /* Minimum Number of Slots */
195 uint8_t Type; /* Type of Mobile */
196 uint8_t rx_win_min = 0, rx_win_max = 7;
197 uint8_t tx_win_min, tx_win_max, tx_range;
198 uint8_t rx_window = 0, tx_window = 0;
199 static const char *digit[10] = { "0","1","2","3","4","5","6","7","8","9" };
200 int8_t usf[8] = { -1, -1, -1, -1, -1, -1, -1, -1 }; /* must be signed */
201 int8_t tsc = -1; /* must be signed */
202 int8_t first_common_ts = -1;
203 uint8_t i, ts;
204 uint8_t slotcount = 0;
205
206
207 if (tbf->ms_class >= 32) {
208 LOGP(DRLCMAC, LOGL_ERROR, "Multislot class %d out of range.\n",
209 tbf->ms_class);
210 return -EINVAL;
211 }
212
213 if (tbf->ms_class) {
214 ms_class = &gprs_ms_multislot_class[tbf->ms_class];
215 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
216 "class %d\n", tbf->ms_class);
217 } else {
218 ms_class = &gprs_ms_multislot_class[12];
219 LOGP(DRLCMAC, LOGL_DEBUG, "Slot Allocation (Algorithm B) for "
220 "unknow class (assuming 12)\n");
221 }
222
223 if (ms_class->tx == MS_NA) {
224 LOGP(DRLCMAC, LOGL_NOTICE, "Multislot class %d not "
225 "applicable.\n", tbf->ms_class);
226 return -EINVAL;
227 }
228
229 Rx = ms_class->rx;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200230 Tx = ms_class->tx;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200231 Sum = ms_class->sum;
232 Tta = ms_class->ta;
233 Ttb = ms_class->tb;
234 Tra = ms_class->ra;
235 Trb = ms_class->rb;
236 Type = ms_class->type;
237
238 /* Tta and Ttb may depend on hopping or frequency change */
Holger Hans Peter Freyther11a74892013-09-29 08:13:42 +0200239 if (Ttb == MS_A)
240 Ttb = 0;
241 if (Trb == MS_A)
242 Trb = 0;
243 if (Ttb == MS_B)
244 Ttb = 0;
245 if (Trb == MS_C)
246 Trb = 0;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200247
248 LOGP(DRLCMAC, LOGL_DEBUG, "- Rx=%d Tx=%d Sum Rx+Tx=%s Tta=%s Ttb=%d "
249 " Tra=%d Trb=%d Type=%d\n", Rx, Tx,
250 (Sum == MS_NA) ? "N/A" : digit[Sum],
251 (Tta == MS_NA) ? "N/A" : digit[Tta], Ttb, Tra, Trb, Type);
252
253 /* select the values for time contraints */
Holger Hans Peter Freyther11a74892013-09-29 08:13:42 +0200254 /* applicable to type 1 and type 2 */
255 Tt = Ttb;
256 Tr = Trb;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200257
258 /* select a window of Rx slots if available
259 * The maximum allowed slots depend on RX or the window of available
260 * slots.
261 * This must be done for uplink TBF also, because it is the basis
262 * for calculating control slot and uplink slot(s). */
263 for (ts = 0, i = 0; ts < 8; ts++) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200264 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200265 /* check if enabled */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200266 if (!pdch->is_enabled()) {
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200267 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, because "
268 "not enabled\n", ts);
269 /* increase window for Type 1 */
270 if (Type == 1 && rx_window)
271 i++;
272 continue;
273 }
274 /* check if TSC changes */
275 if (tsc < 0)
Holger Hans Peter Freyther8f399de2013-12-25 20:22:35 +0100276 tsc = pdch->tsc;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200277 else if (tsc != pdch->tsc) {
278 LOGP(DRLCMAC, LOGL_ERROR, "Skipping TS %d of TRX=%d, "
279 "because it has different TSC than lower TS "
280 "of TRX. In order to allow multislot, all "
281 "slots must be configured with the same "
Holger Hans Peter Freytherec80f822013-10-27 13:44:37 +0100282 "TSC!\n", ts, tbf->trx->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200283 /* increase window for Type 1 */
284 if (Type == 1 && rx_window)
285 i++;
286 continue;
287 }
288
289 if (!rx_window)
290 rx_win_min = ts;
291
292 rx_window |= (1 << ts);
293 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected DL TS %d\n", ts);
294
295 /* range of window (required for Type 1) */
296 rx_win_max = ts;
297
298 if (++i == Rx) {
299 LOGP(DRLCMAC, LOGL_DEBUG, "- Done, because slots / "
300 "window reached maximum alowed Rx size\n");
301 break;
302 }
303 }
304
305 LOGP(DRLCMAC, LOGL_DEBUG, "- Selected slots for RX: "
306 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
307 ((rx_window & 0x01)) ? 'D' : '.',
308 ((rx_window & 0x02)) ? 'D' : '.',
309 ((rx_window & 0x04)) ? 'D' : '.',
310 ((rx_window & 0x08)) ? 'D' : '.',
311 ((rx_window & 0x10)) ? 'D' : '.',
312 ((rx_window & 0x20)) ? 'D' : '.',
313 ((rx_window & 0x40)) ? 'D' : '.',
314 ((rx_window & 0x80)) ? 'D' : '.');
315
316 /* reduce window, if existing uplink slots collide RX window */
317 if (Type == 1 && old_tbf && old_tbf->direction == GPRS_RLCMAC_UL_TBF) {
318 uint8_t collide = 0, ul_usage = 0;
319 int j;
320
321 /* calculate mask of colliding slots */
322 for (ts = 0; ts < 8; ts++) {
323 if (old_tbf->pdch[ts]) {
324 ul_usage |= (1 << ts);
325 /* mark bits from TS-t .. TS+r */
326 for (j = ts - Tt; j != ((ts + Tr + 1) & 7);
327 j = (j + 1) & 7)
328 collide |= (1 << j);
329 }
330 }
331 LOGP(DRLCMAC, LOGL_DEBUG, "- Not allowed slots due to existing "
332 "UL allocation: (TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7) "
333 " D=downlink x=not usable\n",
334 ((ul_usage & 0x01)) ? 'D' : ((collide & 0x01))?'x':'.',
335 ((ul_usage & 0x02)) ? 'D' : ((collide & 0x02))?'x':'.',
336 ((ul_usage & 0x04)) ? 'D' : ((collide & 0x04))?'x':'.',
337 ((ul_usage & 0x08)) ? 'D' : ((collide & 0x08))?'x':'.',
338 ((ul_usage & 0x10)) ? 'D' : ((collide & 0x10))?'x':'.',
339 ((ul_usage & 0x20)) ? 'D' : ((collide & 0x20))?'x':'.',
340 ((ul_usage & 0x40)) ? 'D' : ((collide & 0x40))?'x':'.',
341 ((ul_usage & 0x80)) ? 'D' : ((collide & 0x80))?'x':'.');
342
343 /* apply mask to reduce tx_window (shifted by 3 slots) */
344 rx_window &= ~(collide << 3);
345 rx_window &= ~(collide >> 5);
346 LOGP(DRLCMAC, LOGL_DEBUG, "- Remaining slots for RX: "
347 "(TS=0)\"%c%c%c%c%c%c%c%c\"(TS=7)\n",
348 ((rx_window & 0x01)) ? 'D' : '.',
349 ((rx_window & 0x02)) ? 'D' : '.',
350 ((rx_window & 0x04)) ? 'D' : '.',
351 ((rx_window & 0x08)) ? 'D' : '.',
352 ((rx_window & 0x10)) ? 'D' : '.',
353 ((rx_window & 0x20)) ? 'D' : '.',
354 ((rx_window & 0x40)) ? 'D' : '.',
355 ((rx_window & 0x80)) ? 'D' : '.');
356 if (!rx_window) {
357 LOGP(DRLCMAC, LOGL_NOTICE, "No suitable downlink slots "
358 "available with current uplink assignment\n");
359 return -EBUSY;
360 }
361
362 /* calculate new min/max */
363 for (ts = rx_win_min; ts <= rx_win_max; ts++) {
364 if ((rx_window & (1 << ts)))
365 break;
366 rx_win_min = ts + 1;
367 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
368 "raising start of DL window to %d\n",
369 rx_win_min);
370 }
371 for (ts = rx_win_max; ts >= rx_win_min; ts--) {
372 if ((rx_window & (1 << ts)))
373 break;
374 rx_win_max = ts - 1;
375 LOGP(DRLCMAC, LOGL_DEBUG, "- TS has been deleted, so "
376 "lowering end of DL window to %d\n",
377 rx_win_max);
378 }
379 }
380
381 /* reduce window, to allow at least one uplink TX slot
382 * this is only required for Type 1 */
383 if (Type == 1 && rx_win_max - rx_win_min + 1 + Tt + 1 + Tr > 8) {
384 rx_win_max = rx_win_min + 7 - Tt - 1 - Tr;
385 LOGP(DRLCMAC, LOGL_DEBUG, "- Reduce RX window due to time "
386 "contraints to %d slots\n",
387 rx_win_max - rx_win_min + 1);
388 }
389
390 LOGP(DRLCMAC, LOGL_DEBUG, "- RX-Window is: %d..%d\n", rx_win_min,
391 rx_win_max);
392
393 /* calculate TX window */
394 if (Type == 1) {
395 /* calculate TX window (shifted by 3 timeslots)
396 * it uses the space between tx_win_max and tx_win_min */
397 tx_win_min = (rx_win_max - 2 + Tt) & 7;
398 tx_win_max = (rx_win_min + 4 - Tr) & 7;
399 /* calculate the TX window size (might be larger than Tx) */
400 tx_range = (tx_win_max - tx_win_min + 1) & 7;
401 } else {
402 /* TX and RX simultaniously */
403 tx_win_min = rx_win_min;
404 tx_win_max = 7;
405 /* TX window size (might be larger than Tx) */
406 tx_range = tx_win_max - tx_win_min + 1;
407 }
408
409 LOGP(DRLCMAC, LOGL_DEBUG, "- TX-Window is: %d..%d\n", tx_win_min,
410 tx_win_max);
411
412 /* select a window of Tx slots if available
413 * The maximum allowed slots depend on TX or the window of available
414 * slots.
415 *
416 * also assign the first common ts, which is used for control or single
417 * slot. */
418 if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
419 for (ts = tx_win_min, i = 0; i < tx_range; ts = (ts + 1) & 7) {
Holger Hans Peter Freyther743bafa2013-09-29 07:50:50 +0200420 pdch = &tbf->trx->pdch[ts];
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200421 /* check if enabled */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200422 if (!pdch->is_enabled()) {
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200423 LOGP(DRLCMAC, LOGL_DEBUG, "- Skipping TS %d, "
424 "because not enabled\n", ts);
Holger Hans Peter Freytherdf022f62013-12-25 20:24:16 +0100425 #warning "Why isn't it needed to increase the window?"
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200426 continue;
427 }
428 /* check if TSC changes */
429 if (tsc < 0)
Holger Hans Peter Freyther8f399de2013-12-25 20:22:35 +0100430 tsc = pdch->tsc;
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200431 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 Freytherec80f822013-10-27 13:44:37 +0100437 ts, tbf->trx->trx_no);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200438 /* increase window for Type 1 */
Holger Hans Peter Freytherdf022f62013-12-25 20:24:16 +0100439 #warning "Why isn't it needed to check for tx_window"
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200440 if (Type == 1)
441 i++;
442 continue;
443 }
444 /* check for free usf */
Holger Hans Peter Freyther6796ed22013-10-20 16:45:10 +0200445 usf[ts] = find_free_usf(pdch);
Holger Hans Peter Freyther02ab4a82013-09-29 07:37:40 +0200446 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 Freyther6796ed22013-10-20 16:45:10 +0200528 assign_dlink_tbf(pdch, 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];
Holger Hans Peter Freyther6796ed22013-10-20 16:45:10 +0200548 assign_uplink_tbf_usf(pdch, 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}