[PATCH] osmocom-bb[master]: host/trxcon/scheduler: pass trx_lchan_state to lchan handlers

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Feb 22 15:33:16 UTC 2018


Review at  https://gerrit.osmocom.org/6760

host/trxcon/scheduler: pass trx_lchan_state to lchan handlers

It's better to pass a trx_lchan_state instance directly from
caller to lchan handler instead of passing trx_lchan_type. This
way a handler wouldn't need to find lchan itself.

Change-Id: I47a40542b03ab31da12b0abb1c263c83662ff018
---
M src/host/trxcon/sched_lchan_desc.c
M src/host/trxcon/sched_lchan_rach.c
M src/host/trxcon/sched_lchan_sch.c
M src/host/trxcon/sched_lchan_xcch.c
M src/host/trxcon/sched_trx.c
M src/host/trxcon/sched_trx.h
6 files changed, 36 insertions(+), 39 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/60/6760/1

diff --git a/src/host/trxcon/sched_lchan_desc.c b/src/host/trxcon/sched_lchan_desc.c
index e3998fa..dee8f6a 100644
--- a/src/host/trxcon/sched_lchan_desc.c
+++ b/src/host/trxcon/sched_lchan_desc.c
@@ -39,19 +39,19 @@
 
 /* Forward declaration of handlers */
 int rx_data_fn(struct trx_instance *trx, struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan, uint8_t bid,
+	struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid,
 	sbit_t *bits, uint16_t nbits, int8_t rssi, float toa);
 
 int tx_data_fn(struct trx_instance *trx, struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan,
+	struct trx_lchan_state *lchan, uint32_t fn,
 	uint8_t bid, uint16_t *nbits);
 
 int rx_sch_fn(struct trx_instance *trx, struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan, uint8_t bid,
+	struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid,
 	sbit_t *bits, uint16_t nbits, int8_t rssi, float toa);
 
 int tx_rach_fn(struct trx_instance *trx, struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan,
+	struct trx_lchan_state *lchan, uint32_t fn,
 	uint8_t bid, uint16_t *nbits);
 
 const struct trx_lchan_desc trx_lchan_desc[_TRX_CHAN_MAX] = {
diff --git a/src/host/trxcon/sched_lchan_rach.c b/src/host/trxcon/sched_lchan_rach.c
index 0e8d2e8..6a10ab8 100644
--- a/src/host/trxcon/sched_lchan_rach.c
+++ b/src/host/trxcon/sched_lchan_rach.c
@@ -58,7 +58,7 @@
 
 /* Obtain a to-be-transmitted RACH burst */
 int tx_rach_fn(struct trx_instance *trx, struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan,
+	struct trx_lchan_state *lchan, uint32_t fn,
 	uint8_t bid, uint16_t *nbits)
 {
 	struct trx_ts_prim *prim;
diff --git a/src/host/trxcon/sched_lchan_sch.c b/src/host/trxcon/sched_lchan_sch.c
index 9e854bb..aff8fb6 100644
--- a/src/host/trxcon/sched_lchan_sch.c
+++ b/src/host/trxcon/sched_lchan_sch.c
@@ -73,7 +73,7 @@
 }
 
 int rx_sch_fn(struct trx_instance *trx, struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan, uint8_t bid,
+	struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid,
 	sbit_t *bits, uint16_t nbits, int8_t rssi, float toa)
 {
 	sbit_t payload[2 * 39];
@@ -117,8 +117,8 @@
 		return -ENOMEM;
 
 	/* Fill in some downlink info */
-	data->chan_nr = trx_lchan_desc[chan].chan_nr | ts->index;
-	data->link_id = trx_lchan_desc[chan].link_id;
+	data->chan_nr = trx_lchan_desc[lchan->type].chan_nr | ts->index;
+	data->link_id = trx_lchan_desc[lchan->type].link_id;
 	data->band_arfcn = htons(trx->band_arfcn);
 	data->frame_nr = htonl(fn);
 	data->rx_level = -rssi;
diff --git a/src/host/trxcon/sched_lchan_xcch.c b/src/host/trxcon/sched_lchan_xcch.c
index 81bd305..aa95656 100644
--- a/src/host/trxcon/sched_lchan_xcch.c
+++ b/src/host/trxcon/sched_lchan_xcch.c
@@ -83,26 +83,19 @@
 };
 
 int rx_data_fn(struct trx_instance *trx, struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan, uint8_t bid,
+	struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid,
 	sbit_t *bits, uint16_t nbits, int8_t rssi, float toa)
 {
+	const struct trx_lchan_desc *lchan_desc;
 	int n_errors, n_bits_total, rc;
-	struct trx_lchan_state *lchan;
 	uint8_t *rssi_num, *toa_num;
 	float *rssi_sum, *toa_sum;
 	sbit_t *buffer, *offset;
 	uint8_t l2[23], *mask;
 	uint32_t *first_fn;
 
-	LOGP(DSCH, LOGL_DEBUG, "Data received on %s: fn=%u ts=%u bid=%u\n",
-		trx_lchan_desc[chan].name, fn, ts->index, bid);
-
-	/* Find required channel state */
-	lchan = sched_trx_find_lchan(ts, chan);
-	if (lchan == NULL)
-		return -EINVAL;
-
 	/* Set up pointers */
+	lchan_desc = &trx_lchan_desc[lchan->type];
 	first_fn = &lchan->rx_first_fn;
 	mask = &lchan->rx_burst_mask;
 	buffer = lchan->rx_bursts;
@@ -111,6 +104,9 @@
 	rssi_num = &lchan->rssi_num;
 	toa_sum = &lchan->toa_sum;
 	toa_num = &lchan->toa_num;
+
+	LOGP(DSCH, LOGL_DEBUG, "Data received on %s: fn=%u ts=%u bid=%u\n",
+		lchan_desc->name, fn, ts->index, bid);
 
 	/* Clear buffer & store frame number of first burst */
 	if (bid == 0) {
@@ -147,7 +143,7 @@
 			"fn=%u (%u/%u) for %s\n", *first_fn,
 			(*first_fn) % ts->mf_layout->period,
 			ts->mf_layout->period,
-			trx_lchan_desc[chan].name);
+			lchan_desc->name);
 
 		return -1;
 	}
