clean-up: Continue to use types instead of passing ints around

Make parts of the recevie handling work on the PDCH and removing
the duplication of ARFCN, TS-Number and TRX-Number. Only the lower
level should deal with ints and everyone else just with the object
This commit is contained in:
Holger Hans Peter Freyther 2014-05-29 10:43:12 +02:00
parent 77e58f602d
commit ead6f08f42
9 changed files with 85 additions and 71 deletions

View File

@ -96,6 +96,19 @@ struct rate_ctr_group *bts_main_data_stats()
return BTS::main_bts()->rate_counters();
}
gprs_rlcmac_pdch *bts_find_pdch(uint8_t trx_nr, uint8_t ts_nr, uint16_t arfcn)
{
if (trx_nr >= 8 || ts_nr >= 8)
return 0;
gprs_rlcmac_trx *trx = &bts_main_data()->trx[trx_nr];
gprs_rlcmac_pdch *pdch = &trx->pdch[ts_nr];
/* verify we talk about the same thing */
OSMO_ASSERT(trx->arfcn == arfcn);
return pdch;
}
BTS::BTS()
: m_cur_fn(0)
, m_pollController(*this)

View File

@ -313,6 +313,7 @@ extern "C" {
#endif
struct gprs_rlcmac_bts *bts_main_data();
struct rate_ctr_group *bts_main_data_stats();
struct gprs_rlcmac_pdch *bts_find_pdch(uint8_t trx, uint8_t ts, uint16_t arfcn);
#ifdef __cplusplus
}

View File

