pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-bts/+/18488 )

Change subject: bts-trx: Implement power ramping during BTS bring up
......................................................................

bts-trx: Implement power ramping during BTS bring up

The nominal transmit power is still only configurable manually from
osmo-bts-trx VTY interface. Support to retrieve the nominal power
from osmo-trx will come later.

Change-Id: Ia7c353e4c199e0fc3bcab55c45a4abda2c66d2c1
---
M include/osmo-bts/tx_power.h
M src/osmo-bts-trx/l1_if.c
M src/osmo-bts-trx/l1_if.h
M src/osmo-bts-trx/main.c
M src/osmo-bts-trx/trx_if.c
M src/osmo-bts-trx/trx_if.h
M src/osmo-bts-trx/trx_vty.c
7 files changed, 73 insertions(+), 73 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  daniel: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmo-bts/tx_power.h b/include/osmo-bts/tx_power.h
index 21887c7..10129eb 100644
--- a/include/osmo-bts/tx_power.h
+++ b/include/osmo-bts/tx_power.h
@@ -65,6 +65,8 @@
 int get_p_target_mdBm(struct gsm_bts_trx *trx, uint8_t bs_power_ie);
 int get_p_target_mdBm_lchan(struct gsm_lchan *lchan);

+int get_p_actual_mdBm(struct gsm_bts_trx *trx, int p_target_mdBm);
+
 int get_p_trxout_target_mdBm(struct gsm_bts_trx *trx, uint8_t bs_power_ie);
 int get_p_trxout_target_mdBm_lchan(struct gsm_lchan *lchan);

diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c
index b67d8fa..ff8e293 100644
--- a/src/osmo-bts-trx/l1_if.c
+++ b/src/osmo-bts-trx/l1_if.c
@@ -177,6 +177,15 @@
                if (rc == 0 && pinst->phy_link->state != PHY_LINK_CONNECTED) {
                        trx_sched_clock_started(pinst->trx->bts);
                        phy_link_state_set(pinst->phy_link, PHY_LINK_CONNECTED);
+
+                       /* Begin to ramp up the power on all TRX associated 
with this phy */
+                       llist_for_each_entry(pinst, &plink->instances, list) {
+                               struct gsm_bts_trx *trx = pinst->trx;
+                               if (l1h->config.forced_max_power_red == -1)
+                                       power_ramp_start(trx, 
get_p_nominal_mdBm(trx), 0);
+                               else
+                                       power_ramp_start(trx, 
get_p_max_out_mdBm(trx) - to_mdB(l1h->config.forced_max_power_red), 1);
+                       }
                } else if (rc != 0 && pinst->phy_link->state != 
PHY_LINK_SHUTDOWN) {
                        trx_sched_clock_stopped(pinst->trx->bts);
                        phy_link_state_set(pinst->phy_link, PHY_LINK_SHUTDOWN);
@@ -184,6 +193,16 @@
        }
 }

+static void l1if_setpower_cb(struct trx_l1h *l1h, int power_att_db, int rc)
+{
+       struct phy_instance *pinst = l1h->phy_inst;
+       struct gsm_bts_trx *trx = pinst->trx;
+
+       LOGPPHI(pinst, DL1C, LOGL_DEBUG, "l1if_setpower_cb(power_att_db=%d, 
rc=%d)\n", power_att_db, rc);
+
+       power_trx_change_compl(trx, get_p_max_out_mdBm(trx) - 
to_mdB(power_att_db));
+}
+
 /*
  * transceiver provisioning
  */
@@ -249,10 +268,6 @@
                        trx_if_cmd_setrxgain(l1h, l1h->config.rxgain);
                        l1h->config.rxgain_sent = 1;
                }
-               if (l1h->config.power_valid && !l1h->config.power_sent) {
-                       trx_if_cmd_setpower(l1h, l1h->config.power);
-                       l1h->config.power_sent = 1;
-               }
                if (l1h->config.maxdly_valid && !l1h->config.maxdly_sent) {
                        trx_if_cmd_setmaxdly(l1h, l1h->config.maxdly);
                        l1h->config.maxdly_sent = 1;
@@ -279,7 +294,6 @@
                        plink->u.osmotrx.poweronoff_sent = true;
                }
                l1h->config.rxgain_sent = 0;
-               l1h->config.power_sent = 0;
                l1h->config.maxdly_sent = 0;
                l1h->config.maxdlynb_sent = 0;
                for (tn = 0; tn < TRX_NR_TS; tn++)
@@ -304,7 +318,6 @@
                l1h->config.tsc_sent = 0;
                l1h->config.bsic_sent = 0;
                l1h->config.rxgain_sent = 0;
