aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2023-10-04 06:34:40 +0700
committerpespin <pespin@sysmocom.de>2023-10-04 11:40:57 +0000
commit5162449b71c4285e6c032fb0df39e8c1ba86835d (patch)
treec7f1b6385af655da54dbede16532044a842fa74c
parentf81a7389f1bcbbb008c52ee0904586b15a4678b0 (diff)
rlcmac: migrate from fn_cmp() to gsm0502_fncmp()
-rw-r--r--include/osmocom/gprs/rlcmac/sched.h14
-rw-r--r--src/rlcmac/pdch_ul_controller.c7
-rw-r--r--src/rlcmac/tbf_dl_ass_fsm.c9
-rw-r--r--src/rlcmac/tbf_ul_ass_fsm.c14
4 files changed, 16 insertions, 28 deletions
diff --git a/include/osmocom/gprs/rlcmac/sched.h b/include/osmocom/gprs/rlcmac/sched.h
index a90cbc1..9e03c01 100644
--- a/include/osmocom/gprs/rlcmac/sched.h
+++ b/include/osmocom/gprs/rlcmac/sched.h
@@ -20,20 +20,6 @@ static inline bool fn_valid(uint32_t fn)
return f == 0 || f == 4 || f == 8;
}
-#define GSM_MAX_FN_THRESH (GSM_MAX_FN >> 1)
-/* 0: equal, -1: fn1 BEFORE fn2, 1: fn1 AFTER fn2 */
-static inline int fn_cmp(uint32_t fn1, uint32_t fn2)
-{
- if (fn1 == fn2)
- return 0;
- /* FN1 goes before FN2: */
- if ((fn1 < fn2 && (fn2 - fn1) < GSM_MAX_FN_THRESH) ||
- (fn1 > fn2 && (fn1 - fn2) > GSM_MAX_FN_THRESH))
- return -1;
- /* FN1 goes after FN2: */
- return 1;
-}
-
static inline uint32_t fn2bn(uint32_t fn)
{
return (fn % 52) / 4;
diff --git a/src/rlcmac/pdch_ul_controller.c b/src/rlcmac/pdch_ul_controller.c
index 7c5e41a..b6859b1 100644
--- a/src/rlcmac/pdch_ul_controller.c
+++ b/src/rlcmac/pdch_ul_controller.c
@@ -22,6 +22,7 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/linuxrbtree.h>
#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/gsm0502.h>
#include <osmocom/gprs/rlcmac/pdch_ul_controller.h>
#include <osmocom/gprs/rlcmac/rlcmac_private.h>
@@ -61,7 +62,7 @@ struct gprs_rlcmac_pdch_ulc_node *gprs_rlcmac_pdch_ulc_get_node(struct gprs_rlcm
while (node) {
it = rb_entry(node, struct gprs_rlcmac_pdch_ulc_node, node);
- res = fn_cmp(it->fn, fn);
+ res = gsm0502_fncmp(it->fn, fn);
if (res > 0) /* it->fn AFTER fn */
node = node->rb_left;
else if (res < 0) /* it->fn BEFORE fn */
@@ -105,7 +106,7 @@ static int gprs_rlcmac_pdch_ulc_add_node(struct gprs_rlcmac_pdch_ulc *ulc, struc
it = container_of(*n, struct gprs_rlcmac_pdch_ulc_node, node);
parent = *n;
- res = fn_cmp(item->fn, it->fn);
+ res = gsm0502_fncmp(item->fn, it->fn);
if (res < 0) { /* item->fn "BEFORE" it->fn */
n = &((*n)->rb_left);
} else if (res > 0) { /* item->fn "AFTER" it->fn */
@@ -180,7 +181,7 @@ void gprs_rlcmac_pdch_ulc_expire_fn(struct gprs_rlcmac_pdch_ulc *ulc, uint32_t f
struct rb_node *first;
while ((first = rb_first(&ulc->tree_root))) {
item = container_of(first, struct gprs_rlcmac_pdch_ulc_node, node);
- res = fn_cmp(item->fn, fn);
+ res = gsm0502_fncmp(item->fn, fn);
if (res > 0) /* item->fn AFTER fn */
break;
if (res < 0) { /* item->fn BEFORE fn */
diff --git a/src/rlcmac/tbf_dl_ass_fsm.c b/src/rlcmac/tbf_dl_ass_fsm.c
index 9acf723..fec375f 100644
--- a/src/rlcmac/tbf_dl_ass_fsm.c
+++ b/src/rlcmac/tbf_dl_ass_fsm.c
@@ -24,6 +24,7 @@
#include <osmocom/core/tdef.h>
#include <osmocom/core/fsm.h>
#include <osmocom/core/bitvec.h>
+#include <osmocom/gsm/gsm0502.h>
#include <osmocom/gprs/rlcmac/types.h>
#include <osmocom/gprs/rlcmac/tbf_dl_ass_fsm.h>
@@ -141,7 +142,7 @@ static void st_idle(struct osmo_fsm_inst *fi, uint32_t event, void *data)
return;
memcpy(&ctx->iaro, ev_ccch_imm_ass->iaro, sizeof(ctx->iaro));
if (ctx->tbf_starting_time_exists &&
- fn_cmp(ctx->tbf_starting_time, ev_ccch_imm_ass->fn) > 0)
+ gsm0502_fncmp(ctx->tbf_starting_time, ev_ccch_imm_ass->fn) > 0)
tbf_dl_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_DL_ASS_ST_WAIT_TBF_STARTING_TIME);
else
tbf_dl_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_DL_ASS_ST_COMPL);
@@ -152,7 +153,7 @@ static void st_idle(struct osmo_fsm_inst *fi, uint32_t event, void *data)
return;
memcpy(&ctx->dl_block, ev_pacch_pkt_ass->dl_block, sizeof(ctx->dl_block));
if (ctx->tbf_starting_time_exists &&
- fn_cmp(ctx->tbf_starting_time, ev_pacch_pkt_ass->fn) > 0)
+ gsm0502_fncmp(ctx->tbf_starting_time, ev_pacch_pkt_ass->fn) > 0)
tbf_dl_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_DL_ASS_ST_WAIT_TBF_STARTING_TIME);
else
tbf_dl_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_DL_ASS_ST_COMPL);
@@ -175,7 +176,7 @@ static void st_wait_tbf_starting_time(struct osmo_fsm_inst *fi, uint32_t event,
return;
memcpy(&ctx->iaro, ev_ccch_imm_ass->iaro, sizeof(ctx->iaro));
if (ctx->tbf_starting_time_exists &&
- fn_cmp(ctx->tbf_starting_time, ev_ccch_imm_ass->fn) > 0)
+ gsm0502_fncmp(ctx->tbf_starting_time, ev_ccch_imm_ass->fn) > 0)
tbf_dl_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_DL_ASS_ST_WAIT_TBF_STARTING_TIME);
else
tbf_dl_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_DL_ASS_ST_COMPL);
@@ -186,7 +187,7 @@ static void st_wait_tbf_starting_time(struct osmo_fsm_inst *fi, uint32_t event,
return;
memcpy(&ctx->dl_block, ev_pacch_pkt_ass->dl_block, sizeof(ctx->dl_block));
if (ctx->tbf_starting_time_exists &&
- fn_cmp(ctx->tbf_starting_time, ev_pacch_pkt_ass->fn) > 0)
+ gsm0502_fncmp(ctx->tbf_starting_time, ev_pacch_pkt_ass->fn) > 0)
tbf_dl_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_DL_ASS_ST_WAIT_TBF_STARTING_TIME);
else
tbf_dl_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_DL_ASS_ST_COMPL);
diff --git a/src/rlcmac/tbf_ul_ass_fsm.c b/src/rlcmac/tbf_ul_ass_fsm.c
index df5b799..e577313 100644
--- a/src/rlcmac/tbf_ul_ass_fsm.c
+++ b/src/rlcmac/tbf_ul_ass_fsm.c
@@ -318,7 +318,7 @@ static void st_wait_ccch_imm_ass(struct osmo_fsm_inst *fi, uint32_t event, void
if (handle_imm_ass(ctx, ev_rx_ccch_imm_ass_ctx) < 0)
return;
if (ctx->tbf_starting_time_exists &&
- fn_cmp(ctx->tbf_starting_time, ev_rx_ccch_imm_ass_ctx->fn) > 0) {
+ gsm0502_fncmp(ctx->tbf_starting_time, ev_rx_ccch_imm_ass_ctx->fn) > 0) {
tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_TBF_STARTING_TIME1);
return;
}
@@ -353,7 +353,7 @@ static void st_wait_tbf_starting_time1(struct osmo_fsm_inst *fi, uint32_t event,
if (handle_imm_ass(ctx, ev_rx_ccch_imm_ass_ctx) < 0)
return;
if (ctx->tbf_starting_time_exists &&
- fn_cmp(ctx->tbf_starting_time, ev_rx_ccch_imm_ass_ctx->fn) > 0) {
+ gsm0502_fncmp(ctx->tbf_starting_time, ev_rx_ccch_imm_ass_ctx->fn) > 0) {
tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_TBF_STARTING_TIME1);
return;
}
@@ -413,14 +413,14 @@ static void st_wait_pkt_ul_ass(struct osmo_fsm_inst *fi, uint32_t event, void *d
/* We need to wait at least until sending the PKT CTRL
* ACK (in the old CTRL TS) before completing the
* assignment and using the new TS assignment. */
- if (!ctx->tbf_starting_time_exists && fn_cmp(ctx->tbf_starting_time, next_blk) < 0) {
+ if (!ctx->tbf_starting_time_exists && gsm0502_fncmp(ctx->tbf_starting_time, next_blk) < 0) {
ctx->tbf_starting_time_exists = true;
ctx->tbf_starting_time = next_blk;
}
}
if (ctx->tbf_starting_time_exists &&
- fn_cmp(ctx->tbf_starting_time, d->fn) > 0) {
+ gsm0502_fncmp(ctx->tbf_starting_time, d->fn) > 0) {
tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_TBF_STARTING_TIME2);
} else {
tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL);
@@ -474,14 +474,14 @@ static void st_wait_tbf_starting_time2(struct osmo_fsm_inst *fi, uint32_t event,
/* We need to wait at least until sending the PKT CTRL
* ACK (in the old CTRL TS) before completing the
* assignment and using the new TS assignment. */
- if (!ctx->tbf_starting_time_exists && fn_cmp(ctx->tbf_starting_time, next_blk) < 0) {
+ if (!ctx->tbf_starting_time_exists && gsm0502_fncmp(ctx->tbf_starting_time, next_blk) < 0) {
ctx->tbf_starting_time_exists = true;
ctx->tbf_starting_time = next_blk;
}
}
if (ctx->tbf_starting_time_exists &&
- fn_cmp(ctx->tbf_starting_time, d->fn) > 0) {
+ gsm0502_fncmp(ctx->tbf_starting_time, d->fn) > 0) {
tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_TBF_STARTING_TIME2);
} else {
tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL);
@@ -746,7 +746,7 @@ void gprs_rlcmac_tbf_ul_ass_fn_tick(const struct gprs_rlcmac_ul_tbf *ul_tbf, uin
default:
OSMO_ASSERT(0);
}
- res = fn_cmp(fn, ul_tbf->ul_ass_fsm.tbf_starting_time);
+ res = gsm0502_fncmp(fn, ul_tbf->ul_ass_fsm.tbf_starting_time);
if (res < 0) {/* fn BEFORE tbf_starting_time */
LOGPTBFUL(ul_tbf, LOGL_DEBUG, "TS=%" PRIu8 " FN=%u Waiting for tbf_starting_time=%u\n",
ts_nr, fn, ul_tbf->ul_ass_fsm.tbf_starting_time);