@@ -159,7 +155,7 @@
 			"(%u/%u) for %s\n", *first_fn,
 			(*first_fn) % ts->mf_layout->period,
 			ts->mf_layout->period,
-			trx_lchan_desc[chan].name);
+			lchan_desc->name);
 		return rc;
 	}
 
@@ -170,8 +166,8 @@
 		return -ENOMEM;
 
 	/* Fill in some downlink info */
-	data->chan_nr = trx_lchan_desc[chan].chan_nr | ts->index;
-	data->link_id = trx_lchan_desc[chan].link_id;
+	data->chan_nr = lchan_desc->chan_nr | ts->index;
+	data->link_id = lchan_desc->link_id;
 	data->band_arfcn = htons(trx->band_arfcn);
 	data->frame_nr = htonl(*first_fn);
 	data->rx_level = -(*rssi_sum / *rssi_num);
@@ -193,10 +189,10 @@
 }
 
 int tx_data_fn(struct trx_instance *trx, struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan,
+	struct trx_lchan_state *lchan, uint32_t fn,
 	uint8_t bid, uint16_t *nbits)
 {
-	struct trx_lchan_state *lchan;
+	const struct trx_lchan_desc *lchan_desc;
 	struct trx_ts_prim *prim;
 	struct l1ctl_info_ul *ul;
 	ubit_t burst[GSM_BURST_LEN];
@@ -205,12 +201,8 @@
 	const uint8_t *tsc;
 	int rc;
 
-	/* Find required channel state */
-	lchan = sched_trx_find_lchan(ts, chan);
-	if (lchan == NULL)
-		return -EINVAL;
-
 	/* Set up pointers */
+	lchan_desc = &trx_lchan_desc[lchan->type];
 	mask = &lchan->tx_burst_mask;
 	buffer = lchan->tx_bursts;
 
@@ -262,7 +254,7 @@
 		*nbits = GSM_BURST_LEN;
 
 	LOGP(DSCH, LOGL_DEBUG, "Transmitting %s fn=%u ts=%u burst=%u\n",
-		trx_lchan_desc[chan].name, fn, ts->index, bid);
+		lchan_desc->name, fn, ts->index, bid);
 
 	/* Send burst to transceiver */
 	rc = trx_if_tx_burst(trx, ts->index, fn, 10, burst);
