Change in osmo-bts[master]: Move struct gsm_bts_trx: gsm_data.* & bts.* => trx.*

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/.

pespin gerrit-no-reply at lists.osmocom.org
Fri Jul 3 15:27:58 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/19124 )


Change subject: Move struct gsm_bts_trx: gsm_data.* & bts.* => trx.*
......................................................................

Move struct gsm_bts_trx: gsm_data.* & bts.* => trx.*

Move all struct gsm_bts_trx references from bulky gsm_data to its own
file containing all related definitions and implementations. Also move a
few functions clearly related to that object which were placed in bts.*

Change-Id: Iebaf5b221c48b571f45408af867ce6f9c0cd9f4a
---
M include/osmo-bts/Makefile.am
M include/osmo-bts/bts.h
M include/osmo-bts/gsm_data.h
M include/osmo-bts/phy_link.h
A include/osmo-bts/trx.h
M src/common/Makefile.am
M src/common/abis.c
M src/common/bts.c
M src/common/bts_ctrl_lookup.c
M src/common/gsm_data.c
M src/common/sysinfo.c
A src/common/trx.c
M src/common/tx_power.c
13 files changed, 283 insertions(+), 237 deletions(-)



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

diff --git a/include/osmo-bts/Makefile.am b/include/osmo-bts/Makefile.am
index 310fce2..6f6b133 100644
--- a/include/osmo-bts/Makefile.am
+++ b/include/osmo-bts/Makefile.am
@@ -26,4 +26,5 @@
 	phy_link.h \
 	dtx_dl_amr_fsm.h \
 	ta_control.h \
+	trx.h \
 	$(NULL)
diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index cb8787f..4e3e41a 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -3,6 +3,10 @@
 
 #include <osmocom/core/rate_ctr.h>
 #include <osmo-bts/gsm_data.h>
