74e631ad18109baab26d757b2499dd37260cb15f
[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
32  /** @ingroup group_source_api_p7_fapi2phy_proc
33  *
34  *  @param[in]  p_phy_instance Pointer to PHY instance.
35  *  @param[in]  p_fapi_req Pointer to FAPI TX_Data.request message structure.
36  *  
37  *  @return     Returns ::SUCCESS and ::FAILURE.
38  *
39  *  @description
40  *  This message contains the MAC PDU data for transmission over the air 
41  *  interface. The PDUs described in this message must follow the same order 
42  *  as DL_TTI.request. 
43  *
44 **/
45 uint8_t nr5g_fapi_tx_data_request(
46     p_nr5g_fapi_phy_instance_t p_phy_instance,
47     fapi_tx_data_req_t * p_fapi_req,
48     fapi_vendor_msg_t * p_fapi_vendor_msg)
49 {
50     PTXRequestStruct p_ia_tx_req;
51     PMAC2PHY_QUEUE_EL p_list_elem;
52     nr5g_fapi_stats_t *p_stats;
53     UNUSED(p_fapi_vendor_msg);
54
55     if (NULL == p_phy_instance) {
56         NR5G_FAPI_LOG(ERROR_LOG, ("[TX_Data.request] Invalid " "phy instance"));
57         return FAILURE;
58     }
59
60     if (NULL == p_fapi_req) {
61         NR5G_FAPI_LOG(ERROR_LOG, ("[TX_Data.request] Invalid fapi " "message"));
62         return FAILURE;
63     }
64
65     p_stats = &p_phy_instance->stats;
66     p_stats->fapi_stats.fapi_tx_data_req++;
67     p_list_elem = nr5g_fapi_fapi2phy_create_api_list_elem((uint8_t)
68         MSG_TYPE_PHY_TX_REQ, 1, (uint32_t) sizeof(TXRequestStruct));
69     if (!p_list_elem) {
70         NR5G_FAPI_LOG(ERROR_LOG, ("[TX_Data.request] Unable to create "
71                 "list element. Out of memory!!!"));
72         return FAILURE;
73     }
74
75     p_ia_tx_req = (PTXRequestStruct) (p_list_elem + 1);
76     nr5g_fapi_tx_data_req_to_phy_translation(p_phy_instance, p_fapi_req,
77         p_ia_tx_req);
78     nr5g_fapi_fapi2phy_add_to_api_list(p_list_elem);
79
80     p_stats->iapi_stats.iapi_tx_req++;
81     NR5G_FAPI_LOG(DEBUG_LOG, ("[TX_Data.request][%d][%d,%d]",
82             p_phy_instance->phy_id, p_ia_tx_req->sSFN_Slot.nSFN,
83             p_ia_tx_req->sSFN_Slot.nSlot));
84
85     return SUCCESS;
86 }
87
88  /** @ingroup group_source_api_p7_fapi2phy_proc
89  *
90  *  @param[in]  p_fapi_req Pointer to FAPI TX_Data.request structure.
91  *  @param[in]  p_ia_tx_req Pointer to IAPI TX_Data.request structure.
92  *  
93  *  @return     Returns ::SUCCESS and ::FAILURE.
94  *
95  *  @description
96  *  This function converts FAPI TX_Data.request to IAPI TX.request
97  *  structure.
98  *
99 **/
100 uint8_t nr5g_fapi_tx_data_req_to_phy_translation(
101     p_nr5g_fapi_phy_instance_t p_phy_instance,
102     fapi_tx_data_req_t * p_fapi_req,
103     PTXRequestStruct p_phy_req)
104 {
105     uint16_t idx;
106     uint32_t tlv;
107     fapi_tx_pdu_desc_t *p_fapi_pdu = NULL;
108     PDLPDUDataStruct p_phy_pdu = NULL;
109
110     p_phy_req->sMsgHdr.nMessageType = MSG_TYPE_PHY_TX_REQ;
111     p_phy_req->sMsgHdr.nMessageLen = (uint16_t) sizeof(TXRequestStruct);
112     p_phy_req->sSFN_Slot.nCarrierIdx = p_phy_instance->phy_id;
113     p_phy_req->sSFN_Slot.nSFN = p_fapi_req->sfn;
114     p_phy_req->sSFN_Slot.nSlot = p_fapi_req->slot;
115     p_phy_req->nPDU = p_fapi_req->num_pdus;
116     p_phy_pdu = (PDLPDUDataStruct) (p_phy_req + 1);
117     for (idx = 0; idx < p_fapi_req->num_pdus; idx++) {
118         p_fapi_pdu = &p_fapi_req->pdu_desc[idx];
119         for (tlv = 0; tlv < p_fapi_pdu->num_tlvs; tlv++) {
120             p_phy_pdu->nPduIdx = p_fapi_pdu->pdu_index;
121             p_phy_pdu->nPduLen1 = 0;
122             p_phy_pdu->nPduLen2 = 0;
123             p_phy_pdu->pPayload1 = NULL;
124             p_phy_pdu->pPayload2 = NULL;
125             if (tlv == 0) {
126                 p_phy_pdu->nPduLen1 = p_fapi_pdu->tlvs[tlv].tl.length;
127                 p_phy_pdu->pPayload1 = p_fapi_pdu->tlvs[tlv].value;
128             } else {
129                 p_phy_pdu->nPduLen2 = p_fapi_pdu->tlvs[tlv].tl.length;
130                 p_phy_pdu->pPayload2 = p_fapi_pdu->tlvs[tlv].value;
131             }
132         }
133         p_phy_pdu++;
134     }
135     return SUCCESS;
136 }