diff --git a/src/host/trxcon/sched_trx.c b/src/host/trxcon/sched_trx.c
index 40d1446..b9f1889 100644
--- a/src/host/trxcon/sched_trx.c
+++ b/src/host/trxcon/sched_trx.c
@@ -49,6 +49,7 @@
 {
 	struct trx_instance *trx = (struct trx_instance *) sched->data;
 	const struct trx_frame *frame;
+	struct trx_lchan_state *lchan;
 	trx_lchan_tx_func *handler;
 	struct trx_ts_prim *prim;
 	enum trx_lchan_type chan;
@@ -86,12 +87,17 @@
 		if (!handler)
 			continue;
 
+		/* Make sure that lchan was allocated and activated */
+		lchan = sched_trx_find_lchan(ts, chan);
+		if (lchan == NULL)
+			continue;
+
 		/* Get a message from TX queue */
 		prim = llist_entry(ts->tx_prims.next, struct trx_ts_prim, list);
 
 		/* Poke lchan handler */
 		if (prim->chan == chan)
-			handler(trx, ts, fn, chan, bid, NULL);
+			handler(trx, ts, lchan, fn, bid, NULL);
 	}
 }
 
@@ -500,7 +506,7 @@
 		/* Put burst to handler */
 		if (fn == burst_fn) {
 			/* TODO: decrypt if required */
-			handler(trx, ts, fn, chan, bid, bits, nbits, rssi, toa);
+			handler(trx, ts, lchan, fn, bid, bits, nbits, rssi, toa);
 		}
 
 next_frame:
diff --git a/src/host/trxcon/sched_trx.h b/src/host/trxcon/sched_trx.h
index 7ebfa15..f8a8b53 100644
--- a/src/host/trxcon/sched_trx.h
+++ b/src/host/trxcon/sched_trx.h
@@ -23,6 +23,7 @@
 #define MAX_A5_KEY_LEN		(128 / 8)
 
 /* Forward declaration to avoid mutual include */
+struct trx_lchan_state;
 struct trx_instance;
 struct trx_ts;
 
@@ -78,15 +79,13 @@
 };
 
 typedef int trx_lchan_rx_func(struct trx_instance *trx,
-	struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan,
-	uint8_t bid, sbit_t *bits, uint16_t nbits,
-	int8_t rssi, float toa);
+	struct trx_ts *ts, struct trx_lchan_state *lchan,
+	uint32_t fn, uint8_t bid, sbit_t *bits,
+	uint16_t nbits, int8_t rssi, float toa);
 
 typedef int trx_lchan_tx_func(struct trx_instance *trx,
-	struct trx_ts *ts,
-	uint32_t fn, enum trx_lchan_type chan,
-	uint8_t bid, uint16_t *nbits);
+	struct trx_ts *ts, struct trx_lchan_state *lchan,
+	uint32_t fn, uint8_t bid, uint16_t *nbits);
 
 struct trx_lchan_desc {
 	/*! \brief TRX Channel Type */

-- 
To view, visit https://gerrit.osmocom.org/6760
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I47a40542b03ab31da12b0abb1c263c83662ff018
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list