-               l1h->config.power_sent = 0;
                l1h->config.maxdly_sent = 0;
                l1h->config.maxdlynb_sent = 0;
                for (tn = 0; tn < TRX_NR_TS; tn++)
@@ -408,6 +421,7 @@
 {
        struct phy_instance *pinst = trx_phy_instance(trx);
        struct trx_l1h *l1h = pinst->u.osmotrx.hdl;
+       struct phy_link *plink = pinst->phy_link;
        uint16_t arfcn = trx->arfcn;

        if (l1h->config.arfcn != arfcn || !l1h->config.arfcn_valid) {
@@ -417,12 +431,11 @@
                l1if_provision_transceiver_trx(l1h);
        }

-       if (l1h->config.power_oml) {
-               l1h->config.power = trx->max_power_red;
-               l1h->config.power_valid = 1;
-               l1h->config.power_sent = 0;
-               l1if_provision_transceiver_trx(l1h);
-       }
+       /* Begin to ramp up the power if power reduction is set by OML and TRX
+          is already running. Otherwise skip, power ramping will be started
+          after TRX is running */
+       if (plink->u.osmotrx.powered && l1h->config.forced_max_power_red == -1)
+               power_ramp_start(pinst->trx, get_p_nominal_mdBm(pinst->trx), 0);

        return 0;
 }
@@ -802,9 +815,10 @@

 int bts_model_change_power(struct gsm_bts_trx *trx, int p_trxout_mdBm)
 {
-#warning "implement bts_model_change_power\n"
-       LOGP(DL1C, LOGL_NOTICE, "Setting TRX output power not supported!\n");
-       return 0;
+       struct phy_instance *pinst = trx_phy_instance(trx);
+       struct trx_l1h *l1h = pinst->u.osmotrx.hdl;
+       int power_att = (get_p_max_out_mdBm(trx) - p_trxout_mdBm) / 1000;
+       return trx_if_cmd_setpower(l1h, power_att, l1if_setpower_cb);
 }

 int bts_model_ts_disconnect(struct gsm_bts_trx_ts *ts)
diff --git a/src/osmo-bts-trx/l1_if.h b/src/osmo-bts-trx/l1_if.h
index 42452d2..46f2c18 100644
--- a/src/osmo-bts-trx/l1_if.h
+++ b/src/osmo-bts-trx/l1_if.h
@@ -73,10 +73,7 @@
        uint8_t                 rxgain;
        int                     rxgain_sent;

-       int                     power_valid;
-       uint8_t                 power;
-       int                     power_oml;
-       int                     power_sent;
+       int                     forced_max_power_red; /* -1 if not forced by 
VTY config (default) */

        bool                    nominal_power_set_by_vty; /* whether nominal 
trx power was enforced/retreived from VTY config "nominal-tx-power" */

diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c
index bd3d0cb..8fb67d2 100644
--- a/src/osmo-bts-trx/main.c
+++ b/src/osmo-bts-trx/main.c
@@ -129,6 +129,7 @@

 int bts_model_trx_init(struct gsm_bts_trx *trx)
 {
+       trx->power_params.trx_p_max_out_mdBm = 
to_mdB(trx->bts->c0->nominal_power);
        return 0;
 }

@@ -150,7 +151,7 @@
        l1h = trx_l1h_alloc(tall_bts_ctx, pinst);
        pinst->u.osmotrx.hdl = l1h;

-       l1h->config.power_oml = 1;
+       l1h->config.forced_max_power_red = -1;
 }

 int main(int argc, char **argv)
diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
index 24d6b9b..5e3bf91 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -303,9 +303,9 @@
 }

 /*! Send "SETPOWER" command to TRX */
-int trx_if_cmd_setpower(struct trx_l1h *l1h, int db)
+int trx_if_cmd_setpower(struct trx_l1h *l1h, int power_att_db, 
trx_if_cmd_setpower_cb *cb)
 {
-       return trx_ctrl_cmd(l1h, 0, "SETPOWER", "%d", db);
+       return trx_ctrl_cmd_cb(l1h, 0, cb, "SETPOWER", "%d", power_att_db);
 }

 /*! Send "SETMAXDLY" command to TRX, i.e. maximum delay for RACH bursts */
@@ -544,6 +544,22 @@
        return 0;
 }

