* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fapi_5g / source / framework / wls / lib / nr5g_fapi_wls.c
index 2370511..f7074c2 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
 *
-*   Copyright (c) 2019 Intel.
+*   Copyright (c) 2021 Intel.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
@@ -28,6 +28,8 @@
 #include "nr5g_fapi_log.h"
 #include "nr5g_fapi_memory.h"
 
+#define WLS_HUGE_DEF_PAGE_SIZEA 0x40000000LL
+
 nr5g_fapi_wls_context_t g_wls_ctx;
 
 static uint8_t alloc_track[ALLOC_TRACK_SIZE];
@@ -74,30 +76,6 @@ inline uint8_t nr5g_fapi_fapi2phy_wls_ready(
     return retval;
 }
 
-//----------------------------------------------------------------------------------
-/** @ingroup nr5g_fapi_source_framework_wls_fapi2phy_group
- *
- *  @param void
- *
- *  @return  0 if SUCCESS
- *
- *  @description
- *  This function is called at WLS init and waits in an infinite for L1 to respond back with some information
- *  needed by the L2
- *
-**/
-//----------------------------------------------------------------------------------
-inline uint8_t nr5g_fapi_fapi2mac_wls_ready(
-    )
-{
-    int retval = 0;
-    p_nr5g_fapi_wls_context_t p_wls = nr5g_fapi_wls_context();
-
-    retval = WLS_Ready1(p_wls->h_wls[NR5G_FAPI2MAC_WLS_INST]);
-
-    return retval;
-}
-
 //------------------------------------------------------------------------------
 /** @ingroup nr5g_fapi_source_framework_wls_lib_group
  *
@@ -116,7 +94,7 @@ void nr5g_fapi_wls_show_data(
     uint32_t size)
 {
     uint8_t *d = ptr;
-    int i;
+    uint32_t i;
 
     for (i = 0; i < size; i++) {
         if (!(i & 0xf))
@@ -226,10 +204,10 @@ void *nr5g_fapi_wls_pa_to_va(
  *
 **/
 //------------------------------------------------------------------------------
