69a17f2e2d05d4c53467299e9582aa37666b387f
[o-du/phy.git] / fhi_lib / lib / api / xran_pkt.h
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  * @brief Definitions and support functions to process XRAN packet
21  * @file xran_pkt.h
22  * @ingroup group_source_xran
23  * @author Intel Corporation
24  **/
25
26 /* ORAN-WG4.CUS.0-v01.00 O-RAN Fronthaul Working Group
27                          Control, User and Synchronization Plane Specification
28 */
29
30 /*
31  * Layer common to data and control packets
32  */
33
34 #ifndef _XRAN_PKT_H_
35 #define _XRAN_PKT_H_
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #include <rte_common.h>
42 #include <rte_ether.h>
43 #include <rte_byteorder.h>
44
45 /**
46  *****************************************************************************
47  * @file xran_pkt.h
48  *
49  * @defgroup xran_common_pkt XRAN Packet definitions and functions
50  * @ingroup xran
51  *
52  * @description
53  *      Definitions and support functions to process XRAN packet
54  *****************************************************************************/
55
56 #define ECPRI_MAX_PAYLOAD_SIZE 65535 /**< Max packet size taken in this implementation */
57
58 /* XRAN spec: For this encapsulation, either the eCPRI Ethertype or the IEEE 1914.3 Ethertype shall be use */
59 #define XRAN_ETHER_TYPE 0xAEFE /**< defined by eCPRI Specification V1.1 */
60
61 #define XRAN_ECPRI_VER      0x0001      /**< eCPRI protocol revision 3.1.3.1.1 */
62 #define XRAN_PAYLOAD_VER    0x0001      /**< Payload version 5.4.4.2 */
63
64 #define VLAN_ID  0 /**< Default Tag protocol identifier (TPID)*/
65 #define VLAN_PCP 7 /**< U-Plane and C-Plane only see Table 3 5 : Quality of service classes */
66
67 /**
68  ******************************************************************************
69  * @ingroup xran_common_pkt
70  *
71  * @description
72  *       eCPRI message types
73  *       as per eCPRI spec 3.2.4. Message Types
74  *****************************************************************************/
75 enum ecpri_msg_type
76 {
77      ECPRI_IQ_DATA           = 0x00, /**< U-plane: IQ data */
78      ECPRI_BIT_SEQUENCE      = 0x01, /* msg type is not supported */
79      ECPRI_RT_CONTROL_DATA   = 0x02, /**< C-plane: Control */
80
81      /* Below msg types are not supported */
82      ECPRI_GEN_DATA_TRANSFER = 0x03,
83      ECPRI_REMOTE_MEM_ACCESS = 0x04,
84      ECPRI_DELAY_MEASUREMENT = 0x05,
85      ECPRI_REMOTE_RESET      = 0x06,
86      ECPRI_EVENT_INDICATION  = 0x07,
87      ECPRI_MSG_TYPE_MAX
88 };
89
90 /**
91  ******************************************************************************
92  * @ingroup xran_common_pkt
93  *
94  * @description
95  *       see 3.1.3.1.7 ecpriSeqid (message identifier)
96  *****************************************************************************/
97 struct ecpri_seq_id
98 {
99     uint8_t seq_id:8;       /**< Sequence ID */
100     uint8_t sub_seq_id:7;   /**< Subsequence ID */
101     uint8_t e_bit:1;        /**< E bit */
102 } __rte_packed;
103
104
105 /**
106  ******************************************************************************
107  * @ingroup xran_common_pkt
108  *
109  * @description
110  *       Structure holds common eCPRI header as per
111  *       Table 3 1 : eCPRI Transport Header Field Definitions
112  *****************************************************************************/
113 struct xran_ecpri_cmn_hdr
114 {
115     uint8_t     ecpri_concat:1;     /**< 3.1.3.1.3 eCPRI concatenation indicator */
116     uint8_t     ecpri_resv:3;       /**< 3.1.3.1.2 eCPRI reserved */
117     uint8_t     ecpri_ver:4;        /**< 3.1.3.1.1 eCPRI protocol revision, defined in XRAN_ECPRI_VER */
118     uint8_t     ecpri_mesg_type;    /**< 3.1.3.1.4 eCPRI message type, defined in ecpri_msg_type */
119     uint16_t    ecpri_payl_size;    /**< 3.1.3.1.5 eCPRI payload size, without common header and any padding bytes */
120 } __rte_packed;
121
122 /**
123  ******************************************************************************
124  * @ingroup xran_common_pkt
125  *
126  * @description
127  *       Structure holds eCPRI transport header as per
128  *       Table 3 1 : eCPRI Transport Header Field Definitions
129  *****************************************************************************/
130 struct xran_ecpri_hdr
131 {
132     struct xran_ecpri_cmn_hdr cmnhdr;
133     rte_be16_t ecpri_xtc_id;            /**< 3.1.3.1.6 real time control data / IQ data transfer message series identifier */
134     struct ecpri_seq_id ecpri_seq_id;   /**< 3.1.3.1.7 message identifier */
135 } __rte_packed;
136
137
138 /**
139  ******************************************************************************
140  * @ingroup xran_common_pkt
141  *
142  * @description
143  *      Enum used to set xRAN packet data direction (gNB Tx/Rx 5.4.4.1)
144  *      uplink or downlink
145  *****************************************************************************/
146 enum xran_pkt_dir
147 {
148      XRAN_DIR_UL  = 0, /**< UL direction */
149      XRAN_DIR_DL  = 1, /**< DL direction */
150      XRAN_DIR_MAX
151 };
152
153 /**
154  ******************************************************************************
155  * @ingroup xran_common_pkt
156  *
157  * @description
158  *       Structure holds components of radio application header
159  *       5.4.4 Coding of Information Elements - Application Layer, Common
160  *       for U-plane as per 6.3.2       DL/UL Data
161  *****************************************************************************/
162 struct radio_app_common_hdr
163 {
164    /* Octet 9 */
165    uint8_t filter_id:4; /**< This parameter defines an index to the channel filter to be
166                               used between IQ data and air interface, both in DL and UL.
167                               For most physical channels filterIndex =0000b is used which
168                               indexes the standard channel filter, e.g. 100MHz channel filter
169                               for 100MHz nominal carrier bandwidth. (see 5.4.4.3 for more) */
170    uint8_t payl_ver:3; /**< This parameter defines the payload protocol version valid
171                             for the following IEs in the application layer. In this version of
172                             the specification payloadVersion=001b shall be used. */
173    uint8_t data_direction:1; /**< This parameter indicates the gNB data direction. */
174
175    /* Octet 10 */
176    uint8_t frame_id:8;    /**< This parameter is a counter for 10 ms frames (wrapping period 2.56 seconds) */
177
178    /* Octet 11 */
179    /* Octet 12 */
180    union {
181        uint16_t value;
182        struct {
183            uint16_t symb_id:6; /**< This parameter identifies the first symbol number within slot,
184                                           to which the information of this message is applies. */
185            uint16_t slot_id:6; /**< This parameter is the slot number within a 1ms sub-frame. All slots in
186                                    one sub-frame are counted by this parameter, slotId running from 0 to Nslot-1.
187                                    In this version of the specification the maximum Nslot=16, All
188                                    other values of the 6 bits are reserved for future use. */
189            uint16_t subframe_id:4; /**< This parameter is a counter for 1 ms sub-frames within 10ms frame. */
190        };
191    }sf_slot_sym;
192
193 } __rte_packed;
194
195 /**
196  ******************************************************************************
197  * @ingroup xran_common_pkt
198  *
199  * @description
200  *      This parameter defines the compression method and IQ bit width for the
201  *      user data in the data section.  This field is absent from U-Plane messages
202  *      when the static IQ format and compression method is configured via the M-Plane.
203  *      In this way a single compression method and IQ bit width is provided
204  *     (per UL and DL, per LTE and NR) without adding more overhead to U-Plane messages.
205  *****************************************************************************/
206 struct compression_hdr
207 {
208     uint8_t ud_iq_width:4; /**< Bit width of each I and each Q
209                                 16 for udIqWidth=0, otherwise equals udIqWidth e.g. udIqWidth = 0000b means I and Q are each 16 bits wide;
210                                 e.g. udIQWidth = 0001b means I and Q are each 1 bit wide;
211                                 e.g. udIqWidth = 1111b means I and Q are each 15 bits wide
212                                 */
213     uint8_t ud_comp_meth:4;
214     /**< udCompMeth|  compression method         |udIqWidth meaning
215     ---------------+-----------------------------+--------------------------------------------
216     0000b          | no compression              |bitwidth of each uncompressed I and Q value
217     0001b          | block floating point        |bitwidth of each I and Q mantissa value
218     0010b          | block scaling               |bitwidth of each I and Q scaled value
219     0011b          | mu-law                      |bitwidth of each compressed I and Q value
220     0100b          | modulation compression      |bitwidth of each compressed I and Q value
221     0100b - 1111b  | reserved for future methods |depends on the specific compression method
222     */
223 } __rte_packed;
224
225 /**
226  ******************************************************************************
227  * @ingroup xran_common_pkt
228  *
229  * @description
230  *       Structure holds common xran packet header
231  *       3.1.1  Ethernet Encapsulation
232  *****************************************************************************/
233 struct xran_pkt_comm_hdr
234 {
235     struct ether_hdr eth_hdr; /**< Ethernet Header */
236     struct xran_ecpri_hdr ecpri_hdr; /**< eCPRI Transport Header */
237 } __rte_packed;
238
239 #ifdef __cplusplus
240 }
241 #endif
242
243 #endif