Rach Indication
[o-du/l2.git] / src / 5gnrmac / lwr_mac_handle_phy.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
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 /* header include files (.h) */
20 #include "envopt.h"        /* environment options */
21 #include "envdep.h"        /* environment dependent */
22 #include "envind.h"        /* environment independent */
23 #include "gen.h"           /* general */
24 #include "ssi.h"           /* system services */
25 #include "cm_tkns.h"       /* Common Token Defines */
26 #include "cm_llist.h"      /* Common Link List Defines */
27 #include "cm_hash.h"       /* Common Hash List Defines */
28 #include "cm_lte.h"        /* Common LTE Defines */
29 #include "cm_mblk.h"        /* Common LTE Defines */
30 #include "tfu.h"           /* RGU Interface defines */
31 #ifdef FAPI
32 #include "fapi.h"
33 #endif
34
35 /* header/extern include files (.x) */
36 #include "gen.x"           /* general */
37 #include "ssi.x"           /* system services */
38 #include "cm_tkns.x"       /* Common Token Definitions */
39 #include "cm_llist.x"      /* Common Link List Definitions */
40 #include "cm_lib.x"        /* Common Library Definitions */
41 #include "cm_hash.x"       /* Common Hash List Definitions */
42 #include "cm_lte.x"        /* Common LTE Defines */
43 #include "cm_mblk.x"        /* Common LTE Defines */
44 #include "tfu.x"           /* RGU Interface includes */
45 #include "du_log.h"
46 #include "lwr_mac_fsm.h"
47 #include "lwr_mac_phy.h"
48 #include "lwr_mac_upr_inf.h"
49
50 #ifdef FAPI
51 /* Function pointer for slot indication from lower mac to mac */
52 packSlotIndMsg packSlotIndOpts[] =
53 {
54    packLcSlotInd,  /* packing for loosely coupled */
55    fapiMacSlotInd, /* packing for tightly coupled */
56    packLwlcSlotInd /* packing for light weight loosly coupled */
57 };
58
59 /* Function pointer for rach indication from lower mac to mac */ 
60 packRachIndMsg sendRachIndOpts[] =
61 {
62    packRachInd,
63    fapiMacRachInd,
64    packRachInd
65 };
66
67 /*******************************************************************
68  *
69  * @brief Fills post structure
70  *
71  * @details
72  *
73  *    Function : fillLwrMacToMacPst
74  *
75  *    Functionality:
76  *     Fills post structure used to send message from lower MAC
77  *     to MAC
78  *
79  * @params[in] Pst pointer 
80  * @return ROK     - success
81  *         RFAILED - failure
82  *
83  * ****************************************************************/
84 void fillLwrMacToMacPst(Pst *pst)
85 {
86    pst->srcProcId = 0;
87    pst->dstProcId = 0;
88    pst->srcEnt = ENTTF;
89    pst->dstEnt = ENTRG;
90    pst->srcInst = 0;
91    pst->dstInst = 0;
92    pst->region = 0;
93    pst->pool =  0; 
94    pst->selector = MAC_SELECTOR_TC;
95 }
96
97 /*******************************************************************
98  *
99  * @brief Processes Slot Indication from PHY and sends to MAC
100  *
101  * @details
102  *
103  *    Function : handleSlotInd
104  *
105  *    Functionality:
106  *     Processes Slot Indication from PHY and sends to MAC
107  *
108  * @params[in] fapi_slot_ind_t pointer
109  * @return ROK     - success
110  *         RFAILED - failure
111  *
112  * ****************************************************************/
113 U16 handleSlotInd(fapi_slot_ind_t *fapiSlotInd)
114 {
115    /* fill Pst structure to send to lwr_mac to MAC */
116    Pst pst;
117    uint16_t ret;
118    SlotIndInfo slotInd;
119
120    fillLwrMacToMacPst(&pst);
121    pst.event = EVENT_SLOT_IND_TO_MAC;
122
123    slotInd.sfn = fapiSlotInd->sfn;
124    slotInd.slot = fapiSlotInd->slot;
125
126    ret = (*packSlotIndOpts[pst.selector])(&pst, &slotInd);
127
128 #ifdef INTEL_WLS
129    slotIndIdx++;
130    if(slotIndIdx > WLS_MEM_FREE_PRD)
131    {
132       slotIndIdx = 1;
133    }
134    freeWlsBlockList(slotIndIdx - 1);
135 #endif
136
137    return ret;
138 }
139
140
141 /*******************************************************************
142  *
143  * @brief Processes Rach Indication from PHY and sends to MAC
144  *
145  * @details
146  *
147  *    Function : handleRachInd
148  *
149  *    Functionality:
150  *         Processes Rach Indication from PHY and sends to MAC
151  *
152  * @params[in] fapi_rach_indication_t pointer
153  * @return ROK     - success
154  *         RFAILED - failure
155  *
156  * ****************************************************************/
157 uint8_t handleRachInd(fapi_rach_indication_t  *fapiRachInd)
158 {
159    Pst          pst;
160    uint8_t      pduIdx;
161    uint8_t      prmbleIdx;
162    RachPduInfo  *rachPdu;
163    RachInd      rachInd;
164
165    rachInd.timingInfo.sfn = fapiRachInd->sfn;
166    rachInd.timingInfo.slot = fapiRachInd->slot;
167    rachInd.numPdu = fapiRachInd->numPdus;
168    for(pduIdx=0; pduIdx < rachInd.numPdu; pduIdx++)
169    {
170       rachPdu = &rachInd.rachPdu[pduIdx];
171       rachPdu->pci = fapiRachInd->rachPdu[pduIdx].physCellId;
172       rachPdu->symbolIdx = fapiRachInd->rachPdu[pduIdx].symbolIndex;
173       rachPdu->slotIdx = fapiRachInd->rachPdu[pduIdx].slotIndex;
174       rachPdu->freqIdx = fapiRachInd->rachPdu[pduIdx].freqIndex;
175       rachPdu->numPream = fapiRachInd->rachPdu[pduIdx].numPreamble; 
176       for(prmbleIdx=0; prmbleIdx<rachPdu->numPream; prmbleIdx++)
177       {
178          rachPdu->preamInfo[prmbleIdx].preamIdx = \
179             fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].preambleIndex;
180          rachPdu->preamInfo[prmbleIdx].timingAdv = \
181             fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].timingAdvance;
182       }
183    }
184    fillLwrMacToMacPst(&pst);
185    pst.event = EVENT_RACH_IND_TO_MAC;
186
187    (*sendRachIndOpts[pst.selector])(&pst, &rachInd);
188         return ROK;
189
190 }/* handleRachInd */
191
192 #endif /* FAPI */
193
194 void handlePhyMessages(uint16_t msgType, uint32_t msgSize, void *msg)
195 {
196 #ifdef FAPI
197    /* extract the header */
198    fapi_msg_t *header;
199    header = (fapi_msg_t *)msg;
200
201    switch(header->message_type_id)
202    {
203       case FAPI_PARAM_RESPONSE:
204       case FAPI_CONFIG_RESPONSE:
205       {
206          sendToLowerMac(msgType, msgSize, msg);
207          break;
208       }
209       case FAPI_SLOT_INDICATION:
210       {
211          if(clGlobalCp.phyState == PHY_STATE_CONFIGURED)
212          {
213             DU_LOG("\nLOWER MAC: PHY has moved to running state");
214             clGlobalCp.phyState = PHY_STATE_RUNNING;
215          }
216
217          fapi_slot_ind_t *slotInd;
218          slotInd  = (fapi_slot_ind_t *)msg;
219          handleSlotInd(slotInd);
220          break;
221       }
222       case FAPI_ERROR_INDICATION:
223       {
224          break;
225       }
226       case FAPI_RX_DATA_INDICATION:
227       {
228          break;
229       }  
230       case FAPI_CRC_INDICATION:
231       {
232          break;
233       }  
234       case FAPI_UCI_INDICATION:
235       {
236          break;
237       }  
238       case FAPI_SRS_INDICATION:
239       {
240          break;
241       }  
242       case FAPI_RACH_INDICATION:
243       {
244          fapi_rach_indication_t  *rachInd;
245          rachInd = (fapi_rach_indication_t *)msg;
246          handleRachInd(rachInd);
247          break;
248       }  
249    }
250 #ifdef INTEL_WLS
251    WLS_MEM_FREE(msg, LWR_MAC_WLS_BUF_SIZE); 
252 #endif
253 #endif
254 }
255
256 /**********************************************************************
257          End of file
258 **********************************************************************/