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