9972ea16f14d6c0366270e4510caf89e8b1ab7a0
[o-du/phy.git] / fhi_lib / lib / api / xran_cp_api.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 This file provides the definitions for Control Plane Messages APIs.
21  *
22  * @file xran_cp_api.h
23  * @ingroup group_lte_source_xran
24  * @author Intel Corporation
25  *
26  **/
27
28 #ifndef _XRAN_CP_API_H_
29 #define _XRAN_CP_API_H_
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35
36 #include "xran_fh_o_du.h"
37 #include "xran_pkt_cp.h"
38 #include "xran_transport.h"
39
40 #define XRAN_MAX_SECTIONDB_CTX              2
41
42 #define XRAN_MAX_NUM_EXTENSIONS     4       /* Maximum number of extensions in a section */
43 #define XRAN_MAX_NUM_UE             16      /* Maximum number of UE */
44 #define XRAN_MAX_NUM_ANT_BF         64      /* Maximum number of beamforming antenna,
45                                              * could be defined as XRAN_MAX_ANTENNA_NR */
46 /* Maximum total number of beamforming weights (5.4.7.1.2) */
47 #define XRAN_MAX_BFW_N              (XRAN_MAX_NUM_ANT_BF*XRAN_MAX_NUM_UE)
48 #define XRAN_MAX_MODCOMP_ADDPARMS   2
49
50 #define XRAN_SECTIONEXT_ALIGN       4       /* alignment size in byte for section extension */
51
52
53 /** Control Plane section types, defined in 5.4 Table 5.1 */
54 enum xran_cp_sectiontype {
55     XRAN_CP_SECTIONTYPE_0   = 0,    /**< Unused RB or Symbols in DL or UL, not supported */
56     XRAN_CP_SECTIONTYPE_1   = 1,    /**< Most DL/UL Radio Channels */
57     XRAN_CP_SECTIONTYPE_3   = 3,    /**< PRACH and Mixed-numerology Channels */
58     XRAN_CP_SECTIONTYPE_5   = 5,    /**< UE scheduling information, not supported  */
59     XRAN_CP_SECTIONTYPE_6   = 6,    /**< Channel Information, not supported */
60     XRAN_CP_SECTIONTYPE_7   = 7,    /**< LAA, not supported */
61     XRAN_CP_SECTIONTYPE_MAX
62     };
63
64 /** Filter index, defined in 5.4.4.3 */
65 enum xran_cp_filterindex {
66     XRAN_FILTERINDEX_STANDARD   = 0,    /**< UL filter for standard channel */
67     XRAN_FILTERINDEX_PRACH_012  = 1,    /**< UL filter for PRACH preamble format 0, 1, 2 */
68     XRAN_FILTERINDEX_PRACH_3    = 2,    /**< UL filter for PRACH preamble format 3 */
69     XRAN_FILTERINDEX_PRACH_ABC  = 3,    /**< UL filter for PRACH preamble format A1~3, B1~4, C0, C2 */
70     XRAN_FILTERINDEX_NPRACH     = 4,    /**< UL filter for NPRACH */
71     XRAN_FILTERINDEX_MAX
72     };
73
74 /** Maximum Slot Index, defined in 5.4.4.6 */
75 #define XRAN_SLOTID_MAX                     16
76
77 /** FFT size in frame structure, defined in 5.4.4.13 Table 5.9 */
78 enum xran_cp_fftsize {
79     XRAN_FFTSIZE_128    = 7,       /* 128 */
80     XRAN_FFTSIZE_256    = 8,       /* 256 */
81     XRAN_FFTSIZE_512    = 9,       /* 512 */
82     XRAN_FFTSIZE_1024   = 10,      /* 1024 */
83     XRAN_FFTSIZE_2048   = 11,      /* 2048 */
84     XRAN_FFTSIZE_4096   = 12,      /* 4096 */
85     XRAN_FFTSIZE_1536   = 13,      /* 1536 */
86     XRAN_FFTSIZE_MAX
87     };
88
89 /** Sub-carrier spacing, defined in 5.4.4.13 Table 5.10 */
90 enum xran_cp_subcarrierspacing {   /*3GPP u,  SCS, Nslot, Slot len */
91     XRAN_SCS_15KHZ      = 0,       /*  0,   15kHz,  1, 1ms */
92     XRAN_SCS_30KHZ      = 1,       /*  1,   30kHz,  2, 500us */
93     XRAN_SCS_60KHZ      = 2,       /*  2,   60kHz,  4, 250us */
94     XRAN_SCS_120KHZ     = 3,       /*  3,  120kHz,  8, 125us */
95     XRAN_SCS_240KHZ     = 4,       /*  4,  240kHz, 16, 62.5us */
96     XRAN_SCS_1P25KHZ    = 12,      /* NA, 1.25kHz,  1, 1ms */
97     XRAN_SCS_3P75KHZ    = 13,      /* NA, 3.75kHz,  1, 1ms */
98     XRAN_SCS_5KHZ       = 14,      /* NA,    5kHz,  1, 1ms */
99     XRAN_SCS_7P5KHZ     = 15,      /* NA,  7.5kHz,  1, 1ms */
100     XRAN_SCS_MAX
101     };
102
103 /** Resource block indicator, defined in 5.4.5.2 */
104 enum xran_cp_rbindicator {
105     XRAN_RBIND_EVERY        = 0,    /**< every RB used */
106     XRAN_RBIND_EVERYOTHER   = 1,    /**< every other RB used */
107     XRAN_RBIND_MAX
108     };
109
110 /** Symbol number increment command, defined in 5.4.5.3 */
111 enum xran_cp_symbolnuminc {
112     XRAN_SYMBOLNUMBER_NOTINC    = 0,      /**< do not increment the current symbol number */
113     XRAN_SYMBOLNUMBER_INC       = 1,      /**< increment the current symbol number and use that */
114     XRAN_SYMBOLNUMBER_INC_MAX
115     };
116
117 /** Macro to convert the number of PRBs as defined in 5.4.5.6 */
118 #define XRAN_CONVERT_NUMPRBC(x)             ((x) > 255 ? 0 : (x))
119
120 #define XRAN_CONVERT_IQWIDTH(x)             ((x) > 15 ? 0 : (x))
121
122 /** Minimum number of symbols, defined in 5.4.5.7 */
123 #define XRAN_SYMBOLNUMBER_MIN               1
124 /** Maximum number of symbols, defined in  5.4.5.7 */
125 #define XRAN_SYMBOLNUMBER_MAX               14
126
127 /* LAA message type 5.4.5.14 Table 5.11, not supported */
128 #define XRAN_LAAMSGTYPE_LBT_PDSCH_REQ       0
129 #define XRAN_LAAMSGTYPE_LBT_DRS_REQ         1
130 #define XRAN_LAAMSGTYPE_LBT_PDSCH_RSP       2
131 #define XRAN_LAAMSGTYPE_LBT_DRS_RSP         3
132 #define XRAN_LAAMSGTYPE_LBT_BUFFER_ERROR    4
133 #define XRAN_LAAMSGTYPE_LBT_CWCONFIG_REQ    5
134 #define XRAN_LAAMSGTYPE_LBT_CWCONFIG_RSP    6
135
136 #define XRAN_LBTMODE_FULL                   0
137 #define XRAN_LBTMODE_PARTIAL25              1
138 #define XRAN_LBTMODE_PARTIAL34              2
139 #define XRAN_LBTMODE_FULLSTOP               3
140
141
142 /** Control Plane section extension commands, defined in 5.4.6 Table 5.13 */
143 enum xran_cp_sectionextcmd {
144     XRAN_CP_SECTIONEXTCMD_0 = 0,    /**< Reserved, for future use */
145     XRAN_CP_SECTIONEXTCMD_1 = 1,    /**< Beamforming weights */
146     XRAN_CP_SECTIONEXTCMD_2 = 2,    /**< Beamforming attributes */
147     XRAN_CP_SECTIONEXTCMD_3 = 3,    /**< DL Precoding configuration parameters and indications, not supported */
148     XRAN_CP_SECTIONEXTCMD_4 = 4,    /**< Modulation compression parameter */
149     XRAN_CP_SECTIONEXTCMD_5 = 5,    /**< Modulation compression additional scaling parameters */
150     XRAN_CP_SECTIONEXTCMD_MAX       /* 6~127 reserved for future use */
151     };
152
153 /** Macro to convert bfwIqWidth defined in 5.4.7.1.1, Table 5-15 */
154 #define XRAN_CONVERT_BFWIQWIDTH(x)          ((x) > 15 ? 0 : (x))
155
156 /** Beamforming Weights Compression Method 5.4.7.1.1, Table 5-16 */
157 enum xran_cp_bfw_compression_method {
158     XRAN_BFWCOMPMETHOD_NONE         = 0,    /**< Uncopressed I/Q value */
159     XRAN_BFWCOMPMETHOD_BLKFLOAT     = 1,    /**< I/Q mantissa value */
160     XRAN_BFWCOMPMETHOD_BLKSCALE     = 2,    /**< I/Q scaled value */
161     XRAN_BFWCOMPMETHOD_ULAW         = 3,    /**< compressed I/Q value */
162     XRAN_BFWCOMPMETHOD_BEAMSPACE    = 4,    /**< beamspace I/Q coefficient */
163     XRAN_BFWCOMPMETHOD_MAX                  /* reserved for future methods */
164     };
165
166 /** Beamforming Attributes Bitwidth 5.4.7.2.1 */
167 enum xran_cp_bfa_bitwidth {
168     XRAN_BFABITWIDTH_NO             = 0,    /**< the filed is no applicable or the default value shall be used */
169     XRAN_BFABITWIDTH_2BIT           = 1,    /**< the filed is 2-bit bitwidth */
170     XRAN_BFABITWIDTH_3BIT           = 2,    /**< the filed is 3-bit bitwidth */
171     XRAN_BFABITWIDTH_4BIT           = 3,    /**< the filed is 4-bit bitwidth */
172     XRAN_BFABITWIDTH_5BIT           = 4,    /**< the filed is 5-bit bitwidth */
173     XRAN_BFABITWIDTH_6BIT           = 5,    /**< the filed is 6-bit bitwidth */
174     XRAN_BFABITWIDTH_7BIT           = 6,    /**< the filed is 7-bit bitwidth */
175     XRAN_BFABITWIDTH_8BIT           = 7,    /**< the filed is 8-bit bitwidth */
176     };
177
178 /**
179  * This structure contains the information to generate the section body of C-Plane message */
180 struct xran_section_info {
181     uint8_t     type;       /* type of this section  */
182                             /* section type   bit-    */
183                             /*  0 1 3 5 6 7    length */
184     uint8_t     startSymId; /*  X X X X X X    4bits */
185     uint8_t     numSymbol;  /*  X X X X        4bits */
186     uint8_t     symInc;     /*  X X X X X      1bit  */
187     uint16_t    id;         /*  X X X X X     12bits */
188     uint16_t    reMask;     /*  X X X X       12bits */
189     uint16_t    startPrbc;  /*  X X X X X     10bits */
190     uint16_t    numPrbc;    /*  X X X X X      8bits */ /* will be converted to zero if >255 */
191     uint8_t     rb;         /*  X X X X X      1bit  */
192     uint8_t     iqWidth;    /*    X X X        4bits */
193     uint8_t     compMeth;   /*    X X X        4bits */
194     uint8_t     ef;         /*    X X X X      1bit  */
195     int32_t     freqOffset; /*      X         24bits */
196     uint16_t    beamId;     /*    X X         15bits */
197     uint16_t    ueId;       /*        X X     15bits */
198     uint16_t    regFactor;  /*          X     16bits */
199     uint16_t    pad0;
200     };
201
202
203 struct xran_sectionext1_info {
204     uint16_t    bfwNumber;                  /* number of bf weights in this section */
205     uint8_t     bfwiqWidth;
206     uint8_t     bfwCompMeth;
207     uint16_t    bfwIQ[XRAN_MAX_BFW_N*2];    /* I/Q pair, max 4KB with 16bits, 16UE and 64ANT */
208     union {
209         uint8_t     exponent;
210         uint8_t     blockScaler;
211         uint8_t     compBitWidthShift;
212         uint8_t     activeBeamspaceCoeffMask[XRAN_MAX_BFW_N];   /* ceil(N/8)*8, should be multiple of 8 */
213         } bfwCompParam;
214     };
215
216 struct xran_sectionext2_info {
217     uint8_t     bfAzPtWidth;    /* beamforming zenith beamwidth parameter */
218     uint8_t     bfAzPt;
219     uint8_t     bfZePtWidth;    /* beamforming azimuth beamwidth parameter */
220     uint8_t     bfZePt;
221     uint8_t     bfAz3ddWidth;   /* beamforming zenith pointing parameter */
222     uint8_t     bfAz3dd;
223     uint8_t     bfZe3ddWidth;   /* beamforming azimuth pointing parameter */
224     uint8_t     bfZe3dd;
225
226     uint8_t     bfAzSI;
227     uint8_t     bfZeSI;
228     };
229
230 struct xran_sectionext3_info {  /* NOT SUPPORTED */
231     uint8_t     codebookIdx;
232     uint8_t     layerId;
233     uint8_t     numLayers;
234     uint8_t     txScheme;
235     uint16_t    crsReMask;
236     uint8_t     crsShift;
237     uint8_t     crsSymNum;
238     uint16_t    beamIdAP1;
239     uint16_t    beamIdAP2;
240     uint16_t    beamIdAP3;
241     };
242
243 struct xran_sectionext4_info {
244     uint8_t     csf;
245     uint8_t     pad0;
246     uint16_t    modCompScaler;
247     };
248
249 struct xran_sectionext5_info {
250     uint8_t     num_sets;
251     struct {
252         uint16_t    csf;
253 //        uint16_t    pad0;
254         uint16_t    mcScaleReMask;
255         uint16_t    mcScaleOffset;
256         } mc[XRAN_MAX_MODCOMP_ADDPARMS];
257     };
258
259 struct xran_sectionext_info {
260     uint16_t    type;
261     uint16_t    len;
262     void        *data;
263     };
264
265
266 /**
267  * This structure contains the information to generate the section header of C-Plane message */
268 struct xran_cp_header_params {
269     // common parameters
270     uint8_t     filterIdx;
271     uint8_t     frameId;
272     uint8_t     subframeId;
273     uint8_t     slotId;
274     uint8_t     startSymId;
275                             /* section type   bit-    */
276                             /*  0 1 3 5 6 7    length */
277     uint8_t     fftSize;    /*  X   X          4bits */
278     uint8_t     scs;        /*  X   X          4bits */
279     uint8_t     iqWidth;    /*    X X X        4bits */
280     uint8_t     compMeth;   /*    X X X        4bits */
281     uint8_t     numUEs;     /*          X      8bits */
282     uint16_t    timeOffset; /*  X   X         16bits */
283     uint16_t    cpLength;   /*  X   X         16bits */
284     };
285
286 /**
287  * This structure to hold the information to generate the sections of C-Plane message */
288 struct xran_section_gen_info {
289     struct xran_section_info info;  /**< The information for section */
290
291     uint32_t    exDataSize;         /**< The number of Extensions or type 6/7 data */
292     /** the array to store section extension */
293     struct {
294         uint16_t    type;           /**< the type of section extension */
295         uint16_t    len;            /**< length of extension data */
296         void        *data;          /**< pointer to extension data */
297         } exData[XRAN_MAX_NUM_EXTENSIONS];
298     };
299
300 /**
301  * This structure to hold the information to generate a C-Plane message */
302 struct xran_cp_gen_params {
303     uint8_t     dir;            /**< UL or DL */
304     uint8_t     sectionType;    /**< each section must have same type with this */
305     uint16_t    numSections;    /**< the number of sections to generate */
306
307     struct xran_cp_header_params hdr;
308     /**< The information for C-Plane message header */
309     struct xran_section_gen_info *sections;
310     /**< Array of the section information */
311     };
312
313 /**
314  * This structure to hold the information of RB allocation from PHY
315  * to send data for allocated RBs only. */
316 struct xran_cp_rbmap_list {
317     uint16_t    grp_id;     /**< group id for this entry, reserved for future use */
318
319     uint8_t     sym_start;  /**< Start symbol ID */
320     uint8_t     sym_num;    /**< Number of symbols */
321
322     uint16_t    rb_start;   /**< Start RB position */
323     uint16_t    rb_num;     /**< Number of RBs */
324
325     uint16_t    beam_id;    /**< Bean Index */
326     uint8_t     comp_meth;  /**< Compression method */
327     uint8_t     pad0;
328     };
329
330
331 uint16_t xran_get_cplength(int cpLength);
332 int32_t xran_get_freqoffset(int freqOffset, int scs);
333
334 int xran_prepare_ctrl_pkt(struct rte_mbuf *mbuf,
335                         struct xran_cp_gen_params *params,
336                         uint8_t CC_ID, uint8_t Ant_ID,
337                         uint8_t seq_id);
338
339 int xran_parse_cp_pkt(struct rte_mbuf *mbuf,
340                     struct xran_cp_gen_params *result,
341                     struct xran_recv_packet_info *pkt_info);
342
343 int xran_cp_init_sectiondb(void *pHandle);
344 int xran_cp_free_sectiondb(void *pHandle);
345 int xran_cp_add_section_info(void *pHandle,
346         uint8_t dir, uint8_t cc_id, uint8_t ruport_id,
347         uint8_t ctx_id, struct xran_section_info *info);
348 int xran_cp_add_multisection_info(void *pHandle,
349         uint8_t cc_id, uint8_t ruport_id, uint8_t ctx_id,
350         struct xran_cp_gen_params *gen_info);
351 struct xran_section_info *xran_cp_find_section_info(void *pHandle,
352         uint8_t dir, uint8_t cc_id, uint8_t ruport_id,
353         uint8_t ctx_id, uint16_t section_id);
354 struct xran_section_info *xran_cp_iterate_section_info(void *pHandle,
355         uint8_t dir, uint8_t cc_id, uint8_t ruport_id,
356         uint8_t ctx_id, uint32_t *next);
357 int xran_cp_getsize_section_info(void *pHandle, uint8_t dir, uint8_t cc_id, uint8_t ruport_id, uint8_t ctx_id);
358 int xran_cp_reset_section_info(void *pHandle, uint8_t dir, uint8_t cc_id, uint8_t ruport_id, uint8_t ctx_id);
359
360 #ifdef __cplusplus
361 }
362 #endif
363
364 #endif /* _XRAN_CP_API_H_ */