X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=fhi_lib%2Fapp%2Fsrc%2Fsample-app.c;h=43582f5bc7972ddb2c4ef1ce992c56381a3448ba;hb=refs%2Fheads%2Fmaster;hp=f45cf947c4c096eb31e95790d6a18dba29aa685a;hpb=cef07f74965b1749dd909fc1322e211489fea2ea;p=o-du%2Fphy.git diff --git a/fhi_lib/app/src/sample-app.c b/fhi_lib/app/src/sample-app.c index f45cf94..43582f5 100644 --- a/fhi_lib/app/src/sample-app.c +++ b/fhi_lib/app/src/sample-app.c @@ -1,6 +1,6 @@ /****************************************************************************** * -* Copyright (c) 2019 Intel. +* Copyright (c) 2020 Intel. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,20 @@ * *******************************************************************************/ +/** + * @brief Main module of sample application. Demonstration of usage of xRAN library for ORAN + * WG4 Front haul + * @file sample-app.c + * @ingroup xran + * @author Intel Corporation + * + **/ #define _GNU_SOURCE #include +#include #include +#include #include #include #include @@ -32,147 +42,56 @@ #include #include #include - +#include +#include #include "common.h" #include "config.h" #include "xran_mlog_lnx.h" #include "xran_fh_o_du.h" -#include "xran_cp_api.h" #include "xran_sync_api.h" #include "xran_mlog_task_id.h" +#include "app_io_fh_xran.h" +#include "app_profile_xran.h" +#ifdef FWK_ENABLED +#include "app_bbu_pool.h" +#endif +#include "xran_ecpri_owd_measurements.h" #define MAX_BBU_POOL_CORE_MASK (4) - - -#define SW_FPGA_TOTAL_BUFFER_LEN 4*1024*1024*1024 -#define SW_FPGA_SEGMENT_BUFFER_LEN 1*1024*1024*1024 -#define SW_FPGA_FH_TOTAL_BUFFER_LEN 1*1024*1024*1024 -#define FPGA_TO_SW_PRACH_RX_BUFFER_LEN (8192) - -#define NSEC_PER_SEC 1000000000 - -#define MAX_PKT_BURST (448+4) // 4x14x8 -#define N_MAX_BUFFER_SEGMENT MAX_PKT_BURST - +#ifndef NS_PER_SEC +#define NS_PER_SEC 1E9 +#endif #define MAIN_PRIORITY 98 -#define NUM_OF_SUBFRAME_PER_FRAME (10) +#define CPU_HZ ticks_per_usec /* us */ -enum app_state state; +struct sample_app_params { + int num_vfs; + int num_o_xu; + char *cfg_file; + char *usecase_file; + char vf_pcie_addr[XRAN_PORTS_NUM][XRAN_VF_MAX][32]; +}; -uint64_t tick_per_usec; -static volatile uint64_t timer_last_irq_tick = 0; -static uint64_t tsc_resolution_hz = 0; +struct app_sym_cb_ctx { + int32_t cb_param; + struct xran_sense_of_time sense_of_time; +}; -RuntimeConfig startupConfiguration = {0}; +static enum app_state state; +static uint64_t ticks_per_usec; -/* buffers size */ -uint32_t nFpgaToSW_FTH_RxBufferLen; -uint32_t nFpgaToSW_PRACH_RxBufferLen; -uint32_t nSW_ToFpga_FTH_TxBufferLen; +UsecaseConfig* p_usecaseConfiguration = {NULL}; +RuntimeConfig* p_startupConfiguration[XRAN_PORTS_NUM] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; -static struct xran_fh_init xranInit; -void * xranHandle = NULL; +struct app_sym_cb_ctx cb_sym_ctx[XRAN_CB_SYM_MAX]; -struct xran_fh_config xranConf; -struct xran_fh_config *pXranConf = NULL; - -typedef struct -{ - uint32_t phaseFlag :1; - uint32_t NRARFCN :22; - uint32_t SULFreShift :1; - uint32_t SULFlag :1; - uint32_t rsv :7; -}FPGAPhaseCompCfg; - -typedef struct XranLibConfig -{ - uint32_t nDriverCoreId; - uint32_t nTimingAdvance; - uint32_t nFhConfig; - uint32_t nFhBufIntFlag; - uint32_t nSectorNum; - uint32_t nNrOfSlotInSf; - uint32_t nNrofSfInFrame; - void * pFthInstanceHandles; -}XranLibConfigStruct; -typedef enum { - XRANFTHTX_OUT = 0, - XRANFTHTX_PRB_MAP_OUT, - XRANFTHRX_IN, - XRANFTHRX_PRB_MAP_IN, - XRANFTHRACH_IN, - MAX_SW_XRAN_INTERFACE_NUM -}SWXRANInterfaceTypeEnum; - -/* - * manage one cell's all Ethernet frames for one DL or UL LTE subframe - */ -typedef struct { - /* -1-this subframe is not used in current frame format - 0-this subframe can be transmitted, i.e., data is ready - 1-this subframe is waiting transmission, i.e., data is not ready - 10 - DL transmission missing deadline. When FE needs this subframe data but bValid is still 1, - set bValid to 10. - */ - int32_t bValid ; // when UL rx, it is subframe index. - int32_t nSegToBeGen; - int32_t nSegGenerated; // how many date segment are generated by DL LTE processing or received from FE - // -1 means that DL packet to be transmitted is not ready in BS - int32_t nSegTransferred; // number of data segments has been transmitted or received - struct rte_mbuf *pData[N_MAX_BUFFER_SEGMENT]; // point to DPDK allocated memory pool - struct xran_buffer_list sBufferList; -} BbuIoBufCtrlStruct; - -typedef struct { - uint64_t nCoreMask; - int16_t cpuSocketId; - uint8_t nDriverCoreId; - uint8_t nFHCoreId; - - struct rte_mempool *bbuio_buf_pool; - - /* io struct */ - BbuIoBufCtrlStruct sFrontHaulTxBbuIoBufCtrl[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR]; - BbuIoBufCtrlStruct sFrontHaulTxPrbMapBbuIoBufCtrl[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR]; - BbuIoBufCtrlStruct sFrontHaulRxBbuIoBufCtrl[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR]; - BbuIoBufCtrlStruct sFrontHaulRxPrbMapBbuIoBufCtrl[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR]; - BbuIoBufCtrlStruct sFHPrachRxBbuIoBufCtrl[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR]; - - /* buffers lists */ - struct xran_flat_buffer sFrontHaulTxBuffers[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR][XRAN_NUM_OF_SYMBOL_PER_SLOT]; - struct xran_flat_buffer sFrontHaulTxPrbMapBuffers[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR]; - struct xran_flat_buffer sFrontHaulRxBuffers[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR][XRAN_NUM_OF_SYMBOL_PER_SLOT]; - struct xran_flat_buffer sFrontHaulRxPrbMapBuffers[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR]; - struct xran_flat_buffer sFHPrachRxBuffers[XRAN_N_FE_BUF_LEN][XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR][XRAN_NUM_OF_SYMBOL_PER_SLOT]; - - void* nInstanceHandle[XRAN_PORTS_NUM][XRAN_MAX_SECTOR_NR]; // instance per sector - uint32_t nBufPoolIndex[XRAN_MAX_SECTOR_NR][MAX_SW_XRAN_INTERFACE_NUM]; // every api owns unique buffer pool - uint16_t nInstanceNum; - - uint64_t nTscTiming[XRAN_N_FE_BUF_LEN]; // records the TSC when a timing packet is received. -} BbuXranIoIfStruct; - -static BbuXranIoIfStruct gsXranIoIf; -static XranLibConfigStruct *gpXranLibConfig = NULL; - -extern long rx_counter; -extern long tx_counter; - -#define CPU_HZ tick_per_usec //us - -/* Application User space functions */ -void xran_fh_rx_callback(void *pCallbackTag, int32_t status); -void xran_fh_rx_prach_callback(void *pCallbackTag, int32_t status); - -static BbuXranIoIfStruct *xran_get_ctx(void) -{ - return &gsXranIoIf; -} +long old_rx_counter[XRAN_PORTS_NUM] = {0,0,0,0,0,0,0,0}; +long old_tx_counter[XRAN_PORTS_NUM] = {0,0,0,0,0,0,0,0}; -static void print_menu() +static void +app_print_menu() { puts("+---------------------------------------+"); puts("| Press 1 to start 5G NR XRAN traffic |"); @@ -181,84 +100,13 @@ static void print_menu() puts("+---------------------------------------+"); } -static int32_t get_xran_sfidx(uint8_t nNrOfSlotInSf) -{ - int32_t nSfIdx = -1; - uint32_t nFrameIdx; - uint32_t nSubframeIdx; - uint32_t nSlotIdx; - uint64_t nSecond; - - uint32_t nXranTime = xran_get_slot_idx(&nFrameIdx, &nSubframeIdx, &nSlotIdx, &nSecond); - nSfIdx = nFrameIdx*NUM_OF_SUBFRAME_PER_FRAME*nNrOfSlotInSf - + nSubframeIdx*nNrOfSlotInSf - + nSlotIdx; -#if 0 - printf("\nxranTime is %d, return is %d, radio frame is %d, subframe is %d slot is %d tsc is %llu us", - nXranTime, - nSfIdx, - nFrameIdx, - nSubframeIdx, - nSlotIdx, - __rdtsc()/CPU_HZ); -#endif - - return nSfIdx; -} - -void xran_fh_rx_callback(void *pCallbackTag, xran_status_t status) -{ - uint64_t t1 = MLogTick(); - uint32_t mlogVar[10]; - uint32_t mlogVarCnt = 0; - uint8_t Numerlogy = xranConf.frame_conf.nNumerology; - uint8_t nNrOfSlotInSf = 1<> 16; /* tti */ - mlogVar[mlogVarCnt++] = status & 0xFF; /* sym */ - mlogVar[mlogVarCnt++] = (uint32_t)sfIdx; - MLogAddVariables(mlogVarCnt, mlogVar, MLogTick()); - rte_pause(); - - MLogTask(PID_GNB_SYM_CB, t1, MLogTick()); - return; -} - -void xran_fh_rx_prach_callback(void *pCallbackTag, xran_status_t status) -{ - uint64_t t1 = MLogTick(); - uint32_t mlogVar[10]; - uint32_t mlogVarCnt = 0; - - mlogVar[mlogVarCnt++] = 0xDDDDDDDD; - mlogVar[mlogVarCnt++] = status >> 16; /* tti */ - mlogVar[mlogVarCnt++] = status & 0xFF; /* sym */ - MLogAddVariables(mlogVarCnt, mlogVar, MLogTick()); - rte_pause(); - - MLogTask(PID_GNB_PRACH_CB, t1, MLogTick()); -} - -//------------------------------------------------------------------------------------------- -/** @ingroup group_nbiot_source_auxlib_timer - * - * @param void - * - * @return Ticks - * - * @description - * This function reads the rtdsc clock and returns the current value in there. - * -**/ -//------------------------------------------------------------------------------------------- -unsigned long timer_get_ticks(void) +uint64_t +app_timer_get_ticks(void) { - unsigned long ret; + uint64_t ret; union { - unsigned long tsc_64; + uint64_t tsc_64; struct { uint32_t lo_32; @@ -270,12 +118,12 @@ unsigned long timer_get_ticks(void) "=a" (tsc.lo_32), "=d" (tsc.hi_32)); - ret = ((unsigned long)tsc.tsc_64); + ret = ((uint64_t)tsc.tsc_64); return ret; } //------------------------------------------------------------------------------------------- -/** @ingroup group_lte_source_auxlib_timer +/** @ingroup xran * * @param void * @@ -287,965 +135,711 @@ unsigned long timer_get_ticks(void) * **/ //------------------------------------------------------------------------------------------- -int timer_set_tsc_freq_from_clock(void) +int32_t +app_timer_set_tsc_freq_from_clock(void) { -#define NS_PER_SEC 1E9 struct timespec sleeptime = {.tv_nsec = 5E8 }; /* 1/2 second */ struct timespec t_start, t_end; uint64_t tsc_resolution_hz = 0; - if (clock_gettime(CLOCK_MONOTONIC_RAW, &t_start) == 0) - { - unsigned long ns, end, start = timer_get_ticks(); + if (clock_gettime(CLOCK_MONOTONIC_RAW, &t_start) == 0) { + unsigned long ns, end, start = app_timer_get_ticks(); nanosleep(&sleeptime,NULL); clock_gettime(CLOCK_MONOTONIC_RAW, &t_end); - end = timer_get_ticks(); + end = app_timer_get_ticks(); ns = ((t_end.tv_sec - t_start.tv_sec) * NS_PER_SEC); ns += (t_end.tv_nsec - t_start.tv_nsec); double secs = (double)ns/NS_PER_SEC; tsc_resolution_hz = (unsigned long)((end - start)/secs); - tick_per_usec = (tsc_resolution_hz / 1000000); + ticks_per_usec = (tsc_resolution_hz / 1000000); printf("System clock (rdtsc) resolution %lu [Hz]\n", tsc_resolution_hz); - printf("Ticks per us %lu\n", tick_per_usec); + printf("Ticks per us %lu\n", ticks_per_usec); return 0; } return -1; } -int physide_dl_tti_call_back(void * param) +void +app_version_print(void) { - uint64_t t1 = MLogTick(); - rte_pause(); - MLogTask(PID_GNB_PROC_TIMING, t1, MLogTick()); - return 0; -} + char sysversion[100]; + char *compilation_date = __DATE__; + char *compilation_time = __TIME__; + char compiler[100]; -int physide_ul_half_slot_call_back(void * param) -{ - uint64_t t1 = MLogTick(); - rte_pause(); - MLogTask(PID_GNB_PROC_TIMING, t1, MLogTick()); - return 0; + snprintf(sysversion, 99, "Version: %s", VERSIONX); + +#if defined(__clang__) + snprintf(compiler, 99, "family clang: %s", __clang_version__); +#elif defined(__ICC) || defined(__INTEL_COMPILER) + snprintf(compiler, 99, "family icc: version %d", __INTEL_COMPILER); +#elif defined(__INTEL_LLVM_COMPILER) + snprintf(compiler, 99, "family icx: version %d", __INTEL_LLVM_COMPILER); +#elif defined(__GNUC__) || defined(__GNUG__) + snprintf(compiler, 99, "family gcc: version %d.%d.%d", __GNUC__, __GNUC_MINOR__,__GNUC_PATCHLEVEL__); +#endif + + printf("\n\n"); + printf("===========================================================================================================\n"); + printf("SAMPLE-APP VERSION\n"); + printf("===========================================================================================================\n"); + + printf("%s\n", sysversion); + printf("build-date: %s\n", compilation_date); + printf("build-time: %s\n", compilation_time); + printf("build-with: %s\n", compiler); } -int physide_ul_full_slot_call_back(void * param) +static void +app_help(void) { - uint64_t t1 = MLogTick(); - rte_pause(); - MLogTask(PID_GNB_PROC_TIMING, t1, MLogTick()); - return 0; + char help_content[] = \ + "sample application\n\n"\ + "Usage: sample-app --usecasefile ./usecase_du.cfg --num_eth_vfs 12"\ + "--vf_addr_o_xu_a \"0000:51:01.0,0000:51:01.1,0000:51:01.2,0000:51:01.3\""\ + "--vf_addr_o_xu_b \"0000:51:01.4,0000:51:01.5,0000:51:01.6,0000:51:01.7\""\ + "--vf_addr_o_xu_c \"0000:51:02.0,0000:51:02.1,0000:51:02.2,0000:51:02.3\"\n\n"\ + "or sample-app --usecasefile ./usecase_du.cfg --num_eth_vfs 2"\ + "--vf_addr_o_xu_a \"0000:51:01.0,0000:51:01.1\""\ + "supports the following options:\n\n"\ + "-p | --num_eth_pfs 2 - default\n" + "-a | --vf_addr_o_xu_a " + "-b | --vf_addr_o_xu_b " + "-c | --vf_addr_o_xu_c " + "-d | --vf_addr_o_xu_d " + "-u | --usecasefile \n"\ + "-h | --help print usage\n"; + + printf("%s", help_content); } -int32_t init_xran(void) +/** + ******************************************************************************* + * + * @fn app_parse_args + * @brief is used to parse incoming app args + * + * @description + * The routine is parse input args and convert them into app startup params + * + * @references + * + * @ingroup xran_lib + * + ******************************************************************************/ +static int32_t +app_parse_cmdline_args(int argc, char ** argv, struct sample_app_params* params) { - BbuXranIoIfStruct *psBbuIo = xran_get_ctx(); - xran_status_t status; - int32_t nSectorIndex[XRAN_MAX_SECTOR_NR]; - int32_t nSectorNum; - int32_t i, j, k, z; - - void *ptr; - void *mb; - uint32_t *u32dptr; - uint16_t *u16dptr; - uint8_t *u8dptr; - - SWXRANInterfaceTypeEnum eInterfaceType; - - XranLibConfigStruct *ptrLibConfig; - - struct xran_buffer_list *pFthTxBuffer[XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN]; - struct xran_buffer_list *pFthTxPrbMapBuffer[XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN]; - struct xran_buffer_list *pFthRxBuffer[XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN]; - struct xran_buffer_list *pFthRxPrbMapBuffer[XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN]; - struct xran_buffer_list *pFthRxRachBuffer[XRAN_MAX_SECTOR_NR][XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN]; + int32_t c = 0; + int32_t vf_cnt = 0; + int32_t cnt = 0; + size_t optlen = 0; + char *saveptr = NULL; + char *token = NULL; + int32_t port = 8; + + static struct option long_options[] = { + {"cfgfile", required_argument, 0, 'z'}, + {"usecasefile", required_argument, 0, 'u'}, + {"num_eth_vfs", required_argument, 0, 'p'}, + {"vf_addr_o_xu_a", required_argument, 0, 'a'}, + {"vf_addr_o_xu_b", required_argument, 0, 'b'}, + {"vf_addr_o_xu_c", required_argument, 0, 'c'}, + {"vf_addr_o_xu_d", required_argument, 0, 'd'}, + {"vf_addr_o_xu_e", required_argument, 0, 'e'}, + {"vf_addr_o_xu_f", required_argument, 0, 'F'}, + {"vf_addr_o_xu_g", required_argument, 0, 'g'}, + {"vf_addr_o_xu_h", required_argument, 0, 'H'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + memset(params, 0, sizeof (*params)); + + while (1) { + //int this_option_optind = optind ? optind : 1; + int option_index = 0; + + c = getopt_long(argc, argv, "a:b:c:d:e:f:F:g:h:H:p:u:v", long_options, &option_index); + + if (c == -1) + break; - for (nSectorNum = 0; nSectorNum < XRAN_MAX_SECTOR_NR; nSectorNum++) - { - nSectorIndex[nSectorNum] = nSectorNum; - } + cnt += 1; + port = 8; - nSectorNum = numCCPorts; - printf ("XRAN front haul xran_mm_init \n"); - status = xran_mm_init (xranHandle, (uint64_t) SW_FPGA_FH_TOTAL_BUFFER_LEN, SW_FPGA_SEGMENT_BUFFER_LEN); - if (status != XRAN_STATUS_SUCCESS) - { - printf ("Failed at XRAN front haul xran_mm_init \n"); - exit(-1); + switch (c) { + case 'f': + params->cfg_file = optarg; + optlen = strlen(optarg) + 1; + printf("%s:%d: %s [len %ld]\n",__FUNCTION__, __LINE__, params->cfg_file, optlen); + break; + case 'p': + params->num_vfs = atoi(optarg); + printf("%s:%d: %d\n",__FUNCTION__, __LINE__, params->num_vfs); + break; + case 'u': + params->usecase_file = optarg; + optlen = strlen(optarg) + 1; + printf("%s:%d: %s [len %ld]\n",__FUNCTION__, __LINE__, params->usecase_file, optlen); + break; + case 'a': + port -= 1; + case 'b': + port -= 1; + case 'c': + port -= 1; + case 'd': + port -= 1; + case 'e': + port -= 1; + case 'F': + port -= 1; + case 'g': + port -= 1; + case 'H': + port -= 1; + vf_cnt = 0; + optlen = strlen(optarg) + 1; + printf("%s:%d: port %d %s [len %ld]\n",__FUNCTION__, __LINE__, port, optarg, optlen); + token = strtok_r(optarg, ",", &saveptr); + while (token != NULL) { + optlen = strlen(token) + 1; + snprintf(¶ms->vf_pcie_addr[port][vf_cnt][0], optlen, "%s", token); + printf("%s:%d: port %d %s [len %ld]\n",__FUNCTION__, __LINE__, port, ¶ms->vf_pcie_addr[port][vf_cnt][0], optlen); + token = strtok_r(NULL, ",", &saveptr); + vf_cnt +=1; + } + break; + case 'h': + app_help(); + exit(0); + } } + return cnt; +} - psBbuIo->nInstanceNum = numCCPorts; - - for (k = 0; k < XRAN_PORTS_NUM; k++) { - status = xran_sector_get_instances (xranHandle, psBbuIo->nInstanceNum,&psBbuIo->nInstanceHandle[k][0]); - if (status != XRAN_STATUS_SUCCESS) - { - printf ("get sector instance failed %d for XRAN nInstanceNum %d\n",k, psBbuIo->nInstanceNum); - exit(-1); - } - for (i = 0; i < psBbuIo->nInstanceNum; i++){ - printf("%s [%d]: CC %d handle %p\n", __FUNCTION__, k, i, psBbuIo->nInstanceHandle[0][i]); +int32_t +app_apply_slot_cfg(RuntimeConfig *config) +{ + int32_t ret = 0; + int32_t slot_idx = 0; + int32_t cc_idx = 0; + int32_t ant_idx = 0; + int32_t section_idx = 0; + int32_t direction = 0; + + int32_t enable = 0; + + for (slot_idx = 0; slot_idx < config->numSlots; slot_idx++) { + for (direction = 0; direction < XRAN_DIR_MAX; direction++) { + for (cc_idx = 0; cc_idx < config->numCC; cc_idx++) { + for (ant_idx = 0; ant_idx < ((direction == XRAN_DIR_UL) ? config->numUlAxc :config->numAxc); ant_idx++) { + for (section_idx = 0; section_idx < config->p_SlotPrbMap[direction][slot_idx]->nPrbElm && section_idx < XRAN_MAX_SECTIONS_PER_SLOT; section_idx++) { + if (config->SlotPrbCCmask[direction][slot_idx][section_idx] & (1L << cc_idx)) { + if (config->SlotPrbAntCMask[direction][slot_idx][section_idx] & (1L << ant_idx)) { + struct xran_prb_map *pRbMap = config->p_RunSlotPrbMap[direction][slot_idx][cc_idx][ant_idx]; + pRbMap->dir = direction; + pRbMap->xran_port = config->o_xu_id; + pRbMap->band_id = 0; + pRbMap->cc_id = cc_idx; + pRbMap->ru_port_id = ant_idx; + pRbMap->tti_id = slot_idx; + pRbMap->start_sym_id = 0; + if (pRbMap->nPrbElm < XRAN_MAX_SECTIONS_PER_SLOT && section_idx < XRAN_MAX_SECTIONS_PER_SLOT) { + struct xran_prb_elm *pMapElmRun = &pRbMap->prbMap[pRbMap->nPrbElm]; + struct xran_prb_elm *pMapElmCfg = &config->p_SlotPrbMap[direction][slot_idx]->prbMap[section_idx]; + memcpy(pMapElmRun, pMapElmCfg, sizeof(struct xran_prb_elm)); + } else { + rte_panic("Incorrect slot cfg\n"); + } + pRbMap->nPrbElm++; + enable = 1; } } - - printf("Sucess xran_mm_init \n"); - gpXranLibConfig = (XranLibConfigStruct*)malloc(sizeof(XranLibConfigStruct)); - ptrLibConfig = gpXranLibConfig; - if (ptrLibConfig) - { - #if 0 - ptrLibConfig->nDriverCoreId = psBbuIo->nDriverCoreId; - ptrLibConfig->pFecInstanceHandles = &(psBbuIo->nInstanceHandle[FPGA_FEC][0]); - ptrLibConfig->pFthInstanceHandles = &(psBbuIo->nInstanceHandle[FPGA_FRONTHAUL][0]); - ptrLibConfig->nTimingAdvance = psFPGAInitPara->nTimeAdvance; - ptrLibConfig->nFhConfig = psFPGAInitPara->nEthPorts; - ptrLibConfig->nFhBufIntFlag = 0; //need init fronthaul buffer, then set to 1. - ptrLibConfig->nNrofSfInFrame = NUM_OF_SUBFRAME_PER_FRAME; - ptrLibConfig->nNrOfSlotInSf = pConfigParams->nNumOfSlotPerSubframe; - if (pConfigParams->nNumerology < 3) - { - ptrLibConfig->nSectorNum = psFPGAInitPara->nSecNum; +} + } + } } - #endif } - else - { - printf ("could not allocate ptrLibConfig in init_xran\n"); + + config->RunSlotPrbMapEnabled = enable; + printf("[%d]config->RunSlotPrbMapEnabled %d\n",config->o_xu_id, config->RunSlotPrbMapEnabled); + + return ret; +} + +int32_t +app_parse_all_cfgs(struct sample_app_params* p_args, UsecaseConfig* p_use_cfg, RuntimeConfig* p_o_xu_cfg) +{ + int32_t ret = 0; + int32_t vf_num = 0; + int32_t o_xu_id = 0; + char filename[512]; + char bbu_filename[512]; + char *dir; + size_t len; + + if (p_use_cfg) { + memset(p_use_cfg, 0, sizeof(UsecaseConfig)); + } else { + printf("p_use_cfg error.\n"); exit(-1); } - printf("nSectorNum %d\n", nSectorNum); - - /* Init Memory */ - for(i = 0; inInstanceHandle[0][i], &psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType], - XRAN_N_FE_BUF_LEN*XRAN_MAX_ANTENNA_NR*XRAN_NUM_OF_SYMBOL_PER_SLOT, nSW_ToFpga_FTH_TxBufferLen); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_init , status %d\n", status); - iAssert(status == XRAN_STATUS_SUCCESS); - } - for(j = 0; j < XRAN_N_FE_BUF_LEN; j++) - { - for(z = 0; z < XRAN_MAX_ANTENNA_NR; z++){ - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].bValid = 0; - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].nSegGenerated = -1; - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].nSegToBeGen = -1; - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].nSegTransferred = 0; - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].sBufferList.nNumBuffers = XRAN_NUM_OF_SYMBOL_PER_SLOT; - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers = &psBbuIo->sFrontHaulTxBuffers[j][i][z][0]; - - for(k = 0; k < XRAN_NUM_OF_SYMBOL_PER_SLOT; k++) - { - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].nElementLenInBytes = nSW_ToFpga_FTH_TxBufferLen; // 14 symbols 3200bytes/symbol - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].nNumberOfElements = 1; - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].nOffsetInBytes = 0; - status = xran_bm_allocate_buffer(psBbuIo->nInstanceHandle[0][i], psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType],&ptr, &mb); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_allocate_buffer , status %d\n",status); - iAssert(status == XRAN_STATUS_SUCCESS); - } - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].pData = (uint8_t *)ptr; - psBbuIo->sFrontHaulTxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].pCtrl = (void *)mb; - - if(ptr){ - u32dptr = (uint32_t*)(ptr); - uint8_t *ptr_temp = (uint8_t *)ptr; - memset(u32dptr, 0xCC, nSW_ToFpga_FTH_TxBufferLen); - ptr_temp[0] = j; // TTI - ptr_temp[1] = i; // Sec - ptr_temp[2] = z; // Ant - ptr_temp[3] = k; // sym - } - } + p_use_cfg->dlCpProcBurst = 1; + + if (p_args) { + if (p_args->usecase_file) { /* use case for multiple O-RUs */ + printf("p_args->usecase_file (%s)\n", p_args->usecase_file); + len = strlen(p_args->usecase_file) + 1; + if (len > 511){ + printf("app_parse_all_cfgs: Name of p_args->usecase_file, %s is too long. Maximum is 511 characters!!\n", p_args->usecase_file); + return -1; + } else { + strncpy(filename, p_args->usecase_file, RTE_MIN (512,len)); + } + if (parseUsecaseFile(filename, p_use_cfg) != 0) { + printf("Use case config file error.\n"); + return -1; + } + if (p_use_cfg->oXuNum > XRAN_PORTS_NUM) { + printf("Use case config file error.\n"); + return -1; } - } - - /* C-plane DL */ - eInterfaceType = XRANFTHTX_PRB_MAP_OUT; - printf("nSectorIndex[%d] = %d\n",i, nSectorIndex[i]); - status = xran_bm_init(psBbuIo->nInstanceHandle[0][i], &psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType], - XRAN_N_FE_BUF_LEN*XRAN_MAX_ANTENNA_NR*XRAN_NUM_OF_SYMBOL_PER_SLOT, sizeof(struct xran_prb_map)); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_init , status %d\n", status); - iAssert(status == XRAN_STATUS_SUCCESS); - } - for(j = 0; j < XRAN_N_FE_BUF_LEN; j++) - { - for(z = 0; z < XRAN_MAX_ANTENNA_NR; z++){ - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].bValid = 0; - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].nSegGenerated = -1; - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].nSegToBeGen = -1; - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].nSegTransferred = 0; - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.nNumBuffers = XRAN_NUM_OF_SYMBOL_PER_SLOT; - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers = &psBbuIo->sFrontHaulTxPrbMapBuffers[j][i][z]; - { - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->nElementLenInBytes = sizeof(struct xran_prb_map); - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->nNumberOfElements = 1; - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->nOffsetInBytes = 0; - status = xran_bm_allocate_buffer(psBbuIo->nInstanceHandle[0][i], psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType],&ptr, &mb); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_allocate_buffer , status %d\n",status); - iAssert(status == XRAN_STATUS_SUCCESS); - } - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->pData = (uint8_t *)ptr; - psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->pCtrl = (void *)mb; - - if(ptr){ - u32dptr = (uint32_t*)(ptr); - uint8_t *ptr_temp = (uint8_t *)ptr; - memset(u32dptr, 0xCC, sizeof(struct xran_prb_map)); - ptr_temp[0] = j; // TTI - ptr_temp[1] = i; // Sec - ptr_temp[2] = z; // Ant - ptr_temp[3] = k; // sym - } + if (p_o_xu_cfg) { + int32_t i; + RuntimeConfig* p_o_xu_cfg_loc = p_o_xu_cfg; + for (i = 0; i < p_use_cfg->oXuNum; i++) { + config_init(p_o_xu_cfg_loc); + p_o_xu_cfg_loc++; } + } else { + printf("p_o_xu_cfg error.\n"); + exit(-1); } - } - } - - for(i = 0; inInstanceHandle[0][i], &psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType], XRAN_N_FE_BUF_LEN*XRAN_MAX_ANTENNA_NR*XRAN_NUM_OF_SYMBOL_PER_SLOT, nSW_ToFpga_FTH_TxBufferLen); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_init, status %d\n", status); - iAssert(status == XRAN_STATUS_SUCCESS); - } - - for(j = 0;j < XRAN_N_FE_BUF_LEN; j++) - { - for(z = 0; z < XRAN_MAX_ANTENNA_NR; z++){ - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].bValid = 0; - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].nSegGenerated = -1; - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].nSegToBeGen = -1; - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].nSegTransferred = 0; - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].sBufferList.nNumBuffers = XRAN_NUM_OF_SYMBOL_PER_SLOT; - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers = &psBbuIo->sFrontHaulRxBuffers[j][i][z][0]; - for(k = 0; k< XRAN_NUM_OF_SYMBOL_PER_SLOT; k++) - { - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].nElementLenInBytes = nFpgaToSW_FTH_RxBufferLen; // 1 symbols 3200bytes - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].nNumberOfElements = 1; - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].nOffsetInBytes = 0; - status = xran_bm_allocate_buffer(psBbuIo->nInstanceHandle[0][i],psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType],&ptr, &mb); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_allocate_buffer , status %d\n",status); - iAssert(status == XRAN_STATUS_SUCCESS); - } - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].pData = (uint8_t *)ptr; - psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].pCtrl = (void *) mb; - if(ptr){ - u32dptr = (uint32_t*)(ptr); - uint8_t *ptr_temp = (uint8_t *)ptr; - memset(u32dptr, 0xCC, nFpgaToSW_FTH_RxBufferLen); - ptr_temp[0] = j; // TTI - ptr_temp[1] = i; // Sec - ptr_temp[2] = z; // Ant - ptr_temp[3] = k; // sym - } + /* use cmdline pcie address */ + for (o_xu_id = 0; o_xu_id < p_use_cfg->oXuNum && o_xu_id < XRAN_PORTS_NUM; o_xu_id++) { + for (vf_num = 0; vf_num < XRAN_VF_MAX && p_args->num_vfs ; vf_num++) { + strncpy(&p_use_cfg->o_xu_pcie_bus_addr[o_xu_id][vf_num][0], &p_args->vf_pcie_addr[o_xu_id][vf_num][0], RTE_MIN (512,strlen(&p_args->vf_pcie_addr[o_xu_id][vf_num][0]))); } } - } - /* C-plane */ - eInterfaceType = XRANFTHRX_PRB_MAP_IN; - status = xran_bm_init(psBbuIo->nInstanceHandle[0][i], &psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType], - XRAN_N_FE_BUF_LEN*XRAN_MAX_ANTENNA_NR*XRAN_NUM_OF_SYMBOL_PER_SLOT, sizeof(struct xran_prb_map)); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_init, status %d\n", status); - iAssert(status == XRAN_STATUS_SUCCESS); - } - for(j = 0;j < XRAN_N_FE_BUF_LEN; j++) - { - for(z = 0; z < XRAN_MAX_ANTENNA_NR; z++){ - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].bValid = 0; - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].nSegGenerated = -1; - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].nSegToBeGen = -1; - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].nSegTransferred = 0; - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.nNumBuffers = XRAN_NUM_OF_SYMBOL_PER_SLOT; - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers = &psBbuIo->sFrontHaulRxPrbMapBuffers[j][i][z]; - { - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->nElementLenInBytes = sizeof(struct xran_prb_map); - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->nNumberOfElements = 1; - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->nOffsetInBytes = 0; - status = xran_bm_allocate_buffer(psBbuIo->nInstanceHandle[0][i],psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType],&ptr, &mb); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_allocate_buffer , status %d\n",status); - iAssert(status == XRAN_STATUS_SUCCESS); - } - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->pData = (uint8_t *)ptr; - psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].sBufferList.pBuffers->pCtrl = (void *)mb; - if(ptr){ - u32dptr = (uint32_t*)(ptr); - uint8_t *ptr_temp = (uint8_t *)ptr; - memset(u32dptr, 0xCC, sizeof(struct xran_prb_map)); - ptr_temp[0] = j; // TTI - ptr_temp[1] = i; // Sec - ptr_temp[2] = z; // Ant - ptr_temp[3] = k; // sym - } + dir = dirname(p_args->usecase_file); + if(strlen(p_use_cfg->o_xu_bbu_cfg_file)){ + memset(bbu_filename, 0, sizeof(bbu_filename)); + printf("dir (%s)\n",dir); + len = strlen(dir) + 1; + if (len > 511){ + printf("app_parse_all_cfgs: Name of directory, %s, xu_id = %d is too long. Maximum is 511 characters!!\n", dir, o_xu_id); + return -1; + } else { + strncpy(bbu_filename, dir, RTE_MIN(512,len)); } + strncat(bbu_filename, "/", 1); + len +=1; + len = (sizeof(bbu_filename)) - len; + if (len > strlen(p_use_cfg->o_xu_bbu_cfg_file)) { + strncat(bbu_filename, p_use_cfg->o_xu_bbu_cfg_file, RTE_MIN (len, strlen(p_use_cfg->o_xu_bbu_cfg_file))); + } else { + printf("File name error\n"); + return -1; + } + strncpy(p_use_cfg->o_xu_bbu_cfg_file, bbu_filename, RTE_MIN (512, strlen(bbu_filename))); + printf("bbu_cfg_file (%s)\n",p_use_cfg->o_xu_bbu_cfg_file); +#ifdef FWK_ENABLED + p_use_cfg->bbu_offload = 1; +#else + p_use_cfg->bbu_offload = 0; +#endif + } else { + printf("bbu_cfg_file is not provided\n"); + p_use_cfg->bbu_offload = 0; } - } - } - // add prach rx buffer - for(i = 0; inInstanceHandle[0][i],&psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType],XRAN_N_FE_BUF_LEN*XRAN_MAX_ANTENNA_NR*XRAN_NUM_OF_SYMBOL_PER_SLOT, FPGA_TO_SW_PRACH_RX_BUFFER_LEN); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_init, status %d\n", status); - iAssert(status == XRAN_STATUS_SUCCESS); - } - for(j = 0;j < XRAN_N_FE_BUF_LEN; j++) - { - for(z = 0; z < XRAN_MAX_ANTENNA_NR; z++){ - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].bValid = 0; - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].nSegGenerated = -1; - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].nSegToBeGen = -1; - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].nSegTransferred = 0; - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].sBufferList.nNumBuffers = XRAN_MAX_ANTENNA_NR; // ant number. - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers = &psBbuIo->sFHPrachRxBuffers[j][i][z][0]; - for(k = 0; k< XRAN_NUM_OF_SYMBOL_PER_SLOT; k++) - { - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].nElementLenInBytes = FPGA_TO_SW_PRACH_RX_BUFFER_LEN; - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].nNumberOfElements = 1; - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].nOffsetInBytes = 0; - status = xran_bm_allocate_buffer(psBbuIo->nInstanceHandle[0][i],psBbuIo->nBufPoolIndex[nSectorIndex[i]][eInterfaceType],&ptr, &mb); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_bm_allocate_buffer, status %d\n",status); - iAssert(status == XRAN_STATUS_SUCCESS); + for (o_xu_id = 0; o_xu_id < p_use_cfg->oXuNum && o_xu_id < XRAN_PORTS_NUM; o_xu_id++) { + memset(filename, 0, sizeof(filename)); + printf("dir (%s)\n",dir); + len = strlen(dir) + 1; + if (len > 511){ + printf("app_parse_all_cfgs: Name of directory, %s, xu_id = %d is too long. Maximum is 511 characters!!\n", dir, o_xu_id); + return -1; + } else { + strncpy(filename, dir, RTE_MIN (512,len)); + } + strncat(filename, "/", 1); + len +=1; + len = (sizeof(filename)) - len; + + if (len > strlen(p_use_cfg->o_xu_cfg_file[o_xu_id])) { + strncat(filename, p_use_cfg->o_xu_cfg_file[o_xu_id], RTE_MIN (len, strlen(p_use_cfg->o_xu_cfg_file[o_xu_id]))); + } else { + printf("File name error\n"); + return -1; + } + printf("cfg_file (%s)\n",filename); + printf("\n=================== O-XU %d===================\n", o_xu_id); + if (parseConfigFile(filename, p_o_xu_cfg) != 0) { + printf("Configuration file error\n"); + return -1; + } + p_o_xu_cfg->o_xu_id = o_xu_id; + config_init2(p_o_xu_cfg); + if (p_o_xu_cfg->SlotNum_fileEnabled) { + if (parseSlotConfigFile(dir, p_o_xu_cfg) != 0) { + printf("parseSlotConfigFiles\n"); + return -1; } - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].pData = (uint8_t *)ptr; - psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].sBufferList.pBuffers[k].pCtrl = (void *)mb; - if(ptr){ - u32dptr = (uint32_t*)(ptr); - memset(u32dptr, 0xCC, FPGA_TO_SW_PRACH_RX_BUFFER_LEN); + if (app_apply_slot_cfg(p_o_xu_cfg)!= 0) { + printf("app_apply_slot_cfg\n"); + return -1; } } - } - } - } - for(i=0; isFrontHaulTxBbuIoBufCtrl[j][i][z].sBufferList); - pFthTxPrbMapBuffer[i][z][j] = &(psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[j][i][z].sBufferList); - pFthRxBuffer[i][z][j] = &(psBbuIo->sFrontHaulRxBbuIoBufCtrl[j][i][z].sBufferList); - pFthRxPrbMapBuffer[i][z][j] = &(psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[j][i][z].sBufferList); - pFthRxRachBuffer[i][z][j] = &(psBbuIo->sFHPrachRxBbuIoBufCtrl[j][i][z].sBufferList); + p_o_xu_cfg++; } - } + } else { + printf("p_args error\n"); + app_help(); + exit(-1); } - - if(NULL != psBbuIo->nInstanceHandle[0]) - { - for (i = 0; inInstanceHandle[0][i], - pFthTxBuffer[i], - pFthTxPrbMapBuffer[i], - pFthRxBuffer[i], - pFthRxPrbMapBuffer[i], - xran_fh_rx_callback, &pFthRxBuffer[i][0]); - } - - // add prach callback here - for (i = 0; inInstanceHandle[0][i], pFthRxRachBuffer[i], - xran_fh_rx_prach_callback,&pFthRxRachBuffer[i][0]); - } - ptrLibConfig->nFhBufIntFlag = 1; + } else { + printf("p_args error\n"); + exit(-1); } - return status; + return ret; } -int init_xran_iq_content(void) +int32_t +app_setup_o_xu_buffers(UsecaseConfig* p_use_cfg, RuntimeConfig* p_o_xu_cfg, struct xran_fh_init* p_xran_fh_init) { - BbuXranIoIfStruct *psBbuIo = xran_get_ctx(); - xran_status_t status; - int32_t nSectorIndex[XRAN_MAX_SECTOR_NR]; - int32_t nSectorNum; - int32_t cc_id, ant_id, sym_id, tti; - int32_t flowId; - - uint8_t frame_id = 0; - uint8_t subframe_id = 0; - uint8_t slot_id = 0; - uint8_t sym = 0; - - void *ptr; - uint32_t *u32dptr; - uint16_t *u16dptr; - uint8_t *u8dptr; - - char *pos = NULL; - struct xran_prb_map *pRbMap = NULL; - - for (nSectorNum = 0; nSectorNum < XRAN_MAX_SECTOR_NR; nSectorNum++) - { - nSectorIndex[nSectorNum] = nSectorNum; - } - nSectorNum = numCCPorts; - printf ("init_xran_iq_content\n"); + int32_t ret = 0; + int32_t i = 0; + int32_t j = 0; + char filename[256]; + struct o_xu_buffers *p_iq = NULL; - /* Init Memory */ - for(cc_id = 0; cc_id sFrontHaulTxBbuIoBufCtrl[tti][cc_id][ant_id].sBufferList.pBuffers[sym_id].pData; - - if(ptr && pos){ - u32dptr = (uint32_t*)(ptr); - rte_memcpy(u32dptr, pos, pXranConf->nDLRBs*N_SC_PER_PRB*4); -#ifdef DEBUG_XRAN_BUFFERS - uint8_t *ptr_temp = (uint8_t *)ptr; - ptr_temp[0] = tti; // TTI - ptr_temp[1] = cc_id; // Sec - ptr_temp[2] = ant_id; // Ant - ptr_temp[3] = sym_id; // sym -#endif - } else { - exit(-1); - printf("ptr ==NULL\n"); - } + if (p_o_xu_cfg->p_buff) { + p_iq = p_o_xu_cfg->p_buff; + printf("IQ files size is %d slots\n", p_o_xu_cfg->numSlots); - /* c-plane DL */ - pRbMap = (struct xran_prb_map *) psBbuIo->sFrontHaulTxPrbMapBbuIoBufCtrl[tti][cc_id][ant_id].sBufferList.pBuffers->pData; - if(pRbMap){ - pRbMap->dir = XRAN_DIR_DL; - pRbMap->xran_port = 0; - pRbMap->band_id = 0; - pRbMap->cc_id = cc_id; - pRbMap->ru_port_id = ant_id; - pRbMap->tti_id = tti; - pRbMap->start_sym_id = 0; - pRbMap->nPrbElm = 1; - pRbMap->prbMap[0].nRBStart = 0; - pRbMap->prbMap[0].nRBSize = pXranConf->nDLRBs; - pRbMap->prbMap[0].nBeamIndex = 0; - pRbMap->prbMap[0].compMethod = XRAN_COMPMETHOD_NONE; - }else{ - printf("DL pRbMap ==NULL\n"); - exit(-1); - } + //printf("numSlots=%u\n", p_o_xu_cfg->numSlots); + //getchar(); + p_iq->iq_playback_buffer_size_dl = (p_o_xu_cfg->numSlots * N_SYM_PER_SLOT * N_SC_PER_PRB * + app_xran_get_num_rbs(p_o_xu_cfg->xranTech, p_o_xu_cfg->mu_number, + p_o_xu_cfg->nDLBandwidth, p_o_xu_cfg->nDLAbsFrePointA) *4L); - /* c-plane UL */ - pRbMap = (struct xran_prb_map *) psBbuIo->sFrontHaulRxPrbMapBbuIoBufCtrl[tti][cc_id][ant_id].sBufferList.pBuffers->pData; - if(pRbMap){ - pRbMap->dir = XRAN_DIR_UL; - pRbMap->xran_port = 0; - pRbMap->band_id = 0; - pRbMap->cc_id = cc_id; - pRbMap->ru_port_id = ant_id; - pRbMap->tti_id = tti; - pRbMap->start_sym_id = 0; - pRbMap->nPrbElm = 1; - pRbMap->prbMap[0].nRBStart = 0; - pRbMap->prbMap[0].nRBSize = pXranConf->nULRBs; - pRbMap->prbMap[0].nBeamIndex = 0; - pRbMap->prbMap[0].compMethod = XRAN_COMPMETHOD_NONE; - }else { - printf("UL: pRbMap ==NULL\n"); - exit(-1); - } + p_iq->iq_playback_buffer_size_ul = (p_o_xu_cfg->numSlots * N_SYM_PER_SLOT * N_SC_PER_PRB * + app_xran_get_num_rbs(p_o_xu_cfg->xranTech, p_o_xu_cfg->mu_number, + p_o_xu_cfg->nULBandwidth, p_o_xu_cfg->nULAbsFrePointA) *4L); - tx_play_buffer_position[flowId] += pXranConf->nDLRBs*N_SC_PER_PRB*4; - if(tx_play_buffer_position[flowId] >= tx_play_buffer_size[flowId]) - tx_play_buffer_position[flowId] = 0; - } else { - //printf("flowId %d\n", flowId); - } - } - } + /* 10 * [273*32*2*2] = 349440 bytes */ + p_iq->iq_bfw_buffer_size_dl = (p_o_xu_cfg->numSlots * N_SYM_PER_SLOT * p_o_xu_cfg->antElmTRx * + app_xran_get_num_rbs(p_o_xu_cfg->xranTech, p_o_xu_cfg->mu_number, + p_o_xu_cfg->nDLBandwidth, p_o_xu_cfg->nDLAbsFrePointA) *4L); - /* prach TX for RU only */ - if(startupConfiguration.appMode == APP_O_RU && startupConfiguration.enablePrach){ - for(ant_id = 0; ant_id < XRAN_MAX_ANTENNA_NR; ant_id++){ - for(sym_id = 0; sym_id < 1; sym_id++) { - flowId = XRAN_MAX_ANTENNA_NR*cc_id + ant_id; - - if(p_tx_prach_play_buffer[flowId]){ - /* (0-79 slots) 10ms of IQs */ - pos = ((char*)p_tx_prach_play_buffer[flowId]); - - ptr = psBbuIo->sFHPrachRxBbuIoBufCtrl[tti][cc_id][ant_id].sBufferList.pBuffers[sym_id].pData; - - if(ptr && pos){ - u32dptr = (uint32_t*)(ptr); - rte_memcpy(u32dptr, pos, PRACH_PLAYBACK_BUFFER_BYTES); -#ifdef DEBUG_XRAN_BUFFERS - uint8_t *ptr_temp = (uint8_t *)ptr; - ptr_temp[0] = tti; // TTI - ptr_temp[1] = cc_id; // Sec - ptr_temp[2] = ant_id; // Ant - ptr_temp[3] = sym_id; // sym -#endif - } else { - exit(-1); - printf("ptr ==NULL\n"); - } - } else { - //printf("flowId %d\n", flowId); - } - } - } - } - } - } + /* 10 * [273*32*2*2] = 349440 bytes */ + p_iq->iq_bfw_buffer_size_ul = (p_o_xu_cfg->numSlots * N_SYM_PER_SLOT * p_o_xu_cfg->antElmTRx * + app_xran_get_num_rbs(p_o_xu_cfg->xranTech, p_o_xu_cfg->mu_number, + p_o_xu_cfg->nULBandwidth, p_o_xu_cfg->nULAbsFrePointA) *4L); - return 0; -} + /* 10 * [1*273*2*2] = 349440 bytes */ + p_iq->iq_srs_buffer_size_ul = (p_o_xu_cfg->numSlots * N_SYM_PER_SLOT * N_SC_PER_PRB * + app_xran_get_num_rbs(p_o_xu_cfg->xranTech, p_o_xu_cfg->mu_number, + p_o_xu_cfg->nULBandwidth, p_o_xu_cfg->nULAbsFrePointA)*4L); -void stop_xran(void) -{ - xran_status_t status = 0; - SWXRANInterfaceTypeEnum eInterfaceType; + p_iq->numSlots = p_o_xu_cfg->numSlots; - free(gpXranLibConfig); - gpXranLibConfig = NULL; + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { + p_iq->p_tx_play_buffer[i] = (int16_t*)malloc(p_iq->iq_playback_buffer_size_dl); + p_iq->tx_play_buffer_size[i] = (int32_t)p_iq->iq_playback_buffer_size_dl; - status += xran_mm_destroy(xranHandle)*2; + if (p_iq->p_tx_play_buffer[i] == NULL) + exit(-1); - if(XRAN_STATUS_SUCCESS != status) - { - printf("Failed at xran_mm_destroy, status %d\n",status); - iAssert(status == XRAN_STATUS_SUCCESS); - } -} -int get_xran_iq_content(void) -{ - BbuXranIoIfStruct *psBbuIo = xran_get_ctx(); - xran_status_t status; - int32_t nSectorIndex[XRAN_MAX_SECTOR_NR]; - int32_t nSectorNum; - int32_t cc_id, ant_id, sym_id, tti; - int32_t flowId; - - uint8_t frame_id = 0; - uint8_t subframe_id = 0; - uint8_t slot_id = 0; - uint8_t sym = 0; - - void *ptr; - uint32_t *u32dptr; - uint16_t *u16dptr; - uint8_t *u8dptr; - - char *pos = NULL; - - for (nSectorNum = 0; nSectorNum < XRAN_MAX_SECTOR_NR; nSectorNum++) - { - nSectorIndex[nSectorNum] = nSectorNum; + p_iq->tx_play_buffer_size[i] = sys_load_file_to_buff(p_o_xu_cfg->ant_file[i], + "DL IFFT IN IQ Samples in binary format", + (uint8_t*)p_iq->p_tx_play_buffer[i], + p_iq->tx_play_buffer_size[i], + 1); } - nSectorNum = numCCPorts; - printf ("get_xran_iq_content\n"); - /* Init Memory */ - for(cc_id = 0; cc_id sFrontHaulRxBbuIoBufCtrl[tti][cc_id][ant_id].sBufferList.pBuffers[sym_id].pData; - if(ptr){ - u32dptr = (uint32_t*)(ptr); - rte_memcpy(pos, u32dptr, pXranConf->nULRBs*N_SC_PER_PRB*4); -#ifdef DEBUG_XRAN_BUFFERS - if (pos[0] != tti|| - pos[1] != cc_id || - pos[2] != ant_id || - pos[3] != sym_id){ - printf("[flowId %d] %d %d %d %d\n", flowId, pos[0], pos[1], pos[2], pos[3]); - } -#endif - }else - printf("ptr ==NULL\n"); + if (p_o_xu_cfg->appMode == APP_O_DU && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { - rx_log_buffer_position[flowId] += pXranConf->nULRBs*N_SC_PER_PRB*4; + p_iq->p_tx_dl_bfw_buffer[i] = (int16_t*)malloc(p_iq->iq_bfw_buffer_size_dl); + p_iq->tx_dl_bfw_buffer_size[i] = (int32_t)p_iq->iq_bfw_buffer_size_dl; - if(rx_log_buffer_position[flowId] >= rx_log_buffer_size[flowId]) - rx_log_buffer_position[flowId] = 0; - } else { - //printf("flowId %d\n", flowId); - } - } + if (p_iq->p_tx_dl_bfw_buffer[i] == NULL) + exit(-1); - /* prach RX for O-DU only */ - if(startupConfiguration.appMode == APP_O_DU){ - flowId = XRAN_MAX_ANTENNA_NR * cc_id + ant_id; - sym_id = 0; - - if(p_prach_log_buffer[flowId]){ - /* (0-79 slots) 10ms of IQs */ - pos = ((char*)p_prach_log_buffer[flowId]) + prach_log_buffer_position[flowId]; - ptr = psBbuIo->sFHPrachRxBbuIoBufCtrl[tti][cc_id][ant_id].sBufferList.pBuffers[sym_id].pData; - if(ptr){ - u32dptr = (uint32_t*)(ptr); - rte_memcpy(pos, u32dptr, PRACH_PLAYBACK_BUFFER_BYTES); -#ifdef DEBUG_XRAN_BUFFERS - if (pos[0] != tti|| - pos[1] != cc_id || - pos[2] != ant_id || - pos[3] != sym_id){ - printf("[flowId %d] %d %d %d %d\n", flowId, pos[0], pos[1], pos[2], pos[3]); - } -#endif - }else - printf("ptr ==NULL\n"); + p_iq->tx_dl_bfw_buffer_size[i] = sys_load_file_to_buff(p_o_xu_cfg->dl_bfw_file[i], + "DL BF weights IQ Samples in binary format", + (uint8_t*) p_iq->p_tx_dl_bfw_buffer[i], + p_iq->tx_dl_bfw_buffer_size[i], + 1); + } + } - prach_log_buffer_position[flowId] += PRACH_PLAYBACK_BUFFER_BYTES; + if (p_o_xu_cfg->appMode == APP_O_DU && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { - if(prach_log_buffer_position[flowId] >= prach_log_buffer_size[flowId]) - prach_log_buffer_position[flowId] = 0; - } else { - //printf("flowId %d\n", flowId); - } - } + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { + p_iq->p_tx_ul_bfw_buffer[i] = (int16_t*)malloc(p_iq->iq_bfw_buffer_size_ul); + p_iq->tx_ul_bfw_buffer_size[i] = (int32_t)p_iq->iq_bfw_buffer_size_ul; - } + if (p_iq->p_tx_ul_bfw_buffer[i] == NULL) + exit(-1); + + p_iq->tx_ul_bfw_buffer_size[i] = sys_load_file_to_buff(p_o_xu_cfg->ul_bfw_file[i], + "UL BF weights IQ Samples in binary format", + (uint8_t*) p_iq->p_tx_ul_bfw_buffer[i], + p_iq->tx_ul_bfw_buffer_size[i], + 1); } } - return 0; -} + if (p_o_xu_cfg->appMode == APP_O_RU && p_o_xu_cfg->enablePrach) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { + p_iq->p_tx_prach_play_buffer[i] = (int16_t*)malloc(PRACH_PLAYBACK_BUFFER_BYTES); + p_iq->tx_prach_play_buffer_size[i] = (int32_t)PRACH_PLAYBACK_BUFFER_BYTES; -void version_print(void) -{ - char sysversion[100]; - char *compilation_date = __DATE__; - char *compilation_time = __TIME__; + if (p_iq->p_tx_prach_play_buffer[i] == NULL) + exit(-1); - uint32_t nLen; - uint32_t i; + memset(p_iq->p_tx_prach_play_buffer[i], 0, PRACH_PLAYBACK_BUFFER_BYTES); - snprintf(sysversion, 99, "Version: %s", VERSIONX); - nLen = strlen(sysversion); + p_iq->tx_prach_play_buffer_size[i] = sys_load_file_to_buff(p_o_xu_cfg->prach_file[i], + "PRACH IQ Samples in binary format", + (uint8_t*) p_iq->p_tx_prach_play_buffer[i], + p_iq->tx_prach_play_buffer_size[i], + 1); + p_iq->tx_prach_play_buffer_position[i] = 0; + } + } - printf("\n\n"); - printf("===========================================================================================================\n"); - printf("SAMPLE-APP VERSION\n"); - printf("===========================================================================================================\n"); + if (p_o_xu_cfg->appMode == APP_O_RU && p_o_xu_cfg->enableSrs) { + for(i = 0; + i < MAX_ANT_CARRIER_SUPPORTED_CAT_B && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->antElmTRx); + i++) { - printf("%s\n", sysversion); - printf("build-date: %s\n", compilation_date); - printf("build-time: %s\n", compilation_time); -} + p_iq->p_tx_srs_play_buffer[i] = (int16_t*)malloc(p_iq->iq_srs_buffer_size_ul); + p_iq->tx_srs_play_buffer_size[i] = (int32_t)p_iq->iq_srs_buffer_size_ul; -int main(int argc, char *argv[]) -{ - int i; - int j, len; - int lcore_id = 0; - char filename[64]; - uint32_t nCenterFreq; - int32_t xret = 0; - struct stat st = {0}; - uint32_t filenameLength = strlen(argv[1]); - char *pCheckName1 = NULL, *pCheckName2 = NULL; - enum xran_if_state xran_curr_if_state = XRAN_INIT; + if (p_iq->p_tx_srs_play_buffer[i] == NULL) + exit(-1); - if (argc == 3) - errx(2, "Need two argument - the PCI address of the network port"); - if (filenameLength >= 64) - { - printf("Config file name input is too long, exiting!\n"); - exit(-1); + memset(p_iq->p_tx_srs_play_buffer[i], 0, p_iq->iq_srs_buffer_size_ul); + p_iq->tx_srs_play_buffer_size[i] = sys_load_file_to_buff(p_o_xu_cfg->ul_srs_file[i], + "SRS IQ Samples in binary format", + (uint8_t*) p_iq->p_tx_srs_play_buffer[i], + p_iq->tx_srs_play_buffer_size[i], + 1); + + p_iq->tx_srs_play_buffer_position[i] = 0; + } } - version_print(); + /* log of ul */ + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { - //add for Klocworks - len = strlen(argv[1]) + 1; - if (len > (sizeof(filename) - 10)) - len = (sizeof(filename) - 10); - strncpy(filename, argv[1], (sizeof(filename) - 10)); - filename[len] = '\0'; + p_iq->p_rx_log_buffer[i] = (int16_t*)malloc(p_iq->iq_playback_buffer_size_ul); + p_iq->rx_log_buffer_size[i] = (int32_t)p_iq->iq_playback_buffer_size_ul; - pCheckName1 = strstr(filename, "config_file_o_du.dat"); - pCheckName2 = strstr(filename, "config_file_o_ru.dat"); - if ((pCheckName1 == NULL) && (pCheckName2 == NULL)) - { - printf("config file name %s is not valid!\n", filename); - exit(-1); + if (p_iq->p_rx_log_buffer[i] == NULL) + exit(-1); + + memset(p_iq->p_rx_log_buffer[i], 0, p_iq->rx_log_buffer_size[i]); } - if (xran_is_synchronized() != 0) - printf("Machine is not synchronized using PTP!\n"); - else - printf("Machine is synchronized using PTP!\n"); + /* log of prach */ + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { - memset(&startupConfiguration, 0, sizeof(RuntimeConfig)); + p_iq->p_prach_log_buffer[i] = (int16_t*)malloc(p_o_xu_cfg->numSlots*XRAN_NUM_OF_SYMBOL_PER_SLOT*PRACH_PLAYBACK_BUFFER_BYTES); + p_iq->prach_log_buffer_size[i] = (int32_t)p_o_xu_cfg->numSlots*XRAN_NUM_OF_SYMBOL_PER_SLOT*PRACH_PLAYBACK_BUFFER_BYTES; - if (parseConfigFile(filename, (RuntimeConfig*)&startupConfiguration) != 0) { - printf("Configuration file error.\n"); - return 0; - } + if (p_iq->p_prach_log_buffer[i] == NULL) + exit(-1); - if(startupConfiguration.ant_file[0] == NULL){ - printf("it looks like test vector for antennas were not provided\n"); - exit(-1); + memset(p_iq->p_prach_log_buffer[i], 0, p_iq->prach_log_buffer_size[i]); } - if (startupConfiguration.numCC > XRAN_MAX_SECTOR_NR) - { - printf("Number of cells %d exceeds max number supported %d!\n", startupConfiguration.numCC, XRAN_MAX_SECTOR_NR); - startupConfiguration.numCC = XRAN_MAX_SECTOR_NR; - } - numCCPorts = startupConfiguration.numCC; - num_eAxc = startupConfiguration.numAxc; - - printf("numCCPorts %d num_eAxc%d\n", numCCPorts, num_eAxc); - - if (startupConfiguration.mu_number <= 1){ - nFpgaToSW_FTH_RxBufferLen = 13168; /* 273*12*4 + 64*/ - nFpgaToSW_PRACH_RxBufferLen = 8192; - nSW_ToFpga_FTH_TxBufferLen = 13168; /* 273*12*4 + 64*/ - } else if (startupConfiguration.mu_number == 3){ - nFpgaToSW_FTH_RxBufferLen = 3328; - nFpgaToSW_PRACH_RxBufferLen = 8192; - nSW_ToFpga_FTH_TxBufferLen = 3328; - } else { - printf("given numerology is not supported %d\n", startupConfiguration.mu_number); - exit(-1); - } - - memset(&xranInit, 0, sizeof(struct xran_fh_init)); - - if(startupConfiguration.appMode == APP_O_DU) { - printf("set O-DU\n"); - xranInit.io_cfg.id = 0;//ID_LLS_CU; - xranInit.io_cfg.core = 4+1; - xranInit.io_cfg.system_core = 0; - xranInit.io_cfg.pkt_proc_core = 4+2; - xranInit.io_cfg.pkt_aux_core = 0; /* do not start*/ - xranInit.io_cfg.timing_core = 4+3; - } else { - printf("set O-DU\n"); - xranInit.io_cfg.id = 1; /* ID_LLS_CU;*/ - xranInit.io_cfg.core = 1; - xranInit.io_cfg.system_core = 0; - xranInit.io_cfg.pkt_proc_core = 2; - xranInit.io_cfg.pkt_aux_core = 0; /* do not start */ - xranInit.io_cfg.timing_core = 3; - } - - xranInit.io_cfg.bbdev_mode = XRAN_BBDEV_NOT_USED; - - xranInit.eAxCId_conf.mask_cuPortId = 0xf000; - xranInit.eAxCId_conf.mask_bandSectorId = 0x0f00; - xranInit.eAxCId_conf.mask_ccId = 0x00f0; - xranInit.eAxCId_conf.mask_ruPortId = 0x000f; - xranInit.eAxCId_conf.bit_cuPortId = 12; - xranInit.eAxCId_conf.bit_bandSectorId = 8; - xranInit.eAxCId_conf.bit_ccId = 4; - xranInit.eAxCId_conf.bit_ruPortId = 0; - - xranInit.io_cfg.dpdk_dev[XRAN_UP_VF] = argv[2]; - xranInit.io_cfg.dpdk_dev[XRAN_CP_VF] = argv[3]; - xranInit.mtu = startupConfiguration.mtu; - - xranInit.p_o_du_addr = (int8_t*)&startupConfiguration.o_du_addr; - xranInit.p_o_ru_addr = (int8_t*)&startupConfiguration.o_ru_addr; - xranInit.filePrefix = "wls"; - xranInit.xranCat = XRAN_CATRGORY_A; - - xranInit.Tadv_cp_dl = startupConfiguration.Tadv_cp_dl; - xranInit.T2a_min_cp_dl = startupConfiguration.T2a_min_cp_dl; - xranInit.T2a_max_cp_dl = startupConfiguration.T2a_max_cp_dl; - xranInit.T2a_min_cp_ul = startupConfiguration.T2a_min_cp_ul; - xranInit.T2a_max_cp_ul = startupConfiguration.T2a_max_cp_ul; - xranInit.T2a_min_up = startupConfiguration.T2a_min_up; - xranInit.T2a_max_up = startupConfiguration.T2a_max_up; - xranInit.Ta3_min = startupConfiguration.Ta3_min; - xranInit.Ta3_max = startupConfiguration.Ta3_max; - xranInit.T1a_min_cp_dl = startupConfiguration.T1a_min_cp_dl; - xranInit.T1a_max_cp_dl = startupConfiguration.T1a_max_cp_dl; - xranInit.T1a_min_cp_ul = startupConfiguration.T1a_min_cp_ul; - xranInit.T1a_max_cp_ul = startupConfiguration.T1a_max_cp_ul; - xranInit.T1a_min_up = startupConfiguration.T1a_min_up; - xranInit.T1a_max_up = startupConfiguration.T1a_max_up; - xranInit.Ta4_min = startupConfiguration.Ta4_min; - xranInit.Ta4_max = startupConfiguration.Ta4_max; - - xranInit.enableCP = startupConfiguration.enableCP; - xranInit.prachEnable = startupConfiguration.enablePrach; - xranInit.debugStop = startupConfiguration.debugStop; - xranInit.debugStopCount = startupConfiguration.debugStopCount; - xranInit.DynamicSectionEna = startupConfiguration.DynamicSectionEna; - xranInit.io_cfg.bbdev_mode = XRAN_BBDEV_NOT_USED; //startupConfiguration.bbdevMode; - - xranInit.cp_vlan_tag = startupConfiguration.cp_vlan_tag; - xranInit.up_vlan_tag = startupConfiguration.up_vlan_tag; - - printf("IQ files size is %d slots\n", startupConfiguration.numSlots); - - iq_playback_buffer_size_dl = (startupConfiguration.numSlots * N_SYM_PER_SLOT * N_SC_PER_PRB * - app_xran_get_num_rbs(startupConfiguration.mu_number, startupConfiguration.nDLBandwidth, startupConfiguration.nDLAbsFrePointA) - *4L); - - iq_playback_buffer_size_ul = (startupConfiguration.numSlots * N_SYM_PER_SLOT * N_SC_PER_PRB * - app_xran_get_num_rbs(startupConfiguration.mu_number, startupConfiguration.nULBandwidth, startupConfiguration.nULAbsFrePointA) - *4L); - - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { - - p_tx_play_buffer[i] = (int16_t*)malloc(iq_playback_buffer_size_dl); - tx_play_buffer_size[i] = (int32_t)iq_playback_buffer_size_dl; - - if (p_tx_play_buffer[i] == NULL) - exit(-1); + /* log of SRS */ + if (p_o_xu_cfg->appMode == APP_O_DU && p_o_xu_cfg->enableSrs) { + for(i = 0; + i < MAX_ANT_CARRIER_SUPPORTED_CAT_B && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->antElmTRx); + i++) { - tx_play_buffer_size[i] = sys_load_file_to_buff(startupConfiguration.ant_file[i], - "DL IFFT IN IQ Samples in binary format", - (uint8_t*) p_tx_play_buffer[i], - tx_play_buffer_size[i], - 1); - tx_play_buffer_position[i] = 0; - } + p_iq->p_srs_log_buffer[i] = (int16_t*)malloc(p_iq->iq_srs_buffer_size_ul); + p_iq->srs_log_buffer_size[i] = (int32_t)p_iq->iq_srs_buffer_size_ul; - if (startupConfiguration.appMode == APP_O_RU && startupConfiguration.enablePrach){ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { - p_tx_prach_play_buffer[i] = (int16_t*)malloc(PRACH_PLAYBACK_BUFFER_BYTES); - tx_prach_play_buffer_size[i] = (int32_t)PRACH_PLAYBACK_BUFFER_BYTES; - - if (p_tx_prach_play_buffer[i] == NULL) + if (p_iq->p_srs_log_buffer[i] == NULL) exit(-1); - tx_prach_play_buffer_size[i] = sys_load_file_to_buff(startupConfiguration.prach_file[i], - "PRACH IQ Samples in binary format", - (uint8_t*) p_tx_prach_play_buffer[i], - tx_prach_play_buffer_size[i], - 1); - tx_prach_play_buffer_position[i] = 0; - } - } - /* log of ul */ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { + memset(p_iq->p_srs_log_buffer[i], 0, p_iq->iq_srs_buffer_size_ul); + } + } - p_rx_log_buffer[i] = (int16_t*)malloc(iq_playback_buffer_size_ul); - rx_log_buffer_size[i] = (int32_t)iq_playback_buffer_size_ul; + /* log of BFWs */ + if (p_o_xu_cfg->appMode == APP_O_RU && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { - if (p_rx_log_buffer[i] == NULL) - exit(-1); + p_iq->p_tx_dl_bfw_log_buffer[i] = (int16_t*)malloc(p_iq->iq_bfw_buffer_size_dl); + p_iq->tx_dl_bfw_log_buffer_size[i] = (int32_t)p_iq->iq_bfw_buffer_size_dl; - rx_log_buffer_position[i] = 0; + if (p_iq->p_tx_dl_bfw_log_buffer[i] == NULL) + exit(-1); - memset(p_rx_log_buffer[i], 0, rx_log_buffer_size[i]); - } + memset(p_iq->p_tx_dl_bfw_log_buffer[i], 0, p_iq->iq_bfw_buffer_size_dl); + } + } - /* log of Prach */ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { + if (p_o_xu_cfg->appMode == APP_O_RU && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { - p_prach_log_buffer[i] = (int16_t*)malloc(startupConfiguration.numSlots*PRACH_PLAYBACK_BUFFER_BYTES); - prach_log_buffer_size[i] = (int32_t)startupConfiguration.numSlots*PRACH_PLAYBACK_BUFFER_BYTES; + p_iq->p_tx_ul_bfw_log_buffer[i] = (int16_t*)malloc(p_iq->iq_bfw_buffer_size_ul); + p_iq->tx_ul_bfw_log_buffer_size[i] = (int32_t)p_iq->iq_bfw_buffer_size_ul; - if (p_prach_log_buffer[i] == NULL) - exit(-1); + if (p_iq->p_tx_ul_bfw_log_buffer[i] == NULL) + exit(-1); - memset(p_prach_log_buffer[i], 0, prach_log_buffer_size[i]); - prach_log_buffer_position[i] = 0; + memset(p_iq->p_tx_ul_bfw_log_buffer[i], 0, p_iq->iq_bfw_buffer_size_ul); } - - if (stat("./logs", &st) == -1) { - mkdir("./logs", 0777); } - for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { - sprintf(filename, "./logs/%s-play_ant%d.txt",((startupConfiguration.appMode == APP_O_DU) ? "o-du" : "o-ru"), i); + snprintf(filename, sizeof(filename), "./logs/%s%d-play_ant%d.txt",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); sys_save_buf_to_file_txt(filename, "DL IFFT IN IQ Samples in human readable format", - (uint8_t*) p_tx_play_buffer[i], - tx_play_buffer_size[i], + (uint8_t*) p_iq->p_tx_play_buffer[i], + p_iq->tx_play_buffer_size[i], 1); - sprintf(filename, "./logs/%s-play_ant%d.bin",((startupConfiguration.appMode == APP_O_DU) ? "o-du" : "o-ru"), i); + snprintf(filename, sizeof(filename),"./logs/%s%d-play_ant%d.bin",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); sys_save_buf_to_file(filename, "DL IFFT IN IQ Samples in binary format", - (uint8_t*) p_tx_play_buffer[i], - tx_play_buffer_size[i]/sizeof(short), + (uint8_t*) p_iq->p_tx_play_buffer[i], + p_iq->tx_play_buffer_size[i]/sizeof(short), sizeof(short)); - if (startupConfiguration.appMode == APP_O_RU && startupConfiguration.enablePrach){ - sprintf(filename, "./logs/%s-play_prach_ant%d.txt",((startupConfiguration.appMode == APP_O_DU) ? "o-du" : "o-ru"), i); + + if (p_o_xu_cfg->appMode == APP_O_DU && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { + snprintf(filename, sizeof(filename),"./logs/%s%d-dl_bfw_ue%d.txt",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); sys_save_buf_to_file_txt(filename, - "DL IFFT IN IQ Samples in human readable format", - (uint8_t*) p_tx_prach_play_buffer[i], - tx_prach_play_buffer_size[i], + "DL Beamformig weights IQ Samples in human readable format", + (uint8_t*) p_iq->p_tx_dl_bfw_buffer[i], + p_iq->tx_dl_bfw_buffer_size[i], 1); - sprintf(filename, "./logs/%s-play_prach_ant%d.bin",((startupConfiguration.appMode == APP_O_DU) ? "o-du" : "o-ru"), i); + snprintf(filename, sizeof(filename),"./logs/%s%d-dl_bfw_ue%d.bin",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"),p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file(filename, + "DL Beamformig weightsIQ Samples in binary format", + (uint8_t*) p_iq->p_tx_dl_bfw_buffer[i], + p_iq->tx_dl_bfw_buffer_size[i]/sizeof(short), + sizeof(short)); + + + snprintf(filename, sizeof(filename), "./logs/%s%d-ul_bfw_ue%d.txt",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file_txt(filename, + "UL Beamformig weights IQ Samples in human readable format", + (uint8_t*) p_iq->p_tx_ul_bfw_buffer[i], + p_iq->tx_ul_bfw_buffer_size[i], + 1); + + snprintf(filename, sizeof(filename),"./logs/%s%d-ul_bfw_ue%d.bin",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file(filename, + "UL Beamformig weightsIQ Samples in binary format", + (uint8_t*) p_iq->p_tx_ul_bfw_buffer[i], + p_iq->tx_ul_bfw_buffer_size[i]/sizeof(short), + sizeof(short)); + + } + } + + if (p_o_xu_cfg->appMode == APP_O_RU && p_o_xu_cfg->enableSrs && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { + for(i = 0; + i < MAX_ANT_CARRIER_SUPPORTED_CAT_B && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->antElmTRx); + i++) { + + snprintf(filename, sizeof(filename), "./logs/%s%d-play_srs_ant%d.txt",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file_txt(filename, + "SRS IQ Samples in human readable format", + (uint8_t*)p_iq->p_tx_srs_play_buffer[i], + p_iq->tx_srs_play_buffer_size[i], + 1); + + snprintf(filename,sizeof(filename), "./logs/%s%d-play_srs_ant%d.bin",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); sys_save_buf_to_file(filename, - "DL IFFT IN IQ Samples in binary format", - (uint8_t*) p_tx_prach_play_buffer[i], - tx_prach_play_buffer_size[i]/sizeof(short), + "SRS IQ Samples in binary format", + (uint8_t*) p_iq->p_tx_srs_play_buffer[i], + p_iq->tx_srs_play_buffer_size[i]/sizeof(short), sizeof(short)); } } - if (startupConfiguration.iqswap == 1){ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { + + if (p_o_xu_cfg->iqswap == 1) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { printf("TX: Swap I and Q to match RU format: [%d]\n",i); { /* swap I and Q */ int32_t j; - signed short *ptr = (signed short *) p_tx_play_buffer[i]; + signed short *ptr = (signed short *) p_iq->p_tx_play_buffer[i]; signed short temp; - for (j = 0; j < (int32_t)(tx_play_buffer_size[i]/sizeof(short)) ; j = j + 2){ + for (j = 0; j < (int32_t)(p_iq->tx_play_buffer_size[i]/sizeof(short)) ; j = j + 2) { temp = ptr[j]; ptr[j] = ptr[j + 1]; ptr[j + 1] = temp; } } + if (p_o_xu_cfg->appMode == APP_O_DU && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { + printf("DL BFW: Swap I and Q to match RU format: [%d]\n",i); + { + /* swap I and Q */ + int32_t j; + signed short *ptr = (signed short *) p_iq->p_tx_dl_bfw_buffer[i]; + signed short temp; + + for (j = 0; j < (int32_t)(p_iq->tx_dl_bfw_buffer_size[i]/sizeof(short)) ; j = j + 2) { + temp = ptr[j]; + ptr[j] = ptr[j + 1]; + ptr[j + 1] = temp; + } + } + printf("UL BFW: Swap I and Q to match RU format: [%d]\n",i); + { + /* swap I and Q */ + int32_t j; + signed short *ptr = (signed short *) p_iq->p_tx_ul_bfw_buffer[i]; + signed short temp; + + for (j = 0; j < (int32_t)(p_iq->tx_ul_bfw_buffer_size[i]/sizeof(short)) ; j = j + 2) { + temp = ptr[j]; + ptr[j] = ptr[j + 1]; + ptr[j + 1] = temp; + } + } + } } - if (startupConfiguration.appMode == APP_O_RU){ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { + + if (p_o_xu_cfg->appMode == APP_O_RU) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { printf("PRACH: Swap I and Q to match RU format: [%d]\n",i); { /* swap I and Q */ int32_t j; - signed short *ptr = (signed short *) p_tx_prach_play_buffer[i]; + signed short *ptr = (signed short *) p_iq-> p_tx_prach_play_buffer[i]; signed short temp; - for (j = 0; j < (int32_t)(tx_prach_play_buffer_size[i]/sizeof(short)) ; j = j + 2){ + for (j = 0; j < (int32_t)(p_iq->tx_prach_play_buffer_size[i]/sizeof(short)) ; j = j + 2) { temp = ptr[j]; ptr[j] = ptr[j + 1]; ptr[j + 1] = temp; @@ -1254,159 +848,649 @@ int main(int argc, char *argv[]) } } + if (p_o_xu_cfg->appMode == APP_O_RU) { + for(i = 0; + i < MAX_ANT_CARRIER_SUPPORTED_CAT_B && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->antElmTRx); + i++) { + printf("SRS: Swap I and Q to match RU format: [%d]\n",i); + { + /* swap I and Q */ + int32_t j; + signed short *ptr = (signed short *) p_iq->p_tx_srs_play_buffer[i]; + signed short temp; + + for (j = 0; j < (int32_t)(p_iq->tx_srs_play_buffer_size[i]/sizeof(short)) ; j = j + 2) { + temp = ptr[j]; + ptr[j] = ptr[j + 1]; + ptr[j + 1] = temp; + } + } + } + } } #if 0 - for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { sprintf(filename, "./logs/swap_IQ_play_ant%d.txt", i); sys_save_buf_to_file_txt(filename, "DL IFFT IN IQ Samples in human readable format", - (uint8_t*) p_tx_play_buffer[i], - tx_play_buffer_size[i], + (uint8_t*) p_iq->p_tx_play_buffer[i], + p_iq->tx_play_buffer_size[i], 1); } #endif - if (startupConfiguration.nebyteorderswap == 1){ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { + if (p_o_xu_cfg->nebyteorderswap == 1 && p_o_xu_cfg->compression == 0) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { printf("TX: Convert S16 I and S16 Q to network byte order for XRAN Ant: [%d]\n",i); - for (j = 0; j < tx_play_buffer_size[i]/sizeof(short); j++){ - p_tx_play_buffer[i][j] = rte_cpu_to_be_16(p_tx_play_buffer[i][j]); + for (j = 0; j < p_iq->tx_play_buffer_size[i]/sizeof(short); j++) { + p_iq->p_tx_play_buffer[i][j] = rte_cpu_to_be_16(p_iq->p_tx_play_buffer[i][j]); + } + + if (p_o_xu_cfg->appMode == APP_O_DU && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { + printf("DL BFW: Convert S16 I and S16 Q to network byte order for XRAN Ant: [%d]\n",i); + for (j = 0; j < p_iq->tx_dl_bfw_buffer_size[i]/sizeof(short); j++) { + p_iq->p_tx_dl_bfw_buffer[i][j] = rte_cpu_to_be_16(p_iq->p_tx_dl_bfw_buffer[i][j]); + } + printf("UL BFW: Convert S16 I and S16 Q to network byte order for XRAN Ant: [%d]\n",i); + for (j = 0; j < p_iq->tx_ul_bfw_buffer_size[i]/sizeof(short); j++) { + p_iq->p_tx_ul_bfw_buffer[i][j] = rte_cpu_to_be_16(p_iq->p_tx_ul_bfw_buffer[i][j]); + } } } - if (startupConfiguration.appMode == APP_O_RU){ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { + if (p_o_xu_cfg->appMode == APP_O_RU && p_o_xu_cfg->enablePrach) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { printf("PRACH: Convert S16 I and S16 Q to network byte order for XRAN Ant: [%d]\n",i); - for (j = 0; j < tx_prach_play_buffer_size[i]/sizeof(short); j++){ - p_tx_prach_play_buffer[i][j] = rte_cpu_to_be_16(p_tx_prach_play_buffer[i][j]); + for (j = 0; j < p_iq->tx_prach_play_buffer_size[i]/sizeof(short); j++) { + p_iq->p_tx_prach_play_buffer[i][j] = rte_cpu_to_be_16(p_iq->p_tx_prach_play_buffer[i][j]); } } } + + if (p_o_xu_cfg->appMode == APP_O_RU && p_o_xu_cfg->enableSrs) { + for(i = 0; + i < MAX_ANT_CARRIER_SUPPORTED_CAT_B && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->antElmTRx); + i++) { + printf("SRS: Convert S16 I and S16 Q to network byte order for XRAN Ant: [%d]\n",i); + for (j = 0; j < p_iq->tx_srs_play_buffer_size[i]/sizeof(short); j++) { + p_iq->p_tx_srs_play_buffer[i][j] = rte_cpu_to_be_16(p_iq->p_tx_srs_play_buffer[i][j]); + } + } + } + } #if 0 - for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { sprintf(filename, "./logs/swap_be_play_ant%d.txt", i); sys_save_buf_to_file_txt(filename, "DL IFFT IN IQ Samples in human readable format", - (uint8_t*) p_tx_play_buffer[i], - tx_play_buffer_size[i], + (uint8_t*) p_iq->p_tx_play_buffer[i], + p_iq->tx_play_buffer_size[i], 1); } #endif + } + return ret; +} - timer_set_tsc_freq_from_clock(); - xret = xran_init(argc, argv, &xranInit, argv[0], &xranHandle); - if(xret != XRAN_STATUS_SUCCESS){ - printf("xran_init failed %d\n", xret); +int32_t +app_dump_o_xu_buffers(UsecaseConfig* p_use_cfg, RuntimeConfig* p_o_xu_cfg) +{ + int32_t ret = 0; + int32_t i = 0; + int32_t j = 0; + char filename[256]; + struct o_xu_buffers* p_iq = NULL; + + if (p_o_xu_cfg->p_buff) { + p_iq = p_o_xu_cfg->p_buff; + } else { + printf("Error p_o_xu_cfg->p_buff\n"); exit(-1); } - if(xranHandle == NULL) - exit(1); + if (p_o_xu_cfg->iqswap == 1) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { + printf("RX: Swap I and Q to match CPU format: [%d]\n",i); + { + /* swap I and Q */ + int32_t j; + signed short *ptr = (signed short *) p_iq->p_rx_log_buffer[i]; + signed short temp; + + for (j = 0; j < (int32_t)(p_iq->rx_log_buffer_size[i]/sizeof(short)) ; j = j + 2) { + temp = ptr[j]; + ptr[j] = ptr[j + 1]; + ptr[j + 1] = temp; + } + } + } + + if (p_o_xu_cfg->appMode == APP_O_DU && p_o_xu_cfg->enableSrs) { + for (i = 0; + i < MAX_ANT_CARRIER_SUPPORTED_CAT_B && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->antElmTRx); + i++) { + printf("SRS: Swap I and Q to match CPU format: [%d]\n",i); + { + /* swap I and Q */ + int32_t j; + signed short *ptr = (signed short *) p_iq->p_srs_log_buffer[i]; + signed short temp; + + for (j = 0; j < (int32_t)(p_iq->srs_log_buffer_size[i]/sizeof(short)) ; j = j + 2) { + temp = ptr[j]; + ptr[j] = ptr[j + 1]; + ptr[j + 1] = temp; + } + } + } + } + } + + if (p_o_xu_cfg->nebyteorderswap == 1 && p_o_xu_cfg->compression == 0) { + + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { + printf("RX: Convert S16 I and S16 Q to cpu byte order from XRAN Ant: [%d]\n",i); + for (j = 0; j < p_iq->rx_log_buffer_size[i]/sizeof(short); j++) { + p_iq->p_rx_log_buffer[i][j] = rte_be_to_cpu_16(p_iq->p_rx_log_buffer[i][j]); + } + } + + if (p_o_xu_cfg->appMode == APP_O_DU && p_o_xu_cfg->enableSrs) { + for (i = 0; + i < MAX_ANT_CARRIER_SUPPORTED_CAT_B && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->antElmTRx); + i++) { + printf("SRS: Convert S16 I and S16 Q to cpu byte order from XRAN Ant: [%d]\n",i); + for (j = 0; j < p_iq->srs_log_buffer_size[i]/sizeof(short); j++) { + p_iq->p_srs_log_buffer[i][j] = rte_be_to_cpu_16(p_iq->p_srs_log_buffer[i][j]); + } + } + } + } + + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { + + snprintf(filename, sizeof(filename), "./logs/%s%d-rx_log_ant%d.txt",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file_txt(filename, + "UL FFT OUT IQ Samples in human readable format", + (uint8_t*) p_iq->p_rx_log_buffer[i], + p_iq->rx_log_buffer_size[i], + 1); + + snprintf(filename, sizeof(filename), "./logs/%s%d-rx_log_ant%d.bin",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file(filename, + "UL FFT OUT IQ Samples in binary format", + (uint8_t*) p_iq->p_rx_log_buffer[i], + p_iq->rx_log_buffer_size[i]/sizeof(short), + sizeof(short)); + + if (p_o_xu_cfg->appMode == APP_O_RU && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { + snprintf(filename, sizeof(filename),"./logs/%s%d-dl_bfw_log_ue%d.txt",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file_txt(filename, + "DL Beamformig weights IQ Samples in human readable format", + (uint8_t*) p_iq->p_tx_dl_bfw_log_buffer[i], + p_iq->tx_dl_bfw_log_buffer_size[i], + 1); + + snprintf(filename, sizeof(filename),"./logs/%s%d-dl_bfw_log_ue%d.bin",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"),p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file(filename, + "DL Beamformig weightsIQ Samples in binary format", + (uint8_t*) p_iq->p_tx_dl_bfw_log_buffer[i], + p_iq->tx_dl_bfw_log_buffer_size[i]/sizeof(short), + sizeof(short)); + + } + if (p_o_xu_cfg->appMode == APP_O_RU && p_o_xu_cfg->xranCat == XRAN_CATEGORY_B) { + snprintf(filename, sizeof(filename),"./logs/%s%d-ul_bfw_log_ue%d.txt",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file_txt(filename, + "DL Beamformig weights IQ Samples in human readable format", + (uint8_t*) p_iq->p_tx_ul_bfw_log_buffer[i], + p_iq->tx_ul_bfw_log_buffer_size[i], + 1); + + snprintf(filename, sizeof(filename),"./logs/%s%d-ul_bfw_log_ue%d.bin",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"),p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file(filename, + "DL Beamformig weightsIQ Samples in binary format", + (uint8_t*) p_iq->p_tx_ul_bfw_log_buffer[i], + p_iq->tx_ul_bfw_log_buffer_size[i]/sizeof(short), + sizeof(short)); + } + + } + + if (p_o_xu_cfg->appMode == APP_O_DU && p_o_xu_cfg->enableSrs) { + for (i = 0; + i < MAX_ANT_CARRIER_SUPPORTED_CAT_B && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->antElmTRx); + i++) { + snprintf(filename, sizeof(filename), "./logs/%s%d-srs_log_ant%d.txt",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file_txt(filename, + "SRS UL FFT OUT IQ Samples in human readable format", + (uint8_t*)p_iq-> p_srs_log_buffer[i], + p_iq->srs_log_buffer_size[i], + 1); + + snprintf(filename, sizeof(filename), "./logs/%s%d-srs_log_ant%d.bin",((p_o_xu_cfg->appMode == APP_O_DU) ? "o-du" : "o-ru"), p_o_xu_cfg->o_xu_id, i); + sys_save_buf_to_file(filename, + "SRS UL FFT OUT IQ Samples in binary format", + (uint8_t*) p_iq->p_srs_log_buffer[i], + p_iq->srs_log_buffer_size[i]/sizeof(short), + sizeof(short)); + } + } + + if (p_o_xu_cfg->enablePrach) { + if (p_o_xu_cfg->iqswap == 1) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { + printf("PRACH: Swap I and Q to match CPU format: [%d]\n",i); + { + /* swap I and Q */ + int32_t j; + signed short *ptr = (signed short *) p_iq->p_prach_log_buffer[i]; + signed short temp; + + for (j = 0; j < (int32_t)(p_iq->prach_log_buffer_size[i]/sizeof(short)) ; j = j + 2) { + temp = ptr[j]; + ptr[j] = ptr[j + 1]; + ptr[j + 1] = temp; + } + } + } + } + + if (p_o_xu_cfg->nebyteorderswap == 1 && p_o_xu_cfg->compression == 0) { + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { + printf("PRACH: Convert S16 I and S16 Q to cpu byte order from XRAN Ant: [%d]\n",i); + for (j = 0; j < p_iq->prach_log_buffer_size[i]/sizeof(short); j++) { + p_iq->p_prach_log_buffer[i][j] = rte_be_to_cpu_16(p_iq->p_prach_log_buffer[i][j]); + } + } + } - memset(&xranConf, 0, sizeof(struct xran_fh_config)); - pXranConf = &xranConf; + for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(p_o_xu_cfg->numCC * p_o_xu_cfg->numAxc); i++) { - pXranConf->sector_id = 0; - pXranConf->nCC = numCCPorts; - pXranConf->neAxc = num_eAxc; + if (p_o_xu_cfg->appMode == APP_O_DU) + snprintf(filename, sizeof(filename), "./logs/%s%d%s_ant%d.txt","o-du",p_o_xu_cfg->o_xu_id,"-prach_log", i); + else + snprintf(filename, sizeof(filename), "./logs/%s%d%s_ant%d.txt","o-ru",p_o_xu_cfg->o_xu_id,"-play_prach", i); + sys_save_buf_to_file_txt(filename, + "PRACH IQ Samples in human readable format", + (uint8_t*) p_iq->p_prach_log_buffer[i], + p_iq->prach_log_buffer_size[i], + 1); - pXranConf->frame_conf.nFrameDuplexType = startupConfiguration.nFrameDuplexType; - pXranConf->frame_conf.nNumerology = startupConfiguration.mu_number; - pXranConf->frame_conf.nTddPeriod = startupConfiguration.nTddPeriod; + if (p_o_xu_cfg->appMode == APP_O_DU) + snprintf(filename, sizeof(filename), "./logs/%s%d%s_ant%d.bin","o-du",p_o_xu_cfg->o_xu_id,"-prach_log", i); + else + snprintf(filename, sizeof(filename), "./logs/%s%d%s_ant%d.bin","o-ru",p_o_xu_cfg->o_xu_id,"-play_prach", i); + sys_save_buf_to_file(filename, + "PRACH IQ Samples in binary format", + (uint8_t*) p_iq->p_prach_log_buffer[i], + p_iq->prach_log_buffer_size[i]/sizeof(short), + sizeof(short)); + } + } + return ret; +} - for (i = 0; i < startupConfiguration.nTddPeriod; i++){ - pXranConf->frame_conf.sSlotConfig[i] = startupConfiguration.sSlotConfig[i]; +int32_t +app_set_main_core(UsecaseConfig* p_usecase) +{ + struct sched_param sched_param; + cpu_set_t cpuset; + int32_t result = 0; + memset(&sched_param, 0, sizeof(struct sched_param)); + /* set main thread affinity mask to CPU2 */ + sched_param.sched_priority = 99; + CPU_ZERO(&cpuset); + + printf("This system has %d processors configured and %d processors available.\n", get_nprocs_conf(), get_nprocs()); + + if (p_usecase->main_core < get_nprocs_conf()) + CPU_SET(p_usecase->main_core, &cpuset); + else + return -1; + + if ((result = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset))) + { + printf("pthread_setaffinity_np failed: coreId = 2, result = %d\n",result); + } + printf("%s [CPU %2d] [PID: %6d]\n", __FUNCTION__, sched_getcpu(), getpid()); +#if 0 + if ((result = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sched_param))) + { + printf("priority is not changed: coreId = 2, result = %d\n",result); } +#endif + return result; +} - pXranConf->prach_conf.nPrachSubcSpacing = startupConfiguration.mu_number; - pXranConf->prach_conf.nPrachFreqStart = 0; - pXranConf->prach_conf.nPrachFilterIdx = XRAN_FILTERINDEX_PRACH_ABC; - pXranConf->prach_conf.nPrachConfIdx = startupConfiguration.prachConfigIndex; - pXranConf->prach_conf.nPrachFreqOffset = -792; +int32_t +app_alloc_all_cfgs(void) +{ + void * ptr = NULL; + RuntimeConfig* p_rt_cfg = NULL; + int32_t i = 0; + + ptr = _mm_malloc(sizeof(UsecaseConfig), 256); + if (ptr == NULL) { + rte_panic("_mm_malloc: Can't allocate %lu bytes\n", sizeof(UsecaseConfig)); + } - pXranConf->ru_conf.iqWidth = 16; - pXranConf->ru_conf.compMeth = XRAN_COMPMETHOD_NONE; - pXranConf->ru_conf.fftSize = 0; - while (startupConfiguration.nULFftSize >>= 1) - ++pXranConf->ru_conf.fftSize; + p_usecaseConfiguration = (UsecaseConfig*)ptr; - pXranConf->ru_conf.byteOrder = (startupConfiguration.nebyteorderswap == 1) ? XRAN_NE_BE_BYTE_ORDER : XRAN_CPU_LE_BYTE_ORDER ; - pXranConf->ru_conf.iqOrder = (startupConfiguration.iqswap == 1) ? XRAN_Q_I_ORDER : XRAN_I_Q_ORDER; + ptr = _mm_malloc(sizeof(RuntimeConfig)*XRAN_PORTS_NUM, 256); + if (ptr == NULL) { + rte_panic("_mm_malloc: Can't allocate %lu bytes\n", sizeof(RuntimeConfig)*XRAN_PORTS_NUM); + } + p_rt_cfg = (RuntimeConfig*)ptr; - printf("FFT Order %d\n", pXranConf->ru_conf.fftSize); + for (i = 0; i < XRAN_PORTS_NUM; i++) { + p_startupConfiguration[i] = p_rt_cfg++; + } - pXranConf->nDLRBs = app_xran_get_num_rbs(startupConfiguration.mu_number, startupConfiguration.nDLBandwidth, startupConfiguration.nDLAbsFrePointA); - pXranConf->nULRBs = app_xran_get_num_rbs(startupConfiguration.mu_number, startupConfiguration.nULBandwidth, startupConfiguration.nULAbsFrePointA); + return 0; +} - nCenterFreq = startupConfiguration.nDLAbsFrePointA + (((pXranConf->nDLRBs * N_SC_PER_PRB) / 2) * app_xran_get_scs(startupConfiguration.mu_number)); - pXranConf->nDLCenterFreqARFCN = app_xran_cal_nrarfcn(nCenterFreq); - printf("DL center freq %d DL NR-ARFCN %d\n", nCenterFreq, pXranConf->nDLCenterFreqARFCN); +int main(int argc, char *argv[]) +{ + int32_t o_xu_id = 0; + char filename[256]; + int32_t xret = 0; + struct stat st = {0}; + uint32_t filenameLength = strlen(argv[1]); + enum xran_if_state xran_curr_if_state = XRAN_INIT; + struct sample_app_params arg_params; + uint64_t nActiveCoreMask[MAX_BBU_POOL_CORE_MASK] = {0}; + uint64_t nTotalTime; + uint64_t nUsedTime; + uint32_t nCoresUsed; + uint32_t nCoreUsedNum[64]; + //float nUsedPercent; - nCenterFreq = startupConfiguration.nULAbsFrePointA + (((pXranConf->nULRBs * N_SC_PER_PRB) / 2) * app_xran_get_scs(startupConfiguration.mu_number)); - pXranConf->nULCenterFreqARFCN = app_xran_cal_nrarfcn(nCenterFreq); - printf("UL center freq %d UL NR-ARFCN %d\n", nCenterFreq, pXranConf->nULCenterFreqARFCN); + app_version_print(); + app_timer_set_tsc_freq_from_clock(); - pXranConf->bbdev_dec = NULL; - pXranConf->bbdev_enc = NULL; + if (xran_is_synchronized() != 0) + printf("Machine is not synchronized using PTP!\n"); + else + printf("Machine is synchronized using PTP!\n"); - if(init_xran() != 0) + if (filenameLength >= 256) { + printf("Config file name input is too long, exiting!\n"); exit(-1); + } - xran_reg_physide_cb(xranHandle, physide_dl_tti_call_back, NULL, 10, XRAN_CB_TTI); - xran_reg_physide_cb(xranHandle, physide_ul_half_slot_call_back, NULL, 10, XRAN_CB_HALF_SLOT_RX); - xran_reg_physide_cb(xranHandle, physide_ul_full_slot_call_back, NULL, 10, XRAN_CB_FULL_SLOT_RX); + if ((xret = app_alloc_all_cfgs()) < 0) { + printf("app_alloc_all_cfgs failed %d\n", xret); + exit(-1); + } - init_xran_iq_content(); + if ((xret = app_parse_cmdline_args(argc, argv, &arg_params)) < 0) { + printf("app_parse_args failed %d\n", xret); + exit(-1); + } - xret = xran_open(xranHandle, pXranConf); + if ((xret = app_parse_all_cfgs(&arg_params, p_usecaseConfiguration, p_startupConfiguration[0])) < 0) { + printf("app_parse_all_cfgs failed %d\n", xret); + exit(-1); + } +#ifdef FWK_ENABLED + if(p_usecaseConfiguration->bbu_offload) { + if(p_startupConfiguration[0]->appMode == APP_O_DU) { + if ((xret = app_bbu_init(argc, argv, p_usecaseConfiguration->o_xu_bbu_cfg_file, p_usecaseConfiguration, p_startupConfiguration, + nActiveCoreMask)) < 0) { + printf("app_bbu_init failed %d\n", xret); + } - if(xret != XRAN_STATUS_SUCCESS){ - printf("xran_open failed %d\n", xret); + uint32_t i; + uint64_t nMask = 1; + /* use only 1 worker for BBU offload */ + for (i = 0; i < 64; i++) + { + if(p_usecaseConfiguration->io_core < 64) { + if (nMask & p_usecaseConfiguration->io_worker) { + p_usecaseConfiguration->io_worker = nMask; + p_usecaseConfiguration->io_worker_64_127 = 0; + break; + } + } + if(p_usecaseConfiguration->io_core >= 64) { + if (nMask & p_usecaseConfiguration->io_worker_64_127) { + p_usecaseConfiguration->io_worker_64_127 = nMask; + p_usecaseConfiguration->io_worker = 0; + break; + } + } + nMask = nMask << 1; + } + } + } +#endif + if ((xret = app_set_main_core(p_usecaseConfiguration)) < 0) { + printf("app_set_main_core failed %d\n", xret); exit(-1); } - sprintf(filename, "mlog-%s", startupConfiguration.appMode == 0 ? "o-du" : "o-ru"); + app_io_xran_if_alloc(); + + /* one init for all O-XU */ + app_io_xran_fh_init_init(p_usecaseConfiguration, p_startupConfiguration[0], &app_io_xran_fh_init); + xret = xran_init(argc, argv, &app_io_xran_fh_init, argv[0], &app_io_xran_handle); + if (xret != XRAN_STATUS_SUCCESS) { + printf("xran_init failed %d\n", xret); + exit(-1); + } + + if (app_io_xran_handle == NULL) + exit(1); + + if (stat("./logs", &st) == -1) { + mkdir("./logs", 0777); + } + + snprintf(filename, sizeof(filename),"mlog-%s", p_usecaseConfiguration->appMode == 0 ? "o-du" : "o-ru"); -// MLogOpen(0, 32, 0, 0xFFFFFFFF, filename); + /* Init mlog */ + unsigned int mlogSubframes = 128; + unsigned int mlogCores = 32; + unsigned int mlogSize = 10000; - MLogOpen(256, 3, 20000, 0xFFFFFFFF, filename); + // Open Mlog Buffers and initalize variables + MLogOpen(mlogSubframes, mlogCores, mlogSize, 0, filename); + MLogSetMask(0); puts("----------------------------------------"); - printf("MLog Info: virt=0x%016lx size=%d\n", MLogGetFileLocation(), MLogGetFileSize()); + printf("MLog Info: virt=0x%p size=%d\n", MLogGetFileLocation(), MLogGetFileSize()); puts("----------------------------------------"); - uint64_t nActiveCoreMask[MAX_BBU_POOL_CORE_MASK] = {0}; - nActiveCoreMask[0] = 1 << xranInit.io_cfg.timing_core; - uint32_t numCarriers = startupConfiguration.numCC; + uint32_t totalCC = 0; + + if(((1 << app_io_xran_fh_init.io_cfg.timing_core) | app_io_xran_fh_init.io_cfg.pkt_proc_core) & nActiveCoreMask[0]) + rte_panic("[0 - 63] BBU and IO cores conflict\n"); + if(app_io_xran_fh_init.io_cfg.pkt_proc_core_64_127 & nActiveCoreMask[1]) + rte_panic("[64-127] BBU and IO cores conflict\n"); + + nActiveCoreMask[0] |= ((1 << app_io_xran_fh_init.io_cfg.timing_core) | app_io_xran_fh_init.io_cfg.pkt_proc_core); + nActiveCoreMask[1] |= app_io_xran_fh_init.io_cfg.pkt_proc_core_64_127; + + MLogSetup(nActiveCoreMask[0], nActiveCoreMask[1], nActiveCoreMask[2], nActiveCoreMask[3]); + + for (o_xu_id = 0; o_xu_id < p_usecaseConfiguration->oXuNum; o_xu_id++) { + RuntimeConfig* p_o_xu_cfg = p_startupConfiguration[o_xu_id]; + totalCC += p_o_xu_cfg->numCC; + } + MLogAddTestCase(nActiveCoreMask, totalCC); + + /** process all the O-RU|O-DU for use case */ + for (o_xu_id = 0; o_xu_id < p_usecaseConfiguration->oXuNum; o_xu_id++) { + RuntimeConfig* p_o_xu_cfg = p_startupConfiguration[o_xu_id]; + if (o_xu_id == 0) + app_io_xran_buffers_max_sz_set(p_o_xu_cfg); + + if (p_o_xu_cfg->ant_file[0] == NULL) { + printf("it looks like test vector for antennas were not provided\n"); + exit(-1); + } + if (p_o_xu_cfg->numCC > XRAN_MAX_SECTOR_NR) { + printf("Number of cells %d exceeds max number supported %d!\n", p_o_xu_cfg->numCC, XRAN_MAX_SECTOR_NR); + p_o_xu_cfg->numCC = XRAN_MAX_SECTOR_NR; + + } + if (p_o_xu_cfg->antElmTRx > XRAN_MAX_ANT_ARRAY_ELM_NR) { + printf("Number of Antenna elements %d exceeds max number supported %d!\n", p_o_xu_cfg->antElmTRx, XRAN_MAX_ANT_ARRAY_ELM_NR); + p_o_xu_cfg->antElmTRx = XRAN_MAX_ANT_ARRAY_ELM_NR; + } + + printf("Numm CC %d numAxc %d numUlAxc %d\n", p_o_xu_cfg->numCC, p_o_xu_cfg->numAxc, p_o_xu_cfg->numUlAxc); + + app_setup_o_xu_buffers(p_usecaseConfiguration, p_o_xu_cfg, &app_io_xran_fh_init); + + app_io_xran_fh_config_init(p_usecaseConfiguration, p_o_xu_cfg, &app_io_xran_fh_init, &app_io_xran_fh_config[o_xu_id]); + + xret = xran_open(app_io_xran_handle, &app_io_xran_fh_config[o_xu_id]); + if(xret != XRAN_STATUS_SUCCESS){ + printf("xran_open failed %d\n", xret); + exit(-1); + } + if (app_io_xran_interface(o_xu_id, p_startupConfiguration[o_xu_id], p_usecaseConfiguration, &app_io_xran_fh_init) != 0) + exit(-1); + + app_io_xran_iq_content_init(o_xu_id, p_startupConfiguration[o_xu_id]); +#ifdef FWK_ENABLED + if(p_o_xu_cfg->appMode == APP_O_DU && p_usecaseConfiguration->bbu_offload) { + if ((xret = xran_reg_physide_cb(app_io_xran_handle, app_bbu_dl_tti_call_back, NULL, 10, XRAN_CB_TTI)) != XRAN_STATUS_SUCCESS) { + printf("xran_reg_physide_cb failed %d\n", xret); + exit(-1); + } + } else { + if ((xret = xran_reg_physide_cb(app_io_xran_handle, app_io_xran_dl_tti_call_back, NULL, 10, XRAN_CB_TTI)) != XRAN_STATUS_SUCCESS) { + printf("xran_reg_physide_cb failed %d\n", xret); + exit(-1); + } + } +#else + if ((xret = xran_reg_physide_cb(app_io_xran_handle, app_io_xran_dl_tti_call_back, NULL, 10, XRAN_CB_TTI)) != XRAN_STATUS_SUCCESS) { + printf("xran_reg_physide_cb failed %d\n", xret); + exit(-1); + } +#endif + if ((xret = xran_reg_physide_cb(app_io_xran_handle, app_io_xran_ul_half_slot_call_back, NULL, 10, XRAN_CB_HALF_SLOT_RX)) != XRAN_STATUS_SUCCESS) { + printf("xran_reg_physide_cb failed %d\n", xret); + exit(-1); + } + if ((xret = xran_reg_physide_cb(app_io_xran_handle, app_io_xran_ul_full_slot_call_back, NULL, 10, XRAN_CB_FULL_SLOT_RX)) != XRAN_STATUS_SUCCESS) { + printf("xran_reg_physide_cb failed %d\n", xret); + exit(-1); + } +#ifdef TEST_SYM_CBS + if ((xret = xran_reg_sym_cb(app_io_xran_handle, app_io_xran_ul_custom_sym_call_back, + (void*)&cb_sym_ctx[0].cb_param, + &cb_sym_ctx[0].sense_of_time, + 3, XRAN_CB_SYM_RX_WIN_BEGIN)) != XRAN_STATUS_SUCCESS) { + printf("xran_reg_sym_cb failed %d\n", xret); + exit(-1); + } + + if ((xret = xran_reg_sym_cb(app_io_xran_handle, app_io_xran_ul_custom_sym_call_back, + (void*)&cb_sym_ctx[1].cb_param, + &cb_sym_ctx[1].sense_of_time, + 3, XRAN_CB_SYM_RX_WIN_END)) != XRAN_STATUS_SUCCESS) { + printf("xran_reg_sym_cb failed %d\n", xret); + exit(-1); + } + + if ((xret = xran_reg_sym_cb(app_io_xran_handle, app_io_xran_ul_custom_sym_call_back, + (void*)&cb_sym_ctx[2].cb_param, + &cb_sym_ctx[2].sense_of_time, + 3, XRAN_CB_SYM_TX_WIN_BEGIN)) != XRAN_STATUS_SUCCESS) { + printf("xran_reg_sym_cb failed %d\n", xret); + exit(-1); + } + + if ((xret = xran_reg_sym_cb(app_io_xran_handle, app_io_xran_ul_custom_sym_call_back, + (void*)&cb_sym_ctx[3].cb_param, + &cb_sym_ctx[3].sense_of_time, + 3, XRAN_CB_SYM_TX_WIN_END)) != XRAN_STATUS_SUCCESS) { + printf("xran_reg_sym_cb failed %d\n", xret); + exit(-1); + } +#endif + } + - MLogAddTestCase(nActiveCoreMask, numCarriers); fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); state = APP_RUNNING; printf("Start XRAN traffic\n"); - xran_start(xranHandle); - sleep(3); - print_menu(); + xran_start(app_io_xran_handle); + app_print_menu(); + + struct xran_common_counters x_counters[XRAN_PORTS_NUM]; + int is_mlog_on = 0; for (;;) { - struct xran_common_counters x_counters; char input[10]; sleep(1); xran_curr_if_state = xran_get_if_state(); - if(xran_get_common_counters(xranHandle, &x_counters) == XRAN_STATUS_SUCCESS) { - printf("rx %ld tx %ld [on_time %ld early %ld late %ld corrupt %ld pkt_dupl %ld Total %ld\n", rx_counter, tx_counter, - x_counters.Rx_on_time, - x_counters.Rx_early, - x_counters.Rx_late, - x_counters.Rx_corrupt, - x_counters.Rx_pkt_dupl, - x_counters.Total_msgs_rcvd); + + if (xran_get_common_counters(app_io_xran_handle, &x_counters[0]) == XRAN_STATUS_SUCCESS) { + for (o_xu_id = 0; o_xu_id < p_usecaseConfiguration->oXuNum; o_xu_id++) { + if (o_xu_id == 0) { + xran_get_time_stats(&nTotalTime, &nUsedTime, &nCoresUsed, nCoreUsedNum, 1); + //nUsedPercent = 0.0; + //if (nTotalTime) { + // nUsedPercent = ((float)nUsedTime * 100.0) / (float)nTotalTime; + //} + mlog_times.core_total_time += nTotalTime; + mlog_times.core_used_time += nUsedTime; + +#if 0 + printf("[nCoresUsed: %d] [MainCore: %d - Util: %5.2f %%]", nCoresUsed, nCoreUsedNum[0], nUsedPercent); + if (nCoresUsed > 1) { + printf("[Additional Cores: "); + for (int nCore = 1; nCore < nCoresUsed; nCore++) { + printf("%d ", nCoreUsedNum[nCore]); + } + printf("]"); + } + printf("\n"); +#endif + } + printf("[%s%d][rx %7ld pps %7ld kbps %7ld][tx %7ld pps %7ld kbps %7ld] [on_time %ld early %ld late %ld corrupt %ld pkt_dupl %ld Invalid_Ext1_packets %ld Total %ld]\n", + ((p_usecaseConfiguration->appMode == APP_O_DU) ? "o-du" : "o-ru"), + o_xu_id, + x_counters[o_xu_id].rx_counter, + x_counters[o_xu_id].rx_counter-old_rx_counter[o_xu_id], + x_counters[o_xu_id].rx_bytes_per_sec*8/1000L, + x_counters[o_xu_id].tx_counter, + x_counters[o_xu_id].tx_counter-old_tx_counter[o_xu_id], + x_counters[o_xu_id].tx_bytes_per_sec*8/1000L, + x_counters[o_xu_id].Rx_on_time, + x_counters[o_xu_id].Rx_early, + x_counters[o_xu_id].Rx_late, + x_counters[o_xu_id].Rx_corrupt, + x_counters[o_xu_id].Rx_pkt_dupl, + x_counters[o_xu_id].rx_invalid_ext1_packets, + x_counters[o_xu_id].Total_msgs_rcvd); + + if (x_counters[o_xu_id].rx_counter > old_rx_counter[o_xu_id]) + old_rx_counter[o_xu_id] = x_counters[o_xu_id].rx_counter; + if (x_counters[o_xu_id].tx_counter > old_tx_counter[o_xu_id]) + old_tx_counter[o_xu_id] = x_counters[o_xu_id].tx_counter; + + if(o_xu_id == 0){ + if(is_mlog_on == 0 && x_counters[o_xu_id].rx_counter > 0 && x_counters[o_xu_id].tx_counter > 0) { + xran_set_debug_stop(p_startupConfiguration[0]->debugStop, p_startupConfiguration[0]->debugStopCount); + MLogSetMask(0xFFFFFFFF); + is_mlog_on = 1; + } + } + } } else { printf("error xran_get_common_counters\n"); } @@ -1421,13 +1505,13 @@ int main(int argc, char *argv[]) const int sel_opt = atoi(input); switch (sel_opt) { case 1: - xran_start(xranHandle); + xran_start(app_io_xran_handle); printf("Start XRAN traffic\n"); break; case 2: break; case 3: - xran_stop(xranHandle); + xran_stop(app_io_xran_handle); printf("Stop XRAN traffic\n"); state = APP_STOPPED; break; @@ -1439,106 +1523,55 @@ int main(int argc, char *argv[]) break; } - get_xran_iq_content(); - - puts("Closing l1 app... Ending all threads..."); - xran_close(xranHandle); - MLogPrint(NULL); - - stop_xran(); - puts("Dump IQs..."); - - if (startupConfiguration.iqswap == 1){ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { - printf("RX: Swap I and Q to match CPU format: [%d]\n",i); + /** process all the O-RU|O-DU for use case */ + for (o_xu_id = 0; o_xu_id < p_usecaseConfiguration->oXuNum; o_xu_id++) { + app_io_xran_iq_content_get(o_xu_id, p_startupConfiguration[o_xu_id]); + /* Check for owd results */ + if (p_usecaseConfiguration->owdmEnable) { - /* swap I and Q */ - int32_t j; - signed short *ptr = (signed short *) p_rx_log_buffer[i]; - signed short temp; - for (j = 0; j < (int32_t)(rx_log_buffer_size[i]/sizeof(short)) ; j = j + 2){ - temp = ptr[j]; - ptr[j] = ptr[j + 1]; - ptr[j + 1] = temp; - } - } + FILE *file= NULL; + uint64_t avgDelay =0; + snprintf(filename, sizeof(filename), "./logs/%s%d-owd_results.txt", ((p_startupConfiguration[o_xu_id]->appMode == APP_O_DU)?"o-du":"o-ru"),o_xu_id); + file = fopen(filename, "w"); + if (file == NULL) { + printf("can't open file %s\n",filename); + exit (-1); } - } - - if (startupConfiguration.nebyteorderswap == 1){ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { - printf("RX: Convert S16 I and S16 Q to cpu byte order from XRAN Ant: [%d]\n",i); - for (j = 0; j < rx_log_buffer_size[i]/sizeof(short); j++){ - p_rx_log_buffer[i][j] = rte_be_to_cpu_16(p_rx_log_buffer[i][j]); - } + if (xran_get_delay_measurements_results (app_io_xran_handle, (uint16_t) p_startupConfiguration[o_xu_id]->o_xu_id, p_usecaseConfiguration->appMode, &avgDelay)) + { + fprintf(file,"OWD Measurements failed for port %d and appMode %d \n", p_startupConfiguration[o_xu_id]->o_xu_id,p_usecaseConfiguration->appMode); } - } - - for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { - - sprintf(filename, "./logs/%s-rx_log_ant%d.txt",((startupConfiguration.appMode == APP_O_DU) ? "o-du" : "o-ru"), i); - sys_save_buf_to_file_txt(filename, - "UL FFT OUT IQ Samples in human readable format", - (uint8_t*) p_rx_log_buffer[i], - rx_log_buffer_size[i], - 1); - - sprintf(filename, "./logs/%s-rx_log_ant%d.bin",((startupConfiguration.appMode == APP_O_DU) ? "o-du" : "o-ru"), i); - sys_save_buf_to_file(filename, - "UL FFT OUT IQ Samples in binary format", - (uint8_t*) p_rx_log_buffer[i], - rx_log_buffer_size[i]/sizeof(short), - sizeof(short)); - } - - if (startupConfiguration.appMode == APP_O_DU && startupConfiguration.enablePrach){ - if (startupConfiguration.iqswap == 1){ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { - printf("PRACH: Swap I and Q to match CPU format: [%d]\n",i); + else { - /* swap I and Q */ - int32_t j; - signed short *ptr = (signed short *) p_prach_log_buffer[i]; - signed short temp; - - for (j = 0; j < (int32_t)(prach_log_buffer_size[i]/sizeof(short)) ; j = j + 2){ - temp = ptr[j]; - ptr[j] = ptr[j + 1]; - ptr[j + 1] = temp; - } + fprintf(file,"OWD Measurements passed for port %d and appMode %d with AverageDelay %lu [ns]\n", p_startupConfiguration[o_xu_id]->o_xu_id,p_usecaseConfiguration->appMode, avgDelay); } + fflush(file); + fclose(file); } } + MLogSetMask(0x0); + puts("Closing l1 app... Ending all threads..."); - if (startupConfiguration.nebyteorderswap == 1){ - for(i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { - printf("PRACH: Convert S16 I and S16 Q to cpu byte order from XRAN Ant: [%d]\n",i); - for (j = 0; j < prach_log_buffer_size[i]/sizeof(short); j++){ - p_prach_log_buffer[i][j] = rte_be_to_cpu_16(p_prach_log_buffer[i][j]); - } - } + xran_close(app_io_xran_handle); +#ifdef FWK_ENABLED + if(p_startupConfiguration[0]->appMode == APP_O_DU && p_usecaseConfiguration->bbu_offload) { + app_bbu_close(); } +#endif + app_io_xran_if_stop(); + puts("Dump IQs..."); + for (o_xu_id = 0; o_xu_id < p_usecaseConfiguration->oXuNum; o_xu_id++) { + app_dump_o_xu_buffers(p_usecaseConfiguration, p_startupConfiguration[o_xu_id]); + } - for (i = 0; i < MAX_ANT_CARRIER_SUPPORTED && i < (uint32_t)(numCCPorts * num_eAxc); i++) { - - sprintf(filename, "./logs/%s-prach_log_ant%d.txt",((startupConfiguration.appMode == APP_O_DU) ? "o-du" : "o-ru"), i); - sys_save_buf_to_file_txt(filename, - "PRACH FFT OUT IQ Samples in human readable format", - (uint8_t*) p_prach_log_buffer[i], - prach_log_buffer_size[i], - 1); - - sprintf(filename, "./logs/%s-prach_log_ant%d.bin",((startupConfiguration.appMode == APP_O_DU) ? "o-du" : "o-ru"), i); - sys_save_buf_to_file(filename, - "PRACH FFT OUT IQ Samples in binary format", - (uint8_t*) p_prach_log_buffer[i], - prach_log_buffer_size[i]/sizeof(short), - sizeof(short)); - } + if(is_mlog_on) { + app_profile_xran_print_mlog_stats(arg_params.usecase_file); + rte_pause(); } + app_io_xran_if_free(); return 0; }