fixeria has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/28551 )
Change subject: trxcon: allocate a prim in l1sched_prim_push() ......................................................................
trxcon: allocate a prim in l1sched_prim_push()
Make l1sched_prim_alloc() private and call it from l1sched_prim_push(). This makes the API more convinient, because both functions are always used together.
Change-Id: Ia9c0170fb06efcef569e987b57ab9ab7f7c7e847 Related: OS#5599, OS#3761 --- M src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h M src/host/trxcon/src/l1ctl.c M src/host/trxcon/src/sched_prim.c 3 files changed, 29 insertions(+), 52 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve pespin: Looks good to me, approved
diff --git a/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h b/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h index cb82cfb..fa7296a 100644 --- a/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h +++ b/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h @@ -358,10 +358,9 @@ enum l1sched_lchan_type chan);
/* Primitive management functions */ -struct l1sched_ts_prim *l1sched_prim_alloc(void *ctx, size_t pl_len, - uint8_t chan_nr, uint8_t link_id); -int l1sched_prim_push(struct trx_instance *trx, - struct l1sched_ts_prim *prim, uint8_t chan_nr); +struct l1sched_ts_prim *l1sched_prim_push(struct trx_instance *trx, + uint8_t chan_nr, uint8_t link_id, + const uint8_t *pl, size_t pl_len);
#define L1SCHED_TCH_MODE_IS_SPEECH(mode) \ (mode == GSM48_CMODE_SPEECH_V1 \ diff --git a/src/host/trxcon/src/l1ctl.c b/src/host/trxcon/src/l1ctl.c index 734fa77..a6fae33 100644 --- a/src/host/trxcon/src/l1ctl.c +++ b/src/host/trxcon/src/l1ctl.c @@ -540,27 +540,14 @@ ul->chan_nr = RSL_CHAN_RACH; }
- /* Init a new primitive */ - prim = l1sched_prim_alloc(l1l->trx, len, ul->chan_nr, ul->link_id); - if (prim == NULL) { - rc = -ENOMEM; - goto exit; - } - /** * Push this primitive to the transmit queue. * Indicated timeslot needs to be configured. */ - rc = l1sched_prim_push(l1l->trx, prim, ul->chan_nr); - if (rc) { - talloc_free(prim); - goto exit; - } + prim = l1sched_prim_push(l1l->trx, ul->chan_nr, ul->link_id, ul->payload, len); + if (prim == NULL) + rc = -ENOMEM;
- /* Fill in the payload */ - memcpy(prim->payload, ul->payload, len); - -exit: msgb_free(msg); return rc; } @@ -725,24 +712,11 @@ "link_id=0x%02x, len=%zu)\n", traffic ? "TRAFFIC" : "DATA", chan_nr, link_id, payload_len);
- /* Init a new primitive */ - prim = l1sched_prim_alloc(l1l->trx, payload_len, chan_nr, link_id); - if (prim == NULL) { - rc = -ENOMEM; - goto exit; - } - /* Push this primitive to transmit queue */ - rc = l1sched_prim_push(l1l->trx, prim, chan_nr); - if (rc) { - talloc_free(prim); - goto exit; - } + prim = l1sched_prim_push(l1l->trx, chan_nr, link_id, ul->payload, payload_len); + if (prim == NULL) + rc = -ENOMEM;
- /* Fill in the payload */ - memcpy(prim->payload, ul->payload, payload_len); - -exit: msgb_free(msg); return rc; } diff --git a/src/host/trxcon/src/sched_prim.c b/src/host/trxcon/src/sched_prim.c index 398cb9e..f9b4213 100644 --- a/src/host/trxcon/src/sched_prim.c +++ b/src/host/trxcon/src/sched_prim.c @@ -44,8 +44,8 @@ * @param link_id RSL link description (used to set a proper chan) * @return allocated primitive or NULL */ -struct l1sched_ts_prim *l1sched_prim_alloc(void *ctx, size_t pl_len, - uint8_t chan_nr, uint8_t link_id) +static struct l1sched_ts_prim *prim_alloc(void *ctx, size_t pl_len, + uint8_t chan_nr, uint8_t link_id) { enum l1sched_lchan_type lchan_type; struct l1sched_ts_prim *prim; @@ -77,13 +77,17 @@ * timeslot, whose index is parsed from chan_nr. * * @param trx TRX instance - * @param prim to be enqueued primitive * @param chan_nr RSL channel description - * @return zero in case of success, otherwise a error number + * @param link_id RSL link description + * @param pl Payload data + * @param pl_len Payload length + * @return queued primitive or NULL */ -int l1sched_prim_push(struct trx_instance *trx, - struct l1sched_ts_prim *prim, uint8_t chan_nr) +struct l1sched_ts_prim *l1sched_prim_push(struct trx_instance *trx, + uint8_t chan_nr, uint8_t link_id, + const uint8_t *pl, size_t pl_len) { + struct l1sched_ts_prim *prim; struct l1sched_ts *ts; uint8_t tn;
@@ -94,19 +98,19 @@ ts = trx->ts_list[tn]; if (ts == NULL || ts->mf_layout == NULL) { LOGP(DSCH, LOGL_ERROR, "Timeslot %u isn't configured\n", tn); - return -EINVAL; + return NULL; }
- /** - * Change talloc context of primitive - * from trx to the parent ts - */ - talloc_steal(ts, prim); + prim = prim_alloc(ts, pl_len, chan_nr, link_id); + if (prim == NULL) + return NULL; + + memcpy(&prim->payload[0], pl, pl_len);
/* Add primitive to TS transmit queue */ llist_add_tail(&prim->list, &ts->tx_prims);
- return 0; + return prim; }
/** @@ -152,9 +156,9 @@ };
/* Allocate a new primitive */ - prim = l1sched_prim_alloc(lchan, GSM_MACBLOCK_LEN, - l1sched_lchan_desc[lchan->type].chan_nr, - L1SCHED_CH_LID_SACCH); + prim = prim_alloc(lchan, GSM_MACBLOCK_LEN, + l1sched_lchan_desc[lchan->type].chan_nr, + L1SCHED_CH_LID_SACCH); OSMO_ASSERT(prim != NULL);
/* Check if the MR cache is populated (verify LAPDm header) */