Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 3 | * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <osmocom/core/utils.h> |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 24 | #include <osmocom/core/linuxlist.h> |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 25 | #include <osmocom/ctrl/ports.h> |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 26 | |
| 27 | #include "gprs_pcu.h" |
| 28 | #include "bts.h" |
| 29 | |
| 30 | struct gprs_pcu *the_pcu; |
| 31 | |
Pau Espin Pedrol | 924aaad | 2021-01-14 12:01:42 +0100 | [diff] [blame] | 32 | static struct osmo_tdef T_defs_pcu[] = { |
Oliver Smith | d3c7591 | 2021-07-09 16:37:16 +0200 | [diff] [blame] | 33 | { .T=3113, .default_val=7, .unit=OSMO_TDEF_S, .desc="Timeout for paging", .val=0 }, |
Pau Espin Pedrol | 924aaad | 2021-01-14 12:01:42 +0100 | [diff] [blame] | 34 | { .T=3190, .default_val=5, .unit=OSMO_TDEF_S, .desc="Return to packet idle mode after Packet DL Assignment on CCCH (s)", .val=0}, |
Pau Espin Pedrol | 4b6f0bf | 2021-05-10 18:54:52 +0200 | [diff] [blame] | 35 | { .T=3141, .default_val=10, .unit=OSMO_TDEF_S, .desc="Timeout for contention resolution procedure (s)", .val=0 }, |
Pau Espin Pedrol | 56b7c64 | 2021-11-15 18:20:05 +0100 | [diff] [blame] | 36 | { .T=3172, .default_val=5000, .unit=OSMO_TDEF_MS, .desc="Wait Indication used in Imm Ass Reject during TBF Establishment (PACCH)", .val=0, .min_val = 0, .max_val = 255000 }, /* TS 44.060 7.1.3.2.1 */ |
Pau Espin Pedrol | 41a22a7 | 2021-01-26 19:00:37 +0100 | [diff] [blame] | 37 | { .T=PCU_TDEF_NEIGH_RESOLVE_TO, .default_val=1000, .unit=OSMO_TDEF_MS, .desc="[ARFCN+BSIC]->[RAC+CI] resolution timeout (ms)", .val=0 }, |
| 38 | { .T=PCU_TDEF_SI_RESOLVE_TO, .default_val=1000, .unit=OSMO_TDEF_MS, .desc="RIM RAN-INFO response timeout (ms)", .val=0 }, |
Pau Espin Pedrol | ab7159f | 2021-01-26 17:51:44 +0100 | [diff] [blame] | 39 | { .T=PCU_TDEF_NEIGH_CACHE_ALIVE, .default_val=5, .unit=OSMO_TDEF_S, .desc="[ARFCN+BSIC]->[RAC+CI] resolution cache entry storage timeout (s)", .val=0 }, |
| 40 | { .T=PCU_TDEF_SI_CACHE_ALIVE, .default_val=5, .unit=OSMO_TDEF_S, .desc="[RAC+CI]->[SI] resolution cache entry storage timeout (s)", .val=0 }, |
Pau Espin Pedrol | 14339f6 | 2021-04-26 14:14:37 +0200 | [diff] [blame] | 41 | { .T=-101, .default_val=30, .unit=OSMO_TDEF_S, .desc="BSSGP (un)blocking procedures timer (s)", .val=0 }, |
| 42 | { .T=-102, .default_val=30, .unit=OSMO_TDEF_S, .desc="BSSGP reset procedure timer (s)", .val=0 }, |
Pau Espin Pedrol | 683ce64 | 2021-11-15 14:49:08 +0100 | [diff] [blame] | 43 | { .T=-2000, .default_val=0, .unit=OSMO_TDEF_MS, .desc="Delay release of UL TBF after tx Packet Access Reject (PACCH) (ms)", .val=0 }, |
Pau Espin Pedrol | 039ee82 | 2021-04-26 18:49:33 +0200 | [diff] [blame] | 44 | { .T=-2001, .default_val=2, .unit=OSMO_TDEF_S, .desc="PACCH assignment timeout (s)", .val=0 }, |
Pau Espin Pedrol | 924aaad | 2021-01-14 12:01:42 +0100 | [diff] [blame] | 45 | { .T=-2002, .default_val=200, .unit=OSMO_TDEF_MS, .desc="Waiting after IMM.ASS confirm timer (ms)", .val=0 }, |
| 46 | { .T=-2030, .default_val=60, .unit=OSMO_TDEF_S, .desc="Time to keep an idle MS object alive (s)", .val=0 }, /* slightly above T3314 (default 44s, 24.008, 11.2.2) */ |
| 47 | { .T=-2031, .default_val=2000, .unit=OSMO_TDEF_MS, .desc="Time to keep an idle DL TBF alive (ms)", .val=0 }, |
| 48 | { .T=0, .default_val=0, .unit=OSMO_TDEF_S, .desc=NULL, .val=0 } /* empty item at the end */ |
| 49 | }; |
| 50 | |
Pau Espin Pedrol | 0dcbc07 | 2021-11-10 19:09:10 +0100 | [diff] [blame] | 51 | static void _update_stats_timer_cb(void *data) |
| 52 | { |
| 53 | struct gprs_pcu *pcu = (struct gprs_pcu *)data; |
| 54 | struct gprs_rlcmac_bts *bts; |
| 55 | |
| 56 | llist_for_each_entry(bts, &pcu->bts_list, list) |
| 57 | osmo_time_cc_set_flag(&bts->all_allocated_pdch, bts_all_pdch_allocated(bts)); |
| 58 | |
| 59 | osmo_timer_schedule(&pcu->update_stats_timer, 1, 0); |
| 60 | } |
| 61 | |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 62 | static int gprs_pcu_talloc_destructor(struct gprs_pcu *pcu) |
| 63 | { |
Pau Espin Pedrol | adcf279 | 2022-05-09 15:44:32 +0200 | [diff] [blame] | 64 | struct gprs_rlcmac_bts *bts; |
| 65 | while ((bts = llist_first_entry_or_null(&pcu->bts_list, struct gprs_rlcmac_bts, list))) |
| 66 | talloc_free(bts); |
| 67 | |
Vadim Yanitskiy | e33c236 | 2022-07-22 03:44:44 +0700 | [diff] [blame] | 68 | osmo_timer_del(&pcu->update_stats_timer); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 69 | neigh_cache_free(pcu->neigh_cache); |
| 70 | si_cache_free(pcu->si_cache); |
| 71 | return 0; |
| 72 | } |
| 73 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 74 | struct gprs_pcu *gprs_pcu_alloc(void *ctx) |
| 75 | { |
| 76 | struct gprs_pcu *pcu; |
| 77 | |
| 78 | pcu = (struct gprs_pcu *)talloc_zero(ctx, struct gprs_pcu); |
| 79 | OSMO_ASSERT(pcu); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 80 | talloc_set_destructor(pcu, gprs_pcu_talloc_destructor); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 81 | |
Pau Espin Pedrol | e891222 | 2021-01-14 14:03:17 +0100 | [diff] [blame] | 82 | pcu->vty.fc_interval = 1; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 83 | pcu->vty.max_cs_ul = MAX_GPRS_CS; |
| 84 | pcu->vty.max_cs_dl = MAX_GPRS_CS; |
| 85 | pcu->vty.max_mcs_ul = MAX_EDGE_MCS; |
| 86 | pcu->vty.max_mcs_dl = MAX_EDGE_MCS; |
Pau Espin Pedrol | fe8de45 | 2021-02-09 18:47:34 +0100 | [diff] [blame] | 87 | pcu->vty.force_alpha = (uint8_t)-1; /* don't force by default, use BTS SI13 provided value */ |
Pau Espin Pedrol | 05f9f59 | 2021-01-14 12:56:58 +0100 | [diff] [blame] | 88 | pcu->vty.dl_tbf_preemptive_retransmission = true; |
Pau Espin Pedrol | 97296b2 | 2021-01-14 13:08:02 +0100 | [diff] [blame] | 89 | /* By default resegmentation is supported in DL can also be configured |
| 90 | * through VTY */ |
| 91 | pcu->vty.dl_arq_type = EGPRS_ARQ1; |
Pau Espin Pedrol | e8dcf64 | 2021-01-14 13:17:01 +0100 | [diff] [blame] | 92 | pcu->vty.cs_adj_enabled = true; |
| 93 | pcu->vty.cs_adj_upper_limit = 33; /* Decrease CS if the error rate is above */ |
| 94 | pcu->vty.cs_adj_lower_limit = 10; /* Increase CS if the error rate is below */ |
Pau Espin Pedrol | ad79b85 | 2021-01-14 13:20:55 +0100 | [diff] [blame] | 95 | pcu->vty.cs_downgrade_threshold = 200; |
Pau Espin Pedrol | 54b159a | 2021-01-14 13:30:04 +0100 | [diff] [blame] | 96 | /* CS-1 to CS-4 */ |
| 97 | pcu->vty.cs_lqual_ranges[0].low = -256; |
| 98 | pcu->vty.cs_lqual_ranges[0].high = 6; |
| 99 | pcu->vty.cs_lqual_ranges[1].low = 5; |
| 100 | pcu->vty.cs_lqual_ranges[1].high = 8; |
| 101 | pcu->vty.cs_lqual_ranges[2].low = 7; |
| 102 | pcu->vty.cs_lqual_ranges[2].high = 13; |
| 103 | pcu->vty.cs_lqual_ranges[3].low = 12; |
| 104 | pcu->vty.cs_lqual_ranges[3].high = 256; |
| 105 | /* MCS-1 to MCS-9 */ |
| 106 | /* Default thresholds are referenced from literature */ |
| 107 | /* Fig. 2.3, Chapter 2, Optimizing Wireless Communication Systems, Springer (2009) */ |
| 108 | pcu->vty.mcs_lqual_ranges[0].low = -256; |
| 109 | pcu->vty.mcs_lqual_ranges[0].high = 6; |
| 110 | pcu->vty.mcs_lqual_ranges[1].low = 5; |
| 111 | pcu->vty.mcs_lqual_ranges[1].high = 8; |
| 112 | pcu->vty.mcs_lqual_ranges[2].low = 7; |
| 113 | pcu->vty.mcs_lqual_ranges[2].high = 13; |
| 114 | pcu->vty.mcs_lqual_ranges[3].low = 12; |
| 115 | pcu->vty.mcs_lqual_ranges[3].high = 15; |
| 116 | pcu->vty.mcs_lqual_ranges[4].low = 14; |
| 117 | pcu->vty.mcs_lqual_ranges[4].high = 17; |
| 118 | pcu->vty.mcs_lqual_ranges[5].low = 16; |
| 119 | pcu->vty.mcs_lqual_ranges[5].high = 18; |
| 120 | pcu->vty.mcs_lqual_ranges[6].low = 17; |
| 121 | pcu->vty.mcs_lqual_ranges[6].high = 20; |
| 122 | pcu->vty.mcs_lqual_ranges[7].low = 19; |
| 123 | pcu->vty.mcs_lqual_ranges[7].high = 24; |
| 124 | pcu->vty.mcs_lqual_ranges[8].low = 23; |
| 125 | pcu->vty.mcs_lqual_ranges[8].high = 256; |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 126 | pcu->vty.ns_dialect = GPRS_NS2_DIALECT_IPACCESS; |
Harald Welte | d9367e3 | 2021-04-29 22:02:47 +0200 | [diff] [blame] | 127 | pcu->vty.ns_ip_dscp = -1; |
| 128 | pcu->vty.ns_priority = -1; |
Pau Espin Pedrol | 519d071 | 2021-01-14 14:30:03 +0100 | [diff] [blame] | 129 | /* TODO: increase them when CRBB decoding is implemented */ |
| 130 | pcu->vty.ws_base = 64; |
| 131 | pcu->vty.ws_pdch = 0; |
Pau Espin Pedrol | f473ec9 | 2021-01-14 14:45:14 +0100 | [diff] [blame] | 132 | pcu->vty.llc_codel_interval_msec = LLC_CODEL_USE_DEFAULT; |
| 133 | pcu->vty.llc_idle_ack_csec = 10; |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 134 | pcu->vty.neigh_ctrl_addr = NULL; /* don't use CTRL iface for Neigh Addr Resolution */ |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 135 | pcu->vty.neigh_ctrl_port = OSMO_CTRL_PORT_BSC_NEIGH; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 136 | |
Pau Espin Pedrol | 924aaad | 2021-01-14 12:01:42 +0100 | [diff] [blame] | 137 | pcu->T_defs = T_defs_pcu; |
| 138 | osmo_tdefs_reset(pcu->T_defs); |
| 139 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 140 | INIT_LLIST_HEAD(&pcu->bts_list); |
| 141 | |
Pau Espin Pedrol | ab7159f | 2021-01-26 17:51:44 +0100 | [diff] [blame] | 142 | pcu->neigh_cache = neigh_cache_alloc(pcu, osmo_tdef_get(pcu->T_defs, PCU_TDEF_NEIGH_CACHE_ALIVE, OSMO_TDEF_S, -1)); |
| 143 | pcu->si_cache = si_cache_alloc(pcu, osmo_tdef_get(pcu->T_defs, PCU_TDEF_SI_CACHE_ALIVE, OSMO_TDEF_S, -1)); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 144 | |
Pau Espin Pedrol | 0dcbc07 | 2021-11-10 19:09:10 +0100 | [diff] [blame] | 145 | osmo_timer_setup(&pcu->update_stats_timer, _update_stats_timer_cb, pcu); |
| 146 | osmo_timer_schedule(&pcu->update_stats_timer, 1, 0); |
| 147 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 148 | return pcu; |
| 149 | } |
| 150 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 151 | struct gprs_rlcmac_bts *gprs_pcu_get_bts_by_nr(struct gprs_pcu *pcu, uint8_t bts_nr) |
| 152 | { |
| 153 | struct gprs_rlcmac_bts *pos; |
| 154 | llist_for_each_entry(pos, &pcu->bts_list, list) { |
| 155 | if (pos->nr == bts_nr) |
| 156 | return pos; |
| 157 | } |
| 158 | return NULL; |
| 159 | } |
| 160 | |
Pau Espin Pedrol | 3a27102 | 2021-01-21 18:44:23 +0100 | [diff] [blame] | 161 | struct gprs_rlcmac_bts *gprs_pcu_get_bts_by_cgi_ps(struct gprs_pcu *pcu, struct osmo_cell_global_id_ps *cgi_ps) |
| 162 | { |
| 163 | struct gprs_rlcmac_bts *pos; |
| 164 | llist_for_each_entry(pos, &pcu->bts_list, list) { |
Pau Espin Pedrol | a100a6b | 2021-01-22 17:45:50 +0100 | [diff] [blame] | 165 | if (osmo_cgi_ps_cmp(&pos->cgi_ps, cgi_ps) == 0) |
Pau Espin Pedrol | 3a27102 | 2021-01-21 18:44:23 +0100 | [diff] [blame] | 166 | return pos; |
| 167 | } |
| 168 | return NULL; |
| 169 | } |
| 170 | |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 171 | void gprs_pcu_set_initial_cs(struct gprs_pcu *pcu, uint8_t cs_dl, uint8_t cs_ul) |
| 172 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 173 | struct gprs_rlcmac_bts *bts; |
| 174 | |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 175 | the_pcu->vty.initial_cs_dl = cs_dl; |
| 176 | the_pcu->vty.initial_cs_ul = cs_ul; |
| 177 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 178 | llist_for_each_entry(bts, &pcu->bts_list, list) { |
| 179 | bts_recalc_initial_cs(bts); |
| 180 | } |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 181 | } |
| 182 | void gprs_pcu_set_initial_mcs(struct gprs_pcu *pcu, uint8_t mcs_dl, uint8_t mcs_ul) |
| 183 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 184 | struct gprs_rlcmac_bts *bts; |
| 185 | |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 186 | the_pcu->vty.initial_mcs_dl = mcs_dl; |
| 187 | the_pcu->vty.initial_mcs_ul = mcs_ul; |
| 188 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 189 | llist_for_each_entry(bts, &pcu->bts_list, list) { |
| 190 | bts_recalc_initial_mcs(bts); |
| 191 | } |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 192 | } |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 193 | |
| 194 | void gprs_pcu_set_max_cs(struct gprs_pcu *pcu, uint8_t cs_dl, uint8_t cs_ul) |
| 195 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 196 | struct gprs_rlcmac_bts *bts; |
| 197 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 198 | the_pcu->vty.max_cs_dl = cs_dl; |
| 199 | the_pcu->vty.max_cs_ul = cs_ul; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 200 | |
| 201 | llist_for_each_entry(bts, &pcu->bts_list, list) { |
| 202 | bts_recalc_max_cs(bts); |
| 203 | } |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 204 | } |
| 205 | void gprs_pcu_set_max_mcs(struct gprs_pcu *pcu, uint8_t mcs_dl, uint8_t mcs_ul) |
| 206 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 207 | struct gprs_rlcmac_bts *bts; |
| 208 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 209 | the_pcu->vty.max_mcs_dl = mcs_dl; |
| 210 | the_pcu->vty.max_mcs_ul = mcs_ul; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 211 | |
| 212 | llist_for_each_entry(bts, &pcu->bts_list, list) { |
| 213 | bts_recalc_max_mcs(bts); |
| 214 | } |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 215 | } |