blob: 0e66720220648d42b3b1f538bf2c018c6ce299ef [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 */
39 uint32_t last_fn; /* last FN rx from TDMA clock */
40 struct rb_root tree_root;
41 void *pool_ctx; /* talloc pool of struct pdch_ulc_node */
42};
43
44enum PdchUlcNode {
45 PDCH_ULC_NODE_TBF_USF,
46 PDCH_ULC_NODE_TBF_POLL,
47 PDCH_ULC_NODE_SBA,
48};
49extern const struct value_string pdch_ul_node_names[];
50
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020051enum pdch_ulc_tbf_poll_reason {
52 PDCH_ULC_POLL_UL_ASS, /* Expect CTRL ACK for UL ASS we transmit */
53 PDCH_ULC_POLL_DL_ASS, /* Expect CTRL ACK for DL ASS we transmit */
Pau Espin Pedrol43479972021-04-22 19:18:13 +020054 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 +020055 PDCH_ULC_POLL_DL_ACK, /* Expect DL ACK/NACK requested by RRBP */
56 PDCH_ULC_POLL_CELL_CHG_CONTINUE, /* Expect CTRL ACK for Pkt cell Change Continue we transmit */
57};
Pau Espin Pedrolc6e911c2021-06-07 18:13:23 +020058extern const struct value_string pdch_ulc_tbf_poll_reason_names[];
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020059
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010060struct pdch_ulc_node {
61 struct rb_node node; /*! entry in pdch_ulc->tree_root */
62 uint32_t fn;
63 enum PdchUlcNode type;
64 union {
65 struct {
66 struct gprs_rlcmac_ul_tbf *ul_tbf;
67 } tbf_usf;
68 struct {
69 struct gprs_rlcmac_tbf *poll_tbf;
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020070 enum pdch_ulc_tbf_poll_reason reason;
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010071 } tbf_poll;
72 struct {
73 struct gprs_rlcmac_sba *sba;
74 } sba;
75 };
76};
77
78
79struct pdch_ulc *pdch_ulc_alloc(struct gprs_rlcmac_pdch *pdch, void *ctx);
80
81int 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 +020082int 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 +010083int pdch_ulc_reserve_sba(struct pdch_ulc *ulc, struct gprs_rlcmac_sba *sba);
84
85bool pdch_ulc_fn_is_free(struct pdch_ulc *ulc, uint32_t fn);
86
Pau Espin Pedrol99360a32021-03-09 17:18:12 +010087int pdch_ulc_get_next_free_rrbp_fn(struct pdch_ulc *ulc, uint32_t fn, uint32_t *poll_fn, unsigned int *rrbp);
Pau Espin Pedrolce3bd252021-03-29 12:13:13 +020088uint32_t pdch_ulc_get_next_free_fn(struct pdch_ulc *ulc, uint32_t start_fn);
Pau Espin Pedrol99360a32021-03-09 17:18:12 +010089
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010090struct pdch_ulc_node *pdch_ulc_get_node(struct pdch_ulc *ulc, uint32_t fn);
91struct pdch_ulc_node *pdch_ulc_pop_node(struct pdch_ulc *ulc, uint32_t fn);
92struct gprs_rlcmac_sba *pdch_ulc_get_sba(struct pdch_ulc *ulc, uint32_t fn);
Pau Espin Pedrolfd1fbdb2021-03-11 16:59:50 +010093struct gprs_rlcmac_tbf *pdch_ulc_get_tbf_poll(struct pdch_ulc *ulc, uint32_t fn);
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010094
Pau Espin Pedrolade9c2f2021-03-24 14:02:49 +010095void pdch_ulc_release_node(struct pdch_ulc *ulc, struct pdch_ulc_node *item);
Pau Espin Pedrol99360a32021-03-09 17:18:12 +010096void pdch_ulc_release_tbf(struct pdch_ulc *ulc, const struct gprs_rlcmac_tbf *tbf);
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010097int pdch_ulc_release_fn(struct pdch_ulc *ulc, uint32_t fn);
98
99void pdch_ulc_expire_fn(struct pdch_ulc *ulc, uint32_t fn);