+#include <osmo-bts/trx.h>
+
+
+struct gsm_bts_trx;
 
 enum bts_global_status {
 	BTS_STATUS_RF_ACTIVE,
@@ -318,12 +322,9 @@
 struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
 
 int bts_init(struct gsm_bts *bts);
-int bts_trx_init(struct gsm_bts_trx *trx);
 void bts_shutdown(struct gsm_bts *bts, const char *reason);
 
 int bts_link_estab(struct gsm_bts *bts);
-int trx_link_estab(struct gsm_bts_trx *trx);
-int trx_set_available(struct gsm_bts_trx *trx, int avail);
 
 int bts_agch_enqueue(struct gsm_bts *bts, struct msgb *msg);
 struct msgb *bts_agch_dequeue(struct gsm_bts *bts);
@@ -337,11 +338,8 @@
 int lchan_init_lapdm(struct gsm_lchan *lchan);
 
 void load_timer_start(struct gsm_bts *bts);
-uint8_t num_agch(struct gsm_bts_trx *trx, const char * arg);
 void bts_update_status(enum bts_global_status which, int on);
 
-bool trx_ms_pwr_ctrl_is_osmo(struct gsm_bts_trx *trx);
-
 struct gsm_time *get_time(struct gsm_bts *bts);
 
 int bts_main(int argc, char **argv);
diff --git a/include/osmo-bts/gsm_data.h b/include/osmo-bts/gsm_data.h
index 0bb7761..0402f11 100644
--- a/include/osmo-bts/gsm_data.h
+++ b/include/osmo-bts/gsm_data.h
@@ -43,7 +43,6 @@
 #define GSM_BTS_AGCH_QUEUE_HIGH_LEVEL_DEFAULT 91
 
 #define LOGPLCHAN(lchan, ss, lvl, fmt, args...) LOGP(ss, lvl, "%s " fmt, gsm_lchan_name(lchan), ## args)
-#define LOGPTRX(trx, ss, lvl, fmt, args...) LOGP(ss, lvl, "%s " fmt, gsm_trx_name(trx), ## args)
 
 struct gsm_network {
 	struct llist_head bts_list;
@@ -339,53 +338,6 @@
 	struct gsm_lchan lchan[TS_MAX_LCHAN];
 };
 
-/* One TRX in a BTS */
-struct gsm_bts_trx {
-	/* list header in bts->trx_list */
-	struct llist_head list;
-
-	struct gsm_bts *bts;
-	/* number of this TRX in the BTS */
-	uint8_t nr;
-	/* human readable name / description */
-	char *description;
-	/* how do we talk RSL with this TRX? */
-	uint8_t rsl_tei;
-	struct e1inp_sign_link *rsl_link;
-
-	/* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
-	struct e1inp_sign_link *oml_link;
-
-	struct gsm_abis_mo mo;
-	struct tlv_parsed nm_attr;
-	struct {
-		struct gsm_abis_mo mo;
-	} bb_transc;
-
-	uint16_t arfcn;
-	int nominal_power;		/* in dBm */
-	unsigned int max_power_red;	/* in actual dB */
-        uint8_t max_power_backoff_8psk; /* in actual dB OC-2G only */
-        uint8_t c0_idle_power_red;      /* in actual dB OC-2G only */
-
-
-	struct trx_power_params power_params;
-	bool ms_pwr_ctl_soft; /* is power control loop done by osmocom software? */
-
-	struct {
-		void *l1h;
-	} role_bts;
-
-	union {
-		struct {
-			unsigned int test_state;
-			uint8_t test_nr;
-			struct rxlev_stats rxlev_stat;
-		} ipaccess;
-	};
-	struct gsm_bts_trx_ts ts[TRX_NR_TS];
-};
-
 #define GSM_LCHAN_SI(lchan, i) (void *)((lchan)->si.buf[i][0])
 
 enum gprs_rlc_par {
@@ -424,16 +376,12 @@
  * OML connection will cause a special warning to be logged. */
 #define OSMO_BTS_OML_CONN_EARLY_DISCONNECT 10	 /* in seconds */
 
-struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
-struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
-
 
 extern const struct value_string gsm_pchant_names[13];
 extern const struct value_string gsm_pchant_descs[13];
 const char *gsm_pchan_name(enum gsm_phys_chan_config c);
 enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
 const char *gsm_lchant_name(enum gsm_chan_t c);
-char *gsm_trx_name(const struct gsm_bts_trx *trx);
 char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
 char *gsm_ts_and_pchan_name(const struct gsm_bts_trx_ts *ts);
 char *gsm_lchan_name_compute(const struct gsm_lchan *lchan);
@@ -458,7 +406,6 @@
 enum gsm_phys_chan_config ts_pchan(struct gsm_bts_trx_ts *ts);
 uint8_t ts_subslots(struct gsm_bts_trx_ts *ts);
 bool ts_is_tch(struct gsm_bts_trx_ts *ts);
-const char *gsm_trx_unit_id(struct gsm_bts_trx *trx);
 
 int lchan2ecu_codec(const struct gsm_lchan *lchan);
 
diff --git a/include/osmo-bts/phy_link.h b/include/osmo-bts/phy_link.h
index 2a53d91..8e75342 100644
--- a/include/osmo-bts/phy_link.h
+++ b/include/osmo-bts/phy_link.h
@@ -5,11 +5,12 @@
 #include <osmocom/core/linuxlist.h>
 
 #include <osmo-bts/scheduler.h>
+#include <osmo-bts/trx.h>
 
 #include <linux/if_packet.h>
 #include "btsconfig.h"
 
-struct gsm_bts_trx;
+
 struct virt_um_inst;
 
 enum phy_link_type {
diff --git a/include/osmo-bts/trx.h b/include/osmo-bts/trx.h
new file mode 100644
index 0000000..ae87528
--- /dev/null
+++ b/include/osmo-bts/trx.h
@@ -0,0 +1,65 @@
+#pragma once
+
+#include <osmo-bts/gsm_data.h>
+
+/* One TRX in a BTS */
+struct gsm_bts_trx {
+	/* list header in bts->trx_list */
+	struct llist_head list;
+
+	struct gsm_bts *bts;
+	/* number of this TRX in the BTS */
+	uint8_t nr;
+	/* human readable name / description */
+	char *description;
+	/* how do we talk RSL with this TRX? */
+	uint8_t rsl_tei;
+	struct e1inp_sign_link *rsl_link;
+
+	/* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
+	struct e1inp_sign_link *oml_link;
+
+	struct gsm_abis_mo mo;
+	struct tlv_parsed nm_attr;
+	struct {
+		struct gsm_abis_mo mo;
+	} bb_transc;
+
+	uint16_t arfcn;
+	int nominal_power;		/* in dBm */
+	unsigned int max_power_red;	/* in actual dB */
+        uint8_t max_power_backoff_8psk; /* in actual dB OC-2G only */
+        uint8_t c0_idle_power_red;      /* in actual dB OC-2G only */
+
+
+	struct trx_power_params power_params;
+	bool ms_pwr_ctl_soft; /* is power control loop done by osmocom software? */
+
+	struct {
+		void *l1h;
+	} role_bts;
+
+	union {
+		struct {
+			unsigned int test_state;
+			uint8_t test_nr;
+			struct rxlev_stats rxlev_stat;
+		} ipaccess;
+	};
+	struct gsm_bts_trx_ts ts[TRX_NR_TS];
+};
+
+
+struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
+int bts_trx_init(struct gsm_bts_trx *trx);
+struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
+char *gsm_trx_name(const struct gsm_bts_trx *trx);
+const char *gsm_trx_unit_id(struct gsm_bts_trx *trx);
+
+int trx_link_estab(struct gsm_bts_trx *trx);
+int trx_set_available(struct gsm_bts_trx *trx, int avail);
+
+uint8_t num_agch(struct gsm_bts_trx *trx, const char * arg);
+bool trx_ms_pwr_ctrl_is_osmo(struct gsm_bts_trx *trx);
+
+#define LOGPTRX(trx, ss, lvl, fmt, args...) LOGP(ss, lvl, "%s " fmt, gsm_trx_name(trx), ## args)
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 2fa5514..348dd97 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -36,6 +36,7 @@
 	dtx_dl_amr_fsm.c \
 	scheduler_mframe.c \
 	ta_control.c \
+	trx.c \
 	$(NULL)
 
 libl1sched_a_SOURCES = scheduler.c
diff --git a/src/common/abis.c b/src/common/abis.c
index ad6fddc..bac1179 100644
--- a/src/common/abis.c
+++ b/src/common/abis.c
@@ -49,6 +49,7 @@
 #include <osmo-bts/rsl.h>
 #include <osmo-bts/oml.h>
 #include <osmo-bts/bts_model.h>
+#include <osmo-bts/trx.h>
 
 static struct gsm_bts *g_bts;
 
diff --git a/src/common/bts.c b/src/common/bts.c
index 2f6a700..983f61d 100644
--- a/src/common/bts.c
+++ b/src/common/bts.c
@@ -383,40 +383,6 @@
 	return rc;
 }
 
-/* Initialize the TRX data structures, called before config
- * file reading */
-int bts_trx_init(struct gsm_bts_trx *trx)
-{
-	/* initialize bts data structure */
-	struct trx_power_params *tpp = &trx->power_params;
-	int rc, i;
-
-	for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
-		struct gsm_bts_trx_ts *ts = &trx->ts[i];
-		int k;
-
-		for (k = 0; k < ARRAY_SIZE(ts->lchan); k++) {
-			struct gsm_lchan *lchan = &ts->lchan[k];
-			INIT_LLIST_HEAD(&lchan->dl_tch_queue);
-		}
-	}
-	/* Default values for the power adjustments */
-	tpp->ramp.max_initial_pout_mdBm = to_mdB(0);
-	tpp->ramp.step_size_mdB = to_mdB(2);
-	tpp->ramp.step_interval_sec = 1;
-
-	/* IF BTS model doesn't DSP/HW support MS Power Control Loop, enable osmo algo by default: */
-	if (!bts_internal_flag_get(trx->bts, BTS_INTERNAL_FLAG_MS_PWR_CTRL_DSP))
-		trx->ms_pwr_ctl_soft = true;
-
-	rc = bts_model_trx_init(trx);
-	if (rc < 0) {
-		llist_del(&trx->list);
-		return rc;
-	}
-	return 0;
-}
-
 /* main link is established, send status report */
 int bts_link_estab(struct gsm_bts *bts)
 {
@@ -451,55 +417,6 @@
 	return bts_model_oml_estab(bts);
 }
 
-/* RSL link is established, send status report */
-int trx_link_estab(struct gsm_bts_trx *trx)
-{
-	struct e1inp_sign_link *link = trx->rsl_link;
-	uint8_t radio_state = link ?  NM_OPSTATE_ENABLED : NM_OPSTATE_DISABLED;
-	int rc;
-
-	LOGP(DSUM, LOGL_INFO, "RSL link (TRX %02x) state changed to %s, sending Status'.\n",
-		trx->nr, link ? "up" : "down");
-
-	oml_mo_state_chg(&trx->mo, radio_state, NM_AVSTATE_OK);
-
-	if (link)
-		rc = rsl_tx_rf_res(trx);
-	else
-		rc = bts_model_trx_deact_rf(trx);
-	if (rc < 0) {
-		oml_tx_failure_event_rep(&trx->bb_transc.mo, NM_SEVER_MAJOR, OSMO_EVT_MAJ_RSL_FAIL,
-					 link ?
-					 "Failed to establish RSL link (%d)" :
-					 "Failed to deactivate RF (%d)", rc);
-	}
-
-	return 0;
-}
-
-/* set the availability of the TRX (used by PHY driver) */
-int trx_set_available(struct gsm_bts_trx *trx, int avail)
-{
-	int tn;
-
-	LOGP(DSUM, LOGL_INFO, "TRX(%d): Setting available = %d\n",
-		trx->nr, avail);
-	if (avail) {
-		int op_state = trx->rsl_link ?  NM_OPSTATE_ENABLED : NM_OPSTATE_DISABLED;
-		oml_mo_state_chg(&trx->mo, op_state, NM_AVSTATE_OK);
-		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
-		for (tn = 0; tn < ARRAY_SIZE(trx->ts); tn++)
-			oml_mo_state_chg(&trx->ts[tn].mo, op_state, NM_AVSTATE_OK);
-	} else {
-		oml_mo_state_chg(&trx->mo,  NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
-		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_NOT_INSTALLED);
-
-		for (tn = 0; tn < ARRAY_SIZE(trx->ts); tn++)
-			oml_mo_state_chg(&trx->ts[tn].mo, NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
-	}
-	return 0;
-}
-
 /* prepare the per-SAPI T200 arrays for a given lchan */
 static int t200_by_lchan(int *t200_ms_dcch, int *t200_ms_acch, struct gsm_lchan *lchan)
 {
@@ -899,11 +816,6 @@
 	return sup > 0;
 }
 
-bool trx_ms_pwr_ctrl_is_osmo(struct gsm_bts_trx *trx)
-{
-	return trx->ms_pwr_ctl_soft;
-}
-
 struct gsm_time *get_time(struct gsm_bts *bts)
 {
 	return &bts->gsm_time;
diff --git a/src/common/bts_ctrl_lookup.c b/src/common/bts_ctrl_lookup.c
index f0157e9..e9b06f4 100644
--- a/src/common/bts_ctrl_lookup.c
+++ b/src/common/bts_ctrl_lookup.c
@@ -28,6 +28,7 @@
 #include <osmo-bts/logging.h>
 #include <osmo-bts/gsm_data.h>
 #include <osmo-bts/control_if.h>
+#include <osmo-bts/trx.h>
 
 extern vector ctrl_node_vec;
 
diff --git a/src/common/gsm_data.c b/src/common/gsm_data.c
index c63793c..d26cb1a 100644
--- a/src/common/gsm_data.c
+++ b/src/common/gsm_data.c
@@ -37,6 +37,7 @@
 
 #include <osmo-bts/gsm_data.h>
 #include <osmo-bts/bts.h>
+#include <osmo-bts/trx.h>
 
 const struct value_string gsm_pchant_names[13] = {
 	{ GSM_PCHAN_NONE,	"NONE" },
@@ -103,88 +104,8 @@
 	return get_value_string(lchan_s_names, s);
 }
 
-struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts)
-{
-	struct gsm_bts_trx *trx = talloc_zero(bts, struct gsm_bts_trx);
-	int k;
-
-	if (!trx)
-		return NULL;
-
-	trx->bts = bts;
-	trx->nr = bts->num_trx++;
-
-	gsm_mo_init(&trx->mo, bts, NM_OC_RADIO_CARRIER,
-		    bts->nr, trx->nr, 0xff);
-
-	gsm_mo_init(&trx->bb_transc.mo, bts, NM_OC_BASEB_TRANSC,
-		    bts->nr, trx->nr, 0xff);
-
-	for (k = 0; k < TRX_NR_TS; k++) {
-		struct gsm_bts_trx_ts *ts = &trx->ts[k];
-		int l;
-
-		ts->trx = trx;
-		ts->nr = k;
-		ts->pchan = GSM_PCHAN_NONE;
-		ts->dyn.pchan_is = GSM_PCHAN_NONE;
-		ts->dyn.pchan_want = GSM_PCHAN_NONE;
-		ts->tsc = -1;
-
-		gsm_mo_init(&ts->mo, bts, NM_OC_CHANNEL,
-			    bts->nr, trx->nr, ts->nr);
-
-		for (l = 0; l < TS_MAX_LCHAN; l++) {
-			struct gsm_lchan *lchan;
-			char *name;
-			lchan = &ts->lchan[l];
-
-			lchan->ts = ts;
-			lchan->nr = l;
-			lchan->type = GSM_LCHAN_NONE;
-
-			name = gsm_lchan_name_compute(lchan);
-			lchan->name = talloc_strdup(trx, name);
-			INIT_LLIST_HEAD(&lchan->sapi_cmds);
-		}
-	}
-
-	if (trx->nr != 0)
-		trx->nominal_power = bts->c0->nominal_power;
-
-	llist_add_tail(&trx->list, &bts->trx_list);
-
-	return trx;
-}
-
-struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num)
-{
-	struct gsm_bts_trx *trx;
-
-	if (num >= bts->num_trx)
-		return NULL;
-
-	llist_for_each_entry(trx, &bts->trx_list, list) {
-		if (trx->nr == num)
-			return trx;
-	}
-
-	return NULL;
-}
-
 static char ts2str[255];
 
-char *gsm_trx_name(const struct gsm_bts_trx *trx)
-{
-	if (!trx)
-		snprintf(ts2str, sizeof(ts2str), "(trx=NULL)");
-	else
-		snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d)",
-			 trx->bts->nr, trx->nr);
-
-	return ts2str;
-}
-
 
 char *gsm_ts_name(const struct gsm_bts_trx_ts *ts)
 {
@@ -459,15 +380,6 @@
 	return pchan_is_tch(ts_pchan(ts));
 }
 
