alloc: Use a separate usage computation for algo A

Currently algorithm A can select an TBF even when there is no free
TBF in the reverse direction. While this does not necessarily lead to
an allocation failure, the probabily is higher. In addition, the
current slot reservations are not taken into account.

This commit changes the selection algorithm to prefer slots where TFI
are available in both directions and which are less reserved.

Sponsored-by: On-Waves ehf
diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index ffbbe2b..e2c2a0f 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -211,6 +211,22 @@
 		pdch->num_reserved(GPRS_RLCMAC_UL_TBF);
 }
 
+static int compute_usage_for_algo_a(struct gprs_rlcmac_pdch *pdch,
+	enum gprs_rlcmac_tbf_direction dir)
+{
+	int usage =
+		pdch->num_tbfs(GPRS_RLCMAC_DL_TBF) +
+		pdch->num_tbfs(GPRS_RLCMAC_UL_TBF) +
+		compute_usage_by_reservation(pdch, dir);
+
+	if (pdch->assigned_tfi(reverse(dir)) == 0xffffffff)
+		/* No TFI in the opposite direction, avoid it */
+		usage += 32;
+
+	return usage;
+
+}
+
 static int find_least_busy_pdch(struct gprs_rlcmac_trx *trx,
 	enum gprs_rlcmac_tbf_direction dir,
 	uint8_t mask,
@@ -417,7 +433,7 @@
 		return -EINVAL;
 
 	ts = find_least_busy_pdch(trx, tbf->direction, mask,
-		compute_usage_by_reservation,
+		compute_usage_for_algo_a,
 		&tfi, &usf);
 
 	if (tbf->direction == GPRS_RLCMAC_UL_TBF && usf < 0) {