@ -88,8 +88,7 @@ int gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf);
int gprs_rlcmac_paging_request(uint8_t *ptmsi, uint16_t ptmsi_len,
const char *imsi);
int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_bts *bts,
uint8_t trx, uint8_t ts, uint16_t arfcn,
int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_pdch *pdch,
uint32_t fn, uint8_t block_nr);
extern "C" {

View File

@ -23,8 +23,8 @@
#include <bts.h>
#include <tbf.h>
static uint32_t sched_poll(struct gprs_rlcmac_bts *bts,
uint8_t trx, uint8_t ts, uint32_t fn, uint8_t block_nr,
static uint32_t sched_poll(struct gprs_rlcmac_pdch *pdch,
uint32_t fn, uint8_t block_nr,
struct gprs_rlcmac_tbf **poll_tbf,
struct gprs_rlcmac_tbf **ul_ass_tbf,
struct gprs_rlcmac_tbf **dl_ass_tbf,
@ -38,9 +38,10 @@ static uint32_t sched_poll(struct gprs_rlcmac_bts *bts,
if ((block_nr % 3) == 2)
poll_fn ++;
poll_fn = poll_fn % 2715648;
llist_for_each_entry(tbf, &bts->ul_tbfs, list) {
llist_for_each_entry(tbf, &pdch->bts_data()->ul_tbfs, list) {
/* this trx, this ts */
if (tbf->trx->trx_no != trx || tbf->control_ts != ts)
if (tbf->trx != pdch->trx || tbf->control_ts != pdch->ts_no)
continue;
/* polling for next uplink block */
if (tbf->poll_state == GPRS_RLCMAC_POLL_SCHED
@ -54,9 +55,9 @@ static uint32_t sched_poll(struct gprs_rlcmac_bts *bts,
*ul_ass_tbf = tbf;
#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?"
}
llist_for_each_entry(tbf, &bts->dl_tbfs, list) {
llist_for_each_entry(tbf, &pdch->bts_data()->dl_tbfs, list) {
/* this trx, this ts */
if (tbf->trx->trx_no != trx || tbf->control_ts != ts)
if (tbf->trx != pdch->trx || tbf->control_ts != pdch->ts_no)
continue;
/* polling for next uplink block */
if (tbf->poll_state == GPRS_RLCMAC_POLL_SCHED
@ -71,8 +72,8 @@ static uint32_t sched_poll(struct gprs_rlcmac_bts *bts,
return poll_fn;
}
static uint8_t sched_select_uplink(uint8_t trx, uint8_t ts, uint32_t fn,
uint8_t block_nr, struct gprs_rlcmac_pdch *pdch)
static uint8_t sched_select_uplink(struct gprs_rlcmac_pdch *pdch, uint32_t fn,
uint8_t block_nr)
{
struct gprs_rlcmac_tbf *tbf;
uint8_t usf = 0x07;
@ -93,11 +94,11 @@ static uint8_t sched_select_uplink(uint8_t trx, uint8_t ts, uint32_t fn,
continue;
/* use this USF */
usf = tbf->dir.ul.usf[ts];
usf = tbf->dir.ul.usf[pdch->ts_no];
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: TRX=%d "
"TS=%d FN=%d block_nr=%d scheduling USF=%d for "
"required uplink resource of UL TFI=%d\n", trx, ts, fn,
block_nr, usf, tfi);
"required uplink resource of UL TFI=%d\n", pdch->trx->trx_no,
pdch->ts_no, fn, block_nr, usf, tfi);
/* next TBF to handle resource is the next one */
pdch->next_ul_tfi = (tfi + 1) & 31;
break;
@ -107,8 +108,8 @@ static uint8_t sched_select_uplink(uint8_t trx, uint8_t ts, uint32_t fn,
}
static struct msgb *sched_select_ctrl_msg(
uint8_t trx, uint8_t ts, uint32_t fn,
uint8_t block_nr, struct gprs_rlcmac_pdch *pdch,
struct gprs_rlcmac_pdch *pdch, uint32_t fn,
uint8_t block_nr,
struct gprs_rlcmac_tbf *ul_ass_tbf,
struct gprs_rlcmac_tbf *dl_ass_tbf,
struct gprs_rlcmac_tbf *ul_ack_tbf)
@ -144,23 +145,23 @@ static struct msgb *sched_select_ctrl_msg(
tbf->rotate_in_list();
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Scheduling control "
"message at RTS for %s (TRX=%d, TS=%d)\n",
tbf_name(tbf), trx, ts);
tbf_name(tbf), pdch->trx->trx_no, pdch->ts_no);
return msg;
}
/* schedule PACKET PAGING REQUEST */
msg = pdch->packet_paging_request();
if (msg) {
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Scheduling paging request "
"message at RTS for (TRX=%d, TS=%d)\n", trx, ts);
"message at RTS for (TRX=%d, TS=%d)\n",
pdch->trx->trx_no, pdch->ts_no);
return msg;
}
return NULL;
}
static struct msgb *sched_select_downlink(struct gprs_rlcmac_bts *bts,
uint8_t trx, uint8_t ts, uint32_t fn,
uint8_t block_nr, struct gprs_rlcmac_pdch *pdch)
static struct msgb *sched_select_downlink(struct gprs_rlcmac_pdch *pdch,
uint32_t fn, uint8_t block_nr)
{
struct msgb *msg = NULL;
struct gprs_rlcmac_tbf *tbf = NULL;
@ -186,11 +187,12 @@ static struct msgb *sched_select_downlink(struct gprs_rlcmac_bts *bts,
continue;
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Scheduling data message at "
"RTS for DL TFI=%d (TRX=%d, TS=%d)\n", tfi, trx, ts);
"RTS for DL TFI=%d (TRX=%d, TS=%d)\n", tfi,
pdch->trx->trx_no, pdch->ts_no);
/* next TBF to handle resource is the next one */
pdch->next_dl_tfi = (tfi + 1) & 31;
/* generate DL data block */
msg = tbf->create_dl_acked_block(fn, ts);
msg = tbf->create_dl_acked_block(fn, pdch->ts_no);
break;
}
@ -217,60 +219,52 @@ static struct msgb *sched_dummy(void)
return msg;
}
int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_bts *bts,
uint8_t trx, uint8_t ts, uint16_t arfcn,
int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_pdch *pdch,
uint32_t fn, uint8_t block_nr)
{
struct gprs_rlcmac_pdch *pdch;
struct gprs_rlcmac_tbf *poll_tbf = NULL, *dl_ass_tbf = NULL,
*ul_ass_tbf = NULL, *ul_ack_tbf = NULL;
uint8_t usf = 0x7;
struct msgb *msg = NULL;
uint32_t poll_fn, sba_fn;
#warning "ARFCN... it is already in the TRX..... is it consistent with it?"
if (trx >= 8 || ts >= 8)
return -EINVAL;
pdch = &bts->trx[trx].pdch[ts];
if (!pdch->is_enabled()) {
LOGP(DRLCMACSCHED, LOGL_ERROR, "Received RTS on disabled PDCH: "
"TRX=%d TS=%d\n", trx, ts);
"TRX=%d TS=%d\n", pdch->trx->trx_no, pdch->ts_no);
return -EIO;
}
/* store last frame number of RTS */
pdch->last_rts_fn = fn;
poll_fn = sched_poll(bts, trx, ts, fn, block_nr, &poll_tbf, &ul_ass_tbf,
poll_fn = sched_poll(pdch, fn, block_nr, &poll_tbf, &ul_ass_tbf,
&dl_ass_tbf, &ul_ack_tbf);
/* check uplink resource for polling */
if (poll_tbf)
LOGP(DRLCMACSCHED, LOGL_DEBUG, "Received RTS for PDCH: TRX=%d "
"TS=%d FN=%d block_nr=%d scheduling free USF for "
"polling at FN=%d of %s\n", trx, ts, fn,
block_nr, poll_fn,
"polling at FN=%d of %s\n", pdch->trx->trx_no,
pdch->ts_no, fn, block_nr, poll_fn,
tbf_name(poll_tbf));
/* use free USF */
/* else. check for sba */
else if ((sba_fn = bts->bts->sba()->sched(trx, ts, fn, block_nr) != 0xffffffff))
else if ((sba_fn = pdch->bts()->sba()->sched(pdch, fn, block_nr) != 0xffffffff))
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);
"single block allocation at FN=%d\n", pdch->trx->trx_no,
pdch->ts_no, fn, block_nr, sba_fn);
/* use free USF */
/* else, we search for uplink resource */
else
usf = sched_select_uplink(trx, ts, fn, block_nr, pdch);
usf = sched_select_uplink(pdch, fn, block_nr);
/* Prio 1: select control message */
msg = sched_select_ctrl_msg(trx, ts, fn, block_nr, pdch, ul_ass_tbf,
msg = sched_select_ctrl_msg(pdch, fn, block_nr, ul_ass_tbf,
dl_ass_tbf, ul_ack_tbf);
/* Prio 2: select data message for downlink */
if (!msg)
msg = sched_select_downlink(bts, trx, ts, fn, block_nr, pdch);
msg = sched_select_downlink(pdch, fn, block_nr);
/* Prio 3: send dummy contol message */
if (!msg)
@ -284,7 +278,7 @@ int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_bts *bts,
msg->data[0] = (msg->data[0] & 0xf8) | usf;
/* send PDTCH/PACCH to L1 */
pcu_l1if_tx_pdtch(msg, trx, ts, arfcn, fn, block_nr);
pcu_l1if_tx_pdtch(msg, pdch, fn, block_nr);
return 0;
}

View File

@ -50,6 +50,11 @@ int l1if_pdch_req(void *obj, uint8_t ts, int is_ptcch, uint32_t fn,
extern void *tall_pcu_ctx;
static gprs_rlcmac_pdch *find_pdch(struct gsm_pcu_if_rts_req *req)
{
return bts_find_pdch(req->trx_nr, req->ts_nr, req->arfcn);
}
/*
* PCU messages
*/
@ -121,34 +126,31 @@ static int pcu_tx_data_req(uint8_t trx, uint8_t ts, uint8_t sapi,
return pcu_sock_send(msg);
}
void pcu_l1if_tx_pdtch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn,
void pcu_l1if_tx_pdtch(msgb *msg, struct gprs_rlcmac_pdch *pdch,
uint32_t fn, uint8_t block_nr)
{
#ifdef ENABLE_SYSMODSP
struct gprs_rlcmac_bts *bts = bts_main_data();
if (bts->trx[trx].fl1h)
l1if_pdch_req(bts->trx[trx].fl1h, ts, 0, fn, arfcn, block_nr,
msg->data, msg->len);
if (pdch->trx->fl1h)
l1if_pdch_req(pdch->trx->fl1h, pdch->ts_no, 0, fn,
pdch->trx->arfcn, block_nr, msg->data, msg->len);
else
#endif
pcu_tx_data_req(trx, ts, PCU_IF_SAPI_PDTCH, arfcn, fn, block_nr,
msg->data, msg->len);
pcu_tx_data_req(pdch->trx->trx_no, pdch->ts_no, PCU_IF_SAPI_PDTCH,
pdch->trx->arfcn, fn, block_nr, msg->data, msg->len);
msgb_free(msg);
}
void pcu_l1if_tx_ptcch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn,
void pcu_l1if_tx_ptcch(msgb *msg, gprs_rlcmac_pdch *pdch,
uint32_t fn, uint8_t block_nr)
{
#ifdef ENABLE_SYSMODSP
struct gprs_rlcmac_bts *bts = bts_main_data();
if (bts->trx[trx].fl1h)
l1if_pdch_req(bts->trx[trx].fl1h, ts, 1, fn, arfcn, block_nr,
msg->data, msg->len);
if (pdch->trx->fl1h)
l1if_pdch_req(pdch->trx->fl1h, pdch->ts_no, 1, fn,
pdch->trx->arfcn, block_nr, msg->data, msg->len);
else
#endif
pcu_tx_data_req(trx, ts, PCU_IF_SAPI_PTCCH, arfcn, fn, block_nr,
pcu_tx_data_req(pdch->trx->trx_no, pdch->ts_no, PCU_IF_SAPI_PTCCH,
pdch->trx->arfcn, fn, block_nr,
msg->data, msg->len);
msgb_free(msg);
}
@ -235,33 +237,35 @@ static int pcu_rx_data_cnf(struct gsm_pcu_if_data *data_cnf)
}
// FIXME: remove this, when changed from c++ to c.
extern "C" int pcu_rx_rts_req_pdtch(uint8_t trx, uint8_t ts, uint16_t arfcn,
extern "C" int pcu_rx_rts_req_pdtch(struct gprs_rlcmac_pdch *pdch,
uint32_t fn, uint8_t block_nr)
{
return gprs_rlcmac_rcv_rts_block(bts_main_data(),
trx, ts, arfcn, fn, block_nr);
return gprs_rlcmac_rcv_rts_block(pdch, fn, block_nr);
}
static int pcu_rx_rts_req(struct gsm_pcu_if_rts_req *rts_req)
{
gprs_rlcmac_pdch *pdch;
int rc = 0;
LOGP(DL1IF, LOGL_DEBUG, "RTS request received: trx=%d ts=%d sapi=%d "
"arfcn=%d fn=%d block=%d\n", rts_req->trx_nr, rts_req->ts_nr,
rts_req->sapi, rts_req->arfcn, rts_req->fn, rts_req->block_nr);
pdch = find_pdch(rts_req);
if (!pdch)
return -EINVAL;
switch (rts_req->sapi) {
case PCU_IF_SAPI_PDTCH:
pcu_rx_rts_req_pdtch(rts_req->trx_nr, rts_req->ts_nr,
rts_req->arfcn, rts_req->fn, rts_req->block_nr);
pcu_rx_rts_req_pdtch(pdch, rts_req->fn, rts_req->block_nr);
break;
case PCU_IF_SAPI_PTCCH:
/* FIXME */
{
struct msgb *msg = msgb_alloc(23, "l1_prim");
memset(msgb_put(msg, 23), 0x2b, 23);
pcu_l1if_tx_ptcch(msg, rts_req->trx_nr, rts_req->ts_nr,
rts_req->arfcn, rts_req->fn, rts_req->block_nr);
pcu_l1if_tx_ptcch(msg, pdch, rts_req->fn, rts_req->block_nr);
}
break;
default:

View File

@ -20,6 +20,8 @@
#ifndef PCU_L1_IF_H
#define PCU_L1_IF_H
struct gprs_rlcmac_pdch;
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
@ -32,7 +34,7 @@ extern "C" {
#ifdef __cplusplus
}
void pcu_l1if_tx_pdtch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn,
void pcu_l1if_tx_pdtch(msgb *msg, struct gprs_rlcmac_pdch *pdch,
uint32_t fn, uint8_t block_nr);
void pcu_l1if_tx_ptcch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn,
uint32_t fn, uint8_t block_nr);
@ -50,7 +52,7 @@ int pcu_sock_send(struct msgb *msg);
#ifdef __cplusplus
extern "C"
#endif
int pcu_rx_rts_req_pdtch(uint8_t trx, uint8_t ts, uint16_t arfcn,
int pcu_rx_rts_req_pdtch(struct gprs_rlcmac_pdch *pdch,
uint32_t fn, uint8_t block_nr);
#ifdef __cplusplus

View File

@ -104,7 +104,7 @@ gprs_rlcmac_sba *SBAController::find(const gprs_rlcmac_pdch *pdch, uint32_t fn)
return find(pdch->trx_no(), pdch->ts_no, fn);
}
uint32_t SBAController::sched(uint8_t trx, uint8_t ts, uint32_t fn, uint8_t block_nr)
uint32_t SBAController::sched(gprs_rlcmac_pdch *pdch, uint32_t fn, uint8_t block_nr)
{
uint32_t sba_fn;
struct gprs_rlcmac_sba *sba;
@ -114,7 +114,7 @@ uint32_t SBAController::sched(uint8_t trx, uint8_t ts, uint32_t fn, uint8_t bloc
if ((block_nr % 3) == 2)
sba_fn ++;
sba_fn = sba_fn % 2715648;
sba = find(trx, ts, sba_fn);
sba = find(pdch->trx->trx_no, pdch->ts_no, sba_fn);
if (sba)
return sba_fn;

View File

@ -56,7 +56,7 @@ public:
gprs_rlcmac_sba *find(uint8_t trx, uint8_t ts, uint32_t fn);
gprs_rlcmac_sba *find(const gprs_rlcmac_pdch *pdch, uint32_t fn);
uint32_t sched(uint8_t trx, uint8_t ts, uint32_t fn, uint8_t block_nr);
uint32_t sched(gprs_rlcmac_pdch *pdch, uint32_t fn, uint8_t block_nr);
int timeout(struct gprs_rlcmac_sba *sba);
void free_resources(struct gprs_rlcmac_pdch *pdch);

View File

@ -13,6 +13,7 @@
#include <sysmo_l1_if.h>
#include <gprs_debug.h>
#include <pcu_l1_if.h>
#include <bts.h>
extern void *tall_pcu_ctx;
@ -152,8 +153,8 @@ static int handle_ph_readytosend_ind(struct femtol1_hdl *fl1h,
switch (rts_ind->sapi) {
case GsmL1_Sapi_Pdtch:
case GsmL1_Sapi_Pacch:
rc = pcu_rx_rts_req_pdtch((long)fl1h->priv, rts_ind->u8Tn,
rts_ind->u16Arfcn, rts_ind->u32Fn, rts_ind->u8BlockNbr);
rc = pcu_rx_rts_req_pdtch(bts_find_pdch((long)fl1h->priv, rts_ind->u8Tn,
rts_ind->u16Arfcn), rts_ind->u32Fn, rts_ind->u8BlockNbr);
case GsmL1_Sapi_Ptcch:
// FIXME
default: