Front Haul Interface Library first seed code contribution
[o-du/phy.git] / fhi_lib / lib / src / xran_transport.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 Intel.
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 *
17 *******************************************************************************/
18
19
20 /**
21  * @brief This file provides the implementation for Transport lyaer (eCPRI) API.
22  *
23  * @file xran_transport.c
24  * @ingroup group_lte_source_xran
25  * @author Intel Corporation
26  *
27  **/
28
29 #include <stdint.h>
30 #include <endian.h>
31 #include <rte_common.h>
32 #include <rte_config.h>
33
34 #include "xran_fh_lls_cu.h"
35 #include "xran_common.h"
36 #include "xran_transport.h"
37 #include "xran_up_api.h"
38
39
40 /**
41  * @brief Compose ecpriRtcid/ecpriPcid
42  *
43  * @param CU_Port_ID CU Port ID
44  * @param BanbSector_ID Band Sector ID
45  * @param CC_ID Component Carrier ID
46  * @param Ant_ID RU Port ID (antenna ID)
47  * @return uint16_t composed ecpriRtcid/ecpriPcid (network byte order)
48  */
49 inline uint16_t xran_compose_cid(uint8_t CU_Port_ID, uint8_t BandSector_ID, uint8_t CC_ID, uint8_t Ant_ID)
50 {
51   uint16_t cid;
52   XRANEAXCIDCONFIG *conf;
53
54     conf = xran_get_conf_eAxC(NULL);
55
56     cid = ((CU_Port_ID      << conf->bit_cuPortId)      & conf->mask_cuPortId)
57         | ((BandSector_ID   << conf->bit_bandSectorId)  & conf->mask_bandSectorId)
58         | ((CC_ID           << conf->bit_ccId)          & conf->mask_ccId)
59         | ((Ant_ID          << conf->bit_ruPortId)      & conf->mask_ruPortId);
60
61     return (rte_cpu_to_be_16(cid));
62 }
63
64 /**
65  * @brief Decompose ecpriRtcid/ecpriPcid
66  *
67  * @param cid composed ecpriRtcid/ecpriPcid (network byte order)
68  * @param result the pointer of the structure to store decomposed values
69  * @return none
70  */
71 inline void xran_decompose_cid(uint16_t cid, struct xran_eaxc_info *result)
72 {
73   XRANEAXCIDCONFIG *conf;
74
75     conf = xran_get_conf_eAxC(NULL);
76     cid = rte_be_to_cpu_16(cid);
77
78     result->cuPortId        = (cid&conf->mask_cuPortId)     >> conf->bit_cuPortId;
79     result->bandSectorId    = (cid&conf->mask_bandSectorId) >> conf->bit_bandSectorId;
80     result->ccId            = (cid&conf->mask_ccId)         >> conf->bit_ccId;
81     result->ruPortId        = (cid&conf->mask_ruPortId)     >> conf->bit_ruPortId;
82
83     return;
84 }
85
86 /**
87  * @brief modify the payload size of eCPRI header in xRAN packet
88  *
89  * @param mbuf Initialized rte_mbuf packet which has eCPRI header already
90  * @param size payload size to be updated
91  * @return none
92  */
93 inline void xran_update_ecpri_payload_size(struct rte_mbuf *mbuf, int size)
94 {
95   struct xran_ecpri_hdr *ecpri_hdr;
96
97     ecpri_hdr = rte_pktmbuf_mtod(mbuf, struct xran_ecpri_hdr *);
98
99     ecpri_hdr->ecpri_payl_size = rte_cpu_to_be_16(size);
100 }
101