blob: 94c3c564d366233c739d86b3e747318dd4329cbc [file] [log] [blame]
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +01001/* sba.c
2 *
3 * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010015 */
16
17#include <sba.h>
18#include <gprs_debug.h>
19#include <bts.h>
20#include <pcu_utils.h>
21#include <pdch.h>
22#include <errno.h>
23
24#include <osmocom/core/logging.h>
25#include <osmocom/core/talloc.h>
26#include <osmocom/gsm/protocol/gsm_04_08.h>
27#include <osmocom/gsm/gsm_utils.h>
28
29#include "pdch.h"
30#include "pdch_ul_controller.h"
31
Pau Espin Pedrol54e64502021-03-26 20:44:48 +010032/* TBF Starting Time for assigning SBA.
33 * See TS 44.060 12.21 "Starting Frame Number Description".
34 * According to spec, k=0 (offset=4) "should not be used, so as to leave time
35 * for the MS to analyze the message and get ready to receive or transmit".
36 * Hence, k=1 (offset=8-9) is theoretically the minimum offset which could be
37 * used.
38 *
39 * However, it was found, empirically, that it takes around 30-40 FNs time for
40 * the Immediate Assignment message created with this "TBF Starting Time" to
41 * travel from PCU->BTS and be transmitted over CCCH on the Um interface. Hence,
42 * we must account for this delay here, otherwise the MS would be receiving eg.
43 * a TBF Starting Time of FN=40 while the Imm Assigned containing it is sent in
44 * eg. FN=50, which would be too late for the MS to answer to it.
45 *
46 * The situation described above, can even get worse on high BTS load for AGCH,
47 * since the Immediate Assignment will queue in the BTS waiting to be
48 * transmitted one after the other, hence increasing the required delay.
49 */
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010050#define AGCH_START_OFFSET 52
51
52
53struct gprs_rlcmac_sba *sba_alloc(void *ctx, struct gprs_rlcmac_pdch *pdch, uint8_t ta)
54{
55 struct gprs_rlcmac_sba *sba;
Pau Espin Pedrolce3bd252021-03-29 12:13:13 +020056 uint32_t start_fn;
57
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010058 sba = talloc_zero(ctx, struct gprs_rlcmac_sba);
59 if (!sba)
60 return NULL;
61
Pau Espin Pedrolce3bd252021-03-29 12:13:13 +020062 /* TODO: Increase start_fn dynamically based on AGCH queue load in the BTS: */
63 start_fn = next_fn(pdch->last_rts_fn, AGCH_START_OFFSET);
64
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010065 sba->pdch = pdch;
66 sba->ta = ta;
Pau Espin Pedrolce3bd252021-03-29 12:13:13 +020067 sba->fn = pdch_ulc_get_next_free_fn(pdch->ulc, start_fn);
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010068
69 pdch_ulc_reserve_sba(pdch->ulc, sba);
70 return sba;
71}
72
73/* Internal use */
74static void sba_free_norelease(struct gprs_rlcmac_sba *sba)
75{
76 bts_do_rate_ctr_inc(sba->pdch->trx->bts, CTR_SBA_FREED);
77 talloc_free(sba);
78}
79
80void sba_free(struct gprs_rlcmac_sba *sba)
81{
82 if (pdch_ulc_release_fn(sba->pdch->ulc, sba->fn) < 0)
83 LOGPDCH(sba->pdch, DRLCMAC, LOGL_NOTICE,
84 "Trying to release unregistered SBA (FN=%u, TA=%u)\n",
85 sba->fn, sba->ta);
86 sba_free_norelease(sba);
87}
88
89void sba_timeout(struct gprs_rlcmac_sba *sba)
90{
91 /* Upon timeout, the UL Controller node is already released */
92 sba_free_norelease(sba);
93}