* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p7 / nr5g_fapi_proc_vendor_p7_msgs.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2021 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 #include "nr5g_mac_phy_api.h"
20 #include "nr5g_fapi_framework.h"
21 #include "nr5g_fapi_fapi2mac_api.h"
22 #include "nr5g_fapi_fapi2mac_p7_proc.h"
23
24
25 static inline p_fapi_api_queue_elem_t alloc_vendor_p7_msg()
26 {
27     p_fapi_api_queue_elem_t p_vend_elem = nr5g_fapi_fapi2mac_create_api_list_elem(
28         FAPI_VENDOR_EXT_P7_IND,
29         1, sizeof(fapi_vendor_p7_ind_msg_t));
30
31     if (p_vend_elem)
32     {
33         fapi_vendor_p7_ind_msg_t* p_vend_p7_ind = (fapi_vendor_p7_ind_msg_t*) (p_vend_elem + 1);
34         p_vend_p7_ind->header.msg_id = FAPI_VENDOR_EXT_P7_IND;
35         p_vend_p7_ind->header.length = (uint16_t) sizeof(fapi_vendor_p7_ind_msg_t);
36     }
37     else
38     {
39         NR5G_FAPI_LOG(ERROR_LOG, ("[VENDOR EXT indication] Unable to create "
40             "list element. Out of memory!!!"));
41     }
42     return p_vend_elem;
43 }
44
45
46 /** @ingroup group_source_api_p7_fapi2mac_proc
47  *
48  *  @return  Returns pointer to fapi_vendor_p7_ind_msg_t
49  *
50  *  @description
51  *  Used to access fapi_vendor_p7_ind_msg_t for filling.
52  *  Allocates the message if it's not allocated yet.
53  *
54 **/
55 fapi_vendor_p7_ind_msg_t* nr5g_fapi_proc_vendor_p7_msg_get(
56     p_fapi_api_stored_vendor_queue_elems vendor_extension_elems,
57     uint8_t phy_id)
58 {
59     if(phy_id >= FAPI_MAX_PHY_INSTANCES)
60     {
61         NR5G_FAPI_LOG(ERROR_LOG, ("[VENDOR EXT indication] Out of bounds"
62             "phy_id=%u", phy_id));
63         return NULL;
64     }
65
66     p_fapi_api_queue_elem_t p_vend_elem = vendor_extension_elems->vendor_ext[phy_id];
67     if(!p_vend_elem)
68     {
69         NR5G_FAPI_LOG(DEBUG_LOG, ("[VENDOR EXT indication] No vendor element"
70             "for phy_id=%u yet. Creating new", phy_id));
71         p_vend_elem = alloc_vendor_p7_msg();
72         vendor_extension_elems->vendor_ext[phy_id] = p_vend_elem;
73     }
74
75     return p_vend_elem ? (fapi_vendor_p7_ind_msg_t*) (p_vend_elem + 1) : NULL;
76 }
77
78 /** @ingroup group_source_api_p7_fapi2mac_proc
79  *
80  *  @return  none
81  *
82  *  @description
83  *  Adds all cached vendor msgs to api list.
84  *  Function shall be called after all other fapi msgs are added.
85  *
86 **/
87 void nr5g_fapi_proc_vendor_p7_msgs_move_to_api_list(
88     bool is_urllc,
89     p_fapi_api_stored_vendor_queue_elems vendor_extension_elems)
90 {
91     uint8_t phy_id;
92     for(phy_id=0; phy_id<FAPI_MAX_PHY_INSTANCES; phy_id++)
93     {
94         p_fapi_api_queue_elem_t* p_vend_elem = &(vendor_extension_elems->vendor_ext[phy_id]);
95         nr5g_fapi_fapi2mac_add_api_to_list(phy_id, *p_vend_elem, is_urllc);
96         *p_vend_elem = NULL;
97     }
98 }