O-RAN E Maintenance Release contribution for ODULOW
[o-du/phy.git] / fapi_5g / source / framework / wls / lib / nr5g_fapi_wls.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  * @file This file has definitions of Shared Memory interface functions between
21  * FAPI and PHY.
22  *
23  **/
24
25 #ifndef _NR5G_FAPI_WLS_H_
26 #define _NR5G_FAPI_WLS_H_
27
28 #include "nr5g_fapi_std.h"
29 #include "nr5g_fapi_common_types.h"
30 #include "wls_lib.h"
31 #include "gnb_l1_l2_api.h"
32
33 typedef void *WLS_HANDLE;
34
35 #define NUM_WLS_INSTANCES 2
36 #define NR5G_FAPI2PHY_WLS_INST  0
37 #define NR5G_FAPI2MAC_WLS_INST  1
38
39 #define MAX_NUM_LOCATIONS          (16)
40
41 #define MIN_DL_BUF_LOCATIONS        (0) /* Used for stats collection 0-10 */
42 #define MAX_DL_BUF_LOCATIONS        (MIN_DL_BUF_LOCATIONS + MAX_NUM_LOCATIONS)  /* Used for stats collection 0-10 */
43 #define MIN_UL_BUF_LOCATIONS        (MAX_DL_BUF_LOCATIONS)  /* Used for stats collection 0-10 */
44 #define MAX_UL_BUF_LOCATIONS        (MIN_UL_BUF_LOCATIONS + MAX_NUM_LOCATIONS)
45
46 #define TO_FREE_SIZE                        ( 5 )
47 #define TO_FREE_SIZE_URLLC                  ( MAX_NUM_OF_SYMBOL_PER_SLOT * TO_FREE_SIZE ) // TR 38.912 8.1 mini-slot may be 1 symbol long
48 #define TOTAL_FREE_BLOCKS                   ( 100 * FAPI_MAX_PHY_INSTANCES)  /* To hold both send and recv blocks on PHY side wls */
49 #define ALLOC_TRACK_SIZE                    ( 16384 )
50 #define MSG_MAXSIZE                         (16*16384 )
51
52 #define MEMORY_CORRUPTION_DETECT
53 #define MEMORY_CORRUPTION_DETECT_FLAG       (0xAB)
54
55 typedef enum wls_fapi_free_list_e {
56     WLS_FAPI_FREE_SEND_LIST = 0,
57     WLS_FAPI_FREE_RECV_LIST
58 } wls_fapi_free_list_t;
59
60 typedef struct wls_fapi_mem_array {
61     void **ppFreeBlock;
62     void *pStorage;
63     void *pEndOfStorage;
64     uint32_t nBlockSize;
65     uint32_t nBlockCount;
66 } WLS_FAPI_MEM_STRUCT,
67 *PWLS_FAPI_MEM_STRUCT;
68
69 // WLS context structure
70 typedef struct _nr5g_fapi_wls_context {
71     void *shmem;                // shared  memory region.
72     uint64_t shmem_size;        // shared  memory region size.
73     WLS_FAPI_MEM_STRUCT sWlsStruct;
74     WLS_HANDLE h_wls[NUM_WLS_INSTANCES];    // WLS context handle
75     void *pWlsMemBase;
76     uint32_t nTotalMemorySize;
77     uint32_t nTotalBlocks;
78     uint32_t nAllocBlocks;
79     uint32_t nTotalAllocCnt;
80     uint32_t nTotalFreeCnt;
81     uint32_t nTotalUlBufAllocCnt;
82     uint32_t nTotalUlBufFreeCnt;
83     uint32_t nTotalDlBufAllocCnt[MAX_DL_BUF_LOCATIONS];
84     uint32_t nTotalDlBufFreeCnt[MAX_DL_BUF_LOCATIONS];
85     uint32_t nPartitionMemSize;
86     void *pPartitionMemBase;
87     volatile pthread_mutex_t fapi2phy_lock_send;
88     volatile pthread_mutex_t fapi2phy_lock_alloc;
89     volatile pthread_mutex_t fapi2mac_lock_send;
90     volatile pthread_mutex_t fapi2mac_lock_alloc;
91 } nr5g_fapi_wls_context_t,
92 *p_nr5g_fapi_wls_context_t;
93
94 extern nr5g_fapi_wls_context_t g_wls_ctx;
95
96 inline p_nr5g_fapi_wls_context_t nr5g_fapi_wls_context(
97     );
98 inline uint8_t nr5g_fapi_fapi2phy_wls_ready(
99     );
100 inline uint8_t nr5g_fapi_fapi2mac_wls_ready(
101     );
102 uint8_t nr5g_fapi_wls_init(
103     );
104 uint8_t nr5g_fapi_wls_memory_init(
105     );
106 uint8_t nr5g_fapi_wls_destroy(
107     WLS_HANDLE h_wls);
108 void *wls_fapi_alloc_buffer(
109     uint32_t size,
110     uint32_t loc);
111 void wls_fapi_free_buffer(
112     void *pMsg,
113     uint32_t loc);
114 uint32_t wls_fapi_create_mem_array(
115     PWLS_FAPI_MEM_STRUCT pMemArray,
116     void *pMemArrayMemory,
117     uint32_t totalSize,
118     uint32_t nBlockSize);
119 uint32_t wls_fapi_alloc_mem_array(
120     PWLS_FAPI_MEM_STRUCT pMemArray,
121     void **ppBlock);
122 uint32_t wls_fapi_free_mem_array(
123     PWLS_FAPI_MEM_STRUCT pMemArray,
124     void *pBlock);
125 uint64_t nr5g_fapi_wls_va_to_pa(
126     WLS_HANDLE h_wls,
127     void *ptr);
128 void *nr5g_fapi_wls_pa_to_va(
129     WLS_HANDLE h_wls,
130     uint64_t ptr);
131 uint32_t wls_fapi_add_blocks_to_ul(
132     void);
133 void nr5g_fapi_wls_show_data(
134     void *ptr,
135     uint32_t size);
136 void wls_fapi_free_list_all(
137     void);
138 void nr5g_fapi_wls_print_stats(
139     void);
140
141 #endif /*_NR5G_FAPI_WLS_H_*/