-uint8_t wls_fapi_add_blocks_to_ul(
+uint32_t wls_fapi_add_blocks_to_ul(
     void)
 {
-    int num_blocks = 0;
+    uint32_t num_blocks = 0;
     p_nr5g_fapi_wls_context_t pWls = nr5g_fapi_wls_context();
     WLS_HANDLE h_wls = pWls->h_wls[NR5G_FAPI2PHY_WLS_INST];
 
@@ -268,8 +246,10 @@ uint8_t wls_fapi_add_blocks_to_ul(
 uint8_t nr5g_fapi_wls_init(
     p_nr5g_fapi_cfg_t cfg)
 {
+    uint64_t mac_shmem_size = 0;
+    uint64_t phy_shmem_size = 0;
+
     p_nr5g_fapi_wls_context_t p_wls_ctx = nr5g_fapi_wls_context();
-    const char *dev_name = "wls0";
 
     if (p_wls_ctx->h_wls[NR5G_FAPI2PHY_WLS_INST] &&
         p_wls_ctx->h_wls[NR5G_FAPI2MAC_WLS_INST]) {
@@ -277,10 +257,12 @@ uint8_t nr5g_fapi_wls_init(
         return FAILURE;
     }
 
-    p_wls_ctx->shmem_size = cfg->wls.shmem_size;
     p_wls_ctx->h_wls[NR5G_FAPI2MAC_WLS_INST] =
-        WLS_Open_Dual(dev_name, WLS_SLAVE_CLIENT,
-        cfg->wls.shmem_size, &p_wls_ctx->h_wls[NR5G_FAPI2PHY_WLS_INST]);
+        WLS_Open_Dual(basename(cfg->wls.device_name), WLS_SLAVE_CLIENT,
+        &mac_shmem_size, &phy_shmem_size, &p_wls_ctx->h_wls[NR5G_FAPI2PHY_WLS_INST]);
+    
+    cfg->wls.shmem_size = mac_shmem_size + phy_shmem_size;
+    p_wls_ctx->shmem_size = cfg->wls.shmem_size;
     if ((NULL == p_wls_ctx->h_wls[NR5G_FAPI2PHY_WLS_INST]) &&
         (NULL == p_wls_ctx->h_wls[NR5G_FAPI2MAC_WLS_INST])) {
         NR5G_FAPI_LOG(ERROR_LOG, ("[NR5G_FAPI_ WLS] WLS Open Dual Failed."));
@@ -298,7 +280,7 @@ uint8_t nr5g_fapi_wls_init(
     p_wls_ctx->shmem = WLS_Alloc(p_wls_ctx->h_wls[NR5G_FAPI2PHY_WLS_INST],
         p_wls_ctx->shmem_size);
     p_wls_ctx->pWlsMemBase = p_wls_ctx->shmem;
-    p_wls_ctx->nTotalMemorySize = p_wls_ctx->shmem_size;
+    p_wls_ctx->nTotalMemorySize = mac_shmem_size;
     if (NULL == p_wls_ctx->shmem) {
         printf("Unable to alloc WLS Memory\n");
         return FAILURE;
@@ -420,16 +402,34 @@ uint32_t wls_fapi_create_mem_array(
 uint8_t wls_fapi_create_partition(
     p_nr5g_fapi_wls_context_t pWls)
 {
-#define WLS_HUGE_DEF_PAGE_SIZEA    0x40000000LL
-    static long hugePageSize = WLS_HUGE_DEF_PAGE_SIZEA;
-    //   NR5G_FAPI_MEMSET(pWls->pWlsMemBase , 0xCC, pWls->nTotalMemorySize);  // This is done by the Master Only
-    pWls->pPartitionMemBase =
-        (void *)(((uint8_t *) pWls->pWlsMemBase) + hugePageSize);
-    pWls->nPartitionMemSize = (pWls->nTotalMemorySize - hugePageSize);
-
-    pWls->nTotalBlocks = pWls->nPartitionMemSize / MSG_MAXSIZE;
+    uint64_t nWlsMemBaseUsable;
+    uint64_t nTotalMemorySizeUsable;
+    uint64_t nBalance, nBlockSize, nBlockSizeMask, nHugepageSizeMask;
+
+    nBlockSize = MSG_MAXSIZE;
+    nWlsMemBaseUsable = (uint64_t)pWls->pWlsMemBase;
+    nTotalMemorySizeUsable = pWls->nTotalMemorySize - WLS_HUGE_DEF_PAGE_SIZEA;
+    nBlockSizeMask = nBlockSize-1;
+
+    // Align Starting Location
+    nWlsMemBaseUsable = (nWlsMemBaseUsable + nBlockSizeMask) & (~nBlockSizeMask);
+    nBalance = nWlsMemBaseUsable - (uint64_t)pWls->pWlsMemBase;
+    nTotalMemorySizeUsable -= nBalance;
+
+    // Align Ending Location
+    nBalance = nTotalMemorySizeUsable % nBlockSize;
+    nTotalMemorySizeUsable -= nBalance;
+
+    // Move start location to the next hugepage boundary
+    nHugepageSizeMask = WLS_HUGE_DEF_PAGE_SIZEA-1;
+    nWlsMemBaseUsable = (nWlsMemBaseUsable + WLS_HUGE_DEF_PAGE_SIZEA) & (~nHugepageSizeMask);
+
+
+    pWls->pPartitionMemBase = (void *)nWlsMemBaseUsable;
+    pWls->nPartitionMemSize = nTotalMemorySizeUsable;
+    pWls->nTotalBlocks = pWls->nPartitionMemSize / nBlockSize;
     return wls_fapi_create_mem_array(&pWls->sWlsStruct, pWls->pPartitionMemBase,
-        pWls->nPartitionMemSize, MSG_MAXSIZE);
+        pWls->nPartitionMemSize, nBlockSize);
 }
 
 //------------------------------------------------------------------------------
@@ -702,7 +702,7 @@ void wls_fapi_free_buffer(
 uint8_t nr5g_fapi_wls_memory_init(
     )
 {
-    int nBlocks = 0;
+    uint32_t nBlocks = 0;
     p_nr5g_fapi_wls_context_t p_wls = nr5g_fapi_wls_context();
 
     if (FAILURE == wls_fapi_create_partition(p_wls))