Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 1 | /* 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 Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 15 | */ |
| 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 | |
| 24 | struct gprs_rlcmac_pdch; |
| 25 | struct gprs_rlcmac_tbf; |
| 26 | struct gprs_rlcmac_ul_tbf; |
| 27 | struct gprs_rlcmac_sba; |
| 28 | |
Pau Espin Pedrol | 50a1ede | 2021-03-29 13:49:43 +0200 | [diff] [blame] | 29 | /* RRBP offsets, see TS 44.060 able 10.4.5.1 */ |
| 30 | enum 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 Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 37 | struct pdch_ulc { |
| 38 | struct gprs_rlcmac_pdch *pdch; /* back pointer */ |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 39 | struct rb_root tree_root; |
| 40 | void *pool_ctx; /* talloc pool of struct pdch_ulc_node */ |
| 41 | }; |
| 42 | |
| 43 | enum PdchUlcNode { |
| 44 | PDCH_ULC_NODE_TBF_USF, |
| 45 | PDCH_ULC_NODE_TBF_POLL, |
| 46 | PDCH_ULC_NODE_SBA, |
| 47 | }; |
| 48 | extern const struct value_string pdch_ul_node_names[]; |
| 49 | |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 50 | enum 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 Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 53 | 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 Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 54 | 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 Pedrol | c6e911c | 2021-06-07 18:13:23 +0200 | [diff] [blame] | 57 | extern const struct value_string pdch_ulc_tbf_poll_reason_names[]; |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 58 | |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 59 | struct 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 Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 69 | enum pdch_ulc_tbf_poll_reason reason; |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 70 | } tbf_poll; |
| 71 | struct { |
| 72 | struct gprs_rlcmac_sba *sba; |
| 73 | } sba; |
| 74 | }; |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | struct pdch_ulc *pdch_ulc_alloc(struct gprs_rlcmac_pdch *pdch, void *ctx); |
| 79 | |
| 80 | int pdch_ulc_reserve_tbf_usf(struct pdch_ulc *ulc, uint32_t fn, struct gprs_rlcmac_ul_tbf *ul_tbf); |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 81 | int 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 Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 82 | int pdch_ulc_reserve_sba(struct pdch_ulc *ulc, struct gprs_rlcmac_sba *sba); |
| 83 | |
| 84 | bool pdch_ulc_fn_is_free(struct pdch_ulc *ulc, uint32_t fn); |
| 85 | |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 86 | int pdch_ulc_get_next_free_rrbp_fn(struct pdch_ulc *ulc, uint32_t fn, uint32_t *poll_fn, unsigned int *rrbp); |
Max | dc6a860 | 2022-11-17 19:25:40 +0300 | [diff] [blame] | 87 | uint32_t pdch_ulc_get_next_free_fn(const struct pdch_ulc *ulc, uint32_t start_fn); |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 88 | |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 89 | struct pdch_ulc_node *pdch_ulc_get_node(struct pdch_ulc *ulc, uint32_t fn); |
| 90 | struct pdch_ulc_node *pdch_ulc_pop_node(struct pdch_ulc *ulc, uint32_t fn); |
| 91 | struct gprs_rlcmac_sba *pdch_ulc_get_sba(struct pdch_ulc *ulc, uint32_t fn); |
Pau Espin Pedrol | fd1fbdb | 2021-03-11 16:59:50 +0100 | [diff] [blame] | 92 | struct gprs_rlcmac_tbf *pdch_ulc_get_tbf_poll(struct pdch_ulc *ulc, uint32_t fn); |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 93 | |
Pau Espin Pedrol | ade9c2f | 2021-03-24 14:02:49 +0100 | [diff] [blame] | 94 | void pdch_ulc_release_node(struct pdch_ulc *ulc, struct pdch_ulc_node *item); |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 95 | void pdch_ulc_release_tbf(struct pdch_ulc *ulc, const struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 96 | int pdch_ulc_release_fn(struct pdch_ulc *ulc, uint32_t fn); |
| 97 | |
| 98 | void pdch_ulc_expire_fn(struct pdch_ulc *ulc, uint32_t fn); |