+static int trx_ctrl_rx_rsp_setpower(struct trx_l1h *l1h, struct trx_ctrl_rsp 
*rsp)
+{
+       trx_if_cmd_setpower_cb *cb = (trx_if_cmd_setpower_cb*) rsp->cb;
+       struct phy_instance *pinst = l1h->phy_inst;
+       int power_att;
+
+       if (rsp->status)
+               LOGPPHI(pinst, DTRX, LOGL_ERROR, "transceiver SETPOWER failed 
with status %d\n",
+                       rsp->status);
+       if (cb) {
+               sscanf(rsp->params, "%d", &power_att);
+               cb(l1h, power_att, rsp->status);
+       }
+       return 0;
+}
+
 /* -EINVAL: unrecoverable error, exit BTS
  * N > 0: try sending originating command again after N seconds
  * 0: Done with response, get originating command out from send queue
@@ -562,6 +578,8 @@
         * so that's why we should use tcm instead of rsp. */
        } else if (strcmp(tcm->cmd, "SETFORMAT") == 0) {
                return trx_ctrl_rx_rsp_setformat(l1h, rsp);
+       } else if (strcmp(tcm->cmd, "SETPOWER") == 0) {
+               return trx_ctrl_rx_rsp_setpower(l1h, rsp);
        }

        if (rsp->status) {
diff --git a/src/osmo-bts-trx/trx_if.h b/src/osmo-bts-trx/trx_if.h
index fd0077d..0630eb6 100644
--- a/src/osmo-bts-trx/trx_if.h
+++ b/src/osmo-bts-trx/trx_if.h
@@ -15,6 +15,7 @@

 typedef void trx_if_cmd_poweronoff_cb(struct trx_l1h *l1h, bool poweronoff, 
int rc);
 typedef void trx_if_cmd_setslot_cb(struct trx_l1h *l1h, uint8_t tn, uint8_t 
type, int rc);
+typedef void trx_if_cmd_setpower_cb(struct trx_l1h *l1h, int power_att_db, int 
rc);

 void trx_if_init(struct trx_l1h *l1h);
 int trx_if_cmd_poweroff(struct trx_l1h *l1h, trx_if_cmd_poweronoff_cb *cb);
@@ -22,7 +23,7 @@
 int trx_if_cmd_settsc(struct trx_l1h *l1h, uint8_t tsc);
 int trx_if_cmd_setbsic(struct trx_l1h *l1h, uint8_t bsic);
 int trx_if_cmd_setrxgain(struct trx_l1h *l1h, int db);
-int trx_if_cmd_setpower(struct trx_l1h *l1h, int db);
+int trx_if_cmd_setpower(struct trx_l1h *l1h, int power_att_db, 
trx_if_cmd_setpower_cb *cb);
 int trx_if_cmd_setmaxdly(struct trx_l1h *l1h, int dly);
 int trx_if_cmd_setmaxdlynb(struct trx_l1h *l1h, int dly);
 int trx_if_cmd_setslot(struct trx_l1h *l1h, uint8_t tn, uint8_t type, 
trx_if_cmd_setslot_cb *cb);
diff --git a/src/osmo-bts-trx/trx_vty.c b/src/osmo-bts-trx/trx_vty.c
index 6dddfe2..b920c57 100644
--- a/src/osmo-bts-trx/trx_vty.c
+++ b/src/osmo-bts-trx/trx_vty.c
@@ -97,6 +97,7 @@
 {
        uint8_t tn;
        struct trx_l1h *l1h = pinst->u.osmotrx.hdl;
+       struct gsm_bts_trx *trx = pinst->trx;

        vty_out(vty, "PHY Instance %s%s",
                phy_instance_name(pinst), VTY_NEWLINE);
@@ -106,11 +107,9 @@
                        l1h->config.rxgain, VTY_NEWLINE);
        else
                vty_out(vty, " rx-gain        : undefined%s", VTY_NEWLINE);
-       if (l1h->config.power_valid)
-               vty_out(vty, " tx-attenuation : %d dB%s",
-                       l1h->config.power, VTY_NEWLINE);
-       else
-               vty_out(vty, " tx-attenuation : undefined%s", VTY_NEWLINE);
+       vty_out(vty, " tx-attenuation : %d dB%s",
+               (get_p_max_out_mdBm(trx) - get_p_actual_mdBm(trx, 
trx->power_params.p_total_tgt_mdBm))/1000,
+               VTY_NEWLINE);
        if (l1h->config.maxdly_valid)
                vty_out(vty, " maxdly : %d%s", l1h->config.maxdly,
                        VTY_NEWLINE);
@@ -171,6 +170,7 @@
        int val = atoi(argv[0]);

        trx->nominal_power = val;
+       trx->power_params.trx_p_max_out_mdBm = to_mdB(trx->nominal_power);
        l1h->config.nominal_power_set_by_vty = true;

        return CMD_SUCCESS;
@@ -361,36 +361,19 @@
 }

 DEFUN(cfg_phyinst_tx_atten, cfg_phyinst_tx_atten_cmd,
-       "osmotrx tx-attenuation <0-50>",
+       "osmotrx tx-attenuation (oml|<0-50>)",
        OSMOTRX_STR
        "Set the transmitter attenuation\n"
-       "Fixed attenuation in dB, overriding OML\n")
+       "Use NM_ATT_RF_MAXPOWR_R (max power reduction) from BSC via OML 
(default)\n"
+       "Fixed attenuation in dB, overriding OML (default)\n")
 {
        struct phy_instance *pinst = vty->index;
        struct trx_l1h *l1h = pinst->u.osmotrx.hdl;

-       l1h->config.power = atoi(argv[0]);
-       l1h->config.power_oml = 0;
-       l1h->config.power_valid = 1;
-       l1h->config.power_sent = 0;
-       l1if_provision_transceiver_trx(l1h);
-
-       return CMD_SUCCESS;
-}
-
-DEFUN(cfg_phyinst_tx_atten_oml, cfg_phyinst_tx_atten_oml_cmd,
-       "osmotrx tx-attenuation oml",
-       OSMOTRX_STR
-       "Set the transmitter attenuation\n"
-       "Use NM_ATT_RF_MAXPOWR_R (max power reduction) from BSC via OML\n")
-{
-       struct phy_instance *pinst = vty->index;
-       struct trx_l1h *l1h = pinst->u.osmotrx.hdl;
-
-       l1h->config.power_oml = 1;
-       l1h->config.power_valid = 1;
-       l1h->config.power_sent = 0;
-       l1if_provision_transceiver_trx(l1h);
+       if (strcmp(argv[0], "oml") == 0)
+               l1h->config.forced_max_power_red = -1;
+       else
+               l1h->config.forced_max_power_red = atoi(argv[0]);

        return CMD_SUCCESS;
 }
