FAPI TM, WLS_LIB and ODULOW documentation
[o-du/phy.git] / wls_lib / test / phy / phy_main.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  * @brief This file is test PHY wls lib main process
21  * @file phy_main.c
22  * @ingroup group_testphywls
23  * @author Intel Corporation
24  **/
25
26
27 #include <stdint.h>
28 #include <stdio.h>
29
30 #include <rte_eal.h>
31 #include <rte_cfgfile.h>
32 #include <rte_string_fns.h>
33 #include <rte_common.h>
34 #include <rte_string_fns.h>
35 #include <rte_lcore.h>
36 #include <rte_debug.h>
37 #include <rte_launch.h>
38
39 #include "wls_lib.h"
40
41 #define SUCCESS 0
42 #define FAILURE 1
43 #define WLS_TEST_DEV_NAME "wls"
44 #define WLS_TEST_MSG_ID   1
45 #define WLS_TEST_MSG_SIZE 100
46 #define WLS_TEST_MEM_SIZE 2126512128
47 #define NUM_PHY_MSGS  16
48
49 typedef void* WLS_HANDLE;
50 void *g_shmem;
51 uint64_t g_shmem_size;
52
53 WLS_HANDLE  g_fapi_wls, g_phy_wls;
54
55 uint8_t    phy_dpdk_init(void);
56 uint8_t    phy_wls_init(const char *dev_name, unsigned long long mem_size);
57 uint64_t   phy_fapi_recv();
58 uint8_t    phy_fapi_send();
59
60 int main()
61 {
62     int64_t ret;
63     uint64_t p_msg;
64
65     // DPDK init
66     ret = phy_dpdk_init();
67     if (ret)
68     {
69         printf("\n[PHY] DPDK Init - Failed\n");
70         return FAILURE;
71     }
72     printf("\n[PHY] DPDK Init - Done\n");
73
74     // WLS init
75     ret = phy_wls_init(WLS_TEST_DEV_NAME, WLS_TEST_MEM_SIZE);
76     if(ret)
77     {
78         printf("\n[PHY] WLS Init - Failed\n");
79         return FAILURE;
80     }
81     printf("\n[PHY] WLS Init - Done\n");
82
83     // Receive from MAC WLS
84     p_msg = phy_fapi_recv();
85     if (!p_msg)
86     {
87         printf("\n[PHY] Receive from FAPI - Failed\n");
88         return FAILURE;
89     }
90     printf("\n[PHY] Receive from FAPI - Done\n");
91
92     // Sent to PHY WLS
93     ret = phy_fapi_send();
94     if (ret)
95     {
96         printf("\n[PHY] Send to FAPI - Failed\n");
97         return FAILURE;
98     }
99     printf("\n[PHY] Send to FAPI - Done\n");
100
101     printf("\n[PHY] Exiting...\n");
102
103     return SUCCESS;
104 }
105
106 uint8_t phy_dpdk_init(void)
107 {
108     char whitelist[32];
109     uint8_t i;
110
111     char *argv[] = {"phy_app", "--proc-type=primary",
112         "--file-prefix", "wls", whitelist};
113     
114     int argc = RTE_DIM(argv);
115
116     /* initialize EAL first */
117     sprintf(whitelist, "-w %s",  "0000:00:06.0");
118     printf("[PHY] Calling rte_eal_init: ");
119
120     for (i = 0; i < RTE_DIM(argv); i++)
121     {
122         printf("%s ", argv[i]);
123     }
124     printf("\n");
125
126     if (rte_eal_init(argc, argv) < 0)
127         rte_panic("Cannot init EAL\n");
128
129     return SUCCESS;
130 }
131
132 uint8_t phy_wls_init(const char *dev_name, unsigned long long mem_size)
133 {
134     g_phy_wls = WLS_Open(dev_name, WLS_SLAVE_CLIENT, mem_size);
135     if(NULL == g_phy_wls)
136     {
137         return FAILURE;
138     }
139     g_shmem_size = mem_size;
140
141     g_shmem = WLS_Alloc(g_phy_wls, g_shmem_size);
142     if (NULL == g_shmem)
143     {
144         printf("Unable to alloc WLS Memory\n");
145         return FAILURE;
146     }
147     return SUCCESS;
148 }
149
150 uint64_t phy_fapi_recv()
151 {
152     uint8_t  num_blks = 0;
153     uint64_t p_msg;
154     uint32_t msg_size;
155     uint16_t msg_id;
156     uint16_t flags;
157         uint32_t i=0;
158
159                 
160         while (1)
161         {
162     num_blks = WLS_Wait(g_phy_wls);
163             printf("WLS_Wait returns %d blocks\n",num_blks);
164     
165     if (num_blks)
166     {
167         p_msg = WLS_Get(g_phy_wls, &msg_size, &msg_id, &flags);
168                         if (p_msg)
169                         {
170                                 printf("\n[PHY] FAPI2PHY WLS Received Block %d\n",i);
171                                 i++;
172     }
173     else
174     {
175                              printf("\n[PHY] FAPI2PHY WLS Get Error for msg %d\n",i);
176                              break;
177                     }
178                 if (flags & WLS_TF_FIN)
179                 {
180                     return p_msg;
181                 }
182                 }
183                 else
184                 {
185                         printf("\n[PHY] FAPI2PHY WLS wait returned 0 blocks exiting \n");
186                         return FAILURE;
187                 }
188         
189     }
190     return p_msg;
191 }
192
193 uint8_t phy_fapi_send()
194 {
195     uint64_t pa_block = 0;
196     uint8_t ret = FAILURE;
197     uint32_t i;
198     
199     for (i=0 ; i < NUM_PHY_MSGS; i++)
200     {
201
202     pa_block = (uint64_t) WLS_DequeueBlock((void*) g_phy_wls);
203     if (!pa_block)
204     {
205                 printf("\n[PHY] FAPI2PHY WLS Dequeue block %d error\n",i);
206         return FAILURE;
207     }
208
209         ret = WLS_Put(g_phy_wls, pa_block, WLS_TEST_MSG_SIZE, WLS_TEST_MSG_ID, (i== (NUM_PHY_MSGS-1))? WLS_TF_FIN:0);
210         printf("\n[PHY] FAPI2PHY WLS Put Msg %d \n",i);
211         if (ret)
212         {
213                 printf("\n[PHY] FAPI2PHY WLS Put Msg Error %d \n",i);
214       }
215     }
216     return ret;
217 }