blob: 776f5ba46f592bc1596343eb9806ca8c8d348327 [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20#pragma once
21
22#include <stdint.h>
23#include <stdbool.h>
24
25#include <osmocom/core/linuxrbtree.h>
26#include <osmocom/core/utils.h>
27
28struct gprs_rlcmac_pdch;
29struct gprs_rlcmac_tbf;
30struct gprs_rlcmac_ul_tbf;
31struct gprs_rlcmac_sba;
32
Pau Espin Pedrol50a1ede2021-03-29 13:49:43 +020033/* RRBP offsets, see TS 44.060 able 10.4.5.1 */
34enum rrbp_field {
35 RRBP_N_plus_13 = 0x0,
36 RRBP_N_plus_17_18 = 0x1,
37 RRBP_N_plus_21_22 = 0x2,
38 RRBP_N_plus_26 = 0x3,
39};
40
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010041struct pdch_ulc {
42 struct gprs_rlcmac_pdch *pdch; /* back pointer */
43 uint32_t last_fn; /* last FN rx from TDMA clock */
44 struct rb_root tree_root;
45 void *pool_ctx; /* talloc pool of struct pdch_ulc_node */
46};
47
48enum PdchUlcNode {
49 PDCH_ULC_NODE_TBF_USF,
50 PDCH_ULC_NODE_TBF_POLL,
51 PDCH_ULC_NODE_SBA,
52};
53extern const struct value_string pdch_ul_node_names[];
54
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020055enum pdch_ulc_tbf_poll_reason {
56 PDCH_ULC_POLL_UL_ASS, /* Expect CTRL ACK for UL ASS we transmit */
57 PDCH_ULC_POLL_DL_ASS, /* Expect CTRL ACK for DL ASS we transmit */
Pau Espin Pedrol43479972021-04-22 19:18:13 +020058 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 +020059 PDCH_ULC_POLL_DL_ACK, /* Expect DL ACK/NACK requested by RRBP */
60 PDCH_ULC_POLL_CELL_CHG_CONTINUE, /* Expect CTRL ACK for Pkt cell Change Continue we transmit */
61};
62
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010063struct pdch_ulc_node {
64 struct rb_node node; /*! entry in pdch_ulc->tree_root */
65 uint32_t fn;
66 enum PdchUlcNode type;
67 union {
68 struct {
69 struct gprs_rlcmac_ul_tbf *ul_tbf;
70 } tbf_usf;
71 struct {
72 struct gprs_rlcmac_tbf *poll_tbf;
Pau Espin Pedrol86580e12021-03-29 18:15:30 +020073 enum pdch_ulc_tbf_poll_reason reason;
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010074 } tbf_poll;
75 struct {
76 struct gprs_rlcmac_sba *sba;
77 } sba;
78 };
79};
80
81
82struct pdch_ulc *pdch_ulc_alloc(struct gprs_rlcmac_pdch *pdch, void *ctx);
83
84int 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 +020085int 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 +010086int pdch_ulc_reserve_sba(struct pdch_ulc *ulc, struct gprs_rlcmac_sba *sba);
87
88bool pdch_ulc_fn_is_free(struct pdch_ulc *ulc, uint32_t fn);
89
Pau Espin Pedrol99360a32021-03-09 17:18:12 +010090int 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 +020091uint32_t pdch_ulc_get_next_free_fn(struct pdch_ulc *ulc, uint32_t start_fn);
Pau Espin Pedrol99360a32021-03-09 17:18:12 +010092
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010093struct pdch_ulc_node *pdch_ulc_get_node(struct pdch_ulc *ulc, uint32_t fn);
94struct pdch_ulc_node *pdch_ulc_pop_node(struct pdch_ulc *ulc, uint32_t fn);
95struct gprs_rlcmac_sba *pdch_ulc_get_sba(struct pdch_ulc *ulc, uint32_t fn);
Pau Espin Pedrolfd1fbdb2021-03-11 16:59:50 +010096struct gprs_rlcmac_tbf *pdch_ulc_get_tbf_poll(struct pdch_ulc *ulc, uint32_t fn);
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010097
Pau Espin Pedrolade9c2f2021-03-24 14:02:49 +010098void pdch_ulc_release_node(struct pdch_ulc *ulc, struct pdch_ulc_node *item);
Pau Espin Pedrol99360a32021-03-09 17:18:12 +010099void pdch_ulc_release_tbf(struct pdch_ulc *ulc, const struct gprs_rlcmac_tbf *tbf);
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +0100100int pdch_ulc_release_fn(struct pdch_ulc *ulc, uint32_t fn);
101
102void pdch_ulc_expire_fn(struct pdch_ulc *ulc, uint32_t fn);