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. |
| 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 | |
| 28 | struct gprs_rlcmac_pdch; |
| 29 | struct gprs_rlcmac_tbf; |
| 30 | struct gprs_rlcmac_ul_tbf; |
| 31 | struct gprs_rlcmac_sba; |
| 32 | |
Pau Espin Pedrol | 50a1ede | 2021-03-29 13:49:43 +0200 | [diff] [blame] | 33 | /* RRBP offsets, see TS 44.060 able 10.4.5.1 */ |
| 34 | enum 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 Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 41 | struct 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 | |
| 48 | enum PdchUlcNode { |
| 49 | PDCH_ULC_NODE_TBF_USF, |
| 50 | PDCH_ULC_NODE_TBF_POLL, |
| 51 | PDCH_ULC_NODE_SBA, |
| 52 | }; |
| 53 | extern const struct value_string pdch_ul_node_names[]; |
| 54 | |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 55 | enum 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 Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 58 | 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] | 59 | 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 | }; |
Pau Espin Pedrol | c6e911c | 2021-06-07 18:13:23 +0200 | [diff] [blame] | 62 | extern const struct value_string pdch_ulc_tbf_poll_reason_names[]; |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 63 | |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 64 | struct pdch_ulc_node { |
| 65 | struct rb_node node; /*! entry in pdch_ulc->tree_root */ |
| 66 | uint32_t fn; |
| 67 | enum PdchUlcNode type; |
| 68 | union { |
| 69 | struct { |
| 70 | struct gprs_rlcmac_ul_tbf *ul_tbf; |
| 71 | } tbf_usf; |
| 72 | struct { |
| 73 | struct gprs_rlcmac_tbf *poll_tbf; |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 74 | enum pdch_ulc_tbf_poll_reason reason; |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 75 | } tbf_poll; |
| 76 | struct { |
| 77 | struct gprs_rlcmac_sba *sba; |
| 78 | } sba; |
| 79 | }; |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | struct pdch_ulc *pdch_ulc_alloc(struct gprs_rlcmac_pdch *pdch, void *ctx); |
| 84 | |
| 85 | 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] | 86 | 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] | 87 | int pdch_ulc_reserve_sba(struct pdch_ulc *ulc, struct gprs_rlcmac_sba *sba); |
| 88 | |
| 89 | bool pdch_ulc_fn_is_free(struct pdch_ulc *ulc, uint32_t fn); |
| 90 | |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 91 | int pdch_ulc_get_next_free_rrbp_fn(struct pdch_ulc *ulc, uint32_t fn, uint32_t *poll_fn, unsigned int *rrbp); |
Pau Espin Pedrol | ce3bd25 | 2021-03-29 12:13:13 +0200 | [diff] [blame] | 92 | uint32_t pdch_ulc_get_next_free_fn(struct pdch_ulc *ulc, uint32_t start_fn); |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 93 | |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 94 | struct pdch_ulc_node *pdch_ulc_get_node(struct pdch_ulc *ulc, uint32_t fn); |
| 95 | struct pdch_ulc_node *pdch_ulc_pop_node(struct pdch_ulc *ulc, uint32_t fn); |
| 96 | 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] | 97 | 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] | 98 | |
Pau Espin Pedrol | ade9c2f | 2021-03-24 14:02:49 +0100 | [diff] [blame] | 99 | 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] | 100 | 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] | 101 | int pdch_ulc_release_fn(struct pdch_ulc *ulc, uint32_t fn); |
| 102 | |
| 103 | void pdch_ulc_expire_fn(struct pdch_ulc *ulc, uint32_t fn); |