fixeria has uploaded this change for review.

View Change

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, 24 insertions(+), 47 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/51/28551/1
diff --git a/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h b/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h
index 56cd378..10b3b6f 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 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 39eb923..3a06bf2 100644
--- a/src/host/trxcon/src/sched_prim.c
+++ b/src/host/trxcon/src/sched_prim.c
@@ -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 = l1sched_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;
}

/**

To view, visit change 28551. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Ia9c0170fb06efcef569e987b57ab9ab7f7c7e847
Gerrit-Change-Number: 28551
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de>
Gerrit-MessageType: newchange