@@ -407,18 +390,6 @@
        return CMD_SUCCESS;
 }

-DEFUN(cfg_phyinst_no_tx_atten, cfg_phyinst_no_tx_atten_cmd,
-       "no osmotrx tx-attenuation",
-       NO_STR OSMOTRX_STR "Unset the transmitter attenuation\n")
-{
-       struct phy_instance *pinst = vty->index;
-       struct trx_l1h *l1h = pinst->u.osmotrx.hdl;
-
-       l1h->config.power_valid = 0;
-
-       return CMD_SUCCESS;
-}
-
 DEFUN(cfg_phyinst_no_maxdly, cfg_phyinst_no_maxdly_cmd,
        "no osmotrx maxdly",
        NO_STR OSMOTRX_STR
@@ -574,13 +545,11 @@
        if (l1h->config.rxgain_valid)
                vty_out(vty, "  osmotrx rx-gain %d%s",
                        l1h->config.rxgain, VTY_NEWLINE);
-       if (l1h->config.power_valid) {
-               if (l1h->config.power_oml)
-                       vty_out(vty, "  osmotrx tx-attenuation oml%s", 
VTY_NEWLINE);
-               else
-                       vty_out(vty, "  osmotrx tx-attenuation %d%s",
-                               l1h->config.power, VTY_NEWLINE);
-       }
+       if (l1h->config.forced_max_power_red == -1)
+               vty_out(vty, "  osmotrx tx-attenuation oml%s", VTY_NEWLINE);
+       else
+               vty_out(vty, "  osmotrx tx-attenuation %d%s",
+                       l1h->config.forced_max_power_red, VTY_NEWLINE);
        if (l1h->config.maxdly_valid)
                vty_out(vty, "  osmotrx maxdly %d%s", l1h->config.maxdly, 
VTY_NEWLINE);
        if (l1h->config.maxdlynb_valid)
@@ -637,9 +606,7 @@

        install_element(PHY_INST_NODE, &cfg_phyinst_rxgain_cmd);
        install_element(PHY_INST_NODE, &cfg_phyinst_tx_atten_cmd);
-       install_element(PHY_INST_NODE, &cfg_phyinst_tx_atten_oml_cmd);
        install_element(PHY_INST_NODE, &cfg_phyinst_no_rxgain_cmd);
-       install_element(PHY_INST_NODE, &cfg_phyinst_no_tx_atten_cmd);
        install_element(PHY_INST_NODE, &cfg_phyinst_slotmask_cmd);
        install_element(PHY_INST_NODE, &cfg_phyinst_power_on_cmd);
        install_element(PHY_INST_NODE, &cfg_phyinst_maxdly_cmd);

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

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: Ia7c353e4c199e0fc3bcab55c45a4abda2c66d2c1
Gerrit-Change-Number: 18488
Gerrit-PatchSet: 8
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillm...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-Reviewer: tnt <t...@246tnt.com>
Gerrit-MessageType: merged

Reply via email to