2012-06-27 13:36:27 +00:00
|
|
|
/* PDCH scheduler
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2019-09-25 15:48:35 +00:00
|
|
|
|
2012-06-27 13:36:27 +00:00
|
|
|
#include <gprs_bssgp_pcu.h>
|
|
|
|
#include <gprs_rlcmac.h>
|
|
|
|
#include <pcu_l1_if.h>
|
2013-10-17 15:01:54 +00:00
|
|
|
#include <bts.h>
|
2013-10-16 15:42:31 +00:00
|
|
|
#include <tbf.h>
|
2018-01-26 12:31:42 +00:00
|
|
|
#include <gprs_debug.h>
|
|
|
|
#include <gprs_ms.h>
|
|
|
|
#include <rlc.h>
|
|
|
|
#include <sba.h>
|
2018-02-19 16:17:28 +00:00
|
|
|
#include <pdch.h>
|
2015-03-20 13:26:05 +00:00
|
|
|
#include "pcu_utils.h"
|
|
|
|
|
2018-01-26 12:31:42 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <osmocom/core/gsmtap.h>
|
|
|
|
}
|
|
|
|
|
2015-12-28 18:15:40 +00:00
|
|
|
static uint32_t sched_poll(BTS *bts,
|
2013-10-19 19:10:38 +00:00
|
|
|
uint8_t trx, uint8_t ts, uint32_t fn, uint8_t block_nr,
|
2012-07-25 06:38:21 +00:00
|
|
|
struct gprs_rlcmac_tbf **poll_tbf,
|
2012-07-25 13:47:03 +00:00
|
|
|
struct gprs_rlcmac_tbf **ul_ass_tbf,
|
2012-07-25 06:38:21 +00:00
|
|
|
struct gprs_rlcmac_tbf **dl_ass_tbf,
|
2014-08-07 12:58:59 +00:00
|
|
|
struct gprs_rlcmac_ul_tbf **ul_ack_tbf)
|
2012-06-27 13:36:27 +00:00
|
|
|
{
|
2014-08-07 12:58:59 +00:00
|
|
|
struct gprs_rlcmac_ul_tbf *ul_tbf;
|
|
|
|
struct gprs_rlcmac_dl_tbf *dl_tbf;
|
2015-12-28 18:15:40 +00:00
|
|
|
LListHead<gprs_rlcmac_tbf> *pos;
|
2012-06-27 13:36:27 +00:00
|
|
|
uint32_t poll_fn;
|
2012-07-03 11:36:03 +00:00
|
|
|
|
2012-07-15 04:25:37 +00:00
|
|
|
/* check special TBF for events */
|
2012-06-27 13:36:27 +00:00
|
|
|
poll_fn = fn + 4;
|
|
|
|
if ((block_nr % 3) == 2)
|
|
|
|
poll_fn ++;
|
2017-05-16 14:10:45 +00:00
|
|
|
poll_fn = poll_fn % GSM_MAX_FN;
|
2015-12-28 18:15:40 +00:00
|
|
|
llist_for_each(pos, &bts->ul_tbfs()) {
|
|
|
|
ul_tbf = as_ul_tbf(pos->entry());
|
|
|
|
OSMO_ASSERT(ul_tbf);
|
2012-07-15 04:25:37 +00:00
|
|
|
/* this trx, this ts */
|
2016-01-22 16:41:33 +00:00
|
|
|
if (ul_tbf->trx->trx_no != trx || !ul_tbf->is_control_ts(ts))
|
2012-07-15 04:25:37 +00:00
|
|
|
continue;
|
|
|
|
/* polling for next uplink block */
|
2018-01-24 10:00:17 +00:00
|
|
|
if (ul_tbf->poll_scheduled() && ul_tbf->poll_fn == poll_fn)
|
2014-08-07 12:58:59 +00:00
|
|
|
*poll_tbf = ul_tbf;
|
2018-01-23 19:16:23 +00:00
|
|
|
if (ul_tbf->ul_ack_state_is(GPRS_RLCMAC_UL_ACK_SEND_ACK))
|
2014-08-07 12:58:59 +00:00
|
|
|
*ul_ack_tbf = ul_tbf;
|
2018-01-23 19:09:06 +00:00
|
|
|
if (ul_tbf->dl_ass_state_is(GPRS_RLCMAC_DL_ASS_SEND_ASS))
|
2014-08-07 12:58:59 +00:00
|
|
|
*dl_ass_tbf = ul_tbf;
|
2018-01-23 19:09:06 +00:00
|
|
|
if (ul_tbf->ul_ass_state_is(GPRS_RLCMAC_UL_ASS_SEND_ASS)
|
|
|
|
|| ul_tbf->ul_ass_state_is(GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ))
|
2014-08-07 12:58:59 +00:00
|
|
|
*ul_ass_tbf = ul_tbf;
|
2017-09-01 12:36:44 +00:00
|
|
|
/* FIXME: Is this supposed to be fair? The last TBF for each wins? Maybe use llist_add_tail and skip once we have all
|
|
|
|
states? */
|
2012-06-27 13:36:27 +00:00
|
|
|
}
|
2015-12-28 18:15:40 +00:00
|
|
|
llist_for_each(pos, &bts->dl_tbfs()) {
|
|
|
|
dl_tbf = as_dl_tbf(pos->entry());
|
|
|
|
OSMO_ASSERT(dl_tbf);
|
2012-07-15 04:25:37 +00:00
|
|
|
/* this trx, this ts */
|
2016-01-22 16:41:33 +00:00
|
|
|
if (dl_tbf->trx->trx_no != trx || !dl_tbf->is_control_ts(ts))
|
2012-07-15 04:25:37 +00:00
|
|
|
continue;
|
|
|
|
/* polling for next uplink block */
|
2018-01-24 10:00:17 +00:00
|
|
|
if (dl_tbf->poll_scheduled() && dl_tbf->poll_fn == poll_fn)
|
2014-08-07 12:58:59 +00:00
|
|
|
*poll_tbf = dl_tbf;
|
2018-01-23 19:09:06 +00:00
|
|
|
if (dl_tbf->dl_ass_state_is(GPRS_RLCMAC_DL_ASS_SEND_ASS))
|
2014-08-07 12:58:59 +00:00
|
|
|
*dl_ass_tbf = dl_tbf;
|
2018-01-23 19:09:06 +00:00
|
|
|
if (dl_tbf->ul_ass_state_is(GPRS_RLCMAC_UL_ASS_SEND_ASS)
|
|
|
|
|| dl_tbf->ul_ass_state_is(GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ))
|
2014-08-07 12:58:59 +00:00
|
|
|
*ul_ass_tbf = dl_tbf;
|
2012-07-15 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2012-07-25 06:38:21 +00:00
|
|
|
return poll_fn;
|
|
|
|
}
|
|
|
|
|
2013-11-23 22:03:14 +00:00
|
|
|
static uint8_t sched_select_uplink(uint8_t trx, uint8_t ts, uint32_t fn,
|
2012-07-25 06:38:21 +00:00
|
|
|
uint8_t block_nr, struct gprs_rlcmac_pdch *pdch)
|
|
|
|
{
|
2014-08-07 12:58:59 +00:00
|
|
|
struct gprs_rlcmac_ul_tbf *tbf;
|
2012-07-25 06:38:21 +00:00
|
|
|
uint8_t usf = 0x07;
|
|
|
|
uint8_t i, tfi;
|
|
|
|
|
2013-10-27 09:38:31 +00:00
|
|
|
/* select uplink resource */
|
2012-07-25 06:38:21 +00:00
|
|
|
for (i = 0, tfi = pdch->next_ul_tfi; i < 32;
|
|
|
|
i++, tfi = (tfi + 1) & 31) {
|
2014-06-04 12:56:09 +00:00
|
|
|
tbf = pdch->ul_tbf_by_tfi(tfi);
|
2012-07-25 06:38:21 +00:00
|
|
|
/* no TBF for this tfi, go next */
|
|
|
|
if (!tbf)
|
|
|
|
continue;
|
2013-10-16 14:33:00 +00:00
|
|
|
/* no UL resources needed, go next */
|
|
|
|
/* we don't need to give resources in FINISHED state,
|
2012-07-25 06:38:21 +00:00
|
|
|
* because we have received all blocks and only poll
|
|
|
|
* for packet control ack. */
|
2013-10-16 16:33:18 +00:00
|
|
|
if (tbf->state_is_not(GPRS_RLCMAC_FLOW))
|
2012-07-25 06:38:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* use this USF */
|
2014-08-07 13:49:21 +00:00
|
|
|
usf = tbf->m_usf[ts];
|
2012-06-27 13:36:27 +00:00
|
|
|
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: TRX=%d "
|
2012-07-25 06:38:21 +00:00
|
|
|
"TS=%d FN=%d block_nr=%d scheduling USF=%d for "
|
2013-10-27 11:30:46 +00:00
|
|
|
"required uplink resource of UL TFI=%d\n", trx, ts, fn,
|
2012-07-25 06:38:21 +00:00
|
|
|
block_nr, usf, tfi);
|
2013-10-27 09:38:31 +00:00
|
|
|
/* next TBF to handle resource is the next one */
|
2012-07-25 06:38:21 +00:00
|
|
|
pdch->next_ul_tfi = (tfi + 1) & 31;
|
|
|
|
break;
|
2012-06-27 13:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-07-25 06:38:21 +00:00
|
|
|
return usf;
|
|
|
|
}
|
|
|
|
|
2019-09-05 15:13:33 +00:00
|
|
|
struct msgb *sched_app_info(struct gprs_rlcmac_tbf *tbf) {
|
|
|
|
struct gprs_rlcmac_bts *bts_data;
|
|
|
|
struct msgb *msg = NULL;
|
|
|
|
|
|
|
|
if (!tbf || !tbf->ms()->app_info_pending)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
bts_data = BTS::main_bts()->bts_data();
|
|
|
|
|
|
|
|
if (bts_data->app_info) {
|
|
|
|
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Sending Packet Application Information message\n");
|
|
|
|
msg = msgb_copy(bts_data->app_info, "app_info_msg_sched");
|
|
|
|
} else
|
|
|
|
LOGP(DRLCMACSCHED, LOGL_ERROR, "MS has app_info_pending flag set, but no Packet Application Information"
|
|
|
|
" message stored in BTS!\n");
|
|
|
|
|
|
|
|
tbf->ms()->app_info_pending = false;
|
|
|
|
bts_data->app_info_pending--;
|
|
|
|
|
|
|
|
if (!bts_data->app_info_pending) {
|
|
|
|
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Packet Application Information successfully sent to all MS with active"
|
|
|
|
" TBF\n");
|
|
|
|
msgb_free(bts_data->app_info);
|
|
|
|
bts_data->app_info = NULL;
|
|
|
|
}
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2013-12-25 14:19:54 +00:00
|
|
|
static struct msgb *sched_select_ctrl_msg(
|
2013-10-17 11:29:03 +00:00
|
|
|
uint8_t trx, uint8_t ts, uint32_t fn,
|
2012-07-25 06:38:21 +00:00
|
|
|
uint8_t block_nr, struct gprs_rlcmac_pdch *pdch,
|
2012-07-25 13:47:03 +00:00
|
|
|
struct gprs_rlcmac_tbf *ul_ass_tbf,
|
2012-07-25 06:38:21 +00:00
|
|
|
struct gprs_rlcmac_tbf *dl_ass_tbf,
|
2014-08-07 12:58:59 +00:00
|
|
|
struct gprs_rlcmac_ul_tbf *ul_ack_tbf)
|
2012-07-25 06:38:21 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg = NULL;
|
|
|
|
struct gprs_rlcmac_tbf *tbf = NULL;
|
2013-11-26 15:39:28 +00:00
|
|
|
struct gprs_rlcmac_tbf *next_list[3] = { ul_ass_tbf, dl_ass_tbf, ul_ack_tbf };
|
2012-07-25 06:38:21 +00:00
|
|
|
|
2019-09-05 15:13:33 +00:00
|
|
|
/* Send Packet Application Information first (ETWS primary notifications) */
|
|
|
|
msg = sched_app_info(dl_ass_tbf);
|
2013-11-26 15:39:28 +00:00
|
|
|
|
2019-09-05 15:13:33 +00:00
|
|
|
if (!msg) {
|
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(next_list); ++i) {
|
|
|
|
tbf = next_list[(pdch->next_ctrl_prio + i) % 3];
|
|
|
|
if (!tbf)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assignments for the same direction have lower precedence,
|
|
|
|
* because they may kill the TBF when the CONTROL ACK is
|
|
|
|
* received, thus preventing the others from being processed.
|
|
|
|
*/
|
|
|
|
if (tbf == ul_ass_tbf && tbf->ul_ass_state_is(GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ))
|
2016-11-11 11:45:10 +00:00
|
|
|
msg = ul_ass_tbf->create_packet_access_reject();
|
2019-09-05 15:13:33 +00:00
|
|
|
else if (tbf == ul_ass_tbf && tbf->direction ==
|
|
|
|
GPRS_RLCMAC_DL_TBF)
|
|
|
|
if (tbf->ul_ass_state_is(GPRS_RLCMAC_UL_ASS_SEND_ASS_REJ))
|
|
|
|
msg = ul_ass_tbf->create_packet_access_reject();
|
|
|
|
else
|
|
|
|
msg = ul_ass_tbf->create_ul_ass(fn, ts);
|
|
|
|
else if (tbf == dl_ass_tbf && tbf->direction == GPRS_RLCMAC_UL_TBF)
|
|
|
|
msg = dl_ass_tbf->create_dl_ass(fn, ts);
|
|
|
|
else if (tbf == ul_ack_tbf)
|
|
|
|
msg = ul_ack_tbf->create_ul_ack(fn, ts);
|
2013-11-26 15:39:28 +00:00
|
|
|
|
2019-09-05 15:13:33 +00:00
|
|
|
if (!msg) {
|
|
|
|
tbf = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdch->next_ctrl_prio += 1;
|
|
|
|
pdch->next_ctrl_prio %= 3;
|
|
|
|
break;
|
|
|
|
}
|
2012-07-15 04:25:37 +00:00
|
|
|
}
|
2013-11-26 15:39:28 +00:00
|
|
|
|
2016-02-01 18:42:09 +00:00
|
|
|
if (!msg) {
|
|
|
|
/*
|
|
|
|
* If one of these is left, the response (CONTROL ACK) from the
|
|
|
|
* MS will kill the current TBF, only one of them can be
|
|
|
|
* non-NULL
|
|
|
|
*/
|
|
|
|
if (dl_ass_tbf) {
|
|
|
|
tbf = dl_ass_tbf;
|
|
|
|
msg = dl_ass_tbf->create_dl_ass(fn, ts);
|
|
|
|
} else if (ul_ass_tbf) {
|
|
|
|
tbf = ul_ass_tbf;
|
|
|
|
msg = ul_ass_tbf->create_ul_ass(fn, ts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-25 06:38:21 +00:00
|
|
|
/* any message */
|
2012-07-15 04:25:37 +00:00
|
|
|
if (msg) {
|
fix PACCH paging: don't return early in case of NULL TBF
Commit b78a4a6dfef217c538d45949a6ae725e22a36b05 tried to fix a NULL dereference
error, but apparently was overly eager to return, because it looked like all
code paths would dereference the tbf.
In fact the code path further above, for msg != NULL, has "always" dereferenced
the tbf, but the lower code path, the one effecting the paging, has only
started to dereference tbf since shortly before the overly eager fix: in
da7250ad2c1cd5ddc7d3c6e10435a00b357ef8f7, to "update the dl ctrl msg counter
for ms". It seems that this tbf dereference in the paging path is bogus and the
cause for the segfault that made me write the early exit fix.
Fix that fix:
Do not exit early if tbf == NULL, stay in there to be able to reach the paging
path below.
In case of a message to be sent, assume that tbf is present, and verify: print
an error message and abort if there is a msg but no tbf, so that we will see
the error if I'm wrong there. If a tbf is missing, free the msg.
In case of no message, go on to send pending pagings, but do not attempt to
count ctrl messages for a tbf -- IIUC there will never be a tbf if we're
paging.
This should avoid segfaults while keeping PACCH paging intact.
Tweak a comment for and add a blank line above the paging section.
Related: OS#2176 CID#158969
Change-Id: Ib79f4a945e211a13ac7d1e511cc37b0940ac6202
2017-04-26 23:33:39 +00:00
|
|
|
if (!tbf) {
|
|
|
|
LOGP(DRLCMACSCHED, LOGL_ERROR,
|
|
|
|
"Control message to be scheduled, but no TBF (TRX=%d, TS=%d)\n", trx, ts);
|
|
|
|
msgb_free(msg);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-11-26 12:08:12 +00:00
|
|
|
tbf->rotate_in_list();
|
2012-07-15 04:25:37 +00:00
|
|
|
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Scheduling control "
|
2013-10-27 19:31:47 +00:00
|
|
|
"message at RTS for %s (TRX=%d, TS=%d)\n",
|
|
|
|
tbf_name(tbf), trx, ts);
|
2016-12-16 07:27:18 +00:00
|
|
|
/* Updates the dl ctrl msg counter for ms */
|
|
|
|
tbf->ms()->update_dl_ctrl_msg();
|
2012-07-25 06:38:21 +00:00
|
|
|
return msg;
|
2012-06-27 13:36:27 +00:00
|
|
|
}
|
fix PACCH paging: don't return early in case of NULL TBF
Commit b78a4a6dfef217c538d45949a6ae725e22a36b05 tried to fix a NULL dereference
error, but apparently was overly eager to return, because it looked like all
code paths would dereference the tbf.
In fact the code path further above, for msg != NULL, has "always" dereferenced
the tbf, but the lower code path, the one effecting the paging, has only
started to dereference tbf since shortly before the overly eager fix: in
da7250ad2c1cd5ddc7d3c6e10435a00b357ef8f7, to "update the dl ctrl msg counter
for ms". It seems that this tbf dereference in the paging path is bogus and the
cause for the segfault that made me write the early exit fix.
Fix that fix:
Do not exit early if tbf == NULL, stay in there to be able to reach the paging
path below.
In case of a message to be sent, assume that tbf is present, and verify: print
an error message and abort if there is a msg but no tbf, so that we will see
the error if I'm wrong there. If a tbf is missing, free the msg.
In case of no message, go on to send pending pagings, but do not attempt to
count ctrl messages for a tbf -- IIUC there will never be a tbf if we're
paging.
This should avoid segfaults while keeping PACCH paging intact.
Tweak a comment for and add a blank line above the paging section.
Related: OS#2176 CID#158969
Change-Id: Ib79f4a945e211a13ac7d1e511cc37b0940ac6202
2017-04-26 23:33:39 +00:00
|
|
|
|
|
|
|
/* schedule PACKET PAGING REQUEST, if any are pending */
|
2013-10-19 16:15:44 +00:00
|
|
|
msg = pdch->packet_paging_request();
|
2012-08-07 14:00:56 +00:00
|
|
|
if (msg) {
|
2012-07-25 06:38:21 +00:00
|
|
|
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Scheduling paging request "
|
|
|
|
"message at RTS for (TRX=%d, TS=%d)\n", trx, ts);
|
2012-08-07 14:00:56 +00:00
|
|
|
return msg;
|
|
|
|
}
|
2012-07-25 06:38:21 +00:00
|
|
|
|
2012-08-07 14:00:56 +00:00
|
|
|
return NULL;
|
2012-07-25 06:38:21 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 17:27:32 +00:00
|
|
|
static inline enum tbf_dl_prio tbf_compute_priority(const struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_dl_tbf *tbf,
|
|
|
|
uint8_t ts, uint32_t fn, int age)
|
|
|
|
{
|
|
|
|
const gprs_rlc_dl_window *w = tbf->window();
|
2019-09-09 11:41:00 +00:00
|
|
|
unsigned long msecs_t3190 = osmo_tdef_get(bts->T_defs_pcu, 3190, OSMO_TDEF_MS, -1);
|
|
|
|
unsigned long dl_tbf_idle_msec = osmo_tdef_get(bts->T_defs_pcu, -2031, OSMO_TDEF_MS, -1);
|
2019-09-09 10:55:01 +00:00
|
|
|
int age_thresh1 = msecs_to_frames(200);
|
2019-09-09 11:41:00 +00:00
|
|
|
int age_thresh2 = msecs_to_frames(OSMO_MIN(msecs_t3190/2, dl_tbf_idle_msec));
|
2017-12-13 17:27:32 +00:00
|
|
|
|
|
|
|
if (tbf->is_control_ts(ts) && tbf->need_control_ts())
|
|
|
|
return DL_PRIO_CONTROL;
|
|
|
|
|
|
|
|
if (tbf->is_control_ts(ts) && age > age_thresh2 && age_thresh2 > 0)
|
|
|
|
return DL_PRIO_HIGH_AGE;
|
|
|
|
|
|
|
|
if ((tbf->state_is(GPRS_RLCMAC_FLOW) && tbf->have_data()) || w->resend_needed() >= 0)
|
|
|
|
return DL_PRIO_NEW_DATA;
|
|
|
|
|
|
|
|
if (tbf->is_control_ts(ts) && age > age_thresh1 && tbf->keep_open(fn))
|
|
|
|
return DL_PRIO_LOW_AGE;
|
|
|
|
|
|
|
|
if (!w->window_empty())
|
|
|
|
return DL_PRIO_SENT_DATA;
|
|
|
|
|
|
|
|
return DL_PRIO_NONE;
|
|
|
|
}
|
|
|
|
|
2013-10-17 13:21:10 +00:00
|
|
|
static struct msgb *sched_select_downlink(struct gprs_rlcmac_bts *bts,
|
|
|
|
uint8_t trx, uint8_t ts, uint32_t fn,
|
2012-07-25 06:38:21 +00:00
|
|
|
uint8_t block_nr, struct gprs_rlcmac_pdch *pdch)
|
|
|
|
{
|
|
|
|
struct msgb *msg = NULL;
|
2015-03-02 13:28:12 +00:00
|
|
|
struct gprs_rlcmac_dl_tbf *tbf, *prio_tbf = NULL;
|
2017-12-13 17:27:32 +00:00
|
|
|
enum tbf_dl_prio prio, max_prio = DL_PRIO_NONE;
|
2015-03-20 13:26:05 +00:00
|
|
|
|
2015-03-02 13:28:12 +00:00
|
|
|
uint8_t i, tfi, prio_tfi;
|
2015-03-20 13:26:05 +00:00
|
|
|
int age;
|
2012-07-25 06:38:21 +00:00
|
|
|
|
2013-10-27 09:38:31 +00:00
|
|
|
/* select downlink resource */
|
2012-07-25 06:38:21 +00:00
|
|
|
for (i = 0, tfi = pdch->next_dl_tfi; i < 32;
|
|
|
|
i++, tfi = (tfi + 1) & 31) {
|
2014-06-04 12:56:09 +00:00
|
|
|
tbf = pdch->dl_tbf_by_tfi(tfi);
|
2012-07-25 06:38:21 +00:00
|
|
|
/* no TBF for this tfi, go next */
|
|
|
|
if (!tbf)
|
|
|
|
continue;
|
|
|
|
/* no DL TBF, go next */
|
|
|
|
if (tbf->direction != GPRS_RLCMAC_DL_TBF)
|
|
|
|
continue;
|
2013-10-16 14:33:00 +00:00
|
|
|
/* no DL resources needed, go next */
|
2013-10-16 16:33:18 +00:00
|
|
|
if (tbf->state_is_not(GPRS_RLCMAC_FLOW)
|
|
|
|
&& tbf->state_is_not(GPRS_RLCMAC_FINISHED))
|
2012-07-25 06:38:21 +00:00
|
|
|
continue;
|
|
|
|
|
2012-09-27 07:23:24 +00:00
|
|
|
/* waiting for CCCH IMM.ASS confirm */
|
2014-08-07 13:49:21 +00:00
|
|
|
if (tbf->m_wait_confirm)
|
2012-09-27 07:23:24 +00:00
|
|
|
continue;
|
|
|
|
|
2015-03-20 13:26:05 +00:00
|
|
|
age = tbf->frames_since_last_poll(fn);
|
|
|
|
|
2015-03-02 13:28:12 +00:00
|
|
|
/* compute priority */
|
2017-12-13 17:27:32 +00:00
|
|
|
prio = tbf_compute_priority(bts, tbf, ts, fn, age);
|
|
|
|
if (prio == DL_PRIO_NONE)
|
2015-03-20 13:26:05 +00:00
|
|
|
continue;
|
2015-03-02 13:28:12 +00:00
|
|
|
|
|
|
|
/* get the TBF with the highest priority */
|
|
|
|
if (prio > max_prio) {
|
|
|
|
prio_tfi = tfi;
|
|
|
|
prio_tbf = tbf;
|
|
|
|
max_prio = prio;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prio_tbf) {
|
2012-07-25 06:38:21 +00:00
|
|
|
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Scheduling data message at "
|
2015-03-20 13:26:05 +00:00
|
|
|
"RTS for DL TFI=%d (TRX=%d, TS=%d) prio=%d\n",
|
|
|
|
prio_tfi, trx, ts, max_prio);
|
2013-10-27 09:38:31 +00:00
|
|
|
/* next TBF to handle resource is the next one */
|
2015-03-02 13:28:12 +00:00
|
|
|
pdch->next_dl_tfi = (prio_tfi + 1) & 31;
|
2012-07-25 06:38:21 +00:00
|
|
|
/* generate DL data block */
|
2015-03-02 13:28:12 +00:00
|
|
|
msg = prio_tbf->create_dl_acked_block(fn, ts);
|
2012-07-20 09:19:59 +00:00
|
|
|
}
|
2012-06-27 13:36:27 +00:00
|
|
|
|
2012-07-25 06:38:21 +00:00
|
|
|
return msg;
|
|
|
|
}
|
2013-11-23 22:03:14 +00:00
|
|
|
|
|
|
|
static const uint8_t rlcmac_dl_idle[23] = {
|
2012-07-25 06:38:21 +00:00
|
|
|
0x47, /* control without optional header octets, no polling, USF=111 */
|
|
|
|
0x94, /* dummy downlink control message, paging mode 00 */
|
|
|
|
0x2b, /* no persistance level, 7 bits spare pattern */
|
|
|
|
0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b,
|
|
|
|
0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b
|
|
|
|
};
|
|
|
|
|
2013-11-23 22:03:14 +00:00
|
|
|
static struct msgb *sched_dummy(void)
|
2012-07-25 06:38:21 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
|
|
|
|
msg = msgb_alloc(23, "rlcmac_dl_idle");
|
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
|
|
|
memcpy(msgb_put(msg, 23), rlcmac_dl_idle, 23);
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2017-08-31 13:42:06 +00:00
|
|
|
static inline void tap_n_acc(const struct msgb *msg, const struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts,
|
|
|
|
uint32_t fn, enum pcu_gsmtap_category cat)
|
|
|
|
{
|
|
|
|
if (!msg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(cat) {
|
|
|
|
case PCU_GSMTAP_C_DL_CTRL:
|
|
|
|
bts->bts->rlc_sent_control();
|
|
|
|
bts->bts->send_gsmtap(PCU_GSMTAP_C_DL_CTRL, false, trx, ts, GSMTAP_CHANNEL_PACCH, fn, msg->data,
|
|
|
|
msg->len);
|
|
|
|
break;
|
|
|
|
case PCU_GSMTAP_C_DL_DATA_GPRS:
|
|
|
|
bts->bts->rlc_sent();
|
|
|
|
/* FIXME: distinguish between GPRS and EGPRS */
|
|
|
|
bts->bts->send_gsmtap(PCU_GSMTAP_C_DL_DATA_GPRS, false, trx, ts, GSMTAP_CHANNEL_PDTCH, fn, msg->data,
|
|
|
|
msg->len);
|
|
|
|
break;
|
|
|
|
case PCU_GSMTAP_C_DL_DUMMY:
|
|
|
|
bts->bts->rlc_sent_dummy();
|
|
|
|
bts->bts->send_gsmtap(PCU_GSMTAP_C_DL_DUMMY, false, trx, ts, GSMTAP_CHANNEL_PACCH, fn, msg->data,
|
|
|
|
msg->len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 16:12:18 +00:00
|
|
|
int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_bts *bts,
|
2016-07-20 11:05:05 +00:00
|
|
|
uint8_t trx, uint8_t ts,
|
2012-07-25 06:38:21 +00:00
|
|
|
uint32_t fn, uint8_t block_nr)
|
|
|
|
{
|
|
|
|
struct gprs_rlcmac_pdch *pdch;
|
|
|
|
struct gprs_rlcmac_tbf *poll_tbf = NULL, *dl_ass_tbf = NULL,
|
2014-08-07 12:58:59 +00:00
|
|
|
*ul_ass_tbf = NULL;
|
|
|
|
struct gprs_rlcmac_ul_tbf *ul_ack_tbf = NULL;
|
2012-07-25 06:38:21 +00:00
|
|
|
uint8_t usf = 0x7;
|
|
|
|
struct msgb *msg = NULL;
|
2012-08-07 14:00:56 +00:00
|
|
|
uint32_t poll_fn, sba_fn;
|
2012-07-25 06:38:21 +00:00
|
|
|
|
|
|
|
if (trx >= 8 || ts >= 8)
|
|
|
|
return -EINVAL;
|
|
|
|
pdch = &bts->trx[trx].pdch[ts];
|
|
|
|
|
2013-10-19 15:37:48 +00:00
|
|
|
if (!pdch->is_enabled()) {
|
2012-07-25 06:38:21 +00:00
|
|
|
LOGP(DRLCMACSCHED, LOGL_ERROR, "Received RTS on disabled PDCH: "
|
|
|
|
"TRX=%d TS=%d\n", trx, ts);
|
|
|
|
return -EIO;
|
2012-06-27 13:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-07-25 06:38:21 +00:00
|
|
|
/* store last frame number of RTS */
|
|
|
|
pdch->last_rts_fn = fn;
|
|
|
|
|
2015-12-28 18:15:40 +00:00
|
|
|
poll_fn = sched_poll(bts->bts, trx, ts, fn, block_nr, &poll_tbf, &ul_ass_tbf,
|
2012-07-25 13:47:03 +00:00
|
|
|
&dl_ass_tbf, &ul_ack_tbf);
|
2013-10-27 09:38:31 +00:00
|
|
|
/* check uplink resource for polling */
|
2012-07-25 06:38:21 +00:00
|
|
|
if (poll_tbf)
|
|
|
|
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: TRX=%d "
|
|
|
|
"TS=%d FN=%d block_nr=%d scheduling free USF for "
|
2013-10-27 19:31:47 +00:00
|
|
|
"polling at FN=%d of %s\n", trx, ts, fn,
|
2012-07-25 06:38:21 +00:00
|
|
|
block_nr, poll_fn,
|
2013-10-27 19:31:47 +00:00
|
|
|
tbf_name(poll_tbf));
|
2012-07-25 06:38:21 +00:00
|
|
|
/* use free USF */
|
2012-08-07 14:00:56 +00:00
|
|
|
/* else. check for sba */
|
2013-10-19 18:47:12 +00:00
|
|
|
else if ((sba_fn = bts->bts->sba()->sched(trx, ts, fn, block_nr) != 0xffffffff))
|
2012-08-07 14:00:56 +00:00
|
|
|
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: TRX=%d "
|
|
|
|
"TS=%d FN=%d block_nr=%d scheduling free USF for "
|
|
|
|
"single block allocation at FN=%d\n", trx, ts, fn,
|
|
|
|
block_nr, sba_fn);
|
|
|
|
/* use free USF */
|
2013-10-27 09:38:31 +00:00
|
|
|
/* else, we search for uplink resource */
|
2012-07-25 06:38:21 +00:00
|
|
|
else
|
|
|
|
usf = sched_select_uplink(trx, ts, fn, block_nr, pdch);
|
|
|
|
|
|
|
|
/* Prio 1: select control message */
|
2013-12-25 14:19:54 +00:00
|
|
|
msg = sched_select_ctrl_msg(trx, ts, fn, block_nr, pdch, ul_ass_tbf,
|
2012-07-25 13:47:03 +00:00
|
|
|
dl_ass_tbf, ul_ack_tbf);
|
2017-08-31 13:42:06 +00:00
|
|
|
tap_n_acc(msg, bts, trx, ts, fn, PCU_GSMTAP_C_DL_CTRL);
|
2012-07-25 06:38:21 +00:00
|
|
|
|
|
|
|
/* Prio 2: select data message for downlink */
|
2016-05-18 14:41:03 +00:00
|
|
|
if (!msg) {
|
2013-10-17 13:21:10 +00:00
|
|
|
msg = sched_select_downlink(bts, trx, ts, fn, block_nr, pdch);
|
2017-08-31 13:42:06 +00:00
|
|
|
tap_n_acc(msg, bts, trx, ts, fn, PCU_GSMTAP_C_DL_DATA_GPRS);
|
2016-05-18 14:41:03 +00:00
|
|
|
}
|
2012-07-25 06:38:21 +00:00
|
|
|
|
2012-06-27 13:36:27 +00:00
|
|
|
/* Prio 3: send dummy contol message */
|
2016-05-18 14:43:10 +00:00
|
|
|
if (!msg) {
|
|
|
|
/* increase counter */
|
2012-07-25 06:38:21 +00:00
|
|
|
msg = sched_dummy();
|
2017-08-31 13:42:06 +00:00
|
|
|
tap_n_acc(msg, bts, trx, ts, fn, PCU_GSMTAP_C_DL_DUMMY);
|
2016-05-18 14:43:10 +00:00
|
|
|
}
|
2012-07-25 06:38:21 +00:00
|
|
|
|
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
2012-06-27 13:36:27 +00:00
|
|
|
/* msg is now available */
|
2016-05-21 17:45:23 +00:00
|
|
|
bts->bts->rlc_dl_bytes(msg->data_len);
|
2012-06-27 13:36:27 +00:00
|
|
|
|
|
|
|
/* set USF */
|
2015-12-28 13:10:14 +00:00
|
|
|
OSMO_ASSERT(msgb_length(msg) > 0);
|
2012-06-27 13:36:27 +00:00
|
|
|
msg->data[0] = (msg->data[0] & 0xf8) | usf;
|
|
|
|
|
2015-09-07 16:49:00 +00:00
|
|
|
/* Used to measure the leak rate, count all blocks */
|
|
|
|
gprs_bssgp_update_frames_sent();
|
|
|
|
|
2012-06-27 13:36:27 +00:00
|
|
|
/* send PDTCH/PACCH to L1 */
|
2016-07-20 11:05:05 +00:00
|
|
|
pcu_l1if_tx_pdtch(msg, trx, ts, bts->trx[trx].arfcn, fn, block_nr);
|
2012-06-27 13:36:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|