[PATCH] osmo-bts[master]: TRX: merge/simplify l1_if and trx_if code

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
Sat Jun 24 16:48:36 UTC 2017


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

TRX: merge/simplify l1_if and trx_if code

Related code / function structure still dates back to the pre-phy_link
days.  Let's clean this up to make things less convoluted and reduce the
number of non-static symbols needed between code split over two files.

Change-Id: I1f30ae1f547a5c01c516d4a05032193294c25f2d
---
M src/osmo-bts-trx/l1_if.c
M src/osmo-bts-trx/l1_if.h
M src/osmo-bts-trx/trx_if.c
M src/osmo-bts-trx/trx_if.h
4 files changed, 93 insertions(+), 104 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/42/3042/1

diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c
index a7bcd2c..59a6b6c 100644
--- a/src/osmo-bts-trx/l1_if.c
+++ b/src/osmo-bts-trx/l1_if.c
@@ -57,48 +57,6 @@
 };
 
 
-/*
- * create/destroy trx l1 instance
- */
-
-struct trx_l1h *l1if_open(struct phy_instance *pinst)
-{
-	struct trx_l1h *l1h;
-	int rc;
-
-	l1h = pinst->u.osmotrx.hdl;
-	if (!l1h)
-		return NULL;
-
-	rc = trx_sched_init(&l1h->l1s, pinst->trx);
-	if (rc < 0) {
-		LOGP(DL1C, LOGL_FATAL, "Cannot initialize scheduler for phy "
-		     "instance %d\n", pinst->num);
-		return NULL;
-	}
-
-	rc = trx_if_open(l1h);
-	if (rc < 0) {
-		LOGP(DL1C, LOGL_FATAL, "Cannot open TRX interface for phy "
-		     "instance %d\n", pinst->num);
-		l1if_close(l1h);
-		return NULL;
-	}
-
-	return l1h;
-}
-
-void l1if_close(struct trx_l1h *l1h)
-{
-	trx_if_close(l1h);
-	trx_sched_exit(&l1h->l1s);
-	talloc_free(l1h);
-}
-
-void l1if_reset(struct trx_l1h *l1h)
-{
-}
-
 static void check_transceiver_availability_trx(struct trx_l1h *l1h, int avail)
 {
 	struct phy_instance *pinst = l1h->phy_inst;
diff --git a/src/osmo-bts-trx/l1_if.h b/src/osmo-bts-trx/l1_if.h
index 1864857..40f55ab 100644
--- a/src/osmo-bts-trx/l1_if.h
+++ b/src/osmo-bts-trx/l1_if.h
@@ -61,9 +61,6 @@
 	struct l1sched_trx	l1s;
 };
 
-struct trx_l1h *l1if_open(struct phy_instance *pinst);
-void l1if_close(struct trx_l1h *l1h);
-void l1if_reset(struct trx_l1h *l1h);
 int check_transceiver_availability(struct gsm_bts *bts, int avail);
 int l1if_provision_transceiver_trx(struct trx_l1h *l1h);
 int l1if_provision_transceiver(struct gsm_bts *bts);
diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
index ba2908a..c56efbf 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -536,47 +536,32 @@
  * open/close
  */
 
-/*! open the PHY link using TRX protocol */
-int bts_model_phy_link_open(struct phy_link *plink)
+/*! flush (delete) all pending control messages */
+void trx_if_flush(struct trx_l1h *l1h)
 {
-	struct phy_instance *pinst;
-	int rc;
+	struct trx_ctrl_msg *tcm;
 
-	phy_link_state_set(plink, PHY_LINK_CONNECTING);
-
-	/* open the shared/common clock socket */
-	rc = trx_udp_open(plink, &plink->u.osmotrx.trx_ofd_clk,
-			  plink->u.osmotrx.local_ip,
-			  plink->u.osmotrx.base_port_local,
-			  plink->u.osmotrx.remote_ip,
-			  plink->u.osmotrx.base_port_remote,
-			  trx_clk_read_cb);
-	if (rc < 0) {
-		phy_link_state_set(plink, PHY_LINK_SHUTDOWN);
-		return -1;
+	/* free ctrl message list */
+	while (!llist_empty(&l1h->trx_ctrl_list)) {
+		tcm = llist_entry(l1h->trx_ctrl_list.next, struct trx_ctrl_msg,
+			list);
+		llist_del(&tcm->list);
+		talloc_free(tcm);
 	}
+}
 
-	/* open the individual instances with their ctrl+data sockets */
-	llist_for_each_entry(pinst, &plink->instances, list) {
-		pinst->u.osmotrx.hdl = l1if_open(pinst);
-		if (!pinst->u.osmotrx.hdl)
-			goto cleanup;
-	}
-	/* FIXME: is there better way to check/report TRX availability? */
-	transceiver_available = 1;
-	phy_link_state_set(plink, PHY_LINK_CONNECTED);
-	return 0;
+/*! close the TRX for given handle (data + control socket) */
+void trx_if_close(struct trx_l1h *l1h)
+{
+	struct phy_instance *pinst = l1h->phy_inst;
+	LOGP(DTRX, LOGL_NOTICE, "Close transceiver for %s\n",
+		phy_instance_name(pinst));
 
-cleanup:
-	phy_link_state_set(plink, PHY_LINK_SHUTDOWN);
-	llist_for_each_entry(pinst, &plink->instances, list) {
-		if (pinst->u.osmotrx.hdl) {
-			trx_if_close(pinst->u.osmotrx.hdl);
-			pinst->u.osmotrx.hdl = NULL;
-		}
-	}
-	trx_udp_close(&plink->u.osmotrx.trx_ofd_clk);
-	return -1;
+	trx_if_flush(l1h);
+
+	/* close sockets */
+	trx_udp_close(&l1h->trx_ofd_ctrl);
+	trx_udp_close(&l1h->trx_ofd_data);
 }
 
 /*! compute UDP port number used for TRX protocol */
@@ -595,7 +580,7 @@
 }
 
 /*! open a TRX interface. creates contro + data sockets */
