Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 1 | /* 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | #include <sba.h> |
| 22 | #include <gprs_debug.h> |
| 23 | #include <bts.h> |
| 24 | #include <pcu_utils.h> |
| 25 | #include <pdch.h> |
| 26 | #include <errno.h> |
| 27 | |
| 28 | #include <osmocom/core/logging.h> |
| 29 | #include <osmocom/core/talloc.h> |
| 30 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 31 | #include <osmocom/gsm/gsm_utils.h> |
| 32 | |
| 33 | #include "pdch.h" |
| 34 | #include "pdch_ul_controller.h" |
| 35 | |
Pau Espin Pedrol | 54e6450 | 2021-03-26 20:44:48 +0100 | [diff] [blame] | 36 | /* TBF Starting Time for assigning SBA. |
| 37 | * See TS 44.060 12.21 "Starting Frame Number Description". |
| 38 | * According to spec, k=0 (offset=4) "should not be used, so as to leave time |
| 39 | * for the MS to analyze the message and get ready to receive or transmit". |
| 40 | * Hence, k=1 (offset=8-9) is theoretically the minimum offset which could be |
| 41 | * used. |
| 42 | * |
| 43 | * However, it was found, empirically, that it takes around 30-40 FNs time for |
| 44 | * the Immediate Assignment message created with this "TBF Starting Time" to |
| 45 | * travel from PCU->BTS and be transmitted over CCCH on the Um interface. Hence, |
| 46 | * we must account for this delay here, otherwise the MS would be receiving eg. |
| 47 | * a TBF Starting Time of FN=40 while the Imm Assigned containing it is sent in |
| 48 | * eg. FN=50, which would be too late for the MS to answer to it. |
| 49 | * |
| 50 | * The situation described above, can even get worse on high BTS load for AGCH, |
| 51 | * since the Immediate Assignment will queue in the BTS waiting to be |
| 52 | * transmitted one after the other, hence increasing the required delay. |
| 53 | */ |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 54 | #define AGCH_START_OFFSET 52 |
| 55 | |
| 56 | |
| 57 | struct gprs_rlcmac_sba *sba_alloc(void *ctx, struct gprs_rlcmac_pdch *pdch, uint8_t ta) |
| 58 | { |
| 59 | struct gprs_rlcmac_sba *sba; |
Pau Espin Pedrol | ce3bd25 | 2021-03-29 12:13:13 +0200 | [diff] [blame] | 60 | uint32_t start_fn; |
| 61 | |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 62 | sba = talloc_zero(ctx, struct gprs_rlcmac_sba); |
| 63 | if (!sba) |
| 64 | return NULL; |
| 65 | |
Pau Espin Pedrol | ce3bd25 | 2021-03-29 12:13:13 +0200 | [diff] [blame] | 66 | /* TODO: Increase start_fn dynamically based on AGCH queue load in the BTS: */ |
| 67 | start_fn = next_fn(pdch->last_rts_fn, AGCH_START_OFFSET); |
| 68 | |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 69 | sba->pdch = pdch; |
| 70 | sba->ta = ta; |
Pau Espin Pedrol | ce3bd25 | 2021-03-29 12:13:13 +0200 | [diff] [blame] | 71 | sba->fn = pdch_ulc_get_next_free_fn(pdch->ulc, start_fn); |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 72 | |
| 73 | pdch_ulc_reserve_sba(pdch->ulc, sba); |
| 74 | return sba; |
| 75 | } |
| 76 | |
| 77 | /* Internal use */ |
| 78 | static void sba_free_norelease(struct gprs_rlcmac_sba *sba) |
| 79 | { |
| 80 | bts_do_rate_ctr_inc(sba->pdch->trx->bts, CTR_SBA_FREED); |
| 81 | talloc_free(sba); |
| 82 | } |
| 83 | |
| 84 | void sba_free(struct gprs_rlcmac_sba *sba) |
| 85 | { |
| 86 | if (pdch_ulc_release_fn(sba->pdch->ulc, sba->fn) < 0) |
| 87 | LOGPDCH(sba->pdch, DRLCMAC, LOGL_NOTICE, |
| 88 | "Trying to release unregistered SBA (FN=%u, TA=%u)\n", |
| 89 | sba->fn, sba->ta); |
| 90 | sba_free_norelease(sba); |
| 91 | } |
| 92 | |
| 93 | void sba_timeout(struct gprs_rlcmac_sba *sba) |
| 94 | { |
| 95 | /* Upon timeout, the UL Controller node is already released */ |
| 96 | sba_free_norelease(sba); |
| 97 | } |