From 5162449b71c4285e6c032fb0df39e8c1ba86835d Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Wed, 4 Oct 2023 06:34:40 +0700 Subject: rlcmac: migrate from fn_cmp() to gsm0502_fncmp() Change-Id: I3030d00c6881713a088b1739b2b5ba77bac84e46 Depends: libosmocore.git I9590f2e836fc48650decf1564b6ab46306c4fe2d Depends: libosmocore.git Ie8bb9c49c6f81b8f4a1766547d6943f9880d1186 --- include/osmocom/gprs/rlcmac/sched.h | 14 -------------- src/rlcmac/pdch_ul_controller.c | 7 ++++--- src/rlcmac/tbf_dl_ass_fsm.c | 9 +++++---- src/rlcmac/tbf_ul_ass_fsm.c | 14 +++++++------- 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 #include #include +#include #include #include @@ -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 #include #include +#include #include #include @@ -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); -- cgit v1.2.3