9ac28927375d6da785e76b4c7adcb8b63a6b8d5d
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / nr5g_fapi_fapi2mac_api.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  * @file This file contains implementation of all the functions used 
21  * to send APIs from FAPI to MAC
22  *
23  **/
24
25 #include <stdio.h>
26 #include "nr5g_fapi_internal.h"
27 #include "gnb_l1_l2_api.h"
28 #include "nr5g_fapi_fapi2mac_api.h"
29 #include "nr5g_fapi_fapi2mac_wls.h"
30
31 static nr5g_fapi_fapi2mac_queue_t fapi2mac_q[FAPI_MAX_PHY_INSTANCES];
32
33 //------------------------------------------------------------------------------
34 /** @ingroup     group_source_api_fapi2phy
35  *
36  *  @param[in]   p_list_elem Pointer to the ListElement
37  *
38  *  @return      void
39  *
40  *  @description This function adds a ListElement API to a Linked list which will
41  *               be sent to L1 once all APIs for a TTI are added
42  *
43 **/
44 //------------------------------------------------------------------------------
45 inline p_nr5g_fapi_fapi2mac_queue_t nr5g_fapi_fapi2mac_queue(
46     uint8_t phy_id)
47 {
48     return &fapi2mac_q[phy_id];
49 }
50
51 //------------------------------------------------------------------------------
52 /** @ingroup     group_lte_source_phy_fapi
53  *
54  *  @param[in]   pListElem Pointer to the ListElement
55  *
56  *  @return      void
57  *
58  *  @description This function adds a ListElement API to a Linked list which will
59  *               be sent to L1 once all APIs for a TTI are added
60  *
61 **/
62 //------------------------------------------------------------------------------
63 void nr5g_fapi_fapi2mac_add_api_to_list(
64     uint8_t phy_id,
65     p_fapi_api_queue_elem_t p_list_elem)
66 {
67     p_nr5g_fapi_fapi2mac_queue_t queue = NULL;
68     p_fapi_msg_header_t p_fapi_msg_hdr = NULL;
69
70     if (!p_list_elem) {
71         return;
72     }
73
74     queue = nr5g_fapi_fapi2mac_queue(phy_id);
75     if (queue->p_send_list_head && queue->p_send_list_tail) {
76         p_fapi_msg_hdr = (p_fapi_msg_header_t) (queue->p_send_list_head + 1);
77         p_fapi_msg_hdr->num_msg += 1;
78         queue->p_send_list_tail->p_next = p_list_elem;
79         queue->p_send_list_tail = p_list_elem;
80     } else {
81         queue->p_send_list_head = queue->p_send_list_tail = p_list_elem;
82     }
83 }
84
85 //------------------------------------------------------------------------------
86 /** @ingroup      group_lte_source_phy_fapi
87  *
88  *  @param        A pointer to phy Instance
89  *
90  *  @return       FAPI status
91  *
92  *  @description  This function send API list to L1
93  *
94 **/
95 //------------------------------------------------------------------------------
96 void nr5g_fapi_fapi2mac_send_api_list(
97     )
98 {
99     uint8_t phy_id = 0;
100     p_fapi_api_queue_elem_t p_commit_list_head = NULL;
101     p_fapi_api_queue_elem_t p_commit_list_tail = NULL;
102     p_nr5g_fapi_fapi2mac_queue_t queue = NULL;
103
104     for (phy_id = 0; phy_id < FAPI_MAX_PHY_INSTANCES; phy_id++) {
105         queue = nr5g_fapi_fapi2mac_queue(phy_id);
106         if (queue->p_send_list_head && queue->p_send_list_tail) {
107             if (p_commit_list_head && p_commit_list_tail) {
108                 p_commit_list_tail->p_next = queue->p_send_list_head;
109                 p_commit_list_tail = queue->p_send_list_tail;
110             } else {
111                 p_commit_list_head = queue->p_send_list_head;
112                 p_commit_list_tail = queue->p_send_list_tail;
113             }
114             queue->p_send_list_head = queue->p_send_list_tail = NULL;
115         }
116     }
117
118     if (p_commit_list_head)
119         nr5g_fapi_fapi2mac_wls_send(p_commit_list_head);
120 }
121
122 //------------------------------------------------------------------------------
123 /** @ingroup     group_lte_source_phy_fapi
124  *
125  *  @param[in]   phyInstance PhyInstance Id
126  *  @param[in]   NumMessageInBlock Number of Messages in Block
127  *  @param[in]   AlignOffset Align Offset
128  *  @param[in]   MsgType Message Type
129  *  @param[in]   FrameNum Frame Number
130  *  @param[in]   subFrameNum subframe Number
131  *
132  *  @return      Pointer to the List Element structure
133  *
134  *  @description This function allocates a buffer from shared memory WLS
135  *               interface and creates a List Element structures. It then fills
136  *               all the fields with data being passed in.
137  *
138 **/
139 //------------------------------------------------------------------------------
140 p_fapi_api_queue_elem_t nr5g_fapi_fapi2mac_create_api_list_elem(
141     uint32_t msg_type,
142     uint16_t num_message_in_block,
143     uint32_t align_offset)
144 {
145     p_fapi_api_queue_elem_t p_list_elem = NULL;
146
147     p_list_elem = (p_fapi_api_queue_elem_t)
148         nr5g_fapi_fapi2mac_wls_alloc_buffer();
149     //Fill header for link list of API messages
150     if (p_list_elem) {
151         p_list_elem->msg_type = (uint8_t) msg_type;
152         p_list_elem->num_message_in_block = num_message_in_block;
153         p_list_elem->align_offset = (uint16_t) align_offset;
154         p_list_elem->msg_len = num_message_in_block * align_offset;
155         p_list_elem->p_next = NULL;
156         p_list_elem->p_tx_data_elm_list = NULL;
157         p_list_elem->time_stamp = 0;
158     }
159
160     return p_list_elem;
161 }
162