Add new PDCH UL Controller, drop SBAllocator class

Right now we handle different types of UL allocations in different
classes like PollAllocator and SBAllocator, and they usually don't take
into account the other one in most cases. Furthermore, those objects are
usually per-BTS object, instead of per PDCH object.

This is a first step towards having a unified per-PDCH controller which
takes care of controlling what is scheduled and hence expected on the
uplink. Each PDCH has a UL Controller which keeps track of all reserved
uplink frame, be it SB, RRBP poll or USF assigned, all under the same
API.

As a first step, only the SBA part is fully implemented and used (being
it the easiest part to replace); TBF poll+usf will come in follow-up
patches later on. As a result, the SBAllocator per-BTS class dissappears
but some of its code is refactored/reused to provide more features to the
gprs_rlcmac_sba object, which is also further integrated into the new UL
Controller.

Related: OS#5020
Change-Id: I84b24beea4a1aa2c1528f41435f77bd16df2b947
diff --git a/src/pdch_ul_controller.h b/src/pdch_ul_controller.h
new file mode 100644
index 0000000..e86dbf5
--- /dev/null
+++ b/src/pdch_ul_controller.h
@@ -0,0 +1,79 @@
+/* pdch_ul_controller.h
+ *
+ * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+ * Author: Pau Espin Pedrol <pespin@sysmocom.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include <osmocom/core/linuxrbtree.h>
+#include <osmocom/core/utils.h>
+
+struct gprs_rlcmac_pdch;
+struct gprs_rlcmac_tbf;
+struct gprs_rlcmac_ul_tbf;
+struct gprs_rlcmac_sba;
+
+struct pdch_ulc {
+	struct gprs_rlcmac_pdch *pdch; /* back pointer */
+	uint32_t last_fn; /* last FN rx from TDMA clock */
+	struct rb_root tree_root;
+	void *pool_ctx; /* talloc pool of struct pdch_ulc_node  */
+};
+
+enum PdchUlcNode {
+	PDCH_ULC_NODE_TBF_USF,
+	PDCH_ULC_NODE_TBF_POLL,
+	PDCH_ULC_NODE_SBA,
+};
+extern const struct value_string pdch_ul_node_names[];
+
+struct pdch_ulc_node {
+	struct rb_node node;	  /*! entry in pdch_ulc->tree_root */
+	uint32_t fn;
+	enum PdchUlcNode type;
+	union {
+		struct {
+			struct gprs_rlcmac_ul_tbf *ul_tbf;
+		} tbf_usf;
+		struct {
+			struct gprs_rlcmac_tbf *poll_tbf;
+		} tbf_poll;
+		struct {
+			struct gprs_rlcmac_sba *sba;
+		} sba;
+	};
+};
+
+
+struct pdch_ulc *pdch_ulc_alloc(struct gprs_rlcmac_pdch *pdch, void *ctx);
+
+int pdch_ulc_reserve_tbf_usf(struct pdch_ulc *ulc, uint32_t fn, struct gprs_rlcmac_ul_tbf *ul_tbf);
+int pdch_ulc_reserve_tbf_poll(struct pdch_ulc *ulc, uint32_t fn, struct gprs_rlcmac_tbf *tbf);
+int pdch_ulc_reserve_sba(struct pdch_ulc *ulc, struct gprs_rlcmac_sba *sba);
+
+bool pdch_ulc_fn_is_free(struct pdch_ulc *ulc, uint32_t fn);
+
+struct pdch_ulc_node *pdch_ulc_get_node(struct pdch_ulc *ulc, uint32_t fn);
+struct pdch_ulc_node *pdch_ulc_pop_node(struct pdch_ulc *ulc, uint32_t fn);
+struct gprs_rlcmac_sba *pdch_ulc_get_sba(struct pdch_ulc *ulc, uint32_t fn);
+
+int pdch_ulc_release_fn(struct pdch_ulc *ulc, uint32_t fn);
+
+void pdch_ulc_expire_fn(struct pdch_ulc *ulc, uint32_t fn);