blob: a488e9b9eeaf46118343ae01a93f1bf06e089368 [file] [log] [blame]
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +01001/* pdch_ul_controller.h
2 *
3 * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010015 */
16#pragma once
17
18#include <stdint.h>
19#include <stdbool.h>
20
21#include <osmocom/core/linuxrbtree.h>
22#include <osmocom/core/utils.h>
23
24struct gprs_rlcmac_pdch;
25struct gprs_rlcmac_tbf;
26struct gprs_rlcmac_ul_tbf;
27struct gprs_rlcmac_sba;
28
Pau Espin Pedrol50a1ede2021-03-29 13:49:43 +020029/* RRBP offsets, see TS 44.060 able 10.4.5.1 */
30enum rrbp_field {
31 RRBP_N_plus_13 = 0x0,
32 RRBP_N_plus_17_18 = 0x1,
33 RRBP_N_plus_21_22 = 0x2,
34 RRBP_N_plus_26 = 0x3,
35};
36
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010037struct pdch_ulc {
38 struct gprs_rlcmac_pdch *pdch; /* back pointer */
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010039 struct rb_root tree_root;
40 void *pool_ctx; /* talloc pool of struct pdch_ulc_node */
41};
42
43enum PdchUlcNode {
44 PDCH_ULC_NODE_TBF_USF,
45 PDCH_ULC_NODE_TBF_POLL,
46 PDCH_ULC_NODE_SBA,
47};
48extern const struct value_string pdch_ul_node_names[];
49
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020050enum pdch_ulc_tbf_poll_reason {
51 PDCH_ULC_POLL_UL_ASS, /* Expect CTRL ACK for UL ASS we transmit */
52 PDCH_ULC_POLL_DL_ASS, /* Expect CTRL ACK for DL ASS we transmit */
Pau Espin Pedrol43479972021-04-22 19:18:13 +020053 PDCH_ULC_POLL_UL_ACK, /* Expect CTRL ACK (or PKT RES REQ on final UL ACK/NACK) for UL ACK/NACK we transmit */
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020054 PDCH_ULC_POLL_DL_ACK, /* Expect DL ACK/NACK requested by RRBP */
55 PDCH_ULC_POLL_CELL_CHG_CONTINUE, /* Expect CTRL ACK for Pkt cell Change Continue we transmit */
56};
Pau Espin Pedrolc6e911c2021-06-07 18:13:23 +020057extern const struct value_string pdch_ulc_tbf_poll_reason_names[];
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020058
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010059struct pdch_ulc_node {
60 struct rb_node node; /*! entry in pdch_ulc->tree_root */
61 uint32_t fn;
62 enum PdchUlcNode type;
63 union {
64 struct {
65 struct gprs_rlcmac_ul_tbf *ul_tbf;
66 } tbf_usf;
67 struct {
68 struct gprs_rlcmac_tbf *poll_tbf;
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020069 enum pdch_ulc_tbf_poll_reason reason;
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010070 } tbf_poll;
71 struct {
72 struct gprs_rlcmac_sba *sba;
73 } sba;
74 };
75};
76
77
78struct pdch_ulc *pdch_ulc_alloc(struct gprs_rlcmac_pdch *pdch, void *ctx);
79
80int pdch_ulc_reserve_tbf_usf(struct pdch_ulc *ulc, uint32_t fn, struct gprs_rlcmac_ul_tbf *ul_tbf);
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020081int pdch_ulc_reserve_tbf_poll(struct pdch_ulc *ulc, uint32_t fn, struct gprs_rlcmac_tbf *tbf, enum pdch_ulc_tbf_poll_reason reason);
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010082int pdch_ulc_reserve_sba(struct pdch_ulc *ulc, struct gprs_rlcmac_sba *sba);
83
84bool pdch_ulc_fn_is_free(struct pdch_ulc *ulc, uint32_t fn);
85
Pau Espin Pedrol99360a32021-03-09 17:18:12 +010086int pdch_ulc_get_next_free_rrbp_fn(struct pdch_ulc *ulc, uint32_t fn, uint32_t *poll_fn, unsigned int *rrbp);
Maxdc6a8602022-11-17 19:25:40 +030087uint32_t pdch_ulc_get_next_free_fn(const struct pdch_ulc *ulc, uint32_t start_fn);
Pau Espin Pedrol99360a32021-03-09 17:18:12 +010088
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010089struct pdch_ulc_node *pdch_ulc_get_node(struct pdch_ulc *ulc, uint32_t fn);
90struct pdch_ulc_node *pdch_ulc_pop_node(struct pdch_ulc *ulc, uint32_t fn);
91struct gprs_rlcmac_sba *pdch_ulc_get_sba(struct pdch_ulc *ulc, uint32_t fn);
Pau Espin Pedrolfd1fbdb2021-03-11 16:59:50 +010092struct gprs_rlcmac_tbf *pdch_ulc_get_tbf_poll(struct pdch_ulc *ulc, uint32_t fn);
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010093
Pau Espin Pedrolade9c2f2021-03-24 14:02:49 +010094void pdch_ulc_release_node(struct pdch_ulc *ulc, struct pdch_ulc_node *item);
Pau Espin Pedrol99360a32021-03-09 17:18:12 +010095void pdch_ulc_release_tbf(struct pdch_ulc *ulc, const struct gprs_rlcmac_tbf *tbf);
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010096int pdch_ulc_release_fn(struct pdch_ulc *ulc, uint32_t fn);
97
98void pdch_ulc_expire_fn(struct pdch_ulc *ulc, uint32_t fn);