O-RAN E Maintenance Release contribution for ODULOW
[o-du/phy.git] / fapi_5g / source / api / fapi2phy / p7 / nr5g_fapi_proc_tx_data_req.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
21  * This file consist of implementation of FAPI TX_Data.request message.
22  *
23  **/
24
25 #include "nr5g_fapi_framework.h"
26 #include "gnb_l1_l2_api.h"
27 #include "nr5g_fapi_fapi2mac_api.h"
28 #include "nr5g_fapi_fapi2phy_api.h"
29 #include "nr5g_fapi_fapi2phy_p7_proc.h"
30 #include "nr5g_fapi_fapi2phy_p7_pvt_proc.h"
31 #include "nr5g_fapi_memory.h"
32
33  /** @ingroup group_source_api_p7_fapi2phy_proc
34  *
35  *  @param[in]  p_phy_instance Pointer to PHY instance.
36  *  @param[in]  p_fapi_req Pointer to FAPI TX_Data.request message structure.
37  *  
38  *  @return     Returns ::SUCCESS and ::FAILURE.
39  *
40  *  @description
41  *  This message contains the MAC PDU data for transmission over the air 
42  *  interface. The PDUs described in this message must follow the same order 
43  *  as DL_TTI.request. 
44  *
45 **/
46 uint8_t nr5g_fapi_tx_data_request(
47     bool is_urllc,
48     p_nr5g_fapi_phy_instance_t p_phy_instance,
49     fapi_tx_data_req_t * p_fapi_req,
50     fapi_vendor_msg_t * p_fapi_vendor_msg)
51 {
52     PTXRequestStruct p_ia_tx_req;
53     PMAC2PHY_QUEUE_EL p_list_elem;
54     nr5g_fapi_stats_t *p_stats;
55
56     if (NULL == p_phy_instance) {
57         NR5G_FAPI_LOG(ERROR_LOG, ("[TX_Data.request] Invalid " "phy instance"));
58         return FAILURE;
59     }
60
61     if (NULL == p_fapi_req) {
62         NR5G_FAPI_LOG(ERROR_LOG, ("[TX_Data.request] Invalid fapi " "message"));
63         return FAILURE;
64     }
65
66     p_stats = &p_phy_instance->stats;
67     p_stats->fapi_stats.fapi_tx_data_req++;
68     p_list_elem = nr5g_fapi_fapi2phy_create_api_list_elem((uint8_t)
69         MSG_TYPE_PHY_TX_REQ, 1, (uint32_t) sizeof(TXRequestStruct));
70     if (!p_list_elem) {
71         NR5G_FAPI_LOG(ERROR_LOG, ("[TX_Data.request] Unable to create "
72                 "list element. Out of memory!!!"));
73         return FAILURE;
74     }
75
76     p_ia_tx_req = (PTXRequestStruct) (p_list_elem + 1);
77     nr5g_fapi_tx_data_req_to_phy_translation(p_phy_instance, p_fapi_req, p_fapi_vendor_msg, p_ia_tx_req);
78     nr5g_fapi_fapi2phy_add_to_api_list(is_urllc, p_list_elem);
79
80     p_stats->iapi_stats.iapi_tx_req++;
81     NR5G_FAPI_LOG(DEBUG_LOG, ("[TX_Data.request][%u][%u,%u,%u] is_urllc %u",
82         p_phy_instance->phy_id,
83         p_ia_tx_req->sSFN_Slot.nSFN, p_ia_tx_req->sSFN_Slot.nSlot,
84         p_ia_tx_req->sSFN_Slot.nSym, is_urllc));
85
86     return SUCCESS;
87 }
88
89  /** @ingroup group_source_api_p7_fapi2phy_proc
90  *
91  *  @param[in]  p_fapi_req Pointer to FAPI TX_Data.request structure.
92  *  @param[in]  p_ia_tx_req Pointer to IAPI TX_Data.request structure.
93  *  
94  *  @return     Returns ::SUCCESS and ::FAILURE.
95  *
96  *  @description
97  *  This function converts FAPI TX_Data.request to IAPI TX.request
98  *  structure.
99  *
100 **/
101 uint8_t nr5g_fapi_tx_data_req_to_phy_translation(
102     p_nr5g_fapi_phy_instance_t p_phy_instance,
103     fapi_tx_data_req_t * p_fapi_req,
104     fapi_vendor_msg_t * p_fapi_vendor_msg,
105     PTXRequestStruct p_phy_req)
106 {
107 #define GATHER_SIZE 3
108 #define GATHER_PDU_IDX 0
109 #define GATHER_CW1 1
110 #define GATHER_CW2 2
111     int gather[FAPI_MAX_NUMBER_DL_PDUS_PER_TTI][GATHER_SIZE];
112     int gathered_count = 0;
113     uint8_t *tag;
114     uint32_t length;
115     uint16_t idx, count, found;
116     fapi_tx_pdu_desc_t *p_fapi_pdu = NULL;
117     PDLPDUDataStruct p_phy_pdu = NULL;
118
119     NR5G_FAPI_MEMSET(gather,
120         (sizeof(int) * FAPI_MAX_NUMBER_DL_PDUS_PER_TTI * 3), -1,
121         (sizeof(int) * FAPI_MAX_NUMBER_DL_PDUS_PER_TTI * 3));
122     NR5G_FAPI_MEMSET(p_phy_req, sizeof(TXRequestStruct), 0,
123         sizeof(TXRequestStruct));
124     p_phy_req->sMsgHdr.nMessageType = MSG_TYPE_PHY_TX_REQ;
125     p_phy_req->sMsgHdr.nMessageLen = (uint16_t) sizeof(TXRequestStruct);
126     p_phy_req->sSFN_Slot.nCarrierIdx = p_phy_instance->phy_id;
127     p_phy_req->sSFN_Slot.nSFN = p_fapi_req->sfn;
128     p_phy_req->sSFN_Slot.nSlot = p_fapi_req->slot;
129
130     if (NULL != p_fapi_vendor_msg) {
131         nr5g_fapi_tx_data_req_to_phy_translation_vendor_ext(p_fapi_vendor_msg,
132                                                             p_phy_req);
133     }
134
135     p_phy_req->nPDU = p_fapi_req->num_pdus;
136     p_phy_pdu = (PDLPDUDataStruct) (p_phy_req + 1);
137
138     for (idx = 0; idx < p_fapi_req->num_pdus; idx++) {
139         found = FALSE;
140         p_fapi_pdu = &p_fapi_req->pdu_desc[idx];
141         for (count = 0; count < gathered_count; count++) {
142             if (gather[count][GATHER_PDU_IDX] == p_fapi_pdu->pdu_index) {
143                 found = TRUE;
144                 break;
145             }
146         }
147
148         if (found) {
149             gather[count][GATHER_CW2] = idx;
150         } else {
151             if (gathered_count < FAPI_MAX_NUMBER_DL_PDUS_PER_TTI) {
152                 gather[gathered_count][GATHER_PDU_IDX] = p_fapi_pdu->pdu_index;
153                 gather[gathered_count][GATHER_CW1] = idx;
154                 gathered_count++;
155             } else {
156                 NR5G_FAPI_LOG(ERROR_LOG,
157                     ("exceeded Max DL Pdus supported per tti: %d [%d] ",
158                         gathered_count, FAPI_MAX_NUMBER_DL_PDUS_PER_TTI));
159             }
160         }
161     }
162
163     for (count = 0; count < gathered_count; count++) {
164         p_phy_pdu->nPduLen1 = 0;
165         p_phy_pdu->nPduLen2 = 0;
166         p_phy_pdu->pPayload1 = NULL;
167         p_phy_pdu->pPayload2 = NULL;
168         if (gather[count][GATHER_CW1] >= 0) {
169             p_fapi_pdu = &p_fapi_req->pdu_desc[gather[count][GATHER_CW1]];
170             p_phy_pdu->nPduIdx = p_fapi_pdu->pdu_index;
171             tag = (uint8_t *) & p_fapi_pdu->tlvs[0].tl.tag;
172             if (*tag == FAPI_TX_DATA_PTR_TO_PAYLOAD_64) {
173                 tag++;
174                 length =
175                     (((uint32_t) *
176                         tag) << 16) | (uint32_t) p_fapi_pdu->tlvs[0].tl.length;
177                 p_phy_pdu->nPduLen1 = length;
178                 p_phy_pdu->pPayload1 = p_fapi_pdu->tlvs[0].value;
179             } else {
180                 NR5G_FAPI_LOG(ERROR_LOG,
181                     ("Only 64 bit Ptr to Payload in TX_DATA.req is supported"));
182             }
183         }
184         if (gather[count][GATHER_CW2] >= 0) {
185             p_fapi_pdu = &p_fapi_req->pdu_desc[gather[count][GATHER_CW2]];
186             tag = (uint8_t *) & p_fapi_pdu->tlvs[0].tl.tag;
187             if (*tag == FAPI_TX_DATA_PTR_TO_PAYLOAD_64) {
188                 tag++;
189                 length =
190                     (((uint32_t) *
191                         tag) << 16) | (uint32_t) p_fapi_pdu->tlvs[0].tl.length;
192                 p_phy_pdu->nPduLen2 = length;
193                 p_phy_pdu->pPayload2 = p_fapi_pdu->tlvs[0].value;
194             } else {
195                 NR5G_FAPI_LOG(ERROR_LOG,
196                     ("Only 64 bit Ptr to Payload in TX_DATA.req is supported"));
197             }
198         }
199         p_phy_pdu++;
200     }
201     return SUCCESS;
202 }
203
204  /** @ingroup group_source_api_p7_fapi2phy_proc
205  *
206  *  @param[in]  p_fapi_vendor_msg Pointer to FAPI TX_Data.request structure.
207  *  @param[in]  p_ia_tx_req       Pointer to IAPI TX_Data.request structure.
208  *  
209  *  @return     no return.
210  *
211  *  @description
212  *  This function fills fields for TX.Data structure that come from
213  *  a vendor extension.
214  *
215 **/
216 void nr5g_fapi_tx_data_req_to_phy_translation_vendor_ext(
217     fapi_vendor_msg_t * p_fapi_vendor_msg,
218     PTXRequestStruct p_phy_req)
219 {
220     p_phy_req->sSFN_Slot.nSym = p_fapi_vendor_msg->p7_req_vendor.tx_data_req.sym;
221 }