<p>fixeria has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-bts/+/19030">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">osmo-bts-trx/scheduler: implement baseband frequency hopping<br><br>Change-Id: I68f4ae09fd0789ad0d8f1c1e17e17dfc4de8e462<br>Related: OS#4546<br>---<br>M include/osmo-bts/scheduler.h<br>M src/osmo-bts-trx/scheduler_trx.c<br>M src/osmo-bts-trx/trx_if.c<br>3 files changed, 78 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/30/19030/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmo-bts/scheduler.h b/include/osmo-bts/scheduler.h</span><br><span>index e65665f..6f93812 100644</span><br><span>--- a/include/osmo-bts/scheduler.h</span><br><span>+++ b/include/osmo-bts/scheduler.h</span><br><span>@@ -270,6 +270,7 @@</span><br><span> };</span><br><span> </span><br><span> /*! Handle an UL burst received by PHY */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_sched_route_burst_ind(struct l1sched_trx *l1t, struct trx_ul_burst_ind *bi);</span><br><span> int trx_sched_ul_burst(struct l1sched_trx *l1t, struct trx_ul_burst_ind *bi);</span><br><span> </span><br><span> #endif /* TRX_SCHEDULER_H */</span><br><span>diff --git a/src/osmo-bts-trx/scheduler_trx.c b/src/osmo-bts-trx/scheduler_trx.c</span><br><span>index 8e1ccfa..eecc65e 100644</span><br><span>--- a/src/osmo-bts-trx/scheduler_trx.c</span><br><span>+++ b/src/osmo-bts-trx/scheduler_trx.c</span><br><span>@@ -34,6 +34,7 @@</span><br><span> #include <osmocom/core/timer_compat.h></span><br><span> #include <osmocom/core/bits.h></span><br><span> #include <osmocom/gsm/a5.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/gsm/gsm0502.h></span><br><span> </span><br><span> </span><br><span> #include <osmo-bts/gsm_data.h></span><br><span>@@ -55,6 +56,30 @@</span><br><span>   return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Find a route (PHY instance) for a given Downlink burst request */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct phy_instance *dlfh_route_br(const struct gsm_bts_trx_ts *ts,</span><br><span style="color: hsl(120, 100%, 40%);">+                                    const struct trx_dl_burst_req *br)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       const struct gsm_bts_trx *trx;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct gsm_time time;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint16_t arfcn;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     gsm_fn2gsmtime(&time, br->fn);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       /* TODO: implement a "cache", so we could avoid frequent lookups */</span><br><span style="color: hsl(120, 100%, 40%);">+ arfcn = gsm0502_hop_seq_gen(&time, ts->hopping.hsn, ts->hopping.maio,</span><br><span style="color: hsl(120, 100%, 40%);">+                                   ts->hopping.ma_len, ts->hopping.ma);</span><br><span style="color: hsl(120, 100%, 40%);">+        llist_for_each_entry(trx, &ts->trx->bts->trx_list, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+               if (trx->arfcn == arfcn)</span><br><span style="color: hsl(120, 100%, 40%);">+                   return trx->role_bts.l1h;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   LOGP(DL1C, LOGL_FATAL, "Failed to resolve TDMA fn=%u "</span><br><span style="color: hsl(120, 100%, 40%);">+                             "(hsn=%u, maio=%u, ma_len=%u)\n",</span><br><span style="color: hsl(120, 100%, 40%);">+         br->fn, ts->hopping.hsn, ts->hopping.maio, ts->hopping.ma_len);</span><br><span style="color: hsl(120, 100%, 40%);">+      return ts->trx->role_bts.l1h; /* fall-back to the current trx */</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* schedule all frames of all TRX for given FN */</span><br><span> static void trx_sched_fn(struct gsm_bts *bts, const uint32_t fn)</span><br><span> {</span><br><span>@@ -100,8 +125,14 @@</span><br><span>                             continue;</span><br><span>                    }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+                 /* resolve PHY instance if freq. hopping is enabled */</span><br><span style="color: hsl(120, 100%, 40%);">+                        if (trx->ts[tn].hopping.enabled) {</span><br><span style="color: hsl(120, 100%, 40%);">+                         pinst = dlfh_route_br(&trx->ts[tn], &br);</span><br><span style="color: hsl(120, 100%, 40%);">+                          l1h = pinst->u.osmotrx.hdl;</span><br><span style="color: hsl(120, 100%, 40%);">+                        }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>                  /* update dummy burst mask for C0 */</span><br><span style="color: hsl(0, 100%, 40%);">-                    if (trx == bts->c0)</span><br><span style="color: hsl(120, 100%, 40%);">+                        if (pinst->trx == bts->c0)</span><br><span>                             c0_mask |= (1 << tn);</span><br><span> </span><br><span>                      trx_if_send_burst(l1h, &br);</span><br><span>@@ -127,6 +158,50 @@</span><br><span>      }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Find a route (TRX instance) for a given Uplink burst indication */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct gsm_bts_trx *ulfh_route_bi(const struct gsm_bts_trx *src_trx,</span><br><span style="color: hsl(120, 100%, 40%);">+                                         const struct trx_ul_burst_ind *bi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        struct gsm_bts_trx *trx;</span><br><span style="color: hsl(120, 100%, 40%);">+      struct gsm_time time;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint16_t arfcn;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     gsm_fn2gsmtime(&time, bi->fn);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       /* TODO: implement a "cache", so we could avoid frequent lookups */</span><br><span style="color: hsl(120, 100%, 40%);">+ llist_for_each_entry(trx, &src_trx->bts->trx_list, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+          const struct gsm_bts_trx_ts *ts = &trx->ts[bi->tn];</span><br><span style="color: hsl(120, 100%, 40%);">+         if (!ts->hopping.enabled)</span><br><span style="color: hsl(120, 100%, 40%);">+                  continue;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           arfcn = gsm0502_hop_seq_gen(&time, ts->hopping.hsn, ts->hopping.maio,</span><br><span style="color: hsl(120, 100%, 40%);">+                                           ts->hopping.ma_len, ts->hopping.ma);</span><br><span style="color: hsl(120, 100%, 40%);">+                if (src_trx->arfcn == arfcn)</span><br><span style="color: hsl(120, 100%, 40%);">+                       return trx;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   LOGP(DL1C, LOGL_FATAL, "Failed to find transceiver for an Uplink burst fn=%u\n", bi->fn);</span><br><span style="color: hsl(120, 100%, 40%);">+        return (struct gsm_bts_trx *) src_trx; /* fall-back to the originating trx */</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Route a given Uplink burst indication to the scheduler depending on freq. hopping state */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_sched_route_burst_ind(struct l1sched_trx *l1t, struct trx_ul_burst_ind *bi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     const struct phy_instance *pinst;</span><br><span style="color: hsl(120, 100%, 40%);">+     const struct gsm_bts_trx *trx;</span><br><span style="color: hsl(120, 100%, 40%);">+        struct trx_l1h *l1h;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* no frequency hopping => nothing to do */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (!l1t->trx->ts[bi->tn].hopping.enabled)</span><br><span style="color: hsl(120, 100%, 40%);">+           return trx_sched_ul_burst(l1t, bi);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ trx = ulfh_route_bi(l1t->trx, bi);</span><br><span style="color: hsl(120, 100%, 40%);">+ pinst = trx_phy_instance(trx);</span><br><span style="color: hsl(120, 100%, 40%);">+        l1h = pinst->u.osmotrx.hdl;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      return trx_sched_ul_burst(&l1h->l1s, bi);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! maximum number of 'missed' frame periods we can tolerate of OS doesn't schedule us*/</span><br><span> #define MAX_FN_SKEW            50</span><br><span> /*! maximum number of frame periods we can tolerate without TRX Clock Indication*/</span><br><span>diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c</span><br><span>index 58f7455..2b74cd8 100644</span><br><span>--- a/src/osmo-bts-trx/trx_if.c</span><br><span>+++ b/src/osmo-bts-trx/trx_if.c</span><br><span>@@ -1097,7 +1097,7 @@</span><br><span>            hdr_ver, trx_data_desc_msg(&bi));</span><br><span> </span><br><span>    /* feed received burst into scheduler code */</span><br><span style="color: hsl(0, 100%, 40%);">-   trx_sched_ul_burst(&l1h->l1s, &bi);</span><br><span style="color: hsl(120, 100%, 40%);">+        trx_sched_route_burst_ind(&l1h->l1s, &bi);</span><br><span> </span><br><span>    return 0;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-bts/+/19030">change 19030</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-bts/+/19030"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-bts </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I68f4ae09fd0789ad0d8f1c1e17e17dfc4de8e462 </div>
<div style="display:none"> Gerrit-Change-Number: 19030 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>