1b67be641f28ca13275774476ba2388803faf0aa
[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                        ( 10 )
47 #define TOTAL_FREE_BLOCKS                   ( 50 * FAPI_MAX_PHY_INSTANCES)  /* To hold both send and recv blocks on PHY side wls */
48 #define ALLOC_TRACK_SIZE                    ( 16384 )
49 #define MSG_MAXSIZE                         (16*16384 )
50
51 #define MEMORY_CORRUPTION_DETECT
52 #define MEMORY_CORRUPTION_DETECT_FLAG       (0xAB)
53
54 typedef enum wls_fapi_free_list_e {
55     WLS_FAPI_FREE_SEND_LIST = 0,
56     WLS_FAPI_FREE_RECV_LIST
57 } wls_fapi_free_list_t;
58
59 typedef struct wls_fapi_mem_array {
60     void **ppFreeBlock;
61     void *pStorage;
62     void *pEndOfStorage;
63     uint32_t nBlockSize;
64     uint32_t nBlockCount;
65 } WLS_FAPI_MEM_STRUCT, *PWLS_FAPI_MEM_STRUCT;
66
67 // WLS context structure
68 typedef struct _nr5g_fapi_wls_context {
69     void *shmem;                // shared  memory region.
70     uint64_t shmem_size;        // shared  memory region size.
71     WLS_FAPI_MEM_STRUCT sWlsStruct;
72     WLS_HANDLE h_wls[NUM_WLS_INSTANCES];    // WLS context handle
73     void *pWlsMemBase;
74     uint32_t nTotalMemorySize;
75     uint32_t nTotalBlocks;
76     uint32_t nAllocBlocks;
77     uint32_t nTotalAllocCnt;
78     uint32_t nTotalFreeCnt;
79     uint32_t nTotalUlBufAllocCnt;
80     uint32_t nTotalUlBufFreeCnt;
81     uint32_t nTotalDlBufAllocCnt[MAX_DL_BUF_LOCATIONS];
82     uint32_t nTotalDlBufFreeCnt[MAX_DL_BUF_LOCATIONS];
83     uint32_t nPartitionMemSize;
84     void *pPartitionMemBase;
85     volatile pthread_mutex_t fapi2phy_lock_send;
86     volatile pthread_mutex_t fapi2phy_lock_alloc;
87     volatile pthread_mutex_t fapi2mac_lock_send;
88     volatile pthread_mutex_t fapi2mac_lock_alloc;
89 } nr5g_fapi_wls_context_t, *p_nr5g_fapi_wls_context_t;
90
91 extern nr5g_fapi_wls_context_t g_wls_ctx;
92
93 inline p_nr5g_fapi_wls_context_t nr5g_fapi_wls_context(
94     );
95 uint8_t nr5g_fapi_wls_init(
96     );
97 uint8_t nr5g_fapi2Phy_wls_init(
98     p_nr5g_fapi_wls_context_t p_wls);
99
100 uint8_t nr5g_fapi_wls_destroy(
101     WLS_HANDLE h_wls);
102 void *wls_fapi_alloc_buffer(
103     uint32_t size,
104     uint32_t loc);
105 void wls_fapi_free_buffer(
106     void *pMsg,
107     uint32_t loc);
108 uint32_t wls_fapi_create_mem_array(
109     PWLS_FAPI_MEM_STRUCT pMemArray,
110     void *pMemArrayMemory,
111     uint32_t totalSize,
112     uint32_t nBlockSize);
113 uint32_t wls_fapi_alloc_mem_array(
114     PWLS_FAPI_MEM_STRUCT pMemArray,
115     void **ppBlock);
116 uint32_t wls_fapi_free_mem_array(
117     PWLS_FAPI_MEM_STRUCT pMemArray,
118     void *pBlock);
119 uint64_t nr5g_fapi_wls_va_to_pa(
120     WLS_HANDLE h_wls,
121     void *ptr);
122 void *nr5g_fapi_wls_pa_to_va(
123     WLS_HANDLE h_wls,
124     uint64_t ptr);
125 uint8_t wls_fapi_add_blocks_to_ul(
126     void);
127 void nr5g_fapi_wls_show_data(
128     void *ptr,
129     uint32_t size);
130 int32_t wls_fapi_sdu_zbc_block_add_to_free(
131     void *pMsgHeaderHead,
132     int count,
133     uint64_t * pToFreeList);
134 void wls_fapi_free_list_all(
135     void);
136 void nr5g_fapi_wls_print_stats(
137     void);
138
139 void wls_fapi_add_send_apis_to_free(
140     PMAC2PHY_QUEUE_EL pListElem,
141     uint32_t idx);
142 void wls_fapi_free_send_free_list(
143     uint32_t idx);
144 void wls_fapi_add_recv_apis_to_free(
145     PMAC2PHY_QUEUE_EL pListElem,
146     uint32_t idx);
147 void wls_fapi_free_recv_free_list(
148     uint32_t idx);
149 #endif /*_NR5G_FAPI_WLS_H_*/