diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-06-24 18:15:40 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-07-01 07:38:01 +0000 |
commit | f2eaba88691d0125ed033add7863403593745b3e (patch) | |
tree | b2764025d57d662435a94f06b4ddc336c3b0435d /src | |
parent | cdf20fec7c4729e81b1c6c78147dc8aaa74682e3 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/osmo-bts-trx/l1_if.c | 42 | ||||
-rw-r--r-- | src/osmo-bts-trx/l1_if.h | 3 | ||||
-rw-r--r-- | src/osmo-bts-trx/trx_if.c | 147 | ||||
-rw-r--r-- | src/osmo-bts-trx/trx_if.h | 3 |
4 files changed, 92 insertions, 103 deletions
diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c index 35177870..37a399f3 100644 --- a/src/osmo-bts-trx/l1_if.c +++ b/src/osmo-bts-trx/l1_if.c @@ -57,48 +57,6 @@ static const uint8_t transceiver_chan_types[_GSM_PCHAN_MAX] = { }; -/* - * 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 fdc40f2c..d978c44d 100644 --- a/src/osmo-bts-trx/l1_if.h +++ b/src/osmo-bts-trx/l1_if.h @@ -61,9 +61,6 @@ struct trx_l1h { 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 ba2908ad..c56efbfa 100644 --- a/src/osmo-bts-trx/trx_if.c +++ b/src/osmo-bts-trx/trx_if.c @@ -536,47 +536,32 @@ int trx_if_send_burst(struct trx_l1h *l1h, uint8_t tn, uint32_t fn, uint8_t pwr, * 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; - - phy_link_state_set(plink, PHY_LINK_CONNECTING); + struct trx_ctrl_msg *tcm; - /* 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 @@ static uint16_t compute_port(struct phy_instance *pinst, int remote, int is_data } /*! 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 @@ err: 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); +} + +/*! open the control + burst data sockets for one phy_instance */ +static int trx_phy_inst_open(struct phy_instance *pinst) +{ + struct trx_l1h *l1h; + int rc; + + l1h = pinst->u.osmotrx.hdl; + if (!l1h) + return -EINVAL; + + 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; } -/*! close the TRX for given handle (data + control socket) */ -void trx_if_close(struct trx_l1h *l1h) +/*! open the PHY link using TRX protocol */ +int bts_model_phy_link_open(struct phy_link *plink) { - struct phy_instance *pinst = l1h->phy_inst; - LOGP(DTRX, LOGL_NOTICE, "Close transceiver for %s\n", - phy_instance_name(pinst)); + struct phy_instance *pinst; + int rc; - trx_if_flush(l1h); + phy_link_state_set(plink, PHY_LINK_CONNECTING); - /* close sockets */ - trx_udp_close(&l1h->trx_ofd_ctrl); - trx_udp_close(&l1h->trx_ofd_data); + /* 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 93ea1800..1fc454dc 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_handover(struct trx_l1h *l1h, uint8_t tn, uint8_t ss); 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 */ |