Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 1 | /* PDCH scheduler |
| 2 | * |
| 3 | * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 14 | */ |
Pau Espin Pedrol | 488aa29 | 2019-09-25 17:48:35 +0200 | [diff] [blame] | 15 | |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 16 | #include <gprs_bssgp_pcu.h> |
| 17 | #include <gprs_rlcmac.h> |
| 18 | #include <pcu_l1_if.h> |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 19 | #include <bts.h> |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 20 | #include <tbf.h> |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 21 | #include <tbf_ul.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 22 | #include <gprs_debug.h> |
| 23 | #include <gprs_ms.h> |
| 24 | #include <rlc.h> |
| 25 | #include <sba.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 26 | #include <pdch.h> |
Jacob Erlbeck | 502bd1f | 2015-03-20 14:26:05 +0100 | [diff] [blame] | 27 | #include "pcu_utils.h" |
| 28 | |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 29 | extern "C" { |
| 30 | #include <osmocom/core/gsmtap.h> |
| 31 | } |
| 32 | |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 33 | struct tbf_sched_candidates { |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 34 | struct gprs_rlcmac_tbf *ul_ass; |
| 35 | struct gprs_rlcmac_tbf *dl_ass; |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 36 | struct gprs_rlcmac_tbf *nacc; |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 37 | struct gprs_rlcmac_ul_tbf *ul_ack; |
| 38 | }; |
| 39 | |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 40 | static void get_ctrl_msg_tbf_candidates(const struct gprs_rlcmac_pdch *pdch, |
Pau Espin Pedrol | 4851762 | 2021-04-30 14:15:46 +0200 | [diff] [blame] | 41 | struct tbf_sched_candidates *tbf_cand) |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 42 | { |
Daniel Willmann | 4f3c420 | 2014-08-07 14:58:59 +0200 | [diff] [blame] | 43 | struct gprs_rlcmac_ul_tbf *ul_tbf; |
| 44 | struct gprs_rlcmac_dl_tbf *dl_tbf; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 45 | struct llist_item *pos; |
Andreas Eversberg | e6228b3 | 2012-07-03 13:36:03 +0200 | [diff] [blame] | 46 | |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 47 | llist_for_each_entry(pos, &pdch->trx->ul_tbfs, list) { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 48 | ul_tbf = tbf_as_ul_tbf((struct gprs_rlcmac_tbf *)pos->entry); |
Pau Espin Pedrol | b5fece9 | 2021-08-23 16:58:04 +0200 | [diff] [blame] | 49 | OSMO_ASSERT(ul_tbf); |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 50 | /* this trx, this ts */ |
Pau Espin Pedrol | e875769 | 2022-12-12 16:18:05 +0100 | [diff] [blame^] | 51 | if (!tbf_is_control_ts(ul_tbf, pdch)) |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 52 | continue; |
Pau Espin Pedrol | ea8dbdd | 2021-07-29 18:39:16 +0200 | [diff] [blame] | 53 | if (tbf_ul_ack_rts(ul_tbf)) |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 54 | tbf_cand->ul_ack = ul_tbf; |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 55 | if (tbf_dl_ass_rts(ul_tbf)) |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 56 | tbf_cand->dl_ass = ul_tbf; |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 57 | if (tbf_ul_ass_rts(ul_tbf)) |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 58 | tbf_cand->ul_ass = ul_tbf; |
Pau Espin Pedrol | 9345eb3 | 2021-02-18 14:27:14 +0100 | [diff] [blame] | 59 | /* NACC ready to send. TFI assigned is needed to send messages */ |
Pau Espin Pedrol | c6e4aef | 2022-11-17 21:00:24 +0100 | [diff] [blame] | 60 | if (tbf_is_tfi_assigned(ul_tbf) && ms_nacc_rts(ul_tbf->ms())) |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 61 | tbf_cand->nacc = ul_tbf; |
Max | 5a6bcfb | 2017-09-01 14:36:44 +0200 | [diff] [blame] | 62 | /* FIXME: Is this supposed to be fair? The last TBF for each wins? Maybe use llist_add_tail and skip once we have all |
| 63 | states? */ |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 64 | } |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 65 | llist_for_each_entry(pos, &pdch->trx->dl_tbfs, list) { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 66 | dl_tbf = tbf_as_dl_tbf((struct gprs_rlcmac_tbf *)pos->entry); |
Pau Espin Pedrol | b5fece9 | 2021-08-23 16:58:04 +0200 | [diff] [blame] | 67 | OSMO_ASSERT(dl_tbf); |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 68 | /* this trx, this ts */ |
Pau Espin Pedrol | e875769 | 2022-12-12 16:18:05 +0100 | [diff] [blame^] | 69 | if (!tbf_is_control_ts(dl_tbf, pdch)) |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 70 | continue; |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 71 | if (tbf_dl_ass_rts(dl_tbf)) |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 72 | tbf_cand->dl_ass = dl_tbf; |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 73 | if (tbf_ul_ass_rts(dl_tbf)) |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 74 | tbf_cand->ul_ass = dl_tbf; |
Pau Espin Pedrol | 9345eb3 | 2021-02-18 14:27:14 +0100 | [diff] [blame] | 75 | /* NACC ready to send. TFI assigned is needed to send messages */ |
Pau Espin Pedrol | c6e4aef | 2022-11-17 21:00:24 +0100 | [diff] [blame] | 76 | if (tbf_is_tfi_assigned(dl_tbf) && ms_nacc_rts(dl_tbf->ms())) |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 77 | tbf_cand->nacc = dl_tbf; |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 78 | } |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Pau Espin Pedrol | 6325423 | 2021-05-11 14:04:33 +0200 | [diff] [blame] | 81 | static struct gprs_rlcmac_ul_tbf *sched_select_uplink(struct gprs_rlcmac_pdch *pdch, bool require_gprs_only) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 82 | { |
Pau Espin Pedrol | 107e94c | 2021-03-24 17:06:15 +0100 | [diff] [blame] | 83 | struct gprs_rlcmac_ul_tbf *tbf; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 84 | uint8_t i, tfi; |
| 85 | |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 86 | /* select uplink resource */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 87 | for (i = 0, tfi = pdch->next_ul_tfi; i < 32; |
| 88 | i++, tfi = (tfi + 1) & 31) { |
Daniel Willmann | 1e0c610 | 2014-06-04 14:56:09 +0200 | [diff] [blame] | 89 | tbf = pdch->ul_tbf_by_tfi(tfi); |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 90 | /* no TBF for this tfi, go next */ |
| 91 | if (!tbf) |
| 92 | continue; |
Holger Hans Peter Freyther | 483f77a | 2013-10-16 16:33:00 +0200 | [diff] [blame] | 93 | /* no UL resources needed, go next */ |
| 94 | /* we don't need to give resources in FINISHED state, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 95 | * because we have received all blocks and only poll |
| 96 | * for packet control ack. */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 97 | if (tbf->state_is_not(TBF_ST_FLOW)) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 98 | continue; |
| 99 | |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 100 | if (require_gprs_only && tbf->is_egprs_enabled()) |
| 101 | continue; |
| 102 | |
Pau Espin Pedrol | 6325423 | 2021-05-11 14:04:33 +0200 | [diff] [blame] | 103 | /* use this USF (tbf) */ |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 104 | /* next TBF to handle resource is the next one */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 105 | pdch->next_ul_tfi = (tfi + 1) & 31; |
Pau Espin Pedrol | 107e94c | 2021-03-24 17:06:15 +0100 | [diff] [blame] | 106 | return tbf; |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Pau Espin Pedrol | 107e94c | 2021-03-24 17:06:15 +0100 | [diff] [blame] | 109 | return NULL; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 112 | struct msgb *sched_app_info(struct gprs_rlcmac_tbf *tbf) { |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 113 | struct gprs_rlcmac_bts *bts; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 114 | struct msgb *msg = NULL; |
| 115 | |
| 116 | if (!tbf || !tbf->ms()->app_info_pending) |
| 117 | return NULL; |
| 118 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 119 | bts = tbf->bts; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 120 | |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 121 | if (bts->app_info) { |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 122 | LOGP(DRLCMACSCHED, LOGL_DEBUG, "Sending Packet Application Information message\n"); |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 123 | msg = msgb_copy(bts->app_info, "app_info_msg_sched"); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 124 | } else |
| 125 | LOGP(DRLCMACSCHED, LOGL_ERROR, "MS has app_info_pending flag set, but no Packet Application Information" |
| 126 | " message stored in BTS!\n"); |
| 127 | |
| 128 | tbf->ms()->app_info_pending = false; |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 129 | bts->app_info_pending--; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 130 | |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 131 | if (!bts->app_info_pending) { |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 132 | LOGP(DRLCMACSCHED, LOGL_DEBUG, "Packet Application Information successfully sent to all MS with active" |
| 133 | " TBF\n"); |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 134 | msgb_free(bts->app_info); |
| 135 | bts->app_info = NULL; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 136 | } |
| 137 | return msg; |
| 138 | } |
| 139 | |
Pau Espin Pedrol | 3973eb5 | 2021-03-03 20:47:07 +0100 | [diff] [blame] | 140 | static struct msgb *sched_select_ctrl_msg(struct gprs_rlcmac_pdch *pdch, uint32_t fn, |
| 141 | uint8_t block_nr, struct tbf_sched_candidates *tbfs) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 142 | { |
| 143 | struct msgb *msg = NULL; |
| 144 | struct gprs_rlcmac_tbf *tbf = NULL; |
Pau Espin Pedrol | d6b913f | 2020-12-15 18:55:16 +0100 | [diff] [blame] | 145 | struct gprs_rlcmac_tbf *next_list[] = { tbfs->ul_ass, |
| 146 | tbfs->dl_ass, |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 147 | tbfs->ul_ack, |
| 148 | tbfs->nacc }; |
Pau Espin Pedrol | 3973eb5 | 2021-03-03 20:47:07 +0100 | [diff] [blame] | 149 | uint8_t ts = pdch->ts_no; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 150 | |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 151 | /* Send Packet Application Information first (ETWS primary notifications) */ |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 152 | msg = sched_app_info(tbfs->dl_ass); |
Holger Hans Peter Freyther | 705653b | 2013-11-26 16:39:28 +0100 | [diff] [blame] | 153 | |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 154 | if (!msg) { |
| 155 | for (size_t i = 0; i < ARRAY_SIZE(next_list); ++i) { |
Pau Espin Pedrol | d6b913f | 2020-12-15 18:55:16 +0100 | [diff] [blame] | 156 | tbf = next_list[(pdch->next_ctrl_prio + i) % ARRAY_SIZE(next_list)]; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 157 | if (!tbf) |
| 158 | continue; |
| 159 | |
| 160 | /* |
| 161 | * Assignments for the same direction have lower precedence, |
| 162 | * because they may kill the TBF when the CONTROL ACK is |
| 163 | * received, thus preventing the others from being processed. |
| 164 | */ |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 165 | if (tbf == tbfs->ul_ass && tbf->ul_ass_state_is(TBF_UL_ASS_SEND_ASS_REJ)) |
| 166 | msg = tbf_ul_ass_create_rlcmac_msg(tbfs->ul_ass, fn, ts); |
Pau Espin Pedrol | 34f61af | 2021-04-26 18:02:52 +0200 | [diff] [blame] | 167 | else if (tbf == tbfs->ul_ass && tbf->direction == GPRS_RLCMAC_DL_TBF) |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 168 | msg = tbf_ul_ass_create_rlcmac_msg(tbfs->ul_ass, fn, ts); |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 169 | else if (tbf == tbfs->dl_ass && tbf->direction == GPRS_RLCMAC_UL_TBF) |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 170 | msg = tbf_dl_ass_create_rlcmac_msg(tbfs->dl_ass, fn, ts); |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 171 | else if (tbf == tbfs->ul_ack) |
Pau Espin Pedrol | ea8dbdd | 2021-07-29 18:39:16 +0200 | [diff] [blame] | 172 | msg = tbf_ul_ack_create_rlcmac_msg(tbfs->ul_ack, fn, ts); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 173 | else if (tbf == tbfs->nacc) { |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 174 | msg = ms_nacc_create_rlcmac_msg(tbf->ms(), tbf, fn, ts); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 175 | } |
Holger Hans Peter Freyther | 705653b | 2013-11-26 16:39:28 +0100 | [diff] [blame] | 176 | |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 177 | if (!msg) { |
| 178 | tbf = NULL; |
| 179 | continue; |
| 180 | } |
| 181 | |
Pau Espin Pedrol | d6b913f | 2020-12-15 18:55:16 +0100 | [diff] [blame] | 182 | pdch->next_ctrl_prio = (pdch->next_ctrl_prio + 1) % ARRAY_SIZE(next_list); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 183 | break; |
Holger Hans Peter Freyther | 705653b | 2013-11-26 16:39:28 +0100 | [diff] [blame] | 184 | } |
Andreas Eversberg | ee31b78 | 2012-07-15 16:27:01 +0200 | [diff] [blame] | 185 | } |
Holger Hans Peter Freyther | 705653b | 2013-11-26 16:39:28 +0100 | [diff] [blame] | 186 | |
Jacob Erlbeck | 1ff70c2 | 2016-02-01 19:42:09 +0100 | [diff] [blame] | 187 | if (!msg) { |
| 188 | /* |
| 189 | * If one of these is left, the response (CONTROL ACK) from the |
| 190 | * MS will kill the current TBF, only one of them can be |
| 191 | * non-NULL |
| 192 | */ |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 193 | if (tbfs->dl_ass) { |
| 194 | tbf = tbfs->dl_ass; |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 195 | msg = tbf_dl_ass_create_rlcmac_msg(tbfs->dl_ass, fn, ts); |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 196 | } else if (tbfs->ul_ass) { |
| 197 | tbf = tbfs->ul_ass; |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 198 | msg = tbf_ul_ass_create_rlcmac_msg(tbfs->ul_ass, fn, ts); |
Jacob Erlbeck | 1ff70c2 | 2016-02-01 19:42:09 +0100 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 202 | /* any message */ |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 203 | if (msg) { |
Neels Hofmeyr | 3de6d06 | 2017-04-27 01:33:39 +0200 | [diff] [blame] | 204 | if (!tbf) { |
Pau Espin Pedrol | 3973eb5 | 2021-03-03 20:47:07 +0100 | [diff] [blame] | 205 | LOGPDCH(pdch, DRLCMACSCHED, LOGL_ERROR, "FN=%" PRIu32 |
| 206 | " Control message to be scheduled, but no TBF\n", fn); |
Neels Hofmeyr | 3de6d06 | 2017-04-27 01:33:39 +0200 | [diff] [blame] | 207 | msgb_free(msg); |
| 208 | return NULL; |
| 209 | } |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 210 | tbf->rotate_in_list(); |
Pau Espin Pedrol | 3973eb5 | 2021-03-03 20:47:07 +0100 | [diff] [blame] | 211 | LOGPDCH(pdch, DRLCMACSCHED, LOGL_DEBUG, "FN=%" PRIu32 |
| 212 | " Scheduling control message at RTS for %s\n", |
| 213 | fn, tbf_name(tbf)); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 214 | rate_ctr_inc(rate_ctr_group_get_ctr(tbf->ms()->ctrs, MS_CTR_DL_CTRL_MSG_SCHED)); |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 215 | return msg; |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 216 | } |
Neels Hofmeyr | 3de6d06 | 2017-04-27 01:33:39 +0200 | [diff] [blame] | 217 | |
| 218 | /* schedule PACKET PAGING REQUEST, if any are pending */ |
Holger Hans Peter Freyther | 24e98d0 | 2013-10-19 18:15:44 +0200 | [diff] [blame] | 219 | msg = pdch->packet_paging_request(); |
Andreas Eversberg | 07e97cf | 2012-08-07 16:00:56 +0200 | [diff] [blame] | 220 | if (msg) { |
Pau Espin Pedrol | 3973eb5 | 2021-03-03 20:47:07 +0100 | [diff] [blame] | 221 | LOGPDCH(pdch, DRLCMACSCHED, LOGL_DEBUG, "FN=%" PRIu32 |
| 222 | " Scheduling paging request message at RTS\n", fn); |
Andreas Eversberg | 07e97cf | 2012-08-07 16:00:56 +0200 | [diff] [blame] | 223 | return msg; |
| 224 | } |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 225 | |
Andreas Eversberg | 07e97cf | 2012-08-07 16:00:56 +0200 | [diff] [blame] | 226 | return NULL; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Max | d0532b5 | 2017-12-13 18:27:32 +0100 | [diff] [blame] | 229 | static inline enum tbf_dl_prio tbf_compute_priority(const struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_dl_tbf *tbf, |
| 230 | uint8_t ts, uint32_t fn, int age) |
| 231 | { |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 232 | const gprs_rlc_dl_window *w = static_cast<gprs_rlc_dl_window *>(tbf->window()); |
Pau Espin Pedrol | 924aaad | 2021-01-14 12:01:42 +0100 | [diff] [blame] | 233 | unsigned long msecs_t3190 = osmo_tdef_get(the_pcu->T_defs, 3190, OSMO_TDEF_MS, -1); |
| 234 | unsigned long dl_tbf_idle_msec = osmo_tdef_get(the_pcu->T_defs, -2031, OSMO_TDEF_MS, -1); |
Pau Espin Pedrol | 38cfa73 | 2019-09-09 12:55:01 +0200 | [diff] [blame] | 235 | int age_thresh1 = msecs_to_frames(200); |
Pau Espin Pedrol | 2b5c629 | 2019-09-09 13:41:00 +0200 | [diff] [blame] | 236 | int age_thresh2 = msecs_to_frames(OSMO_MIN(msecs_t3190/2, dl_tbf_idle_msec)); |
Pau Espin Pedrol | e875769 | 2022-12-12 16:18:05 +0100 | [diff] [blame^] | 237 | const struct gprs_rlcmac_pdch *pdch = &tbf_get_trx(tbf)->pdch[ts]; |
Max | d0532b5 | 2017-12-13 18:27:32 +0100 | [diff] [blame] | 238 | |
Pau Espin Pedrol | e875769 | 2022-12-12 16:18:05 +0100 | [diff] [blame^] | 239 | if (tbf_is_control_ts(tbf, pdch) && tbf->need_poll_for_dl_ack_nack()) |
Max | d0532b5 | 2017-12-13 18:27:32 +0100 | [diff] [blame] | 240 | return DL_PRIO_CONTROL; |
| 241 | |
Pau Espin Pedrol | e875769 | 2022-12-12 16:18:05 +0100 | [diff] [blame^] | 242 | if (tbf_is_control_ts(tbf, pdch) && age > age_thresh2 && age_thresh2 > 0) |
Max | d0532b5 | 2017-12-13 18:27:32 +0100 | [diff] [blame] | 243 | return DL_PRIO_HIGH_AGE; |
| 244 | |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 245 | if ((tbf->state_is(TBF_ST_FLOW) && tbf->have_data()) || w->resend_needed() >= 0) |
Max | d0532b5 | 2017-12-13 18:27:32 +0100 | [diff] [blame] | 246 | return DL_PRIO_NEW_DATA; |
| 247 | |
Pau Espin Pedrol | e875769 | 2022-12-12 16:18:05 +0100 | [diff] [blame^] | 248 | if (tbf_is_control_ts(tbf, pdch) && age > age_thresh1 && tbf->keep_open(fn)) |
Max | d0532b5 | 2017-12-13 18:27:32 +0100 | [diff] [blame] | 249 | return DL_PRIO_LOW_AGE; |
| 250 | |
| 251 | if (!w->window_empty()) |
| 252 | return DL_PRIO_SENT_DATA; |
| 253 | |
| 254 | return DL_PRIO_NONE; |
| 255 | } |
| 256 | |
Pau Espin Pedrol | 1a5439b | 2021-01-25 17:30:31 +0100 | [diff] [blame] | 257 | /* Check if next data block of a TBF can be encoded in GMSK [(M)CS1-4]. */ |
| 258 | static bool can_produce_gmsk_data_block_next(struct gprs_rlcmac_dl_tbf *tbf, enum tbf_dl_prio prio) |
| 259 | { |
| 260 | const gprs_rlc_dl_window *w; |
| 261 | |
| 262 | /* GPRS TBFs can always send GMSK */ |
| 263 | if (!tbf->is_egprs_enabled()) |
| 264 | return true; |
| 265 | |
| 266 | switch (prio) { |
| 267 | case DL_PRIO_CONTROL: |
| 268 | /* Control blocks are always CS-1 */ |
| 269 | return true; |
| 270 | case DL_PRIO_NEW_DATA: |
| 271 | /* We can send any new data (no block generated yet) using any |
| 272 | * MCS. However, we don't (yet) support resegmenting already |
| 273 | * sent blocks (NACKed blocks in this case) into lower MCS of |
| 274 | * the same family. See OS#4966 */ |
| 275 | w = static_cast<gprs_rlc_dl_window *>(tbf->window()); |
| 276 | return w->resend_needed() < 0; |
| 277 | default: |
| 278 | return false; |
| 279 | } |
| 280 | } |
| 281 | |
Pau Espin Pedrol | e080808 | 2021-10-11 17:42:33 +0200 | [diff] [blame] | 282 | static struct msgb *sched_select_dl_data_msg(struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_pdch *pdch, |
| 283 | uint32_t fn, uint8_t block_nr, enum mcs_kind req_mcs_kind, |
| 284 | bool *is_egprs) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 285 | { |
| 286 | struct msgb *msg = NULL; |
Jacob Erlbeck | 0eabffd | 2015-03-02 14:28:12 +0100 | [diff] [blame] | 287 | struct gprs_rlcmac_dl_tbf *tbf, *prio_tbf = NULL; |
Max | d0532b5 | 2017-12-13 18:27:32 +0100 | [diff] [blame] | 288 | enum tbf_dl_prio prio, max_prio = DL_PRIO_NONE; |
Pau Espin Pedrol | 2ad15d5 | 2021-03-03 20:52:19 +0100 | [diff] [blame] | 289 | uint8_t ts = pdch->ts_no; |
Jacob Erlbeck | 502bd1f | 2015-03-20 14:26:05 +0100 | [diff] [blame] | 290 | |
Jacob Erlbeck | 0eabffd | 2015-03-02 14:28:12 +0100 | [diff] [blame] | 291 | uint8_t i, tfi, prio_tfi; |
Jacob Erlbeck | 502bd1f | 2015-03-20 14:26:05 +0100 | [diff] [blame] | 292 | int age; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 293 | |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 294 | /* select downlink resource */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 295 | for (i = 0, tfi = pdch->next_dl_tfi; i < 32; |
| 296 | i++, tfi = (tfi + 1) & 31) { |
Daniel Willmann | 1e0c610 | 2014-06-04 14:56:09 +0200 | [diff] [blame] | 297 | tbf = pdch->dl_tbf_by_tfi(tfi); |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 298 | /* no TBF for this tfi, go next */ |
| 299 | if (!tbf) |
| 300 | continue; |
| 301 | /* no DL TBF, go next */ |
| 302 | if (tbf->direction != GPRS_RLCMAC_DL_TBF) |
| 303 | continue; |
Holger Hans Peter Freyther | 483f77a | 2013-10-16 16:33:00 +0200 | [diff] [blame] | 304 | /* no DL resources needed, go next */ |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 305 | if (tbf->state_is_not(TBF_ST_FLOW) |
| 306 | && tbf->state_is_not(TBF_ST_FINISHED)) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 307 | continue; |
| 308 | |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 309 | /* If a GPRS (CS1-4) Dl block is required, skip EGPRS(_GSMK) tbfs: */ |
| 310 | if (req_mcs_kind == GPRS && tbf->is_egprs_enabled()) |
| 311 | continue; |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 312 | |
Jacob Erlbeck | 502bd1f | 2015-03-20 14:26:05 +0100 | [diff] [blame] | 313 | age = tbf->frames_since_last_poll(fn); |
| 314 | |
Jacob Erlbeck | 0eabffd | 2015-03-02 14:28:12 +0100 | [diff] [blame] | 315 | /* compute priority */ |
Max | d0532b5 | 2017-12-13 18:27:32 +0100 | [diff] [blame] | 316 | prio = tbf_compute_priority(bts, tbf, ts, fn, age); |
| 317 | if (prio == DL_PRIO_NONE) |
Jacob Erlbeck | 502bd1f | 2015-03-20 14:26:05 +0100 | [diff] [blame] | 318 | continue; |
Jacob Erlbeck | 0eabffd | 2015-03-02 14:28:12 +0100 | [diff] [blame] | 319 | |
Pau Espin Pedrol | 022f9e5 | 2020-11-16 18:49:39 +0100 | [diff] [blame] | 320 | /* If a GPRS (CS1-4/MCS1-4) Dl block is required, downgrade MCS |
| 321 | * below instead of skipping. However, downgrade can only be |
| 322 | * done on new data BSNs (not yet sent) and control blocks. */ |
Pau Espin Pedrol | 1a5439b | 2021-01-25 17:30:31 +0100 | [diff] [blame] | 323 | if (req_mcs_kind == EGPRS_GMSK && !can_produce_gmsk_data_block_next(tbf, prio)) { |
Pau Espin Pedrol | 2ad15d5 | 2021-03-03 20:52:19 +0100 | [diff] [blame] | 324 | LOGPDCH(pdch, DRLCMACSCHED, LOGL_DEBUG, "FN=%" PRIu32 |
| 325 | " Cannot downgrade EGPRS TBF with prio %d for %s\n", |
| 326 | fn, prio, tbf_name(tbf)); |
Pau Espin Pedrol | 022f9e5 | 2020-11-16 18:49:39 +0100 | [diff] [blame] | 327 | continue; |
| 328 | } |
| 329 | |
Jacob Erlbeck | 0eabffd | 2015-03-02 14:28:12 +0100 | [diff] [blame] | 330 | /* get the TBF with the highest priority */ |
| 331 | if (prio > max_prio) { |
| 332 | prio_tfi = tfi; |
| 333 | prio_tbf = tbf; |
| 334 | max_prio = prio; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | if (prio_tbf) { |
Pau Espin Pedrol | 2ad15d5 | 2021-03-03 20:52:19 +0100 | [diff] [blame] | 339 | LOGPDCH(pdch, DRLCMACSCHED, LOGL_DEBUG, "FN=%" PRIu32 |
| 340 | " Scheduling data message at RTS for DL TFI=%d prio=%d mcs_mode_restrict=%s\n", |
| 341 | fn, prio_tfi, max_prio, mode_name(req_mcs_kind)); |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 342 | /* next TBF to handle resource is the next one */ |
Jacob Erlbeck | 0eabffd | 2015-03-02 14:28:12 +0100 | [diff] [blame] | 343 | pdch->next_dl_tfi = (prio_tfi + 1) & 31; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 344 | /* generate DL data block */ |
Pau Espin Pedrol | 022f9e5 | 2020-11-16 18:49:39 +0100 | [diff] [blame] | 345 | msg = prio_tbf->create_dl_acked_block(fn, ts, req_mcs_kind); |
Pau Espin Pedrol | 8f1701f | 2021-01-25 11:31:57 +0100 | [diff] [blame] | 346 | *is_egprs = prio_tbf->is_egprs_enabled(); |
Andreas Eversberg | 3b7461c | 2012-07-20 11:19:59 +0200 | [diff] [blame] | 347 | } |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 348 | |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 349 | return msg; |
| 350 | } |
Holger Hans Peter Freyther | 40fc8f9 | 2013-11-23 23:03:14 +0100 | [diff] [blame] | 351 | |
| 352 | static const uint8_t rlcmac_dl_idle[23] = { |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 353 | 0x47, /* control without optional header octets, no polling, USF=111 */ |
| 354 | 0x94, /* dummy downlink control message, paging mode 00 */ |
| 355 | 0x2b, /* no persistance level, 7 bits spare pattern */ |
| 356 | 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, |
| 357 | 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b |
| 358 | }; |
| 359 | |
Holger Hans Peter Freyther | 40fc8f9 | 2013-11-23 23:03:14 +0100 | [diff] [blame] | 360 | static struct msgb *sched_dummy(void) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 361 | { |
| 362 | struct msgb *msg; |
| 363 | |
| 364 | msg = msgb_alloc(23, "rlcmac_dl_idle"); |
| 365 | if (!msg) |
| 366 | return NULL; |
| 367 | memcpy(msgb_put(msg, 23), rlcmac_dl_idle, 23); |
| 368 | |
| 369 | return msg; |
| 370 | } |
| 371 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 372 | static inline void tap_n_acc(const struct msgb *msg, struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts, |
Max | 8bfa659 | 2017-08-31 15:42:06 +0200 | [diff] [blame] | 373 | uint32_t fn, enum pcu_gsmtap_category cat) |
| 374 | { |
| 375 | if (!msg) |
| 376 | return; |
| 377 | |
| 378 | switch(cat) { |
| 379 | case PCU_GSMTAP_C_DL_CTRL: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 380 | bts_do_rate_ctr_inc(bts, CTR_RLC_SENT_CONTROL); |
| 381 | bts_send_gsmtap(bts, PCU_GSMTAP_C_DL_CTRL, false, trx, ts, GSMTAP_CHANNEL_PACCH, fn, msg->data, |
Max | 8bfa659 | 2017-08-31 15:42:06 +0200 | [diff] [blame] | 382 | msg->len); |
| 383 | break; |
| 384 | case PCU_GSMTAP_C_DL_DATA_GPRS: |
Pau Espin Pedrol | daa6c1c | 2020-11-16 14:25:06 +0100 | [diff] [blame] | 385 | case PCU_GSMTAP_C_DL_DATA_EGPRS: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 386 | bts_do_rate_ctr_inc(bts, CTR_RLC_SENT); |
| 387 | bts_send_gsmtap(bts, cat, false, trx, ts, GSMTAP_CHANNEL_PDTCH, fn, msg->data, |
Max | 8bfa659 | 2017-08-31 15:42:06 +0200 | [diff] [blame] | 388 | msg->len); |
| 389 | break; |
| 390 | case PCU_GSMTAP_C_DL_DUMMY: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 391 | bts_do_rate_ctr_inc(bts, CTR_RLC_SENT_DUMMY); |
| 392 | bts_send_gsmtap(bts, PCU_GSMTAP_C_DL_DUMMY, false, trx, ts, GSMTAP_CHANNEL_PACCH, fn, msg->data, |
Max | 8bfa659 | 2017-08-31 15:42:06 +0200 | [diff] [blame] | 393 | msg->len); |
| 394 | break; |
| 395 | default: |
| 396 | break; |
| 397 | } |
| 398 | } |
| 399 | |
Holger Hans Peter Freyther | b19d726 | 2013-10-17 18:12:18 +0200 | [diff] [blame] | 400 | int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_bts *bts, |
Max | 878bd1f | 2016-07-20 13:05:05 +0200 | [diff] [blame] | 401 | uint8_t trx, uint8_t ts, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 402 | uint32_t fn, uint8_t block_nr) |
| 403 | { |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 404 | struct gprs_rlcmac_pdch *pdch; |
Pau Espin Pedrol | b77a2c9 | 2020-12-15 18:46:33 +0100 | [diff] [blame] | 405 | struct tbf_sched_candidates tbf_cand = {0}; |
Pau Espin Pedrol | fd1fbdb | 2021-03-11 16:59:50 +0100 | [diff] [blame] | 406 | struct gprs_rlcmac_tbf *poll_tbf; |
Pau Espin Pedrol | 4bab867 | 2021-03-24 12:40:18 +0100 | [diff] [blame] | 407 | struct gprs_rlcmac_ul_tbf *usf_tbf = NULL; |
Pau Espin Pedrol | fd1fbdb | 2021-03-11 16:59:50 +0100 | [diff] [blame] | 408 | struct gprs_rlcmac_sba *sba; |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 409 | uint8_t usf; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 410 | struct msgb *msg = NULL; |
Pau Espin Pedrol | fd1fbdb | 2021-03-11 16:59:50 +0100 | [diff] [blame] | 411 | uint32_t poll_fn; |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 412 | enum pcu_gsmtap_category gsmtap_cat = PCU_GSMTAP_C_DL_DUMMY; /* init: make gcc happy */ |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 413 | bool tx_is_egprs = false; |
| 414 | bool require_gprs_only; |
| 415 | enum mcs_kind req_mcs_kind; /* Restrict CS/MCS if DL Data block is to be sent */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 416 | |
| 417 | if (trx >= 8 || ts >= 8) |
| 418 | return -EINVAL; |
| 419 | pdch = &bts->trx[trx].pdch[ts]; |
| 420 | |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 421 | if (!pdch->is_enabled()) { |
Pau Espin Pedrol | 25d60ca | 2021-08-31 16:50:32 +0200 | [diff] [blame] | 422 | LOGPDCH(pdch, DRLCMACSCHED, LOGL_INFO, "Received RTS on disabled TS\n"); |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 423 | return -EIO; |
| 424 | } |
| 425 | |
| 426 | /* store last frame number of RTS */ |
| 427 | pdch->last_rts_fn = fn; |
| 428 | |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 429 | /* require_gprs_only: Prioritize USF for GPRS-only MS here, |
| 430 | * since anyway we'll need to tx a Dl block with CS1-4 due to |
| 431 | * synchronization requirements. See 3GPP TS 03.64 version |
| 432 | * 8.12.0 |
| 433 | */ |
| 434 | require_gprs_only = (pdch->fn_without_cs14 == MS_RESYNC_NUM_FRAMES - 1); |
| 435 | if (require_gprs_only) { |
| 436 | LOGP(DRLCMACSCHED, LOGL_DEBUG, "TRX=%d TS=%d FN=%d " |
| 437 | "synchronization frame (every 18 frames), only CS1-4 allowed", |
| 438 | trx, ts, fn); |
| 439 | req_mcs_kind = GPRS; /* only GPRS CS1-4 allowed, all MS need to be able to decode it */ |
| 440 | } else { |
| 441 | req_mcs_kind = EGPRS; /* all kinds are fine */ |
| 442 | } |
| 443 | |
Pau Espin Pedrol | fd1fbdb | 2021-03-11 16:59:50 +0100 | [diff] [blame] | 444 | /* polling for next uplink block */ |
| 445 | poll_fn = rts_next_fn(fn, block_nr); |
Pau Espin Pedrol | 7bd92a3 | 2021-03-24 13:14:09 +0100 | [diff] [blame] | 446 | /* check for sba */ |
| 447 | if ((sba = pdch_ulc_get_sba(pdch->ulc, poll_fn))) { |
| 448 | LOGPDCH(pdch, DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: " |
| 449 | "FN=%d block_nr=%d scheduling free USF for " |
| 450 | "single block allocation at FN=%d\n", fn, block_nr, sba->fn); |
| 451 | /* else, check uplink resource for polling */ |
| 452 | } else if ((poll_tbf = pdch_ulc_get_tbf_poll(pdch->ulc, poll_fn))) { |
Pau Espin Pedrol | 6325423 | 2021-05-11 14:04:33 +0200 | [diff] [blame] | 453 | LOGPDCH(pdch, DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: FN=%d " |
| 454 | "block_nr=%d scheduling free USF for polling at FN=%d of %s\n", |
| 455 | fn, block_nr, poll_fn, tbf_name(poll_tbf)); |
Pau Espin Pedrol | 7bd92a3 | 2021-03-24 13:14:09 +0100 | [diff] [blame] | 456 | /* If POLL TBF is UL and already has a USF assigned on this TS, |
| 457 | * let's set its USF in the DL msg. This is not really needed, |
| 458 | * but it helps understand better the flow when looking at |
| 459 | * pcaps. */ |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 460 | if (poll_tbf->direction == GPRS_RLCMAC_UL_TBF && tbf_as_ul_tbf(poll_tbf)->m_usf[ts] != USF_INVALID) |
| 461 | usf_tbf = tbf_as_ul_tbf(poll_tbf); |
Pau Espin Pedrol | 7bd92a3 | 2021-03-24 13:14:09 +0100 | [diff] [blame] | 462 | /* else, search for uplink tbf */ |
Pau Espin Pedrol | 6325423 | 2021-05-11 14:04:33 +0200 | [diff] [blame] | 463 | } else if ((usf_tbf = sched_select_uplink(pdch, require_gprs_only))) { |
| 464 | LOGPDCH(pdch, DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: FN=%d " |
| 465 | "block_nr=%d scheduling USF=%d for %s, expect answer on UL FN=%d\n", |
| 466 | fn, block_nr, usf_tbf->m_usf[pdch->ts_no], tbf_name(usf_tbf), poll_fn); |
Pau Espin Pedrol | c1f38c7 | 2021-03-24 14:06:15 +0100 | [diff] [blame] | 467 | pdch_ulc_reserve_tbf_usf(pdch->ulc, poll_fn, usf_tbf); |
Alexander Couzens | 9736d00 | 2016-05-18 16:41:03 +0200 | [diff] [blame] | 468 | } |
Pau Espin Pedrol | 7bd92a3 | 2021-03-24 13:14:09 +0100 | [diff] [blame] | 469 | /* If MS selected for USF is GPRS-only, then it will only be |
Pau Espin Pedrol | c4fe1f9 | 2021-08-25 14:35:27 +0200 | [diff] [blame] | 470 | * able to read USF if dl block uses GMSK (CS1-4, MCS1-4) */ |
Pau Espin Pedrol | 7bd92a3 | 2021-03-24 13:14:09 +0100 | [diff] [blame] | 471 | if (usf_tbf && req_mcs_kind == EGPRS && ms_mode(usf_tbf->ms()) != EGPRS) |
| 472 | req_mcs_kind = EGPRS_GMSK; |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 473 | |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 474 | get_ctrl_msg_tbf_candidates(pdch, &tbf_cand); |
Pau Espin Pedrol | fd1fbdb | 2021-03-11 16:59:50 +0100 | [diff] [blame] | 475 | |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 476 | /* Prio 1: select control message */ |
Pau Espin Pedrol | 3973eb5 | 2021-03-03 20:47:07 +0100 | [diff] [blame] | 477 | if ((msg = sched_select_ctrl_msg(pdch, fn, block_nr, &tbf_cand))) { |
Vadim Yanitskiy | c2eb4b7 | 2022-10-04 02:57:00 +0700 | [diff] [blame] | 478 | gsmtap_cat = PCU_GSMTAP_C_DL_CTRL; |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 479 | } |
| 480 | /* Prio 2: select data message for downlink */ |
Pau Espin Pedrol | e080808 | 2021-10-11 17:42:33 +0200 | [diff] [blame] | 481 | else if((msg = sched_select_dl_data_msg(bts, pdch, fn, block_nr, req_mcs_kind, &tx_is_egprs))) { |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 482 | gsmtap_cat = tx_is_egprs ? PCU_GSMTAP_C_DL_DATA_EGPRS : |
| 483 | PCU_GSMTAP_C_DL_DATA_GPRS; |
| 484 | } |
Pau Espin Pedrol | a89a238 | 2021-08-25 16:49:48 +0200 | [diff] [blame] | 485 | /* Prio 3: send dummy control message if need to poll or USF */ |
| 486 | else { |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 487 | /* If there's no TBF attached to this PDCH, we can submit an empty |
| 488 | * data_req since there's nothing to transmit nor to poll/USF. This |
| 489 | * way we help BTS energy saving (on TRX!=C0) by sending nothing |
Pau Espin Pedrol | a89a238 | 2021-08-25 16:49:48 +0200 | [diff] [blame] | 490 | * instead of a dummy block. The early return is done here and |
| 491 | * not at the start of the function because the condition below |
| 492 | * (num_tbfs==0) may not be enough, because temporary dummy TBFs |
| 493 | * created to send Imm Ass Rej (see handle_tbf_reject()) don't |
| 494 | * have a TFI assigned and hence are not attached to the PDCH |
| 495 | * TS, so they don't show up in the count below. |
| 496 | */ |
| 497 | const unsigned num_tbfs = pdch->num_tbfs(GPRS_RLCMAC_DL_TBF) |
| 498 | + pdch->num_tbfs(GPRS_RLCMAC_UL_TBF); |
Pau Espin Pedrol | 0e3083d | 2021-09-17 17:35:34 +0200 | [diff] [blame] | 499 | bool skip_idle = (num_tbfs == 0); |
| 500 | #ifdef ENABLE_DIRECT_PHY |
| 501 | /* In DIRECT_PHY mode we want to always submit something to L1 in |
| 502 | * TRX0, since BTS is not preparing dummy bursts on idle TS for us */ |
| 503 | skip_idle = skip_idle && trx != 0; |
| 504 | #endif |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 505 | if (!skip_idle && (msg = sched_dummy())) { |
Pau Espin Pedrol | a89a238 | 2021-08-25 16:49:48 +0200 | [diff] [blame] | 506 | /* increase counter */ |
| 507 | gsmtap_cat = PCU_GSMTAP_C_DL_DUMMY; |
| 508 | } else { |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 509 | msg = NULL; /* submit empty frame */ |
Pau Espin Pedrol | a89a238 | 2021-08-25 16:49:48 +0200 | [diff] [blame] | 510 | } |
Alexander Couzens | 2cb1547 | 2016-05-18 16:43:10 +0200 | [diff] [blame] | 511 | } |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 512 | |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 513 | if (tx_is_egprs && pdch->has_gprs_only_tbf_attached()) { |
| 514 | pdch->fn_without_cs14 += 1; |
| 515 | } else { |
| 516 | pdch->fn_without_cs14 = 0; |
| 517 | } |
| 518 | |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 519 | /* Used to measure the leak rate, count all blocks */ |
| 520 | gprs_bssgp_update_frames_sent(); |
| 521 | |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 522 | if (msg) { |
| 523 | /* msg is now available */ |
| 524 | bts_do_rate_ctr_add(bts, CTR_RLC_DL_BYTES, msgb_length(msg)); |
Pau Espin Pedrol | 4c5a7d3 | 2020-11-16 14:23:29 +0100 | [diff] [blame] | 525 | |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 526 | /* set USF */ |
| 527 | OSMO_ASSERT(msgb_length(msg) > 0); |
| 528 | usf = usf_tbf ? usf_tbf->m_usf[ts] : USF_UNUSED; |
| 529 | msg->data[0] = (msg->data[0] & 0xf8) | usf; |
| 530 | |
| 531 | /* Send to GSMTAP */ |
| 532 | tap_n_acc(msg, bts, trx, ts, fn, gsmtap_cat); |
| 533 | } |
| 534 | |
| 535 | /* send PDTCH/PACCH to L1. msg=NULL accepted too (idle block) */ |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 536 | pcu_l1if_tx_pdtch(msg, bts, trx, ts, bts->trx[trx].arfcn, fn, block_nr); |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 537 | |
| 538 | return 0; |
| 539 | } |