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 | */ |
| 19 | |
| 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> |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 25 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 26 | static uint32_t sched_poll(struct gprs_rlcmac_bts *bts, |
| 27 | uint8_t trx, uint8_t ts, uint32_t fn, uint8_t block_nr, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 28 | struct gprs_rlcmac_tbf **poll_tbf, |
Andreas Eversberg | ef42540 | 2012-07-25 15:47:03 +0200 | [diff] [blame] | 29 | struct gprs_rlcmac_tbf **ul_ass_tbf, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 30 | struct gprs_rlcmac_tbf **dl_ass_tbf, |
Andreas Eversberg | ef42540 | 2012-07-25 15:47:03 +0200 | [diff] [blame] | 31 | struct gprs_rlcmac_tbf **ul_ack_tbf) |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 32 | { |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 33 | struct gprs_rlcmac_tbf *tbf; |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 34 | uint32_t poll_fn; |
Andreas Eversberg | e6228b3 | 2012-07-03 13:36:03 +0200 | [diff] [blame] | 35 | |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 36 | /* check special TBF for events */ |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 37 | poll_fn = fn + 4; |
| 38 | if ((block_nr % 3) == 2) |
| 39 | poll_fn ++; |
| 40 | poll_fn = poll_fn % 2715648; |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 41 | llist_for_each_entry(tbf, &bts->ul_tbfs, list) { |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 42 | /* this trx, this ts */ |
Holger Hans Peter Freyther | ec80f82 | 2013-10-27 13:44:37 +0100 | [diff] [blame] | 43 | if (tbf->trx->trx_no != trx || tbf->control_ts != ts) |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 44 | continue; |
| 45 | /* polling for next uplink block */ |
| 46 | if (tbf->poll_state == GPRS_RLCMAC_POLL_SCHED |
| 47 | && tbf->poll_fn == poll_fn) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 48 | *poll_tbf = tbf; |
Andreas Eversberg | ee31b78 | 2012-07-15 16:27:01 +0200 | [diff] [blame] | 49 | if (tbf->ul_ack_state == GPRS_RLCMAC_UL_ACK_SEND_ACK) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 50 | *ul_ack_tbf = tbf; |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 51 | if (tbf->dl_ass_state == GPRS_RLCMAC_DL_ASS_SEND_ASS) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 52 | *dl_ass_tbf = tbf; |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 53 | if (tbf->ul_ass_state == GPRS_RLCMAC_UL_ASS_SEND_ASS) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 54 | *ul_ass_tbf = tbf; |
Holger Hans Peter Freyther | 45396a9 | 2013-10-16 19:31:57 +0200 | [diff] [blame] | 55 | #warning "Is this supposed to be fair? The last TBF for each wins? Maybe use llist_add_tail and skip once we have all states?" |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 56 | } |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 57 | llist_for_each_entry(tbf, &bts->dl_tbfs, list) { |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 58 | /* this trx, this ts */ |
Holger Hans Peter Freyther | ec80f82 | 2013-10-27 13:44:37 +0100 | [diff] [blame] | 59 | if (tbf->trx->trx_no != trx || tbf->control_ts != ts) |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 60 | continue; |
| 61 | /* polling for next uplink block */ |
| 62 | if (tbf->poll_state == GPRS_RLCMAC_POLL_SCHED |
| 63 | && tbf->poll_fn == poll_fn) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 64 | *poll_tbf = tbf; |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 65 | if (tbf->dl_ass_state == GPRS_RLCMAC_DL_ASS_SEND_ASS) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 66 | *dl_ass_tbf = tbf; |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 67 | if (tbf->ul_ass_state == GPRS_RLCMAC_UL_ASS_SEND_ASS) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 68 | *ul_ass_tbf = tbf; |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 71 | return poll_fn; |
| 72 | } |
| 73 | |
Holger Hans Peter Freyther | 40fc8f9 | 2013-11-23 23:03:14 +0100 | [diff] [blame] | 74 | static uint8_t sched_select_uplink(uint8_t trx, uint8_t ts, uint32_t fn, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 75 | uint8_t block_nr, struct gprs_rlcmac_pdch *pdch) |
| 76 | { |
| 77 | struct gprs_rlcmac_tbf *tbf; |
| 78 | uint8_t usf = 0x07; |
| 79 | uint8_t i, tfi; |
| 80 | |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 81 | /* select uplink resource */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 82 | for (i = 0, tfi = pdch->next_ul_tfi; i < 32; |
| 83 | i++, tfi = (tfi + 1) & 31) { |
| 84 | tbf = pdch->ul_tbf[tfi]; |
| 85 | /* no TBF for this tfi, go next */ |
| 86 | if (!tbf) |
| 87 | continue; |
Holger Hans Peter Freyther | 483f77a | 2013-10-16 16:33:00 +0200 | [diff] [blame] | 88 | /* no UL resources needed, go next */ |
| 89 | /* we don't need to give resources in FINISHED state, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 90 | * because we have received all blocks and only poll |
| 91 | * for packet control ack. */ |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 92 | if (tbf->state_is_not(GPRS_RLCMAC_FLOW)) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 93 | continue; |
| 94 | |
| 95 | /* use this USF */ |
| 96 | usf = tbf->dir.ul.usf[ts]; |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 97 | LOGP(DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: TRX=%d " |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 98 | "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] | 99 | "required uplink resource of UL TFI=%d\n", trx, ts, fn, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 100 | block_nr, usf, tfi); |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 101 | /* next TBF to handle resource is the next one */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 102 | pdch->next_ul_tfi = (tfi + 1) & 31; |
| 103 | break; |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 106 | return usf; |
| 107 | } |
| 108 | |
Holger Hans Peter Freyther | aadfc2e | 2013-12-25 15:19:54 +0100 | [diff] [blame] | 109 | static struct msgb *sched_select_ctrl_msg( |
Holger Hans Peter Freyther | ae947fc | 2013-10-17 13:29:03 +0200 | [diff] [blame] | 110 | uint8_t trx, uint8_t ts, uint32_t fn, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 111 | uint8_t block_nr, struct gprs_rlcmac_pdch *pdch, |
Andreas Eversberg | ef42540 | 2012-07-25 15:47:03 +0200 | [diff] [blame] | 112 | struct gprs_rlcmac_tbf *ul_ass_tbf, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 113 | struct gprs_rlcmac_tbf *dl_ass_tbf, |
Andreas Eversberg | ef42540 | 2012-07-25 15:47:03 +0200 | [diff] [blame] | 114 | struct gprs_rlcmac_tbf *ul_ack_tbf) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 115 | { |
| 116 | struct msgb *msg = NULL; |
| 117 | struct gprs_rlcmac_tbf *tbf = NULL; |
Holger Hans Peter Freyther | 705653b | 2013-11-26 16:39:28 +0100 | [diff] [blame] | 118 | struct gprs_rlcmac_tbf *next_list[3] = { ul_ass_tbf, dl_ass_tbf, ul_ack_tbf }; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 119 | |
Holger Hans Peter Freyther | 705653b | 2013-11-26 16:39:28 +0100 | [diff] [blame] | 120 | for (size_t i = 0; i < ARRAY_SIZE(next_list); ++i) { |
| 121 | tbf = next_list[(pdch->next_ctrl_prio + i) % 3]; |
| 122 | if (!tbf) |
| 123 | continue; |
| 124 | |
| 125 | if (tbf == ul_ass_tbf) |
| 126 | msg = tbf->create_ul_ass(fn); |
| 127 | else if (tbf == dl_ass_tbf) |
| 128 | msg = tbf->create_dl_ass(fn); |
| 129 | else |
| 130 | msg = tbf->create_ul_ack(fn); |
| 131 | |
| 132 | if (!msg) { |
| 133 | tbf = NULL; |
| 134 | continue; |
| 135 | } |
| 136 | |
| 137 | pdch->next_ctrl_prio += i + 1; |
| 138 | pdch->next_ctrl_prio %= 3; |
| 139 | break; |
Andreas Eversberg | ee31b78 | 2012-07-15 16:27:01 +0200 | [diff] [blame] | 140 | } |
Holger Hans Peter Freyther | 705653b | 2013-11-26 16:39:28 +0100 | [diff] [blame] | 141 | |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 142 | /* any message */ |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 143 | if (msg) { |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 144 | tbf->rotate_in_list(); |
Andreas Eversberg | 592e04a | 2012-07-15 06:25:37 +0200 | [diff] [blame] | 145 | LOGP(DRLCMACSCHED, LOGL_DEBUG, "Scheduling control " |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 146 | "message at RTS for %s (TRX=%d, TS=%d)\n", |
| 147 | tbf_name(tbf), trx, ts); |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 148 | return msg; |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 149 | } |
Andreas Eversberg | 3b7461c | 2012-07-20 11:19:59 +0200 | [diff] [blame] | 150 | /* schedule PACKET PAGING REQUEST */ |
Holger Hans Peter Freyther | 24e98d0 | 2013-10-19 18:15:44 +0200 | [diff] [blame] | 151 | msg = pdch->packet_paging_request(); |
Andreas Eversberg | 07e97cf | 2012-08-07 16:00:56 +0200 | [diff] [blame] | 152 | if (msg) { |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 153 | LOGP(DRLCMACSCHED, LOGL_DEBUG, "Scheduling paging request " |
| 154 | "message at RTS for (TRX=%d, TS=%d)\n", trx, ts); |
Andreas Eversberg | 07e97cf | 2012-08-07 16:00:56 +0200 | [diff] [blame] | 155 | return msg; |
| 156 | } |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 157 | |
Andreas Eversberg | 07e97cf | 2012-08-07 16:00:56 +0200 | [diff] [blame] | 158 | return NULL; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 159 | } |
| 160 | |
Holger Hans Peter Freyther | 4ffc260 | 2013-10-17 15:21:10 +0200 | [diff] [blame] | 161 | static struct msgb *sched_select_downlink(struct gprs_rlcmac_bts *bts, |
| 162 | uint8_t trx, uint8_t ts, uint32_t fn, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 163 | uint8_t block_nr, struct gprs_rlcmac_pdch *pdch) |
| 164 | { |
| 165 | struct msgb *msg = NULL; |
| 166 | struct gprs_rlcmac_tbf *tbf = NULL; |
| 167 | uint8_t i, tfi; |
| 168 | |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 169 | /* select downlink resource */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 170 | for (i = 0, tfi = pdch->next_dl_tfi; i < 32; |
| 171 | i++, tfi = (tfi + 1) & 31) { |
| 172 | tbf = pdch->dl_tbf[tfi]; |
| 173 | /* no TBF for this tfi, go next */ |
| 174 | if (!tbf) |
| 175 | continue; |
| 176 | /* no DL TBF, go next */ |
| 177 | if (tbf->direction != GPRS_RLCMAC_DL_TBF) |
| 178 | continue; |
Holger Hans Peter Freyther | 483f77a | 2013-10-16 16:33:00 +0200 | [diff] [blame] | 179 | /* no DL resources needed, go next */ |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 180 | if (tbf->state_is_not(GPRS_RLCMAC_FLOW) |
| 181 | && tbf->state_is_not(GPRS_RLCMAC_FINISHED)) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 182 | continue; |
| 183 | |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 184 | /* waiting for CCCH IMM.ASS confirm */ |
| 185 | if (tbf->dir.dl.wait_confirm) |
| 186 | continue; |
| 187 | |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 188 | LOGP(DRLCMACSCHED, LOGL_DEBUG, "Scheduling data message at " |
Holger Hans Peter Freyther | 15bb1a2 | 2013-10-27 12:30:46 +0100 | [diff] [blame] | 189 | "RTS for DL TFI=%d (TRX=%d, TS=%d)\n", tfi, trx, ts); |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 190 | /* next TBF to handle resource is the next one */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 191 | pdch->next_dl_tfi = (tfi + 1) & 31; |
| 192 | /* generate DL data block */ |
Holger Hans Peter Freyther | 61a0a04 | 2013-10-26 21:48:38 +0200 | [diff] [blame] | 193 | msg = tbf->create_dl_acked_block(fn, ts); |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 194 | break; |
Andreas Eversberg | 3b7461c | 2012-07-20 11:19:59 +0200 | [diff] [blame] | 195 | } |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 196 | |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 197 | return msg; |
| 198 | } |
Holger Hans Peter Freyther | 40fc8f9 | 2013-11-23 23:03:14 +0100 | [diff] [blame] | 199 | |
| 200 | static const uint8_t rlcmac_dl_idle[23] = { |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 201 | 0x47, /* control without optional header octets, no polling, USF=111 */ |
| 202 | 0x94, /* dummy downlink control message, paging mode 00 */ |
| 203 | 0x2b, /* no persistance level, 7 bits spare pattern */ |
| 204 | 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, |
| 205 | 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b |
| 206 | }; |
| 207 | |
Holger Hans Peter Freyther | 40fc8f9 | 2013-11-23 23:03:14 +0100 | [diff] [blame] | 208 | static struct msgb *sched_dummy(void) |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 209 | { |
| 210 | struct msgb *msg; |
| 211 | |
| 212 | msg = msgb_alloc(23, "rlcmac_dl_idle"); |
| 213 | if (!msg) |
| 214 | return NULL; |
| 215 | memcpy(msgb_put(msg, 23), rlcmac_dl_idle, 23); |
| 216 | |
| 217 | return msg; |
| 218 | } |
| 219 | |
Holger Hans Peter Freyther | b19d726 | 2013-10-17 18:12:18 +0200 | [diff] [blame] | 220 | int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_bts *bts, |
| 221 | uint8_t trx, uint8_t ts, uint16_t arfcn, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 222 | uint32_t fn, uint8_t block_nr) |
| 223 | { |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 224 | struct gprs_rlcmac_pdch *pdch; |
| 225 | struct gprs_rlcmac_tbf *poll_tbf = NULL, *dl_ass_tbf = NULL, |
| 226 | *ul_ass_tbf = NULL, *ul_ack_tbf = NULL; |
| 227 | uint8_t usf = 0x7; |
| 228 | struct msgb *msg = NULL; |
Andreas Eversberg | 07e97cf | 2012-08-07 16:00:56 +0200 | [diff] [blame] | 229 | uint32_t poll_fn, sba_fn; |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 230 | |
Holger Hans Peter Freyther | 5458765 | 2013-10-20 16:48:56 +0200 | [diff] [blame] | 231 | #warning "ARFCN... it is already in the TRX..... is it consistent with it?" |
| 232 | |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 233 | if (trx >= 8 || ts >= 8) |
| 234 | return -EINVAL; |
| 235 | pdch = &bts->trx[trx].pdch[ts]; |
| 236 | |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 237 | if (!pdch->is_enabled()) { |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 238 | LOGP(DRLCMACSCHED, LOGL_ERROR, "Received RTS on disabled PDCH: " |
| 239 | "TRX=%d TS=%d\n", trx, ts); |
| 240 | return -EIO; |
| 241 | } |
| 242 | |
| 243 | /* store last frame number of RTS */ |
| 244 | pdch->last_rts_fn = fn; |
| 245 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 246 | poll_fn = sched_poll(bts, trx, ts, fn, block_nr, &poll_tbf, &ul_ass_tbf, |
Andreas Eversberg | ef42540 | 2012-07-25 15:47:03 +0200 | [diff] [blame] | 247 | &dl_ass_tbf, &ul_ack_tbf); |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 248 | /* check uplink resource for polling */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 249 | if (poll_tbf) |
| 250 | LOGP(DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: TRX=%d " |
| 251 | "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] | 252 | "polling at FN=%d of %s\n", trx, ts, fn, |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 253 | block_nr, poll_fn, |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 254 | tbf_name(poll_tbf)); |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 255 | /* use free USF */ |
Andreas Eversberg | 07e97cf | 2012-08-07 16:00:56 +0200 | [diff] [blame] | 256 | /* else. check for sba */ |
Holger Hans Peter Freyther | cedf890 | 2013-10-19 20:47:12 +0200 | [diff] [blame] | 257 | else if ((sba_fn = bts->bts->sba()->sched(trx, ts, fn, block_nr) != 0xffffffff)) |
Andreas Eversberg | 07e97cf | 2012-08-07 16:00:56 +0200 | [diff] [blame] | 258 | LOGP(DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: TRX=%d " |
| 259 | "TS=%d FN=%d block_nr=%d scheduling free USF for " |
| 260 | "single block allocation at FN=%d\n", trx, ts, fn, |
| 261 | block_nr, sba_fn); |
| 262 | /* use free USF */ |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 263 | /* else, we search for uplink resource */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 264 | else |
| 265 | usf = sched_select_uplink(trx, ts, fn, block_nr, pdch); |
| 266 | |
| 267 | /* Prio 1: select control message */ |
Holger Hans Peter Freyther | aadfc2e | 2013-12-25 15:19:54 +0100 | [diff] [blame] | 268 | msg = sched_select_ctrl_msg(trx, ts, fn, block_nr, pdch, ul_ass_tbf, |
Andreas Eversberg | ef42540 | 2012-07-25 15:47:03 +0200 | [diff] [blame] | 269 | dl_ass_tbf, ul_ack_tbf); |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 270 | |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 271 | /* Prio 2: select data message for downlink */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 272 | if (!msg) |
Holger Hans Peter Freyther | 4ffc260 | 2013-10-17 15:21:10 +0200 | [diff] [blame] | 273 | msg = sched_select_downlink(bts, trx, ts, fn, block_nr, pdch); |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 274 | |
| 275 | /* Prio 3: send dummy contol message */ |
Andreas Eversberg | d6a8db6 | 2012-07-25 08:38:21 +0200 | [diff] [blame] | 276 | if (!msg) |
| 277 | msg = sched_dummy(); |
| 278 | |
| 279 | if (!msg) |
| 280 | return -ENOMEM; |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 281 | /* msg is now available */ |
| 282 | |
| 283 | /* set USF */ |
| 284 | msg->data[0] = (msg->data[0] & 0xf8) | usf; |
| 285 | |
Andreas Eversberg | 39621c4 | 2012-06-27 15:36:27 +0200 | [diff] [blame] | 286 | /* send PDTCH/PACCH to L1 */ |
| 287 | pcu_l1if_tx_pdtch(msg, trx, ts, arfcn, fn, block_nr); |
| 288 | |
| 289 | return 0; |
| 290 | } |