-int trx_if_open(struct trx_l1h *l1h)
+static int trx_if_open(struct trx_l1h *l1h)
 {
 	struct phy_instance *pinst = l1h->phy_inst;
 	struct phy_link *plink = pinst->phy_link;
@@ -637,32 +622,84 @@
 	return rc;
 }
 
-/*! flush (delete) all pending control messages */
-void trx_if_flush(struct trx_l1h *l1h)
+/*! close the control + burst data sockets for one phy_instance */
+static void trx_phy_inst_close(struct phy_instance *pinst)
 {
-	struct trx_ctrl_msg *tcm;
+	struct trx_l1h *l1h = pinst->u.osmotrx.hdl;
 
-	/* free ctrl message list */
-	while (!llist_empty(&l1h->trx_ctrl_list)) {
-		tcm = llist_entry(l1h->trx_ctrl_list.next, struct trx_ctrl_msg,
-			list);
-		llist_del(&tcm->list);
-		talloc_free(tcm);
-	}
+	trx_if_close(l1h);
+	trx_sched_exit(&l1h->l1s);
+	talloc_free(l1h);
 }
 
-/*! close the TRX for given handle (data + control socket) */
-void trx_if_close(struct trx_l1h *l1h)
+/*! open the control + burst data sockets for one phy_instance */
+static int trx_phy_inst_open(struct phy_instance *pinst)
 {
-	struct phy_instance *pinst = l1h->phy_inst;
-	LOGP(DTRX, LOGL_NOTICE, "Close transceiver for %s\n",
-		phy_instance_name(pinst));
+	struct trx_l1h *l1h;
+	int rc;
 
-	trx_if_flush(l1h);
+	l1h = pinst->u.osmotrx.hdl;
+	if (!l1h)
+		return -EINVAL;
 
-	/* close sockets */
-	trx_udp_close(&l1h->trx_ofd_ctrl);
-	trx_udp_close(&l1h->trx_ofd_data);
+	rc = trx_sched_init(&l1h->l1s, pinst->trx);
+	if (rc < 0) {
+		LOGP(DL1C, LOGL_FATAL, "Cannot initialize scheduler for phy "
+		     "instance %d\n", pinst->num);
+		return -EIO;
+	}
+
+	rc = trx_if_open(l1h);
+	if (rc < 0) {
+		LOGP(DL1C, LOGL_FATAL, "Cannot open TRX interface for phy "
+		     "instance %d\n", pinst->num);
+		trx_phy_inst_close(pinst);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+/*! open the PHY link using TRX protocol */
+int bts_model_phy_link_open(struct phy_link *plink)
+{
+	struct phy_instance *pinst;
+	int rc;
+
+	phy_link_state_set(plink, PHY_LINK_CONNECTING);
+
+	/* open the shared/common clock socket */
+	rc = trx_udp_open(plink, &plink->u.osmotrx.trx_ofd_clk,
+			  plink->u.osmotrx.local_ip,
+			  plink->u.osmotrx.base_port_local,
+			  plink->u.osmotrx.remote_ip,
+			  plink->u.osmotrx.base_port_remote,
+			  trx_clk_read_cb);
+	if (rc < 0) {
+		phy_link_state_set(plink, PHY_LINK_SHUTDOWN);
+		return -1;
+	}
+
+	/* open the individual instances with their ctrl+data sockets */
+	llist_for_each_entry(pinst, &plink->instances, list) {
+		if (trx_phy_inst_open(pinst) < 0)
+			goto cleanup;
+	}
+	/* FIXME: is there better way to check/report TRX availability? */
+	transceiver_available = 1;
+	phy_link_state_set(plink, PHY_LINK_CONNECTED);
+	return 0;
+
+cleanup:
+	phy_link_state_set(plink, PHY_LINK_SHUTDOWN);
+	llist_for_each_entry(pinst, &plink->instances, list) {
+		if (pinst->u.osmotrx.hdl) {
+			trx_if_close(pinst->u.osmotrx.hdl);
+			pinst->u.osmotrx.hdl = NULL;
+		}
+	}
+	trx_udp_close(&plink->u.osmotrx.trx_ofd_clk);
+	return -1;
 }
 
 /*! determine if the TRX for given handle is powered up */
diff --git a/src/osmo-bts-trx/trx_if.h b/src/osmo-bts-trx/trx_if.h
index 93ea180..1fc454d 100644
--- a/src/osmo-bts-trx/trx_if.h
+++ b/src/osmo-bts-trx/trx_if.h
@@ -31,9 +31,6 @@
 int trx_if_cmd_nohandover(struct trx_l1h *l1h, uint8_t tn, uint8_t ss);
 int trx_if_send_burst(struct trx_l1h *l1h, uint8_t tn, uint32_t fn, uint8_t pwr,
 	const ubit_t *bits, uint16_t nbits);
-int trx_if_open(struct trx_l1h *l1h);
-void trx_if_flush(struct trx_l1h *l1h);
-void trx_if_close(struct trx_l1h *l1h);
 int trx_if_powered(struct trx_l1h *l1h);
 
 #endif /* TRX_IF_H */

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f30ae1f547a5c01c516d4a05032193294c25f2d
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list