-const char *gsm_trx_unit_id(struct gsm_bts_trx *trx)
-{
-	static char buf[23];
-
-	snprintf(buf, sizeof(buf), "%u/%u/%u", trx->bts->ip_access.site_id,
-		trx->bts->ip_access.bts_id, trx->nr);
-	return buf;
-}
-
 const struct value_string lchan_ciph_state_names[] = {
 	{ LCHAN_CIPH_NONE,	"NONE" },
 	{ LCHAN_CIPH_RX_REQ,	"RX_REQ" },
diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c
index 4a86c4e..751fb12 100644
--- a/src/common/sysinfo.c
+++ b/src/common/sysinfo.c
@@ -26,6 +26,7 @@
 #include <osmo-bts/gsm_data.h>
 #include <osmo-bts/pcu_if.h>
 #include <osmo-bts/bts.h>
+#include <osmo-bts/trx.h>
 
 /* properly increment SI2q index and return SI2q data for scheduling */
 static inline uint8_t *get_si2q_inc_index(struct gsm_bts *bts)
diff --git a/src/common/trx.c b/src/common/trx.c
new file mode 100644
index 0000000..074cb95
--- /dev/null
+++ b/src/common/trx.c
@@ -0,0 +1,205 @@
+/* (C) 2008-2010 by Harald Welte <laforge at gnumonks.org>
+ * (C) 2020 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <osmo-bts/logging.h>
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/trx.h>
+#include <osmo-bts/bts.h>
+#include <osmo-bts/bts_model.h>
+#include <osmo-bts/rsl.h>
+
+struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts)
+{
+	struct gsm_bts_trx *trx = talloc_zero(bts, struct gsm_bts_trx);
+	int k;
+
+	if (!trx)
+		return NULL;
+
+	trx->bts = bts;
+	trx->nr = bts->num_trx++;
+
+	gsm_mo_init(&trx->mo, bts, NM_OC_RADIO_CARRIER,
+		    bts->nr, trx->nr, 0xff);
+
+	gsm_mo_init(&trx->bb_transc.mo, bts, NM_OC_BASEB_TRANSC,
+		    bts->nr, trx->nr, 0xff);
+
+	for (k = 0; k < TRX_NR_TS; k++) {
+		struct gsm_bts_trx_ts *ts = &trx->ts[k];
+		int l;
+
+		ts->trx = trx;
+		ts->nr = k;
+		ts->pchan = GSM_PCHAN_NONE;
+		ts->dyn.pchan_is = GSM_PCHAN_NONE;
+		ts->dyn.pchan_want = GSM_PCHAN_NONE;
+		ts->tsc = -1;
+
+		gsm_mo_init(&ts->mo, bts, NM_OC_CHANNEL,
+			    bts->nr, trx->nr, ts->nr);
+
+		for (l = 0; l < TS_MAX_LCHAN; l++) {
+			struct gsm_lchan *lchan;
+			char *name;
+			lchan = &ts->lchan[l];
+
+			lchan->ts = ts;
+			lchan->nr = l;
+			lchan->type = GSM_LCHAN_NONE;
+
+			name = gsm_lchan_name_compute(lchan);
+			lchan->name = talloc_strdup(trx, name);
+			INIT_LLIST_HEAD(&lchan->sapi_cmds);
+		}
+	}
+
+	if (trx->nr != 0)
+		trx->nominal_power = bts->c0->nominal_power;
+
+	llist_add_tail(&trx->list, &bts->trx_list);
+
+	return trx;
+}
+
+/* Initialize the TRX data structures, called before config
+ * file reading */
+int bts_trx_init(struct gsm_bts_trx *trx)
+{
+	/* initialize bts data structure */
+	struct trx_power_params *tpp = &trx->power_params;
+	int rc, i;
+
+	for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
+		struct gsm_bts_trx_ts *ts = &trx->ts[i];
+		int k;
+
+		for (k = 0; k < ARRAY_SIZE(ts->lchan); k++) {
+			struct gsm_lchan *lchan = &ts->lchan[k];
+			INIT_LLIST_HEAD(&lchan->dl_tch_queue);
+		}
+	}
+	/* Default values for the power adjustments */
+	tpp->ramp.max_initial_pout_mdBm = to_mdB(0);
+	tpp->ramp.step_size_mdB = to_mdB(2);
+	tpp->ramp.step_interval_sec = 1;
+
+	/* IF BTS model doesn't DSP/HW support MS Power Control Loop, enable osmo algo by default: */
+	if (!bts_internal_flag_get(trx->bts, BTS_INTERNAL_FLAG_MS_PWR_CTRL_DSP))
+		trx->ms_pwr_ctl_soft = true;
+
+	rc = bts_model_trx_init(trx);
+	if (rc < 0) {
+		llist_del(&trx->list);
+		return rc;
+	}
+	return 0;
+}
+
+struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num)
+{
+	struct gsm_bts_trx *trx;
+
+	if (num >= bts->num_trx)
+		return NULL;
+
+	llist_for_each_entry(trx, &bts->trx_list, list) {
+		if (trx->nr == num)
+			return trx;
+	}
+
+	return NULL;
+}
+
+static char ts2str[255];
+
+char *gsm_trx_name(const struct gsm_bts_trx *trx)
+{
+	if (!trx)
+		snprintf(ts2str, sizeof(ts2str), "(trx=NULL)");
+	else
+		snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d)",
+			 trx->bts->nr, trx->nr);
+
+	return ts2str;
+}
+
+const char *gsm_trx_unit_id(struct gsm_bts_trx *trx)
+{
+	static char buf[23];
+
+	snprintf(buf, sizeof(buf), "%u/%u/%u", trx->bts->ip_access.site_id,
+		trx->bts->ip_access.bts_id, trx->nr);
+	return buf;
+}
+
+/* RSL link is established, send status report */
+int trx_link_estab(struct gsm_bts_trx *trx)
+{
+	struct e1inp_sign_link *link = trx->rsl_link;
+	uint8_t radio_state = link ?  NM_OPSTATE_ENABLED : NM_OPSTATE_DISABLED;
+	int rc;
+
+	LOGP(DSUM, LOGL_INFO, "RSL link (TRX %02x) state changed to %s, sending Status'.\n",
+		trx->nr, link ? "up" : "down");
+
+	oml_mo_state_chg(&trx->mo, radio_state, NM_AVSTATE_OK);
+
+	if (link)
+		rc = rsl_tx_rf_res(trx);
+	else
+		rc = bts_model_trx_deact_rf(trx);
+	if (rc < 0) {
+		oml_tx_failure_event_rep(&trx->bb_transc.mo, NM_SEVER_MAJOR, OSMO_EVT_MAJ_RSL_FAIL,
+					 link ?
+					 "Failed to establish RSL link (%d)" :
+					 "Failed to deactivate RF (%d)", rc);
+	}
+
+	return 0;
+}
+
+/* set the availability of the TRX (used by PHY driver) */
+int trx_set_available(struct gsm_bts_trx *trx, int avail)
+{
+	int tn;
+
+	LOGP(DSUM, LOGL_INFO, "TRX(%d): Setting available = %d\n",
+		trx->nr, avail);
+	if (avail) {
+		int op_state = trx->rsl_link ?  NM_OPSTATE_ENABLED : NM_OPSTATE_DISABLED;
+		oml_mo_state_chg(&trx->mo, op_state, NM_AVSTATE_OK);
+		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
+		for (tn = 0; tn < ARRAY_SIZE(trx->ts); tn++)
+			oml_mo_state_chg(&trx->ts[tn].mo, op_state, NM_AVSTATE_OK);
+	} else {
+		oml_mo_state_chg(&trx->mo,  NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
+		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_NOT_INSTALLED);
+
+		for (tn = 0; tn < ARRAY_SIZE(trx->ts); tn++)
+			oml_mo_state_chg(&trx->ts[tn].mo, NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
+	}
+	return 0;
+}
+
+
+bool trx_ms_pwr_ctrl_is_osmo(struct gsm_bts_trx *trx)
+{
+	return trx->ms_pwr_ctl_soft;
+}
diff --git a/src/common/tx_power.c b/src/common/tx_power.c
index 8292d9f..3714c99 100644
--- a/src/common/tx_power.c
+++ b/src/common/tx_power.c
@@ -29,6 +29,7 @@
 #include <osmo-bts/gsm_data.h>
 #include <osmo-bts/bts_model.h>
 #include <osmo-bts/tx_power.h>
+#include <osmo-bts/trx.h>
 
 static int get_pa_drive_level_mdBm(const struct power_amp *pa,
 		       int desired_p_out_mdBm, unsigned int arfcn)

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/19124
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: Iebaf5b221c48b571f45408af867ce6f9c0cd9f4a
Gerrit-Change-Number: 19124
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200703/6a16b04d/attachment.htm>


More information about the gerrit-log mailing list